@arkyn/server 3.0.1-beta.91 → 3.0.1-beta.92
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 +16 -16
- package/dist/bundle.umd.cjs +6 -6
- package/dist/http/successResponses/created.d.ts +4 -1
- package/dist/http/successResponses/created.d.ts.map +1 -1
- package/dist/http/successResponses/created.js +1 -1
- package/dist/http/successResponses/found.d.ts +4 -1
- package/dist/http/successResponses/found.d.ts.map +1 -1
- package/dist/http/successResponses/found.js +1 -1
- package/dist/http/successResponses/success.d.ts +4 -1
- package/dist/http/successResponses/success.d.ts.map +1 -1
- package/dist/http/successResponses/success.js +1 -1
- package/dist/http/successResponses/updated.d.ts +4 -1
- package/dist/http/successResponses/updated.d.ts.map +1 -1
- package/dist/http/successResponses/updated.js +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var w = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var o = (e, t, s) =>
|
|
2
|
+
var U = (e, t, s) => t in e ? w(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
3
|
+
var o = (e, t, s) => U(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
4
|
import "zod";
|
|
5
5
|
import { removeNonNumeric as N } from "@arkyn/shared";
|
|
6
6
|
import "node:dns";
|
|
7
|
-
import { countries as
|
|
7
|
+
import { countries as v } from "@arkyn/templates";
|
|
8
8
|
function g(e) {
|
|
9
9
|
var s;
|
|
10
10
|
if (process.env.NODE_ENV === "development" || ((s = process.env) == null ? void 0 : s.SHOW_ERRORS_IN_CONSOLE) === "true") {
|
|
@@ -343,7 +343,7 @@ class q extends p {
|
|
|
343
343
|
return Response.json(this.body, s);
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
|
-
class
|
|
346
|
+
class F extends p {
|
|
347
347
|
/**
|
|
348
348
|
* Creates an instance of the `NotImplemented` class.
|
|
349
349
|
*
|
|
@@ -439,7 +439,7 @@ class T extends p {
|
|
|
439
439
|
return Response.json(this.body, s);
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
|
-
class
|
|
442
|
+
class H extends p {
|
|
443
443
|
/**
|
|
444
444
|
* Creates an instance of the `Unauthorized` class.
|
|
445
445
|
*
|
|
@@ -584,7 +584,7 @@ class P extends m {
|
|
|
584
584
|
o(this, "headers");
|
|
585
585
|
o(this, "status");
|
|
586
586
|
o(this, "statusText");
|
|
587
|
-
this.body = s, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 201, this.statusText = (n == null ? void 0 : n.statusText) || "Resource created successfully", this.onDebug("Created", s);
|
|
587
|
+
this.body = { ...s, name: "Created", message: n == null ? void 0 : n.message }, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 201, this.statusText = (n == null ? void 0 : n.statusText) || "Resource created successfully", this.onDebug("Created", s);
|
|
588
588
|
}
|
|
589
589
|
/**
|
|
590
590
|
* Converts the `Created` instance into a `Response` object with a JSON body.
|
|
@@ -631,7 +631,7 @@ class Y extends m {
|
|
|
631
631
|
o(this, "headers");
|
|
632
632
|
o(this, "status");
|
|
633
633
|
o(this, "statusText");
|
|
634
|
-
this.body = s, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 302, this.statusText = (n == null ? void 0 : n.statusText) || "Found", this.onDebug("Found", s);
|
|
634
|
+
this.body = { ...s, name: "Found", message: n == null ? void 0 : n.message }, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 302, this.statusText = (n == null ? void 0 : n.statusText) || "Found", this.onDebug("Found", s);
|
|
635
635
|
}
|
|
636
636
|
/**
|
|
637
637
|
* Converts the `Found` instance into a `Response` object.
|
|
@@ -703,7 +703,7 @@ class M extends m {
|
|
|
703
703
|
o(this, "headers");
|
|
704
704
|
o(this, "status");
|
|
705
705
|
o(this, "statusText");
|
|
706
|
-
this.body = s, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 200, this.statusText = (n == null ? void 0 : n.statusText) ?? "OK", this.onDebug("Success", s);
|
|
706
|
+
this.body = { ...s, name: "Success", message: n == null ? void 0 : n.message }, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 200, this.statusText = (n == null ? void 0 : n.statusText) ?? "OK", this.onDebug("Success", s);
|
|
707
707
|
}
|
|
708
708
|
/**
|
|
709
709
|
* Converts the `Success` instance into a `Response` object with a JSON body.
|
|
@@ -747,7 +747,7 @@ class _ extends m {
|
|
|
747
747
|
o(this, "headers");
|
|
748
748
|
o(this, "status");
|
|
749
749
|
o(this, "statusText");
|
|
750
|
-
this.body = s, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 200, this.statusText = (n == null ? void 0 : n.statusText) || "Resource updated successfully", this.onDebug("Updated", s);
|
|
750
|
+
this.body = { ...s, name: "Updated", message: n == null ? void 0 : n.message }, this.headers = (n == null ? void 0 : n.headers) || {}, this.status = (n == null ? void 0 : n.status) || 200, this.statusText = (n == null ? void 0 : n.statusText) || "Resource updated successfully", this.onDebug("Updated", s);
|
|
751
751
|
}
|
|
752
752
|
/**
|
|
753
753
|
* Converts the `Updated` instance into a `Response` object with a JSON body.
|
|
@@ -1105,11 +1105,11 @@ function Es(e) {
|
|
|
1105
1105
|
return e.toResponse();
|
|
1106
1106
|
case e instanceof q:
|
|
1107
1107
|
return e.toResponse();
|
|
1108
|
-
case e instanceof
|
|
1108
|
+
case e instanceof F:
|
|
1109
1109
|
return e.toResponse();
|
|
1110
1110
|
case e instanceof T:
|
|
1111
1111
|
return e.toResponse();
|
|
1112
|
-
case e instanceof
|
|
1112
|
+
case e instanceof H:
|
|
1113
1113
|
return e.toResponse();
|
|
1114
1114
|
case e instanceof R:
|
|
1115
1115
|
return e.toResponse();
|
|
@@ -1455,7 +1455,7 @@ const Js = async (e) => {
|
|
|
1455
1455
|
a
|
|
1456
1456
|
].every((c) => c);
|
|
1457
1457
|
}, ws = (e) => {
|
|
1458
|
-
for (const t of
|
|
1458
|
+
for (const t of v) {
|
|
1459
1459
|
const s = t.code, n = t.prefix ? `-${t.prefix}` : "", r = t.mask.replace(/[^_]/g, "").length;
|
|
1460
1460
|
if (t.iso === "BR") {
|
|
1461
1461
|
if (new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e)) return !0;
|
|
@@ -1464,7 +1464,7 @@ const Js = async (e) => {
|
|
|
1464
1464
|
if (new RegExp(`^\\${s}${n} \\d{${r}}$`).test(e)) return !0;
|
|
1465
1465
|
}
|
|
1466
1466
|
return !1;
|
|
1467
|
-
},
|
|
1467
|
+
}, Us = (e) => {
|
|
1468
1468
|
if (!e || !/^[0-9a-zA-Z.-]+$/.test(e)) return !1;
|
|
1469
1469
|
const s = e.replace(/[^a-zA-Z0-9]/g, "");
|
|
1470
1470
|
return s.length < 7 || s.length > 9 ? !1 : /^[0-9]{7,8}[0-9Xx]?$/.test(s);
|
|
@@ -1481,11 +1481,11 @@ export {
|
|
|
1481
1481
|
Y as Found,
|
|
1482
1482
|
z as NoContent,
|
|
1483
1483
|
q as NotFound,
|
|
1484
|
-
|
|
1484
|
+
F as NotImplemented,
|
|
1485
1485
|
Os as SchemaValidator,
|
|
1486
1486
|
T as ServerError,
|
|
1487
1487
|
M as Success,
|
|
1488
|
-
|
|
1488
|
+
H as Unauthorized,
|
|
1489
1489
|
R as UnprocessableEntity,
|
|
1490
1490
|
_ as Updated,
|
|
1491
1491
|
Rs as decodeErrorMessageFromRequest,
|
|
@@ -1503,5 +1503,5 @@ export {
|
|
|
1503
1503
|
Js as validateEmail,
|
|
1504
1504
|
js as validatePassword,
|
|
1505
1505
|
ws as validatePhone,
|
|
1506
|
-
|
|
1506
|
+
Us as validateRg
|
|
1507
1507
|
};
|
package/dist/bundle.umd.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(u,
|
|
1
|
+
(function(u,f){typeof exports=="object"&&typeof module<"u"?f(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"],f):(u=typeof globalThis<"u"?globalThis:u||self,f(u["@arkyn/server"]={},null,u.shared,null,u.templates))})(this,function(u,f,m,js,Y){"use strict";var $s=Object.defineProperty;var Is=(u,f,m)=>f in u?$s(u,f,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[f]=m;var o=(u,f,m)=>Is(u,typeof f!="symbol"?f+"":f,m);function b(e){var s;if(process.env.NODE_ENV==="development"||((s=process.env)==null?void 0:s.SHOW_ERRORS_IN_CONSOLE)==="true"){const a=`${{yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m",green:"\x1B[32m"}[e.scheme]}[${e.name}]\x1B[0m`;let h=`
|
|
2
2
|
`;e.debugs.forEach(l=>{h+=`${a} ${l.trim()}
|
|
3
|
-
`}),console.log(h)}}const _={};class D{static setIgnoreFile(
|
|
4
|
-
`).map(i=>i.trim()),r=D.ignoreFiles;let a=2;for(;a<
|
|
3
|
+
`}),console.log(h)}}const _={};class D{static setIgnoreFile(n){this.ignoreFiles.push(n)}static clearIgnoreFiles(){this.ignoreFiles=[]}}o(D,"ignoreFiles",[]);function N(){const e=process.cwd(),t=(new Error().stack||"").split(`
|
|
4
|
+
`).map(i=>i.trim()),r=D.ignoreFiles;let a=2;for(;a<t.length&&(t[a].includes("node:internal")||t[a].includes("/node_modules/"));)a++;if(r.length>0)for(;a<t.length&&r.some(i=>t[a].includes(i));)a++;const h=t[a]||"";let l="Unknown function",c="Unknown caller";const d=h.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(d)l=d[1],c=d[2];else{const i=h.match(/at\s+(.+)/);if(i){c=i[1];const p=c.match(/at\s+([^(\s]+)\s+/);p&&p[1]!=="new"&&(l=p[1])}}c.includes("(")&&(c=c.substring(c.indexOf("(")+1,c.lastIndexOf(")"))),c=c.split(":").slice(0,-2).join(":");try{c=_.relative(e,c)}catch{}return{functionName:l,callerInfo:c}}class g{onDebug(n){const{name:s,body:t,cause:r,message:a}=n,h=[],{callerInfo:l,functionName:c}=N();h.push(`${s} initialized`),h.push(`Caller Function: ${c}`),h.push(`Caller Location: ${l}`),a&&h.push(`Message: ${a}`),t&&h.push(`Body: ${JSON.stringify(t,null,2)}`),r&&h.push(`Cause: ${JSON.stringify(r,null,2)}`),b({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:h})}}class C extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"BadGateway",body:this.body,cause:this.cause,message:this.statusText})}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 S extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"BadRequest",body:this.body,cause:this.cause,message:this.statusText})}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 g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"Conflict",body:this.body,cause:this.cause,message:this.statusText})}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 g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"Forbidden",body:this.body,cause:this.cause,message:this.statusText})}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 g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"NotFound",body:this.body,cause:this.cause,message:this.statusText})}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 g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",501);o(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"NotImplemented",body:this.body,cause:this.cause,message:this.statusText})}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 E extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",500);o(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"ServerError",body:this.body,cause:this.cause,message:this.statusText})}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 U extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",401);o(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"Unauthorized",body:this.body,cause:this.cause,message:this.statusText})}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 O extends g{constructor(s){super();o(this,"body");o(this,"status",422);o(this,"statusText");this.statusText=s.message||"Unprocessable Entity",this.body={name:"UnprocessableEntity",message:s.message||null,data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug({name:"UnprocessableEntity",cause:s.fieldErrors,message:s.message})}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 R{onDebug(n,s,t){const r=[],{callerInfo:a,functionName:h}=N();r.push(`${n} initialized
|
|
5
5
|
`),r.push(`Caller Function: ${h}
|
|
6
6
|
`),r.push(`Caller Location: ${a}
|
|
7
7
|
`),r.push(`Body: ${JSON.stringify(s,null,2)}
|
|
8
|
-
`),
|
|
9
|
-
`),b({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class U extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||201,this.statusText=(n==null?void 0:n.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class A extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||302,this.statusText=(n==null?void 0:n.statusText)||"Found",this.onDebug("Found",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class q extends R{constructor(s){super();o(this,"headers");o(this,"status");o(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class k extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends R{constructor(s,n){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(n==null?void 0:n.headers)||{},this.status=(n==null?void 0:n.status)||200,this.statusText=(n==null?void 0:n.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class V{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[n,r])=>(typeof r=="string"?s[n]=r:Array.isArray(r)?s[n]=r.join(", "):s[n]=JSON.stringify(r),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((n,r)=>{s[r]=n}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class v{static setArkynConfig(t){if(this.arkynConfig)return;const{trafficSourceId:s,userToken:n,logBaseApiUrl:r}=t;this.arkynConfig={trafficSourceId:s,userToken:n,apiUrl:r||"http://95.216.190.158:8081/ingest-log"}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(v,"arkynConfig");async function G(e){const t=v.getArkynConfig();if(!t)return;const{userToken:s,apiUrl:n,trafficSourceId:r}=t,{elapsedTime:a,method:h,queryParams:l,requestBody:c,requestHeaders:f,responseBody:i,responseHeaders:g,status:z,token:y,rawUrl:vs}=e;if(process.env.NODE_ENV!=="development")try{const T=new URL(vs);let M="https";T.protocol==="http:"&&(M="http");const Cs=JSON.stringify({domainUrl:T.protocol+"//"+T.host,pathnameUrl:T.pathname,trafficSourceId:r,status:z,protocol:M,method:h.toLowerCase(),trafficUserId:null,elapsedTime:a,requestHeaders:JSON.stringify(f),requestBody:JSON.stringify(c),queryParams:JSON.stringify(l),responseHeaders:JSON.stringify(g),responseBody:JSON.stringify(i)});await fetch(n,{method:"POST",body:Cs,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(T){b({debugs:[`Error sending request: ${T}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function x(e,t,s={},n){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const a=performance.now(),h={...s,"Content-Type":"application/json"},l=await fetch(t,{method:e,headers:h,body:n?JSON.stringify(n):void 0}),c=performance.now()-a,f=l.status;let i=null;try{i=await l.json()}catch{i=null}const g=V.handle({elapsedTime:c,method:e,queryParams:new URL(t).searchParams,requestHeaders:h,requestBody:n,responseBody:i,responseHeaders:l.headers,status:f,url:t});return G(g),l.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||r[e],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||l.statusText||"Request failed",response:i,cause:null}}catch(a){return b({debugs:[`Network error or request failed: ${a}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:a instanceof Error?a.message:String(a)}}}async function Z(e,t={},s){return x("DELETE",e,t,s)}async function W(e,t={}){return x("GET",e,t)}async function K(e,t={},s){return x("PATCH",e,t,s)}async function Q(e,t={},s){return x("POST",e,t,s)}async function X(e,t={},s){return x("PUT",e,t,s)}class ss{constructor(t){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,n){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${t}`),r.push(`Method: ${s}`),n[0]&&r.push(`Headers: ${JSON.stringify(n[0])}`),n[1]&&r.push(`Body: ${JSON.stringify(n[1])}`),b({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),t&&(n={...n,...t}),s&&(n={...n,Authorization:`Bearer ${s}`}),n}async get(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(t,"get",[r]),await W(n,r)}async post(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(t,"post",[r,a]),await Q(n,r,a)}async put(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(t,"put",[r,a]),await X(n,r,a)}async patch(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(t,"patch",[r,a]),await K(n,r,a)}async delete(t,s){const n=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(t,"delete",[r,a]),await Z(n,r,a)}}function es(e,t){var s,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:(s=e==null?void 0:e.error)!=null&&s.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:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const ts=async e=>{let t;const s=await e.arrayBuffer(),n=new TextDecoder().decode(s);try{t=JSON.parse(n)}catch{try{if(n.includes("=")){const a=new URLSearchParams(n);t=Object.fromEntries(a.entries())}else throw new S("Invalid URLSearchParams format")}catch{throw new S("Failed to extract data from request")}}return t};function ns(e){switch(!0){case e instanceof Response:return e;case e instanceof A:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof B:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof q:return e.toResponse()}switch(!0){case e instanceof C:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof J:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof O:return e.toResponse()}return new E("Server error",e).toResponse()}async function L([e,t]){const s=await t.safeParseAsync(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}function F([e,t]){const s=t.safeParse(e);if(s.success===!1){const n=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:n,fields:e}}else return{success:s.success,data:s.data}}const rs=(e,t="")=>{const s=new URL(e.url);if(t==="")return s.searchParams;const n=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${t}:`)).map(([r,a])=>[r.replace(`${t}:`,""),a]);return new URLSearchParams(n)};function os(e){const t="Error validating:",s=e.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[t,...s].join(`
|
|
10
|
-
`)}class as{constructor(
|
|
8
|
+
`),t&&r.push(`Cause: ${JSON.stringify(t,null,2)}
|
|
9
|
+
`),b({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class w extends R{constructor(s,t){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body={...s,name:"Created",message:t==null?void 0:t.message},this.headers=(t==null?void 0:t.headers)||{},this.status=(t==null?void 0:t.status)||201,this.statusText=(t==null?void 0:t.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class A extends R{constructor(s,t){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body={...s,name:"Found",message:t==null?void 0:t.message},this.headers=(t==null?void 0:t.headers)||{},this.status=(t==null?void 0:t.status)||302,this.statusText=(t==null?void 0:t.statusText)||"Found",this.onDebug("Found",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class q extends R{constructor(s){super();o(this,"headers");o(this,"status");o(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class k extends R{constructor(s,t){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body={...s,name:"Success",message:t==null?void 0:t.message},this.headers=(t==null?void 0:t.headers)||{},this.status=(t==null?void 0:t.status)||200,this.statusText=(t==null?void 0:t.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends R{constructor(s,t){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body={...s,name:"Updated",message:t==null?void 0:t.message},this.headers=(t==null?void 0:t.headers)||{},this.status=(t==null?void 0:t.status)||200,this.statusText=(t==null?void 0:t.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class V{static mapHeaders(n){return n instanceof Headers?Object.fromEntries(n.entries()):typeof n=="object"?Object.entries(n).reduce((s,[t,r])=>(typeof r=="string"?s[t]=r:Array.isArray(r)?s[t]=r.join(", "):s[t]=JSON.stringify(r),s),{}):{}}static mapQueryParams(n){const s={};return n.forEach((t,r)=>{s[r]=t}),s}static handle(n){return{rawUrl:n.url,status:n.status,method:n.method,token:null,elapsedTime:n.elapsedTime,requestHeaders:this.mapHeaders(n.requestHeaders),requestBody:n.requestBody||null,queryParams:this.mapQueryParams(n.queryParams),responseHeaders:this.mapHeaders(n.responseHeaders),responseBody:n.responseBody||null}}}class v{static setArkynConfig(n){if(this.arkynConfig)return;const{trafficSourceId:s,userToken:t,logBaseApiUrl:r}=n;this.arkynConfig={trafficSourceId:s,userToken:t,apiUrl:r||"http://95.216.190.158:8081/ingest-log"}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(v,"arkynConfig");async function G(e){const n=v.getArkynConfig();if(!n)return;const{userToken:s,apiUrl:t,trafficSourceId:r}=n,{elapsedTime:a,method:h,queryParams:l,requestBody:c,requestHeaders:d,responseBody:i,responseHeaders:p,status:z,token:y,rawUrl:vs}=e;if(process.env.NODE_ENV!=="development")try{const T=new URL(vs);let M="https";T.protocol==="http:"&&(M="http");const Cs=JSON.stringify({domainUrl:T.protocol+"//"+T.host,pathnameUrl:T.pathname,trafficSourceId:r,status:z,protocol:M,method:h.toLowerCase(),trafficUserId:null,elapsedTime:a,requestHeaders:JSON.stringify(d),requestBody:JSON.stringify(c),queryParams:JSON.stringify(l),responseHeaders:JSON.stringify(p),responseBody:JSON.stringify(i)});await fetch(t,{method:"POST",body:Cs,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(T){b({debugs:[`Error sending request: ${T}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function x(e,n,s={},t){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const a=performance.now(),h={...s,"Content-Type":"application/json"},l=await fetch(n,{method:e,headers:h,body:t?JSON.stringify(t):void 0}),c=performance.now()-a,d=l.status;let i=null;try{i=await l.json()}catch{i=null}const p=V.handle({elapsedTime:c,method:e,queryParams:new URL(n).searchParams,requestHeaders:h,requestBody:t,responseBody:i,responseHeaders:l.headers,status:d,url:n});return G(p),l.ok?{success:!0,status:d,message:(i==null?void 0:i.message)||r[e],response:i,cause:null}:{success:!1,status:d,message:(i==null?void 0:i.message)||l.statusText||"Request failed",response:i,cause:null}}catch(a){return b({debugs:[`Network error or request failed: ${a}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:a instanceof Error?a.message:String(a)}}}async function Z(e,n={},s){return x("DELETE",e,n,s)}async function W(e,n={}){return x("GET",e,n)}async function K(e,n={},s){return x("PATCH",e,n,s)}async function Q(e,n={},s){return x("POST",e,n,s)}async function X(e,n={},s){return x("PUT",e,n,s)}class ss{constructor(n){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=n.baseUrl,this.baseHeaders=n.baseHeaders||void 0,this.baseToken=n.baseToken||void 0,this.enableDebug=n.enableDebug||!1}onDebug(n,s,t){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${n}`),r.push(`Method: ${s}`),t[0]&&r.push(`Headers: ${JSON.stringify(t[0])}`),t[1]&&r.push(`Body: ${JSON.stringify(t[1])}`),b({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(n){return this.baseUrl+n}generateHeaders(n,s){let t={};return this.baseToken&&(t={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(t={...t,...this.baseHeaders}),n&&(t={...t,...n}),s&&(t={...t,Authorization:`Bearer ${s}`}),t}async get(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(n,"get",[r]),await W(t,r)}async post(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(n,"post",[r,a]),await Q(t,r,a)}async put(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(n,"put",[r,a]),await X(t,r,a)}async patch(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(n,"patch",[r,a]),await K(t,r,a)}async delete(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(n,"delete",[r,a]),await Z(t,r,a)}}function es(e,n){var s,t,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:(s=e==null?void 0:e.error)!=null&&s.message&&typeof((t=e==null?void 0:e.error)==null?void 0:t.message)=="string"?(r=e==null?void 0:e.error)==null?void 0:r.message:n!=null&&n.statusText&&typeof(n==null?void 0:n.statusText)=="string"?n==null?void 0:n.statusText:"Missing error message"}const ts=async e=>{let n;const s=await e.arrayBuffer(),t=new TextDecoder().decode(s);try{n=JSON.parse(t)}catch{try{if(t.includes("=")){const a=new URLSearchParams(t);n=Object.fromEntries(a.entries())}else throw new S("Invalid URLSearchParams format")}catch{throw new S("Failed to extract data from request")}}return n};function ns(e){switch(!0){case e instanceof Response:return e;case e instanceof A:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof B:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof q:return e.toResponse()}switch(!0){case e instanceof C:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof J:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof O:return e.toResponse()}return new E("Server error",e).toResponse()}async function L([e,n]){const s=await n.safeParseAsync(e);if(s.success===!1){const t=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:t,fields:e}}else return{success:s.success,data:s.data}}function F([e,n]){const s=n.safeParse(e);if(s.success===!1){const t=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:t,fields:e}}else return{success:s.success,data:s.data}}const rs=(e,n="")=>{const s=new URL(e.url);if(n==="")return s.searchParams;const t=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${n}:`)).map(([r,a])=>[r.replace(`${n}:`,""),a]);return new URLSearchParams(t)};function os(e){const n="Error validating:",s=e.issues.map(({path:t,message:r})=>`-> ${t.join(".")}: ${r}`);return[n,...s].join(`
|
|
10
|
+
`)}class as{constructor(n){o(this,"functionName");o(this,"callerInfo");this.schema=n;const{callerInfo:s,functionName:t}=N();this.callerInfo=s,this.functionName=t}isValid(n){return this.schema.safeParse(n).success}safeValidate(n){return this.schema.safeParse(n)}validate(n){try{return this.schema.parse(n)}catch(s){throw new E(os(s))}}formValidate(n,s){const t=F([n,this.schema]);if(!t.success){const r=Object.keys(t.fieldErrors)[0];throw new O({fields:t.fields,fieldErrors:t.fieldErrors,data:{scrollTo:r},message:s})}return t.data}async formAsyncValidate(n,s){const t=await L([n,this.schema]);if(!t.success){const r=Object.keys(t.fieldErrors)[0];throw new O({fields:t.fields,fieldErrors:t.fieldErrors,data:{scrollTo:r},message:s})}return t.data}}const us=e=>{if(!e||!/^[0-9-]+$/.test(e))return!1;const s=m.removeNonNumeric(e),t=8,r=/^\d{8}$/.test(s);return s.length===t&&r};function is(e){return e.length!==14}function cs(e){const[n]=e;return[...e].every(s=>s===n)}function H(e,n){let s=0;for(let r=0;r<n.length;r++)s+=parseInt(e[r])*n[r];const t=s%11;return t<2?0:11-t}function hs(e){return e.slice(12)}const ls=e=>{if(!e)return!1;const n=m.removeNonNumeric(e);if(is(n)||cs(n))return!1;const s=n.slice(0,12),t=H(s,[5,4,3,2,9,8,7,6,5,4,3,2]),r=H(s+t,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return hs(n)===`${t}${r}`};function ds(e){return e.length!==11}function fs(e){const[n]=e;return[...e].every(s=>s===n)}function P(e,n){let s=0;for(const r of e)n>1&&(s+=parseInt(r)*n--);const t=s%11;return t<2?0:11-t}function ys(e){return e.slice(9)}const gs=e=>{if(!e)return!1;const n=m.removeNonNumeric(e);if(ds(n)||fs(n))return!1;const s=P(n,10),t=P(n,11);return ys(n)===`${s}${t}`},ps=(e,n)=>{let s,t,r;const a=(n==null?void 0:n.inputFormat)||"DD/MM/YYYY",h=(n==null?void 0:n.minYear)||1900,l=(n==null?void 0:n.maxYear)||3e3;if(a==="DD/MM/YYYY"){const y=/^(\d{2})\/(\d{2})\/(\d{4})$/;if(!y.test(e))return!1;[,s,t,r]=e.match(y)||[]}else if(a==="MM-DD-YYYY"){const y=/^(\d{2})-(\d{2})-(\d{4})$/;if(!y.test(e))return!1;[,t,s,r]=e.match(y)||[]}else if(a==="YYYY-MM-DD"){const y=/^(\d{4})-(\d{2})-(\d{2})$/;if(!y.test(e))return!1;[,r,t,s]=e.match(y)||[]}else throw new Error("Invalid date format");const c=parseInt(s,10),d=parseInt(t,10),i=parseInt(r,10);if(c<1||c>31||d<1||d>12)return!1;const p=[31,28,31,30,31,30,31,31,30,31,30,31];if(d===2){const y=i%4===0&&i%100!==0||i%400===0;if(c>(y?29:28))return!1}else if(c>p[d-1])return!1;return i<h||i>l?!1:new Date(i,d-1,c).getDate()===c};function ms(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 bs(e){return!(e.length===0||e.length>64||e.startsWith(".")||e.endsWith(".")||e.includes("..")||!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e))}function Ts(e){return!(e.length===0||e.length>63||e.startsWith("-")||e.endsWith("-")||!/^[a-zA-Z0-9-]+$/.test(e))}function Rs(e){if(e.length===0||e.length>253||e.startsWith(".")||e.endsWith(".")||e.startsWith("-")||e.endsWith("-"))return!1;const n=e.split(".");if(n.length<2)return!1;for(const t of n)if(!Ts(t))return!1;const s=n[n.length-1];return!(s.length<2||!/^[a-zA-Z]+$/.test(s))}function xs(e){const n=e.split("@");if(n.length!==2)return!1;const[s,t]=n;return!(!bs(s)||!Rs(t))}function Ns(e){const n=e.split("@");return n.length===2?n[1].toLowerCase():null}const Ss=async e=>{if(!e||typeof e!="string")return!1;const n=e.trim();return!(!ms(n)||!xs(n)||!Ns(n))},Es=e=>{if(!e)return!1;const n=e.length>=8,s=/[A-Z]/.test(e),t=/[a-z]/.test(e),r=/\d/.test(e),a=/[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(e);return[n,s,t,r,a].every(h=>h)},Os=e=>{for(const n of Y.countries){const s=n.code,t=n.prefix?`-${n.prefix}`:"",r=n.mask.replace(/[^_]/g,"").length;if(n.iso==="BR"){if(new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e))return!0;continue}if(new RegExp(`^\\${s}${t} \\d{${r}}$`).test(e))return!0}return!1},Ds=e=>{if(!e||!/^[0-9a-zA-Z.-]+$/.test(e))return!1;const s=e.replace(/[^a-zA-Z0-9]/g,"");return s.length<7||s.length>9?!1:/^[0-9]{7,8}[0-9Xx]?$/.test(s)};u.ApiService=ss,u.ArkynLogService=v,u.BadGateway=C,u.BadRequest=S,u.Conflict=$,u.Created=w,u.DebugService=D,u.Forbidden=I,u.Found=A,u.NoContent=q,u.NotFound=j,u.NotImplemented=J,u.SchemaValidator=as,u.ServerError=E,u.Success=k,u.Unauthorized=U,u.UnprocessableEntity=O,u.Updated=B,u.decodeErrorMessageFromRequest=es,u.decodeRequestBody=ts,u.errorHandler=ns,u.flushDebugLogs=b,u.formAsyncParse=L,u.formParse=F,u.getCaller=N,u.getScopedParams=rs,u.validateCep=us,u.validateCnpj=ls,u.validateCpf=gs,u.validateDate=ps,u.validateEmail=Ss,u.validatePassword=Es,u.validatePhone=Os,u.validateRg=Ds,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
|
+
type InitProps = ResponseInit & {
|
|
3
|
+
message?: string;
|
|
4
|
+
};
|
|
2
5
|
/**
|
|
3
6
|
* Represents a successful HTTP response with a status code of 201 (Created).
|
|
4
7
|
* This class is used to standardize the structure of a "Created" response,
|
|
@@ -17,7 +20,7 @@ declare class Created<T> extends SuccessResponse {
|
|
|
17
20
|
* @param body - The response body to be included in the HTTP response.
|
|
18
21
|
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
19
22
|
*/
|
|
20
|
-
constructor(body: T, init?:
|
|
23
|
+
constructor(body: T, init?: InitProps);
|
|
21
24
|
/**
|
|
22
25
|
* Converts the `Created` instance into a `Response` object with a JSON body.
|
|
23
26
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/created.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/created.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,SAAS,GAAG,YAAY,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;IAWrC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -19,7 +19,7 @@ class Created extends SuccessResponse {
|
|
|
19
19
|
*/
|
|
20
20
|
constructor(body, init) {
|
|
21
21
|
super();
|
|
22
|
-
this.body = body;
|
|
22
|
+
this.body = { ...body, name: "Created", message: init?.message };
|
|
23
23
|
this.headers = init?.headers || {};
|
|
24
24
|
this.status = init?.status || 201;
|
|
25
25
|
this.statusText = init?.statusText || "Resource created successfully";
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
|
+
type InitProps = ResponseInit & {
|
|
3
|
+
message?: string;
|
|
4
|
+
};
|
|
2
5
|
/**
|
|
3
6
|
* Represents an HTTP 302 Found response.
|
|
4
7
|
* This class is used to create a standardized HTTP response with a status of 302 (Found),
|
|
@@ -20,7 +23,7 @@ declare class Found<T> extends SuccessResponse {
|
|
|
20
23
|
* - `status`: HTTP status code (default is 302).
|
|
21
24
|
* - `statusText`: HTTP status text (default is "Found").
|
|
22
25
|
*/
|
|
23
|
-
constructor(body: T, init?:
|
|
26
|
+
constructor(body: T, init?: InitProps);
|
|
24
27
|
/**
|
|
25
28
|
* Converts the `Found` instance into a `Response` object.
|
|
26
29
|
* This method serializes the response body as JSON and includes the appropriate headers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"found.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/found.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;GAMG;AAEH,cAAM,KAAK,CAAC,CAAC,CAAE,SAAQ,eAAe;IACpC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"found.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/found.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,SAAS,GAAG,YAAY,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AAEH,cAAM,KAAK,CAAC,CAAC,CAAE,SAAQ,eAAe;IACpC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;OAQG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;IAWrC;;;;;OAKG;IAEH,UAAU;IAUV;;;;;OAKG;IAEH,MAAM;CASP;AAED,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -22,7 +22,7 @@ class Found extends SuccessResponse {
|
|
|
22
22
|
*/
|
|
23
23
|
constructor(body, init) {
|
|
24
24
|
super();
|
|
25
|
-
this.body = body;
|
|
25
|
+
this.body = { ...body, name: "Found", message: init?.message };
|
|
26
26
|
this.headers = init?.headers || {};
|
|
27
27
|
this.status = init?.status || 302;
|
|
28
28
|
this.statusText = init?.statusText || "Found";
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
|
+
type InitProps = ResponseInit & {
|
|
3
|
+
message?: string;
|
|
4
|
+
};
|
|
2
5
|
/**
|
|
3
6
|
* Represents a successful HTTP response with a status code of 200 (OK).
|
|
4
7
|
* This class is used to standardize the structure of a "Success" response,
|
|
@@ -17,7 +20,7 @@ declare class Success<T> extends SuccessResponse {
|
|
|
17
20
|
* @param body - The response body to be included in the HTTP response.
|
|
18
21
|
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
19
22
|
*/
|
|
20
|
-
constructor(body: T, init?:
|
|
23
|
+
constructor(body: T, init?: InitProps);
|
|
21
24
|
/**
|
|
22
25
|
* Converts the `Success` instance into a `Response` object with a JSON body.
|
|
23
26
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"success.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/success.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"success.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/success.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,SAAS,GAAG,YAAY,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;IAWrC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -19,7 +19,7 @@ class Success extends SuccessResponse {
|
|
|
19
19
|
*/
|
|
20
20
|
constructor(body, init) {
|
|
21
21
|
super();
|
|
22
|
-
this.body = body;
|
|
22
|
+
this.body = { ...body, name: "Success", message: init?.message };
|
|
23
23
|
this.headers = init?.headers || {};
|
|
24
24
|
this.status = init?.status || 200;
|
|
25
25
|
this.statusText = init?.statusText ?? "OK";
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { SuccessResponse } from "./_successResponse";
|
|
2
|
+
type InitProps = ResponseInit & {
|
|
3
|
+
message?: string;
|
|
4
|
+
};
|
|
2
5
|
/**
|
|
3
6
|
* Represents a successful HTTP response with a status code of 200 (OK) or other custom status codes.
|
|
4
7
|
* This class is used to standardize the structure of an "Updated" response,
|
|
@@ -17,7 +20,7 @@ declare class Updated<T> extends SuccessResponse {
|
|
|
17
20
|
* @param body - The response body to be included in the HTTP response.
|
|
18
21
|
* @param init - Optional initialization object for customizing headers, status, and status text.
|
|
19
22
|
*/
|
|
20
|
-
constructor(body: T, init?:
|
|
23
|
+
constructor(body: T, init?: InitProps);
|
|
21
24
|
/**
|
|
22
25
|
* Converts the `Updated` instance into a `Response` object with a JSON body.
|
|
23
26
|
* This method ensures the response has the appropriate headers, status, and status text.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/updated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/updated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,KAAK,SAAS,GAAG,YAAY,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC,CAAE,SAAQ,eAAe;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;IAWrC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -19,7 +19,7 @@ class Updated extends SuccessResponse {
|
|
|
19
19
|
*/
|
|
20
20
|
constructor(body, init) {
|
|
21
21
|
super();
|
|
22
|
-
this.body = body;
|
|
22
|
+
this.body = { ...body, name: "Updated", message: init?.message };
|
|
23
23
|
this.headers = init?.headers || {};
|
|
24
24
|
this.status = init?.status || 200;
|
|
25
25
|
this.statusText = init?.statusText || "Resource updated successfully";
|