@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseCommand } from '../BaseCommand.js';
|
|
2
|
-
import {
|
|
2
|
+
import { withWranglerDevVarsSnapshot } from '../cloudflare/CloudflareWranglerDevEnv.js';
|
|
3
3
|
import { createDenoRunnerSource, createLambdaRunnerSource } from '../commands/runner/index.js';
|
|
4
4
|
import { EnvFileLoader } from '../utils/EnvFileLoader.js';
|
|
5
5
|
import { SpawnUtil } from '../utils/spawn.js';
|
|
@@ -7,7 +7,7 @@ import { readEnvString } from '../../common/ExternalServiceUtils.js';
|
|
|
7
7
|
import * as Common from '../../common/index.js';
|
|
8
8
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
9
9
|
import { isNonEmptyString } from '../../helper/index.js';
|
|
10
|
-
import { existsSync, mkdirSync, readFileSync,
|
|
10
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from '../../node-singletons/fs.js';
|
|
11
11
|
import * as path from '../../node-singletons/path.js';
|
|
12
12
|
import { ProjectRuntime } from '../../runtime/ProjectRuntime.js';
|
|
13
13
|
const isAsciiUppercaseLetter = (value) => value >= 'A' && value <= 'Z';
|
|
@@ -337,82 +337,6 @@ const buildStartEnv = (projectRoot) => ({
|
|
|
337
337
|
...process.env,
|
|
338
338
|
ZINTRUST_PROJECT_ROOT: projectRoot,
|
|
339
339
|
});
|
|
340
|
-
const WRANGLER_RUNTIME_ENV_KEYS = Object.freeze([
|
|
341
|
-
'APP_PORT',
|
|
342
|
-
'CLOUDFLARE_WORKER',
|
|
343
|
-
'DOCKER_WORKER',
|
|
344
|
-
'ENVIRONMENT',
|
|
345
|
-
'HOST',
|
|
346
|
-
'NODE_ENV',
|
|
347
|
-
'PORT',
|
|
348
|
-
'RUNTIME',
|
|
349
|
-
'SERVICE_DOMAIN',
|
|
350
|
-
'SERVICE_NAME',
|
|
351
|
-
'SERVICE_PORT',
|
|
352
|
-
'WORKER_ENABLED',
|
|
353
|
-
'ZINTRUST_PROJECT_ROOT',
|
|
354
|
-
]);
|
|
355
|
-
const buildWorkerDevVarsContent = (selectedKeys) => {
|
|
356
|
-
const allowedKeys = selectedKeys === undefined || selectedKeys.length === 0
|
|
357
|
-
? undefined
|
|
358
|
-
: new Set([...WRANGLER_RUNTIME_ENV_KEYS, ...selectedKeys]);
|
|
359
|
-
return (Object.entries(process.env)
|
|
360
|
-
.filter((entry) => {
|
|
361
|
-
const [key, value] = entry;
|
|
362
|
-
return (isWranglerVarName(key) &&
|
|
363
|
-
typeof value === 'string' &&
|
|
364
|
-
(allowedKeys === undefined || allowedKeys.has(key)));
|
|
365
|
-
})
|
|
366
|
-
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
|
|
367
|
-
.join('\n') + '\n');
|
|
368
|
-
};
|
|
369
|
-
const getWranglerEnvBackupPath = (targetPath) => `${targetPath}.disabled-by-zin`;
|
|
370
|
-
const reconcileWranglerEnvBackup = (targetPath, backupPath) => {
|
|
371
|
-
const hasTarget = existsSync(targetPath);
|
|
372
|
-
const hasBackup = existsSync(backupPath);
|
|
373
|
-
if (!hasBackup)
|
|
374
|
-
return;
|
|
375
|
-
if (!hasTarget) {
|
|
376
|
-
renameSync(backupPath, targetPath);
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
unlinkSync(backupPath);
|
|
380
|
-
};
|
|
381
|
-
async function withWranglerEnvSnapshot(cwd, envName, selectedKeys, fn) {
|
|
382
|
-
const normalizedEnv = typeof envName === 'string' ? envName.trim() : '';
|
|
383
|
-
const targetName = normalizedEnv === '' ? '.dev.vars' : `.dev.vars.${normalizedEnv}`;
|
|
384
|
-
const targetPath = path.join(cwd, targetName);
|
|
385
|
-
const backupPath = getWranglerEnvBackupPath(targetPath);
|
|
386
|
-
try {
|
|
387
|
-
reconcileWranglerEnvBackup(targetPath, backupPath);
|
|
388
|
-
}
|
|
389
|
-
catch {
|
|
390
|
-
// noop
|
|
391
|
-
}
|
|
392
|
-
if (existsSync(targetPath)) {
|
|
393
|
-
renameSync(targetPath, backupPath);
|
|
394
|
-
}
|
|
395
|
-
try {
|
|
396
|
-
writeFileSync(targetPath, buildWorkerDevVarsContent(selectedKeys), 'utf-8');
|
|
397
|
-
return await fn();
|
|
398
|
-
}
|
|
399
|
-
finally {
|
|
400
|
-
try {
|
|
401
|
-
if (existsSync(targetPath))
|
|
402
|
-
unlinkSync(targetPath);
|
|
403
|
-
}
|
|
404
|
-
catch {
|
|
405
|
-
// noop
|
|
406
|
-
}
|
|
407
|
-
try {
|
|
408
|
-
if (existsSync(backupPath))
|
|
409
|
-
renameSync(backupPath, targetPath);
|
|
410
|
-
}
|
|
411
|
-
catch {
|
|
412
|
-
// noop
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
340
|
const resolveManifestServiceEnvDir = (projectRoot, entry) => {
|
|
417
341
|
const configRoot = entry.configRoot;
|
|
418
342
|
if (isNonEmptyString(configRoot)) {
|
|
@@ -564,19 +488,7 @@ const buildWranglerDevArgs = (args) => {
|
|
|
564
488
|
}
|
|
565
489
|
return wranglerArgs;
|
|
566
490
|
};
|
|
567
|
-
const
|
|
568
|
-
const zintrustConfigPath = path.join(context.projectRoot, '.zintrust.json');
|
|
569
|
-
if (!existsSync(zintrustConfigPath))
|
|
570
|
-
return undefined;
|
|
571
|
-
return resolveCloudflareEnvKeys({
|
|
572
|
-
config: readZintrustConfig(context.projectRoot),
|
|
573
|
-
projectRoot: context.projectRoot,
|
|
574
|
-
cwd: context.cwd,
|
|
575
|
-
...(configPath === undefined ? {} : { configPath }),
|
|
576
|
-
...(envName === undefined ? {} : { wranglerEnv: envName }),
|
|
577
|
-
});
|
|
578
|
-
};
|
|
579
|
-
const executeWranglerStart = async (cmd, context, port, runtime, envName, wranglerConfig) => {
|
|
491
|
+
const executeWranglerStart = async (cmd, context, port, runtime, envName, wranglerConfig, envPath) => {
|
|
580
492
|
if (runtime !== undefined) {
|
|
581
493
|
throw ErrorFactory.createCliError('Error: --runtime is not supported with --wrangler (Wrangler controls Workers runtime).');
|
|
582
494
|
}
|
|
@@ -591,8 +503,13 @@ const executeWranglerStart = async (cmd, context, port, runtime, envName, wrangl
|
|
|
591
503
|
});
|
|
592
504
|
logMySqlProxyHint(cmd);
|
|
593
505
|
cmd.info('Starting in Wrangler dev mode...');
|
|
594
|
-
const
|
|
595
|
-
|
|
506
|
+
const exitCode = await withWranglerDevVarsSnapshot({
|
|
507
|
+
cwd: context.cwd,
|
|
508
|
+
projectRoot: context.projectRoot,
|
|
509
|
+
envName,
|
|
510
|
+
...(envPath === undefined ? {} : { envPath }),
|
|
511
|
+
...(configPath === undefined ? {} : { configPath }),
|
|
512
|
+
}, async () => {
|
|
596
513
|
const startEnv = {
|
|
597
514
|
...buildStartEnv(context.projectRoot),
|
|
598
515
|
WORKER_ENABLED: 'false',
|
|
@@ -805,7 +722,8 @@ const executeStart = async (options, cmd) => {
|
|
|
805
722
|
const wranglerConfig = typeof options.wranglerConfig === 'string' && options.wranglerConfig.trim() !== ''
|
|
806
723
|
? options.wranglerConfig.trim()
|
|
807
724
|
: undefined;
|
|
808
|
-
|
|
725
|
+
const envPath = resolveEnvPath(options, context.projectRoot);
|
|
726
|
+
await executeWranglerStart(cmd, context, port, runtime, envName === '' ? undefined : envName, wranglerConfig, envPath);
|
|
809
727
|
return;
|
|
810
728
|
}
|
|
811
729
|
if (envName !== '') {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WranglerDevVarsCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/WranglerDevVarsCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA2DvF,eAAO,MAAM,sBAAsB;cACvB,YAAY;EAYtB,CAAC;AAEH,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BaseCommand } from '../BaseCommand.js';
|
|
2
|
+
import { materializeWranglerDevVars } from '../cloudflare/CloudflareWranglerDevEnv.js';
|
|
3
|
+
const optionalTrimmed = (value) => {
|
|
4
|
+
if (typeof value !== 'string')
|
|
5
|
+
return undefined;
|
|
6
|
+
const trimmed = value.trim();
|
|
7
|
+
return trimmed === '' ? undefined : trimmed;
|
|
8
|
+
};
|
|
9
|
+
const addOptions = (command) => {
|
|
10
|
+
command
|
|
11
|
+
.option('--env <name>', 'Wrangler environment name used for .dev.vars.<env> output')
|
|
12
|
+
.option('--env-path <path>', 'Env file used as source values for generated Wrangler dev vars', '.env')
|
|
13
|
+
.option('--target <id>', 'Cloudflare worker target key from .zintrust.json cloudflare.targets')
|
|
14
|
+
.option('-c, --config <path>', 'Wrangler config file used for target inference (optional)');
|
|
15
|
+
};
|
|
16
|
+
const execute = async (cmd, options) => {
|
|
17
|
+
const result = await materializeWranglerDevVars({
|
|
18
|
+
cwd: process.cwd(),
|
|
19
|
+
projectRoot: process.cwd(),
|
|
20
|
+
...(optionalTrimmed(options.env) === undefined
|
|
21
|
+
? {}
|
|
22
|
+
: { envName: optionalTrimmed(options.env) }),
|
|
23
|
+
...(optionalTrimmed(options.envPath) === undefined
|
|
24
|
+
? {}
|
|
25
|
+
: { envPath: optionalTrimmed(options.envPath) }),
|
|
26
|
+
...(optionalTrimmed(options.target) === undefined
|
|
27
|
+
? {}
|
|
28
|
+
: { target: optionalTrimmed(options.target) }),
|
|
29
|
+
...(optionalTrimmed(options.config) === undefined
|
|
30
|
+
? {}
|
|
31
|
+
: { configPath: optionalTrimmed(options.config) }),
|
|
32
|
+
requireSelection: true,
|
|
33
|
+
});
|
|
34
|
+
cmd.success(`Wrangler dev vars prepared at ${result.filePath}`);
|
|
35
|
+
cmd.info(`Selected keys: ${result.selectedKeys.length}`);
|
|
36
|
+
if (result.missingKeys.length > 0) {
|
|
37
|
+
cmd.warn(`Missing keys: ${result.missingKeys.join(', ')}`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const WranglerDevVarsCommand = Object.freeze({
|
|
41
|
+
create() {
|
|
42
|
+
const cmd = BaseCommand.create({
|
|
43
|
+
name: 'wrangler:dev-vars',
|
|
44
|
+
description: 'Generate manifest-scoped Wrangler .dev.vars files for local Worker development',
|
|
45
|
+
aliases: ['cloudflare:dev-vars'],
|
|
46
|
+
addOptions,
|
|
47
|
+
execute: async (options) => execute(cmd, options),
|
|
48
|
+
});
|
|
49
|
+
return cmd;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
export default WranglerDevVarsCommand;
|
|
@@ -8,6 +8,7 @@ export { ContainerWorkersCommand } from '../commands/ContainerWorkersCommand';
|
|
|
8
8
|
export { AddMigrationCommand, CreateCommand, CreateMigrationCommand, } from '../commands/CreateCommand';
|
|
9
9
|
export { D1ProxyCommand } from '../commands/D1ProxyCommand';
|
|
10
10
|
export { DebugCommand } from '../commands/DebugCommand';
|
|
11
|
+
export { DebuggerCommands } from '../commands/DebuggerCommands';
|
|
11
12
|
export { JwtDevCommand } from '../commands/JwtDevCommand';
|
|
12
13
|
export { KvProxyCommand } from '../commands/KvProxyCommand';
|
|
13
14
|
export { LogsCleanupCommand } from '../commands/LogsCleanupCommand';
|
|
@@ -25,4 +26,5 @@ export { RoutesCommand } from '../commands/RoutesCommand';
|
|
|
25
26
|
export { SecretsCommand } from '../commands/SecretsCommand';
|
|
26
27
|
export { StartCommand } from '../commands/StartCommand';
|
|
27
28
|
export { TemplatesCommand } from '../commands/TemplatesCommand';
|
|
29
|
+
export { WranglerDevVarsCommand } from '../commands/WranglerDevVarsCommand';
|
|
28
30
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,uBAA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,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,+BAA+B,EAAE,MAAM,+CAA+C,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC"}
|
|
@@ -8,6 +8,7 @@ export { ContainerWorkersCommand } from '../commands/ContainerWorkersCommand.js'
|
|
|
8
8
|
export { AddMigrationCommand, CreateCommand, CreateMigrationCommand, } from '../commands/CreateCommand.js';
|
|
9
9
|
export { D1ProxyCommand } from '../commands/D1ProxyCommand.js';
|
|
10
10
|
export { DebugCommand } from '../commands/DebugCommand.js';
|
|
11
|
+
export { DebuggerCommands } from '../commands/DebuggerCommands.js';
|
|
11
12
|
export { JwtDevCommand } from '../commands/JwtDevCommand.js';
|
|
12
13
|
export { KvProxyCommand } from '../commands/KvProxyCommand.js';
|
|
13
14
|
export { LogsCleanupCommand } from '../commands/LogsCleanupCommand.js';
|
|
@@ -25,3 +26,4 @@ export { RoutesCommand } from '../commands/RoutesCommand.js';
|
|
|
25
26
|
export { SecretsCommand } from '../commands/SecretsCommand.js';
|
|
26
27
|
export { StartCommand } from '../commands/StartCommand.js';
|
|
27
28
|
export { TemplatesCommand } from '../commands/TemplatesCommand.js';
|
|
29
|
+
export { WranglerDevVarsCommand } from '../commands/WranglerDevVarsCommand.js';
|
package/src/cli/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { AddCommand } from './commands/AddCommand';
|
|
|
10
10
|
export { ConfigCommand } from './commands/ConfigCommand';
|
|
11
11
|
export { D1ProxyCommand } from './commands/D1ProxyCommand';
|
|
12
12
|
export { DebugCommand } from './commands/DebugCommand';
|
|
13
|
+
export { DebuggerCommands } from './commands/DebuggerCommands';
|
|
13
14
|
export { KvProxyCommand } from './commands/KvProxyCommand';
|
|
14
15
|
export { MigrateCommand } from './commands/MigrateCommand';
|
|
15
16
|
export { MySqlProxyCommand } from './commands/MySqlProxyCommand';
|
package/src/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAA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AAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
|
package/src/cli/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { AddCommand } from './commands/AddCommand.js';
|
|
|
11
11
|
export { ConfigCommand } from './commands/ConfigCommand.js';
|
|
12
12
|
export { D1ProxyCommand } from './commands/D1ProxyCommand.js';
|
|
13
13
|
export { DebugCommand } from './commands/DebugCommand.js';
|
|
14
|
+
export { DebuggerCommands } from './commands/DebuggerCommands.js';
|
|
14
15
|
export { KvProxyCommand } from './commands/KvProxyCommand.js';
|
|
15
16
|
export { MigrateCommand } from './commands/MigrateCommand.js';
|
|
16
17
|
export { MySqlProxyCommand } from './commands/MySqlProxyCommand.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvFileLoader.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/EnvFileLoader.ts"],"names":[],"mappings":"AASA,KAAK,QAAQ,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"EnvFileLoader.d.ts","sourceRoot":"","sources":["../../../../src/cli/utils/EnvFileLoader.ts"],"names":[],"mappings":"AASA,KAAK,QAAQ,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS,CAAC;AA8IzD,KAAK,WAAW,GAAG;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,KAAK,SAAS,GAAG;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAaF,KAAK,YAAY,GAAG;IAClB,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAwMF,eAAO,MAAM,aAAa;qBAjDH,WAAW,KAAQ,SAAS;6BAapB,IAAI,CAAC,WAAW,EAAE,kBAAkB,CAAC,KAAQ,SAAS;mCAG/C,YAAY,KAAG,IAAI;oBA+BpC,SAAS;EAO5B,CAAC"}
|
|
@@ -2,10 +2,8 @@ import { Env } from '../../config/env.js';
|
|
|
2
2
|
import { isArray, isNonEmptyString } from '../../helper/index.js';
|
|
3
3
|
import { existsSync, readFileSync } from '../../node-singletons/fs.js';
|
|
4
4
|
import * as path from '../../node-singletons/path.js';
|
|
5
|
+
const PACK_CONTROL_KEYS = new Set(['USE_PACK', 'PACK_KEYS']);
|
|
5
6
|
const safeEnvGet = (key, defaultValue = '') => {
|
|
6
|
-
const envAny = Env;
|
|
7
|
-
if (typeof envAny.get === 'function')
|
|
8
|
-
return envAny.get(key, defaultValue);
|
|
9
7
|
const fromProcess = typeof process === 'undefined' ? undefined : process.env?.[key];
|
|
10
8
|
if (typeof fromProcess === 'string' && fromProcess !== '')
|
|
11
9
|
return fromProcess;
|
|
@@ -109,6 +107,18 @@ const readEnvFileIfExists = (cwd, filename) => {
|
|
|
109
107
|
const raw = readFileSync(fullPath, 'utf-8');
|
|
110
108
|
return parseEnvFile(raw);
|
|
111
109
|
};
|
|
110
|
+
const readPackEnvFileIfExists = (cwd) => {
|
|
111
|
+
const parsed = readEnvFileIfExists(cwd, '.env.pack');
|
|
112
|
+
if (parsed === undefined)
|
|
113
|
+
return undefined;
|
|
114
|
+
const filtered = {};
|
|
115
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
116
|
+
if (PACK_CONTROL_KEYS.has(key))
|
|
117
|
+
continue;
|
|
118
|
+
filtered[key] = value;
|
|
119
|
+
}
|
|
120
|
+
return filtered;
|
|
121
|
+
};
|
|
112
122
|
const resolveAppMode = (cwd) => {
|
|
113
123
|
const existing = safeEnvGet('NODE_ENV', '');
|
|
114
124
|
if (existing.trim() !== '')
|
|
@@ -143,11 +153,13 @@ let cached;
|
|
|
143
153
|
const loadFromCwd = (cwd, overrideExisting) => {
|
|
144
154
|
const mode = resolveAppMode(cwd);
|
|
145
155
|
const files = filesLoader(cwd, mode);
|
|
156
|
+
const loadedFiles = [];
|
|
146
157
|
let baseApplied = false;
|
|
147
158
|
for (const file of files) {
|
|
148
159
|
const parsed = readEnvFileIfExists(cwd, file);
|
|
149
160
|
if (!parsed)
|
|
150
161
|
continue;
|
|
162
|
+
loadedFiles.push(file);
|
|
151
163
|
if (file === '.env') {
|
|
152
164
|
applyToProcessEnv(parsed, overrideExisting);
|
|
153
165
|
baseApplied = true;
|
|
@@ -156,11 +168,16 @@ const loadFromCwd = (cwd, overrideExisting) => {
|
|
|
156
168
|
// .env is primary: overlays only fill missing values and never override base.
|
|
157
169
|
applyToProcessEnv(parsed, baseApplied ? false : overrideExisting);
|
|
158
170
|
}
|
|
171
|
+
const packedEnv = readPackEnvFileIfExists(cwd);
|
|
172
|
+
if (packedEnv !== undefined) {
|
|
173
|
+
applyToProcessEnv(packedEnv, false);
|
|
174
|
+
loadedFiles.push('.env.pack');
|
|
175
|
+
}
|
|
159
176
|
// Set NODE_ENV to the normalized mode if we have one (after applying files)
|
|
160
177
|
if (mode !== undefined) {
|
|
161
178
|
safeEnvSet('NODE_ENV', mode);
|
|
162
179
|
}
|
|
163
|
-
return { loadedFiles
|
|
180
|
+
return { loadedFiles, mode };
|
|
164
181
|
};
|
|
165
182
|
const loadFromFile = (filePath, overrideExisting) => {
|
|
166
183
|
if (!existsSync(filePath))
|
package/src/cli.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { BaseCommand } from './cli/BaseCommand';
|
|
|
2
2
|
export type { CommandOptions } from './cli/BaseCommand';
|
|
3
3
|
export { CLI } from './cli/CLI';
|
|
4
4
|
export { ErrorHandler, EXIT_CODES } from './cli/ErrorHandler';
|
|
5
|
+
export { DebuggerCommands } from './cli/commands/DebuggerCommands';
|
|
5
6
|
export { WorkerCommands } from './cli/commands/WorkerCommands';
|
|
6
7
|
export { OptionalCliCommandRegistry } from './cli/OptionalCliCommandRegistry';
|
|
7
8
|
export type { CliCommandProvider } from './cli/OptionalCliCommandRegistry';
|
package/src/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC"}
|
package/src/cli.js
CHANGED
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
export { BaseCommand } from './cli/BaseCommand.js';
|
|
3
3
|
export { CLI } from './cli/CLI.js';
|
|
4
4
|
export { ErrorHandler, EXIT_CODES } from './cli/ErrorHandler.js';
|
|
5
|
+
export { DebuggerCommands } from './cli/commands/DebuggerCommands.js';
|
|
5
6
|
export { WorkerCommands } from './cli/commands/WorkerCommands.js';
|
|
6
7
|
export { OptionalCliCommandRegistry } from './cli/OptionalCliCommandRegistry.js';
|
package/src/config/env.d.ts
CHANGED
|
@@ -7,8 +7,19 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { ProcessLike } from './type';
|
|
9
9
|
export type EnvSource = Record<string, unknown> | (() => Record<string, unknown>);
|
|
10
|
+
export type ResolvedEnvState = {
|
|
11
|
+
values: Record<string, string>;
|
|
12
|
+
sources: Record<string, string>;
|
|
13
|
+
packedEnabled: boolean;
|
|
14
|
+
packedKeys: string[];
|
|
15
|
+
};
|
|
10
16
|
export declare const getProcessLike: () => ProcessLike | undefined;
|
|
11
17
|
export declare const dirnameFromExecPath: (execPath: string, platform?: string) => string;
|
|
18
|
+
export declare const getOptional: (key: string) => string | undefined;
|
|
19
|
+
export declare const has: (key: string) => boolean;
|
|
20
|
+
export declare const getSourceOf: (key: string) => string | undefined;
|
|
21
|
+
export declare const snapshotSources: () => Record<string, string>;
|
|
22
|
+
export declare const getResolvedState: () => ResolvedEnvState;
|
|
12
23
|
export declare const get: (key: string, defaultValue?: string) => string;
|
|
13
24
|
export declare const getInt: (key: string, defaultValue: number) => number;
|
|
14
25
|
export declare const getFloat: (key: string, defaultValue?: number) => number;
|
|
@@ -21,13 +32,18 @@ export declare const getDefaultLogLevel: () => "debug" | "info" | "warn" | "erro
|
|
|
21
32
|
export declare const ZT_PROXY_TIMEOUT_MS: number;
|
|
22
33
|
export declare const Env: Readonly<{
|
|
23
34
|
get: (key: string, defaultValue?: string) => string;
|
|
35
|
+
getOptional: (key: string) => string | undefined;
|
|
24
36
|
getInt: (key: string, defaultValue: number) => number;
|
|
25
37
|
getBool: (key: string, defaultValue?: boolean) => boolean;
|
|
26
38
|
getFloat: (key: string, defaultValue?: number) => number;
|
|
39
|
+
has: (key: string) => boolean;
|
|
27
40
|
set: (key: string, value: string) => void;
|
|
28
41
|
unset: (key: string) => void;
|
|
29
42
|
setSource: (source: EnvSource | null) => void;
|
|
30
43
|
snapshot: () => Record<string, string>;
|
|
44
|
+
getSourceOf: (key: string) => string | undefined;
|
|
45
|
+
snapshotSources: () => Record<string, string>;
|
|
46
|
+
getResolvedState: () => ResolvedEnvState;
|
|
31
47
|
NODE_ENV: NodeJS.ProcessEnv["NODE_ENV"];
|
|
32
48
|
PORT: number;
|
|
33
49
|
HOST: string;
|
package/src/config/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/config/env.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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
|
|
6
6
|
* Safe for both Node.js and serverless runtimes (Cloudflare Workers, Deno, Lambda)
|
|
7
7
|
*/
|
|
8
|
+
import { isArray, isNonEmptyString, isObject } from '../helper/index.js';
|
|
8
9
|
// Cache process check once at module load time
|
|
9
10
|
const processLike = typeof process === 'undefined' ? undefined : process;
|
|
10
11
|
let externalEnvSource = null;
|
|
12
|
+
const DIRECT_ENV_SOURCE = 'direct-env';
|
|
13
|
+
const PACKED_ENV_ENABLE_KEY = 'USE_PACK';
|
|
14
|
+
const PACKED_ENV_KEYS_KEY = 'PACK_KEYS';
|
|
15
|
+
const PACKED_ENV_CONTROL_KEYS = new Set([PACKED_ENV_ENABLE_KEY, PACKED_ENV_KEYS_KEY]);
|
|
16
|
+
const createPackedEnvError = (message, details) => {
|
|
17
|
+
const error = Object.create(globalThis.Error.prototype);
|
|
18
|
+
error.name = 'ConfigError';
|
|
19
|
+
error.message = message;
|
|
20
|
+
error.code = 'CONFIG_ERROR';
|
|
21
|
+
error.statusCode = 500;
|
|
22
|
+
if (details !== undefined) {
|
|
23
|
+
error.details = details;
|
|
24
|
+
}
|
|
25
|
+
return error;
|
|
26
|
+
};
|
|
11
27
|
const getGlobalEnv = () => {
|
|
12
28
|
const env = globalThis.env;
|
|
13
29
|
if (env === undefined || env === null || typeof env !== 'object')
|
|
14
30
|
return undefined;
|
|
15
31
|
return env;
|
|
16
32
|
};
|
|
17
|
-
const
|
|
33
|
+
const getRawEnvSource = () => {
|
|
18
34
|
if (typeof externalEnvSource === 'function')
|
|
19
35
|
return externalEnvSource();
|
|
20
36
|
if (externalEnvSource !== null)
|
|
@@ -28,6 +44,14 @@ const getEnvSource = () => {
|
|
|
28
44
|
}
|
|
29
45
|
return processLike?.env ?? {};
|
|
30
46
|
};
|
|
47
|
+
const normalizePackedScalar = (packName, key, value) => {
|
|
48
|
+
if (typeof value === 'string')
|
|
49
|
+
return value;
|
|
50
|
+
if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
|
|
51
|
+
return String(value);
|
|
52
|
+
}
|
|
53
|
+
throw createPackedEnvError(`${packName} contains unsupported value for ${key}. Expected a flat string-compatible value.`);
|
|
54
|
+
};
|
|
31
55
|
const normalizeEnvValue = (value) => {
|
|
32
56
|
if (value === null || value === undefined)
|
|
33
57
|
return '';
|
|
@@ -38,6 +62,86 @@ const normalizeEnvValue = (value) => {
|
|
|
38
62
|
}
|
|
39
63
|
return '';
|
|
40
64
|
};
|
|
65
|
+
const isDirectEnvScalar = (value) => {
|
|
66
|
+
return (value === null ||
|
|
67
|
+
value === undefined ||
|
|
68
|
+
typeof value === 'string' ||
|
|
69
|
+
typeof value === 'number' ||
|
|
70
|
+
typeof value === 'boolean' ||
|
|
71
|
+
typeof value === 'bigint');
|
|
72
|
+
};
|
|
73
|
+
const parsePackedEnvKeys = (env) => {
|
|
74
|
+
const enabled = normalizeEnvValue(env[PACKED_ENV_ENABLE_KEY]).trim().toLowerCase() === 'true';
|
|
75
|
+
if (!enabled) {
|
|
76
|
+
return { enabled: false, packKeys: [] };
|
|
77
|
+
}
|
|
78
|
+
const raw = normalizeEnvValue(env[PACKED_ENV_KEYS_KEY]);
|
|
79
|
+
const packKeys = raw
|
|
80
|
+
.split(',')
|
|
81
|
+
.map((item) => item.trim())
|
|
82
|
+
.filter((item, index, items) => item !== '' && items.indexOf(item) === index);
|
|
83
|
+
if (packKeys.length === 0) {
|
|
84
|
+
throw createPackedEnvError('USE_PACK is true but PACK_KEYS is empty');
|
|
85
|
+
}
|
|
86
|
+
return { enabled: true, packKeys };
|
|
87
|
+
};
|
|
88
|
+
const parsePackedPayload = (packName, payload) => {
|
|
89
|
+
if (!isNonEmptyString(normalizeEnvValue(payload))) {
|
|
90
|
+
throw createPackedEnvError(`PACK_KEYS contains ${packName} but env.${packName} is missing`);
|
|
91
|
+
}
|
|
92
|
+
let parsed;
|
|
93
|
+
try {
|
|
94
|
+
parsed = JSON.parse(normalizeEnvValue(payload));
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw createPackedEnvError(`${packName} did not parse as a JSON object`, error);
|
|
98
|
+
}
|
|
99
|
+
if (!isObject(parsed) || isArray(parsed)) {
|
|
100
|
+
throw createPackedEnvError(`${packName} did not parse as a JSON object`);
|
|
101
|
+
}
|
|
102
|
+
return parsed;
|
|
103
|
+
};
|
|
104
|
+
const applyPackedPayload = (values, sources, packName, payload) => {
|
|
105
|
+
for (const [rawKey, rawValue] of Object.entries(payload)) {
|
|
106
|
+
const key = rawKey.trim();
|
|
107
|
+
if (!isNonEmptyString(key))
|
|
108
|
+
continue;
|
|
109
|
+
if (PACKED_ENV_CONTROL_KEYS.has(key))
|
|
110
|
+
continue;
|
|
111
|
+
if (isObject(rawValue) || isArray(rawValue) || rawValue === null || rawValue === undefined) {
|
|
112
|
+
throw createPackedEnvError(`${packName} contains unsupported value for ${key}. Nested or null values are not supported.`);
|
|
113
|
+
}
|
|
114
|
+
values[key] = normalizePackedScalar(packName, key, rawValue);
|
|
115
|
+
sources[key] = packName;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const overlayDirectEnvValues = (values, sources, env) => {
|
|
119
|
+
for (const [key, rawValue] of Object.entries(env)) {
|
|
120
|
+
if (!isDirectEnvScalar(rawValue))
|
|
121
|
+
continue;
|
|
122
|
+
values[key] = normalizeEnvValue(rawValue);
|
|
123
|
+
sources[key] = DIRECT_ENV_SOURCE;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const resolvePackedEnvState = (env) => {
|
|
127
|
+
const values = {};
|
|
128
|
+
const sources = {};
|
|
129
|
+
const { enabled, packKeys } = parsePackedEnvKeys(env);
|
|
130
|
+
if (enabled) {
|
|
131
|
+
for (const packName of packKeys) {
|
|
132
|
+
applyPackedPayload(values, sources, packName, parsePackedPayload(packName, env[packName]));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
overlayDirectEnvValues(values, sources, env);
|
|
136
|
+
return {
|
|
137
|
+
values,
|
|
138
|
+
sources,
|
|
139
|
+
packedEnabled: enabled,
|
|
140
|
+
packedKeys: packKeys,
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const getResolvedEnvState = () => resolvePackedEnvState(getRawEnvSource());
|
|
144
|
+
const getEnvSource = () => getResolvedEnvState().values;
|
|
41
145
|
export const getProcessLike = () => processLike;
|
|
42
146
|
export const dirnameFromExecPath = (execPath, platform) => {
|
|
43
147
|
const separator = platform === 'win32' ? '\\' : '/';
|
|
@@ -46,11 +150,26 @@ export const dirnameFromExecPath = (execPath, platform) => {
|
|
|
46
150
|
return '';
|
|
47
151
|
return execPath.slice(0, lastSep);
|
|
48
152
|
};
|
|
153
|
+
export const getOptional = (key) => {
|
|
154
|
+
const env = getEnvSource();
|
|
155
|
+
return Object.prototype.hasOwnProperty.call(env, key) ? normalizeEnvValue(env[key]) : undefined;
|
|
156
|
+
};
|
|
157
|
+
export const has = (key) => {
|
|
158
|
+
const env = getEnvSource();
|
|
159
|
+
return Object.prototype.hasOwnProperty.call(env, key);
|
|
160
|
+
};
|
|
161
|
+
export const getSourceOf = (key) => {
|
|
162
|
+
return getResolvedEnvState().sources[key];
|
|
163
|
+
};
|
|
164
|
+
export const snapshotSources = () => {
|
|
165
|
+
return { ...getResolvedEnvState().sources };
|
|
166
|
+
};
|
|
167
|
+
export const getResolvedState = () => getResolvedEnvState();
|
|
49
168
|
// Private helper functions
|
|
50
169
|
export const get = (key, defaultValue) => {
|
|
51
170
|
const env = getEnvSource();
|
|
52
171
|
const value = normalizeEnvValue(env[key]);
|
|
53
|
-
return value === '' ? defaultValue ?? '' : value;
|
|
172
|
+
return value === '' ? (defaultValue ?? '') : value;
|
|
54
173
|
};
|
|
55
174
|
export const getInt = (key, defaultValue) => {
|
|
56
175
|
const value = get(key, String(defaultValue ?? 0));
|
|
@@ -107,13 +226,18 @@ const PROXY_SECRET_FALLBACK = get('APP_KEY', '');
|
|
|
107
226
|
export const Env = Object.freeze({
|
|
108
227
|
// Helper functions
|
|
109
228
|
get,
|
|
229
|
+
getOptional,
|
|
110
230
|
getInt,
|
|
111
231
|
getBool,
|
|
112
232
|
getFloat,
|
|
233
|
+
has,
|
|
113
234
|
set,
|
|
114
235
|
unset,
|
|
115
236
|
setSource,
|
|
116
237
|
snapshot,
|
|
238
|
+
getSourceOf,
|
|
239
|
+
snapshotSources,
|
|
240
|
+
getResolvedState,
|
|
117
241
|
// Core
|
|
118
242
|
NODE_ENV: get('NODE_ENV', 'development'),
|
|
119
243
|
// Prefer PORT, fallback to APP_PORT for compatibility
|
package/src/config/logger.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LogLevel } from './type';
|
|
1
2
|
interface ILogger {
|
|
2
3
|
debug(message: string, data?: unknown, category?: string): void;
|
|
3
4
|
info(message: string, data?: unknown, category?: string): void;
|
|
@@ -5,6 +6,11 @@ interface ILogger {
|
|
|
5
6
|
error(message: string, error?: unknown, category?: string): void;
|
|
6
7
|
fatal(message: string, error?: unknown, category?: string): void;
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* External log sink. Receives every log line after the built-in sinks have fired.
|
|
11
|
+
* Return value is ignored; errors are swallowed to protect the caller.
|
|
12
|
+
*/
|
|
13
|
+
export type LogSink = (level: LogLevel, message: string, context?: Record<string, unknown>) => void;
|
|
8
14
|
export declare const cleanLogsOnce: () => Promise<string[]>;
|
|
9
15
|
export declare const Logger: Readonly<{
|
|
10
16
|
debug: (message: string, data?: unknown, category?: string) => void;
|
|
@@ -14,6 +20,7 @@ export declare const Logger: Readonly<{
|
|
|
14
20
|
fatal: (message: string, error?: unknown, category?: string) => void;
|
|
15
21
|
cleanLogsOnce: () => Promise<string[]>;
|
|
16
22
|
scope: (scope: string) => ILogger;
|
|
23
|
+
addSink: (fn: LogSink) => (() => void);
|
|
17
24
|
}>;
|
|
18
25
|
export default Logger;
|
|
19
26
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/config/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/config/logger.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE7C,UAAU,OAAO;IACf,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClE;AAubD;;;GAGG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;AAkCpG,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,MAAM,EAAE,CAYtD,CAAC;AAEF,eAAO,MAAM,MAAM;qBA3MQ,MAAM,SAAS,OAAO,aAAa,MAAM,KAAG,IAAI;oBAuBjD,MAAM,SAAS,OAAO,aAAa,MAAM,KAAG,IAAI;oBAuBhD,MAAM,SAAS,OAAO,aAAa,MAAM,KAAG,IAAI;qBAuB/C,MAAM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