@arkyn/server 3.0.1-beta.99 → 3.0.2
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 +277 -224
- package/dist/http/api/_deleteRequest.d.ts +17 -0
- package/dist/http/api/_deleteRequest.d.ts.map +1 -0
- package/dist/http/api/_getRequest.d.ts +16 -0
- package/dist/http/api/_getRequest.d.ts.map +1 -0
- package/dist/http/api/_logMapperService.d.ts +86 -0
- package/dist/http/api/_logMapperService.d.ts.map +1 -0
- package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
- package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
- package/dist/http/api/_makeRequest.d.ts +61 -0
- package/dist/http/api/_makeRequest.d.ts.map +1 -0
- package/dist/http/api/_patchRequest.d.ts +17 -0
- package/dist/http/api/_patchRequest.d.ts.map +1 -0
- package/dist/http/api/_postRequest.d.ts +17 -0
- package/dist/http/api/_postRequest.d.ts.map +1 -0
- package/dist/http/api/_putRequest.d.ts +17 -0
- package/dist/http/api/_putRequest.d.ts.map +1 -0
- package/dist/http/badResponses/_badResponse.d.ts +21 -7
- package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
- package/dist/http/badResponses/badGateway.d.ts +12 -23
- package/dist/http/badResponses/badGateway.d.ts.map +1 -1
- package/dist/http/badResponses/badRequest.d.ts +10 -23
- package/dist/http/badResponses/badRequest.d.ts.map +1 -1
- package/dist/http/badResponses/conflict.d.ts +10 -23
- package/dist/http/badResponses/conflict.d.ts.map +1 -1
- package/dist/http/badResponses/forbidden.d.ts +10 -23
- package/dist/http/badResponses/forbidden.d.ts.map +1 -1
- package/dist/http/badResponses/notFound.d.ts +10 -23
- package/dist/http/badResponses/notFound.d.ts.map +1 -1
- package/dist/http/badResponses/notImplemented.d.ts +10 -23
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
- package/dist/http/badResponses/serverError.d.ts +10 -23
- package/dist/http/badResponses/serverError.d.ts.map +1 -1
- package/dist/http/badResponses/unauthorized.d.ts +10 -23
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
- package/dist/http/badResponses/unprocessableEntity.d.ts +23 -33
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
- package/dist/http/successResponses/_successResponse.d.ts +21 -7
- package/dist/http/successResponses/_successResponse.d.ts.map +1 -1
- package/dist/http/successResponses/created.d.ts +11 -29
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/found.d.ts +11 -32
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/noContent.d.ts +10 -16
- package/dist/http/successResponses/noContent.d.ts.map +1 -1
- package/dist/http/successResponses/success.d.ts +11 -29
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/updated.d.ts +12 -29
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/index.d.ts +9 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1069 -38
- package/dist/index.js.map +1 -0
- package/dist/modules/http/api/_deleteRequest.js +15 -0
- package/dist/modules/http/api/_deleteRequest.js.map +1 -0
- package/dist/modules/http/api/_getRequest.js +14 -0
- package/dist/modules/http/api/_getRequest.js.map +1 -0
- package/dist/modules/http/api/_logMapperService.js +33 -0
- package/dist/modules/http/api/_logMapperService.js.map +1 -0
- package/dist/modules/http/api/_logRequest.js +58 -0
- package/dist/modules/http/api/_logRequest.js.map +1 -0
- package/dist/modules/http/api/_makeRequest.js +72 -0
- package/dist/modules/http/api/_makeRequest.js.map +1 -0
- package/dist/modules/http/api/_patchRequest.js +15 -0
- package/dist/modules/http/api/_patchRequest.js.map +1 -0
- package/dist/modules/http/api/_postRequest.js +15 -0
- package/dist/modules/http/api/_postRequest.js.map +1 -0
- package/dist/modules/http/api/_putRequest.js +15 -0
- package/dist/modules/http/api/_putRequest.js.map +1 -0
- package/dist/modules/http/badResponses/_badResponse.js +65 -0
- package/dist/modules/http/badResponses/_badResponse.js.map +1 -0
- package/dist/modules/http/badResponses/badGateway.js +26 -0
- package/dist/modules/http/badResponses/badGateway.js.map +1 -0
- package/dist/modules/http/badResponses/badRequest.js +26 -0
- package/dist/modules/http/badResponses/badRequest.js.map +1 -0
- package/dist/modules/http/badResponses/conflict.js +26 -0
- package/dist/modules/http/badResponses/conflict.js.map +1 -0
- package/dist/modules/http/badResponses/forbidden.js +26 -0
- package/dist/modules/http/badResponses/forbidden.js.map +1 -0
- package/dist/modules/http/badResponses/notFound.js +26 -0
- package/dist/modules/http/badResponses/notFound.js.map +1 -0
- package/dist/modules/http/badResponses/notImplemented.js +26 -0
- package/dist/modules/http/badResponses/notImplemented.js.map +1 -0
- package/dist/modules/http/badResponses/serverError.js +26 -0
- package/dist/modules/http/badResponses/serverError.js.map +1 -0
- package/dist/modules/http/badResponses/unauthorized.js +26 -0
- package/dist/modules/http/badResponses/unauthorized.js.map +1 -0
- package/dist/modules/http/badResponses/unprocessableEntity.js +30 -0
- package/dist/modules/http/badResponses/unprocessableEntity.js.map +1 -0
- package/dist/modules/http/successResponses/_successResponse.js +64 -0
- package/dist/modules/http/successResponses/_successResponse.js.map +1 -0
- package/dist/modules/http/successResponses/created.js +26 -0
- package/dist/modules/http/successResponses/created.js.map +1 -0
- package/dist/modules/http/successResponses/found.js +26 -0
- package/dist/modules/http/successResponses/found.js.map +1 -0
- package/dist/modules/http/successResponses/noContent.js +19 -0
- package/dist/modules/http/successResponses/noContent.js.map +1 -0
- package/dist/modules/http/successResponses/success.js +26 -0
- package/dist/modules/http/successResponses/success.js.map +1 -0
- package/dist/modules/http/successResponses/updated.js +26 -0
- package/dist/modules/http/successResponses/updated.js.map +1 -0
- package/dist/modules/services/apiService.js +111 -0
- package/dist/modules/services/apiService.js.map +1 -0
- package/dist/modules/services/debugService.js +38 -0
- package/dist/modules/services/debugService.js.map +1 -0
- package/dist/modules/services/logService.js +23 -0
- package/dist/modules/services/logService.js.map +1 -0
- package/dist/modules/utilities/decodeRequestBody.js +22 -0
- package/dist/modules/utilities/decodeRequestBody.js.map +1 -0
- package/dist/modules/utilities/decodeRequestErrorMessage.js +8 -0
- package/dist/modules/utilities/decodeRequestErrorMessage.js.map +1 -0
- package/dist/modules/utilities/errorHandler.js +41 -0
- package/dist/modules/utilities/errorHandler.js.map +1 -0
- package/dist/modules/utilities/flushDebugLogs.js +18 -0
- package/dist/modules/utilities/flushDebugLogs.js.map +1 -0
- package/dist/modules/utilities/formAsyncParse.js +16 -0
- package/dist/modules/utilities/formAsyncParse.js.map +1 -0
- package/dist/modules/utilities/formParse.js +16 -0
- package/dist/modules/utilities/formParse.js.map +1 -0
- package/dist/modules/utilities/getScopedParams.js +11 -0
- package/dist/modules/utilities/getScopedParams.js.map +1 -0
- package/dist/modules/utilities/schemaValidator.js +57 -0
- package/dist/modules/utilities/schemaValidator.js.map +1 -0
- package/dist/modules/validations/validateCep.js +11 -0
- package/dist/modules/validations/validateCep.js.map +1 -0
- package/dist/modules/validations/validateCnpj.js +56 -0
- package/dist/modules/validations/validateCnpj.js.map +1 -0
- package/dist/modules/validations/validateCpf.js +29 -0
- package/dist/modules/validations/validateCpf.js.map +1 -0
- package/dist/modules/validations/validateDate.js +28 -0
- package/dist/modules/validations/validateDate.js.map +1 -0
- package/dist/modules/validations/validateEmail.js +56 -0
- package/dist/modules/validations/validateEmail.js.map +1 -0
- package/dist/modules/validations/validatePassword.js +14 -0
- package/dist/modules/validations/validatePassword.js.map +1 -0
- package/dist/modules/validations/validatePhone.js +12 -0
- package/dist/modules/validations/validatePhone.js.map +1 -0
- package/dist/modules/validations/validateRg.js +10 -0
- package/dist/modules/validations/validateRg.js.map +1 -0
- package/dist/services/apiService.d.ts +25 -26
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/debugService.d.ts +15 -32
- package/dist/services/debugService.d.ts.map +1 -1
- package/dist/services/logService.d.ts +33 -0
- package/dist/services/logService.d.ts.map +1 -0
- package/dist/utilities/decodeRequestBody.d.ts +18 -0
- package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
- package/dist/utilities/decodeRequestErrorMessage.d.ts +19 -0
- package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
- package/dist/utilities/errorHandler.d.ts +25 -0
- package/dist/utilities/errorHandler.d.ts.map +1 -0
- package/dist/utilities/flushDebugLogs.d.ts +24 -0
- package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
- package/dist/utilities/formAsyncParse.d.ts +38 -0
- package/dist/utilities/formAsyncParse.d.ts.map +1 -0
- package/dist/utilities/formParse.d.ts +38 -0
- package/dist/utilities/formParse.d.ts.map +1 -0
- package/dist/utilities/getScopedParams.d.ts +19 -0
- package/dist/utilities/getScopedParams.d.ts.map +1 -0
- package/dist/utilities/schemaValidator.d.ts +75 -0
- package/dist/utilities/schemaValidator.d.ts.map +1 -0
- package/dist/validations/validateCep.d.ts +6 -11
- package/dist/validations/validateCep.d.ts.map +1 -1
- package/dist/validations/validateCnpj.d.ts +2 -3
- package/dist/validations/validateCnpj.d.ts.map +1 -1
- package/dist/validations/validateCpf.d.ts +4 -12
- package/dist/validations/validateCpf.d.ts.map +1 -1
- package/dist/validations/validateDate.d.ts +13 -24
- package/dist/validations/validateDate.d.ts.map +1 -1
- package/dist/validations/validateEmail.d.ts +3 -4
- package/dist/validations/validateEmail.d.ts.map +1 -1
- package/dist/validations/validatePassword.d.ts +3 -4
- package/dist/validations/validatePassword.d.ts.map +1 -1
- package/dist/validations/validatePhone.d.ts +7 -20
- package/dist/validations/validatePhone.d.ts.map +1 -1
- package/dist/validations/validateRg.d.ts +1 -2
- package/dist/validations/validateRg.d.ts.map +1 -1
- package/package.json +317 -15
- package/dist/api/arkynLogRequest.js +0 -88
- package/dist/api/deleteRequest.d.ts +0 -13
- package/dist/api/deleteRequest.d.ts.map +0 -1
- package/dist/api/deleteRequest.js +0 -14
- package/dist/api/getRequest.d.ts +0 -12
- package/dist/api/getRequest.d.ts.map +0 -1
- package/dist/api/getRequest.js +0 -13
- package/dist/api/makeRequest.d.ts +0 -38
- package/dist/api/makeRequest.d.ts.map +0 -1
- package/dist/api/makeRequest.js +0 -107
- package/dist/api/patchRequest.d.ts +0 -13
- package/dist/api/patchRequest.d.ts.map +0 -1
- package/dist/api/patchRequest.js +0 -14
- package/dist/api/postRequest.d.ts +0 -13
- package/dist/api/postRequest.d.ts.map +0 -1
- package/dist/api/postRequest.js +0 -14
- package/dist/api/putRequest.d.ts +0 -13
- package/dist/api/putRequest.d.ts.map +0 -1
- package/dist/api/putRequest.js +0 -14
- package/dist/bundle.js +0 -1507
- package/dist/bundle.umd.cjs +0 -10
- package/dist/http/badResponses/_badResponse.js +0 -20
- package/dist/http/badResponses/badGateway.js +0 -58
- package/dist/http/badResponses/badRequest.js +0 -58
- package/dist/http/badResponses/conflict.js +0 -58
- package/dist/http/badResponses/forbidden.js +0 -58
- package/dist/http/badResponses/notFound.js +0 -58
- package/dist/http/badResponses/notImplemented.js +0 -58
- package/dist/http/badResponses/serverError.js +0 -58
- package/dist/http/badResponses/unauthorized.js +0 -58
- package/dist/http/badResponses/unprocessableEntity.js +0 -65
- package/dist/http/successResponses/_successResponse.js +0 -37
- package/dist/http/successResponses/created.js +0 -57
- package/dist/http/successResponses/found.js +0 -60
- package/dist/http/successResponses/noContent.js +0 -38
- package/dist/http/successResponses/success.js +0 -57
- package/dist/http/successResponses/updated.js +0 -57
- package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
- package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
- package/dist/mapper/arkynLogRequestMapper.js +0 -44
- package/dist/services/apiService.js +0 -133
- package/dist/services/arkynLogService.d.ts +0 -44
- package/dist/services/arkynLogService.d.ts.map +0 -1
- package/dist/services/arkynLogService.js +0 -46
- package/dist/services/debugService.js +0 -57
- package/dist/services/decodeErrorMessageFromRequest.d.ts +0 -17
- package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
- package/dist/services/decodeErrorMessageFromRequest.js +0 -30
- package/dist/services/decodeRequestBody.d.ts +0 -17
- package/dist/services/decodeRequestBody.d.ts.map +0 -1
- package/dist/services/decodeRequestBody.js +0 -38
- package/dist/services/errorHandler.d.ts +0 -44
- package/dist/services/errorHandler.d.ts.map +0 -1
- package/dist/services/errorHandler.js +0 -93
- package/dist/services/flushDebugLogs.d.ts +0 -8
- package/dist/services/flushDebugLogs.d.ts.map +0 -1
- package/dist/services/flushDebugLogs.js +0 -20
- package/dist/services/formAsyncParse.d.ts +0 -59
- package/dist/services/formAsyncParse.d.ts.map +0 -1
- package/dist/services/formAsyncParse.js +0 -58
- package/dist/services/formParse.d.ts +0 -59
- package/dist/services/formParse.d.ts.map +0 -1
- package/dist/services/formParse.js +0 -58
- package/dist/services/getCaller.d.ts +0 -17
- package/dist/services/getCaller.d.ts.map +0 -1
- package/dist/services/getCaller.js +0 -60
- package/dist/services/getScopedParams.d.ts +0 -28
- package/dist/services/getScopedParams.d.ts.map +0 -1
- package/dist/services/getScopedParams.js +0 -34
- package/dist/services/measureRouteExecution.d.ts +0 -3
- package/dist/services/measureRouteExecution.d.ts.map +0 -1
- package/dist/services/measureRouteExecution.js +0 -24
- package/dist/services/schemaValidator.d.ts +0 -158
- package/dist/services/schemaValidator.d.ts.map +0 -1
- package/dist/services/schemaValidator.js +0 -207
- package/dist/types/ApiResponseDTO.d.ts +0 -17
- package/dist/types/ApiResponseDTO.d.ts.map +0 -1
- package/dist/types/ApiResponseDTO.js +0 -1
- package/dist/validations/validateCep.js +0 -33
- package/dist/validations/validateCnpj.js +0 -52
- package/dist/validations/validateCpf.js +0 -54
- package/dist/validations/validateDate.js +0 -73
- package/dist/validations/validateEmail.js +0 -123
- package/dist/validations/validatePassword.js +0 -34
- package/dist/validations/validatePhone.js +0 -44
- package/dist/validations/validateRg.js +0 -31
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { flushDebugLogs as e } from "../utilities/flushDebugLogs.js";
|
|
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
|
+
//#region src/services/apiService.ts
|
|
8
|
+
var o = class {
|
|
9
|
+
baseUrl;
|
|
10
|
+
baseHeaders;
|
|
11
|
+
baseToken;
|
|
12
|
+
enableDebug;
|
|
13
|
+
constructor(e) {
|
|
14
|
+
this.baseUrl = e.baseUrl, this.baseHeaders = e.baseHeaders || void 0, this.baseToken = e.baseToken || void 0, this.enableDebug = e.enableDebug || !1;
|
|
15
|
+
}
|
|
16
|
+
onDebug(t, n, r) {
|
|
17
|
+
if (this.enableDebug) {
|
|
18
|
+
let i = [], a = (e) => JSON.stringify(e, null, 2);
|
|
19
|
+
i.push(`Base URL: ${this.baseUrl}`), i.push(`Endpoint: ${t}`), i.push(`Status/Method: ${n} => ${r.status}`), i.push(`Message: ${r.message}`), r.headers && i.push(`Headers: ${a(r.headers)}`), r.body && i.push(`Body: ${a(r.body)}`), e({
|
|
20
|
+
debugs: i,
|
|
21
|
+
name: "ApiDebug",
|
|
22
|
+
scheme: "yellow"
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
generateHeaders(e, t) {
|
|
27
|
+
let n = {};
|
|
28
|
+
return this.baseToken && (n = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (n = {
|
|
29
|
+
...n,
|
|
30
|
+
...this.baseHeaders
|
|
31
|
+
}), e && (n = {
|
|
32
|
+
...n,
|
|
33
|
+
...e
|
|
34
|
+
}), t && (n = {
|
|
35
|
+
...n,
|
|
36
|
+
Authorization: `Bearer ${t}`
|
|
37
|
+
}), n;
|
|
38
|
+
}
|
|
39
|
+
async get(e, t) {
|
|
40
|
+
let r = this.generateHeaders(t?.headers || {}, t?.token), i = await n({
|
|
41
|
+
url: this.baseUrl + e,
|
|
42
|
+
urlParams: t?.urlParams || {},
|
|
43
|
+
headers: r
|
|
44
|
+
});
|
|
45
|
+
return this.onDebug(e, "get", {
|
|
46
|
+
headers: r,
|
|
47
|
+
message: i.message,
|
|
48
|
+
status: i.status
|
|
49
|
+
}), i;
|
|
50
|
+
}
|
|
51
|
+
async post(e, t) {
|
|
52
|
+
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, a = await i({
|
|
53
|
+
url: this.baseUrl + e,
|
|
54
|
+
urlParams: t?.urlParams || {},
|
|
55
|
+
headers: n,
|
|
56
|
+
body: r
|
|
57
|
+
});
|
|
58
|
+
return this.onDebug(e, "post", {
|
|
59
|
+
headers: n,
|
|
60
|
+
body: r,
|
|
61
|
+
message: a.message,
|
|
62
|
+
status: a.status
|
|
63
|
+
}), a;
|
|
64
|
+
}
|
|
65
|
+
async put(e, t) {
|
|
66
|
+
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await a({
|
|
67
|
+
url: this.baseUrl + e,
|
|
68
|
+
urlParams: t?.urlParams || {},
|
|
69
|
+
headers: n,
|
|
70
|
+
body: r
|
|
71
|
+
});
|
|
72
|
+
return this.onDebug(e, "put", {
|
|
73
|
+
headers: n,
|
|
74
|
+
body: r,
|
|
75
|
+
message: i.message,
|
|
76
|
+
status: i.status
|
|
77
|
+
}), i;
|
|
78
|
+
}
|
|
79
|
+
async patch(e, t) {
|
|
80
|
+
let n = this.generateHeaders(t?.headers || {}, t?.token), i = t?.body, a = await r({
|
|
81
|
+
url: this.baseUrl + e,
|
|
82
|
+
urlParams: t?.urlParams || {},
|
|
83
|
+
headers: n,
|
|
84
|
+
body: i
|
|
85
|
+
});
|
|
86
|
+
return this.onDebug(e, "patch", {
|
|
87
|
+
headers: n,
|
|
88
|
+
body: i,
|
|
89
|
+
message: a.message,
|
|
90
|
+
status: a.status
|
|
91
|
+
}), a;
|
|
92
|
+
}
|
|
93
|
+
async delete(e, n) {
|
|
94
|
+
let r = this.generateHeaders(n?.headers || {}, n?.token), i = n?.body, a = await t({
|
|
95
|
+
url: this.baseUrl + e,
|
|
96
|
+
urlParams: n?.urlParams || {},
|
|
97
|
+
headers: r,
|
|
98
|
+
body: i
|
|
99
|
+
});
|
|
100
|
+
return this.onDebug(e, "delete", {
|
|
101
|
+
headers: r,
|
|
102
|
+
body: i,
|
|
103
|
+
message: a.message,
|
|
104
|
+
status: a.status
|
|
105
|
+
}), a;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
//#endregion
|
|
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,38 @@
|
|
|
1
|
+
import e from "node:path";
|
|
2
|
+
//#region src/services/debugService.ts
|
|
3
|
+
var t = class t {
|
|
4
|
+
static ignoreFiles = [];
|
|
5
|
+
static setIgnoreFile(e) {
|
|
6
|
+
t.ignoreFiles.push(e);
|
|
7
|
+
}
|
|
8
|
+
static clearIgnoreFiles() {
|
|
9
|
+
t.ignoreFiles = [];
|
|
10
|
+
}
|
|
11
|
+
static getCaller() {
|
|
12
|
+
let n = process.cwd(), r = ((/* @__PURE__ */ Error()).stack || "").split("\n").map((e) => e.trim()), i = 2;
|
|
13
|
+
for (; i < r.length && (r[i].includes("node:internal") || r[i].includes("/node_modules/"));) i++;
|
|
14
|
+
if (t.ignoreFiles.length > 0) for (; i < r.length && t.ignoreFiles.some((e) => r[i].includes(e));) i++;
|
|
15
|
+
let a = r[i] || "", o = "Unknown function", s = "Unknown caller", c = a.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
|
|
16
|
+
if (c) o = c[1], s = c[2];
|
|
17
|
+
else {
|
|
18
|
+
let e = a.match(/at\s+(.+)/);
|
|
19
|
+
if (e) {
|
|
20
|
+
s = e[1];
|
|
21
|
+
let t = s.match(/at\s+([^(\s]+)\s+/);
|
|
22
|
+
t && t[1] !== "new" && (o = t[1]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
s.includes("(") && (s = s.substring(s.indexOf("(") + 1, s.lastIndexOf(")"))), s = s.split(":").slice(0, -2).join(":");
|
|
26
|
+
try {
|
|
27
|
+
s = e.relative(n, s);
|
|
28
|
+
} catch {}
|
|
29
|
+
return {
|
|
30
|
+
functionName: o,
|
|
31
|
+
callerInfo: s
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { t as DebugService };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=debugService.js.map
|
|
@@ -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,23 @@
|
|
|
1
|
+
//#region src/services/logService.ts
|
|
2
|
+
var e = class e {
|
|
3
|
+
static config;
|
|
4
|
+
static setConfig(t) {
|
|
5
|
+
if (e.config) return;
|
|
6
|
+
let { trafficSourceId: n, userToken: r, logBaseApiUrl: i } = t;
|
|
7
|
+
e.config = {
|
|
8
|
+
trafficSourceId: n,
|
|
9
|
+
userToken: r,
|
|
10
|
+
apiUrl: `${i || "http://62.238.8.44:8081"}/ingest-log`
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
static getConfig() {
|
|
14
|
+
return e.config;
|
|
15
|
+
}
|
|
16
|
+
static resetConfig() {
|
|
17
|
+
e.config = void 0;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { e as LogService };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=logService.js.map
|
|
@@ -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,22 @@
|
|
|
1
|
+
import { BadRequest as e } from "../http/badResponses/badRequest.js";
|
|
2
|
+
//#region src/utilities/decodeRequestBody.ts
|
|
3
|
+
async function t(t) {
|
|
4
|
+
let n, r = await t.arrayBuffer(), i = new TextDecoder().decode(r);
|
|
5
|
+
try {
|
|
6
|
+
n = JSON.parse(i);
|
|
7
|
+
} catch {
|
|
8
|
+
try {
|
|
9
|
+
if (i.includes("=")) {
|
|
10
|
+
let e = new URLSearchParams(i);
|
|
11
|
+
n = Object.fromEntries(e.entries());
|
|
12
|
+
} else throw new e("Invalid URLSearchParams format");
|
|
13
|
+
} catch {
|
|
14
|
+
throw new e("Failed to extract data from request");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { t as decodeRequestBody };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=decodeRequestBody.js.map
|
|
@@ -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,8 @@
|
|
|
1
|
+
//#region src/utilities/decodeRequestErrorMessage.ts
|
|
2
|
+
function e(e, t) {
|
|
3
|
+
return e?.message && typeof e?.message == "string" ? e?.message : e?.operator_erro_message && typeof e?.operator_erro_message == "string" ? e?.operator_erro_message : e?.error && typeof e?.error == "string" ? e?.error : e?.error?.message && typeof e?.error?.message == "string" ? e?.error?.message : t?.statusText && typeof t?.statusText == "string" ? t?.statusText : "Missing error message";
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
export { e as decodeRequestErrorMessage };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=decodeRequestErrorMessage.js.map
|
|
@@ -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,41 @@
|
|
|
1
|
+
import { BadGateway as e } from "../http/badResponses/badGateway.js";
|
|
2
|
+
import { BadRequest as t } from "../http/badResponses/badRequest.js";
|
|
3
|
+
import { Conflict as n } from "../http/badResponses/conflict.js";
|
|
4
|
+
import { Forbidden as r } from "../http/badResponses/forbidden.js";
|
|
5
|
+
import { NotFound as i } from "../http/badResponses/notFound.js";
|
|
6
|
+
import { NotImplemented as a } from "../http/badResponses/notImplemented.js";
|
|
7
|
+
import { ServerError as o } from "../http/badResponses/serverError.js";
|
|
8
|
+
import { Unauthorized as s } from "../http/badResponses/unauthorized.js";
|
|
9
|
+
import { UnprocessableEntity as c } from "../http/badResponses/unprocessableEntity.js";
|
|
10
|
+
import { Created as l } from "../http/successResponses/created.js";
|
|
11
|
+
import { Found as u } from "../http/successResponses/found.js";
|
|
12
|
+
import { NoContent as d } from "../http/successResponses/noContent.js";
|
|
13
|
+
import { Success as f } from "../http/successResponses/success.js";
|
|
14
|
+
import { Updated as p } from "../http/successResponses/updated.js";
|
|
15
|
+
//#region src/utilities/errorHandler.ts
|
|
16
|
+
function m(m) {
|
|
17
|
+
switch (!0) {
|
|
18
|
+
case m instanceof Response: return m;
|
|
19
|
+
case m instanceof u: return m.toResponse();
|
|
20
|
+
case m instanceof l: return m.toResponse();
|
|
21
|
+
case m instanceof p: return m.toResponse();
|
|
22
|
+
case m instanceof f: return m.toResponse();
|
|
23
|
+
case m instanceof d: return m.toResponse();
|
|
24
|
+
}
|
|
25
|
+
switch (!0) {
|
|
26
|
+
case m instanceof e: return m.toResponse();
|
|
27
|
+
case m instanceof t: return m.toResponse();
|
|
28
|
+
case m instanceof n: return m.toResponse();
|
|
29
|
+
case m instanceof r: return m.toResponse();
|
|
30
|
+
case m instanceof i: return m.toResponse();
|
|
31
|
+
case m instanceof a: return m.toResponse();
|
|
32
|
+
case m instanceof o: return m.toResponse();
|
|
33
|
+
case m instanceof s: return m.toResponse();
|
|
34
|
+
case m instanceof c: return m.toResponse();
|
|
35
|
+
}
|
|
36
|
+
return new o("Server error", m).toResponse();
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { m as errorHandler };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=errorHandler.js.map
|
|
@@ -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,18 @@
|
|
|
1
|
+
//#region src/utilities/flushDebugLogs.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
if (process.env.NODE_ENV === "development" || process.env?.DEBUG_MODE === "true") {
|
|
4
|
+
let t = `${{
|
|
5
|
+
yellow: "\x1B[33m",
|
|
6
|
+
cyan: "\x1B[36m",
|
|
7
|
+
red: "\x1B[31m",
|
|
8
|
+
green: "\x1B[32m"
|
|
9
|
+
}[e.scheme]}[${e.name}][0m`, n = "\n";
|
|
10
|
+
e.debugs.forEach((r, i) => {
|
|
11
|
+
n += `${t} ${r.trim()}`, i < e.debugs.length - 1 && (n += "\n");
|
|
12
|
+
}), console.log(n);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { e as flushDebugLogs };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=flushDebugLogs.js.map
|
|
@@ -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,16 @@
|
|
|
1
|
+
//#region src/utilities/formAsyncParse.ts
|
|
2
|
+
async function e([e, t]) {
|
|
3
|
+
let n = await t.safeParseAsync(e);
|
|
4
|
+
return n.success === !1 ? {
|
|
5
|
+
success: !1,
|
|
6
|
+
fieldErrors: Object.fromEntries(n.error.issues.map((e) => [e.path.join("."), e.message])),
|
|
7
|
+
fields: e
|
|
8
|
+
} : {
|
|
9
|
+
success: !0,
|
|
10
|
+
data: n.data
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { e as formAsyncParse };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=formAsyncParse.js.map
|
|
@@ -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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/utilities/formParse.ts
|
|
2
|
+
function e([e, t]) {
|
|
3
|
+
let n = t.safeParse(e);
|
|
4
|
+
return n.success === !1 ? {
|
|
5
|
+
success: !1,
|
|
6
|
+
fieldErrors: Object.fromEntries(n.error.issues.map((e) => [e.path.join("."), e.message])),
|
|
7
|
+
fields: e
|
|
8
|
+
} : {
|
|
9
|
+
success: !0,
|
|
10
|
+
data: n.data
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { e as formParse };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=formParse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formParse.js","names":[],"sources":["../../../src/utilities/formParse.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 * Validates form data against a Zod schema synchronously.\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({ name: z.string().min(1, \"Required\"), age: z.number().min(18) });\n * const result = formParse([{ name: \"\", age: 15 }, schema]);\n *\n * if (!result.success) {\n * console.log(result.fieldErrors); // { name: \"Required\", age: \"...\" }\n * }\n * ```\n */\n\nfunction formParse<T extends FormParseProps>([\n\tformData,\n\tschema,\n]: T): FormParseReturnType<T> {\n\tconst zodResponse = schema.safeParse(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 { formParse };\n"],"mappings":";AAsCA,SAAS,EAAoC,CAC5C,GACA,IAC6B;CAC7B,IAAM,IAAc,EAAO,UAAU,CAAQ;CAe5C,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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/utilities/getScopedParams.ts
|
|
2
|
+
function e(e, t = "") {
|
|
3
|
+
let n = new URL(e.url);
|
|
4
|
+
if (t === "") return n.searchParams;
|
|
5
|
+
let r = Array.from(n.searchParams.entries()).filter(([e]) => e.startsWith(`${t}:`)).map(([e, n]) => [e.replace(`${t}:`, ""), n]);
|
|
6
|
+
return new URLSearchParams(r);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as getScopedParams };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=getScopedParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getScopedParams.js","names":[],"sources":["../../../src/utilities/getScopedParams.ts"],"sourcesContent":["/**\n * Extracts URL search parameters from a request, optionally filtered by a namespace prefix\n * (e.g. `scope:key` → `key`). Without a scope, returns all search params as-is.\n *\n * @param request - The incoming request whose URL will be parsed.\n * @param scope - Namespace prefix to filter by (e.g. `\"table\"` matches `table:page`, `table:sort`).\n * @returns A `URLSearchParams` object with the matching params, stripped of the scope prefix.\n *\n * @example\n * ```typescript\n * // URL: /products?table:page=2&table:sort=asc&other=1\n * const params = getScopedParams(request, \"table\");\n * params.get(\"page\"); // \"2\"\n * params.get(\"sort\"); // \"asc\"\n * ```\n */\n\nfunction getScopedParams(request: Request, scope: string = \"\") {\n\tconst url = new URL(request.url);\n\tif (scope === \"\") return url.searchParams;\n\n\tconst scopedSearchParams: [string, string][] = Array.from(\n\t\turl.searchParams.entries(),\n\t)\n\t\t.filter(([key]) => key.startsWith(`${scope}:`))\n\t\t.map(([key, value]) => [key.replace(`${scope}:`, \"\"), value]);\n\n\treturn new URLSearchParams(scopedSearchParams);\n}\n\nexport { getScopedParams };\n"],"mappings":";AAiBA,SAAS,EAAgB,GAAkB,IAAgB,IAAI;CAC9D,IAAM,IAAM,IAAI,IAAI,EAAQ,GAAG;CAC/B,IAAI,MAAU,IAAI,OAAO,EAAI;CAE7B,IAAM,IAAyC,MAAM,KACpD,EAAI,aAAa,QAAQ,CAC1B,CAAC,CACC,QAAQ,CAAC,OAAS,EAAI,WAAW,GAAG,EAAM,EAAE,CAAC,CAAC,CAC9C,KAAK,CAAC,GAAK,OAAW,CAAC,EAAI,QAAQ,GAAG,EAAM,IAAI,EAAE,GAAG,CAAK,CAAC;CAE7D,OAAO,IAAI,gBAAgB,CAAkB;AAC9C"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ServerError as e } from "../http/badResponses/serverError.js";
|
|
2
|
+
import { UnprocessableEntity as t } from "../http/badResponses/unprocessableEntity.js";
|
|
3
|
+
import { formAsyncParse as n } from "./formAsyncParse.js";
|
|
4
|
+
import { formParse as r } from "./formParse.js";
|
|
5
|
+
//#region src/utilities/schemaValidator.ts
|
|
6
|
+
function i(e) {
|
|
7
|
+
return ["Error validating:", ...e.issues.map(({ path: e, message: t }) => `-> ${e.join(".")}: ${t}`)].join("\n");
|
|
8
|
+
}
|
|
9
|
+
var a = class {
|
|
10
|
+
schema;
|
|
11
|
+
constructor(e) {
|
|
12
|
+
this.schema = e;
|
|
13
|
+
}
|
|
14
|
+
isValid(e) {
|
|
15
|
+
return this.schema.safeParse(e).success;
|
|
16
|
+
}
|
|
17
|
+
safeValidate(e) {
|
|
18
|
+
return this.schema.safeParse(e);
|
|
19
|
+
}
|
|
20
|
+
validate(t) {
|
|
21
|
+
try {
|
|
22
|
+
return this.schema.parse(t);
|
|
23
|
+
} catch (t) {
|
|
24
|
+
throw new e(i(t));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
formValidate(e, n) {
|
|
28
|
+
let i = r([e, this.schema]);
|
|
29
|
+
if ("fieldErrors" in i) {
|
|
30
|
+
let e = Object.keys(i.fieldErrors)[0];
|
|
31
|
+
throw new t({
|
|
32
|
+
fields: i.fields,
|
|
33
|
+
fieldErrors: i.fieldErrors,
|
|
34
|
+
data: { scrollTo: e },
|
|
35
|
+
message: n
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return i.data;
|
|
39
|
+
}
|
|
40
|
+
async formAsyncValidate(e, r) {
|
|
41
|
+
let i = await n([e, this.schema]);
|
|
42
|
+
if ("fieldErrors" in i) {
|
|
43
|
+
let e = Object.keys(i.fieldErrors)[0];
|
|
44
|
+
throw new t({
|
|
45
|
+
fields: i.fields,
|
|
46
|
+
fieldErrors: i.fieldErrors,
|
|
47
|
+
data: { scrollTo: e },
|
|
48
|
+
message: r
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return i.data;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { a as SchemaValidator };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=schemaValidator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaValidator.js","names":[],"sources":["../../../src/utilities/schemaValidator.ts"],"sourcesContent":["import type { ZodType, z } from \"zod\";\n\nimport { ServerError } from \"../http/badResponses/serverError\";\nimport { UnprocessableEntity } from \"../http/badResponses/unprocessableEntity\";\nimport { formAsyncParse } from \"./formAsyncParse\";\nimport { formParse } from \"./formParse\";\n\nfunction formatErrorMessage(error: z.ZodError) {\n\tconst title = \"Error validating:\";\n\tconst lines = error.issues.map(\n\t\t({ path, message }) => `-> ${path.join(\".\")}: ${message}`,\n\t);\n\n\treturn [title, ...lines].join(\"\\n\");\n}\n\n/**\n * Wraps a Zod schema with convenience validation methods suited for server-side use:\n * - `isValid` — boolean check, no throws\n * - `safeValidate` — raw Zod result, no throws\n * - `validate` — throws `ServerError` on failure (for trusted/internal data)\n * - `formValidate` / `formAsyncValidate` — throws `UnprocessableEntity` on failure (for user-submitted forms)\n *\n * @example\n * ```typescript\n * const validator = new SchemaValidator(z.object({ email: z.string().email() }));\n *\n * // Inside a Remix action:\n * const body = validator.formValidate(await decodeRequestBody(request));\n * ```\n */\nclass SchemaValidator<T extends ZodType> {\n\t/**\n\t * @param schema - The Zod schema used for all validation methods on this instance.\n\t */\n\tconstructor(readonly schema: T) {}\n\n\t/**\n\t * Returns `true` if the data satisfies the schema, `false` otherwise. Never throws.\n\t *\n\t * @param data - The value to check.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tisValid(data: any): boolean {\n\t\treturn this.schema.safeParse(data).success;\n\t}\n\n\t/**\n\t * Validates data and returns the raw Zod `safeParseResult` without throwing.\n\t * Useful when you need access to the full error details.\n\t *\n\t * @param data - The value to validate.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tsafeValidate(data: any): z.ZodSafeParseResult<z.infer<T>> {\n\t\treturn this.schema.safeParse(data);\n\t}\n\n\t/**\n\t * Validates data and returns the typed result, throwing `ServerError` on failure.\n\t * Use for validating internal/trusted data (e.g. env vars, config objects).\n\t *\n\t * @param data - The value to validate.\n\t * @throws `ServerError` with a formatted field-by-field error message.\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tvalidate(data: any): z.infer<T> {\n\t\ttry {\n\t\t\treturn this.schema.parse(data);\n\t\t} catch (error) {\n\t\t\tthrow new ServerError(formatErrorMessage(error as z.ZodError));\n\t\t}\n\t}\n\n\t/**\n\t * Validates form data and returns the typed result, throwing `UnprocessableEntity` on failure.\n\t * The error includes `fieldErrors`, `fields`, and `data.scrollTo` (first failing field name).\n\t *\n\t * @param data - The raw form data to validate.\n\t * @param message - Optional human-readable error message for the 422 response.\n\t * @throws `UnprocessableEntity` with structured field errors for client-side form handling.\n\t *\n\t * @example\n\t * ```typescript\n\t * const validator = new SchemaValidator(registerSchema);\n\t * const body = validator.formValidate(await decodeRequestBody(request));\n\t * ```\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tformValidate(data: any, message?: string): z.infer<T> {\n\t\tconst formParsed = formParse([data, this.schema]);\n\n\t\tif (\"fieldErrors\" in formParsed) {\n\t\t\tconst firstErrorKey = Object.keys(formParsed.fieldErrors)[0];\n\n\t\t\tthrow new UnprocessableEntity({\n\t\t\t\tfields: formParsed.fields,\n\t\t\t\tfieldErrors: formParsed.fieldErrors,\n\t\t\t\tdata: { scrollTo: firstErrorKey },\n\t\t\t\tmessage,\n\t\t\t});\n\t\t}\n\n\t\treturn formParsed.data as z.infer<T>;\n\t}\n\n\t/**\n\t * Async version of `formValidate` for schemas with async refinements (e.g. uniqueness checks).\n\t *\n\t * @param data - The raw form data to validate.\n\t * @param message - Optional human-readable error message for the 422 response.\n\t * @throws `UnprocessableEntity` with structured field errors for client-side form handling.\n\t *\n\t * @example\n\t * ```typescript\n\t * const validator = new SchemaValidator(registerSchema);\n\t * const body = await validator.formAsyncValidate(await decodeRequestBody(request));\n\t * ```\n\t */\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tasync formAsyncValidate(data: any, message?: string): Promise<z.infer<T>> {\n\t\tconst formParsed = await formAsyncParse([data, this.schema]);\n\n\t\tif (\"fieldErrors\" in formParsed) {\n\t\t\tconst firstErrorKey = Object.keys(formParsed.fieldErrors)[0];\n\n\t\t\tthrow new UnprocessableEntity({\n\t\t\t\tfields: formParsed.fields,\n\t\t\t\tfieldErrors: formParsed.fieldErrors,\n\t\t\t\tdata: { scrollTo: firstErrorKey },\n\t\t\t\tmessage,\n\t\t\t});\n\t\t}\n\n\t\treturn formParsed.data as z.infer<T>;\n\t}\n}\n\nexport { SchemaValidator };\n"],"mappings":";;;;;AAOA,SAAS,EAAmB,GAAmB;CAM9C,OAAO,CAAC,qBAAO,GAJD,EAAM,OAAO,KACzB,EAAE,SAAM,iBAAc,MAAM,EAAK,KAAK,GAAG,EAAE,IAAI,GAG/B,CAAK,CAAC,CAAC,KAAK,IAAI;AACnC;AAiBA,IAAM,IAAN,MAAyC;CAInB;CAArB,YAAY,GAAoB;EAAX,KAAA,SAAA;CAAY;CAQjC,QAAQ,GAAoB;EAC3B,OAAO,KAAK,OAAO,UAAU,CAAI,CAAC,CAAC;CACpC;CASA,aAAa,GAA6C;EACzD,OAAO,KAAK,OAAO,UAAU,CAAI;CAClC;CAUA,SAAS,GAAuB;EAC/B,IAAI;GACH,OAAO,KAAK,OAAO,MAAM,CAAI;EAC9B,SAAS,GAAO;GACf,MAAM,IAAI,EAAY,EAAmB,CAAmB,CAAC;EAC9D;CACD;CAiBA,aAAa,GAAW,GAA8B;EACrD,IAAM,IAAa,EAAU,CAAC,GAAM,KAAK,MAAM,CAAC;EAEhD,IAAI,iBAAiB,GAAY;GAChC,IAAM,IAAgB,OAAO,KAAK,EAAW,WAAW,CAAC,CAAC;GAE1D,MAAM,IAAI,EAAoB;IAC7B,QAAQ,EAAW;IACnB,aAAa,EAAW;IACxB,MAAM,EAAE,UAAU,EAAc;IAChC;GACD,CAAC;EACF;EAEA,OAAO,EAAW;CACnB;CAgBA,MAAM,kBAAkB,GAAW,GAAuC;EACzE,IAAM,IAAa,MAAM,EAAe,CAAC,GAAM,KAAK,MAAM,CAAC;EAE3D,IAAI,iBAAiB,GAAY;GAChC,IAAM,IAAgB,OAAO,KAAK,EAAW,WAAW,CAAC,CAAC;GAE1D,MAAM,IAAI,EAAoB;IAC7B,QAAQ,EAAW;IACnB,aAAa,EAAW;IACxB,MAAM,EAAE,UAAU,EAAc;IAChC;GACD,CAAC;EACF;EAEA,OAAO,EAAW;CACnB;AACD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { removeNonNumeric as e } from "@arkyn/shared";
|
|
2
|
+
//#region src/validations/validateCep.ts
|
|
3
|
+
function t(t) {
|
|
4
|
+
if (!(/^\d{5}-\d{3}$/.test(t) || /^\d{8}$/.test(t))) return !1;
|
|
5
|
+
let n = e(t), r = /^\d{8}$/.test(n);
|
|
6
|
+
return n.length === 8 && r;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as validateCep };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=validateCep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateCep.js","names":[],"sources":["../../../src/validations/validateCep.ts"],"sourcesContent":["import { removeNonNumeric } from \"@arkyn/shared\";\n\n/**\n * Validates a Brazilian CEP (postal code).\n *\n * A valid CEP must contain exactly 8 numeric digits,\n * optionally formatted as \"12345-678\".\n *\n * @param rawCep - CEP value, with or without formatting.\n * @returns `true` if the CEP is valid, otherwise `false`.\n *\n * @example\n * ```typescript\n * validateCep(\"12345-678\"); // true\n * validateCep(\"12345678\"); // true\n * validateCep(\"ABCDE-123\"); // false\n * ```\n */\n\nfunction validateCep(rawCep: string): boolean {\n\tconst validFormat = /^\\d{5}-\\d{3}$/.test(rawCep) || /^\\d{8}$/.test(rawCep);\n\tif (!validFormat) return false;\n\n\tconst cep = removeNonNumeric(rawCep);\n\n\tconst CEP_LENGTH = 8;\n\tconst isOnlyDigits = /^\\d{8}$/.test(cep);\n\n\treturn cep.length === CEP_LENGTH && isOnlyDigits;\n}\n\nexport { validateCep };\n"],"mappings":";;AAmBA,SAAS,EAAY,GAAyB;CAE7C,IAAI,EADgB,gBAAgB,KAAK,CAAM,KAAK,UAAU,KAAK,CAAM,IACvD,OAAO;CAEzB,IAAM,IAAM,EAAiB,CAAM,GAG7B,IAAe,UAAU,KAAK,CAAG;CAEvC,OAAO,EAAI,WAAW,KAAc;AACrC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { removeNonNumeric as e } from "@arkyn/shared";
|
|
2
|
+
//#region src/validations/validateCnpj.ts
|
|
3
|
+
function t(e) {
|
|
4
|
+
return e.length !== 14;
|
|
5
|
+
}
|
|
6
|
+
function n(e) {
|
|
7
|
+
let [t] = e;
|
|
8
|
+
return [...e].every((e) => e === t);
|
|
9
|
+
}
|
|
10
|
+
function r(e, t) {
|
|
11
|
+
let n = 0;
|
|
12
|
+
for (let r = 0; r < t.length; r++) n += parseInt(e[r], 10) * t[r];
|
|
13
|
+
let r = n % 11;
|
|
14
|
+
return r < 2 ? 0 : 11 - r;
|
|
15
|
+
}
|
|
16
|
+
function i(e) {
|
|
17
|
+
return e.slice(12);
|
|
18
|
+
}
|
|
19
|
+
function a(a) {
|
|
20
|
+
if (!a || a.length > 18 || a.length < 14 || /\s/.test(a)) return !1;
|
|
21
|
+
let o = e(a);
|
|
22
|
+
if (t(o) || n(o)) return !1;
|
|
23
|
+
let s = o.slice(0, 12), c = r(s, [
|
|
24
|
+
5,
|
|
25
|
+
4,
|
|
26
|
+
3,
|
|
27
|
+
2,
|
|
28
|
+
9,
|
|
29
|
+
8,
|
|
30
|
+
7,
|
|
31
|
+
6,
|
|
32
|
+
5,
|
|
33
|
+
4,
|
|
34
|
+
3,
|
|
35
|
+
2
|
|
36
|
+
]), l = r(s + c, [
|
|
37
|
+
6,
|
|
38
|
+
5,
|
|
39
|
+
4,
|
|
40
|
+
3,
|
|
41
|
+
2,
|
|
42
|
+
9,
|
|
43
|
+
8,
|
|
44
|
+
7,
|
|
45
|
+
6,
|
|
46
|
+
5,
|
|
47
|
+
4,
|
|
48
|
+
3,
|
|
49
|
+
2
|
|
50
|
+
]);
|
|
51
|
+
return i(o) === `${c}${l}`;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { a as validateCnpj };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=validateCnpj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateCnpj.js","names":[],"sources":["../../../src/validations/validateCnpj.ts"],"sourcesContent":["import { removeNonNumeric } from \"@arkyn/shared\";\n\nfunction isInvalidLength(cnpj: string) {\n\tconst CNPJ_LENGTH = 14;\n\treturn cnpj.length !== CNPJ_LENGTH;\n}\n\nfunction hasAllDigitsEqual(cnpj: string) {\n\tconst [firstDigit] = cnpj;\n\treturn [...cnpj].every((digit) => digit === firstDigit);\n}\n\nfunction calculateDigit(cnpj: string, multipliers: number[]) {\n\tlet total = 0;\n\tfor (let i = 0; i < multipliers.length; i++) {\n\t\ttotal += parseInt(cnpj[i], 10) * multipliers[i];\n\t}\n\tconst rest = total % 11;\n\treturn rest < 2 ? 0 : 11 - rest;\n}\n\nfunction extractDigit(cnpj: string) {\n\treturn cnpj.slice(12);\n}\n\n/**\n * Validates a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) number.\n *\n * This function performs:\n * - Sanitization (removes non-digit characters).\n * - Length check (must be 14 digits).\n * - Repeating digits check (invalid if all digits are the same).\n * - Verifies the two check digits with the proper weights.\n *\n * @param rawCnpj - CNPJ string, possibly formatted.\n * @returns `true` if valid, otherwise `false`.\n *\n * @example\n * ```typescript\n * validateCnpj(\"12.345.678/0001-95\"); // false\n * validateCnpj(\"11.444.777/0001-61\"); // true\n * ```\n */\n\nfunction validateCnpj(rawCnpj: string): boolean {\n\tif (!rawCnpj) return false;\n\tif (rawCnpj.length > 18) return false;\n\tif (rawCnpj.length < 14) return false;\n\n\tconst hasSpaces = /\\s/.test(rawCnpj);\n\tif (hasSpaces) return false;\n\n\tconst cnpj = removeNonNumeric(rawCnpj);\n\n\tif (isInvalidLength(cnpj)) return false;\n\tif (hasAllDigitsEqual(cnpj)) return false;\n\n\tconst base = cnpj.slice(0, 12);\n\tconst digit1 = calculateDigit(base, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]);\n\tconst digit2 = calculateDigit(\n\t\tbase + digit1,\n\t\t[6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2],\n\t);\n\n\treturn extractDigit(cnpj) === `${digit1}${digit2}`;\n}\n\nexport { validateCnpj };\n"],"mappings":";;AAEA,SAAS,EAAgB,GAAc;CAEtC,OAAO,EAAK,WAAW;AACxB;AAEA,SAAS,EAAkB,GAAc;CACxC,IAAM,CAAC,KAAc;CACrB,OAAO,CAAC,GAAG,CAAI,CAAC,CAAC,OAAO,MAAU,MAAU,CAAU;AACvD;AAEA,SAAS,EAAe,GAAc,GAAuB;CAC5D,IAAI,IAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,IAAI,EAAY,QAAQ,KACvC,KAAS,SAAS,EAAK,IAAI,EAAE,IAAI,EAAY;CAE9C,IAAM,IAAO,IAAQ;CACrB,OAAO,IAAO,IAAI,IAAI,KAAK;AAC5B;AAEA,SAAS,EAAa,GAAc;CACnC,OAAO,EAAK,MAAM,EAAE;AACrB;AAqBA,SAAS,EAAa,GAA0B;CAM/C,IALI,CAAC,KACD,EAAQ,SAAS,MACjB,EAAQ,SAAS,MAEH,KAAK,KAAK,CACxB,GAAW,OAAO;CAEtB,IAAM,IAAO,EAAiB,CAAO;CAGrC,IADI,EAAgB,CAAI,KACpB,EAAkB,CAAI,GAAG,OAAO;CAEpC,IAAM,IAAO,EAAK,MAAM,GAAG,EAAE,GACvB,IAAS,EAAe,GAAM;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC,CAAC,GAClE,IAAS,EACd,IAAO,GACP;EAAC;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;EAAG;CAAC,CACvC;CAEA,OAAO,EAAa,CAAI,MAAM,GAAG,IAAS;AAC3C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { removeNonNumeric as e } from "@arkyn/shared";
|
|
2
|
+
//#region src/validations/validateCpf.ts
|
|
3
|
+
function t(e) {
|
|
4
|
+
return e.length !== 11;
|
|
5
|
+
}
|
|
6
|
+
function n(e) {
|
|
7
|
+
let [t] = e;
|
|
8
|
+
return [...e].every((e) => e === t);
|
|
9
|
+
}
|
|
10
|
+
function r(e, t) {
|
|
11
|
+
let n = 0;
|
|
12
|
+
for (let r of e) t > 1 && (n += parseInt(r, 10) * t--);
|
|
13
|
+
let r = n % 11;
|
|
14
|
+
return r < 2 ? 0 : 11 - r;
|
|
15
|
+
}
|
|
16
|
+
function i(e) {
|
|
17
|
+
return e.slice(9);
|
|
18
|
+
}
|
|
19
|
+
function a(a) {
|
|
20
|
+
if (!a || a.length > 14 || a.length < 11 || /\s/.test(a)) return !1;
|
|
21
|
+
let o = e(a);
|
|
22
|
+
if (t(o) || n(o)) return !1;
|
|
23
|
+
let s = r(o, 10), c = r(o, 11);
|
|
24
|
+
return i(o) === `${s}${c}`;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { a as validateCpf };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=validateCpf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateCpf.js","names":[],"sources":["../../../src/validations/validateCpf.ts"],"sourcesContent":["import { removeNonNumeric } from \"@arkyn/shared\";\n\nfunction isInvalidLength(cpf: string) {\n\tconst CPF_LENGTH = 11;\n\treturn cpf.length !== CPF_LENGTH;\n}\n\nfunction hasAllDigitsEqual(cpf: string) {\n\tconst [firstCpfDigit] = cpf;\n\treturn [...cpf].every((digit) => digit === firstCpfDigit);\n}\n\nfunction calculateDigit(cpf: string, factor: number) {\n\tlet total = 0;\n\tfor (const digit of cpf) {\n\t\tif (factor > 1) total += parseInt(digit, 10) * factor--;\n\t}\n\tconst rest = total % 11;\n\treturn rest < 2 ? 0 : 11 - rest;\n}\n\nfunction extractDigit(cpf: string) {\n\treturn cpf.slice(9);\n}\n\n/**\n * Validates a Brazilian CPF number. Strips formatting, checks length, rejects\n * repeated-digit sequences, and verifies both check digits with the CPF algorithm.\n *\n * @param rawCpf - CPF string, with or without formatting (dots and dashes).\n * @returns `true` if the CPF is valid, otherwise `false`.\n *\n * @example\n * ```typescript\n * validateCpf(\"123.456.789-09\"); // false\n * validateCpf(\"111.444.777-35\"); // true\n * ```\n */\n\nfunction validateCpf(rawCpf: string): boolean {\n\tif (!rawCpf) return false;\n\tif (rawCpf.length > 14) return false;\n\tif (rawCpf.length < 11) return false;\n\n\tconst hasSpaces = /\\s/.test(rawCpf);\n\tif (hasSpaces) return false;\n\n\tconst cpf = removeNonNumeric(rawCpf);\n\n\tif (isInvalidLength(cpf)) return false;\n\tif (hasAllDigitsEqual(cpf)) return false;\n\n\tconst digit1 = calculateDigit(cpf, 10);\n\tconst digit2 = calculateDigit(cpf, 11);\n\n\treturn extractDigit(cpf) === `${digit1}${digit2}`;\n}\n\nexport { validateCpf };\n"],"mappings":";;AAEA,SAAS,EAAgB,GAAa;CAErC,OAAO,EAAI,WAAW;AACvB;AAEA,SAAS,EAAkB,GAAa;CACvC,IAAM,CAAC,KAAiB;CACxB,OAAO,CAAC,GAAG,CAAG,CAAC,CAAC,OAAO,MAAU,MAAU,CAAa;AACzD;AAEA,SAAS,EAAe,GAAa,GAAgB;CACpD,IAAI,IAAQ;CACZ,KAAK,IAAM,KAAS,GACnB,AAAI,IAAS,MAAG,KAAS,SAAS,GAAO,EAAE,IAAI;CAEhD,IAAM,IAAO,IAAQ;CACrB,OAAO,IAAO,IAAI,IAAI,KAAK;AAC5B;AAEA,SAAS,EAAa,GAAa;CAClC,OAAO,EAAI,MAAM,CAAC;AACnB;AAgBA,SAAS,EAAY,GAAyB;CAM7C,IALI,CAAC,KACD,EAAO,SAAS,MAChB,EAAO,SAAS,MAEF,KAAK,KAAK,CACxB,GAAW,OAAO;CAEtB,IAAM,IAAM,EAAiB,CAAM;CAGnC,IADI,EAAgB,CAAG,KACnB,EAAkB,CAAG,GAAG,OAAO;CAEnC,IAAM,IAAS,EAAe,GAAK,EAAE,GAC/B,IAAS,EAAe,GAAK,EAAE;CAErC,OAAO,EAAa,CAAG,MAAM,GAAG,IAAS;AAC1C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ValidateDateService as e } from "@arkyn/shared";
|
|
2
|
+
//#region src/validations/validateDate.ts
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
let r = n?.inputFormat || "brazilianDate", i = n?.minYear || 1900, a = n?.maxYear || 3e3, o = new e();
|
|
5
|
+
o.validateInputFormat(r);
|
|
6
|
+
let s, c, l, u = t.split(/[-/]/).map(Number);
|
|
7
|
+
if (u.length !== 3) return !1;
|
|
8
|
+
try {
|
|
9
|
+
switch (r) {
|
|
10
|
+
case "brazilianDate":
|
|
11
|
+
[s, c, l] = u, o.validateDateParts(l, c, s);
|
|
12
|
+
break;
|
|
13
|
+
case "isoDate":
|
|
14
|
+
[c, s, l] = u, o.validateDateParts(l, c, s);
|
|
15
|
+
break;
|
|
16
|
+
case "timestamp":
|
|
17
|
+
[l, c, s] = u, o.validateDateParts(l, c, s);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
return !(l < i || l > a);
|
|
21
|
+
} catch {
|
|
22
|
+
return !1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { t as validateDate };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=validateDate.js.map
|