@arkyn/server 3.0.1-beta.154 → 3.0.1-beta.156
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1301 -37
- package/dist/modules/http/api/_logRequest.js +69 -0
- package/dist/modules/http/api/_makeRequest.js +69 -0
- package/dist/modules/http/api/deleteRequest.js +13 -0
- package/dist/modules/http/api/getRequest.js +12 -0
- package/dist/modules/http/api/patchRequest.js +13 -0
- package/dist/modules/http/api/postRequest.js +13 -0
- package/dist/modules/http/api/putRequest.js +13 -0
- package/dist/modules/http/badResponses/_badResponse.js +59 -0
- package/dist/modules/http/badResponses/badGateway.js +30 -0
- package/dist/modules/http/badResponses/badRequest.js +30 -0
- package/dist/modules/http/badResponses/conflict.js +30 -0
- package/dist/modules/http/badResponses/forbidden.js +30 -0
- package/dist/modules/http/badResponses/notFound.js +30 -0
- package/dist/modules/http/badResponses/notImplemented.js +30 -0
- package/dist/modules/http/badResponses/serverError.js +30 -0
- package/dist/modules/http/badResponses/unauthorized.js +30 -0
- package/dist/modules/http/badResponses/unprocessableEntity.js +36 -0
- package/dist/modules/http/successResponses/_successResponse.js +69 -0
- package/dist/modules/http/successResponses/created.js +30 -0
- package/dist/modules/http/successResponses/found.js +30 -0
- package/dist/modules/http/successResponses/noContent.js +21 -0
- package/dist/modules/http/successResponses/success.js +30 -0
- package/dist/modules/http/successResponses/updated.js +30 -0
- package/dist/modules/index.js +68 -0
- package/dist/modules/services/apiService.js +129 -0
- package/dist/modules/services/debugService.js +66 -0
- package/dist/modules/services/logMapperService.js +52 -0
- package/dist/modules/services/logService.js +31 -0
- package/dist/modules/utilities/decodeRequestBody.js +22 -0
- package/dist/modules/utilities/decodeRequestErrorMessage.js +7 -0
- package/dist/modules/utilities/errorHandler.js +54 -0
- package/dist/modules/utilities/flushDebugLogs.js +20 -0
- package/dist/modules/utilities/formAsyncParse.js +19 -0
- package/dist/modules/utilities/formParse.js +19 -0
- package/dist/modules/utilities/getScopedParams.js +11 -0
- package/dist/modules/utilities/schemaValidator.js +106 -0
- package/dist/modules/validations/validateCep.js +9 -0
- package/dist/modules/validations/validateCnpj.js +31 -0
- package/dist/modules/validations/validateCpf.js +28 -0
- package/dist/modules/validations/validateDate.js +27 -0
- package/dist/modules/validations/validateEmail.js +53 -0
- package/dist/modules/validations/validatePassword.js +16 -0
- package/dist/modules/validations/validatePhone.js +10 -0
- package/dist/modules/validations/validateRg.js +8 -0
- package/package.json +121 -87
- package/dist/bundle.js +0 -3014
- package/dist/bundle.umd.cjs +0 -9
- package/dist/http/api/_logRequest.js +0 -109
- package/dist/http/api/_makeRequest.js +0 -116
- package/dist/http/api/deleteRequest.js +0 -18
- package/dist/http/api/getRequest.js +0 -17
- package/dist/http/api/patchRequest.js +0 -18
- package/dist/http/api/postRequest.js +0 -18
- package/dist/http/api/putRequest.js +0 -18
- package/dist/http/badResponses/_badResponse.js +0 -62
- package/dist/http/badResponses/badGateway.js +0 -43
- package/dist/http/badResponses/badRequest.js +0 -41
- package/dist/http/badResponses/conflict.js +0 -42
- package/dist/http/badResponses/forbidden.js +0 -41
- package/dist/http/badResponses/notFound.js +0 -41
- package/dist/http/badResponses/notImplemented.js +0 -41
- package/dist/http/badResponses/serverError.js +0 -41
- package/dist/http/badResponses/unauthorized.js +0 -42
- package/dist/http/badResponses/unprocessableEntity.js +0 -53
- package/dist/http/successResponses/_successResponse.js +0 -75
- package/dist/http/successResponses/created.js +0 -41
- package/dist/http/successResponses/found.js +0 -41
- package/dist/http/successResponses/noContent.js +0 -32
- package/dist/http/successResponses/success.js +0 -41
- package/dist/http/successResponses/updated.js +0 -42
- package/dist/services/apiService.js +0 -174
- package/dist/services/debugService.js +0 -82
- package/dist/services/logMapperService.js +0 -68
- package/dist/services/logService.js +0 -35
- package/dist/utilities/decodeRequestBody.js +0 -40
- package/dist/utilities/decodeRequestErrorMessage.js +0 -36
- package/dist/utilities/errorHandler.js +0 -74
- package/dist/utilities/flushDebugLogs.js +0 -39
- package/dist/utilities/formAsyncParse.js +0 -37
- package/dist/utilities/formParse.js +0 -37
- package/dist/utilities/getScopedParams.js +0 -26
- package/dist/utilities/schemaValidator.js +0 -119
- package/dist/validations/validateCep.js +0 -27
- package/dist/validations/validateCnpj.js +0 -59
- package/dist/validations/validateCpf.js +0 -54
- package/dist/validations/validateDate.js +0 -51
- package/dist/validations/validateEmail.js +0 -111
- package/dist/validations/validatePassword.js +0 -34
- package/dist/validations/validatePhone.js +0 -28
- package/dist/validations/validateRg.js +0 -31
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { formatJsonObject as w } from "@arkyn/shared";
|
|
2
|
+
import { LogService as x } from "../../services/logService.js";
|
|
3
|
+
import { flushDebugLogs as n } from "../../utilities/flushDebugLogs.js";
|
|
4
|
+
async function B(a) {
|
|
5
|
+
const r = x.getConfig();
|
|
6
|
+
if (!r) return;
|
|
7
|
+
const { userToken: i, apiUrl: c, trafficSourceId: u } = r, {
|
|
8
|
+
elapsedTime: p,
|
|
9
|
+
method: d,
|
|
10
|
+
queryParams: f,
|
|
11
|
+
requestBody: m,
|
|
12
|
+
requestHeaders: l,
|
|
13
|
+
responseBody: g,
|
|
14
|
+
responseHeaders: h,
|
|
15
|
+
status: y,
|
|
16
|
+
token: L,
|
|
17
|
+
rawUrl: S
|
|
18
|
+
} = a;
|
|
19
|
+
if (process.env.NODE_ENV !== "development")
|
|
20
|
+
try {
|
|
21
|
+
const e = new URL(S);
|
|
22
|
+
let o = "https";
|
|
23
|
+
e.protocol === "http:" && (o = "http");
|
|
24
|
+
const N = JSON.stringify({
|
|
25
|
+
domainUrl: e.protocol + "//" + e.host,
|
|
26
|
+
pathnameUrl: e.pathname,
|
|
27
|
+
trafficSourceId: u,
|
|
28
|
+
status: y,
|
|
29
|
+
protocol: o,
|
|
30
|
+
method: d.toLowerCase(),
|
|
31
|
+
trafficUserId: null,
|
|
32
|
+
elapsedTime: p,
|
|
33
|
+
requestHeaders: JSON.stringify(l),
|
|
34
|
+
requestBody: JSON.stringify(m),
|
|
35
|
+
queryParams: JSON.stringify(f),
|
|
36
|
+
responseHeaders: JSON.stringify(h),
|
|
37
|
+
responseBody: JSON.stringify(g)
|
|
38
|
+
}), O = {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
Authorization: `Bearer ${i}`
|
|
41
|
+
}, t = await fetch(c, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
body: N,
|
|
44
|
+
headers: O
|
|
45
|
+
});
|
|
46
|
+
if (!t.ok) {
|
|
47
|
+
const q = await t.text(), J = t.status, T = t.statusText, s = await t.json().catch(() => null);
|
|
48
|
+
n({
|
|
49
|
+
name: "LogError",
|
|
50
|
+
scheme: "red",
|
|
51
|
+
debugs: [
|
|
52
|
+
"Failed to log request.",
|
|
53
|
+
`Status: ${J} ${T}.`,
|
|
54
|
+
`Status text: ${q}.`,
|
|
55
|
+
`JSON Response: ${s ? w(s, 0) : "No JSON response"}`
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
n({
|
|
61
|
+
debugs: [`Error sending request: ${e}`],
|
|
62
|
+
name: "LogError",
|
|
63
|
+
scheme: "red"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
B as logRequest
|
|
69
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { flushDebugLogs as n } from "../../utilities/flushDebugLogs.js";
|
|
2
|
+
import { LogMapperService as d } from "../../services/logMapperService.js";
|
|
3
|
+
import { logRequest as f } from "./_logRequest.js";
|
|
4
|
+
async function i(e) {
|
|
5
|
+
let a = e.url;
|
|
6
|
+
e.urlParams && Object.entries(e.urlParams).forEach(([r, c]) => {
|
|
7
|
+
a = a.replaceAll(`:${r}`, c);
|
|
8
|
+
});
|
|
9
|
+
const u = {
|
|
10
|
+
POST: "Resource created successfully",
|
|
11
|
+
PUT: "Resource updated successfully",
|
|
12
|
+
DELETE: "Resource deleted successfully",
|
|
13
|
+
PATCH: "Resource patched successfully",
|
|
14
|
+
GET: "Request successful"
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
const r = performance.now(), c = { ...e.headers, "Content-Type": "application/json" }, o = await fetch(a, {
|
|
18
|
+
headers: c,
|
|
19
|
+
method: e.method,
|
|
20
|
+
body: e.body ? JSON.stringify(e.body) : void 0
|
|
21
|
+
}), l = performance.now() - r, t = o.status;
|
|
22
|
+
let s = null;
|
|
23
|
+
try {
|
|
24
|
+
s = await o.json();
|
|
25
|
+
} catch {
|
|
26
|
+
s = null;
|
|
27
|
+
}
|
|
28
|
+
const m = d.handle({
|
|
29
|
+
elapsedTime: l,
|
|
30
|
+
method: e.method,
|
|
31
|
+
queryParams: new URL(a).searchParams,
|
|
32
|
+
requestHeaders: c,
|
|
33
|
+
requestBody: e.body,
|
|
34
|
+
responseBody: s,
|
|
35
|
+
responseHeaders: o.headers,
|
|
36
|
+
status: t,
|
|
37
|
+
rawUrl: e.url,
|
|
38
|
+
urlParams: e.urlParams
|
|
39
|
+
});
|
|
40
|
+
return f(m), o.ok ? {
|
|
41
|
+
success: !0,
|
|
42
|
+
status: t,
|
|
43
|
+
message: (s == null ? void 0 : s.message) || u[e.method],
|
|
44
|
+
response: s,
|
|
45
|
+
cause: null
|
|
46
|
+
} : {
|
|
47
|
+
success: !1,
|
|
48
|
+
status: t,
|
|
49
|
+
message: (s == null ? void 0 : s.message) || o.statusText || "Request failed",
|
|
50
|
+
response: s,
|
|
51
|
+
cause: null
|
|
52
|
+
};
|
|
53
|
+
} catch (r) {
|
|
54
|
+
return n({
|
|
55
|
+
debugs: [`Network error or request failed: ${r}`],
|
|
56
|
+
name: "MakeRequestError",
|
|
57
|
+
scheme: "red"
|
|
58
|
+
}), {
|
|
59
|
+
success: !1,
|
|
60
|
+
status: 0,
|
|
61
|
+
message: "Network error or request failed",
|
|
62
|
+
response: null,
|
|
63
|
+
cause: r instanceof Error ? r.message : String(r)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
i as makeRequest
|
|
69
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var r = Object.defineProperty;
|
|
2
|
+
var n = (t, s, e) => s in t ? r(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
|
|
3
|
+
var u = (t, s, e) => n(t, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
import { formatJsonString as o } from "@arkyn/shared";
|
|
5
|
+
import { DebugService as i } from "../../services/debugService.js";
|
|
6
|
+
import { flushDebugLogs as h } from "../../utilities/flushDebugLogs.js";
|
|
7
|
+
class l {
|
|
8
|
+
constructor() {
|
|
9
|
+
u(this, "_cause");
|
|
10
|
+
u(this, "_name", "BadResponse");
|
|
11
|
+
u(this, "_status", 500);
|
|
12
|
+
u(this, "_statusText", "Unknown error");
|
|
13
|
+
u(this, "_debugColor", "red");
|
|
14
|
+
}
|
|
15
|
+
get cause() {
|
|
16
|
+
return this._cause;
|
|
17
|
+
}
|
|
18
|
+
set cause(s) {
|
|
19
|
+
this._cause = s;
|
|
20
|
+
}
|
|
21
|
+
get name() {
|
|
22
|
+
return this._name;
|
|
23
|
+
}
|
|
24
|
+
set name(s) {
|
|
25
|
+
this._name = s;
|
|
26
|
+
}
|
|
27
|
+
get status() {
|
|
28
|
+
return this._status;
|
|
29
|
+
}
|
|
30
|
+
set status(s) {
|
|
31
|
+
this._status = s;
|
|
32
|
+
}
|
|
33
|
+
get statusText() {
|
|
34
|
+
return this._statusText;
|
|
35
|
+
}
|
|
36
|
+
set statusText(s) {
|
|
37
|
+
this._statusText = s;
|
|
38
|
+
}
|
|
39
|
+
get debugColor() {
|
|
40
|
+
return this._debugColor;
|
|
41
|
+
}
|
|
42
|
+
set debugColor(s) {
|
|
43
|
+
["green", "yellow", "cyan", "red"].includes(s) && (this._debugColor = s);
|
|
44
|
+
}
|
|
45
|
+
onDebug() {
|
|
46
|
+
const s = [], { callerInfo: e, functionName: a } = i.getCaller();
|
|
47
|
+
s.push(`Caller Function: ${a}`), s.push(`Caller Location: ${e}`), this._statusText && s.push(`Message: ${this._statusText}`), this._cause && s.push(`Cause: ${o(JSON.stringify(this._cause))}`), h({ scheme: "red", name: this._name, debugs: s });
|
|
48
|
+
}
|
|
49
|
+
makeBody() {
|
|
50
|
+
return {
|
|
51
|
+
name: this._name,
|
|
52
|
+
message: this._statusText,
|
|
53
|
+
cause: this._cause
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
l as BadResponse
|
|
59
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadResponse as e } from "./_badResponse.js";
|
|
2
|
+
class o extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Error description sent in the response body and logged for debugging.
|
|
5
|
+
* @param cause - Optional extra context (serialized to JSON in the response).
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "BadGateway", this.status = 502, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.makeBody(), s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
o as BadGateway
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadResponse as e } from "./_badResponse.js";
|
|
2
|
+
class i extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Error description.
|
|
5
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "BadRequest", this.status = 400, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.makeBody(), s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as BadRequest
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadResponse as e } from "./_badResponse.js";
|
|
2
|
+
class i extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Error description.
|
|
5
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "Conflict", this.status = 409, this.statusText = s, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.makeBody(), s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as Conflict
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadResponse as e } from "./_badResponse.js";
|
|
2
|
+
class i extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Error description.
|
|
5
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "Forbidden", this.status = 403, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.makeBody(), s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as Forbidden
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadResponse as e } from "./_badResponse.js";
|
|
2
|
+
class i extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Error description.
|
|
5
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "NotFound", this.status = 404, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.makeBody(), s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as NotFound
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadResponse as e } from "./_badResponse.js";
|
|
2
|
+
class i extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Error description.
|
|
5
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
6
|
+
*/
|
|
7
|
+
constructor(t, s) {
|
|
8
|
+
super(), this.name = "NotImplemented", this.status = 501, this.statusText = t, this.cause = s ? JSON.stringify(s) : void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const t = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.makeBody()), t);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const t = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.makeBody(), t);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as NotImplemented
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadResponse as e } from "./_badResponse.js";
|
|
2
|
+
class r extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Error description.
|
|
5
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "ServerError", this.status = 500, this.statusText = s, this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.makeBody(), s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
r as ServerError
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BadResponse as e } from "./_badResponse.js";
|
|
2
|
+
class i extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Error description.
|
|
5
|
+
* @param cause - Optional extra context (serialized to JSON).
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "Unauthorized", this.status = 401, this.statusText = s, this.debugColor = "yellow", this.cause = t ? JSON.stringify(t) : void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.makeBody(), s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as Unauthorized
|
|
30
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BadResponse as t } from "./_badResponse.js";
|
|
2
|
+
class o extends t {
|
|
3
|
+
/**
|
|
4
|
+
* @param props.message - Human-readable description of the error.
|
|
5
|
+
* @param props.fieldErrors - Per-field validation messages keyed by field name.
|
|
6
|
+
* @param props.fields - Original submitted field values (useful for repopulating forms).
|
|
7
|
+
* @param props.data - Any extra data to include in the response body.
|
|
8
|
+
*/
|
|
9
|
+
constructor(s) {
|
|
10
|
+
super(), this.name = "UnprocessableEntity", this.status = 422, this.statusText = s.message || "Unprocessable entity", this.debugColor = "yellow", this.cause = {
|
|
11
|
+
data: s.data,
|
|
12
|
+
fieldErrors: s.fieldErrors,
|
|
13
|
+
fields: s.fields
|
|
14
|
+
}, this.onDebug();
|
|
15
|
+
}
|
|
16
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
17
|
+
toResponse() {
|
|
18
|
+
const s = {
|
|
19
|
+
headers: { "Content-Type": "application/json" },
|
|
20
|
+
status: this.status,
|
|
21
|
+
statusText: this.statusText
|
|
22
|
+
};
|
|
23
|
+
return new Response(JSON.stringify(this.makeBody()), s);
|
|
24
|
+
}
|
|
25
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
26
|
+
toJson() {
|
|
27
|
+
const s = {
|
|
28
|
+
status: this.status,
|
|
29
|
+
statusText: this.statusText
|
|
30
|
+
};
|
|
31
|
+
return Response.json(this.makeBody(), s);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
o as UnprocessableEntity
|
|
36
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var r = Object.defineProperty;
|
|
2
|
+
var a = (e, t, s) => t in e ? r(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
3
|
+
var u = (e, t, s) => a(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
+
import { DebugService as i } from "../../services/debugService.js";
|
|
5
|
+
import { flushDebugLogs as h } from "../../utilities/flushDebugLogs.js";
|
|
6
|
+
class m {
|
|
7
|
+
constructor() {
|
|
8
|
+
u(this, "_body", null);
|
|
9
|
+
u(this, "_name", "SuccessResponse");
|
|
10
|
+
u(this, "_status", 200);
|
|
11
|
+
u(this, "_statusText", "OK");
|
|
12
|
+
u(this, "_debugColor", "green");
|
|
13
|
+
}
|
|
14
|
+
get body() {
|
|
15
|
+
return this._body;
|
|
16
|
+
}
|
|
17
|
+
set body(t) {
|
|
18
|
+
this._body = t ?? null;
|
|
19
|
+
}
|
|
20
|
+
get name() {
|
|
21
|
+
return this._name;
|
|
22
|
+
}
|
|
23
|
+
set name(t) {
|
|
24
|
+
this._name = t;
|
|
25
|
+
}
|
|
26
|
+
get status() {
|
|
27
|
+
return this._status;
|
|
28
|
+
}
|
|
29
|
+
set status(t) {
|
|
30
|
+
this._status = t;
|
|
31
|
+
}
|
|
32
|
+
get statusText() {
|
|
33
|
+
return this._statusText;
|
|
34
|
+
}
|
|
35
|
+
set statusText(t) {
|
|
36
|
+
this._statusText = t;
|
|
37
|
+
}
|
|
38
|
+
get debugColor() {
|
|
39
|
+
return this._debugColor;
|
|
40
|
+
}
|
|
41
|
+
set debugColor(t) {
|
|
42
|
+
["green", "yellow", "cyan", "red"].includes(t) && (this._debugColor = t);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Logs debug information for success responses including caller context and response details.
|
|
46
|
+
*
|
|
47
|
+
* @param {any} body - The response body or success data to be logged
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const SuccessResponse = new SuccessResponse();
|
|
52
|
+
* SuccessResponse.onDebug({ data: "Operation completed successfully" });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
onDebug(t) {
|
|
56
|
+
const s = [], { callerInfo: o, functionName: n } = i.getCaller();
|
|
57
|
+
s.push(`Caller Function: ${n}`), s.push(`Caller Location: ${o}`), this.statusText && s.push(`Message: ${this.statusText}`), t && s.push(`Body: ${JSON.stringify(t)}`), h({ scheme: this._debugColor, name: this.name, debugs: s });
|
|
58
|
+
}
|
|
59
|
+
makeBody() {
|
|
60
|
+
return {
|
|
61
|
+
name: this.name,
|
|
62
|
+
message: this.statusText,
|
|
63
|
+
body: this.body
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
m as SuccessResponse
|
|
69
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SuccessResponse as e } from "./_successResponse.js";
|
|
2
|
+
class i extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Description included in the response status text.
|
|
5
|
+
* @param body - Data to include in the response body.
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "Created", this.status = 201, this.statusText = s, this.body = t || void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.body), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.body, s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as Created
|
|
30
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SuccessResponse as e } from "./_successResponse.js";
|
|
2
|
+
class i extends e {
|
|
3
|
+
/**
|
|
4
|
+
* @param message - Description included in the response status text.
|
|
5
|
+
* @param body - Data to include in the response body.
|
|
6
|
+
*/
|
|
7
|
+
constructor(s, t) {
|
|
8
|
+
super(), this.name = "Found", this.status = 302, this.statusText = s, this.body = t || void 0, this.onDebug();
|
|
9
|
+
}
|
|
10
|
+
/** Converts to a `Response` with `Content-Type: application/json` header. */
|
|
11
|
+
toResponse() {
|
|
12
|
+
const s = {
|
|
13
|
+
headers: { "Content-Type": "application/json" },
|
|
14
|
+
status: this.status,
|
|
15
|
+
statusText: this.statusText
|
|
16
|
+
};
|
|
17
|
+
return new Response(JSON.stringify(this.body), s);
|
|
18
|
+
}
|
|
19
|
+
/** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
|
|
20
|
+
toJson() {
|
|
21
|
+
const s = {
|
|
22
|
+
status: this.status,
|
|
23
|
+
statusText: this.statusText
|
|
24
|
+
};
|
|
25
|
+
return Response.json(this.body, s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as Found
|
|
30
|
+
};
|