@zintrust/core 0.4.40 → 0.4.42
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 +3 -2
- package/src/boot/registry/runtime.d.ts.map +1 -1
- package/src/boot/registry/runtime.js +120 -0
- package/src/cache/Cache.d.ts.map +1 -1
- package/src/cache/Cache.js +25 -2
- package/src/cli/BaseCommand.d.ts.map +1 -1
- package/src/cli/BaseCommand.js +8 -0
- package/src/cli/CLI.d.ts.map +1 -1
- package/src/cli/CLI.js +2 -0
- package/src/cli/OptionalCliExtensions.d.ts.map +1 -1
- package/src/cli/OptionalCliExtensions.js +12 -0
- package/src/cli/cloudflare/CloudflareSecretSync.d.ts.map +1 -1
- package/src/cli/cloudflare/CloudflareSecretSync.js +1 -2
- package/src/cli/cloudflare/CloudflareWranglerDevEnv.d.ts +24 -0
- package/src/cli/cloudflare/CloudflareWranglerDevEnv.d.ts.map +1 -0
- package/src/cli/cloudflare/CloudflareWranglerDevEnv.js +174 -0
- package/src/cli/commands/DebuggerCommand.d.ts +18 -0
- package/src/cli/commands/DebuggerCommand.d.ts.map +1 -0
- package/src/cli/commands/DebuggerCommand.js +6 -0
- package/src/cli/commands/DebuggerCommands.d.ts +25 -0
- package/src/cli/commands/DebuggerCommands.d.ts.map +1 -0
- package/src/cli/commands/DebuggerCommands.js +454 -0
- package/src/cli/commands/DeployCommand.d.ts.map +1 -1
- package/src/cli/commands/DeployCommand.js +3 -1
- package/src/cli/commands/DeployContainersProxyCommand.d.ts.map +1 -1
- package/src/cli/commands/DeployContainersProxyCommand.js +3 -1
- package/src/cli/commands/PrepareCommand.d.ts.map +1 -1
- package/src/cli/commands/PrepareCommand.js +56 -20
- package/src/cli/commands/StartCommand.d.ts.map +1 -1
- package/src/cli/commands/StartCommand.js +12 -94
- package/src/cli/commands/WranglerDevVarsCommand.d.ts +6 -0
- package/src/cli/commands/WranglerDevVarsCommand.d.ts.map +1 -0
- package/src/cli/commands/WranglerDevVarsCommand.js +52 -0
- package/src/cli/commands/index.d.ts +2 -0
- package/src/cli/commands/index.d.ts.map +1 -1
- package/src/cli/commands/index.js +2 -0
- package/src/cli/index.d.ts +1 -0
- package/src/cli/index.d.ts.map +1 -1
- package/src/cli/index.js +1 -0
- package/src/cli/utils/EnvFileLoader.d.ts.map +1 -1
- package/src/cli/utils/EnvFileLoader.js +21 -4
- package/src/cli.d.ts +1 -0
- package/src/cli.d.ts.map +1 -1
- package/src/cli.js +1 -0
- package/src/config/env.d.ts +16 -0
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +126 -2
- package/src/config/logger.d.ts +7 -0
- package/src/config/logger.d.ts.map +1 -1
- package/src/config/logger.js +37 -0
- package/src/debugger/SystemDebuggerBridge.d.ts +15 -0
- package/src/debugger/SystemDebuggerBridge.d.ts.map +1 -0
- package/src/debugger/SystemDebuggerBridge.js +109 -0
- package/src/events/EventDispatcher.d.ts.map +1 -1
- package/src/events/EventDispatcher.js +3 -0
- package/src/functions/cloudflare.d.ts.map +1 -1
- package/src/functions/cloudflare.js +27 -8
- package/src/http/Kernel.d.ts.map +1 -1
- package/src/http/Kernel.js +8 -0
- package/src/http/RequestContext.d.ts +1 -0
- package/src/http/RequestContext.d.ts.map +1 -1
- package/src/http/RequestContext.js +9 -1
- package/src/index.d.ts +4 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +5 -3
- package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -1
- package/src/migrations/schema/SchemaCompiler.js +2 -2
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/Database.js +0 -14
- package/src/orm/Model.d.ts +8 -2
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +193 -109
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +85 -1
- package/src/runtime/RuntimeServices.d.ts.map +1 -1
- package/src/runtime/RuntimeServices.js +4 -34
- package/src/runtime/WorkerAdapterImports.d.ts.map +1 -1
- package/src/runtime/WorkerAdapterImports.js +1 -6
- package/src/runtime/WorkerProjectPlugins.d.ts +6 -0
- package/src/runtime/WorkerProjectPlugins.d.ts.map +1 -0
- package/src/runtime/WorkerProjectPlugins.js +5 -0
- package/src/runtime/plugins/system-debugger-runtime.d.ts +19 -0
- package/src/runtime/plugins/system-debugger-runtime.d.ts.map +1 -0
- package/src/runtime/plugins/system-debugger-runtime.js +19 -0
- package/src/runtime/plugins/system-debugger.d.ts +2 -0
- package/src/runtime/plugins/system-debugger.d.ts.map +1 -0
- package/src/runtime/plugins/system-debugger.js +14 -0
- package/src/security/JwtManager.d.ts.map +1 -1
- package/src/security/JwtManager.js +29 -0
- package/src/tools/http/Http.d.ts.map +1 -1
- package/src/tools/http/Http.js +2 -0
- package/src/tools/mail/index.d.ts.map +1 -1
- package/src/tools/mail/index.js +7 -1
- package/src/tools/notification/Service.d.ts.map +1 -1
- package/src/tools/notification/Service.js +18 -6
- package/src/tools/queue/Queue.d.ts.map +1 -1
- package/src/tools/queue/Queue.js +2 -0
- package/src/zintrust.plugins.d.ts +1 -0
- package/src/zintrust.plugins.d.ts.map +1 -1
- package/src/zintrust.plugins.js +3 -21
- package/src/zintrust.plugins.wg.d.ts +1 -0
- package/src/zintrust.plugins.wg.d.ts.map +1 -1
- package/src/zintrust.plugins.wg.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.42",
|
|
4
4
|
"description": "Production-grade TypeScript backend framework for JavaScript",
|
|
5
5
|
"homepage": "https://zintrust.com",
|
|
6
6
|
"repository": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@cloudflare/containers": "^0.2.0",
|
|
61
|
-
"@zintrust/workers": "^0.4.
|
|
61
|
+
"@zintrust/workers": "^0.4.42",
|
|
62
62
|
"bcryptjs": "^3.0.3",
|
|
63
63
|
"bullmq": "^5.71.1",
|
|
64
64
|
"chalk": "^5.6.2",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"overrides": {
|
|
72
72
|
"ajv": "^8.18.0",
|
|
73
73
|
"axios": "^1.13.5",
|
|
74
|
+
"@tootallnate/once": "^3.0.1",
|
|
74
75
|
"node-forge": "^1.4.0",
|
|
75
76
|
"brace-expansion": "^5.0.5",
|
|
76
77
|
"picomatch": "^4.0.4",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/boot/registry/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../../src/boot/registry/runtime.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAOvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA+N9C,eAAO,MAAM,8BAA8B,GAAI,iBAAiB,gBAAgB,KAAG,IA4BlF,CAAC;AA6RF,eAAO,MAAM,eAAe,GAAI,QAAQ;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,EAAE,gBAAgB,CAAC;IAClC,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACrC,KAAG;IAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CA8E7D,CAAC"}
|
|
@@ -2,6 +2,7 @@ import * as RuntimeConfig from '../../config/index.js';
|
|
|
2
2
|
import { StartupHealthChecks } from '../../health/StartupHealthChecks.js';
|
|
3
3
|
import { loadQueueMonitorModule, loadWorkersModule } from '../../runtime/WorkersModule.js';
|
|
4
4
|
import { registerCachesFromRuntimeConfig } from '../../cache/CacheRuntimeRegistration.js';
|
|
5
|
+
import { readEnvString } from '../../common/ExternalServiceUtils.js';
|
|
5
6
|
import broadcastConfig from '../../config/broadcast.js';
|
|
6
7
|
import { Cloudflare } from '../../config/cloudflare.js';
|
|
7
8
|
import { FeatureFlags } from '../../config/features.js';
|
|
@@ -11,6 +12,7 @@ import { StartupConfigValidator } from '../../config/StartupConfigValidator.js';
|
|
|
11
12
|
import { existsSync } from '../../node-singletons/fs.js';
|
|
12
13
|
import * as path from '../../node-singletons/path.js';
|
|
13
14
|
import { pathToFileURL } from '../../node-singletons/url.js';
|
|
15
|
+
import { useDatabase } from '../../orm/Database.js';
|
|
14
16
|
import { registerDatabasesFromRuntimeConfig } from '../../orm/DatabaseRuntimeRegistration.js';
|
|
15
17
|
import { registerMasterRoutes, tryImportOptional } from './registerRoute.js';
|
|
16
18
|
import { registerWorkerShutdownHook } from './worker.js';
|
|
@@ -19,6 +21,44 @@ import { registerBroadcastersFromRuntimeConfig } from '../../tools/broadcast/Bro
|
|
|
19
21
|
import { registerNotificationChannelsFromRuntimeConfig } from '../../tools/notification/NotificationRuntimeRegistration.js';
|
|
20
22
|
import { registerQueuesFromRuntimeConfig } from '../../tools/queue/QueueRuntimeRegistration.js';
|
|
21
23
|
import { registerDisksFromRuntimeConfig } from '../../tools/storage/StorageRuntimeRegistration.js';
|
|
24
|
+
const importFromExistingCandidates = async (moduleCandidates) => {
|
|
25
|
+
for (const modulePath of moduleCandidates) {
|
|
26
|
+
if (!existsSync(modulePath))
|
|
27
|
+
continue;
|
|
28
|
+
try {
|
|
29
|
+
const url = pathToFileURL(modulePath).href;
|
|
30
|
+
// eslint-disable-next-line no-await-in-loop
|
|
31
|
+
return (await import(url));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// try next candidate
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
39
|
+
const loadLocalSystemDebuggerModule = async () => {
|
|
40
|
+
const globalDebuggerPluginState = globalThis;
|
|
41
|
+
if (globalDebuggerPluginState.__zintrust_system_debugger_runtime__ !== undefined) {
|
|
42
|
+
return globalDebuggerPluginState.__zintrust_system_debugger_runtime__;
|
|
43
|
+
}
|
|
44
|
+
const projectRoot = typeof process !== 'undefined' && typeof process.cwd === 'function' ? process.cwd() : '';
|
|
45
|
+
if (projectRoot !== '') {
|
|
46
|
+
const moduleCandidates = [
|
|
47
|
+
path.join(projectRoot, 'src', 'runtime', 'plugins', 'system-debugger-runtime.ts'),
|
|
48
|
+
path.join(projectRoot, 'src', 'runtime', 'plugins', 'system-debugger-runtime.js'),
|
|
49
|
+
path.join(projectRoot, 'dist', 'runtime', 'plugins', 'system-debugger-runtime.js'),
|
|
50
|
+
path.join(projectRoot, 'dist', 'src', 'runtime', 'plugins', 'system-debugger-runtime.js'),
|
|
51
|
+
];
|
|
52
|
+
const localModule = await importFromExistingCandidates(moduleCandidates);
|
|
53
|
+
if (localModule !== undefined) {
|
|
54
|
+
if (typeof localModule.isAvailable === 'function' && localModule.isAvailable() === false) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return localModule;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return tryImportOptional('@runtime/plugins/system-debugger-runtime');
|
|
61
|
+
};
|
|
22
62
|
const loadRuntimeQueueConfig = async () => {
|
|
23
63
|
try {
|
|
24
64
|
const modulePath = '@runtime-config/queue';
|
|
@@ -308,6 +348,85 @@ const initializeScheduleHttpGateway = async (router) => {
|
|
|
308
348
|
Logger.warn('Failed to register Schedule HTTP gateway routes', error);
|
|
309
349
|
}
|
|
310
350
|
};
|
|
351
|
+
const isDebuggerEnabled = () => {
|
|
352
|
+
const raw = readEnvString('DEBUGGER_ENABLED').trim().toLowerCase();
|
|
353
|
+
return raw === '1' || raw === 'true';
|
|
354
|
+
};
|
|
355
|
+
const isSystemDebuggerPluginRequested = () => {
|
|
356
|
+
const globalDebuggerPluginState = globalThis;
|
|
357
|
+
return globalDebuggerPluginState.__zintrust_system_debugger_plugin_requested__ === true;
|
|
358
|
+
};
|
|
359
|
+
const resolveDebuggerBasePath = () => {
|
|
360
|
+
const raw = readEnvString('DEBUGGER_BASE_PATH').trim();
|
|
361
|
+
if (raw === '')
|
|
362
|
+
return '/debugger';
|
|
363
|
+
return raw.startsWith('/') ? raw : `/${raw}`;
|
|
364
|
+
};
|
|
365
|
+
const resolveDebuggerMiddleware = () => {
|
|
366
|
+
const raw = readEnvString('DEBUGGER_MIDDLEWARE').trim();
|
|
367
|
+
if (raw === '')
|
|
368
|
+
return [];
|
|
369
|
+
return raw
|
|
370
|
+
.split(',')
|
|
371
|
+
.map((segment) => segment.trim())
|
|
372
|
+
.filter((segment) => segment !== '');
|
|
373
|
+
};
|
|
374
|
+
const resolveDebuggerConnectionName = (configuredConnection) => {
|
|
375
|
+
const explicitConnection = configuredConnection?.trim();
|
|
376
|
+
if (explicitConnection !== undefined && explicitConnection !== '')
|
|
377
|
+
return explicitConnection;
|
|
378
|
+
const defaultConnection = readEnvString('DB_CONNECTION').trim();
|
|
379
|
+
if (defaultConnection === '')
|
|
380
|
+
return 'default';
|
|
381
|
+
return defaultConnection;
|
|
382
|
+
};
|
|
383
|
+
const hasDebuggerRouteRegistered = (router, basePath) => {
|
|
384
|
+
return router.routes.some((route) => {
|
|
385
|
+
return (route.path === basePath ||
|
|
386
|
+
route.path === `${basePath}/*` ||
|
|
387
|
+
route.path.startsWith(`${basePath}/api`));
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
const initializeSystemDebugger = async (router) => {
|
|
391
|
+
if (!isSystemDebuggerPluginRequested()) {
|
|
392
|
+
Logger.debug('System Debugger plugin is not enabled in zintrust.plugins.*. Skipping mount.');
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (!isDebuggerEnabled())
|
|
396
|
+
return;
|
|
397
|
+
const debuggerModule = (await tryImportOptional('@zintrust/system-debugger')) ??
|
|
398
|
+
(await loadLocalSystemDebuggerModule());
|
|
399
|
+
if (debuggerModule === undefined) {
|
|
400
|
+
Logger.debug('System Debugger is enabled but the optional package is unavailable.');
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const debuggerRegisterModule = await tryImportOptional('@zintrust/system-debugger/register');
|
|
404
|
+
if (debuggerRegisterModule === undefined) {
|
|
405
|
+
const localDebuggerModule = await loadLocalSystemDebuggerModule();
|
|
406
|
+
if (localDebuggerModule === undefined) {
|
|
407
|
+
Logger.warn('System Debugger plugin was requested but the register module could not be loaded.');
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
Logger.debug('System Debugger register module is unavailable in source mode. Mounting dashboard routes without source fallback auto-registration.');
|
|
411
|
+
}
|
|
412
|
+
const config = debuggerModule.DebuggerConfig.merge();
|
|
413
|
+
const basePath = resolveDebuggerBasePath();
|
|
414
|
+
if (hasDebuggerRouteRegistered(router, basePath))
|
|
415
|
+
return;
|
|
416
|
+
try {
|
|
417
|
+
const db = useDatabase(undefined, resolveDebuggerConnectionName(config.connection));
|
|
418
|
+
const storage = debuggerModule.DebuggerStorage.resolveStorage(db);
|
|
419
|
+
const middleware = resolveDebuggerMiddleware();
|
|
420
|
+
debuggerModule.registerDebuggerRoutes(router, storage, {
|
|
421
|
+
basePath,
|
|
422
|
+
middleware: middleware.length > 0 ? middleware : undefined,
|
|
423
|
+
});
|
|
424
|
+
Logger.info(`System Debugger routes registered at http://127.0.0.1:${appConfig.port}${basePath}`);
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
Logger.warn('Failed to register System Debugger routes', error);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
311
430
|
export const createLifecycle = (params) => {
|
|
312
431
|
const boot = async () => {
|
|
313
432
|
if (params.getBooted())
|
|
@@ -335,6 +454,7 @@ export const createLifecycle = (params) => {
|
|
|
335
454
|
await registerFromRuntimeConfig();
|
|
336
455
|
await initializeArtifactDirectories(params.resolvedBasePath);
|
|
337
456
|
await registerMasterRoutes(params.resolvedBasePath, params.router);
|
|
457
|
+
await initializeSystemDebugger(params.router);
|
|
338
458
|
if (Cloudflare.getWorkersEnv() === null &&
|
|
339
459
|
appConfig.dockerWorker === false &&
|
|
340
460
|
appConfig.worker === true) {
|
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;AAEH,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;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA8JtD,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;AA8DH,eAAO,MAAM,KAAK;UA5HC,CAAC,OAAO,MAAM,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;UAWlC,CAAC,OAAO,MAAM,SAAS,CAAC,QAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;kBAUjD,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;iBAUtB,OAAO,CAAC,IAAI,CAAC;eASb,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;qBAW3B,WAAW;mBAaX,MAAM,KAAG,UAAU;iBAuDvB,IAAI;EAcpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,KAAK;UA1IC,CAAC,OAAO,MAAM,KAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;UAWlC,CAAC,OAAO,MAAM,SAAS,CAAC,QAAQ,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;kBAUjD,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;iBAUtB,OAAO,CAAC,IAAI,CAAC;eASb,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;qBAW3B,WAAW;mBAaX,MAAM,KAAG,UAAU;iBAuDvB,IAAI;EAmBI,CAAC"}
|
package/src/cache/Cache.js
CHANGED
|
@@ -11,6 +11,7 @@ import { MemoryDriver } from './drivers/MemoryDriver.js';
|
|
|
11
11
|
import { MongoDriver } from './drivers/MongoDriver.js';
|
|
12
12
|
import { RedisDriver } from './drivers/RedisDriver.js';
|
|
13
13
|
import { cacheConfig } from '../config/cache.js';
|
|
14
|
+
import { SystemDebuggerBridge } from '../debugger/SystemDebuggerBridge.js';
|
|
14
15
|
import { Env } from '../config/env.js';
|
|
15
16
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
16
17
|
const instances = new Map();
|
|
@@ -85,7 +86,9 @@ function getDriverInstance(storeName) {
|
|
|
85
86
|
*/
|
|
86
87
|
const get = async (key) => {
|
|
87
88
|
const prefixedKey = autoPrefixKey(key);
|
|
89
|
+
const startedAt = Date.now();
|
|
88
90
|
const value = await getDriverInstance().get(prefixedKey);
|
|
91
|
+
SystemDebuggerBridge.emitCache('get', prefixedKey, Date.now() - startedAt, value !== null);
|
|
89
92
|
return value;
|
|
90
93
|
};
|
|
91
94
|
/**
|
|
@@ -93,27 +96,35 @@ const get = async (key) => {
|
|
|
93
96
|
*/
|
|
94
97
|
const set = async (key, value, ttl) => {
|
|
95
98
|
const prefixedKey = autoPrefixKey(key);
|
|
99
|
+
const startedAt = Date.now();
|
|
96
100
|
await getDriverInstance().set(prefixedKey, value, ttl);
|
|
101
|
+
SystemDebuggerBridge.emitCache('set', prefixedKey, Date.now() - startedAt);
|
|
97
102
|
};
|
|
98
103
|
/**
|
|
99
104
|
* Remove an item from the cache
|
|
100
105
|
*/
|
|
101
106
|
const del = async (key) => {
|
|
102
107
|
const prefixedKey = autoPrefixKey(key);
|
|
108
|
+
const startedAt = Date.now();
|
|
103
109
|
await getDriverInstance().delete(prefixedKey);
|
|
110
|
+
SystemDebuggerBridge.emitCache('delete', prefixedKey, Date.now() - startedAt);
|
|
104
111
|
};
|
|
105
112
|
/**
|
|
106
113
|
* Clear all items from the cache
|
|
107
114
|
*/
|
|
108
115
|
const clear = async () => {
|
|
116
|
+
const startedAt = Date.now();
|
|
109
117
|
await getDriverInstance().clear();
|
|
118
|
+
SystemDebuggerBridge.emitCache('clear', 'zt:*', Date.now() - startedAt);
|
|
110
119
|
};
|
|
111
120
|
/**
|
|
112
121
|
* Check if an item exists in the cache
|
|
113
122
|
*/
|
|
114
123
|
const has = async (key) => {
|
|
115
124
|
const prefixedKey = autoPrefixKey(key);
|
|
125
|
+
const startedAt = Date.now();
|
|
116
126
|
const exists = await getDriverInstance().has(prefixedKey);
|
|
127
|
+
SystemDebuggerBridge.emitCache('has', prefixedKey, Date.now() - startedAt, exists);
|
|
117
128
|
return exists;
|
|
118
129
|
};
|
|
119
130
|
/**
|
|
@@ -125,22 +136,34 @@ const getDriver = () => {
|
|
|
125
136
|
const store = (name) => {
|
|
126
137
|
const getFromStore = async (key) => {
|
|
127
138
|
const prefixedKey = autoPrefixKey(key);
|
|
128
|
-
|
|
139
|
+
const startedAt = Date.now();
|
|
140
|
+
const value = await getDriverInstance(name).get(prefixedKey);
|
|
141
|
+
SystemDebuggerBridge.emitCache('get', prefixedKey, Date.now() - startedAt, value !== null);
|
|
142
|
+
return value;
|
|
129
143
|
};
|
|
130
144
|
const setInStore = async (key, value, ttl) => {
|
|
131
145
|
const prefixedKey = autoPrefixKey(key);
|
|
146
|
+
const startedAt = Date.now();
|
|
132
147
|
await getDriverInstance(name).set(prefixedKey, value, ttl);
|
|
148
|
+
SystemDebuggerBridge.emitCache('set', prefixedKey, Date.now() - startedAt);
|
|
133
149
|
};
|
|
134
150
|
const delFromStore = async (key) => {
|
|
135
151
|
const prefixedKey = autoPrefixKey(key);
|
|
152
|
+
const startedAt = Date.now();
|
|
136
153
|
await getDriverInstance(name).delete(prefixedKey);
|
|
154
|
+
SystemDebuggerBridge.emitCache('delete', prefixedKey, Date.now() - startedAt);
|
|
137
155
|
};
|
|
138
156
|
const clearStore = async () => {
|
|
157
|
+
const startedAt = Date.now();
|
|
139
158
|
await getDriverInstance(name).clear();
|
|
159
|
+
SystemDebuggerBridge.emitCache('clear', `store:${String(name ?? 'default')}`, Date.now() - startedAt);
|
|
140
160
|
};
|
|
141
161
|
const hasInStore = async (key) => {
|
|
142
162
|
const prefixedKey = autoPrefixKey(key);
|
|
143
|
-
|
|
163
|
+
const startedAt = Date.now();
|
|
164
|
+
const exists = await getDriverInstance(name).has(prefixedKey);
|
|
165
|
+
SystemDebuggerBridge.emitCache('has', prefixedKey, Date.now() - startedAt, exists);
|
|
166
|
+
return exists;
|
|
144
167
|
};
|
|
145
168
|
const getStoreDriver = () => {
|
|
146
169
|
return getDriverInstance(name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCommand.d.ts","sourceRoot":"","sources":["../../../src/cli/BaseCommand.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"BaseCommand.d.ts","sourceRoot":"","sources":["../../../src/cli/BaseCommand.ts"],"names":[],"mappings":"AAAA;;;GAGG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@@
|
|
|
2
2
|
* Base Command - Abstract Command Class
|
|
3
3
|
* All CLI commands extend this class
|
|
4
4
|
*/
|
|
5
|
+
import { SystemDebuggerBridge } from '../debugger/SystemDebuggerBridge.js';
|
|
5
6
|
import { ErrorHandler } from './ErrorHandler.js';
|
|
6
7
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
7
8
|
import { Command } from 'commander';
|
|
9
|
+
const toCommandArguments = (options) => {
|
|
10
|
+
return Object.fromEntries(Object.entries(options).filter(([, value]) => typeof value !== 'function'));
|
|
11
|
+
};
|
|
8
12
|
/**
|
|
9
13
|
* Command Factory Helper
|
|
10
14
|
* Sealed namespace for immutability
|
|
@@ -37,10 +41,14 @@ export const BaseCommand = Object.freeze({
|
|
|
37
41
|
const options = args.at(-2);
|
|
38
42
|
const commandArgs = args.slice(0, -2);
|
|
39
43
|
options.args = commandArgs;
|
|
44
|
+
const startedAt = Date.now();
|
|
40
45
|
try {
|
|
41
46
|
await config.execute(options);
|
|
47
|
+
SystemDebuggerBridge.emitCommand(config.name, toCommandArguments(options), 0, Date.now() - startedAt);
|
|
42
48
|
}
|
|
43
49
|
catch (error) {
|
|
50
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
51
|
+
SystemDebuggerBridge.emitCommand(config.name, toCommandArguments(options), 1, Date.now() - startedAt, message);
|
|
44
52
|
if (error instanceof Error) {
|
|
45
53
|
ErrorFactory.createTryCatchError('Command execution failed', error);
|
|
46
54
|
ErrorHandler.handle(error, undefined, false);
|
package/src/cli/CLI.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CLI.d.ts","sourceRoot":"","sources":["../../../src/cli/CLI.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"CLI.d.ts","sourceRoot":"","sources":["../../../src/cli/CLI.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,MAAM,WAAW,IAAI;IACnB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,UAAU,IAAI,OAAO,CAAC;CACvB;AAyPD;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG;cACJ,IAAI;EAed,CAAC"}
|
package/src/cli/CLI.js
CHANGED
|
@@ -60,6 +60,7 @@ import { SqlServerProxyCommand } from './commands/SqlServerProxyCommand.js';
|
|
|
60
60
|
import { StartCommand } from './commands/StartCommand.js';
|
|
61
61
|
import { TemplatesCommand } from './commands/TemplatesCommand.js';
|
|
62
62
|
import { UpgradeCommand } from './commands/UpgradeCommand.js';
|
|
63
|
+
import { WranglerDevVarsCommand } from './commands/WranglerDevVarsCommand.js';
|
|
63
64
|
import { ErrorHandler } from './ErrorHandler.js';
|
|
64
65
|
import { OptionalCliCommandRegistry } from './OptionalCliCommandRegistry.js';
|
|
65
66
|
import { VersionChecker } from './services/VersionChecker.js';
|
|
@@ -81,6 +82,7 @@ const buildCommandRegistry = () => {
|
|
|
81
82
|
NewCommand.create(),
|
|
82
83
|
UpgradeCommand.create(),
|
|
83
84
|
PrepareCommand,
|
|
85
|
+
WranglerDevVarsCommand.create(),
|
|
84
86
|
InitContainerCommand.create(),
|
|
85
87
|
InitContainersProxyCommand.create(),
|
|
86
88
|
InitProxyCommand.create(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionalCliExtensions.d.ts","sourceRoot":"","sources":["../../../src/cli/OptionalCliExtensions.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,KAAK,8BAA8B,GAAG,SAAS,GAAG,SAAS,GAAG,g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GAClD,0BAA0B,GAAG,SAAS;uCASN,0BAA0B,GAAG,MAAM;mCArDlC,MAAM,EAAE,KAAG,oBAAoB,GAAG,SAAS;EA8D/E,CAAC;AAEH,eAAO,MAAM,6BAA6B;yBA5UhB,MAAM;8BAQD,MAAM;wCAiG5B,oBAAoB,YACjB,+BAA+B,KACxC,MAAM,GAAG,IAAI;kCA7FqB,+BAA+B,KAAG,OAAO;4BAMnE,MAAM,QACT,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACnB,+BAA+B,KACxC,IAAI;8CA0GE,oBAAoB,YACjB,+BAA+B,KACxC,OAAO,CAAC,OAAO,CAAC;qCA0BV,oBAAoB,YACjB,+BAA+B,KACxC,OAAO,CAAC,OAAO,CAAC;uCAgCV,oBAAoB,YACjB,+BAA+B,KACxC,OAAO,CAAC,OAAO,CAAC;gCAuBV,oBAAoB,YACjB,+BAA+B,KACxC,OAAO,CAAC,0BAA0B,CAAC;gCAwCH,MAAM,EAAE,KAAG,MAAM,GAAG,SAAS;mCAU1B,MAAM,EAAE,KAAG,oBAAoB,GAAG,SAAS;8BAOhD,MAAM,EAAE,KAAG,OAAO;uCAvMT,oBAAoB,KAAG,MAAM,EAAE;gCAwBtC,oBAAoB,KAAG,MAAM,EAAE;EAuPhE,CAAC"}
|
|
@@ -63,6 +63,18 @@ const OPTIONAL_CLI_EXTENSIONS = Object.freeze([
|
|
|
63
63
|
path.join(packageRoot, 'dist', 'packages', 'workers', 'src', 'register.js'),
|
|
64
64
|
],
|
|
65
65
|
},
|
|
66
|
+
{
|
|
67
|
+
packageName: '@zintrust/system-debugger',
|
|
68
|
+
specifier: '@zintrust/system-debugger/cli-register',
|
|
69
|
+
commands: ['debugger:prune', 'debugger:clear', 'debugger:status', 'migrate:debugger'],
|
|
70
|
+
installCommand: 'npm install @zintrust/system-debugger',
|
|
71
|
+
localCandidates: [
|
|
72
|
+
path.join(packageRoot, 'packages', 'system-debugger', 'src', 'cli-register.ts'),
|
|
73
|
+
path.join(packageRoot, 'packages', 'system-debugger', 'src', 'cli-register.js'),
|
|
74
|
+
path.join(packageRoot, 'packages', 'system-debugger', 'dist', 'cli-register.js'),
|
|
75
|
+
path.join(packageRoot, 'dist', 'packages', 'system-debugger', 'src', 'cli-register.js'),
|
|
76
|
+
],
|
|
77
|
+
},
|
|
66
78
|
]);
|
|
67
79
|
const getProjectLocalCandidates = (entry) => {
|
|
68
80
|
const projectRoot = resolveProjectRoot();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudflareSecretSync.d.ts","sourceRoot":"","sources":["../../../../src/cli/cloudflare/CloudflareSecretSync.ts"],"names":[],"mappings":"AAYA,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAaF,KAAK,wBAAwB,GAAG;IAC9B,GAAG,EAAE,mBAAmB,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,2BAA2B,EAAE,CAAC;IACxC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Q,GAAG,UAAU,CAAC,KAC9D,IAcF,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAU,kGAUzC,wBAAwB,KAAG,OAAO,CAAC,0BAA0B,CAqC/D,CAAC;;8HArCC,wBAAwB,KAAG,OAAO,CAAC,0BAA0B,CAAC;sCA5B1D,mBAAmB,UAChB,IAAI,CAAC,0BAA0B,EAAE,QAAQ,GAAG,UAAU,CAAC,KAC9D,IAAI;;AAiEP,wBAGG"}
|
|
@@ -117,8 +117,7 @@ export const reportCloudflareSecretSync = (log, result) => {
|
|
|
117
117
|
};
|
|
118
118
|
export const syncCloudflareSecrets = async ({ log, cwd, wranglerEnvs, envPath, dryRun = false, configGroups = [], configPath, target, requireSelection = true, }) => {
|
|
119
119
|
const normalizedConfigPath = typeof configPath === 'string' && configPath.trim() !== '' ? configPath.trim() : undefined;
|
|
120
|
-
if (normalizedConfigPath !== undefined &&
|
|
121
|
-
!existsSync(path.join(cwd, normalizedConfigPath))) {
|
|
120
|
+
if (normalizedConfigPath !== undefined && !existsSync(path.join(cwd, normalizedConfigPath))) {
|
|
122
121
|
throw ErrorFactory.createCliError(`Wrangler config not found: ${normalizedConfigPath}`);
|
|
123
122
|
}
|
|
124
123
|
const config = readZintrustConfig(cwd);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type WranglerDevEnvArgs = {
|
|
2
|
+
cwd: string;
|
|
3
|
+
projectRoot: string;
|
|
4
|
+
envName?: string;
|
|
5
|
+
envPath?: string;
|
|
6
|
+
configPath?: string;
|
|
7
|
+
target?: string;
|
|
8
|
+
runtimeEnv?: NodeJS.ProcessEnv;
|
|
9
|
+
requireSelection?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type WranglerDevEnvMaterializationResult = {
|
|
12
|
+
filePath: string;
|
|
13
|
+
selectedKeys: string[];
|
|
14
|
+
missingKeys: string[];
|
|
15
|
+
values: Record<string, string>;
|
|
16
|
+
};
|
|
17
|
+
export declare const materializeWranglerDevVars: (args: WranglerDevEnvArgs) => Promise<WranglerDevEnvMaterializationResult>;
|
|
18
|
+
export declare const withWranglerDevVarsSnapshot: <T>(args: WranglerDevEnvArgs, fn: () => Promise<T>) => Promise<T>;
|
|
19
|
+
declare const _default: Readonly<{
|
|
20
|
+
materializeWranglerDevVars: (args: WranglerDevEnvArgs) => Promise<WranglerDevEnvMaterializationResult>;
|
|
21
|
+
withWranglerDevVarsSnapshot: <T>(args: WranglerDevEnvArgs, fn: () => Promise<T>) => Promise<T>;
|
|
22
|
+
}>;
|
|
23
|
+
export default _default;
|
|
24
|
+
//# sourceMappingURL=CloudflareWranglerDevEnv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CloudflareWranglerDevEnv.d.ts","sourceRoot":"","sources":["../../../../src/cli/cloudflare/CloudflareWranglerDevEnv.ts"],"names":[],"mappings":"AAUA,KAAK,kBAAkB,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC,CAAC;AAyJF,eAAO,MAAM,0BAA0B,GACrC,MAAM,kBAAkB,KACvB,OAAO,CAAC,mCAAmC,CAmB7C,CAAC;AAEF,eAAO,MAAM,2BAA2B,GAAU,CAAC,EACjD,MAAM,kBAAkB,EACxB,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,KACnB,OAAO,CAAC,CAAC,CA8BX,CAAC;;uCAvDM,kBAAkB,KACvB,OAAO,CAAC,mCAAmC,CAAC;kCAqBG,CAAC,QAC3C,kBAAkB,MACpB,MAAM,OAAO,CAAC,CAAC,CAAC,KACnB,OAAO,CAAC,CAAC,CAAC;;AAgCb,wBAGG"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { readZintrustConfig, resolveCloudflareEnvKeys, } from '../cloudflare/CloudflareEnvTargetConfig.js';
|
|
2
|
+
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
3
|
+
import { isNonEmptyString } from '../../helper/index.js';
|
|
4
|
+
import { existsSync, renameSync, unlinkSync } from '../../node-singletons/fs.js';
|
|
5
|
+
import * as path from '../../node-singletons/path.js';
|
|
6
|
+
import { EnvFile } from '../../toolkit/Secrets/EnvFile.js';
|
|
7
|
+
const WRANGLER_RUNTIME_ENV_KEYS = Object.freeze([
|
|
8
|
+
'APP_PORT',
|
|
9
|
+
'CLOUDFLARE_WORKER',
|
|
10
|
+
'DOCKER_WORKER',
|
|
11
|
+
'ENVIRONMENT',
|
|
12
|
+
'HOST',
|
|
13
|
+
'NODE_ENV',
|
|
14
|
+
'PORT',
|
|
15
|
+
'RUNTIME',
|
|
16
|
+
'SERVICE_DOMAIN',
|
|
17
|
+
'SERVICE_NAME',
|
|
18
|
+
'SERVICE_PORT',
|
|
19
|
+
'WORKER_ENABLED',
|
|
20
|
+
'ZINTRUST_PROJECT_ROOT',
|
|
21
|
+
]);
|
|
22
|
+
const isAsciiUppercaseLetter = (value) => value >= 'A' && value <= 'Z';
|
|
23
|
+
const isAsciiDigit = (value) => value >= '0' && value <= '9';
|
|
24
|
+
const isWranglerWordCharacter = (value) => isAsciiUppercaseLetter(value) || isAsciiDigit(value) || value === '_';
|
|
25
|
+
const isWranglerVarName = (value) => {
|
|
26
|
+
if (value.length === 0)
|
|
27
|
+
return false;
|
|
28
|
+
const first = value[0] ?? '';
|
|
29
|
+
if (!(isAsciiUppercaseLetter(first) || first === '_'))
|
|
30
|
+
return false;
|
|
31
|
+
for (let index = 1; index < value.length; index += 1) {
|
|
32
|
+
if (!isWranglerWordCharacter(value[index] ?? ''))
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
};
|
|
37
|
+
const uniq = (items) => {
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
const output = [];
|
|
40
|
+
for (const item of items) {
|
|
41
|
+
const normalized = item.trim();
|
|
42
|
+
if (normalized === '' || seen.has(normalized))
|
|
43
|
+
continue;
|
|
44
|
+
seen.add(normalized);
|
|
45
|
+
output.push(normalized);
|
|
46
|
+
}
|
|
47
|
+
return output;
|
|
48
|
+
};
|
|
49
|
+
const getNormalizedEnvName = (envName) => {
|
|
50
|
+
return typeof envName === 'string' ? envName.trim() : '';
|
|
51
|
+
};
|
|
52
|
+
const getWranglerDevVarsFileName = (envName) => {
|
|
53
|
+
const normalizedEnv = getNormalizedEnvName(envName);
|
|
54
|
+
return normalizedEnv === '' ? '.dev.vars' : `.dev.vars.${normalizedEnv}`;
|
|
55
|
+
};
|
|
56
|
+
const getWranglerDevVarsBackupPath = (targetPath) => `${targetPath}.disabled-by-zin`;
|
|
57
|
+
const reconcileWranglerEnvBackup = (targetPath, backupPath) => {
|
|
58
|
+
const hasTarget = existsSync(targetPath);
|
|
59
|
+
const hasBackup = existsSync(backupPath);
|
|
60
|
+
if (!hasBackup)
|
|
61
|
+
return;
|
|
62
|
+
if (!hasTarget) {
|
|
63
|
+
renameSync(backupPath, targetPath);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
unlinkSync(backupPath);
|
|
67
|
+
};
|
|
68
|
+
const resolveRuntimeEnvMap = (runtimeEnv) => {
|
|
69
|
+
return Object.fromEntries(Object.entries(runtimeEnv).filter((entry) => {
|
|
70
|
+
return typeof entry[1] === 'string';
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
const resolveSelectedKeys = (args) => {
|
|
74
|
+
const zintrustConfigPath = path.join(args.projectRoot, '.zintrust.json');
|
|
75
|
+
if (!existsSync(zintrustConfigPath)) {
|
|
76
|
+
if (args.requireSelection === true) {
|
|
77
|
+
throw ErrorFactory.createCliError('No .zintrust.json found. Add a Cloudflare env manifest before generating Wrangler dev vars.');
|
|
78
|
+
}
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const selectedKeys = resolveCloudflareEnvKeys({
|
|
82
|
+
config: readZintrustConfig(args.projectRoot),
|
|
83
|
+
projectRoot: args.projectRoot,
|
|
84
|
+
cwd: args.cwd,
|
|
85
|
+
...(isNonEmptyString(args.configPath) ? { configPath: args.configPath.trim() } : {}),
|
|
86
|
+
...(isNonEmptyString(args.envName) ? { wranglerEnv: args.envName.trim() } : {}),
|
|
87
|
+
...(isNonEmptyString(args.target) ? { target: args.target.trim() } : {}),
|
|
88
|
+
});
|
|
89
|
+
if (selectedKeys.length === 0 && args.requireSelection === true) {
|
|
90
|
+
throw ErrorFactory.createCliError('No Wrangler dev env keys resolved from .zintrust.json cloudflare.shared_env/cloudflare.targets/cloudflare.wrangler_envs.');
|
|
91
|
+
}
|
|
92
|
+
return selectedKeys;
|
|
93
|
+
};
|
|
94
|
+
const collectWranglerDevVarValues = async (args, selectedKeys) => {
|
|
95
|
+
const runtimeEnv = resolveRuntimeEnvMap(args.runtimeEnv ?? process.env);
|
|
96
|
+
const envPath = isNonEmptyString(args.envPath) ? args.envPath.trim() : '.env';
|
|
97
|
+
const envFileValues = await EnvFile.read({
|
|
98
|
+
cwd: args.projectRoot,
|
|
99
|
+
path: envPath,
|
|
100
|
+
});
|
|
101
|
+
const allowedKeys = selectedKeys.length === 0
|
|
102
|
+
? undefined
|
|
103
|
+
: new Set([...WRANGLER_RUNTIME_ENV_KEYS, ...selectedKeys]);
|
|
104
|
+
const candidateKeys = allowedKeys === undefined
|
|
105
|
+
? uniq([...Object.keys(runtimeEnv), ...Object.keys(envFileValues)]).filter(isWranglerVarName)
|
|
106
|
+
: [...allowedKeys].filter(isWranglerVarName);
|
|
107
|
+
const values = {};
|
|
108
|
+
const missingKeys = [];
|
|
109
|
+
for (const key of candidateKeys) {
|
|
110
|
+
const value = envFileValues[key] ?? runtimeEnv[key];
|
|
111
|
+
if (typeof value !== 'string') {
|
|
112
|
+
if (selectedKeys.includes(key))
|
|
113
|
+
missingKeys.push(key);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
values[key] = value;
|
|
117
|
+
}
|
|
118
|
+
return { values, missingKeys };
|
|
119
|
+
};
|
|
120
|
+
export const materializeWranglerDevVars = async (args) => {
|
|
121
|
+
const selectedKeys = resolveSelectedKeys(args);
|
|
122
|
+
const { values, missingKeys } = await collectWranglerDevVarValues(args, selectedKeys);
|
|
123
|
+
const fileName = getWranglerDevVarsFileName(args.envName);
|
|
124
|
+
const filePath = path.join(args.cwd, fileName);
|
|
125
|
+
await EnvFile.write({
|
|
126
|
+
cwd: args.cwd,
|
|
127
|
+
path: fileName,
|
|
128
|
+
values,
|
|
129
|
+
mode: 'overwrite',
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
filePath,
|
|
133
|
+
selectedKeys,
|
|
134
|
+
missingKeys,
|
|
135
|
+
values,
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
export const withWranglerDevVarsSnapshot = async (args, fn) => {
|
|
139
|
+
const targetPath = path.join(args.cwd, getWranglerDevVarsFileName(args.envName));
|
|
140
|
+
const backupPath = getWranglerDevVarsBackupPath(targetPath);
|
|
141
|
+
try {
|
|
142
|
+
reconcileWranglerEnvBackup(targetPath, backupPath);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// noop
|
|
146
|
+
}
|
|
147
|
+
if (existsSync(targetPath)) {
|
|
148
|
+
renameSync(targetPath, backupPath);
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
await materializeWranglerDevVars(args);
|
|
152
|
+
return await fn();
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
try {
|
|
156
|
+
if (existsSync(targetPath))
|
|
157
|
+
unlinkSync(targetPath);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// noop
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
if (existsSync(backupPath))
|
|
164
|
+
renameSync(backupPath, targetPath);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// noop
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
export default Object.freeze({
|
|
172
|
+
materializeWranglerDevVars,
|
|
173
|
+
withWranglerDevVarsSnapshot,
|
|
174
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { DebuggerCommands } from '../commands/DebuggerCommands';
|
|
2
|
+
export declare const DebuggerPruneCommand: Readonly<{
|
|
3
|
+
name: string;
|
|
4
|
+
getCommand: () => import("commander").Command;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const DebuggerClearCommand: Readonly<{
|
|
7
|
+
name: string;
|
|
8
|
+
getCommand: () => import("commander").Command;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const DebuggerStatusCommand: Readonly<{
|
|
11
|
+
name: string;
|
|
12
|
+
getCommand: () => import("commander").Command;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const DebuggerMigrateCommand: Readonly<{
|
|
15
|
+
name: string;
|
|
16
|
+
getCommand: () => import("commander").Command;
|
|
17
|
+
}>;
|
|
18
|
+
//# sourceMappingURL=DebuggerCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DebuggerCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/DebuggerCommand.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE,eAAO,MAAM,oBAAoB;;;EAAiD,CAAC;AAEnF,eAAO,MAAM,oBAAoB;;;EAAiD,CAAC;AAEnF,eAAO,MAAM,qBAAqB;;;EAAkD,CAAC;AAErF,eAAO,MAAM,sBAAsB;;;EAAmD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DebuggerCommands } from '../commands/DebuggerCommands.js';
|
|
2
|
+
export { DebuggerCommands } from '../commands/DebuggerCommands.js';
|
|
3
|
+
export const DebuggerPruneCommand = DebuggerCommands.createDebuggerPruneProvider();
|
|
4
|
+
export const DebuggerClearCommand = DebuggerCommands.createDebuggerClearProvider();
|
|
5
|
+
export const DebuggerStatusCommand = DebuggerCommands.createDebuggerStatusProvider();
|
|
6
|
+
export const DebuggerMigrateCommand = DebuggerCommands.createDebuggerMigrateProvider();
|