@arkyn/server 3.0.7 → 3.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +200 -0
- package/dist/http/api/_logRequest.d.ts.map +1 -1
- package/dist/index.js +200 -146
- package/dist/index.js.map +1 -1
- package/dist/modules/http/api/_logRequest.js +31 -28
- package/dist/modules/http/api/_logRequest.js.map +1 -1
- package/dist/modules/services/apiService.js +35 -23
- package/dist/modules/services/apiService.js.map +1 -1
- package/dist/modules/services/logService.js +29 -11
- package/dist/modules/services/logService.js.map +1 -1
- package/dist/modules/utilities/sensitiveDataKeys.js +31 -0
- package/dist/modules/utilities/sensitiveDataKeys.js.map +1 -0
- package/dist/services/apiService.d.ts +12 -0
- package/dist/services/apiService.d.ts.map +1 -1
- package/dist/services/logService.d.ts +15 -2
- package/dist/services/logService.d.ts.map +1 -1
- package/dist/utilities/sensitiveDataKeys.d.ts +22 -0
- package/dist/utilities/sensitiveDataKeys.d.ts.map +1 -0
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ValidateDateService as e, formatJsonObject as t, formatJsonString as n,
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { countries as
|
|
5
|
-
import { isValidPhoneNumber as
|
|
1
|
+
import { ValidateDateService as e, formatJsonObject as t, formatJsonString as n, parseSensitiveData as r, removeNonNumeric as i } from "@arkyn/shared";
|
|
2
|
+
import a from "node:path";
|
|
3
|
+
import o from "node:dns";
|
|
4
|
+
import { countries as s } from "@arkyn/templates";
|
|
5
|
+
import { isValidPhoneNumber as c, parsePhoneNumberWithError as l } from "libphonenumber-js";
|
|
6
6
|
//#region src/services/debugService.ts
|
|
7
|
-
var
|
|
7
|
+
var u = class e {
|
|
8
8
|
static ignoreFiles = [];
|
|
9
9
|
static setIgnoreFile(t) {
|
|
10
10
|
e.ignoreFiles.push(t);
|
|
@@ -16,10 +16,10 @@ var l = class e {
|
|
|
16
16
|
let t = process.cwd(), n = ((/* @__PURE__ */ Error()).stack || "").split("\n").map((e) => e.trim()), r = 2;
|
|
17
17
|
for (; r < n.length && (n[r].includes("node:internal") || n[r].includes("/node_modules/"));) r++;
|
|
18
18
|
if (e.ignoreFiles.length > 0) for (; r < n.length && e.ignoreFiles.some((e) => n[r].includes(e));) r++;
|
|
19
|
-
let
|
|
19
|
+
let i = n[r] || "", o = "Unknown function", s = "Unknown caller", c = i.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
|
|
20
20
|
if (c) o = c[1], s = c[2];
|
|
21
21
|
else {
|
|
22
|
-
let e =
|
|
22
|
+
let e = i.match(/at\s+(.+)/);
|
|
23
23
|
if (e) {
|
|
24
24
|
s = e[1];
|
|
25
25
|
let t = s.match(/at\s+([^(\s]+)\s+/);
|
|
@@ -28,7 +28,7 @@ var l = class e {
|
|
|
28
28
|
}
|
|
29
29
|
s.includes("(") && (s = s.substring(s.indexOf("(") + 1, s.lastIndexOf(")"))), s = s.split(":").slice(0, -2).join(":");
|
|
30
30
|
try {
|
|
31
|
-
s =
|
|
31
|
+
s = a.relative(t, s);
|
|
32
32
|
} catch {}
|
|
33
33
|
return {
|
|
34
34
|
functionName: o,
|
|
@@ -38,7 +38,7 @@ var l = class e {
|
|
|
38
38
|
};
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region src/utilities/flushDebugLogs.ts
|
|
41
|
-
function
|
|
41
|
+
function d(e) {
|
|
42
42
|
if (process.env.NODE_ENV === "development" || process.env?.DEBUG_MODE === "true") {
|
|
43
43
|
let t = `${{
|
|
44
44
|
yellow: "\x1B[33m",
|
|
@@ -53,7 +53,7 @@ function u(e) {
|
|
|
53
53
|
}
|
|
54
54
|
//#endregion
|
|
55
55
|
//#region src/http/badResponses/_badResponse.ts
|
|
56
|
-
var
|
|
56
|
+
var f = class {
|
|
57
57
|
_cause;
|
|
58
58
|
_name = "BadResponse";
|
|
59
59
|
_status = 500;
|
|
@@ -95,8 +95,8 @@ var d = class {
|
|
|
95
95
|
].includes(e) && (this._debugColor = e);
|
|
96
96
|
}
|
|
97
97
|
onDebug() {
|
|
98
|
-
let e = [], { callerInfo: t, functionName: r } =
|
|
99
|
-
e.push(`Caller Function: ${r}`), e.push(`Caller Location: ${t}`), this._statusText && e.push(`Message: ${this._statusText}`), this._cause && e.push(`Cause: ${n(JSON.stringify(this._cause))}`),
|
|
98
|
+
let e = [], { callerInfo: t, functionName: r } = u.getCaller();
|
|
99
|
+
e.push(`Caller Function: ${r}`), e.push(`Caller Location: ${t}`), this._statusText && e.push(`Message: ${this._statusText}`), this._cause && e.push(`Cause: ${n(JSON.stringify(this._cause))}`), d({
|
|
100
100
|
scheme: "red",
|
|
101
101
|
name: this._name,
|
|
102
102
|
debugs: e
|
|
@@ -109,7 +109,7 @@ var d = class {
|
|
|
109
109
|
cause: this._cause
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
},
|
|
112
|
+
}, p = class extends f {
|
|
113
113
|
constructor(e, t) {
|
|
114
114
|
super(), this.name = "BadGateway", this.status = 502, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
115
115
|
}
|
|
@@ -128,7 +128,7 @@ var d = class {
|
|
|
128
128
|
};
|
|
129
129
|
return Response.json(this.makeBody(), e);
|
|
130
130
|
}
|
|
131
|
-
},
|
|
131
|
+
}, m = class extends f {
|
|
132
132
|
constructor(e, t) {
|
|
133
133
|
super(), this.name = "BadRequest", this.status = 400, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
134
134
|
}
|
|
@@ -147,7 +147,7 @@ var d = class {
|
|
|
147
147
|
};
|
|
148
148
|
return Response.json(this.makeBody(), e);
|
|
149
149
|
}
|
|
150
|
-
},
|
|
150
|
+
}, h = class extends f {
|
|
151
151
|
constructor(e, t) {
|
|
152
152
|
super(), this.name = "Conflict", this.status = 409, this.statusText = e, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
153
153
|
}
|
|
@@ -166,7 +166,7 @@ var d = class {
|
|
|
166
166
|
};
|
|
167
167
|
return Response.json(this.makeBody(), e);
|
|
168
168
|
}
|
|
169
|
-
},
|
|
169
|
+
}, g = class extends f {
|
|
170
170
|
constructor(e, t) {
|
|
171
171
|
super(), this.name = "Forbidden", this.status = 403, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
172
172
|
}
|
|
@@ -185,7 +185,7 @@ var d = class {
|
|
|
185
185
|
};
|
|
186
186
|
return Response.json(this.makeBody(), e);
|
|
187
187
|
}
|
|
188
|
-
},
|
|
188
|
+
}, _ = class extends f {
|
|
189
189
|
constructor(e, t) {
|
|
190
190
|
super(), this.name = "NotFound", this.status = 404, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
191
191
|
}
|
|
@@ -204,7 +204,7 @@ var d = class {
|
|
|
204
204
|
};
|
|
205
205
|
return Response.json(this.makeBody(), e);
|
|
206
206
|
}
|
|
207
|
-
},
|
|
207
|
+
}, v = class extends f {
|
|
208
208
|
constructor(e, t) {
|
|
209
209
|
super(), this.name = "NotImplemented", this.status = 501, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
210
210
|
}
|
|
@@ -223,7 +223,7 @@ var d = class {
|
|
|
223
223
|
};
|
|
224
224
|
return Response.json(this.makeBody(), e);
|
|
225
225
|
}
|
|
226
|
-
},
|
|
226
|
+
}, y = class extends f {
|
|
227
227
|
constructor(e, t) {
|
|
228
228
|
super(), this.name = "ServerError", this.status = 500, this.statusText = e, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
229
229
|
}
|
|
@@ -242,7 +242,7 @@ var d = class {
|
|
|
242
242
|
};
|
|
243
243
|
return Response.json(this.makeBody(), e);
|
|
244
244
|
}
|
|
245
|
-
},
|
|
245
|
+
}, b = class extends f {
|
|
246
246
|
constructor(e, t) {
|
|
247
247
|
super(), this.name = "Unauthorized", this.status = 401, this.statusText = e, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
248
248
|
}
|
|
@@ -261,7 +261,7 @@ var d = class {
|
|
|
261
261
|
};
|
|
262
262
|
return Response.json(this.makeBody(), e);
|
|
263
263
|
}
|
|
264
|
-
},
|
|
264
|
+
}, x = class extends f {
|
|
265
265
|
constructor(e) {
|
|
266
266
|
super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = e.message || "Unprocessable entity", this.debugColor = "yellow", this.cause = {
|
|
267
267
|
data: e.data,
|
|
@@ -284,7 +284,7 @@ var d = class {
|
|
|
284
284
|
};
|
|
285
285
|
return Response.json(this.makeBody(), e);
|
|
286
286
|
}
|
|
287
|
-
},
|
|
287
|
+
}, S = class {
|
|
288
288
|
_body = null;
|
|
289
289
|
_name = "SuccessResponse";
|
|
290
290
|
_status = 200;
|
|
@@ -326,8 +326,8 @@ var d = class {
|
|
|
326
326
|
].includes(e) && (this._debugColor = e);
|
|
327
327
|
}
|
|
328
328
|
onDebug(e) {
|
|
329
|
-
let t = [], { callerInfo: n, functionName: r } =
|
|
330
|
-
t.push(`Caller Function: ${r}`), t.push(`Caller Location: ${n}`), this.statusText && t.push(`Message: ${this.statusText}`), e && t.push(`Body: ${JSON.stringify(e)}`),
|
|
329
|
+
let t = [], { callerInfo: n, functionName: r } = u.getCaller();
|
|
330
|
+
t.push(`Caller Function: ${r}`), t.push(`Caller Location: ${n}`), this.statusText && t.push(`Message: ${this.statusText}`), e && t.push(`Body: ${JSON.stringify(e)}`), d({
|
|
331
331
|
scheme: this._debugColor,
|
|
332
332
|
name: this.name,
|
|
333
333
|
debugs: t
|
|
@@ -340,7 +340,7 @@ var d = class {
|
|
|
340
340
|
body: this.body
|
|
341
341
|
};
|
|
342
342
|
}
|
|
343
|
-
},
|
|
343
|
+
}, C = class extends S {
|
|
344
344
|
constructor(e, t) {
|
|
345
345
|
super(), this.name = "Created", this.status = 201, this.statusText = e, this.body = t || void 0, this.onDebug();
|
|
346
346
|
}
|
|
@@ -359,7 +359,7 @@ var d = class {
|
|
|
359
359
|
};
|
|
360
360
|
return Response.json(this.body, e);
|
|
361
361
|
}
|
|
362
|
-
},
|
|
362
|
+
}, w = class extends S {
|
|
363
363
|
constructor(e, t) {
|
|
364
364
|
super(), this.name = "Found", this.status = 302, this.statusText = e, this.body = t || void 0, this.onDebug();
|
|
365
365
|
}
|
|
@@ -378,7 +378,7 @@ var d = class {
|
|
|
378
378
|
};
|
|
379
379
|
return Response.json(this.body, e);
|
|
380
380
|
}
|
|
381
|
-
},
|
|
381
|
+
}, T = class extends S {
|
|
382
382
|
constructor(e) {
|
|
383
383
|
super(), this.name = "NoContent", this.status = 204, this.statusText = e, this.onDebug();
|
|
384
384
|
}
|
|
@@ -390,7 +390,7 @@ var d = class {
|
|
|
390
390
|
};
|
|
391
391
|
return new Response(null, e);
|
|
392
392
|
}
|
|
393
|
-
},
|
|
393
|
+
}, E = class extends S {
|
|
394
394
|
constructor(e, t) {
|
|
395
395
|
super(), this.name = "Success", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
|
|
396
396
|
}
|
|
@@ -409,7 +409,7 @@ var d = class {
|
|
|
409
409
|
};
|
|
410
410
|
return Response.json(this.body, e);
|
|
411
411
|
}
|
|
412
|
-
},
|
|
412
|
+
}, D = class extends S {
|
|
413
413
|
constructor(e, t) {
|
|
414
414
|
super(), this.name = "Updated", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
|
|
415
415
|
}
|
|
@@ -428,7 +428,7 @@ var d = class {
|
|
|
428
428
|
};
|
|
429
429
|
return Response.json(this.body, e);
|
|
430
430
|
}
|
|
431
|
-
},
|
|
431
|
+
}, O = class e {
|
|
432
432
|
static mapHeaders(e) {
|
|
433
433
|
return e instanceof Headers ? Object.fromEntries(e.entries()) : typeof e == "object" ? Object.entries(e).reduce((e, [t, n]) => (typeof n == "string" ? e[t] = n : Array.isArray(n) ? e[t] = n.join(", ") : e[t] = JSON.stringify(n), e), {}) : {};
|
|
434
434
|
}
|
|
@@ -455,15 +455,32 @@ var d = class {
|
|
|
455
455
|
responseBody: t.responseBody || null
|
|
456
456
|
};
|
|
457
457
|
}
|
|
458
|
-
},
|
|
458
|
+
}, k = class e {
|
|
459
459
|
static config;
|
|
460
|
+
static isSecureEndpoint(e) {
|
|
461
|
+
return e.protocol === "https:" ? !0 : e.hostname === "localhost" || e.hostname === "127.0.0.1";
|
|
462
|
+
}
|
|
460
463
|
static setConfig(t) {
|
|
461
464
|
if (e.config) return;
|
|
462
|
-
let { trafficSourceId: n, userToken: r, logBaseApiUrl: i } = t;
|
|
465
|
+
let { trafficSourceId: n, userToken: r, logBaseApiUrl: i } = t, a = null;
|
|
466
|
+
if (i) try {
|
|
467
|
+
let t = new URL(i);
|
|
468
|
+
e.isSecureEndpoint(t) ? a = `${i}/ingest-log` : d({
|
|
469
|
+
name: "LogServiceError",
|
|
470
|
+
scheme: "red",
|
|
471
|
+
debugs: [`Insecure logBaseApiUrl "${i}" rejected: use https://, or http:// only for localhost/127.0.0.1. Remote logging disabled.`]
|
|
472
|
+
});
|
|
473
|
+
} catch {
|
|
474
|
+
d({
|
|
475
|
+
name: "LogServiceError",
|
|
476
|
+
scheme: "red",
|
|
477
|
+
debugs: [`Invalid logBaseApiUrl "${i}". Remote logging disabled.`]
|
|
478
|
+
});
|
|
479
|
+
}
|
|
463
480
|
e.config = {
|
|
464
481
|
trafficSourceId: n,
|
|
465
482
|
userToken: r,
|
|
466
|
-
apiUrl:
|
|
483
|
+
apiUrl: a
|
|
467
484
|
};
|
|
468
485
|
}
|
|
469
486
|
static getConfig() {
|
|
@@ -472,41 +489,68 @@ var d = class {
|
|
|
472
489
|
static resetConfig() {
|
|
473
490
|
e.config = void 0;
|
|
474
491
|
}
|
|
475
|
-
}
|
|
492
|
+
}, A = [
|
|
493
|
+
"password",
|
|
494
|
+
"Password",
|
|
495
|
+
"confirmPassword",
|
|
496
|
+
"ConfirmPassword",
|
|
497
|
+
"creditCard",
|
|
498
|
+
"CreditCard",
|
|
499
|
+
"authorization",
|
|
500
|
+
"Authorization",
|
|
501
|
+
"cookie",
|
|
502
|
+
"Cookie",
|
|
503
|
+
"set-cookie",
|
|
504
|
+
"Set-Cookie",
|
|
505
|
+
"setCookie",
|
|
506
|
+
"SetCookie",
|
|
507
|
+
"token",
|
|
508
|
+
"Token",
|
|
509
|
+
"refreshToken",
|
|
510
|
+
"RefreshToken",
|
|
511
|
+
"accessToken",
|
|
512
|
+
"AccessToken",
|
|
513
|
+
"apiKey",
|
|
514
|
+
"ApiKey",
|
|
515
|
+
"secret",
|
|
516
|
+
"Secret"
|
|
517
|
+
];
|
|
476
518
|
//#endregion
|
|
477
519
|
//#region src/http/api/_logRequest.ts
|
|
478
|
-
async function
|
|
479
|
-
let n =
|
|
520
|
+
async function j(e) {
|
|
521
|
+
let n = k.getConfig();
|
|
480
522
|
if (!n) return;
|
|
481
|
-
let { userToken:
|
|
523
|
+
let { userToken: i, apiUrl: a, trafficSourceId: o } = n;
|
|
524
|
+
if (!a) return;
|
|
525
|
+
let { elapsedTime: s, method: c, queryParams: l, requestBody: u, requestHeaders: f, responseBody: p, responseHeaders: m, status: h, rawUrl: g } = e;
|
|
482
526
|
if (process.env.NODE_ENV !== "development") try {
|
|
483
|
-
let e = new URL(
|
|
527
|
+
let e = new URL(g), n = "https";
|
|
484
528
|
e.protocol === "http:" && (n = "http");
|
|
485
|
-
let
|
|
529
|
+
let _ = JSON.stringify({
|
|
486
530
|
domainUrl: `${e.protocol}//${e.host}`,
|
|
487
531
|
pathnameUrl: e.pathname,
|
|
488
|
-
trafficSourceId:
|
|
489
|
-
status:
|
|
532
|
+
trafficSourceId: o,
|
|
533
|
+
status: h,
|
|
490
534
|
protocol: n,
|
|
491
|
-
method:
|
|
535
|
+
method: c.toLowerCase(),
|
|
492
536
|
trafficUserId: null,
|
|
493
|
-
elapsedTime:
|
|
494
|
-
requestHeaders: JSON.stringify(
|
|
495
|
-
requestBody: JSON.stringify(
|
|
496
|
-
queryParams: JSON.stringify(
|
|
497
|
-
responseHeaders: JSON.stringify(
|
|
498
|
-
responseBody: JSON.stringify(
|
|
499
|
-
}),
|
|
537
|
+
elapsedTime: s,
|
|
538
|
+
requestHeaders: r(JSON.stringify(f), [...A]),
|
|
539
|
+
requestBody: r(JSON.stringify(u), [...A]),
|
|
540
|
+
queryParams: JSON.stringify(l),
|
|
541
|
+
responseHeaders: r(JSON.stringify(m), [...A]),
|
|
542
|
+
responseBody: r(JSON.stringify(p), [...A])
|
|
543
|
+
}), v = {
|
|
500
544
|
"Content-Type": "application/json",
|
|
501
|
-
Authorization: `Bearer ${
|
|
502
|
-
},
|
|
545
|
+
Authorization: `Bearer ${i}`
|
|
546
|
+
}, y = await fetch(a, {
|
|
503
547
|
method: "POST",
|
|
504
|
-
body:
|
|
505
|
-
headers:
|
|
548
|
+
body: _,
|
|
549
|
+
headers: v
|
|
506
550
|
});
|
|
507
|
-
if (!
|
|
508
|
-
let e = await
|
|
509
|
-
|
|
551
|
+
if (!y.ok) {
|
|
552
|
+
let e = await y.text(), n = y.status, r = y.statusText, i = await y.json().catch(() => null);
|
|
553
|
+
d({
|
|
510
554
|
name: "LogError",
|
|
511
555
|
scheme: "red",
|
|
512
556
|
debugs: [
|
|
@@ -518,7 +562,7 @@ async function k(e) {
|
|
|
518
562
|
});
|
|
519
563
|
}
|
|
520
564
|
} catch (e) {
|
|
521
|
-
|
|
565
|
+
d({
|
|
522
566
|
debugs: [`Error sending request: ${e}`],
|
|
523
567
|
name: "LogError",
|
|
524
568
|
scheme: "red"
|
|
@@ -527,7 +571,7 @@ async function k(e) {
|
|
|
527
571
|
}
|
|
528
572
|
//#endregion
|
|
529
573
|
//#region src/http/api/_makeRequest.ts
|
|
530
|
-
async function
|
|
574
|
+
async function M(e) {
|
|
531
575
|
let t = e.url;
|
|
532
576
|
e.urlParams && Object.entries(e.urlParams).forEach(([e, n]) => {
|
|
533
577
|
t = t.replaceAll(`:${e}`, n);
|
|
@@ -553,7 +597,7 @@ async function A(e) {
|
|
|
553
597
|
} catch {
|
|
554
598
|
c = null;
|
|
555
599
|
}
|
|
556
|
-
return
|
|
600
|
+
return j(O.handle({
|
|
557
601
|
elapsedTime: o,
|
|
558
602
|
method: e.method,
|
|
559
603
|
queryParams: new URL(t).searchParams,
|
|
@@ -578,7 +622,7 @@ async function A(e) {
|
|
|
578
622
|
cause: null
|
|
579
623
|
};
|
|
580
624
|
} catch (e) {
|
|
581
|
-
return
|
|
625
|
+
return d({
|
|
582
626
|
debugs: [`Network error or request failed: ${e}`],
|
|
583
627
|
name: "MakeRequestError",
|
|
584
628
|
scheme: "red"
|
|
@@ -593,8 +637,8 @@ async function A(e) {
|
|
|
593
637
|
}
|
|
594
638
|
//#endregion
|
|
595
639
|
//#region src/http/api/_deleteRequest.ts
|
|
596
|
-
async function
|
|
597
|
-
return
|
|
640
|
+
async function N(e) {
|
|
641
|
+
return M({
|
|
598
642
|
method: "DELETE",
|
|
599
643
|
url: e.url,
|
|
600
644
|
urlParams: e.urlParams,
|
|
@@ -604,8 +648,8 @@ async function j(e) {
|
|
|
604
648
|
}
|
|
605
649
|
//#endregion
|
|
606
650
|
//#region src/http/api/_getRequest.ts
|
|
607
|
-
async function
|
|
608
|
-
return
|
|
651
|
+
async function ee(e) {
|
|
652
|
+
return M({
|
|
609
653
|
method: "GET",
|
|
610
654
|
url: e.url,
|
|
611
655
|
urlParams: e.urlParams,
|
|
@@ -614,8 +658,8 @@ async function M(e) {
|
|
|
614
658
|
}
|
|
615
659
|
//#endregion
|
|
616
660
|
//#region src/http/api/_patchRequest.ts
|
|
617
|
-
async function
|
|
618
|
-
return
|
|
661
|
+
async function te(e) {
|
|
662
|
+
return M({
|
|
619
663
|
method: "PATCH",
|
|
620
664
|
url: e.url,
|
|
621
665
|
urlParams: e.urlParams,
|
|
@@ -625,8 +669,8 @@ async function ee(e) {
|
|
|
625
669
|
}
|
|
626
670
|
//#endregion
|
|
627
671
|
//#region src/http/api/_postRequest.ts
|
|
628
|
-
async function
|
|
629
|
-
return
|
|
672
|
+
async function P(e) {
|
|
673
|
+
return M({
|
|
630
674
|
method: "POST",
|
|
631
675
|
url: e.url,
|
|
632
676
|
urlParams: e.urlParams,
|
|
@@ -636,8 +680,8 @@ async function N(e) {
|
|
|
636
680
|
}
|
|
637
681
|
//#endregion
|
|
638
682
|
//#region src/http/api/_putRequest.ts
|
|
639
|
-
async function
|
|
640
|
-
return
|
|
683
|
+
async function F(e) {
|
|
684
|
+
return M({
|
|
641
685
|
method: "PUT",
|
|
642
686
|
url: e.url,
|
|
643
687
|
urlParams: e.urlParams,
|
|
@@ -647,7 +691,7 @@ async function P(e) {
|
|
|
647
691
|
}
|
|
648
692
|
//#endregion
|
|
649
693
|
//#region src/services/apiService.ts
|
|
650
|
-
var
|
|
694
|
+
var I = class e {
|
|
651
695
|
baseUrl;
|
|
652
696
|
baseHeaders;
|
|
653
697
|
baseToken;
|
|
@@ -655,11 +699,21 @@ var F = class {
|
|
|
655
699
|
constructor(e) {
|
|
656
700
|
this.baseUrl = e.baseUrl, this.baseHeaders = e.baseHeaders || void 0, this.baseToken = e.baseToken || void 0, this.enableDebug = e.enableDebug || !1;
|
|
657
701
|
}
|
|
658
|
-
|
|
702
|
+
static toPlainHeaders(e) {
|
|
703
|
+
return e instanceof Headers ? Object.fromEntries(e.entries()) : Object.fromEntries(new Headers(e).entries());
|
|
704
|
+
}
|
|
705
|
+
static toRedactedJson(e) {
|
|
706
|
+
return r(JSON.stringify(e), [...A]);
|
|
707
|
+
}
|
|
708
|
+
onDebug(t, n, r) {
|
|
659
709
|
if (this.enableDebug) {
|
|
660
|
-
let
|
|
661
|
-
|
|
662
|
-
|
|
710
|
+
let i = [];
|
|
711
|
+
if (i.push(`Base URL: ${this.baseUrl}`), i.push(`Endpoint: ${t}`), i.push(`Status/Method: ${n} => ${r.status}`), i.push(`Message: ${r.message}`), r.headers) {
|
|
712
|
+
let t = e.toPlainHeaders(r.headers);
|
|
713
|
+
i.push(`Headers: ${e.toRedactedJson(t)}`);
|
|
714
|
+
}
|
|
715
|
+
r.body && i.push(`Body: ${e.toRedactedJson(r.body)}`), d({
|
|
716
|
+
debugs: i,
|
|
663
717
|
name: "ApiDebug",
|
|
664
718
|
scheme: "yellow"
|
|
665
719
|
});
|
|
@@ -679,7 +733,7 @@ var F = class {
|
|
|
679
733
|
}), n;
|
|
680
734
|
}
|
|
681
735
|
async get(e, t) {
|
|
682
|
-
let n = this.generateHeaders(t?.headers || {}, t?.token), r = await
|
|
736
|
+
let n = this.generateHeaders(t?.headers || {}, t?.token), r = await ee({
|
|
683
737
|
url: this.baseUrl + e,
|
|
684
738
|
urlParams: t?.urlParams || {},
|
|
685
739
|
headers: n
|
|
@@ -691,7 +745,7 @@ var F = class {
|
|
|
691
745
|
}), r;
|
|
692
746
|
}
|
|
693
747
|
async post(e, t) {
|
|
694
|
-
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await
|
|
748
|
+
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await P({
|
|
695
749
|
url: this.baseUrl + e,
|
|
696
750
|
urlParams: t?.urlParams || {},
|
|
697
751
|
headers: n,
|
|
@@ -705,7 +759,7 @@ var F = class {
|
|
|
705
759
|
}), i;
|
|
706
760
|
}
|
|
707
761
|
async put(e, t) {
|
|
708
|
-
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await
|
|
762
|
+
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await F({
|
|
709
763
|
url: this.baseUrl + e,
|
|
710
764
|
urlParams: t?.urlParams || {},
|
|
711
765
|
headers: n,
|
|
@@ -719,7 +773,7 @@ var F = class {
|
|
|
719
773
|
}), i;
|
|
720
774
|
}
|
|
721
775
|
async patch(e, t) {
|
|
722
|
-
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await
|
|
776
|
+
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await te({
|
|
723
777
|
url: this.baseUrl + e,
|
|
724
778
|
urlParams: t?.urlParams || {},
|
|
725
779
|
headers: n,
|
|
@@ -733,7 +787,7 @@ var F = class {
|
|
|
733
787
|
}), i;
|
|
734
788
|
}
|
|
735
789
|
async delete(e, t) {
|
|
736
|
-
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await
|
|
790
|
+
let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await N({
|
|
737
791
|
url: this.baseUrl + e,
|
|
738
792
|
urlParams: t?.urlParams || {},
|
|
739
793
|
headers: n,
|
|
@@ -749,7 +803,7 @@ var F = class {
|
|
|
749
803
|
};
|
|
750
804
|
//#endregion
|
|
751
805
|
//#region src/utilities/decodeRequestBody.ts
|
|
752
|
-
async function
|
|
806
|
+
async function L(e) {
|
|
753
807
|
let t, n = await e.arrayBuffer(), r = new TextDecoder().decode(n);
|
|
754
808
|
try {
|
|
755
809
|
t = JSON.parse(r);
|
|
@@ -758,31 +812,30 @@ async function I(e) {
|
|
|
758
812
|
if (r.includes("=")) {
|
|
759
813
|
let e = new URLSearchParams(r);
|
|
760
814
|
t = Object.fromEntries(e.entries());
|
|
761
|
-
} else throw new
|
|
815
|
+
} else throw new m("Invalid URLSearchParams format");
|
|
762
816
|
} catch {
|
|
763
|
-
throw new
|
|
817
|
+
throw new m("Failed to extract data from request");
|
|
764
818
|
}
|
|
765
819
|
}
|
|
766
820
|
return t;
|
|
767
821
|
}
|
|
768
822
|
//#endregion
|
|
769
823
|
//#region src/utilities/decodeRequestErrorMessage.ts
|
|
770
|
-
function
|
|
824
|
+
function R(e, t) {
|
|
771
825
|
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";
|
|
772
826
|
}
|
|
773
827
|
//#endregion
|
|
774
828
|
//#region src/utilities/errorHandler.ts
|
|
775
|
-
function
|
|
829
|
+
function z(e) {
|
|
776
830
|
switch (!0) {
|
|
777
831
|
case e instanceof Response: return e;
|
|
832
|
+
case e instanceof w: return e.toResponse();
|
|
778
833
|
case e instanceof C: return e.toResponse();
|
|
779
|
-
case e instanceof
|
|
834
|
+
case e instanceof D: return e.toResponse();
|
|
780
835
|
case e instanceof E: return e.toResponse();
|
|
781
836
|
case e instanceof T: return e.toResponse();
|
|
782
|
-
case e instanceof w: return e.toResponse();
|
|
783
837
|
}
|
|
784
838
|
switch (!0) {
|
|
785
|
-
case e instanceof f: return e.toResponse();
|
|
786
839
|
case e instanceof p: return e.toResponse();
|
|
787
840
|
case e instanceof m: return e.toResponse();
|
|
788
841
|
case e instanceof h: return e.toResponse();
|
|
@@ -791,12 +844,13 @@ function R(e) {
|
|
|
791
844
|
case e instanceof v: return e.toResponse();
|
|
792
845
|
case e instanceof y: return e.toResponse();
|
|
793
846
|
case e instanceof b: return e.toResponse();
|
|
847
|
+
case e instanceof x: return e.toResponse();
|
|
794
848
|
}
|
|
795
|
-
return new
|
|
849
|
+
return new y("Server error", e).toResponse();
|
|
796
850
|
}
|
|
797
851
|
//#endregion
|
|
798
852
|
//#region src/utilities/formAsyncParse.ts
|
|
799
|
-
async function
|
|
853
|
+
async function B([e, t]) {
|
|
800
854
|
let n = await t.safeParseAsync(e);
|
|
801
855
|
return n.success === !1 ? {
|
|
802
856
|
success: !1,
|
|
@@ -809,7 +863,7 @@ async function z([e, t]) {
|
|
|
809
863
|
}
|
|
810
864
|
//#endregion
|
|
811
865
|
//#region src/utilities/formParse.ts
|
|
812
|
-
function
|
|
866
|
+
function V([e, t]) {
|
|
813
867
|
let n = t.safeParse(e);
|
|
814
868
|
return n.success === !1 ? {
|
|
815
869
|
success: !1,
|
|
@@ -822,7 +876,7 @@ function B([e, t]) {
|
|
|
822
876
|
}
|
|
823
877
|
//#endregion
|
|
824
878
|
//#region src/utilities/getScopedParams.ts
|
|
825
|
-
function
|
|
879
|
+
function H(e, t = "") {
|
|
826
880
|
let n = new URL(e.url);
|
|
827
881
|
if (t === "") return n.searchParams;
|
|
828
882
|
let r = Array.from(n.searchParams.entries()).filter(([e]) => e.startsWith(`${t}:`)).map(([e, n]) => [e.replace(`${t}:`, ""), n]);
|
|
@@ -830,10 +884,10 @@ function V(e, t = "") {
|
|
|
830
884
|
}
|
|
831
885
|
//#endregion
|
|
832
886
|
//#region src/utilities/schemaValidator.ts
|
|
833
|
-
function
|
|
887
|
+
function U(e) {
|
|
834
888
|
return ["Error validating:", ...e.issues.map(({ path: e, message: t }) => `-> ${e.join(".")}: ${t}`)].join("\n");
|
|
835
889
|
}
|
|
836
|
-
var
|
|
890
|
+
var W = class {
|
|
837
891
|
schema;
|
|
838
892
|
constructor(e) {
|
|
839
893
|
this.schema = e;
|
|
@@ -848,14 +902,14 @@ var U = class {
|
|
|
848
902
|
try {
|
|
849
903
|
return this.schema.parse(e);
|
|
850
904
|
} catch (e) {
|
|
851
|
-
throw new
|
|
905
|
+
throw new y(U(e));
|
|
852
906
|
}
|
|
853
907
|
}
|
|
854
908
|
formValidate(e, t) {
|
|
855
|
-
let n =
|
|
909
|
+
let n = V([e, this.schema]);
|
|
856
910
|
if ("fieldErrors" in n) {
|
|
857
911
|
let e = Object.keys(n.fieldErrors)[0];
|
|
858
|
-
throw new
|
|
912
|
+
throw new x({
|
|
859
913
|
fields: n.fields,
|
|
860
914
|
fieldErrors: n.fieldErrors,
|
|
861
915
|
data: { scrollTo: e },
|
|
@@ -865,10 +919,10 @@ var U = class {
|
|
|
865
919
|
return n.data;
|
|
866
920
|
}
|
|
867
921
|
async formAsyncValidate(e, t) {
|
|
868
|
-
let n = await
|
|
922
|
+
let n = await B([e, this.schema]);
|
|
869
923
|
if ("fieldErrors" in n) {
|
|
870
924
|
let e = Object.keys(n.fieldErrors)[0];
|
|
871
|
-
throw new
|
|
925
|
+
throw new x({
|
|
872
926
|
fields: n.fields,
|
|
873
927
|
fieldErrors: n.fieldErrors,
|
|
874
928
|
data: { scrollTo: e },
|
|
@@ -880,34 +934,34 @@ var U = class {
|
|
|
880
934
|
};
|
|
881
935
|
//#endregion
|
|
882
936
|
//#region src/validations/validateCep.ts
|
|
883
|
-
function
|
|
937
|
+
function G(e) {
|
|
884
938
|
if (!(/^\d{5}-\d{3}$/.test(e) || /^\d{8}$/.test(e))) return !1;
|
|
885
|
-
let t =
|
|
939
|
+
let t = i(e), n = /^\d{8}$/.test(t);
|
|
886
940
|
return t.length === 8 && n;
|
|
887
941
|
}
|
|
888
942
|
//#endregion
|
|
889
943
|
//#region src/validations/validateCnpj.ts
|
|
890
|
-
function
|
|
944
|
+
function K(e) {
|
|
891
945
|
return e.length !== 14;
|
|
892
946
|
}
|
|
893
|
-
function
|
|
947
|
+
function q(e) {
|
|
894
948
|
let [t] = e;
|
|
895
949
|
return [...e].every((e) => e === t);
|
|
896
950
|
}
|
|
897
|
-
function
|
|
951
|
+
function J(e, t) {
|
|
898
952
|
let n = 0;
|
|
899
953
|
for (let r = 0; r < t.length; r++) n += parseInt(e[r], 10) * t[r];
|
|
900
954
|
let r = n % 11;
|
|
901
955
|
return r < 2 ? 0 : 11 - r;
|
|
902
956
|
}
|
|
903
|
-
function
|
|
957
|
+
function Y(e) {
|
|
904
958
|
return e.slice(12);
|
|
905
959
|
}
|
|
906
|
-
function
|
|
960
|
+
function ne(e) {
|
|
907
961
|
if (!e || e.length > 18 || e.length < 14 || /\s/.test(e)) return !1;
|
|
908
|
-
let t =
|
|
909
|
-
if (
|
|
910
|
-
let n = t.slice(0, 12),
|
|
962
|
+
let t = i(e);
|
|
963
|
+
if (K(t) || q(t)) return !1;
|
|
964
|
+
let n = t.slice(0, 12), r = J(n, [
|
|
911
965
|
5,
|
|
912
966
|
4,
|
|
913
967
|
3,
|
|
@@ -920,7 +974,7 @@ function te(e) {
|
|
|
920
974
|
4,
|
|
921
975
|
3,
|
|
922
976
|
2
|
|
923
|
-
]), a =
|
|
977
|
+
]), a = J(n + r, [
|
|
924
978
|
6,
|
|
925
979
|
5,
|
|
926
980
|
4,
|
|
@@ -935,36 +989,36 @@ function te(e) {
|
|
|
935
989
|
3,
|
|
936
990
|
2
|
|
937
991
|
]);
|
|
938
|
-
return
|
|
992
|
+
return Y(t) === `${r}${a}`;
|
|
939
993
|
}
|
|
940
994
|
//#endregion
|
|
941
995
|
//#region src/validations/validateCpf.ts
|
|
942
|
-
function
|
|
996
|
+
function X(e) {
|
|
943
997
|
return e.length !== 11;
|
|
944
998
|
}
|
|
945
|
-
function
|
|
999
|
+
function Z(e) {
|
|
946
1000
|
let [t] = e;
|
|
947
1001
|
return [...e].every((e) => e === t);
|
|
948
1002
|
}
|
|
949
|
-
function
|
|
1003
|
+
function Q(e, t) {
|
|
950
1004
|
let n = 0;
|
|
951
1005
|
for (let r of e) t > 1 && (n += parseInt(r, 10) * t--);
|
|
952
1006
|
let r = n % 11;
|
|
953
1007
|
return r < 2 ? 0 : 11 - r;
|
|
954
1008
|
}
|
|
955
|
-
function
|
|
1009
|
+
function re(e) {
|
|
956
1010
|
return e.slice(9);
|
|
957
1011
|
}
|
|
958
|
-
function
|
|
1012
|
+
function ie(e) {
|
|
959
1013
|
if (!e || e.length > 14 || e.length < 11 || /\s/.test(e)) return !1;
|
|
960
|
-
let t =
|
|
961
|
-
if (
|
|
962
|
-
let n =
|
|
963
|
-
return
|
|
1014
|
+
let t = i(e);
|
|
1015
|
+
if (X(t) || Z(t)) return !1;
|
|
1016
|
+
let n = Q(t, 10), r = Q(t, 11);
|
|
1017
|
+
return re(t) === `${n}${r}`;
|
|
964
1018
|
}
|
|
965
1019
|
//#endregion
|
|
966
1020
|
//#region src/validations/validateDate.ts
|
|
967
|
-
function
|
|
1021
|
+
function ae(t, n) {
|
|
968
1022
|
let r = n?.inputFormat || "brazilianDate", i = n?.minYear || 1900, a = n?.maxYear || 3e3, o = new e();
|
|
969
1023
|
o.validateInputFormat(r);
|
|
970
1024
|
let s, c, l, u = t.split(/[-/]/).map(Number);
|
|
@@ -988,59 +1042,59 @@ function re(t, n) {
|
|
|
988
1042
|
}
|
|
989
1043
|
//#endregion
|
|
990
1044
|
//#region src/validations/validateEmail.ts
|
|
991
|
-
function
|
|
1045
|
+
function oe(e) {
|
|
992
1046
|
return /^[a-zA-Z0-9.!$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e);
|
|
993
1047
|
}
|
|
994
|
-
function
|
|
1048
|
+
function se(e) {
|
|
995
1049
|
return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
|
|
996
1050
|
}
|
|
997
|
-
function
|
|
1051
|
+
function ce(e) {
|
|
998
1052
|
return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
|
|
999
1053
|
}
|
|
1000
|
-
function
|
|
1054
|
+
function le(e) {
|
|
1001
1055
|
if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-")) return !1;
|
|
1002
1056
|
let t = e.split(".");
|
|
1003
1057
|
if (t.length < 2) return !1;
|
|
1004
|
-
for (let e of t) if (!
|
|
1058
|
+
for (let e of t) if (!ce(e)) return !1;
|
|
1005
1059
|
let n = t[t.length - 1];
|
|
1006
1060
|
return !(n.length < 2 || !/^[a-zA-Z]+$/.test(n));
|
|
1007
1061
|
}
|
|
1008
|
-
function
|
|
1062
|
+
function ue(e) {
|
|
1009
1063
|
let t = e.split("@");
|
|
1010
1064
|
if (t.length !== 2) return !1;
|
|
1011
1065
|
let [n, r] = t;
|
|
1012
|
-
return !(!
|
|
1066
|
+
return !(!se(n) || !le(r));
|
|
1013
1067
|
}
|
|
1014
|
-
function
|
|
1068
|
+
function de(e) {
|
|
1015
1069
|
let t = e.split("@");
|
|
1016
1070
|
return t.length === 2 ? t[1].toLowerCase() : null;
|
|
1017
1071
|
}
|
|
1018
|
-
var
|
|
1072
|
+
var fe = [
|
|
1019
1073
|
"MX",
|
|
1020
1074
|
"A",
|
|
1021
1075
|
"AAAA"
|
|
1022
1076
|
];
|
|
1023
|
-
async function
|
|
1077
|
+
async function pe(e, t) {
|
|
1024
1078
|
try {
|
|
1025
|
-
return await
|
|
1079
|
+
return await o?.promises?.resolve(e, t), !0;
|
|
1026
1080
|
} catch {
|
|
1027
1081
|
return !1;
|
|
1028
1082
|
}
|
|
1029
1083
|
}
|
|
1030
|
-
async function
|
|
1031
|
-
for (let t of
|
|
1084
|
+
async function $(e) {
|
|
1085
|
+
for (let t of fe) if (await pe(e, t)) return !0;
|
|
1032
1086
|
return !1;
|
|
1033
1087
|
}
|
|
1034
|
-
async function
|
|
1088
|
+
async function me(e) {
|
|
1035
1089
|
if (!e || typeof e != "string") return !1;
|
|
1036
1090
|
let t = e.trim();
|
|
1037
|
-
if (!
|
|
1038
|
-
let n =
|
|
1039
|
-
return n ? await
|
|
1091
|
+
if (!oe(t) || !ue(t)) return !1;
|
|
1092
|
+
let n = de(t);
|
|
1093
|
+
return n ? await $(n) : !1;
|
|
1040
1094
|
}
|
|
1041
1095
|
//#endregion
|
|
1042
1096
|
//#region src/validations/validatePassword.ts
|
|
1043
|
-
function
|
|
1097
|
+
function he(e) {
|
|
1044
1098
|
return e ? [
|
|
1045
1099
|
e.length >= 8,
|
|
1046
1100
|
/[A-Z]/.test(e),
|
|
@@ -1051,19 +1105,19 @@ function pe(e) {
|
|
|
1051
1105
|
}
|
|
1052
1106
|
//#endregion
|
|
1053
1107
|
//#region src/validations/validatePhone.ts
|
|
1054
|
-
function
|
|
1055
|
-
if (!
|
|
1056
|
-
let t =
|
|
1057
|
-
return !(!t || !
|
|
1108
|
+
function ge(e) {
|
|
1109
|
+
if (!c(e)) return !1;
|
|
1110
|
+
let t = l(e)?.country;
|
|
1111
|
+
return !(!t || !s.find((e) => e.iso === t));
|
|
1058
1112
|
}
|
|
1059
1113
|
//#endregion
|
|
1060
1114
|
//#region src/validations/validateRg.ts
|
|
1061
|
-
function
|
|
1115
|
+
function _e(e) {
|
|
1062
1116
|
if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
|
|
1063
1117
|
let t = e.replace(/[^a-zA-Z0-9]/g, "");
|
|
1064
1118
|
return t.length < 7 || t.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(t);
|
|
1065
1119
|
}
|
|
1066
1120
|
//#endregion
|
|
1067
|
-
export {
|
|
1121
|
+
export { I as ApiService, p as BadGateway, m as BadRequest, h as Conflict, C as Created, u as DebugService, g as Forbidden, w as Found, k as LogService, T as NoContent, _ as NotFound, v as NotImplemented, W as SchemaValidator, y as ServerError, E as Success, b as Unauthorized, x as UnprocessableEntity, D as Updated, L as decodeRequestBody, R as decodeRequestErrorMessage, z as errorHandler, d as flushDebugLogs, B as formAsyncParse, V as formParse, H as getScopedParams, G as validateCep, ne as validateCnpj, ie as validateCpf, ae as validateDate, me as validateEmail, he as validatePassword, ge as validatePhone, _e as validateRg };
|
|
1068
1122
|
|
|
1069
1123
|
//# sourceMappingURL=index.js.map
|