@arkyn/server 3.0.1-beta.159 → 3.0.1-beta.166

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.
Files changed (47) hide show
  1. package/dist/index.js +1026 -1262
  2. package/dist/modules/http/api/_logRequest.js +55 -68
  3. package/dist/modules/http/api/_makeRequest.js +69 -68
  4. package/dist/modules/http/api/deleteRequest.js +12 -12
  5. package/dist/modules/http/api/getRequest.js +11 -11
  6. package/dist/modules/http/api/patchRequest.js +11 -11
  7. package/dist/modules/http/api/postRequest.js +11 -11
  8. package/dist/modules/http/api/putRequest.js +11 -11
  9. package/dist/modules/http/badResponses/_badResponse.js +62 -58
  10. package/dist/modules/http/badResponses/badGateway.js +22 -28
  11. package/dist/modules/http/badResponses/badRequest.js +22 -28
  12. package/dist/modules/http/badResponses/conflict.js +22 -28
  13. package/dist/modules/http/badResponses/forbidden.js +22 -28
  14. package/dist/modules/http/badResponses/notFound.js +22 -28
  15. package/dist/modules/http/badResponses/notImplemented.js +22 -28
  16. package/dist/modules/http/badResponses/serverError.js +22 -28
  17. package/dist/modules/http/badResponses/unauthorized.js +22 -28
  18. package/dist/modules/http/badResponses/unprocessableEntity.js +27 -35
  19. package/dist/modules/http/successResponses/_successResponse.js +61 -68
  20. package/dist/modules/http/successResponses/created.js +22 -28
  21. package/dist/modules/http/successResponses/found.js +22 -28
  22. package/dist/modules/http/successResponses/noContent.js +16 -20
  23. package/dist/modules/http/successResponses/success.js +22 -28
  24. package/dist/modules/http/successResponses/updated.js +22 -28
  25. package/dist/modules/index.js +33 -67
  26. package/dist/modules/services/apiService.js +108 -128
  27. package/dist/modules/services/debugService.js +35 -65
  28. package/dist/modules/services/logMapperService.js +28 -51
  29. package/dist/modules/services/logService.js +20 -30
  30. package/dist/modules/utilities/decodeRequestBody.js +19 -21
  31. package/dist/modules/utilities/decodeRequestErrorMessage.js +5 -6
  32. package/dist/modules/utilities/errorHandler.js +36 -51
  33. package/dist/modules/utilities/flushDebugLogs.js +15 -19
  34. package/dist/modules/utilities/formAsyncParse.js +13 -18
  35. package/dist/modules/utilities/formParse.js +13 -18
  36. package/dist/modules/utilities/getScopedParams.js +8 -10
  37. package/dist/modules/utilities/schemaValidator.js +53 -104
  38. package/dist/modules/validations/validateCep.js +8 -8
  39. package/dist/modules/validations/validateCnpj.js +49 -26
  40. package/dist/modules/validations/validateCpf.js +22 -23
  41. package/dist/modules/validations/validateDate.js +25 -26
  42. package/dist/modules/validations/validateEmail.js +54 -53
  43. package/dist/modules/validations/validatePassword.js +11 -15
  44. package/dist/modules/validations/validatePhone.js +8 -8
  45. package/dist/modules/validations/validateRg.js +7 -7
  46. package/generate-version.ts +74 -0
  47. package/package.json +17 -9
@@ -1,31 +1,54 @@
1
- import { removeNonNumeric as f } from "@arkyn/shared";
2
- function l(t) {
3
- return t.length !== 14;
1
+ import { removeNonNumeric as e } from "@arkyn/shared";
2
+ //#region src/validations/validateCnpj.ts
3
+ function t(e) {
4
+ return e.length !== 14;
4
5
  }
5
- function o(t) {
6
- const [i] = t;
7
- return [...t].every((e) => e === i);
6
+ function n(e) {
7
+ let [t] = e;
8
+ return [...e].every((e) => e === t);
8
9
  }
9
- function s(t, i) {
10
- let e = 0;
11
- for (let n = 0; n < i.length; n++)
12
- e += parseInt(t[n]) * i[n];
13
- const r = e % 11;
14
- return r < 2 ? 0 : 11 - r;
10
+ function r(e, t) {
11
+ let n = 0;
12
+ for (let r = 0; r < t.length; r++) n += parseInt(e[r]) * t[r];
13
+ let r = n % 11;
14
+ return r < 2 ? 0 : 11 - r;
15
15
  }
16
- function u(t) {
17
- return t.slice(12);
16
+ function i(e) {
17
+ return e.slice(12);
18
18
  }
19
- function g(t) {
20
- if (!t || t.length > 18 || t.length < 14 || /\s/.test(t)) return !1;
21
- const e = f(t);
22
- if (l(e) || o(e)) return !1;
23
- const r = e.slice(0, 12), n = s(r, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]), c = s(
24
- r + n,
25
- [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
26
- );
27
- return u(e) === `${n}${c}`;
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}`;
28
52
  }
29
- export {
30
- g as validateCnpj
31
- };
53
+ //#endregion
54
+ export { a as validateCnpj };
@@ -1,28 +1,27 @@
1
- import { removeNonNumeric as o } from "@arkyn/shared";
2
- function c(t) {
3
- return t.length !== 11;
1
+ import { removeNonNumeric as e } from "@arkyn/shared";
2
+ //#region src/validations/validateCpf.ts
3
+ function t(e) {
4
+ return e.length !== 11;
4
5
  }
5
- function f(t) {
6
- const [n] = t;
7
- return [...t].every((e) => e === n);
6
+ function n(e) {
7
+ let [t] = e;
8
+ return [...e].every((e) => e === t);
8
9
  }
9
- function s(t, n) {
10
- let e = 0;
11
- for (const r of t)
12
- n > 1 && (e += parseInt(r) * n--);
13
- const i = e % 11;
14
- return i < 2 ? 0 : 11 - i;
10
+ function r(e, t) {
11
+ let n = 0;
12
+ for (let r of e) t > 1 && (n += parseInt(r) * t--);
13
+ let r = n % 11;
14
+ return r < 2 ? 0 : 11 - r;
15
15
  }
16
- function l(t) {
17
- return t.slice(9);
16
+ function i(e) {
17
+ return e.slice(9);
18
18
  }
19
- function a(t) {
20
- if (!t || t.length > 14 || t.length < 11 || /\s/.test(t)) return !1;
21
- const e = o(t);
22
- if (c(e) || f(e)) return !1;
23
- const i = s(e, 10), r = s(e, 11);
24
- return l(e) === `${i}${r}`;
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
25
  }
26
- export {
27
- a as validateCpf
28
- };
26
+ //#endregion
27
+ export { a as validateCpf };
@@ -1,27 +1,26 @@
1
- import { ValidateDateService as D } from "@arkyn/shared";
2
- function v(i, a) {
3
- const m = (a == null ? void 0 : a.inputFormat) || "brazilianDate", u = (a == null ? void 0 : a.minYear) || 1900, d = (a == null ? void 0 : a.maxYear) || 3e3, s = new D();
4
- s.validateInputFormat(m);
5
- let e, r, t;
6
- const l = i.split(/[-/]/).map(Number);
7
- if (l.length !== 3) return !1;
8
- try {
9
- switch (m) {
10
- case "brazilianDate":
11
- [e, r, t] = l, s.validateDateParts(t, r, e);
12
- break;
13
- case "isoDate":
14
- [r, e, t] = l, s.validateDateParts(t, r, e);
15
- break;
16
- case "timestamp":
17
- [t, r, e] = l, s.validateDateParts(t, r, e);
18
- break;
19
- }
20
- return !(t < u || t > d);
21
- } catch {
22
- return !1;
23
- }
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
24
  }
25
- export {
26
- v as validateDate
27
- };
25
+ //#endregion
26
+ export { t as validateDate };
@@ -1,53 +1,54 @@
1
- import s from "node:dns";
2
- function i(t) {
3
- 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(t);
4
- }
5
- function f(t) {
6
- return !(t.length === 0 || t.length > 64 || t.startsWith(".") || t.endsWith(".") || t.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(t));
7
- }
8
- function a(t) {
9
- return !(t.length === 0 || t.length > 63 || t.startsWith("-") || t.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(t));
10
- }
11
- function u(t) {
12
- if (t.length === 0 || t.length > 253 || t.startsWith(".") || t.endsWith(".") || t.startsWith("-") || t.endsWith("-"))
13
- return !1;
14
- const e = t.split(".");
15
- if (e.length < 2) return !1;
16
- for (const r of e) if (!a(r)) return !1;
17
- const n = e[e.length - 1];
18
- return !(n.length < 2 || !/^[a-zA-Z]+$/.test(n));
19
- }
20
- function l(t) {
21
- const e = t.split("@");
22
- if (e.length !== 2) return !1;
23
- const [n, r] = e;
24
- return !(!f(n) || !u(r));
25
- }
26
- function o(t) {
27
- const e = t.split("@");
28
- return e.length === 2 ? e[1].toLowerCase() : null;
29
- }
30
- const c = ["MX", "A", "AAAA"];
31
- async function h(t, e) {
32
- var n, r;
33
- try {
34
- return await ((r = (n = s) == null ? void 0 : n.promises) == null ? void 0 : r.resolve(t, e)), !0;
35
- } catch {
36
- return !1;
37
- }
38
- }
39
- async function d(t) {
40
- for (const e of c)
41
- if (await h(t, e)) return !0;
42
- return !1;
43
- }
44
- async function A(t) {
45
- if (!t || typeof t != "string") return !1;
46
- const e = t.trim();
47
- if (!i(e) || !l(e)) return !1;
48
- const n = o(e);
49
- return n ? await d(n) : !1;
50
- }
51
- export {
52
- A as validateEmail
53
- };
1
+ import e from "node:dns";
2
+ //#region src/validations/validateEmail.ts
3
+ function t(e) {
4
+ 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);
5
+ }
6
+ function n(e) {
7
+ return !(e.length === 0 || e.length > 64 || e.startsWith(".") || e.endsWith(".") || e.includes("..") || !/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e));
8
+ }
9
+ function r(e) {
10
+ return !(e.length === 0 || e.length > 63 || e.startsWith("-") || e.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(e));
11
+ }
12
+ function i(e) {
13
+ if (e.length === 0 || e.length > 253 || e.startsWith(".") || e.endsWith(".") || e.startsWith("-") || e.endsWith("-")) return !1;
14
+ let t = e.split(".");
15
+ if (t.length < 2) return !1;
16
+ for (let e of t) if (!r(e)) return !1;
17
+ let n = t[t.length - 1];
18
+ return !(n.length < 2 || !/^[a-zA-Z]+$/.test(n));
19
+ }
20
+ function a(e) {
21
+ let t = e.split("@");
22
+ if (t.length !== 2) return !1;
23
+ let [r, a] = t;
24
+ return !(!n(r) || !i(a));
25
+ }
26
+ function o(e) {
27
+ let t = e.split("@");
28
+ return t.length === 2 ? t[1].toLowerCase() : null;
29
+ }
30
+ var s = [
31
+ "MX",
32
+ "A",
33
+ "AAAA"
34
+ ];
35
+ async function c(t, n) {
36
+ try {
37
+ return await e?.promises?.resolve(t, n), !0;
38
+ } catch {
39
+ return !1;
40
+ }
41
+ }
42
+ async function l(e) {
43
+ for (let t of s) if (await c(e, t)) return !0;
44
+ return !1;
45
+ }
46
+ async function u(e) {
47
+ if (!e || typeof e != "string") return !1;
48
+ let n = e.trim();
49
+ if (!t(n) || !a(n)) return !1;
50
+ let r = o(n);
51
+ return r ? await l(r) : !1;
52
+ }
53
+ //#endregion
54
+ export { u as validateEmail };
@@ -1,16 +1,12 @@
1
- function l(t) {
2
- if (!t) return !1;
3
- const e = t.length >= 8, n = /[A-Z]/.test(t), c = /[a-z]/.test(t), h = /\d/.test(t), s = /[!@#$%^&*(),.?":;{}|<>_\-+=~`[\]\\\/]/.test(
4
- t
5
- );
6
- return [
7
- e,
8
- n,
9
- c,
10
- h,
11
- s
12
- ].every((i) => i);
1
+ //#region src/validations/validatePassword.ts
2
+ function e(e) {
3
+ return e ? [
4
+ e.length >= 8,
5
+ /[A-Z]/.test(e),
6
+ /[a-z]/.test(e),
7
+ /\d/.test(e),
8
+ /[!@#$%^&*(),.?":;{}|<>_\-+=~`[\]\\\/]/.test(e)
9
+ ].every((e) => e) : !1;
13
10
  }
14
- export {
15
- l as validatePassword
16
- };
11
+ //#endregion
12
+ export { e as validatePassword };
@@ -1,10 +1,10 @@
1
1
  import { countries as e } from "@arkyn/templates";
2
- import { isValidPhoneNumber as i, parsePhoneNumberWithError as u } from "libphonenumber-js";
3
- function m(t) {
4
- if (!i(t)) return !1;
5
- const r = u(t), o = r == null ? void 0 : r.country;
6
- return !(!o || !e.find((n) => n.iso === o));
2
+ import { isValidPhoneNumber as t, parsePhoneNumberWithError as n } from "libphonenumber-js";
3
+ //#region src/validations/validatePhone.ts
4
+ function r(r) {
5
+ if (!t(r)) return !1;
6
+ let i = n(r)?.country;
7
+ return !(!i || !e.find((e) => e.iso === i));
7
8
  }
8
- export {
9
- m as validatePhone
10
- };
9
+ //#endregion
10
+ export { r as validatePhone };
@@ -1,8 +1,8 @@
1
- function i(t) {
2
- if (!t || !/^[0-9a-zA-Z.-]+$/.test(t)) return !1;
3
- const e = t.replace(/[^a-zA-Z0-9]/g, "");
4
- return e.length < 7 || e.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(e);
1
+ //#region src/validations/validateRg.ts
2
+ function e(e) {
3
+ if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
4
+ let t = e.replace(/[^a-zA-Z0-9]/g, "");
5
+ return t.length < 7 || t.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(t);
5
6
  }
6
- export {
7
- i as validateRg
8
- };
7
+ //#endregion
8
+ export { e as validateRg };
@@ -0,0 +1,74 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+
4
+ type ReleaseType = "beta" | "patch" | "minor" | "major";
5
+
6
+ interface PackageJson {
7
+ version: string;
8
+ [key: string]: unknown;
9
+ }
10
+
11
+ const release = process.argv[2] as ReleaseType;
12
+
13
+ const VALID_RELEASES: ReleaseType[] = ["beta", "patch", "minor", "major"];
14
+
15
+ if (!VALID_RELEASES.includes(release)) {
16
+ console.error("Usage: bun generate-version.ts [beta|patch|minor|major]");
17
+ process.exit(1);
18
+ }
19
+
20
+ const PACKAGE_JSON = join(process.cwd(), "package.json");
21
+
22
+ function parseVersion(version: string) {
23
+ const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-beta\.(\d+))?$/);
24
+
25
+ if (!match) {
26
+ throw new Error(`Invalid version: ${version}`);
27
+ }
28
+
29
+ return {
30
+ major: Number(match[1]),
31
+ minor: Number(match[2]),
32
+ patch: Number(match[3]),
33
+ beta: match[4] ? Number(match[4]) : null,
34
+ };
35
+ }
36
+
37
+ function nextVersion(version: string, release: ReleaseType): string {
38
+ const parsed = parseVersion(version);
39
+
40
+ switch (release) {
41
+ case "beta":
42
+ return `${parsed.major}.${parsed.minor}.${parsed.patch}-beta.${
43
+ parsed.beta === null ? 0 : parsed.beta + 1
44
+ }`;
45
+
46
+ case "patch":
47
+ return `${parsed.major}.${parsed.minor}.${parsed.patch + 1}`;
48
+
49
+ case "minor":
50
+ return `${parsed.major}.${parsed.minor + 1}.0`;
51
+
52
+ case "major":
53
+ return `${parsed.major + 1}.0.0`;
54
+ }
55
+ }
56
+
57
+ async function main() {
58
+ const pkg = JSON.parse(await readFile(PACKAGE_JSON, "utf8")) as PackageJson;
59
+
60
+ const current = pkg.version;
61
+ const next = nextVersion(current, release);
62
+
63
+ pkg.version = next;
64
+
65
+ await writeFile(PACKAGE_JSON, JSON.stringify(pkg, null, 2) + "\n");
66
+
67
+ console.log(`Version updated`);
68
+ console.log(`${current} -> ${next}`);
69
+ }
70
+
71
+ main().catch((error) => {
72
+ console.error(error);
73
+ process.exit(1);
74
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "3.0.1-beta.159",
3
+ "version": "3.0.1-beta.166",
4
4
  "author": "Arkyn | Lucas Gonçalves",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -27,20 +27,28 @@
27
27
  },
28
28
  "sideEffects": false,
29
29
  "scripts": {
30
+ "audit": "bun audit --workspace packages/server",
30
31
  "build": "bunx vite build && bunx tsc --project tsconfig.json --emitDeclarationOnly && bun ./generate-exports.ts",
31
- "test": "vitest --config vitest.config.ts",
32
+ "publish:beta": "bun publish --tag beta",
33
+ "release:beta": "bun ./generate-version.ts beta",
34
+ "release:patch": "bun ./generate-version.ts patch",
35
+ "release:minor": "bun ./generate-version.ts minor",
36
+ "release:major": "bun ./generate-version.ts major",
37
+ "test": "bunx vitest --config vitest.config.ts --run",
38
+ "test:watch": "bunx vitest --config vitest.config.ts --watch",
32
39
  "typecheck": "bunx tsc --project tsconfig.json --noEmit"
33
40
  },
34
41
  "peerDependencies": {
35
- "@arkyn/shared": ">=3.0.1-beta.145",
36
- "@arkyn/templates": ">=3.0.1-beta.145",
37
- "zod": ">=4.3.6"
42
+ "libphonenumber-js": ">=1.13.7",
43
+ "zod": ">=4.4.3"
38
44
  },
39
45
  "devDependencies": {
40
- "bun-types": "latest",
41
- "vitest": "^3.2.4",
42
- "typescript": "^5.9.3",
43
- "vite": "^5.4.21"
46
+ "@types/bun": "^1.3.14",
47
+ "@types/node": "^26.0.1",
48
+ "libphonenumber-js": "^1.13.7",
49
+ "vite": "^8.1.0",
50
+ "vitest": "^4.1.9",
51
+ "zod": "^4.4.3"
44
52
  },
45
53
  "exports": {
46
54
  ".": {