@appwarden/middleware 3.11.6 → 3.13.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 +1 -1
- package/chunk-2ZSJUEHK.js +445 -0
- package/{chunk-5HCAAVK5.js → chunk-GNDWHKJ5.js} +3 -5
- package/{chunk-R7TXTHSG.js → chunk-HP5GMFH7.js} +75 -143
- package/chunk-HUWGPM4M.js +9 -0
- package/{chunk-WBWF3PPX.js → chunk-J2TA6BEU.js} +4 -6
- package/chunk-NV7K5PRA.js +36 -0
- package/chunk-SREQAAZC.js +220 -0
- package/{chunk-UFWJYCX6.js → chunk-TBSMAMWC.js} +1 -1
- package/cloudflare/astro.d.ts +2 -2
- package/cloudflare/astro.js +55 -15
- package/cloudflare/nextjs.d.ts +2 -2
- package/cloudflare/nextjs.js +60 -15
- package/cloudflare/react-router.d.ts +2 -2
- package/cloudflare/react-router.js +43 -15
- package/cloudflare/tanstack-start.d.ts +2 -2
- package/cloudflare/tanstack-start.js +40 -15
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +80 -11
- package/index.d.ts +109 -2
- package/index.js +10 -5
- package/package.json +1 -1
- package/{use-content-security-policy-CvdzUPYF.d.ts → use-content-security-policy-Dwdcwp33.d.ts} +0 -1
- package/vercel.js +38 -16
- package/chunk-AY4ZKZTF.js +0 -162
- package/chunk-QC2ZUZWY.js +0 -84
- package/chunk-WEM7GS4M.js +0 -29
- package/chunk-ZTVJBORU.js +0 -81
- package/cloudflare-MAHYENA6.js +0 -29
package/cloudflare/nextjs.d.ts
CHANGED
|
@@ -329,8 +329,8 @@ declare const NextJsCloudflareConfigSchema: z.ZodObject<{
|
|
|
329
329
|
};
|
|
330
330
|
}>>>;
|
|
331
331
|
}, "strip", z.ZodTypeAny, {
|
|
332
|
-
debug: boolean;
|
|
333
332
|
lockPageSlug: string;
|
|
333
|
+
debug: boolean;
|
|
334
334
|
appwardenApiToken: string;
|
|
335
335
|
contentSecurityPolicy?: {
|
|
336
336
|
mode: "disabled" | "report-only" | "enforced";
|
|
@@ -367,7 +367,6 @@ declare const NextJsCloudflareConfigSchema: z.ZodObject<{
|
|
|
367
367
|
}, {
|
|
368
368
|
lockPageSlug: string;
|
|
369
369
|
appwardenApiToken: string;
|
|
370
|
-
debug?: string | boolean | undefined;
|
|
371
370
|
contentSecurityPolicy?: {
|
|
372
371
|
mode: "disabled" | "report-only" | "enforced";
|
|
373
372
|
directives: string | {
|
|
@@ -399,6 +398,7 @@ declare const NextJsCloudflareConfigSchema: z.ZodObject<{
|
|
|
399
398
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
400
399
|
};
|
|
401
400
|
} | undefined;
|
|
401
|
+
debug?: string | boolean | undefined;
|
|
402
402
|
appwardenApiHostname?: string | undefined;
|
|
403
403
|
}>;
|
|
404
404
|
type NextJsCloudflareConfig = z.infer<typeof NextJsCloudflareConfigSchema>;
|
package/cloudflare/nextjs.js
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toNextResponse
|
|
3
|
+
} from "../chunk-HUWGPM4M.js";
|
|
1
4
|
import {
|
|
2
5
|
getNowMs,
|
|
3
6
|
logElapsed
|
|
4
7
|
} from "../chunk-G6BMPIYD.js";
|
|
5
8
|
import {
|
|
6
9
|
checkLockStatus
|
|
7
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-HP5GMFH7.js";
|
|
8
11
|
import {
|
|
9
12
|
TEMPORARY_REDIRECT_STATUS,
|
|
10
13
|
buildLockPageUrl,
|
|
14
|
+
createHeartbeatConfigError,
|
|
11
15
|
debug,
|
|
16
|
+
handleHeartbeatRequest,
|
|
12
17
|
isHTMLRequest,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
printMessage
|
|
20
|
-
} from "../chunk-R7TXTHSG.js";
|
|
18
|
+
isHeartbeatRequest,
|
|
19
|
+
isOnLockPage,
|
|
20
|
+
makeCSPHeader,
|
|
21
|
+
printMessage,
|
|
22
|
+
sanitizeConfigErrors
|
|
23
|
+
} from "../chunk-2ZSJUEHK.js";
|
|
21
24
|
import {
|
|
22
25
|
AppwardenApiHostnameSchema,
|
|
23
26
|
AppwardenApiTokenSchema,
|
|
24
|
-
BooleanSchema
|
|
25
|
-
|
|
27
|
+
BooleanSchema,
|
|
28
|
+
HEARTBEAT_SERVICES,
|
|
29
|
+
UseCSPInputSchema
|
|
30
|
+
} from "../chunk-SREQAAZC.js";
|
|
26
31
|
|
|
27
32
|
// src/adapters/nextjs-cloudflare.ts
|
|
33
|
+
import { getCloudflareContext } from "@opennextjs/cloudflare";
|
|
28
34
|
import {
|
|
29
35
|
NextResponse
|
|
30
36
|
} from "next/server";
|
|
@@ -56,12 +62,53 @@ var NextJsCloudflareConfigSchema = z.object({
|
|
|
56
62
|
});
|
|
57
63
|
|
|
58
64
|
// src/adapters/nextjs-cloudflare.ts
|
|
65
|
+
var createNextJsHeartbeatResponse = (request, configFn) => {
|
|
66
|
+
let runtime;
|
|
67
|
+
try {
|
|
68
|
+
runtime = getCloudflareContext();
|
|
69
|
+
} catch {
|
|
70
|
+
return toNextResponse(
|
|
71
|
+
handleHeartbeatRequest(request, HEARTBEAT_SERVICES.CLOUDFLARE_NEXTJS, [
|
|
72
|
+
createHeartbeatConfigError(
|
|
73
|
+
["context"],
|
|
74
|
+
"custom",
|
|
75
|
+
"Cloudflare context unavailable"
|
|
76
|
+
)
|
|
77
|
+
])
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const validationResult = NextJsCloudflareConfigSchema.safeParse(
|
|
82
|
+
configFn(runtime)
|
|
83
|
+
);
|
|
84
|
+
return toNextResponse(
|
|
85
|
+
handleHeartbeatRequest(
|
|
86
|
+
request,
|
|
87
|
+
HEARTBEAT_SERVICES.CLOUDFLARE_NEXTJS,
|
|
88
|
+
validationResult.success ? [] : sanitizeConfigErrors(validationResult.error)
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
} catch {
|
|
92
|
+
return toNextResponse(
|
|
93
|
+
handleHeartbeatRequest(request, HEARTBEAT_SERVICES.CLOUDFLARE_NEXTJS, [
|
|
94
|
+
createHeartbeatConfigError(
|
|
95
|
+
["config"],
|
|
96
|
+
"custom",
|
|
97
|
+
"Appwarden config evaluation failed"
|
|
98
|
+
)
|
|
99
|
+
])
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
59
103
|
function createAppwardenMiddleware(configFn) {
|
|
60
104
|
return async (request, _event) => {
|
|
61
105
|
const startTime = getNowMs();
|
|
106
|
+
const requestUrl = new URL(request.url);
|
|
107
|
+
if (isHeartbeatRequest(request, requestUrl)) {
|
|
108
|
+
return createNextJsHeartbeatResponse(request, configFn);
|
|
109
|
+
}
|
|
62
110
|
try {
|
|
63
|
-
const {
|
|
64
|
-
const { env, ctx } = await getCloudflareContext();
|
|
111
|
+
const { env, ctx } = getCloudflareContext();
|
|
65
112
|
const rawConfig = configFn({ env, ctx });
|
|
66
113
|
const validationResult = NextJsCloudflareConfigSchema.safeParse(rawConfig);
|
|
67
114
|
if (!validationResult.success) {
|
|
@@ -74,7 +121,6 @@ function createAppwardenMiddleware(configFn) {
|
|
|
74
121
|
}
|
|
75
122
|
const config = validationResult.data;
|
|
76
123
|
const debugFn = debug(config.debug);
|
|
77
|
-
const requestUrl = new URL(request.url);
|
|
78
124
|
const isHTML = isHTMLRequest(request);
|
|
79
125
|
debugFn(
|
|
80
126
|
`Appwarden middleware invoked for ${requestUrl.pathname}`,
|
|
@@ -105,7 +151,6 @@ function createAppwardenMiddleware(configFn) {
|
|
|
105
151
|
debugFn(
|
|
106
152
|
`Applying CSP headers in ${config.contentSecurityPolicy.mode} mode`
|
|
107
153
|
);
|
|
108
|
-
const { makeCSPHeader } = await import("../cloudflare-MAHYENA6.js");
|
|
109
154
|
const [headerName, headerValue] = makeCSPHeader(
|
|
110
155
|
"",
|
|
111
156
|
config.contentSecurityPolicy.directives,
|
|
@@ -268,8 +268,8 @@ declare const ReactRouterCloudflareConfigSchema: z.ZodObject<{
|
|
|
268
268
|
};
|
|
269
269
|
}>>>;
|
|
270
270
|
}, "strip", z.ZodTypeAny, {
|
|
271
|
-
debug: boolean;
|
|
272
271
|
lockPageSlug: string;
|
|
272
|
+
debug: boolean;
|
|
273
273
|
appwardenApiToken: string;
|
|
274
274
|
contentSecurityPolicy?: {
|
|
275
275
|
mode: "disabled" | "report-only" | "enforced";
|
|
@@ -306,7 +306,6 @@ declare const ReactRouterCloudflareConfigSchema: z.ZodObject<{
|
|
|
306
306
|
}, {
|
|
307
307
|
lockPageSlug: string;
|
|
308
308
|
appwardenApiToken: string;
|
|
309
|
-
debug?: string | boolean | undefined;
|
|
310
309
|
contentSecurityPolicy?: {
|
|
311
310
|
mode: "disabled" | "report-only" | "enforced";
|
|
312
311
|
directives: string | {
|
|
@@ -338,6 +337,7 @@ declare const ReactRouterCloudflareConfigSchema: z.ZodObject<{
|
|
|
338
337
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
339
338
|
};
|
|
340
339
|
} | undefined;
|
|
340
|
+
debug?: string | boolean | undefined;
|
|
341
341
|
appwardenApiHostname?: string | undefined;
|
|
342
342
|
}>;
|
|
343
343
|
type ReactRouterCloudflareConfig = z.infer<typeof ReactRouterCloudflareConfigSchema>;
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyContentSecurityPolicyToResponse,
|
|
3
3
|
isResponseLike
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-TBSMAMWC.js";
|
|
5
|
+
import "../chunk-J2TA6BEU.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-
|
|
12
|
+
} from "../chunk-HP5GMFH7.js";
|
|
13
13
|
import {
|
|
14
14
|
buildLockPageUrl,
|
|
15
|
+
createHeartbeatConfigError,
|
|
15
16
|
createRedirect,
|
|
16
17
|
debug,
|
|
18
|
+
handleHeartbeatRequest,
|
|
17
19
|
isHTMLRequest,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from "../chunk-
|
|
23
|
-
import {
|
|
24
|
-
printMessage
|
|
25
|
-
} from "../chunk-R7TXTHSG.js";
|
|
20
|
+
isHeartbeatRequest,
|
|
21
|
+
isOnLockPage,
|
|
22
|
+
printMessage,
|
|
23
|
+
sanitizeConfigErrors
|
|
24
|
+
} from "../chunk-2ZSJUEHK.js";
|
|
26
25
|
import {
|
|
27
26
|
AppwardenApiHostnameSchema,
|
|
28
27
|
AppwardenApiTokenSchema,
|
|
29
|
-
BooleanSchema
|
|
30
|
-
|
|
28
|
+
BooleanSchema,
|
|
29
|
+
HEARTBEAT_SERVICES,
|
|
30
|
+
UseCSPInputSchema
|
|
31
|
+
} from "../chunk-SREQAAZC.js";
|
|
31
32
|
|
|
32
33
|
// src/adapters/react-router-cloudflare.ts
|
|
33
34
|
import { waitUntil } from "cloudflare:workers";
|
|
@@ -48,13 +49,38 @@ var ReactRouterCloudflareConfigSchema = z.object({
|
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
// src/adapters/react-router-cloudflare.ts
|
|
52
|
+
var createConfigEvaluationHeartbeatResponse = (request) => {
|
|
53
|
+
return handleHeartbeatRequest(
|
|
54
|
+
request,
|
|
55
|
+
HEARTBEAT_SERVICES.CLOUDFLARE_REACT_ROUTER,
|
|
56
|
+
[
|
|
57
|
+
createHeartbeatConfigError(
|
|
58
|
+
["config"],
|
|
59
|
+
"custom",
|
|
60
|
+
"Appwarden config evaluation failed"
|
|
61
|
+
)
|
|
62
|
+
]
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
var handleReactRouterHeartbeatRequest = (request, configFn) => {
|
|
66
|
+
try {
|
|
67
|
+
const validationResult = ReactRouterCloudflareConfigSchema.safeParse(configFn());
|
|
68
|
+
return handleHeartbeatRequest(
|
|
69
|
+
request,
|
|
70
|
+
HEARTBEAT_SERVICES.CLOUDFLARE_REACT_ROUTER,
|
|
71
|
+
validationResult.success ? [] : sanitizeConfigErrors(validationResult.error)
|
|
72
|
+
);
|
|
73
|
+
} catch {
|
|
74
|
+
return createConfigEvaluationHeartbeatResponse(request);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
51
77
|
function createAppwardenMiddleware(configFn) {
|
|
52
78
|
return async (args, next) => {
|
|
53
79
|
const startTime = getNowMs();
|
|
54
80
|
const { request } = args;
|
|
55
81
|
let config;
|
|
56
82
|
let debugFn;
|
|
57
|
-
|
|
83
|
+
const requestUrl = new URL(request.url);
|
|
58
84
|
const applyCspToResponse = async (response2) => {
|
|
59
85
|
if (!config.contentSecurityPolicy || !isResponseLike(response2)) {
|
|
60
86
|
return response2;
|
|
@@ -77,6 +103,9 @@ function createAppwardenMiddleware(configFn) {
|
|
|
77
103
|
return response2;
|
|
78
104
|
}
|
|
79
105
|
};
|
|
106
|
+
if (isHeartbeatRequest(request, requestUrl)) {
|
|
107
|
+
return handleReactRouterHeartbeatRequest(request, configFn);
|
|
108
|
+
}
|
|
80
109
|
try {
|
|
81
110
|
const configInput = configFn();
|
|
82
111
|
const validationResult = ReactRouterCloudflareConfigSchema.safeParse(configInput);
|
|
@@ -90,7 +119,6 @@ function createAppwardenMiddleware(configFn) {
|
|
|
90
119
|
}
|
|
91
120
|
config = validationResult.data;
|
|
92
121
|
debugFn = debug(config.debug);
|
|
93
|
-
requestUrl = new URL(request.url);
|
|
94
122
|
const isHTML = isHTMLRequest(request);
|
|
95
123
|
debugFn(
|
|
96
124
|
`Appwarden middleware invoked for ${requestUrl.pathname}`,
|
|
@@ -268,8 +268,8 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
|
|
|
268
268
|
};
|
|
269
269
|
}>>>;
|
|
270
270
|
}, "strip", z.ZodTypeAny, {
|
|
271
|
-
debug: boolean;
|
|
272
271
|
lockPageSlug: string;
|
|
272
|
+
debug: boolean;
|
|
273
273
|
appwardenApiToken: string;
|
|
274
274
|
contentSecurityPolicy?: {
|
|
275
275
|
mode: "disabled" | "report-only" | "enforced";
|
|
@@ -306,7 +306,6 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
|
|
|
306
306
|
}, {
|
|
307
307
|
lockPageSlug: string;
|
|
308
308
|
appwardenApiToken: string;
|
|
309
|
-
debug?: string | boolean | undefined;
|
|
310
309
|
contentSecurityPolicy?: {
|
|
311
310
|
mode: "disabled" | "report-only" | "enforced";
|
|
312
311
|
directives: string | {
|
|
@@ -338,6 +337,7 @@ declare const TanStackStartCloudflareConfigSchema: z.ZodObject<{
|
|
|
338
337
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
339
338
|
};
|
|
340
339
|
} | undefined;
|
|
340
|
+
debug?: string | boolean | undefined;
|
|
341
341
|
appwardenApiHostname?: string | undefined;
|
|
342
342
|
}>;
|
|
343
343
|
type TanStackStartCloudflareConfig = z.infer<typeof TanStackStartCloudflareConfigSchema>;
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyContentSecurityPolicyToResponse,
|
|
3
3
|
isResponseLike
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-TBSMAMWC.js";
|
|
5
|
+
import "../chunk-J2TA6BEU.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-
|
|
12
|
+
} from "../chunk-HP5GMFH7.js";
|
|
13
13
|
import {
|
|
14
14
|
buildLockPageUrl,
|
|
15
|
+
createHeartbeatConfigError,
|
|
15
16
|
createRedirect,
|
|
16
17
|
debug,
|
|
18
|
+
handleHeartbeatRequest,
|
|
17
19
|
isHTMLRequest,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from "../chunk-
|
|
23
|
-
import {
|
|
24
|
-
printMessage
|
|
25
|
-
} from "../chunk-R7TXTHSG.js";
|
|
20
|
+
isHeartbeatRequest,
|
|
21
|
+
isOnLockPage,
|
|
22
|
+
printMessage,
|
|
23
|
+
sanitizeConfigErrors
|
|
24
|
+
} from "../chunk-2ZSJUEHK.js";
|
|
26
25
|
import {
|
|
27
26
|
AppwardenApiHostnameSchema,
|
|
28
27
|
AppwardenApiTokenSchema,
|
|
29
|
-
BooleanSchema
|
|
30
|
-
|
|
28
|
+
BooleanSchema,
|
|
29
|
+
HEARTBEAT_SERVICES,
|
|
30
|
+
UseCSPInputSchema
|
|
31
|
+
} from "../chunk-SREQAAZC.js";
|
|
31
32
|
|
|
32
33
|
// src/adapters/tanstack-start-cloudflare.ts
|
|
33
34
|
import { waitUntil } from "cloudflare:workers";
|
|
@@ -48,13 +49,35 @@ var TanStackStartCloudflareConfigSchema = z.object({
|
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
// src/adapters/tanstack-start-cloudflare.ts
|
|
52
|
+
var createTanStackHeartbeatResponse = (request, configFn) => {
|
|
53
|
+
try {
|
|
54
|
+
const validationResult = TanStackStartCloudflareConfigSchema.safeParse(configFn());
|
|
55
|
+
return handleHeartbeatRequest(
|
|
56
|
+
request,
|
|
57
|
+
HEARTBEAT_SERVICES.CLOUDFLARE_TANSTACK_START,
|
|
58
|
+
validationResult.success ? [] : sanitizeConfigErrors(validationResult.error)
|
|
59
|
+
);
|
|
60
|
+
} catch {
|
|
61
|
+
return handleHeartbeatRequest(
|
|
62
|
+
request,
|
|
63
|
+
HEARTBEAT_SERVICES.CLOUDFLARE_TANSTACK_START,
|
|
64
|
+
[
|
|
65
|
+
createHeartbeatConfigError(
|
|
66
|
+
["config"],
|
|
67
|
+
"custom",
|
|
68
|
+
"Appwarden config evaluation failed"
|
|
69
|
+
)
|
|
70
|
+
]
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
51
74
|
function createAppwardenMiddleware(configFn) {
|
|
52
75
|
const middleware = async (args) => {
|
|
53
76
|
const startTime = getNowMs();
|
|
54
77
|
const { request, next } = args;
|
|
55
78
|
let config;
|
|
56
79
|
let debugFn;
|
|
57
|
-
|
|
80
|
+
const requestUrl = new URL(request.url);
|
|
58
81
|
const applyCspToResponse = async (response2) => {
|
|
59
82
|
if (!config.contentSecurityPolicy || !isResponseLike(response2)) {
|
|
60
83
|
return response2;
|
|
@@ -77,6 +100,9 @@ function createAppwardenMiddleware(configFn) {
|
|
|
77
100
|
return response2;
|
|
78
101
|
}
|
|
79
102
|
};
|
|
103
|
+
if (isHeartbeatRequest(request, requestUrl)) {
|
|
104
|
+
throw createTanStackHeartbeatResponse(request, configFn);
|
|
105
|
+
}
|
|
80
106
|
try {
|
|
81
107
|
const rawConfig = configFn();
|
|
82
108
|
const validationResult = TanStackStartCloudflareConfigSchema.safeParse(rawConfig);
|
|
@@ -90,7 +116,6 @@ function createAppwardenMiddleware(configFn) {
|
|
|
90
116
|
}
|
|
91
117
|
config = validationResult.data;
|
|
92
118
|
debugFn = debug(config.debug ?? false);
|
|
93
|
-
requestUrl = new URL(request.url);
|
|
94
119
|
const isHTML = isHTMLRequest(request);
|
|
95
120
|
debugFn(
|
|
96
121
|
`Appwarden middleware invoked for ${requestUrl.pathname}`,
|
package/cloudflare.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { R as RequestContext, U as UseCSPInput, M as Middleware, B as Bindings } from './use-content-security-policy-
|
|
1
|
+
import { R as RequestContext, U as UseCSPInput, M as Middleware, B as Bindings } from './use-content-security-policy-Dwdcwp33.js';
|
|
2
2
|
import { z } from 'zod';
|
|
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<{
|
package/cloudflare.js
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UseAppwardenInputSchema,
|
|
3
3
|
lockPageSlugRefinement
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GNDWHKJ5.js";
|
|
5
|
+
import {
|
|
6
|
+
getErrors
|
|
7
|
+
} from "./chunk-NV7K5PRA.js";
|
|
5
8
|
import {
|
|
6
9
|
useContentSecurityPolicy
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-J2TA6BEU.js";
|
|
8
11
|
import {
|
|
9
12
|
checkLockStatus
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-HP5GMFH7.js";
|
|
11
14
|
import {
|
|
12
15
|
buildLockPageUrl,
|
|
16
|
+
createHeartbeatConfigError,
|
|
13
17
|
createRedirect,
|
|
14
18
|
debug,
|
|
19
|
+
handleHeartbeatRequest,
|
|
15
20
|
isHTMLRequest,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
isHeartbeatRequest,
|
|
22
|
+
isOnLockPage,
|
|
23
|
+
printMessage,
|
|
24
|
+
sanitizeConfigErrors
|
|
25
|
+
} from "./chunk-2ZSJUEHK.js";
|
|
19
26
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from "./chunk-R7TXTHSG.js";
|
|
23
|
-
import "./chunk-WEM7GS4M.js";
|
|
27
|
+
HEARTBEAT_SERVICES
|
|
28
|
+
} from "./chunk-SREQAAZC.js";
|
|
24
29
|
|
|
25
30
|
// src/runners/appwarden-on-cloudflare.ts
|
|
26
31
|
import { ZodError } from "zod";
|
|
@@ -51,6 +56,24 @@ var usePipeline = (...initMiddlewares) => {
|
|
|
51
56
|
};
|
|
52
57
|
};
|
|
53
58
|
|
|
59
|
+
// src/utils/cloudflare/insert-errors-logs.ts
|
|
60
|
+
var insertErrorLogs = async (context, error) => {
|
|
61
|
+
const errors = getErrors(error);
|
|
62
|
+
for (const err of errors) {
|
|
63
|
+
console.log(printMessage(err));
|
|
64
|
+
}
|
|
65
|
+
return new HTMLRewriter().on("body", {
|
|
66
|
+
element: (elem) => {
|
|
67
|
+
elem.append(
|
|
68
|
+
`<script>
|
|
69
|
+
${errors.map((err) => `console.error(\`${printMessage(err)}\`)`).join("\n")}
|
|
70
|
+
</script>`,
|
|
71
|
+
{ html: true }
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}).transform(await fetch(context.request.clone()));
|
|
75
|
+
};
|
|
76
|
+
|
|
54
77
|
// src/middlewares/use-appwarden.ts
|
|
55
78
|
var useAppwarden = (input) => async (context, next) => {
|
|
56
79
|
const { request } = context;
|
|
@@ -108,7 +131,36 @@ var useFetchOrigin = () => async (context, next) => {
|
|
|
108
131
|
var appwardenOnCloudflare = (inputFn) => async (request, env, ctx) => {
|
|
109
132
|
ctx.passThroughOnException();
|
|
110
133
|
const requestUrl = new URL(request.url);
|
|
134
|
+
const requestContext = {
|
|
135
|
+
env,
|
|
136
|
+
ctx
|
|
137
|
+
};
|
|
111
138
|
const parsedInput = ConfigFnInputSchema.safeParse(inputFn);
|
|
139
|
+
if (isHeartbeatRequest(request, requestUrl)) {
|
|
140
|
+
let configErrors = parsedInput.success ? [] : sanitizeConfigErrors(parsedInput.error);
|
|
141
|
+
if (parsedInput.success) {
|
|
142
|
+
try {
|
|
143
|
+
parsedInput.data(requestContext);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (error instanceof ZodError) {
|
|
146
|
+
configErrors = sanitizeConfigErrors(error);
|
|
147
|
+
} else {
|
|
148
|
+
configErrors = [
|
|
149
|
+
createHeartbeatConfigError(
|
|
150
|
+
["config"],
|
|
151
|
+
"custom",
|
|
152
|
+
"Appwarden config evaluation failed"
|
|
153
|
+
)
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return handleHeartbeatRequest(
|
|
159
|
+
request,
|
|
160
|
+
HEARTBEAT_SERVICES.CLOUDFLARE,
|
|
161
|
+
configErrors
|
|
162
|
+
);
|
|
163
|
+
}
|
|
112
164
|
if (!parsedInput.success) {
|
|
113
165
|
const tempContext = {
|
|
114
166
|
request,
|
|
@@ -121,7 +173,24 @@ var appwardenOnCloudflare = (inputFn) => async (request, env, ctx) => {
|
|
|
121
173
|
};
|
|
122
174
|
return insertErrorLogs(tempContext, parsedInput.error);
|
|
123
175
|
}
|
|
124
|
-
|
|
176
|
+
let input;
|
|
177
|
+
try {
|
|
178
|
+
input = parsedInput.data(requestContext);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error instanceof ZodError) {
|
|
181
|
+
const tempContext = {
|
|
182
|
+
request,
|
|
183
|
+
hostname: requestUrl.hostname,
|
|
184
|
+
response: new Response("Unhandled response"),
|
|
185
|
+
waitUntil: (fn) => ctx.waitUntil(fn),
|
|
186
|
+
debug: () => {
|
|
187
|
+
}
|
|
188
|
+
// no-op debug for error case
|
|
189
|
+
};
|
|
190
|
+
return insertErrorLogs(tempContext, error);
|
|
191
|
+
}
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
125
194
|
const domainDebug = input.multidomainConfig?.[requestUrl.hostname]?.debug ?? input.debug ?? false;
|
|
126
195
|
const context = {
|
|
127
196
|
request,
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,115 @@
|
|
|
1
|
-
export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware } from './use-content-security-policy-
|
|
1
|
+
export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware } from './use-content-security-policy-Dwdcwp33.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
4
|
declare const LOCKDOWN_TEST_EXPIRY_MS: number;
|
|
5
5
|
declare const APPWARDEN_CACHE_KEY: "appwarden-lock";
|
|
6
|
+
declare const HEARTBEAT_SERVICE_VALUES: readonly ["cloudflare", "cloudflare-astro", "cloudflare-react-router", "cloudflare-tanstack-start", "cloudflare-nextjs", "vercel"];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Service identifiers for different middleware adapters.
|
|
10
|
+
* These are hardcoded per adapter bundle.
|
|
11
|
+
*/
|
|
12
|
+
type HeartbeatService = (typeof HEARTBEAT_SERVICE_VALUES)[number];
|
|
13
|
+
/**
|
|
14
|
+
* Schema for validating heartbeat config errors.
|
|
15
|
+
* Ensures errors are bounded and sanitized.
|
|
16
|
+
*/
|
|
17
|
+
declare const HeartbeatConfigErrorSchema: z.ZodObject<{
|
|
18
|
+
path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
|
|
19
|
+
code: z.ZodString;
|
|
20
|
+
message: z.ZodString;
|
|
21
|
+
}, "strict", z.ZodTypeAny, {
|
|
22
|
+
message: string;
|
|
23
|
+
code: string;
|
|
24
|
+
path: (string | number)[];
|
|
25
|
+
}, {
|
|
26
|
+
message: string;
|
|
27
|
+
code: string;
|
|
28
|
+
path: (string | number)[];
|
|
29
|
+
}>;
|
|
30
|
+
type HeartbeatConfigError = z.infer<typeof HeartbeatConfigErrorSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Schema for validating the heartbeat response body.
|
|
33
|
+
*/
|
|
34
|
+
declare const HeartbeatResponseBodySchema: z.ZodEffects<z.ZodObject<{
|
|
35
|
+
app: z.ZodLiteral<"appwarden">;
|
|
36
|
+
kind: z.ZodLiteral<"heartbeat">;
|
|
37
|
+
status: z.ZodLiteral<"ok">;
|
|
38
|
+
contractVersion: z.ZodLiteral<1>;
|
|
39
|
+
service: z.ZodEnum<["cloudflare", "cloudflare-astro", "cloudflare-react-router", "cloudflare-tanstack-start", "cloudflare-nextjs", "vercel"]>;
|
|
40
|
+
version: z.ZodString;
|
|
41
|
+
configErrors: z.ZodEffects<z.ZodArray<z.ZodObject<{
|
|
42
|
+
path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
|
|
43
|
+
code: z.ZodString;
|
|
44
|
+
message: z.ZodString;
|
|
45
|
+
}, "strict", z.ZodTypeAny, {
|
|
46
|
+
message: string;
|
|
47
|
+
code: string;
|
|
48
|
+
path: (string | number)[];
|
|
49
|
+
}, {
|
|
50
|
+
message: string;
|
|
51
|
+
code: string;
|
|
52
|
+
path: (string | number)[];
|
|
53
|
+
}>, "many">, {
|
|
54
|
+
message: string;
|
|
55
|
+
code: string;
|
|
56
|
+
path: (string | number)[];
|
|
57
|
+
}[], {
|
|
58
|
+
message: string;
|
|
59
|
+
code: string;
|
|
60
|
+
path: (string | number)[];
|
|
61
|
+
}[]>;
|
|
62
|
+
}, "strict", z.ZodTypeAny, {
|
|
63
|
+
status: "ok";
|
|
64
|
+
app: "appwarden";
|
|
65
|
+
kind: "heartbeat";
|
|
66
|
+
contractVersion: 1;
|
|
67
|
+
service: "cloudflare" | "cloudflare-astro" | "cloudflare-react-router" | "cloudflare-tanstack-start" | "cloudflare-nextjs" | "vercel";
|
|
68
|
+
version: string;
|
|
69
|
+
configErrors: {
|
|
70
|
+
message: string;
|
|
71
|
+
code: string;
|
|
72
|
+
path: (string | number)[];
|
|
73
|
+
}[];
|
|
74
|
+
}, {
|
|
75
|
+
status: "ok";
|
|
76
|
+
app: "appwarden";
|
|
77
|
+
kind: "heartbeat";
|
|
78
|
+
contractVersion: 1;
|
|
79
|
+
service: "cloudflare" | "cloudflare-astro" | "cloudflare-react-router" | "cloudflare-tanstack-start" | "cloudflare-nextjs" | "vercel";
|
|
80
|
+
version: string;
|
|
81
|
+
configErrors: {
|
|
82
|
+
message: string;
|
|
83
|
+
code: string;
|
|
84
|
+
path: (string | number)[];
|
|
85
|
+
}[];
|
|
86
|
+
}>, {
|
|
87
|
+
status: "ok";
|
|
88
|
+
app: "appwarden";
|
|
89
|
+
kind: "heartbeat";
|
|
90
|
+
contractVersion: 1;
|
|
91
|
+
service: "cloudflare" | "cloudflare-astro" | "cloudflare-react-router" | "cloudflare-tanstack-start" | "cloudflare-nextjs" | "vercel";
|
|
92
|
+
version: string;
|
|
93
|
+
configErrors: {
|
|
94
|
+
message: string;
|
|
95
|
+
code: string;
|
|
96
|
+
path: (string | number)[];
|
|
97
|
+
}[];
|
|
98
|
+
}, {
|
|
99
|
+
status: "ok";
|
|
100
|
+
app: "appwarden";
|
|
101
|
+
kind: "heartbeat";
|
|
102
|
+
contractVersion: 1;
|
|
103
|
+
service: "cloudflare" | "cloudflare-astro" | "cloudflare-react-router" | "cloudflare-tanstack-start" | "cloudflare-nextjs" | "vercel";
|
|
104
|
+
version: string;
|
|
105
|
+
configErrors: {
|
|
106
|
+
message: string;
|
|
107
|
+
code: string;
|
|
108
|
+
path: (string | number)[];
|
|
109
|
+
}[];
|
|
110
|
+
}>;
|
|
111
|
+
type HeartbeatResponseBody = z.infer<typeof HeartbeatResponseBodySchema>;
|
|
112
|
+
declare function validateHeartbeatResponseBody(value: unknown): HeartbeatResponseBody;
|
|
6
113
|
|
|
7
114
|
/**
|
|
8
115
|
* Extracts the Edge Config ID from a valid Edge Config URL
|
|
@@ -787,4 +894,4 @@ declare const LockValue: z.ZodObject<{
|
|
|
787
894
|
}>;
|
|
788
895
|
type LockValueType = z.infer<typeof LockValue>;
|
|
789
896
|
|
|
790
|
-
export { APPWARDEN_CACHE_KEY, LOCKDOWN_TEST_EXPIRY_MS, type LockValueType, UseAppwardenInputSchema, getEdgeConfigId, isCacheUrl, isValidCacheUrl };
|
|
897
|
+
export { APPWARDEN_CACHE_KEY, type HeartbeatConfigError, HeartbeatConfigErrorSchema, type HeartbeatResponseBody, HeartbeatResponseBodySchema, type HeartbeatService, LOCKDOWN_TEST_EXPIRY_MS, type LockValueType, UseAppwardenInputSchema, getEdgeConfigId, isCacheUrl, isValidCacheUrl, validateHeartbeatResponseBody };
|
package/index.js
CHANGED
|
@@ -5,21 +5,26 @@ import {
|
|
|
5
5
|
} from "./chunk-QEFORWCW.js";
|
|
6
6
|
import {
|
|
7
7
|
UseAppwardenInputSchema
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GNDWHKJ5.js";
|
|
9
9
|
import {
|
|
10
10
|
APPWARDEN_CACHE_KEY,
|
|
11
11
|
CSPDirectivesSchema,
|
|
12
12
|
CSPModeSchema,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
HeartbeatConfigErrorSchema,
|
|
14
|
+
HeartbeatResponseBodySchema,
|
|
15
|
+
LOCKDOWN_TEST_EXPIRY_MS,
|
|
16
|
+
validateHeartbeatResponseBody
|
|
17
|
+
} from "./chunk-SREQAAZC.js";
|
|
16
18
|
export {
|
|
17
19
|
APPWARDEN_CACHE_KEY,
|
|
18
20
|
CSPDirectivesSchema,
|
|
19
21
|
CSPModeSchema,
|
|
22
|
+
HeartbeatConfigErrorSchema,
|
|
23
|
+
HeartbeatResponseBodySchema,
|
|
20
24
|
LOCKDOWN_TEST_EXPIRY_MS,
|
|
21
25
|
UseAppwardenInputSchema,
|
|
22
26
|
getEdgeConfigId,
|
|
23
27
|
isCacheUrl,
|
|
24
|
-
isValidCacheUrl
|
|
28
|
+
isValidCacheUrl,
|
|
29
|
+
validateHeartbeatResponseBody
|
|
25
30
|
};
|