@convex-dev/better-auth 0.8.0-alpha.4 → 0.8.0-alpha.6

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.
@@ -1,297 +0,0 @@
1
- /**
2
- * This file defines a CorsHttpRouter class that extends Convex's HttpRouter.
3
- * It provides CORS (Cross-Origin Resource Sharing) support for HTTP routes.
4
- *
5
- * The CorsHttpRouter:
6
- * 1. Allows specifying allowed origins for CORS.
7
- * 2. Overrides the route method to add CORS headers to all non-OPTIONS requests.
8
- * 3. Automatically adds an OPTIONS route to handle CORS preflight requests.
9
- * 4. Uses the handleCors helper function to apply CORS headers consistently.
10
- *
11
- * This router simplifies the process of making Convex HTTP endpoints
12
- * accessible to web applications hosted on different domains while
13
- * maintaining proper CORS configuration.
14
- */
15
- import { httpActionGeneric, httpRouter, ROUTABLE_HTTP_METHODS, } from "convex/server";
16
- export const DEFAULT_EXPOSED_HEADERS = [
17
- // For Range requests
18
- "Content-Range",
19
- "Accept-Ranges",
20
- ];
21
- /**
22
- * Factory function to create a router that adds CORS support to routes.
23
- * @param allowedOrigins An array of allowed origins for CORS.
24
- * @returns A function to use instead of http.route when you want CORS.
25
- */
26
- export const corsRouter = (http, corsConfig) => {
27
- const allowedExactMethodsByPath = new Map();
28
- const allowedPrefixMethodsByPath = new Map();
29
- return {
30
- http,
31
- route: (routeSpec) => {
32
- const tempRouter = httpRouter();
33
- tempRouter.exactRoutes = http.exactRoutes;
34
- tempRouter.prefixRoutes = http.prefixRoutes;
35
- const config = {
36
- ...corsConfig,
37
- ...routeSpec,
38
- };
39
- const httpCorsHandler = handleCors({
40
- originalHandler: routeSpec.handler,
41
- allowedMethods: [routeSpec.method],
42
- ...config,
43
- });
44
- /**
45
- * Figure out what kind of route we're adding: exact or prefix and handle
46
- * accordingly.
47
- */
48
- if ("path" in routeSpec) {
49
- let methods = allowedExactMethodsByPath.get(routeSpec.path);
50
- if (!methods) {
51
- methods = new Set();
52
- allowedExactMethodsByPath.set(routeSpec.path, methods);
53
- }
54
- methods.add(routeSpec.method);
55
- tempRouter.route({
56
- path: routeSpec.path,
57
- method: routeSpec.method,
58
- handler: httpCorsHandler,
59
- });
60
- handleExactRoute(tempRouter, routeSpec, config, Array.from(methods));
61
- }
62
- else {
63
- let methods = allowedPrefixMethodsByPath.get(routeSpec.pathPrefix);
64
- if (!methods) {
65
- methods = new Set();
66
- allowedPrefixMethodsByPath.set(routeSpec.pathPrefix, methods);
67
- }
68
- methods.add(routeSpec.method);
69
- tempRouter.route({
70
- pathPrefix: routeSpec.pathPrefix,
71
- method: routeSpec.method,
72
- handler: httpCorsHandler,
73
- });
74
- handlePrefixRoute(tempRouter, routeSpec, config, Array.from(methods));
75
- }
76
- /**
77
- * Copy the routes from the temporary router to the main router.
78
- */
79
- http.exactRoutes = new Map(tempRouter.exactRoutes);
80
- http.prefixRoutes = new Map(tempRouter.prefixRoutes);
81
- },
82
- };
83
- };
84
- /**
85
- * Handles exact route matching and adds OPTIONS handler.
86
- * @param tempRouter Temporary router instance.
87
- * @param routeSpec Route specification for exact matching.
88
- */
89
- function handleExactRoute(tempRouter, routeSpec, config, allowedMethods) {
90
- const currentMethodsForPath = tempRouter.exactRoutes.get(routeSpec.path);
91
- /**
92
- * Add the OPTIONS handler for the given path
93
- */
94
- const optionsHandler = createOptionsHandlerForMethods(allowedMethods, config);
95
- currentMethodsForPath?.set("OPTIONS", optionsHandler);
96
- tempRouter.exactRoutes.set(routeSpec.path, new Map(currentMethodsForPath));
97
- }
98
- /**
99
- * Handles prefix route matching and adds OPTIONS handler.
100
- * @param tempRouter Temporary router instance.
101
- * @param routeSpec Route specification for prefix matching.
102
- */
103
- function handlePrefixRoute(tempRouter, routeSpec, config, allowedMethods) {
104
- /**
105
- * prefixRoutes is structured differently than exactRoutes. It's defined as
106
- * a Map<string, Map<string, PublicHttpAction>> where the KEY is the
107
- * METHOD and the VALUE is a map of paths and handlers.
108
- */
109
- const optionsHandler = createOptionsHandlerForMethods(allowedMethods, config);
110
- const optionsPrefixes = tempRouter.prefixRoutes.get("OPTIONS") ||
111
- new Map();
112
- optionsPrefixes.set(routeSpec.pathPrefix, optionsHandler);
113
- tempRouter.prefixRoutes.set("OPTIONS", optionsPrefixes);
114
- }
115
- /**
116
- * Creates an OPTIONS handler for the given HTTP methods.
117
- * @param methods Array of HTTP methods to be allowed.
118
- * @returns A CORS-enabled OPTIONS handler.
119
- */
120
- function createOptionsHandlerForMethods(methods, config) {
121
- return handleCors({
122
- ...config,
123
- allowedMethods: methods,
124
- });
125
- }
126
- export default corsRouter;
127
- /**
128
- * handleCors() is a higher-order function that wraps a Convex HTTP action handler to add CORS support.
129
- * It allows for customization of allowed HTTP methods and origins for cross-origin requests.
130
- *
131
- * The function:
132
- * 1. Validates and normalizes the allowed HTTP methods.
133
- * 2. Generates appropriate CORS headers based on the provided configuration.
134
- * 3. Handles preflight OPTIONS requests automatically.
135
- * 4. Wraps the original handler to add CORS headers to its response.
136
- *
137
- * This helper simplifies the process of making Convex HTTP actions accessible
138
- * to web applications hosted on different domains.
139
- */
140
- const SECONDS_IN_A_DAY = 60 * 60 * 24;
141
- /**
142
- * Example CORS origins:
143
- * - "*" (allow all origins)
144
- * - "https://example.com" (allow a specific domain)
145
- * - "https://*.example.com" (allow all subdomains of example.com)
146
- * - "https://example1.com, https://example2.com" (allow multiple specific domains)
147
- * - "null" (allow requests from data URLs or local files)
148
- */
149
- const handleCors = ({ originalHandler, allowedMethods = ["OPTIONS"], allowedOrigins = ["*"], allowedHeaders = ["Content-Type"], exposedHeaders = DEFAULT_EXPOSED_HEADERS, allowCredentials = false, browserCacheMaxAge = SECONDS_IN_A_DAY, enforceAllowOrigins = true, debug = false, }) => {
150
- const uniqueMethods = Array.from(new Set(allowedMethods.map((method) => method.toUpperCase())));
151
- const filteredMethods = uniqueMethods.filter((method) => ROUTABLE_HTTP_METHODS.includes(method));
152
- if (filteredMethods.length === 0) {
153
- throw new Error("No valid HTTP methods provided");
154
- }
155
- /**
156
- * Ensure OPTIONS is not duplicated if it was passed in
157
- * E.g. if allowedMethods = ["GET", "OPTIONS"]
158
- */
159
- const allowMethods = filteredMethods.includes("OPTIONS")
160
- ? filteredMethods.join(", ")
161
- : [...filteredMethods].join(", ");
162
- /**
163
- * Build up the set of CORS headers
164
- */
165
- const commonHeaders = {
166
- Vary: "Origin",
167
- };
168
- if (allowCredentials) {
169
- commonHeaders["Access-Control-Allow-Credentials"] = "true";
170
- }
171
- if (exposedHeaders.length > 0) {
172
- commonHeaders["Access-Control-Expose-Headers"] = exposedHeaders.join(", ");
173
- }
174
- async function parseAllowedOrigins(request) {
175
- return Array.isArray(allowedOrigins)
176
- ? allowedOrigins
177
- : await allowedOrigins(request);
178
- }
179
- // Helper function to check if origin is allowed (including wildcard subdomain matching)
180
- async function isAllowedOrigin(request) {
181
- const requestOrigin = request.headers.get("origin");
182
- if (!requestOrigin)
183
- return false;
184
- return (await parseAllowedOrigins(request)).some((allowed) => {
185
- if (allowed === "*")
186
- return true;
187
- if (allowed === requestOrigin)
188
- return true;
189
- if (allowed.startsWith("*.")) {
190
- const wildcardDomain = allowed.slice(1); // ".bar.com"
191
- const rootDomain = allowed.slice(2); // "bar.com"
192
- try {
193
- const url = new URL(requestOrigin);
194
- return (url.protocol === "https:" &&
195
- (url.hostname.endsWith(wildcardDomain) ||
196
- url.hostname === rootDomain));
197
- }
198
- catch {
199
- return false; // Invalid URL format
200
- }
201
- }
202
- return false;
203
- });
204
- }
205
- /**
206
- * Return our modified HTTP action
207
- */
208
- return httpActionGeneric(async (ctx, request) => {
209
- if (debug) {
210
- console.log("CORS request", {
211
- path: request.url,
212
- origin: request.headers.get("origin"),
213
- headers: request.headers,
214
- method: request.method,
215
- body: request.body,
216
- });
217
- }
218
- const requestOrigin = request.headers.get("origin");
219
- const parsedAllowedOrigins = await parseAllowedOrigins(request);
220
- if (debug) {
221
- console.log("allowed origins", parsedAllowedOrigins);
222
- }
223
- // Handle origin matching
224
- let allowOrigins = null;
225
- if (parsedAllowedOrigins.includes("*") && !allowCredentials) {
226
- allowOrigins = "*";
227
- }
228
- else if (requestOrigin) {
229
- // Check if the request origin matches any of the allowed origins
230
- // (including wildcard subdomain matching if configured)
231
- if (await isAllowedOrigin(request)) {
232
- allowOrigins = requestOrigin;
233
- }
234
- }
235
- if (enforceAllowOrigins && !allowOrigins) {
236
- // Origin not allowed
237
- console.error(`Request from origin ${requestOrigin} blocked, missing from allowed origins: ${parsedAllowedOrigins.join()}`);
238
- return new Response(null, { status: 403 });
239
- }
240
- /**
241
- * OPTIONS has no handler and just returns headers
242
- */
243
- if (request.method === "OPTIONS") {
244
- const responseHeaders = new Headers({
245
- ...commonHeaders,
246
- "Access-Control-Allow-Origin": allowOrigins ?? "",
247
- "Access-Control-Allow-Methods": allowMethods,
248
- "Access-Control-Allow-Headers": allowedHeaders.join(", "),
249
- "Access-Control-Max-Age": browserCacheMaxAge.toString(),
250
- });
251
- if (debug) {
252
- console.log("CORS OPTIONS response headers", responseHeaders);
253
- }
254
- return new Response(null, {
255
- status: 204,
256
- headers: responseHeaders,
257
- });
258
- }
259
- /**
260
- * If the method is not OPTIONS, it must pass a handler
261
- */
262
- if (!originalHandler) {
263
- throw new Error("No PublicHttpAction provider to CORS handler");
264
- }
265
- /**
266
- * First, execute the original handler
267
- */
268
- const innerHandler = ("_handler" in originalHandler
269
- ? originalHandler["_handler"]
270
- : originalHandler);
271
- const originalResponse = await innerHandler(ctx, request);
272
- /**
273
- * Second, get a copy of the original response's headers
274
- */
275
- const newHeaders = new Headers(originalResponse.headers);
276
- newHeaders.set("Access-Control-Allow-Origin", allowOrigins ?? "");
277
- /**
278
- * Third, add or update our CORS headers
279
- */
280
- Object.entries(commonHeaders).forEach(([key, value]) => {
281
- newHeaders.set(key, value);
282
- });
283
- if (debug) {
284
- console.log("CORS response headers", newHeaders);
285
- }
286
- /**
287
- * Fourth, return the modified Response.
288
- * A Response object is immutable, so we create a new one to return here.
289
- */
290
- return new Response(originalResponse.body, {
291
- status: originalResponse.status,
292
- statusText: originalResponse.statusText,
293
- headers: newHeaders,
294
- });
295
- });
296
- };
297
- //# sourceMappingURL=cors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../../src/client/cors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAEL,iBAAiB,EACjB,UAAU,EAEV,qBAAqB,GAMtB,MAAM,eAAe,CAAC;AAEvB,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,qBAAqB;IACrB,eAAe;IACf,eAAe;CAChB,CAAC;AAsDF;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAgB,EAAE,UAAuB,EAAE,EAAE;IACtE,MAAM,yBAAyB,GAA6B,IAAI,GAAG,EAAE,CAAC;IACtE,MAAM,0BAA0B,GAA6B,IAAI,GAAG,EAAE,CAAC;IACvE,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,CAAC,SAA4B,EAAQ,EAAE;YAC5C,MAAM,UAAU,GAAG,UAAU,EAAE,CAAC;YAChC,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;YAC1C,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;YAE5C,MAAM,MAAM,GAAG;gBACb,GAAG,UAAU;gBACb,GAAG,SAAS;aACb,CAAC;YAEF,MAAM,eAAe,GAAG,UAAU,CAAC;gBACjC,eAAe,EAAE,SAAS,CAAC,OAAO;gBAClC,cAAc,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC;gBAClC,GAAG,MAAM;aACV,CAAC,CAAC;YACH;;;eAGG;YACH,IAAI,MAAM,IAAI,SAAS,EAAE,CAAC;gBACxB,IAAI,OAAO,GAAG,yBAAyB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBAC5D,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,OAAO,GAAG,IAAI,GAAG,EAAU,CA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AAC,CAAC;QACnD,CAAC;QAED;;;WAGG;QACH,OAAO,IAAI,QAAQ,CAAC,gBAAgB,CAAC,IAAI,EAAE;YACzC,MAAM,EAAE,gBAAgB,CAAC,MAAM;YAC/B,UAAU,EAAE,gBAAgB,CAAC,UAAU;YACvC,OAAO,EAAE,UAAU;SACpB,CAAC,CAAC;IACL,CAAC,CACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const requireEnv: (name: string) => string;
2
- //# sourceMappingURL=util.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,WAMtC,CAAC"}
@@ -1,8 +0,0 @@
1
- export const requireEnv = (name) => {
2
- const value = process.env[name];
3
- if (value === undefined) {
4
- throw new Error(`Missing environment variable \`${name}\``);
5
- }
6
- return value;
7
- };
8
- //# sourceMappingURL=util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,IAAI,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -1,77 +0,0 @@
1
- /**
2
- * This file defines a CorsHttpRouter class that extends Convex's HttpRouter.
3
- * It provides CORS (Cross-Origin Resource Sharing) support for HTTP routes.
4
- *
5
- * The CorsHttpRouter:
6
- * 1. Allows specifying allowed origins for CORS.
7
- * 2. Overrides the route method to add CORS headers to all non-OPTIONS requests.
8
- * 3. Automatically adds an OPTIONS route to handle CORS preflight requests.
9
- * 4. Uses the handleCors helper function to apply CORS headers consistently.
10
- *
11
- * This router simplifies the process of making Convex HTTP endpoints
12
- * accessible to web applications hosted on different domains while
13
- * maintaining proper CORS configuration.
14
- */
15
- import { HttpRouter, type RouteSpec } from "convex/server";
16
- export declare const DEFAULT_EXPOSED_HEADERS: string[];
17
- export type CorsConfig = {
18
- /**
19
- * Whether to allow credentials in the request.
20
- * When true, the request can include cookies and authentication headers.
21
- * @default false
22
- */
23
- allowCredentials?: boolean;
24
- /**
25
- * An array of allowed origins: what domains are allowed to make requests.
26
- * For example, ["https://example.com"] would only allow requests from
27
- * https://example.com.
28
- * You can also use wildcards to allow all subdomains of a given domain.
29
- * E.g. ["*.example.com"] would allow requests from:
30
- * - https://subdomain.example.com
31
- * - https://example.com
32
- * @default ["*"]
33
- */
34
- allowedOrigins?: string[] | ((req: Request) => Promise<string[]>);
35
- /**
36
- * An array of allowed headers: what headers are allowed to be sent in
37
- * the request.
38
- * @default ["Content-Type"]
39
- */
40
- allowedHeaders?: string[];
41
- /**
42
- * An array of exposed headers: what headers are allowed to be sent in
43
- * the response.
44
- * Note: if you pass in an empty array, it will not expose any headers.
45
- * If you want to extend the default exposed headers, you can do so by
46
- * passing in [...DEFAULT_EXPOSED_HEADERS, ...yourHeaders].
47
- * @default {@link DEFAULT_EXPOSED_HEADERS}
48
- */
49
- exposedHeaders?: string[];
50
- /**
51
- * The maximum age of the preflight request in seconds.
52
- * @default 86400 (1 day)
53
- */
54
- browserCacheMaxAge?: number;
55
- /**
56
- * Whether to block requests from origins that are not in the allowedOrigins list.
57
- * @default true
58
- */
59
- enforceAllowOrigins?: boolean;
60
- /**
61
- * Whether to log debugging information about CORS requests.
62
- * @default false
63
- */
64
- debug?: boolean;
65
- };
66
- type RouteSpecWithCors = RouteSpec & CorsConfig;
67
- /**
68
- * Factory function to create a router that adds CORS support to routes.
69
- * @param allowedOrigins An array of allowed origins for CORS.
70
- * @returns A function to use instead of http.route when you want CORS.
71
- */
72
- export declare const corsRouter: (http: HttpRouter, corsConfig?: CorsConfig) => {
73
- http: HttpRouter;
74
- route: (routeSpec: RouteSpecWithCors) => void;
75
- };
76
- export default corsRouter;
77
- //# sourceMappingURL=cors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../../src/client/cors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAIL,UAAU,EAIV,KAAK,SAAS,EAGf,MAAM,eAAe,CAAC;AAEvB,eAAO,MAAM,uBAAuB,UAInC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;;;;;OASG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAClE;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,KAAK,iBAAiB,GAAG,SAAS,GAAG,UAAU,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,UAAU,EAAE,aAAa,UAAU;;uBAK7C,iBAAiB,KAAG,IAAI;CAsD9C,CAAC;AA+DF,eAAe,UAAU,CAAC"}