@kitsy/cnos 1.2.0 → 1.3.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.
Files changed (64) hide show
  1. package/README.md +3 -3
  2. package/dist/build/index.cjs +902 -113
  3. package/dist/build/index.d.cts +1 -1
  4. package/dist/build/index.d.ts +1 -1
  5. package/dist/build/index.js +22 -10
  6. package/dist/{chunk-WHUGFPE4.js → chunk-CDXJISGB.js} +1 -1
  7. package/dist/{chunk-APCTXRUN.js → chunk-DRKDNY4I.js} +998 -191
  8. package/dist/chunk-E7SE6N26.js +189 -0
  9. package/dist/{chunk-SO5XREEU.js → chunk-EDCLLCNL.js} +32 -11
  10. package/dist/{chunk-SXTMTACL.js → chunk-FC3IV6A7.js} +1 -31
  11. package/dist/{chunk-MLQGYCO7.js → chunk-JDII6O72.js} +1 -1
  12. package/dist/chunk-K6QYI2T4.js +105 -0
  13. package/dist/{chunk-EIN55XXA.js → chunk-OOKFRWTN.js} +1 -1
  14. package/dist/{chunk-ZA74BO47.js → chunk-OWUZQ4OH.js} +1 -1
  15. package/dist/{chunk-RD5WMHPM.js → chunk-QTKXPY3N.js} +1 -1
  16. package/dist/configure/index.cjs +2928 -0
  17. package/dist/configure/index.d.cts +12 -0
  18. package/dist/configure/index.d.ts +12 -0
  19. package/dist/configure/index.js +24 -0
  20. package/dist/{envNaming-BTJpH93W.d.cts → envNaming-D6k66myh.d.cts} +1 -1
  21. package/dist/{envNaming-CcsqAel3.d.ts → envNaming-Dy3WYiGK.d.ts} +1 -1
  22. package/dist/index.cjs +1142 -178
  23. package/dist/index.d.cts +2 -13
  24. package/dist/index.d.ts +2 -13
  25. package/dist/index.js +13 -25
  26. package/dist/internal.cjs +1512 -80
  27. package/dist/internal.d.cts +170 -14
  28. package/dist/internal.d.ts +170 -14
  29. package/dist/internal.js +645 -5
  30. package/dist/plugin/basic-schema.cjs +29 -2
  31. package/dist/plugin/basic-schema.d.cts +1 -1
  32. package/dist/plugin/basic-schema.d.ts +1 -1
  33. package/dist/plugin/basic-schema.js +2 -2
  34. package/dist/plugin/cli-args.cjs +29 -2
  35. package/dist/plugin/cli-args.d.cts +1 -1
  36. package/dist/plugin/cli-args.d.ts +1 -1
  37. package/dist/plugin/cli-args.js +2 -2
  38. package/dist/plugin/dotenv.cjs +36 -9
  39. package/dist/plugin/dotenv.d.cts +2 -2
  40. package/dist/plugin/dotenv.d.ts +2 -2
  41. package/dist/plugin/dotenv.js +2 -2
  42. package/dist/plugin/env-export.cjs +31 -2
  43. package/dist/plugin/env-export.d.cts +2 -2
  44. package/dist/plugin/env-export.d.ts +2 -2
  45. package/dist/plugin/env-export.js +2 -2
  46. package/dist/plugin/filesystem.cjs +46 -91
  47. package/dist/plugin/filesystem.d.cts +1 -1
  48. package/dist/plugin/filesystem.d.ts +1 -1
  49. package/dist/plugin/filesystem.js +2 -2
  50. package/dist/plugin/process-env.cjs +31 -4
  51. package/dist/plugin/process-env.d.cts +2 -2
  52. package/dist/plugin/process-env.d.ts +2 -2
  53. package/dist/plugin/process-env.js +2 -2
  54. package/dist/{plugin-DkOIT5uI.d.cts → plugin-CyNkf7Dm.d.cts} +14 -2
  55. package/dist/{plugin-DkOIT5uI.d.ts → plugin-CyNkf7Dm.d.ts} +14 -2
  56. package/dist/runtime/index.cjs +956 -128
  57. package/dist/runtime/index.d.cts +1 -1
  58. package/dist/runtime/index.d.ts +1 -1
  59. package/dist/runtime/index.js +11 -186
  60. package/dist/{toPublicEnv-DvFeV3qG.d.cts → toPublicEnv-Cz72m6y0.d.cts} +1 -1
  61. package/dist/{toPublicEnv-C9clvXLo.d.ts → toPublicEnv-D2PZkaN-.d.ts} +1 -1
  62. package/package.json +11 -1
  63. package/dist/chunk-JUHPBAEH.js +0 -20
  64. package/dist/chunk-PQ4KSV76.js +0 -50
@@ -0,0 +1,189 @@
1
+ import {
2
+ graphRequiresSecretHydration,
3
+ readRuntimeGraphFromEnv
4
+ } from "./chunk-K6QYI2T4.js";
5
+ import {
6
+ createCnos,
7
+ getBootstrappedSecretHydrationRequired,
8
+ getSingletonReady,
9
+ getSingletonRuntime,
10
+ setBootstrappedSecretHydrationRequired,
11
+ setSingletonReady,
12
+ setSingletonRuntime
13
+ } from "./chunk-EDCLLCNL.js";
14
+ import {
15
+ inspectValue,
16
+ readOrValue,
17
+ readValue,
18
+ requireValue,
19
+ toEnv,
20
+ toLogicalKey,
21
+ toNamespaceObject,
22
+ toPublicEnv
23
+ } from "./chunk-DRKDNY4I.js";
24
+
25
+ // src/runtime/index.ts
26
+ var NOT_READY_MESSAGE = "CNOS not initialized. Call await cnos.ready() or use cnos run.";
27
+ function getRuntimeOrThrow() {
28
+ const runtime = getSingletonRuntime();
29
+ if (!runtime) {
30
+ throw new Error(NOT_READY_MESSAGE);
31
+ }
32
+ return runtime;
33
+ }
34
+ function attachBootstrappedGraph(graph) {
35
+ if (getSingletonRuntime()) {
36
+ return;
37
+ }
38
+ const bootstrappedManifest = {
39
+ version: 1,
40
+ project: {
41
+ name: "bootstrapped"
42
+ },
43
+ workspaces: {
44
+ global: {
45
+ enabled: Boolean(graph.workspace.globalRoot),
46
+ ...graph.workspace.globalRoot ? {
47
+ root: graph.workspace.globalRoot
48
+ } : {},
49
+ allowWrite: false
50
+ },
51
+ items: {},
52
+ ...graph.workspace.workspaceSource === "implicit" ? {} : {
53
+ default: graph.workspace.workspaceId
54
+ }
55
+ },
56
+ profiles: {
57
+ default: graph.profile,
58
+ resolveFrom: ["default"]
59
+ },
60
+ plugins: {
61
+ loaders: [],
62
+ resolver: "profile-aware",
63
+ validators: [],
64
+ exporters: [],
65
+ inspectors: []
66
+ },
67
+ sources: {},
68
+ resolution: {
69
+ precedence: [],
70
+ arrayPolicy: "replace"
71
+ },
72
+ envMapping: {
73
+ explicit: {}
74
+ },
75
+ public: {
76
+ promote: [],
77
+ frameworks: {}
78
+ },
79
+ namespaces: {},
80
+ vaults: {},
81
+ writePolicy: {
82
+ define: {
83
+ defaultProfile: graph.profile,
84
+ targets: {
85
+ value: "./values/app.yml",
86
+ secret: "./secrets/app.yml"
87
+ }
88
+ }
89
+ },
90
+ schema: {}
91
+ };
92
+ const runtime = {
93
+ manifest: bootstrappedManifest,
94
+ plugins: [],
95
+ graph,
96
+ read(key) {
97
+ return readValue(graph, key);
98
+ },
99
+ require(key) {
100
+ return requireValue(graph, key);
101
+ },
102
+ readOr(key, fallback) {
103
+ return readOrValue(graph, key, fallback);
104
+ },
105
+ value(path) {
106
+ return readValue(graph, toLogicalKey("value", path));
107
+ },
108
+ secret(path) {
109
+ return readValue(graph, toLogicalKey("secret", path));
110
+ },
111
+ meta(path) {
112
+ return readValue(graph, toLogicalKey("meta", path));
113
+ },
114
+ inspect(key) {
115
+ return inspectValue(graph, key);
116
+ },
117
+ toObject() {
118
+ return toNamespaceObject(graph);
119
+ },
120
+ toNamespace(namespace) {
121
+ return toNamespaceObject(graph, namespace);
122
+ },
123
+ toEnv(options) {
124
+ return toEnv(graph, bootstrappedManifest, options);
125
+ },
126
+ toPublicEnv(options) {
127
+ return toPublicEnv(graph, bootstrappedManifest, options);
128
+ }
129
+ };
130
+ setSingletonRuntime(runtime);
131
+ setBootstrappedSecretHydrationRequired(graphRequiresSecretHydration(graph));
132
+ }
133
+ function bootstrapFromProcessEnv() {
134
+ if (typeof process === "undefined") {
135
+ return;
136
+ }
137
+ try {
138
+ const graph = readRuntimeGraphFromEnv(process.env);
139
+ if (graph) {
140
+ attachBootstrappedGraph(graph);
141
+ }
142
+ } catch {
143
+ }
144
+ }
145
+ bootstrapFromProcessEnv();
146
+ var cnos = Object.assign(
147
+ ((key) => readValue(getRuntimeOrThrow().graph, key)),
148
+ {
149
+ read(key) {
150
+ return readValue(getRuntimeOrThrow().graph, key);
151
+ },
152
+ require(key) {
153
+ return requireValue(getRuntimeOrThrow().graph, key);
154
+ },
155
+ readOr(key, fallback) {
156
+ return readOrValue(getRuntimeOrThrow().graph, key, fallback);
157
+ },
158
+ value(path) {
159
+ return readValue(getRuntimeOrThrow().graph, toLogicalKey("value", path));
160
+ },
161
+ secret(path) {
162
+ return readValue(getRuntimeOrThrow().graph, toLogicalKey("secret", path));
163
+ },
164
+ meta(path) {
165
+ return readValue(getRuntimeOrThrow().graph, toLogicalKey("meta", path));
166
+ },
167
+ async ready() {
168
+ if (getSingletonRuntime() && !getBootstrappedSecretHydrationRequired()) {
169
+ return;
170
+ }
171
+ const existing = getSingletonReady();
172
+ if (existing && !getBootstrappedSecretHydrationRequired()) {
173
+ await existing;
174
+ return;
175
+ }
176
+ const readyPromise = createCnos().then((runtime) => {
177
+ setSingletonRuntime(runtime);
178
+ return runtime;
179
+ });
180
+ setSingletonReady(readyPromise);
181
+ await readyPromise;
182
+ }
183
+ }
184
+ );
185
+ var runtime_default = cnos;
186
+
187
+ export {
188
+ runtime_default
189
+ };
@@ -1,27 +1,27 @@
1
+ import {
2
+ createEnvExportPlugin,
3
+ createPublicEnvExportPlugin
4
+ } from "./chunk-OOKFRWTN.js";
1
5
  import {
2
6
  createFilesystemSecretsPlugin,
3
7
  createFilesystemValuesPlugin
4
- } from "./chunk-SXTMTACL.js";
8
+ } from "./chunk-FC3IV6A7.js";
5
9
  import {
6
10
  createProcessEnvPlugin
7
- } from "./chunk-WHUGFPE4.js";
11
+ } from "./chunk-CDXJISGB.js";
8
12
  import {
9
13
  createBasicSchemaPlugin
10
- } from "./chunk-MLQGYCO7.js";
14
+ } from "./chunk-JDII6O72.js";
11
15
  import {
12
16
  createCliArgsPlugin
13
- } from "./chunk-ZA74BO47.js";
17
+ } from "./chunk-OWUZQ4OH.js";
14
18
  import {
15
19
  createDotenvPlugin
16
- } from "./chunk-RD5WMHPM.js";
17
- import {
18
- createEnvExportPlugin,
19
- createPublicEnvExportPlugin
20
- } from "./chunk-EIN55XXA.js";
20
+ } from "./chunk-QTKXPY3N.js";
21
21
  import {
22
22
  createCnos,
23
23
  createProvenanceInspector
24
- } from "./chunk-APCTXRUN.js";
24
+ } from "./chunk-DRKDNY4I.js";
25
25
 
26
26
  // src/defaultPlugins.ts
27
27
  function defaultPlugins() {
@@ -41,12 +41,14 @@ function defaultPlugins() {
41
41
  // src/runtime/state.ts
42
42
  var singletonRuntime;
43
43
  var singletonReady;
44
+ var bootstrappedSecretHydrationRequired = false;
44
45
  function getSingletonRuntime() {
45
46
  return singletonRuntime;
46
47
  }
47
48
  function setSingletonRuntime(runtime) {
48
49
  singletonRuntime = runtime;
49
50
  singletonReady = Promise.resolve(runtime);
51
+ bootstrappedSecretHydrationRequired = false;
50
52
  return runtime;
51
53
  }
52
54
  function getSingletonReady() {
@@ -56,11 +58,17 @@ function setSingletonReady(promise) {
56
58
  singletonReady = promise;
57
59
  return promise;
58
60
  }
61
+ function getBootstrappedSecretHydrationRequired() {
62
+ return bootstrappedSecretHydrationRequired;
63
+ }
64
+ function setBootstrappedSecretHydrationRequired(value) {
65
+ bootstrappedSecretHydrationRequired = value;
66
+ }
59
67
 
60
68
  // package.json
61
69
  var package_default = {
62
70
  name: "@kitsy/cnos",
63
- version: "1.2.0",
71
+ version: "1.3.0",
64
72
  description: "Batteries-included CNOS runtime package wired with the official plugins.",
65
73
  type: "module",
66
74
  main: "./dist/index.cjs",
@@ -72,6 +80,16 @@ var package_default = {
72
80
  import: "./dist/index.js",
73
81
  require: "./dist/index.cjs"
74
82
  },
83
+ "./configure": {
84
+ types: "./dist/configure/index.d.ts",
85
+ import: "./dist/configure/index.js",
86
+ require: "./dist/configure/index.cjs"
87
+ },
88
+ "./create": {
89
+ types: "./dist/configure/index.d.ts",
90
+ import: "./dist/configure/index.js",
91
+ require: "./dist/configure/index.cjs"
92
+ },
75
93
  "./internal": {
76
94
  types: "./dist/internal.d.ts",
77
95
  import: "./dist/internal.js",
@@ -162,6 +180,7 @@ var package_default = {
162
180
  async function createCnos2(options = {}) {
163
181
  const runtime = await createCnos({
164
182
  ...options,
183
+ processEnv: options.processEnv ?? process.env,
165
184
  cnosVersion: package_default.version,
166
185
  plugins: [...defaultPlugins(), ...options.plugins ?? []]
167
186
  });
@@ -175,5 +194,7 @@ export {
175
194
  setSingletonRuntime,
176
195
  getSingletonReady,
177
196
  setSingletonReady,
197
+ getBootstrappedSecretHydrationRequired,
198
+ setBootstrappedSecretHydrationRequired,
178
199
  createCnos2 as createCnos
179
200
  };
@@ -2,11 +2,8 @@ import {
2
2
  CnosManifestError,
3
3
  isSecretReference,
4
4
  parseYaml,
5
- readLocalSecret,
6
- resolveSecretPassphrase,
7
- resolveSecretStoreRoot,
8
5
  toPortablePath
9
- } from "./chunk-APCTXRUN.js";
6
+ } from "./chunk-DRKDNY4I.js";
10
7
 
11
8
  // ../../plugins/filesystem/src/helpers.ts
12
9
  import { readdir } from "fs/promises";
@@ -98,31 +95,6 @@ function yamlObjectToEntries(document, filePath, namespace, sourceId, workspaceI
98
95
  }
99
96
  }));
100
97
  }
101
- async function resolveSecretValue(value, processEnv) {
102
- if (!isSecretReference(value)) {
103
- return value;
104
- }
105
- if (value.provider === "local") {
106
- const passphrase = resolveSecretPassphrase(value.vault, processEnv);
107
- if (!passphrase) {
108
- return value;
109
- }
110
- return readLocalSecret(
111
- resolveSecretStoreRoot(processEnv),
112
- value.ref,
113
- passphrase,
114
- value.vault
115
- );
116
- }
117
- if (value.provider === "env" || value.provider === "github-secrets") {
118
- const resolved = processEnv?.[value.ref];
119
- if (resolved === void 0) {
120
- return value;
121
- }
122
- return resolved;
123
- }
124
- return value;
125
- }
126
98
  function toSecretReferenceMetadata(value) {
127
99
  if (!isSecretReference(value)) {
128
100
  return void 0;
@@ -155,10 +127,8 @@ function createFilesystemSecretsPlugin() {
155
127
  const fileEntries = filesystemSecretsReader(file.relativePath, document, file.workspaceId);
156
128
  for (const entry of fileEntries) {
157
129
  const metadata = toSecretReferenceMetadata(entry.value);
158
- const resolvedValue = await resolveSecretValue(entry.value, context.processEnv);
159
130
  entries.push({
160
131
  ...entry,
161
- value: resolvedValue,
162
132
  ...metadata ? { metadata } : {}
163
133
  });
164
134
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  applySchemaRules
3
- } from "./chunk-APCTXRUN.js";
3
+ } from "./chunk-DRKDNY4I.js";
4
4
 
5
5
  // ../../plugins/basic-schema/src/index.ts
6
6
  function createBasicSchemaPlugin() {
@@ -0,0 +1,105 @@
1
+ import {
2
+ isSecretReference
3
+ } from "./chunk-DRKDNY4I.js";
4
+
5
+ // src/runtime/bootstrap.ts
6
+ import { createCipheriv, createDecipheriv, randomBytes } from "crypto";
7
+ var CNOS_GRAPH_ENV_VAR = "__CNOS_GRAPH__";
8
+ var CNOS_SECRET_PAYLOAD_ENV_VAR = "__CNOS_SECRET_PAYLOAD__";
9
+ var CNOS_SESSION_KEY_ENV_VAR = "__CNOS_SESSION_KEY__";
10
+ function serializeRuntimeGraph(graph) {
11
+ const payload = {
12
+ entries: Array.from(graph.entries.values()),
13
+ profile: graph.profile,
14
+ resolvedAt: graph.resolvedAt,
15
+ profileSource: graph.profileSource,
16
+ workspace: graph.workspace
17
+ };
18
+ return JSON.stringify(payload);
19
+ }
20
+ function deserializeRuntimeGraph(source) {
21
+ const payload = JSON.parse(source);
22
+ if (!payload || !Array.isArray(payload.entries) || typeof payload.profile !== "string" || typeof payload.resolvedAt !== "string" || !payload.profileSource || !payload.workspace || typeof payload.workspace.workspaceId !== "string" || !Array.isArray(payload.workspace.workspaceChain) || !Array.isArray(payload.workspace.workspaceRoots)) {
23
+ throw new Error("Invalid CNOS runtime bootstrap payload");
24
+ }
25
+ return {
26
+ entries: new Map(
27
+ payload.entries.map((entry) => [
28
+ entry.key,
29
+ {
30
+ key: entry.key,
31
+ value: entry.value,
32
+ namespace: entry.namespace,
33
+ winner: entry.winner,
34
+ overridden: entry.overridden ?? []
35
+ }
36
+ ])
37
+ ),
38
+ profile: payload.profile,
39
+ resolvedAt: payload.resolvedAt,
40
+ profileSource: payload.profileSource,
41
+ workspace: payload.workspace
42
+ };
43
+ }
44
+ function decryptSecretPayload(serialized, sessionKey) {
45
+ const payload = JSON.parse(serialized);
46
+ if (!payload || typeof payload.iv !== "string" || typeof payload.tag !== "string" || typeof payload.ciphertext !== "string") {
47
+ throw new Error("Invalid CNOS secret payload");
48
+ }
49
+ const key = Buffer.from(sessionKey, "hex");
50
+ const iv = Buffer.from(payload.iv, "base64");
51
+ const tag = Buffer.from(payload.tag, "base64");
52
+ const ciphertext = Buffer.from(payload.ciphertext, "base64");
53
+ const decipher = createDecipheriv("aes-256-gcm", key, iv);
54
+ decipher.setAuthTag(tag);
55
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
56
+ return JSON.parse(plaintext);
57
+ }
58
+ function serializeSecretPayload(values) {
59
+ const key = randomBytes(32);
60
+ const iv = randomBytes(12);
61
+ const cipher = createCipheriv("aes-256-gcm", key, iv);
62
+ const ciphertext = Buffer.concat([cipher.update(JSON.stringify(values), "utf8"), cipher.final()]);
63
+ const tag = cipher.getAuthTag();
64
+ return {
65
+ payload: JSON.stringify({
66
+ iv: iv.toString("base64"),
67
+ tag: tag.toString("base64"),
68
+ ciphertext: ciphertext.toString("base64")
69
+ }),
70
+ sessionKey: key.toString("hex")
71
+ };
72
+ }
73
+ function readRuntimeGraphFromEnv(processEnv = process.env) {
74
+ const serialized = processEnv[CNOS_GRAPH_ENV_VAR];
75
+ if (!serialized) {
76
+ return void 0;
77
+ }
78
+ const graph = deserializeRuntimeGraph(serialized);
79
+ const secretPayload = processEnv[CNOS_SECRET_PAYLOAD_ENV_VAR];
80
+ const sessionKey = processEnv[CNOS_SESSION_KEY_ENV_VAR];
81
+ if (secretPayload && sessionKey) {
82
+ const decrypted = decryptSecretPayload(secretPayload, sessionKey);
83
+ for (const [key, value] of Object.entries(decrypted)) {
84
+ const entry = graph.entries.get(key);
85
+ if (entry) {
86
+ entry.value = value;
87
+ }
88
+ }
89
+ }
90
+ return graph;
91
+ }
92
+ function graphRequiresSecretHydration(graph) {
93
+ return Array.from(graph.entries.values()).some((entry) => entry.namespace === "secret" && isSecretReference(entry.value));
94
+ }
95
+
96
+ export {
97
+ CNOS_GRAPH_ENV_VAR,
98
+ CNOS_SECRET_PAYLOAD_ENV_VAR,
99
+ CNOS_SESSION_KEY_ENV_VAR,
100
+ serializeRuntimeGraph,
101
+ deserializeRuntimeGraph,
102
+ serializeSecretPayload,
103
+ readRuntimeGraphFromEnv,
104
+ graphRequiresSecretHydration
105
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  toEnv,
3
3
  toPublicEnv
4
- } from "./chunk-APCTXRUN.js";
4
+ } from "./chunk-DRKDNY4I.js";
5
5
 
6
6
  // ../../plugins/env-export/src/index.ts
7
7
  function createEnvExportPlugin() {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  joinConfigPath
3
- } from "./chunk-APCTXRUN.js";
3
+ } from "./chunk-DRKDNY4I.js";
4
4
 
5
5
  // ../../plugins/cli-args/src/index.ts
6
6
  var CLI_ARGS_PLUGIN_ID = "@kitsy/cnos/plugins/cli-args";
@@ -2,7 +2,7 @@ import {
2
2
  envVarToLogicalKey,
3
3
  resolveWorkspaceScopedPath,
4
4
  toPortablePath
5
- } from "./chunk-APCTXRUN.js";
5
+ } from "./chunk-DRKDNY4I.js";
6
6
 
7
7
  // ../../plugins/dotenv/src/index.ts
8
8
  import { readFile } from "fs/promises";