@appwarden/middleware 3.11.2 → 3.11.4

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.05%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,38 @@
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
+ contentSecurityPolicy: z.lazy(() => UseCSPInputSchema).optional(),
24
+ multidomainConfig: AppwardenMultidomainConfigSchema.optional(),
25
+ appwardenApiToken: AppwardenApiTokenSchema,
26
+ appwardenApiHostname: AppwardenApiHostnameSchema.optional()
27
+ });
28
+ var lockPageSlugRefinement = (schema) => schema.refine(
29
+ (data) => data.lockPageSlug || data.multidomainConfig,
30
+ {
31
+ message: "lockPageSlug must be provided"
32
+ }
33
+ );
34
+
35
+ export {
36
+ UseAppwardenInputSchema,
37
+ lockPageSlugRefinement
38
+ };
@@ -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-ASH6UZ27.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-6JYUNSUJ.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-ASH6UZ27.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,29 +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 AppwardenApiHostnameSchema = z.string().url({
117
- message: "Invalid `appwardenApiHostname`. Please provide an absolute URL (e.g. https://api.appwarden.io)."
118
- }).refine((value) => value.startsWith("https://"), {
119
- message: "`appwardenApiHostname` must use the https:// scheme (e.g. https://api.appwarden.io)."
120
- });
121
- var LockValue = z.object({
122
- isLocked: z.number(),
123
- isLockedTest: z.number(),
124
- lastCheck: z.number()
125
- });
126
-
127
108
  // src/utils/errors.ts
128
109
  var errorsMap = {
129
110
  mode: '`CSP_MODE` must be one of "disabled", "report-only", or "enforced"',
@@ -309,10 +290,6 @@ var syncEdgeValue = async (context) => {
309
290
  export {
310
291
  printMessage,
311
292
  getErrors,
312
- BooleanSchema,
313
- AppwardenApiTokenSchema,
314
- AppwardenApiHostnameSchema,
315
- LockValue,
316
293
  store,
317
294
  CSP_KEYWORDS,
318
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-ASH6UZ27.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
  };
@@ -270,8 +270,8 @@ declare const AstroCloudflareConfigSchema: z.ZodObject<{
270
270
  };
271
271
  }>>>;
272
272
  }, "strip", z.ZodTypeAny, {
273
- debug: boolean;
274
273
  lockPageSlug: string;
274
+ debug: boolean;
275
275
  appwardenApiToken: string;
276
276
  contentSecurityPolicy?: {
277
277
  mode: "disabled" | "report-only" | "enforced";
@@ -308,7 +308,6 @@ declare const AstroCloudflareConfigSchema: z.ZodObject<{
308
308
  }, {
309
309
  lockPageSlug: string;
310
310
  appwardenApiToken: string;
311
- debug?: string | boolean | undefined;
312
311
  contentSecurityPolicy?: {
313
312
  mode: "disabled" | "report-only" | "enforced";
314
313
  directives: string | {
@@ -340,6 +339,7 @@ declare const AstroCloudflareConfigSchema: z.ZodObject<{
340
339
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
341
340
  };
342
341
  } | undefined;
342
+ debug?: string | boolean | undefined;
343
343
  appwardenApiHostname?: string | undefined;
344
344
  }>;
345
345
  type AstroCloudflareConfig = z.infer<typeof AstroCloudflareConfigSchema>;
@@ -3,30 +3,32 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-RQLMO5FA.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-VQIRZMED.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-6JYUNSUJ.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
+ import {
25
+ printMessage
26
+ } from "../chunk-R7TXTHSG.js";
24
27
  import {
25
28
  AppwardenApiHostnameSchema,
26
29
  AppwardenApiTokenSchema,
27
- BooleanSchema,
28
- printMessage
29
- } from "../chunk-ASH6UZ27.js";
30
+ BooleanSchema
31
+ } from "../chunk-WEM7GS4M.js";
30
32
 
31
33
  // src/adapters/astro-cloudflare.ts
32
34
  import { waitUntil } from "cloudflare:workers";
@@ -329,8 +329,8 @@ declare const NextJsCloudflareConfigSchema: z.ZodObject<{
329
329
  };
330
330
  }>>>;
331
331
  }, "strip", z.ZodTypeAny, {
332
- debug: boolean;
333
332
  lockPageSlug: string;
333
+ debug: boolean;
334
334
  appwardenApiToken: string;
335
335
  contentSecurityPolicy?: {
336
336
  mode: "disabled" | "report-only" | "enforced";
@@ -367,7 +367,6 @@ declare const NextJsCloudflareConfigSchema: z.ZodObject<{
367
367
  }, {
368
368
  lockPageSlug: string;
369
369
  appwardenApiToken: string;
370
- debug?: string | boolean | undefined;
371
370
  contentSecurityPolicy?: {
372
371
  mode: "disabled" | "report-only" | "enforced";
373
372
  directives: string | {
@@ -399,6 +398,7 @@ declare const NextJsCloudflareConfigSchema: z.ZodObject<{
399
398
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
400
399
  };
401
400
  } | undefined;
401
+ debug?: string | boolean | undefined;
402
402
  appwardenApiHostname?: string | undefined;
403
403
  }>;
404
404
  type NextJsCloudflareConfig = z.infer<typeof NextJsCloudflareConfigSchema>;
@@ -3,23 +3,25 @@ import {
3
3
  } from "../chunk-X7WZVYQS.js";
4
4
  import {
5
5
  checkLockStatus
6
- } from "../chunk-VQIRZMED.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-6JYUNSUJ.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
+ import {
18
+ printMessage
19
+ } from "../chunk-R7TXTHSG.js";
17
20
  import {
18
21
  AppwardenApiHostnameSchema,
19
22
  AppwardenApiTokenSchema,
20
- BooleanSchema,
21
- printMessage
22
- } from "../chunk-ASH6UZ27.js";
23
+ BooleanSchema
24
+ } from "../chunk-WEM7GS4M.js";
23
25
 
24
26
  // src/adapters/nextjs-cloudflare.ts
25
27
  import {
@@ -102,7 +104,7 @@ function createAppwardenMiddleware(configFn) {
102
104
  debugFn(
103
105
  `Applying CSP headers in ${config.contentSecurityPolicy.mode} mode`
104
106
  );
105
- const { makeCSPHeader } = await import("../cloudflare-TJXWELMX.js");
107
+ const { makeCSPHeader } = await import("../cloudflare-MAHYENA6.js");
106
108
  const [headerName, headerValue] = makeCSPHeader(
107
109
  "",
108
110
  config.contentSecurityPolicy.directives,
@@ -268,8 +268,8 @@ declare const ReactRouterCloudflareConfigSchema: z.ZodObject<{
268
268
  };
269
269
  }>>>;
270
270
  }, "strip", z.ZodTypeAny, {
271
- debug: boolean;
272
271
  lockPageSlug: string;
272
+ debug: boolean;
273
273
  appwardenApiToken: string;
274
274
  contentSecurityPolicy?: {
275
275
  mode: "disabled" | "report-only" | "enforced";
@@ -306,7 +306,6 @@ declare const ReactRouterCloudflareConfigSchema: z.ZodObject<{
306
306
  }, {
307
307
  lockPageSlug: string;
308
308
  appwardenApiToken: string;
309
- debug?: string | boolean | undefined;
310
309
  contentSecurityPolicy?: {
311
310
  mode: "disabled" | "report-only" | "enforced";
312
311
  directives: string | {
@@ -338,6 +337,7 @@ declare const ReactRouterCloudflareConfigSchema: z.ZodObject<{
338
337
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
339
338
  };
340
339
  } | undefined;
340
+ debug?: string | boolean | undefined;
341
341
  appwardenApiHostname?: string | undefined;
342
342
  }>;
343
343
  type ReactRouterCloudflareConfig = z.infer<typeof ReactRouterCloudflareConfigSchema>;
@@ -3,29 +3,31 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-RQLMO5FA.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-VQIRZMED.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-6JYUNSUJ.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
+ import {
24
+ printMessage
25
+ } from "../chunk-R7TXTHSG.js";
23
26
  import {
24
27
  AppwardenApiHostnameSchema,
25
28
  AppwardenApiTokenSchema,
26
- BooleanSchema,
27
- printMessage
28
- } from "../chunk-ASH6UZ27.js";
29
+ BooleanSchema
30
+ } from "../chunk-WEM7GS4M.js";
29
31
 
30
32
  // src/adapters/react-router-cloudflare.ts
31
33
  import { waitUntil } from "cloudflare:workers";
@@ -268,8 +268,8 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
268
268
  };
269
269
  }>>>;
270
270
  }, "strip", z.ZodTypeAny, {
271
- debug: boolean;
272
271
  lockPageSlug: string;
272
+ debug: boolean;
273
273
  appwardenApiToken: string;
274
274
  contentSecurityPolicy?: {
275
275
  mode: "disabled" | "report-only" | "enforced";
@@ -306,7 +306,6 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
306
306
  }, {
307
307
  lockPageSlug: string;
308
308
  appwardenApiToken: string;
309
- debug?: string | boolean | undefined;
310
309
  contentSecurityPolicy?: {
311
310
  mode: "disabled" | "report-only" | "enforced";
312
311
  directives: string | {
@@ -338,6 +337,7 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
338
337
  "require-trusted-types-for"?: string | boolean | string[] | undefined;
339
338
  };
340
339
  } | undefined;
340
+ debug?: string | boolean | undefined;
341
341
  appwardenApiHostname?: string | undefined;
342
342
  }>;
343
343
  type TanStackStartCloudflareConfig = z.infer<typeof TanStackStartCloudflareConfigSchema>;
@@ -3,29 +3,31 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-RQLMO5FA.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-VQIRZMED.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-6JYUNSUJ.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
+ import {
24
+ printMessage
25
+ } from "../chunk-R7TXTHSG.js";
23
26
  import {
24
27
  AppwardenApiHostnameSchema,
25
28
  AppwardenApiTokenSchema,
26
- BooleanSchema,
27
- printMessage
28
- } from "../chunk-ASH6UZ27.js";
29
+ BooleanSchema
30
+ } from "../chunk-WEM7GS4M.js";
29
31
 
30
32
  // src/adapters/tanstack-start-cloudflare.ts
31
33
  import { waitUntil } from "cloudflare:workers";
@@ -11,7 +11,8 @@ import {
11
11
  makeCSPHeader,
12
12
  store,
13
13
  syncEdgeValue
14
- } from "./chunk-ASH6UZ27.js";
14
+ } from "./chunk-R7TXTHSG.js";
15
+ import "./chunk-WEM7GS4M.js";
15
16
  export {
16
17
  CSP_KEYWORDS,
17
18
  autoQuoteCSPDirectiveArray,