@arkyn/server 2.0.1-beta.1 → 2.0.1-beta.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.
Files changed (136) hide show
  1. package/dist/http/badResponses/badGateway.d.ts +11 -0
  2. package/dist/http/badResponses/badGateway.d.ts.map +1 -0
  3. package/dist/http/badResponses/badGateway.js +29 -0
  4. package/dist/http/badResponses/badRequest.d.ts +11 -0
  5. package/dist/http/badResponses/badRequest.d.ts.map +1 -0
  6. package/dist/http/badResponses/badRequest.js +29 -0
  7. package/dist/http/badResponses/conflict.d.ts +11 -0
  8. package/dist/http/badResponses/conflict.d.ts.map +1 -0
  9. package/dist/http/badResponses/conflict.js +29 -0
  10. package/dist/http/badResponses/forbidden.d.ts +11 -0
  11. package/dist/http/badResponses/forbidden.d.ts.map +1 -0
  12. package/dist/http/badResponses/forbidden.js +29 -0
  13. package/dist/http/badResponses/notFound.d.ts +11 -0
  14. package/dist/http/badResponses/notFound.d.ts.map +1 -0
  15. package/dist/http/badResponses/notFound.js +29 -0
  16. package/dist/http/badResponses/notImplemented.d.ts +11 -0
  17. package/dist/http/badResponses/notImplemented.d.ts.map +1 -0
  18. package/dist/http/badResponses/notImplemented.js +29 -0
  19. package/dist/http/badResponses/serverError.d.ts +11 -0
  20. package/dist/http/badResponses/serverError.d.ts.map +1 -0
  21. package/dist/http/badResponses/serverError.js +29 -0
  22. package/dist/http/badResponses/unauthorized.d.ts +11 -0
  23. package/dist/http/badResponses/unauthorized.d.ts.map +1 -0
  24. package/dist/http/badResponses/unauthorized.js +29 -0
  25. package/dist/http/badResponses/unprocessableEntity.d.ts +16 -0
  26. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -0
  27. package/dist/http/badResponses/unprocessableEntity.js +33 -0
  28. package/dist/http/httpDebug.d.ts +3 -0
  29. package/dist/http/httpDebug.d.ts.map +1 -0
  30. package/dist/http/httpDebug.js +15 -0
  31. package/dist/http/successResponses/created.d.ts +11 -0
  32. package/dist/http/successResponses/created.d.ts.map +1 -0
  33. package/dist/http/successResponses/created.js +29 -0
  34. package/dist/http/successResponses/found.d.ts +11 -0
  35. package/dist/http/successResponses/found.d.ts.map +1 -0
  36. package/dist/http/successResponses/found.js +29 -0
  37. package/dist/http/successResponses/noContent.d.ts +10 -0
  38. package/dist/http/successResponses/noContent.d.ts.map +1 -0
  39. package/dist/http/successResponses/noContent.js +27 -0
  40. package/dist/http/successResponses/success.d.ts +11 -0
  41. package/dist/http/successResponses/success.d.ts.map +1 -0
  42. package/dist/http/successResponses/success.js +29 -0
  43. package/dist/http/successResponses/updated.d.ts +11 -0
  44. package/dist/http/successResponses/updated.d.ts.map +1 -0
  45. package/dist/http/successResponses/updated.js +29 -0
  46. package/dist/index.d.ts +16 -13
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +16 -17
  49. package/dist/services/decodeRequestBody.d.ts +17 -0
  50. package/dist/services/decodeRequestBody.d.ts.map +1 -0
  51. package/dist/services/{extractJsonFromRequest.js → decodeRequestBody.js} +16 -3
  52. package/dist/services/errorHandler.d.ts +3 -0
  53. package/dist/services/errorHandler.d.ts.map +1 -0
  54. package/dist/services/errorHandler.js +51 -0
  55. package/dist/services/formParse.d.ts +40 -1
  56. package/dist/services/formParse.d.ts.map +1 -1
  57. package/dist/services/formParse.js +40 -1
  58. package/dist/services/getScopedParams.d.ts +26 -1
  59. package/dist/services/getScopedParams.d.ts.map +1 -1
  60. package/dist/services/getScopedParams.js +26 -2
  61. package/dist/services/sendFileToS3.d.ts +50 -18
  62. package/dist/services/sendFileToS3.d.ts.map +1 -1
  63. package/dist/services/sendFileToS3.js +73 -31
  64. package/package.json +2 -1
  65. package/src/http/badResponses/badGateway.ts +36 -0
  66. package/src/http/badResponses/badRequest.ts +36 -0
  67. package/src/http/badResponses/conflict.ts +36 -0
  68. package/src/http/badResponses/forbidden.ts +36 -0
  69. package/src/http/badResponses/notFound.ts +36 -0
  70. package/src/http/badResponses/notImplemented.ts +36 -0
  71. package/src/http/badResponses/serverError.ts +36 -0
  72. package/src/http/badResponses/unauthorized.ts +36 -0
  73. package/src/http/badResponses/unprocessableEntity.ts +48 -0
  74. package/src/http/httpDebug.ts +31 -0
  75. package/src/http/successResponses/created.ts +35 -0
  76. package/src/http/successResponses/found.ts +35 -0
  77. package/src/http/successResponses/noContent.ts +33 -0
  78. package/src/http/successResponses/success.ts +35 -0
  79. package/src/http/successResponses/updated.ts +35 -0
  80. package/src/index.ts +16 -18
  81. package/src/services/decodeRequestBody.ts +46 -0
  82. package/src/services/errorHandler.ts +55 -0
  83. package/src/services/formParse.ts +42 -1
  84. package/src/services/getScopedParams.ts +29 -2
  85. package/src/services/sendFileToS3.ts +81 -56
  86. package/dist/helpers/globalErrorHandler.d.ts +0 -3
  87. package/dist/helpers/globalErrorHandler.d.ts.map +0 -1
  88. package/dist/helpers/globalErrorHandler.js +0 -53
  89. package/dist/httpBadResponses/badRequest.d.ts +0 -9
  90. package/dist/httpBadResponses/badRequest.d.ts.map +0 -1
  91. package/dist/httpBadResponses/badRequest.js +0 -23
  92. package/dist/httpBadResponses/conflict.d.ts +0 -9
  93. package/dist/httpBadResponses/conflict.d.ts.map +0 -1
  94. package/dist/httpBadResponses/conflict.js +0 -23
  95. package/dist/httpBadResponses/forbidden.d.ts +0 -9
  96. package/dist/httpBadResponses/forbidden.d.ts.map +0 -1
  97. package/dist/httpBadResponses/forbidden.js +0 -23
  98. package/dist/httpBadResponses/notFound.d.ts +0 -9
  99. package/dist/httpBadResponses/notFound.d.ts.map +0 -1
  100. package/dist/httpBadResponses/notFound.js +0 -23
  101. package/dist/httpBadResponses/serverError.d.ts +0 -9
  102. package/dist/httpBadResponses/serverError.d.ts.map +0 -1
  103. package/dist/httpBadResponses/serverError.js +0 -23
  104. package/dist/httpBadResponses/unauthorized.d.ts +0 -9
  105. package/dist/httpBadResponses/unauthorized.d.ts.map +0 -1
  106. package/dist/httpBadResponses/unauthorized.js +0 -23
  107. package/dist/httpBadResponses/unprocessableEntity.d.ts +0 -17
  108. package/dist/httpBadResponses/unprocessableEntity.d.ts.map +0 -1
  109. package/dist/httpBadResponses/unprocessableEntity.js +0 -30
  110. package/dist/httpResponses/created.d.ts +0 -10
  111. package/dist/httpResponses/created.d.ts.map +0 -1
  112. package/dist/httpResponses/created.js +0 -30
  113. package/dist/httpResponses/noContent.d.ts +0 -9
  114. package/dist/httpResponses/noContent.d.ts.map +0 -1
  115. package/dist/httpResponses/noContent.js +0 -28
  116. package/dist/httpResponses/success.d.ts +0 -10
  117. package/dist/httpResponses/success.d.ts.map +0 -1
  118. package/dist/httpResponses/success.js +0 -30
  119. package/dist/httpResponses/updated.d.ts +0 -10
  120. package/dist/httpResponses/updated.d.ts.map +0 -1
  121. package/dist/httpResponses/updated.js +0 -30
  122. package/dist/services/extractJsonFromRequest.d.ts +0 -3
  123. package/dist/services/extractJsonFromRequest.d.ts.map +0 -1
  124. package/src/helpers/globalErrorHandler.ts +0 -64
  125. package/src/httpBadResponses/badRequest.ts +0 -29
  126. package/src/httpBadResponses/conflict.ts +0 -29
  127. package/src/httpBadResponses/forbidden.ts +0 -29
  128. package/src/httpBadResponses/notFound.ts +0 -29
  129. package/src/httpBadResponses/serverError.ts +0 -29
  130. package/src/httpBadResponses/unauthorized.ts +0 -29
  131. package/src/httpBadResponses/unprocessableEntity.ts +0 -43
  132. package/src/httpResponses/created.ts +0 -35
  133. package/src/httpResponses/noContent.ts +0 -33
  134. package/src/httpResponses/success.ts +0 -35
  135. package/src/httpResponses/updated.ts +0 -35
  136. package/src/services/extractJsonFromRequest.ts +0 -30
@@ -1,17 +0,0 @@
1
- type UnprocessableEntityErrorProps = {
2
- data?: any;
3
- fieldErrors?: Record<string, string>;
4
- fields?: Record<string, string>;
5
- message?: string;
6
- };
7
- declare function unprocessableEntity(error: UnprocessableEntityError): Response;
8
- declare class UnprocessableEntityError {
9
- name: string;
10
- message?: string;
11
- fieldErrors: any;
12
- fields: any;
13
- data: any;
14
- constructor(data: UnprocessableEntityErrorProps);
15
- }
16
- export { unprocessableEntity, UnprocessableEntityError };
17
- //# sourceMappingURL=unprocessableEntity.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../src/httpBadResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAAA,KAAK,6BAA6B,GAAG;IACnC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,iBAAS,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,YAiB3D;AAED,cAAM,wBAAwB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,GAAG,CAAC;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC;gBAEE,IAAI,EAAE,6BAA6B;CAOhD;AAED,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1,30 +0,0 @@
1
- function unprocessableEntity(error) {
2
- return new Response(JSON.stringify({
3
- status: 433,
4
- success: false,
5
- name: error.name,
6
- message: error.message,
7
- data: error.data || null,
8
- fieldErrors: error.fieldErrors || null,
9
- fields: error.fields || null,
10
- }), {
11
- status: 433,
12
- statusText: "Bad Request",
13
- headers: { "Content-Type": "application/json" },
14
- });
15
- }
16
- class UnprocessableEntityError {
17
- name;
18
- message;
19
- fieldErrors;
20
- fields;
21
- data;
22
- constructor(data) {
23
- this.data = data?.data || null;
24
- this.fieldErrors = data?.fieldErrors || null;
25
- this.fields = data?.fields || null;
26
- this.name = "UnprocessableEntity";
27
- this.message = data?.message;
28
- }
29
- }
30
- export { unprocessableEntity, UnprocessableEntityError };
@@ -1,10 +0,0 @@
1
- declare function created(body: any, init?: ResponseInit): Response;
2
- declare class Created<T> {
3
- body: T;
4
- init: ResponseInit;
5
- constructor(body: T, init?: ResponseInit);
6
- response(): Response;
7
- json(): Promise<any>;
8
- }
9
- export { created, Created };
10
- //# sourceMappingURL=created.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"created.d.ts","sourceRoot":"","sources":["../../src/httpResponses/created.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,QAAQ;IAQR,IAAI;CAOL;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,30 +0,0 @@
1
- function created(body, init) {
2
- return new Response(JSON.stringify(body), {
3
- ...init,
4
- status: 201,
5
- headers: { "Content-Type": "application/json", ...init?.headers },
6
- });
7
- }
8
- class Created {
9
- body;
10
- init;
11
- constructor(body, init) {
12
- this.body = body;
13
- this.init = init || {};
14
- }
15
- response() {
16
- return new Response(JSON.stringify(this.body), {
17
- ...this.init,
18
- status: 201,
19
- headers: { "Content-Type": "application/json", ...this.init.headers },
20
- });
21
- }
22
- json() {
23
- return new Response(JSON.stringify(this.body), {
24
- ...this.init,
25
- status: 201,
26
- headers: { "Content-Type": "application/json", ...this.init.headers },
27
- }).json();
28
- }
29
- }
30
- export { created, Created };
@@ -1,9 +0,0 @@
1
- declare function noContent(init?: ResponseInit): Response;
2
- declare class NoContent {
3
- init: ResponseInit;
4
- constructor(init?: ResponseInit);
5
- response(): Response;
6
- json(): Promise<any>;
7
- }
8
- export { noContent, NoContent };
9
- //# sourceMappingURL=noContent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"noContent.d.ts","sourceRoot":"","sources":["../../src/httpResponses/noContent.ts"],"names":[],"mappings":"AAAA,iBAAS,SAAS,CAAC,IAAI,CAAC,EAAE,YAAY,GAAG,QAAQ,CAMhD;AAED,cAAM,SAAS;IACb,IAAI,EAAE,YAAY,CAAC;gBAEP,IAAI,CAAC,EAAE,YAAY;IAI/B,QAAQ;IAQR,IAAI;CAOL;AAED,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}
@@ -1,28 +0,0 @@
1
- function noContent(init) {
2
- return new Response(null, {
3
- ...init,
4
- status: 200,
5
- headers: { "Content-Type": "application/json", ...init?.headers },
6
- });
7
- }
8
- class NoContent {
9
- init;
10
- constructor(init) {
11
- this.init = init || {};
12
- }
13
- response() {
14
- return new Response(null, {
15
- ...this.init,
16
- status: 200,
17
- headers: { "Content-Type": "application/json", ...this.init.headers },
18
- });
19
- }
20
- json() {
21
- return new Response(null, {
22
- ...this.init,
23
- status: 200,
24
- headers: { "Content-Type": "application/json", ...this.init.headers },
25
- }).json();
26
- }
27
- }
28
- export { noContent, NoContent };
@@ -1,10 +0,0 @@
1
- declare function success(body: any, init?: ResponseInit): Response;
2
- declare class Success<T> {
3
- body: T;
4
- init: ResponseInit;
5
- constructor(body: T, init?: ResponseInit);
6
- response(): Response;
7
- json(): Promise<any>;
8
- }
9
- export { success, Success };
10
- //# sourceMappingURL=success.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"success.d.ts","sourceRoot":"","sources":["../../src/httpResponses/success.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,QAAQ;IAQR,IAAI;CAOL;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,30 +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
- response() {
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
- json() {
23
- return new Response(JSON.stringify(this.body), {
24
- ...this.init,
25
- status: 200,
26
- headers: { "Content-Type": "application/json", ...this.init.headers },
27
- }).json();
28
- }
29
- }
30
- export { success, Success };
@@ -1,10 +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
- response(): Response;
7
- json(): Promise<any>;
8
- }
9
- export { updated, Updated };
10
- //# 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,QAAQ;IAQR,IAAI;CAOL;AAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,30 +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
- response() {
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
- json() {
23
- return new Response(JSON.stringify(this.body), {
24
- ...this.init,
25
- status: 200,
26
- headers: { "Content-Type": "application/json", ...this.init.headers },
27
- }).json();
28
- }
29
- }
30
- export { updated, Updated };
@@ -1,3 +0,0 @@
1
- declare function extractJsonFromRequest(req: Request): Promise<any>;
2
- export { extractJsonFromRequest };
3
- //# sourceMappingURL=extractJsonFromRequest.d.ts.map
@@ -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,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,35 +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
- 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
- json() {
27
- return new Response(JSON.stringify(this.body), {
28
- ...this.init,
29
- status: 201,
30
- headers: { "Content-Type": "application/json", ...this.init.headers },
31
- }).json();
32
- }
33
- }
34
-
35
- export { created, Created };
@@ -1,33 +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
- 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
- json() {
25
- return new Response(null, {
26
- ...this.init,
27
- status: 200,
28
- headers: { "Content-Type": "application/json", ...this.init.headers },
29
- }).json();
30
- }
31
- }
32
-
33
- export { noContent, NoContent };
@@ -1,35 +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
- 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
- json() {
27
- return new Response(JSON.stringify(this.body), {
28
- ...this.init,
29
- status: 200,
30
- headers: { "Content-Type": "application/json", ...this.init.headers },
31
- }).json();
32
- }
33
- }
34
-
35
- export { success, Success };
@@ -1,35 +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
- 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
- json() {
27
- return new Response(JSON.stringify(this.body), {
28
- ...this.init,
29
- status: 200,
30
- headers: { "Content-Type": "application/json", ...this.init.headers },
31
- }).json();
32
- }
33
- }
34
-
35
- export { updated, Updated };