@sailfish-ai/sf-veritas 0.2.13 → 0.2.14

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 (31) hide show
  1. package/dist/contextManager-Cx03mw7l.js +258 -0
  2. package/dist/contextManager-CxQqBCEA.cjs +1 -0
  3. package/dist/funcSpanTransformer-Byqzu4B1.js +231 -0
  4. package/dist/funcSpanTransformer-CDh0o-AP.cjs +1 -0
  5. package/dist/plugins/funcspanEsbuildPlugin.cjs +1 -1
  6. package/dist/plugins/funcspanEsbuildPlugin.mjs +2 -2
  7. package/dist/plugins/funcspanRollupPlugin.cjs +1 -1
  8. package/dist/plugins/funcspanRollupPlugin.mjs +2 -2
  9. package/dist/plugins/funcspanTscPlugin.cjs +1 -1
  10. package/dist/plugins/funcspanTscPlugin.mjs +2 -2
  11. package/dist/plugins/funcspanVitePlugin.cjs +1 -1
  12. package/dist/plugins/funcspanVitePlugin.mjs +2 -2
  13. package/dist/plugins/funcspanWebpackLoader.cjs +1 -1
  14. package/dist/plugins/funcspanWebpackLoader.mjs +1 -1
  15. package/dist/plugins/funcspanWebpackPlugin.cjs +1 -1
  16. package/dist/plugins/funcspanWebpackPlugin.mjs +1 -1
  17. package/dist/{runtimeConfig-CgLfwL3X.js → runtimeConfig-DndXTWki.js} +130 -127
  18. package/dist/{runtimeConfig-DIsq-KCn.cjs → runtimeConfig-TWzqPe1S.cjs} +7 -7
  19. package/dist/sf-veritas.cjs +37 -12
  20. package/dist/sf-veritas.mjs +546 -489
  21. package/dist/types/networkRequestTransmitter.d.ts +4 -0
  22. package/dist/types/setupConfig.d.ts +35 -0
  23. package/dist/worker-pool-capture.cjs +1 -1
  24. package/dist/worker-pool-capture.mjs +1 -1
  25. package/dist/{workerPoolSpanCapture-BYaf3NOr.js → workerPoolSpanCapture-DWS_V0Mn.js} +1 -1
  26. package/dist/{workerPoolSpanCapture-D85i6nhQ.cjs → workerPoolSpanCapture-Danyb3Qa.cjs} +1 -1
  27. package/package.json +2 -1
  28. package/dist/contextManager-BkETRITg.cjs +0 -1
  29. package/dist/contextManager-CEPhVu9T.js +0 -197
  30. package/dist/funcSpanTransformer-B9WWl-g1.cjs +0 -1
  31. package/dist/funcSpanTransformer-CWNEWRxq.js +0 -225
@@ -14,6 +14,10 @@ export interface NetworkRequestData {
14
14
  method: string;
15
15
  retryWithoutTraceId?: boolean;
16
16
  parentSpanId?: string | null;
17
+ requestHeaders?: Record<string, string>;
18
+ responseHeaders?: Record<string, string>;
19
+ requestBody?: string;
20
+ responseBody?: string;
17
21
  }
18
22
  export declare class NetworkRequestTransmitter extends BaseTransmitter {
19
23
  private serviceIdentifier;
@@ -23,6 +23,26 @@ export interface SetupOptions {
23
23
  * Optional Git commit SHA of the running build.
24
24
  */
25
25
  gitSha?: string;
26
+ /**
27
+ * Optional git organization/owner (e.g. "myorg").
28
+ * Override via GIT_ORG or VERCEL_GIT_REPO_OWNER env var.
29
+ */
30
+ gitOrg?: string;
31
+ /**
32
+ * Optional git repository name (e.g. "myrepo").
33
+ * Override via GIT_REPO or VERCEL_GIT_REPO_SLUG env var.
34
+ */
35
+ gitRepo?: string;
36
+ /**
37
+ * Optional git hosting provider (e.g. "github", "gitlab", "bitbucket").
38
+ * Override via GIT_PROVIDER env var.
39
+ */
40
+ gitProvider?: string;
41
+ /**
42
+ * Optional human-readable display name for this service.
43
+ * Override via SERVICE_DISPLAY_NAME env var.
44
+ */
45
+ serviceDisplayName?: string;
26
46
  /**
27
47
  * Optional the depth of exception locals.
28
48
  */
@@ -80,6 +100,21 @@ declare class AppConfig {
80
100
  packageLibraryType: string;
81
101
  version: string;
82
102
  gitSha?: string;
103
+ gitOrg?: string;
104
+ gitRepo?: string;
105
+ gitProvider?: string;
106
+ serviceDisplayName?: string;
107
+ infrastructureType?: string;
108
+ infrastructureDetails?: Record<string, string>;
109
+ setupInterceptorsFile?: string;
110
+ setupInterceptorsLine?: number;
111
+ logIgnoreRegex?: RegExp;
112
+ captureRequestHeaders: boolean;
113
+ captureResponseHeaders: boolean;
114
+ captureRequestBody: boolean;
115
+ captureResponseBody: boolean;
116
+ requestBodyLimitBytes: number;
117
+ responseBodyLimitBytes: number;
83
118
  private _serviceIdentificationReceived;
84
119
  constructor(options: SetupOptions);
85
120
  private getPackageVersion;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./workerPoolSpanCapture-D85i6nhQ.cjs");exports.captureWorkerPoolOperation=e.captureWorkerPoolOperation;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./workerPoolSpanCapture-Danyb3Qa.cjs");exports.captureWorkerPoolOperation=e.captureWorkerPoolOperation;
@@ -1,4 +1,4 @@
1
- import { c as e } from "./workerPoolSpanCapture-BYaf3NOr.js";
1
+ import { c as e } from "./workerPoolSpanCapture-DWS_V0Mn.js";
2
2
  export {
3
3
  e as captureWorkerPoolOperation
4
4
  };
@@ -4,7 +4,7 @@ var S = (n, t, a) => W(n, typeof t != "symbol" ? t + "" : t, a);
4
4
  import { AsyncLocalStorage as V, AsyncResource as J } from "async_hooks";
5
5
  import { appendFileSync as z } from "fs";
6
6
  import { threadId as F } from "worker_threads";
7
- import { g as m, C as k, v as D, a as P } from "./contextManager-CEPhVu9T.js";
7
+ import { g as m, C as k, v as D, a as P } from "./contextManager-Cx03mw7l.js";
8
8
  class x {
9
9
  constructor() {
10
10
  S(this, "apiKey");
@@ -1,4 +1,4 @@
1
- "use strict";const L=require("async_hooks"),W=require("fs"),v=require("worker_threads"),l=require("./contextManager-BkETRITg.cjs");class w{apiKey;endpoint;queryType="mutation";operationName="";serviceUUID=l.getConfig().serviceUUID;contextManager;constructor(){this.apiKey=l.getConfig().apiKey,this.endpoint=l.getConfig().apiGraphqlEndpoint,this.contextManager=l.ContextManager.getInstance()}get queryName(){return this.operationName?this.operationName.charAt(0).toLowerCase()+this.operationName.slice(1):""}getDefaultVariables(){const t=Date.now().toString(),o=this.contextManager.getOrSetSfTraceId(),s=this.contextManager.getCurrentFunctionSpanId();return{apiKey:this.apiKey,serviceUuid:this.serviceUUID,sessionId:o,timestampMs:t,parentSpanId:s}}getVariables(t={}){return{...this.getDefaultVariables(),...t}}setOperationName(t){this.operationName=t}setEndpoint(t){this.endpoint=t}setServiceUUID(t){this.serviceUUID=t}}const B=fetch;let _=!1;async function P(n,t,o,s){try{const a=l.getConfig();let i;try{i=JSON.stringify({query:o,variables:s,operationName:t})}catch{i=JSON.stringify({query:o,operationName:t})}_=!0,B(n,{method:"POST",headers:{"Content-Type":"application/json"},body:i}).then(async e=>{if(_=!1,!e.ok)return void(a.sfDebug&&console.error(`GraphQL request failed with status ${e.status} for ${t}`));const r=await e.json();r.errors?.length?(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0;console.error(d==="identifyServiceDetails"?`IdentifyServiceDetails NOT sent successfully for service: UUID=${c.serviceUUID}`:`GraphQL request failed with errors: ${JSON.stringify(g)} for operation key ${d}`)})(r.data,r.errors,a):a.sfDebug&&(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0,p=u[d]||!1;d==="identifyServiceDetails"&&(c.setServiceIdentificationReceived(p),l.getConfig().sfDebug&&console.log(`IdentifyServiceDetails sent successfully for service: UUID=${c.serviceUUID}; serviceIdentificationReceived=${d==="identifyServiceDetails"?p:"N/A"}`))})(r.data,0,a)}).catch(e=>{_=!1,a.sfDebug&&(console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`,e),e.cause&&console.error("[RequestUtils] Error cause:",e.cause))})}catch(a){_=!1,l.getConfig().sfDebug&&console.error("Error sending data to GraphQL server:",a)}}function N(n,t){if(!n)return t;const o=n.toLowerCase();return o==="true"||o==="1"||o==="yes"}const I=new L.AsyncLocalStorage;function O(n,t){try{const o=JSON.stringify(n).length/1048576;return o<=t?n:{_truncated:!0,_originalSizeMB:o.toFixed(2),_limitMB:t,_preview:JSON.stringify(n).substring(0,500)+"..."}}catch{return{_error:"Failed to serialize data",_type:typeof n}}}function S(n,t){const o=process.env[n];return o===void 0?t:o==="true"||o==="1"}function R(n,t){const o=process.env[n];if(o===void 0)return t;const s=parseFloat(o);return isNaN(s)?t:s}function T(){return{enabled:S("SF_WORKER_POOL_ENABLED",!0),trackFs:S("SF_WORKER_POOL_TRACK_FS",!1),trackDns:S("SF_WORKER_POOL_TRACK_DNS",!0),trackCrypto:S("SF_WORKER_POOL_TRACK_CRYPTO",!1),trackZlib:S("SF_WORKER_POOL_TRACK_ZLIB",!1),captureArguments:S("SF_WORKER_POOL_CAPTURE_ARGUMENTS",!0),captureReturnValue:S("SF_WORKER_POOL_CAPTURE_RETURN_VALUE",!0),argLimitMb:R("SF_WORKER_POOL_ARG_LIMIT_MB",1),returnLimitMb:R("SF_WORKER_POOL_RETURN_LIMIT_MB",1)}}function E(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){const r={};switch(i){case"readFile":case"writeFile":case"appendFile":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"?(r.encoding=e[1].encoding||null,r.flag=e[1].flag||null):typeof e[1]=="string"&&(r.encoding=e[1]),i!=="writeFile"&&i!=="appendFile"||(Buffer.isBuffer(e[1])?(r.dataType="Buffer",r.dataSize=e[1].length):typeof e[1]=="string"&&(r.dataType="string",r.dataSize=e[1].length));break;case"readdir":case"stat":case"lstat":case"access":case"chmod":case"mkdir":case"rmdir":case"unlink":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"&&(r.options={...e[1]},delete r.options.callback);break;case"rename":r.oldPath=String(e[0]||""),r.newPath=String(e[1]||"");break;case"open":r.path=String(e[0]||""),r.flags=e[1],r.mode=e[2];break;case"close":case"fstat":r.fd=e[0];break;case"read":case"write":r.fd=e[0],Buffer.isBuffer(e[1])&&(r.bufferSize=e[1].length),r.offset=e[2],r.length=e[3],r.position=e[4];break;default:r.argsCount=e.length-1}return r})(t,o);break;case"dns":a=(function(i,e){const r={};switch(i){case"lookup":r.hostname=String(e[0]||""),typeof e[1]=="object"?(r.family=e[1].family,r.all=e[1].all):typeof e[1]=="number"&&(r.family=e[1]);break;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":r.hostname=String(e[0]||"");break;case"reverse":r.ip=String(e[0]||"");break;default:r.argsCount=e.length-1}return r})(t,o);break;case"crypto":a=(function(i,e){const r={};switch(i){case"pbkdf2":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.iterations=e[2],r.keylen=e[3],r.digest=e[4];break;case"scrypt":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.keylen=e[2],typeof e[3]=="object"&&(r.N=e[3].N,r.r=e[3].r,r.p=e[3].p);break;case"randomBytes":r.size=e[0];break;case"generateKeyPair":r.type=e[0],typeof e[1]=="object"&&(r.modulusLength=e[1].modulusLength,r.namedCurve=e[1].namedCurve);break;default:r.argsCount=e.length-1}return r})(t,o);break;case"zlib":a=(function(i,e){const r={};return Buffer.isBuffer(e[0])?(r.inputType="Buffer",r.inputSize=e[0].length):typeof e[0]=="string"?(r.inputType="string",r.inputSize=e[0].length):r.inputType=typeof e[0],e[1]&&typeof e[1]=="object"&&typeof e[1]!="function"&&(r.options={...e[1]}),r})(0,o);break;default:return null}return s>0?O(a,s):a}catch{return{error:"Failed to capture arguments",argsCount:o.length-1}}}function D(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){if(!e)return null;switch(i){case"readFile":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e};case"readdir":return{count:Array.isArray(e)?e.length:0,items:e};case"stat":case"lstat":case"fstat":return{size:e.size,mode:e.mode,isFile:e.isFile(),isDirectory:e.isDirectory()};case"open":return{fd:e};case"read":return{bytesRead:e};case"write":return{bytesWritten:e};default:return e}})(t,o);break;case"dns":a=(function(i,e){if(!e)return null;switch(i){case"lookup":return Array.isArray(e)?{count:e.length,addresses:e}:e;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":return{count:Array.isArray(e)?e.length:0,records:e};case"reverse":return{hostnames:e};default:return e}})(t,o);break;case"crypto":a=(function(i,e){if(!e)return null;switch(i){case"pbkdf2":case"scrypt":case"randomBytes":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:{type:typeof e};case"generateKeyPair":return{hasPublicKey:!!e?.publicKey,hasPrivateKey:!!e?.privateKey};default:return e}})(t,o);break;case"zlib":a=(function(i,e){return e?Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e}:null})(0,o);break;default:return null}return s>0?O(a,s):a}catch{return{error:"Failed to capture result",type:typeof o}}}function K(n){return n.operationType==="worker_pool"}class M extends w{constructor(){super(),this.operationName="CollectFunctionSpans"}send(t){const o=l.getConfig().sfDebug;o&&console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);for(const s of t)try{if(K(s)){this.sendWorkerPoolSpan(s,o);continue}const a=s;let i;if(a.result!==void 0&&a.result!==null){const r=typeof a.result;i=JSON.stringify({type:r,has_value:!0,value:a.result})}else i=a.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const e=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:a.spanId,parentSpanId:a.parentSpanId,filePath:a.filePath,lineNumber:a.metadata.line,columnNumber:a.metadata.column,functionName:a.functionName,arguments:JSON.stringify(a.args||{}),returnValue:i,startTimeNs:(1e6*Date.now()-1e6*a.duration).toString(),durationNs:(1e6*a.duration).toString()});o&&(console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(e,null,2))),P(this.endpoint,this.operationName,this.getQuery(),e),o&&console.log(`[FunctionSpanTransmitter] Queued function span for ${a.functionName}`)}catch(a){console.error(`[FunctionSpanTransmitter] Error preparing function span for ${s.functionName}:`,a)}}sendWorkerPoolSpan(t,o){try{let s;if(t.result!==void 0&&t.result!==null){const i=typeof t.result;s=JSON.stringify({type:i,has_value:!0,value:t.result})}else s=t.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const a=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:t.spanId,operationName:t.operationName,moduleName:t.moduleName,methodName:t.methodName,startTimeNs:t.startTimeNs,durationNs:t.durationNs,arguments:JSON.stringify(t.args||{}),returnValue:s,error:t.error,pid:t.pid,threadId:t.threadId});o&&(console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(a,null,2))),P(this.endpoint,"CollectWorkerPoolSpans",this.getWorkerPoolQuery(),a),o&&console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`)}catch(s){console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`,s)}}getWorkerPoolQuery(){return`
1
+ "use strict";const L=require("async_hooks"),W=require("fs"),v=require("worker_threads"),l=require("./contextManager-CxQqBCEA.cjs");class w{apiKey;endpoint;queryType="mutation";operationName="";serviceUUID=l.getConfig().serviceUUID;contextManager;constructor(){this.apiKey=l.getConfig().apiKey,this.endpoint=l.getConfig().apiGraphqlEndpoint,this.contextManager=l.ContextManager.getInstance()}get queryName(){return this.operationName?this.operationName.charAt(0).toLowerCase()+this.operationName.slice(1):""}getDefaultVariables(){const t=Date.now().toString(),o=this.contextManager.getOrSetSfTraceId(),s=this.contextManager.getCurrentFunctionSpanId();return{apiKey:this.apiKey,serviceUuid:this.serviceUUID,sessionId:o,timestampMs:t,parentSpanId:s}}getVariables(t={}){return{...this.getDefaultVariables(),...t}}setOperationName(t){this.operationName=t}setEndpoint(t){this.endpoint=t}setServiceUUID(t){this.serviceUUID=t}}const B=fetch;let _=!1;async function P(n,t,o,s){try{const a=l.getConfig();let i;try{i=JSON.stringify({query:o,variables:s,operationName:t})}catch{i=JSON.stringify({query:o,operationName:t})}_=!0,B(n,{method:"POST",headers:{"Content-Type":"application/json"},body:i}).then(async e=>{if(_=!1,!e.ok)return void(a.sfDebug&&console.error(`GraphQL request failed with status ${e.status} for ${t}`));const r=await e.json();r.errors?.length?(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0;console.error(d==="identifyServiceDetails"?`IdentifyServiceDetails NOT sent successfully for service: UUID=${c.serviceUUID}`:`GraphQL request failed with errors: ${JSON.stringify(g)} for operation key ${d}`)})(r.data,r.errors,a):a.sfDebug&&(function(u,g,c){const d=u&&typeof u=="object"&&!Array.isArray(u)?Object.keys(u)[0]:void 0,p=u[d]||!1;d==="identifyServiceDetails"&&(c.setServiceIdentificationReceived(p),l.getConfig().sfDebug&&console.log(`IdentifyServiceDetails sent successfully for service: UUID=${c.serviceUUID}; serviceIdentificationReceived=${d==="identifyServiceDetails"?p:"N/A"}`))})(r.data,0,a)}).catch(e=>{_=!1,a.sfDebug&&(console.error(`[RequestUtils] Fetch error for ${t} to ${n}:`,e),e.cause&&console.error("[RequestUtils] Error cause:",e.cause))})}catch(a){_=!1,l.getConfig().sfDebug&&console.error("Error sending data to GraphQL server:",a)}}function N(n,t){if(!n)return t;const o=n.toLowerCase();return o==="true"||o==="1"||o==="yes"}const I=new L.AsyncLocalStorage;function O(n,t){try{const o=JSON.stringify(n).length/1048576;return o<=t?n:{_truncated:!0,_originalSizeMB:o.toFixed(2),_limitMB:t,_preview:JSON.stringify(n).substring(0,500)+"..."}}catch{return{_error:"Failed to serialize data",_type:typeof n}}}function S(n,t){const o=process.env[n];return o===void 0?t:o==="true"||o==="1"}function R(n,t){const o=process.env[n];if(o===void 0)return t;const s=parseFloat(o);return isNaN(s)?t:s}function T(){return{enabled:S("SF_WORKER_POOL_ENABLED",!0),trackFs:S("SF_WORKER_POOL_TRACK_FS",!1),trackDns:S("SF_WORKER_POOL_TRACK_DNS",!0),trackCrypto:S("SF_WORKER_POOL_TRACK_CRYPTO",!1),trackZlib:S("SF_WORKER_POOL_TRACK_ZLIB",!1),captureArguments:S("SF_WORKER_POOL_CAPTURE_ARGUMENTS",!0),captureReturnValue:S("SF_WORKER_POOL_CAPTURE_RETURN_VALUE",!0),argLimitMb:R("SF_WORKER_POOL_ARG_LIMIT_MB",1),returnLimitMb:R("SF_WORKER_POOL_RETURN_LIMIT_MB",1)}}function E(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){const r={};switch(i){case"readFile":case"writeFile":case"appendFile":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"?(r.encoding=e[1].encoding||null,r.flag=e[1].flag||null):typeof e[1]=="string"&&(r.encoding=e[1]),i!=="writeFile"&&i!=="appendFile"||(Buffer.isBuffer(e[1])?(r.dataType="Buffer",r.dataSize=e[1].length):typeof e[1]=="string"&&(r.dataType="string",r.dataSize=e[1].length));break;case"readdir":case"stat":case"lstat":case"access":case"chmod":case"mkdir":case"rmdir":case"unlink":r.path=String(e[0]||""),e[1]&&typeof e[1]=="object"&&(r.options={...e[1]},delete r.options.callback);break;case"rename":r.oldPath=String(e[0]||""),r.newPath=String(e[1]||"");break;case"open":r.path=String(e[0]||""),r.flags=e[1],r.mode=e[2];break;case"close":case"fstat":r.fd=e[0];break;case"read":case"write":r.fd=e[0],Buffer.isBuffer(e[1])&&(r.bufferSize=e[1].length),r.offset=e[2],r.length=e[3],r.position=e[4];break;default:r.argsCount=e.length-1}return r})(t,o);break;case"dns":a=(function(i,e){const r={};switch(i){case"lookup":r.hostname=String(e[0]||""),typeof e[1]=="object"?(r.family=e[1].family,r.all=e[1].all):typeof e[1]=="number"&&(r.family=e[1]);break;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":r.hostname=String(e[0]||"");break;case"reverse":r.ip=String(e[0]||"");break;default:r.argsCount=e.length-1}return r})(t,o);break;case"crypto":a=(function(i,e){const r={};switch(i){case"pbkdf2":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.iterations=e[2],r.keylen=e[3],r.digest=e[4];break;case"scrypt":r.passwordType=typeof e[0],r.saltType=typeof e[1],r.keylen=e[2],typeof e[3]=="object"&&(r.N=e[3].N,r.r=e[3].r,r.p=e[3].p);break;case"randomBytes":r.size=e[0];break;case"generateKeyPair":r.type=e[0],typeof e[1]=="object"&&(r.modulusLength=e[1].modulusLength,r.namedCurve=e[1].namedCurve);break;default:r.argsCount=e.length-1}return r})(t,o);break;case"zlib":a=(function(i,e){const r={};return Buffer.isBuffer(e[0])?(r.inputType="Buffer",r.inputSize=e[0].length):typeof e[0]=="string"?(r.inputType="string",r.inputSize=e[0].length):r.inputType=typeof e[0],e[1]&&typeof e[1]=="object"&&typeof e[1]!="function"&&(r.options={...e[1]}),r})(0,o);break;default:return null}return s>0?O(a,s):a}catch{return{error:"Failed to capture arguments",argsCount:o.length-1}}}function D(n,t,o,s){let a;try{switch(n){case"fs":a=(function(i,e){if(!e)return null;switch(i){case"readFile":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e};case"readdir":return{count:Array.isArray(e)?e.length:0,items:e};case"stat":case"lstat":case"fstat":return{size:e.size,mode:e.mode,isFile:e.isFile(),isDirectory:e.isDirectory()};case"open":return{fd:e};case"read":return{bytesRead:e};case"write":return{bytesWritten:e};default:return e}})(t,o);break;case"dns":a=(function(i,e){if(!e)return null;switch(i){case"lookup":return Array.isArray(e)?{count:e.length,addresses:e}:e;case"resolve":case"resolve4":case"resolve6":case"resolveAny":case"resolveMx":case"resolveNs":case"resolveTxt":return{count:Array.isArray(e)?e.length:0,records:e};case"reverse":return{hostnames:e};default:return e}})(t,o);break;case"crypto":a=(function(i,e){if(!e)return null;switch(i){case"pbkdf2":case"scrypt":case"randomBytes":return Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:{type:typeof e};case"generateKeyPair":return{hasPublicKey:!!e?.publicKey,hasPrivateKey:!!e?.privateKey};default:return e}})(t,o);break;case"zlib":a=(function(i,e){return e?Buffer.isBuffer(e)?{type:"Buffer",size:e.length}:typeof e=="string"?{type:"string",size:e.length}:{type:typeof e}:null})(0,o);break;default:return null}return s>0?O(a,s):a}catch{return{error:"Failed to capture result",type:typeof o}}}function K(n){return n.operationType==="worker_pool"}class M extends w{constructor(){super(),this.operationName="CollectFunctionSpans"}send(t){const o=l.getConfig().sfDebug;o&&console.log(`[FunctionSpanTransmitter] Preparing to send ${t.length} function span(s)`);for(const s of t)try{if(K(s)){this.sendWorkerPoolSpan(s,o);continue}const a=s;let i;if(a.result!==void 0&&a.result!==null){const r=typeof a.result;i=JSON.stringify({type:r,has_value:!0,value:a.result})}else i=a.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const e=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:a.spanId,parentSpanId:a.parentSpanId,filePath:a.filePath,lineNumber:a.metadata.line,columnNumber:a.metadata.column,functionName:a.functionName,arguments:JSON.stringify(a.args||{}),returnValue:i,startTimeNs:(1e6*Date.now()-1e6*a.duration).toString(),durationNs:(1e6*a.duration).toString()});o&&(console.log(`[FunctionSpanTransmitter] Sending GraphQL mutation to ${this.endpoint}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(e,null,2))),P(this.endpoint,this.operationName,this.getQuery(),e),o&&console.log(`[FunctionSpanTransmitter] Queued function span for ${a.functionName}`)}catch(a){console.error(`[FunctionSpanTransmitter] Error preparing function span for ${s.functionName}:`,a)}}sendWorkerPoolSpan(t,o){try{let s;if(t.result!==void 0&&t.result!==null){const i=typeof t.result;s=JSON.stringify({type:i,has_value:!0,value:t.result})}else s=t.result===null?JSON.stringify({type:"null",has_value:!0,value:null}):JSON.stringify({type:"undefined",has_value:!1,value:null});const a=this.getVariables({library:"JS/TS BACKEND",version:l.getConfig().version,spanId:t.spanId,operationName:t.operationName,moduleName:t.moduleName,methodName:t.methodName,startTimeNs:t.startTimeNs,durationNs:t.durationNs,arguments:JSON.stringify(t.args||{}),returnValue:s,error:t.error,pid:t.pid,threadId:t.threadId});o&&(console.log(`[FunctionSpanTransmitter] Sending worker pool span: ${t.operationName}`),console.log("[FunctionSpanTransmitter] Variables:",JSON.stringify(a,null,2))),P(this.endpoint,"CollectWorkerPoolSpans",this.getWorkerPoolQuery(),a),o&&console.log(`[FunctionSpanTransmitter] Queued worker pool span for ${t.operationName}`)}catch(s){console.error(`[FunctionSpanTransmitter] Error preparing worker pool span for ${t.operationName}:`,s)}}getWorkerPoolQuery(){return`
2
2
  mutation CollectWorkerPoolSpans(
3
3
  $apiKey: String!,
4
4
  $serviceUuid: String!,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sailfish-ai/sf-veritas",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "publishPublicly": true,
5
5
  "description": "A versatile Edge Runtime-compatible package for JavaScript and TypeScript backend systems and scripts.",
6
6
  "main": "./dist/sf-veritas.cjs",
@@ -89,6 +89,7 @@
89
89
  "@babel/types": "^7.26.0",
90
90
  "glob": "^11.1.0",
91
91
  "js-yaml": "^4.1.0",
92
+ "toml": "^3.0.0",
92
93
  "next": "^15.1.7",
93
94
  "source-map-js": "^1.2.1",
94
95
  "uuid": "^11.1.0"
@@ -1 +0,0 @@
1
- "use strict";const v=require("async_hooks"),o=[];for(let s=0;s<256;++s)o.push((s+256).toString(16).slice(1));let h;const L=new Uint8Array(16),S={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function p(s,e,t){if(S.randomUUID&&!s)return S.randomUUID();const n=(s=s||{}).random??s.rng?.()??(function(){if(!h){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");h=crypto.getRandomValues.bind(crypto)}return h(L)})();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=15&n[6]|64,n[8]=63&n[8]|128,(function(r,i=0){return(o[r[i+0]]+o[r[i+1]]+o[r[i+2]]+o[r[i+3]]+"-"+o[r[i+4]]+o[r[i+5]]+"-"+o[r[i+6]]+o[r[i+7]]+"-"+o[r[i+8]]+o[r[i+9]]+"-"+o[r[i+10]]+o[r[i+11]]+o[r[i+12]]+o[r[i+13]]+o[r[i+14]]+o[r[i+15]]).toLowerCase()})(n)}class _{apiKey;apiGraphqlEndpoint;sfDebug;serviceIdentifier;serviceVersion;serviceUUID;serviceAdditionalMetadata;profilingModeEnabled;profilingMaxDepth;profilingMaxVariableSizeKb;domainsToNotPropagateHeadersTo;nodeModulesToCollectLocalVariablesOn;printConfigurationStatuses;logLevel;stackDepthLocals;stackDepthCodeTraceDepth;packageLibraryType;version;gitSha;_serviceIdentificationReceived=!1;constructor(e){this.apiKey=e.apiKey,this.apiGraphqlEndpoint=e?.apiGraphqlEndpoint||process.env.SAILFISH_GRAPHQL_ENDPOINT||"https://api-service.sailfishqa.com/graphql/",this.sfDebug=e?.debug===!0||process.env.SF_DEBUG==="true",this.serviceIdentifier=e?.serviceIdentifier||process.env.SERVICE_IDENTIFIER,this.serviceUUID=p(),this.serviceVersion=e?.serviceVersion||process.env.SERVICE_VERSION,this.gitSha=e?.gitSha||process.env.GIT_SHA||process.env.VERCEL_GIT_COMMIT_SHA,this.serviceAdditionalMetadata=e?.serviceAdditionalMetadata||{},this.profilingModeEnabled=e?.profilingModeEnabled??!1,this.profilingMaxDepth=e?.profilingMaxDepth??5,this.profilingMaxVariableSizeKb=e?.profilingMaxVariableSizeKb??25,this.domainsToNotPropagateHeadersTo=e?.domainsToNotPropagateHeadersTo||[],this.nodeModulesToCollectLocalVariablesOn=e?.nodeModulesToCollectLocalVariablesOn||["_all_"],this.printConfigurationStatuses=process.env.PRINT_CONFIGURATION_STATUSES||"true",this.logLevel=process.env.LOG_LEVEL||"INFO",this.stackDepthLocals=process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS!==void 0?parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS,10):5,isNaN(this.stackDepthLocals)&&(this.stackDepthLocals=-1),this.stackDepthCodeTraceDepth=process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH!==void 0?parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH,10):-1,isNaN(this.stackDepthCodeTraceDepth)&&(this.stackDepthCodeTraceDepth=-1),this.packageLibraryType="JS/TS BACKEND",this.version=this.getPackageVersion()}getPackageVersion(){return"0.1.15"}get serviceIdentificationReceived(){return this._serviceIdentificationReceived}setServiceIdentificationReceived(e){this._serviceIdentificationReceived=e}}const T=Symbol.for("sailfish.sf_config");function I(){return globalThis[T]}function l(){const s=I();if(!s)throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");return s}const f=Symbol.for("sf.ctx.storeAls"),a=globalThis,C=a[f]??(a[f]=new v.AsyncLocalStorage),x=["identitytoolkit.googleapis.com","t.co","*.twitter.com","*.gravatar.com","*.googleapis.com","*.amazonaws.com","*.smooch.io","*.zendesk.com"],D=Symbol.for("sf.ctx.als"),u=a[D]??(a[D]=new v.AsyncLocalStorage),E=Symbol.for("sf.ctx.sessionRegistry"),d=a[E]??(a[E]=new Map),g={handledExceptions:new Set,reentrancyGuardLoggingActive:!1,reentrancyGuardLoggingPreActive:!1,reentrancyGuardPrintActive:!1,reentrancyGuardPrintPreActive:!1,reentrancyGuardExceptionActive:!1,reentrancyGuardExceptionPreActive:!1,excludedDomains:new Set(x),supportedDomains:new Set};class c{static GLOBAL_MANAGER_SYMBOL=Symbol.for("sf.ctx.manager");constructor(){}current(){return C.getStore()}ensureStore(){const e=this.current();if(e)return e;const t=new Map;return C.enterWith(t),t}runWith(e,t){const n=this.current()??new Map,r=new Map(n);for(const[i,A]of Object.entries(e))r.set(i,A);return C.run(r,t)}static getInstance(){return a[c.GLOBAL_MANAGER_SYMBOL]||(a[c.GLOBAL_MANAGER_SYMBOL]=new c),a[c.GLOBAL_MANAGER_SYMBOL]}getCurrentContext(){return u.getStore()||g}setCurrentContext(e){const t=u.getStore()||g;u.enterWith({...t,...e})}ensureSession(e){let t=d.get(e);return t||(t={...g},d.set(e,t)),t}getContextFor(e){return d.get(e)??g}updateContextFor(e,t){const n=this.ensureSession(e);d.set(e,{...n,...t})}runWithSession(e,t){const n={...this.ensureSession(e)};return u.run(n,t)}deleteSession(e){d.delete(e)}getTraceId(){return this.getCurrentContext().traceId}getPageVisitUUID(){return this.getCurrentContext().pageVisitUUID}setTraceId(e){this.setCurrentContext({traceId:e})}setPageVisitUUID(e){this.setCurrentContext({pageVisitUUID:e})}getCurrentFunctionSpanId(){return this.getCurrentContext().currentFunctionSpanId}setCurrentFunctionSpanId(e){this.setCurrentContext({currentFunctionSpanId:e})}clearCurrentFunctionSpanId(){this.setCurrentContext({currentFunctionSpanId:void 0})}getOrSetSfTraceId(e,t=!1){let n=this.getTraceId();return n||(n=e||(t?p():`nonsession-applogs-v3/${l().apiKey}/${p()}`),this.setTraceId(n),l().sfDebug&&console.log(" Created new trace ID:",n),n)}getOrSetPageVisitUUID(){let e=this.getPageVisitUUID();return e||(e=p(),this.setPageVisitUUID(e),l().sfDebug&&console.log(" Created new page visit UUID:",e),e)}getHandledExceptions(){return this.getCurrentContext().handledExceptions}markExceptionHandled(e){const t=this.getHandledExceptions();t.add(e),this.setCurrentContext({handledExceptions:t})}hasHandledException(e){return this.getHandledExceptions().has(e)}resetHandledExceptions(){this.setCurrentContext({handledExceptions:new Set})}getExcludedDomains(){return this.getCurrentContext().excludedDomains}getSupportedDomains(){return this.getCurrentContext().supportedDomains}addSupportedDomains(e){this.getCurrentContext().supportedDomains.add(e.toLowerCase().trim())}setTraceIdFor(e,t){this.updateContextFor(e,{traceId:t})}setPageVisitUUIDFor(e,t){this.updateContextFor(e,{pageVisitUUID:t})}}exports.ContextManager=c,exports.DEFAULT_DOMAINS_TO_EXCLUDE=x,exports.getConfig=l,exports.getCurrentFunctionSpanId=function(){return c.getInstance().getCurrentFunctionSpanId()},exports.getGlobalConfigUnsafe=I,exports.getOrCreateConfig=function(s){const e=I();if(e)return{config:e};const t=new _(s);return(function(n){globalThis[T]=n})(t),t.sfDebug&&console.log("[[getOrCreateConfig]] Created global config:",t),{config:t}},exports.runWithContext=function(s){const e={...c.getInstance().getCurrentContext()};u.run(e,()=>{s()})},exports.v4=p;
@@ -1,197 +0,0 @@
1
- var L = Object.defineProperty;
2
- var _ = (n, e, t) => e in n ? L(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var r = (n, e, t) => _(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { AsyncLocalStorage as T } from "async_hooks";
5
- const a = [];
6
- for (let n = 0; n < 256; ++n) a.push((n + 256).toString(16).slice(1));
7
- let C;
8
- const U = new Uint8Array(16), f = { randomUUID: typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
9
- function l(n, e, t) {
10
- if (f.randomUUID && !n) return f.randomUUID();
11
- const o = (n = n || {}).random ?? n.rng?.() ?? (function() {
12
- if (!C) {
13
- if (typeof crypto > "u" || !crypto.getRandomValues) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
14
- C = crypto.getRandomValues.bind(crypto);
15
- }
16
- return C(U);
17
- })();
18
- if (o.length < 16) throw new Error("Random bytes length must be >= 16");
19
- return o[6] = 15 & o[6] | 64, o[8] = 63 & o[8] | 128, (function(i, s = 0) {
20
- return (a[i[s + 0]] + a[i[s + 1]] + a[i[s + 2]] + a[i[s + 3]] + "-" + a[i[s + 4]] + a[i[s + 5]] + "-" + a[i[s + 6]] + a[i[s + 7]] + "-" + a[i[s + 8]] + a[i[s + 9]] + "-" + a[i[s + 10]] + a[i[s + 11]] + a[i[s + 12]] + a[i[s + 13]] + a[i[s + 14]] + a[i[s + 15]]).toLowerCase();
21
- })(o);
22
- }
23
- class b {
24
- constructor(e) {
25
- r(this, "apiKey");
26
- r(this, "apiGraphqlEndpoint");
27
- r(this, "sfDebug");
28
- r(this, "serviceIdentifier");
29
- r(this, "serviceVersion");
30
- r(this, "serviceUUID");
31
- r(this, "serviceAdditionalMetadata");
32
- r(this, "profilingModeEnabled");
33
- r(this, "profilingMaxDepth");
34
- r(this, "profilingMaxVariableSizeKb");
35
- r(this, "domainsToNotPropagateHeadersTo");
36
- r(this, "nodeModulesToCollectLocalVariablesOn");
37
- r(this, "printConfigurationStatuses");
38
- r(this, "logLevel");
39
- r(this, "stackDepthLocals");
40
- r(this, "stackDepthCodeTraceDepth");
41
- r(this, "packageLibraryType");
42
- r(this, "version");
43
- r(this, "gitSha");
44
- r(this, "_serviceIdentificationReceived", !1);
45
- this.apiKey = e.apiKey, this.apiGraphqlEndpoint = e?.apiGraphqlEndpoint || process.env.SAILFISH_GRAPHQL_ENDPOINT || "https://api-service.sailfishqa.com/graphql/", this.sfDebug = e?.debug === !0 || process.env.SF_DEBUG === "true", this.serviceIdentifier = e?.serviceIdentifier || process.env.SERVICE_IDENTIFIER, this.serviceUUID = l(), this.serviceVersion = e?.serviceVersion || process.env.SERVICE_VERSION, this.gitSha = e?.gitSha || process.env.GIT_SHA || process.env.VERCEL_GIT_COMMIT_SHA, this.serviceAdditionalMetadata = e?.serviceAdditionalMetadata || {}, this.profilingModeEnabled = e?.profilingModeEnabled ?? !1, this.profilingMaxDepth = e?.profilingMaxDepth ?? 5, this.profilingMaxVariableSizeKb = e?.profilingMaxVariableSizeKb ?? 25, this.domainsToNotPropagateHeadersTo = e?.domainsToNotPropagateHeadersTo || [], this.nodeModulesToCollectLocalVariablesOn = e?.nodeModulesToCollectLocalVariablesOn || ["_all_"], this.printConfigurationStatuses = process.env.PRINT_CONFIGURATION_STATUSES || "true", this.logLevel = process.env.LOG_LEVEL || "INFO", this.stackDepthLocals = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_LOCALS, 10) : 5, isNaN(this.stackDepthLocals) && (this.stackDepthLocals = -1), this.stackDepthCodeTraceDepth = process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH !== void 0 ? parseInt(process.env.SAILFISH_EXCEPTION_STACK_DEPTH_CODE_TRACE_DEPTH, 10) : -1, isNaN(this.stackDepthCodeTraceDepth) && (this.stackDepthCodeTraceDepth = -1), this.packageLibraryType = "JS/TS BACKEND", this.version = this.getPackageVersion();
46
- }
47
- getPackageVersion() {
48
- return "0.1.15";
49
- }
50
- get serviceIdentificationReceived() {
51
- return this._serviceIdentificationReceived;
52
- }
53
- setServiceIdentificationReceived(e) {
54
- this._serviceIdentificationReceived = e;
55
- }
56
- }
57
- const x = Symbol.for("sailfish.sf_config");
58
- function m() {
59
- return globalThis[x];
60
- }
61
- function P(n) {
62
- const e = m();
63
- if (e) return { config: e };
64
- const t = new b(n);
65
- return (function(o) {
66
- globalThis[x] = o;
67
- })(t), t.sfDebug && console.log("[[getOrCreateConfig]] Created global config:", t), { config: t };
68
- }
69
- function I() {
70
- const n = m();
71
- if (!n) throw new Error("Configuration has not been initialized. Call getOrCreateConfig(options) first.");
72
- return n;
73
- }
74
- const D = Symbol.for("sf.ctx.storeAls"), c = globalThis, S = c[D] ?? (c[D] = new T()), y = ["identitytoolkit.googleapis.com", "t.co", "*.twitter.com", "*.gravatar.com", "*.googleapis.com", "*.amazonaws.com", "*.smooch.io", "*.zendesk.com"], E = Symbol.for("sf.ctx.als"), p = c[E] ?? (c[E] = new T()), v = Symbol.for("sf.ctx.sessionRegistry"), u = c[v] ?? (c[v] = /* @__PURE__ */ new Map()), g = { handledExceptions: /* @__PURE__ */ new Set(), reentrancyGuardLoggingActive: !1, reentrancyGuardLoggingPreActive: !1, reentrancyGuardPrintActive: !1, reentrancyGuardPrintPreActive: !1, reentrancyGuardExceptionActive: !1, reentrancyGuardExceptionPreActive: !1, excludedDomains: new Set(y), supportedDomains: /* @__PURE__ */ new Set() }, d = class d {
75
- constructor() {
76
- }
77
- current() {
78
- return S.getStore();
79
- }
80
- ensureStore() {
81
- const e = this.current();
82
- if (e) return e;
83
- const t = /* @__PURE__ */ new Map();
84
- return S.enterWith(t), t;
85
- }
86
- runWith(e, t) {
87
- const o = this.current() ?? /* @__PURE__ */ new Map(), i = new Map(o);
88
- for (const [s, A] of Object.entries(e)) i.set(s, A);
89
- return S.run(i, t);
90
- }
91
- static getInstance() {
92
- return c[d.GLOBAL_MANAGER_SYMBOL] || (c[d.GLOBAL_MANAGER_SYMBOL] = new d()), c[d.GLOBAL_MANAGER_SYMBOL];
93
- }
94
- getCurrentContext() {
95
- return p.getStore() || g;
96
- }
97
- setCurrentContext(e) {
98
- const t = p.getStore() || g;
99
- p.enterWith({ ...t, ...e });
100
- }
101
- ensureSession(e) {
102
- let t = u.get(e);
103
- return t || (t = { ...g }, u.set(e, t)), t;
104
- }
105
- getContextFor(e) {
106
- return u.get(e) ?? g;
107
- }
108
- updateContextFor(e, t) {
109
- const o = this.ensureSession(e);
110
- u.set(e, { ...o, ...t });
111
- }
112
- runWithSession(e, t) {
113
- const o = { ...this.ensureSession(e) };
114
- return p.run(o, t);
115
- }
116
- deleteSession(e) {
117
- u.delete(e);
118
- }
119
- getTraceId() {
120
- return this.getCurrentContext().traceId;
121
- }
122
- getPageVisitUUID() {
123
- return this.getCurrentContext().pageVisitUUID;
124
- }
125
- setTraceId(e) {
126
- this.setCurrentContext({ traceId: e });
127
- }
128
- setPageVisitUUID(e) {
129
- this.setCurrentContext({ pageVisitUUID: e });
130
- }
131
- getCurrentFunctionSpanId() {
132
- return this.getCurrentContext().currentFunctionSpanId;
133
- }
134
- setCurrentFunctionSpanId(e) {
135
- this.setCurrentContext({ currentFunctionSpanId: e });
136
- }
137
- clearCurrentFunctionSpanId() {
138
- this.setCurrentContext({ currentFunctionSpanId: void 0 });
139
- }
140
- getOrSetSfTraceId(e, t = !1) {
141
- let o = this.getTraceId();
142
- return o || (o = e || (t ? l() : `nonsession-applogs-v3/${I().apiKey}/${l()}`), this.setTraceId(o), I().sfDebug && console.log(" Created new trace ID:", o), o);
143
- }
144
- getOrSetPageVisitUUID() {
145
- let e = this.getPageVisitUUID();
146
- return e || (e = l(), this.setPageVisitUUID(e), I().sfDebug && console.log(" Created new page visit UUID:", e), e);
147
- }
148
- getHandledExceptions() {
149
- return this.getCurrentContext().handledExceptions;
150
- }
151
- markExceptionHandled(e) {
152
- const t = this.getHandledExceptions();
153
- t.add(e), this.setCurrentContext({ handledExceptions: t });
154
- }
155
- hasHandledException(e) {
156
- return this.getHandledExceptions().has(e);
157
- }
158
- resetHandledExceptions() {
159
- this.setCurrentContext({ handledExceptions: /* @__PURE__ */ new Set() });
160
- }
161
- getExcludedDomains() {
162
- return this.getCurrentContext().excludedDomains;
163
- }
164
- getSupportedDomains() {
165
- return this.getCurrentContext().supportedDomains;
166
- }
167
- addSupportedDomains(e) {
168
- this.getCurrentContext().supportedDomains.add(e.toLowerCase().trim());
169
- }
170
- setTraceIdFor(e, t) {
171
- this.updateContextFor(e, { traceId: t });
172
- }
173
- setPageVisitUUIDFor(e, t) {
174
- this.updateContextFor(e, { pageVisitUUID: t });
175
- }
176
- };
177
- r(d, "GLOBAL_MANAGER_SYMBOL", Symbol.for("sf.ctx.manager"));
178
- let h = d;
179
- function V(n) {
180
- const e = { ...h.getInstance().getCurrentContext() };
181
- p.run(e, () => {
182
- n();
183
- });
184
- }
185
- function w() {
186
- return h.getInstance().getCurrentFunctionSpanId();
187
- }
188
- export {
189
- h as C,
190
- y as D,
191
- m as a,
192
- w as b,
193
- P as c,
194
- I as g,
195
- V as r,
196
- l as v
197
- };
@@ -1 +0,0 @@
1
- "use strict";const O=require("@babel/parser"),w=require("@babel/traverse"),C=require("@babel/generator"),K=require("@babel/types"),F=require("path"),R=require("fs"),z=require("./source-map-rHHEdpre.cjs");function V(d){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const o in d)if(o!=="default"){const L=Object.getOwnPropertyDescriptor(d,o);Object.defineProperty(t,o,L.get?L:{enumerable:!0,get:()=>d[o]})}}return t.default=d,Object.freeze(t)}const e=V(K),W=new Set(["register","setupInterceptors","initializeConfigLoader","initializeWorkerPoolPatching"]),M=[/instrumentation\.(ts|js|tsx|jsx)$/,/unifiedInterceptor\.(ts|js)$/];let D=!1;const _=w.default||w,q=C.default||C;function $(d){const t=[];for(const o of d)e.isIdentifier(o)?t.push(o.name):e.isRestElement(o)&&e.isIdentifier(o.argument)?t.push(`...${o.argument.name}`):e.isAssignmentPattern(o)&&e.isIdentifier(o.left)?t.push(o.left.name):e.isObjectPattern(o)?t.push("{}"):e.isArrayPattern(o)?t.push("[]"):t.push("_");return t}function A(d){let t=!1;return _(d,{ImportDeclaration(o){e.isStringLiteral(o.node.source)&&o.node.source.value==="@sailfish-ai/sf-veritas"&&o.node.specifiers.some(L=>e.isImportSpecifier(L)&&e.isIdentifier(L.imported)&&L.imported.name==="captureFunctionSpan")&&(t=!0,o.stop())},VariableDeclarator(o){if(e.isObjectPattern(o.node.id)&&e.isCallExpression(o.node.init)&&e.isIdentifier(o.node.init.callee)&&o.node.init.callee.name==="require"){const L=o.node.init.arguments;L.length>0&&e.isStringLiteral(L[0])&&L[0].value==="@sailfish-ai/sf-veritas"&&o.node.id.properties.some(I=>e.isObjectProperty(I)&&e.isIdentifier(I.key)&&I.key.name==="captureFunctionSpan")&&(t=!0,o.stop())}}}),t}function G(d){let t=!1;return _(d,{CallExpression(o){e.isIdentifier(o.node.callee)&&o.node.callee.name==="require"&&(t=!0,o.stop())},MemberExpression(o){!e.isIdentifier(o.node.object)||o.node.object.name!=="module"&&o.node.object.name!=="exports"||(t=!0,o.stop())}}),t}exports.setSkipTypeScriptPlugin=function(d){D=d},exports.transformFunctionSpans=async function(d,t,o={}){const{projectRoot:L=process.cwd(),includeNodeModules:I=[],debug:u=!1}=o;if(t.includes("node_modules")&&!I.some(n=>t.includes(`node_modules/${n}`)))return{code:d,modified:!1,functionsWrapped:0};if(M.some(n=>n.test(t)))return u&&console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${t}`),{code:d,modified:!1,functionsWrapped:0};const k=F.relative(L,t).replace(/\\/g,"/");let h;u&&console.log(`[FuncSpan Transform] Processing: ${k}`);try{h=O.parse(d,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy","classProperties","objectRestSpread","asyncGenerators","dynamicImport","optionalCatchBinding","optionalChaining","nullishCoalescingOperator"]})}catch(n){return u&&console.error(`[FuncSpan Transform] Parse error in ${k}:`,n),{code:d,modified:!1,functionsWrapped:0}}let v=null,T=null;try{const n=R.readFileSync(`${t}.map`,"utf-8");v=await new z.sourceMapExports.SourceMapConsumer(JSON.parse(n))}catch{}const E=(n,r)=>{if(v){const i=v.originalPositionFor({line:n,column:r});if(i.line!==null&&i.column!==null)return!T&&i.source&&(T=i.source),{line:i.line,column:i.column,source:i.source||void 0}}return{line:n,column:r}};let x=!1,S=0;const g=new Set;if(_(h,{FunctionDeclaration(n){const r=n.node.id?.name;if(!r)return;if(W.has(r))return void(u&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${r}`));const i=`decl_${r}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping function declaration: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l;let p=t;l.source&&(p=F.resolve(F.dirname(t),l.source)),!u||m===s&&c===a||console.log(`[FuncSpan Transform] Mapped ${s}:${a} → ${m}:${c} in ${p}`);const y=$(n.node.params),f=e.callExpression(e.identifier("captureFunctionSpan"),[e.identifier(r),e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(j=>e.stringLiteral(j))))])]),b=e.expressionStatement(e.assignmentExpression("=",e.identifier(r),f));n.insertAfter(b),x=!0,S++,g.add(i)},VariableDeclarator(n){const r=n.node.id,i=n.node.init;if(!e.isIdentifier(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=r.name;if(W.has(s))return void(u&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${s}`));const a=`var_${s}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping variable function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c;let f=t;c.source&&(f=F.resolve(F.dirname(t),c.source)),!u||p===l&&y===m||console.log(`[FuncSpan Transform] Mapped ${l}:${m} → ${p}:${y} in ${f}`);const b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.init=j,x=!0,S++,g.add(a)},ClassMethod(n){if(n.node.kind==="constructor"||n.node.kind==="get"||n.node.kind==="set")return;const r=e.isIdentifier(n.node.key)?n.node.key.name:"anonymous",i=`method_${r}_${n.node.start}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping class method: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l,p=t,y=$(n.node.params),f=n.node.body,b=e.functionExpression(null,n.node.params,f,n.node.generator,n.node.async),j=e.callExpression(e.identifier("captureFunctionSpan"),[b,e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(N=>e.stringLiteral(N))))])]),P=e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(j,e.identifier("call")),[e.thisExpression(),e.spreadElement(e.identifier("arguments"))]))]);n.node.body=P,x=!0,S++,g.add(i)},ObjectMethod(n){if(n.node.kind==="get"||n.node.kind==="set")return;const r=e.isIdentifier(n.node.key)?n.node.key.name:e.isStringLiteral(n.node.key)?n.node.key.value:"anonymous",i=`objmethod_${r}_${n.node.start}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping object method: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l;let p=t;l.source&&(p=F.resolve(F.dirname(t),l.source));const y=$(n.node.params),f=e.functionExpression(e.identifier(r),n.node.params,n.node.body,n.node.generator,n.node.async),b=e.callExpression(e.identifier("captureFunctionSpan"),[f,e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(P=>e.stringLiteral(P))))])]),j=e.objectProperty(n.node.key,b,n.node.computed,!1);n.replaceWith(j),x=!0,S++,g.add(i)},ClassProperty(n){const r=n.node.key,i=n.node.value;if(!e.isIdentifier(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=r.name,a=`classprop_${s}_${n.node.start}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping class property function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c;let f=t;c.source&&(f=F.resolve(F.dirname(t),c.source));const b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=j,x=!0,S++,g.add(a)},ObjectProperty(n){const r=n.node.key,i=n.node.value;if(!e.isIdentifier(r)&&!e.isStringLiteral(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=e.isIdentifier(r)?r.name:r.value,a=`objprop_${s}_${n.node.start}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping object property function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c;let f=t;c.source&&(f=F.resolve(F.dirname(t),c.source));const b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=j,x=!0,S++,g.add(a)}}),x&&!A(h))if(G(h)){const n=e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"),!1,!0)]),e.callExpression(e.identifier("require"),[e.stringLiteral("@sailfish-ai/sf-veritas")]))]);h.program.body.unshift(n)}else{const n=e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"))],e.stringLiteral("@sailfish-ai/sf-veritas"));h.program.body.unshift(n)}if(S>0){const n=q(h,{retainLines:!0,compact:!1,sourceMaps:!0,sourceFileName:t},d);return u&&console.log(`[FuncSpan Transform] ✅ Wrapped ${S} functions in ${k}`),{code:n.code,map:n.map,modified:!0,functionsWrapped:S}}return{code:d,modified:!1,functionsWrapped:0}},exports.transformFunctionSpansSync=function(d,t,o={}){const{projectRoot:L=process.cwd(),includeNodeModules:I=[],debug:u=!1,parseAsJavaScript:k=!1}=o;if(t.includes("node_modules")&&!I.some(n=>t.includes(`node_modules/${n}`)))return{code:d,modified:!1,functionsWrapped:0};if(M.some(n=>n.test(t)))return u&&console.log(`[FuncSpan Transform] SKIPPING instrumentation entry point file: ${t}`),{code:d,modified:!1,functionsWrapped:0};const h=F.relative(L,t).replace(/\\/g,"/");let v;u&&console.log(`[FuncSpan Transform] Processing: ${h}`);const T=["jsx","decorators-legacy","classProperties","objectRestSpread","asyncGenerators","dynamicImport","optionalCatchBinding","optionalChaining","nullishCoalescingOperator"];D||k||T.unshift("typescript");try{v=O.parse(d,{sourceType:"module",plugins:T})}catch(n){return u&&console.error(`[FuncSpan Transform] Parse error in ${h}:`,n),{code:d,modified:!1,functionsWrapped:0}}const E=(n,r)=>({line:n,column:r});let x=!1,S=0;const g=new Set;if(_(v,{FunctionDeclaration(n){const r=n.node.id?.name;if(!r)return;if(W.has(r))return void(u&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${r}`));const i=`decl_${r}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping function declaration: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l,p=t,y=$(n.node.params),f=e.callExpression(e.identifier("captureFunctionSpan"),[e.identifier(r),e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(j=>e.stringLiteral(j))))])]),b=e.expressionStatement(e.assignmentExpression("=",e.identifier(r),f));n.insertAfter(b),x=!0,S++,g.add(i)},VariableDeclarator(n){const r=n.node.id,i=n.node.init;if(!e.isIdentifier(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=r.name;if(W.has(s))return void(u&&console.log(`[FuncSpan Transform] SKIPPING entry point function: ${s}`));const a=`var_${s}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping variable function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c,f=t,b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.init=j,x=!0,S++,g.add(a)},ClassMethod(n){if(n.node.kind==="constructor"||n.node.kind==="get"||n.node.kind==="set")return;const r=e.isIdentifier(n.node.key)?n.node.key.name:"anonymous",i=`method_${r}_${n.node.start}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping class method: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l,p=t,y=$(n.node.params),f=n.node.body,b=e.functionExpression(null,n.node.params,f,n.node.generator,n.node.async),j=e.callExpression(e.identifier("captureFunctionSpan"),[b,e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(N=>e.stringLiteral(N))))])]),P=e.blockStatement([e.returnStatement(e.callExpression(e.memberExpression(j,e.identifier("call")),[e.thisExpression(),e.spreadElement(e.identifier("arguments"))]))]);n.node.body=P,x=!0,S++,g.add(i)},ObjectMethod(n){if(n.node.kind==="get"||n.node.kind==="set")return;const r=e.isIdentifier(n.node.key)?n.node.key.name:e.isStringLiteral(n.node.key)?n.node.key.value:"anonymous",i=`objmethod_${r}_${n.node.start}`;if(g.has(i))return;u&&console.log(`[FuncSpan Transform] Wrapping object method: ${r}`);const s=n.node.loc?.start.line??0,a=n.node.loc?.start.column??0,l=E(s,a),{line:m,column:c}=l,p=t,y=$(n.node.params),f=e.functionExpression(e.identifier(r),n.node.params,n.node.body,n.node.generator,n.node.async),b=e.callExpression(e.identifier("captureFunctionSpan"),[f,e.stringLiteral(r),e.stringLiteral(p),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(m)),e.objectProperty(e.identifier("column"),e.numericLiteral(c)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(y.map(P=>e.stringLiteral(P))))])]),j=e.objectProperty(n.node.key,b,n.node.computed,!1);n.replaceWith(j),x=!0,S++,g.add(i)},ClassProperty(n){const r=n.node.key,i=n.node.value;if(!e.isIdentifier(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=r.name,a=`classprop_${s}_${n.node.start}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping class property function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c,f=t,b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=j,x=!0,S++,g.add(a)},ObjectProperty(n){const r=n.node.key,i=n.node.value;if(!e.isIdentifier(r)&&!e.isStringLiteral(r)||!i||!e.isFunctionExpression(i)&&!e.isArrowFunctionExpression(i))return;const s=e.isIdentifier(r)?r.name:r.value,a=`objprop_${s}_${n.node.start}`;if(g.has(a))return;u&&console.log(`[FuncSpan Transform] Wrapping object property function: ${s}`);const l=i.loc?.start.line??0,m=i.loc?.start.column??0,c=E(l,m),{line:p,column:y}=c,f=t,b=$(i.params),j=e.callExpression(e.identifier("captureFunctionSpan"),[i,e.stringLiteral(s),e.stringLiteral(f),e.objectExpression([e.objectProperty(e.identifier("line"),e.numericLiteral(p)),e.objectProperty(e.identifier("column"),e.numericLiteral(y)),e.objectProperty(e.identifier("paramNames"),e.arrayExpression(b.map(P=>e.stringLiteral(P))))])]);n.node.value=j,x=!0,S++,g.add(a)}}),x&&!A(v))if(G(v)){const n=e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern([e.objectProperty(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"),!1,!0)]),e.callExpression(e.identifier("require"),[e.stringLiteral("@sailfish-ai/sf-veritas")]))]);v.program.body.unshift(n)}else{const n=e.importDeclaration([e.importSpecifier(e.identifier("captureFunctionSpan"),e.identifier("captureFunctionSpan"))],e.stringLiteral("@sailfish-ai/sf-veritas"));v.program.body.unshift(n)}if(S>0){const n=q(v,{retainLines:!0,compact:!1,sourceMaps:!0,sourceFileName:t},d);return u&&console.log(`[FuncSpan Transform] ✅ Wrapped ${S} functions in ${h}`),{code:n.code,map:n.map,modified:!0,functionsWrapped:S}}return{code:d,modified:!1,functionsWrapped:0}};