@appwarden/middleware 3.6.0 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,13 +3,13 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-AXWJZE7U.js";
7
- import {
8
- getNowMs
9
- } from "../chunk-X7WZVYQS.js";
6
+ } from "../chunk-52NBQDQT.js";
10
7
  import {
11
8
  validateConfig
12
9
  } from "../chunk-MNGMTDH3.js";
10
+ import {
11
+ getNowMs
12
+ } from "../chunk-X7WZVYQS.js";
13
13
  import {
14
14
  checkLockStatus
15
15
  } from "../chunk-G5FWKV2Q.js";
@@ -50,16 +50,21 @@ function createAppwardenMiddleware(configFn) {
50
50
  const startTime = getNowMs();
51
51
  const { request, next, context } = args;
52
52
  try {
53
- const cloudflare = context.cloudflare;
54
- if (!cloudflare) {
53
+ if (!context.env || !context.waitUntil) {
55
54
  console.error(
56
55
  printMessage(
57
- "Cloudflare context not found in TanStack Start context. Ensure your Register type includes the cloudflare context, or pass it manually in the middleware wrapper."
56
+ "Runtime context missing required properties (env, waitUntil). Ensure you pass { env, waitUntil } from cloudflare:workers to the middleware context."
58
57
  )
59
58
  );
60
59
  return next();
61
60
  }
62
- const config = configFn(cloudflare);
61
+ const rawConfig = configFn(context);
62
+ const parseResult = TanStackStartCloudflareConfigSchema.safeParse(rawConfig);
63
+ if (!parseResult.success) {
64
+ validateConfig(rawConfig, TanStackStartCloudflareConfigSchema);
65
+ return next();
66
+ }
67
+ const config = parseResult.data;
63
68
  const debugFn = debug(config.debug ?? false);
64
69
  const requestUrl = new URL(request.url);
65
70
  const isHTML = isHTMLRequest(request);
@@ -70,13 +75,6 @@ function createAppwardenMiddleware(configFn) {
70
75
  if (!isHTML) {
71
76
  return next();
72
77
  }
73
- const hasError = validateConfig(
74
- config,
75
- TanStackStartCloudflareConfigSchema
76
- );
77
- if (hasError) {
78
- return next();
79
- }
80
78
  if (isOnLockPage(config.lockPageSlug, request.url)) {
81
79
  debugFn("Already on lock page - skipping");
82
80
  return next();
@@ -87,7 +85,7 @@ function createAppwardenMiddleware(configFn) {
87
85
  appwardenApiHostname: config.appwardenApiHostname,
88
86
  debug: config.debug,
89
87
  lockPageSlug: config.lockPageSlug,
90
- waitUntil: (fn) => cloudflare.ctx.waitUntil(fn)
88
+ waitUntil: context.waitUntil
91
89
  });
92
90
  if (lockStatus.isLocked) {
93
91
  const lockPageUrl = buildLockPageUrl(config.lockPageSlug, request.url);
@@ -98,12 +96,11 @@ function createAppwardenMiddleware(configFn) {
98
96
  const result = await next();
99
97
  const { response } = result;
100
98
  if (config.contentSecurityPolicy && isResponseLike(response)) {
101
- debugFn("Applying CSP middleware");
102
99
  const cspContext = {
103
100
  request,
104
101
  response,
105
102
  hostname: requestUrl.hostname,
106
- waitUntil: (fn) => cloudflare.ctx.waitUntil(fn),
103
+ waitUntil: context.waitUntil,
107
104
  debug: debugFn
108
105
  };
109
106
  await useContentSecurityPolicy(config.contentSecurityPolicy)(
package/cloudflare.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useContentSecurityPolicy
3
- } from "./chunk-AXWJZE7U.js";
3
+ } from "./chunk-52NBQDQT.js";
4
4
  import {
5
5
  checkLockStatus
6
6
  } from "./chunk-G5FWKV2Q.js";
package/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-QEFORWCW.js";
6
6
  import {
7
7
  useContentSecurityPolicy
8
- } from "./chunk-AXWJZE7U.js";
8
+ } from "./chunk-52NBQDQT.js";
9
9
  import {
10
10
  APPWARDEN_CACHE_KEY,
11
11
  CSPDirectivesSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "3.6.0",
3
+ "version": "3.8.0",
4
4
  "description": "Instantly shut off access your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -116,7 +116,8 @@
116
116
  "rollup@>=4.0.0 <4.59.0": ">=4.59.0",
117
117
  "h3@<=1.15.4": ">=1.15.5",
118
118
  "js-yaml@<3.14.2": ">=3.14.2",
119
- "fast-xml-parser@<5.3.8": ">=5.3.8"
119
+ "fast-xml-parser@<5.3.8": ">=5.3.8",
120
+ "serialize-javascript@<=7.0.2": ">=7.0.3"
120
121
  }
121
122
  }
122
123
  }