@zintrust/core 0.4.81 → 0.4.84
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 +1 -1
- package/src/cache/Cache.d.ts.map +1 -1
- package/src/cache/Cache.js +11 -10
- package/src/index.js +3 -3
- package/src/orm/adapters/MySQLProxyAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLProxyAdapter.js +62 -1
- package/src/proxy/d1/ZintrustD1Proxy.d.ts.map +1 -1
- package/src/proxy/d1/ZintrustD1Proxy.js +10 -0
- package/src/proxy/kv/ZintrustKvProxy.d.ts.map +1 -1
- package/src/proxy/kv/ZintrustKvProxy.js +14 -0
- package/src/proxy/mongodb/MongoDBProxyServer.d.ts.map +1 -1
- package/src/proxy/mongodb/MongoDBProxyServer.js +8 -0
- package/src/proxy/mysql/MySqlProxyServer.d.ts.map +1 -1
- package/src/proxy/mysql/MySqlProxyServer.js +5 -0
- package/src/proxy/postgres/PostgresProxyServer.d.ts.map +1 -1
- package/src/proxy/postgres/PostgresProxyServer.js +5 -0
- package/src/proxy/redis/RedisProxyServer.d.ts.map +1 -1
- package/src/proxy/redis/RedisProxyServer.js +3 -0
- package/src/proxy/smtp/SmtpProxyServer.d.ts.map +1 -1
- package/src/proxy/smtp/SmtpProxyServer.js +4 -0
- package/src/proxy/sqlserver/SqlServerProxyServer.d.ts.map +1 -1
- package/src/proxy/sqlserver/SqlServerProxyServer.js +5 -0
- package/src/tools/http/Http.d.ts.map +1 -1
- package/src/tools/http/Http.js +72 -4
- package/src/tools/mail/index.d.ts.map +1 -1
- package/src/tools/mail/index.js +1 -1
- package/src/tools/notification/Service.d.ts.map +1 -1
- package/src/tools/notification/Service.js +8 -5
- package/src/trace/SystemTraceBridge.d.ts +16 -4
- package/src/trace/SystemTraceBridge.d.ts.map +1 -1
- package/src/trace/SystemTraceBridge.js +20 -8
- package/src/trace/SystemTraceWorkerBridge.d.ts +7 -0
- package/src/trace/SystemTraceWorkerBridge.d.ts.map +1 -0
- package/src/trace/SystemTraceWorkerBridge.js +35 -0
package/package.json
CHANGED
package/src/cache/Cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../../src/cache/Cache.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"Cache.d.ts","sourceRoot":"","sources":["../../../src/cache/Cache.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAkMtD,KAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3C,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,WAAW,CAAC;CAC9B,CAAC,CAAC;AA8FH,eAAO,MAAM,KAAK;UAhMC,CAAC,OAAO,MAAM,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;UAkBlC,CAAC,OAAO,MAAM,SAAS,CAAC,QAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;kBAkBjD,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;iBAiBtB,OAAO,CAAC,IAAI,CAAC;eAgBb,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;qBAkB3B,WAAW;mBAaX,MAAM,KAAG,UAAU;iBAuFvB,IAAI;EAcpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,KAAK;UA9MC,CAAC,OAAO,MAAM,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;UAkBlC,CAAC,OAAO,MAAM,SAAS,CAAC,QAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;kBAkBjD,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;iBAiBtB,OAAO,CAAC,IAAI,CAAC;eAgBb,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;qBAkB3B,WAAW;mBAaX,MAAM,KAAG,UAAU;iBAuFvB,IAAI;EAmBI,CAAC"}
|
package/src/cache/Cache.js
CHANGED
|
@@ -15,6 +15,7 @@ import { cacheConfig } from '../config/cache.js';
|
|
|
15
15
|
import { Env } from '../config/env.js';
|
|
16
16
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
17
17
|
const instances = new Map();
|
|
18
|
+
const DEFAULT_STORE_NAME = 'default';
|
|
18
19
|
/**
|
|
19
20
|
* Auto-prefix cache keys with 'zt:' if not already prefixed
|
|
20
21
|
*/
|
|
@@ -88,7 +89,7 @@ const get = async (key) => {
|
|
|
88
89
|
const prefixedKey = autoPrefixKey(key);
|
|
89
90
|
const startedAt = Date.now();
|
|
90
91
|
const value = await getDriverInstance().get(prefixedKey);
|
|
91
|
-
SystemTraceBridge.emitCache('get', prefixedKey, Date.now() - startedAt, value !== null);
|
|
92
|
+
SystemTraceBridge.emitCache('get', prefixedKey, Date.now() - startedAt, value !== null, value, DEFAULT_STORE_NAME);
|
|
92
93
|
return value;
|
|
93
94
|
};
|
|
94
95
|
/**
|
|
@@ -98,7 +99,7 @@ const set = async (key, value, ttl) => {
|
|
|
98
99
|
const prefixedKey = autoPrefixKey(key);
|
|
99
100
|
const startedAt = Date.now();
|
|
100
101
|
await getDriverInstance().set(prefixedKey, value, ttl);
|
|
101
|
-
SystemTraceBridge.emitCache('set', prefixedKey, Date.now() - startedAt);
|
|
102
|
+
SystemTraceBridge.emitCache('set', prefixedKey, Date.now() - startedAt, undefined, value, DEFAULT_STORE_NAME, ttl);
|
|
102
103
|
};
|
|
103
104
|
/**
|
|
104
105
|
* Remove an item from the cache
|
|
@@ -107,7 +108,7 @@ const del = async (key) => {
|
|
|
107
108
|
const prefixedKey = autoPrefixKey(key);
|
|
108
109
|
const startedAt = Date.now();
|
|
109
110
|
await getDriverInstance().delete(prefixedKey);
|
|
110
|
-
SystemTraceBridge.emitCache('delete', prefixedKey, Date.now() - startedAt);
|
|
111
|
+
SystemTraceBridge.emitCache('delete', prefixedKey, Date.now() - startedAt, undefined, undefined, DEFAULT_STORE_NAME);
|
|
111
112
|
};
|
|
112
113
|
/**
|
|
113
114
|
* Clear all items from the cache
|
|
@@ -115,7 +116,7 @@ const del = async (key) => {
|
|
|
115
116
|
const clear = async () => {
|
|
116
117
|
const startedAt = Date.now();
|
|
117
118
|
await getDriverInstance().clear();
|
|
118
|
-
SystemTraceBridge.emitCache('clear', 'zt:*', Date.now() - startedAt);
|
|
119
|
+
SystemTraceBridge.emitCache('clear', 'zt:*', Date.now() - startedAt, undefined, undefined, DEFAULT_STORE_NAME);
|
|
119
120
|
};
|
|
120
121
|
/**
|
|
121
122
|
* Check if an item exists in the cache
|
|
@@ -124,7 +125,7 @@ const has = async (key) => {
|
|
|
124
125
|
const prefixedKey = autoPrefixKey(key);
|
|
125
126
|
const startedAt = Date.now();
|
|
126
127
|
const exists = await getDriverInstance().has(prefixedKey);
|
|
127
|
-
SystemTraceBridge.emitCache('has', prefixedKey, Date.now() - startedAt, exists);
|
|
128
|
+
SystemTraceBridge.emitCache('has', prefixedKey, Date.now() - startedAt, exists, undefined, DEFAULT_STORE_NAME);
|
|
128
129
|
return exists;
|
|
129
130
|
};
|
|
130
131
|
/**
|
|
@@ -138,31 +139,31 @@ const store = (name) => {
|
|
|
138
139
|
const prefixedKey = autoPrefixKey(key);
|
|
139
140
|
const startedAt = Date.now();
|
|
140
141
|
const value = await getDriverInstance(name).get(prefixedKey);
|
|
141
|
-
SystemTraceBridge.emitCache('get', prefixedKey, Date.now() - startedAt, value !== null);
|
|
142
|
+
SystemTraceBridge.emitCache('get', prefixedKey, Date.now() - startedAt, value !== null, value, String(name ?? DEFAULT_STORE_NAME));
|
|
142
143
|
return value;
|
|
143
144
|
};
|
|
144
145
|
const setInStore = async (key, value, ttl) => {
|
|
145
146
|
const prefixedKey = autoPrefixKey(key);
|
|
146
147
|
const startedAt = Date.now();
|
|
147
148
|
await getDriverInstance(name).set(prefixedKey, value, ttl);
|
|
148
|
-
SystemTraceBridge.emitCache('set', prefixedKey, Date.now() - startedAt);
|
|
149
|
+
SystemTraceBridge.emitCache('set', prefixedKey, Date.now() - startedAt, undefined, value, String(name ?? DEFAULT_STORE_NAME), ttl);
|
|
149
150
|
};
|
|
150
151
|
const delFromStore = async (key) => {
|
|
151
152
|
const prefixedKey = autoPrefixKey(key);
|
|
152
153
|
const startedAt = Date.now();
|
|
153
154
|
await getDriverInstance(name).delete(prefixedKey);
|
|
154
|
-
SystemTraceBridge.emitCache('delete', prefixedKey, Date.now() - startedAt);
|
|
155
|
+
SystemTraceBridge.emitCache('delete', prefixedKey, Date.now() - startedAt, undefined, undefined, String(name ?? DEFAULT_STORE_NAME));
|
|
155
156
|
};
|
|
156
157
|
const clearStore = async () => {
|
|
157
158
|
const startedAt = Date.now();
|
|
158
159
|
await getDriverInstance(name).clear();
|
|
159
|
-
SystemTraceBridge.emitCache('clear', `store:${String(name ?? 'default')}`, Date.now() - startedAt);
|
|
160
|
+
SystemTraceBridge.emitCache('clear', `store:${String(name ?? 'default')}`, Date.now() - startedAt, undefined, undefined, String(name ?? DEFAULT_STORE_NAME));
|
|
160
161
|
};
|
|
161
162
|
const hasInStore = async (key) => {
|
|
162
163
|
const prefixedKey = autoPrefixKey(key);
|
|
163
164
|
const startedAt = Date.now();
|
|
164
165
|
const exists = await getDriverInstance(name).has(prefixedKey);
|
|
165
|
-
SystemTraceBridge.emitCache('has', prefixedKey, Date.now() - startedAt, exists);
|
|
166
|
+
SystemTraceBridge.emitCache('has', prefixedKey, Date.now() - startedAt, exists, undefined, String(name ?? DEFAULT_STORE_NAME));
|
|
166
167
|
return exists;
|
|
167
168
|
};
|
|
168
169
|
const getStoreDriver = () => {
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zintrust/core v0.4.
|
|
2
|
+
* @zintrust/core v0.4.84
|
|
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-08T17:43:03.695Z
|
|
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-08T17:43:03.659Z'; // 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';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MySQLProxyAdapter.d.ts","sourceRoot":"","sources":["../../../../src/orm/adapters/MySQLProxyAdapter.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAgBH,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"MySQLProxyAdapter.d.ts","sourceRoot":"","sources":["../../../../src/orm/adapters/MySQLProxyAdapter.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAgBH,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAkU1F,eAAO,MAAM,iBAAiB;oBACZ,cAAc,GAAG,gBAAgB;EAcjD,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|
|
@@ -33,18 +33,79 @@ const buildSignedProxyConfig = (settings) => {
|
|
|
33
33
|
};
|
|
34
34
|
const isQueryResponse = (value) => isRecord(value) && Array.isArray(value['rows']) && typeof value['rowCount'] === 'number';
|
|
35
35
|
const isQueryOneResponse = (value) => isRecord(value) && 'row' in value;
|
|
36
|
+
const hasText = (value) => typeof value === 'string' && value.trim() !== '';
|
|
37
|
+
const describeErrorBody = (body) => {
|
|
38
|
+
const bodyCode = hasText(body['code']) ? body['code'].trim() : '';
|
|
39
|
+
const bodyMessage = hasText(body['message']) ? body['message'].trim() : '';
|
|
40
|
+
if (bodyCode !== '' && bodyMessage !== '')
|
|
41
|
+
return `${bodyCode}: ${bodyMessage}`;
|
|
42
|
+
if (bodyCode !== '')
|
|
43
|
+
return bodyCode;
|
|
44
|
+
if (bodyMessage !== '')
|
|
45
|
+
return bodyMessage;
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|
|
48
|
+
const describeErrorRecord = (record) => {
|
|
49
|
+
const body = record['body'];
|
|
50
|
+
if (isRecord(body)) {
|
|
51
|
+
const describedBody = describeErrorBody(body);
|
|
52
|
+
if (describedBody !== undefined)
|
|
53
|
+
return describedBody;
|
|
54
|
+
}
|
|
55
|
+
const nestedDetails = describeErrorDetails(record['details']);
|
|
56
|
+
if (nestedDetails !== undefined)
|
|
57
|
+
return nestedDetails;
|
|
58
|
+
if (hasText(record['message']))
|
|
59
|
+
return record['message'].trim();
|
|
60
|
+
if (hasText(record['code']))
|
|
61
|
+
return record['code'].trim();
|
|
62
|
+
return undefined;
|
|
63
|
+
};
|
|
64
|
+
const describeErrorDetails = (details) => {
|
|
65
|
+
if (hasText(details))
|
|
66
|
+
return details.trim();
|
|
67
|
+
if (!isRecord(details))
|
|
68
|
+
return undefined;
|
|
69
|
+
return describeErrorRecord(details);
|
|
70
|
+
};
|
|
71
|
+
const withMaybeProperty = (target, key, value) => {
|
|
72
|
+
if (value === undefined)
|
|
73
|
+
return target;
|
|
74
|
+
return { ...target, [key]: value };
|
|
75
|
+
};
|
|
76
|
+
const toLoggedError = (error) => {
|
|
77
|
+
if (!(error instanceof Error)) {
|
|
78
|
+
return { message: String(error) };
|
|
79
|
+
}
|
|
80
|
+
const maybeError = error;
|
|
81
|
+
const detailSummary = describeErrorDetails(maybeError.details);
|
|
82
|
+
const message = detailSummary !== undefined && !error.message.includes(detailSummary)
|
|
83
|
+
? `${error.message} (${detailSummary})`
|
|
84
|
+
: error.message;
|
|
85
|
+
let loggedError = {
|
|
86
|
+
message,
|
|
87
|
+
};
|
|
88
|
+
loggedError = withMaybeProperty(loggedError, 'code', hasText(maybeError.code) ? maybeError.code : undefined);
|
|
89
|
+
loggedError = withMaybeProperty(loggedError, 'statusCode', typeof maybeError.statusCode === 'number' ? maybeError.statusCode : undefined);
|
|
90
|
+
loggedError = withMaybeProperty(loggedError, 'details', maybeError.details);
|
|
91
|
+
return loggedError;
|
|
92
|
+
};
|
|
36
93
|
const requestProxy = async (state, path, payload) => {
|
|
37
94
|
try {
|
|
38
95
|
return await SqlProxyHttpAdapterShared.requestProxy(state.signed, path, payload);
|
|
39
96
|
}
|
|
40
97
|
catch (error) {
|
|
98
|
+
const loggedError = toLoggedError(error);
|
|
41
99
|
Logger.error('[MySQLProxyAdapter] Proxy request failed', {
|
|
42
100
|
path,
|
|
43
101
|
baseUrl: state.settings.baseUrl,
|
|
44
102
|
timeoutMs: state.settings.timeoutMs,
|
|
45
103
|
hasKeyId: (state.settings.keyId ?? '').trim() !== '',
|
|
46
104
|
hasSecret: (state.settings.secret ?? '').trim() !== '',
|
|
47
|
-
error:
|
|
105
|
+
error: loggedError.message,
|
|
106
|
+
...withMaybeProperty({}, 'errorCode', loggedError.code),
|
|
107
|
+
...withMaybeProperty({}, 'errorStatusCode', loggedError.statusCode),
|
|
108
|
+
...withMaybeProperty({}, 'errorDetails', loggedError.details),
|
|
48
109
|
});
|
|
49
110
|
throw error;
|
|
50
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZintrustD1Proxy.d.ts","sourceRoot":"","sources":["../../../../src/proxy/d1/ZintrustD1Proxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ZintrustD1Proxy.d.ts","sourceRoot":"","sources":["../../../../src/proxy/d1/ZintrustD1Proxy.ts"],"names":[],"mappings":"AAUA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC;AAEjD,KAAK,qBAAqB,GAAG;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,GAAG,EAAE;QACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QACtC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QACrE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;QAChE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;KAChG,CAAC;IACF,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,KAAK,OAAO,CAAC,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 +1,4 @@
|
|
|
1
|
+
import { SystemTraceWorkerBridge } from '../../trace/SystemTraceWorkerBridge.js';
|
|
1
2
|
import { getEnvInt, json, normalizeBindingName, readAndVerifyJson, toErrorResponse, } from '../CloudflareProxyShared.js';
|
|
2
3
|
import { RequestValidator } from '../RequestValidator.js';
|
|
3
4
|
const DEFAULT_SIGNING_WINDOW_MS = 60_000;
|
|
@@ -143,10 +144,12 @@ const handleQuery = async (request, env) => {
|
|
|
143
144
|
const resolved = await resolveSqlRequest(request, env);
|
|
144
145
|
if (!resolved.ok)
|
|
145
146
|
return resolved.response;
|
|
147
|
+
const startedAt = Date.now();
|
|
146
148
|
const result = await resolved.db
|
|
147
149
|
.prepare(resolved.sql)
|
|
148
150
|
.bind(...resolved.params)
|
|
149
151
|
.all();
|
|
152
|
+
SystemTraceWorkerBridge.emitQuery(resolved.sql, resolved.params, Date.now() - startedAt, 'd1-proxy');
|
|
150
153
|
const rows = result.results ?? [];
|
|
151
154
|
return json(200, { rows, rowCount: rows.length });
|
|
152
155
|
}
|
|
@@ -160,10 +163,12 @@ const handleQueryOne = async (request, env) => {
|
|
|
160
163
|
const resolved = await resolveSqlRequest(request, env);
|
|
161
164
|
if (!resolved.ok)
|
|
162
165
|
return resolved.response;
|
|
166
|
+
const startedAt = Date.now();
|
|
163
167
|
const row = await resolved.db
|
|
164
168
|
.prepare(resolved.sql)
|
|
165
169
|
.bind(...resolved.params)
|
|
166
170
|
.first();
|
|
171
|
+
SystemTraceWorkerBridge.emitQuery(resolved.sql, resolved.params, Date.now() - startedAt, 'd1-proxy');
|
|
167
172
|
return json(200, { row: row ?? null });
|
|
168
173
|
}
|
|
169
174
|
catch (error) {
|
|
@@ -176,10 +181,12 @@ const handleExec = async (request, env) => {
|
|
|
176
181
|
const resolved = await resolveSqlRequest(request, env);
|
|
177
182
|
if (!resolved.ok)
|
|
178
183
|
return resolved.response;
|
|
184
|
+
const startedAt = Date.now();
|
|
179
185
|
const out = await resolved.db
|
|
180
186
|
.prepare(resolved.sql)
|
|
181
187
|
.bind(...resolved.params)
|
|
182
188
|
.run();
|
|
189
|
+
SystemTraceWorkerBridge.emitQuery(resolved.sql, resolved.params, Date.now() - startedAt, 'd1-proxy');
|
|
183
190
|
return json(200, { ok: true, meta: out.meta });
|
|
184
191
|
}
|
|
185
192
|
catch (error) {
|
|
@@ -217,17 +224,20 @@ const handleStatement = async (request, env) => {
|
|
|
217
224
|
if (!isString(sql) || sql.trim() === '') {
|
|
218
225
|
return toErrorResponse(404, 'NOT_FOUND', 'Unknown statementId');
|
|
219
226
|
}
|
|
227
|
+
const startedAt = Date.now();
|
|
220
228
|
if (isMutatingSql(sql)) {
|
|
221
229
|
const out = await resolved.db
|
|
222
230
|
.prepare(sql)
|
|
223
231
|
.bind(...parsed.params)
|
|
224
232
|
.run();
|
|
233
|
+
SystemTraceWorkerBridge.emitQuery(sql, parsed.params, Date.now() - startedAt, 'd1-proxy');
|
|
225
234
|
return json(200, { ok: true, meta: out.meta });
|
|
226
235
|
}
|
|
227
236
|
const out = await resolved.db
|
|
228
237
|
.prepare(sql)
|
|
229
238
|
.bind(...parsed.params)
|
|
230
239
|
.all();
|
|
240
|
+
SystemTraceWorkerBridge.emitQuery(sql, parsed.params, Date.now() - startedAt, 'd1-proxy');
|
|
231
241
|
const rows = out.results ?? [];
|
|
232
242
|
return json(200, { rows, rowCount: rows.length });
|
|
233
243
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZintrustKvProxy.d.ts","sourceRoot":"","sources":["../../../../src/proxy/kv/ZintrustKvProxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ZintrustKvProxy.d.ts","sourceRoot":"","sources":["../../../../src/proxy/kv/ZintrustKvProxy.ts"],"names":[],"mappings":"AAWA,KAAK,qBAAqB,GAAG;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,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,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AA0RF,eAAO,MAAM,eAAe;;;mBAGL,OAAO,OAAO,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;EAqB5D,CAAC;AAEH,eAAe,eAAe,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemTraceWorkerBridge } from '../../trace/SystemTraceWorkerBridge.js';
|
|
1
2
|
import { isObject, isString } from '../../helper/index.js';
|
|
2
3
|
import { getEnvInt, json, normalizeBindingName, readAndVerifyJson, toErrorResponse, } from '../CloudflareProxyShared.js';
|
|
3
4
|
import { RequestValidator } from '../RequestValidator.js';
|
|
@@ -68,15 +69,19 @@ const handleGet = async (request, env) => {
|
|
|
68
69
|
if (!parsed.ok)
|
|
69
70
|
return parsed.response;
|
|
70
71
|
const storageKey = buildStorageKey(env, { namespace: parsed.namespace, key: parsed.key });
|
|
72
|
+
const startedAt = Date.now();
|
|
71
73
|
if (parsed.type === 'json') {
|
|
72
74
|
const value = await resolved.cache.get(storageKey, 'json');
|
|
75
|
+
SystemTraceWorkerBridge.emitCache('get', storageKey, Date.now() - startedAt, value !== null, value, 'kv-proxy');
|
|
73
76
|
return json(200, { value: value ?? null });
|
|
74
77
|
}
|
|
75
78
|
if (parsed.type === 'arrayBuffer') {
|
|
76
79
|
const value = await resolved.cache.get(storageKey, 'arrayBuffer');
|
|
80
|
+
SystemTraceWorkerBridge.emitCache('get', storageKey, Date.now() - startedAt, value !== null, value, 'kv-proxy');
|
|
77
81
|
return json(200, { value: value ?? null });
|
|
78
82
|
}
|
|
79
83
|
const value = await resolved.cache.get(storageKey);
|
|
84
|
+
SystemTraceWorkerBridge.emitCache('get', storageKey, Date.now() - startedAt, value !== null, value, 'kv-proxy');
|
|
80
85
|
return json(200, { value: value ?? null });
|
|
81
86
|
};
|
|
82
87
|
const parsePutPayload = (payload) => {
|
|
@@ -108,11 +113,13 @@ const handlePut = async (request, env) => {
|
|
|
108
113
|
return parsed.response;
|
|
109
114
|
const storageKey = buildStorageKey(env, { namespace: parsed.namespace, key: parsed.key });
|
|
110
115
|
const value = JSON.stringify(parsed.value);
|
|
116
|
+
const startedAt = Date.now();
|
|
111
117
|
const options = {};
|
|
112
118
|
if (parsed.ttlSeconds !== undefined) {
|
|
113
119
|
options.expirationTtl = Math.floor(parsed.ttlSeconds);
|
|
114
120
|
}
|
|
115
121
|
await resolved.cache.put(storageKey, value, options);
|
|
122
|
+
SystemTraceWorkerBridge.emitCache('set', storageKey, Date.now() - startedAt, undefined, parsed.value, 'kv-proxy', parsed.ttlSeconds);
|
|
116
123
|
return json(200, { ok: true });
|
|
117
124
|
};
|
|
118
125
|
const parseDeletePayload = (payload) => {
|
|
@@ -133,7 +140,9 @@ const handleDelete = async (request, env) => {
|
|
|
133
140
|
if (!parsed.ok)
|
|
134
141
|
return parsed.response;
|
|
135
142
|
const storageKey = buildStorageKey(env, { namespace: parsed.namespace, key: parsed.key });
|
|
143
|
+
const startedAt = Date.now();
|
|
136
144
|
await resolved.cache.delete(storageKey);
|
|
145
|
+
SystemTraceWorkerBridge.emitCache('delete', storageKey, Date.now() - startedAt, undefined, undefined, 'kv-proxy');
|
|
137
146
|
return json(200, { ok: true });
|
|
138
147
|
};
|
|
139
148
|
const parseListPayload = (payload) => {
|
|
@@ -168,6 +177,11 @@ const handleList = async (request, env) => {
|
|
|
168
177
|
limit,
|
|
169
178
|
cursor: parsed.params.cursor,
|
|
170
179
|
});
|
|
180
|
+
SystemTraceWorkerBridge.emitEvent('kv-proxy.list', 1, {
|
|
181
|
+
prefix: fullPrefix,
|
|
182
|
+
limit,
|
|
183
|
+
cursor: parsed.params.cursor,
|
|
184
|
+
});
|
|
171
185
|
return json(200, {
|
|
172
186
|
keys: out.keys.map((key) => key.name),
|
|
173
187
|
cursor: out.cursor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoDBProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/mongodb/MongoDBProxyServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MongoDBProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/mongodb/MongoDBProxyServer.ts"],"names":[],"mappings":"AAaA,KAAK,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACnD,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,mBAAmB,CAAC;CACnD,CAAC;AACF,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,iBAAiB,CAAC;IACxC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAaF,KAAK,cAAc,GAAG,OAAO,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,OAAO,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC,CAAC;AAoQH,eAAO,MAAM,kBAAkB;sBACN,cAAc;;;;;;;;;EA+BrC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemTraceBridge } from '../../trace/SystemTraceBridge.js';
|
|
1
2
|
import { Env } from '../../config/env.js';
|
|
2
3
|
import { Logger } from '../../config/logger.js';
|
|
3
4
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
@@ -140,7 +141,14 @@ const createBackend = (client, config) => ({
|
|
|
140
141
|
};
|
|
141
142
|
}
|
|
142
143
|
try {
|
|
144
|
+
const startedAt = Date.now();
|
|
143
145
|
const result = await executeOperation(client, config.mongoOptions.database, validated.collection ?? '', validated.operation ?? '', validated.args ?? {});
|
|
146
|
+
SystemTraceBridge.emitEvent('mongodb-proxy.operation', 1, {
|
|
147
|
+
operation: validated.operation,
|
|
148
|
+
collection: validated.collection,
|
|
149
|
+
args: validated.args,
|
|
150
|
+
duration: Date.now() - startedAt,
|
|
151
|
+
});
|
|
144
152
|
return { status: 200, body: { success: true, result } };
|
|
145
153
|
}
|
|
146
154
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MySqlProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/mysql/MySqlProxyServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MySqlProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/mysql/MySqlProxyServer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAa5E,KAAK,cAAc,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAgOrE,eAAO,MAAM,gBAAgB;sBACJ,cAAc,GAAQ,OAAO,CAAC,IAAI,CAAC;EA0D1D,CAAC;AAEH,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemTraceBridge } from '../../trace/SystemTraceBridge.js';
|
|
1
2
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
2
3
|
import * as Deps from '../SqlProxyServerDeps.js';
|
|
3
4
|
import { createPool } from 'mysql2/promise';
|
|
@@ -83,7 +84,9 @@ const handleStatementRequest = async (params) => {
|
|
|
83
84
|
if (!resolved.ok)
|
|
84
85
|
return resolved.response;
|
|
85
86
|
try {
|
|
87
|
+
const startedAt = Date.now();
|
|
86
88
|
const [rows] = await params.pool.query(resolved.value.sql, resolved.value.params);
|
|
89
|
+
SystemTraceBridge.emitQuery(resolved.value.sql, resolved.value.params, Date.now() - startedAt, 'mysql-proxy');
|
|
87
90
|
const normalized = normalizeResult(rows);
|
|
88
91
|
if (!resolved.value.mutating) {
|
|
89
92
|
return { status: 200, body: { rows: normalized.rows, rowCount: normalized.rowCount } };
|
|
@@ -117,7 +120,9 @@ const handleSqlRequest = async (params) => {
|
|
|
117
120
|
return Deps.ErrorHandler.toProxyError(400, error.code, error.message);
|
|
118
121
|
}
|
|
119
122
|
try {
|
|
123
|
+
const startedAt = Date.now();
|
|
120
124
|
const [rows] = await params.pool.query(sqlValidation.sql ?? '', sqlValidation.params ?? []);
|
|
125
|
+
SystemTraceBridge.emitQuery(sqlValidation.sql ?? '', sqlValidation.params ?? [], Date.now() - startedAt, 'mysql-proxy');
|
|
121
126
|
return handleEndpoint(params.request.path, rows);
|
|
122
127
|
}
|
|
123
128
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgresProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/postgres/PostgresProxyServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PostgresProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/postgres/PostgresProxyServer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAoB5E,KAAK,cAAc,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAyMrE,eAAO,MAAM,mBAAmB;sBACP,cAAc,GAAQ,OAAO,CAAC,IAAI,CAAC;EAyC1D,CAAC;AAEH,eAAe,mBAAmB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemTraceBridge } from '../../trace/SystemTraceBridge.js';
|
|
1
2
|
import * as Deps from '../SqlProxyServerDeps.js';
|
|
2
3
|
import { Pool } from 'pg';
|
|
3
4
|
const resolveDatabaseConfig = (overrides = {}) => {
|
|
@@ -72,7 +73,9 @@ const handleStatementRequest = async (params) => {
|
|
|
72
73
|
return resolved.response;
|
|
73
74
|
try {
|
|
74
75
|
const normalizedSql = normalizeSql(resolved.value.sql);
|
|
76
|
+
const startedAt = Date.now();
|
|
75
77
|
const result = await params.pool.query(normalizedSql, resolved.value.params);
|
|
78
|
+
SystemTraceBridge.emitQuery(normalizedSql, resolved.value.params, Date.now() - startedAt, 'postgres-proxy');
|
|
76
79
|
const rows = (result.rows ?? []);
|
|
77
80
|
const rowCount = result.rowCount ?? rows.length ?? 0;
|
|
78
81
|
if (!resolved.value.mutating) {
|
|
@@ -108,7 +111,9 @@ const handleSqlRequest = async (params) => {
|
|
|
108
111
|
}
|
|
109
112
|
try {
|
|
110
113
|
const sql = normalizeSql(sqlValidation.sql ?? '');
|
|
114
|
+
const startedAt = Date.now();
|
|
111
115
|
const result = await params.pool.query(sql, sqlValidation.params ?? []);
|
|
116
|
+
SystemTraceBridge.emitQuery(sql, sqlValidation.params ?? [], Date.now() - startedAt, 'postgres-proxy');
|
|
112
117
|
return handleEndpoint(params.request.path, {
|
|
113
118
|
rows: (result.rows ?? []),
|
|
114
119
|
rowCount: result.rowCount ?? result.rows?.length ?? 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/redis/RedisProxyServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RedisProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/redis/RedisProxyServer.ts"],"names":[],"mappings":"AAQA,OAAO,EAIL,KAAK,kBAAkB,EACxB,MAAM,yBAAyB,CAAC;AAiBjC,KAAK,cAAc,GAAG,kBAAkB,GACtC,OAAO,CAAC;IACN,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AA2NL,eAAO,MAAM,gBAAgB;sBACJ,cAAc,GAAQ,OAAO,CAAC,IAAI,CAAC;EAqB1D,CAAC;AAEH,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemTraceBridge } from '../../trace/SystemTraceBridge.js';
|
|
1
2
|
import { Env } from '../../config/env.js';
|
|
2
3
|
import { Logger } from '../../config/logger.js';
|
|
3
4
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
@@ -138,7 +139,9 @@ const createBackend = (config) => ({
|
|
|
138
139
|
try {
|
|
139
140
|
const client = await createClient(config);
|
|
140
141
|
try {
|
|
142
|
+
const startedAt = Date.now();
|
|
141
143
|
const result = await executeCommand(client, command, validated.args ?? []);
|
|
144
|
+
SystemTraceBridge.emitRedis(command, Date.now() - startedAt);
|
|
142
145
|
return { status: 200, body: { result } };
|
|
143
146
|
}
|
|
144
147
|
finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmtpProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/smtp/SmtpProxyServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SmtpProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/smtp/SmtpProxyServer.ts"],"names":[],"mappings":"AA6BA,KAAK,cAAc,GAAG,OAAO,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,cAAc,EAAE,OAAO,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC,CAAC;AA6UH,eAAO,MAAM,eAAe;sBACH,cAAc,GAAQ,OAAO,CAAC,IAAI,CAAC;EA2B1D,CAAC;AAEH,eAAe,eAAe,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemTraceBridge } from '../../trace/SystemTraceBridge.js';
|
|
1
2
|
import { Env } from '../../config/env.js';
|
|
2
3
|
import { Logger } from '../../config/logger.js';
|
|
3
4
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
@@ -239,6 +240,9 @@ const createBackend = (config) => ({
|
|
|
239
240
|
try {
|
|
240
241
|
Logger.info('[SmtpProxy] Sending email via SmtpDriver', { to: messageValidation.value.to });
|
|
241
242
|
await SmtpDriver.send(config.smtp, messageValidation.value);
|
|
243
|
+
SystemTraceBridge.emitMail(Array.isArray(messageValidation.value.to)
|
|
244
|
+
? messageValidation.value.to.join(', ')
|
|
245
|
+
: messageValidation.value.to, messageValidation.value.subject, undefined, messageValidation.value.text, messageValidation.value.html);
|
|
242
246
|
Logger.info('[SmtpProxy] Email sent successfully');
|
|
243
247
|
return { status: 200, body: { ok: true } };
|
|
244
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlServerProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/sqlserver/SqlServerProxyServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SqlServerProxyServer.d.ts","sourceRoot":"","sources":["../../../../src/proxy/sqlserver/SqlServerProxyServer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAA0B,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAepG,KAAK,cAAc,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAiPrE,eAAO,MAAM,oBAAoB;sBACR,cAAc,GAAQ,OAAO,CAAC,IAAI,CAAC;EAwC1D,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemTraceBridge } from '../../trace/SystemTraceBridge.js';
|
|
1
2
|
import * as Deps from '../SqlProxyServerDeps.js';
|
|
2
3
|
const resolveDatabaseConfig = (overrides = {}) => {
|
|
3
4
|
const dbHost = overrides.dbHost ?? Deps.Env.get('DB_HOST_MSSQL', Deps.Env.get('DB_HOST', '127.0.0.1'));
|
|
@@ -111,7 +112,9 @@ const handleStatementRequest = async (pool, statements, requestPath, payload) =>
|
|
|
111
112
|
if (!resolved.ok)
|
|
112
113
|
return resolved.response;
|
|
113
114
|
try {
|
|
115
|
+
const startedAt = Date.now();
|
|
114
116
|
const result = await executeQuery(pool, resolved.value.sql, resolved.value.params);
|
|
117
|
+
SystemTraceBridge.emitQuery(resolved.value.sql, resolved.value.params, Date.now() - startedAt, 'sqlserver-proxy');
|
|
115
118
|
if (!resolved.value.mutating)
|
|
116
119
|
return handleEndpoint('/zin/sqlserver/statement', result);
|
|
117
120
|
return toMutatingStatementResponse(result);
|
|
@@ -137,7 +140,9 @@ const handleSqlRequest = async (pool, requestPath, payload) => {
|
|
|
137
140
|
return Deps.ErrorHandler.toProxyError(400, error.code, error.message);
|
|
138
141
|
}
|
|
139
142
|
try {
|
|
143
|
+
const startedAt = Date.now();
|
|
140
144
|
const result = await executeQuery(pool, sqlValidation.sql ?? '', sqlValidation.params ?? []);
|
|
145
|
+
SystemTraceBridge.emitQuery(sqlValidation.sql ?? '', sqlValidation.params ?? [], Date.now() - startedAt, 'sqlserver-proxy');
|
|
141
146
|
return handleEndpoint(requestPath, result);
|
|
142
147
|
}
|
|
143
148
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../../../src/tools/http/Http.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAElF,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC;IACtD,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC;IAC3D,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,YAAY,CAAC;IACnE,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAAC;IAChE,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,CAAC;IACtC,MAAM,IAAI,YAAY,CAAC;IACvB,MAAM,IAAI,YAAY,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IAC/B,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7B,UAAU,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;CAC1F;
|
|
1
|
+
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../../../src/tools/http/Http.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAElF,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,IAAI,EAAE,MA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actory } from '../../exceptions/ZintrustError.js';
|
|
13
13
|
import { createHttpResponse } from './HttpResponse.js';
|
|
14
|
+
const headersToRecord = (headers) => {
|
|
15
|
+
if (!headers)
|
|
16
|
+
return {};
|
|
17
|
+
if (headers instanceof Headers) {
|
|
18
|
+
return Object.fromEntries(headers.entries());
|
|
19
|
+
}
|
|
20
|
+
if (headers instanceof Map) {
|
|
21
|
+
return Object.fromEntries(headers.entries());
|
|
22
|
+
}
|
|
23
|
+
if (typeof headers === 'object' && typeof headers.entries === 'function') {
|
|
24
|
+
return Object.fromEntries(headers.entries());
|
|
25
|
+
}
|
|
26
|
+
if (typeof headers === 'object') {
|
|
27
|
+
return Object.fromEntries(Object.entries(headers).filter((entry) => typeof entry[1] === 'string'));
|
|
28
|
+
}
|
|
29
|
+
return {};
|
|
30
|
+
};
|
|
31
|
+
const bodyToTracePayload = (body) => {
|
|
32
|
+
if (body === null || body === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (typeof body === 'string') {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(body);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return body;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (body instanceof URLSearchParams) {
|
|
43
|
+
return body.toString();
|
|
44
|
+
}
|
|
45
|
+
if (typeof FormData !== 'undefined' && body instanceof FormData) {
|
|
46
|
+
return Array.from(body.entries()).map(([key, value]) => [key, String(value)]);
|
|
47
|
+
}
|
|
48
|
+
return '[stream]';
|
|
49
|
+
};
|
|
50
|
+
const emitHttpClientTrace = (input) => {
|
|
51
|
+
const { state, durationMs, response, responseBody, error } = input;
|
|
52
|
+
SystemTraceBridge.emitHttpClient({
|
|
53
|
+
method: state.method,
|
|
54
|
+
url: state.url,
|
|
55
|
+
requestHeaders: { ...state.headers },
|
|
56
|
+
responseStatus: response?.status,
|
|
57
|
+
duration: durationMs,
|
|
58
|
+
requestBody: bodyToTracePayload(state.body),
|
|
59
|
+
responseHeaders: headersToRecord(response?.headers),
|
|
60
|
+
responseBody,
|
|
61
|
+
error,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const captureTraceResponseBody = async (response) => {
|
|
65
|
+
try {
|
|
66
|
+
return await response.clone().text();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
14
72
|
/**
|
|
15
73
|
* Perform the actual request for a given state. Separated to keep the builder small
|
|
16
74
|
*/
|
|
@@ -26,6 +84,7 @@ async function performRequest(state) {
|
|
|
26
84
|
async function performRequestRaw(state) {
|
|
27
85
|
const { response, durationMs } = await performFetch(state);
|
|
28
86
|
const bodyText = await response.text();
|
|
87
|
+
emitHttpClientTrace({ state, response, responseBody: bodyText, durationMs });
|
|
29
88
|
return { response, bodyText, durationMs };
|
|
30
89
|
}
|
|
31
90
|
async function performFetch(state) {
|
|
@@ -51,15 +110,20 @@ async function performFetch(state) {
|
|
|
51
110
|
}
|
|
52
111
|
return init;
|
|
53
112
|
};
|
|
113
|
+
const startTime = Date.now();
|
|
54
114
|
try {
|
|
55
115
|
const init = buildInit();
|
|
56
|
-
const startTime = Date.now();
|
|
57
116
|
const response = await globalThis.fetch(state.url, init);
|
|
58
117
|
const duration = Date.now() - startTime;
|
|
59
|
-
SystemTraceBridge.emitHttpClient(state.method, state.url, { ...state.headers }, response.status, duration);
|
|
60
118
|
return { response, durationMs: duration };
|
|
61
119
|
}
|
|
62
120
|
catch (error) {
|
|
121
|
+
const duration = Date.now() - startTime;
|
|
122
|
+
emitHttpClientTrace({
|
|
123
|
+
state,
|
|
124
|
+
durationMs: duration,
|
|
125
|
+
error: error instanceof Error ? error.message : String(error),
|
|
126
|
+
});
|
|
63
127
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
64
128
|
throw ErrorFactory.createConnectionError(`HTTP request timeout after ${timeout}ms`, {
|
|
65
129
|
url: state.url,
|
|
@@ -127,11 +191,15 @@ function createRequestBuilder(method, url, initialBody) {
|
|
|
127
191
|
return performRequest(state);
|
|
128
192
|
},
|
|
129
193
|
async sendRaw() {
|
|
130
|
-
const { response } = await performFetch(state);
|
|
194
|
+
const { response, durationMs } = await performFetch(state);
|
|
195
|
+
const responseBody = await captureTraceResponseBody(response);
|
|
196
|
+
emitHttpClientTrace({ state, response, responseBody, durationMs });
|
|
131
197
|
return response;
|
|
132
198
|
},
|
|
133
199
|
async sendStream() {
|
|
134
|
-
const { response } = await performFetch(state);
|
|
200
|
+
const { response, durationMs } = await performFetch(state);
|
|
201
|
+
const responseBody = await captureTraceResponseBody(response);
|
|
202
|
+
emitHttpClientTrace({ state, response, responseBody, durationMs });
|
|
135
203
|
return { response, stream: response.body };
|
|
136
204
|
},
|
|
137
205
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tools/mail/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAI7E,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,WAAW,CAAC,EAAE,eAAe,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,YAAY,CAAC;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tools/mail/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAI7E,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,WAAW,CAAC,EAAE,eAAe,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,GAAG,YAAY,CAAC;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AA6JF,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAsBD,eAAO,MAAM,IAAI;IACf;;OAEG;kBACiB,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAIrD,sBAAsB;gBACJ,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAGnD;;;;OAIG;iBACU,MAAM;cA5Eb,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,cAAc,CAAC;;gBAgFrC,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;EAGzD,CAAC;AAEH,eAAe,IAAI,CAAC"}
|
package/src/tools/mail/index.js
CHANGED
|
@@ -94,7 +94,7 @@ const createMailer = (name) => Object.freeze({
|
|
|
94
94
|
html: input.html,
|
|
95
95
|
attachments,
|
|
96
96
|
});
|
|
97
|
-
SystemTraceBridge.emitMail(normalizeMailRecipients(input.to), input.subject);
|
|
97
|
+
SystemTraceBridge.emitMail(normalizeMailRecipients(input.to), input.subject, undefined, input.text, input.html);
|
|
98
98
|
return result;
|
|
99
99
|
},
|
|
100
100
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../../../src/tools/notification/Service.ts"],"names":[],"mappings":"AAqEA,eAAO,MAAM,mBAAmB;oBACR,MAAM,WAAW,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;yBAWhE,MAAM,aACR,MAAM,WACR,MAAM,YACN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Service.d.ts","sourceRoot":"","sources":["../../../../src/tools/notification/Service.ts"],"names":[],"mappings":"AAqEA,eAAO,MAAM,mBAAmB;oBACR,MAAM,WAAW,MAAM,YAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;yBAWhE,MAAM,aACR,MAAM,WACR,MAAM,YACN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;mBA4DnB,MAAM,EAAE;EAGvB,CAAC;AAEH,eAAe,mBAAmB,CAAC"}
|
|
@@ -58,7 +58,7 @@ export const NotificationService = Object.freeze({
|
|
|
58
58
|
const driverName = NotificationConfig.getDriver();
|
|
59
59
|
const driver = NotificationRegistry.get(driverName);
|
|
60
60
|
const result = await driver.send(recipient, message, options);
|
|
61
|
-
SystemTraceBridge.emitNotification(driverName, [driverName], recipient);
|
|
61
|
+
SystemTraceBridge.emitNotification(driverName, [driverName], recipient, message, options);
|
|
62
62
|
return result;
|
|
63
63
|
},
|
|
64
64
|
async sendVia(channelName, recipient, message, options = {}) {
|
|
@@ -67,14 +67,14 @@ export const NotificationService = Object.freeze({
|
|
|
67
67
|
switch (cfg.driver) {
|
|
68
68
|
case 'console': {
|
|
69
69
|
const result = await ConsoleDriver.send(recipient, message, options);
|
|
70
|
-
SystemTraceBridge.emitNotification(channelName, ['console'], recipient);
|
|
70
|
+
SystemTraceBridge.emitNotification(channelName, ['console'], recipient, message, options);
|
|
71
71
|
return result;
|
|
72
72
|
}
|
|
73
73
|
case 'slack': {
|
|
74
74
|
const slackCfg = cfg;
|
|
75
75
|
const payload = { text: message, ...options };
|
|
76
76
|
const result = await SlackDriver.send({ webhookUrl: slackCfg.webhookUrl }, payload);
|
|
77
|
-
SystemTraceBridge.emitNotification(channelName, ['slack'], recipient);
|
|
77
|
+
SystemTraceBridge.emitNotification(channelName, ['slack'], recipient, message, payload);
|
|
78
78
|
return result;
|
|
79
79
|
}
|
|
80
80
|
case 'twilio': {
|
|
@@ -84,12 +84,15 @@ export const NotificationService = Object.freeze({
|
|
|
84
84
|
authToken: twilioCfg.authToken,
|
|
85
85
|
from: twilioCfg.fromNumber,
|
|
86
86
|
}, { to: recipient, body: message });
|
|
87
|
-
SystemTraceBridge.emitNotification(channelName, ['twilio'], recipient
|
|
87
|
+
SystemTraceBridge.emitNotification(channelName, ['twilio'], recipient, message, {
|
|
88
|
+
to: recipient,
|
|
89
|
+
body: message,
|
|
90
|
+
});
|
|
88
91
|
return result;
|
|
89
92
|
}
|
|
90
93
|
case 'termii': {
|
|
91
94
|
const result = await sendTermii(cfg, recipient, message, options);
|
|
92
|
-
SystemTraceBridge.emitNotification(channelName, ['termii'], recipient);
|
|
95
|
+
SystemTraceBridge.emitNotification(channelName, ['termii'], recipient, message, options);
|
|
93
96
|
return result;
|
|
94
97
|
}
|
|
95
98
|
default:
|
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
export declare const SystemTraceBridge: Readonly<{
|
|
2
2
|
preload: () => Promise<boolean>;
|
|
3
3
|
emitAuth: (event: "login" | "logout" | "failed", userId?: string) => void;
|
|
4
|
-
emitCache: (operation: "get" | "set" | "delete" | "clear" | "has", key: string, duration: number, hit?: boolean) => void;
|
|
4
|
+
emitCache: (operation: "get" | "set" | "delete" | "clear" | "has", key: string, duration: number, hit?: boolean, payload?: unknown, store?: string, ttl?: number) => void;
|
|
5
5
|
emitCommand: (name: string, args: Record<string, unknown>, exitCode: number, duration: number, output?: string) => void;
|
|
6
6
|
emitEvent: (name: string, listenerCount: number, payload?: unknown) => void;
|
|
7
|
-
emitHttpClient: (
|
|
7
|
+
emitHttpClient: (payload: {
|
|
8
|
+
method: string;
|
|
9
|
+
url: string;
|
|
10
|
+
requestHeaders: Record<string, string>;
|
|
11
|
+
responseStatus?: number;
|
|
12
|
+
duration: number;
|
|
13
|
+
requestBody?: unknown;
|
|
14
|
+
responseHeaders?: Record<string, string>;
|
|
15
|
+
responseBody?: unknown;
|
|
16
|
+
error?: string;
|
|
17
|
+
}) => void;
|
|
8
18
|
emitJobDispatch: (name: string, queue: string, connection: string, data?: unknown) => void;
|
|
9
19
|
emitJobFailed: (name: string, error: Error) => void;
|
|
10
20
|
emitJobProcessed: (name: string) => void;
|
|
11
|
-
emitMail: (to: string, subject: string, template?: string) => void;
|
|
12
|
-
emitNotification: (notification: string, channels: string[], notifiable?: string) => void;
|
|
21
|
+
emitMail: (to: string, subject: string, template?: string, text?: string, html?: string) => void;
|
|
22
|
+
emitNotification: (notification: string, channels: string[], notifiable?: string, message?: string, payload?: unknown) => void;
|
|
23
|
+
emitQuery: (query: string, params: unknown[], duration: number, connection?: string) => void;
|
|
24
|
+
emitRedis: (command: string, duration: number) => void;
|
|
13
25
|
}>;
|
|
14
26
|
export default SystemTraceBridge;
|
|
15
27
|
//# sourceMappingURL=SystemTraceBridge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemTraceBridge.d.ts","sourceRoot":"","sources":["../../../src/trace/SystemTraceBridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SystemTraceBridge.d.ts","sourceRoot":"","sources":["../../../src/trace/SystemTraceBridge.ts"],"names":[],"mappings":"AAoOA,eAAO,MAAM,iBAAiB;mBALJ,OAAO,CAAC,OAAO,CAAC;sBAlBjB,OAAO,GAAG,QAAQ,GAAG,QAAQ,WAAW,MAAM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
|
-
const emitCache = (operation, key, duration, hit) => {
|
|
42
|
+
const emitCache = (operation, key, duration, hit, payload, store, ttl) => {
|
|
43
43
|
withSystemTrace((module) => {
|
|
44
|
-
module.CacheWatcher?.emit(operation, key, duration, hit);
|
|
44
|
+
module.CacheWatcher?.emit(operation, key, duration, hit, payload, store, ttl);
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
const emitJobDispatch = (name, queue, connection, data) => {
|
|
@@ -59,19 +59,29 @@ const emitJobFailed = (name, error) => {
|
|
|
59
59
|
module.JobWatcher?.onFailed(name, error);
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
const emitNotification = (notification, channels, notifiable) => {
|
|
62
|
+
const emitNotification = (notification, channels, notifiable, message, payload) => {
|
|
63
63
|
withSystemTrace((module) => {
|
|
64
|
-
module.NotificationWatcher?.emit(notification, channels, notifiable);
|
|
64
|
+
module.NotificationWatcher?.emit(notification, channels, notifiable, message, payload);
|
|
65
65
|
});
|
|
66
66
|
};
|
|
67
|
-
const emitMail = (to, subject, template) => {
|
|
67
|
+
const emitMail = (to, subject, template, text, html) => {
|
|
68
68
|
withSystemTrace((module) => {
|
|
69
|
-
module.MailWatcher?.emit(to, subject, template);
|
|
69
|
+
module.MailWatcher?.emit(to, subject, template, text, html);
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
|
-
const emitHttpClient = (
|
|
72
|
+
const emitHttpClient = (payload) => {
|
|
73
73
|
withSystemTrace((module) => {
|
|
74
|
-
module.HttpClientWatcher?.emit(
|
|
74
|
+
module.HttpClientWatcher?.emit(payload);
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const emitQuery = (query, params, duration, connection) => {
|
|
78
|
+
withSystemTrace((module) => {
|
|
79
|
+
module.QueryWatcher?.emit(query, params, duration, connection);
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const emitRedis = (command, duration) => {
|
|
83
|
+
withSystemTrace((module) => {
|
|
84
|
+
module.RedisWatcher?.emit(command, duration);
|
|
75
85
|
});
|
|
76
86
|
};
|
|
77
87
|
const emitEvent = (name, listenerCount, payload) => {
|
|
@@ -105,5 +115,7 @@ export const SystemTraceBridge = Object.freeze({
|
|
|
105
115
|
emitJobProcessed,
|
|
106
116
|
emitMail,
|
|
107
117
|
emitNotification,
|
|
118
|
+
emitQuery,
|
|
119
|
+
emitRedis,
|
|
108
120
|
});
|
|
109
121
|
export default SystemTraceBridge;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const SystemTraceWorkerBridge: Readonly<{
|
|
2
|
+
emitCache: (operation: "get" | "set" | "delete" | "clear" | "has", key: string, duration: number, hit?: boolean, payload?: unknown, store?: string, ttl?: number) => void;
|
|
3
|
+
emitEvent: (name: string, listenerCount: number, payload?: unknown) => void;
|
|
4
|
+
emitQuery: (query: string, params: unknown[], duration: number, connection?: string) => void;
|
|
5
|
+
}>;
|
|
6
|
+
export default SystemTraceWorkerBridge;
|
|
7
|
+
//# sourceMappingURL=SystemTraceWorkerBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SystemTraceWorkerBridge.d.ts","sourceRoot":"","sources":["../../../src/trace/SystemTraceWorkerBridge.ts"],"names":[],"mappings":"AAgEA,eAAO,MAAM,uBAAuB;2BA9BvB,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,OAChD,MAAM,YACD,MAAM,QACV,OAAO,YACH,OAAO,UACT,MAAM,QACR,MAAM,KACX,IAAI;sBAMkB,MAAM,iBAAiB,MAAM,YAAY,OAAO,KAAG,IAAI;uBAOvE,MAAM,UACL,OAAO,EAAE,YACP,MAAM,eACH,MAAM,KAClB,IAAI;EAUL,CAAC;AAEH,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const getWorkerTraceModule = () => {
|
|
2
|
+
return globalThis.__zintrust_worker_trace_bridge__;
|
|
3
|
+
};
|
|
4
|
+
const withWorkerTraceModule = (run) => {
|
|
5
|
+
const module = getWorkerTraceModule();
|
|
6
|
+
if (module === undefined)
|
|
7
|
+
return;
|
|
8
|
+
try {
|
|
9
|
+
run(module);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
// Ignore optional trace failures so Worker proxy behavior is unaffected.
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const emitCache = (operation, key, duration, hit, payload, store, ttl) => {
|
|
16
|
+
withWorkerTraceModule((module) => {
|
|
17
|
+
module.emitCache?.(operation, key, duration, hit, payload, store, ttl);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const emitEvent = (name, listenerCount, payload) => {
|
|
21
|
+
withWorkerTraceModule((module) => {
|
|
22
|
+
module.emitEvent?.(name, listenerCount, payload);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const emitQuery = (query, params, duration, connection) => {
|
|
26
|
+
withWorkerTraceModule((module) => {
|
|
27
|
+
module.emitQuery?.(query, params, duration, connection);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export const SystemTraceWorkerBridge = Object.freeze({
|
|
31
|
+
emitCache,
|
|
32
|
+
emitEvent,
|
|
33
|
+
emitQuery,
|
|
34
|
+
});
|
|
35
|
+
export default SystemTraceWorkerBridge;
|