@zintrust/core 0.4.40 → 0.4.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/core",
3
- "version": "0.4.40",
3
+ "version": "0.4.41",
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.40",
61
+ "@zintrust/workers": "^0.4.41",
62
62
  "bcryptjs": "^3.0.3",
63
63
  "bullmq": "^5.71.1",
64
64
  "chalk": "^5.6.2",
@@ -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;IACp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AChB,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,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAiJF,eAAO,MAAM,0BAA0B,GACrC,KAAK,mBAAmB,EACxB,QAAQ,IAAI,CAAC,0BAA0B,EAAE,QAAQ,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);
@@ -1 +1 @@
1
- {"version":3,"file":"DeployCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/DeployCommand.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAuLrE;;;GAGG;AACH,eAAO,MAAM,aAAa;IACxB;;OAEG;cACO,YAAY;EAGtB,CAAC"}
1
+ {"version":3,"file":"DeployCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/DeployCommand.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA0LrE;;;GAGG;AACH,eAAO,MAAM,aAAa;IACxB;;OAEG;cACO,YAAY;EAGtB,CAAC"}
@@ -52,7 +52,9 @@ const syncWranglerSecrets = async (cmd, cwd, wranglerEnv, options) => {
52
52
  log: cmd,
53
53
  cwd,
54
54
  wranglerEnvs: [wranglerEnv],
55
- envPath: typeof options.envPath === 'string' && options.envPath.trim() !== '' ? options.envPath : '.env',
55
+ envPath: typeof options.envPath === 'string' && options.envPath.trim() !== ''
56
+ ? options.envPath
57
+ : '.env',
56
58
  configPath: typeof options.config === 'string' ? options.config.trim() : undefined,
57
59
  target: typeof options.target === 'string' ? options.target : undefined,
58
60
  requireSelection: false,
@@ -1 +1 @@
1
- {"version":3,"file":"DeployContainersProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/DeployContainersProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA6ErE,eAAO,MAAM,4BAA4B;cAC7B,YAAY;EAkBtB,CAAC"}
1
+ {"version":3,"file":"DeployContainersProxyCommand.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/DeployContainersProxyCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA6ErE,eAAO,MAAM,4BAA4B;cAC7B,YAAY;EAyBtB,CAAC"}
@@ -25,7 +25,9 @@ const syncDeploySecrets = async (cmd, cwd, config, env, options) => {
25
25
  log: cmd,
26
26
  cwd,
27
27
  wranglerEnvs: [env],
28
- envPath: typeof options.envPath === 'string' && options.envPath.trim() !== '' ? options.envPath : '.env',
28
+ envPath: typeof options.envPath === 'string' && options.envPath.trim() !== ''
29
+ ? options.envPath
30
+ : '.env',
29
31
  configPath: config,
30
32
  target: typeof options.target === 'string' ? options.target : undefined,
31
33
  requireSelection: false,
@@ -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;AAmIzD,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;AAgMF,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"}
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: files, mode };
180
+ return { loadedFiles, mode };
164
181
  };
165
182
  const loadFromFile = (filePath, overrideExisting) => {
166
183
  if (!existsSync(filePath))
@@ -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;
@@ -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;AAEhD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA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DjB,MAAM,KAAG,MAAM,GAAG,SAAS;2BAIzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;4BAIrB,gBAAgB;cA+EN,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAgOpB,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoFxF,CAAC;AAEH,eAAO,MAAM,aAAa,QAAO,MAchC,CAAC"}
package/src/config/env.js CHANGED
@@ -5,16 +5,32 @@
5
5
  * Sealed namespace pattern - all exports through Env namespace
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 getEnvSource = () => {
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/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @zintrust/core v0.4.40
2
+ * @zintrust/core v0.4.41
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-03-31T13:31:43.681Z
8
+ * Built: 2026-03-31T14:32:01.889Z
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-03-31T13:31:43.643Z'; // Replaced during build
24
+ export const ZINTRUST_BUILD_DATE = '2026-03-31T14:32:01.844Z'; // 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":"RuntimeServices.d.ts","sourceRoot":"","sources":["../../../src/runtime/RuntimeServices.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;AAEtF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACpD,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACvD,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACzD,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB,UAAU,GACV,iBAAiB,GACjB,WAAW,GACX,WAAW,GACX,SAAS,GACT,UAAU,GACV,UAAU,GACV,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,YAAY,CAAC;IACrB,eAAe,EAAE,CAAC,CAAC,SAAS,iBAAiB,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9D,UAAU,EAAE,MAAM,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,CA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AAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,eAAe,CAAC;IAC1B,GAAG,EAAE,gBAAgB,CAAC;IACtB,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,aAAa,CAAC;IACtB,EAAE,EAAE,SAAS,CAAC;IACd,KAAK,EAAE,OAAO,KAAK,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,uBAAuB,QAAO,OAE1C,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,eAGxC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,eAAyC,CAAC;AA2GzE,eAAO,MAAM,eAAe;qBACT,eAAe,GAAG,eAAe;EAqBlD,CAAC;AAEH,eAAe,eAAe,CAAC"}
@@ -17,42 +17,12 @@ export const detectRuntimePlatform = () => {
17
17
  return 'nodejs';
18
18
  };
19
19
  export const RUNTIME_PLATFORM = detectRuntimePlatform();
20
- const normalizeEnvValue = (value) => {
21
- if (value === null || value === undefined)
22
- return '';
23
- if (typeof value === 'string')
24
- return value;
25
- if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') {
26
- return String(value);
27
- }
28
- return '';
29
- };
30
- const readEnvFromRecord = (record, key) => {
31
- return normalizeEnvValue(record[key]);
32
- };
33
20
  const createWorkersEnvReader = () => {
34
21
  return {
35
- get(key, defaultValue = '') {
36
- const env = Cloudflare.getWorkersEnv() ?? {};
37
- const value = readEnvFromRecord(env, key);
38
- return value === '' ? defaultValue : value;
39
- },
40
- getInt(key, defaultValue = 0) {
41
- const raw = this.get(key, String(defaultValue));
42
- const parsed = Number.parseInt(raw, 10);
43
- return Number.isFinite(parsed) ? parsed : defaultValue;
44
- },
45
- getFloat(key, defaultValue = 0) {
46
- const raw = this.get(key, String(defaultValue));
47
- const parsed = Number.parseFloat(raw);
48
- return Number.isFinite(parsed) ? parsed : defaultValue;
49
- },
50
- getBool(key, defaultValue = false) {
51
- const raw = this.get(key, defaultValue ? 'true' : 'false').toLowerCase();
52
- if (raw === '')
53
- return defaultValue;
54
- return raw === 'true' || raw === '1';
55
- },
22
+ get: (key, defaultValue) => Env.get(key, defaultValue),
23
+ getInt: (key, defaultValue) => Env.getInt(key, defaultValue ?? 0),
24
+ getFloat: (key, defaultValue) => Env.getFloat(key, defaultValue ?? 0),
25
+ getBool: (key, defaultValue) => Env.getBool(key, defaultValue),
56
26
  };
57
27
  };
58
28
  const createNodeEnvReader = () => {