@mahameru/diatrema 0.0.2 → 0.0.4

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.
Files changed (101) hide show
  1. package/diatrema-DBO4yaCD.d.ts +95 -0
  2. package/diatrema-Fd7aehcd.d.cts +95 -0
  3. package/diatrema.cjs +70 -52
  4. package/diatrema.cjs.map +1 -1
  5. package/diatrema.d.cts +6 -72
  6. package/diatrema.d.ts +4 -71
  7. package/diatrema.js +70 -52
  8. package/diatrema.js.map +1 -1
  9. package/helpers.cjs +2 -18
  10. package/helpers.cjs.map +1 -1
  11. package/helpers.d.cts +1 -6
  12. package/helpers.d.ts +1 -6
  13. package/helpers.js +1 -16
  14. package/helpers.js.map +1 -1
  15. package/index.cjs +4 -18
  16. package/index.cjs.map +1 -1
  17. package/index.d.cts +4 -13
  18. package/index.d.ts +4 -13
  19. package/index.js +2 -9
  20. package/index.js.map +1 -1
  21. package/logger.cjs +10 -5
  22. package/logger.cjs.map +1 -1
  23. package/logger.d.cts +1 -1
  24. package/logger.d.ts +1 -1
  25. package/logger.js +10 -5
  26. package/logger.js.map +1 -1
  27. package/mahameru-plugin.cjs +113 -0
  28. package/mahameru-plugin.cjs.map +1 -0
  29. package/mahameru-plugin.d.cts +4 -0
  30. package/mahameru-plugin.d.ts +4 -0
  31. package/mahameru-plugin.js +89 -0
  32. package/mahameru-plugin.js.map +1 -0
  33. package/package.json +4 -3
  34. package/scripts/preinstall.cjs +10 -0
  35. package/scripts/preinstall.cjs.map +1 -0
  36. package/scripts/preinstall.d.cts +2 -0
  37. package/scripts/preinstall.d.ts +2 -0
  38. package/scripts/preinstall.js +9 -9
  39. package/scripts/preinstall.js.map +1 -0
  40. package/types.cjs +0 -23
  41. package/types.cjs.map +1 -1
  42. package/types.d.cts +5 -3
  43. package/types.d.ts +5 -3
  44. package/types.js +0 -15
  45. package/types.js.map +1 -1
  46. package/container-error.cjs +0 -45
  47. package/container-error.cjs.map +0 -1
  48. package/container-error.d.cts +0 -7
  49. package/container-error.d.ts +0 -7
  50. package/container-error.js +0 -22
  51. package/container-error.js.map +0 -1
  52. package/container.cjs +0 -318
  53. package/container.cjs.map +0 -1
  54. package/container.d.cts +0 -60
  55. package/container.d.ts +0 -60
  56. package/container.js +0 -285
  57. package/container.js.map +0 -1
  58. package/http-server-error.cjs +0 -44
  59. package/http-server-error.cjs.map +0 -1
  60. package/http-server-error.d.cts +0 -7
  61. package/http-server-error.d.ts +0 -7
  62. package/http-server-error.js +0 -21
  63. package/http-server-error.js.map +0 -1
  64. package/http-server.cjs +0 -384
  65. package/http-server.cjs.map +0 -1
  66. package/http-server.d.cts +0 -81
  67. package/http-server.d.ts +0 -81
  68. package/http-server.js +0 -361
  69. package/http-server.js.map +0 -1
  70. package/mahameru-request.cjs +0 -79
  71. package/mahameru-request.cjs.map +0 -1
  72. package/mahameru-request.d.cts +0 -3
  73. package/mahameru-request.d.ts +0 -3
  74. package/mahameru-request.js +0 -56
  75. package/mahameru-request.js.map +0 -1
  76. package/mahameru-response.cjs +0 -71
  77. package/mahameru-response.cjs.map +0 -1
  78. package/mahameru-response.d.cts +0 -17
  79. package/mahameru-response.d.ts +0 -17
  80. package/mahameru-response.js +0 -48
  81. package/mahameru-response.js.map +0 -1
  82. package/mahameru-server-error.cjs +0 -54
  83. package/mahameru-server-error.cjs.map +0 -1
  84. package/mahameru-server-error.d.cts +0 -19
  85. package/mahameru-server-error.d.ts +0 -19
  86. package/mahameru-server-error.js +0 -31
  87. package/mahameru-server-error.js.map +0 -1
  88. package/module-error.cjs +0 -46
  89. package/module-error.cjs.map +0 -1
  90. package/module-error.d.cts +0 -12
  91. package/module-error.d.ts +0 -12
  92. package/module-error.js +0 -23
  93. package/module-error.js.map +0 -1
  94. package/route.cjs +0 -128
  95. package/route.cjs.map +0 -1
  96. package/route.d.cts +0 -46
  97. package/route.d.ts +0 -46
  98. package/route.js +0 -105
  99. package/route.js.map +0 -1
  100. package/types-BmFqDpSs.d.ts +0 -113
  101. package/types-Cd6Gkoxx.d.cts +0 -113
package/http-server.js DELETED
@@ -1,361 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { createServer, IncomingMessage, Server, ServerResponse } from "node:http";
4
- import { join } from "node:path";
5
- import { readFile } from "node:fs/promises";
6
- import { exists } from "./helpers.js";
7
- class HttpServer {
8
- static {
9
- __name(this, "HttpServer");
10
- }
11
- #options;
12
- defaultOptions = {
13
- host: "127.0.0.1",
14
- port: 3e3,
15
- dev: false,
16
- keepAliveTimeout: 6e4,
17
- disableHttpSignature: false,
18
- httpServerSignature: "MahameruJS",
19
- httpServerMessage: "Indonesia Bisa!",
20
- allowedOrigins: void 0,
21
- allowedIps: void 0,
22
- allowedHosts: void 0,
23
- trailingSlash: true,
24
- rootPath: process.cwd(),
25
- get faviconFilePath() {
26
- return join(this.rootPath, "node_modules", "mahameru", "favicon.ico");
27
- },
28
- suportedHTTPMethods: ["DELETE", "GET", "OPTIONS", "PATCH", "POST", "PUT"]
29
- };
30
- httpServer;
31
- isShuttingDown = false;
32
- dependencies;
33
- constructor(arg1, arg2) {
34
- if (typeof arg2 === "undefined") {
35
- this.dependencies = arg1;
36
- this.#options = this.defaultOptions;
37
- } else {
38
- this.#options = {
39
- ...this.defaultOptions,
40
- ...arg1
41
- };
42
- this.dependencies = arg2;
43
- }
44
- this.httpServer = this.create();
45
- this.httpServer.on("error", (error) => {
46
- if (error instanceof Error && "code" in error && error.code === "EADDRINUSE") {
47
- const newError = error;
48
- throw new this.dependencies.MahameruServerError(`Port ${newError.port} is already in use`, {
49
- code: newError.code,
50
- address: newError.address,
51
- port: newError.port
52
- });
53
- }
54
- throw error;
55
- });
56
- }
57
- listen() {
58
- return new Promise((resolve) => {
59
- this.httpServer.listen(this.#options.port, this.#options.host, () => {
60
- const address = this.httpServer.address();
61
- resolve({
62
- port: address && typeof address !== "string" ? address.port : this.#options.port,
63
- host: address && typeof address !== "string" ? address.address : this.#options.host
64
- });
65
- });
66
- });
67
- }
68
- close() {
69
- return new Promise((resolve, reject) => {
70
- if (!this.httpServer.listening) {
71
- resolve();
72
- return;
73
- }
74
- this.httpServer.close((error) => {
75
- if (error) {
76
- reject(error);
77
- return;
78
- }
79
- resolve();
80
- });
81
- });
82
- }
83
- setIsShuttingDown(isShuttingDown) {
84
- this.isShuttingDown = isShuttingDown;
85
- }
86
- get listening() {
87
- return this.httpServer.listening;
88
- }
89
- get options() {
90
- return this.#options;
91
- }
92
- setOptions(options) {
93
- this.#options = {
94
- ...this.defaultOptions,
95
- ...options
96
- };
97
- if (options.rootPath) {
98
- this.#options.rootPath = options.rootPath;
99
- if (!options.faviconFilePath)
100
- this.#options.faviconFilePath = join(this.#options.rootPath, "node_modules", "mahameru", "favicon.ico");
101
- }
102
- }
103
- create() {
104
- const httpServer = createServer(async (request, response) => await this.handleRequest(request, response));
105
- httpServer.keepAliveTimeout = this.#options.keepAliveTimeout;
106
- httpServer.headersTimeout = httpServer.keepAliveTimeout + 1e3;
107
- return httpServer;
108
- }
109
- async handleRequest(request, response) {
110
- const mahameruRequest = new this.dependencies.MahameruRequest(request);
111
- const rawReqPath = mahameruRequest.url.split("?")[0] || "/";
112
- const rawReqUrl = rawReqPath.replace(/\/+/g, "/");
113
- const matchUrl = this.dependencies.route.normalizePathForMatching(rawReqUrl);
114
- const method = mahameruRequest.method;
115
- try {
116
- if (this.isShuttingDown)
117
- response.setHeader("Connection", "close");
118
- if (typeof this.#options.allowedIps !== "undefined" && mahameruRequest.ipAddress) {
119
- if (!this.#options.allowedIps.includes(mahameruRequest.ipAddress))
120
- return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: "Forbidden" }), { status: 403 }));
121
- }
122
- if (typeof this.#options.allowedHosts !== "undefined" && Array.isArray(this.#options.allowedHosts)) {
123
- if (!this.#options.allowedHosts.includes(mahameruRequest.headers.host))
124
- return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: "Forbidden" }), { status: 403 }));
125
- }
126
- if (mahameruRequest.url === "/favicon.ico")
127
- return await this.handleFaviconRequest(mahameruRequest, response);
128
- if (mahameruRequest.headers.origin && this.#options.allowedOrigins && !this.#options.allowedOrigins.includes(mahameruRequest.headers.origin))
129
- return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: "Forbidden" }), { status: 403 }));
130
- if (this.#options.trailingSlash === false && rawReqUrl.length > 1 && rawReqUrl.endsWith("/")) {
131
- const cleanUrl = matchUrl;
132
- const queryStr = mahameruRequest.url?.split("?")[1];
133
- const redirectPath = cleanUrl + (queryStr ? `?${queryStr}` : "");
134
- return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ message: "Redirecting to non-trailing slash URL" }), { status: 301, headers: { Location: redirectPath } }));
135
- }
136
- if (rawReqPath !== rawReqUrl) {
137
- const queryStr = mahameruRequest.url?.includes("?") ? "?" + mahameruRequest.url.split("?")[1] : "";
138
- const redirectPath = rawReqUrl + queryStr;
139
- return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ message: "Redirecting to normalized URL" }), { status: 301, headers: { Location: redirectPath } }));
140
- }
141
- const { matchedRoute, matchResult, notFoundResponse } = await this.dependencies.route.resolveRoute(mahameruRequest);
142
- const middlewareHandler = this.dependencies.container.middlewareHandler;
143
- if (!matchedRoute || !matchResult) {
144
- const routeHandler = /* @__PURE__ */ __name(async () => notFoundResponse, "routeHandler");
145
- const rawResponse = middlewareHandler ? await middlewareHandler({
146
- request: mahameruRequest,
147
- container: this.dependencies.container.mahameruContainer,
148
- method,
149
- params: {},
150
- path: rawReqUrl,
151
- status: 404
152
- }, false, routeHandler) : await routeHandler();
153
- const mahameruResponse2 = this.normalizeMahameruResponse(rawResponse, "Middleware must return a MahameruResponse instance.");
154
- return this.sendResponse(response, mahameruResponse2);
155
- }
156
- const handler = matchedRoute.routeHandlers[method];
157
- if (!handler) {
158
- response.writeHead(405);
159
- return response.end(JSON.stringify({ error: `Method ${method} Not Allowed` }));
160
- }
161
- const params = {};
162
- if (matchResult && matchedRoute.paramNames.length > 0)
163
- matchedRoute.paramNames.forEach((name, index) => {
164
- params[name] = matchResult[index + 1];
165
- });
166
- const mahameruResponse = middlewareHandler ? await this.runMiddlewarePipeline(
167
- middlewareHandler,
168
- {
169
- request: mahameruRequest,
170
- container: this.dependencies.container.mahameruContainer,
171
- params,
172
- path: rawReqUrl,
173
- method,
174
- status: 200
175
- },
176
- () => handler(mahameruRequest, this.dependencies.container.mahameruContainer, { params })
177
- ) : await handler(
178
- mahameruRequest,
179
- this.dependencies.container.mahameruContainer,
180
- { params }
181
- );
182
- return this.sendResponse(response, mahameruResponse);
183
- } catch (error) {
184
- console.error(error);
185
- const errorResponse = await this.runErrorHandler(
186
- error,
187
- {
188
- request: mahameruRequest,
189
- container: this.dependencies.container.mahameruContainer,
190
- path: rawReqUrl,
191
- method,
192
- params: {},
193
- status: 200
194
- }
195
- );
196
- return this.sendResponse(response, errorResponse);
197
- }
198
- }
199
- async handleFaviconRequest(request, response) {
200
- let targetFaviconPath = void 0;
201
- const customFaviconPath = join(this.#options.rootPath, "favicon.ico");
202
- if (await exists(customFaviconPath)) {
203
- targetFaviconPath = customFaviconPath;
204
- } else if (this.#options.faviconFilePath && await exists(this.#options.faviconFilePath)) {
205
- targetFaviconPath = this.#options.faviconFilePath;
206
- }
207
- if (targetFaviconPath === void 0) {
208
- return this.sendResponse(
209
- response,
210
- new this.dependencies.MahameruResponse("Not Found", { status: 404, headers: { "Content-Type": "text/plain" } })
211
- );
212
- }
213
- const favicon = await readFile(targetFaviconPath);
214
- const middlewareHandler = this.dependencies.container.middlewareHandler;
215
- if (middlewareHandler) {
216
- const middlewareResponse = await middlewareHandler({
217
- request,
218
- container: this.dependencies.container.mahameruContainer,
219
- method: request.method,
220
- params: {},
221
- path: request.path,
222
- status: 200
223
- }, false, async () => new this.dependencies.MahameruResponse(favicon, { status: 200 }));
224
- const normalized = this.normalizeMahameruResponse(middlewareResponse, "Middleware error");
225
- const headers = new Headers(normalized.headers);
226
- if (normalized.status === 200) {
227
- headers.set("Content-Type", "image/x-icon");
228
- if (!headers.has("Cache-Control")) {
229
- headers.set("Cache-Control", "public, max-age=31536000");
230
- }
231
- }
232
- return this.sendResponse(response, new this.dependencies.MahameruResponse(normalized.body, {
233
- status: normalized.status,
234
- headers
235
- }));
236
- }
237
- const faviconResponse = new this.dependencies.MahameruResponse(favicon, {
238
- status: 200,
239
- headers: {
240
- "Content-Type": "image/x-icon",
241
- "Cache-Control": "public, max-age=31536000"
242
- }
243
- });
244
- return this.sendResponse(response, faviconResponse);
245
- }
246
- sendResponse(response, mahameruResponse) {
247
- if (!mahameruResponse)
248
- mahameruResponse = new this.dependencies.MahameruResponse(void 0, { status: 204 });
249
- mahameruResponse.headers.forEach((value, key) => {
250
- response.setHeader(key, value);
251
- });
252
- if (!this.#options.disableHttpSignature) {
253
- response.setHeader("X-Powered-By", this.#options.httpServerSignature);
254
- response.setHeader("X-Message", this.#options.httpServerMessage);
255
- }
256
- response.writeHead(mahameruResponse.status);
257
- let responseBody;
258
- if (typeof mahameruResponse.body === "string" || mahameruResponse.body instanceof Uint8Array || Buffer.isBuffer(mahameruResponse.body) || mahameruResponse.body === void 0 || mahameruResponse.body === null) {
259
- responseBody = mahameruResponse.body;
260
- } else {
261
- responseBody = JSON.stringify(mahameruResponse.body);
262
- }
263
- response.end(responseBody);
264
- this.dependencies.logger.info(response.req.method, response.statusCode, response.req.url);
265
- }
266
- async runMiddlewarePipeline(middleware, context, handler) {
267
- const isProtectedRoute = this.validateProtectedRoute(context.method, context.path);
268
- const response = await middleware(context, isProtectedRoute, async () => {
269
- const nextResponse = await handler();
270
- return this.normalizeMahameruResponse(
271
- nextResponse,
272
- "Route handlers and next() must resolve to MahameruResponse."
273
- );
274
- });
275
- return this.normalizeMahameruResponse(
276
- response,
277
- "Global middleware must return a MahameruResponse instance."
278
- );
279
- }
280
- async runErrorHandler(error, context) {
281
- const fallbackResponse = this.createInternalServerErrorResponse(error);
282
- if (!this.dependencies.container.errorHandler)
283
- return fallbackResponse;
284
- try {
285
- const handlerResponse = await this.dependencies.container.errorHandler(
286
- {
287
- ...context,
288
- error
289
- },
290
- async () => fallbackResponse
291
- );
292
- return this.normalizeMahameruResponse(
293
- handlerResponse,
294
- "Error handler must return a MahameruResponse instance."
295
- );
296
- } catch (handlerError) {
297
- return fallbackResponse;
298
- }
299
- }
300
- createInternalServerErrorResponse(error) {
301
- const serverError = error instanceof this.dependencies.HttpServerError ? error : new this.dependencies.HttpServerError(error instanceof Error ? error.message : void 0);
302
- return this.dependencies.MahameruResponse.json(
303
- { error: serverError.message },
304
- { status: serverError.statusCode }
305
- );
306
- }
307
- isMahameruResponseLike(value) {
308
- if (!value || typeof value !== "object") {
309
- return false;
310
- }
311
- if (!("status" in value) || typeof value.status !== "number") {
312
- return false;
313
- }
314
- if (!("body" in value)) {
315
- return false;
316
- }
317
- if (!("headers" in value) || value.headers === void 0) {
318
- return true;
319
- }
320
- if (value.headers instanceof Headers) {
321
- return true;
322
- }
323
- return typeof value.headers === "object" && value.headers !== null && !Array.isArray(value.headers);
324
- }
325
- normalizeMahameruResponse(value, errorMessage) {
326
- if (value instanceof this.dependencies.MahameruResponse)
327
- return value;
328
- if (!this.isMahameruResponseLike(value))
329
- throw new this.dependencies.HttpServerError(errorMessage);
330
- const normalizedHeaders = value.headers instanceof Headers ? Object.fromEntries(value.headers.entries()) : value.headers;
331
- return new this.dependencies.MahameruResponse(value.body, {
332
- status: value.status,
333
- headers: normalizedHeaders
334
- });
335
- }
336
- matchRoutePattern(currentPath, routePattern) {
337
- const regexPattern = routePattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\//g, "\\/").replace(/:[^/]+/g, "[^/]+");
338
- const regex = new RegExp(`^${regexPattern}$`);
339
- return regex.test(currentPath);
340
- }
341
- validateProtectedRoute(method, path) {
342
- if (path.endsWith("/"))
343
- path = path.slice(0, -1);
344
- return this.dependencies.container.protectedRoutes.some((route) => {
345
- if (typeof route === "string")
346
- return this.matchRoutePattern(path, route);
347
- const isPathMatch = this.matchRoutePattern(path, route.path);
348
- const isMethodMatch = route.methods.includes(method);
349
- return isPathMatch && isMethodMatch;
350
- });
351
- }
352
- requestLogger(response) {
353
- if (!this.#options.dev)
354
- return;
355
- this.dependencies.logger.info(`${response.req.method} ${response.statusCode} ${response.req.url}`);
356
- }
357
- }
358
- export {
359
- HttpServer
360
- };
361
- //# sourceMappingURL=http-server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/http-server.ts"],"sourcesContent":["import { createServer, IncomingMessage, Server, ServerResponse } from \"node:http\";\r\nimport { join } from \"node:path\";\r\nimport { readFile } from \"node:fs/promises\";\r\nimport { exists } from \"./helpers\";\r\nimport type { Route } from \"./route\";\r\nimport type { Container } from \"./container\";\r\nimport type { MahameruResponse } from \"./mahameru-response\";\r\nimport type { MahameruRequest } from \"./mahameru-request\";\r\nimport type { HTTPMethod, MahameruMiddleware, MahameruMiddlewareContext, MahameruNext, RequestParams } from \"./types\";\r\nimport type { HttpServerError } from \"./http-server-error\";\r\nimport type { Logger } from \"./logger\";\r\nimport type { MahameruServerError } from \"./mahameru-server-error\";\r\n\r\nexport type HttpServerDependencies = {\r\n route: Route;\r\n container: Container;\r\n logger: Logger;\r\n MahameruServerError: typeof MahameruServerError;\r\n HttpServerError: typeof HttpServerError;\r\n MahameruResponse: typeof MahameruResponse;\r\n MahameruRequest: typeof MahameruRequest;\r\n}\r\n\r\ntype DefaultHTTPResponse = ServerResponse<IncomingMessage> & {\r\n req: IncomingMessage;\r\n}\r\n\r\ntype HTTPServerInstance = Server<typeof IncomingMessage, typeof ServerResponse>\r\n\r\ninterface MahameruResponseLike {\r\n body: unknown;\r\n status: number;\r\n headers?: Headers | Record<string, string>;\r\n}\r\n\r\nexport type HttpServerOptions = {\r\n host: string;\r\n port: number;\r\n dev: boolean;\r\n keepAliveTimeout: number;\r\n disableHttpSignature: boolean;\r\n httpServerSignature: string;\r\n httpServerMessage: string;\r\n allowedOrigins?: string[];\r\n allowedIps?: string[];\r\n allowedHosts?: string[]\r\n trailingSlash: boolean;\r\n rootPath: string;\r\n faviconFilePath?: string;\r\n suportedHTTPMethods: HTTPMethod[]\r\n}\r\n\r\nexport class HttpServer {\r\n #options: HttpServerOptions;\r\n protected readonly defaultOptions: HttpServerOptions = {\r\n host: '127.0.0.1',\r\n port: 3000,\r\n dev: false,\r\n keepAliveTimeout: 60000,\r\n disableHttpSignature: false,\r\n httpServerSignature: 'MahameruJS',\r\n httpServerMessage: 'Indonesia Bisa!',\r\n allowedOrigins: undefined,\r\n allowedIps: undefined,\r\n allowedHosts: undefined,\r\n trailingSlash: true,\r\n rootPath: process.cwd(),\r\n get faviconFilePath(): string {\r\n return join(this.rootPath, 'node_modules', 'mahameru', 'favicon.ico');\r\n },\r\n suportedHTTPMethods: ['DELETE', 'GET', 'OPTIONS', 'PATCH', 'POST', 'PUT']\r\n }\r\n protected httpServer: HTTPServerInstance\r\n protected isShuttingDown = false\r\n protected dependencies: HttpServerDependencies;\r\n\r\n constructor(dependencies: HttpServerDependencies)\r\n constructor(options: Partial<HttpServerOptions>, dependencies: HttpServerDependencies)\r\n constructor(arg1: Partial<HttpServerOptions> | HttpServerDependencies, arg2?: HttpServerDependencies) {\r\n if (typeof arg2 === 'undefined') {\r\n this.dependencies = arg1 as HttpServerDependencies;\r\n this.#options = this.defaultOptions\r\n } else {\r\n this.#options = {\r\n ...this.defaultOptions,\r\n ...arg1 as Partial<HttpServerOptions>\r\n };\r\n this.dependencies = arg2;\r\n }\r\n\r\n this.httpServer = this.create();\r\n this.httpServer.on('error', (error: unknown) => {\r\n if (error instanceof Error && 'code' in error && error.code === 'EADDRINUSE') {\r\n const newError = error as any;\r\n\r\n throw new this.dependencies.MahameruServerError(`Port ${newError.port} is already in use`, {\r\n code: newError.code,\r\n address: newError.address,\r\n port: newError.port\r\n });\r\n }\r\n\r\n throw error;\r\n })\r\n }\r\n\r\n listen() {\r\n return new Promise<{ port: number; host: string }>((resolve) => {\r\n this.httpServer.listen(this.#options.port, this.#options.host, () => {\r\n const address = this.httpServer.address();\r\n\r\n resolve({\r\n port: address && typeof address !== \"string\" ? address.port : this.#options.port,\r\n host: address && typeof address !== \"string\" ? address.address : this.#options.host,\r\n });\r\n });\r\n });\r\n }\r\n\r\n close(): Promise<void> {\r\n return new Promise((resolve, reject) => {\r\n if (!this.httpServer.listening) {\r\n resolve();\r\n\r\n return;\r\n }\r\n\r\n this.httpServer.close((error) => {\r\n if (error) {\r\n reject(error);\r\n\r\n return;\r\n }\r\n\r\n resolve();\r\n });\r\n });\r\n }\r\n\r\n setIsShuttingDown(isShuttingDown: boolean) {\r\n this.isShuttingDown = isShuttingDown;\r\n }\r\n\r\n get listening(): boolean {\r\n return this.httpServer.listening\r\n }\r\n\r\n get options(): HttpServerOptions {\r\n return this.#options\r\n }\r\n\r\n public setOptions(options: Partial<HttpServerOptions>): void {\r\n this.#options = {\r\n ...this.defaultOptions,\r\n ...options\r\n }\r\n\r\n if (options.rootPath) {\r\n this.#options.rootPath = options.rootPath\r\n\r\n if (!options.faviconFilePath)\r\n this.#options.faviconFilePath = join(this.#options.rootPath, 'node_modules', 'mahameru', 'favicon.ico');\r\n }\r\n }\r\n\r\n protected create(): HTTPServerInstance {\r\n const httpServer = createServer(async (request, response) => await this.handleRequest(request, response));\r\n\r\n httpServer.keepAliveTimeout = this.#options.keepAliveTimeout;\r\n httpServer.headersTimeout = httpServer.keepAliveTimeout + 1000\r\n\r\n return httpServer;\r\n }\r\n\r\n protected async handleRequest(request: IncomingMessage, response: ServerResponse<IncomingMessage> & { req: IncomingMessage; }) {\r\n const mahameruRequest = new this.dependencies.MahameruRequest(request);\r\n const rawReqPath = mahameruRequest.url.split('?')[0] || '/';\r\n const rawReqUrl = rawReqPath.replace(/\\/+/g, '/');\r\n const matchUrl = this.dependencies.route.normalizePathForMatching(rawReqUrl);\r\n const method = mahameruRequest.method;\r\n\r\n try {\r\n if (this.isShuttingDown)\r\n response.setHeader('Connection', 'close');\r\n\r\n if (\r\n typeof this.#options.allowedIps !== 'undefined' &&\r\n mahameruRequest.ipAddress\r\n ) {\r\n if (!this.#options.allowedIps.includes(mahameruRequest.ipAddress))\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: 'Forbidden' }), { status: 403 }));\r\n }\r\n\r\n if (typeof this.#options.allowedHosts !== 'undefined' && Array.isArray(this.#options.allowedHosts))\r\n if (!this.#options.allowedHosts.includes(mahameruRequest.headers.host as string))\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: 'Forbidden' }), { status: 403 }));\r\n\r\n if (mahameruRequest.url === '/favicon.ico')\r\n return await this.handleFaviconRequest(mahameruRequest, response);\r\n\r\n if (\r\n mahameruRequest.headers.origin &&\r\n this.#options.allowedOrigins &&\r\n !this.#options.allowedOrigins.includes(mahameruRequest.headers.origin)\r\n )\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ error: 'Forbidden' }), { status: 403 }));\r\n\r\n if (this.#options.trailingSlash === false && rawReqUrl.length > 1 && rawReqUrl.endsWith('/')) {\r\n const cleanUrl = matchUrl;\r\n const queryStr = mahameruRequest.url?.split('?')[1];\r\n const redirectPath = cleanUrl + (queryStr ? `?${queryStr}` : '');\r\n\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ message: 'Redirecting to non-trailing slash URL' }), { status: 301, headers: { Location: redirectPath } }));\r\n }\r\n\r\n if (rawReqPath !== rawReqUrl) {\r\n const queryStr = mahameruRequest.url?.includes('?') ? '?' + mahameruRequest.url.split('?')[1] : '';\r\n const redirectPath = rawReqUrl + queryStr;\r\n\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(JSON.stringify({ message: 'Redirecting to normalized URL' }), { status: 301, headers: { Location: redirectPath } }));\r\n }\r\n\r\n const { matchedRoute, matchResult, notFoundResponse } = await this.dependencies.route.resolveRoute(mahameruRequest);\r\n const middlewareHandler = this.dependencies.container.middlewareHandler;\r\n\r\n if (!matchedRoute || !matchResult) {\r\n const routeHandler: MahameruNext = async () => notFoundResponse;\r\n const rawResponse = middlewareHandler\r\n ? await middlewareHandler({\r\n request: mahameruRequest,\r\n container: this.dependencies.container.mahameruContainer,\r\n method,\r\n params: {},\r\n path: rawReqUrl,\r\n status: 404\r\n }, false, routeHandler)\r\n : await routeHandler();\r\n\r\n const mahameruResponse = this.normalizeMahameruResponse(rawResponse, 'Middleware must return a MahameruResponse instance.');\r\n\r\n return this.sendResponse(response, mahameruResponse);\r\n }\r\n\r\n const handler = matchedRoute.routeHandlers[method];\r\n\r\n if (!handler) {\r\n response.writeHead(405);\r\n\r\n return response.end(JSON.stringify({ error: `Method ${method} Not Allowed` }));\r\n }\r\n\r\n const params: RequestParams = {};\r\n\r\n if (matchResult && matchedRoute.paramNames.length > 0)\r\n matchedRoute.paramNames.forEach((name, index) => {\r\n params[name] = matchResult[index + 1];\r\n });\r\n\r\n const mahameruResponse = middlewareHandler\r\n ? await this.runMiddlewarePipeline(\r\n middlewareHandler,\r\n {\r\n request: mahameruRequest,\r\n container: this.dependencies.container.mahameruContainer,\r\n params,\r\n path: rawReqUrl,\r\n method,\r\n status: 200\r\n },\r\n () => handler(mahameruRequest, this.dependencies.container.mahameruContainer, { params })\r\n )\r\n : await handler(\r\n mahameruRequest,\r\n this.dependencies.container.mahameruContainer,\r\n { params }\r\n );\r\n\r\n return this.sendResponse(response, mahameruResponse);\r\n } catch (error: unknown) {\r\n console.error(error);\r\n const errorResponse = await this.runErrorHandler(\r\n error,\r\n {\r\n request: mahameruRequest,\r\n container: this.dependencies.container.mahameruContainer,\r\n path: rawReqUrl,\r\n method,\r\n params: {},\r\n status: 200\r\n }\r\n );\r\n\r\n return this.sendResponse(response, errorResponse);\r\n }\r\n }\r\n\r\n protected async handleFaviconRequest(request: MahameruRequest, response: DefaultHTTPResponse) {\r\n let targetFaviconPath: string | undefined = undefined;\r\n const customFaviconPath = join(this.#options.rootPath, 'favicon.ico');\r\n\r\n if (await exists(customFaviconPath)) {\r\n targetFaviconPath = customFaviconPath;\r\n } else if (this.#options.faviconFilePath && await exists(this.#options.faviconFilePath)) {\r\n targetFaviconPath = this.#options.faviconFilePath;\r\n }\r\n\r\n if (targetFaviconPath === undefined) {\r\n return this.sendResponse(\r\n response,\r\n new this.dependencies.MahameruResponse('Not Found', { status: 404, headers: { 'Content-Type': 'text/plain' } })\r\n );\r\n }\r\n\r\n const favicon = await readFile(targetFaviconPath);\r\n const middlewareHandler = this.dependencies.container.middlewareHandler;\r\n\r\n if (middlewareHandler) {\r\n const middlewareResponse = await middlewareHandler({\r\n request,\r\n container: this.dependencies.container.mahameruContainer,\r\n method: request.method,\r\n params: {},\r\n path: request.path,\r\n status: 200\r\n }, false, async () => new this.dependencies.MahameruResponse(favicon, { status: 200 }));\r\n\r\n const normalized = this.normalizeMahameruResponse(middlewareResponse, 'Middleware error');\r\n const headers = new Headers(normalized.headers);\r\n\r\n if (normalized.status === 200) {\r\n headers.set('Content-Type', 'image/x-icon');\r\n\r\n if (!headers.has('Cache-Control')) {\r\n headers.set('Cache-Control', 'public, max-age=31536000');\r\n }\r\n }\r\n\r\n return this.sendResponse(response, new this.dependencies.MahameruResponse(normalized.body, {\r\n status: normalized.status,\r\n headers\r\n }));\r\n }\r\n\r\n const faviconResponse = new this.dependencies.MahameruResponse(favicon, {\r\n status: 200,\r\n headers: {\r\n 'Content-Type': 'image/x-icon',\r\n 'Cache-Control': 'public, max-age=31536000'\r\n }\r\n });\r\n\r\n return this.sendResponse(response, faviconResponse);\r\n }\r\n\r\n protected sendResponse(response: DefaultHTTPResponse, mahameruResponse?: MahameruResponse) {\r\n if (!mahameruResponse)\r\n mahameruResponse = new this.dependencies.MahameruResponse(undefined, { status: 204 });\r\n\r\n mahameruResponse.headers.forEach((value, key) => {\r\n response.setHeader(key, value);\r\n });\r\n\r\n if (!this.#options.disableHttpSignature) {\r\n response.setHeader('X-Powered-By', this.#options.httpServerSignature);\r\n response.setHeader('X-Message', this.#options.httpServerMessage);\r\n }\r\n\r\n response.writeHead(mahameruResponse.status);\r\n\r\n let responseBody: any;\r\n\r\n if (typeof mahameruResponse.body === 'string' ||\r\n mahameruResponse.body instanceof Uint8Array ||\r\n Buffer.isBuffer(mahameruResponse.body) ||\r\n mahameruResponse.body === undefined ||\r\n mahameruResponse.body === null) {\r\n\r\n responseBody = mahameruResponse.body;\r\n } else {\r\n responseBody = JSON.stringify(mahameruResponse.body);\r\n }\r\n\r\n response.end(responseBody);\r\n this.dependencies.logger.info(response.req.method, response.statusCode, response.req.url);\r\n }\r\n\r\n protected async runMiddlewarePipeline(\r\n middleware: MahameruMiddleware,\r\n context: MahameruMiddlewareContext,\r\n handler: () => Promise<MahameruResponse> | MahameruResponse\r\n ) {\r\n const isProtectedRoute = this.validateProtectedRoute(context.method, context.path);\r\n const response = await middleware(context, isProtectedRoute, async () => {\r\n const nextResponse = await handler();\r\n\r\n return this.normalizeMahameruResponse(\r\n nextResponse,\r\n 'Route handlers and next() must resolve to MahameruResponse.'\r\n );\r\n });\r\n\r\n return this.normalizeMahameruResponse(\r\n response,\r\n 'Global middleware must return a MahameruResponse instance.'\r\n );\r\n }\r\n\r\n protected async runErrorHandler(error: unknown, context: MahameruMiddlewareContext): Promise<MahameruResponse> {\r\n const fallbackResponse = this.createInternalServerErrorResponse(error);\r\n\r\n if (!this.dependencies.container.errorHandler)\r\n return fallbackResponse;\r\n\r\n try {\r\n const handlerResponse = await this.dependencies.container.errorHandler(\r\n {\r\n ...context,\r\n error\r\n },\r\n async () => fallbackResponse\r\n );\r\n\r\n return this.normalizeMahameruResponse(\r\n handlerResponse,\r\n 'Error handler must return a MahameruResponse instance.'\r\n );\r\n } catch (handlerError: unknown) {\r\n return fallbackResponse;\r\n }\r\n }\r\n\r\n protected createInternalServerErrorResponse(error: unknown): MahameruResponse {\r\n const serverError = error instanceof this.dependencies.HttpServerError\r\n ? error\r\n : new this.dependencies.HttpServerError(error instanceof Error ? error.message : undefined);\r\n\r\n return this.dependencies.MahameruResponse.json(\r\n { error: serverError.message },\r\n { status: serverError.statusCode }\r\n );\r\n }\r\n\r\n protected isMahameruResponseLike(value: unknown): value is MahameruResponseLike {\r\n if (!value || typeof value !== 'object') {\r\n return false;\r\n }\r\n\r\n if (!('status' in value) || typeof value.status !== 'number') {\r\n return false;\r\n }\r\n\r\n if (!('body' in value)) {\r\n return false;\r\n }\r\n\r\n if (!('headers' in value) || value.headers === undefined) {\r\n return true;\r\n }\r\n\r\n if (value.headers instanceof Headers) {\r\n return true;\r\n }\r\n\r\n return typeof value.headers === 'object' && value.headers !== null && !Array.isArray(value.headers);\r\n }\r\n\r\n protected normalizeMahameruResponse(value: unknown, errorMessage: string): MahameruResponse {\r\n if (value instanceof this.dependencies.MahameruResponse)\r\n return value;\r\n\r\n if (!this.isMahameruResponseLike(value))\r\n throw new this.dependencies.HttpServerError(errorMessage);\r\n\r\n const normalizedHeaders = value.headers instanceof Headers\r\n ? Object.fromEntries(value.headers.entries())\r\n : value.headers;\r\n\r\n return new this.dependencies.MahameruResponse(value.body, {\r\n status: value.status,\r\n headers: normalizedHeaders\r\n });\r\n }\r\n\r\n protected matchRoutePattern(currentPath: string, routePattern: string): boolean {\r\n const regexPattern = routePattern\r\n .replace(/[.+^${}()|[\\]\\\\]/g, '\\\\$&')\r\n .replace(/\\//g, '\\\\/')\r\n .replace(/:[^/]+/g, '[^/]+');\r\n\r\n const regex = new RegExp(`^${regexPattern}$`);\r\n return regex.test(currentPath);\r\n }\r\n\r\n protected validateProtectedRoute(method: HTTPMethod, path: string): boolean {\r\n if (path.endsWith('/'))\r\n path = path.slice(0, -1);\r\n\r\n return this.dependencies.container.protectedRoutes.some(route => {\r\n if (typeof route === 'string')\r\n return this.matchRoutePattern(path, route);\r\n\r\n const isPathMatch = this.matchRoutePattern(path, route.path);\r\n const isMethodMatch = route.methods.includes(method);\r\n\r\n return isPathMatch && isMethodMatch;\r\n });\r\n }\r\n\r\n protected requestLogger(response: DefaultHTTPResponse) {\r\n if (!this.#options.dev)\r\n return\r\n\r\n this.dependencies.logger.info(`${response.req.method} ${response.statusCode} ${response.req.url}`);\r\n }\r\n}\r\n"],"mappings":";;AAAA,SAAS,cAAc,iBAAiB,QAAQ,sBAAsB;AACtE,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAiDhB,MAAM,WAAW;AAAA,EApDxB,OAoDwB;AAAA;AAAA;AAAA,EACpB;AAAA,EACmB,iBAAoC;AAAA,IACnD,MAAM;AAAA,IACN,MAAM;AAAA,IACN,KAAK;AAAA,IACL,kBAAkB;AAAA,IAClB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,IACrB,mBAAmB;AAAA,IACnB,gBAAgB;AAAA,IAChB,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,eAAe;AAAA,IACf,UAAU,QAAQ,IAAI;AAAA,IACtB,IAAI,kBAA0B;AAC1B,aAAO,KAAK,KAAK,UAAU,gBAAgB,YAAY,aAAa;AAAA,IACxE;AAAA,IACA,qBAAqB,CAAC,UAAU,OAAO,WAAW,SAAS,QAAQ,KAAK;AAAA,EAC5E;AAAA,EACU;AAAA,EACA,iBAAiB;AAAA,EACjB;AAAA,EAIV,YAAY,MAA2D,MAA+B;AAClG,QAAI,OAAO,SAAS,aAAa;AAC7B,WAAK,eAAe;AACpB,WAAK,WAAW,KAAK;AAAA,IACzB,OAAO;AACH,WAAK,WAAW;AAAA,QACZ,GAAG,KAAK;AAAA,QACR,GAAG;AAAA,MACP;AACA,WAAK,eAAe;AAAA,IACxB;AAEA,SAAK,aAAa,KAAK,OAAO;AAC9B,SAAK,WAAW,GAAG,SAAS,CAAC,UAAmB;AAC5C,UAAI,iBAAiB,SAAS,UAAU,SAAS,MAAM,SAAS,cAAc;AAC1E,cAAM,WAAW;AAEjB,cAAM,IAAI,KAAK,aAAa,oBAAoB,QAAQ,SAAS,IAAI,sBAAsB;AAAA,UACvF,MA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BAAuB,KAAK;AAClC,YAAM,IAAI,KAAK,aAAa,gBAAgB,YAAY;AAE5D,UAAM,oBAAoB,MAAM,mBAAmB,UAC7C,OAAO,YAAY,MAAM,QAAQ,QAAQ,CAAC,IAC1C,MAAM;AAEZ,WAAO,IAAI,KAAK,aAAa,iBAAiB,MAAM,MAAM;AAAA,MACtD,QAAQ,MAAM;AAAA,MACd,SAAS;AAAA,IACb,CAAC;AAAA,EACL;AAAA,EAEU,kBAAkB,aAAqB,cAA+B;AAC5E,UAAM,eAAe,aAChB,QAAQ,qBAAqB,MAAM,EACnC,QAAQ,OAAO,KAAK,EACpB,QAAQ,WAAW,OAAO;AAE/B,UAAM,QAAQ,IAAI,OAAO,IAAI,YAAY,GAAG;AAC5C,WAAO,MAAM,KAAK,WAAW;AAAA,EACjC;AAAA,EAEU,uBAAuB,QAAoB,MAAuB;AACxE,QAAI,KAAK,SAAS,GAAG;AACjB,aAAO,KAAK,MAAM,GAAG,EAAE;AAE3B,WAAO,KAAK,aAAa,UAAU,gBAAgB,KAAK,WAAS;AAC7D,UAAI,OAAO,UAAU;AACjB,eAAO,KAAK,kBAAkB,MAAM,KAAK;AAE7C,YAAM,cAAc,KAAK,kBAAkB,MAAM,MAAM,IAAI;AAC3D,YAAM,gBAAgB,MAAM,QAAQ,SAAS,MAAM;AAEnD,aAAO,eAAe;AAAA,IAC1B,CAAC;AAAA,EACL;AAAA,EAEU,cAAc,UAA+B;AACnD,QAAI,CAAC,KAAK,SAAS;AACf;AAEJ,SAAK,aAAa,OAAO,KAAK,GAAG,SAAS,IAAI,MAAM,IAAI,SAAS,UAAU,IAAI,SAAS,IAAI,GAAG,EAAE;AAAA,EACrG;AACJ;","names":["mahameruResponse"]}
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var mahameru_request_exports = {};
21
- __export(mahameru_request_exports, {
22
- MahameruRequest: () => MahameruRequest
23
- });
24
- module.exports = __toCommonJS(mahameru_request_exports);
25
- class MahameruRequest {
26
- static {
27
- __name(this, "MahameruRequest");
28
- }
29
- method;
30
- url;
31
- headers;
32
- query;
33
- path;
34
- ipAddress;
35
- /**
36
- * Parsed Authorization Bearer header
37
- * @returns {string | undefined}
38
- */
39
- authorization;
40
- rawRequest;
41
- constructor(request) {
42
- this.rawRequest = request;
43
- this.method = request.method || "GET";
44
- this.url = request.url || "/";
45
- const queryIndex = this.url.indexOf("?");
46
- const rawPath = queryIndex >= 0 ? this.url.substring(0, queryIndex) : this.url;
47
- const rawSearch = queryIndex >= 0 ? this.url.substring(queryIndex) : "";
48
- this.path = rawPath.replace(/\/+/g, "/");
49
- const parsedUrl = new URL(this.path + rawSearch, `http://${request.headers.host || "localhost"}`);
50
- this.query = parsedUrl.searchParams;
51
- this.ipAddress = request.socket.remoteAddress;
52
- this.headers = request.headers;
53
- if (request.headers.authorization) {
54
- const splitted = request.headers.authorization.split(" ");
55
- this.authorization = splitted[0].toLowerCase() === "bearer" ? splitted[1] : void 0;
56
- }
57
- }
58
- async json() {
59
- return new Promise((resolve, reject) => {
60
- let body = "";
61
- this.rawRequest.on("data", (chunk) => {
62
- body += chunk.toString();
63
- });
64
- this.rawRequest.on("end", () => {
65
- try {
66
- resolve(body ? JSON.parse(body) : {});
67
- } catch (err) {
68
- reject(new Error("Invalid JSON Body"));
69
- }
70
- });
71
- this.rawRequest.on("error", (err) => reject(err));
72
- });
73
- }
74
- }
75
- // Annotate the CommonJS export names for ESM import in node:
76
- 0 && (module.exports = {
77
- MahameruRequest
78
- });
79
- //# sourceMappingURL=mahameru-request.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/mahameru-request.ts"],"sourcesContent":["import type { IncomingMessage, IncomingHttpHeaders } from \"node:http\";\r\nimport type { HTTPMethod } from \"./types\";\r\n\r\nexport class MahameruRequest {\r\n public method: HTTPMethod;\r\n public url: string;\r\n public headers: IncomingHttpHeaders;\r\n public query: URLSearchParams;\r\n public path: string;\r\n public ipAddress?: string;\r\n /**\r\n * Parsed Authorization Bearer header\r\n * @returns {string | undefined}\r\n */\r\n public authorization?: string;\r\n protected rawRequest: IncomingMessage;\r\n\r\n constructor(request: IncomingMessage) {\r\n this.rawRequest = request;\r\n this.method = request.method as HTTPMethod || 'GET';\r\n this.url = request.url || '/';\r\n const queryIndex = this.url.indexOf('?');\r\n const rawPath = queryIndex >= 0 ? this.url.substring(0, queryIndex) : this.url;\r\n const rawSearch = queryIndex >= 0 ? this.url.substring(queryIndex) : '';\r\n this.path = rawPath.replace(/\\/+/g, '/');\r\n const parsedUrl = new URL(this.path + rawSearch, `http://${request.headers.host || 'localhost'}`);\r\n this.query = parsedUrl.searchParams;\r\n this.ipAddress = request.socket.remoteAddress;\r\n this.headers = request.headers;\r\n\r\n if (request.headers.authorization) {\r\n const splitted = request.headers.authorization.split(' ');\r\n this.authorization = splitted[0].toLowerCase() === 'bearer' ? splitted[1] : undefined;\r\n }\r\n }\r\n\r\n async json(): Promise<any> {\r\n return new Promise((resolve, reject) => {\r\n let body = '';\r\n this.rawRequest.on('data', (chunk) => { body += chunk.toString(); });\r\n this.rawRequest.on('end', () => {\r\n try {\r\n resolve(body ? JSON.parse(body) : {});\r\n } catch (err) {\r\n reject(new Error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O,KAAK,MAAM,IAAI,IAAI,CAAC,CAAC;AAAA,QACxC,SAAS,KAAK;AACV,iBAAO,IAAI,MAAM,mBAAmB,CAAC;AAAA,QACzC;AAAA,MACJ,CAAC;AACD,WAAK,WAAW,GAAG,SAAS,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,IACpD,CAAC;AAAA,EACL;AACJ;","names":[]}
@@ -1,3 +0,0 @@
1
- import 'node:http';
2
- export { j as MahameruRequest } from './types-Cd6Gkoxx.cjs';
3
- import './mahameru-response.cjs';
@@ -1,3 +0,0 @@
1
- import 'node:http';
2
- export { j as MahameruRequest } from './types-BmFqDpSs.js';
3
- import './mahameru-response.js';
@@ -1,56 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- class MahameruRequest {
4
- static {
5
- __name(this, "MahameruRequest");
6
- }
7
- method;
8
- url;
9
- headers;
10
- query;
11
- path;
12
- ipAddress;
13
- /**
14
- * Parsed Authorization Bearer header
15
- * @returns {string | undefined}
16
- */
17
- authorization;
18
- rawRequest;
19
- constructor(request) {
20
- this.rawRequest = request;
21
- this.method = request.method || "GET";
22
- this.url = request.url || "/";
23
- const queryIndex = this.url.indexOf("?");
24
- const rawPath = queryIndex >= 0 ? this.url.substring(0, queryIndex) : this.url;
25
- const rawSearch = queryIndex >= 0 ? this.url.substring(queryIndex) : "";
26
- this.path = rawPath.replace(/\/+/g, "/");
27
- const parsedUrl = new URL(this.path + rawSearch, `http://${request.headers.host || "localhost"}`);
28
- this.query = parsedUrl.searchParams;
29
- this.ipAddress = request.socket.remoteAddress;
30
- this.headers = request.headers;
31
- if (request.headers.authorization) {
32
- const splitted = request.headers.authorization.split(" ");
33
- this.authorization = splitted[0].toLowerCase() === "bearer" ? splitted[1] : void 0;
34
- }
35
- }
36
- async json() {
37
- return new Promise((resolve, reject) => {
38
- let body = "";
39
- this.rawRequest.on("data", (chunk) => {
40
- body += chunk.toString();
41
- });
42
- this.rawRequest.on("end", () => {
43
- try {
44
- resolve(body ? JSON.parse(body) : {});
45
- } catch (err) {
46
- reject(new Error("Invalid JSON Body"));
47
- }
48
- });
49
- this.rawRequest.on("error", (err) => reject(err));
50
- });
51
- }
52
- }
53
- export {
54
- MahameruRequest
55
- };
56
- //# sourceMappingURL=mahameru-request.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/mahameru-request.ts"],"sourcesContent":["import type { IncomingMessage, IncomingHttpHeaders } from \"node:http\";\r\nimport type { HTTPMethod } from \"./types\";\r\n\r\nexport class MahameruRequest {\r\n public method: HTTPMethod;\r\n public url: string;\r\n public headers: IncomingHttpHeaders;\r\n public query: URLSearchParams;\r\n public path: string;\r\n public ipAddress?: string;\r\n /**\r\n * Parsed Authorization Bearer header\r\n * @returns {string | undefined}\r\n */\r\n public authorization?: string;\r\n protected rawRequest: IncomingMessage;\r\n\r\n constructor(request: IncomingMessage) {\r\n this.rawRequest = request;\r\n this.method = request.method as HTTPMethod || 'GET';\r\n this.url = request.url || '/';\r\n const queryIndex = this.url.indexOf('?');\r\n const rawPath = queryIndex >= 0 ? this.url.substring(0, queryIndex) : this.url;\r\n const rawSearch = queryIndex >= 0 ? this.url.substring(queryIndex) : '';\r\n this.path = rawPath.replace(/\\/+/g, '/');\r\n const parsedUrl = new URL(this.path + rawSearch, `http://${request.headers.host || 'localhost'}`);\r\n this.query = parsedUrl.searchParams;\r\n this.ipAddress = request.socket.remoteAddress;\r\n this.headers = request.headers;\r\n\r\n if (request.headers.authorization) {\r\n const splitted = request.headers.authorization.split(' ');\r\n this.authorization = splitted[0].toLowerCase() === 'bearer' ? splitted[1] : undefined;\r\n }\r\n }\r\n\r\n async json(): Promise<any> {\r\n return new Promise((resolve, reject) => {\r\n let body = '';\r\n this.rawRequest.on('data', (chunk) => { body += chunk.toString(); });\r\n this.rawRequest.on('end', () => {\r\n try {\r\n resolve(body ? JSON.parse(body) : {});\r\n } catch (err) {\r\n reject(new Error('Invalid JSON Body'));\r\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BAAO,IAAI,MAAM,mBAAmB,CAAC;AAAA,QACzC;AAAA,MACJ,CAAC;AACD,WAAK,WAAW,GAAG,SAAS,CAAC,QAAQ,OAAO,GAAG,CAAC;AAAA,IACpD,CAAC;AAAA,EACL;AACJ;","names":[]}
@@ -1,71 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var mahameru_response_exports = {};
21
- __export(mahameru_response_exports, {
22
- MahameruResponse: () => MahameruResponse
23
- });
24
- module.exports = __toCommonJS(mahameru_response_exports);
25
- class MahameruResponse {
26
- static {
27
- __name(this, "MahameruResponse");
28
- }
29
- body;
30
- status;
31
- headers;
32
- constructor(body, init) {
33
- this.body = body;
34
- this.status = init?.status || 200;
35
- if (init?.headers instanceof Headers) {
36
- this.headers = init.headers;
37
- } else if (typeof init?.headers === "object" && init.headers !== null && !Array.isArray(init.headers)) {
38
- init.headers = {
39
- "Content-Type": "application/json",
40
- ...init.headers
41
- };
42
- this.headers = new Headers(init.headers);
43
- } else {
44
- this.headers = new Headers({
45
- "Content-Type": "application/json"
46
- });
47
- }
48
- }
49
- static json(body, init) {
50
- return new MahameruResponse(body, init);
51
- }
52
- setHeader(key, value) {
53
- this.headers.set(key, value);
54
- }
55
- setHeaders(headers) {
56
- if (headers instanceof Headers) {
57
- headers.forEach((value, key) => {
58
- this.headers.set(key, value);
59
- });
60
- } else if (typeof headers === "object" && headers !== null && !Array.isArray(headers)) {
61
- for (const [key, value] of Object.entries(headers)) {
62
- this.headers.set(key, value);
63
- }
64
- }
65
- }
66
- }
67
- // Annotate the CommonJS export names for ESM import in node:
68
- 0 && (module.exports = {
69
- MahameruResponse
70
- });
71
- //# sourceMappingURL=mahameru-response.cjs.map