@arkyn/server 3.0.10 → 3.0.12
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/AGENTS.md +7 -2
- package/README.md +25 -3
- package/dist/http/api/_deleteRequest.d.ts +1 -0
- package/dist/http/api/_deleteRequest.d.ts.map +1 -1
- package/dist/http/api/_getRequest.d.ts +1 -0
- package/dist/http/api/_getRequest.d.ts.map +1 -1
- package/dist/http/api/_makeRequest.d.ts +2 -0
- package/dist/http/api/_makeRequest.d.ts.map +1 -1
- package/dist/http/api/_patchRequest.d.ts +1 -0
- package/dist/http/api/_patchRequest.d.ts.map +1 -1
- package/dist/http/api/_postRequest.d.ts +1 -0
- package/dist/http/api/_postRequest.d.ts.map +1 -1
- package/dist/http/api/_putRequest.d.ts +1 -0
- package/dist/http/api/_putRequest.d.ts.map +1 -1
- package/dist/http/badResponses/_badResponse.d.ts +2 -1
- package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.d.ts +1 -1
- package/dist/http/badResponses/badRequest.d.ts +1 -1
- package/dist/http/badResponses/conflict.d.ts +1 -1
- package/dist/http/badResponses/forbidden.d.ts +1 -1
- package/dist/http/badResponses/notFound.d.ts +1 -1
- package/dist/http/badResponses/notImplemented.d.ts +1 -1
- package/dist/http/badResponses/serverError.d.ts +1 -1
- package/dist/http/badResponses/unauthorized.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +181 -134
- package/dist/index.js.map +1 -1
- package/dist/modules/http/api/_deleteRequest.js +2 -1
- package/dist/modules/http/api/_deleteRequest.js.map +1 -1
- package/dist/modules/http/api/_getRequest.js +2 -1
- package/dist/modules/http/api/_getRequest.js.map +1 -1
- package/dist/modules/http/api/_logRequest.js +1 -1
- package/dist/modules/http/api/_logRequest.js.map +1 -1
- package/dist/modules/http/api/_makeRequest.js +51 -33
- package/dist/modules/http/api/_makeRequest.js.map +1 -1
- package/dist/modules/http/api/_patchRequest.js +2 -1
- package/dist/modules/http/api/_patchRequest.js.map +1 -1
- package/dist/modules/http/api/_postRequest.js +2 -1
- package/dist/modules/http/api/_postRequest.js.map +1 -1
- package/dist/modules/http/api/_putRequest.js +2 -1
- package/dist/modules/http/api/_putRequest.js.map +1 -1
- package/dist/modules/http/badResponses/_badResponse.js +4 -1
- package/dist/modules/http/badResponses/_badResponse.js.map +1 -1
- package/dist/modules/http/badResponses/badGateway.js +1 -1
- package/dist/modules/http/badResponses/badGateway.js.map +1 -1
- package/dist/modules/http/badResponses/badRequest.js +1 -1
- package/dist/modules/http/badResponses/badRequest.js.map +1 -1
- package/dist/modules/http/badResponses/conflict.js +1 -1
- package/dist/modules/http/badResponses/conflict.js.map +1 -1
- package/dist/modules/http/badResponses/forbidden.js +1 -1
- package/dist/modules/http/badResponses/forbidden.js.map +1 -1
- package/dist/modules/http/badResponses/notFound.js +1 -1
- package/dist/modules/http/badResponses/notFound.js.map +1 -1
- package/dist/modules/http/badResponses/notImplemented.js +1 -1
- package/dist/modules/http/badResponses/notImplemented.js.map +1 -1
- package/dist/modules/http/badResponses/serverError.js +1 -1
- package/dist/modules/http/badResponses/serverError.js.map +1 -1
- package/dist/modules/http/badResponses/unauthorized.js +1 -1
- package/dist/modules/http/badResponses/unauthorized.js.map +1 -1
- package/dist/modules/http/badResponses/unprocessableEntity.js +1 -1
- package/dist/modules/http/badResponses/unprocessableEntity.js.map +1 -1
- package/dist/modules/services/apiService.js +12 -6
- package/dist/modules/services/apiService.js.map +1 -1
- package/dist/modules/services/logService.js +21 -8
- package/dist/modules/services/logService.js.map +1 -1
- package/dist/modules/utilities/withSecurityHeaders.js +18 -0
- package/dist/modules/utilities/withSecurityHeaders.js.map +1 -0
- package/dist/modules/validations/validateDate.js +4 -14
- package/dist/modules/validations/validateDate.js.map +1 -1
- package/dist/services/apiService.d.ts +5 -0
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/logService.d.ts +25 -5
- package/dist/services/logService.d.ts.map +1 -1
- package/dist/utilities/withSecurityHeaders.d.ts +45 -0
- package/dist/utilities/withSecurityHeaders.d.ts.map +1 -0
- package/dist/validations/validateDate.d.ts +3 -2
- package/dist/validations/validateDate.d.ts.map +1 -1
- package/package.json +9 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_deleteRequest.js","names":[],"sources":["../../../../src/http/api/_deleteRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n};\n\n/**\n * Sends a DELETE request to the specified URL with optional headers and body.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the DELETE request, including URL, URL parameters, headers, and body.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function deleteRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"DELETE\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\tbody: input.body,\n\t});\n}\n\nexport { deleteRequest };\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"_deleteRequest.js","names":[],"sources":["../../../../src/http/api/_deleteRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n\ttimeoutMs?: number;\n};\n\n/**\n * Sends a DELETE request to the specified URL with optional headers and body.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the DELETE request, including URL, URL parameters, headers, and body.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function deleteRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"DELETE\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\tbody: input.body,\n\t\ttimeoutMs: input.timeoutMs,\n\t});\n}\n\nexport { deleteRequest };\n"],"mappings":";;AAoBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,MAAM,EAAM;EACZ,WAAW,EAAM;CAClB,CAAC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_getRequest.js","names":[],"sources":["../../../../src/http/api/_getRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n};\n\n/**\n * Sends a GET request to the specified URL with optional headers.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the GET request, including URL, URL parameters, and headers.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function getRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"GET\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t});\n}\n\nexport { getRequest };\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"_getRequest.js","names":[],"sources":["../../../../src/http/api/_getRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\ttimeoutMs?: number;\n};\n\n/**\n * Sends a GET request to the specified URL with optional headers.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the GET request, including URL, URL parameters, and headers.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function getRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"GET\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\ttimeoutMs: input.timeoutMs,\n\t});\n}\n\nexport { getRequest };\n"],"mappings":";;AAkBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,WAAW,EAAM;CAClB,CAAC;AACF"}
|
|
@@ -6,7 +6,7 @@ import { formatJsonObject as r, parseSensitiveData as i } from "@arkyn/shared";
|
|
|
6
6
|
async function a(a) {
|
|
7
7
|
let o = n.getConfig();
|
|
8
8
|
if (!o) return;
|
|
9
|
-
let {
|
|
9
|
+
let { serviceToken: s, apiUrl: c, trafficSourceId: l } = o;
|
|
10
10
|
if (!c) return;
|
|
11
11
|
let { elapsedTime: u, method: d, queryParams: f, requestBody: p, requestHeaders: m, responseBody: h, responseHeaders: g, status: _, rawUrl: v } = a;
|
|
12
12
|
if (process.env.NODE_ENV !== "development") try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_logRequest.js","names":[],"sources":["../../../../src/http/api/_logRequest.ts"],"sourcesContent":["import { formatJsonObject, parseSensitiveData } from \"@arkyn/shared\";\nimport { flushDebugLogs } from \"../..\";\nimport { LogService } from \"../../services/logService\";\nimport { SENSITIVE_DATA_KEYS } from \"../../utilities/sensitiveDataKeys\";\n\ntype ConfigProps = {\n\trawUrl: string;\n\tstatus: number;\n\tmethod: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\ttoken: string | null;\n\telapsedTime: number;\n\trequestHeaders: Record<string, string>;\n\trequestBody: Record<string, string>;\n\tqueryParams: Record<string, string>;\n\tresponseHeaders: Record<string, string>;\n\tresponseBody: Record<string, string>;\n};\n\n/**\n * Sends a request to the inbox flow API with the provided configuration.\n *\n * - This function retrieves the inbox flow configuration using `LogService.getConfig()`.\n * - If the configuration is not available, the function will return early without performing any action.\n * - In a development environment (`NODE_ENV === \"development\"`), the function will also return early.\n * - The request is sent as a POST request to the inbox API URL with the provided configuration details.\n * - If an error occurs during the request, it will be logged using the `httpDebug` service.\n *\n * @param {ConfigProps} config - The configuration object for the request.\n * @param {string} config.rawUrl - The raw URL of the request.\n * @param {number} config.status - The HTTP status code associated with the request.\n * @param {\"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\"} config.method - The HTTP method used for the request. Can be \"POST\", \"GET\", \"PUT\", \"DELETE\", or \"PATCH\".\n * @param {string | null} config.token - The authentication token for the request.\n * @param {number} config.elapsedTime - The elapsed time for the request in milliseconds.\n * @param {Record<string, string>} config.requestHeaders - The headers sent with the request.\n * @param {Record<string, string>} config.requestBody - The body of the request, if applicable.\n * @param {Record<string, string>} config.queryParams - The query parameters for the request.\n * @param {Record<string, string>} config.responseHeaders - The headers received in the response.\n * @param {Record<string, string>} config.responseBody - The body of the response received.\n *\n * @remarks\n *\n * @returns {Promise<void>} A promise that resolves when the request is complete.\n *\n * @example\n * ```typescript\n * const config = {\n * rawUrl: \"https://example.com/api/data\",\n * status: 200,\n * method: \"GET\",\n * token: \"auth-token-123\",\n * elapsedTime: 150,\n * requestHeaders: { \"Accept\": \"application/json\", \"Authorization\": \"Bearer token123\" },\n * requestBody: {},\n * queryParams: { \"page\": \"1\", \"limit\": \"10\" },\n * responseHeaders: { \"Content-Type\": \"application/json\" },\n * responseBody: { \"data\": \"example response\" }\n * };\n *\n * await logRequest(config);\n * ```\n */\n\nasync function logRequest(config: ConfigProps): Promise<void> {\n\tconst arkynService = LogService.getConfig();\n\tif (!arkynService) return;\n\n\tconst {
|
|
1
|
+
{"version":3,"file":"_logRequest.js","names":[],"sources":["../../../../src/http/api/_logRequest.ts"],"sourcesContent":["import { formatJsonObject, parseSensitiveData } from \"@arkyn/shared\";\nimport { flushDebugLogs } from \"../..\";\nimport { LogService } from \"../../services/logService\";\nimport { SENSITIVE_DATA_KEYS } from \"../../utilities/sensitiveDataKeys\";\n\ntype ConfigProps = {\n\trawUrl: string;\n\tstatus: number;\n\tmethod: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\ttoken: string | null;\n\telapsedTime: number;\n\trequestHeaders: Record<string, string>;\n\trequestBody: Record<string, string>;\n\tqueryParams: Record<string, string>;\n\tresponseHeaders: Record<string, string>;\n\tresponseBody: Record<string, string>;\n};\n\n/**\n * Sends a request to the inbox flow API with the provided configuration.\n *\n * - This function retrieves the inbox flow configuration using `LogService.getConfig()`.\n * - If the configuration is not available, the function will return early without performing any action.\n * - In a development environment (`NODE_ENV === \"development\"`), the function will also return early.\n * - The request is sent as a POST request to the inbox API URL with the provided configuration details.\n * - If an error occurs during the request, it will be logged using the `httpDebug` service.\n *\n * @param {ConfigProps} config - The configuration object for the request.\n * @param {string} config.rawUrl - The raw URL of the request.\n * @param {number} config.status - The HTTP status code associated with the request.\n * @param {\"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\"} config.method - The HTTP method used for the request. Can be \"POST\", \"GET\", \"PUT\", \"DELETE\", or \"PATCH\".\n * @param {string | null} config.token - The authentication token for the request.\n * @param {number} config.elapsedTime - The elapsed time for the request in milliseconds.\n * @param {Record<string, string>} config.requestHeaders - The headers sent with the request.\n * @param {Record<string, string>} config.requestBody - The body of the request, if applicable.\n * @param {Record<string, string>} config.queryParams - The query parameters for the request.\n * @param {Record<string, string>} config.responseHeaders - The headers received in the response.\n * @param {Record<string, string>} config.responseBody - The body of the response received.\n *\n * @remarks\n *\n * @returns {Promise<void>} A promise that resolves when the request is complete.\n *\n * @example\n * ```typescript\n * const config = {\n * rawUrl: \"https://example.com/api/data\",\n * status: 200,\n * method: \"GET\",\n * token: \"auth-token-123\",\n * elapsedTime: 150,\n * requestHeaders: { \"Accept\": \"application/json\", \"Authorization\": \"Bearer token123\" },\n * requestBody: {},\n * queryParams: { \"page\": \"1\", \"limit\": \"10\" },\n * responseHeaders: { \"Content-Type\": \"application/json\" },\n * responseBody: { \"data\": \"example response\" }\n * };\n *\n * await logRequest(config);\n * ```\n */\n\nasync function logRequest(config: ConfigProps): Promise<void> {\n\tconst arkynService = LogService.getConfig();\n\tif (!arkynService) return;\n\n\tconst { serviceToken, apiUrl, trafficSourceId } = arkynService;\n\n\t// No endpoint was configured (missing, invalid, or rejected as insecure by\n\t// `LogService.setConfig`) — never fall back to a hardcoded/default destination.\n\tif (!apiUrl) return;\n\n\tconst {\n\t\telapsedTime,\n\t\tmethod,\n\t\tqueryParams,\n\t\trequestBody,\n\t\trequestHeaders,\n\t\tresponseBody,\n\t\tresponseHeaders,\n\t\tstatus,\n\t\trawUrl,\n\t} = config;\n\n\tif (process.env.NODE_ENV === \"development\") return;\n\n\ttry {\n\t\tconst url = new URL(rawUrl);\n\n\t\tlet protocol: \"http\" | \"https\" = \"https\";\n\t\tif (url.protocol === \"http:\") protocol = \"http\";\n\n\t\tconst body = JSON.stringify({\n\t\t\tdomainUrl: `${url.protocol}//${url.host}`,\n\t\t\tpathnameUrl: url.pathname,\n\t\t\ttrafficSourceId: trafficSourceId,\n\t\t\tstatus,\n\t\t\tprotocol,\n\t\t\tmethod: method.toLowerCase(),\n\t\t\ttrafficUserId: null,\n\t\t\telapsedTime,\n\t\t\t// Sensitive fields (Authorization/Cookie headers, password/token/secret\n\t\t\t// body fields, etc.) are masked before this payload ever leaves the\n\t\t\t// process — see `SENSITIVE_DATA_KEYS`.\n\t\t\trequestHeaders: parseSensitiveData(JSON.stringify(requestHeaders), [\n\t\t\t\t...SENSITIVE_DATA_KEYS,\n\t\t\t]),\n\t\t\trequestBody: parseSensitiveData(JSON.stringify(requestBody), [\n\t\t\t\t...SENSITIVE_DATA_KEYS,\n\t\t\t]),\n\t\t\tqueryParams: JSON.stringify(queryParams),\n\t\t\tresponseHeaders: parseSensitiveData(JSON.stringify(responseHeaders), [\n\t\t\t\t...SENSITIVE_DATA_KEYS,\n\t\t\t]),\n\t\t\tresponseBody: parseSensitiveData(JSON.stringify(responseBody), [\n\t\t\t\t...SENSITIVE_DATA_KEYS,\n\t\t\t]),\n\t\t});\n\n\t\tconst headers = {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t\tAuthorization: `Bearer ${serviceToken}`,\n\t\t};\n\n\t\tconst fetchResponse = await fetch(apiUrl, {\n\t\t\tmethod: \"POST\",\n\t\t\tbody,\n\t\t\theaders,\n\t\t});\n\n\t\tif (!fetchResponse.ok) {\n\t\t\tconst errorText = await fetchResponse.text();\n\t\t\tconst errorStatus = fetchResponse.status;\n\t\t\tconst errorStatusText = fetchResponse.statusText;\n\t\t\tconst jsonResponse = await fetchResponse.json().catch(() => null);\n\n\t\t\tflushDebugLogs({\n\t\t\t\tname: \"LogError\",\n\t\t\t\tscheme: \"red\",\n\t\t\t\tdebugs: [\n\t\t\t\t\t`Failed to log request.`,\n\t\t\t\t\t`Status: ${errorStatus} ${errorStatusText}.`,\n\t\t\t\t\t`Status text: ${errorText}.`,\n\t\t\t\t\t`JSON Response: ${jsonResponse ? formatJsonObject(jsonResponse, 0) : \"No JSON response\"}`,\n\t\t\t\t],\n\t\t\t});\n\t\t}\n\t} catch (err) {\n\t\tflushDebugLogs({\n\t\t\tdebugs: [`Error sending request: ${err}`],\n\t\t\tname: \"LogError\",\n\t\t\tscheme: \"red\",\n\t\t});\n\t}\n}\n\nexport { logRequest };\n"],"mappings":";;;;;AA8DA,eAAe,EAAW,GAAoC;CAC7D,IAAM,IAAe,EAAW,UAAU;CAC1C,IAAI,CAAC,GAAc;CAEnB,IAAM,EAAE,iBAAc,WAAQ,uBAAoB;CAIlD,IAAI,CAAC,GAAQ;CAEb,IAAM,EACL,gBACA,WACA,gBACA,gBACA,mBACA,iBACA,oBACA,WACA,cACG;CAEJ,YAAA,IAAA,aAA6B,eAE7B,IAAI;EACH,IAAM,IAAM,IAAI,IAAI,CAAM,GAEtB,IAA6B;EACjC,AAAI,EAAI,aAAa,YAAS,IAAW;EAEzC,IAAM,IAAO,KAAK,UAAU;GAC3B,WAAW,GAAG,EAAI,SAAS,IAAI,EAAI;GACnC,aAAa,EAAI;GACA;GACjB;GACA;GACA,QAAQ,EAAO,YAAY;GAC3B,eAAe;GACf;GAIA,gBAAgB,EAAmB,KAAK,UAAU,CAAc,GAAG,CAClE,GAAG,CACJ,CAAC;GACD,aAAa,EAAmB,KAAK,UAAU,CAAW,GAAG,CAC5D,GAAG,CACJ,CAAC;GACD,aAAa,KAAK,UAAU,CAAW;GACvC,iBAAiB,EAAmB,KAAK,UAAU,CAAe,GAAG,CACpE,GAAG,CACJ,CAAC;GACD,cAAc,EAAmB,KAAK,UAAU,CAAY,GAAG,CAC9D,GAAG,CACJ,CAAC;EACF,CAAC,GAEK,IAAU;GACf,gBAAgB;GAChB,eAAe,UAAU;EAC1B,GAEM,IAAgB,MAAM,MAAM,GAAQ;GACzC,QAAQ;GACR;GACA;EACD,CAAC;EAED,IAAI,CAAC,EAAc,IAAI;GACtB,IAAM,IAAY,MAAM,EAAc,KAAK,GACrC,IAAc,EAAc,QAC5B,IAAkB,EAAc,YAChC,IAAe,MAAM,EAAc,KAAK,CAAC,CAAC,YAAY,IAAI;GAEhE,EAAe;IACd,MAAM;IACN,QAAQ;IACR,QAAQ;KACP;KACA,WAAW,EAAY,GAAG,EAAgB;KAC1C,gBAAgB,EAAU;KAC1B,kBAAkB,IAAe,EAAiB,GAAc,CAAC,IAAI;IACtE;GACD,CAAC;EACF;CACD,SAAS,GAAK;EACb,EAAe;GACd,QAAQ,CAAC,0BAA0B,GAAK;GACxC,MAAM;GACN,QAAQ;EACT,CAAC;CACF;AACD"}
|
|
@@ -2,58 +2,76 @@ import { flushDebugLogs as e } from "../../utilities/flushDebugLogs.js";
|
|
|
2
2
|
import { LogMapperService as t } from "./_logMapperService.js";
|
|
3
3
|
import { logRequest as n } from "./_logRequest.js";
|
|
4
4
|
//#region src/http/api/_makeRequest.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
var r = 1e4;
|
|
6
|
+
async function i(i) {
|
|
7
|
+
let a = i.url;
|
|
8
|
+
i.urlParams && Object.entries(i.urlParams).forEach(([e, t]) => {
|
|
9
|
+
a = a.replaceAll(`:${e}`, t);
|
|
9
10
|
});
|
|
10
|
-
let
|
|
11
|
+
let o = {
|
|
11
12
|
POST: "Resource created successfully",
|
|
12
13
|
PUT: "Resource updated successfully",
|
|
13
14
|
DELETE: "Resource deleted successfully",
|
|
14
15
|
PATCH: "Resource patched successfully",
|
|
15
16
|
GET: "Request successful"
|
|
16
|
-
};
|
|
17
|
+
}, s = i.timeoutMs ?? r, c = new AbortController(), l = setTimeout(() => c.abort(), s);
|
|
17
18
|
try {
|
|
18
|
-
let e = performance.now(),
|
|
19
|
-
...
|
|
19
|
+
let e = performance.now(), r = {
|
|
20
|
+
...i.headers,
|
|
20
21
|
"Content-Type": "application/json"
|
|
21
|
-
}, s
|
|
22
|
-
headers: o,
|
|
23
|
-
method: r.method,
|
|
24
|
-
body: r.body ? JSON.stringify(r.body) : void 0
|
|
25
|
-
}), c = performance.now() - e, l = s.status, u = null;
|
|
22
|
+
}, s;
|
|
26
23
|
try {
|
|
27
|
-
|
|
24
|
+
s = await fetch(a, {
|
|
25
|
+
headers: r,
|
|
26
|
+
method: i.method,
|
|
27
|
+
body: i.body ? JSON.stringify(i.body) : void 0,
|
|
28
|
+
signal: c.signal
|
|
29
|
+
});
|
|
30
|
+
} finally {
|
|
31
|
+
clearTimeout(l);
|
|
32
|
+
}
|
|
33
|
+
let u = performance.now() - e, d = s.status, f = null;
|
|
34
|
+
try {
|
|
35
|
+
f = await s.json();
|
|
28
36
|
} catch {
|
|
29
|
-
|
|
37
|
+
f = null;
|
|
30
38
|
}
|
|
31
39
|
return n(t.handle({
|
|
32
|
-
elapsedTime:
|
|
33
|
-
method:
|
|
34
|
-
queryParams: new URL(
|
|
35
|
-
requestHeaders:
|
|
36
|
-
requestBody:
|
|
37
|
-
responseBody:
|
|
40
|
+
elapsedTime: u,
|
|
41
|
+
method: i.method,
|
|
42
|
+
queryParams: new URL(a).searchParams,
|
|
43
|
+
requestHeaders: r,
|
|
44
|
+
requestBody: i.body,
|
|
45
|
+
responseBody: f,
|
|
38
46
|
responseHeaders: s.headers,
|
|
39
|
-
status:
|
|
40
|
-
rawUrl:
|
|
41
|
-
urlParams:
|
|
47
|
+
status: d,
|
|
48
|
+
rawUrl: i.url,
|
|
49
|
+
urlParams: i.urlParams
|
|
42
50
|
})), s.ok ? {
|
|
43
51
|
success: !0,
|
|
44
|
-
status:
|
|
45
|
-
message:
|
|
46
|
-
response:
|
|
52
|
+
status: d,
|
|
53
|
+
message: f?.message || o[i.method],
|
|
54
|
+
response: f,
|
|
47
55
|
cause: null
|
|
48
56
|
} : {
|
|
49
57
|
success: !1,
|
|
50
|
-
status:
|
|
51
|
-
message:
|
|
52
|
-
response:
|
|
58
|
+
status: d,
|
|
59
|
+
message: f?.message || s.statusText || "Request failed",
|
|
60
|
+
response: f,
|
|
53
61
|
cause: null
|
|
54
62
|
};
|
|
55
63
|
} catch (t) {
|
|
56
|
-
return e({
|
|
64
|
+
return clearTimeout(l), t instanceof DOMException && t.name === "AbortError" || t instanceof Error && t.name === "AbortError" ? (e({
|
|
65
|
+
debugs: [`Request timed out after ${s}ms`],
|
|
66
|
+
name: "MakeRequestError",
|
|
67
|
+
scheme: "red"
|
|
68
|
+
}), {
|
|
69
|
+
success: !1,
|
|
70
|
+
status: 504,
|
|
71
|
+
message: `Request timed out after ${s}ms`,
|
|
72
|
+
response: null,
|
|
73
|
+
cause: t instanceof Error ? t : Error(String(t))
|
|
74
|
+
}) : (e({
|
|
57
75
|
debugs: [`Network error or request failed: ${t}`],
|
|
58
76
|
name: "MakeRequestError",
|
|
59
77
|
scheme: "red"
|
|
@@ -63,10 +81,10 @@ async function r(r) {
|
|
|
63
81
|
message: "Network error or request failed",
|
|
64
82
|
response: null,
|
|
65
83
|
cause: t instanceof Error ? t.message : String(t)
|
|
66
|
-
};
|
|
84
|
+
});
|
|
67
85
|
}
|
|
68
86
|
}
|
|
69
87
|
//#endregion
|
|
70
|
-
export {
|
|
88
|
+
export { i as makeRequest };
|
|
71
89
|
|
|
72
90
|
//# sourceMappingURL=_makeRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_makeRequest.js","names":[],"sources":["../../../../src/http/api/_makeRequest.ts"],"sourcesContent":["import { flushDebugLogs } from \"../..\";\nimport { LogMapperService } from \"./_logMapperService\";\nimport { logRequest } from \"./_logRequest\";\n\ntype InputProps = {\n\turl: string;\n\tmethod: \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\" | \"GET\";\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n};\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\ntype ApiSuccessResponse<T = any> = {\n\tsuccess: true;\n\tstatus: number;\n\tmessage: string;\n\tresponse: T;\n\tcause: null;\n};\n\ntype ApiFailedResponse = {\n\tsuccess: false;\n\tstatus: number;\n\tmessage: string;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tresponse: any;\n\tcause: string | Error | null;\n};\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\ntype ApiResponseDTO<T = any> = ApiSuccessResponse<T> | ApiFailedResponse;\n\n/**\n * Makes an HTTP request using the Fetch API and returns a standardized response.\n *\n * @template {any} T - The expected type of the response data.\n *\n * @param {\"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\" | \"GET\"} method - The HTTP method to use for the request. Supported methods are:\n * - \"POST\": Create a new resource.\n * - \"PUT\": Update an existing resource.\n * - \"DELETE\": Remove a resource.\n * - \"PATCH\": Partially update a resource.\n * - \"GET\": Retrieve a resource.\n * @param {string} url - The URL to which the request is sent.\n * @param {HeadersInit} headers - Optional headers to include in the request. Defaults to an empty object.\n * @param {any} body - Optional body to include in the request. Should be serializable to JSON.\n *\n * @returns {ApiResponseDTO<T>} A promise that resolves to an `ApiResponseDTO<T>` object containing:\n * - `success`: A boolean indicating whether the request was successful.\n * - `status`: The HTTP status code of the response.\n * - `message`: A message describing the result of the request.\n * - `response`: The parsed JSON response data, or `null` if parsing fails.\n * - `cause`: Additional error information, if applicable.\n *\n * @example\n * ```typescript\n * import { makeRequest } from \"./makeRequest\";\n *\n * async function fetchData() {\n * const response = await makeRequest(\"GET\", \"https://api.example.com/data\");\n * if (response.success) {\n * console.log(\"Data:\", response.response);\n * } else {\n * console.error(\"Error:\", response.message);\n * }\n * }\n * ```\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function makeRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\tlet url = input.url;\n\n\tif (input.urlParams) {\n\t\tObject.entries(input.urlParams).forEach(([key, value]) => {\n\t\t\turl = url.replaceAll(`:${key}`, value);\n\t\t});\n\t}\n\n\tconst successMessage = {\n\t\tPOST: \"Resource created successfully\",\n\t\tPUT: \"Resource updated successfully\",\n\t\tDELETE: \"Resource deleted successfully\",\n\t\tPATCH: \"Resource patched successfully\",\n\t\tGET: \"Request successful\",\n\t};\n\n\ttry {\n\t\tconst startTime = performance.now();\n\n\t\tconst headers = { ...input.headers, \"Content-Type\": \"application/json\" };\n\t\
|
|
1
|
+
{"version":3,"file":"_makeRequest.js","names":[],"sources":["../../../../src/http/api/_makeRequest.ts"],"sourcesContent":["import { flushDebugLogs } from \"../..\";\nimport { LogMapperService } from \"./_logMapperService\";\nimport { logRequest } from \"./_logRequest\";\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\ntype InputProps = {\n\turl: string;\n\tmethod: \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\" | \"GET\";\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n\t/** Aborts the request after this many milliseconds. Defaults to 10,000ms. */\n\ttimeoutMs?: number;\n};\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\ntype ApiSuccessResponse<T = any> = {\n\tsuccess: true;\n\tstatus: number;\n\tmessage: string;\n\tresponse: T;\n\tcause: null;\n};\n\ntype ApiFailedResponse = {\n\tsuccess: false;\n\tstatus: number;\n\tmessage: string;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tresponse: any;\n\tcause: string | Error | null;\n};\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\ntype ApiResponseDTO<T = any> = ApiSuccessResponse<T> | ApiFailedResponse;\n\n/**\n * Makes an HTTP request using the Fetch API and returns a standardized response.\n *\n * @template {any} T - The expected type of the response data.\n *\n * @param {\"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\" | \"GET\"} method - The HTTP method to use for the request. Supported methods are:\n * - \"POST\": Create a new resource.\n * - \"PUT\": Update an existing resource.\n * - \"DELETE\": Remove a resource.\n * - \"PATCH\": Partially update a resource.\n * - \"GET\": Retrieve a resource.\n * @param {string} url - The URL to which the request is sent.\n * @param {HeadersInit} headers - Optional headers to include in the request. Defaults to an empty object.\n * @param {any} body - Optional body to include in the request. Should be serializable to JSON.\n *\n * @returns {ApiResponseDTO<T>} A promise that resolves to an `ApiResponseDTO<T>` object containing:\n * - `success`: A boolean indicating whether the request was successful.\n * - `status`: The HTTP status code of the response.\n * - `message`: A message describing the result of the request.\n * - `response`: The parsed JSON response data, or `null` if parsing fails.\n * - `cause`: Additional error information, if applicable.\n *\n * @example\n * ```typescript\n * import { makeRequest } from \"./makeRequest\";\n *\n * async function fetchData() {\n * const response = await makeRequest(\"GET\", \"https://api.example.com/data\");\n * if (response.success) {\n * console.log(\"Data:\", response.response);\n * } else {\n * console.error(\"Error:\", response.message);\n * }\n * }\n * ```\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function makeRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\tlet url = input.url;\n\n\tif (input.urlParams) {\n\t\tObject.entries(input.urlParams).forEach(([key, value]) => {\n\t\t\turl = url.replaceAll(`:${key}`, value);\n\t\t});\n\t}\n\n\tconst successMessage = {\n\t\tPOST: \"Resource created successfully\",\n\t\tPUT: \"Resource updated successfully\",\n\t\tDELETE: \"Resource deleted successfully\",\n\t\tPATCH: \"Resource patched successfully\",\n\t\tGET: \"Request successful\",\n\t};\n\n\tconst timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n\tconst controller = new AbortController();\n\tconst timeoutId = setTimeout(() => controller.abort(), timeoutMs);\n\n\ttry {\n\t\tconst startTime = performance.now();\n\n\t\tconst headers = { ...input.headers, \"Content-Type\": \"application/json\" };\n\t\tlet response: Response;\n\t\ttry {\n\t\t\tresponse = await fetch(url, {\n\t\t\t\theaders,\n\t\t\t\tmethod: input.method,\n\t\t\t\tbody: input.body ? JSON.stringify(input.body) : undefined,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t} finally {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\n\t\tconst elapsedTime = performance.now() - startTime;\n\t\tconst status = response.status;\n\n\t\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\t\tlet data: any = null;\n\t\ttry {\n\t\t\tdata = await response.json();\n\t\t} catch {\n\t\t\tdata = null;\n\t\t}\n\n\t\tconst logData = LogMapperService.handle({\n\t\t\telapsedTime,\n\t\t\tmethod: input.method,\n\t\t\tqueryParams: new URL(url).searchParams,\n\t\t\trequestHeaders: headers,\n\t\t\trequestBody: input.body,\n\t\t\tresponseBody: data,\n\t\t\tresponseHeaders: response.headers,\n\t\t\tstatus,\n\t\t\trawUrl: input.url,\n\t\t\turlParams: input.urlParams,\n\t\t});\n\n\t\tlogRequest(logData);\n\n\t\tif (!response.ok) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\tstatus,\n\t\t\t\tmessage: data?.message || response.statusText || \"Request failed\",\n\t\t\t\tresponse: data,\n\t\t\t\tcause: null,\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tstatus,\n\t\t\tmessage: data?.message || successMessage[input.method],\n\t\t\tresponse: data,\n\t\t\tcause: null,\n\t\t};\n\t} catch (err) {\n\t\tclearTimeout(timeoutId);\n\n\t\tconst isAbortError =\n\t\t\t(err instanceof DOMException && err.name === \"AbortError\") ||\n\t\t\t(err instanceof Error && err.name === \"AbortError\");\n\n\t\tif (isAbortError) {\n\t\t\tflushDebugLogs({\n\t\t\t\tdebugs: [`Request timed out after ${timeoutMs}ms`],\n\t\t\t\tname: \"MakeRequestError\",\n\t\t\t\tscheme: \"red\",\n\t\t\t});\n\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\tstatus: 504,\n\t\t\t\tmessage: `Request timed out after ${timeoutMs}ms`,\n\t\t\t\tresponse: null,\n\t\t\t\tcause: err instanceof Error ? err : new Error(String(err)),\n\t\t\t};\n\t\t}\n\n\t\tflushDebugLogs({\n\t\t\tdebugs: [`Network error or request failed: ${err}`],\n\t\t\tname: \"MakeRequestError\",\n\t\t\tscheme: \"red\",\n\t\t});\n\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tstatus: 0,\n\t\t\tmessage: \"Network error or request failed\",\n\t\t\tresponse: null,\n\t\t\tcause: err instanceof Error ? err.message : String(err),\n\t\t};\n\t}\n}\n\nexport { type ApiResponseDTO, makeRequest };\n"],"mappings":";;;;AAIA,IAAM,IAAqB;AAwE3B,eAAe,EACd,GAC6B;CAC7B,IAAI,IAAM,EAAM;CAEhB,AAAI,EAAM,aACT,OAAO,QAAQ,EAAM,SAAS,CAAC,CAAC,SAAS,CAAC,GAAK,OAAW;EACzD,IAAM,EAAI,WAAW,IAAI,KAAO,CAAK;CACtC,CAAC;CAGF,IAAM,IAAiB;EACtB,MAAM;EACN,KAAK;EACL,QAAQ;EACR,OAAO;EACP,KAAK;CACN,GAEM,IAAY,EAAM,aAAa,GAC/B,IAAa,IAAI,gBAAgB,GACjC,IAAY,iBAAiB,EAAW,MAAM,GAAG,CAAS;CAEhE,IAAI;EACH,IAAM,IAAY,YAAY,IAAI,GAE5B,IAAU;GAAE,GAAG,EAAM;GAAS,gBAAgB;EAAmB,GACnE;EACJ,IAAI;GACH,IAAW,MAAM,MAAM,GAAK;IAC3B;IACA,QAAQ,EAAM;IACd,MAAM,EAAM,OAAO,KAAK,UAAU,EAAM,IAAI,IAAI,KAAA;IAChD,QAAQ,EAAW;GACpB,CAAC;EACF,UAAU;GACT,aAAa,CAAS;EACvB;EAEA,IAAM,IAAc,YAAY,IAAI,IAAI,GAClC,IAAS,EAAS,QAGpB,IAAY;EAChB,IAAI;GACH,IAAO,MAAM,EAAS,KAAK;EAC5B,QAAQ;GACP,IAAO;EACR;EA2BA,OAZA,EAbgB,EAAiB,OAAO;GACvC;GACA,QAAQ,EAAM;GACd,aAAa,IAAI,IAAI,CAAG,CAAC,CAAC;GAC1B,gBAAgB;GAChB,aAAa,EAAM;GACnB,cAAc;GACd,iBAAiB,EAAS;GAC1B;GACA,QAAQ,EAAM;GACd,WAAW,EAAM;EAClB,CAEW,CAAO,GAEb,EAAS,KAUP;GACN,SAAS;GACT;GACA,SAAS,GAAM,WAAW,EAAe,EAAM;GAC/C,UAAU;GACV,OAAO;EACR,IAfQ;GACN,SAAS;GACT;GACA,SAAS,GAAM,WAAW,EAAS,cAAc;GACjD,UAAU;GACV,OAAO;EACR;CAUF,SAAS,GAAK;EA6Bb,OA5BA,aAAa,CAAS,GAGpB,aAAe,gBAAgB,EAAI,SAAS,gBAC5C,aAAe,SAAS,EAAI,SAAS,gBAGtC,EAAe;GACd,QAAQ,CAAC,2BAA2B,EAAU,GAAG;GACjD,MAAM;GACN,QAAQ;EACT,CAAC,GAEM;GACN,SAAS;GACT,QAAQ;GACR,SAAS,2BAA2B,EAAU;GAC9C,UAAU;GACV,OAAO,aAAe,QAAQ,IAAU,MAAM,OAAO,CAAG,CAAC;EAC1D,MAGD,EAAe;GACd,QAAQ,CAAC,oCAAoC,GAAK;GAClD,MAAM;GACN,QAAQ;EACT,CAAC,GAEM;GACN,SAAS;GACT,QAAQ;GACR,SAAS;GACT,UAAU;GACV,OAAO,aAAe,QAAQ,EAAI,UAAU,OAAO,CAAG;EACvD;CACD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_patchRequest.js","names":[],"sources":["../../../../src/http/api/_patchRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n};\n\n/**\n * Sends a PATCH request to the specified URL with optional headers and body.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the PATCH request, including URL, URL parameters, headers, and body.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function patchRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"PATCH\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\tbody: input.body,\n\t});\n}\n\nexport { patchRequest };\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"_patchRequest.js","names":[],"sources":["../../../../src/http/api/_patchRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n\ttimeoutMs?: number;\n};\n\n/**\n * Sends a PATCH request to the specified URL with optional headers and body.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the PATCH request, including URL, URL parameters, headers, and body.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function patchRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"PATCH\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\tbody: input.body,\n\t\ttimeoutMs: input.timeoutMs,\n\t});\n}\n\nexport { patchRequest };\n"],"mappings":";;AAoBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,MAAM,EAAM;EACZ,WAAW,EAAM;CAClB,CAAC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_postRequest.js","names":[],"sources":["../../../../src/http/api/_postRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n};\n\n/**\n * Sends a POST request to the specified URL with optional headers and body.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the POST request, including URL, URL parameters, headers, and body.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function postRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"POST\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\tbody: input.body,\n\t});\n}\n\nexport { postRequest };\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"_postRequest.js","names":[],"sources":["../../../../src/http/api/_postRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n\ttimeoutMs?: number;\n};\n\n/**\n * Sends a POST request to the specified URL with optional headers and body.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the POST request, including URL, URL parameters, headers, and body.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function postRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"POST\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\tbody: input.body,\n\t\ttimeoutMs: input.timeoutMs,\n\t});\n}\n\nexport { postRequest };\n"],"mappings":";;AAoBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,MAAM,EAAM;EACZ,WAAW,EAAM;CAClB,CAAC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_putRequest.js","names":[],"sources":["../../../../src/http/api/_putRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n};\n\n/**\n * Sends a PUT request to the specified URL with optional headers and body.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the PUT request, including URL, URL parameters, headers, and body.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function putRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"PUT\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\tbody: input.body,\n\t});\n}\n\nexport { putRequest };\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"_putRequest.js","names":[],"sources":["../../../../src/http/api/_putRequest.ts"],"sourcesContent":["import { type ApiResponseDTO, makeRequest } from \"./_makeRequest\";\n\ntype InputProps = {\n\turl: string;\n\turlParams?: Record<string, string>;\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n\ttimeoutMs?: number;\n};\n\n/**\n * Sends a PUT request to the specified URL with optional headers and body.\n *\n * @template T - The expected type of the response data.\n * @param {InputProps} input - The options for the PUT request, including URL, URL parameters, headers, and body.\n * @returns {Promise<ApiResponseDTO<T>>} A promise that resolves to the API response.\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function putRequest<T = any>(\n\tinput: InputProps,\n): Promise<ApiResponseDTO<T>> {\n\treturn makeRequest({\n\t\tmethod: \"PUT\",\n\t\turl: input.url,\n\t\turlParams: input.urlParams,\n\t\theaders: input.headers,\n\t\tbody: input.body,\n\t\ttimeoutMs: input.timeoutMs,\n\t});\n}\n\nexport { putRequest };\n"],"mappings":";;AAoBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,MAAM,EAAM;EACZ,WAAW,EAAM;CAClB,CAAC;AACF"}
|
|
@@ -2,13 +2,16 @@ import { DebugService as e } from "../../services/debugService.js";
|
|
|
2
2
|
import { flushDebugLogs as t } from "../../utilities/flushDebugLogs.js";
|
|
3
3
|
import { formatJsonString as n } from "@arkyn/shared";
|
|
4
4
|
//#region src/http/badResponses/_badResponse.ts
|
|
5
|
-
var r = class {
|
|
5
|
+
var r = class extends Error {
|
|
6
6
|
_cause;
|
|
7
7
|
_name = "BadResponse";
|
|
8
8
|
_status = 500;
|
|
9
9
|
_statusText = "Unknown error";
|
|
10
10
|
_debugColor = "red";
|
|
11
11
|
exposeCauseInProduction = !1;
|
|
12
|
+
constructor(e) {
|
|
13
|
+
super(e || "Unknown error"), this.name = "BadResponse", e && (this._statusText = e), Error.captureStackTrace?.(this, this.constructor);
|
|
14
|
+
}
|
|
12
15
|
get cause() {
|
|
13
16
|
return this._cause;
|
|
14
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_badResponse.js","names":[],"sources":["../../../../src/http/badResponses/_badResponse.ts"],"sourcesContent":["import { formatJsonString } from \"@arkyn/shared\";\n\nimport { DebugService } from \"../../services/debugService\";\nimport { flushDebugLogs } from \"../../utilities/flushDebugLogs\";\n\nclass BadResponse {\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tprivate _cause?: any;\n\tprivate _name: string = \"BadResponse\";\n\tprivate _status: number = 500;\n\tprivate _statusText: string = \"Unknown error\";\n\tprivate _debugColor: \"green\" | \"yellow\" | \"cyan\" | \"red\" = \"red\";\n\t/**\n\t * When `false` (the default), `makeBody()` omits `cause` in production so internal\n\t * details (stack traces, SQL, infra info) never reach the client. Subclasses whose\n\t * `cause` is safe, client-facing data (e.g. `UnprocessableEntity`'s form field errors)\n\t * set this to `true`.\n\t */\n\tprotected exposeCauseInProduction = false;\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tget cause(): any {\n\t\treturn this._cause;\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tset cause(value: any) {\n\t\tthis._cause = value;\n\t}\n\n\tget name(): string {\n\t\treturn this._name;\n\t}\n\n\tset name(value: string) {\n\t\tthis._name = value;\n\t}\n\n\tget status(): number {\n\t\treturn this._status;\n\t}\n\n\tset status(value: number) {\n\t\tthis._status = value;\n\t}\n\n\tget statusText(): string {\n\t\treturn this._statusText;\n\t}\n\n\tset statusText(value: string) {\n\t\tthis._statusText = value;\n\t}\n\n\tget debugColor(): \"green\" | \"yellow\" | \"cyan\" | \"red\" {\n\t\treturn this._debugColor;\n\t}\n\n\tset debugColor(value: \"green\" | \"yellow\" | \"cyan\" | \"red\") {\n\t\tif (![\"green\", \"yellow\", \"cyan\", \"red\"].includes(value)) return;\n\t\tthis._debugColor = value;\n\t}\n\n\tonDebug() {\n\t\tconst debugs: string[] = [];\n\t\tconst { callerInfo, functionName } = DebugService.getCaller();\n\n\t\tdebugs.push(`Caller Function: ${functionName}`);\n\t\tdebugs.push(`Caller Location: ${callerInfo}`);\n\n\t\tif (this._statusText) debugs.push(`Message: ${this._statusText}`);\n\t\tif (this._cause) {\n\t\t\tdebugs.push(`Cause: ${formatJsonString(JSON.stringify(this._cause))}`);\n\t\t}\n\n\t\tflushDebugLogs({ scheme: \"red\", name: this._name, debugs });\n\t}\n\n\tmakeBody() {\n\t\tconst isProduction = process.env.NODE_ENV === \"production\";\n\t\tconst hideCause = isProduction && !this.exposeCauseInProduction;\n\n\t\treturn {\n\t\t\tname: this._name,\n\t\t\tmessage: this._statusText,\n\t\t\tcause: hideCause ? undefined : this._cause,\n\t\t};\n\t}\n}\n\nexport { BadResponse };\n"],"mappings":";;;;AAKA,IAAM,IAAN,
|
|
1
|
+
{"version":3,"file":"_badResponse.js","names":[],"sources":["../../../../src/http/badResponses/_badResponse.ts"],"sourcesContent":["import { formatJsonString } from \"@arkyn/shared\";\n\nimport { DebugService } from \"../../services/debugService\";\nimport { flushDebugLogs } from \"../../utilities/flushDebugLogs\";\n\nclass BadResponse extends Error {\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tprivate _cause?: any;\n\tprivate _name: string = \"BadResponse\";\n\tprivate _status: number = 500;\n\tprivate _statusText: string = \"Unknown error\";\n\tprivate _debugColor: \"green\" | \"yellow\" | \"cyan\" | \"red\" = \"red\";\n\t/**\n\t * When `false` (the default), `makeBody()` omits `cause` in production so internal\n\t * details (stack traces, SQL, infra info) never reach the client. Subclasses whose\n\t * `cause` is safe, client-facing data (e.g. `UnprocessableEntity`'s form field errors)\n\t * set this to `true`.\n\t */\n\tprotected exposeCauseInProduction = false;\n\n\tconstructor(message?: string) {\n\t\tsuper(message || \"Unknown error\");\n\n\t\tthis.name = \"BadResponse\";\n\t\tif (message) this._statusText = message;\n\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tget cause(): any {\n\t\treturn this._cause;\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tset cause(value: any) {\n\t\tthis._cause = value;\n\t}\n\n\tget name(): string {\n\t\treturn this._name;\n\t}\n\n\tset name(value: string) {\n\t\tthis._name = value;\n\t}\n\n\tget status(): number {\n\t\treturn this._status;\n\t}\n\n\tset status(value: number) {\n\t\tthis._status = value;\n\t}\n\n\tget statusText(): string {\n\t\treturn this._statusText;\n\t}\n\n\tset statusText(value: string) {\n\t\tthis._statusText = value;\n\t}\n\n\tget debugColor(): \"green\" | \"yellow\" | \"cyan\" | \"red\" {\n\t\treturn this._debugColor;\n\t}\n\n\tset debugColor(value: \"green\" | \"yellow\" | \"cyan\" | \"red\") {\n\t\tif (![\"green\", \"yellow\", \"cyan\", \"red\"].includes(value)) return;\n\t\tthis._debugColor = value;\n\t}\n\n\tonDebug() {\n\t\tconst debugs: string[] = [];\n\t\tconst { callerInfo, functionName } = DebugService.getCaller();\n\n\t\tdebugs.push(`Caller Function: ${functionName}`);\n\t\tdebugs.push(`Caller Location: ${callerInfo}`);\n\n\t\tif (this._statusText) debugs.push(`Message: ${this._statusText}`);\n\t\tif (this._cause) {\n\t\t\tdebugs.push(`Cause: ${formatJsonString(JSON.stringify(this._cause))}`);\n\t\t}\n\n\t\tflushDebugLogs({ scheme: \"red\", name: this._name, debugs });\n\t}\n\n\tmakeBody() {\n\t\tconst isProduction = process.env.NODE_ENV === \"production\";\n\t\tconst hideCause = isProduction && !this.exposeCauseInProduction;\n\n\t\treturn {\n\t\t\tname: this._name,\n\t\t\tmessage: this._statusText,\n\t\t\tcause: hideCause ? undefined : this._cause,\n\t\t};\n\t}\n}\n\nexport { BadResponse };\n"],"mappings":";;;;AAKA,IAAM,IAAN,cAA0B,MAAM;CAE/B;CACA,QAAwB;CACxB,UAA0B;CAC1B,cAA8B;CAC9B,cAA2D;CAO3D,0BAAoC;CAEpC,YAAY,GAAkB;EAM7B,AALA,MAAM,KAAW,eAAe,GAEhC,KAAK,OAAO,eACR,MAAS,KAAK,cAAc,IAEhC,MAAM,oBAAoB,MAAM,KAAK,WAAW;CACjD;CAGA,IAAI,QAAa;EAChB,OAAO,KAAK;CACb;CAGA,IAAI,MAAM,GAAY;EACrB,KAAK,SAAS;CACf;CAEA,IAAI,OAAe;EAClB,OAAO,KAAK;CACb;CAEA,IAAI,KAAK,GAAe;EACvB,KAAK,QAAQ;CACd;CAEA,IAAI,SAAiB;EACpB,OAAO,KAAK;CACb;CAEA,IAAI,OAAO,GAAe;EACzB,KAAK,UAAU;CAChB;CAEA,IAAI,aAAqB;EACxB,OAAO,KAAK;CACb;CAEA,IAAI,WAAW,GAAe;EAC7B,KAAK,cAAc;CACpB;CAEA,IAAI,aAAkD;EACrD,OAAO,KAAK;CACb;CAEA,IAAI,WAAW,GAA4C;EACrD;GAAC;GAAS;GAAU;GAAQ;EAAK,CAAC,CAAC,SAAS,CAAK,MACtD,KAAK,cAAc;CACpB;CAEA,UAAU;EACT,IAAM,IAAmB,CAAC,GACpB,EAAE,eAAY,oBAAiB,EAAa,UAAU;EAU5D,AARA,EAAO,KAAK,oBAAoB,GAAc,GAC9C,EAAO,KAAK,oBAAoB,GAAY,GAExC,KAAK,eAAa,EAAO,KAAK,YAAY,KAAK,aAAa,GAC5D,KAAK,UACR,EAAO,KAAK,UAAU,EAAiB,KAAK,UAAU,KAAK,MAAM,CAAC,GAAG,GAGtE,EAAe;GAAE,QAAQ;GAAO,MAAM,KAAK;GAAO;EAAO,CAAC;CAC3D;CAEA,WAAW;EAEV,IAAM,IAAA,QAAA,IAAA,aADwC,gBACZ,CAAC,KAAK;EAExC,OAAO;GACN,MAAM,KAAK;GACX,SAAS,KAAK;GACd,OAAO,IAAY,KAAA,IAAY,KAAK;EACrC;CACD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { BadResponse as e } from "./_badResponse.js";
|
|
|
2
2
|
//#region src/http/badResponses/badGateway.ts
|
|
3
3
|
var t = class extends e {
|
|
4
4
|
constructor(e, t) {
|
|
5
|
-
super(), this.name = "BadGateway", this.status = 502, this.statusText = e, this.cause = t
|
|
5
|
+
super(e), this.name = "BadGateway", this.status = 502, this.statusText = e, this.cause = t, this.onDebug();
|
|
6
6
|
}
|
|
7
7
|
toResponse() {
|
|
8
8
|
let e = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badGateway.js","names":[],"sources":["../../../../src/http/badResponses/badGateway.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 502 Bad Gateway, the upstream server returned an invalid or unexpected response.\n *\n * Throw inside a server action/loader and catch with `errorHandler`, or call `.toJson()` directly.\n *\n * @example\n * ```typescript\n * throw new BadGateway(\"Payment gateway unavailable\");\n * ```\n */\nclass BadGateway extends BadResponse {\n\t/**\n\t * @param message - Error description sent in the response body and logged for debugging.\n\t * @param cause - Optional extra context
|
|
1
|
+
{"version":3,"file":"badGateway.js","names":[],"sources":["../../../../src/http/badResponses/badGateway.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 502 Bad Gateway, the upstream server returned an invalid or unexpected response.\n *\n * Throw inside a server action/loader and catch with `errorHandler`, or call `.toJson()` directly.\n *\n * @example\n * ```typescript\n * throw new BadGateway(\"Payment gateway unavailable\");\n * ```\n */\nclass BadGateway extends BadResponse {\n\t/**\n\t * @param message - Error description sent in the response body and logged for debugging.\n\t * @param cause - Optional extra context.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper(message);\n\n\t\tthis.name = \"BadGateway\";\n\t\tthis.status = 502;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { BadGateway };\n"],"mappings":";;AAYA,IAAM,IAAN,cAAyB,EAAY;CAMpC,YAAY,GAAiB,GAAa;EAQzC,AAPA,MAAM,CAAO,GAEb,KAAK,OAAO,cACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,GAEb,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { BadResponse as e } from "./_badResponse.js";
|
|
|
2
2
|
//#region src/http/badResponses/badRequest.ts
|
|
3
3
|
var t = class extends e {
|
|
4
4
|
constructor(e, t) {
|
|
5
|
-
super(), this.name = "BadRequest", this.status = 400, this.statusText = e, this.cause = t
|
|
5
|
+
super(e), this.name = "BadRequest", this.status = 400, this.statusText = e, this.cause = t, this.onDebug();
|
|
6
6
|
}
|
|
7
7
|
toResponse() {
|
|
8
8
|
let e = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"badRequest.js","names":[],"sources":["../../../../src/http/badResponses/badRequest.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 400 Bad Request, the request is malformed or contains invalid data.\n *\n * @example\n * ```typescript\n * throw new BadRequest(\"Invalid request body\");\n * ```\n */\nclass BadRequest extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context
|
|
1
|
+
{"version":3,"file":"badRequest.js","names":[],"sources":["../../../../src/http/badResponses/badRequest.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 400 Bad Request, the request is malformed or contains invalid data.\n *\n * @example\n * ```typescript\n * throw new BadRequest(\"Invalid request body\");\n * ```\n */\nclass BadRequest extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper(message);\n\n\t\tthis.name = \"BadRequest\";\n\t\tthis.status = 400;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { BadRequest };\n"],"mappings":";;AAUA,IAAM,IAAN,cAAyB,EAAY;CAMpC,YAAY,GAAiB,GAAa;EAQzC,AAPA,MAAM,CAAO,GAEb,KAAK,OAAO,cACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,GAEb,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { BadResponse as e } from "./_badResponse.js";
|
|
|
2
2
|
//#region src/http/badResponses/conflict.ts
|
|
3
3
|
var t = class extends e {
|
|
4
4
|
constructor(e, t) {
|
|
5
|
-
super(), this.name = "Conflict", this.status = 409, this.statusText = e, this.debugColor = "yellow", this.cause = t
|
|
5
|
+
super(e), this.name = "Conflict", this.status = 409, this.statusText = e, this.debugColor = "yellow", this.cause = t, this.onDebug();
|
|
6
6
|
}
|
|
7
7
|
toResponse() {
|
|
8
8
|
let e = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict.js","names":[],"sources":["../../../../src/http/badResponses/conflict.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 409 Conflict, the request conflicts with the current state of the server (e.g. duplicate record).\n *\n * @example\n * ```typescript\n * throw new Conflict(\"Email already in use\");\n * ```\n */\nclass Conflict extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context
|
|
1
|
+
{"version":3,"file":"conflict.js","names":[],"sources":["../../../../src/http/badResponses/conflict.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 409 Conflict, the request conflicts with the current state of the server (e.g. duplicate record).\n *\n * @example\n * ```typescript\n * throw new Conflict(\"Email already in use\");\n * ```\n */\nclass Conflict extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper(message);\n\n\t\tthis.name = \"Conflict\";\n\t\tthis.status = 409;\n\t\tthis.statusText = message;\n\t\tthis.debugColor = \"yellow\";\n\t\tthis.cause = cause;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { Conflict };\n"],"mappings":";;AAUA,IAAM,IAAN,cAAuB,EAAY;CAMlC,YAAY,GAAiB,GAAa;EASzC,AARA,MAAM,CAAO,GAEb,KAAK,OAAO,YACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,aAAa,UAClB,KAAK,QAAQ,GAEb,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { BadResponse as e } from "./_badResponse.js";
|
|
|
2
2
|
//#region src/http/badResponses/forbidden.ts
|
|
3
3
|
var t = class extends e {
|
|
4
4
|
constructor(e, t) {
|
|
5
|
-
super(), this.name = "Forbidden", this.status = 403, this.statusText = e, this.cause = t
|
|
5
|
+
super(e), this.name = "Forbidden", this.status = 403, this.statusText = e, this.cause = t, this.onDebug();
|
|
6
6
|
}
|
|
7
7
|
toResponse() {
|
|
8
8
|
let e = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forbidden.js","names":[],"sources":["../../../../src/http/badResponses/forbidden.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 403 Forbidden, authenticated but not authorized to access this resource.\n *\n * @example\n * ```typescript\n * throw new Forbidden(\"You don't have permission to delete this resource\");\n * ```\n */\nclass Forbidden extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context
|
|
1
|
+
{"version":3,"file":"forbidden.js","names":[],"sources":["../../../../src/http/badResponses/forbidden.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 403 Forbidden, authenticated but not authorized to access this resource.\n *\n * @example\n * ```typescript\n * throw new Forbidden(\"You don't have permission to delete this resource\");\n * ```\n */\nclass Forbidden extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper(message);\n\n\t\tthis.name = \"Forbidden\";\n\t\tthis.status = 403;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { Forbidden };\n"],"mappings":";;AAUA,IAAM,IAAN,cAAwB,EAAY;CAMnC,YAAY,GAAiB,GAAa;EAQzC,AAPA,MAAM,CAAO,GAEb,KAAK,OAAO,aACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,GAEb,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { BadResponse as e } from "./_badResponse.js";
|
|
|
2
2
|
//#region src/http/badResponses/notFound.ts
|
|
3
3
|
var t = class extends e {
|
|
4
4
|
constructor(e, t) {
|
|
5
|
-
super(), this.name = "NotFound", this.status = 404, this.statusText = e, this.cause = t
|
|
5
|
+
super(e), this.name = "NotFound", this.status = 404, this.statusText = e, this.cause = t, this.onDebug();
|
|
6
6
|
}
|
|
7
7
|
toResponse() {
|
|
8
8
|
let e = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notFound.js","names":[],"sources":["../../../../src/http/badResponses/notFound.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 404 Not Found, the requested resource does not exist.\n *\n * @example\n * ```typescript\n * throw new NotFound(\"Product not found\");\n * ```\n */\nclass NotFound extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context
|
|
1
|
+
{"version":3,"file":"notFound.js","names":[],"sources":["../../../../src/http/badResponses/notFound.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 404 Not Found, the requested resource does not exist.\n *\n * @example\n * ```typescript\n * throw new NotFound(\"Product not found\");\n * ```\n */\nclass NotFound extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper(message);\n\n\t\tthis.name = \"NotFound\";\n\t\tthis.status = 404;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { NotFound };\n"],"mappings":";;AAUA,IAAM,IAAN,cAAuB,EAAY;CAMlC,YAAY,GAAiB,GAAa;EAQzC,AAPA,MAAM,CAAO,GAEb,KAAK,OAAO,YACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,GAEb,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { BadResponse as e } from "./_badResponse.js";
|
|
|
2
2
|
//#region src/http/badResponses/notImplemented.ts
|
|
3
3
|
var t = class extends e {
|
|
4
4
|
constructor(e, t) {
|
|
5
|
-
super(), this.name = "NotImplemented", this.status = 501, this.statusText = e, this.cause = t
|
|
5
|
+
super(e), this.name = "NotImplemented", this.status = 501, this.statusText = e, this.cause = t, this.onDebug();
|
|
6
6
|
}
|
|
7
7
|
toResponse() {
|
|
8
8
|
let e = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notImplemented.js","names":[],"sources":["../../../../src/http/badResponses/notImplemented.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 501 Not Implemented, the server does not support the functionality required to fulfill the request.\n *\n * @example\n * ```typescript\n * throw new NotImplemented(\"Webhook delivery is not yet implemented\");\n * ```\n */\nclass NotImplemented extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context
|
|
1
|
+
{"version":3,"file":"notImplemented.js","names":[],"sources":["../../../../src/http/badResponses/notImplemented.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 501 Not Implemented, the server does not support the functionality required to fulfill the request.\n *\n * @example\n * ```typescript\n * throw new NotImplemented(\"Webhook delivery is not yet implemented\");\n * ```\n */\nclass NotImplemented extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper(message);\n\n\t\tthis.name = \"NotImplemented\";\n\t\tthis.status = 501;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { NotImplemented };\n"],"mappings":";;AAUA,IAAM,IAAN,cAA6B,EAAY;CAMxC,YAAY,GAAiB,GAAa;EAQzC,AAPA,MAAM,CAAO,GAEb,KAAK,OAAO,kBACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,GAEb,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { BadResponse as e } from "./_badResponse.js";
|
|
|
2
2
|
//#region src/http/badResponses/serverError.ts
|
|
3
3
|
var t = class extends e {
|
|
4
4
|
constructor(e, t) {
|
|
5
|
-
super(), this.name = "ServerError", this.status = 500, this.statusText = e, this.cause = t
|
|
5
|
+
super(e), this.name = "ServerError", this.status = 500, this.statusText = e, this.cause = t, this.onDebug();
|
|
6
6
|
}
|
|
7
7
|
toResponse() {
|
|
8
8
|
let e = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverError.js","names":[],"sources":["../../../../src/http/badResponses/serverError.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 500 Internal Server Error, an unexpected condition prevented the server from fulfilling the request.\n *\n * @example\n * ```typescript\n * throw new ServerError(\"Failed to connect to the database\");\n * ```\n */\nclass ServerError extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context
|
|
1
|
+
{"version":3,"file":"serverError.js","names":[],"sources":["../../../../src/http/badResponses/serverError.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 500 Internal Server Error, an unexpected condition prevented the server from fulfilling the request.\n *\n * @example\n * ```typescript\n * throw new ServerError(\"Failed to connect to the database\");\n * ```\n */\nclass ServerError extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper(message);\n\n\t\tthis.name = \"ServerError\";\n\t\tthis.status = 500;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { ServerError };\n"],"mappings":";;AAUA,IAAM,IAAN,cAA0B,EAAY;CAMrC,YAAY,GAAiB,GAAa;EAQzC,AAPA,MAAM,CAAO,GAEb,KAAK,OAAO,eACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,GAEb,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|
|
@@ -2,7 +2,7 @@ import { BadResponse as e } from "./_badResponse.js";
|
|
|
2
2
|
//#region src/http/badResponses/unauthorized.ts
|
|
3
3
|
var t = class extends e {
|
|
4
4
|
constructor(e, t) {
|
|
5
|
-
super(), this.name = "Unauthorized", this.status = 401, this.statusText = e, this.debugColor = "yellow", this.cause = t
|
|
5
|
+
super(e), this.name = "Unauthorized", this.status = 401, this.statusText = e, this.debugColor = "yellow", this.cause = t, this.onDebug();
|
|
6
6
|
}
|
|
7
7
|
toResponse() {
|
|
8
8
|
let e = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unauthorized.js","names":[],"sources":["../../../../src/http/badResponses/unauthorized.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 401 Unauthorized, the request lacks valid authentication credentials.\n *\n * @example\n * ```typescript\n * throw new Unauthorized(\"Invalid or expired token\");\n * ```\n */\nclass Unauthorized extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context
|
|
1
|
+
{"version":3,"file":"unauthorized.js","names":[],"sources":["../../../../src/http/badResponses/unauthorized.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\n\n/**\n * HTTP 401 Unauthorized, the request lacks valid authentication credentials.\n *\n * @example\n * ```typescript\n * throw new Unauthorized(\"Invalid or expired token\");\n * ```\n */\nclass Unauthorized extends BadResponse {\n\t/**\n\t * @param message - Error description.\n\t * @param cause - Optional extra context.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper(message);\n\n\t\tthis.name = \"Unauthorized\";\n\t\tthis.status = 401;\n\t\tthis.statusText = message;\n\t\tthis.debugColor = \"yellow\";\n\t\tthis.cause = cause;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { Unauthorized };\n"],"mappings":";;AAUA,IAAM,IAAN,cAA2B,EAAY;CAMtC,YAAY,GAAiB,GAAa;EASzC,AARA,MAAM,CAAO,GAEb,KAAK,OAAO,gBACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,aAAa,UAClB,KAAK,QAAQ,GAEb,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|
|
@@ -12,7 +12,7 @@ function r(e) {
|
|
|
12
12
|
}
|
|
13
13
|
var i = class extends e {
|
|
14
14
|
constructor(e) {
|
|
15
|
-
super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.exposeCauseInProduction = !0, this.cause = {
|
|
15
|
+
super(e.message || "Unprocessable entity"), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.exposeCauseInProduction = !0, this.cause = {
|
|
16
16
|
data: r(e.data),
|
|
17
17
|
fieldErrors: e.fieldErrors,
|
|
18
18
|
fields: r(e.fields)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unprocessableEntity.js","names":[],"sources":["../../../../src/http/badResponses/unprocessableEntity.ts"],"sourcesContent":["import { parseSensitiveData } from \"@arkyn/shared\";\nimport { SENSITIVE_DATA_KEYS } from \"../../utilities/sensitiveDataKeys\";\nimport { BadResponse } from \"./_badResponse\";\n\n/**\n * Masks sensitive values (passwords, tokens, etc. — see `SENSITIVE_DATA_KEYS`) inside a\n * form-submission payload before it is echoed back to the client. `fields`/`data` on\n * `UnprocessableEntity` exist to repopulate a form, so submitted secrets must never be\n * returned in cleartext.\n */\nfunction redactSensitiveValues<T>(value: T): T {\n\tif (value === undefined) return value;\n\n\ttry {\n\t\treturn JSON.parse(\n\t\t\tparseSensitiveData(JSON.stringify(value), [...SENSITIVE_DATA_KEYS]),\n\t\t);\n\t} catch {\n\t\treturn value;\n\t}\n}\n\n/**\n * HTTP 422 Unprocessable Entity, the request is well-formed but contains semantic validation errors.\n * Typically used for form field validation failures.\n *\n * @example\n * ```typescript\n * throw new UnprocessableEntity({\n * message: \"Validation failed\",\n * fieldErrors: { email: \"Invalid email format\", age: \"Must be 18 or older\" },\n * fields: { email: \"not-an-email\", age: \"15\" },\n * });\n * ```\n */\nclass UnprocessableEntity extends BadResponse {\n\t/**\n\t * @param props.message - Human-readable description of the error.\n\t * @param props.fieldErrors - Per-field validation messages keyed by field name.\n\t * @param props.fields - Original submitted field values (useful for repopulating forms).\n\t * @param props.data - Any extra data to include in the response body.\n\t */\n\tconstructor(props: {\n\t\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\t\tdata?: any;\n\t\tfieldErrors?: Record<string, string>;\n\t\tfields?: Record<string, string>;\n\t\tmessage?: string;\n\t}) {\n\t\tsuper();\n\n\t\tthis.name = \"UnprocessableEntity\";\n\t\tthis.status = 422;\n\t\tthis.statusText = props.message || \"Unprocessable entity\";\n\t\tthis.debugColor = \"yellow\";\n\t\t// `cause` here is structured, redacted form-validation data meant for the\n\t\t// client (to repopulate the form) — unlike other responses' `cause`, it stays\n\t\t// visible in production.\n\t\tthis.exposeCauseInProduction = true;\n\t\tthis.cause = {\n\t\t\tdata: redactSensitiveValues(props.data),\n\t\t\tfieldErrors: props.fieldErrors,\n\t\t\tfields: redactSensitiveValues(props.fields),\n\t\t};\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { UnprocessableEntity };\n"],"mappings":";;;;AAUA,SAAS,EAAyB,GAAa;CAC9C,IAAI,MAAU,KAAA,GAAW,OAAO;CAEhC,IAAI;EACH,OAAO,KAAK,MACX,EAAmB,KAAK,UAAU,CAAK,GAAG,CAAC,GAAG,CAAmB,CAAC,CACnE;CACD,QAAQ;EACP,OAAO;CACR;AACD;AAeA,IAAM,IAAN,cAAkC,EAAY;CAO7C,YAAY,GAMT;EAiBF,AAhBA,MAAM,
|
|
1
|
+
{"version":3,"file":"unprocessableEntity.js","names":[],"sources":["../../../../src/http/badResponses/unprocessableEntity.ts"],"sourcesContent":["import { parseSensitiveData } from \"@arkyn/shared\";\nimport { SENSITIVE_DATA_KEYS } from \"../../utilities/sensitiveDataKeys\";\nimport { BadResponse } from \"./_badResponse\";\n\n/**\n * Masks sensitive values (passwords, tokens, etc. — see `SENSITIVE_DATA_KEYS`) inside a\n * form-submission payload before it is echoed back to the client. `fields`/`data` on\n * `UnprocessableEntity` exist to repopulate a form, so submitted secrets must never be\n * returned in cleartext.\n */\nfunction redactSensitiveValues<T>(value: T): T {\n\tif (value === undefined) return value;\n\n\ttry {\n\t\treturn JSON.parse(\n\t\t\tparseSensitiveData(JSON.stringify(value), [...SENSITIVE_DATA_KEYS]),\n\t\t);\n\t} catch {\n\t\treturn value;\n\t}\n}\n\n/**\n * HTTP 422 Unprocessable Entity, the request is well-formed but contains semantic validation errors.\n * Typically used for form field validation failures.\n *\n * @example\n * ```typescript\n * throw new UnprocessableEntity({\n * message: \"Validation failed\",\n * fieldErrors: { email: \"Invalid email format\", age: \"Must be 18 or older\" },\n * fields: { email: \"not-an-email\", age: \"15\" },\n * });\n * ```\n */\nclass UnprocessableEntity extends BadResponse {\n\t/**\n\t * @param props.message - Human-readable description of the error.\n\t * @param props.fieldErrors - Per-field validation messages keyed by field name.\n\t * @param props.fields - Original submitted field values (useful for repopulating forms).\n\t * @param props.data - Any extra data to include in the response body.\n\t */\n\tconstructor(props: {\n\t\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\t\tdata?: any;\n\t\tfieldErrors?: Record<string, string>;\n\t\tfields?: Record<string, string>;\n\t\tmessage?: string;\n\t}) {\n\t\tsuper(props.message || \"Unprocessable entity\");\n\n\t\tthis.name = \"UnprocessableEntity\";\n\t\tthis.status = 422;\n\t\tthis.statusText = props.message || \"Unprocessable entity\";\n\t\tthis.debugColor = \"yellow\";\n\t\t// `cause` here is structured, redacted form-validation data meant for the\n\t\t// client (to repopulate the form) — unlike other responses' `cause`, it stays\n\t\t// visible in production.\n\t\tthis.exposeCauseInProduction = true;\n\t\tthis.cause = {\n\t\t\tdata: redactSensitiveValues(props.data),\n\t\t\tfieldErrors: props.fieldErrors,\n\t\t\tfields: redactSensitiveValues(props.fields),\n\t\t};\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header. */\n\ttoResponse(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn new Response(JSON.stringify(this.makeBody()), responseInit);\n\t}\n\n\t/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */\n\ttoJson(): Response {\n\t\tconst responseInit: ResponseInit = {\n\t\t\tstatus: this.status,\n\t\t\tstatusText: this.statusText,\n\t\t};\n\n\t\treturn Response.json(this.makeBody(), responseInit);\n\t}\n}\n\nexport { UnprocessableEntity };\n"],"mappings":";;;;AAUA,SAAS,EAAyB,GAAa;CAC9C,IAAI,MAAU,KAAA,GAAW,OAAO;CAEhC,IAAI;EACH,OAAO,KAAK,MACX,EAAmB,KAAK,UAAU,CAAK,GAAG,CAAC,GAAG,CAAmB,CAAC,CACnE;CACD,QAAQ;EACP,OAAO;CACR;AACD;AAeA,IAAM,IAAN,cAAkC,EAAY;CAO7C,YAAY,GAMT;EAiBF,AAhBA,MAAM,EAAM,WAAW,sBAAsB,GAE7C,KAAK,OAAO,uBACZ,KAAK,SAAS,KACd,KAAK,aAAa,EAAM,WAAW,wBACnC,KAAK,aAAa,UAIlB,KAAK,0BAA0B,IAC/B,KAAK,QAAQ;GACZ,MAAM,EAAsB,EAAM,IAAI;GACtC,aAAa,EAAM;GACnB,QAAQ,EAAsB,EAAM,MAAM;EAC3C,GAEA,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,KAAK,UAAU,KAAK,SAAS,CAAC,GAAG,CAAY;CAClE;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,SAAS,GAAG,CAAY;CACnD;AACD"}
|