@zintrust/core 0.4.80 → 0.4.83
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/bin/zintrust-main.d.ts.map +1 -1
- package/bin/zintrust-main.js +19 -7
- package/package.json +1 -1
- package/src/cache/Cache.d.ts.map +1 -1
- package/src/cache/Cache.js +11 -10
- package/src/cli/commands/D1ProxyCommand.d.ts.map +1 -1
- package/src/cli/commands/D1ProxyCommand.js +12 -1
- package/src/cli/commands/MongoDBProxyCommand.d.ts.map +1 -1
- package/src/cli/commands/MongoDBProxyCommand.js +3 -1
- package/src/cli/commands/MySqlProxyCommand.d.ts.map +1 -1
- package/src/cli/commands/MySqlProxyCommand.js +9 -7
- package/src/cli/commands/PostgresProxyCommand.d.ts.map +1 -1
- package/src/cli/commands/PostgresProxyCommand.js +9 -7
- package/src/cli/commands/ProxyCommandUtils.d.ts +2 -0
- package/src/cli/commands/ProxyCommandUtils.d.ts.map +1 -1
- package/src/cli/commands/ProxyCommandUtils.js +25 -0
- package/src/cli/commands/RedisProxyCommand.d.ts.map +1 -1
- package/src/cli/commands/RedisProxyCommand.js +3 -2
- package/src/cli/commands/SmtpProxyCommand.d.ts.map +1 -1
- package/src/cli/commands/SmtpProxyCommand.js +2 -1
- package/src/cli/commands/SqlServerProxyCommand.d.ts.map +1 -1
- package/src/cli/commands/SqlServerProxyCommand.js +3 -1
- package/src/cli/commands/WranglerProxyCommandUtils.d.ts.map +1 -1
- package/src/cli/commands/WranglerProxyCommandUtils.js +14 -35
- package/src/index.js +3 -3
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zintrust-main.d.ts","sourceRoot":"","sources":["../../bin/zintrust-main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"zintrust-main.d.ts","sourceRoot":"","sources":["../../bin/zintrust-main.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AA0WF,wBAAsB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAMzC;AAED,eAAO,MAAM,mBAAmB;;qCAzUQ,MAAM,KAAG,qBAAqB,GAAG,SAAS;mCA6C5C,MAAM,GAAG,IAAI,UAAU,MAAM,CAAC,OAAO,GAAG,IAAI,KAAG,MAAM;iCAnEzD,MAAM;8BAIP,MAAM,KAAG,MAAM;uCAsEtC,qBAAqB,WACpB,MAAM,EAAE,KAChB,OAAO,CAAC,KAAK,CAAC;oCAhEsB,MAAM,sBAAsB,MAAM,KAAG,OAAO;6CA2G7B,MAAM,EAAE,KAAG,OAAO,CAAC,OAAO,CAAC;yCAtE1E,MAAM,sBACS,MAAM,QACrB,MAAM,CAAC,UAAU,KACrB,qBAAqB,GAAG,SAAS;EAqTlC,CAAC;AAEH,OAAO,EAAE,CAAC"}
|
package/bin/zintrust-main.js
CHANGED
|
@@ -4,12 +4,20 @@
|
|
|
4
4
|
* This module contains the CLI implementation without a hashbang so that it can
|
|
5
5
|
* be imported by other bin shortcuts (zin/z/zt) without parse errors.
|
|
6
6
|
*/
|
|
7
|
-
import { Logger } from '../src/config/logger.js';
|
|
8
7
|
import { spawn } from 'node:child_process';
|
|
9
8
|
import fs from 'node:fs';
|
|
10
9
|
import path from 'node:path';
|
|
11
10
|
import { fileURLToPath } from 'node:url';
|
|
12
11
|
const CLI_HANDOFF_ENV_KEY = 'ZINTRUST_CLI_HANDOFF';
|
|
12
|
+
const loadLogger = async () => {
|
|
13
|
+
try {
|
|
14
|
+
const { Logger } = await import('../src/config/logger.js');
|
|
15
|
+
return Logger;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
13
21
|
const getCurrentPackageRoot = () => {
|
|
14
22
|
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
15
23
|
};
|
|
@@ -199,18 +207,22 @@ const shouldDeferPluginAutoImportWarnings = (args) => {
|
|
|
199
207
|
const command = getPrimaryCommand(args);
|
|
200
208
|
return command === 'start' || command === 's';
|
|
201
209
|
};
|
|
202
|
-
const logPluginAutoImportFailure = (args, scope, details) => {
|
|
210
|
+
const logPluginAutoImportFailure = async (args, scope, details) => {
|
|
211
|
+
const logger = await loadLogger();
|
|
212
|
+
if (logger === undefined)
|
|
213
|
+
return;
|
|
203
214
|
if (shouldDeferPluginAutoImportWarnings(args)) {
|
|
204
|
-
|
|
215
|
+
logger.debug(`${scope} plugin auto-import advisory deferred to runtime bootstrap`, {
|
|
205
216
|
details,
|
|
206
217
|
});
|
|
207
218
|
return;
|
|
208
219
|
}
|
|
209
|
-
|
|
220
|
+
logger.warn(`${scope} plugin auto-imports failed:`, details);
|
|
210
221
|
};
|
|
211
222
|
const handleCliFatal = async (error, context) => {
|
|
212
223
|
try {
|
|
213
|
-
|
|
224
|
+
const logger = await loadLogger();
|
|
225
|
+
logger?.error(context, error);
|
|
214
226
|
}
|
|
215
227
|
catch {
|
|
216
228
|
// best-effort logging
|
|
@@ -259,11 +271,11 @@ const runCliInternal = async () => {
|
|
|
259
271
|
const runtimeImportMode = process.env['DOCKER_WORKER'] === 'true' ? 'worker' : 'base';
|
|
260
272
|
const officialImports = await PluginAutoImports.tryImportRuntimeAutoImports(runtimeImportMode);
|
|
261
273
|
if (!officialImports.ok) {
|
|
262
|
-
logPluginAutoImportFailure(args0, 'Official', officialImports.errorMessage);
|
|
274
|
+
await logPluginAutoImportFailure(args0, 'Official', officialImports.errorMessage);
|
|
263
275
|
}
|
|
264
276
|
const projectImports = await PluginAutoImports.tryImportProjectAutoImports();
|
|
265
277
|
if (!projectImports.ok && projectImports.reason !== 'not-found') {
|
|
266
|
-
logPluginAutoImportFailure(args0, 'Project', projectImports.errorMessage);
|
|
278
|
+
await logPluginAutoImportFailure(args0, 'Project', projectImports.errorMessage);
|
|
267
279
|
}
|
|
268
280
|
}
|
|
269
281
|
catch {
|
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 = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"D1ProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/D1ProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"D1ProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/D1ProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAkIrD,eAAO,MAAM,cAAc;cACf,YAAY;EAkBtB,CAAC;AAEH,eAAe,cAAc,CAAC"}
|
|
@@ -66,6 +66,17 @@ const warnOnPlaceholderDatabaseId = (values) => {
|
|
|
66
66
|
return;
|
|
67
67
|
Logger.warn('Could not resolve a D1 database id automatically. Update wrangler.jsonc or pass --database-id before relying on the generated d1-proxy environment.');
|
|
68
68
|
};
|
|
69
|
+
const warnOnMissingSigningSecret = () => {
|
|
70
|
+
const directSecret = trimNonEmptyOption(Env.get('D1_REMOTE_SECRET', ''));
|
|
71
|
+
const fallbackSecret = trimNonEmptyOption(Env.get('APP_KEY', ''));
|
|
72
|
+
if (directSecret !== undefined || fallbackSecret !== undefined)
|
|
73
|
+
return;
|
|
74
|
+
Logger.warn('D1 proxy signing will fail: the resolved project env does not expose D1_REMOTE_SECRET or APP_KEY to the Worker runtime. Signed requests will be rejected with 401 CONFIG_ERROR until one of those keys is set.');
|
|
75
|
+
};
|
|
76
|
+
const runD1ProxyDiagnostics = (values) => {
|
|
77
|
+
warnOnPlaceholderDatabaseId(values);
|
|
78
|
+
warnOnMissingSigningSecret();
|
|
79
|
+
};
|
|
69
80
|
const addOptions = (command) => {
|
|
70
81
|
addWranglerProxyBaseOptions(command, DEFAULT_CONFIG);
|
|
71
82
|
command.option('--binding <name>', 'D1 binding name', DEFAULT_BINDING);
|
|
@@ -88,7 +99,7 @@ export const D1ProxyCommand = Object.freeze({
|
|
|
88
99
|
addOptions,
|
|
89
100
|
resolveValues: resolveConfigValues,
|
|
90
101
|
renderEnvBlock: renderD1ProxyEnvBlock,
|
|
91
|
-
afterConfigResolved:
|
|
102
|
+
afterConfigResolved: runD1ProxyDiagnostics,
|
|
92
103
|
});
|
|
93
104
|
},
|
|
94
105
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MongoDBProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/MongoDBProxyCommand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MongoDBProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/MongoDBProxyCommand.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4DpC,eAAO,MAAM,mBAAmB;cACpB,OAAO;EA0EjB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Env } from '../../config/env.js';
|
|
2
2
|
import { Logger } from '../../config/logger.js';
|
|
3
3
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
4
|
+
import { ensureProxyEnvLoadedForCwd } from '../commands/ProxyCommandUtils.js';
|
|
4
5
|
import { Command } from 'commander';
|
|
5
6
|
const startWatchMode = async (options) => {
|
|
6
7
|
Logger.info('Starting MongoDB proxy in watch mode...');
|
|
@@ -57,13 +58,14 @@ export const MongoDBProxyCommand = Object.freeze({
|
|
|
57
58
|
const cmd = new Command('proxy:mongodb');
|
|
58
59
|
cmd.description('Start MongoDB HTTP proxy server');
|
|
59
60
|
const configureOptions = () => {
|
|
61
|
+
ensureProxyEnvLoadedForCwd();
|
|
60
62
|
cmd.option('--host <host>', 'Proxy host', Env.get('MONGODB_PROXY_HOST', '127.0.0.1'));
|
|
61
63
|
cmd.option('--port <port>', 'Proxy port', String(Env.getInt('MONGODB_PROXY_PORT', 8792)));
|
|
62
64
|
cmd.option('--mongo-uri <uri>', 'MongoDB connection URI', Env.get('MONGO_URI', ''));
|
|
63
65
|
cmd.option('--mongo-db <database>', 'MongoDB database name', Env.get('MONGO_DB', ''));
|
|
64
66
|
cmd.option('--key-id <keyId>', 'Signing key ID', Env.get('MONGODB_PROXY_KEY_ID', 'default'));
|
|
65
67
|
cmd.option('--secret <secret>', 'Signing secret', Env.get('MONGODB_PROXY_SECRET', ''));
|
|
66
|
-
cmd.option('--require-signing', 'Require request signing', Env.MONGODB_PROXY_REQUIRE_SIGNING);
|
|
68
|
+
cmd.option('--require-signing', 'Require request signing', Env.getBool('MONGODB_PROXY_REQUIRE_SIGNING', true));
|
|
67
69
|
cmd.option('--signing-window-ms <ms>', 'Signing window in milliseconds', String(Env.getInt('MONGODB_PROXY_SIGNING_WINDOW_MS', 60000)));
|
|
68
70
|
cmd.option('--watch', 'Watch mode: restart on file changes');
|
|
69
71
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MySqlProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/MySqlProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"MySqlProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/MySqlProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAgCrE,eAAO,MAAM,iBAAiB;cAClB,YAAY;EAatB,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { BaseCommand } from '../BaseCommand.js';
|
|
2
|
+
import { ensureProxyEnvLoadedForCwd } from '../commands/ProxyCommandUtils.js';
|
|
2
3
|
import { addSqlProxyOptions, runSqlProxyCommand, } from '../commands/SqlProxyCommandUtils.js';
|
|
3
4
|
import { Env } from '../../config/env.js';
|
|
4
5
|
import { MySqlProxyServer } from '../../proxy/mysql/MySqlProxyServer.js';
|
|
5
6
|
const addOptions = (command) => {
|
|
7
|
+
ensureProxyEnvLoadedForCwd();
|
|
6
8
|
addSqlProxyOptions(command, {
|
|
7
|
-
hostDefault: Env.MYSQL_PROXY_HOST,
|
|
8
|
-
portDefault: Env.MYSQL_PROXY_PORT,
|
|
9
|
-
maxBodyBytesDefault: Env.MYSQL_PROXY_MAX_BODY_BYTES,
|
|
9
|
+
hostDefault: Env.get('MYSQL_PROXY_HOST', '127.0.0.1'),
|
|
10
|
+
portDefault: Env.getInt('MYSQL_PROXY_PORT', 8789),
|
|
11
|
+
maxBodyBytesDefault: Env.getInt('MYSQL_PROXY_MAX_BODY_BYTES', 131072),
|
|
10
12
|
dbVendorLabel: 'MySQL',
|
|
11
|
-
requireSigningDefault: Env.MYSQL_PROXY_REQUIRE_SIGNING,
|
|
12
|
-
keyIdDefault: Env.MYSQL_PROXY_KEY_ID,
|
|
13
|
-
secretDefault: Env.MYSQL_PROXY_SECRET,
|
|
14
|
-
signingWindowMsDefault: Env.MYSQL_PROXY_SIGNING_WINDOW_MS,
|
|
13
|
+
requireSigningDefault: Env.getBool('MYSQL_PROXY_REQUIRE_SIGNING', true),
|
|
14
|
+
keyIdDefault: Env.get('MYSQL_PROXY_KEY_ID', Env.get('APP_NAME', 'ZinTrust')),
|
|
15
|
+
secretDefault: Env.get('MYSQL_PROXY_SECRET', Env.get('APP_KEY', '')),
|
|
16
|
+
signingWindowMsDefault: Env.getInt('MYSQL_PROXY_SIGNING_WINDOW_MS', Env.getInt('ZT_PROXY_SIGNING_WINDOW_MS', 60000)),
|
|
15
17
|
});
|
|
16
18
|
};
|
|
17
19
|
export const MySqlProxyCommand = Object.freeze({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgresProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/PostgresProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"PostgresProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/PostgresProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAgCrE,eAAO,MAAM,oBAAoB;cACrB,YAAY;EAatB,CAAC;AAEH,eAAe,oBAAoB,CAAC"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { BaseCommand } from '../BaseCommand.js';
|
|
2
|
+
import { ensureProxyEnvLoadedForCwd } from '../commands/ProxyCommandUtils.js';
|
|
2
3
|
import { addSqlProxyOptions, runSqlProxyCommand, } from '../commands/SqlProxyCommandUtils.js';
|
|
3
4
|
import { Env } from '../../config/env.js';
|
|
4
5
|
import { PostgresProxyServer } from '../../proxy/postgres/PostgresProxyServer.js';
|
|
5
6
|
const addOptions = (command) => {
|
|
7
|
+
ensureProxyEnvLoadedForCwd();
|
|
6
8
|
addSqlProxyOptions(command, {
|
|
7
|
-
hostDefault: Env.POSTGRES_PROXY_HOST,
|
|
8
|
-
portDefault: Env.POSTGRES_PROXY_PORT,
|
|
9
|
-
maxBodyBytesDefault: Env.POSTGRES_PROXY_MAX_BODY_BYTES,
|
|
9
|
+
hostDefault: Env.get('POSTGRES_PROXY_HOST', '127.0.0.1'),
|
|
10
|
+
portDefault: Env.getInt('POSTGRES_PROXY_PORT', 8790),
|
|
11
|
+
maxBodyBytesDefault: Env.getInt('POSTGRES_PROXY_MAX_BODY_BYTES', 131072),
|
|
10
12
|
dbVendorLabel: 'PostgreSQL',
|
|
11
|
-
requireSigningDefault: Env.POSTGRES_PROXY_REQUIRE_SIGNING,
|
|
12
|
-
keyIdDefault: Env.POSTGRES_PROXY_KEY_ID,
|
|
13
|
-
secretDefault: Env.POSTGRES_PROXY_SECRET,
|
|
14
|
-
signingWindowMsDefault: Env.POSTGRES_PROXY_SIGNING_WINDOW_MS,
|
|
13
|
+
requireSigningDefault: Env.getBool('POSTGRES_PROXY_REQUIRE_SIGNING', true),
|
|
14
|
+
keyIdDefault: Env.get('POSTGRES_PROXY_KEY_ID', Env.get('APP_NAME', 'ZinTrust')),
|
|
15
|
+
secretDefault: Env.get('POSTGRES_PROXY_SECRET', Env.get('APP_KEY', '')),
|
|
16
|
+
signingWindowMsDefault: Env.getInt('POSTGRES_PROXY_SIGNING_WINDOW_MS', Env.getInt('ZT_PROXY_SIGNING_WINDOW_MS', 60000)),
|
|
15
17
|
});
|
|
16
18
|
};
|
|
17
19
|
export const PostgresProxyCommand = Object.freeze({
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
type NumberExpectation = 'positive' | 'non-negative';
|
|
2
2
|
export declare const parseIntOption: (raw: string | undefined, name: string, expectation?: NumberExpectation) => number | undefined;
|
|
3
3
|
export declare const trimOption: (value: string | undefined) => string | undefined;
|
|
4
|
+
export declare const resolveProxyProjectRoot: (cwd: string) => string;
|
|
5
|
+
export declare const ensureProxyEnvLoadedForCwd: (cwd?: string) => string;
|
|
4
6
|
export declare const maybeRunProxyWatchMode: (watch: boolean | undefined) => Promise<void>;
|
|
5
7
|
export {};
|
|
6
8
|
//# sourceMappingURL=ProxyCommandUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxyCommandUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/ProxyCommandUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProxyCommandUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/ProxyCommandUtils.ts"],"names":[],"mappings":"AAMA,KAAK,iBAAiB,GAAG,UAAU,GAAG,cAAc,CAAC;AAErD,eAAO,MAAM,cAAc,GACzB,KAAK,MAAM,GAAG,SAAS,EACvB,MAAM,MAAM,EACZ,cAAa,iBAA8B,KAC1C,MAAM,GAAG,SAeX,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SAA0B,CAAC;AAc3F,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,KAAG,MAErD,CAAC;AAEF,eAAO,MAAM,0BAA0B,GAAI,MAAK,MAAsB,KAAG,MAUxE,CAAC;AAUF,eAAO,MAAM,sBAAsB,GAAU,OAAO,OAAO,GAAG,SAAS,KAAG,OAAO,CAAC,IAAI,CAerF,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { EnvFileLoader } from '../utils/EnvFileLoader.js';
|
|
1
2
|
import { SpawnUtil } from '../utils/spawn.js';
|
|
2
3
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
4
|
+
import { existsSync } from '../../node-singletons/fs.js';
|
|
3
5
|
import * as path from '../../node-singletons/path.js';
|
|
4
6
|
export const parseIntOption = (raw, name, expectation = 'positive') => {
|
|
5
7
|
if (raw === undefined)
|
|
@@ -15,6 +17,29 @@ export const parseIntOption = (raw, name, expectation = 'positive') => {
|
|
|
15
17
|
return parsed;
|
|
16
18
|
};
|
|
17
19
|
export const trimOption = (value) => value?.trim();
|
|
20
|
+
const findNearestPackageJsonDir = (cwd) => {
|
|
21
|
+
let current = cwd;
|
|
22
|
+
while (true) {
|
|
23
|
+
if (existsSync(path.join(current, 'package.json')))
|
|
24
|
+
return current;
|
|
25
|
+
const parent = path.dirname(current);
|
|
26
|
+
if (parent === current)
|
|
27
|
+
return undefined;
|
|
28
|
+
current = parent;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const resolveProxyProjectRoot = (cwd) => {
|
|
32
|
+
return findNearestPackageJsonDir(cwd) ?? cwd;
|
|
33
|
+
};
|
|
34
|
+
export const ensureProxyEnvLoadedForCwd = (cwd = process.cwd()) => {
|
|
35
|
+
const projectRoot = resolveProxyProjectRoot(cwd);
|
|
36
|
+
EnvFileLoader.ensureLoaded({
|
|
37
|
+
cwd: projectRoot,
|
|
38
|
+
includeCwd: true,
|
|
39
|
+
...(cwd === projectRoot ? {} : { extraCwds: [cwd] }),
|
|
40
|
+
});
|
|
41
|
+
return projectRoot;
|
|
42
|
+
};
|
|
18
43
|
const isWatchChild = () => process.env['ZINTRUST_PROXY_WATCH_CHILD'] === '1';
|
|
19
44
|
const buildWatchArgs = () => {
|
|
20
45
|
const rawArgs = process.argv.slice(2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RedisProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/RedisProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"RedisProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/RedisProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA0DrE,eAAO,MAAM,iBAAiB;cAClB,YAAY;EAoCtB,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BaseCommand } from '../BaseCommand.js';
|
|
2
|
-
import { maybeRunProxyWatchMode, parseIntOption, trimOption, } from '../commands/ProxyCommandUtils.js';
|
|
2
|
+
import { ensureProxyEnvLoadedForCwd, maybeRunProxyWatchMode, parseIntOption, trimOption, } from '../commands/ProxyCommandUtils.js';
|
|
3
3
|
import { Env } from '../../config/env.js';
|
|
4
4
|
import { RedisProxyServer } from '../../proxy/redis/RedisProxyServer.js';
|
|
5
5
|
const addOptions = (command) => {
|
|
6
|
+
ensureProxyEnvLoadedForCwd();
|
|
6
7
|
command.option('--host <host>', 'Host to bind', Env.get('REDIS_PROXY_HOST', '127.0.0.1'));
|
|
7
8
|
command.option('--port <port>', 'Port to bind', String(Env.getInt('REDIS_PROXY_PORT', 8791)));
|
|
8
9
|
command.option('--max-body-bytes <bytes>', 'Max request size in bytes', String(Env.getInt('REDIS_PROXY_MAX_BODY_BYTES', 131072)));
|
|
@@ -11,7 +12,7 @@ const addOptions = (command) => {
|
|
|
11
12
|
command.option('--redis-port <port>', 'Redis port');
|
|
12
13
|
command.option('--redis-password <password>', 'Redis password');
|
|
13
14
|
command.option('--redis-db <db>', 'Redis database');
|
|
14
|
-
command.option('--require-signing', 'Require signed requests', Env.REDIS_PROXY_REQUIRE_SIGNING);
|
|
15
|
+
command.option('--require-signing', 'Require signed requests', Env.getBool('REDIS_PROXY_REQUIRE_SIGNING', true));
|
|
15
16
|
command.option('--key-id <id>', 'Signing key id', Env.get('REDIS_PROXY_KEY_ID', ''));
|
|
16
17
|
command.option('--secret <secret>', 'Signing secret', Env.get('REDIS_PROXY_SECRET', ''));
|
|
17
18
|
command.option('--signing-window-ms <ms>', 'Signing time window in ms', String(Env.getInt('REDIS_PROXY_SIGNING_WINDOW_MS', 60000)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmtpProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/SmtpProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"SmtpProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/SmtpProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA4DrE,eAAO,MAAM,gBAAgB;cACjB,YAAY;EAsCtB,CAAC;AAEH,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { BaseCommand } from '../BaseCommand.js';
|
|
2
|
-
import { maybeRunProxyWatchMode, parseIntOption, trimOption, } from '../commands/ProxyCommandUtils.js';
|
|
2
|
+
import { ensureProxyEnvLoadedForCwd, maybeRunProxyWatchMode, parseIntOption, trimOption, } from '../commands/ProxyCommandUtils.js';
|
|
3
3
|
import { Env } from '../../config/env.js';
|
|
4
4
|
import { SmtpProxyServer } from '../../proxy/smtp/SmtpProxyServer.js';
|
|
5
5
|
const addOptions = (command) => {
|
|
6
|
+
ensureProxyEnvLoadedForCwd();
|
|
6
7
|
command.option('--host <host>', 'Host to bind', Env.get('SMTP_PROXY_HOST', '127.0.0.1'));
|
|
7
8
|
command.option('--port <port>', 'Port to bind', String(Env.getInt('SMTP_PROXY_PORT', 8794)));
|
|
8
9
|
command.option('--max-body-bytes <bytes>', 'Max request size in bytes', String(Env.getInt('SMTP_PROXY_MAX_BODY_BYTES', 131072)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlServerProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/SqlServerProxyCommand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SqlServerProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/SqlServerProxyCommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2DpC,eAAO,MAAM,qBAAqB;cACtB,OAAO;EAwEjB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Env } from '../../config/env.js';
|
|
2
|
+
import { ensureProxyEnvLoadedForCwd } from '../commands/ProxyCommandUtils.js';
|
|
2
3
|
import { Logger } from '../../config/logger.js';
|
|
3
4
|
import { Command } from 'commander';
|
|
4
5
|
const startWatchMode = async (options) => {
|
|
@@ -39,6 +40,7 @@ export const SqlServerProxyCommand = Object.freeze({
|
|
|
39
40
|
const cmd = new Command('proxy:sqlserver');
|
|
40
41
|
cmd.description('Start SQL Server HTTP proxy server');
|
|
41
42
|
const configureOptions = () => {
|
|
43
|
+
ensureProxyEnvLoadedForCwd();
|
|
42
44
|
cmd.option('--host <host>', 'Proxy host', Env.get('SQLSERVER_PROXY_HOST', '127.0.0.1'));
|
|
43
45
|
cmd.option('--port <port>', 'Proxy port', String(Env.getInt('SQLSERVER_PROXY_PORT', 8793)));
|
|
44
46
|
cmd.option('--db-host <host>', 'SQL Server host', Env.get('DB_HOST_MSSQL', '127.0.0.1'));
|
|
@@ -49,7 +51,7 @@ export const SqlServerProxyCommand = Object.freeze({
|
|
|
49
51
|
cmd.option('--connection-limit <limit>', 'Connection pool limit', String(Env.getInt('SQLSERVER_PROXY_POOL_LIMIT', 10)));
|
|
50
52
|
cmd.option('--key-id <keyId>', 'Signing key ID', Env.get('SQLSERVER_PROXY_KEY_ID', 'default'));
|
|
51
53
|
cmd.option('--secret <secret>', 'Signing secret', Env.get('SQLSERVER_PROXY_SECRET', ''));
|
|
52
|
-
cmd.option('--require-signing', 'Require request signing', Env.SQLSERVER_PROXY_REQUIRE_SIGNING);
|
|
54
|
+
cmd.option('--require-signing', 'Require request signing', Env.getBool('SQLSERVER_PROXY_REQUIRE_SIGNING', true));
|
|
53
55
|
cmd.option('--signing-window-ms <ms>', 'Signing window in milliseconds', String(Env.getInt('SQLSERVER_PROXY_SIGNING_WINDOW_MS', 60000)));
|
|
54
56
|
cmd.option('--watch', 'Watch mode: restart on file changes');
|
|
55
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WranglerProxyCommandUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/WranglerProxyCommandUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"WranglerProxyCommandUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/WranglerProxyCommandUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAkBrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,2BAA2B,GAAG,cAAc,GAAG;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,KAAK,+BAA+B,CAAC,OAAO,EAAE,QAAQ,SAAS,2BAA2B,IAAI;IAC5F,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,QAAQ,KAAK,OAAO,CAAC;IAC3E,cAAc,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,MAAM,CAAC;IAC5C,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACjD,CAAC;AAEF,eAAO,MAAM,2BAA2B,GAAI,SAAS,OAAO,EAAE,eAAe,MAAM,KAAG,IAIrF,CAAC;AAMF,eAAO,MAAM,0BAA0B,GAAI,OAAO,EAAE,QAAQ,SAAS,2BAA2B,EAC9F,OAAO,+BAA+B,CAAC,OAAO,EAAE,QAAQ,CAAC,KACxD,YAoFF,CAAC"}
|
|
@@ -1,37 +1,18 @@
|
|
|
1
1
|
import { BaseCommand } from '../BaseCommand.js';
|
|
2
2
|
import { withWranglerDevVarsSnapshot } from '../cloudflare/CloudflareWranglerDevEnv.js';
|
|
3
|
-
import { maybeRunProxyWatchMode, parseIntOption } from '../commands/ProxyCommandUtils.js';
|
|
3
|
+
import { ensureProxyEnvLoadedForCwd, maybeRunProxyWatchMode, parseIntOption, } from '../commands/ProxyCommandUtils.js';
|
|
4
4
|
import { ensureProxyEntrypoint, ensureWranglerConfig, renderProxyWranglerDevConfig, resolveConfigPath, } from '../commands/ProxyScaffoldUtils.js';
|
|
5
|
-
import { EnvFileLoader } from '../utils/EnvFileLoader.js';
|
|
6
5
|
import { SpawnUtil } from '../utils/spawn.js';
|
|
7
6
|
import { Logger } from '../../config/logger.js';
|
|
8
|
-
import {
|
|
7
|
+
import { mkdirSync, writeFileSync } from '../../node-singletons/fs.js';
|
|
9
8
|
import { dirname, join } from '../../node-singletons/path.js';
|
|
10
9
|
export const addWranglerProxyBaseOptions = (command, defaultConfig) => {
|
|
11
10
|
command.option('-c, --config <path>', 'Wrangler config file', defaultConfig);
|
|
12
11
|
command.option('--port <port>', 'Local Wrangler dev port');
|
|
13
12
|
command.option('--watch', 'Auto-restart proxy on file changes');
|
|
14
13
|
};
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
while (true) {
|
|
18
|
-
if (existsSync(join(current, 'package.json')))
|
|
19
|
-
return current;
|
|
20
|
-
const parent = dirname(current);
|
|
21
|
-
if (parent === current)
|
|
22
|
-
return undefined;
|
|
23
|
-
current = parent;
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
const resolveProxyProjectRoot = (cwd) => {
|
|
27
|
-
return findNearestPackageJsonDir(cwd) ?? cwd;
|
|
28
|
-
};
|
|
29
|
-
const ensureProxyEnvLoaded = (cwd, projectRoot) => {
|
|
30
|
-
EnvFileLoader.ensureLoaded({
|
|
31
|
-
cwd: projectRoot,
|
|
32
|
-
includeCwd: true,
|
|
33
|
-
...(cwd === projectRoot ? {} : { extraCwds: [cwd] }),
|
|
34
|
-
});
|
|
14
|
+
const toRootedProxyConfigContent = (content) => {
|
|
15
|
+
return content.replaceAll('": "../../', '": "./');
|
|
35
16
|
};
|
|
36
17
|
export const createWranglerProxyCommand = (input) => {
|
|
37
18
|
return BaseCommand.create({
|
|
@@ -44,8 +25,7 @@ export const createWranglerProxyCommand = (input) => {
|
|
|
44
25
|
await maybeRunProxyWatchMode(typedOptions.watch);
|
|
45
26
|
const port = parseIntOption(typedOptions.port, 'port');
|
|
46
27
|
const cwd = process.cwd();
|
|
47
|
-
const projectRoot =
|
|
48
|
-
ensureProxyEnvLoaded(cwd, projectRoot);
|
|
28
|
+
const projectRoot = ensureProxyEnvLoadedForCwd(cwd);
|
|
49
29
|
const entrypoint = ensureProxyEntrypoint({
|
|
50
30
|
cwd,
|
|
51
31
|
entryFile: input.entryFile,
|
|
@@ -72,24 +52,23 @@ export const createWranglerProxyCommand = (input) => {
|
|
|
72
52
|
}
|
|
73
53
|
input.afterConfigResolved?.(result.values);
|
|
74
54
|
const proxyConfigContent = renderProxyWranglerDevConfig(result.content, input.envName);
|
|
75
|
-
const proxyConfigDir =
|
|
76
|
-
const proxyConfigPath = join(proxyConfigDir,
|
|
55
|
+
const proxyConfigDir = cwd;
|
|
56
|
+
const proxyConfigPath = join(proxyConfigDir, `.zin.proxy.${input.envName}.jsonc`);
|
|
77
57
|
if (proxyConfigContent !== undefined) {
|
|
78
58
|
mkdirSync(proxyConfigDir, { recursive: true });
|
|
79
|
-
writeFileSync(proxyConfigPath, proxyConfigContent, 'utf-8');
|
|
59
|
+
writeFileSync(proxyConfigPath, toRootedProxyConfigContent(proxyConfigContent), 'utf-8');
|
|
80
60
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
];
|
|
61
|
+
const wranglerRunConfigPath = proxyConfigContent === undefined ? configPath : proxyConfigPath;
|
|
62
|
+
const wranglerDevVarsCwd = proxyConfigContent === undefined ? cwd : dirname(proxyConfigPath);
|
|
63
|
+
const wranglerDevVarsEnvName = proxyConfigContent === undefined ? input.envName : '';
|
|
64
|
+
const args = ['dev', '--config', wranglerRunConfigPath];
|
|
86
65
|
if (port !== undefined) {
|
|
87
66
|
args.push('--port', String(port));
|
|
88
67
|
}
|
|
89
68
|
const exitCode = await withWranglerDevVarsSnapshot({
|
|
90
|
-
cwd,
|
|
69
|
+
cwd: wranglerDevVarsCwd,
|
|
91
70
|
projectRoot,
|
|
92
|
-
envName:
|
|
71
|
+
envName: wranglerDevVarsEnvName,
|
|
93
72
|
configPath,
|
|
94
73
|
runtimeEnv: process.env,
|
|
95
74
|
}, async () => {
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zintrust/core v0.4.
|
|
2
|
+
* @zintrust/core v0.4.83
|
|
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:11:55.886Z
|
|
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:11:55.852Z'; // 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":"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,IAAI,CAAC,CAAC;CACrF,CAAC;AAEF,KAAK,WAAW,CAAC,CAAC,IAAI;IACpB,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;CACf,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,mBAAmB,CAAC;IACpD,GAAG,EAAE,CAAC,CAAC,GAAG,OAAO,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,KAAK,EAAE,CAAC,CAAC,GAAG,OAAO,OAAO,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC5C,GAAG,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;CACjC,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,mBAAmB,CAAC;CAC/C,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,EAAE,CAAC,EAAE,UAAU,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAkSF,eAAO,MAAM,eAAe;;;mBAGL,OAAO,OAAO,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;EAqB5D,CAAC;AAEH,eAAe,eAAe,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SystemTraceBridge } from '../../trace/SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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,CAAC;AAEjD,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,OAAO,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,IAAI,CAAC,CAAC;IACpF,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,EAAE,CAAC,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;CAChG,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,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 { SystemTraceBridge } from '../../trace/SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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
|
+
SystemTraceBridge.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,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;AA4QD;;GAEG;AACH,eAAO,MAAM,UAAU;IACrB;;OAEG;aACM,MAAM,GAAG,YAAY;IAI9B;;OAEG;cACO,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;IAQ/D;;OAEG;aACM,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;IAQ9D;;OAEG;eACQ,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;IAQhE;;OAEG;gBACS,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;EAOjE,CAAC;AAEH,eAAe,UAAU,CAAC"}
|
package/src/tools/http/Http.js
CHANGED
|
@@ -11,6 +11,64 @@ import { Env } from '../../config/env.js';
|
|
|
11
11
|
import { Logger } from '../../config/logger.js';
|
|
12
12
|
import { ErrorFactory } 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,KAAG,IAAI;2BA9FjE,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,OAChD,MAAM,YACD,MAAM,QACV,OAAO,YACH,OAAO,UACT,MAAM,QACR,MAAM,KACX,IAAI;wBA8FC,MAAM,QACN,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACnB,MAAM,YACN,MAAM,WACP,MAAM,KACd,IAAI;sBAlBkB,MAAM,iBAAiB,MAAM,YAAY,OAAO,KAAG,IAAI;8BAjC/C;QAC/B,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACvC,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACzC,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,KAAG,IAAI;4BApDuB,MAAM,SAAS,MAAM,cAAc,MAAM,SAAS,OAAO,KAAG,IAAI;0BAYlE,MAAM,SAAS,KAAK,KAAG,IAAI;6BANxB,MAAM,KAAG,IAAI;mBAyBvC,MAAM,WACD,MAAM,aACJ,MAAM,SACV,MAAM,SACN,MAAM,KACZ,IAAI;qCAjBS,MAAM,YACV,MAAM,EAAE,eACL,MAAM,YACT,MAAM,YACN,OAAO,KAChB,IAAI;uBAmCE,MAAM,UACL,OAAO,EAAE,YACP,MAAM,eACH,MAAM,KAClB,IAAI;yBAMqB,MAAM,YAAY,MAAM,KAAG,IAAI;EAiDzD,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
|
|
@@ -39,9 +39,9 @@ const withSystemTrace = (run) => {
|
|
|
39
39
|
.then(invoke)
|
|
40
40
|
.catch(() => undefined);
|
|
41
41
|
};
|
|
42
|
-
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;
|