@appwarden/middleware 3.2.1 → 3.3.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 +257 -22
- package/{chunk-COV6SHCD.js → chunk-7AVYENM2.js} +2 -4
- package/chunk-BYRGGUK7.js +51 -0
- package/chunk-HCGLR3Z3.js +97 -0
- package/chunk-PH77FI6C.js +70 -0
- package/{chunk-ZX5QO4Y2.js → chunk-SUZPTFWY.js} +2 -58
- package/chunk-ZBYVJ3HA.js +354 -0
- package/cloudflare/astro.d.ts +4 -0
- package/cloudflare/astro.js +33 -9
- package/cloudflare/nextjs.d.ts +4 -0
- package/cloudflare/nextjs.js +35 -8
- package/cloudflare/react-router.d.ts +5 -0
- package/cloudflare/react-router.js +33 -9
- package/cloudflare/tanstack-start.d.ts +5 -0
- package/cloudflare/tanstack-start.js +33 -9
- package/cloudflare-LUT5TVEV.js +28 -0
- package/cloudflare.d.ts +440 -8
- package/cloudflare.js +25 -47
- package/index.d.ts +2 -1
- package/index.js +5 -4
- package/package.json +8 -3
- package/use-content-security-policy-CjlLe4yU.d.ts +16 -0
- package/{use-content-security-policy-DjRTjIpm.d.ts → use-content-security-policy-DUYpyUPy.d.ts} +1 -18
- package/vercel.d.ts +677 -0
- package/vercel.js +59 -9
- package/chunk-A5XGYLYS.js +0 -196
- package/chunk-L5EQIJZB.js +0 -54
- package/chunk-MDODCAA3.js +0 -232
package/cloudflare.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useContentSecurityPolicy
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BYRGGUK7.js";
|
|
4
4
|
import {
|
|
5
|
-
checkLockStatus
|
|
6
|
-
|
|
7
|
-
store
|
|
8
|
-
} from "./chunk-MDODCAA3.js";
|
|
5
|
+
checkLockStatus
|
|
6
|
+
} from "./chunk-PH77FI6C.js";
|
|
9
7
|
import {
|
|
10
|
-
AppwardenApiTokenSchema,
|
|
11
|
-
BooleanSchema,
|
|
12
8
|
buildLockPageUrl,
|
|
13
9
|
createRedirect,
|
|
14
|
-
getErrors,
|
|
15
10
|
isOnLockPage
|
|
16
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-SUZPTFWY.js";
|
|
17
12
|
import {
|
|
18
13
|
APPWARDEN_CACHE_KEY,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} from "./chunk-
|
|
14
|
+
UseCSPInputSchema,
|
|
15
|
+
isHTMLRequest
|
|
16
|
+
} from "./chunk-HCGLR3Z3.js";
|
|
17
|
+
import {
|
|
18
|
+
AppwardenApiTokenSchema,
|
|
19
|
+
BooleanSchema,
|
|
20
|
+
getLockValue,
|
|
21
|
+
insertErrorLogs,
|
|
22
|
+
printMessage,
|
|
23
|
+
store
|
|
24
|
+
} from "./chunk-ZBYVJ3HA.js";
|
|
22
25
|
|
|
23
26
|
// src/runners/appwarden-on-cloudflare.ts
|
|
24
27
|
import { ZodError } from "zod";
|
|
@@ -31,7 +34,8 @@ import { z } from "zod";
|
|
|
31
34
|
var AppwardenMultidomainConfigSchema = z.record(
|
|
32
35
|
z.string(),
|
|
33
36
|
z.object({
|
|
34
|
-
lockPageSlug: z.string()
|
|
37
|
+
lockPageSlug: z.string(),
|
|
38
|
+
contentSecurityPolicy: z.lazy(() => UseCSPInputSchema).optional()
|
|
35
39
|
})
|
|
36
40
|
);
|
|
37
41
|
var UseAppwardenInputSchema = z.object({
|
|
@@ -49,16 +53,7 @@ var lockPageSlugRefinement = (schema) => schema.refine(
|
|
|
49
53
|
);
|
|
50
54
|
|
|
51
55
|
// src/schemas/cloudflare.ts
|
|
52
|
-
var ConfigFnInputSchema = z2.function().args(z2.custom()).returns(
|
|
53
|
-
lockPageSlugRefinement(
|
|
54
|
-
UseAppwardenInputSchema.extend({
|
|
55
|
-
middleware: z2.object({
|
|
56
|
-
before: z2.custom().array().default([]),
|
|
57
|
-
after: z2.custom().array().default([])
|
|
58
|
-
}).default({})
|
|
59
|
-
})
|
|
60
|
-
)
|
|
61
|
-
);
|
|
56
|
+
var ConfigFnInputSchema = z2.function().args(z2.custom()).returns(z2.lazy(() => lockPageSlugRefinement(UseAppwardenInputSchema)));
|
|
62
57
|
|
|
63
58
|
// src/utils/middleware.ts
|
|
64
59
|
var usePipeline = (...initMiddlewares) => {
|
|
@@ -82,24 +77,6 @@ var usePipeline = (...initMiddlewares) => {
|
|
|
82
77
|
};
|
|
83
78
|
};
|
|
84
79
|
|
|
85
|
-
// src/utils/cloudflare/insert-errors-logs.ts
|
|
86
|
-
var insertErrorLogs = async (context, error) => {
|
|
87
|
-
const errors = getErrors(error);
|
|
88
|
-
for (const err of errors) {
|
|
89
|
-
console.log(printMessage(err));
|
|
90
|
-
}
|
|
91
|
-
return new HTMLRewriter().on("body", {
|
|
92
|
-
element: (elem) => {
|
|
93
|
-
elem.append(
|
|
94
|
-
`<script>
|
|
95
|
-
${errors.map((err) => `console.error(\`${printMessage(err)}\`)`).join("\n")}
|
|
96
|
-
</script>`,
|
|
97
|
-
{ html: true }
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}).transform(await fetch(context.request));
|
|
101
|
-
};
|
|
102
|
-
|
|
103
80
|
// src/handlers/reset-cache.ts
|
|
104
81
|
var isResetCacheRequest = (request) => request.method === "POST" && new URL(request.url).pathname === "/__appwarden/reset-cache" && request.headers.get("content-type") === "application/json";
|
|
105
82
|
var handleResetCache = async (keyName, provider, edgeCache, request) => {
|
|
@@ -188,9 +165,10 @@ var useFetchOrigin = () => async (context, next) => {
|
|
|
188
165
|
// src/runners/appwarden-on-cloudflare.ts
|
|
189
166
|
var appwardenOnCloudflare = (inputFn) => async (request, env, ctx) => {
|
|
190
167
|
ctx.passThroughOnException();
|
|
168
|
+
const requestUrl = new URL(request.url);
|
|
191
169
|
const context = {
|
|
192
170
|
request,
|
|
193
|
-
hostname:
|
|
171
|
+
hostname: requestUrl.hostname,
|
|
194
172
|
response: new Response("Unhandled response"),
|
|
195
173
|
// https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors
|
|
196
174
|
waitUntil: (fn) => ctx.waitUntil(fn)
|
|
@@ -201,11 +179,11 @@ var appwardenOnCloudflare = (inputFn) => async (request, env, ctx) => {
|
|
|
201
179
|
}
|
|
202
180
|
try {
|
|
203
181
|
const input = parsedInput.data({ env, ctx, cf: {} });
|
|
204
|
-
const pipeline = [
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
182
|
+
const pipeline = [useAppwarden(input), useFetchOrigin()];
|
|
183
|
+
const cspConfig = input.multidomainConfig?.[requestUrl.hostname]?.contentSecurityPolicy;
|
|
184
|
+
if (cspConfig) {
|
|
185
|
+
pipeline.push(useContentSecurityPolicy(cspConfig));
|
|
186
|
+
}
|
|
209
187
|
await usePipeline(...pipeline).execute(context);
|
|
210
188
|
} catch (error) {
|
|
211
189
|
if (error instanceof ZodError) {
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema
|
|
1
|
+
export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema } from './use-content-security-policy-DUYpyUPy.js';
|
|
2
|
+
export { M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-CjlLe4yU.js';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
|
|
4
5
|
declare const LOCKDOWN_TEST_EXPIRY_MS: number;
|
package/index.js
CHANGED
|
@@ -4,14 +4,15 @@ import {
|
|
|
4
4
|
isValidCacheUrl
|
|
5
5
|
} from "./chunk-QEFORWCW.js";
|
|
6
6
|
import {
|
|
7
|
-
CSPDirectivesSchema,
|
|
8
|
-
CSPModeSchema,
|
|
9
7
|
useContentSecurityPolicy
|
|
10
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-BYRGGUK7.js";
|
|
11
9
|
import {
|
|
12
10
|
APPWARDEN_CACHE_KEY,
|
|
11
|
+
CSPDirectivesSchema,
|
|
12
|
+
CSPModeSchema,
|
|
13
13
|
LOCKDOWN_TEST_EXPIRY_MS
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-HCGLR3Z3.js";
|
|
15
|
+
import "./chunk-ZBYVJ3HA.js";
|
|
15
16
|
export {
|
|
16
17
|
APPWARDEN_CACHE_KEY,
|
|
17
18
|
CSPDirectivesSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appwarden/middleware",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Instantly shut off access your app deployed on Cloudflare or Vercel",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@astrojs/cloudflare": ">=11.0.0",
|
|
67
|
-
"@opennextjs/cloudflare": ">=1.
|
|
67
|
+
"@opennextjs/cloudflare": ">=1.16.6",
|
|
68
68
|
"@vercel/functions": ">=1.0.0",
|
|
69
69
|
"astro": ">=4.0.0",
|
|
70
70
|
"next": ">=14"
|
|
@@ -103,7 +103,12 @@
|
|
|
103
103
|
"@smithy/config-resolver@<4.4.0": ">=4.4.0",
|
|
104
104
|
"@isaacs/brace-expansion@<=5.0.0": ">=5.0.1",
|
|
105
105
|
"npm@<=11.8.0": ">=11.9.0",
|
|
106
|
-
"wrangler@>=4.0.0 <4.59.1": ">=4.59.1"
|
|
106
|
+
"wrangler@>=4.0.0 <4.59.1": ">=4.59.1",
|
|
107
|
+
"qs@>=6.7.0 <=6.14.1": ">=6.14.2",
|
|
108
|
+
"devalue@<=5.6.2": ">=5.6.3",
|
|
109
|
+
"minimatch@<10.2.1": ">=10.2.1",
|
|
110
|
+
"tar@<7.5.8": ">=7.5.8",
|
|
111
|
+
"ajv@>=7.0.0-alpha.0 <8.18.0": ">=8.18.0"
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
114
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { U as UseCSPInput } from './use-content-security-policy-DUYpyUPy.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
interface MiddlewareContext {
|
|
5
|
+
hostname: string;
|
|
6
|
+
request: Request;
|
|
7
|
+
response: Response;
|
|
8
|
+
waitUntil: ExecutionContext["waitUntil"];
|
|
9
|
+
}
|
|
10
|
+
type Middleware = (context: MiddlewareContext, next: () => MiddlewareNextSchemaType) => MiddlewareNextSchemaType;
|
|
11
|
+
declare const MiddlewareNextSchema: z.ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodPromise<z.ZodUnion<[z.ZodVoid, z.ZodNull]>>]>;
|
|
12
|
+
type MiddlewareNextSchemaType = z.infer<typeof MiddlewareNextSchema>;
|
|
13
|
+
|
|
14
|
+
declare const useContentSecurityPolicy: (input: UseCSPInput) => Middleware;
|
|
15
|
+
|
|
16
|
+
export { type Middleware as M, useContentSecurityPolicy as u };
|
package/{use-content-security-policy-DjRTjIpm.d.ts → use-content-security-policy-DUYpyUPy.d.ts}
RENAMED
|
@@ -97,16 +97,6 @@ declare global {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
interface MiddlewareContext {
|
|
101
|
-
hostname: string;
|
|
102
|
-
request: Request;
|
|
103
|
-
response: Response;
|
|
104
|
-
waitUntil: ExecutionContext["waitUntil"];
|
|
105
|
-
}
|
|
106
|
-
type Middleware = (context: MiddlewareContext, next: () => MiddlewareNextSchemaType) => MiddlewareNextSchemaType;
|
|
107
|
-
declare const MiddlewareNextSchema: z.ZodUnion<[z.ZodVoid, z.ZodNull, z.ZodPromise<z.ZodUnion<[z.ZodVoid, z.ZodNull]>>]>;
|
|
108
|
-
type MiddlewareNextSchemaType = z.infer<typeof MiddlewareNextSchema>;
|
|
109
|
-
|
|
110
100
|
declare const CSPDirectivesSchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
111
101
|
"default-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
|
|
112
102
|
"script-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
|
|
@@ -191,7 +181,6 @@ declare const CSPDirectivesSchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
|
191
181
|
}>]>;
|
|
192
182
|
declare const CSPModeSchema: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
|
|
193
183
|
declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
194
|
-
hostname: z.ZodOptional<z.ZodString>;
|
|
195
184
|
mode: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
|
|
196
185
|
directives: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
197
186
|
"default-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
|
|
@@ -413,7 +402,6 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
413
402
|
"trusted-types"?: string | boolean | string[] | undefined;
|
|
414
403
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
415
404
|
} | undefined;
|
|
416
|
-
hostname?: string | undefined;
|
|
417
405
|
}, {
|
|
418
406
|
mode?: "disabled" | "report-only" | "enforced" | undefined;
|
|
419
407
|
directives?: string | {
|
|
@@ -444,7 +432,6 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
444
432
|
"trusted-types"?: string | boolean | string[] | undefined;
|
|
445
433
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
446
434
|
} | undefined;
|
|
447
|
-
hostname?: string | undefined;
|
|
448
435
|
}>, {
|
|
449
436
|
mode: "disabled" | "report-only" | "enforced";
|
|
450
437
|
directives?: {
|
|
@@ -475,7 +462,6 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
475
462
|
"trusted-types"?: string | boolean | string[] | undefined;
|
|
476
463
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
477
464
|
} | undefined;
|
|
478
|
-
hostname?: string | undefined;
|
|
479
465
|
}, {
|
|
480
466
|
mode?: "disabled" | "report-only" | "enforced" | undefined;
|
|
481
467
|
directives?: string | {
|
|
@@ -506,10 +492,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
506
492
|
"trusted-types"?: string | boolean | string[] | undefined;
|
|
507
493
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
508
494
|
} | undefined;
|
|
509
|
-
hostname?: string | undefined;
|
|
510
495
|
}>;
|
|
511
496
|
type UseCSPInput = z.infer<typeof UseCSPInputSchema>;
|
|
512
497
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
export { type Bindings as B, CSPDirectivesSchema as C, type Middleware as M, CSPModeSchema as a, useContentSecurityPolicy as u };
|
|
498
|
+
export { type Bindings as B, CSPDirectivesSchema as C, type UseCSPInput as U, CSPModeSchema as a };
|