@arkyn/server 3.0.1-beta.6 → 3.0.1-beta.61

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 (72) 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 +6 -8
  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 +3 -6
  8. package/dist/bundle.js +1098 -0
  9. package/dist/bundle.umd.cjs +8 -0
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +3 -4
  13. package/dist/mapper/arkynLogRequestMapper.js +2 -2
  14. package/dist/{config/apiInstance.d.ts → services/apiService.d.ts} +25 -21
  15. package/dist/services/apiService.d.ts.map +1 -0
  16. package/dist/{config/apiInstance.js → services/apiService.js} +40 -18
  17. package/dist/{config/arkynLogInstance.d.ts → services/arkynLogService.d.ts} +5 -5
  18. package/dist/services/arkynLogService.d.ts.map +1 -0
  19. package/dist/{config/arkynLogInstance.js → services/arkynLogService.js} +4 -5
  20. package/dist/services/formParse.d.ts +3 -3
  21. package/dist/services/formParse.d.ts.map +1 -1
  22. package/dist/services/formParse.js +8 -5
  23. package/dist/services/getCaller.d.ts.map +1 -1
  24. package/dist/services/getCaller.js +9 -14
  25. package/dist/services/httpDebug.d.ts +40 -1
  26. package/dist/services/httpDebug.d.ts.map +1 -1
  27. package/dist/services/httpDebug.js +42 -1
  28. package/dist/services/measureRouteExecution.d.ts +3 -0
  29. package/dist/services/measureRouteExecution.d.ts.map +1 -0
  30. package/dist/services/measureRouteExecution.js +24 -0
  31. package/dist/services/schemaValidator.d.ts +3 -3
  32. package/dist/services/schemaValidator.d.ts.map +1 -1
  33. package/dist/services/schemaValidator.js +1 -1
  34. package/package.json +33 -18
  35. package/dist/config/apiInstance.d.ts.map +0 -1
  36. package/dist/config/arkynLogInstance.d.ts.map +0 -1
  37. package/src/api/arkynLogRequest.ts +0 -116
  38. package/src/api/deleteRequest.ts +0 -22
  39. package/src/api/getRequest.ts +0 -20
  40. package/src/api/makeRequest.ts +0 -122
  41. package/src/api/patchRequest.ts +0 -22
  42. package/src/api/postRequest.ts +0 -22
  43. package/src/api/putRequest.ts +0 -22
  44. package/src/config/apiInstance.ts +0 -148
  45. package/src/config/arkynLogInstance.ts +0 -75
  46. package/src/http/badResponses/badGateway.ts +0 -63
  47. package/src/http/badResponses/badRequest.ts +0 -63
  48. package/src/http/badResponses/conflict.ts +0 -63
  49. package/src/http/badResponses/forbidden.ts +0 -63
  50. package/src/http/badResponses/notFound.ts +0 -63
  51. package/src/http/badResponses/notImplemented.ts +0 -63
  52. package/src/http/badResponses/serverError.ts +0 -63
  53. package/src/http/badResponses/unauthorized.ts +0 -63
  54. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  55. package/src/http/successResponses/created.ts +0 -64
  56. package/src/http/successResponses/found.ts +0 -67
  57. package/src/http/successResponses/noContent.ts +0 -42
  58. package/src/http/successResponses/success.ts +0 -64
  59. package/src/http/successResponses/updated.ts +0 -64
  60. package/src/index.ts +0 -31
  61. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  62. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  63. package/src/services/decodeRequestBody.ts +0 -43
  64. package/src/services/errorHandler.ts +0 -99
  65. package/src/services/formParse.ts +0 -83
  66. package/src/services/getCaller.ts +0 -82
  67. package/src/services/getScopedParams.ts +0 -43
  68. package/src/services/httpDebug.ts +0 -61
  69. package/src/services/schemaValidator.ts +0 -66
  70. package/src/types/ApiResponseDTO.ts +0 -19
  71. package/tsconfig.json +0 -21
  72. package/vitest.config.ts +0 -5
@@ -0,0 +1,8 @@
1
+ (function(a,y){typeof exports=="object"&&typeof module<"u"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(a=typeof globalThis<"u"?globalThis:a||self,y(a["@arkyn/server"]={}))})(this,function(a){"use strict";var Z=Object.defineProperty;var ss=(a,y,p)=>y in a?Z(a,y,{enumerable:!0,configurable:!0,writable:!0,value:p}):a[y]=p;var o=(a,y,p)=>ss(a,typeof y!="symbol"?y+"":y,p);const y={};function p(){const t=process.cwd(),n=(new Error().stack||"").split(`
2
+ `).map(c=>c.trim()),r=x.ignoreFile;let u=2;for(;u<n.length&&(n[u].includes("node:internal")||n[u].includes("/node_modules/"));)u++;if(r)for(;u<n.length&&n[u].includes(r);)u++;const l=n[u]||"";let h="Unknown function",i="Unknown caller";const f=l.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(f)h=f[1],i=f[2];else{const c=l.match(/at\s+(.+)/);if(c){i=c[1];const T=i.match(/at\s+([^(\s]+)\s+/);T&&T[1]!=="new"&&(h=T[1])}}i.includes("(")&&(i=i.substring(i.indexOf("(")+1,i.lastIndexOf(")"))),i=i.split(":").slice(0,-2).join(":");try{i=y.relative(t,i)}catch{}return{functionName:h,callerInfo:i}}class x{static setIgnoreFile(s){this.ignoreFile=s}}o(x,"ignoreFile");function d(t,s,e){var r;if(process.env.NODE_ENV==="development"||((r=process.env)==null?void 0:r.SHOW_ERRORS_IN_CONSOLE)==="true"){const h="\x1B[36m[ARKYN-DEBUG]\x1B[0m",{callerInfo:i,functionName:f}=p();let c=`${h} ${t} initialized
3
+ `;c+=`${h} Caller Function: ${f}
4
+ `,c+=`${h} Caller Location: ${i}
5
+ `,c+=`${h} Body: ${JSON.stringify(s,null,2)}
6
+ `,e&&(c+=`${h} Cause: ${JSON.stringify(e,null,2)}
7
+ `),console.log(c)}}class N{constructor(s,e){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,d("BadGateway",this.body,this.cause)}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 m{constructor(s,e){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,d("BadRequest",this.body,this.cause)}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{constructor(s,e){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,d("Conflict",this.body,this.cause)}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{constructor(s,e){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,d("Forbidden",this.body,this.cause)}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{constructor(s,e){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,d("NotFound",this.body,this.cause)}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{constructor(s,e){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,d("NotImplemented",this.body,this.cause)}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{constructor(s,e){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,d("ServerError",this.body,this.cause)}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{constructor(s,e){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,d("Unauthorized",this.body,this.cause)}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{constructor(s,e=!1){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},e&&d("UnprocessableEntity",this.body)}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{constructor(s,e){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"}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 J{constructor(s,e){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"}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 C{constructor(s){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"}toResponse(){const s={headers:this.headers,status:this.status,statusText:this.statusText};return new Response(null,s)}}class q{constructor(s,e){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"}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{constructor(s,e){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"}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 ${static mapHeaders(s){return s instanceof Headers?Object.fromEntries(s.entries()):typeof s=="object"?Object.entries(s).reduce((e,[n,r])=>(typeof r=="string"?e[n]=r:Array.isArray(r)?e[n]=r.join(", "):e[n]=JSON.stringify(r),e),{}):{}}static mapQueryParams(s){const e={};return s.forEach((n,r)=>{e[r]=n}),e}static handle(s){return{rawUrl:s.url,status:s.status,method:s.method,token:null,elapsedTime:s.elapsedTime,requestHeaders:this.mapHeaders(s.requestHeaders),requestBody:s.requestBody||null,queryParams:this.mapQueryParams(s.queryParams),responseHeaders:this.mapHeaders(s.responseHeaders),responseBody:s.responseBody||null}}}class S{static setArkynConfig(s){if(this.arkynConfig)return;let n=s.arkynLogBaseApiUrl||"https://logs-arkyn-flow-logs.vw6wo7.easypanel.host";n=n+"/http-traffic-records/:trafficSourceId",this.arkynConfig={arkynTrafficSourceId:s.arkynTrafficSourceId,arkynUserToken:s.arkynUserToken,arkynApiUrl:n}}static getArkynConfig(){return this.arkynConfig}static resetArkynConfig(){this.arkynConfig=void 0}}o(S,"arkynConfig");async function v(t){const s=S.getArkynConfig();if(!s)return;const{arkynUserToken:e,arkynApiUrl:n}=s,{elapsedTime:r,method:u,queryParams:l,requestBody:h,requestHeaders:i,responseBody:f,responseHeaders:c,status:T,token:es,rawUrl:Y}=t;try{const b=new URL(Y);let H="HTTPS";b.protocol==="http:"&&(H="HTTP");const X=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:T,protocol:H,method:u,trafficUserId:null,elapsedTime:r,requestHeaders:i,requestBody:h,queryParams:l,responseHeaders:c,responseBody:f});await fetch(n.replace(":trafficSourceId",s.arkynTrafficSourceId),{method:"POST",body:X,headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`}})}catch(b){d("arkyn log error","Error sending request",b)}}async function g(t,s,e={},n){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(),l={...e,"Content-Type":"application/json"},h=await fetch(s,{method:t,headers:l,body:n?JSON.stringify(n):void 0}),i=performance.now()-u,f=h.status;let c=null;try{c=await h.json()}catch{c=null}const T=$.handle({elapsedTime:i,method:t,queryParams:new URL(s).searchParams,requestHeaders:l,requestBody:n,responseBody:c,responseHeaders:h.headers,status:f,url:s});return v(T),h.ok?{success:!0,status:f,message:(c==null?void 0:c.message)||r[t],response:c,cause:null}:{success:!1,status:f,message:(c==null?void 0:c.message)||h.statusText||"Request failed",response:c,cause:null}}catch(u){return d("Network error or request failed",null,u),{success:!1,status:0,message:"Network error or request failed",response:null,cause:u instanceof Error?u.message:String(u)}}}async function L(t,s={},e){return g("DELETE",t,s,e)}async function A(t,s={}){return g("GET",t,s)}async function D(t,s={},e){return g("PATCH",t,s,e)}async function F(t,s={},e){return g("POST",t,s,e)}async function M(t,s={},e){return g("PUT",t,s,e)}class z{constructor(s){o(this,"baseUrl");o(this,"baseHeaders");o(this,"baseToken");o(this,"enableDebug");this.baseUrl=s.baseUrl,this.baseHeaders=s.baseHeaders||void 0,this.baseToken=s.baseToken||void 0,this.enableDebug=s.enableDebug||!1}onDebug(s,e,n){if(this.enableDebug){const l="\x1B[33m[ARKYN-API-DEBUG]\x1B[0m";console.log(`${l} Base URL: ${this.baseUrl}`),console.log(`${l} Full URL: ${s}`),console.log(`${l} Method: ${e}`),n[0]&&console.log(`${l} Headers: `,n[0]),n[1]&&console.log(`${l} Body: `,n[1])}}generateURL(s){return this.baseUrl+s}generateHeaders(s,e){let n={};return this.baseToken&&(n={Authorization:`Bearer ${this.baseToken}`}),this.baseHeaders&&(n={...n,...this.baseHeaders}),s&&(n={...n,...s}),e&&(n={...n,Authorization:`Bearer ${e}`}),n}async get(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token);return this.onDebug(n,"get",[r]),await A(n,r)}async post(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return this.onDebug(n,"post",[r,u]),await F(n,r,u)}async put(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return this.onDebug(n,"put",[r,u]),await M(n,r,u)}async patch(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return this.onDebug(n,"patch",[r,u]),await D(n,r,u)}async delete(s,e){const n=this.generateURL(s),r=this.generateHeaders((e==null?void 0:e.headers)||{},e==null?void 0:e.token),u=e==null?void 0:e.body;return this.onDebug(n,"delete",[r,u]),await L(n,r,u)}}function G(t,s){var e,n,r;return t!=null&&t.message&&typeof(t==null?void 0:t.message)=="string"?t==null?void 0:t.message:t!=null&&t.error&&typeof(t==null?void 0:t.error)=="string"?t==null?void 0:t.error:(e=t==null?void 0:t.error)!=null&&e.message&&typeof((n=t==null?void 0:t.error)==null?void 0:n.message)=="string"?(r=t==null?void 0:t.error)==null?void 0:r.message:s!=null&&s.statusText&&typeof(s==null?void 0:s.statusText)=="string"?s==null?void 0:s.statusText:"Missing error message"}const V=async t=>{let s;const e=await t.arrayBuffer(),n=new TextDecoder().decode(e);try{s=JSON.parse(n)}catch{try{if(n.includes("=")){const u=new URLSearchParams(n);s=Object.fromEntries(u.entries())}else throw new m("Invalid URLSearchParams format")}catch{throw new m("Failed to extract data from request")}}return s};function _(t){switch(!0){case t instanceof Response:return t;case t instanceof J:return t.toResponse();case t instanceof E:return t.toResponse();case t instanceof B:return t.toResponse();case t instanceof q:return t.toResponse();case t instanceof C:return t.toResponse()}switch(!0){case t instanceof N:return t.toResponse();case t instanceof m:return t.toResponse();case t instanceof U:return t.toResponse();case t instanceof k:return t.toResponse();case t instanceof I:return t.toResponse();case t instanceof j:return t.toResponse();case t instanceof R:return t.toResponse();case t instanceof O:return t.toResponse();case t instanceof w:return t.toResponse()}return new R("Server error",t).toResponse()}function P([t,s]){const e=s.safeParse(t);if(e.success===!1){const n=Object.fromEntries(e.error.issues.map(r=>(console.log(r),[r.path.join("."),r.message])));return{success:e.success,fieldErrors:n,fields:t}}else return{success:e.success,data:e.data}}const K=(t,s="")=>{const e=new URL(t.url);if(s==="")return e.searchParams;const n=Array.from(e.searchParams.entries()).filter(([r])=>r.startsWith(`${s}:`)).map(([r,u])=>[r.replace(`${s}:`,""),u]);return new URLSearchParams(n)};function Q(t){const s="Error validating:",e=t.issues.map(({path:n,message:r})=>`-> ${n.join(".")}: ${r}`);return[s,...e].join(`
8
+ `)}class W{constructor(s){o(this,"functionName");o(this,"callerInfo");this.schema=s;const{callerInfo:e,functionName:n}=p();this.callerInfo=e,this.functionName=n}isValid(s){return this.schema.safeParse(s).success}safeValidate(s){return this.schema.safeParse(s)}validate(s){try{return this.schema.parse(s)}catch(e){throw new R(Q(e))}}formValidate(s,e){const n=P([s,this.schema]);if(!n.success){d("UnprocessableEntity",n);const r=Object.keys(n.fieldErrors)[0];throw new w({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:e},!1)}return n.data}}a.ApiService=z,a.ArkynLogService=S,a.BadGateway=N,a.BadRequest=m,a.Conflict=U,a.Created=E,a.Forbidden=k,a.Found=J,a.HttpDebugService=x,a.NoContent=C,a.NotFound=I,a.NotImplemented=j,a.SchemaValidator=W,a.ServerError=R,a.Success=q,a.Unauthorized=O,a.UnprocessableEntity=w,a.Updated=B,a.decodeErrorMessageFromRequest=G,a.decodeRequestBody=V,a.errorHandler=_,a.formParse=P,a.getCaller=p,a.getScopedParams=K,a.httpDebug=d,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/dist/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export { ApiInstance } from "./config/apiInstance";
2
- export { ArkynLogInstance } from "./config/arkynLogInstance";
3
1
  export { BadGateway } from "./http/badResponses/badGateway";
4
2
  export { BadRequest } from "./http/badResponses/badRequest";
5
3
  export { Conflict } from "./http/badResponses/conflict";
@@ -14,12 +12,14 @@ export { Found } from "./http/successResponses/found";
14
12
  export { NoContent } from "./http/successResponses/noContent";
15
13
  export { Success } from "./http/successResponses/success";
16
14
  export { Updated } from "./http/successResponses/updated";
15
+ export { ApiService } from "./services/apiService";
16
+ export { ArkynLogService } from "./services/arkynLogService";
17
17
  export { decodeErrorMessageFromRequest } from "./services/decodeErrorMessageFromRequest";
18
18
  export { decodeRequestBody } from "./services/decodeRequestBody";
19
19
  export { errorHandler } from "./services/errorHandler";
20
20
  export { formParse } from "./services/formParse";
21
21
  export { getCaller } from "./services/getCaller";
22
22
  export { getScopedParams } from "./services/getScopedParams";
23
- export { httpDebug } from "./services/httpDebug";
23
+ export { httpDebug, HttpDebugService } from "./services/httpDebug";
24
24
  export { SchemaValidator } from "./services/schemaValidator";
25
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAG9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAG9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- // config
2
- export { ApiInstance } from "./config/apiInstance";
3
- export { ArkynLogInstance } from "./config/arkynLogInstance";
4
1
  // http bad responses
5
2
  export { BadGateway } from "./http/badResponses/badGateway";
6
3
  export { BadRequest } from "./http/badResponses/badRequest";
@@ -18,11 +15,13 @@ export { NoContent } from "./http/successResponses/noContent";
18
15
  export { Success } from "./http/successResponses/success";
19
16
  export { Updated } from "./http/successResponses/updated";
20
17
  // services
18
+ export { ApiService } from "./services/apiService";
19
+ export { ArkynLogService } from "./services/arkynLogService";
21
20
  export { decodeErrorMessageFromRequest } from "./services/decodeErrorMessageFromRequest";
22
21
  export { decodeRequestBody } from "./services/decodeRequestBody";
23
22
  export { errorHandler } from "./services/errorHandler";
24
23
  export { formParse } from "./services/formParse";
25
24
  export { getCaller } from "./services/getCaller";
26
25
  export { getScopedParams } from "./services/getScopedParams";
27
- export { httpDebug } from "./services/httpDebug";
26
+ export { httpDebug, HttpDebugService } from "./services/httpDebug";
28
27
  export { SchemaValidator } from "./services/schemaValidator";
@@ -34,10 +34,10 @@ class ArkynLogRequestMapper {
34
34
  token: null,
35
35
  elapsedTime: props.elapsedTime,
36
36
  requestHeaders: this.mapHeaders(props.requestHeaders),
37
- requestBody: props.requestBody,
37
+ requestBody: props.requestBody || null,
38
38
  queryParams: this.mapQueryParams(props.queryParams),
39
39
  responseHeaders: this.mapHeaders(props.responseHeaders),
40
- responseBody: props.responseBody,
40
+ responseBody: props.responseBody || null,
41
41
  };
42
42
  }
43
43
  }
@@ -1,7 +1,8 @@
1
- type ApiInstanceContructorProps = {
1
+ type ApiServiceConstructorProps = {
2
2
  baseUrl: string;
3
3
  baseHeaders?: HeadersInit;
4
4
  baseToken?: string | null;
5
+ enableDebug?: boolean;
5
6
  };
6
7
  type ApiRequestDataWithoutBodyProps = {
7
8
  headers?: HeadersInit;
@@ -15,23 +16,26 @@ type ApiRequestDataWithBodyProps = {
15
16
  /**
16
17
  * Class representing an API instance to handle HTTP requests with base configurations.
17
18
  */
18
- declare class ApiInstance {
19
+ declare class ApiService {
19
20
  private baseUrl;
20
21
  private baseHeaders?;
21
22
  private baseToken?;
23
+ private enableDebug?;
22
24
  /**
23
- * Creates an instance of ApiInstance.
25
+ * Creates an instance of ApiService.
24
26
  * @param props - The configuration properties for the API instance.
25
27
  * @param props.baseUrl - The base URL for the API.
26
28
  * @param props.baseHeaders - Optional base headers to include in all requests.
27
29
  * @param props.baseToken - Optional base token for authorization.
30
+ * @param props.enableDebug - Optional flag to enable debug logging for requests.
28
31
  */
29
- constructor(props: ApiInstanceContructorProps);
32
+ constructor(props: ApiServiceConstructorProps);
30
33
  /**
31
34
  * Generates the full URL by appending the route to the base URL.
32
35
  * @param route - The route to append to the base URL.
33
36
  * @returns The full URL as a string.
34
37
  */
38
+ private onDebug;
35
39
  private generateURL;
36
40
  /**
37
41
  * Generates the headers for a request by merging base headers, provided headers, and tokens.
@@ -41,40 +45,40 @@ declare class ApiInstance {
41
45
  */
42
46
  private generateHeaders;
43
47
  /**
44
- * Sends a GET request to the specified route.
45
- * @param route - The API route to send the GET request to.
48
+ * Sends a get request to the specified route.
49
+ * @param route - The API route to send the get request to.
46
50
  * @param data - The request data, including optional headers and token.
47
51
  * @returns The API response data.
48
52
  */
49
- GET(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
53
+ get(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
50
54
  /**
51
- * Sends a POST request to the specified route.
52
- * @param route - The API route to send the POST request to.
55
+ * Sends a post request to the specified route.
56
+ * @param route - The API route to send the post request to.
53
57
  * @param data - The request data, including body, optional headers, and token.
54
58
  * @returns The API response data.
55
59
  */
56
- POST(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
60
+ post(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
57
61
  /**
58
- * Sends a PUT request to the specified route.
59
- * @param route - The API route to send the PUT request to.
62
+ * Sends a put request to the specified route.
63
+ * @param route - The API route to send the put request to.
60
64
  * @param data - The request data, including body, optional headers, and token.
61
65
  * @returns The API response data.
62
66
  */
63
- PUT(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
67
+ put(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
64
68
  /**
65
- * Sends a PATCH request to the specified route.
66
- * @param route - The API route to send the PATCH request to.
69
+ * Sends a patch request to the specified route.
70
+ * @param route - The API route to send the patch request to.
67
71
  * @param data - The request data, including body, optional headers, and token.
68
72
  * @returns The API response data.
69
73
  */
70
- PATCH(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
74
+ patch(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
71
75
  /**
72
- * Sends a DELETE request to the specified route.
73
- * @param route - The API route to send the DELETE request to.
76
+ * Sends a delete request to the specified route.
77
+ * @param route - The API route to send the delete request to.
74
78
  * @param data - The request data, including body, optional headers, and token.
75
79
  * @returns The API response data.
76
80
  */
77
- DELETE(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
81
+ delete(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
78
82
  }
79
- export { ApiInstance };
80
- //# sourceMappingURL=apiInstance.d.ts.map
83
+ export { ApiService };
84
+ //# sourceMappingURL=apiService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiService.d.ts","sourceRoot":"","sources":["../../src/services/apiService.ts"],"names":[],"mappings":"AAMA,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AAEH,cAAM,UAAU;IACd,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAU;IAE9B;;;;;;;OAOG;gBAES,KAAK,EAAE,0BAA0B;IAO7C;;;;OAIG;IAEH,OAAO,CAAC,OAAO;IAcf,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IAEH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAQ9D;;;;;OAKG;IAEG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS5D;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS3D;;;;;OAKG;IAEG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAS7D;;;;;OAKG;IAEG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAQ/D;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -6,27 +6,44 @@ import { putRequest } from "../api/putRequest";
6
6
  /**
7
7
  * Class representing an API instance to handle HTTP requests with base configurations.
8
8
  */
9
- class ApiInstance {
9
+ class ApiService {
10
10
  baseUrl;
11
11
  baseHeaders;
12
12
  baseToken;
13
+ enableDebug;
13
14
  /**
14
- * Creates an instance of ApiInstance.
15
+ * Creates an instance of ApiService.
15
16
  * @param props - The configuration properties for the API instance.
16
17
  * @param props.baseUrl - The base URL for the API.
17
18
  * @param props.baseHeaders - Optional base headers to include in all requests.
18
19
  * @param props.baseToken - Optional base token for authorization.
20
+ * @param props.enableDebug - Optional flag to enable debug logging for requests.
19
21
  */
20
22
  constructor(props) {
21
23
  this.baseUrl = props.baseUrl;
22
24
  this.baseHeaders = props.baseHeaders || undefined;
23
25
  this.baseToken = props.baseToken || undefined;
26
+ this.enableDebug = props.enableDebug || false;
24
27
  }
25
28
  /**
26
29
  * Generates the full URL by appending the route to the base URL.
27
30
  * @param route - The route to append to the base URL.
28
31
  * @returns The full URL as a string.
29
32
  */
33
+ onDebug(fullRoute, method, data) {
34
+ if (this.enableDebug) {
35
+ const reset = "\x1b[0m";
36
+ const yellow = "\x1b[33m";
37
+ const debugName = `${yellow}[ARKYN-API-DEBUG]${reset}`;
38
+ console.log(`${debugName} Base URL: ${this.baseUrl}`);
39
+ console.log(`${debugName} Full URL: ${fullRoute}`);
40
+ console.log(`${debugName} Method: ${method}`);
41
+ if (data[0])
42
+ console.log(`${debugName} Headers: `, data[0]);
43
+ if (data[1])
44
+ console.log(`${debugName} Body: `, data[1]);
45
+ }
46
+ }
30
47
  generateURL(route) {
31
48
  return this.baseUrl + route;
32
49
  }
@@ -49,63 +66,68 @@ class ApiInstance {
49
66
  return headers;
50
67
  }
51
68
  /**
52
- * Sends a GET request to the specified route.
53
- * @param route - The API route to send the GET request to.
69
+ * Sends a get request to the specified route.
70
+ * @param route - The API route to send the get request to.
54
71
  * @param data - The request data, including optional headers and token.
55
72
  * @returns The API response data.
56
73
  */
57
- async GET(route, data) {
74
+ async get(route, data) {
58
75
  const url = this.generateURL(route);
59
76
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
77
+ this.onDebug(url, "get", [headers]);
60
78
  return await getRequest(url, headers);
61
79
  }
62
80
  /**
63
- * Sends a POST request to the specified route.
64
- * @param route - The API route to send the POST request to.
81
+ * Sends a post request to the specified route.
82
+ * @param route - The API route to send the post request to.
65
83
  * @param data - The request data, including body, optional headers, and token.
66
84
  * @returns The API response data.
67
85
  */
68
- async POST(route, data) {
86
+ async post(route, data) {
69
87
  const url = this.generateURL(route);
70
88
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
71
89
  const body = data?.body;
90
+ this.onDebug(url, "post", [headers, body]);
72
91
  return await postRequest(url, headers, body);
73
92
  }
74
93
  /**
75
- * Sends a PUT request to the specified route.
76
- * @param route - The API route to send the PUT request to.
94
+ * Sends a put request to the specified route.
95
+ * @param route - The API route to send the put request to.
77
96
  * @param data - The request data, including body, optional headers, and token.
78
97
  * @returns The API response data.
79
98
  */
80
- async PUT(route, data) {
99
+ async put(route, data) {
81
100
  const url = this.generateURL(route);
82
101
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
83
102
  const body = data?.body;
103
+ this.onDebug(url, "put", [headers, body]);
84
104
  return await putRequest(url, headers, body);
85
105
  }
86
106
  /**
87
- * Sends a PATCH request to the specified route.
88
- * @param route - The API route to send the PATCH request to.
107
+ * Sends a patch request to the specified route.
108
+ * @param route - The API route to send the patch request to.
89
109
  * @param data - The request data, including body, optional headers, and token.
90
110
  * @returns The API response data.
91
111
  */
92
- async PATCH(route, data) {
112
+ async patch(route, data) {
93
113
  const url = this.generateURL(route);
94
114
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
95
115
  const body = data?.body;
116
+ this.onDebug(url, "patch", [headers, body]);
96
117
  return await patchRequest(url, headers, body);
97
118
  }
98
119
  /**
99
- * Sends a DELETE request to the specified route.
100
- * @param route - The API route to send the DELETE request to.
120
+ * Sends a delete request to the specified route.
121
+ * @param route - The API route to send the delete request to.
101
122
  * @param data - The request data, including body, optional headers, and token.
102
123
  * @returns The API response data.
103
124
  */
104
- async DELETE(route, data) {
125
+ async delete(route, data) {
105
126
  const url = this.generateURL(route);
106
127
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
107
128
  const body = data?.body;
129
+ this.onDebug(url, "delete", [headers, body]);
108
130
  return await deleteRequest(url, headers, body);
109
131
  }
110
132
  }
111
- export { ApiInstance };
133
+ export { ApiService };
@@ -9,11 +9,11 @@ type SetArkynConfigProps = {
9
9
  arkynLogBaseApiUrl?: string;
10
10
  };
11
11
  /**
12
- * The `ArkynLogInstance` class manages the configuration for the arkyn flow.
12
+ * The `ArkynLogService` class manages the configuration for the arkyn flow.
13
13
  * It allows you to set and retrieve the arkyn configuration, including the traffic source ID,
14
14
  * user token, and API URL.
15
15
  */
16
- declare class ArkynLogInstance {
16
+ declare class ArkynLogService {
17
17
  private static arkynConfig?;
18
18
  /**
19
19
  * Sets the configuration for the arkyn. This method initializes the arkyn configuration
@@ -28,7 +28,7 @@ declare class ArkynLogInstance {
28
28
  */
29
29
  static setArkynConfig(arkynConfig: SetArkynConfigProps): void;
30
30
  /**
31
- * Retrieves the current arkyn configuration for the ArkynLogInstance.
31
+ * Retrieves the current arkyn configuration for the ArkynLogService.
32
32
  *
33
33
  * @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
34
34
  * or `undefined` if no configuration has been initialized.
@@ -40,5 +40,5 @@ declare class ArkynLogInstance {
40
40
  */
41
41
  static resetArkynConfig(): void;
42
42
  }
43
- export { ArkynLogInstance };
44
- //# sourceMappingURL=arkynLogInstance.d.ts.map
43
+ export { ArkynLogService };
44
+ //# sourceMappingURL=arkynLogService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arkynLogService.d.ts","sourceRoot":"","sources":["../../src/services/arkynLogService.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;;GAIG;AAEH,cAAM,eAAe;IACnB,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAmB;IAE9C;;;;;;;;;;OAUG;IAEH,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,mBAAmB;IAgBtD;;;;;OAKG;IACH,MAAM,CAAC,cAAc,IAAI,gBAAgB,GAAG,SAAS;IAIrD;;;OAGG;IAEH,MAAM,CAAC,gBAAgB;CAGxB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,9 +1,9 @@
1
1
  /**
2
- * The `ArkynLogInstance` class manages the configuration for the arkyn flow.
2
+ * The `ArkynLogService` class manages the configuration for the arkyn flow.
3
3
  * It allows you to set and retrieve the arkyn configuration, including the traffic source ID,
4
4
  * user token, and API URL.
5
5
  */
6
- class ArkynLogInstance {
6
+ class ArkynLogService {
7
7
  static arkynConfig;
8
8
  /**
9
9
  * Sets the configuration for the arkyn. This method initializes the arkyn configuration
@@ -23,7 +23,6 @@ class ArkynLogInstance {
23
23
  let arkynLogBaseApiUrl = arkynConfig.arkynLogBaseApiUrl || defaultArkynURL;
24
24
  arkynLogBaseApiUrl =
25
25
  arkynLogBaseApiUrl + "/http-traffic-records/:trafficSourceId";
26
- arkynLogBaseApiUrl.replace(":trafficSourceId", arkynConfig.arkynTrafficSourceId);
27
26
  this.arkynConfig = {
28
27
  arkynTrafficSourceId: arkynConfig.arkynTrafficSourceId,
29
28
  arkynUserToken: arkynConfig.arkynUserToken,
@@ -31,7 +30,7 @@ class ArkynLogInstance {
31
30
  };
32
31
  }
33
32
  /**
34
- * Retrieves the current arkyn configuration for the ArkynLogInstance.
33
+ * Retrieves the current arkyn configuration for the ArkynLogService.
35
34
  *
36
35
  * @returns {ArkynConfigProps | undefined} The current arkyn configuration if set,
37
36
  * or `undefined` if no configuration has been initialized.
@@ -47,4 +46,4 @@ class ArkynLogInstance {
47
46
  this.arkynConfig = undefined;
48
47
  }
49
48
  }
50
- export { ArkynLogInstance };
49
+ export { ArkynLogService };
@@ -1,7 +1,7 @@
1
- import type { Schema } from "zod";
1
+ import type { ZodType } from "zod";
2
2
  type SuccessResponse<T extends FormParseProps> = {
3
3
  success: true;
4
- data: T[1] extends Schema<infer U> ? U : never;
4
+ data: T[1] extends ZodType<infer U> ? U : never;
5
5
  };
6
6
  type ErrorResponse = {
7
7
  success: false;
@@ -14,7 +14,7 @@ type ErrorResponse = {
14
14
  };
15
15
  type FormParseProps = [formData: {
16
16
  [k: string]: any;
17
- }, schema: Schema];
17
+ }, schema: ZodType];
18
18
  type FormParseReturnType<T extends FormParseProps> = SuccessResponse<T> | ErrorResponse;
19
19
  /**
20
20
  * Parses form data using a Zod schema and returns the result.
@@ -1 +1 @@
1
- {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAElC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CAChD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEvE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAmB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"formParse.d.ts","sourceRoot":"","sources":["../../src/services/formParse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CACjD,CAAC;AAEF,KAAK,aAAa,GAAG;IACnB,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACtC,CAAC;AAEF,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExE,KAAK,mBAAmB,CAAC,CAAC,SAAS,cAAc,IAC7C,eAAe,CAAC,CAAC,CAAC,GAClB,aAAa,CAAC;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,SAAS,CAAC,CAAC,SAAS,cAAc,EAAE,CAC3C,QAAQ,EACR,MAAM,EACP,EAAE,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAsB5B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -39,10 +39,10 @@
39
39
  function formParse([formData, schema,]) {
40
40
  const zodResponse = schema.safeParse(formData);
41
41
  if (zodResponse.success === false) {
42
- const errorsObject = Object.fromEntries(zodResponse.error.errors.map((item) => [
43
- item.path.join("."),
44
- item.message,
45
- ]));
42
+ const errorsObject = Object.fromEntries(zodResponse.error.issues.map((item) => {
43
+ console.log(item);
44
+ return [item.path.join("."), item.message];
45
+ }));
46
46
  return {
47
47
  success: zodResponse.success,
48
48
  fieldErrors: errorsObject,
@@ -50,7 +50,10 @@ function formParse([formData, schema,]) {
50
50
  };
51
51
  }
52
52
  else {
53
- return { success: zodResponse.success, data: zodResponse.data };
53
+ return {
54
+ success: zodResponse.success,
55
+ data: zodResponse.data,
56
+ };
54
57
  }
55
58
  }
56
59
  export { formParse };
@@ -1 +1 @@
1
- {"version":3,"file":"getCaller.d.ts","sourceRoot":"","sources":["../../src/services/getCaller.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,iBAAS,SAAS;;;EAkEjB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"getCaller.d.ts","sourceRoot":"","sources":["../../src/services/getCaller.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AAEH,iBAAS,SAAS;;;EA+DjB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import path from "path";
2
+ import { HttpDebugService } from "./httpDebug";
2
3
  /**
3
4
  * Retrieves information about the caller of the current function.
4
5
  *
@@ -15,51 +16,45 @@ function getCaller() {
15
16
  const err = new Error();
16
17
  const stack = err.stack || "";
17
18
  const stackLines = stack.split("\n").map((line) => line.trim());
18
- // The first line is the error message
19
- // The second line is this function (getCaller)
20
- // The third line should be the direct caller
21
- // We start from 2 because indexes are zero-based
19
+ const ignoreFile = HttpDebugService.ignoreFile;
22
20
  let callerIndex = 2;
23
- // Ignore internal or infrastructure lines if necessary
24
21
  while (callerIndex < stackLines.length &&
25
22
  (stackLines[callerIndex].includes("node:internal") ||
26
23
  stackLines[callerIndex].includes("/node_modules/"))) {
27
24
  callerIndex++;
28
25
  }
26
+ if (ignoreFile) {
27
+ while (callerIndex < stackLines.length &&
28
+ stackLines[callerIndex].includes(ignoreFile)) {
29
+ callerIndex++;
30
+ }
31
+ }
29
32
  const callerLine = stackLines[callerIndex] || "";
30
33
  let functionName = "Unknown function";
31
34
  let callerInfo = "Unknown caller";
32
- // Default for named functions: "at functionName (file:line:column)"
33
35
  const namedFunctionMatch = callerLine.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
34
36
  if (namedFunctionMatch) {
35
37
  functionName = namedFunctionMatch[1];
36
38
  callerInfo = namedFunctionMatch[2];
37
39
  }
38
- // Default for anonymous functions or methods: "at file:line:column"
39
40
  else {
40
41
  const anonymousFunctionMatch = callerLine.match(/at\s+(.+)/);
41
42
  if (anonymousFunctionMatch) {
42
43
  callerInfo = anonymousFunctionMatch[1];
43
- // Tenta extrair nome da função de padrões como Object.method ou Class.method
44
44
  const objectMethodMatch = callerInfo.match(/at\s+([^(\s]+)\s+/);
45
45
  if (objectMethodMatch && objectMethodMatch[1] !== "new") {
46
46
  functionName = objectMethodMatch[1];
47
47
  }
48
48
  }
49
49
  }
50
- // Handles file paths
51
50
  if (callerInfo.includes("(")) {
52
51
  callerInfo = callerInfo.substring(callerInfo.indexOf("(") + 1, callerInfo.lastIndexOf(")"));
53
52
  }
54
- // Remove the line:column part of the file path
55
53
  callerInfo = callerInfo.split(":").slice(0, -2).join(":");
56
- // Make the path relative to the project
57
54
  try {
58
55
  callerInfo = path.relative(projectRoot, callerInfo);
59
56
  }
60
- catch (e) {
61
- // If it fails to relativize, use the original path
62
- }
57
+ catch (e) { }
63
58
  return { functionName, callerInfo };
64
59
  }
65
60
  export { getCaller };
@@ -1,3 +1,42 @@
1
+ /**
2
+ * Service for managing HTTP debug configuration and behavior.
3
+ *
4
+ * This service provides functionality to configure how the `getCaller` function
5
+ * identifies the actual caller in the stack trace by allowing specific files
6
+ * to be ignored during stack trace analysis.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Configure to ignore httpAdapter.ts in stack traces
11
+ * HttpDebugService.setIgnoreFile("httpAdapter.ts");
12
+ *
13
+ * // Now when httpDebug is called from within httpAdapter.ts,
14
+ * // it will show the actual caller (e.g., cart.ts) instead
15
+ * ```
16
+ */
17
+ declare class HttpDebugService {
18
+ /**
19
+ * The name of the file to ignore when analyzing the stack trace.
20
+ * When set, the `getCaller` function will skip stack frames containing this file name.
21
+ */
22
+ static ignoreFile?: string;
23
+ /**
24
+ * Sets the file name to be ignored during stack trace analysis.
25
+ *
26
+ * This method configures the debug service to skip specific files when
27
+ * determining the actual caller of a function. This is useful when you have
28
+ * adapter or wrapper functions that you want to be transparent in the debug output.
29
+ *
30
+ * @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Ignore the HTTP adapter file so debug shows the actual business logic caller
35
+ * HttpDebugService.setIgnoreFile("httpAdapter.ts");
36
+ * ```
37
+ */
38
+ static setIgnoreFile(file: string): void;
39
+ }
1
40
  /**
2
41
  * Logs debug information to the console when in development mode or when the
3
42
  * `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
@@ -31,5 +70,5 @@
31
70
  * ```
32
71
  */
33
72
  declare function httpDebug(name: string, body: any, cause?: any): void;
34
- export { httpDebug };
73
+ export { httpDebug, HttpDebugService };
35
74
  //# sourceMappingURL=httpDebug.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/services/httpDebug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAuBtD;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/services/httpDebug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,cAAM,gBAAgB;IACpB;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM;CAGlC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAuBtD;AAED,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC"}