@adonix.org/cloud-spark 0.0.74 → 0.0.76
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.ts +17 -6
- package/dist/index.js +37 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare abstract class BaseWorker implements Worker {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
declare abstract class CacheWorker extends BaseWorker {
|
|
21
|
-
protected getCacheKey():
|
|
21
|
+
protected getCacheKey(...values: Array<string | null | undefined>): URL | RequestInfo;
|
|
22
22
|
protected getCachedResponse(): Promise<Response | undefined>;
|
|
23
23
|
protected setCachedResponse(response: Response): void;
|
|
24
24
|
}
|
|
@@ -35,6 +35,11 @@ declare const CacheControl: {
|
|
|
35
35
|
declare namespace HttpHeader {
|
|
36
36
|
const VARY = "Vary";
|
|
37
37
|
const X_CONTENT_TYPE_OPTIONS = "X-Content-Type-Options";
|
|
38
|
+
const X_FRAME_OPTIONS = "X-Frame-Options";
|
|
39
|
+
const STRICT_TRANSPORT_SECURITY = "Strict-Transport-Security";
|
|
40
|
+
const CONTENT_SECURITY_POLICY = "Content-Security-Policy";
|
|
41
|
+
const REFERRER_POLICY = "Referrer-Policy";
|
|
42
|
+
const PERMISSIONS_POLICY = "Permissions-Policy";
|
|
38
43
|
const NOSNIFF = "nosniff";
|
|
39
44
|
const ORIGIN = "Origin";
|
|
40
45
|
}
|
|
@@ -114,11 +119,12 @@ declare function mergeHeader(headers: Headers, key: string, value: string | stri
|
|
|
114
119
|
* @param url The original URL string to normalize.
|
|
115
120
|
* @returns A normalized URL string suitable for hashing or direct cache key use.
|
|
116
121
|
*/
|
|
117
|
-
declare function normalizeUrl(url: string):
|
|
122
|
+
declare function normalizeUrl(url: string): URL;
|
|
118
123
|
|
|
119
124
|
interface CorsProvider {
|
|
120
125
|
getOrigin(): string | null;
|
|
121
126
|
getAllowOrigins(): string[];
|
|
127
|
+
allowAnyOrigin(): boolean;
|
|
122
128
|
getAllowMethods(): Method[];
|
|
123
129
|
getAllowHeaders(): string[];
|
|
124
130
|
getExposeHeaders(): string[];
|
|
@@ -145,22 +151,25 @@ declare abstract class BaseResponse {
|
|
|
145
151
|
status: StatusCodes;
|
|
146
152
|
statusText?: string;
|
|
147
153
|
mimeType?: MimeType;
|
|
148
|
-
cache?: CacheControl;
|
|
149
154
|
constructor(content?: BodyInit | null);
|
|
150
155
|
protected get responseInit(): ResponseInit;
|
|
151
156
|
setHeader(key: string, value: string | string[]): void;
|
|
152
157
|
mergeHeader(key: string, value: string | string[]): void;
|
|
153
158
|
addContentType(): void;
|
|
154
|
-
addCacheControl(): void;
|
|
155
159
|
}
|
|
156
160
|
declare abstract class CorsResponse extends BaseResponse {
|
|
157
161
|
readonly cors: CorsProvider;
|
|
158
162
|
constructor(cors: CorsProvider, content?: BodyInit | null);
|
|
159
163
|
protected addCorsHeaders(): void;
|
|
160
164
|
}
|
|
161
|
-
declare abstract class
|
|
165
|
+
declare abstract class CacheResponse extends CorsResponse {
|
|
166
|
+
cache?: CacheControl;
|
|
162
167
|
constructor(cors: CorsProvider, body?: BodyInit | null, cache?: CacheControl);
|
|
168
|
+
protected addCacheHeader(): void;
|
|
169
|
+
}
|
|
170
|
+
declare abstract class WorkerResponse extends CacheResponse {
|
|
163
171
|
createResponse(): Response;
|
|
172
|
+
protected addSecurityHeaders(): void;
|
|
164
173
|
}
|
|
165
174
|
declare class ClonedResponse extends WorkerResponse {
|
|
166
175
|
constructor(cors: CorsProvider, response: Response, cache?: CacheControl);
|
|
@@ -178,7 +187,7 @@ declare class TextResponse extends SuccessResponse {
|
|
|
178
187
|
constructor(cors: CorsProvider, content: string, cache?: CacheControl, status?: StatusCodes);
|
|
179
188
|
}
|
|
180
189
|
/**
|
|
181
|
-
*
|
|
190
|
+
* Removes the body from a GET response.
|
|
182
191
|
*/
|
|
183
192
|
declare class Head extends WorkerResponse {
|
|
184
193
|
constructor(cors: CorsProvider, get: Response);
|
|
@@ -230,9 +239,11 @@ declare abstract class BasicWorker extends CacheWorker implements CorsProvider {
|
|
|
230
239
|
protected delete(): Promise<Response>;
|
|
231
240
|
protected options(): Promise<Response>;
|
|
232
241
|
protected head(): Promise<Response>;
|
|
242
|
+
protected getCacheKey(): URL | RequestInfo;
|
|
233
243
|
protected getResponse<T extends WorkerResponse>(ResponseClass: new (cors: CorsProvider, ...args: any[]) => T, ...args: any[]): Promise<Response>;
|
|
234
244
|
isAllowed(method: string): boolean;
|
|
235
245
|
getAllowOrigins(): string[];
|
|
246
|
+
allowAnyOrigin(): boolean;
|
|
236
247
|
getAllowMethods(): Method[];
|
|
237
248
|
getAllowHeaders(): string[];
|
|
238
249
|
getExposeHeaders(): string[];
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,11 @@ var HttpHeader;
|
|
|
11
11
|
((HttpHeader2) => {
|
|
12
12
|
HttpHeader2.VARY = "Vary";
|
|
13
13
|
HttpHeader2.X_CONTENT_TYPE_OPTIONS = "X-Content-Type-Options";
|
|
14
|
+
HttpHeader2.X_FRAME_OPTIONS = "X-Frame-Options";
|
|
15
|
+
HttpHeader2.STRICT_TRANSPORT_SECURITY = "Strict-Transport-Security";
|
|
16
|
+
HttpHeader2.CONTENT_SECURITY_POLICY = "Content-Security-Policy";
|
|
17
|
+
HttpHeader2.REFERRER_POLICY = "Referrer-Policy";
|
|
18
|
+
HttpHeader2.PERMISSIONS_POLICY = "Permissions-Policy";
|
|
14
19
|
HttpHeader2.NOSNIFF = "nosniff";
|
|
15
20
|
HttpHeader2.ORIGIN = "Origin";
|
|
16
21
|
})(HttpHeader || (HttpHeader = {}));
|
|
@@ -129,7 +134,7 @@ function normalizeUrl(url) {
|
|
|
129
134
|
params.sort(([a], [b]) => a.localeCompare(b));
|
|
130
135
|
u.search = params.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&");
|
|
131
136
|
u.hash = "";
|
|
132
|
-
return u
|
|
137
|
+
return u;
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
// src/base-worker.ts
|
|
@@ -151,9 +156,16 @@ var BaseWorker = class {
|
|
|
151
156
|
};
|
|
152
157
|
|
|
153
158
|
// src/cache-worker.ts
|
|
159
|
+
import { createHash } from "crypto";
|
|
154
160
|
var CacheWorker = class extends BaseWorker {
|
|
155
|
-
getCacheKey() {
|
|
156
|
-
|
|
161
|
+
getCacheKey(...values) {
|
|
162
|
+
const raw = [
|
|
163
|
+
normalizeUrl(this.request.url),
|
|
164
|
+
...values.filter((v) => v != null).map((v) => v.trim()).filter((v) => v.length > 0)
|
|
165
|
+
// skip empty strings after trim
|
|
166
|
+
].join("");
|
|
167
|
+
const hash = createHash("sha256").update(raw).digest("base64url");
|
|
168
|
+
return new URL(`http://cache/${hash}`);
|
|
157
169
|
}
|
|
158
170
|
async getCachedResponse() {
|
|
159
171
|
if (this.request.method !== "GET" /* GET */) return;
|
|
@@ -192,7 +204,6 @@ var BaseResponse = class {
|
|
|
192
204
|
status = StatusCodes.OK;
|
|
193
205
|
statusText;
|
|
194
206
|
mimeType;
|
|
195
|
-
cache;
|
|
196
207
|
constructor(content = null) {
|
|
197
208
|
this.body = this.status === StatusCodes.NO_CONTENT ? null : content;
|
|
198
209
|
}
|
|
@@ -214,11 +225,6 @@ var BaseResponse = class {
|
|
|
214
225
|
this.headers.set("Content-Type", getContentType(this.mimeType));
|
|
215
226
|
}
|
|
216
227
|
}
|
|
217
|
-
addCacheControl() {
|
|
218
|
-
if (this.cache) {
|
|
219
|
-
this.headers.set("Cache-Control", CacheControl.stringify(this.cache));
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
228
|
};
|
|
223
229
|
var CorsResponse = class extends BaseResponse {
|
|
224
230
|
constructor(cors, content = null) {
|
|
@@ -230,10 +236,9 @@ var CorsResponse = class extends BaseResponse {
|
|
|
230
236
|
if (!origin) return;
|
|
231
237
|
this.headers.delete(Cors.ALLOW_ORIGIN);
|
|
232
238
|
this.headers.delete(Cors.ALLOW_CREDENTIALS);
|
|
233
|
-
|
|
234
|
-
if (allowed.includes(Cors.ALLOW_ALL_ORIGINS)) {
|
|
239
|
+
if (this.cors.allowAnyOrigin()) {
|
|
235
240
|
this.setHeader(Cors.ALLOW_ORIGIN, Cors.ALLOW_ALL_ORIGINS);
|
|
236
|
-
} else if (
|
|
241
|
+
} else if (this.cors.getAllowOrigins().includes(origin)) {
|
|
237
242
|
this.setHeader(Cors.ALLOW_ORIGIN, origin);
|
|
238
243
|
this.setHeader(Cors.ALLOW_CREDENTIALS, String(true));
|
|
239
244
|
this.mergeHeader(HttpHeader.VARY, HttpHeader.ORIGIN);
|
|
@@ -244,19 +249,30 @@ var CorsResponse = class extends BaseResponse {
|
|
|
244
249
|
this.setHeader(Cors.MAX_AGE, String(this.cors.getMaxAge()));
|
|
245
250
|
}
|
|
246
251
|
};
|
|
247
|
-
var
|
|
252
|
+
var CacheResponse = class extends CorsResponse {
|
|
253
|
+
cache;
|
|
248
254
|
constructor(cors, body = null, cache) {
|
|
249
255
|
super(cors, body);
|
|
250
256
|
this.cache = cache;
|
|
251
257
|
}
|
|
258
|
+
addCacheHeader() {
|
|
259
|
+
if (this.cache) {
|
|
260
|
+
this.headers.set("Cache-Control", CacheControl.stringify(this.cache));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
var WorkerResponse = class extends CacheResponse {
|
|
252
265
|
createResponse() {
|
|
253
266
|
this.addCorsHeaders();
|
|
254
|
-
this.
|
|
255
|
-
this.
|
|
267
|
+
this.addCacheHeader();
|
|
268
|
+
this.addSecurityHeaders();
|
|
256
269
|
const body = this.status === StatusCodes.NO_CONTENT ? null : this.body;
|
|
257
270
|
if (body) this.addContentType();
|
|
258
271
|
return new Response(body, this.responseInit);
|
|
259
272
|
}
|
|
273
|
+
addSecurityHeaders() {
|
|
274
|
+
this.setHeader(HttpHeader.X_CONTENT_TYPE_OPTIONS, HttpHeader.NOSNIFF);
|
|
275
|
+
}
|
|
260
276
|
};
|
|
261
277
|
var ClonedResponse = class extends WorkerResponse {
|
|
262
278
|
constructor(cors, response, cache) {
|
|
@@ -423,6 +439,9 @@ var BasicWorker = class extends CacheWorker {
|
|
|
423
439
|
await this.dispatch(new Request(this.request, { method: "GET" /* GET */ }))
|
|
424
440
|
);
|
|
425
441
|
}
|
|
442
|
+
getCacheKey() {
|
|
443
|
+
return super.getCacheKey(this.getOrigin());
|
|
444
|
+
}
|
|
426
445
|
async getResponse(ResponseClass, ...args) {
|
|
427
446
|
const response = new ResponseClass(this, ...args).createResponse();
|
|
428
447
|
this.setCachedResponse(response);
|
|
@@ -434,6 +453,9 @@ var BasicWorker = class extends CacheWorker {
|
|
|
434
453
|
getAllowOrigins() {
|
|
435
454
|
return ["*"];
|
|
436
455
|
}
|
|
456
|
+
allowAnyOrigin() {
|
|
457
|
+
return this.getAllowOrigins().includes("*");
|
|
458
|
+
}
|
|
437
459
|
getAllowMethods() {
|
|
438
460
|
return ["GET" /* GET */, "OPTIONS" /* OPTIONS */, "HEAD" /* HEAD */];
|
|
439
461
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/common.ts","../src/base-worker.ts","../src/cache-worker.ts","../src/response.ts","../src/cors.ts","../src/basic-worker.ts","../src/routes.ts","../src/routed-worker.ts"],"sourcesContent":["/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { StatusCodes } from \"http-status-codes\";\n\nexport * from \"./basic-worker\";\nexport * from \"./common\";\nexport * from \"./cors\";\nexport * from \"./response\";\nexport * from \"./routed-worker\";\nexport * from \"./routes\";\nexport * from \"./worker\";\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * https://github.com/etienne-martin/cache-control-parser\n */\nimport CacheLib from \"cache-control-parser\";\n\nexport type CacheControl = CacheLib.CacheControl;\nexport const CacheControl = {\n parse: CacheLib.parse,\n stringify: CacheLib.stringify,\n};\n\nexport namespace HttpHeader {\n export const VARY = \"Vary\";\n export const X_CONTENT_TYPE_OPTIONS = \"X-Content-Type-Options\";\n export const NOSNIFF = \"nosniff\";\n export const ORIGIN = \"Origin\";\n}\n\nexport const Time = {\n Second: 1,\n Minute: 60,\n Hour: 60 * 60,\n Day: 60 * 60 * 24,\n Week: 60 * 60 * 24 * 7,\n Year: 60 * 60 * 24 * 365,\n} as const;\n\nexport enum Method {\n GET = \"GET\",\n PUT = \"PUT\",\n POST = \"POST\",\n PATCH = \"PATCH\",\n DELETE = \"DELETE\",\n HEAD = \"HEAD\",\n OPTIONS = \"OPTIONS\",\n}\nconst METHOD_SET: Set<string> = new Set(Object.values(Method));\n\nexport function isMethod(value: string): value is Method {\n return METHOD_SET.has(value);\n}\n\nexport function getContentType(type: MimeType): string {\n if (ADD_CHARSET.has(type)) {\n return `${type}; charset=utf-8`;\n }\n return type;\n}\n\nexport enum MimeType {\n PLAIN_TEXT = \"text/plain\",\n HTML = \"text/html\",\n CSS = \"text/css\",\n CSV = \"text/csv\",\n XML = \"text/xml\",\n MARKDOWN = \"text/markdown\",\n RICH_TEXT = \"text/richtext\",\n JSON = \"application/json\",\n XML_APP = \"application/xml\",\n YAML = \"application/x-yaml\",\n FORM_URLENCODED = \"application/x-www-form-urlencoded\",\n NDJSON = \"application/x-ndjson\",\n MSGPACK = \"application/x-msgpack\",\n PROTOBUF = \"application/x-protobuf\",\n MULTIPART_FORM_DATA = \"multipart/form-data\",\n MULTIPART_MIXED = \"multipart/mixed\",\n MULTIPART_ALTERNATIVE = \"multipart/alternative\",\n MULTIPART_DIGEST = \"multipart/digest\",\n MULTIPART_RELATED = \"multipart/related\",\n MULTIPART_SIGNED = \"multipart/signed\",\n MULTIPART_ENCRYPTED = \"multipart/encrypted\",\n OCTET_STREAM = \"application/octet-stream\",\n PDF = \"application/pdf\",\n ZIP = \"application/zip\",\n GZIP = \"application/gzip\",\n MSWORD = \"application/msword\",\n DOCX = \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n EXCEL = \"application/vnd.ms-excel\",\n XLSX = \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n POWERPOINT = \"application/vnd.ms-powerpoint\",\n PPTX = \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n ICO = \"image/x-icon\",\n ICO_MS = \"image/vnd.microsoft.icon\",\n GIF = \"image/gif\",\n PNG = \"image/png\",\n JPEG = \"image/jpeg\",\n WEBP = \"image/webp\",\n SVG = \"image/svg+xml\",\n HEIF = \"image/heif\",\n AVIF = \"image/avif\",\n EVENT_STREAM = \"text/event-stream\",\n TAR = \"application/x-tar\",\n BZIP2 = \"application/x-bzip2\",\n}\n\nconst ADD_CHARSET: Set<MimeType> = new Set([\n MimeType.PLAIN_TEXT,\n MimeType.HTML,\n MimeType.CSS,\n MimeType.CSV,\n MimeType.MARKDOWN,\n MimeType.XML,\n MimeType.JSON,\n MimeType.XML_APP,\n MimeType.FORM_URLENCODED,\n MimeType.NDJSON,\n MimeType.RICH_TEXT,\n MimeType.SVG,\n]);\n\nexport function setHeader(headers: Headers, key: string, value: string | string[]): void {\n const raw = Array.isArray(value) ? value : [value];\n const values = Array.from(new Set(raw.map((v) => v.trim()))).filter((v) => v.length);\n\n if (!values.length) {\n headers.delete(key);\n return;\n }\n\n headers.set(key, values.join(\", \"));\n}\n\nexport function mergeHeader(headers: Headers, key: string, value: string | string[]): void {\n const values = Array.isArray(value) ? value : [value];\n if (!values.length) return;\n\n const existing = headers.get(key);\n if (existing) {\n const merged = existing.split(\",\").map((v) => v.trim());\n values.forEach((v) => merged.push(v.trim()));\n setHeader(headers, key, merged);\n } else {\n setHeader(headers, key, values);\n }\n}\n\n/**\n * Normalizes a URL string for use as a consistent cache key.\n *\n * - Sorts query parameters alphabetically so `?b=2&a=1` and `?a=1&b=2` are treated the same.\n * - Strips fragment identifiers (`#...`) since they are not sent in HTTP requests.\n * - Leaves protocol, host, path, and query values intact.\n *\n * @param url The original URL string to normalize.\n * @returns A normalized URL string suitable for hashing or direct cache key use.\n */\nexport function normalizeUrl(url: string): string {\n const u = new URL(url);\n\n const params = [...u.searchParams.entries()];\n params.sort(([a], [b]) => a.localeCompare(b));\n\n u.search = params\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join(\"&\");\n u.hash = \"\";\n\n return u.toString();\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Worker } from \"./worker\";\n\nexport abstract class BaseWorker implements Worker {\n constructor(\n private readonly _request: Request,\n private readonly _env: Env = {},\n private readonly _ctx?: ExecutionContext\n ) {}\n\n protected get request(): Request {\n return this._request;\n }\n\n protected get env(): Env {\n return this._env;\n }\n\n protected get ctx(): ExecutionContext | undefined {\n return this._ctx;\n }\n\n public abstract fetch(): Promise<Response>;\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * https://github.com/etienne-martin/cache-control-parser\n */\nimport { Method, normalizeUrl } from \"./common\";\nimport { BaseWorker } from \"./base-worker\";\n\nexport abstract class CacheWorker extends BaseWorker {\n protected getCacheKey(): string {\n return normalizeUrl(this.request.url);\n }\n\n protected async getCachedResponse(): Promise<Response | undefined> {\n if (this.request.method !== Method.GET) return;\n\n return await caches.default.match(this.getCacheKey());\n }\n\n protected setCachedResponse(response: Response): void {\n if (!response.ok) return;\n if (this.request.method !== Method.GET) return;\n\n try {\n this.ctx?.waitUntil(caches.default.put(this.getCacheKey(), response.clone()));\n } catch (e) {\n console.warn(\"Failed to cache response:\", e);\n }\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getReasonPhrase, StatusCodes } from \"http-status-codes\";\nimport {\n CacheControl,\n getContentType,\n HttpHeader,\n mergeHeader,\n Method,\n MimeType,\n setHeader,\n} from \"./common\";\nimport { Cors, CorsProvider } from \"./cors\";\n\nexport interface ErrorJson {\n status: number;\n error: string;\n details: string;\n}\n\nabstract class BaseResponse {\n public headers: Headers = new Headers();\n public body: BodyInit | null;\n public status: StatusCodes = StatusCodes.OK;\n public statusText?: string;\n public mimeType?: MimeType;\n public cache?: CacheControl;\n\n constructor(content: BodyInit | null = null) {\n this.body = this.status === StatusCodes.NO_CONTENT ? null : content;\n }\n\n protected get responseInit(): ResponseInit {\n return {\n headers: this.headers,\n status: this.status,\n statusText: this.statusText ?? getReasonPhrase(this.status),\n };\n }\n\n public setHeader(key: string, value: string | string[]): void {\n setHeader(this.headers, key, value);\n }\n\n public mergeHeader(key: string, value: string | string[]): void {\n mergeHeader(this.headers, key, value);\n }\n\n public addContentType() {\n if (this.mimeType) {\n this.headers.set(\"Content-Type\", getContentType(this.mimeType));\n }\n }\n\n public addCacheControl() {\n if (this.cache) {\n this.headers.set(\"Cache-Control\", CacheControl.stringify(this.cache));\n }\n }\n}\n\nabstract class CorsResponse extends BaseResponse {\n constructor(public readonly cors: CorsProvider, content: BodyInit | null = null) {\n super(content);\n }\n\n protected addCorsHeaders(): void {\n const origin = this.cors.getOrigin();\n if (!origin) return; // no Origin, skip CORS\n\n this.headers.delete(Cors.ALLOW_ORIGIN);\n this.headers.delete(Cors.ALLOW_CREDENTIALS);\n\n const allowed = this.cors.getAllowOrigins();\n if (allowed.includes(Cors.ALLOW_ALL_ORIGINS)) {\n this.setHeader(Cors.ALLOW_ORIGIN, Cors.ALLOW_ALL_ORIGINS);\n } else if (allowed.includes(origin)) {\n this.setHeader(Cors.ALLOW_ORIGIN, origin);\n this.setHeader(Cors.ALLOW_CREDENTIALS, String(true));\n this.mergeHeader(HttpHeader.VARY, HttpHeader.ORIGIN);\n }\n\n this.mergeHeader(Cors.EXPOSE_HEADERS, this.cors.getExposeHeaders());\n this.setHeader(Cors.ALLOW_HEADERS, this.cors.getAllowHeaders());\n this.setHeader(Cors.ALLOW_METHODS, this.cors.getAllowMethods());\n this.setHeader(Cors.MAX_AGE, String(this.cors.getMaxAge()));\n }\n}\n\nexport abstract class WorkerResponse extends CorsResponse {\n constructor(cors: CorsProvider, body: BodyInit | null = null, cache?: CacheControl) {\n super(cors, body);\n this.cache = cache;\n }\n\n public createResponse(): Response {\n this.addCorsHeaders();\n this.addCacheControl();\n\n this.setHeader(HttpHeader.X_CONTENT_TYPE_OPTIONS, HttpHeader.NOSNIFF);\n\n const body = this.status === StatusCodes.NO_CONTENT ? null : this.body;\n if (body) this.addContentType();\n return new Response(body, this.responseInit);\n }\n}\n\nexport class ClonedResponse extends WorkerResponse {\n constructor(cors: CorsProvider, response: Response, cache?: CacheControl) {\n const clone = response.clone();\n super(cors, clone.body, cache);\n this.headers = new Headers(clone.headers);\n this.status = clone.status;\n this.statusText = clone.statusText;\n }\n}\n\nexport class SuccessResponse extends WorkerResponse {\n constructor(\n cors: CorsProvider,\n body: BodyInit | null = null,\n cache?: CacheControl,\n status: StatusCodes = StatusCodes.OK\n ) {\n super(cors, body, cache);\n this.status = status;\n }\n}\n\nexport class JsonResponse extends SuccessResponse {\n constructor(\n cors: CorsProvider,\n json: unknown = {},\n cache?: CacheControl,\n status: StatusCodes = StatusCodes.OK\n ) {\n super(cors, JSON.stringify(json), cache, status);\n this.mimeType = MimeType.JSON;\n }\n}\n\nexport class HtmlResponse extends SuccessResponse {\n constructor(\n cors: CorsProvider,\n body: string,\n cache?: CacheControl,\n status: StatusCodes = StatusCodes.OK\n ) {\n super(cors, body, cache, status);\n this.mimeType = MimeType.HTML;\n }\n}\n\nexport class TextResponse extends SuccessResponse {\n constructor(\n cors: CorsProvider,\n content: string,\n cache?: CacheControl,\n status: StatusCodes = StatusCodes.OK\n ) {\n super(cors, content, cache, status);\n this.mimeType = MimeType.PLAIN_TEXT;\n }\n}\n\n/**\n * Remove the body from a GET response.\n */\nexport class Head extends WorkerResponse {\n constructor(cors: CorsProvider, get: Response) {\n super(cors);\n this.headers = new Headers(get.headers);\n }\n}\n\nexport class Options extends SuccessResponse {\n constructor(cors: CorsProvider) {\n super(cors, null, undefined, StatusCodes.NO_CONTENT);\n this.setHeader(\"Allow\", this.cors.getAllowMethods());\n }\n}\n\nexport class HttpError extends JsonResponse {\n constructor(cors: CorsProvider, status: StatusCodes, protected readonly details?: string) {\n const cache: CacheControl = {\n \"no-cache\": true,\n \"no-store\": true,\n \"must-revalidate\": true,\n \"max-age\": 0,\n };\n super(cors, undefined, cache, status);\n }\n\n public get json(): ErrorJson {\n return {\n status: this.status,\n error: getReasonPhrase(this.status),\n details: this.details ?? getReasonPhrase(this.status),\n };\n }\n\n public override createResponse(): Response {\n this.body = JSON.stringify(this.json);\n return super.createResponse();\n }\n}\n\nexport class BadRequest extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.BAD_REQUEST, details);\n }\n}\n\nexport class Unauthorized extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.UNAUTHORIZED, details);\n }\n}\n\nexport class Forbidden extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.FORBIDDEN, details);\n }\n}\n\nexport class NotFound extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.NOT_FOUND, details);\n }\n}\n\nexport class MethodNotAllowed extends HttpError {\n constructor(cors: CorsProvider, method: string) {\n super(cors, StatusCodes.METHOD_NOT_ALLOWED, `${method} method not allowed.`);\n this.setHeader(\"Allow\", this.cors.getAllowMethods());\n }\n\n public override get json(): ErrorJson & { allowed: Method[] } {\n return {\n ...super.json,\n allowed: this.cors.getAllowMethods(),\n };\n }\n}\n\nexport class InternalServerError extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.INTERNAL_SERVER_ERROR, details);\n }\n}\n\nexport class NotImplemented extends HttpError {\n constructor(cors: CorsProvider) {\n super(cors, StatusCodes.NOT_IMPLEMENTED);\n }\n}\n\nexport class ServiceUnavailable extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.SERVICE_UNAVAILABLE, details);\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Method } from \"./common\";\n\nexport interface CorsProvider {\n getOrigin(): string | null;\n getAllowOrigins(): string[];\n getAllowMethods(): Method[];\n getAllowHeaders(): string[];\n getExposeHeaders(): string[];\n getMaxAge(): number;\n}\n\nexport namespace Cors {\n export const ALLOW_ORIGIN = \"Access-Control-Allow-Origin\";\n export const ALLOW_CREDENTIALS = \"Access-Control-Allow-Credentials\";\n export const EXPOSE_HEADERS = \"Access-Control-Expose-Headers\";\n export const ALLOW_HEADERS = \"Access-Control-Allow-Headers\";\n export const ALLOW_METHODS = \"Access-Control-Allow-Methods\";\n export const MAX_AGE = \"Access-Control-Max-Age\";\n export const ALLOW_ALL_ORIGINS = \"*\";\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CacheWorker } from \"./cache-worker\";\nimport { isMethod, Method, Time } from \"./common\";\nimport { CorsProvider } from \"./cors\";\nimport {\n Head,\n InternalServerError,\n MethodNotAllowed,\n NotImplemented,\n Options,\n WorkerResponse,\n} from \"./response\";\n\nexport abstract class BasicWorker extends CacheWorker implements CorsProvider {\n public async fetch(): Promise<Response> {\n if (!this.isAllowed(this.request.method)) {\n return this.getResponse(MethodNotAllowed, this.request.method);\n }\n\n try {\n return await this.dispatch();\n } catch (error) {\n return this.getResponse(InternalServerError, String(error));\n }\n }\n\n protected async dispatch(request: Request = this.request): Promise<Response> {\n const method = request.method as Method;\n const handler: Record<Method, () => Promise<Response>> = {\n GET: () => this.get(),\n PUT: () => this.put(),\n POST: () => this.post(),\n PATCH: () => this.patch(),\n DELETE: () => this.delete(),\n HEAD: () => this.head(),\n OPTIONS: () => this.options(),\n };\n return (handler[method] ?? (() => this.getResponse(MethodNotAllowed, method)))();\n }\n\n protected async get(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async put(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async post(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async patch(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async delete(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async options(): Promise<Response> {\n return this.getResponse(Options);\n }\n\n protected async head(): Promise<Response> {\n // Dispatch a new GET request created from the HEAD request\n // and return the GET response with the body removed.\n return this.getResponse(\n Head,\n await this.dispatch(new Request(this.request, { method: Method.GET }))\n );\n }\n\n protected async getResponse<T extends WorkerResponse>(\n ResponseClass: new (cors: CorsProvider, ...args: any[]) => T,\n ...args: any[]\n ): Promise<Response> {\n const response = new ResponseClass(this, ...args).createResponse();\n this.setCachedResponse(response);\n return response;\n }\n\n public isAllowed(method: string): boolean {\n return isMethod(method) && this.getAllowMethods().includes(method);\n }\n\n public getAllowOrigins(): string[] {\n return [\"*\"];\n }\n\n public getAllowMethods(): Method[] {\n return [Method.GET, Method.OPTIONS, Method.HEAD];\n }\n\n public getAllowHeaders(): string[] {\n return [\"Content-Type\"];\n }\n\n public getExposeHeaders(): string[] {\n return [];\n }\n\n public getMaxAge(): number {\n return Time.Week;\n }\n\n public getOrigin(): string | null {\n return this.request.headers.get(\"Origin\");\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Method } from \"./common\";\n\nexport type RouteCallback = (...matches: string[]) => Response | Promise<Response>;\n\nexport type RouteInit = [Method, string, RouteCallback];\n\nexport class Route {\n public readonly pattern: RegExp;\n\n constructor(pattern: RegExp | string, public readonly callback: RouteCallback) {\n this.pattern = new RegExp(pattern);\n }\n}\n\nexport class Routes {\n private readonly map = new Map<Method, Route[]>();\n\n public add(method: Method, route: Route) {\n const existing = this.map.get(method);\n if (existing) {\n existing.push(route);\n } else {\n this.map.set(method, [route]);\n }\n return this;\n }\n\n public get(method: Method, url: string): Route | undefined {\n const routes = this.map.get(method);\n if (!routes) return undefined;\n\n const pathname = new URL(url).pathname;\n return routes.find(({ pattern }) => pattern.test(pathname));\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BasicWorker } from \"./basic-worker\";\nimport { Method } from \"./common\";\nimport { NotFound } from \"./response\";\nimport { Route, Routes, RouteInit, RouteCallback } from \"./routes\";\n\nexport abstract class RoutedWorker extends BasicWorker {\n private readonly routes: Routes = new Routes();\n\n protected initialize(routes: RouteInit[]) {\n routes.forEach(([method, pattern, callback]) => {\n this.add(method, pattern, callback);\n });\n }\n\n protected add(method: Method, pattern: RegExp | string, callback: RouteCallback) {\n this.routes.add(method, new Route(pattern, callback));\n return this;\n }\n\n protected async dispatch(request: Request = this.request): Promise<Response> {\n const route = this.routes.get(request.method as Method, request.url);\n if (!route) return super.dispatch(request);\n\n const match = new URL(request.url).pathname.match(route.pattern) ?? [];\n return route.callback.call(this, ...match);\n }\n\n protected override async get(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override async put(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override async post(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override async patch(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override async delete(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n}\n"],"mappings":";AAgBA,SAAS,eAAAA,oBAAmB;;;ACG5B,OAAO,cAAc;AAGd,IAAM,eAAe;AAAA,EACxB,OAAO,SAAS;AAAA,EAChB,WAAW,SAAS;AACxB;AAEO,IAAU;AAAA,CAAV,CAAUC,gBAAV;AACI,EAAMA,YAAA,OAAO;AACb,EAAMA,YAAA,yBAAyB;AAC/B,EAAMA,YAAA,UAAU;AAChB,EAAMA,YAAA,SAAS;AAAA,GAJT;AAOV,IAAM,OAAO;AAAA,EAChB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM,KAAK;AAAA,EACX,KAAK,KAAK,KAAK;AAAA,EACf,MAAM,KAAK,KAAK,KAAK;AAAA,EACrB,MAAM,KAAK,KAAK,KAAK;AACzB;AAEO,IAAK,SAAL,kBAAKC,YAAL;AACH,EAAAA,QAAA,SAAM;AACN,EAAAA,QAAA,SAAM;AACN,EAAAA,QAAA,UAAO;AACP,EAAAA,QAAA,WAAQ;AACR,EAAAA,QAAA,YAAS;AACT,EAAAA,QAAA,UAAO;AACP,EAAAA,QAAA,aAAU;AAPF,SAAAA;AAAA,GAAA;AASZ,IAAM,aAA0B,IAAI,IAAI,OAAO,OAAO,MAAM,CAAC;AAEtD,SAAS,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","../src/base-worker.ts","../src/cache-worker.ts","../src/response.ts","../src/cors.ts","../src/basic-worker.ts","../src/routes.ts","../src/routed-worker.ts"],"sourcesContent":["/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { StatusCodes } from \"http-status-codes\";\n\nexport * from \"./basic-worker\";\nexport * from \"./common\";\nexport * from \"./cors\";\nexport * from \"./response\";\nexport * from \"./routed-worker\";\nexport * from \"./routes\";\nexport * from \"./worker\";\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * https://github.com/etienne-martin/cache-control-parser\n */\nimport CacheLib from \"cache-control-parser\";\n\nexport type CacheControl = CacheLib.CacheControl;\nexport const CacheControl = {\n parse: CacheLib.parse,\n stringify: CacheLib.stringify,\n};\n\nexport namespace HttpHeader {\n export const VARY = \"Vary\";\n\n // Security Headers\n export const X_CONTENT_TYPE_OPTIONS = \"X-Content-Type-Options\"; // usually \"nosniff\"\n export const X_FRAME_OPTIONS = \"X-Frame-Options\"; // e.g. \"DENY\" or \"SAMEORIGIN\"\n export const STRICT_TRANSPORT_SECURITY = \"Strict-Transport-Security\"; // e.g. \"max-age=63072000; includeSubDomains; preload\"\n export const CONTENT_SECURITY_POLICY = \"Content-Security-Policy\"; // fine-grained script/style/image restrictions\n export const REFERRER_POLICY = \"Referrer-Policy\"; // e.g. \"no-referrer\", \"strict-origin-when-cross-origin\"\n export const PERMISSIONS_POLICY = \"Permissions-Policy\"; // formerly Feature-Policy, controls APIs like geolocation/camera\n\n // Values\n export const NOSNIFF = \"nosniff\";\n export const ORIGIN = \"Origin\";\n}\n\nexport const Time = {\n Second: 1,\n Minute: 60,\n Hour: 60 * 60,\n Day: 60 * 60 * 24,\n Week: 60 * 60 * 24 * 7,\n Year: 60 * 60 * 24 * 365,\n} as const;\n\nexport enum Method {\n GET = \"GET\",\n PUT = \"PUT\",\n POST = \"POST\",\n PATCH = \"PATCH\",\n DELETE = \"DELETE\",\n HEAD = \"HEAD\",\n OPTIONS = \"OPTIONS\",\n}\nconst METHOD_SET: Set<string> = new Set(Object.values(Method));\n\nexport function isMethod(value: string): value is Method {\n return METHOD_SET.has(value);\n}\n\nexport function getContentType(type: MimeType): string {\n if (ADD_CHARSET.has(type)) {\n return `${type}; charset=utf-8`;\n }\n return type;\n}\n\nexport enum MimeType {\n PLAIN_TEXT = \"text/plain\",\n HTML = \"text/html\",\n CSS = \"text/css\",\n CSV = \"text/csv\",\n XML = \"text/xml\",\n MARKDOWN = \"text/markdown\",\n RICH_TEXT = \"text/richtext\",\n JSON = \"application/json\",\n XML_APP = \"application/xml\",\n YAML = \"application/x-yaml\",\n FORM_URLENCODED = \"application/x-www-form-urlencoded\",\n NDJSON = \"application/x-ndjson\",\n MSGPACK = \"application/x-msgpack\",\n PROTOBUF = \"application/x-protobuf\",\n MULTIPART_FORM_DATA = \"multipart/form-data\",\n MULTIPART_MIXED = \"multipart/mixed\",\n MULTIPART_ALTERNATIVE = \"multipart/alternative\",\n MULTIPART_DIGEST = \"multipart/digest\",\n MULTIPART_RELATED = \"multipart/related\",\n MULTIPART_SIGNED = \"multipart/signed\",\n MULTIPART_ENCRYPTED = \"multipart/encrypted\",\n OCTET_STREAM = \"application/octet-stream\",\n PDF = \"application/pdf\",\n ZIP = \"application/zip\",\n GZIP = \"application/gzip\",\n MSWORD = \"application/msword\",\n DOCX = \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n EXCEL = \"application/vnd.ms-excel\",\n XLSX = \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n POWERPOINT = \"application/vnd.ms-powerpoint\",\n PPTX = \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n ICO = \"image/x-icon\",\n ICO_MS = \"image/vnd.microsoft.icon\",\n GIF = \"image/gif\",\n PNG = \"image/png\",\n JPEG = \"image/jpeg\",\n WEBP = \"image/webp\",\n SVG = \"image/svg+xml\",\n HEIF = \"image/heif\",\n AVIF = \"image/avif\",\n EVENT_STREAM = \"text/event-stream\",\n TAR = \"application/x-tar\",\n BZIP2 = \"application/x-bzip2\",\n}\n\nconst ADD_CHARSET: Set<MimeType> = new Set([\n MimeType.PLAIN_TEXT,\n MimeType.HTML,\n MimeType.CSS,\n MimeType.CSV,\n MimeType.MARKDOWN,\n MimeType.XML,\n MimeType.JSON,\n MimeType.XML_APP,\n MimeType.FORM_URLENCODED,\n MimeType.NDJSON,\n MimeType.RICH_TEXT,\n MimeType.SVG,\n]);\n\nexport function setHeader(headers: Headers, key: string, value: string | string[]): void {\n const raw = Array.isArray(value) ? value : [value];\n const values = Array.from(new Set(raw.map((v) => v.trim()))).filter((v) => v.length);\n\n if (!values.length) {\n headers.delete(key);\n return;\n }\n\n headers.set(key, values.join(\", \"));\n}\n\nexport function mergeHeader(headers: Headers, key: string, value: string | string[]): void {\n const values = Array.isArray(value) ? value : [value];\n if (!values.length) return;\n\n const existing = headers.get(key);\n if (existing) {\n const merged = existing.split(\",\").map((v) => v.trim());\n values.forEach((v) => merged.push(v.trim()));\n setHeader(headers, key, merged);\n } else {\n setHeader(headers, key, values);\n }\n}\n\n/**\n * Normalizes a URL string for use as a consistent cache key.\n *\n * - Sorts query parameters alphabetically so `?b=2&a=1` and `?a=1&b=2` are treated the same.\n * - Strips fragment identifiers (`#...`) since they are not sent in HTTP requests.\n * - Leaves protocol, host, path, and query values intact.\n *\n * @param url The original URL string to normalize.\n * @returns A normalized URL string suitable for hashing or direct cache key use.\n */\nexport function normalizeUrl(url: string): URL {\n const u = new URL(url);\n\n const params = [...u.searchParams.entries()];\n params.sort(([a], [b]) => a.localeCompare(b));\n\n u.search = params\n .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)\n .join(\"&\");\n u.hash = \"\";\n\n return u;\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Worker } from \"./worker\";\n\nexport abstract class BaseWorker implements Worker {\n constructor(\n private readonly _request: Request,\n private readonly _env: Env = {},\n private readonly _ctx?: ExecutionContext\n ) {}\n\n protected get request(): Request {\n return this._request;\n }\n\n protected get env(): Env {\n return this._env;\n }\n\n protected get ctx(): ExecutionContext | undefined {\n return this._ctx;\n }\n\n public abstract fetch(): Promise<Response>;\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * https://github.com/etienne-martin/cache-control-parser\n */\nimport { Method, normalizeUrl } from \"./common\";\nimport { BaseWorker } from \"./base-worker\";\nimport { createHash } from \"crypto\";\n\nexport abstract class CacheWorker extends BaseWorker {\n protected getCacheKey(...values: Array<string | null | undefined>): URL | RequestInfo {\n const raw = [\n normalizeUrl(this.request.url),\n ...values\n .filter((v) => v != null) // remove null/undefined\n .map((v) => v!.trim()) // trim whitespace\n .filter((v) => v.length > 0), // skip empty strings after trim\n ].join(\"\\u0001\");\n const hash = createHash(\"sha256\").update(raw).digest(\"base64url\");\n return new URL(`http://cache/${hash}`);\n }\n\n protected async getCachedResponse(): Promise<Response | undefined> {\n if (this.request.method !== Method.GET) return;\n\n return await caches.default.match(this.getCacheKey());\n }\n\n protected setCachedResponse(response: Response): void {\n if (!response.ok) return;\n if (this.request.method !== Method.GET) return;\n\n try {\n this.ctx?.waitUntil(caches.default.put(this.getCacheKey(), response.clone()));\n } catch (e) {\n console.warn(\"Failed to cache response:\", e);\n }\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getReasonPhrase, StatusCodes } from \"http-status-codes\";\nimport {\n CacheControl,\n getContentType,\n HttpHeader,\n mergeHeader,\n Method,\n MimeType,\n setHeader,\n} from \"./common\";\nimport { Cors, CorsProvider } from \"./cors\";\n\nexport interface ErrorJson {\n status: number;\n error: string;\n details: string;\n}\n\nabstract class BaseResponse {\n public headers: Headers = new Headers();\n public body: BodyInit | null;\n public status: StatusCodes = StatusCodes.OK;\n public statusText?: string;\n public mimeType?: MimeType;\n\n constructor(content: BodyInit | null = null) {\n this.body = this.status === StatusCodes.NO_CONTENT ? null : content;\n }\n\n protected get responseInit(): ResponseInit {\n return {\n headers: this.headers,\n status: this.status,\n statusText: this.statusText ?? getReasonPhrase(this.status),\n };\n }\n\n public setHeader(key: string, value: string | string[]): void {\n setHeader(this.headers, key, value);\n }\n\n public mergeHeader(key: string, value: string | string[]): void {\n mergeHeader(this.headers, key, value);\n }\n\n public addContentType() {\n if (this.mimeType) {\n this.headers.set(\"Content-Type\", getContentType(this.mimeType));\n }\n }\n}\n\nabstract class CorsResponse extends BaseResponse {\n constructor(public readonly cors: CorsProvider, content: BodyInit | null = null) {\n super(content);\n }\n\n protected addCorsHeaders(): void {\n const origin = this.cors.getOrigin();\n if (!origin) return; // no Origin, skip CORS\n\n this.headers.delete(Cors.ALLOW_ORIGIN);\n this.headers.delete(Cors.ALLOW_CREDENTIALS);\n\n if (this.cors.allowAnyOrigin()) {\n this.setHeader(Cors.ALLOW_ORIGIN, Cors.ALLOW_ALL_ORIGINS);\n } else if (this.cors.getAllowOrigins().includes(origin)) {\n this.setHeader(Cors.ALLOW_ORIGIN, origin);\n this.setHeader(Cors.ALLOW_CREDENTIALS, String(true));\n this.mergeHeader(HttpHeader.VARY, HttpHeader.ORIGIN);\n }\n\n this.mergeHeader(Cors.EXPOSE_HEADERS, this.cors.getExposeHeaders());\n this.setHeader(Cors.ALLOW_HEADERS, this.cors.getAllowHeaders());\n this.setHeader(Cors.ALLOW_METHODS, this.cors.getAllowMethods());\n this.setHeader(Cors.MAX_AGE, String(this.cors.getMaxAge()));\n }\n}\n\nabstract class CacheResponse extends CorsResponse {\n public cache?: CacheControl;\n\n constructor(cors: CorsProvider, body: BodyInit | null = null, cache?: CacheControl) {\n super(cors, body);\n this.cache = cache;\n }\n\n protected addCacheHeader(): void {\n if (this.cache) {\n this.headers.set(\"Cache-Control\", CacheControl.stringify(this.cache));\n }\n }\n}\n\nexport abstract class WorkerResponse extends CacheResponse {\n public createResponse(): Response {\n this.addCorsHeaders();\n this.addCacheHeader();\n this.addSecurityHeaders();\n\n const body = this.status === StatusCodes.NO_CONTENT ? null : this.body;\n if (body) this.addContentType();\n return new Response(body, this.responseInit);\n }\n\n protected addSecurityHeaders(): void {\n this.setHeader(HttpHeader.X_CONTENT_TYPE_OPTIONS, HttpHeader.NOSNIFF);\n }\n}\n\nexport class ClonedResponse extends WorkerResponse {\n constructor(cors: CorsProvider, response: Response, cache?: CacheControl) {\n const clone = response.clone();\n super(cors, clone.body, cache);\n this.headers = new Headers(clone.headers);\n this.status = clone.status;\n this.statusText = clone.statusText;\n }\n}\n\nexport class SuccessResponse extends WorkerResponse {\n constructor(\n cors: CorsProvider,\n body: BodyInit | null = null,\n cache?: CacheControl,\n status: StatusCodes = StatusCodes.OK\n ) {\n super(cors, body, cache);\n this.status = status;\n }\n}\n\nexport class JsonResponse extends SuccessResponse {\n constructor(\n cors: CorsProvider,\n json: unknown = {},\n cache?: CacheControl,\n status: StatusCodes = StatusCodes.OK\n ) {\n super(cors, JSON.stringify(json), cache, status);\n this.mimeType = MimeType.JSON;\n }\n}\n\nexport class HtmlResponse extends SuccessResponse {\n constructor(\n cors: CorsProvider,\n body: string,\n cache?: CacheControl,\n status: StatusCodes = StatusCodes.OK\n ) {\n super(cors, body, cache, status);\n this.mimeType = MimeType.HTML;\n }\n}\n\nexport class TextResponse extends SuccessResponse {\n constructor(\n cors: CorsProvider,\n content: string,\n cache?: CacheControl,\n status: StatusCodes = StatusCodes.OK\n ) {\n super(cors, content, cache, status);\n this.mimeType = MimeType.PLAIN_TEXT;\n }\n}\n\n/**\n * Removes the body from a GET response.\n */\nexport class Head extends WorkerResponse {\n constructor(cors: CorsProvider, get: Response) {\n super(cors);\n this.headers = new Headers(get.headers);\n }\n}\n\nexport class Options extends SuccessResponse {\n constructor(cors: CorsProvider) {\n super(cors, null, undefined, StatusCodes.NO_CONTENT);\n this.setHeader(\"Allow\", this.cors.getAllowMethods());\n }\n}\n\nexport class HttpError extends JsonResponse {\n constructor(cors: CorsProvider, status: StatusCodes, protected readonly details?: string) {\n const cache: CacheControl = {\n \"no-cache\": true,\n \"no-store\": true,\n \"must-revalidate\": true,\n \"max-age\": 0,\n };\n super(cors, undefined, cache, status);\n }\n\n public get json(): ErrorJson {\n return {\n status: this.status,\n error: getReasonPhrase(this.status),\n details: this.details ?? getReasonPhrase(this.status),\n };\n }\n\n public override createResponse(): Response {\n this.body = JSON.stringify(this.json);\n return super.createResponse();\n }\n}\n\nexport class BadRequest extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.BAD_REQUEST, details);\n }\n}\n\nexport class Unauthorized extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.UNAUTHORIZED, details);\n }\n}\n\nexport class Forbidden extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.FORBIDDEN, details);\n }\n}\n\nexport class NotFound extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.NOT_FOUND, details);\n }\n}\n\nexport class MethodNotAllowed extends HttpError {\n constructor(cors: CorsProvider, method: string) {\n super(cors, StatusCodes.METHOD_NOT_ALLOWED, `${method} method not allowed.`);\n this.setHeader(\"Allow\", this.cors.getAllowMethods());\n }\n\n public override get json(): ErrorJson & { allowed: Method[] } {\n return {\n ...super.json,\n allowed: this.cors.getAllowMethods(),\n };\n }\n}\n\nexport class InternalServerError extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.INTERNAL_SERVER_ERROR, details);\n }\n}\n\nexport class NotImplemented extends HttpError {\n constructor(cors: CorsProvider) {\n super(cors, StatusCodes.NOT_IMPLEMENTED);\n }\n}\n\nexport class ServiceUnavailable extends HttpError {\n constructor(cors: CorsProvider, details?: string) {\n super(cors, StatusCodes.SERVICE_UNAVAILABLE, details);\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Method } from \"./common\";\n\nexport interface CorsProvider {\n getOrigin(): string | null;\n getAllowOrigins(): string[];\n allowAnyOrigin(): boolean;\n getAllowMethods(): Method[];\n getAllowHeaders(): string[];\n getExposeHeaders(): string[];\n getMaxAge(): number;\n}\n\nexport namespace Cors {\n export const ALLOW_ORIGIN = \"Access-Control-Allow-Origin\";\n export const ALLOW_CREDENTIALS = \"Access-Control-Allow-Credentials\";\n export const EXPOSE_HEADERS = \"Access-Control-Expose-Headers\";\n export const ALLOW_HEADERS = \"Access-Control-Allow-Headers\";\n export const ALLOW_METHODS = \"Access-Control-Allow-Methods\";\n export const MAX_AGE = \"Access-Control-Max-Age\";\n export const ALLOW_ALL_ORIGINS = \"*\";\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CacheWorker } from \"./cache-worker\";\nimport { isMethod, Method, Time } from \"./common\";\nimport { CorsProvider } from \"./cors\";\nimport {\n Head,\n InternalServerError,\n MethodNotAllowed,\n NotImplemented,\n Options,\n WorkerResponse,\n} from \"./response\";\n\nexport abstract class BasicWorker extends CacheWorker implements CorsProvider {\n public async fetch(): Promise<Response> {\n if (!this.isAllowed(this.request.method)) {\n return this.getResponse(MethodNotAllowed, this.request.method);\n }\n\n try {\n return await this.dispatch();\n } catch (error) {\n return this.getResponse(InternalServerError, String(error));\n }\n }\n\n protected async dispatch(request: Request = this.request): Promise<Response> {\n const method = request.method as Method;\n const handler: Record<Method, () => Promise<Response>> = {\n GET: () => this.get(),\n PUT: () => this.put(),\n POST: () => this.post(),\n PATCH: () => this.patch(),\n DELETE: () => this.delete(),\n HEAD: () => this.head(),\n OPTIONS: () => this.options(),\n };\n return (handler[method] ?? (() => this.getResponse(MethodNotAllowed, method)))();\n }\n\n protected async get(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async put(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async post(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async patch(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async delete(): Promise<Response> {\n return this.getResponse(NotImplemented);\n }\n\n protected async options(): Promise<Response> {\n return this.getResponse(Options);\n }\n\n protected async head(): Promise<Response> {\n // Dispatch a new GET request created from the HEAD request\n // and return the GET response with the body removed.\n return this.getResponse(\n Head,\n await this.dispatch(new Request(this.request, { method: Method.GET }))\n );\n }\n\n protected override getCacheKey(): URL | RequestInfo {\n return super.getCacheKey(this.getOrigin());\n }\n\n protected async getResponse<T extends WorkerResponse>(\n ResponseClass: new (cors: CorsProvider, ...args: any[]) => T,\n ...args: any[]\n ): Promise<Response> {\n const response = new ResponseClass(this, ...args).createResponse();\n this.setCachedResponse(response);\n return response;\n }\n\n public isAllowed(method: string): boolean {\n return isMethod(method) && this.getAllowMethods().includes(method);\n }\n\n public getAllowOrigins(): string[] {\n return [\"*\"];\n }\n\n public allowAnyOrigin(): boolean {\n return this.getAllowOrigins().includes(\"*\");\n }\n\n public getAllowMethods(): Method[] {\n return [Method.GET, Method.OPTIONS, Method.HEAD];\n }\n\n public getAllowHeaders(): string[] {\n return [\"Content-Type\"];\n }\n\n public getExposeHeaders(): string[] {\n return [];\n }\n\n public getMaxAge(): number {\n return Time.Week;\n }\n\n public getOrigin(): string | null {\n return this.request.headers.get(\"Origin\");\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Method } from \"./common\";\n\nexport type RouteCallback = (...matches: string[]) => Response | Promise<Response>;\n\nexport type RouteInit = [Method, string, RouteCallback];\n\nexport class Route {\n public readonly pattern: RegExp;\n\n constructor(pattern: RegExp | string, public readonly callback: RouteCallback) {\n this.pattern = new RegExp(pattern);\n }\n}\n\nexport class Routes {\n private readonly map = new Map<Method, Route[]>();\n\n public add(method: Method, route: Route) {\n const existing = this.map.get(method);\n if (existing) {\n existing.push(route);\n } else {\n this.map.set(method, [route]);\n }\n return this;\n }\n\n public get(method: Method, url: string): Route | undefined {\n const routes = this.map.get(method);\n if (!routes) return undefined;\n\n const pathname = new URL(url).pathname;\n return routes.find(({ pattern }) => pattern.test(pathname));\n }\n}\n","/*\n * Copyright (C) 2025 Ty Busby\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BasicWorker } from \"./basic-worker\";\nimport { Method } from \"./common\";\nimport { NotFound } from \"./response\";\nimport { Route, Routes, RouteInit, RouteCallback } from \"./routes\";\n\nexport abstract class RoutedWorker extends BasicWorker {\n private readonly routes: Routes = new Routes();\n\n protected initialize(routes: RouteInit[]) {\n routes.forEach(([method, pattern, callback]) => {\n this.add(method, pattern, callback);\n });\n }\n\n protected add(method: Method, pattern: RegExp | string, callback: RouteCallback) {\n this.routes.add(method, new Route(pattern, callback));\n return this;\n }\n\n protected async dispatch(request: Request = this.request): Promise<Response> {\n const route = this.routes.get(request.method as Method, request.url);\n if (!route) return super.dispatch(request);\n\n const match = new URL(request.url).pathname.match(route.pattern) ?? [];\n return route.callback.call(this, ...match);\n }\n\n protected override async get(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override async put(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override async post(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override async patch(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n\n protected override async delete(): Promise<Response> {\n return this.getResponse(NotFound);\n }\n}\n"],"mappings":";AAgBA,SAAS,eAAAA,oBAAmB;;;ACG5B,OAAO,cAAc;AAGd,IAAM,eAAe;AAAA,EACxB,OAAO,SAAS;AAAA,EAChB,WAAW,SAAS;AACxB;AAEO,IAAU;AAAA,CAAV,CAAUC,gBAAV;AACI,EAAMA,YAAA,OAAO;AAGb,EAAMA,YAAA,yBAAyB;AAC/B,EAAMA,YAAA,kBAAkB;AACxB,EAAMA,YAAA,4BAA4B;AAClC,EAAMA,YAAA,0BAA0B;AAChC,EAAMA,YAAA,kBAAkB;AACxB,EAAMA,YAAA,qBAAqB;AAG3B,EAAMA,YAAA,UAAU;AAChB,EAAMA,YAAA,SAAS;AAAA,GAbT;AAgBV,IAAM,OAAO;AAAA,EAChB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM,KAAK;AAAA,EACX,KAAK,KAAK,KAAK;AAAA,EACf,MAAM,KAAK,KAAK,KAAK;AAAA,EACrB,MAAM,KAAK,KAAK,KAAK;AACzB;AAEO,IAAK,SAAL,kBAAKC,YAAL;AACH,EAAAA,QAAA,SAAM;AACN,EAAAA,QAAA,SAAM;AACN,EAAAA,QAAA,UAAO;AACP,EAAAA,QAAA,WAAQ;AACR,EAAAA,QAAA,YAAS;AACT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AAI,QAAQ,QAAkB,QAAQ,GAAG;AACnE,QAAI,CAAC,MAAO,QAAO,MAAM,SAAS,OAAO;AAEzC,UAAM,QAAQ,IAAI,IAAI,QAAQ,GAAG,EAAE,SAAS,MAAM,MAAM,OAAO,KAAK,CAAC;AACrE,WAAO,MAAM,SAAS,KAAK,MAAM,GAAG,KAAK;AAAA,EAC7C;AAAA,EAEA,MAAyB,MAAyB;AAC9C,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEA,MAAyB,MAAyB;AAC9C,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEA,MAAyB,OAA0B;AAC/C,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEA,MAAyB,QAA2B;AAChD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AAAA,EAEA,MAAyB,SAA4B;AACjD,WAAO,KAAK,YAAY,QAAQ;AAAA,EACpC;AACJ;","names":["StatusCodes","HttpHeader","Method","MimeType","Cors"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonix.org/cloud-spark",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.76",
|
|
4
4
|
"description": "Ignite your Cloudflare Workers with a type-safe library for rapid development.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@cloudflare/workers-types": "^4.20250821.0",
|
|
47
|
+
"@types/node": "^24.3.0",
|
|
47
48
|
"tsup": "^8.5.0",
|
|
48
49
|
"tsx": "^4.20.4",
|
|
49
50
|
"typescript": "^5.9.2",
|