@lupaflow/secrets 0.1.0

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 ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@lupaflow/secrets",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "require": "./dist/index.js",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "tsup",
21
+ "dev": "tsup --watch"
22
+ },
23
+ "dependencies": {
24
+ "@lupaflow/core": "workspace:*",
25
+ "conf": "^13.1.0",
26
+ "dotenv": "^16.4.5"
27
+ },
28
+ "devDependencies": {
29
+ "tsup": "^8.3.0",
30
+ "typescript": "^5.6.0"
31
+ }
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { SecretsManager } from "./manager"
2
+ export { getOpenRouterKey, getGoogleKey, getGroqKey } from "./providers"
package/src/manager.ts ADDED
@@ -0,0 +1,66 @@
1
+ import dotenv from "dotenv"
2
+ import Conf from "conf"
3
+ import { ConfigError } from "@lupaflow/core"
4
+
5
+ dotenv.config()
6
+
7
+ const store = new Conf({
8
+ projectName: "lupaflow",
9
+ schema: {
10
+ apiKeys: {
11
+ type: "object",
12
+ default: {},
13
+ },
14
+ },
15
+ })
16
+
17
+ export class SecretsManager {
18
+ private static keys: Map<string, string> = new Map()
19
+
20
+ static init(): void {
21
+ const saved = store.get("apiKeys") as Record<string, string>
22
+ for (const [key, value] of Object.entries(saved)) {
23
+ SecretsManager.keys.set(key, value)
24
+ }
25
+ }
26
+
27
+ static get(key: string): string | undefined {
28
+ const envKey = key.toUpperCase()
29
+ const envValue = process.env[envKey] || process.env[`LUPAFLOW_${envKey}`]
30
+ if (envValue) return envValue
31
+ return SecretsManager.keys.get(key)
32
+ }
33
+
34
+ static require(key: string): string {
35
+ const value = SecretsManager.get(key)
36
+ if (!value) {
37
+ throw new ConfigError(`Missing required secret: ${key}`, {
38
+ hint: `Set ${key.toUpperCase()} in your .env file or run: lupaflow secrets set ${key} <value>`,
39
+ })
40
+ }
41
+ return value
42
+ }
43
+
44
+ static set(key: string, value: string): void {
45
+ SecretsManager.keys.set(key, value)
46
+ const saved = store.get("apiKeys") as Record<string, string>
47
+ saved[key] = value
48
+ store.set("apiKeys", saved)
49
+ }
50
+
51
+ static delete(key: string): void {
52
+ SecretsManager.keys.delete(key)
53
+ const saved = store.get("apiKeys") as Record<string, string>
54
+ delete saved[key]
55
+ store.set("apiKeys", saved)
56
+ }
57
+
58
+ static list(): string[] {
59
+ return Array.from(SecretsManager.keys.keys())
60
+ }
61
+
62
+ static clear(): void {
63
+ SecretsManager.keys.clear()
64
+ store.set("apiKeys", {})
65
+ }
66
+ }
@@ -0,0 +1,13 @@
1
+ import { SecretsManager } from "./manager"
2
+
3
+ export function getOpenRouterKey(): string {
4
+ return SecretsManager.require("OPENROUTER_API_KEY")
5
+ }
6
+
7
+ export function getGoogleKey(): string {
8
+ return SecretsManager.require("GOOGLE_API_KEY")
9
+ }
10
+
11
+ export function getGroqKey(): string {
12
+ return SecretsManager.require("GROQ_API_KEY")
13
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src"]
8
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from "tsup"
2
+ export default defineConfig({
3
+ entry: { index: "src/index.ts" },
4
+ format: ["cjs", "esm"],
5
+ dts: true,
6
+ sourcemap: true,
7
+ clean: true,
8
+ external: [/node_modules/],
9
+ })