@arkyn/server 3.0.1-beta.99 → 3.0.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 (265) hide show
  1. package/LICENSE.txt +184 -1
  2. package/README.md +277 -224
  3. package/dist/http/api/_deleteRequest.d.ts +17 -0
  4. package/dist/http/api/_deleteRequest.d.ts.map +1 -0
  5. package/dist/http/api/_getRequest.d.ts +16 -0
  6. package/dist/http/api/_getRequest.d.ts.map +1 -0
  7. package/dist/http/api/_logMapperService.d.ts +86 -0
  8. package/dist/http/api/_logMapperService.d.ts.map +1 -0
  9. package/dist/{api/arkynLogRequest.d.ts → http/api/_logRequest.d.ts} +22 -19
  10. package/dist/{api/arkynLogRequest.d.ts.map → http/api/_logRequest.d.ts.map} +1 -1
  11. package/dist/http/api/_makeRequest.d.ts +61 -0
  12. package/dist/http/api/_makeRequest.d.ts.map +1 -0
  13. package/dist/http/api/_patchRequest.d.ts +17 -0
  14. package/dist/http/api/_patchRequest.d.ts.map +1 -0
  15. package/dist/http/api/_postRequest.d.ts +17 -0
  16. package/dist/http/api/_postRequest.d.ts.map +1 -0
  17. package/dist/http/api/_putRequest.d.ts +17 -0
  18. package/dist/http/api/_putRequest.d.ts.map +1 -0
  19. package/dist/http/badResponses/_badResponse.d.ts +21 -7
  20. package/dist/http/badResponses/_badResponse.d.ts.map +1 -1
  21. package/dist/http/badResponses/badGateway.d.ts +12 -23
  22. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  23. package/dist/http/badResponses/badRequest.d.ts +10 -23
  24. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  25. package/dist/http/badResponses/conflict.d.ts +10 -23
  26. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  27. package/dist/http/badResponses/forbidden.d.ts +10 -23
  28. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  29. package/dist/http/badResponses/notFound.d.ts +10 -23
  30. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  31. package/dist/http/badResponses/notImplemented.d.ts +10 -23
  32. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  33. package/dist/http/badResponses/serverError.d.ts +10 -23
  34. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  35. package/dist/http/badResponses/unauthorized.d.ts +10 -23
  36. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  37. package/dist/http/badResponses/unprocessableEntity.d.ts +23 -33
  38. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  39. package/dist/http/successResponses/_successResponse.d.ts +21 -7
  40. package/dist/http/successResponses/_successResponse.d.ts.map +1 -1
  41. package/dist/http/successResponses/created.d.ts +11 -29
  42. package/dist/http/successResponses/created.d.ts.map +1 -1
  43. package/dist/http/successResponses/found.d.ts +11 -32
  44. package/dist/http/successResponses/found.d.ts.map +1 -1
  45. package/dist/http/successResponses/noContent.d.ts +10 -16
  46. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  47. package/dist/http/successResponses/success.d.ts +11 -29
  48. package/dist/http/successResponses/success.d.ts.map +1 -1
  49. package/dist/http/successResponses/updated.d.ts +12 -29
  50. package/dist/http/successResponses/updated.d.ts.map +1 -1
  51. package/dist/index.d.ts +9 -10
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +1069 -38
  54. package/dist/index.js.map +1 -0
  55. package/dist/modules/http/api/_deleteRequest.js +15 -0
  56. package/dist/modules/http/api/_deleteRequest.js.map +1 -0
  57. package/dist/modules/http/api/_getRequest.js +14 -0
  58. package/dist/modules/http/api/_getRequest.js.map +1 -0
  59. package/dist/modules/http/api/_logMapperService.js +33 -0
  60. package/dist/modules/http/api/_logMapperService.js.map +1 -0
  61. package/dist/modules/http/api/_logRequest.js +58 -0
  62. package/dist/modules/http/api/_logRequest.js.map +1 -0
  63. package/dist/modules/http/api/_makeRequest.js +72 -0
  64. package/dist/modules/http/api/_makeRequest.js.map +1 -0
  65. package/dist/modules/http/api/_patchRequest.js +15 -0
  66. package/dist/modules/http/api/_patchRequest.js.map +1 -0
  67. package/dist/modules/http/api/_postRequest.js +15 -0
  68. package/dist/modules/http/api/_postRequest.js.map +1 -0
  69. package/dist/modules/http/api/_putRequest.js +15 -0
  70. package/dist/modules/http/api/_putRequest.js.map +1 -0
  71. package/dist/modules/http/badResponses/_badResponse.js +65 -0
  72. package/dist/modules/http/badResponses/_badResponse.js.map +1 -0
  73. package/dist/modules/http/badResponses/badGateway.js +26 -0
  74. package/dist/modules/http/badResponses/badGateway.js.map +1 -0
  75. package/dist/modules/http/badResponses/badRequest.js +26 -0
  76. package/dist/modules/http/badResponses/badRequest.js.map +1 -0
  77. package/dist/modules/http/badResponses/conflict.js +26 -0
  78. package/dist/modules/http/badResponses/conflict.js.map +1 -0
  79. package/dist/modules/http/badResponses/forbidden.js +26 -0
  80. package/dist/modules/http/badResponses/forbidden.js.map +1 -0
  81. package/dist/modules/http/badResponses/notFound.js +26 -0
  82. package/dist/modules/http/badResponses/notFound.js.map +1 -0
  83. package/dist/modules/http/badResponses/notImplemented.js +26 -0
  84. package/dist/modules/http/badResponses/notImplemented.js.map +1 -0
  85. package/dist/modules/http/badResponses/serverError.js +26 -0
  86. package/dist/modules/http/badResponses/serverError.js.map +1 -0
  87. package/dist/modules/http/badResponses/unauthorized.js +26 -0
  88. package/dist/modules/http/badResponses/unauthorized.js.map +1 -0
  89. package/dist/modules/http/badResponses/unprocessableEntity.js +30 -0
  90. package/dist/modules/http/badResponses/unprocessableEntity.js.map +1 -0
  91. package/dist/modules/http/successResponses/_successResponse.js +64 -0
  92. package/dist/modules/http/successResponses/_successResponse.js.map +1 -0
  93. package/dist/modules/http/successResponses/created.js +26 -0
  94. package/dist/modules/http/successResponses/created.js.map +1 -0
  95. package/dist/modules/http/successResponses/found.js +26 -0
  96. package/dist/modules/http/successResponses/found.js.map +1 -0
  97. package/dist/modules/http/successResponses/noContent.js +19 -0
  98. package/dist/modules/http/successResponses/noContent.js.map +1 -0
  99. package/dist/modules/http/successResponses/success.js +26 -0
  100. package/dist/modules/http/successResponses/success.js.map +1 -0
  101. package/dist/modules/http/successResponses/updated.js +26 -0
  102. package/dist/modules/http/successResponses/updated.js.map +1 -0
  103. package/dist/modules/services/apiService.js +111 -0
  104. package/dist/modules/services/apiService.js.map +1 -0
  105. package/dist/modules/services/debugService.js +38 -0
  106. package/dist/modules/services/debugService.js.map +1 -0
  107. package/dist/modules/services/logService.js +23 -0
  108. package/dist/modules/services/logService.js.map +1 -0
  109. package/dist/modules/utilities/decodeRequestBody.js +22 -0
  110. package/dist/modules/utilities/decodeRequestBody.js.map +1 -0
  111. package/dist/modules/utilities/decodeRequestErrorMessage.js +8 -0
  112. package/dist/modules/utilities/decodeRequestErrorMessage.js.map +1 -0
  113. package/dist/modules/utilities/errorHandler.js +41 -0
  114. package/dist/modules/utilities/errorHandler.js.map +1 -0
  115. package/dist/modules/utilities/flushDebugLogs.js +18 -0
  116. package/dist/modules/utilities/flushDebugLogs.js.map +1 -0
  117. package/dist/modules/utilities/formAsyncParse.js +16 -0
  118. package/dist/modules/utilities/formAsyncParse.js.map +1 -0
  119. package/dist/modules/utilities/formParse.js +16 -0
  120. package/dist/modules/utilities/formParse.js.map +1 -0
  121. package/dist/modules/utilities/getScopedParams.js +11 -0
  122. package/dist/modules/utilities/getScopedParams.js.map +1 -0
  123. package/dist/modules/utilities/schemaValidator.js +57 -0
  124. package/dist/modules/utilities/schemaValidator.js.map +1 -0
  125. package/dist/modules/validations/validateCep.js +11 -0
  126. package/dist/modules/validations/validateCep.js.map +1 -0
  127. package/dist/modules/validations/validateCnpj.js +56 -0
  128. package/dist/modules/validations/validateCnpj.js.map +1 -0
  129. package/dist/modules/validations/validateCpf.js +29 -0
  130. package/dist/modules/validations/validateCpf.js.map +1 -0
  131. package/dist/modules/validations/validateDate.js +28 -0
  132. package/dist/modules/validations/validateDate.js.map +1 -0
  133. package/dist/modules/validations/validateEmail.js +56 -0
  134. package/dist/modules/validations/validateEmail.js.map +1 -0
  135. package/dist/modules/validations/validatePassword.js +14 -0
  136. package/dist/modules/validations/validatePassword.js.map +1 -0
  137. package/dist/modules/validations/validatePhone.js +12 -0
  138. package/dist/modules/validations/validatePhone.js.map +1 -0
  139. package/dist/modules/validations/validateRg.js +10 -0
  140. package/dist/modules/validations/validateRg.js.map +1 -0
  141. package/dist/services/apiService.d.ts +25 -26
  142. package/dist/services/apiService.d.ts.map +1 -1
  143. package/dist/services/debugService.d.ts +15 -32
  144. package/dist/services/debugService.d.ts.map +1 -1
  145. package/dist/services/logService.d.ts +33 -0
  146. package/dist/services/logService.d.ts.map +1 -0
  147. package/dist/utilities/decodeRequestBody.d.ts +18 -0
  148. package/dist/utilities/decodeRequestBody.d.ts.map +1 -0
  149. package/dist/utilities/decodeRequestErrorMessage.d.ts +19 -0
  150. package/dist/utilities/decodeRequestErrorMessage.d.ts.map +1 -0
  151. package/dist/utilities/errorHandler.d.ts +25 -0
  152. package/dist/utilities/errorHandler.d.ts.map +1 -0
  153. package/dist/utilities/flushDebugLogs.d.ts +24 -0
  154. package/dist/utilities/flushDebugLogs.d.ts.map +1 -0
  155. package/dist/utilities/formAsyncParse.d.ts +38 -0
  156. package/dist/utilities/formAsyncParse.d.ts.map +1 -0
  157. package/dist/utilities/formParse.d.ts +38 -0
  158. package/dist/utilities/formParse.d.ts.map +1 -0
  159. package/dist/utilities/getScopedParams.d.ts +19 -0
  160. package/dist/utilities/getScopedParams.d.ts.map +1 -0
  161. package/dist/utilities/schemaValidator.d.ts +75 -0
  162. package/dist/utilities/schemaValidator.d.ts.map +1 -0
  163. package/dist/validations/validateCep.d.ts +6 -11
  164. package/dist/validations/validateCep.d.ts.map +1 -1
  165. package/dist/validations/validateCnpj.d.ts +2 -3
  166. package/dist/validations/validateCnpj.d.ts.map +1 -1
  167. package/dist/validations/validateCpf.d.ts +4 -12
  168. package/dist/validations/validateCpf.d.ts.map +1 -1
  169. package/dist/validations/validateDate.d.ts +13 -24
  170. package/dist/validations/validateDate.d.ts.map +1 -1
  171. package/dist/validations/validateEmail.d.ts +3 -4
  172. package/dist/validations/validateEmail.d.ts.map +1 -1
  173. package/dist/validations/validatePassword.d.ts +3 -4
  174. package/dist/validations/validatePassword.d.ts.map +1 -1
  175. package/dist/validations/validatePhone.d.ts +7 -20
  176. package/dist/validations/validatePhone.d.ts.map +1 -1
  177. package/dist/validations/validateRg.d.ts +1 -2
  178. package/dist/validations/validateRg.d.ts.map +1 -1
  179. package/package.json +317 -15
  180. package/dist/api/arkynLogRequest.js +0 -88
  181. package/dist/api/deleteRequest.d.ts +0 -13
  182. package/dist/api/deleteRequest.d.ts.map +0 -1
  183. package/dist/api/deleteRequest.js +0 -14
  184. package/dist/api/getRequest.d.ts +0 -12
  185. package/dist/api/getRequest.d.ts.map +0 -1
  186. package/dist/api/getRequest.js +0 -13
  187. package/dist/api/makeRequest.d.ts +0 -38
  188. package/dist/api/makeRequest.d.ts.map +0 -1
  189. package/dist/api/makeRequest.js +0 -107
  190. package/dist/api/patchRequest.d.ts +0 -13
  191. package/dist/api/patchRequest.d.ts.map +0 -1
  192. package/dist/api/patchRequest.js +0 -14
  193. package/dist/api/postRequest.d.ts +0 -13
  194. package/dist/api/postRequest.d.ts.map +0 -1
  195. package/dist/api/postRequest.js +0 -14
  196. package/dist/api/putRequest.d.ts +0 -13
  197. package/dist/api/putRequest.d.ts.map +0 -1
  198. package/dist/api/putRequest.js +0 -14
  199. package/dist/bundle.js +0 -1507
  200. package/dist/bundle.umd.cjs +0 -10
  201. package/dist/http/badResponses/_badResponse.js +0 -20
  202. package/dist/http/badResponses/badGateway.js +0 -58
  203. package/dist/http/badResponses/badRequest.js +0 -58
  204. package/dist/http/badResponses/conflict.js +0 -58
  205. package/dist/http/badResponses/forbidden.js +0 -58
  206. package/dist/http/badResponses/notFound.js +0 -58
  207. package/dist/http/badResponses/notImplemented.js +0 -58
  208. package/dist/http/badResponses/serverError.js +0 -58
  209. package/dist/http/badResponses/unauthorized.js +0 -58
  210. package/dist/http/badResponses/unprocessableEntity.js +0 -65
  211. package/dist/http/successResponses/_successResponse.js +0 -37
  212. package/dist/http/successResponses/created.js +0 -57
  213. package/dist/http/successResponses/found.js +0 -60
  214. package/dist/http/successResponses/noContent.js +0 -38
  215. package/dist/http/successResponses/success.js +0 -57
  216. package/dist/http/successResponses/updated.js +0 -57
  217. package/dist/mapper/arkynLogRequestMapper.d.ts +0 -30
  218. package/dist/mapper/arkynLogRequestMapper.d.ts.map +0 -1
  219. package/dist/mapper/arkynLogRequestMapper.js +0 -44
  220. package/dist/services/apiService.js +0 -133
  221. package/dist/services/arkynLogService.d.ts +0 -44
  222. package/dist/services/arkynLogService.d.ts.map +0 -1
  223. package/dist/services/arkynLogService.js +0 -46
  224. package/dist/services/debugService.js +0 -57
  225. package/dist/services/decodeErrorMessageFromRequest.d.ts +0 -17
  226. package/dist/services/decodeErrorMessageFromRequest.d.ts.map +0 -1
  227. package/dist/services/decodeErrorMessageFromRequest.js +0 -30
  228. package/dist/services/decodeRequestBody.d.ts +0 -17
  229. package/dist/services/decodeRequestBody.d.ts.map +0 -1
  230. package/dist/services/decodeRequestBody.js +0 -38
  231. package/dist/services/errorHandler.d.ts +0 -44
  232. package/dist/services/errorHandler.d.ts.map +0 -1
  233. package/dist/services/errorHandler.js +0 -93
  234. package/dist/services/flushDebugLogs.d.ts +0 -8
  235. package/dist/services/flushDebugLogs.d.ts.map +0 -1
  236. package/dist/services/flushDebugLogs.js +0 -20
  237. package/dist/services/formAsyncParse.d.ts +0 -59
  238. package/dist/services/formAsyncParse.d.ts.map +0 -1
  239. package/dist/services/formAsyncParse.js +0 -58
  240. package/dist/services/formParse.d.ts +0 -59
  241. package/dist/services/formParse.d.ts.map +0 -1
  242. package/dist/services/formParse.js +0 -58
  243. package/dist/services/getCaller.d.ts +0 -17
  244. package/dist/services/getCaller.d.ts.map +0 -1
  245. package/dist/services/getCaller.js +0 -60
  246. package/dist/services/getScopedParams.d.ts +0 -28
  247. package/dist/services/getScopedParams.d.ts.map +0 -1
  248. package/dist/services/getScopedParams.js +0 -34
  249. package/dist/services/measureRouteExecution.d.ts +0 -3
  250. package/dist/services/measureRouteExecution.d.ts.map +0 -1
  251. package/dist/services/measureRouteExecution.js +0 -24
  252. package/dist/services/schemaValidator.d.ts +0 -158
  253. package/dist/services/schemaValidator.d.ts.map +0 -1
  254. package/dist/services/schemaValidator.js +0 -207
  255. package/dist/types/ApiResponseDTO.d.ts +0 -17
  256. package/dist/types/ApiResponseDTO.d.ts.map +0 -1
  257. package/dist/types/ApiResponseDTO.js +0 -1
  258. package/dist/validations/validateCep.js +0 -33
  259. package/dist/validations/validateCnpj.js +0 -52
  260. package/dist/validations/validateCpf.js +0 -54
  261. package/dist/validations/validateDate.js +0 -73
  262. package/dist/validations/validateEmail.js +0 -123
  263. package/dist/validations/validatePassword.js +0 -34
  264. package/dist/validations/validatePhone.js +0 -44
  265. package/dist/validations/validateRg.js +0 -31
@@ -1,10 +0,0 @@
1
- (function(u,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("zod"),require("@arkyn/shared"),require("node:dns"),require("@arkyn/templates")):typeof define=="function"&&define.amd?define(["exports","zod","@arkyn/shared","node:dns","@arkyn/templates"],f):(u=typeof globalThis<"u"?globalThis:u||self,f(u["@arkyn/server"]={},null,u.shared,null,u.templates))})(this,function(u,f,m,js,Y){"use strict";var $s=Object.defineProperty;var Is=(u,f,m)=>f in u?$s(u,f,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[f]=m;var o=(u,f,m)=>Is(u,typeof f!="symbol"?f+"":f,m);function b(e){var s;if(process.env.NODE_ENV==="development"||((s=process.env)==null?void 0:s.SHOW_ERRORS_IN_CONSOLE)==="true"){const a=`${{yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m",green:"\x1B[32m"}[e.scheme]}[${e.name}]\x1B[0m`;let h=`
2
- `;e.debugs.forEach(l=>{h+=`${a} ${l.trim()}
3
- `}),console.log(h)}}const _={};class D{static setIgnoreFile(n){this.ignoreFiles.push(n)}static clearIgnoreFiles(){this.ignoreFiles=[]}}o(D,"ignoreFiles",[]);function N(){const e=process.cwd(),t=(new Error().stack||"").split(`
4
- `).map(i=>i.trim()),r=D.ignoreFiles;let a=2;for(;a<t.length&&(t[a].includes("node:internal")||t[a].includes("/node_modules/"));)a++;if(r.length>0)for(;a<t.length&&r.some(i=>t[a].includes(i));)a++;const h=t[a]||"";let l="Unknown function",c="Unknown caller";const d=h.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(d)l=d[1],c=d[2];else{const i=h.match(/at\s+(.+)/);if(i){c=i[1];const p=c.match(/at\s+([^(\s]+)\s+/);p&&p[1]!=="new"&&(l=p[1])}}c.includes("(")&&(c=c.substring(c.indexOf("(")+1,c.lastIndexOf(")"))),c=c.split(":").slice(0,-2).join(":");try{c=_.relative(e,c)}catch{}return{functionName:l,callerInfo:c}}class g{onDebug(n){const{name:s,body:t,cause:r,message:a}=n,h=[],{callerInfo:l,functionName:c}=N();h.push(`${s} initialized`),h.push(`Caller Function: ${c}`),h.push(`Caller Location: ${l}`),a&&h.push(`Message: ${a}`),t&&h.push(`Body: ${JSON.stringify(t,null,2)}`),r&&h.push(`Cause: ${JSON.stringify(r,null,2)}`),b({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:h})}}class C extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",502);o(this,"statusText");this.body={name:"BadGateway",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"BadGateway",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class S extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",400);o(this,"statusText");this.body={name:"BadRequest",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"BadRequest",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class $ extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",409);o(this,"statusText");this.body={name:"Conflict",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"Conflict",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class I extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",403);o(this,"statusText");this.body={name:"Forbidden",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"Forbidden",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class j extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",404);o(this,"statusText");this.body={name:"NotFound",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"NotFound",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class J extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",501);o(this,"statusText");this.body={name:"NotImplemented",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"NotImplemented",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class E extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",500);o(this,"statusText");this.body={name:"ServerError",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"ServerError",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class U extends g{constructor(s,t){super();o(this,"body");o(this,"cause");o(this,"status",401);o(this,"statusText");this.body={name:"Unauthorized",message:s},this.statusText=s,this.cause=t?JSON.stringify(t):void 0,this.onDebug({name:"Unauthorized",body:this.body,cause:this.cause,message:this.statusText})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class O extends g{constructor(s){super();o(this,"body");o(this,"status",422);o(this,"statusText");this.statusText=s.message||"Unprocessable Entity",this.body={name:"UnprocessableEntity",message:s.message||null,data:s.data,fieldErrors:s.fieldErrors,fields:s.fields},this.onDebug({name:"UnprocessableEntity",cause:s.fieldErrors,message:s.message})}toResponse(){const s={headers:{"Content-Type":"application/json"},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class R{onDebug(n,s,t){const r=[],{callerInfo:a,functionName:h}=N();r.push(`${n} initialized
5
- `),r.push(`Caller Function: ${h}
6
- `),r.push(`Caller Location: ${a}
7
- `),r.push(`Body: ${JSON.stringify(s,null,2)}
8
- `),t&&r.push(`Cause: ${JSON.stringify(t,null,2)}
9
- `),b({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class w extends R{constructor(s,t){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body={...s,name:"Created",message:t==null?void 0:t.message},this.headers=(t==null?void 0:t.headers)||{},this.status=(t==null?void 0:t.status)||201,this.statusText=(t==null?void 0:t.statusText)||"Resource created successfully",this.onDebug("Created",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class A extends R{constructor(s,t){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body={...s,name:"Found",message:t==null?void 0:t.message},this.headers=(t==null?void 0:t.headers)||{},this.status=(t==null?void 0:t.status)||302,this.statusText=(t==null?void 0:t.statusText)||"Found",this.onDebug("Found",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class q extends R{constructor(s){super();o(this,"headers");o(this,"status");o(this,"statusText");this.headers=(s==null?void 0:s.headers)||{},this.status=(s==null?void 0:s.status)||204,this.statusText=(s==null?void 0:s.statusText)??"No content",this.onDebug("No content",null)}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class k extends R{constructor(s,t){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body={...s,name:"Success",message:t==null?void 0:t.message},this.headers=(t==null?void 0:t.headers)||{},this.status=(t==null?void 0:t.status)||200,this.statusText=(t==null?void 0:t.statusText)??"OK",this.onDebug("Success",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class B extends R{constructor(s,t){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body={...s,name:"Updated",message:t==null?void 0:t.message},this.headers=(t==null?void 0:t.headers)||{},this.status=(t==null?void 0:t.status)||200,this.statusText=(t==null?void 0:t.statusText)||"Resource updated successfully",this.onDebug("Updated",s)}toResponse(){const s={headers:{"Content-Type":"application/json",...this.headers},status:this.status,statusText:this.statusText};return new Response(JSON.stringify(this.body),s)}toJson(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return Response.json(this.body,s)}}class V{static mapHeaders(n){return n instanceof Headers?Object.fromEntries(n.entries()):typeof n=="object"?Object.entries(n).reduce((s,[t,r])=>(typeof r=="string"?s[t]=r:Array.isArray(r)?s[t]=r.join(", "):s[t]=JSON.stringify(r),s),{}):{}}static mapQueryParams(n){const s={};return n.forEach((t,r)=>{s[r]=t}),s}static handle(n){return{rawUrl:n.url,status:n.status,method:n.method,token:null,elapsedTime:n.elapsedTime,requestHeaders:this.mapHeaders(n.requestHeaders),requestBody:n.requestBody||null,queryParams:this.mapQueryParams(n.queryParams),responseHeaders:this.mapHeaders(n.responseHeaders),responseBody:n.responseBody||null}}}class v{static setArkynConfig(n){if(this.arkynConfig)return;const{trafficSourceId:s,userToken:t,logBaseApiUrl:r}=n;this.arkynConfig={trafficSourceId:s,userToken:t,apiUrl:r||"http://95.216.190.158:8081/ingest-log"}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(v,"arkynConfig");async function G(e){const n=v.getArkynConfig();if(!n)return;const{userToken:s,apiUrl:t,trafficSourceId:r}=n,{elapsedTime:a,method:h,queryParams:l,requestBody:c,requestHeaders:d,responseBody:i,responseHeaders:p,status:z,token:y,rawUrl:vs}=e;if(process.env.NODE_ENV!=="development")try{const T=new URL(vs);let M="https";T.protocol==="http:"&&(M="http");const Cs=JSON.stringify({domainUrl:T.protocol+"//"+T.host,pathnameUrl:T.pathname,trafficSourceId:r,status:z,protocol:M,method:h.toLowerCase(),trafficUserId:null,elapsedTime:a,requestHeaders:JSON.stringify(d),requestBody:JSON.stringify(c),queryParams:JSON.stringify(l),responseHeaders:JSON.stringify(p),responseBody:JSON.stringify(i)});await fetch(t,{method:"POST",body:Cs,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(T){b({debugs:[`Error sending request: ${T}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function x(e,n,s={},t){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const a=performance.now(),h={...s,"Content-Type":"application/json"},l=await fetch(n,{method:e,headers:h,body:t?JSON.stringify(t):void 0}),c=performance.now()-a,d=l.status;let i=null;try{i=await l.json()}catch{i=null}const p=V.handle({elapsedTime:c,method:e,queryParams:new URL(n).searchParams,requestHeaders:h,requestBody:t,responseBody:i,responseHeaders:l.headers,status:d,url:n});return G(p),l.ok?{success:!0,status:d,message:(i==null?void 0:i.message)||r[e],response:i,cause:null}:{success:!1,status:d,message:(i==null?void 0:i.message)||l.statusText||"Request failed",response:i,cause:null}}catch(a){return b({debugs:[`Network error or request failed: ${a}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:a instanceof Error?a.message:String(a)}}}async function Z(e,n={},s){return x("DELETE",e,n,s)}async function W(e,n={}){return x("GET",e,n)}async function K(e,n={},s){return x("PATCH",e,n,s)}async function Q(e,n={},s){return x("POST",e,n,s)}async function X(e,n={},s){return x("PUT",e,n,s)}class ss{constructor(n){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=n.baseUrl,this.baseHeaders=n.baseHeaders||void 0,this.baseToken=n.baseToken||void 0,this.enableDebug=n.enableDebug||!1}onDebug(n,s,t){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${n}`),r.push(`Method: ${s}`),t[0]&&r.push(`Headers: ${JSON.stringify(t[0])}`),t[1]&&r.push(`Body: ${JSON.stringify(t[1])}`),b({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(n){return this.baseUrl+n}generateHeaders(n,s){let t={};return this.baseToken&&(t={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(t={...t,...this.baseHeaders}),n&&(t={...t,...n}),s&&(t={...t,Authorization:`Bearer ${s}`}),t}async get(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(n,"get",[r]),await W(t,r)}async post(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(n,"post",[r,a]),await Q(t,r,a)}async put(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(n,"put",[r,a]),await X(t,r,a)}async patch(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(n,"patch",[r,a]),await K(t,r,a)}async delete(n,s){const t=this.generateURL(n),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),a=s==null?void 0:s.body;return this.onDebug(n,"delete",[r,a]),await Z(t,r,a)}}function es(e,n){var s,t,r;return e!=null&&e.message&&typeof(e==null?void 0:e.message)=="string"?e==null?void 0:e.message:e!=null&&e.error&&typeof(e==null?void 0:e.error)=="string"?e==null?void 0:e.error:(s=e==null?void 0:e.error)!=null&&s.message&&typeof((t=e==null?void 0:e.error)==null?void 0:t.message)=="string"?(r=e==null?void 0:e.error)==null?void 0:r.message:n!=null&&n.statusText&&typeof(n==null?void 0:n.statusText)=="string"?n==null?void 0:n.statusText:"Missing error message"}const ts=async e=>{let n;const s=await e.arrayBuffer(),t=new TextDecoder().decode(s);try{n=JSON.parse(t)}catch{try{if(t.includes("=")){const a=new URLSearchParams(t);n=Object.fromEntries(a.entries())}else throw new S("Invalid URLSearchParams format")}catch{throw new S("Failed to extract data from request")}}return n};function ns(e){switch(!0){case e instanceof Response:return e;case e instanceof A:return e.toResponse();case e instanceof w:return e.toResponse();case e instanceof B:return e.toResponse();case e instanceof k:return e.toResponse();case e instanceof q:return e.toResponse()}switch(!0){case e instanceof C:return e.toResponse();case e instanceof S:return e.toResponse();case e instanceof $:return e.toResponse();case e instanceof I:return e.toResponse();case e instanceof j:return e.toResponse();case e instanceof J:return e.toResponse();case e instanceof E:return e.toResponse();case e instanceof U:return e.toResponse();case e instanceof O:return e.toResponse()}return new E("Server error",e).toResponse()}async function L([e,n]){const s=await n.safeParseAsync(e);if(s.success===!1){const t=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:t,fields:e}}else return{success:s.success,data:s.data}}function F([e,n]){const s=n.safeParse(e);if(s.success===!1){const t=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:t,fields:e}}else return{success:s.success,data:s.data}}const rs=(e,n="")=>{const s=new URL(e.url);if(n==="")return s.searchParams;const t=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${n}:`)).map(([r,a])=>[r.replace(`${n}:`,""),a]);return new URLSearchParams(t)};function os(e){const n="Error validating:",s=e.issues.map(({path:t,message:r})=>`-> ${t.join(".")}: ${r}`);return[n,...s].join(`
10
- `)}class as{constructor(n){o(this,"functionName");o(this,"callerInfo");this.schema=n;const{callerInfo:s,functionName:t}=N();this.callerInfo=s,this.functionName=t}isValid(n){return this.schema.safeParse(n).success}safeValidate(n){return this.schema.safeParse(n)}validate(n){try{return this.schema.parse(n)}catch(s){throw new E(os(s))}}formValidate(n,s){const t=F([n,this.schema]);if(!t.success){const r=Object.keys(t.fieldErrors)[0];throw new O({fields:t.fields,fieldErrors:t.fieldErrors,data:{scrollTo:r},message:s})}return t.data}async formAsyncValidate(n,s){const t=await L([n,this.schema]);if(!t.success){const r=Object.keys(t.fieldErrors)[0];throw new O({fields:t.fields,fieldErrors:t.fieldErrors,data:{scrollTo:r},message:s})}return t.data}}const us=e=>{if(!e||!/^[0-9-]+$/.test(e))return!1;const s=m.removeNonNumeric(e),t=8,r=/^\d{8}$/.test(s);return s.length===t&&r};function is(e){return e.length!==14}function cs(e){const[n]=e;return[...e].every(s=>s===n)}function H(e,n){let s=0;for(let r=0;r<n.length;r++)s+=parseInt(e[r])*n[r];const t=s%11;return t<2?0:11-t}function hs(e){return e.slice(12)}const ls=e=>{if(!e)return!1;const n=m.removeNonNumeric(e);if(is(n)||cs(n))return!1;const s=n.slice(0,12),t=H(s,[5,4,3,2,9,8,7,6,5,4,3,2]),r=H(s+t,[6,5,4,3,2,9,8,7,6,5,4,3,2]);return hs(n)===`${t}${r}`};function ds(e){return e.length!==11}function fs(e){const[n]=e;return[...e].every(s=>s===n)}function P(e,n){let s=0;for(const r of e)n>1&&(s+=parseInt(r)*n--);const t=s%11;return t<2?0:11-t}function ys(e){return e.slice(9)}const gs=e=>{if(!e)return!1;const n=m.removeNonNumeric(e);if(ds(n)||fs(n))return!1;const s=P(n,10),t=P(n,11);return ys(n)===`${s}${t}`},ps=(e,n)=>{let s,t,r;const a=(n==null?void 0:n.inputFormat)||"DD/MM/YYYY",h=(n==null?void 0:n.minYear)||1900,l=(n==null?void 0:n.maxYear)||3e3;if(a==="DD/MM/YYYY"){const y=/^(\d{2})\/(\d{2})\/(\d{4})$/;if(!y.test(e))return!1;[,s,t,r]=e.match(y)||[]}else if(a==="MM-DD-YYYY"){const y=/^(\d{2})-(\d{2})-(\d{4})$/;if(!y.test(e))return!1;[,t,s,r]=e.match(y)||[]}else if(a==="YYYY-MM-DD"){const y=/^(\d{4})-(\d{2})-(\d{2})$/;if(!y.test(e))return!1;[,r,t,s]=e.match(y)||[]}else throw new Error("Invalid date format");const c=parseInt(s,10),d=parseInt(t,10),i=parseInt(r,10);if(c<1||c>31||d<1||d>12)return!1;const p=[31,28,31,30,31,30,31,31,30,31,30,31];if(d===2){const y=i%4===0&&i%100!==0||i%400===0;if(c>(y?29:28))return!1}else if(c>p[d-1])return!1;return i<h||i>l?!1:new Date(i,d-1,c).getDate()===c};function ms(e){return/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(e)}function bs(e){return!(e.length===0||e.length>64||e.startsWith(".")||e.endsWith(".")||e.includes("..")||!/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+$/.test(e))}function Ts(e){return!(e.length===0||e.length>63||e.startsWith("-")||e.endsWith("-")||!/^[a-zA-Z0-9-]+$/.test(e))}function Rs(e){if(e.length===0||e.length>253||e.startsWith(".")||e.endsWith(".")||e.startsWith("-")||e.endsWith("-"))return!1;const n=e.split(".");if(n.length<2)return!1;for(const t of n)if(!Ts(t))return!1;const s=n[n.length-1];return!(s.length<2||!/^[a-zA-Z]+$/.test(s))}function xs(e){const n=e.split("@");if(n.length!==2)return!1;const[s,t]=n;return!(!bs(s)||!Rs(t))}function Ns(e){const n=e.split("@");return n.length===2?n[1].toLowerCase():null}const Ss=async e=>{if(!e||typeof e!="string")return!1;const n=e.trim();return!(!ms(n)||!xs(n)||!Ns(n))},Es=e=>{if(!e)return!1;const n=e.length>=8,s=/[A-Z]/.test(e),t=/[a-z]/.test(e),r=/\d/.test(e),a=/[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(e);return[n,s,t,r,a].every(h=>h)},Os=e=>{for(const n of Y.countries){const s=n.code,t=n.prefix?`-${n.prefix}`:"",r=n.mask.replace(/[^_]/g,"").length;if(n.iso==="BR"){if(new RegExp(`^\\${s} \\d{2}9?\\d{8}$`).test(e))return!0;continue}if(new RegExp(`^\\${s}${t} \\d{${r}}$`).test(e))return!0}return!1},Ds=e=>{if(!e||!/^[0-9a-zA-Z.-]+$/.test(e))return!1;const s=e.replace(/[^a-zA-Z0-9]/g,"");return s.length<7||s.length>9?!1:/^[0-9]{7,8}[0-9Xx]?$/.test(s)};u.ApiService=ss,u.ArkynLogService=v,u.BadGateway=C,u.BadRequest=S,u.Conflict=$,u.Created=w,u.DebugService=D,u.Forbidden=I,u.Found=A,u.NoContent=q,u.NotFound=j,u.NotImplemented=J,u.SchemaValidator=as,u.ServerError=E,u.Success=k,u.Unauthorized=U,u.UnprocessableEntity=O,u.Updated=B,u.decodeErrorMessageFromRequest=es,u.decodeRequestBody=ts,u.errorHandler=ns,u.flushDebugLogs=b,u.formAsyncParse=L,u.formParse=F,u.getCaller=N,u.getScopedParams=rs,u.validateCep=us,u.validateCnpj=ls,u.validateCpf=gs,u.validateDate=ps,u.validateEmail=Ss,u.validatePassword=Es,u.validatePhone=Os,u.validateRg=Ds,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
@@ -1,20 +0,0 @@
1
- import { flushDebugLogs } from "../../services/flushDebugLogs";
2
- import { getCaller } from "../../services/getCaller";
3
- class BadResponse {
4
- onDebug(input) {
5
- const { name, body, cause, message } = input;
6
- const debugs = [];
7
- const { callerInfo, functionName } = getCaller();
8
- debugs.push(`${name} initialized`);
9
- debugs.push(`Caller Function: ${functionName}`);
10
- debugs.push(`Caller Location: ${callerInfo}`);
11
- if (message)
12
- debugs.push(`Message: ${message}`);
13
- if (body)
14
- debugs.push(`Body: ${JSON.stringify(body, null, 2)}`);
15
- if (cause)
16
- debugs.push(`Cause: ${JSON.stringify(cause, null, 2)}`);
17
- flushDebugLogs({ scheme: "red", name: "ARKYN-BAD-RESPONSE-DEBUG", debugs });
18
- }
19
- }
20
- export { BadResponse };
@@ -1,58 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 502 (Bad Gateway).
4
- * This class is used to standardize the structure of a "Bad Gateway" error response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class BadGateway extends BadResponse {
8
- body;
9
- cause;
10
- status = 502;
11
- statusText;
12
- /**
13
- * Creates an instance of the `BadGateway` class.
14
- *
15
- * @param message - A descriptive message explaining the cause of the error.
16
- * @param cause - Optional additional information about the cause of the error.
17
- */
18
- constructor(message, cause) {
19
- super();
20
- this.body = { name: "BadGateway", message: message };
21
- this.statusText = message;
22
- this.cause = cause ? JSON.stringify(cause) : undefined;
23
- this.onDebug({
24
- name: "BadGateway",
25
- body: this.body,
26
- cause: this.cause,
27
- message: this.statusText,
28
- });
29
- }
30
- /**
31
- * Converts the `BadGateway` instance into a `Response` object with a JSON body.
32
- * This method ensures the response has the appropriate headers, status, and status text.
33
- *
34
- * @returns A `Response` object with the serialized JSON body and response metadata.
35
- */
36
- toResponse() {
37
- const responseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
- return new Response(JSON.stringify(this.body), responseInit);
43
- }
44
- /**
45
- * Converts the `BadGateway` instance into a `Response` object using the `Response.json` method.
46
- * This method is an alternative to `toResponse` for generating JSON error responses.
47
- *
48
- * @returns A `Response` object with the JSON body and response metadata.
49
- */
50
- toJson() {
51
- const responseInit = {
52
- status: this.status,
53
- statusText: this.statusText,
54
- };
55
- return Response.json(this.body, responseInit);
56
- }
57
- }
58
- export { BadGateway };
@@ -1,58 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 400 (Bad Request).
4
- * This class is used to standardize the structure of a "Bad Request" error response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class BadRequest extends BadResponse {
8
- body;
9
- cause;
10
- status = 400;
11
- statusText;
12
- /**
13
- * Creates an instance of the `BadRequest` class.
14
- *
15
- * @param message - A descriptive message explaining the cause of the error.
16
- * @param cause - Optional additional information about the cause of the error.
17
- */
18
- constructor(message, cause) {
19
- super();
20
- this.body = { name: "BadRequest", message: message };
21
- this.statusText = message;
22
- this.cause = cause ? JSON.stringify(cause) : undefined;
23
- this.onDebug({
24
- name: "BadRequest",
25
- body: this.body,
26
- cause: this.cause,
27
- message: this.statusText,
28
- });
29
- }
30
- /**
31
- * Converts the `BadRequest` instance into a `Response` object with a JSON body.
32
- * This method ensures the response has the appropriate headers, status, and status text.
33
- *
34
- * @returns A `Response` object with the serialized JSON body and response metadata.
35
- */
36
- toResponse() {
37
- const responseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
- return new Response(JSON.stringify(this.body), responseInit);
43
- }
44
- /**
45
- * Converts the `BadRequest` instance into a `Response` object using the `Response.json` method.
46
- * This method is an alternative to `toResponse` for generating JSON error responses.
47
- *
48
- * @returns A `Response` object with the JSON body and response metadata.
49
- */
50
- toJson() {
51
- const responseInit = {
52
- status: this.status,
53
- statusText: this.statusText,
54
- };
55
- return Response.json(this.body, responseInit);
56
- }
57
- }
58
- export { BadRequest };
@@ -1,58 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 409 (Conflict).
4
- * This class is used to standardize the structure of a "Conflict" error response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class Conflict extends BadResponse {
8
- body;
9
- cause;
10
- status = 409;
11
- statusText;
12
- /**
13
- * Creates an instance of the `Conflict` class.
14
- *
15
- * @param message - A descriptive message explaining the cause of the conflict.
16
- * @param cause - Optional additional information about the cause of the conflict.
17
- */
18
- constructor(message, cause) {
19
- super();
20
- this.body = { name: "Conflict", message: message };
21
- this.statusText = message;
22
- this.cause = cause ? JSON.stringify(cause) : undefined;
23
- this.onDebug({
24
- name: "Conflict",
25
- body: this.body,
26
- cause: this.cause,
27
- message: this.statusText,
28
- });
29
- }
30
- /**
31
- * Converts the `Conflict` instance into a `Response` object with a JSON body.
32
- * This method ensures the response has the appropriate headers, status, and status text.
33
- *
34
- * @returns A `Response` object with the serialized JSON body and response metadata.
35
- */
36
- toResponse() {
37
- const responseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
- return new Response(JSON.stringify(this.body), responseInit);
43
- }
44
- /**
45
- * Converts the `Conflict` instance into a `Response` object using the `Response.json` method.
46
- * This method is an alternative to `toResponse` for generating JSON error responses.
47
- *
48
- * @returns A `Response` object with the JSON body and response metadata.
49
- */
50
- toJson() {
51
- const responseInit = {
52
- status: this.status,
53
- statusText: this.statusText,
54
- };
55
- return Response.json(this.body, responseInit);
56
- }
57
- }
58
- export { Conflict };
@@ -1,58 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 403 (Forbidden).
4
- * This class is used to standardize the structure of a "Forbidden" error response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class Forbidden extends BadResponse {
8
- body;
9
- cause;
10
- status = 403;
11
- statusText;
12
- /**
13
- * Creates an instance of the `Forbidden` class.
14
- *
15
- * @param message - A descriptive message explaining why access is forbidden.
16
- * @param cause - Optional additional information about the cause of the error.
17
- */
18
- constructor(message, cause) {
19
- super();
20
- this.body = { name: "Forbidden", message: message };
21
- this.statusText = message;
22
- this.cause = cause ? JSON.stringify(cause) : undefined;
23
- this.onDebug({
24
- name: "Forbidden",
25
- body: this.body,
26
- cause: this.cause,
27
- message: this.statusText,
28
- });
29
- }
30
- /**
31
- * Converts the `Forbidden` instance into a `Response` object with a JSON body.
32
- * This method ensures the response has the appropriate headers, status, and status text.
33
- *
34
- * @returns A `Response` object with the serialized JSON body and response metadata.
35
- */
36
- toResponse() {
37
- const responseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
- return new Response(JSON.stringify(this.body), responseInit);
43
- }
44
- /**
45
- * Converts the `Forbidden` instance into a `Response` object using the `Response.json` method.
46
- * This method is an alternative to `toResponse` for generating JSON error responses.
47
- *
48
- * @returns A `Response` object with the JSON body and response metadata.
49
- */
50
- toJson() {
51
- const responseInit = {
52
- status: this.status,
53
- statusText: this.statusText,
54
- };
55
- return Response.json(this.body, responseInit);
56
- }
57
- }
58
- export { Forbidden };
@@ -1,58 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 404 (Not Found).
4
- * This class is used to standardize the structure of a "Not Found" error response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class NotFound extends BadResponse {
8
- body;
9
- cause;
10
- status = 404;
11
- statusText;
12
- /**
13
- * Creates an instance of the `NotFound` class.
14
- *
15
- * @param message - A descriptive message explaining the reason the resource was not found.
16
- * @param cause - Optional additional information about the cause of the error.
17
- */
18
- constructor(message, cause) {
19
- super();
20
- this.body = { name: "NotFound", message: message };
21
- this.statusText = message;
22
- this.cause = cause ? JSON.stringify(cause) : undefined;
23
- this.onDebug({
24
- name: "NotFound",
25
- body: this.body,
26
- cause: this.cause,
27
- message: this.statusText,
28
- });
29
- }
30
- /**
31
- * Converts the `NotFound` instance into a `Response` object with a JSON body.
32
- * This method ensures the response has the appropriate headers, status, and status text.
33
- *
34
- * @returns A `Response` object with the serialized JSON body and response metadata.
35
- */
36
- toResponse() {
37
- const responseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
- return new Response(JSON.stringify(this.body), responseInit);
43
- }
44
- /**
45
- * Converts the `NotFound` instance into a `Response` object using the `Response.json` method.
46
- * This method is an alternative to `toResponse` for generating JSON error responses.
47
- *
48
- * @returns A `Response` object with the JSON body and response metadata.
49
- */
50
- toJson() {
51
- const responseInit = {
52
- status: this.status,
53
- statusText: this.statusText,
54
- };
55
- return Response.json(this.body, responseInit);
56
- }
57
- }
58
- export { NotFound };
@@ -1,58 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 501 (Not Implemented).
4
- * This class is used to standardize the structure of a "Not Implemented" error response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class NotImplemented extends BadResponse {
8
- body;
9
- cause;
10
- status = 501;
11
- statusText;
12
- /**
13
- * Creates an instance of the `NotImplemented` class.
14
- *
15
- * @param message - A descriptive message explaining why the functionality is not implemented.
16
- * @param cause - Optional additional information about the cause of the error.
17
- */
18
- constructor(message, cause) {
19
- super();
20
- this.body = { name: "NotImplemented", message: message };
21
- this.statusText = message;
22
- this.cause = cause ? JSON.stringify(cause) : undefined;
23
- this.onDebug({
24
- name: "NotImplemented",
25
- body: this.body,
26
- cause: this.cause,
27
- message: this.statusText,
28
- });
29
- }
30
- /**
31
- * Converts the `NotImplemented` instance into a `Response` object with a JSON body.
32
- * This method ensures the response has the appropriate headers, status, and status text.
33
- *
34
- * @returns A `Response` object with the serialized JSON body and response metadata.
35
- */
36
- toResponse() {
37
- const responseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
- return new Response(JSON.stringify(this.body), responseInit);
43
- }
44
- /**
45
- * Converts the `NotImplemented` instance into a `Response` object using the `Response.json` method.
46
- * This method is an alternative to `toResponse` for generating JSON error responses.
47
- *
48
- * @returns A `Response` object with the JSON body and response metadata.
49
- */
50
- toJson() {
51
- const responseInit = {
52
- status: this.status,
53
- statusText: this.statusText,
54
- };
55
- return Response.json(this.body, responseInit);
56
- }
57
- }
58
- export { NotImplemented };
@@ -1,58 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 500 (Internal Server Error).
4
- * This class is used to standardize the structure of a "Server Error" response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class ServerError extends BadResponse {
8
- body;
9
- cause;
10
- status = 500;
11
- statusText;
12
- /**
13
- * Creates an instance of the `ServerError` class.
14
- *
15
- * @param message - A descriptive message explaining the cause of the server error.
16
- * @param cause - Optional additional information about the cause of the error.
17
- */
18
- constructor(message, cause) {
19
- super();
20
- this.body = { name: "ServerError", message: message };
21
- this.statusText = message;
22
- this.cause = cause ? JSON.stringify(cause) : undefined;
23
- this.onDebug({
24
- name: "ServerError",
25
- body: this.body,
26
- cause: this.cause,
27
- message: this.statusText,
28
- });
29
- }
30
- /**
31
- * Converts the `ServerError` instance into a `Response` object with a JSON body.
32
- * This method ensures the response has the appropriate headers, status, and status text.
33
- *
34
- * @returns A `Response` object with the serialized JSON body and response metadata.
35
- */
36
- toResponse() {
37
- const responseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
- return new Response(JSON.stringify(this.body), responseInit);
43
- }
44
- /**
45
- * Converts the `ServerError` instance into a `Response` object using the `Response.json` method.
46
- * This method is an alternative to `toResponse` for generating JSON error responses.
47
- *
48
- * @returns A `Response` object with the JSON body and response metadata.
49
- */
50
- toJson() {
51
- const responseInit = {
52
- status: this.status,
53
- statusText: this.statusText,
54
- };
55
- return Response.json(this.body, responseInit);
56
- }
57
- }
58
- export { ServerError };
@@ -1,58 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 401 (Unauthorized).
4
- * This class is used to standardize the structure of an "Unauthorized" error response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class Unauthorized extends BadResponse {
8
- body;
9
- cause;
10
- status = 401;
11
- statusText;
12
- /**
13
- * Creates an instance of the `Unauthorized` class.
14
- *
15
- * @param message - A descriptive message explaining why the request is unauthorized.
16
- * @param cause - Optional additional information about the cause of the error.
17
- */
18
- constructor(message, cause) {
19
- super();
20
- this.body = { name: "Unauthorized", message: message };
21
- this.statusText = message;
22
- this.cause = cause ? JSON.stringify(cause) : undefined;
23
- this.onDebug({
24
- name: "Unauthorized",
25
- body: this.body,
26
- cause: this.cause,
27
- message: this.statusText,
28
- });
29
- }
30
- /**
31
- * Converts the `Unauthorized` instance into a `Response` object with a JSON body.
32
- * This method ensures the response has the appropriate headers, status, and status text.
33
- *
34
- * @returns A `Response` object with the serialized JSON body and response metadata.
35
- */
36
- toResponse() {
37
- const responseInit = {
38
- headers: { "Content-Type": "application/json" },
39
- status: this.status,
40
- statusText: this.statusText,
41
- };
42
- return new Response(JSON.stringify(this.body), responseInit);
43
- }
44
- /**
45
- * Converts the `Unauthorized` instance into a `Response` object using the `Response.json` method.
46
- * This method is an alternative to `toResponse` for generating JSON error responses.
47
- *
48
- * @returns A `Response` object with the JSON body and response metadata.
49
- */
50
- toJson() {
51
- const responseInit = {
52
- status: this.status,
53
- statusText: this.statusText,
54
- };
55
- return Response.json(this.body, responseInit);
56
- }
57
- }
58
- export { Unauthorized };
@@ -1,65 +0,0 @@
1
- import { BadResponse } from "./_badResponse";
2
- /**
3
- * Represents an HTTP error response with a status code of 422 (Unprocessable Entity).
4
- * This class is used to standardize the structure of an "Unprocessable Entity" error response,
5
- * including the response body, headers, status, and status text.
6
- */
7
- class UnprocessableEntity extends BadResponse {
8
- body;
9
- status = 422;
10
- statusText;
11
- /**
12
- * Creates an instance of the `UnprocessableEntity` class.
13
- *
14
- * @param props - An object containing details about the error, such as:
15
- * - `data`: Additional data related to the error.
16
- * - `fieldErrors`: A record of field-specific error messages.
17
- * - `fields`: A record of field values that caused the error.
18
- * - `message`: A descriptive message explaining the error.
19
- * @param enableDebug - A boolean indicating whether to enable debug logging for this error.
20
- */
21
- constructor(props) {
22
- super();
23
- this.statusText = props.message || "Unprocessable Entity";
24
- this.body = {
25
- name: "UnprocessableEntity",
26
- message: props.message || null,
27
- data: props.data,
28
- fieldErrors: props.fieldErrors,
29
- fields: props.fields,
30
- };
31
- this.onDebug({
32
- name: "UnprocessableEntity",
33
- cause: props.fieldErrors,
34
- message: props.message,
35
- });
36
- }
37
- /**
38
- * Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
39
- * This method ensures the response has the appropriate headers, status, and status text.
40
- *
41
- * @returns A `Response` object with the serialized JSON body and response metadata.
42
- */
43
- toResponse() {
44
- const responseInit = {
45
- headers: { "Content-Type": "application/json" },
46
- status: this.status,
47
- statusText: this.statusText,
48
- };
49
- return new Response(JSON.stringify(this.body), responseInit);
50
- }
51
- /**
52
- * Converts the `UnprocessableEntity` instance into a `Response` object using the `Response.json` method.
53
- * This method is an alternative to `toResponse` for generating JSON error responses.
54
- *
55
- * @returns A `Response` object with the JSON body and response metadata.
56
- */
57
- toJson() {
58
- const responseInit = {
59
- status: this.status,
60
- statusText: this.statusText,
61
- };
62
- return Response.json(this.body, responseInit);
63
- }
64
- }
65
- export { UnprocessableEntity };
@@ -1,37 +0,0 @@
1
- import { flushDebugLogs } from "../../services/flushDebugLogs";
2
- import { getCaller } from "../../services/getCaller";
3
- /**
4
- * Base class for handling bad HTTP responses with debugging capabilities.
5
- * Provides logging functionality to track response errors and their context.
6
- */
7
- class SuccessResponse {
8
- /**
9
- * Logs debug information for success responses including caller context and response details.
10
- *
11
- * @param name - The name/type of the success response being logged
12
- * @param body - The response body or success data to be logged
13
- * @param cause - Optional additional cause information for the error
14
- *
15
- * @example
16
- * ```typescript
17
- * const SuccessResponse = new SuccessResponse();
18
- * SuccessResponse.onDebug("ValidationError", { field: "email", message: "Invalid format" });
19
- * ```
20
- */
21
- onDebug(name, body, cause) {
22
- const debugs = [];
23
- const { callerInfo, functionName } = getCaller();
24
- debugs.push(`${name} initialized\n`);
25
- debugs.push(`Caller Function: ${functionName}\n`);
26
- debugs.push(`Caller Location: ${callerInfo}\n`);
27
- debugs.push(`Body: ${JSON.stringify(body, null, 2)}\n`);
28
- if (cause)
29
- debugs.push(`Cause: ${JSON.stringify(cause, null, 2)}\n`);
30
- flushDebugLogs({
31
- scheme: "green",
32
- name: "ARKYN-SUCCESS-RESPONSE-DEBUG",
33
- debugs,
34
- });
35
- }
36
- }
37
- export { SuccessResponse };