@c15t/backend 0.0.1-rc.16 → 0.0.1-rc.18

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,16 +1,16 @@
1
1
 
2
2
  
3
- > @c15t/backend@0.0.1-rc.16 build /Users/christopherburns/glados/k/c15t/packages/backend
3
+ > @c15t/backend@0.0.1-rc.18 build /Users/christopherburns/glados/k/c15t/packages/backend
4
4
  > rslib build
5
5
 
6
6
    Rslib v0.5.3
7
7
  
8
- ready  built in 0.36 s (esm)
9
- ready  built in 0.35 s (cjs)
8
+ ready  built in 0.31 s (esm)
9
+ ready  built in 0.32 s (cjs)
10
10
  start  Generating DTS... (esm)
11
11
  start  Generating DTS... (cjs)
12
- ready  DTS generated in 3.48 s (cjs)
13
- ready  DTS generated in 3.53 s (esm)
12
+ ready  DTS generated in 4.64 s (cjs)
13
+ ready  DTS generated in 4.70 s (esm)
14
14
 
15
15
   File (esm) Size 
16
16
  dist/pkgs/types/index.js 0.00 kB
@@ -18,7 +18,7 @@
18
18
  dist/pkgs/logger/index.js 7.2 kB
19
19
  dist/integrations/node.js 9.1 kB
20
20
  dist/integrations/next.js 9.6 kB
21
- dist/integrations/cloudflare.js 11.2 kB
21
+ dist/integrations/cloudflare.js 11.8 kB
22
22
  dist/pkgs/results/index.js 22.2 kB
23
23
  dist/pkgs/db-adapters/adapters/memory-adapter/index.js 49.4 kB
24
24
  dist/pkgs/db-adapters/adapters/prisma-adapter/index.js 52.6 kB
@@ -29,9 +29,9 @@
29
29
  dist/schema/index.js 74.9 kB
30
30
  dist/pkgs/data-model/index.js 75.6 kB
31
31
  dist/pkgs/db-adapters/index.js 94.3 kB
32
- dist/index.js 154.5 kB
32
+ dist/index.js 154.6 kB
33
33
 
34
- Total: 811.9 kB
34
+ Total: 812.6 kB
35
35
 
36
36
   -----
37
37
 
@@ -41,7 +41,7 @@
41
41
  dist/pkgs/logger/index.cjs 8.1 kB
42
42
  dist/integrations/node.cjs 10.2 kB
43
43
  dist/integrations/next.cjs 10.7 kB
44
- dist/integrations/cloudflare.cjs 12.3 kB
44
+ dist/integrations/cloudflare.cjs 12.9 kB
45
45
  dist/pkgs/results/index.cjs 23.1 kB
46
46
  dist/pkgs/db-adapters/adapters/memory-adapter/index.cjs 50.1 kB
47
47
  dist/pkgs/db-adapters/adapters/prisma-adapter/index.cjs 53.3 kB
@@ -52,7 +52,7 @@
52
52
  dist/schema/index.cjs 82.6 kB
53
53
  dist/pkgs/data-model/index.cjs 83.5 kB
54
54
  dist/pkgs/db-adapters/index.cjs 95.0 kB
55
- dist/index.cjs 168.2 kB
55
+ dist/index.cjs 168.3 kB
56
56
 
57
- Total: 860.3 kB
57
+ Total: 861.0 kB
58
58
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  
3
- > @c15t/backend@0.0.1-rc.15 fmt /Users/christopherburns/glados/k/c15t/packages/backend
3
+ > @c15t/backend@0.0.1-rc.17 fmt /Users/christopherburns/glados/k/c15t/packages/backend
4
4
  > pnpm biome format --write . && biome check --formatter-enabled=false --linter-enabled=false --organize-imports-enabled=true --write
5
5
 
6
- Formatted 167 files in 42ms. Fixed 2 files.
7
- Checked 362 files in 49ms. Fixed 28 files.
6
+ Formatted 167 files in 24ms. Fixed 1 file.
7
+ Checked 362 files in 104ms. Fixed 28 files.
package/dist/index.cjs CHANGED
@@ -3300,13 +3300,16 @@ var __webpack_exports__ = {};
3300
3300
  message
3301
3301
  };
3302
3302
  }
3303
+ var package_namespaceObject = {
3304
+ i8: "0.0.1-rc.18"
3305
+ };
3303
3306
  const status_status = defineRoute({
3304
3307
  path: '/status',
3305
3308
  method: 'get',
3306
3309
  handler: async (event)=>{
3307
3310
  const response = {
3308
3311
  status: 'ok',
3309
- version: '2.0.0',
3312
+ version: package_namespaceObject.i8,
3310
3313
  timestamp: new Date().toISOString(),
3311
3314
  storage: {
3312
3315
  type: event.context.adapter?.id ?? 'Unavailable',
package/dist/index.js CHANGED
@@ -3270,13 +3270,16 @@ function checkJurisdiction(countryCode) {
3270
3270
  message
3271
3271
  };
3272
3272
  }
3273
+ var package_namespaceObject = {
3274
+ i8: "0.0.1-rc.18"
3275
+ };
3273
3276
  const status_status = defineRoute({
3274
3277
  path: '/status',
3275
3278
  method: 'get',
3276
3279
  handler: async (event)=>{
3277
3280
  const response = {
3278
3281
  status: 'ok',
3279
- version: '2.0.0',
3282
+ version: package_namespaceObject.i8,
3280
3283
  timestamp: new Date().toISOString(),
3281
3284
  storage: {
3282
3285
  type: event.context.adapter?.id ?? 'Unavailable',
@@ -201,7 +201,6 @@ function toCloudflareHandler(instance) {
201
201
  'HEAD'
202
202
  ].includes(request.method) ? void 0 : request.body
203
203
  });
204
- await updateBaseUrl(request, basePath);
205
204
  const result = await instance.handler(rewrittenRequest);
206
205
  return await result.match((response)=>addCorsHeaders(response, request, instance), (error)=>{
207
206
  const status = error.statusCode || 500;
@@ -266,22 +265,40 @@ function toCloudflareHandler(instance) {
266
265
  function isTrustedOrigin(origin, instance) {
267
266
  if (!origin) return false;
268
267
  const { trustedOrigins = [] } = instance.options || {};
269
- if (trustedOrigins.includes('*')) return true;
270
- return trustedOrigins.includes(origin);
271
- }
272
- async function updateBaseUrl(request, basePath) {
273
- if (!instance.$context) return;
268
+ let originsArray = [];
269
+ if (Array.isArray(trustedOrigins)) originsArray = trustedOrigins.map((item)=>{
270
+ if ('string' == typeof item && (item.startsWith('"') && item.endsWith('"') || item.startsWith('[') && item.endsWith(']'))) try {
271
+ const parsed = JSON.parse(item);
272
+ return 'string' == typeof parsed ? parsed : item;
273
+ } catch {}
274
+ return item;
275
+ });
276
+ else if ('string' == typeof trustedOrigins) {
277
+ if (trustedOrigins.startsWith('[') && trustedOrigins.endsWith(']')) try {
278
+ const parsed = JSON.parse(trustedOrigins);
279
+ originsArray = Array.isArray(parsed) ? parsed : [
280
+ trustedOrigins
281
+ ];
282
+ } catch {
283
+ originsArray = [
284
+ trustedOrigins
285
+ ];
286
+ }
287
+ else originsArray = [
288
+ trustedOrigins
289
+ ];
290
+ }
291
+ if (originsArray.includes('*')) return true;
292
+ const isExactMatch = originsArray.includes(origin);
293
+ if (isExactMatch) return true;
274
294
  try {
275
- const contextResult = await instance.$context;
276
- contextResult.match((context)=>{
277
- const url = new URL(request.url);
278
- const baseURL = `${url.protocol}//${url.host}${basePath}`;
279
- if (!context.baseURL || context.baseURL !== baseURL) {
280
- context.baseURL = baseURL;
281
- if (context.options) context.options.baseURL = baseURL;
282
- }
283
- }, ()=>{});
284
- } catch {}
295
+ const originUrl = new URL(origin);
296
+ const originHostname = originUrl.hostname;
297
+ if (originsArray.includes(originHostname)) return true;
298
+ return false;
299
+ } catch {
300
+ return false;
301
+ }
285
302
  }
286
303
  }
287
304
  var __webpack_export_target__ = exports;
@@ -1 +1 @@
1
- {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/integrations/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAI3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,IAC3C,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAiNlD"}
1
+ {"version":3,"file":"cloudflare.d.ts","sourceRoot":"","sources":["../../src/integrations/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,IAC3C,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CA0OlD"}
@@ -173,7 +173,6 @@ function toCloudflareHandler(instance) {
173
173
  'HEAD'
174
174
  ].includes(request.method) ? void 0 : request.body
175
175
  });
176
- await updateBaseUrl(request, basePath);
177
176
  const result = await instance.handler(rewrittenRequest);
178
177
  return await result.match((response)=>addCorsHeaders(response, request, instance), (error)=>{
179
178
  const status = error.statusCode || 500;
@@ -238,22 +237,40 @@ function toCloudflareHandler(instance) {
238
237
  function isTrustedOrigin(origin, instance) {
239
238
  if (!origin) return false;
240
239
  const { trustedOrigins = [] } = instance.options || {};
241
- if (trustedOrigins.includes('*')) return true;
242
- return trustedOrigins.includes(origin);
243
- }
244
- async function updateBaseUrl(request, basePath) {
245
- if (!instance.$context) return;
240
+ let originsArray = [];
241
+ if (Array.isArray(trustedOrigins)) originsArray = trustedOrigins.map((item)=>{
242
+ if ('string' == typeof item && (item.startsWith('"') && item.endsWith('"') || item.startsWith('[') && item.endsWith(']'))) try {
243
+ const parsed = JSON.parse(item);
244
+ return 'string' == typeof parsed ? parsed : item;
245
+ } catch {}
246
+ return item;
247
+ });
248
+ else if ('string' == typeof trustedOrigins) {
249
+ if (trustedOrigins.startsWith('[') && trustedOrigins.endsWith(']')) try {
250
+ const parsed = JSON.parse(trustedOrigins);
251
+ originsArray = Array.isArray(parsed) ? parsed : [
252
+ trustedOrigins
253
+ ];
254
+ } catch {
255
+ originsArray = [
256
+ trustedOrigins
257
+ ];
258
+ }
259
+ else originsArray = [
260
+ trustedOrigins
261
+ ];
262
+ }
263
+ if (originsArray.includes('*')) return true;
264
+ const isExactMatch = originsArray.includes(origin);
265
+ if (isExactMatch) return true;
246
266
  try {
247
- const contextResult = await instance.$context;
248
- contextResult.match((context)=>{
249
- const url = new URL(request.url);
250
- const baseURL = `${url.protocol}//${url.host}${basePath}`;
251
- if (!context.baseURL || context.baseURL !== baseURL) {
252
- context.baseURL = baseURL;
253
- if (context.options) context.options.baseURL = baseURL;
254
- }
255
- }, ()=>{});
256
- } catch {}
267
+ const originUrl = new URL(origin);
268
+ const originHostname = originUrl.hostname;
269
+ if (originsArray.includes(originHostname)) return true;
270
+ return false;
271
+ } catch {
272
+ return false;
273
+ }
257
274
  }
258
275
  }
259
276
  export { toCloudflareHandler };
@@ -1 +1 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/routes/status.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,OAAO,CAAC;KACnB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,MAAM;;CAgBjB,CAAC"}
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/routes/status.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,OAAO,CAAC;KACnB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,MAAM;;CAgBjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c15t/backend",
3
- "version": "0.0.1-rc.16",
3
+ "version": "0.0.1-rc.18",
4
4
  "license": "GPL-3.0-only",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,6 +1,5 @@
1
1
  import type { C15TInstance } from '~/core';
2
2
  import { ERROR_CODES } from '~/pkgs/results';
3
- import type { C15TContext } from '~/types';
4
3
 
5
4
  /**
6
5
  * Convert a c15t handler to a Cloudflare Worker handler.
@@ -39,6 +38,7 @@ export function toCloudflareHandler(instance: C15TInstance) {
39
38
 
40
39
  // Extract the path and rewrite for c15t routing
41
40
  const originalUrl = new URL(request.url);
41
+
42
42
  let pathWithoutBase = originalUrl.pathname;
43
43
 
44
44
  // Handle CORS preflight requests directly
@@ -72,16 +72,16 @@ export function toCloudflareHandler(instance: C15TInstance) {
72
72
  : request.body,
73
73
  });
74
74
 
75
- // Update baseURL for proper URL generation in responses
76
- await updateBaseUrl(request, basePath);
77
-
78
75
  // Let c15t handle the request
76
+
79
77
  const result = await instance.handler(rewrittenRequest);
80
78
 
81
79
  // Convert c15t response to standard Response with CORS headers
82
80
  return await result.match(
83
81
  // Success case - add CORS headers and return
84
- (response) => addCorsHeaders(response, request, instance),
82
+ (response) => {
83
+ return addCorsHeaders(response, request, instance);
84
+ },
85
85
  // Error case - create an error response with CORS headers
86
86
  (error) => {
87
87
  const status = error.statusCode || 500;
@@ -107,6 +107,7 @@ export function toCloudflareHandler(instance: C15TInstance) {
107
107
  );
108
108
  } catch (error) {
109
109
  // Basic error handling
110
+
110
111
  const errorResponse = new Response(
111
112
  JSON.stringify({
112
113
  error: true,
@@ -197,48 +198,71 @@ export function toCloudflareHandler(instance: C15TInstance) {
197
198
  return false;
198
199
  }
199
200
 
200
- // If no trusted origins are defined, none are trusted
201
+ // Get trusted origins from options
201
202
  const { trustedOrigins = [] } = instance.options || {};
202
203
 
204
+ // Normalize trustedOrigins to array of strings
205
+ let originsArray: string[] = [];
206
+
207
+ if (Array.isArray(trustedOrigins)) {
208
+ // Handle potential nested array from env vars: ["localhost"] becomes ["localhost"]
209
+ originsArray = trustedOrigins.map((item) => {
210
+ // If item is a string that looks like an array element (has quotes and brackets)
211
+ if (
212
+ typeof item === 'string' &&
213
+ ((item.startsWith('"') && item.endsWith('"')) ||
214
+ (item.startsWith('[') && item.endsWith(']')))
215
+ ) {
216
+ try {
217
+ const parsed = JSON.parse(item);
218
+ return typeof parsed === 'string' ? parsed : item;
219
+ } catch {
220
+ return item;
221
+ }
222
+ }
223
+ return item;
224
+ });
225
+ } else if (typeof trustedOrigins === 'string') {
226
+ // Try to parse as JSON if it looks like an array
227
+ if (
228
+ (trustedOrigins as string).startsWith('[') &&
229
+ (trustedOrigins as string).endsWith(']')
230
+ ) {
231
+ try {
232
+ const parsed = JSON.parse(trustedOrigins as string);
233
+ originsArray = Array.isArray(parsed) ? parsed : [trustedOrigins];
234
+ } catch {
235
+ originsArray = [trustedOrigins];
236
+ }
237
+ } else {
238
+ originsArray = [trustedOrigins];
239
+ }
240
+ }
241
+
203
242
  // If wildcard is included, all origins are trusted
204
- if (trustedOrigins.includes('*')) {
243
+ if (originsArray.includes('*')) {
205
244
  return true;
206
245
  }
207
246
 
208
- // Check if origin is in trusted list
209
- return trustedOrigins.includes(origin);
210
- }
211
-
212
- /**
213
- * Update baseUrl in c15t context
214
- */
215
- async function updateBaseUrl(
216
- request: Request,
217
- basePath: string
218
- ): Promise<void> {
219
- if (!instance.$context) {
220
- return;
247
+ // 1. Check exact match
248
+ const isExactMatch = originsArray.includes(origin);
249
+ if (isExactMatch) {
250
+ return true;
221
251
  }
222
252
 
253
+ // 2. Check domain-based matching
223
254
  try {
224
- const contextResult = await instance.$context;
255
+ const originUrl = new URL(origin);
256
+ const originHostname = originUrl.hostname;
225
257
 
226
- contextResult.match(
227
- (context: C15TContext) => {
228
- const url = new URL(request.url);
229
- const baseURL = `${url.protocol}//${url.host}${basePath}`;
258
+ // Check if any trusted origin is just the hostname (without protocol)
259
+ if (originsArray.includes(originHostname)) {
260
+ return true;
261
+ }
230
262
 
231
- if (!context.baseURL || context.baseURL !== baseURL) {
232
- context.baseURL = baseURL;
233
- if (context.options) {
234
- context.options.baseURL = baseURL;
235
- }
236
- }
237
- },
238
- () => {} // Ignore errors
239
- );
263
+ return false;
240
264
  } catch {
241
- // Ignore errors
265
+ return false;
242
266
  }
243
267
  }
244
268
  }
@@ -1,4 +1,5 @@
1
1
  import { defineRoute } from '~/pkgs/api-router/utils/define-route';
2
+ import { version } from '../../package.json';
2
3
 
3
4
  /**
4
5
  * Response type for the status endpoint
@@ -47,7 +48,7 @@ export const status = defineRoute<StatusResponse>({
47
48
  handler: async (event) => {
48
49
  const response: StatusResponse = {
49
50
  status: 'ok',
50
- version: '2.0.0',
51
+ version: version,
51
52
  timestamp: new Date().toISOString(),
52
53
  storage: {
53
54
  type: event.context.adapter?.id ?? 'Unavailable',