@appwarden/middleware 3.14.1 → 3.15.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/{chunk-2FSRHIPY.js → chunk-2R3NOSYY.js} +50 -2
- package/{chunk-DM57ZOTI.js → chunk-3CC6CMAB.js} +2 -2
- package/{chunk-LDKC5DRW.js → chunk-4U4OJ6SP.js} +21 -2
- package/{chunk-7BZFEX4Z.js → chunk-55QG265Y.js} +1 -1
- package/{chunk-JJOX4UAG.js → chunk-PIVEQ7QB.js} +5 -4
- package/{chunk-PCWFMNHW.js → chunk-PZ3M7SYD.js} +17 -4
- 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 +738 -9
- package/cloudflare.js +17 -5
- package/index.d.ts +8 -8
- package/index.js +2 -2
- package/package.json +19 -13
- package/scripts/appwarden-link.cjs +851 -0
- package/vercel.d.ts +14 -13
- 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<{
|
|
@@ -318,7 +318,6 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
318
318
|
lockPageSlug: string;
|
|
319
319
|
appwardenApiToken: string;
|
|
320
320
|
cacheUrl: string;
|
|
321
|
-
debug?: boolean | undefined;
|
|
322
321
|
contentSecurityPolicy?: {
|
|
323
322
|
mode: "disabled" | "report-only" | "enforced";
|
|
324
323
|
directives?: {
|
|
@@ -350,12 +349,12 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
350
349
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
351
350
|
} | undefined;
|
|
352
351
|
} | undefined;
|
|
352
|
+
debug?: boolean | undefined;
|
|
353
353
|
appwardenApiHostname?: string | undefined;
|
|
354
354
|
vercelApiToken?: string | undefined;
|
|
355
355
|
}, {
|
|
356
356
|
appwardenApiToken: string;
|
|
357
357
|
cacheUrl: string;
|
|
358
|
-
debug?: boolean | undefined;
|
|
359
358
|
lockPageSlug?: string | undefined;
|
|
360
359
|
contentSecurityPolicy?: {
|
|
361
360
|
mode: "disabled" | "report-only" | "enforced";
|
|
@@ -388,13 +387,13 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
388
387
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
389
388
|
};
|
|
390
389
|
} | undefined;
|
|
390
|
+
debug?: boolean | undefined;
|
|
391
391
|
appwardenApiHostname?: string | undefined;
|
|
392
392
|
vercelApiToken?: string | undefined;
|
|
393
393
|
}>, {
|
|
394
394
|
lockPageSlug: string;
|
|
395
395
|
appwardenApiToken: string;
|
|
396
396
|
cacheUrl: string;
|
|
397
|
-
debug?: boolean | undefined;
|
|
398
397
|
contentSecurityPolicy?: {
|
|
399
398
|
mode: "disabled" | "report-only" | "enforced";
|
|
400
399
|
directives?: {
|
|
@@ -426,12 +425,12 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
426
425
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
427
426
|
} | undefined;
|
|
428
427
|
} | undefined;
|
|
428
|
+
debug?: boolean | undefined;
|
|
429
429
|
appwardenApiHostname?: string | undefined;
|
|
430
430
|
vercelApiToken?: string | undefined;
|
|
431
431
|
}, {
|
|
432
432
|
appwardenApiToken: string;
|
|
433
433
|
cacheUrl: string;
|
|
434
|
-
debug?: boolean | undefined;
|
|
435
434
|
lockPageSlug?: string | undefined;
|
|
436
435
|
contentSecurityPolicy?: {
|
|
437
436
|
mode: "disabled" | "report-only" | "enforced";
|
|
@@ -464,13 +463,13 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
464
463
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
465
464
|
};
|
|
466
465
|
} | undefined;
|
|
466
|
+
debug?: boolean | undefined;
|
|
467
467
|
appwardenApiHostname?: string | undefined;
|
|
468
468
|
vercelApiToken?: string | undefined;
|
|
469
469
|
}>, {
|
|
470
470
|
lockPageSlug: string;
|
|
471
471
|
appwardenApiToken: string;
|
|
472
472
|
cacheUrl: string;
|
|
473
|
-
debug?: boolean | undefined;
|
|
474
473
|
contentSecurityPolicy?: {
|
|
475
474
|
mode: "disabled" | "report-only" | "enforced";
|
|
476
475
|
directives?: {
|
|
@@ -502,12 +501,12 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
502
501
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
503
502
|
} | undefined;
|
|
504
503
|
} | undefined;
|
|
504
|
+
debug?: boolean | undefined;
|
|
505
505
|
appwardenApiHostname?: string | undefined;
|
|
506
506
|
vercelApiToken?: string | undefined;
|
|
507
507
|
}, {
|
|
508
508
|
appwardenApiToken: string;
|
|
509
509
|
cacheUrl: string;
|
|
510
|
-
debug?: boolean | undefined;
|
|
511
510
|
lockPageSlug?: string | undefined;
|
|
512
511
|
contentSecurityPolicy?: {
|
|
513
512
|
mode: "disabled" | "report-only" | "enforced";
|
|
@@ -540,13 +539,13 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
540
539
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
541
540
|
};
|
|
542
541
|
} | undefined;
|
|
542
|
+
debug?: boolean | undefined;
|
|
543
543
|
appwardenApiHostname?: string | undefined;
|
|
544
544
|
vercelApiToken?: string | undefined;
|
|
545
545
|
}>, {
|
|
546
546
|
lockPageSlug: string;
|
|
547
547
|
appwardenApiToken: string;
|
|
548
548
|
cacheUrl: string;
|
|
549
|
-
debug?: boolean | undefined;
|
|
550
549
|
contentSecurityPolicy?: {
|
|
551
550
|
mode: "disabled" | "report-only" | "enforced";
|
|
552
551
|
directives?: {
|
|
@@ -578,12 +577,12 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
578
577
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
579
578
|
} | undefined;
|
|
580
579
|
} | undefined;
|
|
580
|
+
debug?: boolean | undefined;
|
|
581
581
|
appwardenApiHostname?: string | undefined;
|
|
582
582
|
vercelApiToken?: string | undefined;
|
|
583
583
|
}, {
|
|
584
584
|
appwardenApiToken: string;
|
|
585
585
|
cacheUrl: string;
|
|
586
|
-
debug?: boolean | undefined;
|
|
587
586
|
lockPageSlug?: string | undefined;
|
|
588
587
|
contentSecurityPolicy?: {
|
|
589
588
|
mode: "disabled" | "report-only" | "enforced";
|
|
@@ -616,13 +615,13 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
616
615
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
617
616
|
};
|
|
618
617
|
} | undefined;
|
|
618
|
+
debug?: boolean | undefined;
|
|
619
619
|
appwardenApiHostname?: string | undefined;
|
|
620
620
|
vercelApiToken?: string | undefined;
|
|
621
621
|
}>, {
|
|
622
622
|
lockPageSlug: string;
|
|
623
623
|
appwardenApiToken: string;
|
|
624
624
|
cacheUrl: string;
|
|
625
|
-
debug?: boolean | undefined;
|
|
626
625
|
contentSecurityPolicy?: {
|
|
627
626
|
mode: "disabled" | "report-only" | "enforced";
|
|
628
627
|
directives?: {
|
|
@@ -654,12 +653,12 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
654
653
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
655
654
|
} | undefined;
|
|
656
655
|
} | undefined;
|
|
656
|
+
debug?: boolean | undefined;
|
|
657
657
|
appwardenApiHostname?: string | undefined;
|
|
658
658
|
vercelApiToken?: string | undefined;
|
|
659
659
|
}, {
|
|
660
660
|
appwardenApiToken: string;
|
|
661
661
|
cacheUrl: string;
|
|
662
|
-
debug?: boolean | undefined;
|
|
663
662
|
lockPageSlug?: string | undefined;
|
|
664
663
|
contentSecurityPolicy?: {
|
|
665
664
|
mode: "disabled" | "report-only" | "enforced";
|
|
@@ -692,12 +691,14 @@ declare const AppwardenConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.Zo
|
|
|
692
691
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
693
692
|
};
|
|
694
693
|
} | undefined;
|
|
694
|
+
debug?: boolean | undefined;
|
|
695
695
|
appwardenApiHostname?: string | undefined;
|
|
696
696
|
vercelApiToken?: string | undefined;
|
|
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-2R3NOSYY.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-4U4OJ6SP.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
|
};
|