@arkyn/server 3.0.1-beta.201 → 3.0.1-beta.204
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/LICENSE.txt +184 -1
- package/README.md +1 -1
- package/dist/http/api/{deleteRequest.d.ts → _deleteRequest.d.ts} +1 -1
- package/dist/http/api/_deleteRequest.d.ts.map +1 -0
- package/dist/http/api/{getRequest.d.ts → _getRequest.d.ts} +1 -1
- package/dist/http/api/_getRequest.d.ts.map +1 -0
- package/dist/{services/logMapperService.d.ts → http/api/_logMapperService.d.ts} +1 -1
- package/dist/http/api/_logMapperService.d.ts.map +1 -0
- package/dist/http/api/{patchRequest.d.ts → _patchRequest.d.ts} +1 -1
- package/dist/http/api/_patchRequest.d.ts.map +1 -0
- package/dist/http/api/{postRequest.d.ts → _postRequest.d.ts} +1 -1
- package/dist/http/api/_postRequest.d.ts.map +1 -0
- package/dist/http/api/{putRequest.d.ts → _putRequest.d.ts} +1 -1
- package/dist/http/api/_putRequest.d.ts.map +1 -0
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -0
- package/dist/modules/http/api/{deleteRequest.js → _deleteRequest.js} +3 -1
- package/dist/modules/http/api/_deleteRequest.js.map +1 -0
- package/dist/modules/http/api/{getRequest.js → _getRequest.js} +3 -1
- package/dist/modules/http/api/_getRequest.js.map +1 -0
- package/dist/modules/{services/logMapperService.js → http/api/_logMapperService.js} +3 -1
- package/dist/modules/http/api/_logMapperService.js.map +1 -0
- package/dist/modules/http/api/_logRequest.js +2 -0
- package/dist/modules/http/api/_logRequest.js.map +1 -0
- package/dist/modules/http/api/_makeRequest.js +3 -1
- package/dist/modules/http/api/_makeRequest.js.map +1 -0
- package/dist/modules/http/api/{patchRequest.js → _patchRequest.js} +3 -1
- package/dist/modules/http/api/_patchRequest.js.map +1 -0
- package/dist/modules/http/api/{postRequest.js → _postRequest.js} +3 -1
- package/dist/modules/http/api/_postRequest.js.map +1 -0
- package/dist/modules/http/api/{putRequest.js → _putRequest.js} +3 -1
- package/dist/modules/http/api/_putRequest.js.map +1 -0
- package/dist/modules/http/badResponses/_badResponse.js +2 -0
- package/dist/modules/http/badResponses/_badResponse.js.map +1 -0
- package/dist/modules/http/badResponses/badGateway.js +2 -0
- package/dist/modules/http/badResponses/badGateway.js.map +1 -0
- package/dist/modules/http/badResponses/badRequest.js +2 -0
- package/dist/modules/http/badResponses/badRequest.js.map +1 -0
- package/dist/modules/http/badResponses/conflict.js +2 -0
- package/dist/modules/http/badResponses/conflict.js.map +1 -0
- package/dist/modules/http/badResponses/forbidden.js +2 -0
- package/dist/modules/http/badResponses/forbidden.js.map +1 -0
- package/dist/modules/http/badResponses/notFound.js +2 -0
- package/dist/modules/http/badResponses/notFound.js.map +1 -0
- package/dist/modules/http/badResponses/notImplemented.js +2 -0
- package/dist/modules/http/badResponses/notImplemented.js.map +1 -0
- package/dist/modules/http/badResponses/serverError.js +2 -0
- package/dist/modules/http/badResponses/serverError.js.map +1 -0
- package/dist/modules/http/badResponses/unauthorized.js +2 -0
- package/dist/modules/http/badResponses/unauthorized.js.map +1 -0
- package/dist/modules/http/badResponses/unprocessableEntity.js +2 -0
- package/dist/modules/http/badResponses/unprocessableEntity.js.map +1 -0
- package/dist/modules/http/successResponses/_successResponse.js +2 -0
- package/dist/modules/http/successResponses/_successResponse.js.map +1 -0
- package/dist/modules/http/successResponses/created.js +2 -0
- package/dist/modules/http/successResponses/created.js.map +1 -0
- package/dist/modules/http/successResponses/found.js +2 -0
- package/dist/modules/http/successResponses/found.js.map +1 -0
- package/dist/modules/http/successResponses/noContent.js +2 -0
- package/dist/modules/http/successResponses/noContent.js.map +1 -0
- package/dist/modules/http/successResponses/success.js +2 -0
- package/dist/modules/http/successResponses/success.js.map +1 -0
- package/dist/modules/http/successResponses/updated.js +2 -0
- package/dist/modules/http/successResponses/updated.js.map +1 -0
- package/dist/modules/services/apiService.js +7 -5
- package/dist/modules/services/apiService.js.map +1 -0
- package/dist/modules/services/debugService.js +2 -0
- package/dist/modules/services/debugService.js.map +1 -0
- package/dist/modules/services/logService.js +2 -0
- package/dist/modules/services/logService.js.map +1 -0
- package/dist/modules/utilities/decodeRequestBody.js +2 -0
- package/dist/modules/utilities/decodeRequestBody.js.map +1 -0
- package/dist/modules/utilities/decodeRequestErrorMessage.js +2 -0
- package/dist/modules/utilities/decodeRequestErrorMessage.js.map +1 -0
- package/dist/modules/utilities/errorHandler.js +2 -0
- package/dist/modules/utilities/errorHandler.js.map +1 -0
- package/dist/modules/utilities/flushDebugLogs.js +2 -0
- package/dist/modules/utilities/flushDebugLogs.js.map +1 -0
- package/dist/modules/utilities/formAsyncParse.js +2 -0
- package/dist/modules/utilities/formAsyncParse.js.map +1 -0
- package/dist/modules/utilities/formParse.js +2 -0
- package/dist/modules/utilities/formParse.js.map +1 -0
- package/dist/modules/utilities/getScopedParams.js +2 -0
- package/dist/modules/utilities/getScopedParams.js.map +1 -0
- package/dist/modules/utilities/schemaValidator.js +2 -0
- package/dist/modules/utilities/schemaValidator.js.map +1 -0
- package/dist/modules/validations/validateCep.js +2 -0
- package/dist/modules/validations/validateCep.js.map +1 -0
- package/dist/modules/validations/validateCnpj.js +2 -0
- package/dist/modules/validations/validateCnpj.js.map +1 -0
- package/dist/modules/validations/validateCpf.js +2 -0
- package/dist/modules/validations/validateCpf.js.map +1 -0
- package/dist/modules/validations/validateDate.js +2 -0
- package/dist/modules/validations/validateDate.js.map +1 -0
- package/dist/modules/validations/validateEmail.js +2 -0
- package/dist/modules/validations/validateEmail.js.map +1 -0
- package/dist/modules/validations/validatePassword.js +2 -0
- package/dist/modules/validations/validatePassword.js.map +1 -0
- package/dist/modules/validations/validatePhone.js +2 -0
- package/dist/modules/validations/validatePhone.js.map +1 -0
- package/dist/modules/validations/validateRg.js +2 -0
- package/dist/modules/validations/validateRg.js.map +1 -0
- package/package.json +116 -5
- package/dist/http/api/deleteRequest.d.ts.map +0 -1
- package/dist/http/api/getRequest.d.ts.map +0 -1
- package/dist/http/api/patchRequest.d.ts.map +0 -1
- package/dist/http/api/postRequest.d.ts.map +0 -1
- package/dist/http/api/putRequest.d.ts.map +0 -1
- package/dist/modules/index.js +0 -34
- package/dist/services/logMapperService.d.ts.map +0 -1
|
@@ -0,0 +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":";;AAmBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,MAAM,EAAM;CACb,CAAC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { makeRequest as e } from "./_makeRequest.js";
|
|
2
|
-
//#region src/http/api/
|
|
2
|
+
//#region src/http/api/_getRequest.ts
|
|
3
3
|
async function t(t) {
|
|
4
4
|
return e({
|
|
5
5
|
method: "GET",
|
|
@@ -10,3 +10,5 @@ async function t(t) {
|
|
|
10
10
|
}
|
|
11
11
|
//#endregion
|
|
12
12
|
export { t as getRequest };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=_getRequest.js.map
|
|
@@ -0,0 +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":";;AAiBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;CAChB,CAAC;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/http/api/_logMapperService.ts
|
|
2
2
|
var e = class e {
|
|
3
3
|
static mapHeaders(e) {
|
|
4
4
|
return e instanceof Headers ? Object.fromEntries(e.entries()) : typeof e == "object" ? Object.entries(e).reduce((e, [t, n]) => (typeof n == "string" ? e[t] = n : Array.isArray(n) ? e[t] = n.join(", ") : e[t] = JSON.stringify(n), e), {}) : {};
|
|
@@ -29,3 +29,5 @@ var e = class e {
|
|
|
29
29
|
};
|
|
30
30
|
//#endregion
|
|
31
31
|
export { e as LogMapperService };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=_logMapperService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_logMapperService.js","names":[],"sources":["../../../../src/http/api/_logMapperService.ts"],"sourcesContent":["/**\n * Input properties for log mapping.\n *\n * @typedef {object} InputProps\n * @property {number} status - HTTP response status code.\n * @property {string} url - The request URL.\n * @property {\"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\"} method - HTTP method used.\n * @property {HeadersInit} requestHeaders - Headers sent with the request.\n * @property {HeadersInit} responseHeaders - Headers received in the response.\n * @property {any} requestBody - Body of the request.\n * @property {number} elapsedTime - Time elapsed for the request in milliseconds.\n * @property {any} responseBody - Body of the response.\n * @property {URLSearchParams} queryParams - Query parameters from the URL.\n */\ntype InputProps = {\n\tstatus: number;\n\trawUrl: string;\n\turlParams?: Record<string, string>;\n\tmethod: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\trequestHeaders: HeadersInit;\n\tresponseHeaders: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\trequestBody: any;\n\telapsedTime: number;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tresponseBody: any;\n\tqueryParams: URLSearchParams;\n};\n\n/**\n * Output properties after log mapping transformation.\n *\n * @typedef {object} OutputProps\n * @property {string} rawUrl - The original request URL.\n * @property {number} status - HTTP response status code.\n * @property {\"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\"} method - HTTP method used.\n * @property {string | null} token - Authentication token (if present).\n * @property {number} elapsedTime - Time elapsed for the request in milliseconds.\n * @property {Record<string, string>} requestHeaders - Mapped request headers.\n * @property {Record<string, string>} requestBody - Mapped request body.\n * @property {Record<string, string>} queryParams - Mapped query parameters.\n * @property {Record<string, string>} responseHeaders - Mapped response headers.\n * @property {any} responseBody - The response body.\n */\ntype OutputProps = {\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\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tresponseBody: any;\n};\n\n/**\n * Static service for mapping HTTP request/response data into a standardized log format.\n *\n * Provides utilities to transform headers and query parameters into plain objects,\n * and produces a unified output structure for logging purposes.\n */\nclass LogMapperService {\n\t/**\n\t * Converts various header formats into a plain key-value object.\n\t *\n\t * @param {HeadersInit} headers - The headers to map.\n\t * @returns {Record<string, string>} A plain object with header key-value pairs.\n\t * @private\n\t */\n\tprivate static mapHeaders(headers: HeadersInit): Record<string, string> {\n\t\tif (headers instanceof Headers) {\n\t\t\treturn Object.fromEntries(headers.entries());\n\t\t} else if (typeof headers === \"object\") {\n\t\t\treturn Object.entries(headers).reduce(\n\t\t\t\t(acc, [key, value]) => {\n\t\t\t\t\tif (typeof value === \"string\") acc[key] = value;\n\t\t\t\t\telse if (Array.isArray(value)) acc[key] = value.join(\", \");\n\t\t\t\t\telse acc[key] = JSON.stringify(value);\n\t\t\t\t\treturn acc;\n\t\t\t\t},\n\t\t\t\t{} as Record<string, string>,\n\t\t\t);\n\t\t}\n\t\treturn {};\n\t}\n\n\t/**\n\t * Converts URLSearchParams into a plain key-value object.\n\t *\n\t * @param {URLSearchParams} queryParams - The query parameters to map.\n\t * @returns {Record<string, string>} A plain object with query parameter key-value pairs.\n\t * @private\n\t */\n\tprivate static mapQueryParams(\n\t\tqueryParams: URLSearchParams,\n\t): Record<string, string> {\n\t\tconst params: Record<string, string> = {};\n\n\t\tqueryParams.forEach((value, key) => {\n\t\t\tparams[key] = value;\n\t\t});\n\n\t\treturn params;\n\t}\n\n\t/**\n\t * Transforms raw HTTP request/response data into a standardized log output format.\n\t *\n\t * @param {InputProps} props - The input properties containing request/response data.\n\t * @returns {OutputProps} The mapped output object ready for logging.\n\t */\n\tstatic handle(props: InputProps): OutputProps {\n\t\treturn {\n\t\t\trawUrl: props.rawUrl,\n\t\t\tstatus: props.status,\n\t\t\tmethod: props.method,\n\t\t\ttoken: null,\n\t\t\telapsedTime: props.elapsedTime,\n\t\t\trequestHeaders: LogMapperService.mapHeaders(props.requestHeaders),\n\t\t\trequestBody: props.requestBody || null,\n\t\t\tqueryParams: {\n\t\t\t\t...LogMapperService.mapQueryParams(props.queryParams),\n\t\t\t\t...props.urlParams,\n\t\t\t},\n\t\t\tresponseHeaders: LogMapperService.mapHeaders(props.responseHeaders),\n\t\t\tresponseBody: props.responseBody || null,\n\t\t};\n\t}\n}\n\nexport { LogMapperService };\n"],"mappings":";AAgEA,IAAM,IAAN,MAAM,EAAiB;CAQtB,OAAe,WAAW,GAA8C;EAcvE,OAbI,aAAmB,UACf,OAAO,YAAY,EAAQ,QAAQ,CAAC,IACjC,OAAO,KAAY,WACtB,OAAO,QAAQ,CAAO,CAAC,CAAC,QAC7B,GAAK,CAAC,GAAK,QACP,OAAO,KAAU,WAAU,EAAI,KAAO,IACjC,MAAM,QAAQ,CAAK,IAAG,EAAI,KAAO,EAAM,KAAK,IAAI,IACpD,EAAI,KAAO,KAAK,UAAU,CAAK,GAC7B,IAER,CAAC,CACF,IAEM,CAAC;CACT;CASA,OAAe,eACd,GACyB;EACzB,IAAM,IAAiC,CAAC;EAMxC,OAJA,EAAY,SAAS,GAAO,MAAQ;GACnC,EAAO,KAAO;EACf,CAAC,GAEM;CACR;CAQA,OAAO,OAAO,GAAgC;EAC7C,OAAO;GACN,QAAQ,EAAM;GACd,QAAQ,EAAM;GACd,QAAQ,EAAM;GACd,OAAO;GACP,aAAa,EAAM;GACnB,gBAAgB,EAAiB,WAAW,EAAM,cAAc;GAChE,aAAa,EAAM,eAAe;GAClC,aAAa;IACZ,GAAG,EAAiB,eAAe,EAAM,WAAW;IACpD,GAAG,EAAM;GACV;GACA,iBAAiB,EAAiB,WAAW,EAAM,eAAe;GAClE,cAAc,EAAM,gBAAgB;EACrC;CACD;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_logRequest.js","names":[],"sources":["../../../../src/http/api/_logRequest.ts"],"sourcesContent":["import { formatJsonObject } from \"@arkyn/shared\";\nimport { flushDebugLogs } from \"../..\";\nimport { LogService } from \"../../services/logService\";\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 { userToken, apiUrl, trafficSourceId } = arkynService;\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\trequestHeaders: JSON.stringify(requestHeaders),\n\t\t\trequestBody: JSON.stringify(requestBody),\n\t\t\tqueryParams: JSON.stringify(queryParams),\n\t\t\tresponseHeaders: JSON.stringify(responseHeaders),\n\t\t\tresponseBody: JSON.stringify(responseBody),\n\t\t});\n\n\t\tconst headers = {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t\tAuthorization: `Bearer ${userToken}`,\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":";;;;AA6DA,eAAe,EAAW,GAAoC;CAC7D,IAAM,IAAe,EAAW,UAAU;CAC1C,IAAI,CAAC,GAAc;CAEnB,IAAM,EAAE,cAAW,WAAQ,uBAAoB,GAEzC,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;GACA,gBAAgB,KAAK,UAAU,CAAc;GAC7C,aAAa,KAAK,UAAU,CAAW;GACvC,aAAa,KAAK,UAAU,CAAW;GACvC,iBAAiB,KAAK,UAAU,CAAe;GAC/C,cAAc,KAAK,UAAU,CAAY;EAC1C,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { flushDebugLogs as e } from "../../utilities/flushDebugLogs.js";
|
|
2
|
-
import { LogMapperService as t } from "
|
|
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
5
|
async function r(r) {
|
|
@@ -68,3 +68,5 @@ async function r(r) {
|
|
|
68
68
|
}
|
|
69
69
|
//#endregion
|
|
70
70
|
export { r as makeRequest };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=_makeRequest.js.map
|
|
@@ -0,0 +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\tconst response = await fetch(url, {\n\t\t\theaders,\n\t\t\tmethod: input.method,\n\t\t\tbody: input.body ? JSON.stringify(input.body) : undefined,\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\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":";;;;AAwEA,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;CAEA,IAAI;EACH,IAAM,IAAY,YAAY,IAAI,GAE5B,IAAU;GAAE,GAAG,EAAM;GAAS,gBAAgB;EAAmB,GACjE,IAAW,MAAM,MAAM,GAAK;GACjC;GACA,QAAQ,EAAM;GACd,MAAM,EAAM,OAAO,KAAK,UAAU,EAAM,IAAI,IAAI,KAAA;EACjD,CAAC,GAEK,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;EAOb,OANA,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,5 +1,5 @@
|
|
|
1
1
|
import { makeRequest as e } from "./_makeRequest.js";
|
|
2
|
-
//#region src/http/api/
|
|
2
|
+
//#region src/http/api/_patchRequest.ts
|
|
3
3
|
async function t(t) {
|
|
4
4
|
return e({
|
|
5
5
|
method: "PATCH",
|
|
@@ -11,3 +11,5 @@ async function t(t) {
|
|
|
11
11
|
}
|
|
12
12
|
//#endregion
|
|
13
13
|
export { t as patchRequest };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=_patchRequest.js.map
|
|
@@ -0,0 +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":";;AAmBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,MAAM,EAAM;CACb,CAAC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { makeRequest as e } from "./_makeRequest.js";
|
|
2
|
-
//#region src/http/api/
|
|
2
|
+
//#region src/http/api/_postRequest.ts
|
|
3
3
|
async function t(t) {
|
|
4
4
|
return e({
|
|
5
5
|
method: "POST",
|
|
@@ -11,3 +11,5 @@ async function t(t) {
|
|
|
11
11
|
}
|
|
12
12
|
//#endregion
|
|
13
13
|
export { t as postRequest };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=_postRequest.js.map
|
|
@@ -0,0 +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":";;AAmBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,MAAM,EAAM;CACb,CAAC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { makeRequest as e } from "./_makeRequest.js";
|
|
2
|
-
//#region src/http/api/
|
|
2
|
+
//#region src/http/api/_putRequest.ts
|
|
3
3
|
async function t(t) {
|
|
4
4
|
return e({
|
|
5
5
|
method: "PUT",
|
|
@@ -11,3 +11,5 @@ async function t(t) {
|
|
|
11
11
|
}
|
|
12
12
|
//#endregion
|
|
13
13
|
export { t as putRequest };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=_putRequest.js.map
|
|
@@ -0,0 +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":";;AAmBA,eAAe,EACd,GAC6B;CAC7B,OAAO,EAAY;EAClB,QAAQ;EACR,KAAK,EAAM;EACX,WAAW,EAAM;EACjB,SAAS,EAAM;EACf,MAAM,EAAM;CACb,CAAC;AACF"}
|
|
@@ -0,0 +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\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\treturn {\n\t\t\tname: this._name,\n\t\t\tmessage: this._statusText,\n\t\t\tcause: this._cause,\n\t\t};\n\t}\n}\n\nexport { BadResponse };\n"],"mappings":";;;;AAKA,IAAM,IAAN,MAAkB;CAEjB;CACA,QAAwB;CACxB,UAA0B;CAC1B,cAA8B;CAC9B,cAA2D;CAG3D,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;EACV,OAAO;GACN,MAAM,KAAK;GACX,SAAS,KAAK;GACd,OAAO,KAAK;EACb;CACD;AACD"}
|
|
@@ -0,0 +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 (serialized to JSON in the response).\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"BadGateway\";\n\t\tthis.status = 502;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause ? JSON.stringify(cause) : undefined;\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,GAEN,KAAK,OAAO,cACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,IAAQ,KAAK,UAAU,CAAK,IAAI,KAAA,GAE7C,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"}
|
|
@@ -0,0 +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 (serialized to JSON).\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"BadRequest\";\n\t\tthis.status = 400;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause ? JSON.stringify(cause) : undefined;\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,GAEN,KAAK,OAAO,cACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,IAAQ,KAAK,UAAU,CAAK,IAAI,KAAA,GAE7C,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"}
|
|
@@ -0,0 +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 (serialized to JSON).\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper();\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 ? JSON.stringify(cause) : undefined;\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,GAEN,KAAK,OAAO,YACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,aAAa,UAClB,KAAK,QAAQ,IAAQ,KAAK,UAAU,CAAK,IAAI,KAAA,GAE7C,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"}
|
|
@@ -0,0 +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 (serialized to JSON).\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"Forbidden\";\n\t\tthis.status = 403;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause ? JSON.stringify(cause) : undefined;\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,GAEN,KAAK,OAAO,aACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,IAAQ,KAAK,UAAU,CAAK,IAAI,KAAA,GAE7C,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"}
|
|
@@ -0,0 +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 (serialized to JSON).\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"NotFound\";\n\t\tthis.status = 404;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause ? JSON.stringify(cause) : undefined;\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,GAEN,KAAK,OAAO,YACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,IAAQ,KAAK,UAAU,CAAK,IAAI,KAAA,GAE7C,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"}
|
|
@@ -0,0 +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 (serialized to JSON).\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"NotImplemented\";\n\t\tthis.status = 501;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause ? JSON.stringify(cause) : undefined;\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,GAEN,KAAK,OAAO,kBACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,IAAQ,KAAK,UAAU,CAAK,IAAI,KAAA,GAE7C,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"}
|
|
@@ -0,0 +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 (serialized to JSON).\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"ServerError\";\n\t\tthis.status = 500;\n\t\tthis.statusText = message;\n\t\tthis.cause = cause ? JSON.stringify(cause) : undefined;\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,GAEN,KAAK,OAAO,eACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,QAAQ,IAAQ,KAAK,UAAU,CAAK,IAAI,KAAA,GAE7C,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"}
|
|
@@ -0,0 +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 (serialized to JSON).\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, cause?: any) {\n\t\tsuper();\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 ? JSON.stringify(cause) : undefined;\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,GAEN,KAAK,OAAO,gBACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,aAAa,UAClB,KAAK,QAAQ,IAAQ,KAAK,UAAU,CAAK,IAAI,KAAA,GAE7C,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unprocessableEntity.js","names":[],"sources":["../../../../src/http/badResponses/unprocessableEntity.ts"],"sourcesContent":["import { BadResponse } from \"./_badResponse\";\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\tthis.cause = {\n\t\t\tdata: props.data,\n\t\t\tfieldErrors: props.fieldErrors,\n\t\t\tfields: 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":";;AAeA,IAAM,IAAN,cAAkC,EAAY;CAO7C,YAAY,GAMT;EAaF,AAZA,MAAM,GAEN,KAAK,OAAO,uBACZ,KAAK,SAAS,KACd,KAAK,aAAa,EAAM,WAAW,wBACnC,KAAK,aAAa,UAClB,KAAK,QAAQ;GACZ,MAAM,EAAM;GACZ,aAAa,EAAM;GACnB,QAAQ,EAAM;EACf,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_successResponse.js","names":[],"sources":["../../../../src/http/successResponses/_successResponse.ts"],"sourcesContent":["import { DebugService } from \"../../services/debugService\";\nimport { flushDebugLogs } from \"../../utilities/flushDebugLogs\";\n\n/**\n * Base class for handling successful HTTP responses with debugging capabilities.\n * Provides logging functionality to track response and their context.\n */\nclass SuccessResponse {\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tprivate _body: any = null;\n\tprivate _name: string = \"SuccessResponse\";\n\tprivate _status: number = 200;\n\tprivate _statusText: string = \"OK\";\n\tprivate _debugColor: \"green\" | \"yellow\" | \"cyan\" | \"red\" = \"green\";\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tget body(): any {\n\t\treturn this._body;\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tset body(value: any) {\n\t\tthis._body = value ?? null;\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\t/**\n\t * Logs debug information for success responses including caller context and response details.\n\t *\n\t * @param {any} body - The response body or success data to be logged\n\t *\n\t * @example\n\t * ```typescript\n\t * const SuccessResponse = new SuccessResponse();\n\t * SuccessResponse.onDebug({ data: \"Operation completed successfully\" });\n\t * ```\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tonDebug(body?: any): void {\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 (body) debugs.push(`Body: ${JSON.stringify(body)}`);\n\n\t\tflushDebugLogs({ scheme: this._debugColor, name: this.name, debugs });\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tmakeBody(): any {\n\t\treturn {\n\t\t\tname: this.name,\n\t\t\tmessage: this.statusText,\n\t\t\tbody: this.body,\n\t\t};\n\t}\n}\n\nexport { SuccessResponse };\n"],"mappings":";;;AAOA,IAAM,IAAN,MAAsB;CAErB,QAAqB;CACrB,QAAwB;CACxB,UAA0B;CAC1B,cAA8B;CAC9B,cAA2D;CAG3D,IAAI,OAAY;EACf,OAAO,KAAK;CACb;CAGA,IAAI,KAAK,GAAY;EACpB,KAAK,QAAQ,KAAS;CACvB;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;CAcA,QAAQ,GAAkB;EACzB,IAAM,IAAmB,CAAC,GACpB,EAAE,eAAY,oBAAiB,EAAa,UAAU;EAQ5D,AANA,EAAO,KAAK,oBAAoB,GAAc,GAC9C,EAAO,KAAK,oBAAoB,GAAY,GAExC,KAAK,cAAY,EAAO,KAAK,YAAY,KAAK,YAAY,GAC1D,KAAM,EAAO,KAAK,SAAS,KAAK,UAAU,CAAI,GAAG,GAErD,EAAe;GAAE,QAAQ,KAAK;GAAa,MAAM,KAAK;GAAM;EAAO,CAAC;CACrE;CAGA,WAAgB;EACf,OAAO;GACN,MAAM,KAAK;GACX,SAAS,KAAK;GACd,MAAM,KAAK;EACZ;CACD;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"created.js","names":[],"sources":["../../../../src/http/successResponses/created.ts"],"sourcesContent":["import { SuccessResponse } from \"./_successResponse\";\n\n/**\n * HTTP 201 Created — the request succeeded and a new resource was created.\n *\n * @example\n * ```typescript\n * return new Created(\"User created successfully\", { id: user.id }).toJson();\n * ```\n */\nclass Created extends SuccessResponse {\n\t/**\n\t * @param message - Description included in the response status text.\n\t * @param body - Data to include in the response body.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, body?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"Created\";\n\t\tthis.status = 201;\n\t\tthis.statusText = message;\n\t\tthis.body = body || undefined;\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.body), 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.body, responseInit);\n\t}\n}\n\nexport { Created };\n"],"mappings":";;AAUA,IAAM,IAAN,cAAsB,EAAgB;CAMrC,YAAY,GAAiB,GAAY;EAQxC,AAPA,MAAM,GAEN,KAAK,OAAO,WACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,OAAO,KAAQ,KAAA,GAEpB,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,IAAI,GAAG,CAAY;CAC5D;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,MAAM,CAAY;CAC7C;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"found.js","names":[],"sources":["../../../../src/http/successResponses/found.ts"],"sourcesContent":["import { SuccessResponse } from \"./_successResponse\";\n\n/**\n * HTTP 302 Found — the resource was located and the response includes it in the body.\n *\n * @example\n * ```typescript\n * return new Found(\"Products retrieved\", { products }).toJson();\n * ```\n */\nclass Found extends SuccessResponse {\n\t/**\n\t * @param message - Description included in the response status text.\n\t * @param body - Data to include in the response body.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, body?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"Found\";\n\t\tthis.status = 302;\n\t\tthis.statusText = message;\n\t\tthis.body = body || undefined;\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.body), 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.body, responseInit);\n\t}\n}\n\nexport { Found };\n"],"mappings":";;AAUA,IAAM,IAAN,cAAoB,EAAgB;CAMnC,YAAY,GAAiB,GAAY;EAQxC,AAPA,MAAM,GAEN,KAAK,OAAO,SACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,OAAO,KAAQ,KAAA,GAEpB,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,IAAI,GAAG,CAAY;CAC5D;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,MAAM,CAAY;CAC7C;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noContent.js","names":[],"sources":["../../../../src/http/successResponses/noContent.ts"],"sourcesContent":["import { SuccessResponse } from \"./_successResponse\";\n\n/**\n * HTTP 204 No Content — the request succeeded but there is no content to return.\n * Typically used for delete or update operations where a body is not needed.\n *\n * @example\n * ```typescript\n * return new NoContent(\"Record deleted\").toResponse();\n * ```\n */\nclass NoContent extends SuccessResponse {\n\t/**\n\t * @param message - Description included in the response status text.\n\t */\n\tconstructor(message: string) {\n\t\tsuper();\n\n\t\tthis.name = \"NoContent\";\n\t\tthis.status = 204;\n\t\tthis.statusText = message;\n\n\t\tthis.onDebug();\n\t}\n\n\t/** Converts to a `Response` with `Content-Type: application/json` header and no body. */\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(null, responseInit);\n\t}\n}\n\nexport { NoContent };\n"],"mappings":";;AAWA,IAAM,IAAN,cAAwB,EAAgB;CAIvC,YAAY,GAAiB;EAO5B,AANA,MAAM,GAEN,KAAK,OAAO,aACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAElB,KAAK,QAAQ;CACd;CAGA,aAAuB;EACtB,IAAM,IAA6B;GAClC,SAAS,EAAE,gBAAgB,mBAAmB;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,IAAI,SAAS,MAAM,CAAY;CACvC;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"success.js","names":[],"sources":["../../../../src/http/successResponses/success.ts"],"sourcesContent":["import { SuccessResponse } from \"./_successResponse\";\n\n/**\n * HTTP 200 OK — the request succeeded and the response body contains the result.\n *\n * @example\n * ```typescript\n * return new Success(\"Order fetched\", { order }).toJson();\n * ```\n */\nclass Success extends SuccessResponse {\n\t/**\n\t * @param message - Description included in the response status text.\n\t * @param body - Data to include in the response body.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, body?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"Success\";\n\t\tthis.status = 200;\n\t\tthis.statusText = message;\n\t\tthis.body = body || undefined;\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.body), 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.body, responseInit);\n\t}\n}\n\nexport { Success };\n"],"mappings":";;AAUA,IAAM,IAAN,cAAsB,EAAgB;CAMrC,YAAY,GAAiB,GAAY;EAQxC,AAPA,MAAM,GAEN,KAAK,OAAO,WACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,OAAO,KAAQ,KAAA,GAEpB,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,IAAI,GAAG,CAAY;CAC5D;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,MAAM,CAAY;CAC7C;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updated.js","names":[],"sources":["../../../../src/http/successResponses/updated.ts"],"sourcesContent":["import { SuccessResponse } from \"./_successResponse\";\n\n/**\n * HTTP 200 OK — the request succeeded and the resource was updated.\n * Semantically equivalent to `Success` but signals an update operation to consumers.\n *\n * @example\n * ```typescript\n * return new Updated(\"Profile updated\", { user }).toJson();\n * ```\n */\nclass Updated extends SuccessResponse {\n\t/**\n\t * @param message - Description included in the response status text.\n\t * @param body - Data to include in the response body.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tconstructor(message: string, body?: any) {\n\t\tsuper();\n\n\t\tthis.name = \"Updated\";\n\t\tthis.status = 200;\n\t\tthis.statusText = message;\n\t\tthis.body = body || undefined;\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.body), 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.body, responseInit);\n\t}\n}\n\nexport { Updated };\n"],"mappings":";;AAWA,IAAM,IAAN,cAAsB,EAAgB;CAMrC,YAAY,GAAiB,GAAY;EAQxC,AAPA,MAAM,GAEN,KAAK,OAAO,WACZ,KAAK,SAAS,KACd,KAAK,aAAa,GAClB,KAAK,OAAO,KAAQ,KAAA,GAEpB,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,IAAI,GAAG,CAAY;CAC5D;CAGA,SAAmB;EAClB,IAAM,IAA6B;GAClC,QAAQ,KAAK;GACb,YAAY,KAAK;EAClB;EAEA,OAAO,SAAS,KAAK,KAAK,MAAM,CAAY;CAC7C;AACD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { flushDebugLogs as e } from "../utilities/flushDebugLogs.js";
|
|
2
|
-
import { deleteRequest as t } from "../http/api/
|
|
3
|
-
import { getRequest as n } from "../http/api/
|
|
4
|
-
import { patchRequest as r } from "../http/api/
|
|
5
|
-
import { postRequest as i } from "../http/api/
|
|
6
|
-
import { putRequest as a } from "../http/api/
|
|
2
|
+
import { deleteRequest as t } from "../http/api/_deleteRequest.js";
|
|
3
|
+
import { getRequest as n } from "../http/api/_getRequest.js";
|
|
4
|
+
import { patchRequest as r } from "../http/api/_patchRequest.js";
|
|
5
|
+
import { postRequest as i } from "../http/api/_postRequest.js";
|
|
6
|
+
import { putRequest as a } from "../http/api/_putRequest.js";
|
|
7
7
|
//#region src/services/apiService.ts
|
|
8
8
|
var o = class {
|
|
9
9
|
baseUrl;
|
|
@@ -107,3 +107,5 @@ var o = class {
|
|
|
107
107
|
};
|
|
108
108
|
//#endregion
|
|
109
109
|
export { o as ApiService };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=apiService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiService.js","names":[],"sources":["../../../src/services/apiService.ts"],"sourcesContent":["import { deleteRequest } from \"../http/api/_deleteRequest\";\nimport { getRequest } from \"../http/api/_getRequest\";\nimport { patchRequest } from \"../http/api/_patchRequest\";\nimport { postRequest } from \"../http/api/_postRequest\";\nimport { putRequest } from \"../http/api/_putRequest\";\nimport { flushDebugLogs } from \"../utilities/flushDebugLogs\";\n\ntype ApiServiceConstructorProps = {\n\t/** Base URL prepended to every request path (e.g. `\"https://api.example.com\"`). */\n\tbaseUrl: string;\n\t/** Default headers merged into every request. */\n\tbaseHeaders?: HeadersInit;\n\t/** Default Bearer token; can be overridden per request via `data.token`. */\n\tbaseToken?: string | null;\n\t/** When `true`, logs each request and response to the console in development. */\n\tenableDebug?: boolean;\n};\n\ntype ApiRequestDataWithoutBodyProps = {\n\theaders?: HeadersInit;\n\ttoken?: string;\n\turlParams?: Record<string, string>;\n};\n\ntype ApiRequestDataWithBodyProps = {\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n\theaders?: HeadersInit;\n\ttoken?: string;\n\turlParams?: Record<string, string>;\n};\n\ntype DebugConfig = {\n\theaders?: HeadersInit;\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tbody?: any;\n\tstatus: number;\n\tmessage: string;\n};\n\n/**\n * HTTP client for external API calls. Wraps fetch with base URL, default headers, optional auth token,\n * and per-request overrides for all standard HTTP methods.\n *\n * @example\n * ```typescript\n * const api = new ApiService({\n * baseUrl: \"https://api.example.com\",\n * baseToken: session.token,\n * enableDebug: true,\n * });\n *\n * const { data } = await api.get(\"/users/me\");\n * const { data: created } = await api.post(\"/orders\", { body: { productId: 1 } });\n * ```\n */\nclass ApiService {\n\tprivate baseUrl: string;\n\tprivate baseHeaders?: HeadersInit;\n\tprivate baseToken?: string;\n\tprivate enableDebug?: boolean;\n\n\tconstructor(props: ApiServiceConstructorProps) {\n\t\tthis.baseUrl = props.baseUrl;\n\t\tthis.baseHeaders = props.baseHeaders || undefined;\n\t\tthis.baseToken = props.baseToken || undefined;\n\t\tthis.enableDebug = props.enableDebug || false;\n\t}\n\n\tprivate onDebug(endpoint: string, method: string, data: DebugConfig) {\n\t\tif (this.enableDebug) {\n\t\t\tconst debugs: string[] = [];\n\t\t\tconst json = (data: unknown) => JSON.stringify(data, null, 2);\n\n\t\t\tdebugs.push(`Base URL: ${this.baseUrl}`);\n\t\t\tdebugs.push(`Endpoint: ${endpoint}`);\n\t\t\tdebugs.push(`Status/Method: ${method} => ${data.status}`);\n\t\t\tdebugs.push(`Message: ${data.message}`);\n\n\t\t\tif (data.headers) debugs.push(`Headers: ${json(data.headers)}`);\n\t\t\tif (data.body) debugs.push(`Body: ${json(data.body)}`);\n\n\t\t\tflushDebugLogs({ debugs, name: \"ApiDebug\", scheme: \"yellow\" });\n\t\t}\n\t}\n\n\tprivate generateHeaders(\n\t\tinitHeaders: HeadersInit,\n\t\ttoken?: string,\n\t): HeadersInit {\n\t\tlet headers: HeadersInit = {};\n\t\tif (this.baseToken) headers = { Authorization: `Bearer ${this.baseToken}` };\n\t\tif (this.baseHeaders) headers = { ...headers, ...this.baseHeaders };\n\n\t\tif (initHeaders) headers = { ...headers, ...initHeaders };\n\t\tif (token) headers = { ...headers, Authorization: `Bearer ${token}` };\n\n\t\treturn headers;\n\t}\n\n\t/**\n\t * Sends a get request to the specified endpoint.\n\t * @param endpoint - The API endpoint to send the get request to.\n\t * @param data - The request data, including optional headers and token.\n\t * @returns The API response data.\n\t */\n\n\tasync get(endpoint: string, data?: ApiRequestDataWithoutBodyProps) {\n\t\tconst headers = this.generateHeaders(data?.headers || {}, data?.token);\n\n\t\tconst response = await getRequest({\n\t\t\turl: this.baseUrl + endpoint,\n\t\t\turlParams: data?.urlParams || {},\n\t\t\theaders,\n\t\t});\n\n\t\tthis.onDebug(endpoint, \"get\", {\n\t\t\theaders,\n\t\t\tmessage: response.message,\n\t\t\tstatus: response.status,\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Sends a post request to the specified endpoint.\n\t * @param endpoint - The API endpoint to send the post request to.\n\t * @param data - The request data, including body, optional headers, and token.\n\t * @returns The API response data.\n\t */\n\n\tasync post(endpoint: string, data?: ApiRequestDataWithBodyProps) {\n\t\tconst headers = this.generateHeaders(data?.headers || {}, data?.token);\n\t\tconst body = data?.body;\n\n\t\tconst response = await postRequest({\n\t\t\turl: this.baseUrl + endpoint,\n\t\t\turlParams: data?.urlParams || {},\n\t\t\theaders,\n\t\t\tbody,\n\t\t});\n\n\t\tthis.onDebug(endpoint, \"post\", {\n\t\t\theaders,\n\t\t\tbody,\n\t\t\tmessage: response.message,\n\t\t\tstatus: response.status,\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Sends a put request to the specified endpoint.\n\t * @param endpoint - The API endpoint to send the put request to.\n\t * @param data - The request data, including body, optional headers, and token.\n\t * @returns The API response data.\n\t */\n\n\tasync put(endpoint: string, data?: ApiRequestDataWithBodyProps) {\n\t\tconst headers = this.generateHeaders(data?.headers || {}, data?.token);\n\t\tconst body = data?.body;\n\n\t\tconst response = await putRequest({\n\t\t\turl: this.baseUrl + endpoint,\n\t\t\turlParams: data?.urlParams || {},\n\t\t\theaders,\n\t\t\tbody,\n\t\t});\n\n\t\tthis.onDebug(endpoint, \"put\", {\n\t\t\theaders,\n\t\t\tbody,\n\t\t\tmessage: response.message,\n\t\t\tstatus: response.status,\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Sends a patch request to the specified endpoint.\n\t * @param endpoint - The API endpoint to send the patch request to.\n\t * @param data - The request data, including body, optional headers, and token.\n\t * @returns The API response data.\n\t */\n\n\tasync patch(endpoint: string, data?: ApiRequestDataWithBodyProps) {\n\t\tconst headers = this.generateHeaders(data?.headers || {}, data?.token);\n\t\tconst body = data?.body;\n\n\t\tconst response = await patchRequest({\n\t\t\turl: this.baseUrl + endpoint,\n\t\t\turlParams: data?.urlParams || {},\n\t\t\theaders,\n\t\t\tbody,\n\t\t});\n\n\t\tthis.onDebug(endpoint, \"patch\", {\n\t\t\theaders,\n\t\t\tbody,\n\t\t\tmessage: response.message,\n\t\t\tstatus: response.status,\n\t\t});\n\n\t\treturn response;\n\t}\n\n\t/**\n\t * Sends a delete request to the specified endpoint.\n\t * @param endpoint - The API endpoint to send the delete request to.\n\t * @param data - The request data, including body, optional headers, and token.\n\t * @returns The API response data.\n\t */\n\n\tasync delete(endpoint: string, data?: ApiRequestDataWithBodyProps) {\n\t\tconst headers = this.generateHeaders(data?.headers || {}, data?.token);\n\t\tconst body = data?.body;\n\n\t\tconst response = await deleteRequest({\n\t\t\turl: this.baseUrl + endpoint,\n\t\t\turlParams: data?.urlParams || {},\n\t\t\theaders,\n\t\t\tbody,\n\t\t});\n\n\t\tthis.onDebug(endpoint, \"delete\", {\n\t\t\theaders,\n\t\t\tbody,\n\t\t\tmessage: response.message,\n\t\t\tstatus: response.status,\n\t\t});\n\n\t\treturn response;\n\t}\n}\n\nexport { ApiService };\n"],"mappings":";;;;;;;AAwDA,IAAM,IAAN,MAAiB;CAChB;CACA;CACA;CACA;CAEA,YAAY,GAAmC;EAI9C,AAHA,KAAK,UAAU,EAAM,SACrB,KAAK,cAAc,EAAM,eAAe,KAAA,GACxC,KAAK,YAAY,EAAM,aAAa,KAAA,GACpC,KAAK,cAAc,EAAM,eAAe;CACzC;CAEA,QAAgB,GAAkB,GAAgB,GAAmB;EACpE,IAAI,KAAK,aAAa;GACrB,IAAM,IAAmB,CAAC,GACpB,KAAQ,MAAkB,KAAK,UAAU,GAAM,MAAM,CAAC;GAU5D,AARA,EAAO,KAAK,aAAa,KAAK,SAAS,GACvC,EAAO,KAAK,aAAa,GAAU,GACnC,EAAO,KAAK,kBAAkB,EAAO,MAAM,EAAK,QAAQ,GACxD,EAAO,KAAK,YAAY,EAAK,SAAS,GAElC,EAAK,WAAS,EAAO,KAAK,YAAY,EAAK,EAAK,OAAO,GAAG,GAC1D,EAAK,QAAM,EAAO,KAAK,SAAS,EAAK,EAAK,IAAI,GAAG,GAErD,EAAe;IAAE;IAAQ,MAAM;IAAY,QAAQ;GAAS,CAAC;EAC9D;CACD;CAEA,gBACC,GACA,GACc;EACd,IAAI,IAAuB,CAAC;EAO5B,OANI,KAAK,cAAW,IAAU,EAAE,eAAe,UAAU,KAAK,YAAY,IACtE,KAAK,gBAAa,IAAU;GAAE,GAAG;GAAS,GAAG,KAAK;EAAY,IAE9D,MAAa,IAAU;GAAE,GAAG;GAAS,GAAG;EAAY,IACpD,MAAO,IAAU;GAAE,GAAG;GAAS,eAAe,UAAU;EAAQ,IAE7D;CACR;CASA,MAAM,IAAI,GAAkB,GAAuC;EAClE,IAAM,IAAU,KAAK,gBAAgB,GAAM,WAAW,CAAC,GAAG,GAAM,KAAK,GAE/D,IAAW,MAAM,EAAW;GACjC,KAAK,KAAK,UAAU;GACpB,WAAW,GAAM,aAAa,CAAC;GAC/B;EACD,CAAC;EAQD,OANA,KAAK,QAAQ,GAAU,OAAO;GAC7B;GACA,SAAS,EAAS;GAClB,QAAQ,EAAS;EAClB,CAAC,GAEM;CACR;CASA,MAAM,KAAK,GAAkB,GAAoC;EAChE,IAAM,IAAU,KAAK,gBAAgB,GAAM,WAAW,CAAC,GAAG,GAAM,KAAK,GAC/D,IAAO,GAAM,MAEb,IAAW,MAAM,EAAY;GAClC,KAAK,KAAK,UAAU;GACpB,WAAW,GAAM,aAAa,CAAC;GAC/B;GACA;EACD,CAAC;EASD,OAPA,KAAK,QAAQ,GAAU,QAAQ;GAC9B;GACA;GACA,SAAS,EAAS;GAClB,QAAQ,EAAS;EAClB,CAAC,GAEM;CACR;CASA,MAAM,IAAI,GAAkB,GAAoC;EAC/D,IAAM,IAAU,KAAK,gBAAgB,GAAM,WAAW,CAAC,GAAG,GAAM,KAAK,GAC/D,IAAO,GAAM,MAEb,IAAW,MAAM,EAAW;GACjC,KAAK,KAAK,UAAU;GACpB,WAAW,GAAM,aAAa,CAAC;GAC/B;GACA;EACD,CAAC;EASD,OAPA,KAAK,QAAQ,GAAU,OAAO;GAC7B;GACA;GACA,SAAS,EAAS;GAClB,QAAQ,EAAS;EAClB,CAAC,GAEM;CACR;CASA,MAAM,MAAM,GAAkB,GAAoC;EACjE,IAAM,IAAU,KAAK,gBAAgB,GAAM,WAAW,CAAC,GAAG,GAAM,KAAK,GAC/D,IAAO,GAAM,MAEb,IAAW,MAAM,EAAa;GACnC,KAAK,KAAK,UAAU;GACpB,WAAW,GAAM,aAAa,CAAC;GAC/B;GACA;EACD,CAAC;EASD,OAPA,KAAK,QAAQ,GAAU,SAAS;GAC/B;GACA;GACA,SAAS,EAAS;GAClB,QAAQ,EAAS;EAClB,CAAC,GAEM;CACR;CASA,MAAM,OAAO,GAAkB,GAAoC;EAClE,IAAM,IAAU,KAAK,gBAAgB,GAAM,WAAW,CAAC,GAAG,GAAM,KAAK,GAC/D,IAAO,GAAM,MAEb,IAAW,MAAM,EAAc;GACpC,KAAK,KAAK,UAAU;GACpB,WAAW,GAAM,aAAa,CAAC;GAC/B;GACA;EACD,CAAC;EASD,OAPA,KAAK,QAAQ,GAAU,UAAU;GAChC;GACA;GACA,SAAS,EAAS;GAClB,QAAQ,EAAS;EAClB,CAAC,GAEM;CACR;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugService.js","names":[],"sources":["../../../src/services/debugService.ts"],"sourcesContent":["import path from \"node:path\";\n\n/**\n * Manages stack-trace configuration for debug output, allowing specific adapter/wrapper files\n * to be skipped so logs show the actual business-logic caller.\n *\n * @example\n * ```typescript\n * // Skip httpAdapter.ts so debug output shows the calling route instead\n * DebugService.setIgnoreFile(\"httpAdapter.ts\");\n * ```\n */\n\nclass DebugService {\n\t/**\n\t * The name of the file to ignore when analyzing the stack trace.\n\t * When set, the `getCaller` function will skip stack frames containing this file name.\n\t */\n\tstatic ignoreFiles: string[] = [];\n\n\t/**\n\t * Adds a file name to the ignore list so it is skipped when resolving the caller in stack traces.\n\t *\n\t * @param file - File name to ignore (e.g. `\"httpAdapter.ts\"`).\n\t */\n\tstatic setIgnoreFile(file: string): void {\n\t\tDebugService.ignoreFiles.push(file);\n\t}\n\n\t/** Resets the ignore list, restoring full stack trace analysis. */\n\tstatic clearIgnoreFiles(): void {\n\t\tDebugService.ignoreFiles = [];\n\t}\n\n\t/**\n\t * Resolves the file path and function name of the code that triggered the current debug call,\n\t * skipping internal node modules and any files registered with `setIgnoreFile`.\n\t *\n\t * @returns `{ functionName, callerInfo }` — caller function name and file path relative to `process.cwd()`.\n\t */\n\tstatic getCaller() {\n\t\tconst projectRoot = process.cwd();\n\n\t\tconst err = new Error();\n\t\tconst stack = err.stack || \"\";\n\t\tconst stackLines = stack.split(\"\\n\").map((line) => line.trim());\n\n\t\tlet callerIndex = 2;\n\n\t\twhile (\n\t\t\tcallerIndex < stackLines.length &&\n\t\t\t(stackLines[callerIndex].includes(\"node:internal\") ||\n\t\t\t\tstackLines[callerIndex].includes(\"/node_modules/\"))\n\t\t) {\n\t\t\tcallerIndex++;\n\t\t}\n\n\t\tif (DebugService.ignoreFiles.length > 0) {\n\t\t\twhile (\n\t\t\t\tcallerIndex < stackLines.length &&\n\t\t\t\tDebugService.ignoreFiles.some((ignoreFile) =>\n\t\t\t\t\tstackLines[callerIndex].includes(ignoreFile),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tcallerIndex++;\n\t\t\t}\n\t\t}\n\n\t\tconst callerLine = stackLines[callerIndex] || \"\";\n\n\t\tlet functionName = \"Unknown function\";\n\t\tlet callerInfo = \"Unknown caller\";\n\n\t\tconst namedFunctionMatch = callerLine.match(/at\\s+([^(\\s]+)\\s+\\(([^)]+)\\)/);\n\t\tif (namedFunctionMatch) {\n\t\t\tfunctionName = namedFunctionMatch[1];\n\t\t\tcallerInfo = namedFunctionMatch[2];\n\t\t} else {\n\t\t\tconst anonymousFunctionMatch = callerLine.match(/at\\s+(.+)/);\n\t\t\tif (anonymousFunctionMatch) {\n\t\t\t\tcallerInfo = anonymousFunctionMatch[1];\n\n\t\t\t\tconst objectMethodMatch = callerInfo.match(/at\\s+([^(\\s]+)\\s+/);\n\t\t\t\tif (objectMethodMatch && objectMethodMatch[1] !== \"new\") {\n\t\t\t\t\tfunctionName = objectMethodMatch[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (callerInfo.includes(\"(\")) {\n\t\t\tcallerInfo = callerInfo.substring(\n\t\t\t\tcallerInfo.indexOf(\"(\") + 1,\n\t\t\t\tcallerInfo.lastIndexOf(\")\"),\n\t\t\t);\n\t\t}\n\n\t\tcallerInfo = callerInfo.split(\":\").slice(0, -2).join(\":\");\n\n\t\ttry {\n\t\t\tcallerInfo = path.relative(projectRoot, callerInfo);\n\t\t} catch (_e) {}\n\n\t\treturn { functionName, callerInfo };\n\t}\n}\n\nexport { DebugService };\n"],"mappings":";;AAaA,IAAM,IAAN,MAAM,EAAa;CAKlB,OAAO,cAAwB,CAAC;CAOhC,OAAO,cAAc,GAAoB;EACxC,EAAa,YAAY,KAAK,CAAI;CACnC;CAGA,OAAO,mBAAyB;EAC/B,EAAa,cAAc,CAAC;CAC7B;CAQA,OAAO,YAAY;EAClB,IAAM,IAAc,QAAQ,IAAI,GAI1B,MADQ,gBADE,MACF,EAAA,CAAI,SAAS,GAAA,CACF,MAAM,IAAI,CAAC,CAAC,KAAK,MAAS,EAAK,KAAK,CAAC,GAE1D,IAAc;EAElB,OACC,IAAc,EAAW,WACxB,EAAW,EAAY,CAAC,SAAS,eAAe,KAChD,EAAW,EAAY,CAAC,SAAS,gBAAgB,KAElD;EAGD,IAAI,EAAa,YAAY,SAAS,GACrC,OACC,IAAc,EAAW,UACzB,EAAa,YAAY,MAAM,MAC9B,EAAW,EAAY,CAAC,SAAS,CAAU,CAC5C,IAEA;EAIF,IAAM,IAAa,EAAW,MAAgB,IAE1C,IAAe,oBACf,IAAa,kBAEX,IAAqB,EAAW,MAAM,8BAA8B;EAC1E,IAAI,GAEH,AADA,IAAe,EAAmB,IAClC,IAAa,EAAmB;OAC1B;GACN,IAAM,IAAyB,EAAW,MAAM,WAAW;GAC3D,IAAI,GAAwB;IAC3B,IAAa,EAAuB;IAEpC,IAAM,IAAoB,EAAW,MAAM,mBAAmB;IAC9D,AAAI,KAAqB,EAAkB,OAAO,UACjD,IAAe,EAAkB;GAEnC;EACD;EASA,AAPI,EAAW,SAAS,GAAG,MAC1B,IAAa,EAAW,UACvB,EAAW,QAAQ,GAAG,IAAI,GAC1B,EAAW,YAAY,GAAG,CAC3B,IAGD,IAAa,EAAW,MAAM,GAAG,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG;EAExD,IAAI;GACH,IAAa,EAAK,SAAS,GAAa,CAAU;EACnD,QAAa,CAAC;EAEd,OAAO;GAAE;GAAc;EAAW;CACnC;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logService.js","names":[],"sources":["../../../src/services/logService.ts"],"sourcesContent":["/**\n * Static service for log endpoint configuration and access.\n *\n * Stores a singleton configuration containing the traffic source identifier,\n * user token, and log ingestion URL.\n */\nclass LogService {\n\tprivate static config?: {\n\t\ttrafficSourceId: string;\n\t\tuserToken: string;\n\t\tapiUrl: string;\n\t};\n\n\t/**\n\t * Sets the log service configuration once. Subsequent calls are ignored.\n\t *\n\t * @param config.trafficSourceId - Traffic source identifier.\n\t * @param config.userToken - User token for authentication.\n\t * @param config.logBaseApiUrl - Override the default log ingestion base URL.\n\t */\n\tstatic setConfig(config: {\n\t\ttrafficSourceId: string;\n\t\tuserToken: string;\n\t\tlogBaseApiUrl?: string;\n\t}): void {\n\t\tif (LogService.config) return;\n\n\t\tconst { trafficSourceId, userToken, logBaseApiUrl } = config;\n\t\tconst baseUrl = logBaseApiUrl || `http://62.238.8.44:8081`;\n\t\tconst apiUrl = `${baseUrl}/ingest-log`;\n\n\t\tLogService.config = { trafficSourceId, userToken, apiUrl };\n\t}\n\n\t/** Returns the stored configuration, or `undefined` if `setConfig` has not been called. */\n\tstatic getConfig():\n\t\t| { trafficSourceId: string; userToken: string; apiUrl: string }\n\t\t| undefined {\n\t\treturn LogService.config;\n\t}\n\n\t/**\n\t * Resets the stored configuration, allowing a new initialization.\n\t */\n\tstatic resetConfig() {\n\t\tLogService.config = undefined;\n\t}\n}\n\nexport { LogService };\n"],"mappings":";AAMA,IAAM,IAAN,MAAM,EAAW;CAChB,OAAe;CAaf,OAAO,UAAU,GAIR;EACR,IAAI,EAAW,QAAQ;EAEvB,IAAM,EAAE,oBAAiB,cAAW,qBAAkB;EAItD,EAAW,SAAS;GAAE;GAAiB;GAAW,QAAA,GAHlC,KAAiB,0BACP;EAE+B;CAC1D;CAGA,OAAO,YAEM;EACZ,OAAO,EAAW;CACnB;CAKA,OAAO,cAAc;EACpB,EAAW,SAAS,KAAA;CACrB;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeRequestBody.js","names":[],"sources":["../../../src/utilities/decodeRequestBody.ts"],"sourcesContent":["import { BadRequest } from \"../http/badResponses/badRequest\";\n\n/**\n * Decodes a request body into a plain object, trying JSON first then URL-encoded form data.\n * Throws `BadRequest` if neither format can be parsed.\n *\n * @param request - The incoming request whose body will be decoded.\n * @returns The decoded body as a plain object.\n *\n * @example\n * ```typescript\n * export async function action({ request }: ActionFunctionArgs) {\n * const body = await decodeRequestBody(request);\n * // body is now a plain JS object\n * }\n * ```\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nasync function decodeRequestBody(request: Request): Promise<any> {\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tlet data: any;\n\n\tconst arrayBuffer = await request.arrayBuffer();\n\tconst text = new TextDecoder().decode(arrayBuffer);\n\n\ttry {\n\t\tdata = JSON.parse(text);\n\t} catch (_jsonError) {\n\t\ttry {\n\t\t\tif (text.includes(\"=\")) {\n\t\t\t\tconst formData = new URLSearchParams(text);\n\t\t\t\tdata = Object.fromEntries(formData.entries());\n\t\t\t} else {\n\t\t\t\tthrow new BadRequest(\"Invalid URLSearchParams format\");\n\t\t\t}\n\t\t} catch (_formDataError) {\n\t\t\tthrow new BadRequest(\"Failed to extract data from request\");\n\t\t}\n\t}\n\n\treturn data;\n}\n\nexport { decodeRequestBody };\n"],"mappings":";;AAmBA,eAAe,EAAkB,GAAgC;CAEhE,IAAI,GAEE,IAAc,MAAM,EAAQ,YAAY,GACxC,IAAO,IAAI,YAAY,CAAC,CAAC,OAAO,CAAW;CAEjD,IAAI;EACH,IAAO,KAAK,MAAM,CAAI;CACvB,QAAqB;EACpB,IAAI;GACH,IAAI,EAAK,SAAS,GAAG,GAAG;IACvB,IAAM,IAAW,IAAI,gBAAgB,CAAI;IACzC,IAAO,OAAO,YAAY,EAAS,QAAQ,CAAC;GAC7C,OACC,MAAM,IAAI,EAAW,gCAAgC;EAEvD,QAAyB;GACxB,MAAM,IAAI,EAAW,qCAAqC;EAC3D;CACD;CAEA,OAAO;AACR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeRequestErrorMessage.js","names":[],"sources":["../../../src/utilities/decodeRequestErrorMessage.ts"],"sourcesContent":["/**\n * Extracts a human-readable error message from an API response body or a `Response` object.\n * Checks `data.message`, `data.operator_erro_message`, `data.error`, `data.error.message`,\n * and `response.statusText` in that order. Falls back to `\"Missing error message\"`.\n *\n * @param data - Parsed response body that may contain error info.\n * @param response - The raw `Response` object, used as a fallback for `statusText`.\n * @returns The first non-empty string error message found.\n *\n * @example\n * ```typescript\n * const res = await fetch(\"/api/orders\");\n * const data = await res.json().catch(() => null);\n * const message = decodeRequestErrorMessage(data, res);\n * ```\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nfunction decodeRequestErrorMessage(data: any, response: Response): string {\n\tif (data?.message && typeof data?.message === \"string\") {\n\t\treturn data?.message;\n\t}\n\n\tif (\n\t\tdata?.operator_erro_message &&\n\t\ttypeof data?.operator_erro_message === \"string\"\n\t) {\n\t\treturn data?.operator_erro_message;\n\t}\n\n\tif (data?.error && typeof data?.error === \"string\") {\n\t\treturn data?.error;\n\t}\n\n\tif (data?.error?.message && typeof data?.error?.message === \"string\") {\n\t\treturn data?.error?.message;\n\t}\n\n\tif (response?.statusText && typeof response?.statusText === \"string\") {\n\t\treturn response?.statusText;\n\t}\n\n\treturn \"Missing error message\";\n}\n\nexport { decodeRequestErrorMessage };\n"],"mappings":";AAkBA,SAAS,EAA0B,GAAW,GAA4B;CAwBzE,OAvBI,GAAM,WAAW,OAAO,GAAM,WAAY,WACtC,GAAM,UAIb,GAAM,yBACN,OAAO,GAAM,yBAA0B,WAEhC,GAAM,wBAGV,GAAM,SAAS,OAAO,GAAM,SAAU,WAClC,GAAM,QAGV,GAAM,OAAO,WAAW,OAAO,GAAM,OAAO,WAAY,WACpD,GAAM,OAAO,UAGjB,GAAU,cAAc,OAAO,GAAU,cAAe,WACpD,GAAU,aAGX;AACR"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorHandler.js","names":[],"sources":["../../../src/utilities/errorHandler.ts"],"sourcesContent":["import { BadGateway } from \"../http/badResponses/badGateway\";\nimport { BadRequest } from \"../http/badResponses/badRequest\";\nimport { Conflict } from \"../http/badResponses/conflict\";\nimport { Forbidden } from \"../http/badResponses/forbidden\";\nimport { NotFound } from \"../http/badResponses/notFound\";\nimport { NotImplemented } from \"../http/badResponses/notImplemented\";\nimport { ServerError } from \"../http/badResponses/serverError\";\nimport { Unauthorized } from \"../http/badResponses/unauthorized\";\nimport { UnprocessableEntity } from \"../http/badResponses/unprocessableEntity\";\n\nimport { Created } from \"../http/successResponses/created\";\nimport { Found } from \"../http/successResponses/found\";\nimport { NoContent } from \"../http/successResponses/noContent\";\nimport { Success } from \"../http/successResponses/success\";\nimport { Updated } from \"../http/successResponses/updated\";\n\n/**\n * Converts any thrown value into a `Response`. Recognizes all `@arkyn/server` success and error\n * response classes, native `Response` objects, and falls back to a 500 `ServerError` for anything else.\n *\n * Intended to be used as the catch handler of a route action or loader:\n *\n * @param error - The thrown value to convert.\n * @returns A `Response` with the appropriate HTTP status, headers, and JSON body.\n *\n * @example\n * ```typescript\n * export async function action({ request }: ActionFunctionArgs) {\n * try {\n * const user = await findUser(id);\n * if (!user) throw new NotFound(\"User not found\");\n * return new Success(\"User retrieved\", { user }).toJson();\n * } catch (error) {\n * return errorHandler(error);\n * }\n * }\n * ```\n */\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nfunction errorHandler(error: any): Response {\n\tswitch (true) {\n\t\tcase error instanceof Response:\n\t\t\treturn error;\n\t\tcase error instanceof Found:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof Created:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof Updated:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof Success:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof NoContent:\n\t\t\treturn error.toResponse();\n\t}\n\n\tswitch (true) {\n\t\tcase error instanceof BadGateway:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof BadRequest:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof Conflict:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof Forbidden:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof NotFound:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof NotImplemented:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof ServerError:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof Unauthorized:\n\t\t\treturn error.toResponse();\n\t\tcase error instanceof UnprocessableEntity:\n\t\t\treturn error.toResponse();\n\t}\n\n\treturn new ServerError(\"Server error\", error).toResponse();\n}\n\nexport { errorHandler };\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAS,EAAa,GAAsB;CAC3C,QAAQ,IAAR;EACC,KAAK,aAAiB,UACrB,OAAO;EACR,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;CAC1B;CAEA,QAAQ,IAAR;EACC,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;EACzB,KAAK,aAAiB,GACrB,OAAO,EAAM,WAAW;CAC1B;CAEA,OAAO,IAAI,EAAY,gBAAgB,CAAK,CAAC,CAAC,WAAW;AAC1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flushDebugLogs.js","names":[],"sources":["../../../src/utilities/flushDebugLogs.ts"],"sourcesContent":["/**\n * Writes colored `[name] message` lines to the console, but only when\n * `NODE_ENV === \"development\"` or `DEBUG_MODE === \"true\"`. No-op in production.\n *\n * @param props.name - Label shown before each line (e.g. `\"API\"`, `\"Auth\"`).\n * @param props.scheme - Color of the label tag: `\"cyan\"` info, `\"green\"` success, `\"yellow\"` warning, `\"red\"` error.\n * @param props.debugs - Lines of text to print, one per console entry.\n *\n * @example\n * ```typescript\n * flushDebugLogs({\n * name: \"API\",\n * scheme: \"cyan\",\n * debugs: [\"POST /api/users\", \"Status: 201\"],\n * });\n * ```\n */\n\nfunction flushDebugLogs(props: {\n\tscheme: \"yellow\" | \"cyan\" | \"red\" | \"green\";\n\tname: string;\n\tdebugs: string[];\n}): void {\n\tconst isDebugMode =\n\t\tprocess.env.NODE_ENV === \"development\" ||\n\t\tprocess.env?.DEBUG_MODE === \"true\";\n\n\tif (isDebugMode) {\n\t\tconst reset = \"\\x1b[0m\";\n\n\t\tconst colors = {\n\t\t\tyellow: \"\\x1b[33m\",\n\t\t\tcyan: \"\\x1b[36m\",\n\t\t\tred: \"\\x1b[31m\",\n\t\t\tgreen: \"\\x1b[32m\",\n\t\t};\n\n\t\tconst debugName = `${colors[props.scheme]}[${props.name}]${reset}`;\n\t\tlet consoleData = `\\n`;\n\n\t\tprops.debugs.forEach((debug, index) => {\n\t\t\tconsoleData += `${debugName} ${debug.trim()}`;\n\t\t\tif (index < props.debugs.length - 1) consoleData += `\\n`;\n\t\t});\n\n\t\tconsole.log(consoleData);\n\t}\n}\n\nexport { flushDebugLogs };\n"],"mappings":";AAkBA,SAAS,EAAe,GAIf;CAKR,IAAA,QAAA,IAAA,aAH0B,iBACzB,QAAQ,KAAK,eAAe,QAEZ;EAUhB,IAAM,IAAY,GAAG;GANpB,QAAQ;GACR,MAAM;GACN,KAAK;GACL,OAAO;EAGa,EAAO,EAAM,QAAQ,GAAG,EAAM,KAAK,QACpD,IAAc;EAOlB,AALA,EAAM,OAAO,SAAS,GAAO,MAAU;GAEtC,AADA,KAAe,GAAG,EAAU,GAAG,EAAM,KAAK,KACtC,IAAQ,EAAM,OAAO,SAAS,MAAG,KAAe;EACrD,CAAC,GAED,QAAQ,IAAI,CAAW;CACxB;AACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formAsyncParse.js","names":[],"sources":["../../../src/utilities/formAsyncParse.ts"],"sourcesContent":["import type { ZodType } from \"zod\";\n\ntype SuccessResponse<T extends FormParseProps> = {\n\tsuccess: true;\n\tdata: T[1] extends ZodType<infer U> ? U : never;\n};\n\ntype ErrorResponse = {\n\tsuccess: false;\n\tfields: { [x: string]: string };\n\tfieldErrors: { [x: string]: string };\n};\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\ntype FormParseProps = [formData: { [k: string]: any }, schema: ZodType];\n\ntype FormParseReturnType<T extends FormParseProps> =\n\t| SuccessResponse<T>\n\t| ErrorResponse;\n\n/**\n * Async variant of `formParse` — uses `safeParseAsync` to support Zod schemas with async refinements.\n * Returns `{ success: true, data }` on success or `{ success: false, fieldErrors, fields }` on failure.\n *\n * @param formData - The raw form data object to validate.\n * @param schema - The Zod schema to validate against.\n *\n * @example\n * ```typescript\n * const schema = z.object({ email: z.string().email() });\n * const result = await formAsyncParse([{ email: \"bad\" }, schema]);\n *\n * if (!result.success) {\n * console.log(result.fieldErrors); // { email: \"Invalid email\" }\n * }\n * ```\n */\n\nasync function formAsyncParse<T extends FormParseProps>([\n\tformData,\n\tschema,\n]: T): Promise<FormParseReturnType<T>> {\n\tconst zodResponse = await schema.safeParseAsync(formData);\n\n\tif (zodResponse.success === false) {\n\t\tconst errorsObject = Object.fromEntries(\n\t\t\tzodResponse.error.issues.map((item) => {\n\t\t\t\treturn [item.path.join(\".\"), item.message];\n\t\t\t}),\n\t\t);\n\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tfieldErrors: errorsObject,\n\t\t\tfields: formData,\n\t\t};\n\t} else {\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tdata: zodResponse.data as T[1] extends ZodType<infer U> ? U : never,\n\t\t};\n\t}\n}\n\nexport { formAsyncParse };\n"],"mappings":";AAsCA,eAAe,EAAyC,CACvD,GACA,IACsC;CACtC,IAAM,IAAc,MAAM,EAAO,eAAe,CAAQ;CAevD,OAbG,EAAY,YAAY,KAOpB;EACN,SAAS;EACT,aARoB,OAAO,YAC3B,EAAY,MAAM,OAAO,KAAK,MACtB,CAAC,EAAK,KAAK,KAAK,GAAG,GAAG,EAAK,OAAO,CACzC,CAKY;EACb,QAAQ;CACT,IAEO;EACN,SAAS;EACT,MAAM,EAAY;CACnB;AAEF"}
|