@kitsy/cnos 1.5.1 → 1.6.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/dist/build/index.cjs +325 -113
- package/dist/build/index.d.cts +3 -2
- package/dist/build/index.d.ts +3 -2
- package/dist/build/index.js +13 -8
- package/dist/{chunk-UWFE4JE2.js → chunk-BMAD24KC.js} +1 -1
- package/dist/{chunk-7EI3RFUE.js → chunk-JYWQFMW5.js} +1 -1
- package/dist/{chunk-F2ZAIZNH.js → chunk-MW4OVAT3.js} +1 -1
- package/dist/chunk-QU5CXL47.js +577 -0
- package/dist/{chunk-BS33AW4Y.js → chunk-S7H2UULC.js} +307 -103
- package/dist/{chunk-H53ZRQLX.js → chunk-UJBQS7CJ.js} +1 -1
- package/dist/{chunk-CMQK2AEF.js → chunk-UOKVLCFL.js} +10 -10
- package/dist/{chunk-EJAXWFNT.js → chunk-UR7CHHNN.js} +1 -1
- package/dist/{chunk-SZKQVA2M.js → chunk-VGZREX5D.js} +1 -1
- package/dist/{chunk-5F2OFKND.js → chunk-XSUP7JKH.js} +23 -1
- package/dist/configure/index.cjs +324 -118
- package/dist/configure/index.d.cts +3 -3
- package/dist/configure/index.d.ts +3 -3
- package/dist/configure/index.js +8 -8
- package/dist/{envNaming-Dvm_LP2D.d.ts → envNaming-B7Mztkcf.d.ts} +1 -1
- package/dist/{envNaming-S4B-dHUx.d.cts → envNaming-gMVnPOfe.d.cts} +1 -1
- package/dist/index.cjs +698 -136
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -10
- package/dist/internal.cjs +227 -102
- package/dist/internal.d.cts +16 -28
- package/dist/internal.d.ts +16 -28
- package/dist/internal.js +11 -3
- package/dist/plugin/basic-schema.cjs +22 -15
- package/dist/plugin/basic-schema.d.cts +1 -1
- package/dist/plugin/basic-schema.d.ts +1 -1
- package/dist/plugin/basic-schema.js +2 -2
- package/dist/plugin/cli-args.cjs +27 -18
- package/dist/plugin/cli-args.d.cts +1 -1
- package/dist/plugin/cli-args.d.ts +1 -1
- package/dist/plugin/cli-args.js +2 -2
- package/dist/plugin/dotenv.cjs +35 -26
- package/dist/plugin/dotenv.d.cts +2 -2
- package/dist/plugin/dotenv.d.ts +2 -2
- package/dist/plugin/dotenv.js +2 -2
- package/dist/plugin/env-export.cjs +28 -19
- package/dist/plugin/env-export.d.cts +2 -2
- package/dist/plugin/env-export.d.ts +2 -2
- package/dist/plugin/env-export.js +2 -2
- package/dist/plugin/filesystem.cjs +42 -33
- package/dist/plugin/filesystem.d.cts +1 -1
- package/dist/plugin/filesystem.d.ts +1 -1
- package/dist/plugin/filesystem.js +2 -2
- package/dist/plugin/process-env.cjs +24 -17
- package/dist/plugin/process-env.d.cts +2 -2
- package/dist/plugin/process-env.d.ts +2 -2
- package/dist/plugin/process-env.js +2 -2
- package/dist/{plugin-B4xwySxw.d.cts → plugin-CKrBlWGI.d.cts} +52 -3
- package/dist/{plugin-B4xwySxw.d.ts → plugin-CKrBlWGI.d.ts} +52 -3
- package/dist/runtime/index.cjs +696 -136
- package/dist/runtime/index.d.cts +7 -1
- package/dist/runtime/index.d.ts +7 -1
- package/dist/runtime/index.js +10 -10
- package/dist/{toPublicEnv-ggmphZFs.d.cts → toPublicEnv-CmBsy53P.d.cts} +1 -1
- package/dist/{toPublicEnv-CvhGAfsB.d.ts → toPublicEnv-q6VwWxXZ.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/chunk-TUMR7JA3.js +0 -234
package/dist/build/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CnosCreateOptions } from '../plugin-
|
|
1
|
+
import { C as CnosCreateOptions, S as ServerProjection } from '../plugin-CKrBlWGI.cjs';
|
|
2
2
|
|
|
3
3
|
type BrowserDataMap = Record<string, unknown>;
|
|
4
4
|
type FrameworkEnvTarget = 'generic' | 'vite' | 'next' | 'webpack' | (string & {});
|
|
@@ -9,5 +9,6 @@ declare function toFrameworkEnv(browserData: BrowserDataMap, framework?: Framewo
|
|
|
9
9
|
declare function resolveFrameworkEnv(options?: CnosCreateOptions, framework?: FrameworkEnvTarget, envOptions?: {
|
|
10
10
|
prefix?: string;
|
|
11
11
|
}): Promise<Record<string, string>>;
|
|
12
|
+
declare function resolveServerProjection(options?: CnosCreateOptions): Promise<ServerProjection>;
|
|
12
13
|
|
|
13
|
-
export { type BrowserDataMap, type FrameworkEnvTarget, resolveBrowserData, resolveFrameworkEnv, toFrameworkEnv };
|
|
14
|
+
export { type BrowserDataMap, type FrameworkEnvTarget, resolveBrowserData, resolveFrameworkEnv, resolveServerProjection, toFrameworkEnv };
|
package/dist/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CnosCreateOptions } from '../plugin-
|
|
1
|
+
import { C as CnosCreateOptions, S as ServerProjection } from '../plugin-CKrBlWGI.js';
|
|
2
2
|
|
|
3
3
|
type BrowserDataMap = Record<string, unknown>;
|
|
4
4
|
type FrameworkEnvTarget = 'generic' | 'vite' | 'next' | 'webpack' | (string & {});
|
|
@@ -9,5 +9,6 @@ declare function toFrameworkEnv(browserData: BrowserDataMap, framework?: Framewo
|
|
|
9
9
|
declare function resolveFrameworkEnv(options?: CnosCreateOptions, framework?: FrameworkEnvTarget, envOptions?: {
|
|
10
10
|
prefix?: string;
|
|
11
11
|
}): Promise<Record<string, string>>;
|
|
12
|
+
declare function resolveServerProjection(options?: CnosCreateOptions): Promise<ServerProjection>;
|
|
12
13
|
|
|
13
|
-
export { type BrowserDataMap, type FrameworkEnvTarget, resolveBrowserData, resolveFrameworkEnv, toFrameworkEnv };
|
|
14
|
+
export { type BrowserDataMap, type FrameworkEnvTarget, resolveBrowserData, resolveFrameworkEnv, resolveServerProjection, toFrameworkEnv };
|
package/dist/build/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createCnos
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
10
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-UOKVLCFL.js";
|
|
4
|
+
import "../chunk-BMAD24KC.js";
|
|
5
|
+
import "../chunk-VGZREX5D.js";
|
|
6
|
+
import "../chunk-UR7CHHNN.js";
|
|
7
|
+
import "../chunk-UJBQS7CJ.js";
|
|
8
|
+
import "../chunk-MW4OVAT3.js";
|
|
9
|
+
import "../chunk-JYWQFMW5.js";
|
|
10
|
+
import "../chunk-S7H2UULC.js";
|
|
11
11
|
|
|
12
12
|
// src/build/index.ts
|
|
13
13
|
async function resolveBrowserData(options = {}) {
|
|
@@ -66,8 +66,13 @@ async function resolveFrameworkEnv(options = {}, framework = "generic", envOptio
|
|
|
66
66
|
...envOptions.prefix ? { prefix: envOptions.prefix } : {}
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
+
async function resolveServerProjection(options = {}) {
|
|
70
|
+
const runtime = await createCnos(options);
|
|
71
|
+
return runtime.toServerProjection();
|
|
72
|
+
}
|
|
69
73
|
export {
|
|
70
74
|
resolveBrowserData,
|
|
71
75
|
resolveFrameworkEnv,
|
|
76
|
+
resolveServerProjection,
|
|
72
77
|
toFrameworkEnv
|
|
73
78
|
};
|
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deserializeServerProjection,
|
|
3
|
+
graphRequiresSecretHydration,
|
|
4
|
+
readRuntimeGraphFromEnv,
|
|
5
|
+
readServerProjectionFromEnv
|
|
6
|
+
} from "./chunk-XSUP7JKH.js";
|
|
7
|
+
import {
|
|
8
|
+
createCnos,
|
|
9
|
+
getBootstrappedSecretHydrationRequired,
|
|
10
|
+
getSingletonReady,
|
|
11
|
+
getSingletonRuntime,
|
|
12
|
+
setBootstrappedSecretHydrationRequired,
|
|
13
|
+
setSingletonReady,
|
|
14
|
+
setSingletonRuntime
|
|
15
|
+
} from "./chunk-UOKVLCFL.js";
|
|
16
|
+
import {
|
|
17
|
+
createSecretVaultProvider,
|
|
18
|
+
inspectValue,
|
|
19
|
+
readOrValue,
|
|
20
|
+
readValue,
|
|
21
|
+
requireValue,
|
|
22
|
+
resolveVaultAuth,
|
|
23
|
+
toEnv,
|
|
24
|
+
toLogicalKey,
|
|
25
|
+
toNamespaceObject,
|
|
26
|
+
toPublicEnv
|
|
27
|
+
} from "./chunk-S7H2UULC.js";
|
|
28
|
+
|
|
29
|
+
// src/runtime/index.ts
|
|
30
|
+
import { existsSync, readFileSync } from "fs";
|
|
31
|
+
import path from "path";
|
|
32
|
+
var NOT_READY_MESSAGE = "CNOS not initialized. Call await cnos.ready() or use cnos run.";
|
|
33
|
+
function getRuntimeOrThrow() {
|
|
34
|
+
const runtime = getSingletonRuntime();
|
|
35
|
+
if (!runtime) {
|
|
36
|
+
throw new Error(NOT_READY_MESSAGE);
|
|
37
|
+
}
|
|
38
|
+
return runtime;
|
|
39
|
+
}
|
|
40
|
+
function requireLogicalKey(runtime, key) {
|
|
41
|
+
return runtime.require(key);
|
|
42
|
+
}
|
|
43
|
+
function readLogicalKey(runtime, key) {
|
|
44
|
+
return runtime.read(key);
|
|
45
|
+
}
|
|
46
|
+
function stringifyLogValue(value) {
|
|
47
|
+
if (value === void 0) {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
if (value === null) {
|
|
51
|
+
return "null";
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === "string") {
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
57
|
+
return String(value);
|
|
58
|
+
}
|
|
59
|
+
return JSON.stringify(value);
|
|
60
|
+
}
|
|
61
|
+
function formatMessage(runtime, message) {
|
|
62
|
+
return message.replace(/\$\{([^}]+)\}/g, (match, rawKey) => {
|
|
63
|
+
const key = String(rawKey).trim();
|
|
64
|
+
if (!key) {
|
|
65
|
+
return match;
|
|
66
|
+
}
|
|
67
|
+
const value = runtime.read(key);
|
|
68
|
+
return value === void 0 ? match : stringifyLogValue(value);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function attachBootstrappedGraph(graph) {
|
|
72
|
+
if (getSingletonRuntime()) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const bootstrappedManifest = {
|
|
76
|
+
version: 1,
|
|
77
|
+
project: {
|
|
78
|
+
name: "bootstrapped"
|
|
79
|
+
},
|
|
80
|
+
workspaces: {
|
|
81
|
+
global: {
|
|
82
|
+
enabled: Boolean(graph.workspace.globalRoot),
|
|
83
|
+
...graph.workspace.globalRoot ? {
|
|
84
|
+
root: graph.workspace.globalRoot
|
|
85
|
+
} : {},
|
|
86
|
+
allowWrite: false
|
|
87
|
+
},
|
|
88
|
+
items: {},
|
|
89
|
+
...graph.workspace.workspaceSource === "implicit" ? {} : {
|
|
90
|
+
default: graph.workspace.workspaceId
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
profiles: {
|
|
94
|
+
default: graph.profile,
|
|
95
|
+
resolveFrom: ["default"]
|
|
96
|
+
},
|
|
97
|
+
plugins: {
|
|
98
|
+
loaders: [],
|
|
99
|
+
resolver: "profile-aware",
|
|
100
|
+
validators: [],
|
|
101
|
+
exporters: [],
|
|
102
|
+
inspectors: []
|
|
103
|
+
},
|
|
104
|
+
sources: {},
|
|
105
|
+
resolution: {
|
|
106
|
+
precedence: [],
|
|
107
|
+
arrayPolicy: "replace"
|
|
108
|
+
},
|
|
109
|
+
envMapping: {
|
|
110
|
+
explicit: {}
|
|
111
|
+
},
|
|
112
|
+
public: {
|
|
113
|
+
promote: [],
|
|
114
|
+
frameworks: {}
|
|
115
|
+
},
|
|
116
|
+
namespaces: {},
|
|
117
|
+
vaults: {},
|
|
118
|
+
writePolicy: {
|
|
119
|
+
define: {
|
|
120
|
+
defaultProfile: graph.profile,
|
|
121
|
+
targets: {
|
|
122
|
+
value: "./values/app.yml",
|
|
123
|
+
secret: "./secrets/app.yml"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
schema: {}
|
|
128
|
+
};
|
|
129
|
+
const runtime = {
|
|
130
|
+
manifest: bootstrappedManifest,
|
|
131
|
+
plugins: [],
|
|
132
|
+
graph,
|
|
133
|
+
read(key) {
|
|
134
|
+
return readValue(graph, key);
|
|
135
|
+
},
|
|
136
|
+
require(key) {
|
|
137
|
+
return requireValue(graph, key);
|
|
138
|
+
},
|
|
139
|
+
readOr(key, fallback) {
|
|
140
|
+
return readOrValue(graph, key, fallback);
|
|
141
|
+
},
|
|
142
|
+
value(path2) {
|
|
143
|
+
return readValue(graph, toLogicalKey("value", path2));
|
|
144
|
+
},
|
|
145
|
+
secret(path2) {
|
|
146
|
+
return readValue(graph, toLogicalKey("secret", path2));
|
|
147
|
+
},
|
|
148
|
+
meta(path2) {
|
|
149
|
+
return readValue(graph, toLogicalKey("meta", path2));
|
|
150
|
+
},
|
|
151
|
+
toNamespace(namespace) {
|
|
152
|
+
return toNamespaceObject(graph, namespace);
|
|
153
|
+
},
|
|
154
|
+
toEnv(options) {
|
|
155
|
+
return toEnv(graph, bootstrappedManifest, options);
|
|
156
|
+
},
|
|
157
|
+
toPublicEnv(options) {
|
|
158
|
+
return toPublicEnv(graph, bootstrappedManifest, options);
|
|
159
|
+
},
|
|
160
|
+
inspect(key) {
|
|
161
|
+
return inspectValue(graph, key);
|
|
162
|
+
},
|
|
163
|
+
toObject() {
|
|
164
|
+
return toNamespaceObject(graph);
|
|
165
|
+
},
|
|
166
|
+
toServerProjection() {
|
|
167
|
+
throw new Error("CNOS graph bootstrap payload does not support server projection export.");
|
|
168
|
+
},
|
|
169
|
+
async refreshSecrets() {
|
|
170
|
+
return;
|
|
171
|
+
},
|
|
172
|
+
async refreshSecret() {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
setSingletonRuntime(runtime);
|
|
177
|
+
setBootstrappedSecretHydrationRequired(graphRequiresSecretHydration(graph));
|
|
178
|
+
}
|
|
179
|
+
function toBootstrappedManifest(graph) {
|
|
180
|
+
return {
|
|
181
|
+
version: 1,
|
|
182
|
+
project: {
|
|
183
|
+
name: "bootstrapped"
|
|
184
|
+
},
|
|
185
|
+
workspaces: {
|
|
186
|
+
global: {
|
|
187
|
+
enabled: false,
|
|
188
|
+
allowWrite: false
|
|
189
|
+
},
|
|
190
|
+
items: {},
|
|
191
|
+
...graph.workspace.workspaceSource === "implicit" ? {} : {
|
|
192
|
+
default: graph.workspace.workspaceId
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
profiles: {
|
|
196
|
+
default: graph.profile,
|
|
197
|
+
resolveFrom: ["default"]
|
|
198
|
+
},
|
|
199
|
+
plugins: {
|
|
200
|
+
loaders: [],
|
|
201
|
+
resolver: "profile-aware",
|
|
202
|
+
validators: [],
|
|
203
|
+
exporters: [],
|
|
204
|
+
inspectors: []
|
|
205
|
+
},
|
|
206
|
+
sources: {},
|
|
207
|
+
resolution: {
|
|
208
|
+
precedence: [],
|
|
209
|
+
arrayPolicy: "replace"
|
|
210
|
+
},
|
|
211
|
+
envMapping: {
|
|
212
|
+
explicit: {}
|
|
213
|
+
},
|
|
214
|
+
public: {
|
|
215
|
+
promote: [],
|
|
216
|
+
frameworks: {}
|
|
217
|
+
},
|
|
218
|
+
namespaces: {
|
|
219
|
+
value: { kind: "data", shareable: true },
|
|
220
|
+
secret: { kind: "data", shareable: false, sensitive: true },
|
|
221
|
+
meta: { kind: "system", shareable: false, readonly: true },
|
|
222
|
+
public: { kind: "projection", shareable: true, readonly: true, source: "promote" }
|
|
223
|
+
},
|
|
224
|
+
vaults: {},
|
|
225
|
+
writePolicy: {
|
|
226
|
+
define: {
|
|
227
|
+
defaultProfile: graph.profile,
|
|
228
|
+
targets: {
|
|
229
|
+
value: "./values/app.yml",
|
|
230
|
+
secret: "./secrets/app.yml"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
schema: {}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function graphFromProjection(projection) {
|
|
238
|
+
const entries = /* @__PURE__ */ new Map();
|
|
239
|
+
const now = projection.resolvedAt;
|
|
240
|
+
const explicitNamespaces = /* @__PURE__ */ new Set(["flags", "config", "process", ...projection.meta.namespaces ?? []]);
|
|
241
|
+
for (const [key, value] of Object.entries(projection.values)) {
|
|
242
|
+
const firstSegment = key.split(".")[0] ?? "";
|
|
243
|
+
const logicalKey = key.startsWith("value.") || key.startsWith("public.") || explicitNamespaces.has(firstSegment) ? key : `value.${key}`;
|
|
244
|
+
const namespace = logicalKey.slice(0, logicalKey.indexOf("."));
|
|
245
|
+
const winner = {
|
|
246
|
+
key: logicalKey,
|
|
247
|
+
value,
|
|
248
|
+
namespace,
|
|
249
|
+
sourceId: "server-projection",
|
|
250
|
+
pluginId: "cnos",
|
|
251
|
+
workspaceId: projection.workspace,
|
|
252
|
+
profile: projection.profile
|
|
253
|
+
};
|
|
254
|
+
entries.set(logicalKey, {
|
|
255
|
+
key: logicalKey,
|
|
256
|
+
value,
|
|
257
|
+
namespace,
|
|
258
|
+
winner,
|
|
259
|
+
overridden: []
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
for (const [key, ref] of Object.entries(projection.secretRefs)) {
|
|
263
|
+
const logicalKey = `secret.${key}`;
|
|
264
|
+
entries.set(logicalKey, {
|
|
265
|
+
key: logicalKey,
|
|
266
|
+
value: ref,
|
|
267
|
+
namespace: "secret",
|
|
268
|
+
winner: {
|
|
269
|
+
key: logicalKey,
|
|
270
|
+
value: ref,
|
|
271
|
+
namespace: "secret",
|
|
272
|
+
sourceId: "server-projection",
|
|
273
|
+
pluginId: "cnos",
|
|
274
|
+
workspaceId: projection.workspace,
|
|
275
|
+
profile: projection.profile
|
|
276
|
+
},
|
|
277
|
+
overridden: []
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
for (const key of projection.publicKeys) {
|
|
281
|
+
const valueKey = Object.prototype.hasOwnProperty.call(projection.values, key) ? key : `value.${key}`;
|
|
282
|
+
const publicKey = `public.${key}`;
|
|
283
|
+
const sourceEntry = entries.get(valueKey);
|
|
284
|
+
if (!sourceEntry) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
entries.set(publicKey, {
|
|
288
|
+
key: publicKey,
|
|
289
|
+
value: sourceEntry.value,
|
|
290
|
+
namespace: "public",
|
|
291
|
+
winner: {
|
|
292
|
+
key: publicKey,
|
|
293
|
+
value: sourceEntry.value,
|
|
294
|
+
namespace: "public",
|
|
295
|
+
sourceId: "server-projection",
|
|
296
|
+
pluginId: "cnos",
|
|
297
|
+
workspaceId: projection.workspace,
|
|
298
|
+
profile: projection.profile
|
|
299
|
+
},
|
|
300
|
+
overridden: []
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
entries.set("meta.profile", {
|
|
304
|
+
key: "meta.profile",
|
|
305
|
+
value: projection.profile,
|
|
306
|
+
namespace: "meta",
|
|
307
|
+
winner: {
|
|
308
|
+
key: "meta.profile",
|
|
309
|
+
value: projection.profile,
|
|
310
|
+
namespace: "meta",
|
|
311
|
+
sourceId: "server-projection",
|
|
312
|
+
pluginId: "cnos",
|
|
313
|
+
workspaceId: projection.workspace,
|
|
314
|
+
profile: projection.profile
|
|
315
|
+
},
|
|
316
|
+
overridden: []
|
|
317
|
+
});
|
|
318
|
+
return {
|
|
319
|
+
entries,
|
|
320
|
+
profile: projection.profile,
|
|
321
|
+
resolvedAt: now,
|
|
322
|
+
profileSource: "manifest-default",
|
|
323
|
+
workspace: {
|
|
324
|
+
workspaceId: projection.workspace,
|
|
325
|
+
workspaceSource: "implicit",
|
|
326
|
+
workspaceChain: [projection.workspace],
|
|
327
|
+
workspaceRoots: []
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function attachBootstrappedProjection(projection, force = false) {
|
|
332
|
+
if (getSingletonRuntime() && !force) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const graph = graphFromProjection(projection);
|
|
336
|
+
const manifest = toBootstrappedManifest(graph);
|
|
337
|
+
const hydratedSecrets = /* @__PURE__ */ new Map();
|
|
338
|
+
const resolveSecretValue = async (key) => {
|
|
339
|
+
const entry = graph.entries.get(key);
|
|
340
|
+
if (!entry || entry.namespace !== "secret") {
|
|
341
|
+
return entry?.value;
|
|
342
|
+
}
|
|
343
|
+
if (hydratedSecrets.has(key)) {
|
|
344
|
+
return hydratedSecrets.get(key);
|
|
345
|
+
}
|
|
346
|
+
const ref = projection.secretRefs[key.slice("secret.".length)];
|
|
347
|
+
if (!ref) {
|
|
348
|
+
return void 0;
|
|
349
|
+
}
|
|
350
|
+
const definition = { provider: ref.provider };
|
|
351
|
+
const provider = createSecretVaultProvider(ref.vault ?? "default", definition, process.env);
|
|
352
|
+
const auth = await resolveVaultAuth(ref.vault ?? "default", definition, process.env);
|
|
353
|
+
await provider.authenticate(auth);
|
|
354
|
+
const value = await provider.get(ref.ref);
|
|
355
|
+
hydratedSecrets.set(key, value);
|
|
356
|
+
return value;
|
|
357
|
+
};
|
|
358
|
+
const runtime = {
|
|
359
|
+
manifest,
|
|
360
|
+
plugins: [],
|
|
361
|
+
graph,
|
|
362
|
+
read(key) {
|
|
363
|
+
const entry = graph.entries.get(key);
|
|
364
|
+
if (!entry) {
|
|
365
|
+
return void 0;
|
|
366
|
+
}
|
|
367
|
+
if (entry.namespace === "secret") {
|
|
368
|
+
return hydratedSecrets.get(key);
|
|
369
|
+
}
|
|
370
|
+
return entry.value;
|
|
371
|
+
},
|
|
372
|
+
require(key) {
|
|
373
|
+
const value = this.read(key);
|
|
374
|
+
if (value === void 0) {
|
|
375
|
+
throw new Error(`Missing required CNOS config key: ${key}`);
|
|
376
|
+
}
|
|
377
|
+
return value;
|
|
378
|
+
},
|
|
379
|
+
readOr(key, fallback) {
|
|
380
|
+
return this.read(key) ?? fallback;
|
|
381
|
+
},
|
|
382
|
+
value(segment) {
|
|
383
|
+
return this.read(toLogicalKey("value", segment));
|
|
384
|
+
},
|
|
385
|
+
secret(segment) {
|
|
386
|
+
return this.read(toLogicalKey("secret", segment));
|
|
387
|
+
},
|
|
388
|
+
meta(segment) {
|
|
389
|
+
return this.read(toLogicalKey("meta", segment));
|
|
390
|
+
},
|
|
391
|
+
inspect(key) {
|
|
392
|
+
return inspectValue(
|
|
393
|
+
{
|
|
394
|
+
...graph,
|
|
395
|
+
entries: new Map(
|
|
396
|
+
Array.from(graph.entries.entries()).map(([entryKey, existing]) => [
|
|
397
|
+
entryKey,
|
|
398
|
+
entryKey === key && existing.namespace === "secret" && hydratedSecrets.has(entryKey) ? { ...existing, value: hydratedSecrets.get(entryKey) } : existing
|
|
399
|
+
])
|
|
400
|
+
)
|
|
401
|
+
},
|
|
402
|
+
key
|
|
403
|
+
);
|
|
404
|
+
},
|
|
405
|
+
toObject() {
|
|
406
|
+
return toNamespaceObject(graph);
|
|
407
|
+
},
|
|
408
|
+
toNamespace(namespace) {
|
|
409
|
+
return toNamespaceObject(graph, namespace);
|
|
410
|
+
},
|
|
411
|
+
toEnv(options) {
|
|
412
|
+
return toEnv(graph, manifest, options);
|
|
413
|
+
},
|
|
414
|
+
toPublicEnv(options) {
|
|
415
|
+
return toPublicEnv(graph, manifest, options);
|
|
416
|
+
},
|
|
417
|
+
toServerProjection() {
|
|
418
|
+
return projection;
|
|
419
|
+
},
|
|
420
|
+
async refreshSecrets() {
|
|
421
|
+
for (const key of Object.keys(projection.secretRefs).map((segment) => `secret.${segment}`)) {
|
|
422
|
+
hydratedSecrets.delete(key);
|
|
423
|
+
await resolveSecretValue(key);
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
async refreshSecret(key) {
|
|
427
|
+
hydratedSecrets.delete(key);
|
|
428
|
+
await resolveSecretValue(key);
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
setSingletonRuntime(runtime);
|
|
432
|
+
setBootstrappedSecretHydrationRequired(Object.keys(projection.secretRefs).length > 0);
|
|
433
|
+
}
|
|
434
|
+
function bootstrapFromProcessEnv() {
|
|
435
|
+
if (typeof process === "undefined") {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
try {
|
|
439
|
+
const graph = readRuntimeGraphFromEnv(process.env);
|
|
440
|
+
if (graph) {
|
|
441
|
+
attachBootstrappedGraph(graph);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const projection = readServerProjectionFromEnv(process.env);
|
|
445
|
+
if (projection) {
|
|
446
|
+
attachBootstrappedProjection(projection);
|
|
447
|
+
}
|
|
448
|
+
} catch {
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function discoverProjectionPathSync() {
|
|
452
|
+
const cwd = process.cwd();
|
|
453
|
+
const directCandidates = [
|
|
454
|
+
path.join(cwd, ".cnos-server.json")
|
|
455
|
+
];
|
|
456
|
+
for (const candidate of directCandidates) {
|
|
457
|
+
if (existsSync(candidate)) {
|
|
458
|
+
return candidate;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
let current = cwd;
|
|
462
|
+
for (let depth = 0; depth <= 3; depth += 1) {
|
|
463
|
+
const rcCandidate = path.join(current, ".cnosrc.yml");
|
|
464
|
+
if (existsSync(rcCandidate)) {
|
|
465
|
+
const projectionCandidate = path.join(current, ".cnos-server.json");
|
|
466
|
+
if (existsSync(projectionCandidate)) {
|
|
467
|
+
return projectionCandidate;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const parent = path.dirname(current);
|
|
471
|
+
if (parent === current) {
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
current = parent;
|
|
475
|
+
}
|
|
476
|
+
return void 0;
|
|
477
|
+
}
|
|
478
|
+
function bootstrapFromProjectionFile() {
|
|
479
|
+
if (getSingletonRuntime()) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
try {
|
|
483
|
+
const projectionPath = discoverProjectionPathSync();
|
|
484
|
+
if (!projectionPath) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const projection = deserializeServerProjection(readFileSync(projectionPath, "utf8"));
|
|
488
|
+
attachBootstrappedProjection(projection);
|
|
489
|
+
} catch {
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
bootstrapFromProcessEnv();
|
|
493
|
+
bootstrapFromProjectionFile();
|
|
494
|
+
var cnos = Object.assign(
|
|
495
|
+
((key) => readLogicalKey(getRuntimeOrThrow(), key)),
|
|
496
|
+
{
|
|
497
|
+
read(key) {
|
|
498
|
+
return readLogicalKey(getRuntimeOrThrow(), key);
|
|
499
|
+
},
|
|
500
|
+
require(key) {
|
|
501
|
+
return requireLogicalKey(getRuntimeOrThrow(), key);
|
|
502
|
+
},
|
|
503
|
+
readOr(key, fallback) {
|
|
504
|
+
return getRuntimeOrThrow().readOr(key, fallback);
|
|
505
|
+
},
|
|
506
|
+
value(path2) {
|
|
507
|
+
return getRuntimeOrThrow().value(path2);
|
|
508
|
+
},
|
|
509
|
+
secret(path2) {
|
|
510
|
+
return getRuntimeOrThrow().secret(path2);
|
|
511
|
+
},
|
|
512
|
+
meta(path2) {
|
|
513
|
+
return getRuntimeOrThrow().meta(path2);
|
|
514
|
+
},
|
|
515
|
+
inspect(key) {
|
|
516
|
+
return getRuntimeOrThrow().inspect(key);
|
|
517
|
+
},
|
|
518
|
+
toNamespace(namespace) {
|
|
519
|
+
return getRuntimeOrThrow().toNamespace(namespace);
|
|
520
|
+
},
|
|
521
|
+
toEnv(options) {
|
|
522
|
+
return getRuntimeOrThrow().toEnv(options);
|
|
523
|
+
},
|
|
524
|
+
toPublicEnv(options) {
|
|
525
|
+
return getRuntimeOrThrow().toPublicEnv(options);
|
|
526
|
+
},
|
|
527
|
+
format(message) {
|
|
528
|
+
return formatMessage(getRuntimeOrThrow(), message);
|
|
529
|
+
},
|
|
530
|
+
log(message) {
|
|
531
|
+
const formatted = formatMessage(getRuntimeOrThrow(), message);
|
|
532
|
+
console.log(formatted);
|
|
533
|
+
return formatted;
|
|
534
|
+
},
|
|
535
|
+
async loadProjection(source) {
|
|
536
|
+
const resolvedSource = path.resolve(source);
|
|
537
|
+
const projection = deserializeServerProjection(readFileSync(resolvedSource, "utf8"));
|
|
538
|
+
attachBootstrappedProjection(projection, true);
|
|
539
|
+
setBootstrappedSecretHydrationRequired(Object.keys(projection.secretRefs).length > 0);
|
|
540
|
+
},
|
|
541
|
+
async refreshSecrets() {
|
|
542
|
+
await getRuntimeOrThrow().refreshSecrets();
|
|
543
|
+
setBootstrappedSecretHydrationRequired(false);
|
|
544
|
+
},
|
|
545
|
+
async refreshSecret(key) {
|
|
546
|
+
await getRuntimeOrThrow().refreshSecret(key);
|
|
547
|
+
},
|
|
548
|
+
async ready() {
|
|
549
|
+
const runtime = getSingletonRuntime();
|
|
550
|
+
if (runtime && getBootstrappedSecretHydrationRequired()) {
|
|
551
|
+
await runtime.refreshSecrets();
|
|
552
|
+
setBootstrappedSecretHydrationRequired(false);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (runtime && !getBootstrappedSecretHydrationRequired()) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const existing = getSingletonReady();
|
|
559
|
+
if (existing && !getBootstrappedSecretHydrationRequired()) {
|
|
560
|
+
await existing;
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const readyPromise = createCnos().then((runtime2) => {
|
|
564
|
+
setSingletonRuntime(runtime2);
|
|
565
|
+
setBootstrappedSecretHydrationRequired(false);
|
|
566
|
+
return runtime2;
|
|
567
|
+
});
|
|
568
|
+
setSingletonReady(readyPromise);
|
|
569
|
+
await readyPromise;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
);
|
|
573
|
+
var runtime_default = cnos;
|
|
574
|
+
|
|
575
|
+
export {
|
|
576
|
+
runtime_default
|
|
577
|
+
};
|