@appwarden/middleware 3.11.5 → 3.12.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-5HCAAVK5.js → chunk-6YCNCR22.js} +3 -5
- package/{chunk-R7TXTHSG.js → chunk-EXGUJ5XK.js} +75 -143
- package/chunk-G6BMPIYD.js +11 -0
- package/chunk-HTSD4WPC.js +378 -0
- package/chunk-HUWGPM4M.js +9 -0
- package/{chunk-WBWF3PPX.js → chunk-ILIYP3TG.js} +4 -6
- package/{chunk-XFG6SUSV.js → chunk-M2YVPCTG.js} +15 -0
- package/chunk-NV7K5PRA.js +36 -0
- package/{chunk-ZTVJBORU.js → chunk-Z7P4QVEY.js} +74 -8
- package/cloudflare/astro.d.ts +3 -3
- package/cloudflare/astro.js +109 -62
- package/cloudflare/nextjs.d.ts +2 -2
- package/cloudflare/nextjs.js +65 -21
- package/cloudflare/react-router.d.ts +3 -3
- package/cloudflare/react-router.js +92 -57
- package/cloudflare/tanstack-start.d.ts +2 -2
- package/cloudflare/tanstack-start.js +92 -80
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +80 -11
- package/index.d.ts +1 -1
- package/index.js +2 -3
- 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-X7WZVYQS.js +0 -6
- package/cloudflare-MAHYENA6.js +0 -29
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
|
+
applyContentSecurityPolicyToResponse,
|
|
2
3
|
isResponseLike
|
|
3
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-M2YVPCTG.js";
|
|
5
|
+
import "../chunk-ILIYP3TG.js";
|
|
4
6
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getNowMs
|
|
9
|
-
} from "../chunk-X7WZVYQS.js";
|
|
7
|
+
getNowMs,
|
|
8
|
+
logElapsed
|
|
9
|
+
} from "../chunk-G6BMPIYD.js";
|
|
10
10
|
import {
|
|
11
11
|
checkLockStatus
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-EXGUJ5XK.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-HTSD4WPC.js";
|
|
26
25
|
import {
|
|
27
26
|
AppwardenApiHostnameSchema,
|
|
28
27
|
AppwardenApiTokenSchema,
|
|
29
|
-
BooleanSchema
|
|
30
|
-
|
|
28
|
+
BooleanSchema,
|
|
29
|
+
HEARTBEAT_SERVICES,
|
|
30
|
+
UseCSPInputSchema
|
|
31
|
+
} from "../chunk-Z7P4QVEY.js";
|
|
31
32
|
|
|
32
33
|
// src/adapters/react-router-cloudflare.ts
|
|
33
34
|
import { waitUntil } from "cloudflare:workers";
|
|
@@ -48,10 +49,63 @@ 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;
|
|
81
|
+
let config;
|
|
82
|
+
let debugFn;
|
|
83
|
+
const requestUrl = new URL(request.url);
|
|
84
|
+
const applyCspToResponse = async (response2) => {
|
|
85
|
+
if (!config.contentSecurityPolicy || !isResponseLike(response2)) {
|
|
86
|
+
return response2;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
return await applyContentSecurityPolicyToResponse({
|
|
90
|
+
request,
|
|
91
|
+
response: response2,
|
|
92
|
+
hostname: requestUrl.hostname,
|
|
93
|
+
waitUntil,
|
|
94
|
+
debug: debugFn,
|
|
95
|
+
contentSecurityPolicy: config.contentSecurityPolicy
|
|
96
|
+
});
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error(
|
|
99
|
+
printMessage(
|
|
100
|
+
`Failed to apply content security policy: ${error instanceof Error ? error.message : String(error)}`
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
return response2;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
if (isHeartbeatRequest(request, requestUrl)) {
|
|
107
|
+
return handleReactRouterHeartbeatRequest(request, configFn);
|
|
108
|
+
}
|
|
55
109
|
try {
|
|
56
110
|
const configInput = configFn();
|
|
57
111
|
const validationResult = ReactRouterCloudflareConfigSchema.safeParse(configInput);
|
|
@@ -63,9 +117,8 @@ function createAppwardenMiddleware(configFn) {
|
|
|
63
117
|
);
|
|
64
118
|
return next();
|
|
65
119
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const requestUrl = new URL(request.url);
|
|
120
|
+
config = validationResult.data;
|
|
121
|
+
debugFn = debug(config.debug);
|
|
69
122
|
const isHTML = isHTMLRequest(request);
|
|
70
123
|
debugFn(
|
|
71
124
|
`Appwarden middleware invoked for ${requestUrl.pathname}`,
|
|
@@ -75,45 +128,23 @@ function createAppwardenMiddleware(configFn) {
|
|
|
75
128
|
return next();
|
|
76
129
|
}
|
|
77
130
|
if (isOnLockPage(config.lockPageSlug, request.url)) {
|
|
78
|
-
debugFn("Already on lock page - skipping");
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const result = await checkLockStatus({
|
|
82
|
-
request,
|
|
83
|
-
appwardenApiToken: config.appwardenApiToken,
|
|
84
|
-
appwardenApiHostname: config.appwardenApiHostname,
|
|
85
|
-
debug: config.debug,
|
|
86
|
-
lockPageSlug: config.lockPageSlug,
|
|
87
|
-
waitUntil
|
|
88
|
-
});
|
|
89
|
-
if (result.isLocked) {
|
|
90
|
-
const lockPageUrl = buildLockPageUrl(config.lockPageSlug, request.url);
|
|
91
|
-
debugFn(`Website is locked - redirecting to ${lockPageUrl.pathname}`);
|
|
92
|
-
throw createRedirect(lockPageUrl);
|
|
93
|
-
}
|
|
94
|
-
debugFn("Website is unlocked");
|
|
95
|
-
const response = await next();
|
|
96
|
-
if (config.contentSecurityPolicy && isResponseLike(response)) {
|
|
97
|
-
const cspContext = {
|
|
131
|
+
debugFn("Already on lock page - skipping lock status check");
|
|
132
|
+
} else {
|
|
133
|
+
const result = await checkLockStatus({
|
|
98
134
|
request,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
debugFn(`Middleware executed in ${elapsed2}ms`);
|
|
112
|
-
return cspContext.response;
|
|
135
|
+
appwardenApiToken: config.appwardenApiToken,
|
|
136
|
+
appwardenApiHostname: config.appwardenApiHostname,
|
|
137
|
+
debug: config.debug,
|
|
138
|
+
lockPageSlug: config.lockPageSlug,
|
|
139
|
+
waitUntil
|
|
140
|
+
});
|
|
141
|
+
if (result.isLocked) {
|
|
142
|
+
const lockPageUrl = buildLockPageUrl(config.lockPageSlug, request.url);
|
|
143
|
+
debugFn(`Website is locked - redirecting to ${lockPageUrl.pathname}`);
|
|
144
|
+
throw createRedirect(lockPageUrl);
|
|
145
|
+
}
|
|
146
|
+
debugFn("Website is unlocked");
|
|
113
147
|
}
|
|
114
|
-
const elapsed = Math.round(getNowMs() - startTime);
|
|
115
|
-
debugFn(`Middleware executed in ${elapsed}ms`);
|
|
116
|
-
return response;
|
|
117
148
|
} catch (error) {
|
|
118
149
|
if (isResponseLike(error)) {
|
|
119
150
|
throw error;
|
|
@@ -125,6 +156,10 @@ function createAppwardenMiddleware(configFn) {
|
|
|
125
156
|
);
|
|
126
157
|
return next();
|
|
127
158
|
}
|
|
159
|
+
const response = await next();
|
|
160
|
+
const finalResponse = isResponseLike(response) ? await applyCspToResponse(response) : response;
|
|
161
|
+
logElapsed(debugFn, startTime);
|
|
162
|
+
return finalResponse;
|
|
128
163
|
};
|
|
129
164
|
}
|
|
130
165
|
export {
|
|
@@ -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
|
+
applyContentSecurityPolicyToResponse,
|
|
2
3
|
isResponseLike
|
|
3
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-M2YVPCTG.js";
|
|
5
|
+
import "../chunk-ILIYP3TG.js";
|
|
4
6
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getNowMs
|
|
9
|
-
} from "../chunk-X7WZVYQS.js";
|
|
7
|
+
getNowMs,
|
|
8
|
+
logElapsed
|
|
9
|
+
} from "../chunk-G6BMPIYD.js";
|
|
10
10
|
import {
|
|
11
11
|
checkLockStatus
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-EXGUJ5XK.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-HTSD4WPC.js";
|
|
26
25
|
import {
|
|
27
26
|
AppwardenApiHostnameSchema,
|
|
28
27
|
AppwardenApiTokenSchema,
|
|
29
|
-
BooleanSchema
|
|
30
|
-
|
|
28
|
+
BooleanSchema,
|
|
29
|
+
HEARTBEAT_SERVICES,
|
|
30
|
+
UseCSPInputSchema
|
|
31
|
+
} from "../chunk-Z7P4QVEY.js";
|
|
31
32
|
|
|
32
33
|
// src/adapters/tanstack-start-cloudflare.ts
|
|
33
34
|
import { waitUntil } from "cloudflare:workers";
|
|
@@ -48,10 +49,60 @@ 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;
|
|
78
|
+
let config;
|
|
79
|
+
let debugFn;
|
|
80
|
+
const requestUrl = new URL(request.url);
|
|
81
|
+
const applyCspToResponse = async (response2) => {
|
|
82
|
+
if (!config.contentSecurityPolicy || !isResponseLike(response2)) {
|
|
83
|
+
return response2;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return await applyContentSecurityPolicyToResponse({
|
|
87
|
+
request,
|
|
88
|
+
response: response2,
|
|
89
|
+
hostname: requestUrl.hostname,
|
|
90
|
+
waitUntil,
|
|
91
|
+
debug: debugFn,
|
|
92
|
+
contentSecurityPolicy: config.contentSecurityPolicy
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error(
|
|
96
|
+
printMessage(
|
|
97
|
+
`Failed to apply content security policy: ${error instanceof Error ? error.message : String(error)}`
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
return response2;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
if (isHeartbeatRequest(request, requestUrl)) {
|
|
104
|
+
throw createTanStackHeartbeatResponse(request, configFn);
|
|
105
|
+
}
|
|
55
106
|
try {
|
|
56
107
|
const rawConfig = configFn();
|
|
57
108
|
const validationResult = TanStackStartCloudflareConfigSchema.safeParse(rawConfig);
|
|
@@ -63,9 +114,8 @@ function createAppwardenMiddleware(configFn) {
|
|
|
63
114
|
);
|
|
64
115
|
return next();
|
|
65
116
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const requestUrl = new URL(request.url);
|
|
117
|
+
config = validationResult.data;
|
|
118
|
+
debugFn = debug(config.debug ?? false);
|
|
69
119
|
const isHTML = isHTMLRequest(request);
|
|
70
120
|
debugFn(
|
|
71
121
|
`Appwarden middleware invoked for ${requestUrl.pathname}`,
|
|
@@ -75,69 +125,27 @@ function createAppwardenMiddleware(configFn) {
|
|
|
75
125
|
return next();
|
|
76
126
|
}
|
|
77
127
|
if (isOnLockPage(config.lockPageSlug, request.url)) {
|
|
78
|
-
debugFn("Already on lock page - skipping");
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (config.contentSecurityPolicy && isResponseLike(redirectResponse)) {
|
|
94
|
-
const cspContext = {
|
|
95
|
-
request,
|
|
96
|
-
response: redirectResponse,
|
|
97
|
-
hostname: requestUrl.hostname,
|
|
98
|
-
waitUntil,
|
|
99
|
-
debug: debugFn
|
|
100
|
-
};
|
|
101
|
-
await useContentSecurityPolicy(config.contentSecurityPolicy)(
|
|
102
|
-
cspContext,
|
|
103
|
-
async () => {
|
|
104
|
-
}
|
|
128
|
+
debugFn("Already on lock page - skipping lock status check");
|
|
129
|
+
} else {
|
|
130
|
+
const lockStatus = await checkLockStatus({
|
|
131
|
+
request,
|
|
132
|
+
appwardenApiToken: config.appwardenApiToken,
|
|
133
|
+
appwardenApiHostname: config.appwardenApiHostname,
|
|
134
|
+
debug: config.debug,
|
|
135
|
+
lockPageSlug: config.lockPageSlug,
|
|
136
|
+
waitUntil
|
|
137
|
+
});
|
|
138
|
+
if (lockStatus.isLocked) {
|
|
139
|
+
const lockPageUrl = buildLockPageUrl(config.lockPageSlug, request.url);
|
|
140
|
+
debugFn(`Website is locked - redirecting to ${lockPageUrl.pathname}`);
|
|
141
|
+
const redirectResponse = await applyCspToResponse(
|
|
142
|
+
createRedirect(lockPageUrl)
|
|
105
143
|
);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
throw cspContext.response;
|
|
144
|
+
logElapsed(debugFn, startTime);
|
|
145
|
+
throw redirectResponse;
|
|
109
146
|
}
|
|
110
|
-
|
|
111
|
-
debugFn(`Middleware executed in ${elapsed2}ms`);
|
|
112
|
-
throw redirectResponse;
|
|
113
|
-
}
|
|
114
|
-
debugFn("Website is unlocked");
|
|
115
|
-
const result = await next();
|
|
116
|
-
const { response } = result;
|
|
117
|
-
if (config.contentSecurityPolicy && isResponseLike(response)) {
|
|
118
|
-
const cspContext = {
|
|
119
|
-
request,
|
|
120
|
-
response,
|
|
121
|
-
hostname: requestUrl.hostname,
|
|
122
|
-
waitUntil,
|
|
123
|
-
debug: debugFn
|
|
124
|
-
};
|
|
125
|
-
await useContentSecurityPolicy(config.contentSecurityPolicy)(
|
|
126
|
-
cspContext,
|
|
127
|
-
async () => {
|
|
128
|
-
}
|
|
129
|
-
// no-op next
|
|
130
|
-
);
|
|
131
|
-
const elapsed2 = Math.round(getNowMs() - startTime);
|
|
132
|
-
debugFn(`Middleware executed in ${elapsed2}ms`);
|
|
133
|
-
return {
|
|
134
|
-
...result,
|
|
135
|
-
response: cspContext.response
|
|
136
|
-
};
|
|
147
|
+
debugFn("Website is unlocked");
|
|
137
148
|
}
|
|
138
|
-
const elapsed = Math.round(getNowMs() - startTime);
|
|
139
|
-
debugFn(`Middleware executed in ${elapsed}ms`);
|
|
140
|
-
return result;
|
|
141
149
|
} catch (error) {
|
|
142
150
|
if (isResponseLike(error)) {
|
|
143
151
|
throw error;
|
|
@@ -149,6 +157,10 @@ function createAppwardenMiddleware(configFn) {
|
|
|
149
157
|
);
|
|
150
158
|
return next();
|
|
151
159
|
}
|
|
160
|
+
const result = await next();
|
|
161
|
+
const response = isResponseLike(result.response) ? await applyCspToResponse(result.response) : result.response;
|
|
162
|
+
logElapsed(debugFn, startTime);
|
|
163
|
+
return response === result.response ? result : { ...result, response };
|
|
152
164
|
};
|
|
153
165
|
return middleware;
|
|
154
166
|
}
|
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-6YCNCR22.js";
|
|
5
|
+
import {
|
|
6
|
+
getErrors
|
|
7
|
+
} from "./chunk-NV7K5PRA.js";
|
|
5
8
|
import {
|
|
6
9
|
useContentSecurityPolicy
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ILIYP3TG.js";
|
|
8
11
|
import {
|
|
9
12
|
checkLockStatus
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-EXGUJ5XK.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-HTSD4WPC.js";
|
|
19
26
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from "./chunk-R7TXTHSG.js";
|
|
23
|
-
import "./chunk-WEM7GS4M.js";
|
|
27
|
+
HEARTBEAT_SERVICES
|
|
28
|
+
} from "./chunk-Z7P4QVEY.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,4 +1,4 @@
|
|
|
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;
|
package/index.js
CHANGED
|
@@ -5,14 +5,13 @@ import {
|
|
|
5
5
|
} from "./chunk-QEFORWCW.js";
|
|
6
6
|
import {
|
|
7
7
|
UseAppwardenInputSchema
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-6YCNCR22.js";
|
|
9
9
|
import {
|
|
10
10
|
APPWARDEN_CACHE_KEY,
|
|
11
11
|
CSPDirectivesSchema,
|
|
12
12
|
CSPModeSchema,
|
|
13
13
|
LOCKDOWN_TEST_EXPIRY_MS
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-WEM7GS4M.js";
|
|
14
|
+
} from "./chunk-Z7P4QVEY.js";
|
|
16
15
|
export {
|
|
17
16
|
APPWARDEN_CACHE_KEY,
|
|
18
17
|
CSPDirectivesSchema,
|
package/package.json
CHANGED