@kitsy/cnos 0.0.1 → 1.0.1

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 (47) hide show
  1. package/README.md +3 -1
  2. package/dist/chunk-44JOQPSN.js +109 -0
  3. package/dist/chunk-ASZ7I3JJ.js +35 -0
  4. package/dist/chunk-CGTFH4QQ.js +49 -0
  5. package/dist/chunk-GGYIRIGU.js +83 -0
  6. package/dist/chunk-H65FPTDM.js +23 -0
  7. package/dist/chunk-K2T4R5WH.js +1565 -0
  8. package/dist/chunk-KG6OZX5C.js +202 -0
  9. package/dist/envNaming-BrOk5ndZ.d.cts +8 -0
  10. package/dist/envNaming-DCaNdnrF.d.ts +8 -0
  11. package/dist/index.cjs +1942 -28
  12. package/dist/index.d.cts +7 -3
  13. package/dist/index.d.ts +7 -3
  14. package/dist/index.js +112 -23
  15. package/dist/internal.cjs +288 -0
  16. package/dist/internal.d.cts +20 -0
  17. package/dist/internal.d.ts +20 -0
  18. package/dist/internal.js +18 -0
  19. package/dist/plugin/basic-schema.cjs +214 -3
  20. package/dist/plugin/basic-schema.d.cts +5 -6
  21. package/dist/plugin/basic-schema.d.ts +5 -6
  22. package/dist/plugin/basic-schema.js +7 -2
  23. package/dist/plugin/cli-args.cjs +132 -3
  24. package/dist/plugin/cli-args.d.cts +12 -1
  25. package/dist/plugin/cli-args.d.ts +12 -1
  26. package/dist/plugin/cli-args.js +11 -2
  27. package/dist/plugin/dotenv.cjs +212 -3
  28. package/dist/plugin/dotenv.d.cts +8 -1
  29. package/dist/plugin/dotenv.d.ts +8 -1
  30. package/dist/plugin/dotenv.js +11 -2
  31. package/dist/plugin/env-export.cjs +222 -3
  32. package/dist/plugin/env-export.d.cts +7 -1
  33. package/dist/plugin/env-export.d.ts +7 -1
  34. package/dist/plugin/env-export.js +14 -2
  35. package/dist/plugin/filesystem.cjs +320 -3
  36. package/dist/plugin/filesystem.d.cts +17 -1
  37. package/dist/plugin/filesystem.d.ts +17 -1
  38. package/dist/plugin/filesystem.js +17 -2
  39. package/dist/plugin/process-env.cjs +126 -3
  40. package/dist/plugin/process-env.d.cts +7 -1
  41. package/dist/plugin/process-env.d.ts +7 -1
  42. package/dist/plugin/process-env.js +9 -2
  43. package/dist/plugin-BVNEHj19.d.cts +309 -0
  44. package/dist/plugin-BVNEHj19.d.ts +309 -0
  45. package/dist/toPublicEnv-Dd152fFy.d.cts +7 -0
  46. package/dist/toPublicEnv-Gwz3xTK0.d.ts +7 -0
  47. package/package.json +15 -16
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
1
  # @kitsy/cnos
2
2
 
3
- Developer-friendly CNOS runtime assembly. It prewires the official v1 plugins on top of `@kitsy/cnos-core` and exposes the main `createCnos(...)` entry point for app code.
3
+ Developer-friendly CNOS runtime assembly. It bundles the core engine plus the official built-in plugins, exposes the main `createCnos(...)` entry point for app code, and re-exports the built-ins under `@kitsy/cnos/plugins/*`.
4
+
5
+ Use `@kitsy/cnos-vite` for Vite projects and `@kitsy/cnos-next` for Next.js projects when you want CNOS public values projected into framework-native env surfaces.
@@ -0,0 +1,109 @@
1
+ import {
2
+ envVarToLogicalKey,
3
+ resolveWorkspaceScopedPath,
4
+ toPortablePath
5
+ } from "./chunk-K2T4R5WH.js";
6
+
7
+ // ../../plugins/dotenv/src/index.ts
8
+ import { readFile } from "fs/promises";
9
+ import path from "path";
10
+ var DOTENV_PLUGIN_ID = "@kitsy/cnos/plugins/dotenv";
11
+ function parseDoubleQuoted(value) {
12
+ return value.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, " ").replace(/\\"/g, '"').replace(/\\\\/g, "\\");
13
+ }
14
+ function parseDotenv(document) {
15
+ const parsed = {};
16
+ for (const rawLine of document.split(/\r?\n/)) {
17
+ const line = rawLine.trim();
18
+ if (!line || line.startsWith("#")) {
19
+ continue;
20
+ }
21
+ const withoutExport = line.startsWith("export ") ? line.slice("export ".length).trim() : line;
22
+ const separatorIndex = withoutExport.indexOf("=");
23
+ if (separatorIndex <= 0) {
24
+ continue;
25
+ }
26
+ const envVar = withoutExport.slice(0, separatorIndex).trim();
27
+ let value = withoutExport.slice(separatorIndex + 1).trim();
28
+ if (!envVar) {
29
+ continue;
30
+ }
31
+ if (value.startsWith('"') && value.endsWith('"')) {
32
+ value = parseDoubleQuoted(value.slice(1, -1));
33
+ } else if (value.startsWith("'") && value.endsWith("'")) {
34
+ value = value.slice(1, -1);
35
+ } else {
36
+ value = value.replace(/\s+#.*$/, "").trim();
37
+ }
38
+ parsed[envVar] = value;
39
+ }
40
+ return parsed;
41
+ }
42
+ function dotenvEntriesFromObject(values, mapping = {}, originFile, workspaceId = "default") {
43
+ return Object.entries(values).flatMap(([envVar, value]) => {
44
+ const logicalKey = envVarToLogicalKey(envVar, mapping);
45
+ if (!logicalKey) {
46
+ return [];
47
+ }
48
+ return [
49
+ {
50
+ key: logicalKey,
51
+ value,
52
+ namespace: logicalKey.startsWith("secret.") ? "secret" : "value",
53
+ sourceId: "dotenv",
54
+ pluginId: DOTENV_PLUGIN_ID,
55
+ workspaceId,
56
+ origin: {
57
+ envVar,
58
+ ...originFile ? { file: originFile } : {}
59
+ }
60
+ }
61
+ ];
62
+ });
63
+ }
64
+ async function readIfPresent(filePath) {
65
+ try {
66
+ return await readFile(filePath, "utf8");
67
+ } catch {
68
+ return void 0;
69
+ }
70
+ }
71
+ function createDotenvPlugin() {
72
+ return {
73
+ id: "dotenv",
74
+ kind: "loader",
75
+ async load(context) {
76
+ const config = context.manifestConfig;
77
+ const rootTemplate = config.root ?? "./env";
78
+ const fileNames = context.profileActivation.envFiles;
79
+ const entries = [];
80
+ for (const workspaceRoot of context.workspace.workspaceRoots) {
81
+ const envRoot = resolveWorkspaceScopedPath(workspaceRoot.path, rootTemplate, {
82
+ workspace: workspaceRoot.workspaceId
83
+ });
84
+ for (const fileName of fileNames) {
85
+ const absolutePath = path.join(envRoot, fileName);
86
+ const document = await readIfPresent(absolutePath);
87
+ if (!document) {
88
+ continue;
89
+ }
90
+ entries.push(
91
+ ...dotenvEntriesFromObject(
92
+ parseDotenv(document),
93
+ config.envMapping,
94
+ toPortablePath(path.relative(path.dirname(context.manifestRoot), absolutePath)),
95
+ workspaceRoot.workspaceId
96
+ )
97
+ );
98
+ }
99
+ }
100
+ return entries;
101
+ }
102
+ };
103
+ }
104
+
105
+ export {
106
+ parseDotenv,
107
+ dotenvEntriesFromObject,
108
+ createDotenvPlugin
109
+ };
@@ -0,0 +1,35 @@
1
+ import {
2
+ toEnv,
3
+ toPublicEnv
4
+ } from "./chunk-K2T4R5WH.js";
5
+
6
+ // ../../plugins/env-export/src/index.ts
7
+ function createEnvExportPlugin() {
8
+ return {
9
+ id: "@kitsy/cnos/plugins/env-export",
10
+ kind: "exporter",
11
+ async export(graph, context) {
12
+ return {
13
+ pluginId: "@kitsy/cnos/plugins/env-export",
14
+ value: toEnv(graph, context.manifest)
15
+ };
16
+ }
17
+ };
18
+ }
19
+ function createPublicEnvExportPlugin() {
20
+ return {
21
+ id: "@kitsy/cnos/plugins/public-env-export",
22
+ kind: "exporter",
23
+ async export(graph, context) {
24
+ return {
25
+ pluginId: "@kitsy/cnos/plugins/public-env-export",
26
+ value: toPublicEnv(graph, context.manifest)
27
+ };
28
+ }
29
+ };
30
+ }
31
+
32
+ export {
33
+ createEnvExportPlugin,
34
+ createPublicEnvExportPlugin
35
+ };
@@ -0,0 +1,49 @@
1
+ import {
2
+ envVarToLogicalKey
3
+ } from "./chunk-K2T4R5WH.js";
4
+
5
+ // ../../plugins/process-env/src/index.ts
6
+ var PROCESS_ENV_PLUGIN_ID = "@kitsy/cnos/plugins/process-env";
7
+ function processEnvEntriesFromObject(env, mapping = {}, workspaceId = "default") {
8
+ return Object.entries(env).flatMap(([envVar, value]) => {
9
+ if (typeof value !== "string") {
10
+ return [];
11
+ }
12
+ const logicalKey = envVarToLogicalKey(envVar, mapping);
13
+ if (!logicalKey) {
14
+ return [];
15
+ }
16
+ return [
17
+ {
18
+ key: logicalKey,
19
+ value,
20
+ namespace: logicalKey.startsWith("secret.") ? "secret" : "value",
21
+ sourceId: "process-env",
22
+ pluginId: PROCESS_ENV_PLUGIN_ID,
23
+ workspaceId,
24
+ origin: {
25
+ envVar
26
+ }
27
+ }
28
+ ];
29
+ });
30
+ }
31
+ function createProcessEnvPlugin() {
32
+ return {
33
+ id: "process-env",
34
+ kind: "loader",
35
+ async load(context) {
36
+ const config = context.manifestConfig;
37
+ return processEnvEntriesFromObject(
38
+ context.processEnv ?? process.env,
39
+ config.envMapping,
40
+ context.workspace.workspaceId
41
+ );
42
+ }
43
+ };
44
+ }
45
+
46
+ export {
47
+ processEnvEntriesFromObject,
48
+ createProcessEnvPlugin
49
+ };
@@ -0,0 +1,83 @@
1
+ import {
2
+ joinConfigPath
3
+ } from "./chunk-K2T4R5WH.js";
4
+
5
+ // ../../plugins/cli-args/src/index.ts
6
+ var CLI_ARGS_PLUGIN_ID = "@kitsy/cnos/plugins/cli-args";
7
+ function isNamespaceName(value) {
8
+ return value === "value" || value === "secret";
9
+ }
10
+ function parseCliArgs(args) {
11
+ const parsed = [];
12
+ for (let index = 0; index < args.length; index += 1) {
13
+ const arg = args[index];
14
+ if (!arg?.startsWith("--")) {
15
+ continue;
16
+ }
17
+ if (arg === "--profile") {
18
+ index += 1;
19
+ continue;
20
+ }
21
+ if (arg.startsWith("--profile=")) {
22
+ continue;
23
+ }
24
+ const body = arg.slice(2);
25
+ const separatorIndex = body.indexOf("=");
26
+ if (separatorIndex >= 0) {
27
+ parsed.push({
28
+ key: body.slice(0, separatorIndex),
29
+ value: body.slice(separatorIndex + 1),
30
+ raw: arg
31
+ });
32
+ continue;
33
+ }
34
+ const nextValue = args[index + 1];
35
+ if (nextValue && !nextValue.startsWith("--")) {
36
+ parsed.push({
37
+ key: body,
38
+ value: nextValue,
39
+ raw: `${arg} ${nextValue}`
40
+ });
41
+ index += 1;
42
+ }
43
+ }
44
+ return parsed;
45
+ }
46
+ function cliArgEntriesFromArgs(args, workspaceId = "default") {
47
+ return parseCliArgs(args).flatMap(({ key, value, raw }) => {
48
+ const [candidateNamespace = "", ...pathSegments] = key.split(".");
49
+ if (!isNamespaceName(candidateNamespace) || pathSegments.length === 0) {
50
+ return [];
51
+ }
52
+ const namespace = candidateNamespace;
53
+ const logicalKey = `${namespace}.${joinConfigPath(pathSegments.join("."))}`;
54
+ return [
55
+ {
56
+ key: logicalKey,
57
+ value,
58
+ namespace,
59
+ sourceId: "cli-args",
60
+ pluginId: CLI_ARGS_PLUGIN_ID,
61
+ workspaceId,
62
+ origin: {
63
+ cliArg: raw
64
+ }
65
+ }
66
+ ];
67
+ });
68
+ }
69
+ function createCliArgsPlugin() {
70
+ return {
71
+ id: "cli-args",
72
+ kind: "loader",
73
+ async load(context) {
74
+ return cliArgEntriesFromArgs(context.cliArgs ?? [], context.workspace.workspaceId);
75
+ }
76
+ };
77
+ }
78
+
79
+ export {
80
+ parseCliArgs,
81
+ cliArgEntriesFromArgs,
82
+ createCliArgsPlugin
83
+ };
@@ -0,0 +1,23 @@
1
+ import {
2
+ applySchemaRules
3
+ } from "./chunk-K2T4R5WH.js";
4
+
5
+ // ../../plugins/basic-schema/src/index.ts
6
+ function createBasicSchemaPlugin() {
7
+ return {
8
+ id: "@kitsy/cnos/plugins/basic-schema",
9
+ kind: "validator",
10
+ async validate(graph, context) {
11
+ const result = applySchemaRules(graph, context.schema ?? {});
12
+ return {
13
+ pluginId: "@kitsy/cnos/plugins/basic-schema",
14
+ valid: result.issues.length === 0,
15
+ issues: result.issues
16
+ };
17
+ }
18
+ };
19
+ }
20
+
21
+ export {
22
+ createBasicSchemaPlugin
23
+ };