@sebspark/environment 0.1.2 → 0.1.3
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/CHANGELOG.md +46 -0
- package/dist/index.d.mts +3 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @sebspark/environment
|
|
2
|
+
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 66ac832: * Upgraded to TypeScript 7
|
|
8
|
+
- Replaced tsup with tsdown for package builds
|
|
9
|
+
- Fixed cli-tester stdout parsing, resolving flaky e2e tests across the repo
|
|
10
|
+
- Patched vulnerable transitive dependencies (uuid, socket.io-parser, and others)
|
|
11
|
+
|
|
12
|
+
## 0.1.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- b5f1b3f: add mergeEnvironment helper function
|
|
17
|
+
|
|
18
|
+
## 0.1.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 061b497: adjust filepath and add support for local env
|
|
23
|
+
|
|
24
|
+
## 0.1.0
|
|
25
|
+
|
|
26
|
+
### Minor Changes
|
|
27
|
+
|
|
28
|
+
- 626c170: add initSecretStore function and tests
|
|
29
|
+
|
|
30
|
+
## 0.0.4
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 7d8cc98: Dependabot dependency updates
|
|
35
|
+
|
|
36
|
+
## 0.0.3
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- 736a0b3: No bundling of packages in packages
|
|
41
|
+
|
|
42
|
+
## 0.0.1
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- 49ca25b: feat: publish @sebspark/environment
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
|
-
declare const initEnvironment: <T extends Record<string, string>>() => T & {
|
|
2
|
+
export declare const initEnvironment: <T extends Record<string, string>>() => T & {
|
|
3
3
|
optional: Partial<T>;
|
|
4
4
|
} & {
|
|
5
5
|
[key: string]: string;
|
|
6
6
|
};
|
|
7
|
-
declare const mergeEnvironments: <T extends Record<string, string>, U extends Record<string, string>>(env: T, secrets: U) => T & U;
|
|
7
|
+
export declare const mergeEnvironments: <T extends Record<string, string>, U extends Record<string, string>>(env: T, secrets: U) => T & U;
|
|
8
8
|
type SecretStoreOptions<T> = {
|
|
9
9
|
dir?: string;
|
|
10
10
|
fallback?: boolean | Partial<T>;
|
|
11
11
|
};
|
|
12
|
-
declare const initSecretStore: <T extends Record<string, string>>(opts?: SecretStoreOptions<T>) => T & {
|
|
12
|
+
export declare const initSecretStore: <T extends Record<string, string>>(opts?: SecretStoreOptions<T>) => T & {
|
|
13
13
|
[key: string]: string;
|
|
14
14
|
};
|
|
15
15
|
//#endregion
|
|
16
|
-
export { initEnvironment, initSecretStore, mergeEnvironments };
|
|
17
16
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";qBAIa,kBAAmB,UAAU,6BAiCnC;EAAM,UAAU,QAAQ;;GAAU;;qBAG5B,oBACX,UAAU,wBACV,UAAU,wBAAsB,KAE3B,GAAC,SACG,MACR,IAAI;KAYF,mBAAmB;EACtB;EACA,qBAAqB,QAAQ;;qBAGlB,kBAAmB,UAAU,wBAAsB,OACvD,mBAAmB,OAwCrB;GAAO"}
|
package/dist/index.mjs
CHANGED
|
@@ -36,7 +36,8 @@ const initSecretStore = (opts) => {
|
|
|
36
36
|
if (key in secretCache) return secretCache[key];
|
|
37
37
|
const filePath = dir ? join(dir, key) : key;
|
|
38
38
|
try {
|
|
39
|
-
|
|
39
|
+
const value = readFileSync(filePath, "utf-8").trim();
|
|
40
|
+
secretCache[key] = value;
|
|
40
41
|
return secretCache[key];
|
|
41
42
|
} catch {}
|
|
42
43
|
if (fallback === true) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import assert from 'node:assert'\nimport { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\nexport const initEnvironment = <T extends Record<string, string>>() => {\n const environmentCache: Record<string, string | undefined> = {}\n\n return new Proxy(\n {},\n {\n get(_, k: keyof T | 'optional' | string | symbol) {\n const key = k as string\n if (key === 'optional') {\n return new Proxy(\n {},\n {\n get(_, k: keyof T | string | symbol) {\n const key = k as string\n if (key in environmentCache) {\n return environmentCache[key]\n }\n const { [key]: value } = process.env\n environmentCache[key] = value\n return environmentCache[key]\n },\n }\n ) as T\n }\n if (key in environmentCache) {\n return environmentCache[key]\n }\n const { [key]: value } = process.env\n assert(value, `${key} is required`)\n environmentCache[key] = value\n return environmentCache[key]\n },\n }\n ) as T & { optional: Partial<T> } & { [key: string]: string }\n}\n\nexport const mergeEnvironments = <\n T extends Record<string, string>,\n U extends Record<string, string>,\n>(\n env: T,\n secrets: U\n): T & U =>\n new Proxy({} as T & U, {\n get(_, key) {\n if (typeof key !== 'string') return undefined\n try {\n return (secrets as Record<string, string>)[key]\n } catch {\n return (env as Record<string, string>)[key]\n }\n },\n })\n\ntype SecretStoreOptions<T> = {\n dir?: string\n fallback?: boolean | Partial<T>\n}\n\nexport const initSecretStore = <T extends Record<string, string>>(\n opts?: SecretStoreOptions<T>\n) => {\n const secretCache: Record<string, string | undefined> = {}\n const { dir, fallback } = opts ?? {}\n\n return new Proxy(\n {},\n {\n get(_, k: keyof T | string | symbol) {\n const key = k as string\n if (key in secretCache) {\n return secretCache[key]\n }\n\n // 1. Try reading from file (dir/KEY or just KEY if no dir)\n const filePath = dir ? join(dir, key) : key\n try {\n const value = readFileSync(filePath, 'utf-8').trim()\n secretCache[key] = value\n return secretCache[key]\n } catch {\n // file not found — continue to fallback\n }\n\n // 2. Try fallback\n if (fallback === true) {\n // auto-read from process.env using the same key name\n const { [key]: value } = process.env\n if (value !== undefined) {\n secretCache[key] = value\n return secretCache[key]\n }\n } else if (fallback && key in fallback) {\n secretCache[key] = fallback[key as keyof T] as string\n return secretCache[key]\n }\n\n throw new Error(`Secret ${key} is required`)\n },\n }\n ) as T & { [key: string]: string }\n}\n"],"mappings":";;;;AAIA,MAAa,wBAA0D;CACrE,MAAM,mBAAuD,
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import assert from 'node:assert'\nimport { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\n\nexport const initEnvironment = <T extends Record<string, string>>() => {\n const environmentCache: Record<string, string | undefined> = {}\n\n return new Proxy(\n {},\n {\n get(_, k: keyof T | 'optional' | string | symbol) {\n const key = k as string\n if (key === 'optional') {\n return new Proxy(\n {},\n {\n get(_, k: keyof T | string | symbol) {\n const key = k as string\n if (key in environmentCache) {\n return environmentCache[key]\n }\n const { [key]: value } = process.env\n environmentCache[key] = value\n return environmentCache[key]\n },\n }\n ) as T\n }\n if (key in environmentCache) {\n return environmentCache[key]\n }\n const { [key]: value } = process.env\n assert(value, `${key} is required`)\n environmentCache[key] = value\n return environmentCache[key]\n },\n }\n ) as T & { optional: Partial<T> } & { [key: string]: string }\n}\n\nexport const mergeEnvironments = <\n T extends Record<string, string>,\n U extends Record<string, string>,\n>(\n env: T,\n secrets: U\n): T & U =>\n new Proxy({} as T & U, {\n get(_, key) {\n if (typeof key !== 'string') return undefined\n try {\n return (secrets as Record<string, string>)[key]\n } catch {\n return (env as Record<string, string>)[key]\n }\n },\n })\n\ntype SecretStoreOptions<T> = {\n dir?: string\n fallback?: boolean | Partial<T>\n}\n\nexport const initSecretStore = <T extends Record<string, string>>(\n opts?: SecretStoreOptions<T>\n) => {\n const secretCache: Record<string, string | undefined> = {}\n const { dir, fallback } = opts ?? {}\n\n return new Proxy(\n {},\n {\n get(_, k: keyof T | string | symbol) {\n const key = k as string\n if (key in secretCache) {\n return secretCache[key]\n }\n\n // 1. Try reading from file (dir/KEY or just KEY if no dir)\n const filePath = dir ? join(dir, key) : key\n try {\n const value = readFileSync(filePath, 'utf-8').trim()\n secretCache[key] = value\n return secretCache[key]\n } catch {\n // file not found — continue to fallback\n }\n\n // 2. Try fallback\n if (fallback === true) {\n // auto-read from process.env using the same key name\n const { [key]: value } = process.env\n if (value !== undefined) {\n secretCache[key] = value\n return secretCache[key]\n }\n } else if (fallback && key in fallback) {\n secretCache[key] = fallback[key as keyof T] as string\n return secretCache[key]\n }\n\n throw new Error(`Secret ${key} is required`)\n },\n }\n ) as T & { [key: string]: string }\n}\n"],"mappings":";;;;AAIA,MAAa,wBAA0D;CACrE,MAAM,mBAAuD,CAAC;CAE9D,OAAO,IAAI,MACT,CAAC,GACD,EACE,IAAI,GAAG,GAA2C;EAChD,MAAM,MAAM;EACZ,IAAI,QAAQ,YACV,OAAO,IAAI,MACT,CAAC,GACD,EACE,IAAI,GAAG,GAA8B;GACnC,MAAM,MAAM;GACZ,IAAI,OAAO,kBACT,OAAO,iBAAiB;GAE1B,MAAM,GAAG,MAAM,UAAU,QAAQ;GACjC,iBAAiB,OAAO;GACxB,OAAO,iBAAiB;EAC1B,EACF,CACF;EAEF,IAAI,OAAO,kBACT,OAAO,iBAAiB;EAE1B,MAAM,GAAG,MAAM,UAAU,QAAQ;EACjC,OAAO,OAAO,GAAG,IAAI,aAAa;EAClC,iBAAiB,OAAO;EACxB,OAAO,iBAAiB;CAC1B,EACF,CACF;AACF;AAEA,MAAa,qBAIX,KACA,YAEA,IAAI,MAAM,CAAC,GAAY,EACrB,IAAI,GAAG,KAAK;CACV,IAAI,OAAO,QAAQ,UAAU,OAAO,KAAA;CACpC,IAAI;EACF,OAAQ,QAAmC;CAC7C,QAAQ;EACN,OAAQ,IAA+B;CACzC;AACF,EACF,CAAC;AAOH,MAAa,mBACX,SACG;CACH,MAAM,cAAkD,CAAC;CACzD,MAAM,EAAE,KAAK,aAAa,QAAQ,CAAC;CAEnC,OAAO,IAAI,MACT,CAAC,GACD,EACE,IAAI,GAAG,GAA8B;EACnC,MAAM,MAAM;EACZ,IAAI,OAAO,aACT,OAAO,YAAY;EAIrB,MAAM,WAAW,MAAM,KAAK,KAAK,GAAG,IAAI;EACxC,IAAI;GACF,MAAM,QAAQ,aAAa,UAAU,OAAO,CAAC,CAAC,KAAK;GACnD,YAAY,OAAO;GACnB,OAAO,YAAY;EACrB,QAAQ,CAER;EAGA,IAAI,aAAa,MAAM;GAErB,MAAM,GAAG,MAAM,UAAU,QAAQ;GACjC,IAAI,UAAU,KAAA,GAAW;IACvB,YAAY,OAAO;IACnB,OAAO,YAAY;GACrB;EACF,OAAO,IAAI,YAAY,OAAO,UAAU;GACtC,YAAY,OAAO,SAAS;GAC5B,OAAO,YAAY;EACrB;EAEA,MAAM,IAAI,MAAM,UAAU,IAAI,aAAa;CAC7C,EACF,CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/environment",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -20,10 +20,18 @@
|
|
|
20
20
|
"dev": "tsc --watch --noEmit",
|
|
21
21
|
"lint": "biome check .",
|
|
22
22
|
"test": "vitest run --passWithNoTests --coverage",
|
|
23
|
-
"typecheck": "vitest --typecheck.only --passWithNoTests"
|
|
23
|
+
"typecheck": "vitest --typecheck.only --passWithNoTests --run"
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "https://github.com/seb-oss/Spark-packages.git"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@biomejs/biome": "2.5.12",
|
|
31
|
+
"@sebspark/tsconfig": "*",
|
|
32
|
+
"depcheck": "1.4.7",
|
|
33
|
+
"typescript": "7.0.2",
|
|
34
|
+
"vite": "8.2.2",
|
|
35
|
+
"vitest": "5.0.0"
|
|
28
36
|
}
|
|
29
|
-
}
|
|
37
|
+
}
|