Files
Zero/apps/server/src/lib/services.ts
Adam 277f476575 cleanup on isle zero (#1699)
Ran oxc (https://oxc.rs/docs/guide/usage/linter.html#vscode-extension) and fixed all the issues that came up, set it up to run as a PR check and added steps to the README.md asking users to use it.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Introduced JavaScript linting using oxlint in development guidelines and CI workflow for improved code quality.
  * Added oxlint configuration and dependencies to the project.

* **Bug Fixes**
  * Improved error logging in various components and utilities for better debugging.
  * Enhanced React list rendering by updating keys to use unique values instead of array indices, reducing rendering issues.
  * Replaced browser alerts with toast notifications for a smoother user experience.

* **Refactor**
  * Simplified component logic and state management by removing unused code, imports, props, and components across multiple files.
  * Updated function and component signatures for clarity and maintainability.
  * Improved efficiency of certain operations by switching from arrays to sets for membership checks.

* **Chores**
  * Cleaned up and reorganized import statements throughout the codebase.
  * Removed deprecated files, components, and middleware to streamline the codebase.

* **Documentation**
  * Updated contribution guidelines to include linting requirements for code submissions.

* **Style**
  * Minor formatting and readability improvements in JSX and code structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-10 10:59:40 -07:00

55 lines
1.5 KiB
TypeScript

import { env } from 'cloudflare:workers';
import { Redis } from '@upstash/redis';
import { Resend } from 'resend';
export const resend = () =>
env.RESEND_API_KEY
? new Resend(env.RESEND_API_KEY)
: { emails: { send: async (...args: unknown[]) => console.log(args) } };
export const redis = () => new Redis({ url: env.REDIS_URL, token: env.REDIS_TOKEN });
export const twilio = () => {
// if (env.NODE_ENV === 'development' && !forceUseRealService) {
// return {
// messages: {
// send: async (to: string, body: string) =>
// console.log(`[TWILIO:MOCK] Sending message to ${to}: ${body}`),
// },
// };
// }
if (!env.TWILIO_ACCOUNT_SID || !env.TWILIO_AUTH_TOKEN || !env.TWILIO_PHONE_NUMBER) {
throw new Error('Twilio is not configured correctly');
}
const send = async (to: string, body: string) => {
const response = await fetch(
`https://api.twilio.com/2010-04-01/Accounts/${env.TWILIO_ACCOUNT_SID}/Messages.json`,
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Basic ${btoa(`${env.TWILIO_ACCOUNT_SID}:${env.TWILIO_AUTH_TOKEN}`)}`,
},
body: new URLSearchParams({
To: to,
From: env.TWILIO_PHONE_NUMBER,
Body: body,
}),
},
);
if (!response.ok) {
const error = await response.text();
throw new Error(`Failed to send OTP: ${error}`);
}
};
return {
messages: {
send,
},
};
};