@void/edge 0.22.0 → 0.23.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/dist/index.d.mts +15 -1
- package/dist/index.mjs +42 -2
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -179,6 +179,8 @@ type StaticEdgeEnv = Readonly<{
|
|
|
179
179
|
ASSETS: EdgeAssetFetcher;
|
|
180
180
|
}>;
|
|
181
181
|
type StaticEdgeConfig = Readonly<{
|
|
182
|
+
/** Optional native Worker self-metadata used to identify the served version. */
|
|
183
|
+
versionMetadataBinding?: string;
|
|
182
184
|
assetConfig?: AssetConfig$1;
|
|
183
185
|
headerRules?: ReadonlyArray<HeaderRule$1>;
|
|
184
186
|
redirectRules?: ReadonlyArray<RedirectRule$1>;
|
|
@@ -259,4 +261,16 @@ export declare function getContentType(path: string): string;
|
|
|
259
261
|
*/
|
|
260
262
|
export declare function resolveAssetContentType(stored: string | null | undefined, path: string): string | undefined;
|
|
261
263
|
//#endregion
|
|
262
|
-
|
|
264
|
+
//#region src/limits.d.ts
|
|
265
|
+
/** Shared between the SDK, edge admission and Pages clients. */
|
|
266
|
+
type UsageLimitData = {
|
|
267
|
+
code: "usage_limit";
|
|
268
|
+
resource: "ai" | "sandbox" | "requests" | "execution";
|
|
269
|
+
reason: "monthly_quota" | "rate_limit" | "concurrency" | "runtime_budget" | "cpu";
|
|
270
|
+
message: string;
|
|
271
|
+
retryAt?: string;
|
|
272
|
+
};
|
|
273
|
+
export declare function readUsageLimit(value: unknown): UsageLimitData | null;
|
|
274
|
+
export declare function usageLimitResponse(limit: UsageLimitData): Response;
|
|
275
|
+
//#endregion
|
|
276
|
+
export type { AssetConfig, ClearSiteDataMember, CompiledPattern, EdgeAssetFetcher, HeaderRule, HeaderRulePolicy, ProjectZeroTrustRouting, RedirectRule, ResolvedAsset, RoutingRuleResult, StaticEdgeConfig, StaticEdgeEnv, StaticEdgeHandler, UsageLimitData };
|
package/dist/index.mjs
CHANGED
|
@@ -410,7 +410,14 @@ function mergeQueryIntoLocation(destination, requestSearch) {
|
|
|
410
410
|
function createStaticEdgeHandler(config) {
|
|
411
411
|
return { async fetch(request, env) {
|
|
412
412
|
const originalUrl = new URL(request.url);
|
|
413
|
-
if (request.method === "GET" && originalUrl.pathname === "/__void/ready")
|
|
413
|
+
if (request.method === "GET" && originalUrl.pathname === "/__void/ready") {
|
|
414
|
+
if (!config.versionMetadataBinding) return Response.json({ ready: true });
|
|
415
|
+
const metadata = config.versionMetadataBinding ? env[config.versionMetadataBinding] : void 0;
|
|
416
|
+
return Response.json({
|
|
417
|
+
ready: true,
|
|
418
|
+
...config.versionMetadataBinding ? { versionId: metadata?.id } : {}
|
|
419
|
+
}, { headers: { "cache-control": "no-store" } });
|
|
420
|
+
}
|
|
414
421
|
let effectiveUrl = new URL(originalUrl);
|
|
415
422
|
let effectiveRequest = request;
|
|
416
423
|
const route = applyRoutingRules(effectiveUrl.pathname, config.redirectRules, effectiveUrl.hostname);
|
|
@@ -678,4 +685,37 @@ function resolveAssetContentType(stored, path) {
|
|
|
678
685
|
return stored;
|
|
679
686
|
}
|
|
680
687
|
//#endregion
|
|
681
|
-
|
|
688
|
+
//#region src/limits.ts
|
|
689
|
+
function readUsageLimit(value) {
|
|
690
|
+
if (!value || typeof value !== "object") return null;
|
|
691
|
+
const v = value;
|
|
692
|
+
if (v.code !== "usage_limit" || typeof v.message !== "string" || ![
|
|
693
|
+
"ai",
|
|
694
|
+
"sandbox",
|
|
695
|
+
"requests",
|
|
696
|
+
"execution"
|
|
697
|
+
].includes(String(v.resource)) || ![
|
|
698
|
+
"monthly_quota",
|
|
699
|
+
"rate_limit",
|
|
700
|
+
"concurrency",
|
|
701
|
+
"runtime_budget",
|
|
702
|
+
"cpu"
|
|
703
|
+
].includes(String(v.reason))) return null;
|
|
704
|
+
return {
|
|
705
|
+
code: "usage_limit",
|
|
706
|
+
resource: v.resource,
|
|
707
|
+
reason: v.reason,
|
|
708
|
+
message: v.message,
|
|
709
|
+
...typeof v.retryAt === "string" && Number.isFinite(Date.parse(v.retryAt)) ? { retryAt: v.retryAt } : {}
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
function usageLimitResponse(limit) {
|
|
713
|
+
const headers = new Headers({ "Cache-Control": "no-store" });
|
|
714
|
+
if (limit.retryAt && Number.isFinite(Date.parse(limit.retryAt))) headers.set("Retry-After", String(Math.max(0, Math.ceil((Date.parse(limit.retryAt) - Date.now()) / 1e3))));
|
|
715
|
+
return Response.json(limit, {
|
|
716
|
+
status: 429,
|
|
717
|
+
headers
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
//#endregion
|
|
721
|
+
export { applyHeaderRules, applyRoutingRules, compilePattern, createStaticEdgeHandler, getContentType, matchLiteralPattern, matchPattern, matchPatternCaptures, matchSegmentPattern, mergeQueryIntoLocation, parseClearSiteData, readUsageLimit, resolveAssetContentType, resolveStaticPath, safeDecodePathname, sanitizeClearSiteData, substituteParams, usageLimitResponse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/edge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/voidzero-dev/void.git",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@void/deploy-core": "0.
|
|
23
|
+
"@void/deploy-core": "0.23.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@cloudflare/workers-types": "^4.20260702.1",
|