@appwarden/middleware 3.9.1 → 3.10.1

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
@@ -112,7 +112,7 @@ import { createAppwardenMiddleware } from "@appwarden/middleware/cloudflare"
112
112
 
113
113
  const appwardenHandler = createAppwardenMiddleware((cloudflare) => ({
114
114
  debug: cloudflare.env.DEBUG,
115
- lockPageSlug: cloudflare.env.LOCK_PAGE_SLUG,
115
+ lockPageSlug: cloudflare.env.APPWARDEN_LOCK_PAGE_SLUG,
116
116
  appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
117
117
  contentSecurityPolicy: {
118
118
  mode: cloudflare.env.CSP_MODE,
@@ -45,7 +45,31 @@ function isHTMLResponse(response) {
45
45
  return response.headers.get("Content-Type")?.includes("text/html") ?? false;
46
46
  }
47
47
  function isHTMLRequest(request) {
48
- return request.headers.get("accept")?.includes("text/html") ?? false;
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 mediaRanges = value.split(",");
55
+ let hasNonEmptyRange = false;
56
+ for (const range of mediaRanges) {
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
+ return normalizedAccept.includes("text/html");
49
73
  }
50
74
 
51
75
  // src/schemas/use-content-security-policy.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  LOCKDOWN_TEST_EXPIRY_MS
3
- } from "./chunk-UIIYORBW.js";
3
+ } from "./chunk-6O25N45F.js";
4
4
  import {
5
5
  printMessage
6
6
  } from "./chunk-QGXPAVOA.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  MemoryCache,
3
3
  debug
4
- } from "./chunk-Z7FIMIZS.js";
4
+ } from "./chunk-HIGZSGKS.js";
5
5
  import {
6
6
  APPWARDEN_CACHE_KEY,
7
7
  APPWARDEN_TEST_ROUTE
8
- } from "./chunk-UIIYORBW.js";
8
+ } from "./chunk-6O25N45F.js";
9
9
  import {
10
10
  deleteEdgeValue,
11
11
  getLockValue,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UseCSPInputSchema,
3
3
  isHTMLResponse
4
- } from "./chunk-UIIYORBW.js";
4
+ } from "./chunk-6O25N45F.js";
5
5
  import {
6
6
  makeCSPHeader
7
7
  } from "./chunk-QGXPAVOA.js";
@@ -3,24 +3,24 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-VSCXTBP6.js";
6
+ } from "../chunk-ZQNXNGLV.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-MYIKUPTR.js";
12
+ } from "../chunk-TASPCREA.js";
13
13
  import {
14
14
  TEMPORARY_REDIRECT_STATUS,
15
15
  buildLockPageUrl,
16
16
  createRedirect,
17
17
  debug,
18
18
  isOnLockPage
19
- } from "../chunk-Z7FIMIZS.js";
19
+ } from "../chunk-HIGZSGKS.js";
20
20
  import {
21
21
  UseCSPInputSchema,
22
22
  isHTMLRequest
23
- } from "../chunk-UIIYORBW.js";
23
+ } from "../chunk-6O25N45F.js";
24
24
  import {
25
25
  AppwardenApiTokenSchema,
26
26
  BooleanSchema,
@@ -3,17 +3,17 @@ import {
3
3
  } from "../chunk-X7WZVYQS.js";
4
4
  import {
5
5
  checkLockStatus
6
- } from "../chunk-MYIKUPTR.js";
6
+ } from "../chunk-TASPCREA.js";
7
7
  import {
8
8
  TEMPORARY_REDIRECT_STATUS,
9
9
  buildLockPageUrl,
10
10
  debug,
11
11
  isOnLockPage
12
- } from "../chunk-Z7FIMIZS.js";
12
+ } from "../chunk-HIGZSGKS.js";
13
13
  import {
14
14
  UseCSPInputSchema,
15
15
  isHTMLRequest
16
- } from "../chunk-UIIYORBW.js";
16
+ } from "../chunk-6O25N45F.js";
17
17
  import {
18
18
  AppwardenApiTokenSchema,
19
19
  BooleanSchema,
@@ -3,23 +3,23 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-VSCXTBP6.js";
6
+ } from "../chunk-ZQNXNGLV.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-MYIKUPTR.js";
12
+ } from "../chunk-TASPCREA.js";
13
13
  import {
14
14
  buildLockPageUrl,
15
15
  createRedirect,
16
16
  debug,
17
17
  isOnLockPage
18
- } from "../chunk-Z7FIMIZS.js";
18
+ } from "../chunk-HIGZSGKS.js";
19
19
  import {
20
20
  UseCSPInputSchema,
21
21
  isHTMLRequest
22
- } from "../chunk-UIIYORBW.js";
22
+ } from "../chunk-6O25N45F.js";
23
23
  import {
24
24
  AppwardenApiTokenSchema,
25
25
  BooleanSchema,
@@ -3,23 +3,23 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-VSCXTBP6.js";
6
+ } from "../chunk-ZQNXNGLV.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-MYIKUPTR.js";
12
+ } from "../chunk-TASPCREA.js";
13
13
  import {
14
14
  buildLockPageUrl,
15
15
  createRedirect,
16
16
  debug,
17
17
  isOnLockPage
18
- } from "../chunk-Z7FIMIZS.js";
18
+ } from "../chunk-HIGZSGKS.js";
19
19
  import {
20
20
  UseCSPInputSchema,
21
21
  isHTMLRequest
22
- } from "../chunk-UIIYORBW.js";
22
+ } from "../chunk-6O25N45F.js";
23
23
  import {
24
24
  AppwardenApiTokenSchema,
25
25
  BooleanSchema,
package/cloudflare.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as Bindings } from './use-content-security-policy-jlU0Hjj8.js';
2
- export { u as useContentSecurityPolicy } from './use-content-security-policy-jlU0Hjj8.js';
1
+ import { B as Bindings } from './use-content-security-policy-DpmIa2tk.js';
2
+ export { u as useContentSecurityPolicy } from './use-content-security-policy-DpmIa2tk.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  declare const UseAppwardenInputSchema: z.ZodObject<{
package/cloudflare.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  useContentSecurityPolicy
3
- } from "./chunk-VSCXTBP6.js";
3
+ } from "./chunk-ZQNXNGLV.js";
4
4
  import {
5
5
  checkLockStatus
6
- } from "./chunk-MYIKUPTR.js";
6
+ } from "./chunk-TASPCREA.js";
7
7
  import {
8
8
  buildLockPageUrl,
9
9
  createRedirect,
10
10
  debug,
11
11
  isOnLockPage
12
- } from "./chunk-Z7FIMIZS.js";
12
+ } from "./chunk-HIGZSGKS.js";
13
13
  import {
14
14
  UseCSPInputSchema,
15
15
  isHTMLRequest
16
- } from "./chunk-UIIYORBW.js";
16
+ } from "./chunk-6O25N45F.js";
17
17
  import {
18
18
  AppwardenApiTokenSchema,
19
19
  BooleanSchema,
@@ -123,8 +123,7 @@ var useAppwarden = (input) => async (context, next) => {
123
123
  var useFetchOrigin = () => async (context, next) => {
124
124
  context.response = await fetch(
125
125
  new Request(context.request, {
126
- ...context.request,
127
- redirect: "follow"
126
+ redirect: "manual"
128
127
  })
129
128
  );
130
129
  await next();
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-jlU0Hjj8.js';
1
+ export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-DpmIa2tk.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  declare const LOCKDOWN_TEST_EXPIRY_MS: number;
package/index.js CHANGED
@@ -5,13 +5,13 @@ import {
5
5
  } from "./chunk-QEFORWCW.js";
6
6
  import {
7
7
  useContentSecurityPolicy
8
- } from "./chunk-VSCXTBP6.js";
8
+ } from "./chunk-ZQNXNGLV.js";
9
9
  import {
10
10
  APPWARDEN_CACHE_KEY,
11
11
  CSPDirectivesSchema,
12
12
  CSPModeSchema,
13
13
  LOCKDOWN_TEST_EXPIRY_MS
14
- } from "./chunk-UIIYORBW.js";
14
+ } from "./chunk-6O25N45F.js";
15
15
  import "./chunk-QGXPAVOA.js";
16
16
  export {
17
17
  APPWARDEN_CACHE_KEY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "3.9.1",
3
+ "version": "3.10.1",
4
4
  "description": "Instantly disable all user interaction with your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -84,16 +84,41 @@ declare const ContentSecurityPolicySchema: z.ZodObject<{
84
84
  }>;
85
85
  type ContentSecurityPolicyType = z.infer<typeof ContentSecurityPolicySchema>;
86
86
 
87
+ /**
88
+ * Fallback bindings type for when Wrangler types are not available.
89
+ * This provides a minimal type definition for development.
90
+ *
91
+ * When users run `wrangler types`, it generates:
92
+ * - `declare namespace Cloudflare { interface Env { ... } }`
93
+ * - `interface Env extends Cloudflare.Env {}`
94
+ *
95
+ * Our CloudflareEnv should pick up the user's generated Env type first.
96
+ */
87
97
  type Bindings = {
88
- DEBUG: string | boolean;
89
- LOCK_PAGE_SLUG: string;
90
- CSP_MODE: "disabled" | "report-only" | "enforced";
91
- CSP_DIRECTIVES: string | ContentSecurityPolicyType;
92
- APPWARDEN_API_TOKEN: string;
98
+ DEBUG?: string | boolean;
99
+ APPWARDEN_LOCK_PAGE_SLUG?: string;
100
+ CSP_MODE?: "disabled" | "report-only" | "enforced";
101
+ CSP_DIRECTIVES?: string | ContentSecurityPolicyType;
102
+ APPWARDEN_API_TOKEN?: string;
93
103
  APPWARDEN_API_HOSTNAME?: string;
94
104
  };
95
105
  declare global {
96
- interface CloudflareEnv extends Bindings {
106
+ /**
107
+ * CloudflareEnv is the global type used by all adapters.
108
+ *
109
+ * TypeScript's declaration merging means:
110
+ * 1. If user has Wrangler-generated `interface Env`, CloudflareEnv will extend it
111
+ * 2. If not, CloudflareEnv will extend our fallback Bindings type
112
+ *
113
+ * This ensures Wrangler types take precedence when available.
114
+ */
115
+ interface CloudflareEnv extends Env {
116
+ }
117
+ /**
118
+ * Fallback Env interface when Wrangler types are not generated.
119
+ * If the user runs `wrangler types`, their generated Env will merge with this.
120
+ */
121
+ interface Env extends Bindings {
97
122
  }
98
123
  }
99
124
 
package/vercel.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  buildLockPageUrl,
9
9
  debug,
10
10
  isOnLockPage
11
- } from "./chunk-Z7FIMIZS.js";
11
+ } from "./chunk-HIGZSGKS.js";
12
12
  import {
13
13
  APPWARDEN_CACHE_KEY,
14
14
  CSPDirectivesSchema,
@@ -16,7 +16,7 @@ import {
16
16
  errors,
17
17
  globalErrors,
18
18
  isHTMLRequest
19
- } from "./chunk-UIIYORBW.js";
19
+ } from "./chunk-6O25N45F.js";
20
20
  import {
21
21
  LockValue,
22
22
  getErrors,