@arkyn/server 1.5.1 → 1.5.3
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/LICENSE.txt +24 -0
- package/README.md +116 -0
- package/dist/api/__test__/deleteRequest.spec.d.ts +2 -0
- package/dist/api/__test__/deleteRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/deleteRequest.spec.js +84 -0
- package/dist/api/__test__/getRequest.spec.d.ts +2 -0
- package/dist/api/__test__/getRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/getRequest.spec.js +62 -0
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts +2 -0
- package/dist/api/__test__/inboxFlowRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/inboxFlowRequest.spec.js +96 -0
- package/dist/api/__test__/makeRequest.spec.d.ts +2 -0
- package/dist/api/__test__/makeRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/makeRequest.spec.js +80 -0
- package/dist/api/__test__/patchRequest.spec.d.ts +2 -0
- package/dist/api/__test__/patchRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/patchRequest.spec.js +84 -0
- package/dist/api/__test__/postRequest.spec.d.ts +2 -0
- package/dist/api/__test__/postRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/postRequest.spec.js +84 -0
- package/dist/api/__test__/putRequest.spec.d.ts +2 -0
- package/dist/api/__test__/putRequest.spec.d.ts.map +1 -0
- package/dist/api/__test__/putRequest.spec.js +84 -0
- package/dist/api/deleteRequest.d.ts +13 -0
- package/dist/api/deleteRequest.d.ts.map +1 -0
- package/dist/api/deleteRequest.js +14 -0
- package/dist/api/getRequest.d.ts +12 -0
- package/dist/api/getRequest.d.ts.map +1 -0
- package/dist/api/getRequest.js +13 -0
- package/dist/api/inboxFlowRequest.d.ts +40 -0
- package/dist/api/inboxFlowRequest.d.ts.map +1 -0
- package/dist/api/inboxFlowRequest.js +63 -0
- package/dist/api/makeRequest.d.ts +38 -0
- package/dist/api/makeRequest.d.ts.map +1 -0
- package/dist/api/makeRequest.js +103 -0
- package/dist/api/patchRequest.d.ts +13 -0
- package/dist/api/patchRequest.d.ts.map +1 -0
- package/dist/api/patchRequest.js +14 -0
- package/dist/api/postRequest.d.ts +13 -0
- package/dist/api/postRequest.d.ts.map +1 -0
- package/dist/api/postRequest.js +14 -0
- package/dist/api/putRequest.d.ts +13 -0
- package/dist/api/putRequest.d.ts.map +1 -0
- package/dist/api/putRequest.js +14 -0
- package/dist/config/__test__/apiInstance.spec.d.ts +2 -0
- package/dist/config/__test__/apiInstance.spec.d.ts.map +1 -0
- package/dist/config/__test__/apiInstance.spec.js +86 -0
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts +2 -0
- package/dist/config/__test__/inboxFlowInstance.spec.d.ts.map +1 -0
- package/dist/config/__test__/inboxFlowInstance.spec.js +48 -0
- package/dist/config/apiInstance.d.ts +80 -0
- package/dist/config/apiInstance.d.ts.map +1 -0
- package/dist/config/apiInstance.js +111 -0
- package/dist/config/inboxFlowInstance.d.ts +44 -0
- package/dist/config/inboxFlowInstance.d.ts.map +1 -0
- package/dist/config/inboxFlowInstance.js +46 -0
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/badGateway.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/badGateway.spec.js +42 -0
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/badRequest.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/badRequest.spec.js +40 -0
- package/dist/http/badResponses/__test__/conflict.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/conflict.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/conflict.spec.js +40 -0
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/forbidden.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/forbidden.spec.js +40 -0
- package/dist/http/badResponses/__test__/notFound.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/notFound.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/notFound.spec.js +40 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/notImplemented.spec.js +40 -0
- package/dist/http/badResponses/__test__/serverError.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/serverError.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/serverError.spec.js +40 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/unauthorized.spec.js +40 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts +2 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts.map +1 -0
- package/dist/http/badResponses/__test__/unprocessableEntity.spec.js +66 -0
- package/dist/http/badResponses/badGateway.d.ts +34 -0
- package/dist/http/badResponses/badGateway.d.ts.map +1 -0
- package/dist/http/badResponses/badGateway.js +52 -0
- package/dist/http/badResponses/badRequest.d.ts +34 -0
- package/dist/http/badResponses/badRequest.d.ts.map +1 -0
- package/dist/http/badResponses/badRequest.js +52 -0
- package/dist/http/badResponses/conflict.d.ts +34 -0
- package/dist/http/badResponses/conflict.d.ts.map +1 -0
- package/dist/http/badResponses/conflict.js +52 -0
- package/dist/http/badResponses/forbidden.d.ts +34 -0
- package/dist/http/badResponses/forbidden.d.ts.map +1 -0
- package/dist/http/badResponses/forbidden.js +52 -0
- package/dist/http/badResponses/notFound.d.ts +34 -0
- package/dist/http/badResponses/notFound.d.ts.map +1 -0
- package/dist/http/badResponses/notFound.js +52 -0
- package/dist/http/badResponses/notImplemented.d.ts +34 -0
- package/dist/http/badResponses/notImplemented.d.ts.map +1 -0
- package/dist/http/badResponses/notImplemented.js +52 -0
- package/dist/http/badResponses/serverError.d.ts +34 -0
- package/dist/http/badResponses/serverError.d.ts.map +1 -0
- package/dist/http/badResponses/serverError.js +52 -0
- package/dist/http/badResponses/unauthorized.d.ts +34 -0
- package/dist/http/badResponses/unauthorized.d.ts.map +1 -0
- package/dist/http/badResponses/unauthorized.js +52 -0
- package/dist/http/badResponses/unprocessableEntity.d.ts +43 -0
- package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -0
- package/dist/http/badResponses/unprocessableEntity.js +60 -0
- package/dist/http/successResponses/__test__/created.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/created.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/created.spec.js +57 -0
- package/dist/http/successResponses/__test__/found.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/found.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/found.spec.js +57 -0
- package/dist/http/successResponses/__test__/noContent.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/noContent.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/noContent.spec.js +40 -0
- package/dist/http/successResponses/__test__/success.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/success.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/success.spec.js +60 -0
- package/dist/http/successResponses/__test__/updated.spec.d.ts +2 -0
- package/dist/http/successResponses/__test__/updated.spec.d.ts.map +1 -0
- package/dist/http/successResponses/__test__/updated.spec.js +60 -0
- package/dist/http/successResponses/created.d.ts +36 -0
- package/dist/http/successResponses/created.d.ts.map +1 -0
- package/dist/http/successResponses/created.js +54 -0
- package/dist/http/successResponses/found.d.ts +39 -0
- package/dist/http/successResponses/found.d.ts.map +1 -0
- package/dist/http/successResponses/found.js +57 -0
- package/dist/http/successResponses/noContent.d.ts +25 -0
- package/dist/http/successResponses/noContent.d.ts.map +1 -0
- package/dist/http/successResponses/noContent.js +35 -0
- package/dist/http/successResponses/success.d.ts +36 -0
- package/dist/http/successResponses/success.d.ts.map +1 -0
- package/dist/http/successResponses/success.js +54 -0
- package/dist/http/successResponses/updated.d.ts +36 -0
- package/dist/http/successResponses/updated.d.ts.map +1 -0
- package/dist/http/successResponses/updated.js +54 -0
- package/dist/index.d.ts +22 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -15
- package/dist/services/__test__/decodeRequestBody.spec.d.ts +2 -0
- package/dist/services/__test__/decodeRequestBody.spec.d.ts.map +1 -0
- package/dist/services/__test__/decodeRequestBody.spec.js +39 -0
- package/dist/services/__test__/errorHandler.spec.d.ts +2 -0
- package/dist/services/__test__/errorHandler.spec.d.ts.map +1 -0
- package/dist/services/__test__/errorHandler.spec.js +115 -0
- package/dist/services/__test__/formParse.spec.d.ts +2 -0
- package/dist/services/__test__/formParse.spec.d.ts.map +1 -0
- package/dist/services/__test__/formParse.spec.js +78 -0
- package/dist/services/__test__/getCaller.spec.d.ts +2 -0
- package/dist/services/__test__/getCaller.spec.d.ts.map +1 -0
- package/dist/services/__test__/getCaller.spec.js +60 -0
- package/dist/services/__test__/getScopedParams.spec.d.ts +2 -0
- package/dist/services/__test__/getScopedParams.spec.d.ts.map +1 -0
- package/dist/services/__test__/getScopedParams.spec.js +51 -0
- package/dist/services/__test__/schemaValidator.spec.d.ts +2 -0
- package/dist/services/__test__/schemaValidator.spec.d.ts.map +1 -0
- package/dist/services/__test__/schemaValidator.spec.js +89 -0
- package/dist/services/decodeErrorMessageFromRequest.d.ts +17 -0
- package/dist/services/decodeErrorMessageFromRequest.d.ts.map +1 -0
- package/dist/services/decodeErrorMessageFromRequest.js +30 -0
- package/dist/services/decodeRequestBody.d.ts +17 -0
- package/dist/services/decodeRequestBody.d.ts.map +1 -0
- package/dist/services/decodeRequestBody.js +38 -0
- package/dist/services/errorHandler.d.ts +44 -0
- package/dist/services/errorHandler.d.ts.map +1 -0
- package/dist/services/errorHandler.js +93 -0
- package/dist/services/formParse.d.ts +40 -1
- package/dist/services/formParse.d.ts.map +1 -1
- package/dist/services/formParse.js +44 -3
- package/dist/services/getCaller.d.ts +17 -0
- package/dist/services/getCaller.d.ts.map +1 -0
- package/dist/services/getCaller.js +45 -0
- package/dist/services/getScopedParams.d.ts +26 -1
- package/dist/services/getScopedParams.d.ts.map +1 -1
- package/dist/services/getScopedParams.js +26 -2
- package/dist/services/httpDebug.d.ts +35 -0
- package/dist/services/httpDebug.d.ts.map +1 -0
- package/dist/services/httpDebug.js +56 -0
- package/dist/services/schemaValidator.d.ts +13 -0
- package/dist/services/schemaValidator.d.ts.map +1 -0
- package/dist/services/schemaValidator.js +51 -0
- package/dist/services/sendFileToS3.d.ts +50 -18
- package/dist/services/sendFileToS3.d.ts.map +1 -1
- package/dist/services/sendFileToS3.js +73 -31
- package/package.json +14 -6
- package/src/api/__test__/deleteRequest.spec.ts +107 -0
- package/src/api/__test__/getRequest.spec.ts +76 -0
- package/src/api/__test__/inboxFlowRequest.spec.ts +125 -0
- package/src/api/__test__/makeRequest.spec.ts +121 -0
- package/src/api/__test__/patchRequest.spec.ts +125 -0
- package/src/api/__test__/postRequest.spec.ts +125 -0
- package/src/api/__test__/putRequest.spec.ts +125 -0
- package/src/api/deleteRequest.ts +22 -0
- package/src/api/getRequest.ts +20 -0
- package/src/api/inboxFlowRequest.ts +76 -0
- package/src/api/makeRequest.ts +117 -0
- package/src/api/patchRequest.ts +22 -0
- package/src/api/postRequest.ts +22 -0
- package/src/api/putRequest.ts +22 -0
- package/src/config/__test__/apiInstance.spec.ts +129 -0
- package/src/config/__test__/inboxFlowInstance.spec.ts +61 -0
- package/src/config/apiInstance.ts +148 -0
- package/src/config/inboxFlowInstance.ts +65 -0
- package/src/http/badResponses/__test__/badGateway.spec.ts +50 -0
- package/src/http/badResponses/__test__/badRequest.spec.ts +50 -0
- package/src/http/badResponses/__test__/conflict.spec.ts +50 -0
- package/src/http/badResponses/__test__/forbidden.spec.ts +50 -0
- package/src/http/badResponses/__test__/notFound.spec.ts +50 -0
- package/src/http/badResponses/__test__/notImplemented.spec.ts +50 -0
- package/src/http/badResponses/__test__/serverError.spec.ts +50 -0
- package/src/http/badResponses/__test__/unauthorized.spec.ts +50 -0
- package/src/http/badResponses/__test__/unprocessableEntity.spec.ts +76 -0
- package/src/http/badResponses/badGateway.ts +63 -0
- package/src/http/badResponses/badRequest.ts +63 -0
- package/src/http/badResponses/conflict.ts +63 -0
- package/src/http/badResponses/forbidden.ts +63 -0
- package/src/http/badResponses/notFound.ts +63 -0
- package/src/http/badResponses/notImplemented.ts +63 -0
- package/src/http/badResponses/serverError.ts +63 -0
- package/src/http/badResponses/unauthorized.ts +63 -0
- package/src/http/badResponses/unprocessableEntity.ts +79 -0
- package/src/http/successResponses/__test__/created.spec.ts +65 -0
- package/src/http/successResponses/__test__/found.spec.ts +65 -0
- package/src/http/successResponses/__test__/noContent.spec.ts +49 -0
- package/src/http/successResponses/__test__/success.spec.ts +68 -0
- package/src/http/successResponses/__test__/updated.spec.ts +68 -0
- package/src/http/successResponses/created.ts +64 -0
- package/src/http/successResponses/found.ts +67 -0
- package/src/http/successResponses/noContent.ts +42 -0
- package/src/http/successResponses/success.ts +64 -0
- package/src/http/successResponses/updated.ts +64 -0
- package/src/index.ts +25 -16
- package/src/services/__test__/decodeRequestBody.spec.ts +51 -0
- package/src/services/__test__/errorHandler.spec.ts +133 -0
- package/src/services/__test__/formParse.spec.ts +96 -0
- package/src/services/__test__/getCaller.spec.ts +78 -0
- package/src/services/__test__/getScopedParams.spec.ts +68 -0
- package/src/services/__test__/schemaValidator.spec.ts +106 -0
- package/src/services/decodeErrorMessageFromRequest.ts +36 -0
- package/src/services/decodeRequestBody.ts +42 -0
- package/src/services/errorHandler.ts +99 -0
- package/src/services/formParse.ts +46 -6
- package/src/services/getCaller.ts +58 -0
- package/src/services/getScopedParams.ts +29 -2
- package/src/services/httpDebug.ts +64 -0
- package/src/services/schemaValidator.ts +66 -0
- package/src/services/sendFileToS3.ts +81 -56
- package/vitest.config.ts +5 -0
- package/dist/helpers/globalErrorHandler.d.ts +0 -3
- package/dist/helpers/globalErrorHandler.d.ts.map +0 -1
- package/dist/helpers/globalErrorHandler.js +0 -53
- package/dist/httpBadResponses/badRequest.d.ts +0 -9
- package/dist/httpBadResponses/badRequest.d.ts.map +0 -1
- package/dist/httpBadResponses/badRequest.js +0 -23
- package/dist/httpBadResponses/conflict.d.ts +0 -9
- package/dist/httpBadResponses/conflict.d.ts.map +0 -1
- package/dist/httpBadResponses/conflict.js +0 -23
- package/dist/httpBadResponses/forbidden.d.ts +0 -9
- package/dist/httpBadResponses/forbidden.d.ts.map +0 -1
- package/dist/httpBadResponses/forbidden.js +0 -23
- package/dist/httpBadResponses/notFound.d.ts +0 -9
- package/dist/httpBadResponses/notFound.d.ts.map +0 -1
- package/dist/httpBadResponses/notFound.js +0 -23
- package/dist/httpBadResponses/serverError.d.ts +0 -9
- package/dist/httpBadResponses/serverError.d.ts.map +0 -1
- package/dist/httpBadResponses/serverError.js +0 -23
- package/dist/httpBadResponses/unauthorized.d.ts +0 -9
- package/dist/httpBadResponses/unauthorized.d.ts.map +0 -1
- package/dist/httpBadResponses/unauthorized.js +0 -23
- package/dist/httpBadResponses/unprocessableEntity.d.ts +0 -17
- package/dist/httpBadResponses/unprocessableEntity.d.ts.map +0 -1
- package/dist/httpBadResponses/unprocessableEntity.js +0 -30
- package/dist/httpResponses/created.d.ts +0 -9
- package/dist/httpResponses/created.d.ts.map +0 -1
- package/dist/httpResponses/created.js +0 -23
- package/dist/httpResponses/noContent.d.ts +0 -8
- package/dist/httpResponses/noContent.d.ts.map +0 -1
- package/dist/httpResponses/noContent.js +0 -21
- package/dist/httpResponses/success.d.ts +0 -9
- package/dist/httpResponses/success.d.ts.map +0 -1
- package/dist/httpResponses/success.js +0 -23
- package/dist/httpResponses/updated.d.ts +0 -9
- package/dist/httpResponses/updated.d.ts.map +0 -1
- package/dist/httpResponses/updated.js +0 -23
- package/dist/services/extractJsonFromRequest.d.ts +0 -3
- package/dist/services/extractJsonFromRequest.d.ts.map +0 -1
- package/dist/services/extractJsonFromRequest.js +0 -29
- package/src/helpers/globalErrorHandler.ts +0 -64
- package/src/httpBadResponses/badRequest.ts +0 -29
- package/src/httpBadResponses/conflict.ts +0 -29
- package/src/httpBadResponses/forbidden.ts +0 -29
- package/src/httpBadResponses/notFound.ts +0 -29
- package/src/httpBadResponses/serverError.ts +0 -29
- package/src/httpBadResponses/unauthorized.ts +0 -29
- package/src/httpBadResponses/unprocessableEntity.ts +0 -43
- package/src/httpResponses/created.ts +0 -27
- package/src/httpResponses/noContent.ts +0 -25
- package/src/httpResponses/success.ts +0 -27
- package/src/httpResponses/updated.ts +0 -27
- package/src/services/extractJsonFromRequest.ts +0 -30
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function success(body, init) {
|
|
2
|
-
return new Response(JSON.stringify(body), {
|
|
3
|
-
...init,
|
|
4
|
-
status: 200,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
class Success {
|
|
9
|
-
body;
|
|
10
|
-
init;
|
|
11
|
-
constructor(body, init) {
|
|
12
|
-
this.body = body;
|
|
13
|
-
this.init = init || {};
|
|
14
|
-
}
|
|
15
|
-
json() {
|
|
16
|
-
return new Response(JSON.stringify(this.body), {
|
|
17
|
-
...this.init,
|
|
18
|
-
status: 200,
|
|
19
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export { success, Success };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare function updated(body: any, init?: ResponseInit): Response;
|
|
2
|
-
declare class Updated<T> {
|
|
3
|
-
body: T;
|
|
4
|
-
init: ResponseInit;
|
|
5
|
-
constructor(body: T, init?: ResponseInit);
|
|
6
|
-
json(): Response;
|
|
7
|
-
}
|
|
8
|
-
export { updated, Updated };
|
|
9
|
-
//# sourceMappingURL=updated.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../src/httpResponses/updated.ts"],"names":[],"mappings":"AAAA,iBAAS,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,QAAQ,CAMzD;AAED,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,YAAY,CAAC;gBAEP,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAKxC,IAAI,IAAI,QAAQ;CAOjB;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function updated(body, init) {
|
|
2
|
-
return new Response(JSON.stringify(body), {
|
|
3
|
-
...init,
|
|
4
|
-
status: 200,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
class Updated {
|
|
9
|
-
body;
|
|
10
|
-
init;
|
|
11
|
-
constructor(body, init) {
|
|
12
|
-
this.body = body;
|
|
13
|
-
this.init = init || {};
|
|
14
|
-
}
|
|
15
|
-
json() {
|
|
16
|
-
return new Response(JSON.stringify(this.body), {
|
|
17
|
-
...this.init,
|
|
18
|
-
status: 200,
|
|
19
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export { updated, Updated };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractJsonFromRequest.d.ts","sourceRoot":"","sources":["../../src/services/extractJsonFromRequest.ts"],"names":[],"mappings":"AAAA,iBAAe,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CA2BhE;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
async function extractJsonFromRequest(req) {
|
|
2
|
-
let data;
|
|
3
|
-
try {
|
|
4
|
-
const arrayBuffer = await req.arrayBuffer();
|
|
5
|
-
const text = new TextDecoder().decode(arrayBuffer);
|
|
6
|
-
try {
|
|
7
|
-
data = JSON.parse(text);
|
|
8
|
-
}
|
|
9
|
-
catch (jsonError) {
|
|
10
|
-
try {
|
|
11
|
-
const formData = new URLSearchParams(text);
|
|
12
|
-
data = Object.fromEntries(formData.entries());
|
|
13
|
-
}
|
|
14
|
-
catch (formDataError) {
|
|
15
|
-
console.error("Failed to extract data from request:", {
|
|
16
|
-
jsonError,
|
|
17
|
-
formDataError,
|
|
18
|
-
});
|
|
19
|
-
data = {};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
console.error("Failed to read request body:", error);
|
|
25
|
-
data = {};
|
|
26
|
-
}
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
export { extractJsonFromRequest };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { badRequest, BadRequestError } from "../httpBadResponses/badRequest";
|
|
2
|
-
import { conflict, ConflictError } from "../httpBadResponses/conflict";
|
|
3
|
-
import { forbidden, ForbiddenError } from "../httpBadResponses/forbidden";
|
|
4
|
-
import { notFound, NotFoundError } from "../httpBadResponses/notFound";
|
|
5
|
-
import { serverError } from "../httpBadResponses/serverError";
|
|
6
|
-
import {
|
|
7
|
-
unauthorized,
|
|
8
|
-
UnauthorizedError,
|
|
9
|
-
} from "../httpBadResponses/unauthorized";
|
|
10
|
-
import {
|
|
11
|
-
unprocessableEntity,
|
|
12
|
-
UnprocessableEntityError,
|
|
13
|
-
} from "../httpBadResponses/unprocessableEntity";
|
|
14
|
-
import { created, Created } from "../httpResponses/created";
|
|
15
|
-
import { noContent, NoContent } from "../httpResponses/noContent";
|
|
16
|
-
import { success, Success } from "../httpResponses/success";
|
|
17
|
-
import { updated, Updated } from "../httpResponses/updated";
|
|
18
|
-
|
|
19
|
-
const globalErrorHandler = (error: any) => {
|
|
20
|
-
// If the error is not an instance of Error, return the response
|
|
21
|
-
switch (true) {
|
|
22
|
-
case error instanceof Response:
|
|
23
|
-
return error;
|
|
24
|
-
case error instanceof Created:
|
|
25
|
-
return created(error.body, error.init);
|
|
26
|
-
case error instanceof Updated:
|
|
27
|
-
return updated(error.body, error.init);
|
|
28
|
-
case error instanceof Success:
|
|
29
|
-
return success(error.body, error.init);
|
|
30
|
-
case error instanceof NoContent:
|
|
31
|
-
return noContent(error.init);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const showConsoleError =
|
|
35
|
-
process.env.NODE_ENV === "development" ||
|
|
36
|
-
process.env?.SHOW_ERRORS_IN_CONSOLE === "true";
|
|
37
|
-
|
|
38
|
-
// If showConsoleError is true, log the error to the console
|
|
39
|
-
if (showConsoleError) console.error(error);
|
|
40
|
-
|
|
41
|
-
// If the error is an instance of BadRequestError, ForbiddenError, ConflictError, UnauthorizedError, NotFoundError, or UnprocessableEntityError, return the error
|
|
42
|
-
switch (true) {
|
|
43
|
-
case error instanceof BadRequestError:
|
|
44
|
-
return badRequest(error);
|
|
45
|
-
case error instanceof ForbiddenError:
|
|
46
|
-
return forbidden(error);
|
|
47
|
-
case error instanceof ConflictError:
|
|
48
|
-
return conflict(error);
|
|
49
|
-
case error instanceof UnauthorizedError:
|
|
50
|
-
return unauthorized(error);
|
|
51
|
-
case error instanceof NotFoundError:
|
|
52
|
-
return notFound(error);
|
|
53
|
-
case error instanceof UnprocessableEntityError:
|
|
54
|
-
return unprocessableEntity(error);
|
|
55
|
-
default:
|
|
56
|
-
return serverError({
|
|
57
|
-
message: error?.message || "Server error | Message not found",
|
|
58
|
-
name: "Server Error",
|
|
59
|
-
cause: error.cause || "Unknown",
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export { globalErrorHandler };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function badRequest(error: BadRequestError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 400,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 400,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class BadRequestError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "BadRequestError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { badRequest, BadRequestError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function conflict(error: ConflictError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 409,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 409,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class ConflictError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "ConflictError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { conflict, ConflictError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function forbidden(error: ForbiddenError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 403,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 403,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class ForbiddenError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "ForbiddenError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { forbidden, ForbiddenError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function notFound(error: NotFoundError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 404,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 404,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class NotFoundError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "NotFoundError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { notFound, NotFoundError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function serverError(error: ServerError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 500,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 500,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class ServerError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "ServerError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { serverError, ServerError };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function unauthorized(error: UnauthorizedError) {
|
|
2
|
-
return new Response(
|
|
3
|
-
JSON.stringify({
|
|
4
|
-
status: 401,
|
|
5
|
-
success: false,
|
|
6
|
-
name: error.name,
|
|
7
|
-
message: error.message,
|
|
8
|
-
}),
|
|
9
|
-
{
|
|
10
|
-
status: 401,
|
|
11
|
-
statusText: "Bad Request",
|
|
12
|
-
headers: { "Content-Type": "application/json" },
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
class UnauthorizedError {
|
|
18
|
-
name: string;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: any;
|
|
21
|
-
|
|
22
|
-
constructor(message: string, cause?: any) {
|
|
23
|
-
this.name = "UnauthorizedError";
|
|
24
|
-
this.message = message;
|
|
25
|
-
this.cause = cause ? JSON.stringify(cause) : undefined;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { unauthorized, UnauthorizedError };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
type UnprocessableEntityErrorProps = {
|
|
2
|
-
data?: any;
|
|
3
|
-
fieldErrors?: Record<string, string>;
|
|
4
|
-
fields?: Record<string, string>;
|
|
5
|
-
message?: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
function unprocessableEntity(error: UnprocessableEntityError) {
|
|
9
|
-
return new Response(
|
|
10
|
-
JSON.stringify({
|
|
11
|
-
status: 433,
|
|
12
|
-
success: false,
|
|
13
|
-
name: error.name,
|
|
14
|
-
message: error.message,
|
|
15
|
-
data: error.data || null,
|
|
16
|
-
fieldErrors: error.fieldErrors || null,
|
|
17
|
-
fields: error.fields || null,
|
|
18
|
-
}),
|
|
19
|
-
{
|
|
20
|
-
status: 433,
|
|
21
|
-
statusText: "Bad Request",
|
|
22
|
-
headers: { "Content-Type": "application/json" },
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
class UnprocessableEntityError {
|
|
28
|
-
name: string;
|
|
29
|
-
message?: string;
|
|
30
|
-
fieldErrors: any;
|
|
31
|
-
fields: any;
|
|
32
|
-
data: any;
|
|
33
|
-
|
|
34
|
-
constructor(data: UnprocessableEntityErrorProps) {
|
|
35
|
-
this.data = data?.data || null;
|
|
36
|
-
this.fieldErrors = data?.fieldErrors || null;
|
|
37
|
-
this.fields = data?.fields || null;
|
|
38
|
-
this.name = "UnprocessableEntity";
|
|
39
|
-
this.message = data?.message;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { unprocessableEntity, UnprocessableEntityError };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function created(body: any, init?: ResponseInit): Response {
|
|
2
|
-
return new Response(JSON.stringify(body), {
|
|
3
|
-
...init,
|
|
4
|
-
status: 201,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class Created<T> {
|
|
10
|
-
body: T;
|
|
11
|
-
init: ResponseInit;
|
|
12
|
-
|
|
13
|
-
constructor(body: T, init?: ResponseInit) {
|
|
14
|
-
this.body = body;
|
|
15
|
-
this.init = init || {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
json(): Response {
|
|
19
|
-
return new Response(JSON.stringify(this.body), {
|
|
20
|
-
...this.init,
|
|
21
|
-
status: 201,
|
|
22
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { created, Created };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
function noContent(init?: ResponseInit): Response {
|
|
2
|
-
return new Response(null, {
|
|
3
|
-
...init,
|
|
4
|
-
status: 200,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class NoContent {
|
|
10
|
-
init: ResponseInit;
|
|
11
|
-
|
|
12
|
-
constructor(init?: ResponseInit) {
|
|
13
|
-
this.init = init || {};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
json(): Response {
|
|
17
|
-
return new Response(null, {
|
|
18
|
-
...this.init,
|
|
19
|
-
status: 200,
|
|
20
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { noContent, NoContent };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function success(body: any, init?: ResponseInit): Response {
|
|
2
|
-
return new Response(JSON.stringify(body), {
|
|
3
|
-
...init,
|
|
4
|
-
status: 200,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class Success<T> {
|
|
10
|
-
body: T;
|
|
11
|
-
init: ResponseInit;
|
|
12
|
-
|
|
13
|
-
constructor(body: T, init?: ResponseInit) {
|
|
14
|
-
this.body = body;
|
|
15
|
-
this.init = init || {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
json(): Response {
|
|
19
|
-
return new Response(JSON.stringify(this.body), {
|
|
20
|
-
...this.init,
|
|
21
|
-
status: 200,
|
|
22
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { success, Success };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function updated(body: any, init?: ResponseInit): Response {
|
|
2
|
-
return new Response(JSON.stringify(body), {
|
|
3
|
-
...init,
|
|
4
|
-
status: 200,
|
|
5
|
-
headers: { "Content-Type": "application/json", ...init?.headers },
|
|
6
|
-
});
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class Updated<T> {
|
|
10
|
-
body: T;
|
|
11
|
-
init: ResponseInit;
|
|
12
|
-
|
|
13
|
-
constructor(body: T, init?: ResponseInit) {
|
|
14
|
-
this.body = body;
|
|
15
|
-
this.init = init || {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
json(): Response {
|
|
19
|
-
return new Response(JSON.stringify(this.body), {
|
|
20
|
-
...this.init,
|
|
21
|
-
status: 200,
|
|
22
|
-
headers: { "Content-Type": "application/json", ...this.init.headers },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { updated, Updated };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
async function extractJsonFromRequest(req: Request): Promise<any> {
|
|
2
|
-
let data: any;
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
const arrayBuffer = await req.arrayBuffer();
|
|
6
|
-
const text = new TextDecoder().decode(arrayBuffer);
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
data = JSON.parse(text);
|
|
10
|
-
} catch (jsonError) {
|
|
11
|
-
try {
|
|
12
|
-
const formData = new URLSearchParams(text);
|
|
13
|
-
data = Object.fromEntries(formData.entries());
|
|
14
|
-
} catch (formDataError) {
|
|
15
|
-
console.error("Failed to extract data from request:", {
|
|
16
|
-
jsonError,
|
|
17
|
-
formDataError,
|
|
18
|
-
});
|
|
19
|
-
data = {};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error("Failed to read request body:", error);
|
|
24
|
-
data = {};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { extractJsonFromRequest };
|