@arkyn/server 3.0.1-beta.7 → 3.0.1-beta.71

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 (125) hide show
  1. package/README.md +368 -65
  2. package/dist/api/arkynLogRequest.d.ts +1 -1
  3. package/dist/api/arkynLogRequest.d.ts.map +1 -1
  4. package/dist/api/arkynLogRequest.js +14 -13
  5. package/dist/api/makeRequest.d.ts +1 -1
  6. package/dist/api/makeRequest.d.ts.map +1 -1
  7. package/dist/api/makeRequest.js +9 -8
  8. package/dist/bundle.js +1216 -0
  9. package/dist/bundle.umd.cjs +10 -0
  10. package/dist/http/badResponses/_badResponse.d.ts +11 -0
  11. package/dist/http/badResponses/_badResponse.d.ts.map +1 -0
  12. package/dist/http/badResponses/_badResponse.js +20 -0
  13. package/dist/http/badResponses/badGateway.d.ts +2 -1
  14. package/dist/http/badResponses/badGateway.d.ts.map +1 -1
  15. package/dist/http/badResponses/badGateway.js +9 -3
  16. package/dist/http/badResponses/badRequest.d.ts +2 -1
  17. package/dist/http/badResponses/badRequest.d.ts.map +1 -1
  18. package/dist/http/badResponses/badRequest.js +9 -3
  19. package/dist/http/badResponses/conflict.d.ts +2 -1
  20. package/dist/http/badResponses/conflict.d.ts.map +1 -1
  21. package/dist/http/badResponses/conflict.js +9 -3
  22. package/dist/http/badResponses/forbidden.d.ts +2 -1
  23. package/dist/http/badResponses/forbidden.d.ts.map +1 -1
  24. package/dist/http/badResponses/forbidden.js +9 -3
  25. package/dist/http/badResponses/notFound.d.ts +2 -1
  26. package/dist/http/badResponses/notFound.d.ts.map +1 -1
  27. package/dist/http/badResponses/notFound.js +9 -3
  28. package/dist/http/badResponses/notImplemented.d.ts +2 -1
  29. package/dist/http/badResponses/notImplemented.d.ts.map +1 -1
  30. package/dist/http/badResponses/notImplemented.js +9 -3
  31. package/dist/http/badResponses/serverError.d.ts +2 -1
  32. package/dist/http/badResponses/serverError.d.ts.map +1 -1
  33. package/dist/http/badResponses/serverError.js +9 -3
  34. package/dist/http/badResponses/unauthorized.d.ts +2 -1
  35. package/dist/http/badResponses/unauthorized.d.ts.map +1 -1
  36. package/dist/http/badResponses/unauthorized.js +9 -3
  37. package/dist/http/badResponses/unprocessableEntity.d.ts +3 -2
  38. package/dist/http/badResponses/unprocessableEntity.d.ts.map +1 -1
  39. package/dist/http/badResponses/unprocessableEntity.js +9 -4
  40. package/dist/http/successResponses/_successResponse.d.ts +22 -0
  41. package/dist/http/successResponses/_successResponse.d.ts.map +1 -0
  42. package/dist/http/successResponses/_successResponse.js +37 -0
  43. package/dist/http/successResponses/created.d.ts +2 -1
  44. package/dist/http/successResponses/created.d.ts.map +1 -1
  45. package/dist/http/successResponses/created.js +4 -1
  46. package/dist/http/successResponses/found.d.ts +2 -1
  47. package/dist/http/successResponses/found.d.ts.map +1 -1
  48. package/dist/http/successResponses/found.js +4 -1
  49. package/dist/http/successResponses/noContent.d.ts +2 -1
  50. package/dist/http/successResponses/noContent.d.ts.map +1 -1
  51. package/dist/http/successResponses/noContent.js +4 -1
  52. package/dist/http/successResponses/success.d.ts +2 -1
  53. package/dist/http/successResponses/success.d.ts.map +1 -1
  54. package/dist/http/successResponses/success.js +4 -1
  55. package/dist/http/successResponses/updated.d.ts +2 -1
  56. package/dist/http/successResponses/updated.d.ts.map +1 -1
  57. package/dist/http/successResponses/updated.js +4 -1
  58. package/dist/index.d.ts +4 -3
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +4 -4
  61. package/dist/{config/apiInstance.d.ts → services/apiService.d.ts} +25 -21
  62. package/dist/services/apiService.d.ts.map +1 -0
  63. package/dist/{config/apiInstance.js → services/apiService.js} +45 -23
  64. package/dist/{config/arkynLogInstance.d.ts → services/arkynLogService.d.ts} +5 -5
  65. package/dist/services/arkynLogService.d.ts.map +1 -0
  66. package/dist/{config/arkynLogInstance.js → services/arkynLogService.js} +4 -5
  67. package/dist/services/debugService.d.ts +54 -0
  68. package/dist/services/debugService.d.ts.map +1 -0
  69. package/dist/services/debugService.js +57 -0
  70. package/dist/services/flushDebugLogs.d.ts +8 -0
  71. package/dist/services/flushDebugLogs.d.ts.map +1 -0
  72. package/dist/services/flushDebugLogs.js +20 -0
  73. package/dist/services/formParse.d.ts +3 -3
  74. package/dist/services/formParse.d.ts.map +1 -1
  75. package/dist/services/formParse.js +7 -5
  76. package/dist/services/getCaller.d.ts.map +1 -1
  77. package/dist/services/getCaller.js +9 -14
  78. package/dist/services/measureRouteExecution.d.ts +3 -0
  79. package/dist/services/measureRouteExecution.d.ts.map +1 -0
  80. package/dist/services/measureRouteExecution.js +24 -0
  81. package/dist/services/schemaValidator.d.ts +3 -3
  82. package/dist/services/schemaValidator.d.ts.map +1 -1
  83. package/dist/services/schemaValidator.js +2 -4
  84. package/package.json +33 -18
  85. package/dist/config/apiInstance.d.ts.map +0 -1
  86. package/dist/config/arkynLogInstance.d.ts.map +0 -1
  87. package/dist/services/httpDebug.d.ts +0 -35
  88. package/dist/services/httpDebug.d.ts.map +0 -1
  89. package/dist/services/httpDebug.js +0 -52
  90. package/src/api/arkynLogRequest.ts +0 -118
  91. package/src/api/deleteRequest.ts +0 -22
  92. package/src/api/getRequest.ts +0 -20
  93. package/src/api/makeRequest.ts +0 -122
  94. package/src/api/patchRequest.ts +0 -22
  95. package/src/api/postRequest.ts +0 -22
  96. package/src/api/putRequest.ts +0 -22
  97. package/src/config/apiInstance.ts +0 -148
  98. package/src/config/arkynLogInstance.ts +0 -75
  99. package/src/http/badResponses/badGateway.ts +0 -63
  100. package/src/http/badResponses/badRequest.ts +0 -63
  101. package/src/http/badResponses/conflict.ts +0 -63
  102. package/src/http/badResponses/forbidden.ts +0 -63
  103. package/src/http/badResponses/notFound.ts +0 -63
  104. package/src/http/badResponses/notImplemented.ts +0 -63
  105. package/src/http/badResponses/serverError.ts +0 -63
  106. package/src/http/badResponses/unauthorized.ts +0 -63
  107. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  108. package/src/http/successResponses/created.ts +0 -64
  109. package/src/http/successResponses/found.ts +0 -67
  110. package/src/http/successResponses/noContent.ts +0 -42
  111. package/src/http/successResponses/success.ts +0 -64
  112. package/src/http/successResponses/updated.ts +0 -64
  113. package/src/index.ts +0 -31
  114. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  115. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  116. package/src/services/decodeRequestBody.ts +0 -43
  117. package/src/services/errorHandler.ts +0 -99
  118. package/src/services/formParse.ts +0 -83
  119. package/src/services/getCaller.ts +0 -82
  120. package/src/services/getScopedParams.ts +0 -43
  121. package/src/services/httpDebug.ts +0 -61
  122. package/src/services/schemaValidator.ts +0 -66
  123. package/src/types/ApiResponseDTO.ts +0 -19
  124. package/tsconfig.json +0 -21
  125. package/vitest.config.ts +0 -5
@@ -0,0 +1,10 @@
1
+ (function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a["@arkyn/server"]={}))})(this,function(a){"use strict";var es=Object.defineProperty;var ts=(a,l,g)=>l in a?es(a,l,{enumerable:!0,configurable:!0,writable:!0,value:g}):a[l]=g;var o=(a,l,g)=>ts(a,typeof l!="symbol"?l+"":l,g);function l(n){var s;if(process.env.NODE_ENV==="development"||((s=process.env)==null?void 0:s.SHOW_ERRORS_IN_CONSOLE)==="true"){const u=`${{yellow:"\x1B[33m",cyan:"\x1B[36m",red:"\x1B[31m",green:"\x1B[32m"}[n.scheme]}[${n.name}]\x1B[0m`;let c=`
2
+ `;n.debugs.forEach(d=>{c+=`${u} ${d.trim()}
3
+ `}),console.log(c)}}const g={};class N{static setIgnoreFile(t){this.ignoreFiles.push(t)}static clearIgnoreFiles(){this.ignoreFiles=[]}}o(N,"ignoreFiles",[]);function R(){const n=process.cwd(),e=(new Error().stack||"").split(`
4
+ `).map(i=>i.trim()),r=N.ignoreFiles;let u=2;for(;u<e.length&&(e[u].includes("node:internal")||e[u].includes("/node_modules/"));)u++;if(r.length>0)for(;u<e.length&&r.some(i=>e[u].includes(i));)u++;const c=e[u]||"";let d="Unknown function",h="Unknown caller";const f=c.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)d=f[1],h=f[2];else{const i=c.match(/at\s+(.+)/);if(i){h=i[1];const p=h.match(/at\s+([^(\s]+)\s+/);p&&p[1]!=="new"&&(d=p[1])}}h.includes("(")&&(h=h.substring(h.indexOf("(")+1,h.lastIndexOf(")"))),h=h.split(":").slice(0,-2).join(":");try{h=g.relative(n,h)}catch{}return{functionName:d,callerInfo:h}}class y{onDebug(t){const{name:s,body:e,cause:r,message:u}=t,c=[],{callerInfo:d,functionName:h}=R();c.push(`${s} initialized`),c.push(`Caller Function: ${h}`),c.push(`Caller Location: ${d}`),u&&c.push(`Message: ${u}`),e&&c.push(`Body: ${JSON.stringify(e,null,2)}`),r&&c.push(`Cause: ${JSON.stringify(r,null,2)}`),l({scheme:"red",name:"ARKYN-BAD-RESPONSE-DEBUG",debugs:c})}}class O extends y{constructor(s,e){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=e?JSON.stringify(e):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 x extends y{constructor(s,e){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=e?JSON.stringify(e):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 U extends y{constructor(s,e){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=e?JSON.stringify(e):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 y{constructor(s,e){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=e?JSON.stringify(e):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 k extends y{constructor(s,e){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=e?JSON.stringify(e):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 y{constructor(s,e){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=e?JSON.stringify(e):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 S extends y{constructor(s,e){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=e?JSON.stringify(e):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 C extends y{constructor(s,e){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=e?JSON.stringify(e):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 w extends y{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 T{onDebug(t,s,e){const r=[],{callerInfo:u,functionName:c}=R();r.push(`${t} initialized
5
+ `),r.push(`Caller Function: ${c}
6
+ `),r.push(`Caller Location: ${u}
7
+ `),r.push(`Body: ${JSON.stringify(s,null,2)}
8
+ `),e&&r.push(`Cause: ${JSON.stringify(e,null,2)}
9
+ `),l({scheme:"green",name:"ARKYN-SUCCESS-RESPONSE-DEBUG",debugs:r})}}class J extends T{constructor(s,e){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||201,this.statusText=(e==null?void 0:e.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 D extends T{constructor(s,e){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||302,this.statusText=(e==null?void 0:e.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 B extends T{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 q extends T{constructor(s,e){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.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 P extends T{constructor(s,e){super();o(this,"body");o(this,"headers");o(this,"status");o(this,"statusText");this.body=s,this.headers=(e==null?void 0:e.headers)||{},this.status=(e==null?void 0:e.status)||200,this.statusText=(e==null?void 0:e.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 H{static mapHeaders(t){return t instanceof Headers?Object.fromEntries(t.entries()):typeof t=="object"?Object.entries(t).reduce((s,[e,r])=>(typeof r=="string"?s[e]=r:Array.isArray(r)?s[e]=r.join(", "):s[e]=JSON.stringify(r),s),{}):{}}static mapQueryParams(t){const s={};return t.forEach((e,r)=>{s[r]=e}),s}static handle(t){return{rawUrl:t.url,status:t.status,method:t.method,token:null,elapsedTime:t.elapsedTime,requestHeaders:this.mapHeaders(t.requestHeaders),requestBody:t.requestBody||null,queryParams:this.mapQueryParams(t.queryParams),responseHeaders:this.mapHeaders(t.responseHeaders),responseBody:t.responseBody||null}}}class E{static setArkynConfig(t){if(this.arkynConfig)return;let e=t.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";e=e+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:t.arkynTrafficSourceId,arkynUserToken:t.arkynUserToken,arkynApiUrl:e}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(E,"arkynConfig");async function L(n){const t=E.getArkynConfig();if(!t)return;const{arkynUserToken:s,arkynApiUrl:e}=t,{elapsedTime:r,method:u,queryParams:c,requestBody:d,requestHeaders:h,responseBody:f,responseHeaders:i,status:p,token:ns,rawUrl:Z}=n;if(process.env.NODE_ENV!=="development")try{const b=new URL(Z);let A="HTTPS";b.protocol==="http:"&&(A="HTTP");const ss=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:p,protocol:A,method:u,trafficUserId:null,elapsedTime:r,requestHeaders:h,requestBody:d,queryParams:c,responseHeaders:i,responseBody:f});await fetch(e.replace(":trafficSourceId",t.arkynTrafficSourceId),{method:"POST",body:ss,headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`}})}catch(b){l({debugs:[`Error sending request: ${b}`],name:"ARKYN_LOG_ERROR",scheme:"red"})}}async function m(n,t,s={},e){const r={POST:"Resource created successfully",PUT:"Resource updated successfully",DELETE:"Resource deleted successfully",PATCH:"Resource patched successfully",GET:"Request successful"};try{const u=performance.now(),c={...s,"Content-Type":"application/json"},d=await fetch(t,{method:n,headers:c,body:e?JSON.stringify(e):void 0}),h=performance.now()-u,f=d.status;let i=null;try{i=await d.json()}catch{i=null}const p=H.handle({elapsedTime:h,method:n,queryParams:new URL(t).searchParams,requestHeaders:c,requestBody:e,responseBody:i,responseHeaders:d.headers,status:f,url:t});return L(p),d.ok?{success:!0,status:f,message:(i==null?void 0:i.message)||r[n],response:i,cause:null}:{success:!1,status:f,message:(i==null?void 0:i.message)||d.statusText||"Request failed",response:i,cause:null}}catch(u){return l({debugs:[`Network error or request failed: ${u}`],name:"ARKYN_MAKE_REQUEST_ERROR",scheme:"red"}),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function $(n,t={},s){return m("DELETE",n,t,s)}async function F(n,t={}){return m("GET",n,t)}async function M(n,t={},s){return m("PATCH",n,t,s)}async function _(n,t={},s){return m("POST",n,t,s)}async function z(n,t={},s){return m("PUT",n,t,s)}class G{constructor(t){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=t.baseUrl,this.baseHeaders=t.baseHeaders||void 0,this.baseToken=t.baseToken||void 0,this.enableDebug=t.enableDebug||!1}onDebug(t,s,e){if(this.enableDebug){const r=[];r.push(`Base URL: ${this.baseUrl}`),r.push(`Endpoint: ${t}`),r.push(`Method: ${s}`),e[0]&&r.push(`Headers: ${JSON.stringify(e[0])}`),e[1]&&r.push(`Body: ${JSON.stringify(e[1])}`),l({debugs:r,name:"ARKYN-API-DEBUG",scheme:"yellow"})}}generateURL(t){return this.baseUrl+t}generateHeaders(t,s){let e={};return this.baseToken&&(e={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(e={...e,...this.baseHeaders}),t&&(e={...e,...t}),s&&(e={...e,Authorization:`Bearer ${s}`}),e}async get(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token);return this.onDebug(t,"get",[r]),await F(e,r)}async post(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"post",[r,u]),await _(e,r,u)}async put(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"put",[r,u]),await z(e,r,u)}async patch(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"patch",[r,u]),await M(e,r,u)}async delete(t,s){const e=this.generateURL(t),r=this.generateHeaders((s==null?void 0:s.headers)||{},s==null?void 0:s.token),u=s==null?void 0:s.body;return this.onDebug(t,"delete",[r,u]),await $(e,r,u)}}function K(n,t){var s,e,r;return n!=null&&n.message&&typeof(n==null?void 0:n.message)=="string"?n==null?void 0:n.message:n!=null&&n.error&&typeof(n==null?void 0:n.error)=="string"?n==null?void 0:n.error:(s=n==null?void 0:n.error)!=null&&s.message&&typeof((e=n==null?void 0:n.error)==null?void 0:e.message)=="string"?(r=n==null?void 0:n.error)==null?void 0:r.message:t!=null&&t.statusText&&typeof(t==null?void 0:t.statusText)=="string"?t==null?void 0:t.statusText:"Missing error message"}const V=async n=>{let t;const s=await n.arrayBuffer(),e=new TextDecoder().decode(s);try{t=JSON.parse(e)}catch{try{if(e.includes("=")){const u=new URLSearchParams(e);t=Object.fromEntries(u.entries())}else throw new x("Invalid URLSearchParams format")}catch{throw new x("Failed to extract data from request")}}return t};function Y(n){switch(!0){case n instanceof Response:return n;case n instanceof D:return n.toResponse();case n instanceof J:return n.toResponse();case n instanceof P:return n.toResponse();case n instanceof q:return n.toResponse();case n instanceof B:return n.toResponse()}switch(!0){case n instanceof O:return n.toResponse();case n instanceof x:return n.toResponse();case n instanceof U:return n.toResponse();case n instanceof I:return n.toResponse();case n instanceof k:return n.toResponse();case n instanceof j:return n.toResponse();case n instanceof S:return n.toResponse();case n instanceof C:return n.toResponse();case n instanceof w:return n.toResponse()}return new S("Server error",n).toResponse()}function v([n,t]){const s=t.safeParse(n);if(s.success===!1){const e=Object.fromEntries(s.error.issues.map(r=>[r.path.join("."),r.message]));return{success:s.success,fieldErrors:e,fields:n}}else return{success:s.success,data:s.data}}const Q=(n,t="")=>{const s=new URL(n.url);if(t==="")return s.searchParams;const e=Array.from(s.searchParams.entries()).filter(([r])=>r.startsWith(`${t}:`)).map(([r,u])=>[r.replace(`${t}:`,""),u]);return new URLSearchParams(e)};function W(n){const t="Error validating:",s=n.issues.map(({path:e,message:r})=>`-> ${e.join(".")}: ${r}`);return[t,...s].join(`
10
+ `)}class X{constructor(t){o(this,"functionName");o(this,"callerInfo");this.schema=t;const{callerInfo:s,functionName:e}=R();this.callerInfo=s,this.functionName=e}isValid(t){return this.schema.safeParse(t).success}safeValidate(t){return this.schema.safeParse(t)}validate(t){try{return this.schema.parse(t)}catch(s){throw new S(W(s))}}formValidate(t,s){const e=v([t,this.schema]);if(!e.success){const r=Object.keys(e.fieldErrors)[0];throw new w({fields:e.fields,fieldErrors:e.fieldErrors,data:{scrollTo:r},message:s})}return e.data}}a.ApiService=G,a.ArkynLogService=E,a.BadGateway=O,a.BadRequest=x,a.Conflict=U,a.Created=J,a.DebugService=N,a.Forbidden=I,a.Found=D,a.NoContent=B,a.NotFound=k,a.NotImplemented=j,a.SchemaValidator=X,a.ServerError=S,a.Success=q,a.Unauthorized=C,a.UnprocessableEntity=w,a.Updated=P,a.decodeErrorMessageFromRequest=K,a.decodeRequestBody=V,a.errorHandler=Y,a.flushDebugLogs=l,a.formParse=v,a.getCaller=R,a.getScopedParams=Q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,11 @@
1
+ type Input = {
2
+ name: string;
3
+ body?: any;
4
+ cause?: any;
5
+ message?: string;
6
+ };
7
+ declare class BadResponse {
8
+ onDebug(input: Input): void;
9
+ }
10
+ export { BadResponse };
11
+ //# sourceMappingURL=_badResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_badResponse.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/_badResponse.ts"],"names":[],"mappings":"AAGA,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,cAAM,WAAW;IACf,OAAO,CAAC,KAAK,EAAE,KAAK;CAgBrB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,20 @@
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,9 +1,10 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  /**
2
3
  * Represents an HTTP error response with a status code of 502 (Bad Gateway).
3
4
  * This class is used to standardize the structure of a "Bad Gateway" error response,
4
5
  * including the response body, headers, status, and status text.
5
6
  */
6
- declare class BadGateway {
7
+ declare class BadGateway extends BadResponse {
7
8
  body: any;
8
9
  cause?: any;
9
10
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"badGateway.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badGateway.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,UAAU;IACd,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"badGateway.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badGateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,UAAW,SAAQ,WAAW;IAClC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 502 (Bad Gateway).
4
4
  * This class is used to standardize the structure of a "Bad Gateway" error response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class BadGateway {
7
+ class BadGateway extends BadResponse {
8
8
  body;
9
9
  cause;
10
10
  status = 502;
@@ -16,10 +16,16 @@ class BadGateway {
16
16
  * @param cause - Optional additional information about the cause of the error.
17
17
  */
18
18
  constructor(message, cause) {
19
+ super();
19
20
  this.body = { name: "BadGateway", message: message };
20
21
  this.statusText = message;
21
22
  this.cause = cause ? JSON.stringify(cause) : undefined;
22
- httpDebug("BadGateway", this.body, this.cause);
23
+ this.onDebug({
24
+ name: "BadGateway",
25
+ body: this.body,
26
+ cause: this.cause,
27
+ message: this.statusText,
28
+ });
23
29
  }
24
30
  /**
25
31
  * Converts the `BadGateway` instance into a `Response` object with a JSON body.
@@ -1,9 +1,10 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  /**
2
3
  * Represents an HTTP error response with a status code of 400 (Bad Request).
3
4
  * This class is used to standardize the structure of a "Bad Request" error response,
4
5
  * including the response body, headers, status, and status text.
5
6
  */
6
- declare class BadRequest {
7
+ declare class BadRequest extends BadResponse {
7
8
  body: any;
8
9
  cause?: any;
9
10
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"badRequest.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badRequest.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,UAAU;IACd,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"badRequest.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/badRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,UAAW,SAAQ,WAAW;IAClC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 400 (Bad Request).
4
4
  * This class is used to standardize the structure of a "Bad Request" error response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class BadRequest {
7
+ class BadRequest extends BadResponse {
8
8
  body;
9
9
  cause;
10
10
  status = 400;
@@ -16,10 +16,16 @@ class BadRequest {
16
16
  * @param cause - Optional additional information about the cause of the error.
17
17
  */
18
18
  constructor(message, cause) {
19
+ super();
19
20
  this.body = { name: "BadRequest", message: message };
20
21
  this.statusText = message;
21
22
  this.cause = cause ? JSON.stringify(cause) : undefined;
22
- httpDebug("BadRequest", this.body, this.cause);
23
+ this.onDebug({
24
+ name: "BadRequest",
25
+ body: this.body,
26
+ cause: this.cause,
27
+ message: this.statusText,
28
+ });
23
29
  }
24
30
  /**
25
31
  * Converts the `BadRequest` instance into a `Response` object with a JSON body.
@@ -1,9 +1,10 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  /**
2
3
  * Represents an HTTP error response with a status code of 409 (Conflict).
3
4
  * This class is used to standardize the structure of a "Conflict" error response,
4
5
  * including the response body, headers, status, and status text.
5
6
  */
6
- declare class Conflict {
7
+ declare class Conflict extends BadResponse {
7
8
  body: any;
8
9
  cause?: any;
9
10
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/conflict.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,QAAQ;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"conflict.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/conflict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,QAAS,SAAQ,WAAW;IAChC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 409 (Conflict).
4
4
  * This class is used to standardize the structure of a "Conflict" error response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class Conflict {
7
+ class Conflict extends BadResponse {
8
8
  body;
9
9
  cause;
10
10
  status = 409;
@@ -16,10 +16,16 @@ class Conflict {
16
16
  * @param cause - Optional additional information about the cause of the conflict.
17
17
  */
18
18
  constructor(message, cause) {
19
+ super();
19
20
  this.body = { name: "Conflict", message: message };
20
21
  this.statusText = message;
21
22
  this.cause = cause ? JSON.stringify(cause) : undefined;
22
- httpDebug("Conflict", this.body, this.cause);
23
+ this.onDebug({
24
+ name: "Conflict",
25
+ body: this.body,
26
+ cause: this.cause,
27
+ message: this.statusText,
28
+ });
23
29
  }
24
30
  /**
25
31
  * Converts the `Conflict` instance into a `Response` object with a JSON body.
@@ -1,9 +1,10 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  /**
2
3
  * Represents an HTTP error response with a status code of 403 (Forbidden).
3
4
  * This class is used to standardize the structure of a "Forbidden" error response,
4
5
  * including the response body, headers, status, and status text.
5
6
  */
6
- declare class Forbidden {
7
+ declare class Forbidden extends BadResponse {
7
8
  body: any;
8
9
  cause?: any;
9
10
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"forbidden.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/forbidden.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,SAAS;IACb,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"forbidden.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/forbidden.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,SAAU,SAAQ,WAAW;IACjC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 403 (Forbidden).
4
4
  * This class is used to standardize the structure of a "Forbidden" error response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class Forbidden {
7
+ class Forbidden extends BadResponse {
8
8
  body;
9
9
  cause;
10
10
  status = 403;
@@ -16,10 +16,16 @@ class Forbidden {
16
16
  * @param cause - Optional additional information about the cause of the error.
17
17
  */
18
18
  constructor(message, cause) {
19
+ super();
19
20
  this.body = { name: "Forbidden", message: message };
20
21
  this.statusText = message;
21
22
  this.cause = cause ? JSON.stringify(cause) : undefined;
22
- httpDebug("Forbidden", this.body, this.cause);
23
+ this.onDebug({
24
+ name: "Forbidden",
25
+ body: this.body,
26
+ cause: this.cause,
27
+ message: this.statusText,
28
+ });
23
29
  }
24
30
  /**
25
31
  * Converts the `Forbidden` instance into a `Response` object with a JSON body.
@@ -1,9 +1,10 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  /**
2
3
  * Represents an HTTP error response with a status code of 404 (Not Found).
3
4
  * This class is used to standardize the structure of a "Not Found" error response,
4
5
  * including the response body, headers, status, and status text.
5
6
  */
6
- declare class NotFound {
7
+ declare class NotFound extends BadResponse {
7
8
  body: any;
8
9
  cause?: any;
9
10
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"notFound.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notFound.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,QAAQ;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"notFound.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notFound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,QAAS,SAAQ,WAAW;IAChC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 404 (Not Found).
4
4
  * This class is used to standardize the structure of a "Not Found" error response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class NotFound {
7
+ class NotFound extends BadResponse {
8
8
  body;
9
9
  cause;
10
10
  status = 404;
@@ -16,10 +16,16 @@ class NotFound {
16
16
  * @param cause - Optional additional information about the cause of the error.
17
17
  */
18
18
  constructor(message, cause) {
19
+ super();
19
20
  this.body = { name: "NotFound", message: message };
20
21
  this.statusText = message;
21
22
  this.cause = cause ? JSON.stringify(cause) : undefined;
22
- httpDebug("NotFound", this.body, this.cause);
23
+ this.onDebug({
24
+ name: "NotFound",
25
+ body: this.body,
26
+ cause: this.cause,
27
+ message: this.statusText,
28
+ });
23
29
  }
24
30
  /**
25
31
  * Converts the `NotFound` instance into a `Response` object with a JSON body.
@@ -1,9 +1,10 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  /**
2
3
  * Represents an HTTP error response with a status code of 501 (Not Implemented).
3
4
  * This class is used to standardize the structure of a "Not Implemented" error response,
4
5
  * including the response body, headers, status, and status text.
5
6
  */
6
- declare class NotImplemented {
7
+ declare class NotImplemented extends BadResponse {
7
8
  body: any;
8
9
  cause?: any;
9
10
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"notImplemented.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notImplemented.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,cAAc;IAClB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"notImplemented.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/notImplemented.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,cAAe,SAAQ,WAAW;IACtC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 501 (Not Implemented).
4
4
  * This class is used to standardize the structure of a "Not Implemented" error response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class NotImplemented {
7
+ class NotImplemented extends BadResponse {
8
8
  body;
9
9
  cause;
10
10
  status = 501;
@@ -16,10 +16,16 @@ class NotImplemented {
16
16
  * @param cause - Optional additional information about the cause of the error.
17
17
  */
18
18
  constructor(message, cause) {
19
+ super();
19
20
  this.body = { name: "NotImplemented", message: message };
20
21
  this.statusText = message;
21
22
  this.cause = cause ? JSON.stringify(cause) : undefined;
22
- httpDebug("NotImplemented", this.body, this.cause);
23
+ this.onDebug({
24
+ name: "NotImplemented",
25
+ body: this.body,
26
+ cause: this.cause,
27
+ message: this.statusText,
28
+ });
23
29
  }
24
30
  /**
25
31
  * Converts the `NotImplemented` instance into a `Response` object with a JSON body.
@@ -1,9 +1,10 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  /**
2
3
  * Represents an HTTP error response with a status code of 500 (Internal Server Error).
3
4
  * This class is used to standardize the structure of a "Server Error" response,
4
5
  * including the response body, headers, status, and status text.
5
6
  */
6
- declare class ServerError {
7
+ declare class ServerError extends BadResponse {
7
8
  body: any;
8
9
  cause?: any;
9
10
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/serverError.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,WAAW;IACf,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"serverError.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/serverError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,WAAY,SAAQ,WAAW;IACnC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 500 (Internal Server Error).
4
4
  * This class is used to standardize the structure of a "Server Error" response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class ServerError {
7
+ class ServerError extends BadResponse {
8
8
  body;
9
9
  cause;
10
10
  status = 500;
@@ -16,10 +16,16 @@ class ServerError {
16
16
  * @param cause - Optional additional information about the cause of the error.
17
17
  */
18
18
  constructor(message, cause) {
19
+ super();
19
20
  this.body = { name: "ServerError", message: message };
20
21
  this.statusText = message;
21
22
  this.cause = cause ? JSON.stringify(cause) : undefined;
22
- httpDebug("ServerError", this.body, this.cause);
23
+ this.onDebug({
24
+ name: "ServerError",
25
+ body: this.body,
26
+ cause: this.cause,
27
+ message: this.statusText,
28
+ });
23
29
  }
24
30
  /**
25
31
  * Converts the `ServerError` instance into a `Response` object with a JSON body.
@@ -1,9 +1,10 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  /**
2
3
  * Represents an HTTP error response with a status code of 401 (Unauthorized).
3
4
  * This class is used to standardize the structure of an "Unauthorized" error response,
4
5
  * including the response body, headers, status, and status text.
5
6
  */
6
- declare class Unauthorized {
7
+ declare class Unauthorized extends BadResponse {
7
8
  body: any;
8
9
  cause?: any;
9
10
  status: number;
@@ -1 +1 @@
1
- {"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unauthorized.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,cAAM,YAAY;IAChB,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAOxC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"unauthorized.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unauthorized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;GAIG;AAEH,cAAM,YAAa,SAAQ,WAAW;IACpC,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;gBAES,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG;IAexC;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 401 (Unauthorized).
4
4
  * This class is used to standardize the structure of an "Unauthorized" error response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class Unauthorized {
7
+ class Unauthorized extends BadResponse {
8
8
  body;
9
9
  cause;
10
10
  status = 401;
@@ -16,10 +16,16 @@ class Unauthorized {
16
16
  * @param cause - Optional additional information about the cause of the error.
17
17
  */
18
18
  constructor(message, cause) {
19
+ super();
19
20
  this.body = { name: "Unauthorized", message: message };
20
21
  this.statusText = message;
21
22
  this.cause = cause ? JSON.stringify(cause) : undefined;
22
- httpDebug("Unauthorized", this.body, this.cause);
23
+ this.onDebug({
24
+ name: "Unauthorized",
25
+ body: this.body,
26
+ cause: this.cause,
27
+ message: this.statusText,
28
+ });
23
29
  }
24
30
  /**
25
31
  * Converts the `Unauthorized` instance into a `Response` object with a JSON body.
@@ -1,3 +1,4 @@
1
+ import { BadResponse } from "./_badResponse";
1
2
  type UnprocessableEntityProps = {
2
3
  data?: any;
3
4
  fieldErrors?: Record<string, string>;
@@ -9,7 +10,7 @@ type UnprocessableEntityProps = {
9
10
  * This class is used to standardize the structure of an "Unprocessable Entity" error response,
10
11
  * including the response body, headers, status, and status text.
11
12
  */
12
- declare class UnprocessableEntity {
13
+ declare class UnprocessableEntity extends BadResponse {
13
14
  body: any;
14
15
  status: number;
15
16
  statusText: string;
@@ -23,7 +24,7 @@ declare class UnprocessableEntity {
23
24
  * - `message`: A descriptive message explaining the error.
24
25
  * @param enableDebug - A boolean indicating whether to enable debug logging for this error.
25
26
  */
26
- constructor(props: UnprocessableEntityProps, enableDebug?: boolean);
27
+ constructor(props: UnprocessableEntityProps);
27
28
  /**
28
29
  * Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
29
30
  * This method ensures the response has the appropriate headers, status, and status text.
@@ -1 +1 @@
1
- {"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAEA,KAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AAEH,cAAM,mBAAmB;IACvB,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;OASG;gBAES,KAAK,EAAE,wBAAwB,EAAE,WAAW,UAAQ;IAahE;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"unprocessableEntity.d.ts","sourceRoot":"","sources":["../../../src/http/badResponses/unprocessableEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,KAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AAEH,cAAM,mBAAoB,SAAQ,WAAW;IAC3C,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAO;IACrB,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;OASG;gBAES,KAAK,EAAE,wBAAwB;IAmB3C;;;;;OAKG;IAEH,UAAU,IAAI,QAAQ;IAUtB;;;;;OAKG;IAEH,MAAM,IAAI,QAAQ;CAQnB;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -1,10 +1,10 @@
1
- import { httpDebug } from "../../services/httpDebug";
1
+ import { BadResponse } from "./_badResponse";
2
2
  /**
3
3
  * Represents an HTTP error response with a status code of 422 (Unprocessable Entity).
4
4
  * This class is used to standardize the structure of an "Unprocessable Entity" error response,
5
5
  * including the response body, headers, status, and status text.
6
6
  */
7
- class UnprocessableEntity {
7
+ class UnprocessableEntity extends BadResponse {
8
8
  body;
9
9
  status = 422;
10
10
  statusText;
@@ -18,7 +18,8 @@ class UnprocessableEntity {
18
18
  * - `message`: A descriptive message explaining the error.
19
19
  * @param enableDebug - A boolean indicating whether to enable debug logging for this error.
20
20
  */
21
- constructor(props, enableDebug = false) {
21
+ constructor(props) {
22
+ super();
22
23
  this.statusText = props.message || "Unprocessable Entity";
23
24
  this.body = {
24
25
  name: "UnprocessableEntity",
@@ -27,7 +28,11 @@ class UnprocessableEntity {
27
28
  fieldErrors: props.fieldErrors,
28
29
  fields: props.fields,
29
30
  };
30
- enableDebug && httpDebug("UnprocessableEntity", this.body);
31
+ this.onDebug({
32
+ name: "UnprocessableEntity",
33
+ cause: props.fieldErrors,
34
+ message: props.message,
35
+ });
31
36
  }
32
37
  /**
33
38
  * Converts the `UnprocessableEntity` instance into a `Response` object with a JSON body.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Base class for handling bad HTTP responses with debugging capabilities.
3
+ * Provides logging functionality to track response errors and their context.
4
+ */
5
+ declare class SuccessResponse {
6
+ /**
7
+ * Logs debug information for success responses including caller context and response details.
8
+ *
9
+ * @param name - The name/type of the success response being logged
10
+ * @param body - The response body or success data to be logged
11
+ * @param cause - Optional additional cause information for the error
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const SuccessResponse = new SuccessResponse();
16
+ * SuccessResponse.onDebug("ValidationError", { field: "email", message: "Invalid format" });
17
+ * ```
18
+ */
19
+ onDebug(name: string, body: any, cause?: any): void;
20
+ }
21
+ export { SuccessResponse };
22
+ //# sourceMappingURL=_successResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_successResponse.d.ts","sourceRoot":"","sources":["../../../src/http/successResponses/_successResponse.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,cAAM,eAAe;IACnB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG;CAgB7C;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,37 @@
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 };