@umituz/web-hono 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-hono",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "API backend platform for Cloudflare Workers + Neon Postgres: createApi skeleton + error envelope layer, full-CRUD resource factory (opt-in create/remove, list params), schema→client type bridge (ClientRow), apiFetch/apiWrite client, reactive fetch-backed store (+React hooks), better-auth server integration (tables/getter/mount/session helpers), weak-compare If-None-Match matcher (matchesEtag), and db lifecycle scripts (reset / snapshot / seed)",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -16,6 +16,7 @@
16
16
  "./store/react": "./src/store-react.ts",
17
17
  "./lifecycle": "./src/lifecycle.ts",
18
18
  "./auth": "./src/auth.ts",
19
+ "./mail": "./src/mail.ts",
19
20
  "./etag": "./src/etag.ts",
20
21
  "./package.json": "./package.json"
21
22
  },
package/src/auth.ts CHANGED
@@ -90,7 +90,7 @@ export interface AuthOptions<E extends AuthEnv = AuthEnv> {
90
90
  db: (env: E) => DbLike;
91
91
  tables: AuthTables;
92
92
  trustedOrigins?: string[];
93
- sendResetPassword?: (args: ResetPasswordArgs) => Promise<void> | void;
93
+ sendResetPassword?: (env: E, args: ResetPasswordArgs) => Promise<void> | void;
94
94
  }
95
95
 
96
96
  function initAuth(env: AuthEnv, opts: AuthOptions<AuthEnv>) {
@@ -110,8 +110,12 @@ function initAuth(env: AuthEnv, opts: AuthOptions<AuthEnv>) {
110
110
  enabled: true,
111
111
  sendResetPassword: async (data) => {
112
112
  const send =
113
- opts.sendResetPassword ?? (({ user, url }) => console.log(`[password-reset] ${user.email} ${url}`));
114
- await send({ user: data.user, url: data.url, token: data.token });
113
+ opts.sendResetPassword ??
114
+ ((_env, { user, url, token }) => {
115
+ const link = `${new URL(url).origin}/reset-password?token=${token}`;
116
+ console.log(`[password-reset] ${user.email} ${link}`);
117
+ });
118
+ await send(env, { user: data.user, url: data.url, token: data.token });
115
119
  },
116
120
  onPasswordReset: async ({ user }) => {
117
121
  await opts.db(env).delete(opts.tables.session).where(eq(opts.tables.session.userId, user.id));
package/src/index.ts CHANGED
@@ -40,3 +40,5 @@ export { findRow, softDelete } from './rows';
40
40
  export type { AliveTable } from './rows';
41
41
  export { apiNotFound, spaFallback } from './handlers';
42
42
  export type { ApiEnv } from './env';
43
+ export { sendEmail } from './mail';
44
+ export type { MailEnv, SendEmailInput } from './mail';
package/src/mail.ts ADDED
@@ -0,0 +1,29 @@
1
+ export interface MailEnv {
2
+ RESEND_API_KEY: string;
3
+ }
4
+
5
+ export interface SendEmailInput {
6
+ from: string;
7
+ to: string;
8
+ subject: string;
9
+ html: string;
10
+ text?: string;
11
+ }
12
+
13
+ export async function sendEmail(env: MailEnv, input: SendEmailInput): Promise<void> {
14
+ if (!env.RESEND_API_KEY) {
15
+ throw new Error('RESEND_API_KEY is not configured');
16
+ }
17
+ const body: Record<string, string> = { from: input.from, to: input.to, subject: input.subject, html: input.html };
18
+ if (input.text !== undefined) {
19
+ body.text = input.text;
20
+ }
21
+ const res = await fetch('https://api.resend.com/emails', {
22
+ method: 'POST',
23
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${env.RESEND_API_KEY}` },
24
+ body: JSON.stringify(body),
25
+ });
26
+ if (!res.ok) {
27
+ throw new Error(`resend ${res.status}: ${await res.text()}`);
28
+ }
29
+ }