@appwarden/middleware 3.14.1 → 3.15.1
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-2FSRHIPY.js → chunk-2ZKE4AI4.js} +50 -2
- package/{chunk-JJOX4UAG.js → chunk-IAOONP5L.js} +5 -4
- package/{chunk-PCWFMNHW.js → chunk-L4UHIU77.js} +17 -4
- package/{chunk-7BZFEX4Z.js → chunk-LRDZKQI3.js} +1 -1
- package/{chunk-LDKC5DRW.js → chunk-TXFZUVJP.js} +21 -2
- package/{chunk-DM57ZOTI.js → chunk-YJSTNZGA.js} +8 -3
- package/cloudflare/astro.d.ts +13 -6
- package/cloudflare/astro.js +18 -8
- package/cloudflare/nextjs.d.ts +5 -4
- package/cloudflare/nextjs.js +16 -6
- package/cloudflare/react-router.d.ts +5 -4
- package/cloudflare/react-router.js +18 -8
- package/cloudflare/tanstack-start.d.ts +6 -4
- package/cloudflare/tanstack-start.js +18 -8
- package/cloudflare.d.ts +733 -4
- package/cloudflare.js +26 -8
- package/index.d.ts +3 -3
- package/index.js +2 -2
- package/package.json +19 -13
- package/scripts/appwarden-link.cjs +851 -0
- package/vercel.d.ts +4 -3
- package/vercel.js +34 -6
package/vercel.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { z } from 'zod';
|
|
|
3
3
|
declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
4
4
|
cacheUrl: z.ZodString;
|
|
5
5
|
appwardenApiToken: z.ZodString;
|
|
6
|
-
appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
6
|
+
appwardenApiHostname: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
7
7
|
vercelApiToken: z.ZodOptional<z.ZodString>;
|
|
8
8
|
debug: z.ZodOptional<z.ZodBoolean>;
|
|
9
|
-
lockPageSlug: z.ZodEffects<z.ZodDefault<z.ZodString
|
|
9
|
+
lockPageSlug: z.ZodEffects<z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>, string, string | undefined>;
|
|
10
10
|
contentSecurityPolicy: z.ZodOptional<z.ZodObject<{
|
|
11
11
|
mode: z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>;
|
|
12
12
|
directives: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodLazy<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
@@ -697,7 +697,8 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
697
697
|
}>;
|
|
698
698
|
type VercelAppwardenConfig = z.input<typeof AppwardenConfigSchema>;
|
|
699
699
|
|
|
700
|
+
declare function getAppwardenConfiguration(generatedConfig: Record<string, unknown>, config: Partial<VercelAppwardenConfig>): ReturnType<typeof AppwardenConfigSchema.parse>;
|
|
700
701
|
type VercelMiddlewareFunction = (request: Request) => Promise<Response>;
|
|
701
702
|
declare function createAppwardenMiddleware(config: VercelAppwardenConfig): VercelMiddlewareFunction;
|
|
702
703
|
|
|
703
|
-
export { type VercelMiddlewareFunction, createAppwardenMiddleware };
|
|
704
|
+
export { type VercelMiddlewareFunction, createAppwardenMiddleware, getAppwardenConfiguration };
|
package/vercel.js
CHANGED
|
@@ -18,9 +18,10 @@ import {
|
|
|
18
18
|
isHeartbeatRequest,
|
|
19
19
|
isOnLockPage,
|
|
20
20
|
makeCSPHeader,
|
|
21
|
+
parseMergedConfig,
|
|
21
22
|
printMessage,
|
|
22
23
|
sanitizeConfigErrors
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-2ZKE4AI4.js";
|
|
24
25
|
import {
|
|
25
26
|
APPWARDEN_CACHE_KEY,
|
|
26
27
|
APPWARDEN_MIDDLEWARE_USER_AGENT,
|
|
@@ -29,9 +30,10 @@ import {
|
|
|
29
30
|
CSPModeSchema,
|
|
30
31
|
HEARTBEAT_SERVICES,
|
|
31
32
|
LockValue,
|
|
33
|
+
ValidLockPageSlugSchema,
|
|
32
34
|
errors,
|
|
33
35
|
globalErrors
|
|
34
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-TXFZUVJP.js";
|
|
35
37
|
|
|
36
38
|
// src/runners/appwarden-on-vercel.ts
|
|
37
39
|
import { waitUntil } from "@vercel/functions";
|
|
@@ -111,10 +113,23 @@ var APIError = class extends Error {
|
|
|
111
113
|
this.name = "APIError";
|
|
112
114
|
}
|
|
113
115
|
};
|
|
116
|
+
var API_TIMEOUT_MS = 1e4;
|
|
117
|
+
function resolveApiHostname(hostname) {
|
|
118
|
+
if (!hostname) {
|
|
119
|
+
return "https://api.appwarden.io";
|
|
120
|
+
}
|
|
121
|
+
const parsed = AppwardenApiHostnameSchema.safeParse(hostname);
|
|
122
|
+
if (!parsed.success) {
|
|
123
|
+
return "https://api.appwarden.io";
|
|
124
|
+
}
|
|
125
|
+
return parsed.data;
|
|
126
|
+
}
|
|
114
127
|
var syncEdgeValue = async (context) => {
|
|
115
128
|
context.debug("syncing with api");
|
|
129
|
+
const apiHostname = resolveApiHostname(context.appwardenApiHostname);
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
const timeout = setTimeout(() => controller.abort(), API_TIMEOUT_MS);
|
|
116
132
|
try {
|
|
117
|
-
const apiHostname = context.appwardenApiHostname ?? "https://api.appwarden.io";
|
|
118
133
|
const response = await fetch(new URL("/v1/appwarden/status", apiHostname), {
|
|
119
134
|
method: "POST",
|
|
120
135
|
headers: {
|
|
@@ -127,7 +142,8 @@ var syncEdgeValue = async (context) => {
|
|
|
127
142
|
fqdn: context.requestUrl.hostname,
|
|
128
143
|
vercelApiToken: context.vercelApiToken ?? "",
|
|
129
144
|
appwardenApiToken: context.appwardenApiToken
|
|
130
|
-
})
|
|
145
|
+
}),
|
|
146
|
+
signal: controller.signal
|
|
131
147
|
});
|
|
132
148
|
if (response.status === 403) {
|
|
133
149
|
console.log(
|
|
@@ -152,6 +168,8 @@ var syncEdgeValue = async (context) => {
|
|
|
152
168
|
e instanceof APIError ? e.message : e instanceof Error ? `${message} - ${e.message}` : message
|
|
153
169
|
)
|
|
154
170
|
);
|
|
171
|
+
} finally {
|
|
172
|
+
clearTimeout(timeout);
|
|
155
173
|
}
|
|
156
174
|
};
|
|
157
175
|
|
|
@@ -205,7 +223,9 @@ var BaseNextJsConfigSchema = z.object({
|
|
|
205
223
|
appwardenApiHostname: AppwardenApiHostnameSchema.optional(),
|
|
206
224
|
vercelApiToken: z.string().optional(),
|
|
207
225
|
debug: z.boolean().optional(),
|
|
208
|
-
lockPageSlug:
|
|
226
|
+
lockPageSlug: ValidLockPageSlugSchema.default("").transform(
|
|
227
|
+
(val) => val.replace(/^\/?/, "/")
|
|
228
|
+
),
|
|
209
229
|
contentSecurityPolicy: VercelCSPSchema.optional()
|
|
210
230
|
});
|
|
211
231
|
var AppwardenConfigSchema = BaseNextJsConfigSchema.refine(
|
|
@@ -256,6 +276,13 @@ var AppwardenConfigSchema = BaseNextJsConfigSchema.refine(
|
|
|
256
276
|
});
|
|
257
277
|
|
|
258
278
|
// src/runners/appwarden-on-vercel.ts
|
|
279
|
+
function getAppwardenConfiguration(generatedConfig, config) {
|
|
280
|
+
return parseMergedConfig(
|
|
281
|
+
generatedConfig,
|
|
282
|
+
config,
|
|
283
|
+
AppwardenConfigSchema.parse
|
|
284
|
+
);
|
|
285
|
+
}
|
|
259
286
|
var memoryCache = new MemoryCache({ maxSize: 1 });
|
|
260
287
|
function safeWaitUntil(promise) {
|
|
261
288
|
try {
|
|
@@ -379,5 +406,6 @@ function createAppwardenMiddleware(config) {
|
|
|
379
406
|
};
|
|
380
407
|
}
|
|
381
408
|
export {
|
|
382
|
-
createAppwardenMiddleware
|
|
409
|
+
createAppwardenMiddleware,
|
|
410
|
+
getAppwardenConfiguration
|
|
383
411
|
};
|