@arkyn/server 2.0.1-beta.9 → 2.0.2

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 (128) hide show
  1. package/LICENSE.txt +24 -0
  2. package/README.md +116 -0
  3. package/dist/api/deleteRequest.d.ts +13 -0
  4. package/dist/api/deleteRequest.d.ts.map +1 -0
  5. package/dist/api/deleteRequest.js +14 -0
  6. package/dist/api/getRequest.d.ts +12 -0
  7. package/dist/api/getRequest.d.ts.map +1 -0
  8. package/dist/api/getRequest.js +13 -0
  9. package/dist/api/inboxFlowRequest.d.ts +40 -0
  10. package/dist/api/inboxFlowRequest.d.ts.map +1 -0
  11. package/dist/api/inboxFlowRequest.js +63 -0
  12. package/dist/api/makeRequest.d.ts +38 -0
  13. package/dist/api/makeRequest.d.ts.map +1 -0
  14. package/dist/api/makeRequest.js +103 -0
  15. package/dist/api/patchRequest.d.ts +13 -0
  16. package/dist/api/patchRequest.d.ts.map +1 -0
  17. package/dist/api/patchRequest.js +14 -0
  18. package/dist/api/postRequest.d.ts +13 -0
  19. package/dist/api/postRequest.d.ts.map +1 -0
  20. package/dist/api/postRequest.js +14 -0
  21. package/dist/api/putRequest.d.ts +13 -0
  22. package/dist/api/putRequest.d.ts.map +1 -0
  23. package/dist/api/putRequest.js +14 -0
  24. package/dist/config/apiInstance.d.ts +80 -0
  25. package/dist/config/apiInstance.d.ts.map +1 -0
  26. package/dist/config/apiInstance.js +111 -0
  27. package/dist/config/inboxFlowInstance.d.ts +44 -0
  28. package/dist/config/inboxFlowInstance.d.ts.map +1 -0
  29. package/dist/config/inboxFlowInstance.js +46 -0
  30. package/dist/http/badResponses/badGateway.d.ts +23 -0
  31. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  32. package/dist/http/badResponses/badGateway.js +24 -1
  33. package/dist/http/badResponses/badRequest.d.ts +23 -0
  34. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  35. package/dist/http/badResponses/badRequest.js +24 -1
  36. package/dist/http/badResponses/conflict.d.ts +23 -0
  37. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  38. package/dist/http/badResponses/conflict.js +24 -1
  39. package/dist/http/badResponses/forbidden.d.ts +23 -0
  40. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  41. package/dist/http/badResponses/forbidden.js +25 -2
  42. package/dist/http/badResponses/notFound.d.ts +23 -0
  43. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  44. package/dist/http/badResponses/notFound.js +24 -1
  45. package/dist/http/badResponses/notImplemented.d.ts +23 -0
  46. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  47. package/dist/http/badResponses/notImplemented.js +24 -1
  48. package/dist/http/badResponses/serverError.d.ts +23 -0
  49. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  50. package/dist/http/badResponses/serverError.js +24 -1
  51. package/dist/http/badResponses/unauthorized.d.ts +23 -0
  52. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  53. package/dist/http/badResponses/unauthorized.js +24 -1
  54. package/dist/http/badResponses/unprocessableEntity.d.ts +28 -1
  55. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  56. package/dist/http/badResponses/unprocessableEntity.js +30 -3
  57. package/dist/http/successResponses/created.d.ts +25 -0
  58. package/dist/http/successResponses/created.d.ts.map +1 -1
  59. package/dist/http/successResponses/created.js +25 -0
  60. package/dist/http/successResponses/found.d.ts +28 -0
  61. package/dist/http/successResponses/found.d.ts.map +1 -1
  62. package/dist/http/successResponses/found.js +28 -0
  63. package/dist/http/successResponses/noContent.d.ts +16 -1
  64. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  65. package/dist/http/successResponses/noContent.js +16 -8
  66. package/dist/http/successResponses/success.d.ts +25 -0
  67. package/dist/http/successResponses/success.d.ts.map +1 -1
  68. package/dist/http/successResponses/success.js +25 -0
  69. package/dist/http/successResponses/updated.d.ts +25 -0
  70. package/dist/http/successResponses/updated.d.ts.map +1 -1
  71. package/dist/http/successResponses/updated.js +25 -0
  72. package/dist/index.d.ts +6 -0
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +10 -0
  75. package/dist/services/decodeErrorMessageFromRequest.d.ts +17 -0
  76. package/dist/services/decodeErrorMessageFromRequest.d.ts.map +1 -0
  77. package/dist/services/decodeErrorMessageFromRequest.js +30 -0
  78. package/dist/services/decodeRequestBody.d.ts.map +1 -1
  79. package/dist/services/decodeRequestBody.js +12 -16
  80. package/dist/services/errorHandler.d.ts +42 -1
  81. package/dist/services/errorHandler.d.ts.map +1 -1
  82. package/dist/services/errorHandler.js +42 -0
  83. package/dist/services/formParse.d.ts.map +1 -1
  84. package/dist/services/formParse.js +4 -2
  85. package/dist/services/getCaller.d.ts +17 -0
  86. package/dist/services/getCaller.d.ts.map +1 -0
  87. package/dist/services/getCaller.js +45 -0
  88. package/dist/services/httpDebug.d.ts +35 -0
  89. package/dist/services/httpDebug.d.ts.map +1 -0
  90. package/dist/services/httpDebug.js +56 -0
  91. package/dist/services/schemaValidator.d.ts +13 -0
  92. package/dist/services/schemaValidator.d.ts.map +1 -0
  93. package/dist/services/schemaValidator.js +51 -0
  94. package/package.json +11 -5
  95. package/src/api/deleteRequest.ts +22 -0
  96. package/src/api/getRequest.ts +20 -0
  97. package/src/api/inboxFlowRequest.ts +76 -0
  98. package/src/api/makeRequest.ts +117 -0
  99. package/src/api/patchRequest.ts +22 -0
  100. package/src/api/postRequest.ts +22 -0
  101. package/src/api/putRequest.ts +22 -0
  102. package/src/config/apiInstance.ts +148 -0
  103. package/src/config/inboxFlowInstance.ts +65 -0
  104. package/src/http/badResponses/badGateway.ts +29 -2
  105. package/src/http/badResponses/badRequest.ts +29 -2
  106. package/src/http/badResponses/conflict.ts +29 -2
  107. package/src/http/badResponses/forbidden.ts +30 -3
  108. package/src/http/badResponses/notFound.ts +29 -2
  109. package/src/http/badResponses/notImplemented.ts +29 -2
  110. package/src/http/badResponses/serverError.ts +29 -2
  111. package/src/http/badResponses/unauthorized.ts +29 -2
  112. package/src/http/badResponses/unprocessableEntity.ts +33 -2
  113. package/src/http/successResponses/created.ts +31 -2
  114. package/src/http/successResponses/found.ts +32 -0
  115. package/src/http/successResponses/noContent.ts +20 -11
  116. package/src/http/successResponses/success.ts +31 -2
  117. package/src/http/successResponses/updated.ts +31 -2
  118. package/src/index.ts +9 -1
  119. package/src/services/decodeErrorMessageFromRequest.ts +36 -0
  120. package/src/services/decodeRequestBody.ts +11 -15
  121. package/src/services/errorHandler.ts +45 -1
  122. package/src/services/formParse.ts +4 -5
  123. package/src/services/getCaller.ts +39 -18
  124. package/src/services/httpDebug.ts +46 -5
  125. package/vitest.config.ts +5 -0
  126. package/dist/http/httpDebug.d.ts +0 -3
  127. package/dist/http/httpDebug.d.ts.map +0 -1
  128. package/dist/http/httpDebug.js +0 -15
@@ -1 +1 @@
1
- {"version":3,"file":"success.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/success.ts"],"names":[],"mappings":"AAAA,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;gBAEP,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAOxC,UAAU;IAUV,MAAM;CASP;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"success.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/success.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC;IACb,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,YAAY;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,14 +1,33 @@
1
+ /**
2
+ * Represents a successful HTTP response with a status code of 200 (OK).
3
+ * This class is used to standardize the structure of a "Success" response,
4
+ * including the response body, headers, status, and status text.
5
+ *
6
+ * @template T - The type of the response body.
7
+ */
1
8
  class Success {
2
9
  body;
3
10
  headers;
4
11
  status;
5
12
  statusText;
13
+ /**
14
+ * Creates an instance of the `Success` class.
15
+ *
16
+ * @param body - The response body to be included in the HTTP response.
17
+ * @param init - Optional initialization object for customizing headers, status, and status text.
18
+ */
6
19
  constructor(body, init) {
7
20
  this.body = body;
8
21
  this.headers = init?.headers || {};
9
22
  this.status = init?.status || 200;
10
23
  this.statusText = init?.statusText ?? "OK";
11
24
  }
25
+ /**
26
+ * Converts the `Success` instance into a `Response` object with a JSON body.
27
+ * This method ensures the response has the appropriate headers, status, and status text.
28
+ *
29
+ * @returns A `Response` object with the serialized JSON body and response metadata.
30
+ */
12
31
  toResponse() {
13
32
  const responseInit = {
14
33
  headers: { "Content-Type": "application/json", ...this.headers },
@@ -17,6 +36,12 @@ class Success {
17
36
  };
18
37
  return new Response(JSON.stringify(this.body), responseInit);
19
38
  }
39
+ /**
40
+ * Converts the `Success` instance into a `Response` object using the `Response.json` method.
41
+ * This method is an alternative to `toResponse` for generating JSON responses.
42
+ *
43
+ * @returns A `Response` object with the JSON body and response metadata.
44
+ */
20
45
  toJson() {
21
46
  const responseInit = {
22
47
  headers: this.headers,
@@ -1,10 +1,35 @@
1
+ /**
2
+ * Represents a successful HTTP response with a status code of 200 (OK) or other custom status codes.
3
+ * This class is used to standardize the structure of an "Updated" response,
4
+ * including the response body, headers, status, and status text.
5
+ *
6
+ * @template T - The type of the response body.
7
+ */
1
8
  declare class Updated<T> {
2
9
  body: T;
3
10
  headers: ResponseInit["headers"];
4
11
  status: number;
5
12
  statusText: string;
13
+ /**
14
+ * Creates an instance of the `Updated` class.
15
+ *
16
+ * @param body - The response body to be included in the HTTP response.
17
+ * @param init - Optional initialization object for customizing headers, status, and status text.
18
+ */
6
19
  constructor(body: T, init?: ResponseInit);
20
+ /**
21
+ * Converts the `Updated` instance into a `Response` object with a JSON body.
22
+ * This method ensures the response has the appropriate headers, status, and status text.
23
+ *
24
+ * @returns A `Response` object with the serialized JSON body and response metadata.
25
+ */
7
26
  toResponse(): Response;
27
+ /**
28
+ * Converts the `Updated` instance into a `Response` object using the `Response.json` method.
29
+ * This method is an alternative to `toResponse` for generating JSON responses.
30
+ *
31
+ * @returns A `Response` object with the JSON body and response metadata.
32
+ */
8
33
  toJson(): Response;
9
34
  }
10
35
  export { Updated };
@@ -1 +1 @@
1
- {"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/updated.ts"],"names":[],"mappings":"AAAA,cAAM,OAAO,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;gBAEP,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,YAAY;IAOxC,UAAU;IAUV,MAAM;CASP;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"updated.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/updated.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAM,OAAO,CAAC,CAAC;IACb,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,YAAY;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CASnB;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -1,14 +1,33 @@
1
+ /**
2
+ * Represents a successful HTTP response with a status code of 200 (OK) or other custom status codes.
3
+ * This class is used to standardize the structure of an "Updated" response,
4
+ * including the response body, headers, status, and status text.
5
+ *
6
+ * @template T - The type of the response body.
7
+ */
1
8
  class Updated {
2
9
  body;
3
10
  headers;
4
11
  status;
5
12
  statusText;
13
+ /**
14
+ * Creates an instance of the `Updated` class.
15
+ *
16
+ * @param body - The response body to be included in the HTTP response.
17
+ * @param init - Optional initialization object for customizing headers, status, and status text.
18
+ */
6
19
  constructor(body, init) {
7
20
  this.body = body;
8
21
  this.headers = init?.headers || {};
9
22
  this.status = init?.status || 200;
10
23
  this.statusText = init?.statusText || "Resource updated successfully";
11
24
  }
25
+ /**
26
+ * Converts the `Updated` instance into a `Response` object with a JSON body.
27
+ * This method ensures the response has the appropriate headers, status, and status text.
28
+ *
29
+ * @returns A `Response` object with the serialized JSON body and response metadata.
30
+ */
12
31
  toResponse() {
13
32
  const responseInit = {
14
33
  headers: { "Content-Type": "application/json", ...this.headers },
@@ -17,6 +36,12 @@ class Updated {
17
36
  };
18
37
  return new Response(JSON.stringify(this.body), responseInit);
19
38
  }
39
+ /**
40
+ * Converts the `Updated` instance into a `Response` object using the `Response.json` method.
41
+ * This method is an alternative to `toResponse` for generating JSON responses.
42
+ *
43
+ * @returns A `Response` object with the JSON body and response metadata.
44
+ */
20
45
  toJson() {
21
46
  const responseInit = {
22
47
  headers: this.headers,
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export { ApiInstance } from "./config/apiInstance";
2
+ export { InboxFlowInstance } from "./config/inboxFlowInstance";
1
3
  export { BadGateway } from "./http/badResponses/badGateway";
2
4
  export { BadRequest } from "./http/badResponses/badRequest";
3
5
  export { Conflict } from "./http/badResponses/conflict";
@@ -12,9 +14,13 @@ export { Found } from "./http/successResponses/found";
12
14
  export { NoContent } from "./http/successResponses/noContent";
13
15
  export { Success } from "./http/successResponses/success";
14
16
  export { Updated } from "./http/successResponses/updated";
17
+ export { decodeErrorMessageFromRequest } from "./services/decodeErrorMessageFromRequest";
15
18
  export { decodeRequestBody } from "./services/decodeRequestBody";
16
19
  export { errorHandler } from "./services/errorHandler";
17
20
  export { formParse } from "./services/formParse";
21
+ export { getCaller } from "./services/getCaller";
18
22
  export { getScopedParams } from "./services/getScopedParams";
23
+ export { httpDebug } from "./services/httpDebug";
24
+ export { SchemaValidator } from "./services/schemaValidator";
19
25
  export { sendFileToS3 } from "./services/sendFileToS3";
20
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAE9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAG/D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAG9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ // config
2
+ export { ApiInstance } from "./config/apiInstance";
3
+ export { InboxFlowInstance } from "./config/inboxFlowInstance";
4
+ // http bad responses
1
5
  export { BadGateway } from "./http/badResponses/badGateway";
2
6
  export { BadRequest } from "./http/badResponses/badRequest";
3
7
  export { Conflict } from "./http/badResponses/conflict";
@@ -7,13 +11,19 @@ export { NotImplemented } from "./http/badResponses/notImplemented";
7
11
  export { ServerError } from "./http/badResponses/serverError";
8
12
  export { Unauthorized } from "./http/badResponses/unauthorized";
9
13
  export { UnprocessableEntity } from "./http/badResponses/unprocessableEntity";
14
+ // http success responses
10
15
  export { Created } from "./http/successResponses/created";
11
16
  export { Found } from "./http/successResponses/found";
12
17
  export { NoContent } from "./http/successResponses/noContent";
13
18
  export { Success } from "./http/successResponses/success";
14
19
  export { Updated } from "./http/successResponses/updated";
20
+ // services
21
+ export { decodeErrorMessageFromRequest } from "./services/decodeErrorMessageFromRequest";
15
22
  export { decodeRequestBody } from "./services/decodeRequestBody";
16
23
  export { errorHandler } from "./services/errorHandler";
17
24
  export { formParse } from "./services/formParse";
25
+ export { getCaller } from "./services/getCaller";
18
26
  export { getScopedParams } from "./services/getScopedParams";
27
+ export { httpDebug } from "./services/httpDebug";
28
+ export { SchemaValidator } from "./services/schemaValidator";
19
29
  export { sendFileToS3 } from "./services/sendFileToS3";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Decodes an error message from a given request data object or response object.
3
+ *
4
+ * This function attempts to extract a meaningful error message from the provided
5
+ * `data` or `response` objects by checking various properties in a specific order.
6
+ * If no valid error message is found, it returns a default message: "Missing error message".
7
+ *
8
+ * @param data - The data object that may contain error information. It can have properties
9
+ * such as `message`, `error`, or `error.message` that are checked for a string value.
10
+ * @param response - The response object that may contain a `statusText` property
11
+ * representing the HTTP status text.
12
+ * @returns A string representing the decoded error message, or a default message
13
+ * if no error message is found.
14
+ */
15
+ declare function decodeErrorMessageFromRequest(data: any, response: Response): string;
16
+ export { decodeErrorMessageFromRequest };
17
+ //# sourceMappingURL=decodeErrorMessageFromRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decodeErrorMessageFromRequest.d.ts","sourceRoot":"","sources":["../../src/services/decodeErrorMessageFromRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,iBAAS,6BAA6B,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAkB5E;AAED,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Decodes an error message from a given request data object or response object.
3
+ *
4
+ * This function attempts to extract a meaningful error message from the provided
5
+ * `data` or `response` objects by checking various properties in a specific order.
6
+ * If no valid error message is found, it returns a default message: "Missing error message".
7
+ *
8
+ * @param data - The data object that may contain error information. It can have properties
9
+ * such as `message`, `error`, or `error.message` that are checked for a string value.
10
+ * @param response - The response object that may contain a `statusText` property
11
+ * representing the HTTP status text.
12
+ * @returns A string representing the decoded error message, or a default message
13
+ * if no error message is found.
14
+ */
15
+ function decodeErrorMessageFromRequest(data, response) {
16
+ if (data?.message && typeof data?.message === "string") {
17
+ return data?.message;
18
+ }
19
+ if (data?.error && typeof data?.error === "string") {
20
+ return data?.error;
21
+ }
22
+ if (data?.error?.message && typeof data?.error?.message === "string") {
23
+ return data?.error?.message;
24
+ }
25
+ if (response?.statusText && typeof response?.statusText === "string") {
26
+ return response?.statusText;
27
+ }
28
+ return "Missing error message";
29
+ }
30
+ export { decodeErrorMessageFromRequest };
@@ -1 +1 @@
1
- {"version":3,"file":"decodeRequestBody.d.ts","sourceRoot":"","sources":["../../src/services/decodeRequestBody.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE9D;;;;;;;;;;;;GAYG;AAEH,QAAA,MAAM,iBAAiB,EAAE,yBA2BxB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"decodeRequestBody.d.ts","sourceRoot":"","sources":["../../src/services/decodeRequestBody.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAG9D;;;;;;;;;;;;GAYG;AAEH,QAAA,MAAM,iBAAiB,EAAE,yBAsBxB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { BadRequest } from "../http/badResponses/badRequest";
1
2
  /**
2
3
  * Decodes the body of an incoming request into a JavaScript object.
3
4
  *
@@ -13,29 +14,24 @@
13
14
  */
14
15
  const decodeRequestBody = async (req) => {
15
16
  let data;
17
+ const arrayBuffer = await req.arrayBuffer();
18
+ const text = new TextDecoder().decode(arrayBuffer);
16
19
  try {
17
- const arrayBuffer = await req.arrayBuffer();
18
- const text = new TextDecoder().decode(arrayBuffer);
20
+ data = JSON.parse(text);
21
+ }
22
+ catch (jsonError) {
19
23
  try {
20
- data = JSON.parse(text);
21
- }
22
- catch (jsonError) {
23
- try {
24
+ if (text.includes("=")) {
24
25
  const formData = new URLSearchParams(text);
25
26
  data = Object.fromEntries(formData.entries());
26
27
  }
27
- catch (formDataError) {
28
- console.error("Failed to extract data from request:", {
29
- jsonError,
30
- formDataError,
31
- });
32
- data = {};
28
+ else {
29
+ throw new BadRequest("Invalid URLSearchParams format");
33
30
  }
34
31
  }
35
- }
36
- catch (error) {
37
- console.error("Failed to read request body:", error);
38
- data = {};
32
+ catch (formDataError) {
33
+ throw new BadRequest("Failed to extract data from request");
34
+ }
39
35
  }
40
36
  return data;
41
37
  };
@@ -1,3 +1,44 @@
1
- declare function errorHandler(error: any): Response | undefined;
1
+ /**
2
+ * Handles errors and converts them into appropriate HTTP responses.
3
+ *
4
+ * This function takes an error object and determines its type to return
5
+ * the corresponding HTTP response. It supports both success and error
6
+ * response types, converting them into a standardized format using the
7
+ * `toResponse` method when applicable.
8
+ *
9
+ * @param error - The error object to handle. It can be an instance of various
10
+ * HTTP response classes or a generic error.
11
+ *
12
+ * @returns The corresponding HTTP response object if the error matches a known
13
+ * type, or `undefined` if no match is found.
14
+ *
15
+ * ### Supported Success Responses:
16
+ * - `Found`
17
+ * - `Created`
18
+ * - `Updated`
19
+ * - `Success`
20
+ * - `NoContent`
21
+ *
22
+ * ### Supported Error Responses:
23
+ * - `BadGateway`
24
+ * - `BadRequest`
25
+ * - `Conflict`
26
+ * - `Forbidden`
27
+ * - `NotFound`
28
+ * - `NotImplemented`
29
+ * - `ServerError`
30
+ * - `Unauthorized`
31
+ * - `UnprocessableEntity`
32
+ *
33
+ * ### Example Usage:
34
+ * ```typescript
35
+ * try {
36
+ * // Some operation that might throw an error
37
+ * } catch (error) {
38
+ * return errorHandler(error);
39
+ * }
40
+ * ```
41
+ */
42
+ declare function errorHandler(error: any): Response;
2
43
  export { errorHandler };
3
44
  //# sourceMappingURL=errorHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/services/errorHandler.ts"],"names":[],"mappings":"AAgBA,iBAAS,YAAY,CAAC,KAAK,EAAE,GAAG,wBAoC/B;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../src/services/errorHandler.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,iBAAS,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,QAAQ,CAsC1C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -12,6 +12,47 @@ import { Found } from "../http/successResponses/found";
12
12
  import { NoContent } from "../http/successResponses/noContent";
13
13
  import { Success } from "../http/successResponses/success";
14
14
  import { Updated } from "../http/successResponses/updated";
15
+ /**
16
+ * Handles errors and converts them into appropriate HTTP responses.
17
+ *
18
+ * This function takes an error object and determines its type to return
19
+ * the corresponding HTTP response. It supports both success and error
20
+ * response types, converting them into a standardized format using the
21
+ * `toResponse` method when applicable.
22
+ *
23
+ * @param error - The error object to handle. It can be an instance of various
24
+ * HTTP response classes or a generic error.
25
+ *
26
+ * @returns The corresponding HTTP response object if the error matches a known
27
+ * type, or `undefined` if no match is found.
28
+ *
29
+ * ### Supported Success Responses:
30
+ * - `Found`
31
+ * - `Created`
32
+ * - `Updated`
33
+ * - `Success`
34
+ * - `NoContent`
35
+ *
36
+ * ### Supported Error Responses:
37
+ * - `BadGateway`
38
+ * - `BadRequest`
39
+ * - `Conflict`
40
+ * - `Forbidden`
41
+ * - `NotFound`
42
+ * - `NotImplemented`
43
+ * - `ServerError`
44
+ * - `Unauthorized`
45
+ * - `UnprocessableEntity`
46
+ *
47
+ * ### Example Usage:
48
+ * ```typescript
49
+ * try {
50
+ * // Some operation that might throw an error
51
+ * } catch (error) {
52
+ * return errorHandler(error);
53
+ * }
54
+ * ```
55
+ */
15
56
  function errorHandler(error) {
16
57
  switch (true) {
17
58
  case error instanceof Response:
@@ -47,5 +88,6 @@ function errorHandler(error) {
47
88
  case error instanceof UnprocessableEntity:
48
89
  return error.toResponse();
49
90
  }
91
+ return new ServerError("Server error").toResponse();
50
92
  }
51
93
  export { errorHandler };
@@ -1 +1 @@
1
- {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAoB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAmB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -39,8 +39,10 @@
39
39
  function formParse([formData, schema,]) {
40
40
  const zodResponse = schema.safeParse(formData);
41
41
  if (zodResponse.success === false) {
42
- const errorsArray = Object.entries(zodResponse.error.formErrors.fieldErrors);
43
- const errorsObject = Object.fromEntries(errorsArray.map((item) => [item[0], item[1]?.[0] || "Error"]));
42
+ const errorsObject = Object.fromEntries(zodResponse.error.errors.map((item) => [
43
+ item.path.join("."),
44
+ item.message,
45
+ ]));
44
46
  return {
45
47
  success: zodResponse.success,
46
48
  fieldErrors: errorsObject,
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Retrieves information about the caller of the current function.
3
+ *
4
+ * This function analyzes the stack trace to determine the file path and function name
5
+ * of the caller. It excludes stack trace entries related to the `@arkyn/server` package
6
+ * and attempts to resolve the file path relative to the project root directory.
7
+ *
8
+ * @returns An object containing:
9
+ * - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
10
+ * - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
11
+ */
12
+ declare function getCaller(): {
13
+ functionName: string;
14
+ callerInfo: string;
15
+ };
16
+ export { getCaller };
17
+ //# sourceMappingURL=getCaller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCaller.d.ts","sourceRoot":"","sources":["../../src/services/getCaller.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,iBAAS,SAAS;;;EAyCjB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,45 @@
1
+ import path from "path";
2
+ /**
3
+ * Retrieves information about the caller of the current function.
4
+ *
5
+ * This function analyzes the stack trace to determine the file path and function name
6
+ * of the caller. It excludes stack trace entries related to the `@arkyn/server` package
7
+ * and attempts to resolve the file path relative to the project root directory.
8
+ *
9
+ * @returns An object containing:
10
+ * - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
11
+ * - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
12
+ */
13
+ function getCaller() {
14
+ const projectRoot = process.cwd();
15
+ const error = new Error();
16
+ const stackLines = error.stack?.split("\n").map((line) => line.trim()) || [];
17
+ let callerInfo = "Unknown caller";
18
+ let functionName = "Unknown function";
19
+ const relevantLines = stackLines.filter((line) => !line.includes("@arkyn/server"));
20
+ let foundGetCaller = false;
21
+ for (const line of relevantLines) {
22
+ if (!foundGetCaller) {
23
+ if (line.includes("getCaller")) {
24
+ foundGetCaller = true;
25
+ }
26
+ continue;
27
+ }
28
+ const match = line.match(/at (.+?) \((.+?)\)/) || line.match(/at (.+)/);
29
+ if (match) {
30
+ const rawFuncName = match[1]?.split(" ")[0] || "";
31
+ functionName =
32
+ rawFuncName && !rawFuncName.includes("/")
33
+ ? rawFuncName
34
+ : "Unknown function";
35
+ let fullPath = match[2] || match[1];
36
+ if (fullPath.startsWith(projectRoot)) {
37
+ fullPath = path.relative(projectRoot, fullPath);
38
+ }
39
+ callerInfo = fullPath;
40
+ break;
41
+ }
42
+ }
43
+ return { functionName, callerInfo };
44
+ }
45
+ export { getCaller };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Logs debug information to the console when in development mode or when the
3
+ * `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
4
+ *
5
+ * This function provides detailed information about the caller function,
6
+ * its location, and the provided body and cause, if any.
7
+ *
8
+ * @param name - A string representing the name or context of the debug log.
9
+ * @param body - The main content or data to be logged.
10
+ * @param cause - (Optional) Additional information or error cause to be logged.
11
+ *
12
+ * @remarks
13
+ * The debug logs are only displayed when the application is running in
14
+ * development mode (`NODE_ENV === "development"`) or when the
15
+ * `SHOW_ERRORS_IN_CONSOLE` environment variable is explicitly set to "true".
16
+ *
17
+ * The logs include:
18
+ * - The name of the debug context.
19
+ * - The caller function name and its location.
20
+ * - The provided body content.
21
+ * - The optional cause, if provided.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * httpDebug("FetchUserData", { userId: 123 });
26
+ * ```
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * httpDebug("FetchUserDataError", { userId: 123 }, new Error("User not found"));
31
+ * ```
32
+ */
33
+ declare function httpDebug(name: string, body: any, cause?: any): void;
34
+ export { httpDebug };
35
+ //# sourceMappingURL=httpDebug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/services/httpDebug.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAyBtD;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { InboxFlowInstance } from "../config/inboxFlowInstance";
2
+ import { getCaller } from "../services/getCaller";
3
+ /**
4
+ * Logs debug information to the console when in development mode or when the
5
+ * `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
6
+ *
7
+ * This function provides detailed information about the caller function,
8
+ * its location, and the provided body and cause, if any.
9
+ *
10
+ * @param name - A string representing the name or context of the debug log.
11
+ * @param body - The main content or data to be logged.
12
+ * @param cause - (Optional) Additional information or error cause to be logged.
13
+ *
14
+ * @remarks
15
+ * The debug logs are only displayed when the application is running in
16
+ * development mode (`NODE_ENV === "development"`) or when the
17
+ * `SHOW_ERRORS_IN_CONSOLE` environment variable is explicitly set to "true".
18
+ *
19
+ * The logs include:
20
+ * - The name of the debug context.
21
+ * - The caller function name and its location.
22
+ * - The provided body content.
23
+ * - The optional cause, if provided.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * httpDebug("FetchUserData", { userId: 123 });
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * httpDebug("FetchUserDataError", { userId: 123 }, new Error("User not found"));
33
+ * ```
34
+ */
35
+ function httpDebug(name, body, cause) {
36
+ const isDebugMode = process.env.NODE_ENV === "development" ||
37
+ process.env?.SHOW_ERRORS_IN_CONSOLE === "true";
38
+ if (isDebugMode) {
39
+ const reset = "\x1b[0m";
40
+ const cyan = "\x1b[36m";
41
+ const debugName = `${cyan}[ARKYN-DEBUG]${reset}`;
42
+ const { callerInfo, functionName } = getCaller();
43
+ let consoleData = `${debugName} ${name} initialized\n`;
44
+ consoleData += `${debugName} Caller Function: ${functionName}\n`;
45
+ consoleData += `${debugName} Caller Location: ${callerInfo}\n`;
46
+ consoleData += `${debugName} Body: ${JSON.stringify(body, null, 2)}\n`;
47
+ if (cause) {
48
+ consoleData += `${debugName} Cause: ${JSON.stringify(cause, null, 2)}\n`;
49
+ }
50
+ console.log(consoleData);
51
+ const arkynKeys = InboxFlowInstance.getInboxConfig();
52
+ if (arkynKeys)
53
+ console.log(arkynKeys);
54
+ }
55
+ }
56
+ export { httpDebug };
@@ -0,0 +1,13 @@
1
+ import { Schema, z } from "zod";
2
+ declare class SchemaValidator<T extends Schema> {
3
+ readonly schema: T;
4
+ functionName: string;
5
+ callerInfo: string;
6
+ constructor(schema: T);
7
+ isValid(data: any): boolean;
8
+ safeValidate(data: any): z.SafeParseReturnType<z.infer<T>, z.infer<T>>;
9
+ validate(data: any): z.infer<T>;
10
+ formValidate(data: any, message?: string): z.infer<T>;
11
+ }
12
+ export { SchemaValidator };
13
+ //# sourceMappingURL=schemaValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaValidator.d.ts","sourceRoot":"","sources":["../../src/services/schemaValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBhC,cAAM,eAAe,CAAC,CAAC,SAAS,MAAM;IAIxB,QAAQ,CAAC,MAAM,EAAE,CAAC;IAH9B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;gBAEE,MAAM,EAAE,CAAC;IAM9B,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO;IAI3B,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAItE,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAQ/B,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;CAoBtD;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}