@appwarden/middleware 3.13.1 → 3.13.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-94.02%25-brightgreen)
7
+ ![Test Coverage](https://img.shields.io/badge/coverage-93.24%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
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useContentSecurityPolicy
3
- } from "./chunk-Q5LVKCWK.js";
3
+ } from "./chunk-HZRLFCGV.js";
4
4
 
5
5
  // src/utils/apply-content-security-policy-to-response.ts
6
6
  var applyContentSecurityPolicyToResponse = async ({
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isHTMLResponse,
3
3
  makeCSPHeader
4
- } from "./chunk-U7E4KM2B.js";
4
+ } from "./chunk-PSOS33UD.js";
5
5
  import {
6
6
  UseCSPInputSchema
7
7
  } from "./chunk-OIEAURS7.js";
@@ -122,7 +122,7 @@ var MemoryCache = class {
122
122
  };
123
123
 
124
124
  // src/version.ts
125
- var MIDDLEWARE_VERSION = "3.13.0";
125
+ var MIDDLEWARE_VERSION = "3.13.2";
126
126
 
127
127
  // src/utils/heartbeat.ts
128
128
  var DEFAULT_HEARTBEAT_CONFIG_ERROR_CODE = "custom";
@@ -130,23 +130,66 @@ var DEFAULT_HEARTBEAT_CONFIG_ERROR_MESSAGE = "Appwarden configuration validation
130
130
  var HEARTBEAT_CONSTRUCTION_FAILURE_BODY = JSON.stringify({
131
131
  error: "appwarden_heartbeat_construction_failed"
132
132
  });
133
- function createSanitizedMessage(code, path) {
133
+ function getExpectedType(issue) {
134
+ if ("expected" in issue && typeof issue.expected === "string") {
135
+ return issue.expected;
136
+ }
137
+ if (issue.code === "invalid_union" && "unionErrors" in issue && Array.isArray(issue.unionErrors) && issue.unionErrors.length > 0) {
138
+ const literalValues = [];
139
+ let allAreLiterals = true;
140
+ for (const unionError of issue.unionErrors) {
141
+ if (unionError && "issues" in unionError && Array.isArray(unionError.issues) && unionError.issues.length > 0) {
142
+ const firstIssue = unionError.issues[0];
143
+ if (firstIssue.code === "invalid_literal" && "expected" in firstIssue) {
144
+ literalValues.push(String(firstIssue.expected));
145
+ } else {
146
+ allAreLiterals = false;
147
+ break;
148
+ }
149
+ }
150
+ }
151
+ if (allAreLiterals && literalValues.length > 0) {
152
+ return literalValues.join(" | ");
153
+ }
154
+ const expectedTypes = /* @__PURE__ */ new Set();
155
+ for (const unionError of issue.unionErrors) {
156
+ if (unionError && "issues" in unionError && Array.isArray(unionError.issues) && unionError.issues.length > 0) {
157
+ const firstIssue = unionError.issues[0];
158
+ if (typeof firstIssue.expected === "string") {
159
+ expectedTypes.add(firstIssue.expected);
160
+ }
161
+ }
162
+ }
163
+ if (expectedTypes.size > 0) {
164
+ return Array.from(expectedTypes).join(" | ");
165
+ }
166
+ }
167
+ return void 0;
168
+ }
169
+ function createSanitizedMessage(issue, path) {
134
170
  const fieldName = path.length > 0 ? path[path.length - 1] : "field";
171
+ const code = issue.code;
135
172
  switch (code) {
136
- case "invalid_type":
137
- return `Invalid type for ${fieldName}`;
173
+ case "invalid_type": {
174
+ const expectedType = getExpectedType(issue);
175
+ return expectedType ? `Invalid type for ${fieldName}. Expected ${expectedType}` : `Invalid type for ${fieldName}`;
176
+ }
138
177
  case "invalid_literal":
139
178
  return `Invalid value for ${fieldName}`;
140
179
  case "unrecognized_keys":
141
180
  return `Unrecognized keys in ${fieldName}`;
142
- case "invalid_union":
143
- return `Invalid union value for ${fieldName}`;
181
+ case "invalid_union": {
182
+ const expectedType = getExpectedType(issue);
183
+ return expectedType ? `Invalid type for ${fieldName}. Expected ${expectedType}` : `Invalid union value for ${fieldName}`;
184
+ }
144
185
  case "invalid_enum_value":
145
186
  return `Invalid enum value for ${fieldName}`;
146
187
  case "invalid_arguments":
147
188
  return `Invalid arguments for ${fieldName}`;
148
- case "invalid_return_type":
149
- return `Invalid return type for ${fieldName}`;
189
+ case "invalid_return_type": {
190
+ const expectedType = getExpectedType(issue);
191
+ return expectedType ? `Invalid return type for ${fieldName}. Expected ${expectedType}` : `Invalid return type for ${fieldName}`;
192
+ }
150
193
  case "invalid_date":
151
194
  return `Invalid date for ${fieldName}`;
152
195
  case "invalid_string":
@@ -251,7 +294,7 @@ function sanitizeConfigErrors(error) {
251
294
  for (const issue of issues) {
252
295
  const sanitizedPath = sanitizePath(issue.path);
253
296
  const message = truncateMessage(
254
- createSanitizedMessage(issue.code, sanitizedPath)
297
+ createSanitizedMessage(issue, sanitizedPath)
255
298
  );
256
299
  errors.push({
257
300
  path: sanitizedPath,
@@ -2,7 +2,7 @@ import {
2
2
  MemoryCache,
3
3
  debug,
4
4
  printMessage
5
- } from "./chunk-U7E4KM2B.js";
5
+ } from "./chunk-PSOS33UD.js";
6
6
  import {
7
7
  APPWARDEN_CACHE_KEY,
8
8
  APPWARDEN_TEST_ROUTE,
@@ -21,7 +21,8 @@ var store = {
21
21
  }
22
22
  };
23
23
  var getCacheValue = async (context, cacheKey) => {
24
- const match = await context.cache.match(cacheKey);
24
+ const request = new Request(cacheKey.href);
25
+ const match = await context.cache.match(request);
25
26
  return match ?? void 0;
26
27
  };
27
28
  var updateCacheValue = async (context, cacheKey, value, ttl) => {
@@ -31,19 +32,21 @@ var updateCacheValue = async (context, cacheKey, value, ttl) => {
31
32
  value,
32
33
  ttl ? `expires in ${ttl}s` : ""
33
34
  );
34
- await context.cache.put(
35
- cacheKey,
36
- new Response(JSON.stringify(value), {
37
- headers: {
38
- "content-type": "application/json",
39
- ...ttl && {
40
- "cache-control": `max-age=${ttl}`
41
- }
35
+ const response = new Response(JSON.stringify(value), {
36
+ headers: {
37
+ "content-type": "application/json",
38
+ ...ttl && {
39
+ "cache-control": `max-age=${ttl}`
42
40
  }
43
- })
44
- );
41
+ }
42
+ });
43
+ const request = new Request(cacheKey.href, { method: "GET" });
44
+ await context.cache.put(request, response);
45
+ };
46
+ var clearCache = (context, cacheKey) => {
47
+ const request = new Request(cacheKey.href);
48
+ return context.cache.delete(request);
45
49
  };
46
- var clearCache = (context, cacheKey) => context.cache.delete(cacheKey);
47
50
 
48
51
  // src/utils/cloudflare/delete-edge-value.ts
49
52
  var deleteEdgeValue = async (context) => {
@@ -132,6 +135,13 @@ var syncEdgeValue = async (context) => {
132
135
  appwardenApiToken: context.appwardenApiToken
133
136
  })
134
137
  });
138
+ if (response.status === 403) {
139
+ console.log(
140
+ printMessage(
141
+ "Verifying domain ownership...this will only take a few minutes."
142
+ )
143
+ );
144
+ }
135
145
  if (response.status !== 200) {
136
146
  throw new Error(`${response.status} ${response.statusText}`);
137
147
  }
@@ -176,7 +186,8 @@ var createContext = async (config) => {
176
186
  {
177
187
  serviceOrigin: requestUrl.origin,
178
188
  cache: await caches.open("appwarden:lock"),
179
- debug: debugFn
189
+ debug: debugFn,
190
+ waitUntil: config.waitUntil
180
191
  },
181
192
  keyName
182
193
  );
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  applyContentSecurityPolicyToResponse,
3
3
  isResponseLike
4
- } from "../chunk-QM56445N.js";
5
- import "../chunk-Q5LVKCWK.js";
4
+ } from "../chunk-2ZF7A6Z3.js";
5
+ import "../chunk-HZRLFCGV.js";
6
6
  import {
7
7
  getNowMs,
8
8
  logElapsed
9
9
  } from "../chunk-G6BMPIYD.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-CVOSFBOE.js";
12
+ } from "../chunk-X2TEREDD.js";
13
13
  import {
14
14
  TEMPORARY_REDIRECT_STATUS,
15
15
  buildLockPageUrl,
@@ -22,7 +22,7 @@ import {
22
22
  isOnLockPage,
23
23
  printMessage,
24
24
  sanitizeConfigErrors
25
- } from "../chunk-U7E4KM2B.js";
25
+ } from "../chunk-PSOS33UD.js";
26
26
  import {
27
27
  AppwardenApiHostnameSchema,
28
28
  AppwardenApiTokenSchema,
@@ -7,7 +7,7 @@ import {
7
7
  } from "../chunk-G6BMPIYD.js";
8
8
  import {
9
9
  checkLockStatus
10
- } from "../chunk-CVOSFBOE.js";
10
+ } from "../chunk-X2TEREDD.js";
11
11
  import {
12
12
  TEMPORARY_REDIRECT_STATUS,
13
13
  buildLockPageUrl,
@@ -20,7 +20,7 @@ import {
20
20
  makeCSPHeader,
21
21
  printMessage,
22
22
  sanitizeConfigErrors
23
- } from "../chunk-U7E4KM2B.js";
23
+ } from "../chunk-PSOS33UD.js";
24
24
  import {
25
25
  AppwardenApiHostnameSchema,
26
26
  AppwardenApiTokenSchema,
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  applyContentSecurityPolicyToResponse,
3
3
  isResponseLike
4
- } from "../chunk-QM56445N.js";
5
- import "../chunk-Q5LVKCWK.js";
4
+ } from "../chunk-2ZF7A6Z3.js";
5
+ import "../chunk-HZRLFCGV.js";
6
6
  import {
7
7
  getNowMs,
8
8
  logElapsed
9
9
  } from "../chunk-G6BMPIYD.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-CVOSFBOE.js";
12
+ } from "../chunk-X2TEREDD.js";
13
13
  import {
14
14
  buildLockPageUrl,
15
15
  createHeartbeatConfigError,
@@ -21,7 +21,7 @@ import {
21
21
  isOnLockPage,
22
22
  printMessage,
23
23
  sanitizeConfigErrors
24
- } from "../chunk-U7E4KM2B.js";
24
+ } from "../chunk-PSOS33UD.js";
25
25
  import {
26
26
  AppwardenApiHostnameSchema,
27
27
  AppwardenApiTokenSchema,
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  applyContentSecurityPolicyToResponse,
3
3
  isResponseLike
4
- } from "../chunk-QM56445N.js";
5
- import "../chunk-Q5LVKCWK.js";
4
+ } from "../chunk-2ZF7A6Z3.js";
5
+ import "../chunk-HZRLFCGV.js";
6
6
  import {
7
7
  getNowMs,
8
8
  logElapsed
9
9
  } from "../chunk-G6BMPIYD.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-CVOSFBOE.js";
12
+ } from "../chunk-X2TEREDD.js";
13
13
  import {
14
14
  buildLockPageUrl,
15
15
  createHeartbeatConfigError,
@@ -21,7 +21,7 @@ import {
21
21
  isOnLockPage,
22
22
  printMessage,
23
23
  sanitizeConfigErrors
24
- } from "../chunk-U7E4KM2B.js";
24
+ } from "../chunk-PSOS33UD.js";
25
25
  import {
26
26
  AppwardenApiHostnameSchema,
27
27
  AppwardenApiTokenSchema,
package/cloudflare.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequestContext, U as UseCSPInput, M as Middleware, B as Bindings } from './use-content-security-policy-Dwdcwp33.js';
2
1
  import { z } from 'zod';
2
+ import { R as RequestContext, U as UseCSPInput, M as Middleware, B as Bindings } from './use-content-security-policy-Dwdcwp33.js';
3
3
 
4
4
  declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<RequestContext, z.ZodTypeDef, RequestContext>], z.ZodUnknown>, z.ZodLazy<z.ZodEffects<z.ZodObject<{
5
5
  debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
package/cloudflare.js CHANGED
@@ -7,10 +7,10 @@ import {
7
7
  } from "./chunk-NV7K5PRA.js";
8
8
  import {
9
9
  useContentSecurityPolicy
10
- } from "./chunk-Q5LVKCWK.js";
10
+ } from "./chunk-HZRLFCGV.js";
11
11
  import {
12
12
  checkLockStatus
13
- } from "./chunk-CVOSFBOE.js";
13
+ } from "./chunk-X2TEREDD.js";
14
14
  import {
15
15
  buildLockPageUrl,
16
16
  createHeartbeatConfigError,
@@ -22,7 +22,7 @@ import {
22
22
  isOnLockPage,
23
23
  printMessage,
24
24
  sanitizeConfigErrors
25
- } from "./chunk-U7E4KM2B.js";
25
+ } from "./chunk-PSOS33UD.js";
26
26
  import {
27
27
  HEARTBEAT_SERVICES
28
28
  } from "./chunk-OIEAURS7.js";
package/index.d.ts CHANGED
@@ -61,13 +61,13 @@ declare const HeartbeatConfigErrorSchema: z.ZodObject<{
61
61
  code: z.ZodString;
62
62
  message: z.ZodString;
63
63
  }, "strict", z.ZodTypeAny, {
64
- message: string;
65
64
  code: string;
66
65
  path: (string | number)[];
67
- }, {
68
66
  message: string;
67
+ }, {
69
68
  code: string;
70
69
  path: (string | number)[];
70
+ message: string;
71
71
  }>;
72
72
  type HeartbeatConfigError = z.infer<typeof HeartbeatConfigErrorSchema>;
73
73
  /**
@@ -85,21 +85,21 @@ declare const HeartbeatResponseBodySchema: z.ZodEffects<z.ZodObject<{
85
85
  code: z.ZodString;
86
86
  message: z.ZodString;
87
87
  }, "strict", z.ZodTypeAny, {
88
- message: string;
89
88
  code: string;
90
89
  path: (string | number)[];
91
- }, {
92
90
  message: string;
91
+ }, {
93
92
  code: string;
94
93
  path: (string | number)[];
95
- }>, "many">, {
96
94
  message: string;
95
+ }>, "many">, {
97
96
  code: string;
98
97
  path: (string | number)[];
99
- }[], {
100
98
  message: string;
99
+ }[], {
101
100
  code: string;
102
101
  path: (string | number)[];
102
+ message: string;
103
103
  }[]>;
104
104
  }, "strict", z.ZodTypeAny, {
105
105
  status: "ok";
@@ -109,9 +109,9 @@ declare const HeartbeatResponseBodySchema: z.ZodEffects<z.ZodObject<{
109
109
  service: "cloudflare" | "cloudflare-astro" | "cloudflare-react-router" | "cloudflare-tanstack-start" | "cloudflare-nextjs" | "vercel";
110
110
  version: string;
111
111
  configErrors: {
112
- message: string;
113
112
  code: string;
114
113
  path: (string | number)[];
114
+ message: string;
115
115
  }[];
116
116
  }, {
117
117
  status: "ok";
@@ -121,9 +121,9 @@ declare const HeartbeatResponseBodySchema: z.ZodEffects<z.ZodObject<{
121
121
  service: "cloudflare" | "cloudflare-astro" | "cloudflare-react-router" | "cloudflare-tanstack-start" | "cloudflare-nextjs" | "vercel";
122
122
  version: string;
123
123
  configErrors: {
124
- message: string;
125
124
  code: string;
126
125
  path: (string | number)[];
126
+ message: string;
127
127
  }[];
128
128
  }>, {
129
129
  status: "ok";
@@ -133,9 +133,9 @@ declare const HeartbeatResponseBodySchema: z.ZodEffects<z.ZodObject<{
133
133
  service: "cloudflare" | "cloudflare-astro" | "cloudflare-react-router" | "cloudflare-tanstack-start" | "cloudflare-nextjs" | "vercel";
134
134
  version: string;
135
135
  configErrors: {
136
- message: string;
137
136
  code: string;
138
137
  path: (string | number)[];
138
+ message: string;
139
139
  }[];
140
140
  }, {
141
141
  status: "ok";
@@ -145,9 +145,9 @@ declare const HeartbeatResponseBodySchema: z.ZodEffects<z.ZodObject<{
145
145
  service: "cloudflare" | "cloudflare-astro" | "cloudflare-react-router" | "cloudflare-tanstack-start" | "cloudflare-nextjs" | "vercel";
146
146
  version: string;
147
147
  configErrors: {
148
- message: string;
149
148
  code: string;
150
149
  path: (string | number)[];
150
+ message: string;
151
151
  }[];
152
152
  }>;
153
153
  type HeartbeatResponseBody = z.infer<typeof HeartbeatResponseBodySchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "3.13.1",
3
+ "version": "3.13.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",
@@ -58,7 +58,7 @@
58
58
  "node": ">=24"
59
59
  },
60
60
  "dependencies": {
61
- "@upstash/redis": "^1.36.4",
61
+ "@upstash/redis": "^1.37.0",
62
62
  "@vercel/edge-config": "^1.4.3",
63
63
  "zod": "^3.25.76"
64
64
  },
@@ -97,28 +97,32 @@
97
97
  },
98
98
  "pnpm": {
99
99
  "overrides": {
100
+ "@isaacs/brace-expansion@<=5.0.0": ">=5.0.1",
101
+ "@opennextjs/cloudflare@<1.17.1": ">=1.17.1",
102
+ "@smithy/config-resolver@<4.4.0": ">=4.4.0",
103
+ "ajv@>=7.0.0-alpha.0 <8.18.0": ">=8.18.0",
104
+ "body-parser@>=2.2.0 <2.2.1": ">=2.2.1",
100
105
  "cookie@<0.7.0": ">=0.7.0",
106
+ "devalue@<5.6.4": ">=5.6.4",
101
107
  "esbuild@<=0.24.2": ">=0.25.0",
102
- "path-to-regexp@>=4.0.0 <6.3.0": ">=6.3.0",
103
- "undici@<6.23.0": ">=6.23.0",
104
- "body-parser@>=2.2.0 <2.2.1": ">=2.2.1",
108
+ "fast-xml-parser@>=4.0.0-beta.3 <=5.5.5": ">=5.5.6",
109
+ "h3@<1.15.6": ">=1.15.6",
110
+ "h3@>=2.0.0 <=2.0.1-rc.14": ">=2.0.1-rc.15",
111
+ "js-yaml@<3.14.2": ">=3.14.2",
105
112
  "jws@=4.0.0": ">=4.0.1",
106
- "@smithy/config-resolver@<4.4.0": ">=4.4.0",
107
- "@isaacs/brace-expansion@<=5.0.0": ">=5.0.1",
113
+ "minimatch@<10.2.1": ">=10.2.3",
114
+ "next@>=10.0.0 <16.1.7": ">=16.1.7",
108
115
  "npm@<=11.8.0": ">=11.9.0",
109
- "wrangler@>=4.0.0 <4.59.1": ">=4.59.1",
116
+ "path-to-regexp@>=4.0.0 <6.3.0": ">=6.3.0",
117
+ "picomatch@<4.0.4": ">=4.0.4",
110
118
  "qs@>=6.7.0 <=6.14.1": ">=6.14.2",
111
- "devalue@<=5.6.2": ">=5.6.3",
112
- "minimatch@<10.2.1": ">=10.2.3",
113
- "ajv@>=7.0.0-alpha.0 <8.18.0": ">=8.18.0",
114
119
  "rollup@>=4.0.0 <4.59.0": ">=4.59.0",
115
- "h3@<=1.15.4": ">=1.15.5",
116
- "js-yaml@<3.14.2": ">=3.14.2",
117
- "fast-xml-parser@<5.3.8": ">=5.3.8",
118
120
  "serialize-javascript@<=7.0.2": ">=7.0.3",
119
121
  "svgo@=4.0.0": ">=4.0.1",
120
- "@opennextjs/cloudflare@<1.17.1": ">=1.17.1",
121
- "tar@<=7.5.10": ">=7.5.11"
122
+ "tar@<=7.5.10": ">=7.5.11",
123
+ "undici@<7.24.0": ">=7.24.0",
124
+ "wrangler@>=4.0.0 <4.59.1": ">=4.59.1",
125
+ "@tanstack/start-server-core@1.163.2>h3-v2": "npm:h3@2.0.1-rc.16"
122
126
  }
123
127
  }
124
128
  }
package/vercel.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  makeCSPHeader,
21
21
  printMessage,
22
22
  sanitizeConfigErrors
23
- } from "./chunk-U7E4KM2B.js";
23
+ } from "./chunk-PSOS33UD.js";
24
24
  import {
25
25
  APPWARDEN_CACHE_KEY,
26
26
  AppwardenApiHostnameSchema,
@@ -125,6 +125,13 @@ var syncEdgeValue = async (context) => {
125
125
  appwardenApiToken: context.appwardenApiToken
126
126
  })
127
127
  });
128
+ if (response.status === 403) {
129
+ console.log(
130
+ printMessage(
131
+ "Verifying domain ownership...this will only take a few minutes."
132
+ )
133
+ );
134
+ }
128
135
  if (response.status !== 200) {
129
136
  throw new Error(`${response.status} ${response.statusText}`);
130
137
  }