@hkdigital/lib-core 0.4.18 → 0.4.20
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/dist/services/README.md +254 -47
- package/dist/services/manager-plugins/ConfigPlugin.d.ts +68 -0
- package/dist/services/manager-plugins/ConfigPlugin.js +329 -0
- package/dist/services/service-base/ServiceBase.d.ts +59 -22
- package/dist/services/service-base/ServiceBase.js +139 -61
- package/dist/services/service-base/constants.d.ts +30 -14
- package/dist/services/service-base/constants.js +42 -14
- package/dist/services/service-base/typedef.d.ts +15 -9
- package/dist/services/service-base/typedef.js +33 -11
- package/dist/services/service-manager/ServiceManager.d.ts +25 -5
- package/dist/services/service-manager/ServiceManager.js +103 -20
- package/dist/services/service-manager/constants.js +0 -1
- package/dist/services/service-manager/typedef.d.ts +36 -14
- package/dist/services/service-manager/typedef.js +30 -13
- package/dist/util/sveltekit/env/README.md +424 -0
- package/dist/util/sveltekit/env/all.d.ts +54 -0
- package/dist/util/sveltekit/env/all.js +97 -0
- package/dist/util/sveltekit/env/parsers.d.ts +135 -0
- package/dist/util/sveltekit/env/parsers.js +257 -0
- package/dist/util/sveltekit/env/private.d.ts +56 -0
- package/dist/util/sveltekit/env/private.js +87 -0
- package/dist/util/sveltekit/env/public.d.ts +52 -0
- package/dist/util/sveltekit/env/public.js +82 -0
- package/dist/util/sveltekit/env-all.d.ts +1 -0
- package/dist/util/sveltekit/env-all.js +19 -0
- package/dist/util/sveltekit/env-private.d.ts +1 -0
- package/dist/util/sveltekit/env-private.js +18 -0
- package/dist/util/sveltekit/env-public.d.ts +1 -0
- package/dist/util/sveltekit/env-public.js +18 -0
- package/package.json +1 -1
- package/dist/util/index.js__ +0 -20
- package/dist/util/sveltekit/index.d.ts +0 -0
- package/dist/util/sveltekit/index.js +0 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Environment variable parsing utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides functions for parsing and transforming environment variables
|
|
5
|
+
* with type conversion, key transformation, and prefix handling.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { parseEnv, parseEnvByPrefix } from './parsers.js';
|
|
9
|
+
*
|
|
10
|
+
* const parsed = parseEnv(envObject, {
|
|
11
|
+
* camelCase: true,
|
|
12
|
+
* parseValues: true
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* const dbConfig = parseEnvByPrefix(envObject, 'DATABASE');
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse environment object with type conversion and key transformation
|
|
20
|
+
*
|
|
21
|
+
* @param {Object<string, string>} env - Raw environment variables
|
|
22
|
+
* @param {Object} [options={}] - Parsing options
|
|
23
|
+
* @param {boolean} [options.camelCase=true]
|
|
24
|
+
* Convert env var names to camelCase object keys
|
|
25
|
+
* @param {boolean} [options.parseValues=true]
|
|
26
|
+
* Parse string values to numbers/booleans when possible
|
|
27
|
+
* @param {string} [options.prefix] - Only include vars with this prefix
|
|
28
|
+
* @param {boolean} [options.removePrefix=true]
|
|
29
|
+
* Remove prefix from resulting keys
|
|
30
|
+
*
|
|
31
|
+
* @returns {Object} Parsed environment object
|
|
32
|
+
*/
|
|
33
|
+
export function parseEnv(env, options = {}) {
|
|
34
|
+
const {
|
|
35
|
+
camelCase = true,
|
|
36
|
+
parseValues = true,
|
|
37
|
+
prefix,
|
|
38
|
+
removePrefix = true
|
|
39
|
+
} = options;
|
|
40
|
+
|
|
41
|
+
const result = {};
|
|
42
|
+
|
|
43
|
+
for (const [key, value] of Object.entries(env || {})) {
|
|
44
|
+
// Skip if prefix specified and key doesn't match
|
|
45
|
+
if (prefix && !key.startsWith(prefix)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Determine final key name
|
|
50
|
+
let finalKey = key;
|
|
51
|
+
|
|
52
|
+
if (prefix && removePrefix) {
|
|
53
|
+
finalKey = key.slice(prefix.length);
|
|
54
|
+
// Remove leading underscore if present
|
|
55
|
+
if (finalKey.startsWith('_')) {
|
|
56
|
+
finalKey = finalKey.slice(1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (camelCase) {
|
|
61
|
+
finalKey = toCamelCase(finalKey);
|
|
62
|
+
} else {
|
|
63
|
+
finalKey = finalKey.toLowerCase();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Parse value if requested
|
|
67
|
+
result[finalKey] = parseValues ? parseValue(value) : value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Parse environment variables by prefix
|
|
75
|
+
*
|
|
76
|
+
* @param {Object<string, string>} env - Raw environment variables
|
|
77
|
+
* @param {string} prefix - Environment variable prefix (e.g., 'DATABASE')
|
|
78
|
+
* @param {Object} [options={}] - Parsing options
|
|
79
|
+
*
|
|
80
|
+
* @returns {Object} Parsed configuration object
|
|
81
|
+
*/
|
|
82
|
+
export function parseEnvByPrefix(env, prefix, options = {}) {
|
|
83
|
+
const prefixWithUnderscore = prefix.endsWith('_') ? prefix : `${prefix}_`;
|
|
84
|
+
|
|
85
|
+
return parseEnv(env, {
|
|
86
|
+
...options,
|
|
87
|
+
prefix: prefixWithUnderscore,
|
|
88
|
+
removePrefix: true
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Convert SCREAMING_SNAKE_CASE to camelCase
|
|
94
|
+
*
|
|
95
|
+
* @param {string} str - String to convert
|
|
96
|
+
*
|
|
97
|
+
* @returns {string} camelCase string
|
|
98
|
+
*/
|
|
99
|
+
export function toCamelCase(str) {
|
|
100
|
+
return str
|
|
101
|
+
.toLowerCase()
|
|
102
|
+
.split('_')
|
|
103
|
+
.map((word, index) =>
|
|
104
|
+
index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)
|
|
105
|
+
)
|
|
106
|
+
.join('');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Parse string value to appropriate type
|
|
111
|
+
*
|
|
112
|
+
* @param {string} value - String value to parse
|
|
113
|
+
*
|
|
114
|
+
* @returns {*} Parsed value (string, number, boolean, or null)
|
|
115
|
+
*/
|
|
116
|
+
export function parseValue(value) {
|
|
117
|
+
if (value === 'true') return true;
|
|
118
|
+
if (value === 'false') return false;
|
|
119
|
+
if (value === 'null') return null;
|
|
120
|
+
if (value === 'undefined') return undefined;
|
|
121
|
+
|
|
122
|
+
// Try parsing as number
|
|
123
|
+
const num = Number(value);
|
|
124
|
+
if (!Number.isNaN(num) && value.trim() !== '') {
|
|
125
|
+
return num;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Auto-detect and group environment variables by prefixes
|
|
133
|
+
*
|
|
134
|
+
* Automatically detects prefixes from environment variable names and groups
|
|
135
|
+
* them into configuration objects. All variables with underscores are
|
|
136
|
+
* grouped by their prefix (the part before the first underscore).
|
|
137
|
+
*
|
|
138
|
+
* @param {Object<string, string>} env - Raw environment variables
|
|
139
|
+
* @param {Object} [options={}] - Parsing options
|
|
140
|
+
* @param {boolean} [options.camelCase=true]
|
|
141
|
+
* Convert env var names to camelCase object keys
|
|
142
|
+
* @param {boolean} [options.parseValues=true]
|
|
143
|
+
* Parse string values to numbers/booleans when possible
|
|
144
|
+
*
|
|
145
|
+
* @returns {Object<string, Object>} Grouped environment variables
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* // Input env vars:
|
|
149
|
+
* // DATABASE_HOST=localhost, DATABASE_PORT=5432
|
|
150
|
+
* // REDIS_HOST=cache, API_KEY=secret, SINGLE=value
|
|
151
|
+
*
|
|
152
|
+
* const grouped = autoGroupEnvByPrefix(env);
|
|
153
|
+
* // Returns:
|
|
154
|
+
* // {
|
|
155
|
+
* // database: { host: 'localhost', port: 5432 },
|
|
156
|
+
* // redis: { host: 'cache' },
|
|
157
|
+
* // api: { key: 'secret' },
|
|
158
|
+
* // single: 'value' // No underscore, stays top-level
|
|
159
|
+
* // }
|
|
160
|
+
*/
|
|
161
|
+
export function autoGroupEnvByPrefix(env, options = {}) {
|
|
162
|
+
const {
|
|
163
|
+
camelCase = true,
|
|
164
|
+
parseValues = true
|
|
165
|
+
} = options;
|
|
166
|
+
|
|
167
|
+
// Collect all prefixes from variables with underscores
|
|
168
|
+
const allPrefixes = new Set();
|
|
169
|
+
|
|
170
|
+
for (const key of Object.keys(env)) {
|
|
171
|
+
const parts = key.split('_');
|
|
172
|
+
if (parts.length > 1) {
|
|
173
|
+
const prefix = parts[0];
|
|
174
|
+
allPrefixes.add(prefix);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const result = {};
|
|
179
|
+
const usedKeys = new Set();
|
|
180
|
+
|
|
181
|
+
// Group by all detected prefixes
|
|
182
|
+
for (const prefix of allPrefixes) {
|
|
183
|
+
const groupKey = camelCase ? toCamelCase(prefix) : prefix.toLowerCase();
|
|
184
|
+
const groupConfig = parseEnvByPrefix(env, prefix, { camelCase, parseValues });
|
|
185
|
+
|
|
186
|
+
if (Object.keys(groupConfig).length > 0) {
|
|
187
|
+
result[groupKey] = groupConfig;
|
|
188
|
+
|
|
189
|
+
// Mark keys as used
|
|
190
|
+
for (const key of Object.keys(env)) {
|
|
191
|
+
if (key.startsWith(`${prefix}_`)) {
|
|
192
|
+
usedKeys.add(key);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Add remaining variables (no underscore) as top-level properties
|
|
199
|
+
for (const [key, value] of Object.entries(env)) {
|
|
200
|
+
if (!usedKeys.has(key)) {
|
|
201
|
+
const finalKey = camelCase ? toCamelCase(key) : key.toLowerCase();
|
|
202
|
+
result[finalKey] = parseValues ? parseValue(value) : value;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Group environment variables by specific prefixes
|
|
211
|
+
*
|
|
212
|
+
* @param {Object<string, string>} env - Raw environment variables
|
|
213
|
+
* @param {string[]} prefixes - Array of prefixes to group by
|
|
214
|
+
* @param {Object} [options={}] - Parsing options
|
|
215
|
+
*
|
|
216
|
+
* @returns {Object<string, Object>} Grouped environment variables
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* const grouped = groupEnvByPrefixes(env, ['DATABASE', 'REDIS', 'JWT']);
|
|
220
|
+
* // Returns: { database: {...}, redis: {...}, jwt: {...} }
|
|
221
|
+
*/
|
|
222
|
+
export function groupEnvByPrefixes(env, prefixes, options = {}) {
|
|
223
|
+
const result = {};
|
|
224
|
+
|
|
225
|
+
for (const prefix of prefixes) {
|
|
226
|
+
const groupKey = options.camelCase !== false ?
|
|
227
|
+
toCamelCase(prefix) :
|
|
228
|
+
prefix.toLowerCase();
|
|
229
|
+
|
|
230
|
+
result[groupKey] = parseEnvByPrefix(env, prefix, options);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Filter environment variables by pattern
|
|
238
|
+
*
|
|
239
|
+
* @param {Object<string, string>} env - Raw environment variables
|
|
240
|
+
* @param {RegExp|string} pattern - Pattern to match against keys
|
|
241
|
+
* @param {Object} [options={}] - Parsing options
|
|
242
|
+
*
|
|
243
|
+
* @returns {Object} Filtered and parsed environment variables
|
|
244
|
+
*/
|
|
245
|
+
export function filterEnvByPattern(env, pattern, options = {}) {
|
|
246
|
+
const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
|
|
247
|
+
/** @type {Object<string, string>} */
|
|
248
|
+
const filtered = {};
|
|
249
|
+
|
|
250
|
+
for (const [key, value] of Object.entries(env || {})) {
|
|
251
|
+
if (regex.test(key)) {
|
|
252
|
+
filtered[key] = value;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return parseEnv(filtered, options);
|
|
257
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get all private environment variables with automatic prefix grouping
|
|
3
|
+
*
|
|
4
|
+
* Automatically detects common prefixes in private environment variables
|
|
5
|
+
* and groups them into configuration objects. This is perfect for organizing
|
|
6
|
+
* database connections, API keys, and other sensitive configuration.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} [options={}] - Parsing options
|
|
9
|
+
* @param {boolean} [options.camelCase=true]
|
|
10
|
+
* Convert env var names to camelCase object keys
|
|
11
|
+
* @param {boolean} [options.parseValues=true]
|
|
12
|
+
* Parse string values to numbers/booleans when possible
|
|
13
|
+
* @param {boolean} [options.autoGroup=true]
|
|
14
|
+
* Enable automatic prefix grouping
|
|
15
|
+
*
|
|
16
|
+
* @returns {Object} Grouped and parsed private environment variables
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Environment variables:
|
|
20
|
+
* // DATABASE_HOST=localhost
|
|
21
|
+
* // DATABASE_PORT=5432
|
|
22
|
+
* // DATABASE_NAME=myapp
|
|
23
|
+
* // REDIS_URL=redis://localhost:6379
|
|
24
|
+
* // JWT_SECRET=mysecret
|
|
25
|
+
* // JWT_EXPIRES_IN=24h
|
|
26
|
+
*
|
|
27
|
+
* const config = getPrivateEnv();
|
|
28
|
+
* // Returns:
|
|
29
|
+
* // {
|
|
30
|
+
* // database: { host: 'localhost', port: 5432, name: 'myapp' },
|
|
31
|
+
* // jwt: { secret: 'mysecret', expiresIn: '24h' },
|
|
32
|
+
* // redisUrl: 'redis://localhost:6379' // Single vars become top-level
|
|
33
|
+
* // }
|
|
34
|
+
*/
|
|
35
|
+
export function getPrivateEnv(options?: {
|
|
36
|
+
camelCase?: boolean;
|
|
37
|
+
parseValues?: boolean;
|
|
38
|
+
autoGroup?: boolean;
|
|
39
|
+
}): any;
|
|
40
|
+
/**
|
|
41
|
+
* Get private environment variables by prefix
|
|
42
|
+
*
|
|
43
|
+
* @param {string} prefix - Environment variable prefix (e.g., 'DATABASE')
|
|
44
|
+
* @param {Object} [options={}] - Parsing options
|
|
45
|
+
*
|
|
46
|
+
* @returns {Object} Parsed configuration object
|
|
47
|
+
*/
|
|
48
|
+
export function getPrivateEnvByPrefix(prefix: string, options?: any): any;
|
|
49
|
+
/**
|
|
50
|
+
* Get raw private environment variables (no parsing)
|
|
51
|
+
*
|
|
52
|
+
* @returns {Object<string, string>} Raw private environment variables
|
|
53
|
+
*/
|
|
54
|
+
export function getRawPrivateEnv(): {
|
|
55
|
+
[x: string]: string;
|
|
56
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Private environment variables access (server-side only)
|
|
3
|
+
*
|
|
4
|
+
* Provides access to SvelteKit private environment variables with parsing.
|
|
5
|
+
* IMPORTANT: This module can only be imported on the server side.
|
|
6
|
+
* Attempting to import this on the client will cause a build error.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { getPrivateEnv } from './private.js';
|
|
10
|
+
*
|
|
11
|
+
* const privateVars = getPrivateEnv();
|
|
12
|
+
* const dbConfig = getPrivateEnv({ prefix: 'DATABASE' });
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { env } from '$env/dynamic/private';
|
|
16
|
+
import { autoGroupEnvByPrefix, parseEnv } from './parsers.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get all private environment variables with automatic prefix grouping
|
|
20
|
+
*
|
|
21
|
+
* Automatically detects common prefixes in private environment variables
|
|
22
|
+
* and groups them into configuration objects. This is perfect for organizing
|
|
23
|
+
* database connections, API keys, and other sensitive configuration.
|
|
24
|
+
*
|
|
25
|
+
* @param {Object} [options={}] - Parsing options
|
|
26
|
+
* @param {boolean} [options.camelCase=true]
|
|
27
|
+
* Convert env var names to camelCase object keys
|
|
28
|
+
* @param {boolean} [options.parseValues=true]
|
|
29
|
+
* Parse string values to numbers/booleans when possible
|
|
30
|
+
* @param {boolean} [options.autoGroup=true]
|
|
31
|
+
* Enable automatic prefix grouping
|
|
32
|
+
*
|
|
33
|
+
* @returns {Object} Grouped and parsed private environment variables
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* // Environment variables:
|
|
37
|
+
* // DATABASE_HOST=localhost
|
|
38
|
+
* // DATABASE_PORT=5432
|
|
39
|
+
* // DATABASE_NAME=myapp
|
|
40
|
+
* // REDIS_URL=redis://localhost:6379
|
|
41
|
+
* // JWT_SECRET=mysecret
|
|
42
|
+
* // JWT_EXPIRES_IN=24h
|
|
43
|
+
*
|
|
44
|
+
* const config = getPrivateEnv();
|
|
45
|
+
* // Returns:
|
|
46
|
+
* // {
|
|
47
|
+
* // database: { host: 'localhost', port: 5432, name: 'myapp' },
|
|
48
|
+
* // jwt: { secret: 'mysecret', expiresIn: '24h' },
|
|
49
|
+
* // redisUrl: 'redis://localhost:6379' // Single vars become top-level
|
|
50
|
+
* // }
|
|
51
|
+
*/
|
|
52
|
+
export function getPrivateEnv(options = {}) {
|
|
53
|
+
const { autoGroup = true, ...parseOptions } = options;
|
|
54
|
+
|
|
55
|
+
if (autoGroup) {
|
|
56
|
+
return autoGroupEnvByPrefix(env, parseOptions);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return parseEnv(env, parseOptions);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get private environment variables by prefix
|
|
64
|
+
*
|
|
65
|
+
* @param {string} prefix - Environment variable prefix (e.g., 'DATABASE')
|
|
66
|
+
* @param {Object} [options={}] - Parsing options
|
|
67
|
+
*
|
|
68
|
+
* @returns {Object} Parsed configuration object
|
|
69
|
+
*/
|
|
70
|
+
export function getPrivateEnvByPrefix(prefix, options = {}) {
|
|
71
|
+
const prefixWithUnderscore = prefix.endsWith('_') ? prefix : `${prefix}_`;
|
|
72
|
+
|
|
73
|
+
return parseEnv(env, {
|
|
74
|
+
...options,
|
|
75
|
+
prefix: prefixWithUnderscore,
|
|
76
|
+
removePrefix: true
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get raw private environment variables (no parsing)
|
|
82
|
+
*
|
|
83
|
+
* @returns {Object<string, string>} Raw private environment variables
|
|
84
|
+
*/
|
|
85
|
+
export function getRawPrivateEnv() {
|
|
86
|
+
return { ...env };
|
|
87
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get all public environment variables with automatic prefix grouping
|
|
3
|
+
*
|
|
4
|
+
* Automatically detects common prefixes in public environment variables
|
|
5
|
+
* and groups them into configuration objects. This makes it easy to
|
|
6
|
+
* organize related configuration values.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} [options={}] - Parsing options
|
|
9
|
+
* @param {boolean} [options.camelCase=true]
|
|
10
|
+
* Convert env var names to camelCase object keys
|
|
11
|
+
* @param {boolean} [options.parseValues=true]
|
|
12
|
+
* Parse string values to numbers/booleans when possible
|
|
13
|
+
* @param {boolean} [options.autoGroup=true]
|
|
14
|
+
* Enable automatic prefix grouping
|
|
15
|
+
*
|
|
16
|
+
* @returns {Object} Grouped and parsed public environment variables
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Environment variables:
|
|
20
|
+
* // PUBLIC_API_URL=https://api.example.com
|
|
21
|
+
* // PUBLIC_API_TIMEOUT=5000
|
|
22
|
+
* // PUBLIC_FEATURE_FLAGS=true
|
|
23
|
+
*
|
|
24
|
+
* const config = getPublicEnv();
|
|
25
|
+
* // Returns:
|
|
26
|
+
* // {
|
|
27
|
+
* // publicApi: { url: 'https://api.example.com', timeout: 5000 },
|
|
28
|
+
* // publicFeatureFlags: true
|
|
29
|
+
* // }
|
|
30
|
+
*/
|
|
31
|
+
export function getPublicEnv(options?: {
|
|
32
|
+
camelCase?: boolean;
|
|
33
|
+
parseValues?: boolean;
|
|
34
|
+
autoGroup?: boolean;
|
|
35
|
+
}): any;
|
|
36
|
+
/**
|
|
37
|
+
* Get public environment variables by prefix
|
|
38
|
+
*
|
|
39
|
+
* @param {string} prefix - Environment variable prefix (e.g., 'PUBLIC_API')
|
|
40
|
+
* @param {Object} [options={}] - Parsing options
|
|
41
|
+
*
|
|
42
|
+
* @returns {Object} Parsed configuration object
|
|
43
|
+
*/
|
|
44
|
+
export function getPublicEnvByPrefix(prefix: string, options?: any): any;
|
|
45
|
+
/**
|
|
46
|
+
* Get raw public environment variables (no parsing)
|
|
47
|
+
*
|
|
48
|
+
* @returns {Object<string, string>} Raw public environment variables
|
|
49
|
+
*/
|
|
50
|
+
export function getRawPublicEnv(): {
|
|
51
|
+
[x: string]: string;
|
|
52
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Public environment variables access
|
|
3
|
+
*
|
|
4
|
+
* Provides access to SvelteKit public environment variables with parsing.
|
|
5
|
+
* Safe to use on both client and server side.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { getPublicEnv } from './public.js';
|
|
9
|
+
*
|
|
10
|
+
* const publicVars = getPublicEnv();
|
|
11
|
+
* const apiConfig = getPublicEnv({ prefix: 'PUBLIC_API' });
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { env } from '$env/dynamic/public';
|
|
15
|
+
import { autoGroupEnvByPrefix, parseEnv } from './parsers.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get all public environment variables with automatic prefix grouping
|
|
19
|
+
*
|
|
20
|
+
* Automatically detects common prefixes in public environment variables
|
|
21
|
+
* and groups them into configuration objects. This makes it easy to
|
|
22
|
+
* organize related configuration values.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} [options={}] - Parsing options
|
|
25
|
+
* @param {boolean} [options.camelCase=true]
|
|
26
|
+
* Convert env var names to camelCase object keys
|
|
27
|
+
* @param {boolean} [options.parseValues=true]
|
|
28
|
+
* Parse string values to numbers/booleans when possible
|
|
29
|
+
* @param {boolean} [options.autoGroup=true]
|
|
30
|
+
* Enable automatic prefix grouping
|
|
31
|
+
*
|
|
32
|
+
* @returns {Object} Grouped and parsed public environment variables
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Environment variables:
|
|
36
|
+
* // PUBLIC_API_URL=https://api.example.com
|
|
37
|
+
* // PUBLIC_API_TIMEOUT=5000
|
|
38
|
+
* // PUBLIC_FEATURE_FLAGS=true
|
|
39
|
+
*
|
|
40
|
+
* const config = getPublicEnv();
|
|
41
|
+
* // Returns:
|
|
42
|
+
* // {
|
|
43
|
+
* // publicApi: { url: 'https://api.example.com', timeout: 5000 },
|
|
44
|
+
* // publicFeatureFlags: true
|
|
45
|
+
* // }
|
|
46
|
+
*/
|
|
47
|
+
export function getPublicEnv(options = {}) {
|
|
48
|
+
const { autoGroup = true, ...parseOptions } = options;
|
|
49
|
+
|
|
50
|
+
if (autoGroup) {
|
|
51
|
+
return autoGroupEnvByPrefix(env, parseOptions);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return parseEnv(env, parseOptions);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get public environment variables by prefix
|
|
59
|
+
*
|
|
60
|
+
* @param {string} prefix - Environment variable prefix (e.g., 'PUBLIC_API')
|
|
61
|
+
* @param {Object} [options={}] - Parsing options
|
|
62
|
+
*
|
|
63
|
+
* @returns {Object} Parsed configuration object
|
|
64
|
+
*/
|
|
65
|
+
export function getPublicEnvByPrefix(prefix, options = {}) {
|
|
66
|
+
const prefixWithUnderscore = prefix.endsWith('_') ? prefix : `${prefix}_`;
|
|
67
|
+
|
|
68
|
+
return parseEnv(env, {
|
|
69
|
+
...options,
|
|
70
|
+
prefix: prefixWithUnderscore,
|
|
71
|
+
removePrefix: true
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get raw public environment variables (no parsing)
|
|
77
|
+
*
|
|
78
|
+
* @returns {Object<string, string>} Raw public environment variables
|
|
79
|
+
*/
|
|
80
|
+
export function getRawPublicEnv() {
|
|
81
|
+
return { ...env };
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getAllEnv, getAllEnvByPrefix, getRawAllEnv } from "./env/all.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Combined environment variables export (server-side only)
|
|
3
|
+
*
|
|
4
|
+
* Re-exports combined environment utilities for convenient importing.
|
|
5
|
+
* IMPORTANT: This module can only be imported on the server side since it
|
|
6
|
+
* imports private environment variables.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* import { getAllEnv, getAllEnvByPrefix } from './env-all.js';
|
|
10
|
+
*
|
|
11
|
+
* const allVars = getAllEnv();
|
|
12
|
+
* const dbConfig = getAllEnvByPrefix('DATABASE');
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
getAllEnv,
|
|
17
|
+
getAllEnvByPrefix,
|
|
18
|
+
getRawAllEnv
|
|
19
|
+
} from './env/all.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getPrivateEnv, getPrivateEnvByPrefix, getRawPrivateEnv } from "./env/private.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Private environment variables export (server-side only)
|
|
3
|
+
*
|
|
4
|
+
* Re-exports private environment utilities for convenient importing.
|
|
5
|
+
* IMPORTANT: This module can only be imported on the server side.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { getPrivateEnv, getPrivateEnvByPrefix } from './env-private.js';
|
|
9
|
+
*
|
|
10
|
+
* const privateVars = getPrivateEnv();
|
|
11
|
+
* const dbConfig = getPrivateEnvByPrefix('DATABASE');
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
getPrivateEnv,
|
|
16
|
+
getPrivateEnvByPrefix,
|
|
17
|
+
getRawPrivateEnv
|
|
18
|
+
} from './env/private.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getPublicEnv, getPublicEnvByPrefix, getRawPublicEnv } from "./env/public.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Public environment variables export
|
|
3
|
+
*
|
|
4
|
+
* Re-exports public environment utilities for convenient importing.
|
|
5
|
+
* Safe to use on both client and server side.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { getPublicEnv, getPublicEnvByPrefix } from './env-public.js';
|
|
9
|
+
*
|
|
10
|
+
* const publicVars = getPublicEnv();
|
|
11
|
+
* const apiConfig = getPublicEnvByPrefix('PUBLIC_API');
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
getPublicEnv,
|
|
16
|
+
getPublicEnvByPrefix,
|
|
17
|
+
getRawPublicEnv
|
|
18
|
+
} from './env/public.js';
|
package/package.json
CHANGED
package/dist/util/index.js__
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export { rethrow } from './exceptions/index.js';
|
|
2
|
-
|
|
3
|
-
import * as originalValibot from 'valibot';
|
|
4
|
-
|
|
5
|
-
// Create a modified version of valibot with wrapped parse methods
|
|
6
|
-
|
|
7
|
-
/** @type {typeof originalValibot & { _parse: any }} */
|
|
8
|
-
const v = { ...originalValibot, _parse: originalValibot.parse };
|
|
9
|
-
|
|
10
|
-
// Replace with wrappers for better stack trace detection
|
|
11
|
-
v.parse = function valibotParseWrapper(schema, input, config) {
|
|
12
|
-
return this._parse(schema, input, config);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export { v };
|
|
16
|
-
export * as expect from './expect/index.js';
|
|
17
|
-
export * as is from './is/index.js';
|
|
18
|
-
export * as object from './object/index.js';
|
|
19
|
-
|
|
20
|
-
export * as singleton from './singleton/index.js';
|
|
File without changes
|
|
File without changes
|