@appwarden/middleware 3.7.0 → 3.9.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.
@@ -14,9 +14,9 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
14
14
  /** Enable debug logging */
15
15
  debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
16
16
  /** Optional Content Security Policy configuration */
17
- contentSecurityPolicy: z.ZodOptional<z.ZodLazy<z.ZodEffects<z.ZodObject<{
18
- mode: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
19
- directives: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
17
+ contentSecurityPolicy: z.ZodOptional<z.ZodLazy<z.ZodObject<{
18
+ mode: z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>;
19
+ directives: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
20
20
  "default-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
21
21
  "script-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
22
22
  "style-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
@@ -97,7 +97,7 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
97
97
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
98
98
  "trusted-types"?: string | boolean | string[] | undefined;
99
99
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
100
- }>]>>, string | {
100
+ }>]>, string | {
101
101
  "default-src"?: string | boolean | string[] | undefined;
102
102
  "script-src"?: string | boolean | string[] | undefined;
103
103
  "style-src"?: string | boolean | string[] | undefined;
@@ -124,7 +124,7 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
124
124
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
125
125
  "trusted-types"?: string | boolean | string[] | undefined;
126
126
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
127
- } | undefined, string | {
127
+ }, string | {
128
128
  "default-src"?: string | boolean | string[] | undefined;
129
129
  "script-src"?: string | boolean | string[] | undefined;
130
130
  "style-src"?: string | boolean | string[] | undefined;
@@ -151,7 +151,7 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
151
151
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
152
152
  "trusted-types"?: string | boolean | string[] | undefined;
153
153
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
154
- } | undefined>, {
154
+ }>, {
155
155
  "default-src"?: string | boolean | string[] | undefined;
156
156
  "script-src"?: string | boolean | string[] | undefined;
157
157
  "style-src"?: string | boolean | string[] | undefined;
@@ -205,7 +205,7 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
205
205
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
206
206
  "trusted-types"?: string | boolean | string[] | undefined;
207
207
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
208
- } | undefined>;
208
+ }>;
209
209
  }, "strip", z.ZodTypeAny, {
210
210
  mode: "disabled" | "report-only" | "enforced";
211
211
  directives?: {
@@ -237,38 +237,8 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
237
237
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
238
238
  } | undefined;
239
239
  }, {
240
- mode?: "disabled" | "report-only" | "enforced" | undefined;
241
- directives?: string | {
242
- "default-src"?: string | boolean | string[] | undefined;
243
- "script-src"?: string | boolean | string[] | undefined;
244
- "style-src"?: string | boolean | string[] | undefined;
245
- "img-src"?: string | boolean | string[] | undefined;
246
- "connect-src"?: string | boolean | string[] | undefined;
247
- "font-src"?: string | boolean | string[] | undefined;
248
- "object-src"?: string | boolean | string[] | undefined;
249
- "media-src"?: string | boolean | string[] | undefined;
250
- "frame-src"?: string | boolean | string[] | undefined;
251
- sandbox?: string | boolean | string[] | undefined;
252
- "report-uri"?: string | boolean | string[] | undefined;
253
- "child-src"?: string | boolean | string[] | undefined;
254
- "form-action"?: string | boolean | string[] | undefined;
255
- "frame-ancestors"?: string | boolean | string[] | undefined;
256
- "plugin-types"?: string | boolean | string[] | undefined;
257
- "base-uri"?: string | boolean | string[] | undefined;
258
- "report-to"?: string | boolean | string[] | undefined;
259
- "worker-src"?: string | boolean | string[] | undefined;
260
- "manifest-src"?: string | boolean | string[] | undefined;
261
- "prefetch-src"?: string | boolean | string[] | undefined;
262
- "navigate-to"?: string | boolean | string[] | undefined;
263
- "require-sri-for"?: string | boolean | string[] | undefined;
264
- "block-all-mixed-content"?: string | boolean | string[] | undefined;
265
- "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
266
- "trusted-types"?: string | boolean | string[] | undefined;
267
- "require-trusted-types-for"?: string | boolean | string[] | undefined;
268
- } | undefined;
269
- }>, {
270
240
  mode: "disabled" | "report-only" | "enforced";
271
- directives?: {
241
+ directives: string | {
272
242
  "default-src"?: string | boolean | string[] | undefined;
273
243
  "script-src"?: string | boolean | string[] | undefined;
274
244
  "style-src"?: string | boolean | string[] | undefined;
@@ -295,37 +265,7 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
295
265
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
296
266
  "trusted-types"?: string | boolean | string[] | undefined;
297
267
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
298
- } | undefined;
299
- }, {
300
- mode?: "disabled" | "report-only" | "enforced" | undefined;
301
- directives?: string | {
302
- "default-src"?: string | boolean | string[] | undefined;
303
- "script-src"?: string | boolean | string[] | undefined;
304
- "style-src"?: string | boolean | string[] | undefined;
305
- "img-src"?: string | boolean | string[] | undefined;
306
- "connect-src"?: string | boolean | string[] | undefined;
307
- "font-src"?: string | boolean | string[] | undefined;
308
- "object-src"?: string | boolean | string[] | undefined;
309
- "media-src"?: string | boolean | string[] | undefined;
310
- "frame-src"?: string | boolean | string[] | undefined;
311
- sandbox?: string | boolean | string[] | undefined;
312
- "report-uri"?: string | boolean | string[] | undefined;
313
- "child-src"?: string | boolean | string[] | undefined;
314
- "form-action"?: string | boolean | string[] | undefined;
315
- "frame-ancestors"?: string | boolean | string[] | undefined;
316
- "plugin-types"?: string | boolean | string[] | undefined;
317
- "base-uri"?: string | boolean | string[] | undefined;
318
- "report-to"?: string | boolean | string[] | undefined;
319
- "worker-src"?: string | boolean | string[] | undefined;
320
- "manifest-src"?: string | boolean | string[] | undefined;
321
- "prefetch-src"?: string | boolean | string[] | undefined;
322
- "navigate-to"?: string | boolean | string[] | undefined;
323
- "require-sri-for"?: string | boolean | string[] | undefined;
324
- "block-all-mixed-content"?: string | boolean | string[] | undefined;
325
- "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
326
- "trusted-types"?: string | boolean | string[] | undefined;
327
- "require-trusted-types-for"?: string | boolean | string[] | undefined;
328
- } | undefined;
268
+ };
329
269
  }>>>;
330
270
  }, "strip", z.ZodTypeAny, {
331
271
  debug: boolean;
@@ -368,8 +308,8 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
368
308
  appwardenApiToken: string;
369
309
  debug?: string | boolean | undefined;
370
310
  contentSecurityPolicy?: {
371
- mode?: "disabled" | "report-only" | "enforced" | undefined;
372
- directives?: string | {
311
+ mode: "disabled" | "report-only" | "enforced";
312
+ directives: string | {
373
313
  "default-src"?: string | boolean | string[] | undefined;
374
314
  "script-src"?: string | boolean | string[] | undefined;
375
315
  "style-src"?: string | boolean | string[] | undefined;
@@ -396,57 +336,68 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
396
336
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
397
337
  "trusted-types"?: string | boolean | string[] | undefined;
398
338
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
399
- } | undefined;
339
+ };
400
340
  } | undefined;
401
341
  appwardenApiHostname?: string | undefined;
402
342
  }>;
343
+ type TanStackStartCloudflareConfig = z.infer<typeof TanStackStartCloudflareConfigSchema>;
403
344
  type TanStackStartCloudflareConfigInput = z.input<typeof TanStackStartCloudflareConfigSchema>;
404
345
 
405
346
  /**
406
- * Minimal runtime context type for TanStack Start adapter.
407
- * Contains only what the adapter and config function need.
408
- * Users provide this context by importing env and waitUntil from "cloudflare:workers".
409
- */
410
- interface TanStackStartRuntimeContext {
411
- env: CloudflareEnv;
412
- waitUntil(promise: Promise<unknown>): void;
413
- }
414
- /**
415
- * Configuration function that receives the runtime context and returns the config.
416
- * This allows dynamic configuration based on environment variables.
347
+ * Configuration function that returns the config.
348
+ * This allows dynamic configuration based on environment variables from cloudflare:workers.
417
349
  * Accepts pre-transformation input types (e.g., string | boolean for debug, string | object for CSP directives).
418
350
  */
419
- type TanStackStartConfigFn = (runtime: TanStackStartRuntimeContext) => TanStackStartCloudflareConfigInput;
351
+ type TanStackStartConfigFn = () => TanStackStartCloudflareConfigInput;
420
352
  /**
421
353
  * The result returned by the `next()` function in TanStack Start request middleware.
422
354
  *
423
355
  * Mirrors the internal `RequestServerResult` interface from `@tanstack/start-client-core`
424
356
  * without importing from an unstable internal package path.
357
+ *
358
+ * Note: `pathname` remains required here to stay structurally compatible with
359
+ * TanStack's `RequestServerResult` type, which expects a non-optional string.
360
+ * The adapter itself does not use this property, but other parts of TanStack's
361
+ * type system do, so we keep it required on the result while allowing it to be
362
+ * optional on the middleware *args* type.
425
363
  */
426
364
  interface TanStackStartNextResult {
427
365
  request: Request;
428
366
  pathname: string;
429
- context: Record<string, unknown>;
367
+ context: unknown;
430
368
  response: Response;
431
369
  }
432
370
  /**
433
371
  * The `next()` function passed to TanStack Start request middleware.
434
372
  *
435
- * Mirrors the internal `RequestServerNextFn` signature.
373
+ * This mirrors the shape of TanStack's `RequestServerNextFn` from
374
+ * `@tanstack/start-client-core` without importing the type directly.
375
+ *
376
+ * - It accepts an optional options object with an optional `context`.
377
+ * - It may return either a `TanStackStartNextResult` or a Promise of one,
378
+ * matching TanStack's own union return type
379
+ * (`Promise<RequestServerResult> | RequestServerResult`).
380
+ * - The adapter itself always calls `next()` with no arguments and awaits it,
381
+ * so callers are free to pass TanStack's native `next` implementation
382
+ * directly (`next: next`).
436
383
  */
437
- type TanStackStartNextFn = (options?: {
438
- context?: Record<string, unknown>;
439
- }) => Promise<TanStackStartNextResult>;
384
+ interface TanStackStartNextOptions<TServerContext = Record<string, unknown>> {
385
+ context?: TServerContext;
386
+ }
387
+ type TanStackStartNextFnResult = Promise<TanStackStartNextResult> | TanStackStartNextResult;
388
+ type TanStackStartNextFn = <TServerContext = Record<string, unknown>>(options?: TanStackStartNextOptions<TServerContext>) => TanStackStartNextFnResult;
440
389
  /**
441
390
  * TanStack Start middleware server callback arguments.
442
391
  *
443
392
  * Mirrors the official TanStack Start `RequestServerOptions` interface.
444
- * The context should include env and waitUntil from the Cloudflare Workers runtime.
445
393
  */
446
394
  interface TanStackStartMiddlewareArgs {
447
395
  request: Request;
448
- pathname: string;
449
- context: TanStackStartRuntimeContext & Record<string, unknown>;
396
+ /**
397
+ * Optional pathname supplied by TanStack Start. The adapter does not require it,
398
+ * so callers do not need to provide it when constructing harness args manually.
399
+ */
400
+ pathname?: string;
450
401
  next: TanStackStartNextFn;
451
402
  serverFnMeta?: unknown;
452
403
  }
@@ -462,9 +413,9 @@ interface TanStackStartMiddlewareArgs {
462
413
  type TanStackStartMiddlewareFunction = (args: TanStackStartMiddlewareArgs) => Promise<TanStackStartNextResult>;
463
414
  /**
464
415
  *
465
- * @param configFn - A function that receives the Cloudflare context and returns the config
416
+ * @param configFn - A function that returns the config using env from cloudflare:workers
466
417
  * @returns A TanStack Start middleware function
467
418
  */
468
419
  declare function createAppwardenMiddleware(configFn: TanStackStartConfigFn): TanStackStartMiddlewareFunction;
469
420
 
470
- export { createAppwardenMiddleware };
421
+ export { type TanStackStartCloudflareConfig, type TanStackStartCloudflareConfigInput, type TanStackStartConfigFn, type TanStackStartMiddlewareArgs, type TanStackStartMiddlewareFunction, type TanStackStartNextFn, type TanStackStartNextResult, createAppwardenMiddleware };
@@ -3,31 +3,31 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-52NBQDQT.js";
6
+ } from "../chunk-VSCXTBP6.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
- import {
11
- validateConfig
12
- } from "../chunk-MNGMTDH3.js";
13
10
  import {
14
11
  checkLockStatus
15
- } from "../chunk-G5FWKV2Q.js";
12
+ } from "../chunk-MYIKUPTR.js";
16
13
  import {
17
14
  buildLockPageUrl,
18
15
  createRedirect,
19
16
  debug,
20
17
  isOnLockPage
21
- } from "../chunk-EPJ4ZVO6.js";
18
+ } from "../chunk-Z7FIMIZS.js";
22
19
  import {
23
20
  UseCSPInputSchema,
24
21
  isHTMLRequest
25
- } from "../chunk-HCGLR3Z3.js";
22
+ } from "../chunk-UIIYORBW.js";
26
23
  import {
27
24
  AppwardenApiTokenSchema,
28
25
  BooleanSchema,
29
26
  printMessage
30
- } from "../chunk-GK6JL5NZ.js";
27
+ } from "../chunk-QGXPAVOA.js";
28
+
29
+ // src/adapters/tanstack-start-cloudflare.ts
30
+ import { waitUntil } from "cloudflare:workers";
31
31
 
32
32
  // src/schemas/tanstack-start-cloudflare.ts
33
33
  import { z } from "zod";
@@ -48,23 +48,19 @@ var TanStackStartCloudflareConfigSchema = z.object({
48
48
  function createAppwardenMiddleware(configFn) {
49
49
  const middleware = async (args) => {
50
50
  const startTime = getNowMs();
51
- const { request, next, context } = args;
51
+ const { request, next } = args;
52
52
  try {
53
- if (!context.env || !context.waitUntil) {
53
+ const rawConfig = configFn();
54
+ const validationResult = TanStackStartCloudflareConfigSchema.safeParse(rawConfig);
55
+ if (!validationResult.success) {
54
56
  console.error(
55
57
  printMessage(
56
- "Runtime context missing required properties (env, waitUntil). Ensure you pass { env, waitUntil } from cloudflare:workers to the middleware context."
58
+ `Config validation failed: ${validationResult.error.message}`
57
59
  )
58
60
  );
59
61
  return next();
60
62
  }
61
- const rawConfig = configFn(context);
62
- const parseResult = TanStackStartCloudflareConfigSchema.safeParse(rawConfig);
63
- if (!parseResult.success) {
64
- validateConfig(rawConfig, TanStackStartCloudflareConfigSchema);
65
- return next();
66
- }
67
- const config = parseResult.data;
63
+ const config = validationResult.data;
68
64
  const debugFn = debug(config.debug ?? false);
69
65
  const requestUrl = new URL(request.url);
70
66
  const isHTML = isHTMLRequest(request);
@@ -85,12 +81,32 @@ function createAppwardenMiddleware(configFn) {
85
81
  appwardenApiHostname: config.appwardenApiHostname,
86
82
  debug: config.debug,
87
83
  lockPageSlug: config.lockPageSlug,
88
- waitUntil: context.waitUntil
84
+ waitUntil
89
85
  });
90
86
  if (lockStatus.isLocked) {
91
87
  const lockPageUrl = buildLockPageUrl(config.lockPageSlug, request.url);
92
88
  debugFn(`Website is locked - redirecting to ${lockPageUrl.pathname}`);
93
- throw createRedirect(lockPageUrl);
89
+ const redirectResponse = createRedirect(lockPageUrl);
90
+ if (config.contentSecurityPolicy && isResponseLike(redirectResponse)) {
91
+ const cspContext = {
92
+ request,
93
+ response: redirectResponse,
94
+ hostname: requestUrl.hostname,
95
+ waitUntil,
96
+ debug: debugFn
97
+ };
98
+ await useContentSecurityPolicy(config.contentSecurityPolicy)(
99
+ cspContext,
100
+ async () => {
101
+ }
102
+ );
103
+ const elapsed3 = Math.round(getNowMs() - startTime);
104
+ debugFn(`Middleware executed in ${elapsed3}ms`);
105
+ throw cspContext.response;
106
+ }
107
+ const elapsed2 = Math.round(getNowMs() - startTime);
108
+ debugFn(`Middleware executed in ${elapsed2}ms`);
109
+ throw redirectResponse;
94
110
  }
95
111
  debugFn("Website is unlocked");
96
112
  const result = await next();
@@ -100,7 +116,7 @@ function createAppwardenMiddleware(configFn) {
100
116
  request,
101
117
  response,
102
118
  hostname: requestUrl.hostname,
103
- waitUntil: context.waitUntil,
119
+ waitUntil,
104
120
  debug: debugFn
105
121
  };
106
122
  await useContentSecurityPolicy(config.contentSecurityPolicy)(
@@ -11,7 +11,7 @@ import {
11
11
  makeCSPHeader,
12
12
  store,
13
13
  syncEdgeValue
14
- } from "./chunk-GK6JL5NZ.js";
14
+ } from "./chunk-QGXPAVOA.js";
15
15
  export {
16
16
  CSP_KEYWORDS,
17
17
  autoQuoteCSPDirectiveArray,
package/cloudflare.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { B as Bindings } from './use-content-security-policy-DUYpyUPy.js';
1
+ import { B as Bindings } from './use-content-security-policy-jlU0Hjj8.js';
2
+ export { u as useContentSecurityPolicy } from './use-content-security-policy-jlU0Hjj8.js';
2
3
  import { z } from 'zod';
3
- export { u as useContentSecurityPolicy } from './use-content-security-policy-Dvc-oObb.js';
4
4
 
5
5
  declare const UseAppwardenInputSchema: z.ZodObject<{
6
6
  debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
7
7
  lockPageSlug: z.ZodOptional<z.ZodString>;
8
8
  multidomainConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
9
9
  lockPageSlug: z.ZodString;
10
- contentSecurityPolicy: z.ZodOptional<z.ZodLazy<z.ZodEffects<z.ZodObject<{
11
- mode: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
12
- directives: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
10
+ contentSecurityPolicy: z.ZodOptional<z.ZodLazy<z.ZodObject<{
11
+ mode: z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>;
12
+ directives: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
13
13
  "default-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
14
14
  "script-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
15
15
  "style-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
@@ -90,7 +90,7 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
90
90
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
91
91
  "trusted-types"?: string | boolean | string[] | undefined;
92
92
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
93
- }>]>>, string | {
93
+ }>]>, string | {
94
94
  "default-src"?: string | boolean | string[] | undefined;
95
95
  "script-src"?: string | boolean | string[] | undefined;
96
96
  "style-src"?: string | boolean | string[] | undefined;
@@ -117,7 +117,7 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
117
117
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
118
118
  "trusted-types"?: string | boolean | string[] | undefined;
119
119
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
120
- } | undefined, string | {
120
+ }, string | {
121
121
  "default-src"?: string | boolean | string[] | undefined;
122
122
  "script-src"?: string | boolean | string[] | undefined;
123
123
  "style-src"?: string | boolean | string[] | undefined;
@@ -144,7 +144,7 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
144
144
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
145
145
  "trusted-types"?: string | boolean | string[] | undefined;
146
146
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
147
- } | undefined>, {
147
+ }>, {
148
148
  "default-src"?: string | boolean | string[] | undefined;
149
149
  "script-src"?: string | boolean | string[] | undefined;
150
150
  "style-src"?: string | boolean | string[] | undefined;
@@ -198,7 +198,7 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
198
198
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
199
199
  "trusted-types"?: string | boolean | string[] | undefined;
200
200
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
201
- } | undefined>;
201
+ }>;
202
202
  }, "strip", z.ZodTypeAny, {
203
203
  mode: "disabled" | "report-only" | "enforced";
204
204
  directives?: {
@@ -230,68 +230,8 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
230
230
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
231
231
  } | undefined;
232
232
  }, {
233
- mode?: "disabled" | "report-only" | "enforced" | undefined;
234
- directives?: string | {
235
- "default-src"?: string | boolean | string[] | undefined;
236
- "script-src"?: string | boolean | string[] | undefined;
237
- "style-src"?: string | boolean | string[] | undefined;
238
- "img-src"?: string | boolean | string[] | undefined;
239
- "connect-src"?: string | boolean | string[] | undefined;
240
- "font-src"?: string | boolean | string[] | undefined;
241
- "object-src"?: string | boolean | string[] | undefined;
242
- "media-src"?: string | boolean | string[] | undefined;
243
- "frame-src"?: string | boolean | string[] | undefined;
244
- sandbox?: string | boolean | string[] | undefined;
245
- "report-uri"?: string | boolean | string[] | undefined;
246
- "child-src"?: string | boolean | string[] | undefined;
247
- "form-action"?: string | boolean | string[] | undefined;
248
- "frame-ancestors"?: string | boolean | string[] | undefined;
249
- "plugin-types"?: string | boolean | string[] | undefined;
250
- "base-uri"?: string | boolean | string[] | undefined;
251
- "report-to"?: string | boolean | string[] | undefined;
252
- "worker-src"?: string | boolean | string[] | undefined;
253
- "manifest-src"?: string | boolean | string[] | undefined;
254
- "prefetch-src"?: string | boolean | string[] | undefined;
255
- "navigate-to"?: string | boolean | string[] | undefined;
256
- "require-sri-for"?: string | boolean | string[] | undefined;
257
- "block-all-mixed-content"?: string | boolean | string[] | undefined;
258
- "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
259
- "trusted-types"?: string | boolean | string[] | undefined;
260
- "require-trusted-types-for"?: string | boolean | string[] | undefined;
261
- } | undefined;
262
- }>, {
263
233
  mode: "disabled" | "report-only" | "enforced";
264
- directives?: {
265
- "default-src"?: string | boolean | string[] | undefined;
266
- "script-src"?: string | boolean | string[] | undefined;
267
- "style-src"?: string | boolean | string[] | undefined;
268
- "img-src"?: string | boolean | string[] | undefined;
269
- "connect-src"?: string | boolean | string[] | undefined;
270
- "font-src"?: string | boolean | string[] | undefined;
271
- "object-src"?: string | boolean | string[] | undefined;
272
- "media-src"?: string | boolean | string[] | undefined;
273
- "frame-src"?: string | boolean | string[] | undefined;
274
- sandbox?: string | boolean | string[] | undefined;
275
- "report-uri"?: string | boolean | string[] | undefined;
276
- "child-src"?: string | boolean | string[] | undefined;
277
- "form-action"?: string | boolean | string[] | undefined;
278
- "frame-ancestors"?: string | boolean | string[] | undefined;
279
- "plugin-types"?: string | boolean | string[] | undefined;
280
- "base-uri"?: string | boolean | string[] | undefined;
281
- "report-to"?: string | boolean | string[] | undefined;
282
- "worker-src"?: string | boolean | string[] | undefined;
283
- "manifest-src"?: string | boolean | string[] | undefined;
284
- "prefetch-src"?: string | boolean | string[] | undefined;
285
- "navigate-to"?: string | boolean | string[] | undefined;
286
- "require-sri-for"?: string | boolean | string[] | undefined;
287
- "block-all-mixed-content"?: string | boolean | string[] | undefined;
288
- "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
289
- "trusted-types"?: string | boolean | string[] | undefined;
290
- "require-trusted-types-for"?: string | boolean | string[] | undefined;
291
- } | undefined;
292
- }, {
293
- mode?: "disabled" | "report-only" | "enforced" | undefined;
294
- directives?: string | {
234
+ directives: string | {
295
235
  "default-src"?: string | boolean | string[] | undefined;
296
236
  "script-src"?: string | boolean | string[] | undefined;
297
237
  "style-src"?: string | boolean | string[] | undefined;
@@ -318,7 +258,7 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
318
258
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
319
259
  "trusted-types"?: string | boolean | string[] | undefined;
320
260
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
321
- } | undefined;
261
+ };
322
262
  }>>>;
323
263
  }, "strip", z.ZodTypeAny, {
324
264
  lockPageSlug: string;
@@ -356,8 +296,8 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
356
296
  }, {
357
297
  lockPageSlug: string;
358
298
  contentSecurityPolicy?: {
359
- mode?: "disabled" | "report-only" | "enforced" | undefined;
360
- directives?: string | {
299
+ mode: "disabled" | "report-only" | "enforced";
300
+ directives: string | {
361
301
  "default-src"?: string | boolean | string[] | undefined;
362
302
  "script-src"?: string | boolean | string[] | undefined;
363
303
  "style-src"?: string | boolean | string[] | undefined;
@@ -384,7 +324,7 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
384
324
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
385
325
  "trusted-types"?: string | boolean | string[] | undefined;
386
326
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
387
- } | undefined;
327
+ };
388
328
  } | undefined;
389
329
  }>>>;
390
330
  appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
@@ -435,8 +375,8 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
435
375
  multidomainConfig?: Record<string, {
436
376
  lockPageSlug: string;
437
377
  contentSecurityPolicy?: {
438
- mode?: "disabled" | "report-only" | "enforced" | undefined;
439
- directives?: string | {
378
+ mode: "disabled" | "report-only" | "enforced";
379
+ directives: string | {
440
380
  "default-src"?: string | boolean | string[] | undefined;
441
381
  "script-src"?: string | boolean | string[] | undefined;
442
382
  "style-src"?: string | boolean | string[] | undefined;
@@ -463,7 +403,7 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
463
403
  "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
464
404
  "trusted-types"?: string | boolean | string[] | undefined;
465
405
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
466
- } | undefined;
406
+ };
467
407
  } | undefined;
468
408
  }> | undefined;
469
409
  appwardenApiHostname?: string | undefined;
package/cloudflare.js CHANGED
@@ -1,28 +1,25 @@
1
1
  import {
2
2
  useContentSecurityPolicy
3
- } from "./chunk-52NBQDQT.js";
3
+ } from "./chunk-VSCXTBP6.js";
4
4
  import {
5
5
  checkLockStatus
6
- } from "./chunk-G5FWKV2Q.js";
6
+ } from "./chunk-MYIKUPTR.js";
7
7
  import {
8
8
  buildLockPageUrl,
9
9
  createRedirect,
10
10
  debug,
11
11
  isOnLockPage
12
- } from "./chunk-EPJ4ZVO6.js";
12
+ } from "./chunk-Z7FIMIZS.js";
13
13
  import {
14
- APPWARDEN_CACHE_KEY,
15
14
  UseCSPInputSchema,
16
15
  isHTMLRequest
17
- } from "./chunk-HCGLR3Z3.js";
16
+ } from "./chunk-UIIYORBW.js";
18
17
  import {
19
18
  AppwardenApiTokenSchema,
20
19
  BooleanSchema,
21
- getLockValue,
22
20
  insertErrorLogs,
23
- printMessage,
24
- store
25
- } from "./chunk-GK6JL5NZ.js";
21
+ printMessage
22
+ } from "./chunk-QGXPAVOA.js";
26
23
 
27
24
  // src/runners/appwarden-on-cloudflare.ts
28
25
  import { ZodError } from "zod";
@@ -78,43 +75,12 @@ var usePipeline = (...initMiddlewares) => {
78
75
  };
79
76
  };
80
77
 
81
- // src/handlers/reset-cache.ts
82
- var isResetCacheRequest = (request) => request.method === "POST" && new URL(request.url).pathname === "/__appwarden/reset-cache" && request.headers.get("content-type") === "application/json";
83
- var handleResetCache = async (keyName, provider, edgeCache, request) => {
84
- const { lockValue } = await getLockValue({
85
- keyName,
86
- provider,
87
- edgeCache
88
- });
89
- try {
90
- const body = await request.clone().json();
91
- if (body.code === lockValue?.code) {
92
- await edgeCache.deleteValue();
93
- }
94
- } catch (error) {
95
- }
96
- };
97
-
98
78
  // src/middlewares/use-appwarden.ts
99
79
  var useAppwarden = (input) => async (context, next) => {
100
80
  const { request } = context;
101
81
  let shouldCallNext = true;
102
82
  try {
103
83
  const requestUrl = new URL(request.url);
104
- if (isResetCacheRequest(request)) {
105
- const provider = "cloudflare-cache";
106
- const keyName = APPWARDEN_CACHE_KEY;
107
- const edgeCache = store.json(
108
- {
109
- serviceOrigin: requestUrl.origin,
110
- cache: await caches.open("appwarden:lock"),
111
- debug: context.debug
112
- },
113
- keyName
114
- );
115
- await handleResetCache(keyName, provider, edgeCache, request);
116
- return;
117
- }
118
84
  if (!isHTMLRequest(request)) {
119
85
  return;
120
86
  }
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema } from './use-content-security-policy-DUYpyUPy.js';
2
- export { M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-Dvc-oObb.js';
1
+ export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-jlU0Hjj8.js';
3
2
  import { z } from 'zod';
4
3
 
5
4
  declare const LOCKDOWN_TEST_EXPIRY_MS: number;
@@ -50,14 +49,11 @@ declare const LockValue: z.ZodObject<{
50
49
  isLocked: z.ZodNumber;
51
50
  isLockedTest: z.ZodNumber;
52
51
  lastCheck: z.ZodNumber;
53
- code: z.ZodString;
54
52
  }, "strip", z.ZodTypeAny, {
55
- code: string;
56
53
  isLocked: number;
57
54
  isLockedTest: number;
58
55
  lastCheck: number;
59
56
  }, {
60
- code: string;
61
57
  isLocked: number;
62
58
  isLockedTest: number;
63
59
  lastCheck: number;
package/index.js CHANGED
@@ -5,14 +5,14 @@ import {
5
5
  } from "./chunk-QEFORWCW.js";
6
6
  import {
7
7
  useContentSecurityPolicy
8
- } from "./chunk-52NBQDQT.js";
8
+ } from "./chunk-VSCXTBP6.js";
9
9
  import {
10
10
  APPWARDEN_CACHE_KEY,
11
11
  CSPDirectivesSchema,
12
12
  CSPModeSchema,
13
13
  LOCKDOWN_TEST_EXPIRY_MS
14
- } from "./chunk-HCGLR3Z3.js";
15
- import "./chunk-GK6JL5NZ.js";
14
+ } from "./chunk-UIIYORBW.js";
15
+ import "./chunk-QGXPAVOA.js";
16
16
  export {
17
17
  APPWARDEN_CACHE_KEY,
18
18
  CSPDirectivesSchema,