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

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 (71) 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 +1090 -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} +21 -21
  15. package/dist/{config/apiInstance.d.ts.map → services/apiService.d.ts.map} +1 -1
  16. package/dist/{config/apiInstance.js → services/apiService.js} +18 -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/arkynLogInstance.d.ts.map +0 -1
  36. package/src/api/arkynLogRequest.ts +0 -116
  37. package/src/api/deleteRequest.ts +0 -22
  38. package/src/api/getRequest.ts +0 -20
  39. package/src/api/makeRequest.ts +0 -122
  40. package/src/api/patchRequest.ts +0 -22
  41. package/src/api/postRequest.ts +0 -22
  42. package/src/api/putRequest.ts +0 -22
  43. package/src/config/apiInstance.ts +0 -148
  44. package/src/config/arkynLogInstance.ts +0 -75
  45. package/src/http/badResponses/badGateway.ts +0 -63
  46. package/src/http/badResponses/badRequest.ts +0 -63
  47. package/src/http/badResponses/conflict.ts +0 -63
  48. package/src/http/badResponses/forbidden.ts +0 -63
  49. package/src/http/badResponses/notFound.ts +0 -63
  50. package/src/http/badResponses/notImplemented.ts +0 -63
  51. package/src/http/badResponses/serverError.ts +0 -63
  52. package/src/http/badResponses/unauthorized.ts +0 -63
  53. package/src/http/badResponses/unprocessableEntity.ts +0 -79
  54. package/src/http/successResponses/created.ts +0 -64
  55. package/src/http/successResponses/found.ts +0 -67
  56. package/src/http/successResponses/noContent.ts +0 -42
  57. package/src/http/successResponses/success.ts +0 -64
  58. package/src/http/successResponses/updated.ts +0 -64
  59. package/src/index.ts +0 -31
  60. package/src/mapper/arkynLogRequestMapper.ts +0 -73
  61. package/src/services/decodeErrorMessageFromRequest.ts +0 -36
  62. package/src/services/decodeRequestBody.ts +0 -43
  63. package/src/services/errorHandler.ts +0 -99
  64. package/src/services/formParse.ts +0 -83
  65. package/src/services/getCaller.ts +0 -82
  66. package/src/services/getScopedParams.ts +0 -43
  67. package/src/services/httpDebug.ts +0 -61
  68. package/src/services/schemaValidator.ts +0 -66
  69. package/src/types/ApiResponseDTO.ts +0 -19
  70. package/tsconfig.json +0 -21
  71. package/vitest.config.ts +0 -5
@@ -0,0 +1,8 @@
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 Z=Object.defineProperty;var ss=(a,l,f)=>l in a?Z(a,l,{enumerable:!0,configurable:!0,writable:!0,value:f}):a[l]=f;var o=(a,l,f)=>ss(a,typeof l!="symbol"?l+"":l,f);const l={};function f(){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 p=n[u]||"";let h="Unknown function",i="Unknown caller";const d=p.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);if(d)h=d[1],i=d[2];else{const c=p.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=l.relative(t,i)}catch{}return{functionName:h,callerInfo:i}}class x{static setIgnoreFile(s){this.ignoreFile=s}}o(x,"ignoreFile");function y(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:d}=f();let c=`${h} ${t} initialized
3
+ `;c+=`${h} Caller Function: ${d}
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,y("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,y("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 k{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,y("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 I{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,y("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 U{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,y("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,y("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,y("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,y("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 S{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&&y("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 P{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 v{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 w{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(w,"arkynConfig");async function L(t){const s=w.getArkynConfig();if(!s)return;const{arkynUserToken:e,arkynApiUrl:n}=s,{elapsedTime:r,method:u,queryParams:p,requestBody:h,requestHeaders:i,responseBody:d,responseHeaders:c,status:T,token:es,rawUrl:Y}=t;try{const b=new URL(Y);let B="HTTPS";b.protocol==="http:"&&(B="HTTP");const X=JSON.stringify({domainUrl:b.protocol+"//"+b.host,pathnameUrl:b.pathname,status:T,protocol:B,method:u,trafficUserId:null,elapsedTime:r,requestHeaders:i,requestBody:h,queryParams:p,responseHeaders:c,responseBody:d});await fetch(n.replace(":trafficSourceId",s.arkynTrafficSourceId),{method:"POST",body:X,headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`}})}catch(b){y("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(),p={...e,"Content-Type":"application/json"},h=await fetch(s,{method:t,headers:p,body:n?JSON.stringify(n):void 0}),i=performance.now()-u,d=h.status;let c=null;try{c=await h.json()}catch{c=null}const T=v.handle({elapsedTime:i,method:t,queryParams:new URL(s).searchParams,requestHeaders:p,requestBody:n,responseBody:c,responseHeaders:h.headers,status:d,url:s});return L(T),h.ok?{success:!0,status:d,message:(c==null?void 0:c.message)||r[t],response:c,cause:null}:{success:!1,status:d,message:(c==null?void 0:c.message)||h.statusText||"Request failed",response:c,cause:null}}catch(u){return y("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 A(t,s={},e){return g("DELETE",t,s,e)}async function F(t,s={}){return g("GET",t,s)}async function $(t,s={},e){return g("PATCH",t,s,e)}async function D(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");this.baseUrl=s.baseUrl,this.baseHeaders=s.baseHeaders||void 0,this.baseToken=s.baseToken||void 0}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 await F(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 await D(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 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 await $(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 await A(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 P: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 k:return t.toResponse();case t instanceof I:return t.toResponse();case t instanceof U: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 S:return t.toResponse()}return new R("Server error",t).toResponse()}function H([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}=f();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=H([s,this.schema]);if(!n.success){y("UnprocessableEntity",n);const r=Object.keys(n.fieldErrors)[0];throw new S({fields:n.fields,fieldErrors:n.fieldErrors,data:{scrollTo:r},message:e},!1)}return n.data}}a.ApiService=z,a.ArkynLogService=w,a.BadGateway=N,a.BadRequest=m,a.Conflict=k,a.Created=E,a.Forbidden=I,a.Found=J,a.HttpDebugService=x,a.NoContent=C,a.NotFound=U,a.NotImplemented=j,a.SchemaValidator=W,a.ServerError=R,a.Success=q,a.Unauthorized=O,a.UnprocessableEntity=S,a.Updated=P,a.decodeErrorMessageFromRequest=G,a.decodeRequestBody=V,a.errorHandler=_,a.formParse=H,a.getCaller=f,a.getScopedParams=K,a.httpDebug=y,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,MA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AAC"}
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,4 +1,4 @@
1
- type ApiInstanceContructorProps = {
1
+ type ApiServiceConstructorProps = {
2
2
  baseUrl: string;
3
3
  baseHeaders?: HeadersInit;
4
4
  baseToken?: string | null;
@@ -15,18 +15,18 @@ type ApiRequestDataWithBodyProps = {
15
15
  /**
16
16
  * Class representing an API instance to handle HTTP requests with base configurations.
17
17
  */
18
- declare class ApiInstance {
18
+ declare class ApiService {
19
19
  private baseUrl;
20
20
  private baseHeaders?;
21
21
  private baseToken?;
22
22
  /**
23
- * Creates an instance of ApiInstance.
23
+ * Creates an instance of ApiService.
24
24
  * @param props - The configuration properties for the API instance.
25
25
  * @param props.baseUrl - The base URL for the API.
26
26
  * @param props.baseHeaders - Optional base headers to include in all requests.
27
27
  * @param props.baseToken - Optional base token for authorization.
28
28
  */
29
- constructor(props: ApiInstanceContructorProps);
29
+ constructor(props: ApiServiceConstructorProps);
30
30
  /**
31
31
  * Generates the full URL by appending the route to the base URL.
32
32
  * @param route - The route to append to the base URL.
@@ -41,40 +41,40 @@ declare class ApiInstance {
41
41
  */
42
42
  private generateHeaders;
43
43
  /**
44
- * Sends a GET request to the specified route.
45
- * @param route - The API route to send the GET request to.
44
+ * Sends a get request to the specified route.
45
+ * @param route - The API route to send the get request to.
46
46
  * @param data - The request data, including optional headers and token.
47
47
  * @returns The API response data.
48
48
  */
49
- GET(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
49
+ get(route: string, data?: ApiRequestDataWithoutBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
50
50
  /**
51
- * Sends a POST request to the specified route.
52
- * @param route - The API route to send the POST request to.
51
+ * Sends a post request to the specified route.
52
+ * @param route - The API route to send the post request to.
53
53
  * @param data - The request data, including body, optional headers, and token.
54
54
  * @returns The API response data.
55
55
  */
56
- POST(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
56
+ post(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
57
57
  /**
58
- * Sends a PUT request to the specified route.
59
- * @param route - The API route to send the PUT request to.
58
+ * Sends a put request to the specified route.
59
+ * @param route - The API route to send the put request to.
60
60
  * @param data - The request data, including body, optional headers, and token.
61
61
  * @returns The API response data.
62
62
  */
63
- PUT(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
63
+ put(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
64
64
  /**
65
- * Sends a PATCH request to the specified route.
66
- * @param route - The API route to send the PATCH request to.
65
+ * Sends a patch request to the specified route.
66
+ * @param route - The API route to send the patch request to.
67
67
  * @param data - The request data, including body, optional headers, and token.
68
68
  * @returns The API response data.
69
69
  */
70
- PATCH(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
70
+ patch(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
71
71
  /**
72
- * Sends a DELETE request to the specified route.
73
- * @param route - The API route to send the DELETE request to.
72
+ * Sends a delete request to the specified route.
73
+ * @param route - The API route to send the delete request to.
74
74
  * @param data - The request data, including body, optional headers, and token.
75
75
  * @returns The API response data.
76
76
  */
77
- DELETE(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
77
+ delete(route: string, data?: ApiRequestDataWithBodyProps): Promise<import("../types/ApiResponseDTO").ApiResponseDTO<any>>;
78
78
  }
79
- export { ApiInstance };
80
- //# sourceMappingURL=apiInstance.d.ts.map
79
+ export { ApiService };
80
+ //# sourceMappingURL=apiService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apiInstance.d.ts","sourceRoot":"","sources":["../../src/config/apiInstance.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;CAC3B,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,2BA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;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;IAE3B;;;;;;OAMG;gBAES,KAAK,EAAE,0BAA0B;IAM7C;;;;OAIG;IAEH,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IAEH,OAAO,CAAC,eAAe;IAcvB;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,8BAA8B;IAM9D;;;;;OAKG;IAEG,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO5D;;;;;OAKG;IAEG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO3D;;;;;OAKG;IAEG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;IAO7D;;;;;OAKG;IAEG,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,2BAA2B;CAM/D;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -6,12 +6,12 @@ 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
13
  /**
14
- * Creates an instance of ApiInstance.
14
+ * Creates an instance of ApiService.
15
15
  * @param props - The configuration properties for the API instance.
16
16
  * @param props.baseUrl - The base URL for the API.
17
17
  * @param props.baseHeaders - Optional base headers to include in all requests.
@@ -49,63 +49,63 @@ class ApiInstance {
49
49
  return headers;
50
50
  }
51
51
  /**
52
- * Sends a GET request to the specified route.
53
- * @param route - The API route to send the GET request to.
52
+ * Sends a get request to the specified route.
53
+ * @param route - The API route to send the get request to.
54
54
  * @param data - The request data, including optional headers and token.
55
55
  * @returns The API response data.
56
56
  */
57
- async GET(route, data) {
57
+ async get(route, data) {
58
58
  const url = this.generateURL(route);
59
59
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
60
60
  return await getRequest(url, headers);
61
61
  }
62
62
  /**
63
- * Sends a POST request to the specified route.
64
- * @param route - The API route to send the POST request to.
63
+ * Sends a post request to the specified route.
64
+ * @param route - The API route to send the post request to.
65
65
  * @param data - The request data, including body, optional headers, and token.
66
66
  * @returns The API response data.
67
67
  */
68
- async POST(route, data) {
68
+ async post(route, data) {
69
69
  const url = this.generateURL(route);
70
70
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
71
71
  const body = data?.body;
72
72
  return await postRequest(url, headers, body);
73
73
  }
74
74
  /**
75
- * Sends a PUT request to the specified route.
76
- * @param route - The API route to send the PUT request to.
75
+ * Sends a put request to the specified route.
76
+ * @param route - The API route to send the put request to.
77
77
  * @param data - The request data, including body, optional headers, and token.
78
78
  * @returns The API response data.
79
79
  */
80
- async PUT(route, data) {
80
+ async put(route, data) {
81
81
  const url = this.generateURL(route);
82
82
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
83
83
  const body = data?.body;
84
84
  return await putRequest(url, headers, body);
85
85
  }
86
86
  /**
87
- * Sends a PATCH request to the specified route.
88
- * @param route - The API route to send the PATCH request to.
87
+ * Sends a patch request to the specified route.
88
+ * @param route - The API route to send the patch request to.
89
89
  * @param data - The request data, including body, optional headers, and token.
90
90
  * @returns The API response data.
91
91
  */
92
- async PATCH(route, data) {
92
+ async patch(route, data) {
93
93
  const url = this.generateURL(route);
94
94
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
95
95
  const body = data?.body;
96
96
  return await patchRequest(url, headers, body);
97
97
  }
98
98
  /**
99
- * Sends a DELETE request to the specified route.
100
- * @param route - The API route to send the DELETE request to.
99
+ * Sends a delete request to the specified route.
100
+ * @param route - The API route to send the delete request to.
101
101
  * @param data - The request data, including body, optional headers, and token.
102
102
  * @returns The API response data.
103
103
  */
104
- async DELETE(route, data) {
104
+ async delete(route, data) {
105
105
  const url = this.generateURL(route);
106
106
  const headers = this.generateHeaders(data?.headers || {}, data?.token);
107
107
  const body = data?.body;
108
108
  return await deleteRequest(url, headers, body);
109
109
  }
110
110
  }
111
- export { ApiInstance };
111
+ 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,GA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;;;;;;;;;;;;;;;;;;;;;;;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"}
@@ -1,4 +1,45 @@
1
1
  import { getCaller } from "../services/getCaller";
2
+ /**
3
+ * Service for managing HTTP debug configuration and behavior.
4
+ *
5
+ * This service provides functionality to configure how the `getCaller` function
6
+ * identifies the actual caller in the stack trace by allowing specific files
7
+ * to be ignored during stack trace analysis.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Configure to ignore httpAdapter.ts in stack traces
12
+ * HttpDebugService.setIgnoreFile("httpAdapter.ts");
13
+ *
14
+ * // Now when httpDebug is called from within httpAdapter.ts,
15
+ * // it will show the actual caller (e.g., cart.ts) instead
16
+ * ```
17
+ */
18
+ class HttpDebugService {
19
+ /**
20
+ * The name of the file to ignore when analyzing the stack trace.
21
+ * When set, the `getCaller` function will skip stack frames containing this file name.
22
+ */
23
+ static ignoreFile;
24
+ /**
25
+ * Sets the file name to be ignored during stack trace analysis.
26
+ *
27
+ * This method configures the debug service to skip specific files when
28
+ * determining the actual caller of a function. This is useful when you have
29
+ * adapter or wrapper functions that you want to be transparent in the debug output.
30
+ *
31
+ * @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Ignore the HTTP adapter file so debug shows the actual business logic caller
36
+ * HttpDebugService.setIgnoreFile("httpAdapter.ts");
37
+ * ```
38
+ */
39
+ static setIgnoreFile(file) {
40
+ this.ignoreFile = file;
41
+ }
42
+ }
2
43
  /**
3
44
  * Logs debug information to the console when in development mode or when the
4
45
  * `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
@@ -49,4 +90,4 @@ function httpDebug(name, body, cause) {
49
90
  console.log(consoleData);
50
91
  }
51
92
  }
52
- export { httpDebug };
93
+ export { httpDebug, HttpDebugService };
@@ -0,0 +1,3 @@
1
+ declare function measureRouteExecution<T = unknown>(handler: (props: any) => Promise<T>): (props: any) => Promise<T>;
2
+ export { measureRouteExecution };
3
+ //# sourceMappingURL=measureRouteExecution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measureRouteExecution.d.ts","sourceRoot":"","sources":["../../src/services/measureRouteExecution.ts"],"names":[],"mappings":"AAAA,iBAAS,qBAAqB,CAAC,CAAC,GAAG,OAAO,EACxC,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,IAEG,OAAO,GAAG,KAAG,OAAO,CAAC,CAAC,CAAC,CAyB9D;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}