@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.
- package/README.md +29 -29
- package/{chunk-AXWJZE7U.js → chunk-52NBQDQT.js} +1 -4
- package/cloudflare/astro.js +4 -5
- package/cloudflare/nextjs.js +3 -3
- package/cloudflare/react-router.d.ts +419 -34
- package/cloudflare/react-router.js +17 -35
- package/cloudflare/tanstack-start.d.ts +415 -28
- package/cloudflare/tanstack-start.js +15 -18
- package/cloudflare.js +1 -1
- package/index.js +1 -1
- package/package.json +3 -2
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
} from "../chunk-XFG6SUSV.js";
|
|
4
4
|
import {
|
|
5
5
|
useContentSecurityPolicy
|
|
6
|
-
} from "../chunk-
|
|
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
|
-
|
|
54
|
-
if (!cloudflare) {
|
|
53
|
+
if (!context.env || !context.waitUntil) {
|
|
55
54
|
console.error(
|
|
56
55
|
printMessage(
|
|
57
|
-
"
|
|
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
|
|
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:
|
|
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:
|
|
103
|
+
waitUntil: context.waitUntil,
|
|
107
104
|
debug: debugFn
|
|
108
105
|
};
|
|
109
106
|
await useContentSecurityPolicy(config.contentSecurityPolicy)(
|
package/cloudflare.js
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appwarden/middleware",
|
|
3
|
-
"version": "3.
|
|
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
|
}
|