weifuwu 0.25.2 → 0.27.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.
Files changed (208) hide show
  1. package/README.md +291 -2489
  2. package/ai/provider.ts +129 -0
  3. package/ai/stream.ts +63 -0
  4. package/cli.ts +55 -257
  5. package/core/cookie.ts +114 -0
  6. package/core/env.ts +142 -0
  7. package/core/logger.ts +72 -0
  8. package/core/router.ts +795 -0
  9. package/core/serve.ts +294 -0
  10. package/core/sse.ts +85 -0
  11. package/core/trace.ts +146 -0
  12. package/graphql.ts +267 -0
  13. package/hub.ts +133 -0
  14. package/index.ts +71 -0
  15. package/mailer.ts +81 -0
  16. package/middleware/compress.ts +103 -0
  17. package/middleware/cors.ts +81 -0
  18. package/middleware/csrf.ts +112 -0
  19. package/middleware/flash.ts +144 -0
  20. package/middleware/health.ts +44 -0
  21. package/middleware/helmet.ts +98 -0
  22. package/middleware/i18n.ts +175 -0
  23. package/middleware/rate-limit.ts +167 -0
  24. package/middleware/request-id.ts +60 -0
  25. package/middleware/static.ts +149 -0
  26. package/middleware/theme.ts +84 -0
  27. package/middleware/upload.ts +168 -0
  28. package/middleware/validate.ts +186 -0
  29. package/package.json +14 -36
  30. package/postgres/client.ts +132 -0
  31. package/postgres/index.ts +4 -0
  32. package/postgres/module.ts +37 -0
  33. package/postgres/schema/columns.ts +186 -0
  34. package/postgres/schema/index.ts +36 -0
  35. package/postgres/schema/sql.ts +39 -0
  36. package/postgres/schema/table.ts +548 -0
  37. package/postgres/schema/where.ts +99 -0
  38. package/postgres/types.ts +48 -0
  39. package/queue/cron.ts +90 -0
  40. package/queue/index.ts +654 -0
  41. package/queue/types.ts +60 -0
  42. package/redis/client.ts +24 -0
  43. package/{dist/redis/index.d.ts → redis/index.ts} +2 -2
  44. package/redis/types.ts +28 -0
  45. package/types.ts +78 -0
  46. package/cli/template/app.ts +0 -22
  47. package/cli/template/index.ts +0 -10
  48. package/cli/template/locales/en.json +0 -13
  49. package/cli/template/locales/zh-CN.json +0 -13
  50. package/cli/template/locales/zh-TW.json +0 -13
  51. package/cli/template/locales/zh.json +0 -13
  52. package/cli/template/ui/app/globals.css +0 -2
  53. package/cli/template/ui/app/layout.tsx +0 -15
  54. package/cli/template/ui/app/page.tsx +0 -124
  55. package/cli/template/ui/components/Greeting.tsx +0 -3
  56. package/dist/agent/client.d.ts +0 -2
  57. package/dist/agent/index.d.ts +0 -2
  58. package/dist/agent/rest.d.ts +0 -14
  59. package/dist/agent/run.d.ts +0 -19
  60. package/dist/agent/types.d.ts +0 -55
  61. package/dist/ai/provider.d.ts +0 -45
  62. package/dist/ai/utils.d.ts +0 -5
  63. package/dist/ai/workflow.d.ts +0 -17
  64. package/dist/ai-sdk.d.ts +0 -2
  65. package/dist/ai.d.ts +0 -13
  66. package/dist/analytics.d.ts +0 -45
  67. package/dist/auth.d.ts +0 -22
  68. package/dist/cache.d.ts +0 -74
  69. package/dist/cli.d.ts +0 -2
  70. package/dist/cli.js +0 -302
  71. package/dist/client-locale.d.ts +0 -25
  72. package/dist/client-pref.d.ts +0 -3
  73. package/dist/client-router.d.ts +0 -300
  74. package/dist/client-state.d.ts +0 -22
  75. package/dist/client-theme.d.ts +0 -36
  76. package/dist/compile.d.ts +0 -15
  77. package/dist/compress.d.ts +0 -20
  78. package/dist/cookie.d.ts +0 -36
  79. package/dist/cors.d.ts +0 -25
  80. package/dist/cron-utils.d.ts +0 -73
  81. package/dist/csrf.d.ts +0 -47
  82. package/dist/deploy/config.d.ts +0 -2
  83. package/dist/deploy/gateway.d.ts +0 -2
  84. package/dist/deploy/index.d.ts +0 -4
  85. package/dist/deploy/manager.d.ts +0 -16
  86. package/dist/deploy/process.d.ts +0 -14
  87. package/dist/deploy/types.d.ts +0 -53
  88. package/dist/env.d.ts +0 -69
  89. package/dist/error-boundary.d.ts +0 -2
  90. package/dist/flash.d.ts +0 -90
  91. package/dist/fts.d.ts +0 -36
  92. package/dist/graphql.d.ts +0 -16
  93. package/dist/head.d.ts +0 -6
  94. package/dist/health.d.ts +0 -24
  95. package/dist/helmet.d.ts +0 -33
  96. package/dist/html-shell.d.ts +0 -1
  97. package/dist/hub.d.ts +0 -37
  98. package/dist/i18n.d.ts +0 -39
  99. package/dist/iii/client.d.ts +0 -2
  100. package/dist/iii/index.d.ts +0 -4
  101. package/dist/iii/register-worker.d.ts +0 -9
  102. package/dist/iii/rest.d.ts +0 -3
  103. package/dist/iii/stream.d.ts +0 -82
  104. package/dist/iii/types.d.ts +0 -121
  105. package/dist/iii/worker.d.ts +0 -2
  106. package/dist/iii/ws.d.ts +0 -22
  107. package/dist/index.d.ts +0 -101
  108. package/dist/index.js +0 -12752
  109. package/dist/kb/index.d.ts +0 -3
  110. package/dist/kb/types.d.ts +0 -72
  111. package/dist/layout.d.ts +0 -2
  112. package/dist/live.d.ts +0 -7
  113. package/dist/logdb/client.d.ts +0 -2
  114. package/dist/logdb/index.d.ts +0 -2
  115. package/dist/logdb/rest.d.ts +0 -5
  116. package/dist/logdb/types.d.ts +0 -27
  117. package/dist/logger.d.ts +0 -16
  118. package/dist/mailer.d.ts +0 -51
  119. package/dist/mcp.d.ts +0 -34
  120. package/dist/messager/agent.d.ts +0 -11
  121. package/dist/messager/client.d.ts +0 -2
  122. package/dist/messager/index.d.ts +0 -2
  123. package/dist/messager/rest.d.ts +0 -15
  124. package/dist/messager/types.d.ts +0 -57
  125. package/dist/messager/ws.d.ts +0 -14
  126. package/dist/module-server.d.ts +0 -9
  127. package/dist/not-found.d.ts +0 -2
  128. package/dist/notifier/client.d.ts +0 -2
  129. package/dist/notifier/index.d.ts +0 -2
  130. package/dist/notifier/types.d.ts +0 -105
  131. package/dist/opencode/client.d.ts +0 -2
  132. package/dist/opencode/index.d.ts +0 -2
  133. package/dist/opencode/permissions.d.ts +0 -5
  134. package/dist/opencode/prompt.d.ts +0 -8
  135. package/dist/opencode/rest.d.ts +0 -16
  136. package/dist/opencode/run.d.ts +0 -13
  137. package/dist/opencode/session.d.ts +0 -26
  138. package/dist/opencode/skills.d.ts +0 -4
  139. package/dist/opencode/tools/bash.d.ts +0 -6
  140. package/dist/opencode/tools/edit.d.ts +0 -19
  141. package/dist/opencode/tools/glob.d.ts +0 -9
  142. package/dist/opencode/tools/grep.d.ts +0 -17
  143. package/dist/opencode/tools/index.d.ts +0 -12
  144. package/dist/opencode/tools/question.d.ts +0 -5
  145. package/dist/opencode/tools/read.d.ts +0 -16
  146. package/dist/opencode/tools/skill.d.ts +0 -18
  147. package/dist/opencode/tools/web.d.ts +0 -18
  148. package/dist/opencode/tools/write.d.ts +0 -13
  149. package/dist/opencode/types.d.ts +0 -90
  150. package/dist/opencode/ws.d.ts +0 -21
  151. package/dist/permissions.d.ts +0 -51
  152. package/dist/postgres/client.d.ts +0 -4
  153. package/dist/postgres/index.d.ts +0 -4
  154. package/dist/postgres/module.d.ts +0 -17
  155. package/dist/postgres/schema/columns.d.ts +0 -99
  156. package/dist/postgres/schema/index.d.ts +0 -6
  157. package/dist/postgres/schema/sql.d.ts +0 -22
  158. package/dist/postgres/schema/table.d.ts +0 -141
  159. package/dist/postgres/schema/where.d.ts +0 -29
  160. package/dist/postgres/types.d.ts +0 -50
  161. package/dist/queue/index.d.ts +0 -2
  162. package/dist/queue/types.d.ts +0 -62
  163. package/dist/rate-limit.d.ts +0 -45
  164. package/dist/react.d.ts +0 -14
  165. package/dist/react.js +0 -751
  166. package/dist/redis/client.d.ts +0 -2
  167. package/dist/redis/types.d.ts +0 -18
  168. package/dist/request-id.d.ts +0 -40
  169. package/dist/router.d.ts +0 -73
  170. package/dist/s3.d.ts +0 -68
  171. package/dist/seo.d.ts +0 -104
  172. package/dist/serve.d.ts +0 -38
  173. package/dist/server-registry.d.ts +0 -10
  174. package/dist/session.d.ts +0 -117
  175. package/dist/sse.d.ts +0 -47
  176. package/dist/ssr-entries.d.ts +0 -4
  177. package/dist/ssr.d.ts +0 -11
  178. package/dist/static.d.ts +0 -23
  179. package/dist/stream.d.ts +0 -24
  180. package/dist/tailwind.d.ts +0 -15
  181. package/dist/tenant/client.d.ts +0 -2
  182. package/dist/tenant/graphql.d.ts +0 -3
  183. package/dist/tenant/index.d.ts +0 -2
  184. package/dist/tenant/rest.d.ts +0 -3
  185. package/dist/tenant/schema.d.ts +0 -5
  186. package/dist/tenant/types.d.ts +0 -48
  187. package/dist/tenant/utils.d.ts +0 -9
  188. package/dist/test-utils.d.ts +0 -194
  189. package/dist/theme.d.ts +0 -31
  190. package/dist/trace.d.ts +0 -95
  191. package/dist/tsx-context.d.ts +0 -32
  192. package/dist/types.d.ts +0 -47
  193. package/dist/upload.d.ts +0 -55
  194. package/dist/use-action.d.ts +0 -42
  195. package/dist/use-agent-stream.d.ts +0 -49
  196. package/dist/use-flash-message.d.ts +0 -17
  197. package/dist/use-websocket.d.ts +0 -42
  198. package/dist/user/client.d.ts +0 -30
  199. package/dist/user/index.d.ts +0 -2
  200. package/dist/user/oauth-login.d.ts +0 -21
  201. package/dist/user/oauth2.d.ts +0 -31
  202. package/dist/user/types.d.ts +0 -178
  203. package/dist/validate.d.ts +0 -32
  204. package/dist/vendor.d.ts +0 -7
  205. package/dist/webhook.d.ts +0 -79
  206. package/opencode/ui/app/globals.css +0 -1
  207. package/opencode/ui/app/layout.tsx +0 -13
  208. package/opencode/ui/app/page.tsx +0 -523
@@ -1,30 +0,0 @@
1
- import type { UserOptions, UserData, UserModule } from './types.ts';
2
- declare module '../types.ts' {
3
- interface Context {
4
- user: UserData;
5
- }
6
- }
7
- /**
8
- * User authentication module — local register/login, JWT verification, OAuth2 server, social login.
9
- * Supports DB-less auth via tokens/verify/proxy options.
10
- *
11
- * ```ts
12
- * // Full auth with DB
13
- * import { user, postgres } from 'weifuwu'
14
- * const pg = postgres({ connection: DATABASE_URL })
15
- * const auth = user({ pg, jwtSecret: process.env.JWT_SECRET })
16
- *
17
- * await auth.migrate()
18
- * app.use(auth.middleware()) // inject ctx.user
19
- * app.use('/', auth) // /register, /login
20
- *
21
- * // DB-less token auth
22
- * const auth = user({ tokens: ['sk-123', 'sk-456'] })
23
- * app.use(auth.middleware()) // injects ctx.user for valid tokens
24
- *
25
- * // DB-less custom verify
26
- * const auth = user({ verify: async (token) => validateToken(token) })
27
- * app.use(auth.middleware())
28
- * ```
29
- */
30
- export declare function user(options: UserOptions): UserModule;
@@ -1,2 +0,0 @@
1
- export { user } from './client.ts';
2
- export type { UserOptions, UserData, UserModule, AuthResult, OAuth2Client, OAuthProviderConfig, UserInjected, } from './types.ts';
@@ -1,21 +0,0 @@
1
- import type { SqlClient } from '../vendor.ts';
2
- import type { Router } from '../router.ts';
3
- import type { OAuthProviderConfig } from './types.ts';
4
- interface OAuthLoginDeps {
5
- sql: SqlClient;
6
- jwtSecret: string;
7
- expiresIn: string | number;
8
- usersTable: string;
9
- /** Table for provider-user link, derived from usersTable. */
10
- providerTable: string;
11
- redirectUrl: string;
12
- signToken: (user: Record<string, unknown>) => string;
13
- /** Create a placeholder user for OAuth login (no password). */
14
- createPlaceholderUser: (email: string, name: string) => Promise<Record<string, unknown>>;
15
- /** Find user by internal ID. */
16
- findUserById: (id: number) => Promise<Record<string, unknown> | undefined>;
17
- /** Find user by email. */
18
- findUserByEmail: (email: string) => Promise<Record<string, unknown> | undefined>;
19
- }
20
- export declare function registerOAuthLoginRoutes(router: Router, deps: OAuthLoginDeps, providers: Record<string, OAuthProviderConfig>): void;
21
- export {};
@@ -1,31 +0,0 @@
1
- import type { Context } from '../types.ts';
2
- import type { OAuth2Client } from './types.ts';
3
- import type { BoundTable } from '../postgres/schema/index.ts';
4
- interface OAuth2Deps {
5
- pg: any;
6
- users: BoundTable<any>;
7
- jwtSecret: string;
8
- expiresIn: string | number;
9
- }
10
- /**
11
- * Create an OAuth2 authorization code server.
12
- *
13
- * Registers routes:
14
- * - `GET /oauth/authorize` — authorization page (user consent)
15
- * - `POST /oauth/consent` — user grants/denies access
16
- * - `POST /oauth/token` — exchange code for access token
17
- *
18
- * Used internally by the user module when `oauth2: { server: true }` is set.
19
- */
20
- export declare function createOAuth2Server(deps: OAuth2Deps): {
21
- authorizeHandler: (req: Request, _ctx: Context) => Promise<Response>;
22
- consentHandler: (req: Request) => Promise<Response>;
23
- tokenHandler: (req: Request) => Promise<Response>;
24
- registerClient: (data: {
25
- name: string;
26
- redirectUris: string[];
27
- }) => Promise<OAuth2Client>;
28
- getClient: (clientId: string) => Promise<OAuth2Client | null>;
29
- revokeClient: (clientId: string) => Promise<void>;
30
- };
31
- export {};
@@ -1,178 +0,0 @@
1
- import type { Middleware, Context, Closeable } from '../types.ts';
2
- import type { Router } from '../router.ts';
3
- import type { PostgresClient } from '../postgres/types.ts';
4
- /** A user record from the database. */
5
- export interface UserData {
6
- id: number;
7
- email: string;
8
- name: string;
9
- role: string;
10
- created_at: Date;
11
- updated_at: Date;
12
- }
13
- /** Result of a successful register or login. */
14
- export interface AuthResult {
15
- /** User data (excluding password hash). */
16
- user: Omit<UserData, 'password'>;
17
- /** Signed JWT token. */
18
- token: string;
19
- }
20
- /** An OAuth2 client application registered with the server. */
21
- export interface OAuth2Client {
22
- id: number;
23
- name: string;
24
- clientId: string;
25
- clientSecret: string;
26
- redirectUris: string[];
27
- scopes: string;
28
- }
29
- /** Enable OAuth2 server mode (authorization code flow). */
30
- export interface OAuth2ServerOptions {
31
- server: true;
32
- }
33
- /** Configuration for an OAuth login provider (e.g. GitHub, Google). */
34
- export interface OAuthProviderConfig {
35
- /** OAuth app client ID. */
36
- clientId: string;
37
- /** OAuth app client secret. */
38
- clientSecret: string;
39
- /** Scopes to request (default: `'openid profile email'`). */
40
- scope?: string;
41
- /** Custom auth URL (overrides built-in provider default). */
42
- authUrl?: string;
43
- /** Custom token URL (overrides built-in provider default). */
44
- tokenUrl?: string;
45
- /** Custom user info URL (overrides built-in provider default). */
46
- userUrl?: string;
47
- /**
48
- * Custom user parser.
49
- * Required when any of `authUrl`/`tokenUrl`/`userUrl` is custom.
50
- * Receives the raw response from `userUrl` + the access token.
51
- */
52
- parseUser?: (data: any, accessToken: string) => {
53
- id: string;
54
- email: string;
55
- name: string;
56
- avatarUrl?: string;
57
- };
58
- }
59
- /** Options for {@link user}. */
60
- export interface UserOptions {
61
- /** PostgreSQL client for user storage. Omit for DB-less token/verify/proxy auth. */
62
- pg?: PostgresClient;
63
- /** Secret key for JWT signing. Required for JWT auth and login/register routes. */
64
- jwtSecret?: string;
65
- /** Custom table name for users (default: `'users'`). */
66
- table?: string;
67
- /** JWT expiration time (default: `'7d'`). */
68
- expiresIn?: string | number;
69
- /** Static token(s) for simple bearer auth. No DB or JWT needed. */
70
- tokens?: string[];
71
- /** Custom verify function. Receives the token and request, returns user data or null. */
72
- verify?: (token: string, req: Request) => unknown | Promise<unknown>;
73
- /** Proxy auth — forward request to an external auth service for validation. */
74
- proxy?: string | URL;
75
- /** Custom header name for token extraction (default: `'Authorization'`). */
76
- header?: string;
77
- /**
78
- * Function to load user data from a user ID stored in the session.
79
- * Called when `ctx.session.userId` is present. Only used when `pg` is not provided.
80
- * Return a falsy value to reject (e.g. if the user was deleted).
81
- * If not provided and no pg, `ctx.user` is set to `{ id: userId }`.
82
- */
83
- resolveUser?: (userId: unknown) => unknown | Promise<unknown>;
84
- /** Enable API key management (per-user keys with scopes). */
85
- apiKeys?: boolean;
86
- /** Enable OAuth2 server mode (authorization code flow). */
87
- oauth2?: OAuth2ServerOptions;
88
- /**
89
- * OAuth login providers (login with GitHub/Google).
90
- * Registers `GET /auth/:provider` and `GET /auth/:provider/callback` routes.
91
- */
92
- oauthLogin?: {
93
- /** Map of provider name to config (e.g. `{ github: {...}, google: {...} }`). */
94
- providers: Record<string, OAuthProviderConfig>;
95
- /** Redirect URL after successful login (default: `'/'`). */
96
- redirectUrl?: string;
97
- };
98
- }
99
- /** The shape of `ctx.user` when the user middleware is active. */
100
- export interface UserInjected {
101
- user: UserData;
102
- }
103
- /**
104
- * User module returned by {@link user}. Provides auth routes, middleware, and programmatic API.
105
- *
106
- * ```ts
107
- * const auth = user({ pg, jwtSecret: process.env.JWT_SECRET })
108
- * app.use(auth.middleware()) // injects ctx.user on every request
109
- * app.use('/', auth) // mounts routes: /register, /login
110
- * ```
111
- */
112
- export interface UserModule extends Router, Closeable {
113
- /**
114
- * Strict auth middleware. Reads JWT from `Authorization: Bearer` header.
115
- * Returns 401 if no valid token is found.
116
- * Use for routes that require authentication.
117
- */
118
- middleware: () => Middleware<Context, Context & UserInjected>;
119
- /**
120
- * Optional auth middleware. Reads JWT from `Authorization` header or `token` cookie.
121
- * Sets `ctx.user` if a valid token is present, but does **not** block unauthenticated requests.
122
- * Use as a global middleware when some routes are public and some are protected.
123
- *
124
- * ```ts
125
- * app.use(auth.middlewareOptional({ cookie: 'token' }))
126
- * app.get('/profile', auth.middleware(), handler) // protected
127
- * app.get('/', handler) // public
128
- * ```
129
- */
130
- middlewareOptional: (opts?: {
131
- cookie?: string;
132
- }) => Middleware;
133
- /** Create the users table. */
134
- migrate: () => Promise<void>;
135
- /** Register a new user. Returns user data + JWT. */
136
- register: (data: {
137
- email: string;
138
- password: string;
139
- name: string;
140
- }) => Promise<AuthResult>;
141
- /** Authenticate by email + password. Returns user data + JWT. */
142
- login: (data: {
143
- email: string;
144
- password: string;
145
- }) => Promise<AuthResult>;
146
- /** Verify a JWT and return the user data (or null if invalid). */
147
- verify: (token: string) => Promise<Omit<UserData, 'password'> | null>;
148
- /** Register a new OAuth2 client application. */
149
- registerClient: (data: {
150
- name: string;
151
- redirectUris: string[];
152
- }) => Promise<OAuth2Client>;
153
- /** Look up an OAuth2 client by clientId. */
154
- getClient: (clientId: string) => Promise<OAuth2Client | null>;
155
- /** Revoke an OAuth2 client. */
156
- revokeClient: (clientId: string) => Promise<void>;
157
- /** Create a new API key for a user. Returns the full key (only shown once). */
158
- createApiKey: (userId: number, name: string, scopes?: string[]) => Promise<{
159
- id: number;
160
- key: string;
161
- }>;
162
- /** List user\'s API keys (masked — only prefix + last 4 chars visible). */
163
- listApiKeys: (userId: number) => Promise<ApiKeyInfo[]>;
164
- /** Revoke an API key by ID. */
165
- revokeApiKey: (userId: number, keyId: number) => Promise<void>;
166
- /** Close the underlying DB connection. */
167
- close: () => Promise<void>;
168
- }
169
- /** An API key record (as returned by listApiKeys — masked). */
170
- export interface ApiKeyInfo {
171
- id: number;
172
- name: string;
173
- prefix: string;
174
- scopes: string[];
175
- last_used_at: string | null;
176
- created_at: string;
177
- revoked: boolean;
178
- }
@@ -1,32 +0,0 @@
1
- import type { ZodSchema } from 'zod';
2
- import type { Middleware } from './types.ts';
3
- declare module './types.ts' {
4
- interface Context {
5
- parsed: Record<string, unknown>;
6
- }
7
- }
8
- /** Validation middleware — a {@link Middleware} that injects `ctx.parsed` with validated data. */
9
- export type ValidateModule = Middleware;
10
- export interface ValidationSchemas {
11
- body?: ZodSchema;
12
- query?: ZodSchema;
13
- params?: ZodSchema;
14
- headers?: ZodSchema;
15
- }
16
- /**
17
- * Request validation middleware using Zod schemas.
18
- *
19
- * Validates `params`, `query`, `body`, and/or `headers` against schemas.
20
- * Returns 422 with error details on mismatch.
21
- * Injects `ctx.parsed` with validated-and-transformed values.
22
- *
23
- * ```ts
24
- * import { z } from 'zod'
25
- *
26
- * app.get('/users/:id', validate({
27
- * params: z.object({ id: z.string() }),
28
- * query: z.object({ include: z.string().optional() }),
29
- * }), handler)
30
- * ```
31
- */
32
- export declare function validate(schemas?: ValidationSchemas): Middleware;
package/dist/vendor.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type postgres from 'postgres';
2
- /** Untyped postgres.js SQL client. Use typed `Sql<{ table: { col: type } }>` for schemas. */
3
- export type SqlClient = postgres.Sql<Record<string, unknown>>;
4
- /** Re-export for downstream usage. */
5
- export type { Sql } from 'postgres';
6
- export type { WebSocket } from 'ws';
7
- export type { Redis, RedisOptions } from 'ioredis';
package/dist/webhook.d.ts DELETED
@@ -1,79 +0,0 @@
1
- import type { Context } from './types.ts';
2
- import { Router } from './router.ts';
3
- /** A parsed webhook event delivered to handlers. */
4
- export interface WebhookEvent {
5
- /** Raw event name from the provider (e.g. 'checkout.session.completed'). */
6
- event: string;
7
- /** Parsed event payload (body after verification). */
8
- payload: unknown;
9
- /** Provider name (e.g. 'stripe', 'github'). */
10
- provider: string;
11
- /** Unique event ID for replay protection. */
12
- id?: string;
13
- }
14
- /** Handler function for a webhook event. */
15
- export interface WebhookHandler {
16
- (event: WebhookEvent, ctx: Context): void | Promise<void>;
17
- }
18
- /** Configuration for a built-in platform webhook verifier (Stripe, GitHub, Slack). */
19
- export interface PlatformConfig {
20
- /** HMAC-SHA256 signing secret. */
21
- secret: string;
22
- /** Optional event prefix (default: platform name, e.g. 'stripe'). */
23
- prefix?: string;
24
- }
25
- /** Configuration for a custom webhook verifier. */
26
- export interface CustomVerifierConfig {
27
- /** Name for this verifier. */
28
- name: string;
29
- /** Verify function. Return true if signature is valid. */
30
- verify: (body: string, headers: Record<string, string>) => boolean | Promise<boolean>;
31
- /** Extract event name from body and headers */
32
- event: (body: unknown, headers: Record<string, string>) => string;
33
- }
34
- /** Options for {@link webhook}. */
35
- export interface WebhookOptions {
36
- /** Stripe webhook config (enables Stripe signature verification). */
37
- stripe?: PlatformConfig;
38
- /** GitHub webhook config. */
39
- github?: PlatformConfig;
40
- /** Slack webhook config. */
41
- slack?: PlatformConfig;
42
- /** Custom verifiers. */
43
- custom?: CustomVerifierConfig[];
44
- /** Global prefix for all event types (default: none). */
45
- prefix?: string;
46
- /** Path to mount the webhook receiver. Default: `'/'`. */
47
- path?: string;
48
- /** Enable replay protection (requires provider to send unique event IDs). Default: true. */
49
- replayProtection?: boolean;
50
- /** Idempotency key TTL in ms. Default: 3600000 (1 hour). */
51
- idempotencyTTL?: number;
52
- }
53
- /** Webhook module instance returned by {@link webhook}. */
54
- export interface WebhookModule extends Router {
55
- /** Register an event handler. */
56
- on(event: string, handler: WebhookHandler): this;
57
- /** Remove an event handler. */
58
- off(event: string, handler: WebhookHandler): this;
59
- }
60
- /**
61
- * Webhook receiver module. Validates signatures and dispatches events.
62
- *
63
- * Supports built-in verifiers for Stripe, GitHub, and Slack, plus custom verifiers.
64
- *
65
- * ```ts
66
- * import { webhook } from 'weifuwu'
67
- *
68
- * const wh = webhook({
69
- * stripe: { secret: process.env.STRIPE_WEBHOOK_SECRET },
70
- * })
71
- *
72
- * wh.on('checkout.session.completed', async (event, ctx) => {
73
- * // event.payload contains the parsed Stripe event
74
- * })
75
- *
76
- * app.use('/', wh)
77
- * ```
78
- */
79
- export declare function webhook(options?: WebhookOptions): WebhookModule;
@@ -1 +0,0 @@
1
- @import 'tailwindcss';
@@ -1,13 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- export default function RootLayout({ children }: { children: any }) {
3
- return (
4
- <html lang="en">
5
- <head>
6
- <meta charSet="utf-8" />
7
- <meta name="viewport" content="width=device-width, initial-scale=1" />
8
- <title>Opencode Chat</title>
9
- </head>
10
- <body>{children}</body>
11
- </html>
12
- )
13
- }