@appwarden/middleware 3.11.1 → 3.11.3

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![GitHub](https://img.shields.io/badge/GitHub-appwarden%2Fmiddleware-181717?logo=github&logoColor=white)](https://github.com/appwarden/middleware)
5
5
  [![npm version](https://img.shields.io/npm/v/@appwarden/middleware.svg)](https://www.npmjs.com/package/@appwarden/middleware)
6
6
  [![npm provenance](https://img.shields.io/badge/npm-provenance-green)](https://docs.npmjs.com/generating-provenance-statements)
7
- ![Test Coverage](https://img.shields.io/badge/coverage-93.04%25-brightgreen)
7
+ ![Test Coverage](https://img.shields.io/badge/coverage-93.07%25-brightgreen)
8
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
9
 
10
10
  ## Core Features
@@ -0,0 +1,37 @@
1
+ import {
2
+ UseCSPInputSchema
3
+ } from "./chunk-ZTVJBORU.js";
4
+ import {
5
+ AppwardenApiHostnameSchema,
6
+ AppwardenApiTokenSchema,
7
+ BooleanSchema
8
+ } from "./chunk-WEM7GS4M.js";
9
+
10
+ // src/schemas/use-appwarden.ts
11
+ import { z } from "zod";
12
+ var AppwardenMultidomainConfigSchema = z.record(
13
+ z.string(),
14
+ z.object({
15
+ lockPageSlug: z.string(),
16
+ contentSecurityPolicy: z.lazy(() => UseCSPInputSchema).optional(),
17
+ debug: BooleanSchema.optional()
18
+ })
19
+ );
20
+ var UseAppwardenInputSchema = z.object({
21
+ debug: BooleanSchema.default(false),
22
+ lockPageSlug: z.string().optional(),
23
+ multidomainConfig: AppwardenMultidomainConfigSchema.optional(),
24
+ appwardenApiToken: AppwardenApiTokenSchema,
25
+ appwardenApiHostname: AppwardenApiHostnameSchema.optional()
26
+ });
27
+ var lockPageSlugRefinement = (schema) => schema.refine(
28
+ (data) => data.lockPageSlug || data.multidomainConfig,
29
+ {
30
+ message: "lockPageSlug must be provided"
31
+ }
32
+ );
33
+
34
+ export {
35
+ UseAppwardenInputSchema,
36
+ lockPageSlugRefinement
37
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  LOCKDOWN_TEST_EXPIRY_MS
3
- } from "./chunk-2WPLLVUI.js";
3
+ } from "./chunk-ZTVJBORU.js";
4
4
  import {
5
5
  printMessage
6
- } from "./chunk-QUVGY2YI.js";
6
+ } from "./chunk-R7TXTHSG.js";
7
7
 
8
8
  // src/utils/build-lock-page-url.ts
9
9
  function normalizeLockPageSlug(lockPageSlug) {
@@ -110,11 +110,53 @@ var MemoryCache = class {
110
110
  };
111
111
  };
112
112
 
113
+ // src/utils/request-checks.ts
114
+ function isHTMLResponse(response) {
115
+ return response.headers.get("Content-Type")?.includes("text/html") ?? false;
116
+ }
117
+ function isHTMLRequest(request) {
118
+ const accept = request.headers.get("accept");
119
+ if (!accept) {
120
+ return false;
121
+ }
122
+ const normalizedAccept = accept.toLowerCase();
123
+ const isWildcardOnlyAccept = (value) => {
124
+ const mediaRanges2 = value.split(",");
125
+ let hasNonEmptyRange = false;
126
+ for (const range of mediaRanges2) {
127
+ const [typeSubtype] = range.split(";");
128
+ const trimmed = typeSubtype.trim();
129
+ if (!trimmed) {
130
+ continue;
131
+ }
132
+ hasNonEmptyRange = true;
133
+ if (trimmed !== "*/*" && trimmed !== "*") {
134
+ return false;
135
+ }
136
+ }
137
+ return hasNonEmptyRange;
138
+ };
139
+ if (isWildcardOnlyAccept(normalizedAccept)) {
140
+ return false;
141
+ }
142
+ const mediaRanges = normalizedAccept.split(",");
143
+ for (const range of mediaRanges) {
144
+ const [typeSubtype] = range.split(";");
145
+ const token = typeSubtype.trim();
146
+ if (token === "text/html") {
147
+ return true;
148
+ }
149
+ }
150
+ return false;
151
+ }
152
+
113
153
  export {
114
154
  buildLockPageUrl,
115
155
  isOnLockPage,
116
156
  TEMPORARY_REDIRECT_STATUS,
117
157
  createRedirect,
118
158
  debug,
119
- MemoryCache
159
+ MemoryCache,
160
+ isHTMLResponse,
161
+ isHTMLRequest
120
162
  };
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  MemoryCache,
3
3
  debug
4
- } from "./chunk-KE2UVIYR.js";
4
+ } from "./chunk-AY4ZKZTF.js";
5
5
  import {
6
6
  APPWARDEN_CACHE_KEY,
7
7
  APPWARDEN_TEST_ROUTE
8
- } from "./chunk-2WPLLVUI.js";
8
+ } from "./chunk-ZTVJBORU.js";
9
9
  import {
10
10
  deleteEdgeValue,
11
11
  getLockValue,
12
12
  store,
13
13
  syncEdgeValue
14
- } from "./chunk-QUVGY2YI.js";
14
+ } from "./chunk-R7TXTHSG.js";
15
15
 
16
16
  // src/core/check-lock-status.ts
17
17
  var createContext = async (config) => {
@@ -1,3 +1,7 @@
1
+ import {
2
+ LockValue
3
+ } from "./chunk-WEM7GS4M.js";
4
+
1
5
  // src/utils/cloudflare/cloudflare-cache.ts
2
6
  var store = {
3
7
  json: (context, cacheKey, options) => {
@@ -101,24 +105,6 @@ var deleteEdgeValue = async (context) => {
101
105
  }
102
106
  };
103
107
 
104
- // src/schemas/helpers.ts
105
- import { z } from "zod";
106
- var BoolOrStringSchema = z.union([z.string(), z.boolean()]).optional();
107
- var BooleanSchema = BoolOrStringSchema.transform((val) => {
108
- if (val === "true" || val === true) {
109
- return true;
110
- } else if (val === "false" || val === false) {
111
- return false;
112
- }
113
- throw new Error("Invalid value");
114
- });
115
- var AppwardenApiTokenSchema = z.string().refine((val) => !!val, { message: "appwardenApiToken is required" });
116
- var LockValue = z.object({
117
- isLocked: z.number(),
118
- isLockedTest: z.number(),
119
- lastCheck: z.number()
120
- });
121
-
122
108
  // src/utils/errors.ts
123
109
  var errorsMap = {
124
110
  mode: '`CSP_MODE` must be one of "disabled", "report-only", or "enforced"',
@@ -304,9 +290,6 @@ var syncEdgeValue = async (context) => {
304
290
  export {
305
291
  printMessage,
306
292
  getErrors,
307
- BooleanSchema,
308
- AppwardenApiTokenSchema,
309
- LockValue,
310
293
  store,
311
294
  CSP_KEYWORDS,
312
295
  isCSPKeyword,
@@ -1,10 +1,12 @@
1
1
  import {
2
- UseCSPInputSchema,
3
2
  isHTMLResponse
4
- } from "./chunk-2WPLLVUI.js";
3
+ } from "./chunk-AY4ZKZTF.js";
4
+ import {
5
+ UseCSPInputSchema
6
+ } from "./chunk-ZTVJBORU.js";
5
7
  import {
6
8
  makeCSPHeader
7
- } from "./chunk-QUVGY2YI.js";
9
+ } from "./chunk-R7TXTHSG.js";
8
10
 
9
11
  // src/middlewares/use-content-security-policy.ts
10
12
  var AppendAttribute = (attribute, nonce) => ({
@@ -0,0 +1,29 @@
1
+ // src/schemas/helpers.ts
2
+ import { z } from "zod";
3
+ var BoolOrStringSchema = z.union([z.string(), z.boolean()]).optional();
4
+ var BooleanSchema = BoolOrStringSchema.transform((val) => {
5
+ if (val === "true" || val === true) {
6
+ return true;
7
+ } else if (val === "false" || val === false) {
8
+ return false;
9
+ }
10
+ throw new Error("Invalid value");
11
+ });
12
+ var AppwardenApiTokenSchema = z.string().refine((val) => !!val, { message: "appwardenApiToken is required" });
13
+ var AppwardenApiHostnameSchema = z.string().url({
14
+ message: "Invalid `appwardenApiHostname`. Please provide an absolute URL (e.g. https://api.appwarden.io)."
15
+ }).refine((value) => value.startsWith("https://"), {
16
+ message: "`appwardenApiHostname` must use the https:// scheme (e.g. https://api.appwarden.io)."
17
+ });
18
+ var LockValue = z.object({
19
+ isLocked: z.number(),
20
+ isLockedTest: z.number(),
21
+ lastCheck: z.number()
22
+ });
23
+
24
+ export {
25
+ BooleanSchema,
26
+ AppwardenApiTokenSchema,
27
+ AppwardenApiHostnameSchema,
28
+ LockValue
29
+ };
@@ -40,46 +40,6 @@ var ContentSecurityPolicySchema = z.object({
40
40
  "require-trusted-types-for": stringySchema.optional()
41
41
  });
42
42
 
43
- // src/utils/request-checks.ts
44
- function isHTMLResponse(response) {
45
- return response.headers.get("Content-Type")?.includes("text/html") ?? false;
46
- }
47
- function isHTMLRequest(request) {
48
- const accept = request.headers.get("accept");
49
- if (!accept) {
50
- return false;
51
- }
52
- const normalizedAccept = accept.toLowerCase();
53
- const isWildcardOnlyAccept = (value) => {
54
- const mediaRanges2 = value.split(",");
55
- let hasNonEmptyRange = false;
56
- for (const range of mediaRanges2) {
57
- const [typeSubtype] = range.split(";");
58
- const trimmed = typeSubtype.trim();
59
- if (!trimmed) {
60
- continue;
61
- }
62
- hasNonEmptyRange = true;
63
- if (trimmed !== "*/*" && trimmed !== "*") {
64
- return false;
65
- }
66
- }
67
- return hasNonEmptyRange;
68
- };
69
- if (isWildcardOnlyAccept(normalizedAccept)) {
70
- return false;
71
- }
72
- const mediaRanges = normalizedAccept.split(",");
73
- for (const range of mediaRanges) {
74
- const [typeSubtype] = range.split(";");
75
- const token = typeSubtype.trim();
76
- if (token === "text/html") {
77
- return true;
78
- }
79
- }
80
- return false;
81
- }
82
-
83
43
  // src/schemas/use-content-security-policy.ts
84
44
  var CSPDirectivesSchema = z2.union([
85
45
  z2.string(),
@@ -117,7 +77,5 @@ export {
117
77
  APPWARDEN_CACHE_KEY,
118
78
  CSPDirectivesSchema,
119
79
  CSPModeSchema,
120
- UseCSPInputSchema,
121
- isHTMLResponse,
122
- isHTMLRequest
80
+ UseCSPInputSchema
123
81
  };
@@ -12,7 +12,7 @@ declare const AstroCloudflareConfigSchema: z.ZodObject<{
12
12
  /** The Appwarden API token for authentication */
13
13
  appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
14
14
  /** Optional custom API hostname (defaults to https://api.appwarden.io) */
15
- appwardenApiHostname: z.ZodOptional<z.ZodString>;
15
+ appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
16
16
  /** Enable debug logging */
17
17
  debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
18
18
  /** Optional Content Security Policy configuration */
@@ -3,29 +3,32 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-K7ZIT3FM.js";
6
+ } from "../chunk-WBWF3PPX.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-ZOYE6D3A.js";
12
+ } from "../chunk-QC2ZUZWY.js";
13
13
  import {
14
14
  TEMPORARY_REDIRECT_STATUS,
15
15
  buildLockPageUrl,
16
16
  createRedirect,
17
17
  debug,
18
+ isHTMLRequest,
18
19
  isOnLockPage
19
- } from "../chunk-KE2UVIYR.js";
20
+ } from "../chunk-AY4ZKZTF.js";
20
21
  import {
21
- UseCSPInputSchema,
22
- isHTMLRequest
23
- } from "../chunk-2WPLLVUI.js";
22
+ UseCSPInputSchema
23
+ } from "../chunk-ZTVJBORU.js";
24
24
  import {
25
- AppwardenApiTokenSchema,
26
- BooleanSchema,
27
25
  printMessage
28
- } from "../chunk-QUVGY2YI.js";
26
+ } from "../chunk-R7TXTHSG.js";
27
+ import {
28
+ AppwardenApiHostnameSchema,
29
+ AppwardenApiTokenSchema,
30
+ BooleanSchema
31
+ } from "../chunk-WEM7GS4M.js";
29
32
 
30
33
  // src/adapters/astro-cloudflare.ts
31
34
  import { waitUntil } from "cloudflare:workers";
@@ -38,7 +41,7 @@ var AstroCloudflareConfigSchema = z.object({
38
41
  /** The Appwarden API token for authentication */
39
42
  appwardenApiToken: AppwardenApiTokenSchema,
40
43
  /** Optional custom API hostname (defaults to https://api.appwarden.io) */
41
- appwardenApiHostname: z.string().optional(),
44
+ appwardenApiHostname: AppwardenApiHostnameSchema.optional(),
42
45
  /** Enable debug logging */
43
46
  debug: BooleanSchema.default(false),
44
47
  /** Optional Content Security Policy configuration */
@@ -11,7 +11,7 @@ declare const NextJsCloudflareConfigSchema: z.ZodObject<{
11
11
  /** The Appwarden API token for authentication */
12
12
  appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
13
13
  /** Optional custom API hostname (defaults to https://api.appwarden.io) */
14
- appwardenApiHostname: z.ZodOptional<z.ZodString>;
14
+ appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
15
15
  /** Enable debug logging */
16
16
  debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
17
17
  /** Optional Content Security Policy configuration (headers only, no HTML rewriting; '{{nonce}}' is not supported) */
@@ -3,22 +3,25 @@ import {
3
3
  } from "../chunk-X7WZVYQS.js";
4
4
  import {
5
5
  checkLockStatus
6
- } from "../chunk-ZOYE6D3A.js";
6
+ } from "../chunk-QC2ZUZWY.js";
7
7
  import {
8
8
  TEMPORARY_REDIRECT_STATUS,
9
9
  buildLockPageUrl,
10
10
  debug,
11
+ isHTMLRequest,
11
12
  isOnLockPage
12
- } from "../chunk-KE2UVIYR.js";
13
+ } from "../chunk-AY4ZKZTF.js";
13
14
  import {
14
- UseCSPInputSchema,
15
- isHTMLRequest
16
- } from "../chunk-2WPLLVUI.js";
15
+ UseCSPInputSchema
16
+ } from "../chunk-ZTVJBORU.js";
17
17
  import {
18
- AppwardenApiTokenSchema,
19
- BooleanSchema,
20
18
  printMessage
21
- } from "../chunk-QUVGY2YI.js";
19
+ } from "../chunk-R7TXTHSG.js";
20
+ import {
21
+ AppwardenApiHostnameSchema,
22
+ AppwardenApiTokenSchema,
23
+ BooleanSchema
24
+ } from "../chunk-WEM7GS4M.js";
22
25
 
23
26
  // src/adapters/nextjs-cloudflare.ts
24
27
  import {
@@ -44,7 +47,7 @@ var NextJsCloudflareConfigSchema = z.object({
44
47
  /** The Appwarden API token for authentication */
45
48
  appwardenApiToken: AppwardenApiTokenSchema,
46
49
  /** Optional custom API hostname (defaults to https://api.appwarden.io) */
47
- appwardenApiHostname: z.string().optional(),
50
+ appwardenApiHostname: AppwardenApiHostnameSchema.optional(),
48
51
  /** Enable debug logging */
49
52
  debug: BooleanSchema.default(false),
50
53
  /** Optional Content Security Policy configuration (headers only, no HTML rewriting; '{{nonce}}' is not supported) */
@@ -101,7 +104,7 @@ function createAppwardenMiddleware(configFn) {
101
104
  debugFn(
102
105
  `Applying CSP headers in ${config.contentSecurityPolicy.mode} mode`
103
106
  );
104
- const { makeCSPHeader } = await import("../cloudflare-JVRRPVRP.js");
107
+ const { makeCSPHeader } = await import("../cloudflare-MAHYENA6.js");
105
108
  const [headerName, headerValue] = makeCSPHeader(
106
109
  "",
107
110
  config.contentSecurityPolicy.directives,
@@ -10,7 +10,7 @@ declare const ReactRouterCloudflareConfigSchema: z.ZodObject<{
10
10
  /** The Appwarden API token for authentication */
11
11
  appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
12
12
  /** Optional custom API hostname (defaults to https://api.appwarden.io) */
13
- appwardenApiHostname: z.ZodOptional<z.ZodString>;
13
+ appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
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 */
@@ -3,28 +3,31 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-K7ZIT3FM.js";
6
+ } from "../chunk-WBWF3PPX.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-ZOYE6D3A.js";
12
+ } from "../chunk-QC2ZUZWY.js";
13
13
  import {
14
14
  buildLockPageUrl,
15
15
  createRedirect,
16
16
  debug,
17
+ isHTMLRequest,
17
18
  isOnLockPage
18
- } from "../chunk-KE2UVIYR.js";
19
+ } from "../chunk-AY4ZKZTF.js";
19
20
  import {
20
- UseCSPInputSchema,
21
- isHTMLRequest
22
- } from "../chunk-2WPLLVUI.js";
21
+ UseCSPInputSchema
22
+ } from "../chunk-ZTVJBORU.js";
23
23
  import {
24
- AppwardenApiTokenSchema,
25
- BooleanSchema,
26
24
  printMessage
27
- } from "../chunk-QUVGY2YI.js";
25
+ } from "../chunk-R7TXTHSG.js";
26
+ import {
27
+ AppwardenApiHostnameSchema,
28
+ AppwardenApiTokenSchema,
29
+ BooleanSchema
30
+ } from "../chunk-WEM7GS4M.js";
28
31
 
29
32
  // src/adapters/react-router-cloudflare.ts
30
33
  import { waitUntil } from "cloudflare:workers";
@@ -37,7 +40,7 @@ var ReactRouterCloudflareConfigSchema = z.object({
37
40
  /** The Appwarden API token for authentication */
38
41
  appwardenApiToken: AppwardenApiTokenSchema,
39
42
  /** Optional custom API hostname (defaults to https://api.appwarden.io) */
40
- appwardenApiHostname: z.string().optional(),
43
+ appwardenApiHostname: AppwardenApiHostnameSchema.optional(),
41
44
  /** Enable debug logging */
42
45
  debug: BooleanSchema.default(false),
43
46
  /** Optional Content Security Policy configuration */
@@ -10,7 +10,7 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
10
10
  /** The Appwarden API token for authentication */
11
11
  appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
12
12
  /** Optional custom API hostname (defaults to https://api.appwarden.io) */
13
- appwardenApiHostname: z.ZodOptional<z.ZodString>;
13
+ appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
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 */
@@ -3,28 +3,31 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-K7ZIT3FM.js";
6
+ } from "../chunk-WBWF3PPX.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-ZOYE6D3A.js";
12
+ } from "../chunk-QC2ZUZWY.js";
13
13
  import {
14
14
  buildLockPageUrl,
15
15
  createRedirect,
16
16
  debug,
17
+ isHTMLRequest,
17
18
  isOnLockPage
18
- } from "../chunk-KE2UVIYR.js";
19
+ } from "../chunk-AY4ZKZTF.js";
19
20
  import {
20
- UseCSPInputSchema,
21
- isHTMLRequest
22
- } from "../chunk-2WPLLVUI.js";
21
+ UseCSPInputSchema
22
+ } from "../chunk-ZTVJBORU.js";
23
23
  import {
24
- AppwardenApiTokenSchema,
25
- BooleanSchema,
26
24
  printMessage
27
- } from "../chunk-QUVGY2YI.js";
25
+ } from "../chunk-R7TXTHSG.js";
26
+ import {
27
+ AppwardenApiHostnameSchema,
28
+ AppwardenApiTokenSchema,
29
+ BooleanSchema
30
+ } from "../chunk-WEM7GS4M.js";
28
31
 
29
32
  // src/adapters/tanstack-start-cloudflare.ts
30
33
  import { waitUntil } from "cloudflare:workers";
@@ -37,7 +40,7 @@ var TanStackStartCloudflareConfigSchema = z.object({
37
40
  /** The Appwarden API token for authentication */
38
41
  appwardenApiToken: AppwardenApiTokenSchema,
39
42
  /** Optional custom API hostname (defaults to https://api.appwarden.io) */
40
- appwardenApiHostname: z.string().optional(),
43
+ appwardenApiHostname: AppwardenApiHostnameSchema.optional(),
41
44
  /** Enable debug logging */
42
45
  debug: BooleanSchema.default(false),
43
46
  /** Optional Content Security Policy configuration */
@@ -11,7 +11,8 @@ import {
11
11
  makeCSPHeader,
12
12
  store,
13
13
  syncEdgeValue
14
- } from "./chunk-QUVGY2YI.js";
14
+ } from "./chunk-R7TXTHSG.js";
15
+ import "./chunk-WEM7GS4M.js";
15
16
  export {
16
17
  CSP_KEYWORDS,
17
18
  autoQuoteCSPDirectiveArray,
package/cloudflare.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { B as Bindings } from './use-content-security-policy-DpmIa2tk.js';
2
- export { u as useContentSecurityPolicy } from './use-content-security-policy-DpmIa2tk.js';
1
+ import { R as RequestContext, U as UseCSPInput, M as Middleware, B as Bindings } from './use-content-security-policy-CvdzUPYF.js';
3
2
  import { z } from 'zod';
4
3
 
5
- declare const UseAppwardenInputSchema: z.ZodObject<{
4
+ declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<RequestContext, z.ZodTypeDef, RequestContext>], z.ZodUnknown>, z.ZodLazy<z.ZodEffects<z.ZodObject<{
6
5
  debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
7
6
  lockPageSlug: z.ZodOptional<z.ZodString>;
8
7
  multidomainConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -331,7 +330,7 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
331
330
  } | undefined;
332
331
  }>>>;
333
332
  appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
334
- appwardenApiHostname: z.ZodOptional<z.ZodString>;
333
+ appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
335
334
  }, "strip", z.ZodTypeAny, {
336
335
  debug: boolean;
337
336
  appwardenApiToken: string;
@@ -412,10 +411,11 @@ declare const UseAppwardenInputSchema: z.ZodObject<{
412
411
  } | undefined;
413
412
  }> | undefined;
414
413
  appwardenApiHostname?: string | undefined;
415
- }>;
414
+ }>, any, any>>>;
415
+ type CloudflareConfigFnType = z.input<typeof ConfigFnInputSchema>;
416
416
 
417
- type CloudflareConfigType = z.infer<typeof UseAppwardenInputSchema>;
417
+ declare const useContentSecurityPolicy: (input: UseCSPInput) => Middleware;
418
418
 
419
- declare const createAppwardenMiddleware: (inputFn: CloudflareConfigType) => ExportedHandlerFetchHandler<Bindings>;
419
+ declare const createAppwardenMiddleware: (inputFn: CloudflareConfigFnType) => ExportedHandlerFetchHandler<Bindings>;
420
420
 
421
- export { createAppwardenMiddleware };
421
+ export { createAppwardenMiddleware, useContentSecurityPolicy };
package/cloudflare.js CHANGED
@@ -1,58 +1,33 @@
1
+ import {
2
+ UseAppwardenInputSchema,
3
+ lockPageSlugRefinement
4
+ } from "./chunk-4ADGOFLV.js";
1
5
  import {
2
6
  useContentSecurityPolicy
3
- } from "./chunk-K7ZIT3FM.js";
7
+ } from "./chunk-WBWF3PPX.js";
4
8
  import {
5
9
  checkLockStatus
6
- } from "./chunk-ZOYE6D3A.js";
10
+ } from "./chunk-QC2ZUZWY.js";
7
11
  import {
8
12
  buildLockPageUrl,
9
13
  createRedirect,
10
14
  debug,
15
+ isHTMLRequest,
11
16
  isOnLockPage
12
- } from "./chunk-KE2UVIYR.js";
13
- import {
14
- UseCSPInputSchema,
15
- isHTMLRequest
16
- } from "./chunk-2WPLLVUI.js";
17
+ } from "./chunk-AY4ZKZTF.js";
18
+ import "./chunk-ZTVJBORU.js";
17
19
  import {
18
- AppwardenApiTokenSchema,
19
- BooleanSchema,
20
20
  insertErrorLogs,
21
21
  printMessage
22
- } from "./chunk-QUVGY2YI.js";
22
+ } from "./chunk-R7TXTHSG.js";
23
+ import "./chunk-WEM7GS4M.js";
23
24
 
24
25
  // src/runners/appwarden-on-cloudflare.ts
25
26
  import { ZodError } from "zod";
26
27
 
27
28
  // src/schemas/cloudflare.ts
28
- import { z as z2 } from "zod";
29
-
30
- // src/schemas/use-appwarden.ts
31
29
  import { z } from "zod";
32
- var AppwardenMultidomainConfigSchema = z.record(
33
- z.string(),
34
- z.object({
35
- lockPageSlug: z.string(),
36
- contentSecurityPolicy: z.lazy(() => UseCSPInputSchema).optional(),
37
- debug: BooleanSchema.optional()
38
- })
39
- );
40
- var UseAppwardenInputSchema = z.object({
41
- debug: BooleanSchema.default(false),
42
- lockPageSlug: z.string().optional(),
43
- multidomainConfig: AppwardenMultidomainConfigSchema.optional(),
44
- appwardenApiToken: AppwardenApiTokenSchema,
45
- appwardenApiHostname: z.string().optional()
46
- });
47
- var lockPageSlugRefinement = (schema) => schema.refine(
48
- (data) => data.lockPageSlug || data.multidomainConfig,
49
- {
50
- message: "lockPageSlug must be provided"
51
- }
52
- );
53
-
54
- // src/schemas/cloudflare.ts
55
- var ConfigFnInputSchema = z2.function().args(z2.custom()).returns(z2.lazy(() => lockPageSlugRefinement(UseAppwardenInputSchema)));
30
+ var ConfigFnInputSchema = z.function().args(z.custom()).returns(z.lazy(() => lockPageSlugRefinement(UseAppwardenInputSchema)));
56
31
 
57
32
  // src/utils/middleware.ts
58
33
  var usePipeline = (...initMiddlewares) => {
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-DpmIa2tk.js';
1
+ export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware } from './use-content-security-policy-CvdzUPYF.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  declare const LOCKDOWN_TEST_EXPIRY_MS: number;
@@ -45,6 +45,418 @@ declare const isValidCacheUrl: {
45
45
  upstash: (value?: string) => string | boolean;
46
46
  };
47
47
 
48
+ declare const UseAppwardenInputSchema: z.ZodObject<{
49
+ debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
50
+ lockPageSlug: z.ZodOptional<z.ZodString>;
51
+ multidomainConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
52
+ lockPageSlug: z.ZodString;
53
+ contentSecurityPolicy: z.ZodOptional<z.ZodLazy<z.ZodObject<{
54
+ mode: z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>;
55
+ directives: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodObject<{
56
+ "default-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
57
+ "script-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
58
+ "style-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
59
+ "img-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
60
+ "connect-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
61
+ "font-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
62
+ "object-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
63
+ "media-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
64
+ "frame-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
65
+ sandbox: z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
66
+ "report-uri": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
67
+ "child-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
68
+ "form-action": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
69
+ "frame-ancestors": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
70
+ "plugin-types": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
71
+ "base-uri": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
72
+ "report-to": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
73
+ "worker-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
74
+ "manifest-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
75
+ "prefetch-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
76
+ "navigate-to": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
77
+ "require-sri-for": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
78
+ "block-all-mixed-content": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
79
+ "upgrade-insecure-requests": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
80
+ "trusted-types": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
81
+ "require-trusted-types-for": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
82
+ }, "strip", z.ZodTypeAny, {
83
+ "default-src"?: string | boolean | string[] | undefined;
84
+ "script-src"?: string | boolean | string[] | undefined;
85
+ "style-src"?: string | boolean | string[] | undefined;
86
+ "img-src"?: string | boolean | string[] | undefined;
87
+ "connect-src"?: string | boolean | string[] | undefined;
88
+ "font-src"?: string | boolean | string[] | undefined;
89
+ "object-src"?: string | boolean | string[] | undefined;
90
+ "media-src"?: string | boolean | string[] | undefined;
91
+ "frame-src"?: string | boolean | string[] | undefined;
92
+ sandbox?: string | boolean | string[] | undefined;
93
+ "report-uri"?: string | boolean | string[] | undefined;
94
+ "child-src"?: string | boolean | string[] | undefined;
95
+ "form-action"?: string | boolean | string[] | undefined;
96
+ "frame-ancestors"?: string | boolean | string[] | undefined;
97
+ "plugin-types"?: string | boolean | string[] | undefined;
98
+ "base-uri"?: string | boolean | string[] | undefined;
99
+ "report-to"?: string | boolean | string[] | undefined;
100
+ "worker-src"?: string | boolean | string[] | undefined;
101
+ "manifest-src"?: string | boolean | string[] | undefined;
102
+ "prefetch-src"?: string | boolean | string[] | undefined;
103
+ "navigate-to"?: string | boolean | string[] | undefined;
104
+ "require-sri-for"?: string | boolean | string[] | undefined;
105
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
106
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
107
+ "trusted-types"?: string | boolean | string[] | undefined;
108
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
109
+ }, {
110
+ "default-src"?: string | boolean | string[] | undefined;
111
+ "script-src"?: string | boolean | string[] | undefined;
112
+ "style-src"?: string | boolean | string[] | undefined;
113
+ "img-src"?: string | boolean | string[] | undefined;
114
+ "connect-src"?: string | boolean | string[] | undefined;
115
+ "font-src"?: string | boolean | string[] | undefined;
116
+ "object-src"?: string | boolean | string[] | undefined;
117
+ "media-src"?: string | boolean | string[] | undefined;
118
+ "frame-src"?: string | boolean | string[] | undefined;
119
+ sandbox?: string | boolean | string[] | undefined;
120
+ "report-uri"?: string | boolean | string[] | undefined;
121
+ "child-src"?: string | boolean | string[] | undefined;
122
+ "form-action"?: string | boolean | string[] | undefined;
123
+ "frame-ancestors"?: string | boolean | string[] | undefined;
124
+ "plugin-types"?: string | boolean | string[] | undefined;
125
+ "base-uri"?: string | boolean | string[] | undefined;
126
+ "report-to"?: string | boolean | string[] | undefined;
127
+ "worker-src"?: string | boolean | string[] | undefined;
128
+ "manifest-src"?: string | boolean | string[] | undefined;
129
+ "prefetch-src"?: string | boolean | string[] | undefined;
130
+ "navigate-to"?: string | boolean | string[] | undefined;
131
+ "require-sri-for"?: string | boolean | string[] | undefined;
132
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
133
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
134
+ "trusted-types"?: string | boolean | string[] | undefined;
135
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
136
+ }>]>, string | {
137
+ "default-src"?: string | boolean | string[] | undefined;
138
+ "script-src"?: string | boolean | string[] | undefined;
139
+ "style-src"?: string | boolean | string[] | undefined;
140
+ "img-src"?: string | boolean | string[] | undefined;
141
+ "connect-src"?: string | boolean | string[] | undefined;
142
+ "font-src"?: string | boolean | string[] | undefined;
143
+ "object-src"?: string | boolean | string[] | undefined;
144
+ "media-src"?: string | boolean | string[] | undefined;
145
+ "frame-src"?: string | boolean | string[] | undefined;
146
+ sandbox?: string | boolean | string[] | undefined;
147
+ "report-uri"?: string | boolean | string[] | undefined;
148
+ "child-src"?: string | boolean | string[] | undefined;
149
+ "form-action"?: string | boolean | string[] | undefined;
150
+ "frame-ancestors"?: string | boolean | string[] | undefined;
151
+ "plugin-types"?: string | boolean | string[] | undefined;
152
+ "base-uri"?: string | boolean | string[] | undefined;
153
+ "report-to"?: string | boolean | string[] | undefined;
154
+ "worker-src"?: string | boolean | string[] | undefined;
155
+ "manifest-src"?: string | boolean | string[] | undefined;
156
+ "prefetch-src"?: string | boolean | string[] | undefined;
157
+ "navigate-to"?: string | boolean | string[] | undefined;
158
+ "require-sri-for"?: string | boolean | string[] | undefined;
159
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
160
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
161
+ "trusted-types"?: string | boolean | string[] | undefined;
162
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
163
+ }, string | {
164
+ "default-src"?: string | boolean | string[] | undefined;
165
+ "script-src"?: string | boolean | string[] | undefined;
166
+ "style-src"?: string | boolean | string[] | undefined;
167
+ "img-src"?: string | boolean | string[] | undefined;
168
+ "connect-src"?: string | boolean | string[] | undefined;
169
+ "font-src"?: string | boolean | string[] | undefined;
170
+ "object-src"?: string | boolean | string[] | undefined;
171
+ "media-src"?: string | boolean | string[] | undefined;
172
+ "frame-src"?: string | boolean | string[] | undefined;
173
+ sandbox?: string | boolean | string[] | undefined;
174
+ "report-uri"?: string | boolean | string[] | undefined;
175
+ "child-src"?: string | boolean | string[] | undefined;
176
+ "form-action"?: string | boolean | string[] | undefined;
177
+ "frame-ancestors"?: string | boolean | string[] | undefined;
178
+ "plugin-types"?: string | boolean | string[] | undefined;
179
+ "base-uri"?: string | boolean | string[] | undefined;
180
+ "report-to"?: string | boolean | string[] | undefined;
181
+ "worker-src"?: string | boolean | string[] | undefined;
182
+ "manifest-src"?: string | boolean | string[] | undefined;
183
+ "prefetch-src"?: string | boolean | string[] | undefined;
184
+ "navigate-to"?: string | boolean | string[] | undefined;
185
+ "require-sri-for"?: string | boolean | string[] | undefined;
186
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
187
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
188
+ "trusted-types"?: string | boolean | string[] | undefined;
189
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
190
+ }>, {
191
+ "default-src"?: string | boolean | string[] | undefined;
192
+ "script-src"?: string | boolean | string[] | undefined;
193
+ "style-src"?: string | boolean | string[] | undefined;
194
+ "img-src"?: string | boolean | string[] | undefined;
195
+ "connect-src"?: string | boolean | string[] | undefined;
196
+ "font-src"?: string | boolean | string[] | undefined;
197
+ "object-src"?: string | boolean | string[] | undefined;
198
+ "media-src"?: string | boolean | string[] | undefined;
199
+ "frame-src"?: string | boolean | string[] | undefined;
200
+ sandbox?: string | boolean | string[] | undefined;
201
+ "report-uri"?: string | boolean | string[] | undefined;
202
+ "child-src"?: string | boolean | string[] | undefined;
203
+ "form-action"?: string | boolean | string[] | undefined;
204
+ "frame-ancestors"?: string | boolean | string[] | undefined;
205
+ "plugin-types"?: string | boolean | string[] | undefined;
206
+ "base-uri"?: string | boolean | string[] | undefined;
207
+ "report-to"?: string | boolean | string[] | undefined;
208
+ "worker-src"?: string | boolean | string[] | undefined;
209
+ "manifest-src"?: string | boolean | string[] | undefined;
210
+ "prefetch-src"?: string | boolean | string[] | undefined;
211
+ "navigate-to"?: string | boolean | string[] | undefined;
212
+ "require-sri-for"?: string | boolean | string[] | undefined;
213
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
214
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
215
+ "trusted-types"?: string | boolean | string[] | undefined;
216
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
217
+ } | undefined, string | {
218
+ "default-src"?: string | boolean | string[] | undefined;
219
+ "script-src"?: string | boolean | string[] | undefined;
220
+ "style-src"?: string | boolean | string[] | undefined;
221
+ "img-src"?: string | boolean | string[] | undefined;
222
+ "connect-src"?: string | boolean | string[] | undefined;
223
+ "font-src"?: string | boolean | string[] | undefined;
224
+ "object-src"?: string | boolean | string[] | undefined;
225
+ "media-src"?: string | boolean | string[] | undefined;
226
+ "frame-src"?: string | boolean | string[] | undefined;
227
+ sandbox?: string | boolean | string[] | undefined;
228
+ "report-uri"?: string | boolean | string[] | undefined;
229
+ "child-src"?: string | boolean | string[] | undefined;
230
+ "form-action"?: string | boolean | string[] | undefined;
231
+ "frame-ancestors"?: string | boolean | string[] | undefined;
232
+ "plugin-types"?: string | boolean | string[] | undefined;
233
+ "base-uri"?: string | boolean | string[] | undefined;
234
+ "report-to"?: string | boolean | string[] | undefined;
235
+ "worker-src"?: string | boolean | string[] | undefined;
236
+ "manifest-src"?: string | boolean | string[] | undefined;
237
+ "prefetch-src"?: string | boolean | string[] | undefined;
238
+ "navigate-to"?: string | boolean | string[] | undefined;
239
+ "require-sri-for"?: string | boolean | string[] | undefined;
240
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
241
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
242
+ "trusted-types"?: string | boolean | string[] | undefined;
243
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
244
+ }>;
245
+ }, "strip", z.ZodTypeAny, {
246
+ mode: "disabled" | "report-only" | "enforced";
247
+ directives?: {
248
+ "default-src"?: string | boolean | string[] | undefined;
249
+ "script-src"?: string | boolean | string[] | undefined;
250
+ "style-src"?: string | boolean | string[] | undefined;
251
+ "img-src"?: string | boolean | string[] | undefined;
252
+ "connect-src"?: string | boolean | string[] | undefined;
253
+ "font-src"?: string | boolean | string[] | undefined;
254
+ "object-src"?: string | boolean | string[] | undefined;
255
+ "media-src"?: string | boolean | string[] | undefined;
256
+ "frame-src"?: string | boolean | string[] | undefined;
257
+ sandbox?: string | boolean | string[] | undefined;
258
+ "report-uri"?: string | boolean | string[] | undefined;
259
+ "child-src"?: string | boolean | string[] | undefined;
260
+ "form-action"?: string | boolean | string[] | undefined;
261
+ "frame-ancestors"?: string | boolean | string[] | undefined;
262
+ "plugin-types"?: string | boolean | string[] | undefined;
263
+ "base-uri"?: string | boolean | string[] | undefined;
264
+ "report-to"?: string | boolean | string[] | undefined;
265
+ "worker-src"?: string | boolean | string[] | undefined;
266
+ "manifest-src"?: string | boolean | string[] | undefined;
267
+ "prefetch-src"?: string | boolean | string[] | undefined;
268
+ "navigate-to"?: string | boolean | string[] | undefined;
269
+ "require-sri-for"?: string | boolean | string[] | undefined;
270
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
271
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
272
+ "trusted-types"?: string | boolean | string[] | undefined;
273
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
274
+ } | undefined;
275
+ }, {
276
+ mode: "disabled" | "report-only" | "enforced";
277
+ directives: string | {
278
+ "default-src"?: string | boolean | string[] | undefined;
279
+ "script-src"?: string | boolean | string[] | undefined;
280
+ "style-src"?: string | boolean | string[] | undefined;
281
+ "img-src"?: string | boolean | string[] | undefined;
282
+ "connect-src"?: string | boolean | string[] | undefined;
283
+ "font-src"?: string | boolean | string[] | undefined;
284
+ "object-src"?: string | boolean | string[] | undefined;
285
+ "media-src"?: string | boolean | string[] | undefined;
286
+ "frame-src"?: string | boolean | string[] | undefined;
287
+ sandbox?: string | boolean | string[] | undefined;
288
+ "report-uri"?: string | boolean | string[] | undefined;
289
+ "child-src"?: string | boolean | string[] | undefined;
290
+ "form-action"?: string | boolean | string[] | undefined;
291
+ "frame-ancestors"?: string | boolean | string[] | undefined;
292
+ "plugin-types"?: string | boolean | string[] | undefined;
293
+ "base-uri"?: string | boolean | string[] | undefined;
294
+ "report-to"?: string | boolean | string[] | undefined;
295
+ "worker-src"?: string | boolean | string[] | undefined;
296
+ "manifest-src"?: string | boolean | string[] | undefined;
297
+ "prefetch-src"?: string | boolean | string[] | undefined;
298
+ "navigate-to"?: string | boolean | string[] | undefined;
299
+ "require-sri-for"?: string | boolean | string[] | undefined;
300
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
301
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
302
+ "trusted-types"?: string | boolean | string[] | undefined;
303
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
304
+ };
305
+ }>>>;
306
+ debug: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
307
+ }, "strip", z.ZodTypeAny, {
308
+ lockPageSlug: string;
309
+ debug?: boolean | undefined;
310
+ contentSecurityPolicy?: {
311
+ mode: "disabled" | "report-only" | "enforced";
312
+ directives?: {
313
+ "default-src"?: string | boolean | string[] | undefined;
314
+ "script-src"?: string | boolean | string[] | undefined;
315
+ "style-src"?: string | boolean | string[] | undefined;
316
+ "img-src"?: string | boolean | string[] | undefined;
317
+ "connect-src"?: string | boolean | string[] | undefined;
318
+ "font-src"?: string | boolean | string[] | undefined;
319
+ "object-src"?: string | boolean | string[] | undefined;
320
+ "media-src"?: string | boolean | string[] | undefined;
321
+ "frame-src"?: string | boolean | string[] | undefined;
322
+ sandbox?: string | boolean | string[] | undefined;
323
+ "report-uri"?: string | boolean | string[] | undefined;
324
+ "child-src"?: string | boolean | string[] | undefined;
325
+ "form-action"?: string | boolean | string[] | undefined;
326
+ "frame-ancestors"?: string | boolean | string[] | undefined;
327
+ "plugin-types"?: string | boolean | string[] | undefined;
328
+ "base-uri"?: string | boolean | string[] | undefined;
329
+ "report-to"?: string | boolean | string[] | undefined;
330
+ "worker-src"?: string | boolean | string[] | undefined;
331
+ "manifest-src"?: string | boolean | string[] | undefined;
332
+ "prefetch-src"?: string | boolean | string[] | undefined;
333
+ "navigate-to"?: string | boolean | string[] | undefined;
334
+ "require-sri-for"?: string | boolean | string[] | undefined;
335
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
336
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
337
+ "trusted-types"?: string | boolean | string[] | undefined;
338
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
339
+ } | undefined;
340
+ } | undefined;
341
+ }, {
342
+ lockPageSlug: string;
343
+ debug?: string | boolean | undefined;
344
+ contentSecurityPolicy?: {
345
+ mode: "disabled" | "report-only" | "enforced";
346
+ directives: string | {
347
+ "default-src"?: string | boolean | string[] | undefined;
348
+ "script-src"?: string | boolean | string[] | undefined;
349
+ "style-src"?: string | boolean | string[] | undefined;
350
+ "img-src"?: string | boolean | string[] | undefined;
351
+ "connect-src"?: string | boolean | string[] | undefined;
352
+ "font-src"?: string | boolean | string[] | undefined;
353
+ "object-src"?: string | boolean | string[] | undefined;
354
+ "media-src"?: string | boolean | string[] | undefined;
355
+ "frame-src"?: string | boolean | string[] | undefined;
356
+ sandbox?: string | boolean | string[] | undefined;
357
+ "report-uri"?: string | boolean | string[] | undefined;
358
+ "child-src"?: string | boolean | string[] | undefined;
359
+ "form-action"?: string | boolean | string[] | undefined;
360
+ "frame-ancestors"?: string | boolean | string[] | undefined;
361
+ "plugin-types"?: string | boolean | string[] | undefined;
362
+ "base-uri"?: string | boolean | string[] | undefined;
363
+ "report-to"?: string | boolean | string[] | undefined;
364
+ "worker-src"?: string | boolean | string[] | undefined;
365
+ "manifest-src"?: string | boolean | string[] | undefined;
366
+ "prefetch-src"?: string | boolean | string[] | undefined;
367
+ "navigate-to"?: string | boolean | string[] | undefined;
368
+ "require-sri-for"?: string | boolean | string[] | undefined;
369
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
370
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
371
+ "trusted-types"?: string | boolean | string[] | undefined;
372
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
373
+ };
374
+ } | undefined;
375
+ }>>>;
376
+ appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
377
+ appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
378
+ }, "strip", z.ZodTypeAny, {
379
+ debug: boolean;
380
+ appwardenApiToken: string;
381
+ lockPageSlug?: string | undefined;
382
+ multidomainConfig?: Record<string, {
383
+ lockPageSlug: string;
384
+ debug?: boolean | undefined;
385
+ contentSecurityPolicy?: {
386
+ mode: "disabled" | "report-only" | "enforced";
387
+ directives?: {
388
+ "default-src"?: string | boolean | string[] | undefined;
389
+ "script-src"?: string | boolean | string[] | undefined;
390
+ "style-src"?: string | boolean | string[] | undefined;
391
+ "img-src"?: string | boolean | string[] | undefined;
392
+ "connect-src"?: string | boolean | string[] | undefined;
393
+ "font-src"?: string | boolean | string[] | undefined;
394
+ "object-src"?: string | boolean | string[] | undefined;
395
+ "media-src"?: string | boolean | string[] | undefined;
396
+ "frame-src"?: string | boolean | string[] | undefined;
397
+ sandbox?: string | boolean | string[] | undefined;
398
+ "report-uri"?: string | boolean | string[] | undefined;
399
+ "child-src"?: string | boolean | string[] | undefined;
400
+ "form-action"?: string | boolean | string[] | undefined;
401
+ "frame-ancestors"?: string | boolean | string[] | undefined;
402
+ "plugin-types"?: string | boolean | string[] | undefined;
403
+ "base-uri"?: string | boolean | string[] | undefined;
404
+ "report-to"?: string | boolean | string[] | undefined;
405
+ "worker-src"?: string | boolean | string[] | undefined;
406
+ "manifest-src"?: string | boolean | string[] | undefined;
407
+ "prefetch-src"?: string | boolean | string[] | undefined;
408
+ "navigate-to"?: string | boolean | string[] | undefined;
409
+ "require-sri-for"?: string | boolean | string[] | undefined;
410
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
411
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
412
+ "trusted-types"?: string | boolean | string[] | undefined;
413
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
414
+ } | undefined;
415
+ } | undefined;
416
+ }> | undefined;
417
+ appwardenApiHostname?: string | undefined;
418
+ }, {
419
+ appwardenApiToken: string;
420
+ debug?: string | boolean | undefined;
421
+ lockPageSlug?: string | undefined;
422
+ multidomainConfig?: Record<string, {
423
+ lockPageSlug: string;
424
+ debug?: string | boolean | undefined;
425
+ contentSecurityPolicy?: {
426
+ mode: "disabled" | "report-only" | "enforced";
427
+ directives: string | {
428
+ "default-src"?: string | boolean | string[] | undefined;
429
+ "script-src"?: string | boolean | string[] | undefined;
430
+ "style-src"?: string | boolean | string[] | undefined;
431
+ "img-src"?: string | boolean | string[] | undefined;
432
+ "connect-src"?: string | boolean | string[] | undefined;
433
+ "font-src"?: string | boolean | string[] | undefined;
434
+ "object-src"?: string | boolean | string[] | undefined;
435
+ "media-src"?: string | boolean | string[] | undefined;
436
+ "frame-src"?: string | boolean | string[] | undefined;
437
+ sandbox?: string | boolean | string[] | undefined;
438
+ "report-uri"?: string | boolean | string[] | undefined;
439
+ "child-src"?: string | boolean | string[] | undefined;
440
+ "form-action"?: string | boolean | string[] | undefined;
441
+ "frame-ancestors"?: string | boolean | string[] | undefined;
442
+ "plugin-types"?: string | boolean | string[] | undefined;
443
+ "base-uri"?: string | boolean | string[] | undefined;
444
+ "report-to"?: string | boolean | string[] | undefined;
445
+ "worker-src"?: string | boolean | string[] | undefined;
446
+ "manifest-src"?: string | boolean | string[] | undefined;
447
+ "prefetch-src"?: string | boolean | string[] | undefined;
448
+ "navigate-to"?: string | boolean | string[] | undefined;
449
+ "require-sri-for"?: string | boolean | string[] | undefined;
450
+ "block-all-mixed-content"?: string | boolean | string[] | undefined;
451
+ "upgrade-insecure-requests"?: string | boolean | string[] | undefined;
452
+ "trusted-types"?: string | boolean | string[] | undefined;
453
+ "require-trusted-types-for"?: string | boolean | string[] | undefined;
454
+ };
455
+ } | undefined;
456
+ }> | undefined;
457
+ appwardenApiHostname?: string | undefined;
458
+ }>;
459
+
48
460
  declare const LockValue: z.ZodObject<{
49
461
  isLocked: z.ZodNumber;
50
462
  isLockedTest: z.ZodNumber;
@@ -60,4 +472,4 @@ declare const LockValue: z.ZodObject<{
60
472
  }>;
61
473
  type LockValueType = z.infer<typeof LockValue>;
62
474
 
63
- export { APPWARDEN_CACHE_KEY, LOCKDOWN_TEST_EXPIRY_MS, type LockValueType, getEdgeConfigId, isCacheUrl, isValidCacheUrl };
475
+ export { APPWARDEN_CACHE_KEY, LOCKDOWN_TEST_EXPIRY_MS, type LockValueType, UseAppwardenInputSchema, getEdgeConfigId, isCacheUrl, isValidCacheUrl };
package/index.js CHANGED
@@ -4,22 +4,22 @@ import {
4
4
  isValidCacheUrl
5
5
  } from "./chunk-QEFORWCW.js";
6
6
  import {
7
- useContentSecurityPolicy
8
- } from "./chunk-K7ZIT3FM.js";
7
+ UseAppwardenInputSchema
8
+ } from "./chunk-4ADGOFLV.js";
9
9
  import {
10
10
  APPWARDEN_CACHE_KEY,
11
11
  CSPDirectivesSchema,
12
12
  CSPModeSchema,
13
13
  LOCKDOWN_TEST_EXPIRY_MS
14
- } from "./chunk-2WPLLVUI.js";
15
- import "./chunk-QUVGY2YI.js";
14
+ } from "./chunk-ZTVJBORU.js";
15
+ import "./chunk-WEM7GS4M.js";
16
16
  export {
17
17
  APPWARDEN_CACHE_KEY,
18
18
  CSPDirectivesSchema,
19
19
  CSPModeSchema,
20
20
  LOCKDOWN_TEST_EXPIRY_MS,
21
+ UseAppwardenInputSchema,
21
22
  getEdgeConfigId,
22
23
  isCacheUrl,
23
- isValidCacheUrl,
24
- useContentSecurityPolicy
24
+ isValidCacheUrl
25
25
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "3.11.1",
3
+ "version": "3.11.3",
4
4
  "description": "Instantly disable all user interaction with your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -120,7 +120,7 @@
120
120
  "serialize-javascript@<=7.0.2": ">=7.0.3",
121
121
  "svgo@=4.0.0": ">=4.0.1",
122
122
  "@opennextjs/cloudflare@<1.17.1": ">=1.17.1",
123
- "tar@<=7.5.9": ">=7.5.10"
123
+ "tar@<=7.5.10": ">=7.5.11"
124
124
  }
125
125
  }
126
126
  }
@@ -121,6 +121,15 @@ declare global {
121
121
  interface Env extends Bindings {
122
122
  }
123
123
  }
124
+ /**
125
+ * Cloudflare request context shape used by withAppwarden config functions.
126
+ * This matches the context passed to config functions in appwardenOnCloudflare.
127
+ */
128
+ type RequestContext = {
129
+ env: Bindings;
130
+ ctx: ExecutionContext;
131
+ cf: unknown;
132
+ };
124
133
 
125
134
  interface MiddlewareContext {
126
135
  hostname: string;
@@ -471,6 +480,4 @@ declare const UseCSPInputSchema: z.ZodObject<{
471
480
  }>;
472
481
  type UseCSPInput = z.infer<typeof UseCSPInputSchema>;
473
482
 
474
- declare const useContentSecurityPolicy: (input: UseCSPInput) => Middleware;
475
-
476
- export { type Bindings as B, CSPDirectivesSchema as C, type Middleware as M, CSPModeSchema as a, useContentSecurityPolicy as u };
483
+ export { type Bindings as B, CSPDirectivesSchema as C, type Middleware as M, type RequestContext as R, type UseCSPInput as U, CSPModeSchema as a };
package/vercel.d.ts CHANGED
@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
  declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
4
4
  cacheUrl: z.ZodString;
5
5
  appwardenApiToken: z.ZodString;
6
- appwardenApiHostname: z.ZodOptional<z.ZodString>;
6
+ appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
7
7
  vercelApiToken: z.ZodOptional<z.ZodString>;
8
8
  debug: z.ZodOptional<z.ZodBoolean>;
9
9
  lockPageSlug: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
package/vercel.js CHANGED
@@ -7,22 +7,25 @@ import {
7
7
  TEMPORARY_REDIRECT_STATUS,
8
8
  buildLockPageUrl,
9
9
  debug,
10
+ isHTMLRequest,
10
11
  isOnLockPage
11
- } from "./chunk-KE2UVIYR.js";
12
+ } from "./chunk-AY4ZKZTF.js";
12
13
  import {
13
14
  APPWARDEN_CACHE_KEY,
14
15
  CSPDirectivesSchema,
15
16
  CSPModeSchema,
16
17
  errors,
17
- globalErrors,
18
- isHTMLRequest
19
- } from "./chunk-2WPLLVUI.js";
18
+ globalErrors
19
+ } from "./chunk-ZTVJBORU.js";
20
20
  import {
21
- LockValue,
22
21
  getErrors,
23
22
  makeCSPHeader,
24
23
  printMessage
25
- } from "./chunk-QUVGY2YI.js";
24
+ } from "./chunk-R7TXTHSG.js";
25
+ import {
26
+ AppwardenApiHostnameSchema,
27
+ LockValue
28
+ } from "./chunk-WEM7GS4M.js";
26
29
 
27
30
  // src/runners/appwarden-on-vercel.ts
28
31
  import { waitUntil } from "@vercel/functions";
@@ -183,7 +186,7 @@ var VercelCSPSchema = z.object({
183
186
  var BaseNextJsConfigSchema = z.object({
184
187
  cacheUrl: z.string(),
185
188
  appwardenApiToken: z.string(),
186
- appwardenApiHostname: z.string().optional(),
189
+ appwardenApiHostname: AppwardenApiHostnameSchema.optional(),
187
190
  vercelApiToken: z.string().optional(),
188
191
  debug: z.boolean().optional(),
189
192
  lockPageSlug: z.string().default("").transform((val) => val.replace(/^\/?/, "/")),