@arkyn/server 3.0.1-beta.118 → 3.0.1-beta.119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +9 -9
- package/dist/bundle.umd.cjs +2 -2
- package/dist/services/apiService.js +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -807,14 +807,14 @@ async function W(e) {
|
|
|
807
807
|
responseHeaders: d,
|
|
808
808
|
status: $,
|
|
809
809
|
token: xs,
|
|
810
|
-
rawUrl:
|
|
810
|
+
rawUrl: O
|
|
811
811
|
} = e;
|
|
812
812
|
if (process.env.NODE_ENV !== "development")
|
|
813
813
|
try {
|
|
814
|
-
const m = new URL(
|
|
814
|
+
const m = new URL(O);
|
|
815
815
|
let D = "https";
|
|
816
816
|
m.protocol === "http:" && (D = "http");
|
|
817
|
-
const
|
|
817
|
+
const B = JSON.stringify({
|
|
818
818
|
domainUrl: m.protocol + "//" + m.host,
|
|
819
819
|
pathnameUrl: m.pathname,
|
|
820
820
|
trafficSourceId: r,
|
|
@@ -832,7 +832,7 @@ async function W(e) {
|
|
|
832
832
|
"Content-Type": "application/json",
|
|
833
833
|
Authorization: `Bearer ${t}`
|
|
834
834
|
};
|
|
835
|
-
await fetch(n, { method: "POST", body:
|
|
835
|
+
await fetch(n, { method: "POST", body: B, headers: P });
|
|
836
836
|
} catch (m) {
|
|
837
837
|
p({
|
|
838
838
|
debugs: [`Error sending request: ${m}`],
|
|
@@ -959,7 +959,7 @@ class Es {
|
|
|
959
959
|
onDebug(s, t, n) {
|
|
960
960
|
if (this.enableDebug) {
|
|
961
961
|
const r = [];
|
|
962
|
-
r.push(`Base URL: ${this.baseUrl}`), r.push(`Endpoint: ${s}`), r.push(`Method: ${t}`), n[0] && r.push(`Headers: ${JSON.stringify(n[0])}`), n[1] && r.push(`Body: ${JSON.stringify(n[1])}`), p({ debugs: r, name: "
|
|
962
|
+
r.push(`Base URL: ${this.baseUrl}`), r.push(`Endpoint: ${s}`), r.push(`Method: ${t}`), n[0] && r.push(`Headers: ${JSON.stringify(n[0])}`), n[1] && r.push(`Body: ${JSON.stringify(n[1])}`), p({ debugs: r, name: "ApiDebug", scheme: "yellow" });
|
|
963
963
|
}
|
|
964
964
|
}
|
|
965
965
|
generateHeaders(s, t) {
|
|
@@ -1063,7 +1063,7 @@ function $s(e, s) {
|
|
|
1063
1063
|
var t, n, r;
|
|
1064
1064
|
return e != null && e.message && typeof (e == null ? void 0 : e.message) == "string" ? e == null ? void 0 : e.message : e != null && e.error && typeof (e == null ? void 0 : e.error) == "string" ? e == null ? void 0 : e.error : (t = e == null ? void 0 : e.error) != null && t.message && typeof ((n = e == null ? void 0 : e.error) == null ? void 0 : n.message) == "string" ? (r = e == null ? void 0 : e.error) == null ? void 0 : r.message : s != null && s.statusText && typeof (s == null ? void 0 : s.statusText) == "string" ? s == null ? void 0 : s.statusText : "Missing error message";
|
|
1065
1065
|
}
|
|
1066
|
-
function
|
|
1066
|
+
function Os(e) {
|
|
1067
1067
|
switch (!0) {
|
|
1068
1068
|
case e instanceof Response:
|
|
1069
1069
|
return e;
|
|
@@ -1140,7 +1140,7 @@ function ts([
|
|
|
1140
1140
|
data: t.data
|
|
1141
1141
|
};
|
|
1142
1142
|
}
|
|
1143
|
-
function
|
|
1143
|
+
function Bs(e, s = "") {
|
|
1144
1144
|
const t = new URL(e.url);
|
|
1145
1145
|
if (s === "") return t.searchParams;
|
|
1146
1146
|
const n = Array.from(
|
|
@@ -1478,11 +1478,11 @@ export {
|
|
|
1478
1478
|
Z as Updated,
|
|
1479
1479
|
vs as decodeRequestBody,
|
|
1480
1480
|
$s as decodeRequestErrorMessage,
|
|
1481
|
-
|
|
1481
|
+
Os as errorHandler,
|
|
1482
1482
|
p as flushDebugLogs,
|
|
1483
1483
|
es as formAsyncParse,
|
|
1484
1484
|
ts as formParse,
|
|
1485
|
-
|
|
1485
|
+
Bs as getScopedParams,
|
|
1486
1486
|
ks as validateCep,
|
|
1487
1487
|
ws as validateCnpj,
|
|
1488
1488
|
Js as validateCpf,
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(i,h){typeof exports=="object"&&typeof module<"u"?h(exports,require("zod"),require("@arkyn/shared"),require("node:dns"),require("@arkyn/templates")):typeof define=="function"&&define.amd?define(["exports","zod","@arkyn/shared","node:dns","@arkyn/templates"],h):(i=typeof globalThis<"u"?globalThis:i||self,h(i["@arkyn/server"]={},null,i.shared,i.dns,i.templates))})(this,function(i,h,d,D,L){"use strict";var ws=Object.defineProperty;var js=(i,h,d)=>h in i?ws(i,h,{enumerable:!0,configurable:!0,writable:!0,value:d}):i[h]=d;var l=(i,h,d)=>js(i,typeof h!="symbol"?h+"":h,d);const z={};class x{static setIgnoreFile(s){this.ignoreFiles.push(s)}static clearIgnoreFiles(){this.ignoreFiles=[]}static getCaller(){const s=process.cwd(),r=(new Error().stack||"").split(`
|
|
2
2
|
`).map(y=>y.trim());let a=2;for(;a<r.length&&(r[a].includes("node:internal")||r[a].includes("/node_modules/"));)a++;if(this.ignoreFiles.length>0)for(;a<r.length&&this.ignoreFiles.some(y=>r[a].includes(y));)a++;const u=r[a]||"";let c="Unknown function",o="Unknown caller";const f=u.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)c=f[1],o=f[2];else{const y=u.match(/at\s+(.+)/);if(y){o=y[1];const R=o.match(/at\s+([^(\s]+)\s+/);R&&R[1]!=="new"&&(c=R[1])}}o.includes("(")&&(o=o.substring(o.indexOf("(")+1,o.lastIndexOf(")"))),o=o.split(":").slice(0,-2).join(":");try{o=z.relative(s,o)}catch{}return{functionName:c,callerInfo:o}}}l(x,"ignoreFiles",[]);function g(e){var t;if(process.env.NODE_ENV==="development"||((t=process.env)==null?void 0:t.DEBUG_MODE)==="true"){const a=`${{yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m",green:"\x1B[32m"}[e.scheme]}[${e.name}]\x1B[0m`;let u=`
|
|
3
3
|
`;e.debugs.forEach(c=>{u+=`${a} ${c.trim()}
|
|
4
|
-
`}),console.log(u)}}class m{constructor(){l(this,"_cause");l(this,"_name","BadResponse");l(this,"_status",500);l(this,"_statusText","Unknown error")}get cause(){return this._cause}set cause(s){this._cause=s}get name(){return this._name}set name(s){this._name=s}get status(){return this._status}set status(s){this._status=s}get statusText(){return this._statusText}set statusText(s){this._statusText=s}onDebug(){const s=[],{callerInfo:t,functionName:n}=x.getCaller();s.push(`Caller Function: ${n}`),s.push(`Caller Location: ${t}`),this._statusText&&s.push(`Message: ${this._statusText}`),this._cause&&s.push(`Cause: ${JSON.stringify(this._cause)}`),g({scheme:"red",name:this._name,debugs:s})}makeBody(){return{name:this._name,message:this._statusText,cause:this._cause}}}class P extends m{constructor(s,t){super(),this.name="BadGateway",this.status=502,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class S extends m{constructor(s,t){super(),this.name="BadRequest",this.status=400,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class B extends m{constructor(s,t){super(),this.name="Conflict",this.status=409,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class O extends m{constructor(s,t){super(),this.name="Forbidden",this.status=403,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class $ extends m{constructor(s,t){super(),this.name="NotFound",this.status=404,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class k extends m{constructor(s,t){super(),this.name="NotImplemented",this.status=501,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class v extends m{constructor(s,t){super(),this.name="ServerError",this.status=500,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class w extends m{constructor(s,t){super(),this.name="Unauthorized",this.status=401,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class N extends m{constructor(s){super(),this.name="UnprocessableEntity",this.status=422,this.statusText=s.message||"Unprocessable entity",this.cause={data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class T{constructor(){l(this,"_body",null);l(this,"_name","SuccessResponse");l(this,"_status",200);l(this,"_statusText","OK")}get body(){return this._body}set body(s){this._body=s??null}get name(){return this._name}set name(s){this._name=s}get status(){return this._status}set status(s){this._status=s}get statusText(){return this._statusText}set statusText(s){this._statusText=s}onDebug(s){const t=[],{callerInfo:n,functionName:r}=x.getCaller();t.push(`Caller Function: ${r}`),t.push(`Caller Location: ${n}`),this.statusText&&t.push(`Message: ${this.statusText}`),s&&t.push(`Body: ${JSON.stringify(s)}`),g({scheme:"red",name:this.name,debugs:t})}makeBody(){return{name:this.name,message:this.statusText,body:this.body}}}class j extends T{constructor(s,t){super(),this.name="Created",this.status=201,this.statusText=s,this.body=t||void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class J extends T{constructor(s,t){super(),this.name="Found",this.status=302,this.statusText=s,this.body=t||void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class C extends T{constructor(s){super(),this.name="NoContent",this.status=204,this.statusText=s,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(null,s)}}class I extends T{constructor(s,t){super(),this.name="Success",this.status=200,this.statusText=s,this.body=t||void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class _ extends T{constructor(s,t){super(),this.name="Updated",this.status=200,this.statusText=s,this.body=t||void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class M{static mapHeaders(s){return s instanceof Headers?Object.fromEntries(s.entries()):typeof s=="object"?Object.entries(s).reduce((t,[n,r])=>(typeof r=="string"?t[n]=r:Array.isArray(r)?t[n]=r.join(", "):t[n]=JSON.stringify(r),t),{}):{}}static mapQueryParams(s){const t={};return s.forEach((n,r)=>t[r]=n),t}static handle(s){return{rawUrl:s.rawUrl,status:s.status,method:s.method,token:null,elapsedTime:s.elapsedTime,requestHeaders:this.mapHeaders(s.requestHeaders),requestBody:s.requestBody||null,queryParams:{...this.mapQueryParams(s.queryParams),...s.urlParams},responseHeaders:this.mapHeaders(s.responseHeaders),responseBody:s.responseBody||null}}}class E{static setConfig(s){if(this.config)return;const{trafficSourceId:t,userToken:n,logBaseApiUrl:r}=s,u=`${r||"http://95.216.190.158:8081"}/ingest-log`;this.config={trafficSourceId:t,userToken:n,apiUrl:u}}static getConfig(){return this.config}static resetConfig(){this.config=void 0}}l(E,"config");async function V(e){const s=E.getConfig();if(!s)return;const{userToken:t,apiUrl:n,trafficSourceId:r}=s,{elapsedTime:a,method:u,queryParams:c,requestBody:o,requestHeaders:f,responseBody:y,responseHeaders:R,status:Bs,token:Js,rawUrl:Os}=e;if(process.env.NODE_ENV!=="development")try{const p=new URL(Os);let F="https";p.protocol==="http:"&&(F="http");const $s=JSON.stringify({domainUrl:p.protocol+"//"+p.host,pathnameUrl:p.pathname,trafficSourceId:r,status:Bs,protocol:F,method:u.toLowerCase(),trafficUserId:null,elapsedTime:a,requestHeaders:JSON.stringify(f),requestBody:JSON.stringify(o),queryParams:JSON.stringify(c),responseHeaders:JSON.stringify(R),responseBody:JSON.stringify(y)}),ks={"Content-Type":"application/json",Authorization:`Bearer ${t}`};await fetch(n,{method:"POST",body:$s,headers:ks})}catch(p){g({debugs:[`Error sending request: ${p}`],name:"LogError",scheme:"red"})}}async function b(e){let s=e.url;e.urlParams&&Object.entries(e.urlParams).forEach(([n,r])=>{s=s.replaceAll(`:${n}`,r)});const t={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const n=performance.now(),r={...e.headers,"Content-Type":"application/json"},a=await fetch(s,{headers:r,method:e.method,body:e.body?JSON.stringify(e.body):void 0}),u=performance.now()-n,c=a.status;let o=null;try{o=await a.json()}catch{o=null}const f=M.handle({elapsedTime:u,method:e.method,queryParams:new URL(s).searchParams,requestHeaders:r,requestBody:e.body,responseBody:o,responseHeaders:a.headers,status:c,rawUrl:e.url,urlParams:e.urlParams});return V(f),a.ok?{success:!0,status:c,message:(o==null?void 0:o.message)||t[e.method],response:o,cause:null}:{success:!1,status:c,message:(o==null?void 0:o.message)||a.statusText||"Request failed",response:o,cause:null}}catch(n){return g({debugs:[`Network error or request failed: ${n}`],name:"MakeRequestError",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:n instanceof Error?n.message:String(n)}}}async function Z(e){return b({method:"DELETE",url:e.url,urlParams:e.urlParams,headers:e.headers,body:e.body})}async function G(e){return b({method:"GET",url:e.url,urlParams:e.urlParams,headers:e.headers})}async function W(e){return b({method:"PATCH",url:e.url,urlParams:e.urlParams,headers:e.headers,body:e.body})}async function Y(e){return b({method:"POST",url:e.url,urlParams:e.urlParams,headers:e.headers,body:e.body})}async function K(e){return b({method:"PUT",url:e.url,urlParams:e.urlParams,headers:e.headers,body:e.body})}class Q{constructor(s){l(this,"baseUrl");l(this,"baseHeaders");l(this,"baseToken");l(this,"enableDebug");this.baseUrl=s.baseUrl,this.baseHeaders=s.baseHeaders||void 0,this.baseToken=s.baseToken||void 0,this.enableDebug=s.enableDebug||!1}onDebug(s,t,n){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${s}`),r.push(`Method: ${t}`),n[0]&&r.push(`Headers: ${JSON.stringify(n[0])}`),n[1]&&r.push(`Body: ${JSON.stringify(n[1])}`),g({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateHeaders(s,t){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),s&&(n={...n,...s}),t&&(n={...n,Authorization:`Bearer ${t}`}),n}async get(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token);return this.onDebug(s,"get",[n]),await G({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n})}async post(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token),r=t==null?void 0:t.body;return this.onDebug(s,"post",[n,r]),await Y({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n,body:r})}async put(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token),r=t==null?void 0:t.body;return this.onDebug(s,"put",[n,r]),await K({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n,body:r})}async patch(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token),r=t==null?void 0:t.body;return this.onDebug(s,"patch",[n,r]),await W({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n,body:r})}async delete(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token),r=t==null?void 0:t.body;return this.onDebug(s,"delete",[n,r]),await Z({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n,body:r})}}async function X(e){let s;const t=await e.arrayBuffer(),n=new TextDecoder().decode(t);try{s=JSON.parse(n)}catch{try{if(n.includes("=")){const a=new URLSearchParams(n);s=Object.fromEntries(a.entries())}else throw new S("Invalid URLSearchParams format")}catch{throw new S("Failed to extract data from request")}}return s}function ss(e,s){var t,n,r;return e!=null&&e.message&&typeof(e==null?void 0:e.message)=="string"?e==null?void 0:e.message:e!=null&&e.error&&typeof(e==null?void 0:e.error)=="string"?e==null?void 0:e.error:(t=e==null?void 0:e.error)!=null&&t.message&&typeof((n=e==null?void 0:e.error)==null?void 0:n.message)=="string"?(r=e==null?void 0:e.error)==null?void 0:r.message:s!=null&&s.statusText&&typeof(s==null?void 0:s.statusText)=="string"?s==null?void 0:s.statusText:"Missing error message"}function es(e){switch(!0){case e instanceof Response:return e;case e instanceof J:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof _:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof C:return e.toResponse()}switch(!0){case e instanceof P:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof B:return e.toResponse();case e instanceof O:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof v:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof N:return e.toResponse()}return new v("Server error",e).toResponse()}async function U([e,s]){const t=await s.safeParseAsync(e);if(t.success===!1){const n=Object.fromEntries(t.error.issues.map(r=>[r.path.join("."),r.message]));return{success:t.success,fieldErrors:n,fields:e}}else return{success:t.success,data:t.data}}function q([e,s]){const t=s.safeParse(e);if(t.success===!1){const n=Object.fromEntries(t.error.issues.map(r=>[r.path.join("."),r.message]));return{success:t.success,fieldErrors:n,fields:e}}else return{success:t.success,data:t.data}}function ts(e,s=""){const t=new URL(e.url);if(s==="")return t.searchParams;const n=Array.from(t.searchParams.entries()).filter(([r])=>r.startsWith(`${s}:`)).map(([r,a])=>[r.replace(`${s}:`,""),a]);return new URLSearchParams(n)}function ns(e){const s="Error validating:",t=e.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[s,...t].join(`
|
|
5
|
-
`)}class rs{constructor(s){this.schema=s}isValid(s){return this.schema.safeParse(s).success}safeValidate(s){return this.schema.safeParse(s)}validate(s){try{return this.schema.parse(s)}catch(t){throw new v(ns(t))}}formValidate(s,t){const n=q([s,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new N({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:t})}return n.data}async formAsyncValidate(s,t){const n=await U([s,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new N({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:t})}return n.data}}function is(e){if(!(/^\d{5}-\d{3}$/.test(e)||/^\d{8}$/.test(e)))return!1;const t=d.removeNonNumeric(e),n=8,r=/^\d{8}$/.test(t);return t.length===n&&r}function os(e){return e.length!==14}function as(e){const[s]=e;return[...e].every(t=>t===s)}function A(e,s){let t=0;for(let r=0;r<s.length;r++)t+=parseInt(e[r])*s[r];const n=t%11;return n<2?0:11-n}function us(e){return e.slice(12)}function cs(e){if(!e||e.length>18||e.length<14||/\s/.test(e))return!1;const t=d.removeNonNumeric(e);if(os(t)||as(t))return!1;const n=t.slice(0,12),r=A(n,[5,4,3,2,9,8,7,6,5,4,3,2]),a=A(n+r,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return us(t)===`${r}${a}`}function ls(e){return e.length!==11}function hs(e){const[s]=e;return[...e].every(t=>t===s)}function H(e,s){let t=0;for(const r of e)s>1&&(t+=parseInt(r)*s--);const n=t%11;return n<2?0:11-n}function fs(e){return e.slice(9)}function ds(e){if(!e||e.length>14||e.length<11||/\s/.test(e))return!1;const t=d.removeNonNumeric(e);if(ls(t)||hs(t))return!1;const n=H(t,10),r=H(t,11);return fs(t)===`${n}${r}`}function ms(e,s){const t=(s==null?void 0:s.inputFormat)||"brazilianDate",n=(s==null?void 0:s.minYear)||1900,r=(s==null?void 0:s.maxYear)||3e3,a=new d.ValidateDateService;a.validateInputFormat(t);let u,c,o;const f=e.split(/[-/]/).map(Number);if(f.length!==3)return!1;try{switch(t){case"brazilianDate":[u,c,o]=f,a.validateDateParts(o,c,u);break;case"isoDate":[c,u,o]=f,a.validateDateParts(o,c,u);break;case"timestamp":[o,c,u]=f,a.validateDateParts(o,c,u);break}return!(o<n||o>r)}catch{return!1}}function ys(e){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)}function gs(e){return!(e.length===0||e.length>64||e.startsWith(".")||e.endsWith(".")||e.includes("..")||!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e))}function ps(e){return!(e.length===0||e.length>63||e.startsWith("-")||e.endsWith("-")||!/^[a-zA-Z0-9-]+$/.test(e))}function Ts(e){if(e.length===0||e.length>253||e.startsWith(".")||e.endsWith(".")||e.startsWith("-")||e.endsWith("-"))return!1;const s=e.split(".");if(s.length<2)return!1;for(const n of s)if(!ps(n))return!1;const t=s[s.length-1];return!(t.length<2||!/^[a-zA-Z]+$/.test(t))}function bs(e){const s=e.split("@");if(s.length!==2)return!1;const[t,n]=s;return!(!gs(t)||!Ts(n))}function Rs(e){const s=e.split("@");return s.length===2?s[1].toLowerCase():null}const xs=["MX","A","AAAA"];async function Ss(e,s){var t;try{return await((t=D==null?void 0:D.promises)==null?void 0:t.resolve(e,s)),!0}catch{return!1}}async function vs(e){for(const s of xs)if(await Ss(e,s))return!0;return!1}async function Ns(e){if(!e||typeof e!="string")return!1;const s=e.trim();if(!ys(s)||!bs(s))return!1;const t=Rs(s);return t?await vs(t):!1}function Ds(e){if(!e)return!1;const s=e.length>=8,t=/[A-Z]/.test(e),n=/[a-z]/.test(e),r=/\d/.test(e),a=/[!@#$%^&*(),.?":;{}|<>_\-+=~`[\]\\\/]/.test(e);return[s,t,n,r,a].every(u=>u)}function Es(e){for(const s of L.countries){const t=s.code,n=s.prefix?`-${s.prefix}`:"",r=s.mask.replace(/[^_]/g,"").length;if(s.iso==="BR"){if(new RegExp(`^\\${t} \\d{2}9?\\d{8}$`).test(e))return!0;continue}if(new RegExp(`^\\${t}${n} \\d{${r}}$`).test(e))return!0}return!1}function Ps(e){if(!e||!/^[0-9a-zA-Z.-]+$/.test(e))return!1;const t=e.replace(/[^a-zA-Z0-9]/g,"");return t.length<7||t.length>9?!1:/^[0-9]{7,8}[0-9Xx]?$/.test(t)}i.ApiService=Q,i.BadGateway=P,i.BadRequest=S,i.Conflict=B,i.Created=j,i.DebugService=x,i.Forbidden=O,i.Found=J,i.LogService=E,i.NoContent=C,i.NotFound=$,i.NotImplemented=k,i.SchemaValidator=rs,i.ServerError=v,i.Success=
|
|
4
|
+
`}),console.log(u)}}class m{constructor(){l(this,"_cause");l(this,"_name","BadResponse");l(this,"_status",500);l(this,"_statusText","Unknown error")}get cause(){return this._cause}set cause(s){this._cause=s}get name(){return this._name}set name(s){this._name=s}get status(){return this._status}set status(s){this._status=s}get statusText(){return this._statusText}set statusText(s){this._statusText=s}onDebug(){const s=[],{callerInfo:t,functionName:n}=x.getCaller();s.push(`Caller Function: ${n}`),s.push(`Caller Location: ${t}`),this._statusText&&s.push(`Message: ${this._statusText}`),this._cause&&s.push(`Cause: ${JSON.stringify(this._cause)}`),g({scheme:"red",name:this._name,debugs:s})}makeBody(){return{name:this._name,message:this._statusText,cause:this._cause}}}class P extends m{constructor(s,t){super(),this.name="BadGateway",this.status=502,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class S extends m{constructor(s,t){super(),this.name="BadRequest",this.status=400,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class B extends m{constructor(s,t){super(),this.name="Conflict",this.status=409,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class O extends m{constructor(s,t){super(),this.name="Forbidden",this.status=403,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class $ extends m{constructor(s,t){super(),this.name="NotFound",this.status=404,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class k extends m{constructor(s,t){super(),this.name="NotImplemented",this.status=501,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class v extends m{constructor(s,t){super(),this.name="ServerError",this.status=500,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class w extends m{constructor(s,t){super(),this.name="Unauthorized",this.status=401,this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class N extends m{constructor(s){super(),this.name="UnprocessableEntity",this.status=422,this.statusText=s.message||"Unprocessable entity",this.cause={data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.makeBody()),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.makeBody(),s)}}class T{constructor(){l(this,"_body",null);l(this,"_name","SuccessResponse");l(this,"_status",200);l(this,"_statusText","OK")}get body(){return this._body}set body(s){this._body=s??null}get name(){return this._name}set name(s){this._name=s}get status(){return this._status}set status(s){this._status=s}get statusText(){return this._statusText}set statusText(s){this._statusText=s}onDebug(s){const t=[],{callerInfo:n,functionName:r}=x.getCaller();t.push(`Caller Function: ${r}`),t.push(`Caller Location: ${n}`),this.statusText&&t.push(`Message: ${this.statusText}`),s&&t.push(`Body: ${JSON.stringify(s)}`),g({scheme:"red",name:this.name,debugs:t})}makeBody(){return{name:this.name,message:this.statusText,body:this.body}}}class j extends T{constructor(s,t){super(),this.name="Created",this.status=201,this.statusText=s,this.body=t||void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class J extends T{constructor(s,t){super(),this.name="Found",this.status=302,this.statusText=s,this.body=t||void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class C extends T{constructor(s){super(),this.name="NoContent",this.status=204,this.statusText=s,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(null,s)}}class _ extends T{constructor(s,t){super(),this.name="Success",this.status=200,this.statusText=s,this.body=t||void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class I extends T{constructor(s,t){super(),this.name="Updated",this.status=200,this.statusText=s,this.body=t||void 0,this.onDebug()}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class M{static mapHeaders(s){return s instanceof Headers?Object.fromEntries(s.entries()):typeof s=="object"?Object.entries(s).reduce((t,[n,r])=>(typeof r=="string"?t[n]=r:Array.isArray(r)?t[n]=r.join(", "):t[n]=JSON.stringify(r),t),{}):{}}static mapQueryParams(s){const t={};return s.forEach((n,r)=>t[r]=n),t}static handle(s){return{rawUrl:s.rawUrl,status:s.status,method:s.method,token:null,elapsedTime:s.elapsedTime,requestHeaders:this.mapHeaders(s.requestHeaders),requestBody:s.requestBody||null,queryParams:{...this.mapQueryParams(s.queryParams),...s.urlParams},responseHeaders:this.mapHeaders(s.responseHeaders),responseBody:s.responseBody||null}}}class E{static setConfig(s){if(this.config)return;const{trafficSourceId:t,userToken:n,logBaseApiUrl:r}=s,u=`${r||"http://95.216.190.158:8081"}/ingest-log`;this.config={trafficSourceId:t,userToken:n,apiUrl:u}}static getConfig(){return this.config}static resetConfig(){this.config=void 0}}l(E,"config");async function V(e){const s=E.getConfig();if(!s)return;const{userToken:t,apiUrl:n,trafficSourceId:r}=s,{elapsedTime:a,method:u,queryParams:c,requestBody:o,requestHeaders:f,responseBody:y,responseHeaders:R,status:Bs,token:Js,rawUrl:Os}=e;if(process.env.NODE_ENV!=="development")try{const p=new URL(Os);let F="https";p.protocol==="http:"&&(F="http");const $s=JSON.stringify({domainUrl:p.protocol+"//"+p.host,pathnameUrl:p.pathname,trafficSourceId:r,status:Bs,protocol:F,method:u.toLowerCase(),trafficUserId:null,elapsedTime:a,requestHeaders:JSON.stringify(f),requestBody:JSON.stringify(o),queryParams:JSON.stringify(c),responseHeaders:JSON.stringify(R),responseBody:JSON.stringify(y)}),ks={"Content-Type":"application/json",Authorization:`Bearer ${t}`};await fetch(n,{method:"POST",body:$s,headers:ks})}catch(p){g({debugs:[`Error sending request: ${p}`],name:"LogError",scheme:"red"})}}async function b(e){let s=e.url;e.urlParams&&Object.entries(e.urlParams).forEach(([n,r])=>{s=s.replaceAll(`:${n}`,r)});const t={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const n=performance.now(),r={...e.headers,"Content-Type":"application/json"},a=await fetch(s,{headers:r,method:e.method,body:e.body?JSON.stringify(e.body):void 0}),u=performance.now()-n,c=a.status;let o=null;try{o=await a.json()}catch{o=null}const f=M.handle({elapsedTime:u,method:e.method,queryParams:new URL(s).searchParams,requestHeaders:r,requestBody:e.body,responseBody:o,responseHeaders:a.headers,status:c,rawUrl:e.url,urlParams:e.urlParams});return V(f),a.ok?{success:!0,status:c,message:(o==null?void 0:o.message)||t[e.method],response:o,cause:null}:{success:!1,status:c,message:(o==null?void 0:o.message)||a.statusText||"Request failed",response:o,cause:null}}catch(n){return g({debugs:[`Network error or request failed: ${n}`],name:"MakeRequestError",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:n instanceof Error?n.message:String(n)}}}async function Z(e){return b({method:"DELETE",url:e.url,urlParams:e.urlParams,headers:e.headers,body:e.body})}async function G(e){return b({method:"GET",url:e.url,urlParams:e.urlParams,headers:e.headers})}async function W(e){return b({method:"PATCH",url:e.url,urlParams:e.urlParams,headers:e.headers,body:e.body})}async function Y(e){return b({method:"POST",url:e.url,urlParams:e.urlParams,headers:e.headers,body:e.body})}async function K(e){return b({method:"PUT",url:e.url,urlParams:e.urlParams,headers:e.headers,body:e.body})}class Q{constructor(s){l(this,"baseUrl");l(this,"baseHeaders");l(this,"baseToken");l(this,"enableDebug");this.baseUrl=s.baseUrl,this.baseHeaders=s.baseHeaders||void 0,this.baseToken=s.baseToken||void 0,this.enableDebug=s.enableDebug||!1}onDebug(s,t,n){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${s}`),r.push(`Method: ${t}`),n[0]&&r.push(`Headers: ${JSON.stringify(n[0])}`),n[1]&&r.push(`Body: ${JSON.stringify(n[1])}`),g({debugs:r,name:"ApiDebug",scheme:"yellow"})}}generateHeaders(s,t){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),s&&(n={...n,...s}),t&&(n={...n,Authorization:`Bearer ${t}`}),n}async get(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token);return this.onDebug(s,"get",[n]),await G({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n})}async post(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token),r=t==null?void 0:t.body;return this.onDebug(s,"post",[n,r]),await Y({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n,body:r})}async put(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token),r=t==null?void 0:t.body;return this.onDebug(s,"put",[n,r]),await K({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n,body:r})}async patch(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token),r=t==null?void 0:t.body;return this.onDebug(s,"patch",[n,r]),await W({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n,body:r})}async delete(s,t){const n=this.generateHeaders((t==null?void 0:t.headers)||{},t==null?void 0:t.token),r=t==null?void 0:t.body;return this.onDebug(s,"delete",[n,r]),await Z({url:this.baseUrl+s,urlParams:(t==null?void 0:t.urlParams)||{},headers:n,body:r})}}async function X(e){let s;const t=await e.arrayBuffer(),n=new TextDecoder().decode(t);try{s=JSON.parse(n)}catch{try{if(n.includes("=")){const a=new URLSearchParams(n);s=Object.fromEntries(a.entries())}else throw new S("Invalid URLSearchParams format")}catch{throw new S("Failed to extract data from request")}}return s}function ss(e,s){var t,n,r;return e!=null&&e.message&&typeof(e==null?void 0:e.message)=="string"?e==null?void 0:e.message:e!=null&&e.error&&typeof(e==null?void 0:e.error)=="string"?e==null?void 0:e.error:(t=e==null?void 0:e.error)!=null&&t.message&&typeof((n=e==null?void 0:e.error)==null?void 0:n.message)=="string"?(r=e==null?void 0:e.error)==null?void 0:r.message:s!=null&&s.statusText&&typeof(s==null?void 0:s.statusText)=="string"?s==null?void 0:s.statusText:"Missing error message"}function es(e){switch(!0){case e instanceof Response:return e;case e instanceof J:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof _:return e.toResponse();case e instanceof C:return e.toResponse()}switch(!0){case e instanceof P:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof B:return e.toResponse();case e instanceof O:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof v:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof N:return e.toResponse()}return new v("Server error",e).toResponse()}async function U([e,s]){const t=await s.safeParseAsync(e);if(t.success===!1){const n=Object.fromEntries(t.error.issues.map(r=>[r.path.join("."),r.message]));return{success:t.success,fieldErrors:n,fields:e}}else return{success:t.success,data:t.data}}function q([e,s]){const t=s.safeParse(e);if(t.success===!1){const n=Object.fromEntries(t.error.issues.map(r=>[r.path.join("."),r.message]));return{success:t.success,fieldErrors:n,fields:e}}else return{success:t.success,data:t.data}}function ts(e,s=""){const t=new URL(e.url);if(s==="")return t.searchParams;const n=Array.from(t.searchParams.entries()).filter(([r])=>r.startsWith(`${s}:`)).map(([r,a])=>[r.replace(`${s}:`,""),a]);return new URLSearchParams(n)}function ns(e){const s="Error validating:",t=e.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[s,...t].join(`
|
|
5
|
+
`)}class rs{constructor(s){this.schema=s}isValid(s){return this.schema.safeParse(s).success}safeValidate(s){return this.schema.safeParse(s)}validate(s){try{return this.schema.parse(s)}catch(t){throw new v(ns(t))}}formValidate(s,t){const n=q([s,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new N({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:t})}return n.data}async formAsyncValidate(s,t){const n=await U([s,this.schema]);if(!n.success){const r=Object.keys(n.fieldErrors)[0];throw new N({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:t})}return n.data}}function is(e){if(!(/^\d{5}-\d{3}$/.test(e)||/^\d{8}$/.test(e)))return!1;const t=d.removeNonNumeric(e),n=8,r=/^\d{8}$/.test(t);return t.length===n&&r}function os(e){return e.length!==14}function as(e){const[s]=e;return[...e].every(t=>t===s)}function A(e,s){let t=0;for(let r=0;r<s.length;r++)t+=parseInt(e[r])*s[r];const n=t%11;return n<2?0:11-n}function us(e){return e.slice(12)}function cs(e){if(!e||e.length>18||e.length<14||/\s/.test(e))return!1;const t=d.removeNonNumeric(e);if(os(t)||as(t))return!1;const n=t.slice(0,12),r=A(n,[5,4,3,2,9,8,7,6,5,4,3,2]),a=A(n+r,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return us(t)===`${r}${a}`}function ls(e){return e.length!==11}function hs(e){const[s]=e;return[...e].every(t=>t===s)}function H(e,s){let t=0;for(const r of e)s>1&&(t+=parseInt(r)*s--);const n=t%11;return n<2?0:11-n}function fs(e){return e.slice(9)}function ds(e){if(!e||e.length>14||e.length<11||/\s/.test(e))return!1;const t=d.removeNonNumeric(e);if(ls(t)||hs(t))return!1;const n=H(t,10),r=H(t,11);return fs(t)===`${n}${r}`}function ms(e,s){const t=(s==null?void 0:s.inputFormat)||"brazilianDate",n=(s==null?void 0:s.minYear)||1900,r=(s==null?void 0:s.maxYear)||3e3,a=new d.ValidateDateService;a.validateInputFormat(t);let u,c,o;const f=e.split(/[-/]/).map(Number);if(f.length!==3)return!1;try{switch(t){case"brazilianDate":[u,c,o]=f,a.validateDateParts(o,c,u);break;case"isoDate":[c,u,o]=f,a.validateDateParts(o,c,u);break;case"timestamp":[o,c,u]=f,a.validateDateParts(o,c,u);break}return!(o<n||o>r)}catch{return!1}}function ys(e){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)}function gs(e){return!(e.length===0||e.length>64||e.startsWith(".")||e.endsWith(".")||e.includes("..")||!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e))}function ps(e){return!(e.length===0||e.length>63||e.startsWith("-")||e.endsWith("-")||!/^[a-zA-Z0-9-]+$/.test(e))}function Ts(e){if(e.length===0||e.length>253||e.startsWith(".")||e.endsWith(".")||e.startsWith("-")||e.endsWith("-"))return!1;const s=e.split(".");if(s.length<2)return!1;for(const n of s)if(!ps(n))return!1;const t=s[s.length-1];return!(t.length<2||!/^[a-zA-Z]+$/.test(t))}function bs(e){const s=e.split("@");if(s.length!==2)return!1;const[t,n]=s;return!(!gs(t)||!Ts(n))}function Rs(e){const s=e.split("@");return s.length===2?s[1].toLowerCase():null}const xs=["MX","A","AAAA"];async function Ss(e,s){var t;try{return await((t=D==null?void 0:D.promises)==null?void 0:t.resolve(e,s)),!0}catch{return!1}}async function vs(e){for(const s of xs)if(await Ss(e,s))return!0;return!1}async function Ns(e){if(!e||typeof e!="string")return!1;const s=e.trim();if(!ys(s)||!bs(s))return!1;const t=Rs(s);return t?await vs(t):!1}function Ds(e){if(!e)return!1;const s=e.length>=8,t=/[A-Z]/.test(e),n=/[a-z]/.test(e),r=/\d/.test(e),a=/[!@#$%^&*(),.?":;{}|<>_\-+=~`[\]\\\/]/.test(e);return[s,t,n,r,a].every(u=>u)}function Es(e){for(const s of L.countries){const t=s.code,n=s.prefix?`-${s.prefix}`:"",r=s.mask.replace(/[^_]/g,"").length;if(s.iso==="BR"){if(new RegExp(`^\\${t} \\d{2}9?\\d{8}$`).test(e))return!0;continue}if(new RegExp(`^\\${t}${n} \\d{${r}}$`).test(e))return!0}return!1}function Ps(e){if(!e||!/^[0-9a-zA-Z.-]+$/.test(e))return!1;const t=e.replace(/[^a-zA-Z0-9]/g,"");return t.length<7||t.length>9?!1:/^[0-9]{7,8}[0-9Xx]?$/.test(t)}i.ApiService=Q,i.BadGateway=P,i.BadRequest=S,i.Conflict=B,i.Created=j,i.DebugService=x,i.Forbidden=O,i.Found=J,i.LogService=E,i.NoContent=C,i.NotFound=$,i.NotImplemented=k,i.SchemaValidator=rs,i.ServerError=v,i.Success=_,i.Unauthorized=w,i.UnprocessableEntity=N,i.Updated=I,i.decodeRequestBody=X,i.decodeRequestErrorMessage=ss,i.errorHandler=es,i.flushDebugLogs=g,i.formAsyncParse=U,i.formParse=q,i.getScopedParams=ts,i.validateCep=is,i.validateCnpj=cs,i.validateCpf=ds,i.validateDate=ms,i.validateEmail=Ns,i.validatePassword=Ds,i.validatePhone=Es,i.validateRg=Ps,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -25,7 +25,7 @@ class ApiService {
|
|
|
25
25
|
debugs.push(`Headers: ${JSON.stringify(data[0])}`);
|
|
26
26
|
if (data[1])
|
|
27
27
|
debugs.push(`Body: ${JSON.stringify(data[1])}`);
|
|
28
|
-
flushDebugLogs({ debugs, name: "
|
|
28
|
+
flushDebugLogs({ debugs, name: "ApiDebug", scheme: "yellow" });
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
generateHeaders(initHeaders, token) {
|