@zintrust/core 0.4.98 → 0.4.99
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.
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ export declare const validateRequiredParams: (params: Record<string, unknown>, r
|
|
|
18
18
|
* Create standardized API error response
|
|
19
19
|
*/
|
|
20
20
|
export declare const createApiError: (message: string, service: string) => Error;
|
|
21
|
-
export declare const tracedFetch: (url: string, options: RequestInit,
|
|
21
|
+
export declare const tracedFetch: (url: string, options: RequestInit, trace?: TracedFetchTraceOptions) => Promise<Response>;
|
|
22
22
|
/**
|
|
23
23
|
* Common fetch wrapper with error handling
|
|
24
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExternalServiceUtils.d.ts","sourceRoot":"","sources":["../../../src/common/ExternalServiceUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"ExternalServiceUtils.d.ts","sourceRoot":"","sources":["../../../src/common/ExternalServiceUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAkHF;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,EAAE,iBAAa,KAAG,MAe1D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,UAAU,MAAM,EAAE,KACjB,IAWF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,KAAG,KAEjE,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,KAAK,MAAM,EACX,SAAS,WAAW,EACpB,QAAQ,uBAAuB,KAC9B,OAAO,CAAC,QAAQ,CAWlB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,GACpB,KAAK,MAAM,EACX,SAAS,WAAW,EACpB,QAAQ,uBAAuB,KAC9B,OAAO,CAAC,QAAQ,CAclB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAChC,SAAS,OAAO,EAChB,OAAO,CAAC,EACR,QAAQ,MAAM,KACb;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAY9C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW;IACtB;;OAEG;iBACU,MAAM;IAMnB;;OAEG;oBACa,MAAM;IAItB;;OAEG;8BACuB,MAAM,GAAG,OAAO;IAI1C;;OAEG;gCAEO,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,eACpD,MAAM,UACX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;IAYjC;;OAEG;+BAEO,WAAW,GAAG,WAAW,eACpB,MAAM,SACZ,KAAK,UACJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;CASlC,CAAC"}
|
|
@@ -2,8 +2,92 @@
|
|
|
2
2
|
* Shared Utilities for External Service Drivers
|
|
3
3
|
* Common patterns for API calls, environment variable reading, and error handling
|
|
4
4
|
*/
|
|
5
|
+
import { SystemTraceBridge } from '../trace/SystemTraceBridge.js';
|
|
5
6
|
import { Env } from '../config/env.js';
|
|
6
7
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
8
|
+
const isHeaderEntriesLike = (value) => {
|
|
9
|
+
return typeof value === 'object' && value !== null && 'entries' in value;
|
|
10
|
+
};
|
|
11
|
+
const isHeaderTuple = (value) => {
|
|
12
|
+
return (Array.isArray(value) &&
|
|
13
|
+
value.length === 2 &&
|
|
14
|
+
typeof value[0] === 'string' &&
|
|
15
|
+
typeof value[1] === 'string');
|
|
16
|
+
};
|
|
17
|
+
const isHeaderTupleArray = (value) => {
|
|
18
|
+
return Array.isArray(value) && value.every(isHeaderTuple);
|
|
19
|
+
};
|
|
20
|
+
const asHeadersInitLocal = (headers) => {
|
|
21
|
+
return headers;
|
|
22
|
+
};
|
|
23
|
+
const asBodyInitLocal = (body) => {
|
|
24
|
+
return body;
|
|
25
|
+
};
|
|
26
|
+
const headersToRecord = (headers) => {
|
|
27
|
+
if (headers === undefined)
|
|
28
|
+
return {};
|
|
29
|
+
if (headers instanceof Headers) {
|
|
30
|
+
return Object.fromEntries(headers.entries());
|
|
31
|
+
}
|
|
32
|
+
if (isHeaderEntriesLike(headers)) {
|
|
33
|
+
return Object.fromEntries(headers.entries());
|
|
34
|
+
}
|
|
35
|
+
if (isHeaderTupleArray(headers)) {
|
|
36
|
+
return Object.fromEntries(headers);
|
|
37
|
+
}
|
|
38
|
+
return Object.fromEntries(Object.entries(headers).filter((entry) => typeof entry[1] === 'string'));
|
|
39
|
+
};
|
|
40
|
+
const bodyToTracePayload = (body) => {
|
|
41
|
+
if (body === null || body === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
if (typeof body === 'string') {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(body);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return body;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (body instanceof URLSearchParams) {
|
|
52
|
+
return body.toString();
|
|
53
|
+
}
|
|
54
|
+
if (typeof FormData !== 'undefined' &&
|
|
55
|
+
body instanceof FormData &&
|
|
56
|
+
typeof body.entries === 'function') {
|
|
57
|
+
return Array.from(body.entries()).map(([key, value]) => [key, String(value)]);
|
|
58
|
+
}
|
|
59
|
+
return '[stream]';
|
|
60
|
+
};
|
|
61
|
+
const captureResponseBody = async (response) => {
|
|
62
|
+
try {
|
|
63
|
+
return await response.clone().text();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const emitTrace = async (url, options, trace, duration, response, error) => {
|
|
70
|
+
const responseBody = response ? await captureResponseBody(response) : undefined;
|
|
71
|
+
let traceError;
|
|
72
|
+
if (error instanceof Error) {
|
|
73
|
+
traceError = error.message;
|
|
74
|
+
}
|
|
75
|
+
else if (error !== undefined) {
|
|
76
|
+
traceError = String(error);
|
|
77
|
+
}
|
|
78
|
+
SystemTraceBridge.emitHttpClient({
|
|
79
|
+
source: trace?.source,
|
|
80
|
+
method: String(options.method ?? 'GET').toUpperCase(),
|
|
81
|
+
url,
|
|
82
|
+
requestHeaders: headersToRecord(asHeadersInitLocal(options.headers)),
|
|
83
|
+
responseStatus: response?.status,
|
|
84
|
+
duration,
|
|
85
|
+
requestBody: bodyToTracePayload(asBodyInitLocal(options.body)),
|
|
86
|
+
responseHeaders: headersToRecord(response?.headers),
|
|
87
|
+
responseBody,
|
|
88
|
+
error: traceError,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
7
91
|
/**
|
|
8
92
|
* Environment variable reader with fallback support
|
|
9
93
|
* Handles both Env.get() and process.env for maximum compatibility
|
|
@@ -44,8 +128,17 @@ export const validateRequiredParams = (params, required) => {
|
|
|
44
128
|
export const createApiError = (message, service) => {
|
|
45
129
|
return ErrorFactory.createValidationError(`${service} API error: ${message}`);
|
|
46
130
|
};
|
|
47
|
-
export const tracedFetch = async (url, options,
|
|
48
|
-
|
|
131
|
+
export const tracedFetch = async (url, options, trace) => {
|
|
132
|
+
const startTime = Date.now();
|
|
133
|
+
try {
|
|
134
|
+
const response = await globalThis.fetch(url, options);
|
|
135
|
+
await emitTrace(url, options, trace, Date.now() - startTime, response);
|
|
136
|
+
return response;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
await emitTrace(url, options, trace, Date.now() - startTime, undefined, error);
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
49
142
|
};
|
|
50
143
|
/**
|
|
51
144
|
* Common fetch wrapper with error handling
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zintrust/core v0.4.
|
|
2
|
+
* @zintrust/core v0.4.99
|
|
3
3
|
*
|
|
4
4
|
* ZinTrust Framework - Production-Grade TypeScript Backend
|
|
5
5
|
* Built for performance, type safety, and exceptional developer experience
|
|
6
6
|
*
|
|
7
7
|
* Build Information:
|
|
8
|
-
* Built: 2026-04-
|
|
8
|
+
* Built: 2026-04-12T10:03:16.711Z
|
|
9
9
|
* Node: >=20.0.0
|
|
10
10
|
* License: MIT
|
|
11
11
|
*
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* Available at runtime for debugging and health checks
|
|
22
22
|
*/
|
|
23
23
|
export const ZINTRUST_VERSION = '0.1.41';
|
|
24
|
-
export const ZINTRUST_BUILD_DATE = '2026-04-
|
|
24
|
+
export const ZINTRUST_BUILD_DATE = '2026-04-12T10:03:16.675Z'; // Replaced during build
|
|
25
25
|
export { Application } from './boot/Application.js';
|
|
26
26
|
export { AwsSigV4 } from './common/index.js';
|
|
27
27
|
export { SignedRequest } from './security/SignedRequest.js';
|