tezx 1.0.13 → 1.0.15
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 +8 -3
- package/{dist/cjs → cjs}/index.js +1 -1
- package/{dist/index.js → index.js} +1 -1
- package/package.json +18 -19
- package/dist/MiddlewareConfigure.d.ts +0 -17
- package/dist/MiddlewareConfigure.js +0 -63
- package/dist/adapter.d.ts +0 -10
- package/dist/adapter.js +0 -162
- package/dist/cjs/MiddlewareConfigure.js +0 -68
- package/dist/cjs/adapter.js +0 -166
- package/dist/cjs/common.js +0 -15
- package/dist/cjs/config/config.js +0 -35
- package/dist/cjs/context.js +0 -428
- package/dist/cjs/environment.js +0 -34
- package/dist/cjs/header.js +0 -85
- package/dist/cjs/helper/common.js +0 -11
- package/dist/cjs/helper/env-parser.js +0 -69
- package/dist/cjs/helper/index.js +0 -20
- package/dist/cjs/middleware/cors.js +0 -49
- package/dist/cjs/middleware/index.js +0 -26
- package/dist/cjs/middleware/logger.js +0 -21
- package/dist/cjs/middleware/powered-by.js +0 -10
- package/dist/cjs/middleware/rateLimiter.js +0 -40
- package/dist/cjs/middleware/request-id.js +0 -15
- package/dist/cjs/middleware/sanitizeHeader.js +0 -51
- package/dist/cjs/middleware/secureHeaders.js +0 -42
- package/dist/cjs/middleware/xssProtection.js +0 -26
- package/dist/cjs/request.js +0 -80
- package/dist/cjs/router.js +0 -377
- package/dist/cjs/server.js +0 -170
- package/dist/cjs/utils/colors.js +0 -24
- package/dist/cjs/utils/debugging.js +0 -17
- package/dist/cjs/utils/formData.js +0 -219
- package/dist/cjs/utils/params.js +0 -94
- package/dist/cjs/utils/state.js +0 -34
- package/dist/cjs/utils/staticFile.js +0 -158
- package/dist/cjs/utils/url.js +0 -59
- package/dist/common.d.ts +0 -21
- package/dist/common.js +0 -11
- package/dist/config/config.d.ts +0 -17
- package/dist/config/config.js +0 -31
- package/dist/context.d.ts +0 -195
- package/dist/context.js +0 -424
- package/dist/environment.d.ts +0 -6
- package/dist/environment.js +0 -30
- package/dist/header.d.ts +0 -71
- package/dist/header.js +0 -81
- package/dist/helper/common.d.ts +0 -5
- package/dist/helper/common.js +0 -8
- package/dist/helper/env-parser.d.ts +0 -5
- package/dist/helper/env-parser.js +0 -66
- package/dist/helper/index.d.ts +0 -2
- package/dist/helper/index.js +0 -2
- package/dist/middleware/cors.d.ts +0 -10
- package/dist/middleware/cors.js +0 -46
- package/dist/middleware/index.d.ts +0 -9
- package/dist/middleware/index.js +0 -8
- package/dist/middleware/logger.d.ts +0 -15
- package/dist/middleware/logger.js +0 -18
- package/dist/middleware/powered-by.d.ts +0 -16
- package/dist/middleware/powered-by.js +0 -6
- package/dist/middleware/rateLimiter.d.ts +0 -61
- package/dist/middleware/rateLimiter.js +0 -36
- package/dist/middleware/request-id.d.ts +0 -16
- package/dist/middleware/request-id.js +0 -11
- package/dist/middleware/sanitizeHeader.d.ts +0 -53
- package/dist/middleware/sanitizeHeader.js +0 -47
- package/dist/middleware/secureHeaders.d.ts +0 -78
- package/dist/middleware/secureHeaders.js +0 -38
- package/dist/middleware/xssProtection.d.ts +0 -43
- package/dist/middleware/xssProtection.js +0 -22
- package/dist/request.d.ts +0 -82
- package/dist/request.js +0 -76
- package/dist/router.d.ts +0 -191
- package/dist/router.js +0 -373
- package/dist/server.d.ts +0 -54
- package/dist/server.js +0 -166
- package/dist/utils/colors.d.ts +0 -21
- package/dist/utils/colors.js +0 -21
- package/dist/utils/debugging.d.ts +0 -7
- package/dist/utils/debugging.js +0 -13
- package/dist/utils/formData.d.ts +0 -5
- package/dist/utils/formData.js +0 -213
- package/dist/utils/params.d.ts +0 -7
- package/dist/utils/params.js +0 -91
- package/dist/utils/state.d.ts +0 -50
- package/dist/utils/state.js +0 -30
- package/dist/utils/staticFile.d.ts +0 -9
- package/dist/utils/staticFile.js +0 -154
- package/dist/utils/url.d.ts +0 -16
- package/dist/utils/url.js +0 -55
- /package/{dist/index.d.ts → index.d.ts} +0 -0
package/dist/cjs/context.js
DELETED
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Context = exports.httpStatusMap = void 0;
|
|
4
|
-
const environment_1 = require("./environment");
|
|
5
|
-
const header_1 = require("./header");
|
|
6
|
-
const request_1 = require("./request");
|
|
7
|
-
const state_1 = require("./utils/state");
|
|
8
|
-
const staticFile_1 = require("./utils/staticFile");
|
|
9
|
-
exports.httpStatusMap = {
|
|
10
|
-
100: "Continue",
|
|
11
|
-
101: "Switching Protocols",
|
|
12
|
-
102: "Processing",
|
|
13
|
-
103: "Early Hints",
|
|
14
|
-
200: "OK",
|
|
15
|
-
201: "Created",
|
|
16
|
-
202: "Accepted",
|
|
17
|
-
203: "Non-Authoritative Information",
|
|
18
|
-
204: "No Content",
|
|
19
|
-
205: "Reset Content",
|
|
20
|
-
206: "Partial Content",
|
|
21
|
-
207: "Multi-Status",
|
|
22
|
-
208: "Already Reported",
|
|
23
|
-
226: "IM Used",
|
|
24
|
-
300: "Multiple Choices",
|
|
25
|
-
301: "Moved Permanently",
|
|
26
|
-
302: "Found",
|
|
27
|
-
303: "See Other",
|
|
28
|
-
304: "Not Modified",
|
|
29
|
-
305: "Use Proxy",
|
|
30
|
-
306: "Switch Proxy",
|
|
31
|
-
307: "Temporary Redirect",
|
|
32
|
-
308: "Permanent Redirect",
|
|
33
|
-
400: "Bad Request",
|
|
34
|
-
401: "Unauthorized",
|
|
35
|
-
402: "Payment Required",
|
|
36
|
-
403: "Forbidden",
|
|
37
|
-
404: "Not Found",
|
|
38
|
-
405: "Method Not Allowed",
|
|
39
|
-
406: "Not Acceptable",
|
|
40
|
-
407: "Proxy Authentication Required",
|
|
41
|
-
408: "Request Timeout",
|
|
42
|
-
409: "Conflict",
|
|
43
|
-
410: "Gone",
|
|
44
|
-
411: "Length Required",
|
|
45
|
-
412: "Precondition Failed",
|
|
46
|
-
413: "Payload Too Large",
|
|
47
|
-
414: "URI Too Long",
|
|
48
|
-
415: "Unsupported Media Type",
|
|
49
|
-
416: "Range Not Satisfiable",
|
|
50
|
-
417: "Expectation Failed",
|
|
51
|
-
418: "I'm a Teapot",
|
|
52
|
-
421: "Misdirected Request",
|
|
53
|
-
422: "Unprocessable Entity",
|
|
54
|
-
423: "Locked",
|
|
55
|
-
424: "Failed Dependency",
|
|
56
|
-
425: "Too Early",
|
|
57
|
-
426: "Upgrade Required",
|
|
58
|
-
428: "Precondition Required",
|
|
59
|
-
429: "Too Many Requests",
|
|
60
|
-
431: "Request Header Fields Too Large",
|
|
61
|
-
451: "Unavailable For Legal Reasons",
|
|
62
|
-
500: "Internal Server Error",
|
|
63
|
-
501: "Not Implemented",
|
|
64
|
-
502: "Bad Gateway",
|
|
65
|
-
503: "Service Unavailable",
|
|
66
|
-
504: "Gateway Timeout",
|
|
67
|
-
505: "HTTP Version Not Supported",
|
|
68
|
-
506: "Variant Also Negotiates",
|
|
69
|
-
507: "Insufficient Storage",
|
|
70
|
-
508: "Loop Detected",
|
|
71
|
-
510: "Not Extended",
|
|
72
|
-
511: "Network Authentication Required",
|
|
73
|
-
};
|
|
74
|
-
class Context {
|
|
75
|
-
#rawRequest;
|
|
76
|
-
env = {};
|
|
77
|
-
headers = new header_1.HeadersParser();
|
|
78
|
-
res;
|
|
79
|
-
pathname;
|
|
80
|
-
url;
|
|
81
|
-
method;
|
|
82
|
-
#status = 200;
|
|
83
|
-
state = new state_1.State();
|
|
84
|
-
#params = {};
|
|
85
|
-
#localAddress = {};
|
|
86
|
-
#remoteAddress = {};
|
|
87
|
-
constructor(req, connInfo) {
|
|
88
|
-
this.#rawRequest = req;
|
|
89
|
-
this.#remoteAddress = connInfo.remoteAddr;
|
|
90
|
-
this.#localAddress = connInfo.localAddr;
|
|
91
|
-
this.method = req?.method?.toUpperCase();
|
|
92
|
-
this.pathname = this.req.urlRef.pathname;
|
|
93
|
-
this.url = this.req.url;
|
|
94
|
-
}
|
|
95
|
-
header(key, value) {
|
|
96
|
-
this.headers.set(key, value);
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
get cookies() {
|
|
100
|
-
const c = this.headers.getAll("cookie");
|
|
101
|
-
let cookies = {};
|
|
102
|
-
if (Array.isArray(c) && c.length != 0) {
|
|
103
|
-
const cookieHeader = c.join("; ").split(";");
|
|
104
|
-
for (const pair of cookieHeader) {
|
|
105
|
-
const [key, value] = pair?.trim()?.split("=");
|
|
106
|
-
cookies[key] = decodeURIComponent(value);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (typeof c == "string") {
|
|
110
|
-
const cookieHeader = c.split(";");
|
|
111
|
-
for (const pair of cookieHeader) {
|
|
112
|
-
const [key, value] = pair?.trim()?.split("=");
|
|
113
|
-
cookies[key] = decodeURIComponent(value);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
get: (cookie) => {
|
|
118
|
-
return cookies?.[cookie];
|
|
119
|
-
},
|
|
120
|
-
all: () => {
|
|
121
|
-
return cookies;
|
|
122
|
-
},
|
|
123
|
-
delete: (name, options) => {
|
|
124
|
-
const value = "";
|
|
125
|
-
const cookieOptions = {
|
|
126
|
-
...options,
|
|
127
|
-
expires: new Date(0),
|
|
128
|
-
};
|
|
129
|
-
const cookieHeader = `${name}=${value};${serializeOptions(cookieOptions)}`;
|
|
130
|
-
this.headers.set("Set-Cookie", cookieHeader);
|
|
131
|
-
},
|
|
132
|
-
set: (name, value, options) => {
|
|
133
|
-
const cookieHeader = `${name}=${value};${serializeOptions(options || {})}`;
|
|
134
|
-
this.headers.set("Set-Cookie", cookieHeader);
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
json(body, ...args) {
|
|
139
|
-
let status = this.#status;
|
|
140
|
-
let headers = {
|
|
141
|
-
"Content-Type": "application/json; charset=utf-8",
|
|
142
|
-
};
|
|
143
|
-
if (typeof args[0] === "number") {
|
|
144
|
-
status = args[0];
|
|
145
|
-
if (typeof args[1] === "object") {
|
|
146
|
-
headers = { ...headers, ...args[1] };
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
else if (typeof args[0] === "object") {
|
|
150
|
-
headers = { ...headers, ...args[0] };
|
|
151
|
-
}
|
|
152
|
-
return this.#handleResponse(JSON.stringify(body), {
|
|
153
|
-
status: status,
|
|
154
|
-
headers: headers,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
send(body, ...args) {
|
|
158
|
-
let status = this.#status;
|
|
159
|
-
let headers = {};
|
|
160
|
-
if (typeof args[0] === "number") {
|
|
161
|
-
status = args[0];
|
|
162
|
-
if (typeof args[1] === "object") {
|
|
163
|
-
headers = args[1];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
else if (typeof args[0] === "object") {
|
|
167
|
-
headers = args[0];
|
|
168
|
-
}
|
|
169
|
-
if (!headers["Content-Type"]) {
|
|
170
|
-
if (typeof body === "string") {
|
|
171
|
-
headers["Content-Type"] = "text/plain;";
|
|
172
|
-
}
|
|
173
|
-
else if (typeof body === "object" && body !== null) {
|
|
174
|
-
headers["Content-Type"] = "application/json;";
|
|
175
|
-
body = JSON.stringify(body);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
headers["Content-Type"] = "application/octet-stream";
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return this.#handleResponse(body, {
|
|
182
|
-
status: status,
|
|
183
|
-
headers,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
html(data, ...args) {
|
|
187
|
-
let status = this.#status;
|
|
188
|
-
let headers = {
|
|
189
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
190
|
-
};
|
|
191
|
-
if (typeof args[0] === "number") {
|
|
192
|
-
status = args[0];
|
|
193
|
-
if (typeof args[1] === "object") {
|
|
194
|
-
headers = { ...headers, ...args[1] };
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else if (typeof args[0] === "object") {
|
|
198
|
-
headers = { ...headers, ...args[0] };
|
|
199
|
-
}
|
|
200
|
-
return this.#handleResponse(data, {
|
|
201
|
-
status: status,
|
|
202
|
-
headers: headers,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
text(data, ...args) {
|
|
206
|
-
let status = this.#status;
|
|
207
|
-
let headers = {
|
|
208
|
-
"Content-Type": "text/plain; charset=utf-8",
|
|
209
|
-
};
|
|
210
|
-
if (typeof args[0] === "number") {
|
|
211
|
-
status = args[0];
|
|
212
|
-
if (typeof args[1] === "object") {
|
|
213
|
-
headers = { ...headers, ...args[1] };
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else if (typeof args[0] === "object") {
|
|
217
|
-
headers = { ...headers, ...args[0] };
|
|
218
|
-
}
|
|
219
|
-
return this.#handleResponse(data, {
|
|
220
|
-
status: status,
|
|
221
|
-
headers: headers,
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
xml(data, ...args) {
|
|
225
|
-
let status = this.#status;
|
|
226
|
-
let headers = {
|
|
227
|
-
"Content-Type": "application/xml; charset=utf-8",
|
|
228
|
-
};
|
|
229
|
-
if (typeof args[0] === "number") {
|
|
230
|
-
status = args[0];
|
|
231
|
-
if (typeof args[1] === "object") {
|
|
232
|
-
headers = { ...headers, ...args[1] };
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
else if (typeof args[0] === "object") {
|
|
236
|
-
headers = { ...headers, ...args[0] };
|
|
237
|
-
}
|
|
238
|
-
return this.#handleResponse(data, {
|
|
239
|
-
status: status,
|
|
240
|
-
headers: headers,
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
status = (status) => {
|
|
244
|
-
this.#status = status;
|
|
245
|
-
return this;
|
|
246
|
-
};
|
|
247
|
-
set setStatus(status) {
|
|
248
|
-
this.#status = status;
|
|
249
|
-
}
|
|
250
|
-
get getStatus() {
|
|
251
|
-
return this.#status;
|
|
252
|
-
}
|
|
253
|
-
redirect(url, status = 302) {
|
|
254
|
-
return new Response(null, {
|
|
255
|
-
status: status,
|
|
256
|
-
headers: { Location: url },
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
async download(filePath, fileName) {
|
|
260
|
-
try {
|
|
261
|
-
let fileExists = false;
|
|
262
|
-
const runtime = environment_1.EnvironmentDetector.getEnvironment;
|
|
263
|
-
if (runtime === "node") {
|
|
264
|
-
const { existsSync } = await Promise.resolve().then(() => require("fs"));
|
|
265
|
-
fileExists = existsSync(filePath);
|
|
266
|
-
}
|
|
267
|
-
else if (runtime === "bun") {
|
|
268
|
-
fileExists = Bun.file(filePath).exists();
|
|
269
|
-
}
|
|
270
|
-
else if (runtime === "deno") {
|
|
271
|
-
try {
|
|
272
|
-
await Deno.stat(filePath);
|
|
273
|
-
fileExists = true;
|
|
274
|
-
}
|
|
275
|
-
catch {
|
|
276
|
-
fileExists = false;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
if (!fileExists) {
|
|
280
|
-
throw Error("File not found");
|
|
281
|
-
}
|
|
282
|
-
let fileBuffer;
|
|
283
|
-
if (runtime === "node") {
|
|
284
|
-
const { readFileSync } = await Promise.resolve().then(() => require("fs"));
|
|
285
|
-
fileBuffer = await readFileSync(filePath);
|
|
286
|
-
}
|
|
287
|
-
else if (runtime === "bun") {
|
|
288
|
-
fileBuffer = await Bun.file(filePath)
|
|
289
|
-
.arrayBuffer()
|
|
290
|
-
.then((buf) => new Uint8Array(buf));
|
|
291
|
-
}
|
|
292
|
-
else if (runtime === "deno") {
|
|
293
|
-
fileBuffer = await Deno.readFile(filePath);
|
|
294
|
-
}
|
|
295
|
-
return this.#handleResponse(fileBuffer, {
|
|
296
|
-
status: 200,
|
|
297
|
-
headers: {
|
|
298
|
-
"Content-Disposition": `attachment; filename="${fileName}"`,
|
|
299
|
-
"Content-Type": "application/octet-stream",
|
|
300
|
-
"Content-Length": fileBuffer.byteLength.toString(),
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
catch (error) {
|
|
305
|
-
throw Error("Internal Server Error" + error?.message);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
async sendFile(filePath, ...args) {
|
|
309
|
-
try {
|
|
310
|
-
const runtime = environment_1.EnvironmentDetector.getEnvironment;
|
|
311
|
-
const resolvedPath = filePath;
|
|
312
|
-
let fileExists = false;
|
|
313
|
-
if (runtime === "node") {
|
|
314
|
-
const { existsSync } = await Promise.resolve().then(() => require("fs"));
|
|
315
|
-
fileExists = existsSync(resolvedPath);
|
|
316
|
-
}
|
|
317
|
-
else if (runtime === "bun") {
|
|
318
|
-
fileExists = Bun.file(resolvedPath).exists();
|
|
319
|
-
}
|
|
320
|
-
else if (runtime === "deno") {
|
|
321
|
-
try {
|
|
322
|
-
await Deno.stat(resolvedPath);
|
|
323
|
-
fileExists = true;
|
|
324
|
-
}
|
|
325
|
-
catch {
|
|
326
|
-
fileExists = false;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (!fileExists) {
|
|
330
|
-
throw Error("File not found");
|
|
331
|
-
}
|
|
332
|
-
let fileSize = 0;
|
|
333
|
-
if (runtime === "node") {
|
|
334
|
-
const { statSync } = await Promise.resolve().then(() => require("fs"));
|
|
335
|
-
fileSize = statSync(resolvedPath).size;
|
|
336
|
-
}
|
|
337
|
-
else if (runtime === "bun") {
|
|
338
|
-
fileSize = (await Bun.file(resolvedPath).arrayBuffer()).byteLength;
|
|
339
|
-
}
|
|
340
|
-
else if (runtime === "deno") {
|
|
341
|
-
const fileInfo = await Deno.stat(resolvedPath);
|
|
342
|
-
fileSize = fileInfo.size;
|
|
343
|
-
}
|
|
344
|
-
const ext = filePath.split(".").pop()?.toLowerCase() || "";
|
|
345
|
-
const mimeType = staticFile_1.mimeTypes[ext] || staticFile_1.defaultMimeType;
|
|
346
|
-
let fileStream;
|
|
347
|
-
if (runtime === "node") {
|
|
348
|
-
const { createReadStream } = await Promise.resolve().then(() => require("fs"));
|
|
349
|
-
fileStream = createReadStream(resolvedPath);
|
|
350
|
-
}
|
|
351
|
-
else if (runtime === "bun") {
|
|
352
|
-
fileStream = Bun.file(resolvedPath).stream();
|
|
353
|
-
}
|
|
354
|
-
else if (runtime === "deno") {
|
|
355
|
-
const file = await Deno.open(resolvedPath, { read: true });
|
|
356
|
-
fileStream = file.readable;
|
|
357
|
-
}
|
|
358
|
-
let headers = {
|
|
359
|
-
"Content-Type": mimeType,
|
|
360
|
-
"Content-Length": fileSize.toString(),
|
|
361
|
-
};
|
|
362
|
-
let fileName = "";
|
|
363
|
-
if (typeof args[0] === "string") {
|
|
364
|
-
fileName = args[0];
|
|
365
|
-
if (typeof args[1] === "object") {
|
|
366
|
-
headers = { ...headers, ...args[1] };
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
else if (typeof args[0] === "object") {
|
|
370
|
-
headers = { ...headers, ...args[0] };
|
|
371
|
-
}
|
|
372
|
-
if (fileName) {
|
|
373
|
-
headers["Content-Disposition"] = `attachment; filename="${fileName}"`;
|
|
374
|
-
}
|
|
375
|
-
return this.#handleResponse(fileStream, {
|
|
376
|
-
status: 200,
|
|
377
|
-
headers,
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
catch (error) {
|
|
381
|
-
throw Error("Internal Server Error" + error?.message);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
#handleResponse(body, { headers, status }) {
|
|
385
|
-
let response = new Response(body, {
|
|
386
|
-
status: status,
|
|
387
|
-
headers,
|
|
388
|
-
});
|
|
389
|
-
let clone = response.clone();
|
|
390
|
-
this.res = response;
|
|
391
|
-
return clone;
|
|
392
|
-
}
|
|
393
|
-
get req() {
|
|
394
|
-
return new request_1.Request(this.#rawRequest, this.params, this.#remoteAddress);
|
|
395
|
-
}
|
|
396
|
-
set params(params) {
|
|
397
|
-
this.#params = params;
|
|
398
|
-
}
|
|
399
|
-
get params() {
|
|
400
|
-
return this.#params;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
exports.Context = Context;
|
|
404
|
-
function serializeOptions(options) {
|
|
405
|
-
const parts = [];
|
|
406
|
-
if (options.maxAge) {
|
|
407
|
-
parts.push(`Max-Age=${options.maxAge}`);
|
|
408
|
-
}
|
|
409
|
-
if (options.expires) {
|
|
410
|
-
parts.push(`Expires=${options.expires.toUTCString()}`);
|
|
411
|
-
}
|
|
412
|
-
if (options.path) {
|
|
413
|
-
parts.push(`Path=${options.path}`);
|
|
414
|
-
}
|
|
415
|
-
if (options.domain) {
|
|
416
|
-
parts.push(`Domain=${options.domain}`);
|
|
417
|
-
}
|
|
418
|
-
if (options.secure) {
|
|
419
|
-
parts.push(`Secure`);
|
|
420
|
-
}
|
|
421
|
-
if (options.httpOnly) {
|
|
422
|
-
parts.push(`HttpOnly`);
|
|
423
|
-
}
|
|
424
|
-
if (options.sameSite) {
|
|
425
|
-
parts.push(`SameSite=${options.sameSite}`);
|
|
426
|
-
}
|
|
427
|
-
return parts.join("; ");
|
|
428
|
-
}
|
package/dist/cjs/environment.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnvironmentDetector = void 0;
|
|
4
|
-
class EnvironmentDetector {
|
|
5
|
-
static get getEnvironment() {
|
|
6
|
-
if (typeof Bun !== "undefined")
|
|
7
|
-
return "bun";
|
|
8
|
-
if (typeof Deno !== "undefined")
|
|
9
|
-
return "deno";
|
|
10
|
-
if (typeof process !== "undefined" && process.versions?.node)
|
|
11
|
-
return "node";
|
|
12
|
-
return "unknown";
|
|
13
|
-
}
|
|
14
|
-
static detectProtocol(req) {
|
|
15
|
-
try {
|
|
16
|
-
if (this.getEnvironment === "node") {
|
|
17
|
-
return req?.socket?.encrypted ? "https" : "http";
|
|
18
|
-
}
|
|
19
|
-
return "unknown";
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
throw new Error("Failed to detect protocol.");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
static getHost(headers) {
|
|
26
|
-
try {
|
|
27
|
-
return headers?.get("host") || "unknown";
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
throw new Error("Failed to get host.");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.EnvironmentDetector = EnvironmentDetector;
|
package/dist/cjs/header.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HeadersParser = void 0;
|
|
4
|
-
class HeadersParser {
|
|
5
|
-
headers = new Map();
|
|
6
|
-
constructor(init) {
|
|
7
|
-
if (init) {
|
|
8
|
-
this.add(init);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
add(headers) {
|
|
12
|
-
if (Array.isArray(headers)) {
|
|
13
|
-
for (const [key, value] of headers) {
|
|
14
|
-
this.set(key, value);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
else if (typeof Headers !== "undefined" && headers instanceof Headers) {
|
|
18
|
-
for (const [key, value] of headers.entries()) {
|
|
19
|
-
this.set(key, value);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
else if (typeof headers === "object") {
|
|
23
|
-
for (const key in headers) {
|
|
24
|
-
if (Object.prototype.hasOwnProperty.call(headers, key)) {
|
|
25
|
-
this.set(key, headers[key]);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
set(key, value) {
|
|
32
|
-
this.headers.set(key.toLowerCase(), Array.isArray(value) ? value : [value]);
|
|
33
|
-
return this;
|
|
34
|
-
}
|
|
35
|
-
clear() {
|
|
36
|
-
this.headers.clear();
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
get(key) {
|
|
40
|
-
const values = this.headers.get(key.toLowerCase());
|
|
41
|
-
return values ? values[0] : undefined;
|
|
42
|
-
}
|
|
43
|
-
getAll(key) {
|
|
44
|
-
return this.headers.get(key.toLowerCase()) || [];
|
|
45
|
-
}
|
|
46
|
-
has(key) {
|
|
47
|
-
return this.headers.has(key.toLowerCase());
|
|
48
|
-
}
|
|
49
|
-
delete(key) {
|
|
50
|
-
return this.headers.delete(key.toLowerCase());
|
|
51
|
-
}
|
|
52
|
-
append(key, value) {
|
|
53
|
-
const lowerKey = key.toLowerCase();
|
|
54
|
-
if (this.headers.has(lowerKey)) {
|
|
55
|
-
this.headers.get(lowerKey).push(value);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
this.headers.set(lowerKey, [value]);
|
|
59
|
-
}
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
entries() {
|
|
63
|
-
return this.headers.entries();
|
|
64
|
-
}
|
|
65
|
-
keys() {
|
|
66
|
-
return this.headers.keys();
|
|
67
|
-
}
|
|
68
|
-
values() {
|
|
69
|
-
return this.headers.values();
|
|
70
|
-
}
|
|
71
|
-
forEach(callback) {
|
|
72
|
-
for (const [key, value] of this.headers) {
|
|
73
|
-
callback(value, key);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
toObject() {
|
|
77
|
-
const obj = {};
|
|
78
|
-
for (const [key, value] of this.headers.entries()) {
|
|
79
|
-
obj[key] = value.length > 1 ? value : value[0];
|
|
80
|
-
}
|
|
81
|
-
return obj;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.HeadersParser = HeadersParser;
|
|
85
|
-
Object.defineProperty(HeadersParser, "name", { value: "Headers" });
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateID = generateID;
|
|
4
|
-
function generateID() {
|
|
5
|
-
const timestamp = Date.now().toString(16);
|
|
6
|
-
const random = Math.floor(Math.random() * 0xffffffffffff)
|
|
7
|
-
.toString(16)
|
|
8
|
-
.padStart(12, "0");
|
|
9
|
-
const pid = (process.pid % 0x10000).toString(16).padStart(4, "0");
|
|
10
|
-
return `${timestamp}-${random}-${pid}`;
|
|
11
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadEnv = loadEnv;
|
|
4
|
-
const environment_1 = require("../environment");
|
|
5
|
-
function parseEnvFile(filePath, result) {
|
|
6
|
-
try {
|
|
7
|
-
let fileExists = false;
|
|
8
|
-
let runtime = environment_1.EnvironmentDetector.getEnvironment;
|
|
9
|
-
if (runtime === "node" || runtime === "bun") {
|
|
10
|
-
const { existsSync } = require("fs");
|
|
11
|
-
fileExists = existsSync(filePath);
|
|
12
|
-
}
|
|
13
|
-
else if (runtime === "deno") {
|
|
14
|
-
try {
|
|
15
|
-
Deno.statSync(filePath);
|
|
16
|
-
fileExists = true;
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
fileExists = false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (!fileExists) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
let fileContent = "";
|
|
26
|
-
if (runtime === "node" || runtime === "bun") {
|
|
27
|
-
const { readFileSync } = require("fs");
|
|
28
|
-
fileContent = readFileSync(filePath, "utf8");
|
|
29
|
-
}
|
|
30
|
-
else if (runtime === "deno") {
|
|
31
|
-
fileContent = new TextDecoder("utf-8").decode(Deno.readFileSync(filePath));
|
|
32
|
-
}
|
|
33
|
-
const lines = fileContent.split("\n");
|
|
34
|
-
for (const line of lines) {
|
|
35
|
-
const trimmedLine = line.trim();
|
|
36
|
-
if (!trimmedLine || trimmedLine.startsWith("#"))
|
|
37
|
-
continue;
|
|
38
|
-
const [key, value] = trimmedLine.split("=", 2).map((part) => part.trim());
|
|
39
|
-
if (key && value) {
|
|
40
|
-
const parsedValue = value
|
|
41
|
-
.replace(/^"(.*)"$/, "$1")
|
|
42
|
-
.replace(/^'(.*)'$/, "$1");
|
|
43
|
-
result[key] = parsedValue;
|
|
44
|
-
if (runtime === "node" || runtime === "bun") {
|
|
45
|
-
process.env[key] = parsedValue;
|
|
46
|
-
}
|
|
47
|
-
else if (runtime === "deno") {
|
|
48
|
-
Deno.env.set(key, parsedValue);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
console.error(`[dotenv] Error parsing file: ${filePath}`, error);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function loadEnv(basePath = "./") {
|
|
58
|
-
const result = {};
|
|
59
|
-
const envFiles = [
|
|
60
|
-
".env",
|
|
61
|
-
".env.local",
|
|
62
|
-
`.env.${process?.env?.NODE_ENV || "development"}`,
|
|
63
|
-
`.env.${process?.env?.NODE_ENV || "development"}.local`,
|
|
64
|
-
];
|
|
65
|
-
for (const envFile of envFiles) {
|
|
66
|
-
parseEnvFile(`${basePath}${envFile}`, result);
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
}
|
package/dist/cjs/helper/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.loadEnv = void 0;
|
|
18
|
-
__exportStar(require("./common"), exports);
|
|
19
|
-
var env_parser_1 = require("./env-parser");
|
|
20
|
-
Object.defineProperty(exports, "loadEnv", { enumerable: true, get: function () { return env_parser_1.loadEnv; } });
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cors = cors;
|
|
4
|
-
function cors(option = {}) {
|
|
5
|
-
const { methods, allowedHeaders, credentials, exposedHeaders, maxAge, origin, } = option;
|
|
6
|
-
return async (ctx, next) => {
|
|
7
|
-
const reqOrigin = ctx.req.headers.get("origin") || "";
|
|
8
|
-
let allowOrigin = "*";
|
|
9
|
-
if (typeof origin === "string") {
|
|
10
|
-
allowOrigin = origin;
|
|
11
|
-
}
|
|
12
|
-
else if (origin instanceof RegExp) {
|
|
13
|
-
allowOrigin = origin.test(reqOrigin) ? reqOrigin : "";
|
|
14
|
-
}
|
|
15
|
-
else if (Array.isArray(origin)) {
|
|
16
|
-
const isAllowed = origin.some((item) => {
|
|
17
|
-
if (typeof item === "string") {
|
|
18
|
-
return item === reqOrigin;
|
|
19
|
-
}
|
|
20
|
-
else if (item instanceof RegExp) {
|
|
21
|
-
return item.test(reqOrigin);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
allowOrigin = isAllowed ? reqOrigin : "";
|
|
25
|
-
}
|
|
26
|
-
else if (typeof origin === "function") {
|
|
27
|
-
allowOrigin = origin(reqOrigin) ? reqOrigin : "";
|
|
28
|
-
}
|
|
29
|
-
ctx.headers.set("Access-Control-Allow-Origin", allowOrigin);
|
|
30
|
-
ctx.headers.set("Access-Control-Allow-Methods", (methods || ["GET", "POST", "PUT", "DELETE"]).join(", "));
|
|
31
|
-
ctx.headers.set("Access-Control-Allow-Headers", (allowedHeaders || ["Content-Type", "Authorization"]).join(", "));
|
|
32
|
-
if (exposedHeaders) {
|
|
33
|
-
ctx.headers.set("Access-Control-Expose-Headers", exposedHeaders.join(", "));
|
|
34
|
-
}
|
|
35
|
-
if (credentials) {
|
|
36
|
-
ctx.headers.set("Access-Control-Allow-Credentials", "true");
|
|
37
|
-
}
|
|
38
|
-
if (maxAge) {
|
|
39
|
-
ctx.headers.set("Access-Control-Max-Age", maxAge.toString());
|
|
40
|
-
}
|
|
41
|
-
if (ctx.req.method === "OPTIONS") {
|
|
42
|
-
return new Response(null, {
|
|
43
|
-
status: 204,
|
|
44
|
-
headers: ctx.headers.toObject(),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return await next();
|
|
48
|
-
};
|
|
49
|
-
}
|