@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.
- package/dist/index.js +1026 -1262
- package/dist/modules/http/api/_logRequest.js +55 -68
- package/dist/modules/http/api/_makeRequest.js +69 -68
- package/dist/modules/http/api/deleteRequest.js +12 -12
- package/dist/modules/http/api/getRequest.js +11 -11
- package/dist/modules/http/api/patchRequest.js +11 -11
- package/dist/modules/http/api/postRequest.js +11 -11
- package/dist/modules/http/api/putRequest.js +11 -11
- package/dist/modules/http/badResponses/_badResponse.js +62 -58
- package/dist/modules/http/badResponses/badGateway.js +22 -28
- package/dist/modules/http/badResponses/badRequest.js +22 -28
- package/dist/modules/http/badResponses/conflict.js +22 -28
- package/dist/modules/http/badResponses/forbidden.js +22 -28
- package/dist/modules/http/badResponses/notFound.js +22 -28
- package/dist/modules/http/badResponses/notImplemented.js +22 -28
- package/dist/modules/http/badResponses/serverError.js +22 -28
- package/dist/modules/http/badResponses/unauthorized.js +22 -28
- package/dist/modules/http/badResponses/unprocessableEntity.js +27 -35
- package/dist/modules/http/successResponses/_successResponse.js +61 -68
- package/dist/modules/http/successResponses/created.js +22 -28
- package/dist/modules/http/successResponses/found.js +22 -28
- package/dist/modules/http/successResponses/noContent.js +16 -20
- package/dist/modules/http/successResponses/success.js +22 -28
- package/dist/modules/http/successResponses/updated.js +22 -28
- package/dist/modules/index.js +33 -67
- package/dist/modules/services/apiService.js +108 -128
- package/dist/modules/services/debugService.js +35 -65
- package/dist/modules/services/logMapperService.js +28 -51
- package/dist/modules/services/logService.js +20 -30
- package/dist/modules/utilities/decodeRequestBody.js +19 -21
- package/dist/modules/utilities/decodeRequestErrorMessage.js +5 -6
- package/dist/modules/utilities/errorHandler.js +36 -51
- package/dist/modules/utilities/flushDebugLogs.js +15 -19
- package/dist/modules/utilities/formAsyncParse.js +13 -18
- package/dist/modules/utilities/formParse.js +13 -18
- package/dist/modules/utilities/getScopedParams.js +8 -10
- package/dist/modules/utilities/schemaValidator.js +53 -104
- package/dist/modules/validations/validateCep.js +8 -8
- package/dist/modules/validations/validateCnpj.js +49 -26
- package/dist/modules/validations/validateCpf.js +22 -23
- package/dist/modules/validations/validateDate.js +25 -26
- package/dist/modules/validations/validateEmail.js +54 -53
- package/dist/modules/validations/validatePassword.js +11 -15
- package/dist/modules/validations/validatePhone.js +8 -8
- package/dist/modules/validations/validateRg.js +7 -7
- package/generate-version.ts +74 -0
- package/package.json +17 -9
|
@@ -1,52 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* Transforms raw HTTP request/response data into a standardized log output format.
|
|
28
|
-
*
|
|
29
|
-
* @param {InputProps} props - The input properties containing request/response data.
|
|
30
|
-
* @returns {OutputProps} The mapped output object ready for logging.
|
|
31
|
-
*/
|
|
32
|
-
static handle(e) {
|
|
33
|
-
return {
|
|
34
|
-
rawUrl: e.rawUrl,
|
|
35
|
-
status: e.status,
|
|
36
|
-
method: e.method,
|
|
37
|
-
token: null,
|
|
38
|
-
elapsedTime: e.elapsedTime,
|
|
39
|
-
requestHeaders: this.mapHeaders(e.requestHeaders),
|
|
40
|
-
requestBody: e.requestBody || null,
|
|
41
|
-
queryParams: {
|
|
42
|
-
...this.mapQueryParams(e.queryParams),
|
|
43
|
-
...e.urlParams
|
|
44
|
-
},
|
|
45
|
-
responseHeaders: this.mapHeaders(e.responseHeaders),
|
|
46
|
-
responseBody: e.responseBody || null
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
n as LogMapperService
|
|
1
|
+
//#region src/services/logMapperService.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
static mapHeaders(e) {
|
|
4
|
+
return e instanceof Headers ? Object.fromEntries(e.entries()) : typeof e == "object" ? Object.entries(e).reduce((e, [t, n]) => (typeof n == "string" ? e[t] = n : Array.isArray(n) ? e[t] = n.join(", ") : e[t] = JSON.stringify(n), e), {}) : {};
|
|
5
|
+
}
|
|
6
|
+
static mapQueryParams(e) {
|
|
7
|
+
let t = {};
|
|
8
|
+
return e.forEach((e, n) => t[n] = e), t;
|
|
9
|
+
}
|
|
10
|
+
static handle(e) {
|
|
11
|
+
return {
|
|
12
|
+
rawUrl: e.rawUrl,
|
|
13
|
+
status: e.status,
|
|
14
|
+
method: e.method,
|
|
15
|
+
token: null,
|
|
16
|
+
elapsedTime: e.elapsedTime,
|
|
17
|
+
requestHeaders: this.mapHeaders(e.requestHeaders),
|
|
18
|
+
requestBody: e.requestBody || null,
|
|
19
|
+
queryParams: {
|
|
20
|
+
...this.mapQueryParams(e.queryParams),
|
|
21
|
+
...e.urlParams
|
|
22
|
+
},
|
|
23
|
+
responseHeaders: this.mapHeaders(e.responseHeaders),
|
|
24
|
+
responseBody: e.responseBody || null
|
|
25
|
+
};
|
|
26
|
+
}
|
|
52
27
|
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { e as LogMapperService };
|
|
@@ -1,31 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return this.config;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Resets the stored configuration, allowing a new initialization.
|
|
23
|
-
*/
|
|
24
|
-
static resetConfig() {
|
|
25
|
-
this.config = void 0;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
o(f, "config");
|
|
29
|
-
export {
|
|
30
|
-
f as LogService
|
|
1
|
+
//#region src/services/logService.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
static config;
|
|
4
|
+
static setConfig(e) {
|
|
5
|
+
if (this.config) return;
|
|
6
|
+
let { trafficSourceId: t, userToken: n, logBaseApiUrl: r } = e, i = `${r || "http://62.238.8.44:8081"}/ingest-log`;
|
|
7
|
+
this.config = {
|
|
8
|
+
trafficSourceId: t,
|
|
9
|
+
userToken: n,
|
|
10
|
+
apiUrl: i
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
static getConfig() {
|
|
14
|
+
return this.config;
|
|
15
|
+
}
|
|
16
|
+
static resetConfig() {
|
|
17
|
+
this.config = void 0;
|
|
18
|
+
}
|
|
31
19
|
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { e as LogService };
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { BadRequest as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return r;
|
|
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;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { t as decodeRequestBody };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
5
|
+
//#endregion
|
|
6
|
+
export { e as decodeRequestErrorMessage };
|
|
@@ -1,54 +1,39 @@
|
|
|
1
1
|
import { BadGateway as e } from "../http/badResponses/badGateway.js";
|
|
2
|
-
import { BadRequest as
|
|
3
|
-
import { Conflict as
|
|
4
|
-
import { Forbidden as
|
|
5
|
-
import { NotFound as
|
|
6
|
-
import { NotImplemented as
|
|
7
|
-
import { ServerError as
|
|
8
|
-
import { Unauthorized as
|
|
9
|
-
import { UnprocessableEntity as
|
|
10
|
-
import { Created as
|
|
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
11
|
import { Found as u } from "../http/successResponses/found.js";
|
|
12
|
-
import { NoContent as
|
|
13
|
-
import { Success as
|
|
14
|
-
import { Updated as
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
case t instanceof a:
|
|
38
|
-
return t.toResponse();
|
|
39
|
-
case t instanceof c:
|
|
40
|
-
return t.toResponse();
|
|
41
|
-
case t instanceof i:
|
|
42
|
-
return t.toResponse();
|
|
43
|
-
case t instanceof n:
|
|
44
|
-
return t.toResponse();
|
|
45
|
-
case t instanceof p:
|
|
46
|
-
return t.toResponse();
|
|
47
|
-
case t instanceof f:
|
|
48
|
-
return t.toResponse();
|
|
49
|
-
}
|
|
50
|
-
return new n("Server error", t).toResponse();
|
|
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();
|
|
51
37
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { m as errorHandler };
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
`);
|
|
15
|
-
}), console.log(o);
|
|
16
|
-
}
|
|
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
|
+
}
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { e as flushDebugLogs };
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} : {
|
|
13
|
-
success: !0,
|
|
14
|
-
data: s.data
|
|
15
|
-
};
|
|
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
|
+
};
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { e as formAsyncParse };
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} : {
|
|
13
|
-
success: !0,
|
|
14
|
-
data: s.data
|
|
15
|
-
};
|
|
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
|
+
};
|
|
16
12
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { e as formParse };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return new URLSearchParams(s);
|
|
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);
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { e as getScopedParams };
|
|
@@ -1,106 +1,55 @@
|
|
|
1
|
-
import { ServerError as
|
|
2
|
-
import { UnprocessableEntity as
|
|
3
|
-
import { formAsyncParse as
|
|
4
|
-
import { formParse as
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
);
|
|
9
|
-
return [r, ...e].join(`
|
|
10
|
-
`);
|
|
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");
|
|
11
8
|
}
|
|
12
|
-
class
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @throws `UnprocessableEntity` with structured field errors for client-side form handling.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```typescript
|
|
60
|
-
* const validator = new SchemaValidator(registerSchema);
|
|
61
|
-
* const body = validator.formValidate(await decodeRequestBody(request));
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
formValidate(r, e) {
|
|
65
|
-
const s = n([r, this.schema]);
|
|
66
|
-
if ("fieldErrors" in s) {
|
|
67
|
-
const t = Object.keys(s.fieldErrors)[0];
|
|
68
|
-
throw new a({
|
|
69
|
-
fields: s.fields,
|
|
70
|
-
fieldErrors: s.fieldErrors,
|
|
71
|
-
data: { scrollTo: t },
|
|
72
|
-
message: e
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return s.data;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Async version of `formValidate` for schemas with async refinements (e.g. uniqueness checks).
|
|
79
|
-
*
|
|
80
|
-
* @param data - The raw form data to validate.
|
|
81
|
-
* @param message - Optional human-readable error message for the 422 response.
|
|
82
|
-
* @throws `UnprocessableEntity` with structured field errors for client-side form handling.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const validator = new SchemaValidator(registerSchema);
|
|
87
|
-
* const body = await validator.formAsyncValidate(await decodeRequestBody(request));
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
async formAsyncValidate(r, e) {
|
|
91
|
-
const s = await f([r, this.schema]);
|
|
92
|
-
if ("fieldErrors" in s) {
|
|
93
|
-
const t = Object.keys(s.fieldErrors)[0];
|
|
94
|
-
throw new a({
|
|
95
|
-
fields: s.fields,
|
|
96
|
-
fieldErrors: s.fieldErrors,
|
|
97
|
-
data: { scrollTo: t },
|
|
98
|
-
message: e
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return s.data;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
export {
|
|
105
|
-
E as SchemaValidator
|
|
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
|
+
}
|
|
106
53
|
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { a as SchemaValidator };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { removeNonNumeric as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as validateCep };
|