@arkyn/server 3.0.1-beta.143 → 3.0.1-beta.144
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +90 -323
- package/dist/http/badResponses/badGateway.d.ts +12 -19
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.js +12 -19
- package/dist/http/badResponses/badRequest.d.ts +10 -19
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.js +10 -19
- package/dist/http/badResponses/conflict.d.ts +10 -19
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.js +10 -19
- package/dist/http/badResponses/forbidden.d.ts +10 -19
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.js +10 -19
- package/dist/http/badResponses/notFound.d.ts +10 -19
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.js +10 -19
- package/dist/http/badResponses/notImplemented.d.ts +10 -19
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.js +10 -19
- package/dist/http/badResponses/serverError.d.ts +10 -19
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.js +10 -19
- package/dist/http/badResponses/unauthorized.d.ts +10 -19
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.js +10 -19
- package/dist/http/badResponses/unprocessableEntity.d.ts +17 -22
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.js +17 -22
- package/dist/http/successResponses/created.d.ts +10 -14
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +10 -14
- package/dist/http/successResponses/found.d.ts +10 -14
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +10 -14
- package/dist/http/successResponses/noContent.d.ts +9 -7
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.js +9 -7
- package/dist/http/successResponses/success.d.ts +10 -14
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +10 -14
- package/dist/http/successResponses/updated.d.ts +11 -14
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +11 -14
- package/dist/services/apiService.d.ts +20 -0
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/apiService.js +16 -0
- package/dist/services/debugService.d.ts +10 -42
- package/dist/services/debugService.d.ts.map +1 -1
- package/dist/services/debugService.js +10 -42
- package/dist/services/logService.d.ts +5 -10
- package/dist/services/logService.d.ts.map +1 -1
- package/dist/services/logService.js +5 -10
- package/dist/utilities/decodeRequestBody.d.ts +11 -9
- package/dist/utilities/decodeRequestBody.d.ts.map +1 -1
- package/dist/utilities/decodeRequestBody.js +11 -9
- package/dist/utilities/decodeRequestErrorMessage.d.ts +12 -10
- package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -1
- package/dist/utilities/decodeRequestErrorMessage.js +12 -10
- package/dist/utilities/errorHandler.d.ts +13 -38
- package/dist/utilities/errorHandler.d.ts.map +1 -1
- package/dist/utilities/errorHandler.js +13 -38
- package/dist/utilities/flushDebugLogs.d.ts +6 -28
- package/dist/utilities/flushDebugLogs.d.ts.map +1 -1
- package/dist/utilities/flushDebugLogs.js +6 -28
- package/dist/utilities/formAsyncParse.d.ts +7 -28
- package/dist/utilities/formAsyncParse.d.ts.map +1 -1
- package/dist/utilities/formAsyncParse.js +7 -28
- package/dist/utilities/formParse.d.ts +7 -28
- package/dist/utilities/formParse.d.ts.map +1 -1
- package/dist/utilities/formParse.js +7 -28
- package/dist/utilities/getScopedParams.d.ts +11 -19
- package/dist/utilities/getScopedParams.d.ts.map +1 -1
- package/dist/utilities/getScopedParams.js +11 -19
- package/dist/utilities/schemaValidator.d.ts +31 -102
- package/dist/utilities/schemaValidator.d.ts.map +1 -1
- package/dist/utilities/schemaValidator.js +31 -102
- package/dist/validations/validateCep.d.ts +2 -2
- package/dist/validations/validateCep.js +2 -2
- package/dist/validations/validateCnpj.d.ts +2 -2
- package/dist/validations/validateCnpj.js +2 -2
- package/dist/validations/validateCpf.d.ts +4 -11
- package/dist/validations/validateCpf.d.ts.map +1 -1
- package/dist/validations/validateCpf.js +4 -11
- package/dist/validations/validateDate.d.ts +7 -11
- package/dist/validations/validateDate.d.ts.map +1 -1
- package/dist/validations/validateDate.js +7 -11
- package/dist/validations/validateEmail.d.ts +2 -2
- package/dist/validations/validateEmail.js +2 -2
- package/dist/validations/validatePassword.d.ts +2 -2
- package/dist/validations/validatePassword.js +2 -2
- package/dist/validations/validatePhone.d.ts +6 -18
- package/dist/validations/validatePhone.d.ts.map +1 -1
- package/dist/validations/validatePhone.js +6 -18
- package/dist/validations/validateRg.d.ts +2 -2
- package/dist/validations/validateRg.js +2 -2
- package/package.json +1 -1
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* HTTP 200 OK — the request succeeded and the response body contains the result.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* return new Success("Order fetched", { order }).toJson();
|
|
8
|
+
* ```
|
|
4
9
|
*/
|
|
5
10
|
class Success extends SuccessResponse {
|
|
6
11
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param {string} message - A message describing the creation status.
|
|
10
|
-
* @param {any} body - The response body to be included in the HTTP response.
|
|
12
|
+
* @param message - Description included in the response status text.
|
|
13
|
+
* @param body - Data to include in the response body.
|
|
11
14
|
*/
|
|
12
15
|
constructor(message, body) {
|
|
13
16
|
super();
|
|
@@ -17,10 +20,7 @@ class Success extends SuccessResponse {
|
|
|
17
20
|
this.body = body || undefined;
|
|
18
21
|
this.onDebug();
|
|
19
22
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Converts the `Success` instance into a `Response` object.
|
|
22
|
-
* @returns {Response} A `Response` object with the body and response metadata.
|
|
23
|
-
*/
|
|
23
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
24
24
|
toResponse() {
|
|
25
25
|
const responseInit = {
|
|
26
26
|
headers: { "Content-Type": "application/json" },
|
|
@@ -29,11 +29,7 @@ class Success extends SuccessResponse {
|
|
|
29
29
|
};
|
|
30
30
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Converts the `Success` instance into a `Response` object using the `Response.json` method.
|
|
34
|
-
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
35
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
36
|
-
*/
|
|
32
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
37
33
|
toJson() {
|
|
38
34
|
const responseInit = {
|
|
39
35
|
status: this.status,
|
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* HTTP 200 OK — the request succeeded and the resource was updated.
|
|
4
|
+
* Semantically equivalent to `Success` but signals an update operation to consumers.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* return new Updated("Profile updated", { user }).toJson();
|
|
9
|
+
* ```
|
|
4
10
|
*/
|
|
5
11
|
declare class Updated extends SuccessResponse {
|
|
6
12
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param {string} message - A message describing the creation status.
|
|
10
|
-
* @param {any} body - The response body to be included in the HTTP response.
|
|
13
|
+
* @param message - Description included in the response status text.
|
|
14
|
+
* @param body - Data to include in the response body.
|
|
11
15
|
*/
|
|
12
16
|
constructor(message: string, body?: any);
|
|
13
|
-
/**
|
|
14
|
-
* Converts the `Updated` instance into a `Response` object.
|
|
15
|
-
* @returns {Response} A `Response` object with the body and response metadata.
|
|
16
|
-
*/
|
|
17
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
17
18
|
toResponse(): Response;
|
|
18
|
-
/**
|
|
19
|
-
* Converts the `Updated` instance into a `Response` object using the `Response.json` method.
|
|
20
|
-
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
21
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
22
|
-
*/
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
23
20
|
toJson(): Response;
|
|
24
21
|
}
|
|
25
22
|
export { Updated };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/updated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD
|
|
1
|
+
{"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/updated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;GAQG;AACH,cAAM,OAAQ,SAAQ,eAAe;IACnC;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG;IAWvC,6EAA6E;IAC7E,UAAU,IAAI,QAAQ;IAUtB,uFAAuF;IACvF,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* HTTP 200 OK — the request succeeded and the resource was updated.
|
|
4
|
+
* Semantically equivalent to `Success` but signals an update operation to consumers.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* return new Updated("Profile updated", { user }).toJson();
|
|
9
|
+
* ```
|
|
4
10
|
*/
|
|
5
11
|
class Updated extends SuccessResponse {
|
|
6
12
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @param {string} message - A message describing the creation status.
|
|
10
|
-
* @param {any} body - The response body to be included in the HTTP response.
|
|
13
|
+
* @param message - Description included in the response status text.
|
|
14
|
+
* @param body - Data to include in the response body.
|
|
11
15
|
*/
|
|
12
16
|
constructor(message, body) {
|
|
13
17
|
super();
|
|
@@ -17,10 +21,7 @@ class Updated extends SuccessResponse {
|
|
|
17
21
|
this.body = body || undefined;
|
|
18
22
|
this.onDebug();
|
|
19
23
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Converts the `Updated` instance into a `Response` object.
|
|
22
|
-
* @returns {Response} A `Response` object with the body and response metadata.
|
|
23
|
-
*/
|
|
24
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
24
25
|
toResponse() {
|
|
25
26
|
const responseInit = {
|
|
26
27
|
headers: { "Content-Type": "application/json" },
|
|
@@ -29,11 +30,7 @@ class Updated extends SuccessResponse {
|
|
|
29
30
|
};
|
|
30
31
|
return new Response(JSON.stringify(this.body), responseInit);
|
|
31
32
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Converts the `Updated` instance into a `Response` object using the `Response.json` method.
|
|
34
|
-
* This method is an alternative to `toResponse` for generating JSON responses.
|
|
35
|
-
* @returns {Response["json"]} A `Response` object with the JSON body and response metadata.
|
|
36
|
-
*/
|
|
33
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
37
34
|
toJson() {
|
|
38
35
|
const responseInit = {
|
|
39
36
|
status: this.status,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
type ApiServiceConstructorProps = {
|
|
2
|
+
/** Base URL prepended to every request path (e.g. `"https://api.example.com"`). */
|
|
2
3
|
baseUrl: string;
|
|
4
|
+
/** Default headers merged into every request. */
|
|
3
5
|
baseHeaders?: HeadersInit;
|
|
6
|
+
/** Default Bearer token; can be overridden per request via `data.token`. */
|
|
4
7
|
baseToken?: string | null;
|
|
8
|
+
/** When `true`, logs each request and response to the console in development. */
|
|
5
9
|
enableDebug?: boolean;
|
|
6
10
|
};
|
|
7
11
|
type ApiRequestDataWithoutBodyProps = {
|
|
@@ -15,6 +19,22 @@ type ApiRequestDataWithBodyProps = {
|
|
|
15
19
|
token?: string;
|
|
16
20
|
urlParams?: Record<string, string>;
|
|
17
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* HTTP client for external API calls. Wraps fetch with base URL, default headers, optional auth token,
|
|
24
|
+
* and per-request overrides for all standard HTTP methods.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const api = new ApiService({
|
|
29
|
+
* baseUrl: "https://api.example.com",
|
|
30
|
+
* baseToken: session.token,
|
|
31
|
+
* enableDebug: true,
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const { data } = await api.get("/users/me");
|
|
35
|
+
* const { data: created } = await api.post("/orders", { body: { productId: 1 } });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
18
38
|
declare class ApiService {
|
|
19
39
|
private baseUrl;
|
|
20
40
|
private baseHeaders?;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAOA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC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chRequest";
|
|
|
4
4
|
import { postRequest } from "../http/api/postRequest";
|
|
5
5
|
import { putRequest } from "../http/api/putRequest";
|
|
6
6
|
import { flushDebugLogs } from "../utilities/flushDebugLogs";
|
|
7
|
+
/**
|
|
8
|
+
* HTTP client for external API calls. Wraps fetch with base URL, default headers, optional auth token,
|
|
9
|
+
* and per-request overrides for all standard HTTP methods.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const api = new ApiService({
|
|
14
|
+
* baseUrl: "https://api.example.com",
|
|
15
|
+
* baseToken: session.token,
|
|
16
|
+
* enableDebug: true,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const { data } = await api.get("/users/me");
|
|
20
|
+
* const { data: created } = await api.post("/orders", { body: { productId: 1 } });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
7
23
|
class ApiService {
|
|
8
24
|
baseUrl;
|
|
9
25
|
baseHeaders;
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* This service provides functionality to configure how the `getCaller` function
|
|
5
|
-
* identifies the actual caller in the stack trace by allowing specific files
|
|
6
|
-
* to be ignored during stack trace analysis.
|
|
2
|
+
* Manages stack-trace configuration for debug output, allowing specific adapter/wrapper files
|
|
3
|
+
* to be skipped so logs show the actual business-logic caller.
|
|
7
4
|
*
|
|
8
5
|
* @example
|
|
9
6
|
* ```typescript
|
|
10
|
-
* //
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* // Now when httpDebug is called from within httpAdapter.ts,
|
|
14
|
-
* // it will show the actual caller (e.g., cart.ts) instead
|
|
7
|
+
* // Skip httpAdapter.ts so debug output shows the calling route instead
|
|
8
|
+
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
15
9
|
* ```
|
|
16
10
|
*/
|
|
17
11
|
declare class DebugService {
|
|
@@ -21,44 +15,18 @@ declare class DebugService {
|
|
|
21
15
|
*/
|
|
22
16
|
static ignoreFiles: string[];
|
|
23
17
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* This method configures the debug service to skip specific files when
|
|
27
|
-
* determining the actual caller of a function. This is useful when you have
|
|
28
|
-
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
18
|
+
* Adds a file name to the ignore list so it is skipped when resolving the caller in stack traces.
|
|
29
19
|
*
|
|
30
|
-
* @param
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
35
|
-
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
36
|
-
* ```
|
|
20
|
+
* @param file - File name to ignore (e.g. `"httpAdapter.ts"`).
|
|
37
21
|
*/
|
|
38
22
|
static setIgnoreFile(file: string): void;
|
|
39
|
-
/**
|
|
40
|
-
* Clears all configured ignore files.
|
|
41
|
-
*
|
|
42
|
-
* This method resets the ignore file configuration, allowing all files to be
|
|
43
|
-
* considered in stack trace analysis again.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* // Clear all ignore file configurations
|
|
48
|
-
* DebugService.clearIgnoreFiles();
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
23
|
+
/** Resets the ignore list, restoring full stack trace analysis. */
|
|
51
24
|
static clearIgnoreFiles(): void;
|
|
52
25
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* This function analyzes the stack trace to determine the file path and function name
|
|
56
|
-
* of the caller. It excludes stack trace entries related to the `@arkyn/server` package
|
|
57
|
-
* and attempts to resolve the file path relative to the project root directory.
|
|
26
|
+
* Resolves the file path and function name of the code that triggered the current debug call,
|
|
27
|
+
* skipping internal node modules and any files registered with `setIgnoreFile`.
|
|
58
28
|
*
|
|
59
|
-
* @returns
|
|
60
|
-
* - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
|
|
61
|
-
* - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
|
|
29
|
+
* @returns `{ functionName, callerInfo }` — caller function name and file path relative to `process.cwd()`.
|
|
62
30
|
*/
|
|
63
31
|
static getCaller(): {
|
|
64
32
|
functionName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debugService.d.ts","sourceRoot":"","sources":["../../src/services/debugService.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"debugService.d.ts","sourceRoot":"","sources":["../../src/services/debugService.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,cAAM,YAAY;IAChB;;;OAGG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,CAAM;IAElC;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxC,mEAAmE;IACnE,MAAM,CAAC,gBAAgB,IAAI,IAAI;IAI/B;;;;;OAKG;IACH,MAAM,CAAC,SAAS;;;;CAgEjB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* This service provides functionality to configure how the `getCaller` function
|
|
6
|
-
* identifies the actual caller in the stack trace by allowing specific files
|
|
7
|
-
* to be ignored during stack trace analysis.
|
|
3
|
+
* Manages stack-trace configuration for debug output, allowing specific adapter/wrapper files
|
|
4
|
+
* to be skipped so logs show the actual business-logic caller.
|
|
8
5
|
*
|
|
9
6
|
* @example
|
|
10
7
|
* ```typescript
|
|
11
|
-
* //
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* // Now when httpDebug is called from within httpAdapter.ts,
|
|
15
|
-
* // it will show the actual caller (e.g., cart.ts) instead
|
|
8
|
+
* // Skip httpAdapter.ts so debug output shows the calling route instead
|
|
9
|
+
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
16
10
|
* ```
|
|
17
11
|
*/
|
|
18
12
|
class DebugService {
|
|
@@ -22,48 +16,22 @@ class DebugService {
|
|
|
22
16
|
*/
|
|
23
17
|
static ignoreFiles = [];
|
|
24
18
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* This method configures the debug service to skip specific files when
|
|
28
|
-
* determining the actual caller of a function. This is useful when you have
|
|
29
|
-
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
19
|
+
* Adds a file name to the ignore list so it is skipped when resolving the caller in stack traces.
|
|
30
20
|
*
|
|
31
|
-
* @param
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
36
|
-
* DebugService.setIgnoreFile("httpAdapter.ts");
|
|
37
|
-
* ```
|
|
21
|
+
* @param file - File name to ignore (e.g. `"httpAdapter.ts"`).
|
|
38
22
|
*/
|
|
39
23
|
static setIgnoreFile(file) {
|
|
40
24
|
this.ignoreFiles.push(file);
|
|
41
25
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Clears all configured ignore files.
|
|
44
|
-
*
|
|
45
|
-
* This method resets the ignore file configuration, allowing all files to be
|
|
46
|
-
* considered in stack trace analysis again.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* // Clear all ignore file configurations
|
|
51
|
-
* DebugService.clearIgnoreFiles();
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
26
|
+
/** Resets the ignore list, restoring full stack trace analysis. */
|
|
54
27
|
static clearIgnoreFiles() {
|
|
55
28
|
this.ignoreFiles = [];
|
|
56
29
|
}
|
|
57
30
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* This function analyzes the stack trace to determine the file path and function name
|
|
61
|
-
* of the caller. It excludes stack trace entries related to the `@arkyn/server` package
|
|
62
|
-
* and attempts to resolve the file path relative to the project root directory.
|
|
31
|
+
* Resolves the file path and function name of the code that triggered the current debug call,
|
|
32
|
+
* skipping internal node modules and any files registered with `setIgnoreFile`.
|
|
63
33
|
*
|
|
64
|
-
* @returns
|
|
65
|
-
* - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
|
|
66
|
-
* - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
|
|
34
|
+
* @returns `{ functionName, callerInfo }` — caller function name and file path relative to `process.cwd()`.
|
|
67
35
|
*/
|
|
68
36
|
static getCaller() {
|
|
69
37
|
const projectRoot = process.cwd();
|
|
@@ -7,23 +7,18 @@
|
|
|
7
7
|
declare class LogService {
|
|
8
8
|
private static config?;
|
|
9
9
|
/**
|
|
10
|
-
* Sets the log service configuration
|
|
11
|
-
* If the configuration is already set, the call is ignored.
|
|
10
|
+
* Sets the log service configuration once. Subsequent calls are ignored.
|
|
12
11
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param {string} [config.logBaseApiUrl] - Optional base URL for the log service.
|
|
12
|
+
* @param config.trafficSourceId - Traffic source identifier.
|
|
13
|
+
* @param config.userToken - User token for authentication.
|
|
14
|
+
* @param config.logBaseApiUrl - Override the default log ingestion base URL.
|
|
17
15
|
*/
|
|
18
16
|
static setConfig(config: {
|
|
19
17
|
trafficSourceId: string;
|
|
20
18
|
userToken: string;
|
|
21
19
|
logBaseApiUrl?: string;
|
|
22
20
|
}): void;
|
|
23
|
-
/**
|
|
24
|
-
* Returns the current service configuration, if it exists.
|
|
25
|
-
* @returns {{ trafficSourceId: string; userToken: string; apiUrl: string } | undefined} The stored configuration or `undefined` if not set.
|
|
26
|
-
*/
|
|
21
|
+
/** Returns the stored configuration, or `undefined` if `setConfig` has not been called. */
|
|
27
22
|
static getConfig(): {
|
|
28
23
|
trafficSourceId: string;
|
|
29
24
|
userToken: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logService.d.ts","sourceRoot":"","sources":["../../src/services/logService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAM,UAAU;IACd,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAIpB;IAEF
|
|
1
|
+
{"version":3,"file":"logService.d.ts","sourceRoot":"","sources":["../../src/services/logService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAM,UAAU;IACd,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAIpB;IAEF;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE;QACvB,eAAe,EAAE,MAAM,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GAAG,IAAI;IAUR,2FAA2F;IAC3F,MAAM,CAAC,SAAS,IACZ;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAC9D,SAAS;IAIb;;OAEG;IACH,MAAM,CAAC,WAAW;CAGnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -7,13 +7,11 @@
|
|
|
7
7
|
class LogService {
|
|
8
8
|
static config;
|
|
9
9
|
/**
|
|
10
|
-
* Sets the log service configuration
|
|
11
|
-
* If the configuration is already set, the call is ignored.
|
|
10
|
+
* Sets the log service configuration once. Subsequent calls are ignored.
|
|
12
11
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @param {string} [config.logBaseApiUrl] - Optional base URL for the log service.
|
|
12
|
+
* @param config.trafficSourceId - Traffic source identifier.
|
|
13
|
+
* @param config.userToken - User token for authentication.
|
|
14
|
+
* @param config.logBaseApiUrl - Override the default log ingestion base URL.
|
|
17
15
|
*/
|
|
18
16
|
static setConfig(config) {
|
|
19
17
|
if (!!this.config)
|
|
@@ -23,10 +21,7 @@ class LogService {
|
|
|
23
21
|
const apiUrl = `${baseUrl}/ingest-log`;
|
|
24
22
|
this.config = { trafficSourceId, userToken, apiUrl };
|
|
25
23
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns the current service configuration, if it exists.
|
|
28
|
-
* @returns {{ trafficSourceId: string; userToken: string; apiUrl: string } | undefined} The stored configuration or `undefined` if not set.
|
|
29
|
-
*/
|
|
24
|
+
/** Returns the stored configuration, or `undefined` if `setConfig` has not been called. */
|
|
30
25
|
static getConfig() {
|
|
31
26
|
return this.config;
|
|
32
27
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Decodes
|
|
2
|
+
* Decodes a request body into a plain object, trying JSON first then URL-encoded form data.
|
|
3
|
+
* Throws `BadRequest` if neither format can be parsed.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* 2. If JSON parsing fails, attempts to parse the body as URL-encoded form data.
|
|
7
|
-
* 3. If both parsing attempts fail, logs the errors and returns an empty object.
|
|
5
|
+
* @param request - The incoming request whose body will be decoded.
|
|
6
|
+
* @returns The decoded body as a plain object.
|
|
8
7
|
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* export async function action({ request }: ActionFunctionArgs) {
|
|
11
|
+
* const body = await decodeRequestBody(request);
|
|
12
|
+
* // body is now a plain JS object
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
13
15
|
*/
|
|
14
16
|
declare function decodeRequestBody(request: Request): Promise<any>;
|
|
15
17
|
export { decodeRequestBody };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decodeRequestBody.d.ts","sourceRoot":"","sources":["../../src/utilities/decodeRequestBody.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"decodeRequestBody.d.ts","sourceRoot":"","sources":["../../src/utilities/decodeRequestBody.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAEH,iBAAe,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAsB/D;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { BadRequest } from "../http/badResponses/badRequest";
|
|
2
2
|
/**
|
|
3
|
-
* Decodes
|
|
3
|
+
* Decodes a request body into a plain object, trying JSON first then URL-encoded form data.
|
|
4
|
+
* Throws `BadRequest` if neither format can be parsed.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 2. If JSON parsing fails, attempts to parse the body as URL-encoded form data.
|
|
8
|
-
* 3. If both parsing attempts fail, logs the errors and returns an empty object.
|
|
6
|
+
* @param request - The incoming request whose body will be decoded.
|
|
7
|
+
* @returns The decoded body as a plain object.
|
|
9
8
|
*
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* export async function action({ request }: ActionFunctionArgs) {
|
|
12
|
+
* const body = await decodeRequestBody(request);
|
|
13
|
+
* // body is now a plain JS object
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
14
16
|
*/
|
|
15
17
|
async function decodeRequestBody(request) {
|
|
16
18
|
let data;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Extracts a human-readable error message from an API response body or a `Response` object.
|
|
3
|
+
* Checks `data.message`, `data.operator_erro_message`, `data.error`, `data.error.message`,
|
|
4
|
+
* and `response.statusText` in that order. Falls back to `"Missing error message"`.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* @param data - Parsed response body that may contain error info.
|
|
7
|
+
* @param response - The raw `Response` object, used as a fallback for `statusText`.
|
|
8
|
+
* @returns The first non-empty string error message found.
|
|
7
9
|
*
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const res = await fetch("/api/orders");
|
|
13
|
+
* const data = await res.json().catch(() => null);
|
|
14
|
+
* const message = decodeRequestErrorMessage(data, res);
|
|
15
|
+
* ```
|
|
14
16
|
*/
|
|
15
17
|
declare function decodeRequestErrorMessage(data: any, response: Response): string;
|
|
16
18
|
export { decodeRequestErrorMessage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decodeRequestErrorMessage.d.ts","sourceRoot":"","sources":["../../src/utilities/decodeRequestErrorMessage.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"decodeRequestErrorMessage.d.ts","sourceRoot":"","sources":["../../src/utilities/decodeRequestErrorMessage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAyBxE;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Extracts a human-readable error message from an API response body or a `Response` object.
|
|
3
|
+
* Checks `data.message`, `data.operator_erro_message`, `data.error`, `data.error.message`,
|
|
4
|
+
* and `response.statusText` in that order. Falls back to `"Missing error message"`.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* @param data - Parsed response body that may contain error info.
|
|
7
|
+
* @param response - The raw `Response` object, used as a fallback for `statusText`.
|
|
8
|
+
* @returns The first non-empty string error message found.
|
|
7
9
|
*
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const res = await fetch("/api/orders");
|
|
13
|
+
* const data = await res.json().catch(() => null);
|
|
14
|
+
* const message = decodeRequestErrorMessage(data, res);
|
|
15
|
+
* ```
|
|
14
16
|
*/
|
|
15
17
|
function decodeRequestErrorMessage(data, response) {
|
|
16
18
|
if (data?.message && typeof data?.message === "string") {
|
|
@@ -1,47 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Converts any thrown value into a `Response`. Recognizes all `@arkyn/server` success and error
|
|
3
|
+
* response classes, native `Response` objects, and falls back to a 500 `ServerError` for anything else.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
* response types (both success and error responses) and converts them into HTTP Response
|
|
6
|
-
* objects. If the error is not recognized, it defaults to returning a ServerError response.
|
|
5
|
+
* Intended to be used as the catch handler of a route action or loader:
|
|
7
6
|
*
|
|
8
|
-
* @param
|
|
9
|
-
*
|
|
10
|
-
* - A success response instance (Found, Created, Updated, Success, NoContent)
|
|
11
|
-
* - An error response instance (BadGateway, BadRequest, Conflict, Forbidden, NotFound, NotImplemented, ServerError, Unauthorized, UnprocessableEntity)
|
|
12
|
-
* - Any other error object (will be wrapped in ServerError)
|
|
13
|
-
*
|
|
14
|
-
* @returns {Response} A standard HTTP Response object with appropriate status code, headers, and body
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // Handling a success response
|
|
19
|
-
* try {
|
|
20
|
-
* const result = await someOperation();
|
|
21
|
-
* throw new Success("Operation successful", result);
|
|
22
|
-
* } catch (error) {
|
|
23
|
-
* return errorHandler(error);
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* // Handling an error response
|
|
30
|
-
* try {
|
|
31
|
-
* const user = await findUser(id);
|
|
32
|
-
* if (!user) throw new NotFound("User not found");
|
|
33
|
-
* } catch (error) {
|
|
34
|
-
* return errorHandler(error);
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
7
|
+
* @param error - The thrown value to convert.
|
|
8
|
+
* @returns A `Response` with the appropriate HTTP status, headers, and JSON body.
|
|
37
9
|
*
|
|
38
10
|
* @example
|
|
39
11
|
* ```typescript
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
12
|
+
* export async function action({ request }: ActionFunctionArgs) {
|
|
13
|
+
* try {
|
|
14
|
+
* const user = await findUser(id);
|
|
15
|
+
* if (!user) throw new NotFound("User not found");
|
|
16
|
+
* return new Success("User retrieved", { user }).toJson();
|
|
17
|
+
* } catch (error) {
|
|
18
|
+
* return errorHandler(error);
|
|
19
|
+
* }
|
|
45
20
|
* }
|
|
46
21
|
* ```
|
|
47
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/utilities/errorHandler.ts"],"names":[],"mappings":"AAgBA
|
|
1
|
+
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/utilities/errorHandler.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,QAAQ,CAsC1C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|