@arkyn/server 1.9.1 → 1.9.5

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 (304) hide show
  1. package/LICENSE.txt +24 -0
  2. package/README.md +116 -0
  3. package/dist/api/__test__/deleteRequest.spec.d.ts +2 -0
  4. package/dist/api/__test__/deleteRequest.spec.d.ts.map +1 -0
  5. package/dist/api/__test__/deleteRequest.spec.js +84 -0
  6. package/dist/api/__test__/getRequest.spec.d.ts +2 -0
  7. package/dist/api/__test__/getRequest.spec.d.ts.map +1 -0
  8. package/dist/api/__test__/getRequest.spec.js +62 -0
  9. package/dist/api/__test__/inboxFlowRequest.spec.d.ts +2 -0
  10. package/dist/api/__test__/inboxFlowRequest.spec.d.ts.map +1 -0
  11. package/dist/api/__test__/inboxFlowRequest.spec.js +96 -0
  12. package/dist/api/__test__/makeRequest.spec.d.ts +2 -0
  13. package/dist/api/__test__/makeRequest.spec.d.ts.map +1 -0
  14. package/dist/api/__test__/makeRequest.spec.js +80 -0
  15. package/dist/api/__test__/patchRequest.spec.d.ts +2 -0
  16. package/dist/api/__test__/patchRequest.spec.d.ts.map +1 -0
  17. package/dist/api/__test__/patchRequest.spec.js +84 -0
  18. package/dist/api/__test__/postRequest.spec.d.ts +2 -0
  19. package/dist/api/__test__/postRequest.spec.d.ts.map +1 -0
  20. package/dist/api/__test__/postRequest.spec.js +84 -0
  21. package/dist/api/__test__/putRequest.spec.d.ts +2 -0
  22. package/dist/api/__test__/putRequest.spec.d.ts.map +1 -0
  23. package/dist/api/__test__/putRequest.spec.js +84 -0
  24. package/dist/api/deleteRequest.d.ts +13 -0
  25. package/dist/api/deleteRequest.d.ts.map +1 -0
  26. package/dist/api/deleteRequest.js +14 -0
  27. package/dist/api/getRequest.d.ts +12 -0
  28. package/dist/api/getRequest.d.ts.map +1 -0
  29. package/dist/api/getRequest.js +13 -0
  30. package/dist/api/inboxFlowRequest.d.ts +40 -0
  31. package/dist/api/inboxFlowRequest.d.ts.map +1 -0
  32. package/dist/api/inboxFlowRequest.js +63 -0
  33. package/dist/api/makeRequest.d.ts +38 -0
  34. package/dist/api/makeRequest.d.ts.map +1 -0
  35. package/dist/api/makeRequest.js +103 -0
  36. package/dist/api/patchRequest.d.ts +13 -0
  37. package/dist/api/patchRequest.d.ts.map +1 -0
  38. package/dist/api/patchRequest.js +14 -0
  39. package/dist/api/postRequest.d.ts +13 -0
  40. package/dist/api/postRequest.d.ts.map +1 -0
  41. package/dist/api/postRequest.js +14 -0
  42. package/dist/api/putRequest.d.ts +13 -0
  43. package/dist/api/putRequest.d.ts.map +1 -0
  44. package/dist/api/putRequest.js +14 -0
  45. package/dist/config/__test__/apiInstance.spec.d.ts +2 -0
  46. package/dist/config/__test__/apiInstance.spec.d.ts.map +1 -0
  47. package/dist/config/__test__/apiInstance.spec.js +86 -0
  48. package/dist/config/__test__/inboxFlowInstance.spec.d.ts +2 -0
  49. package/dist/config/__test__/inboxFlowInstance.spec.d.ts.map +1 -0
  50. package/dist/config/__test__/inboxFlowInstance.spec.js +48 -0
  51. package/dist/config/apiInstance.d.ts +80 -0
  52. package/dist/config/apiInstance.d.ts.map +1 -0
  53. package/dist/config/apiInstance.js +111 -0
  54. package/dist/config/inboxFlowInstance.d.ts +44 -0
  55. package/dist/config/inboxFlowInstance.d.ts.map +1 -0
  56. package/dist/config/inboxFlowInstance.js +46 -0
  57. package/dist/http/badResponses/__test__/badGateway.spec.d.ts +2 -0
  58. package/dist/http/badResponses/__test__/badGateway.spec.d.ts.map +1 -0
  59. package/dist/http/badResponses/__test__/badGateway.spec.js +42 -0
  60. package/dist/http/badResponses/__test__/badRequest.spec.d.ts +2 -0
  61. package/dist/http/badResponses/__test__/badRequest.spec.d.ts.map +1 -0
  62. package/dist/http/badResponses/__test__/badRequest.spec.js +40 -0
  63. package/dist/http/badResponses/__test__/conflict.spec.d.ts +2 -0
  64. package/dist/http/badResponses/__test__/conflict.spec.d.ts.map +1 -0
  65. package/dist/http/badResponses/__test__/conflict.spec.js +40 -0
  66. package/dist/http/badResponses/__test__/forbidden.spec.d.ts +2 -0
  67. package/dist/http/badResponses/__test__/forbidden.spec.d.ts.map +1 -0
  68. package/dist/http/badResponses/__test__/forbidden.spec.js +40 -0
  69. package/dist/http/badResponses/__test__/notFound.spec.d.ts +2 -0
  70. package/dist/http/badResponses/__test__/notFound.spec.d.ts.map +1 -0
  71. package/dist/http/badResponses/__test__/notFound.spec.js +40 -0
  72. package/dist/http/badResponses/__test__/notImplemented.spec.d.ts +2 -0
  73. package/dist/http/badResponses/__test__/notImplemented.spec.d.ts.map +1 -0
  74. package/dist/http/badResponses/__test__/notImplemented.spec.js +40 -0
  75. package/dist/http/badResponses/__test__/serverError.spec.d.ts +2 -0
  76. package/dist/http/badResponses/__test__/serverError.spec.d.ts.map +1 -0
  77. package/dist/http/badResponses/__test__/serverError.spec.js +40 -0
  78. package/dist/http/badResponses/__test__/unauthorized.spec.d.ts +2 -0
  79. package/dist/http/badResponses/__test__/unauthorized.spec.d.ts.map +1 -0
  80. package/dist/http/badResponses/__test__/unauthorized.spec.js +40 -0
  81. package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts +2 -0
  82. package/dist/http/badResponses/__test__/unprocessableEntity.spec.d.ts.map +1 -0
  83. package/dist/http/badResponses/__test__/unprocessableEntity.spec.js +66 -0
  84. package/dist/http/badResponses/badGateway.d.ts +34 -0
  85. package/dist/http/badResponses/badGateway.d.ts.map +1 -0
  86. package/dist/http/badResponses/badGateway.js +52 -0
  87. package/dist/http/badResponses/badRequest.d.ts +34 -0
  88. package/dist/http/badResponses/badRequest.d.ts.map +1 -0
  89. package/dist/http/badResponses/badRequest.js +52 -0
  90. package/dist/http/badResponses/conflict.d.ts +34 -0
  91. package/dist/http/badResponses/conflict.d.ts.map +1 -0
  92. package/dist/http/badResponses/conflict.js +52 -0
  93. package/dist/http/badResponses/forbidden.d.ts +34 -0
  94. package/dist/http/badResponses/forbidden.d.ts.map +1 -0
  95. package/dist/http/badResponses/forbidden.js +52 -0
  96. package/dist/http/badResponses/notFound.d.ts +34 -0
  97. package/dist/http/badResponses/notFound.d.ts.map +1 -0
  98. package/dist/http/badResponses/notFound.js +52 -0
  99. package/dist/http/badResponses/notImplemented.d.ts +34 -0
  100. package/dist/http/badResponses/notImplemented.d.ts.map +1 -0
  101. package/dist/http/badResponses/notImplemented.js +52 -0
  102. package/dist/http/badResponses/serverError.d.ts +34 -0
  103. package/dist/http/badResponses/serverError.d.ts.map +1 -0
  104. package/dist/http/badResponses/serverError.js +52 -0
  105. package/dist/http/badResponses/unauthorized.d.ts +34 -0
  106. package/dist/http/badResponses/unauthorized.d.ts.map +1 -0
  107. package/dist/http/badResponses/unauthorized.js +52 -0
  108. package/dist/http/badResponses/unprocessableEntity.d.ts +43 -0
  109. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -0
  110. package/dist/http/badResponses/unprocessableEntity.js +60 -0
  111. package/dist/http/successResponses/__test__/created.spec.d.ts +2 -0
  112. package/dist/http/successResponses/__test__/created.spec.d.ts.map +1 -0
  113. package/dist/http/successResponses/__test__/created.spec.js +57 -0
  114. package/dist/http/successResponses/__test__/found.spec.d.ts +2 -0
  115. package/dist/http/successResponses/__test__/found.spec.d.ts.map +1 -0
  116. package/dist/http/successResponses/__test__/found.spec.js +57 -0
  117. package/dist/http/successResponses/__test__/noContent.spec.d.ts +2 -0
  118. package/dist/http/successResponses/__test__/noContent.spec.d.ts.map +1 -0
  119. package/dist/http/successResponses/__test__/noContent.spec.js +40 -0
  120. package/dist/http/successResponses/__test__/success.spec.d.ts +2 -0
  121. package/dist/http/successResponses/__test__/success.spec.d.ts.map +1 -0
  122. package/dist/http/successResponses/__test__/success.spec.js +60 -0
  123. package/dist/http/successResponses/__test__/updated.spec.d.ts +2 -0
  124. package/dist/http/successResponses/__test__/updated.spec.d.ts.map +1 -0
  125. package/dist/http/successResponses/__test__/updated.spec.js +60 -0
  126. package/dist/http/successResponses/created.d.ts +36 -0
  127. package/dist/http/successResponses/created.d.ts.map +1 -0
  128. package/dist/http/successResponses/created.js +54 -0
  129. package/dist/http/successResponses/found.d.ts +39 -0
  130. package/dist/http/successResponses/found.d.ts.map +1 -0
  131. package/dist/http/successResponses/found.js +57 -0
  132. package/dist/http/successResponses/noContent.d.ts +25 -0
  133. package/dist/http/successResponses/noContent.d.ts.map +1 -0
  134. package/dist/http/successResponses/noContent.js +35 -0
  135. package/dist/http/successResponses/success.d.ts +36 -0
  136. package/dist/http/successResponses/success.d.ts.map +1 -0
  137. package/dist/http/successResponses/success.js +54 -0
  138. package/dist/http/successResponses/updated.d.ts +36 -0
  139. package/dist/http/successResponses/updated.d.ts.map +1 -0
  140. package/dist/http/successResponses/updated.js +54 -0
  141. package/dist/index.d.ts +22 -13
  142. package/dist/index.d.ts.map +1 -1
  143. package/dist/index.js +24 -15
  144. package/dist/services/__test__/decodeRequestBody.spec.d.ts +2 -0
  145. package/dist/services/__test__/decodeRequestBody.spec.d.ts.map +1 -0
  146. package/dist/services/__test__/decodeRequestBody.spec.js +39 -0
  147. package/dist/services/__test__/errorHandler.spec.d.ts +2 -0
  148. package/dist/services/__test__/errorHandler.spec.d.ts.map +1 -0
  149. package/dist/services/__test__/errorHandler.spec.js +115 -0
  150. package/dist/services/__test__/formParse.spec.d.ts +2 -0
  151. package/dist/services/__test__/formParse.spec.d.ts.map +1 -0
  152. package/dist/services/__test__/formParse.spec.js +78 -0
  153. package/dist/services/__test__/getCaller.spec.d.ts +2 -0
  154. package/dist/services/__test__/getCaller.spec.d.ts.map +1 -0
  155. package/dist/services/__test__/getCaller.spec.js +60 -0
  156. package/dist/services/__test__/getScopedParams.spec.d.ts +2 -0
  157. package/dist/services/__test__/getScopedParams.spec.d.ts.map +1 -0
  158. package/dist/services/__test__/getScopedParams.spec.js +51 -0
  159. package/dist/services/__test__/schemaValidator.spec.d.ts +2 -0
  160. package/dist/services/__test__/schemaValidator.spec.d.ts.map +1 -0
  161. package/dist/services/__test__/schemaValidator.spec.js +89 -0
  162. package/dist/services/decodeErrorMessageFromRequest.d.ts +17 -0
  163. package/dist/services/decodeErrorMessageFromRequest.d.ts.map +1 -0
  164. package/dist/services/decodeErrorMessageFromRequest.js +30 -0
  165. package/dist/services/decodeRequestBody.d.ts +17 -0
  166. package/dist/services/decodeRequestBody.d.ts.map +1 -0
  167. package/dist/services/decodeRequestBody.js +38 -0
  168. package/dist/services/errorHandler.d.ts +44 -0
  169. package/dist/services/errorHandler.d.ts.map +1 -0
  170. package/dist/services/errorHandler.js +93 -0
  171. package/dist/services/formParse.d.ts +40 -1
  172. package/dist/services/formParse.d.ts.map +1 -1
  173. package/dist/services/formParse.js +44 -3
  174. package/dist/services/getCaller.d.ts +17 -0
  175. package/dist/services/getCaller.d.ts.map +1 -0
  176. package/dist/services/getCaller.js +45 -0
  177. package/dist/services/getScopedParams.d.ts +26 -1
  178. package/dist/services/getScopedParams.d.ts.map +1 -1
  179. package/dist/services/getScopedParams.js +26 -2
  180. package/dist/services/httpDebug.d.ts +35 -0
  181. package/dist/services/httpDebug.d.ts.map +1 -0
  182. package/dist/services/httpDebug.js +56 -0
  183. package/dist/services/schemaValidator.d.ts +13 -0
  184. package/dist/services/schemaValidator.d.ts.map +1 -0
  185. package/dist/services/schemaValidator.js +51 -0
  186. package/dist/services/sendFileToS3.d.ts +50 -18
  187. package/dist/services/sendFileToS3.d.ts.map +1 -1
  188. package/dist/services/sendFileToS3.js +73 -31
  189. package/package.json +14 -6
  190. package/src/api/__test__/deleteRequest.spec.ts +107 -0
  191. package/src/api/__test__/getRequest.spec.ts +76 -0
  192. package/src/api/__test__/inboxFlowRequest.spec.ts +125 -0
  193. package/src/api/__test__/makeRequest.spec.ts +121 -0
  194. package/src/api/__test__/patchRequest.spec.ts +125 -0
  195. package/src/api/__test__/postRequest.spec.ts +125 -0
  196. package/src/api/__test__/putRequest.spec.ts +125 -0
  197. package/src/api/deleteRequest.ts +22 -0
  198. package/src/api/getRequest.ts +20 -0
  199. package/src/api/inboxFlowRequest.ts +76 -0
  200. package/src/api/makeRequest.ts +117 -0
  201. package/src/api/patchRequest.ts +22 -0
  202. package/src/api/postRequest.ts +22 -0
  203. package/src/api/putRequest.ts +22 -0
  204. package/src/config/__test__/apiInstance.spec.ts +129 -0
  205. package/src/config/__test__/inboxFlowInstance.spec.ts +61 -0
  206. package/src/config/apiInstance.ts +148 -0
  207. package/src/config/inboxFlowInstance.ts +65 -0
  208. package/src/http/badResponses/__test__/badGateway.spec.ts +50 -0
  209. package/src/http/badResponses/__test__/badRequest.spec.ts +50 -0
  210. package/src/http/badResponses/__test__/conflict.spec.ts +50 -0
  211. package/src/http/badResponses/__test__/forbidden.spec.ts +50 -0
  212. package/src/http/badResponses/__test__/notFound.spec.ts +50 -0
  213. package/src/http/badResponses/__test__/notImplemented.spec.ts +50 -0
  214. package/src/http/badResponses/__test__/serverError.spec.ts +50 -0
  215. package/src/http/badResponses/__test__/unauthorized.spec.ts +50 -0
  216. package/src/http/badResponses/__test__/unprocessableEntity.spec.ts +76 -0
  217. package/src/http/badResponses/badGateway.ts +63 -0
  218. package/src/http/badResponses/badRequest.ts +63 -0
  219. package/src/http/badResponses/conflict.ts +63 -0
  220. package/src/http/badResponses/forbidden.ts +63 -0
  221. package/src/http/badResponses/notFound.ts +63 -0
  222. package/src/http/badResponses/notImplemented.ts +63 -0
  223. package/src/http/badResponses/serverError.ts +63 -0
  224. package/src/http/badResponses/unauthorized.ts +63 -0
  225. package/src/http/badResponses/unprocessableEntity.ts +79 -0
  226. package/src/http/successResponses/__test__/created.spec.ts +65 -0
  227. package/src/http/successResponses/__test__/found.spec.ts +65 -0
  228. package/src/http/successResponses/__test__/noContent.spec.ts +49 -0
  229. package/src/http/successResponses/__test__/success.spec.ts +68 -0
  230. package/src/http/successResponses/__test__/updated.spec.ts +68 -0
  231. package/src/http/successResponses/created.ts +64 -0
  232. package/src/http/successResponses/found.ts +67 -0
  233. package/src/http/successResponses/noContent.ts +42 -0
  234. package/src/http/successResponses/success.ts +64 -0
  235. package/src/http/successResponses/updated.ts +64 -0
  236. package/src/index.ts +25 -16
  237. package/src/services/__test__/decodeRequestBody.spec.ts +51 -0
  238. package/src/services/__test__/errorHandler.spec.ts +133 -0
  239. package/src/services/__test__/formParse.spec.ts +96 -0
  240. package/src/services/__test__/getCaller.spec.ts +78 -0
  241. package/src/services/__test__/getScopedParams.spec.ts +68 -0
  242. package/src/services/__test__/schemaValidator.spec.ts +106 -0
  243. package/src/services/decodeErrorMessageFromRequest.ts +36 -0
  244. package/src/services/decodeRequestBody.ts +42 -0
  245. package/src/services/errorHandler.ts +99 -0
  246. package/src/services/formParse.ts +46 -6
  247. package/src/services/getCaller.ts +58 -0
  248. package/src/services/getScopedParams.ts +29 -2
  249. package/src/services/httpDebug.ts +64 -0
  250. package/src/services/schemaValidator.ts +66 -0
  251. package/src/services/sendFileToS3.ts +81 -56
  252. package/vitest.config.ts +5 -0
  253. package/dist/helpers/globalErrorHandler.d.ts +0 -3
  254. package/dist/helpers/globalErrorHandler.d.ts.map +0 -1
  255. package/dist/helpers/globalErrorHandler.js +0 -53
  256. package/dist/httpBadResponses/badRequest.d.ts +0 -9
  257. package/dist/httpBadResponses/badRequest.d.ts.map +0 -1
  258. package/dist/httpBadResponses/badRequest.js +0 -23
  259. package/dist/httpBadResponses/conflict.d.ts +0 -9
  260. package/dist/httpBadResponses/conflict.d.ts.map +0 -1
  261. package/dist/httpBadResponses/conflict.js +0 -23
  262. package/dist/httpBadResponses/forbidden.d.ts +0 -9
  263. package/dist/httpBadResponses/forbidden.d.ts.map +0 -1
  264. package/dist/httpBadResponses/forbidden.js +0 -23
  265. package/dist/httpBadResponses/notFound.d.ts +0 -9
  266. package/dist/httpBadResponses/notFound.d.ts.map +0 -1
  267. package/dist/httpBadResponses/notFound.js +0 -23
  268. package/dist/httpBadResponses/serverError.d.ts +0 -9
  269. package/dist/httpBadResponses/serverError.d.ts.map +0 -1
  270. package/dist/httpBadResponses/serverError.js +0 -23
  271. package/dist/httpBadResponses/unauthorized.d.ts +0 -9
  272. package/dist/httpBadResponses/unauthorized.d.ts.map +0 -1
  273. package/dist/httpBadResponses/unauthorized.js +0 -23
  274. package/dist/httpBadResponses/unprocessableEntity.d.ts +0 -17
  275. package/dist/httpBadResponses/unprocessableEntity.d.ts.map +0 -1
  276. package/dist/httpBadResponses/unprocessableEntity.js +0 -30
  277. package/dist/httpResponses/created.d.ts +0 -10
  278. package/dist/httpResponses/created.d.ts.map +0 -1
  279. package/dist/httpResponses/created.js +0 -30
  280. package/dist/httpResponses/noContent.d.ts +0 -9
  281. package/dist/httpResponses/noContent.d.ts.map +0 -1
  282. package/dist/httpResponses/noContent.js +0 -28
  283. package/dist/httpResponses/success.d.ts +0 -10
  284. package/dist/httpResponses/success.d.ts.map +0 -1
  285. package/dist/httpResponses/success.js +0 -30
  286. package/dist/httpResponses/updated.d.ts +0 -10
  287. package/dist/httpResponses/updated.d.ts.map +0 -1
  288. package/dist/httpResponses/updated.js +0 -30
  289. package/dist/services/extractJsonFromRequest.d.ts +0 -3
  290. package/dist/services/extractJsonFromRequest.d.ts.map +0 -1
  291. package/dist/services/extractJsonFromRequest.js +0 -29
  292. package/src/helpers/globalErrorHandler.ts +0 -64
  293. package/src/httpBadResponses/badRequest.ts +0 -29
  294. package/src/httpBadResponses/conflict.ts +0 -29
  295. package/src/httpBadResponses/forbidden.ts +0 -29
  296. package/src/httpBadResponses/notFound.ts +0 -29
  297. package/src/httpBadResponses/serverError.ts +0 -29
  298. package/src/httpBadResponses/unauthorized.ts +0 -29
  299. package/src/httpBadResponses/unprocessableEntity.ts +0 -43
  300. package/src/httpResponses/created.ts +0 -35
  301. package/src/httpResponses/noContent.ts +0 -33
  302. package/src/httpResponses/success.ts +0 -35
  303. package/src/httpResponses/updated.ts +0 -35
  304. package/src/services/extractJsonFromRequest.ts +0 -30
@@ -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,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,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 };
@@ -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 };