@dxos/config 0.10.0 → 0.11.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/lib/chunk-config.mjs +123 -0
- package/dist/lib/chunk-config.mjs.map +1 -0
- package/dist/lib/chunk-definitions.mjs +97 -0
- package/dist/lib/chunk-definitions.mjs.map +1 -0
- package/dist/lib/chunk-types.mjs +8 -0
- package/dist/lib/chunk-types.mjs.map +1 -0
- package/dist/lib/index.mjs +171 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/loaders/browser.mjs +82 -0
- package/dist/lib/loaders/browser.mjs.map +1 -0
- package/dist/lib/loaders.mjs +66 -0
- package/dist/lib/loaders.mjs.map +1 -0
- package/dist/lib/plugin/browser.mjs +8 -0
- package/dist/lib/plugin/browser.mjs.map +1 -0
- package/dist/lib/plugin/esbuild-plugin.mjs +22 -0
- package/dist/lib/plugin/esbuild-plugin.mjs.map +1 -0
- package/dist/lib/plugin/rollup-plugin.mjs +15 -0
- package/dist/lib/plugin/rollup-plugin.mjs.map +1 -0
- package/dist/lib/plugin/vite-plugin.mjs +24 -0
- package/dist/lib/plugin/vite-plugin.mjs.map +1 -0
- package/dist/lib/plugin.mjs +2 -0
- package/dist/lib/savers/browser.mjs +33 -0
- package/dist/lib/savers/browser.mjs.map +1 -0
- package/dist/lib/savers.mjs +6 -0
- package/dist/lib/savers.mjs.map +1 -0
- package/dist/{lib/node-esm/plugin/index.mjs → plugin/node-esm/chunk-PAYIP2UD.mjs} +49 -9
- package/dist/plugin/node-esm/chunk-PAYIP2UD.mjs.map +7 -0
- package/dist/plugin/node-esm/esbuild-plugin.mjs +1 -1
- package/dist/plugin/node-esm/meta.json +1 -1
- package/dist/plugin/node-esm/rollup-plugin.mjs +1 -1
- package/dist/plugin/node-esm/vite-plugin.mjs +1 -1
- package/dist/types/src/config.d.ts +0 -1
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -28
- package/src/config-service.ts +3 -3
- package/src/config.ts +0 -4
- package/src/edge-services.ts +1 -1
- package/src/preset.ts +1 -1
- package/dist/lib/browser/chunk-VQRJY4AQ.mjs +0 -11
- package/dist/lib/browser/chunk-VQRJY4AQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZY4D4E3Q.mjs +0 -146
- package/dist/lib/browser/chunk-ZY4D4E3Q.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -197
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/loaders/browser.mjs +0 -73
- package/dist/lib/browser/loaders/browser.mjs.map +0 -7
- package/dist/lib/browser/loaders/index.mjs +0 -66
- package/dist/lib/browser/loaders/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/plugin/browser.mjs +0 -8
- package/dist/lib/browser/plugin/browser.mjs.map +0 -7
- package/dist/lib/browser/plugin/index.mjs +0 -98
- package/dist/lib/browser/plugin/index.mjs.map +0 -7
- package/dist/lib/browser/savers/browser.mjs +0 -25
- package/dist/lib/browser/savers/browser.mjs.map +0 -7
- package/dist/lib/browser/savers/index.mjs +0 -7
- package/dist/lib/browser/savers/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-T6NFH3CC.mjs +0 -13
- package/dist/lib/node-esm/chunk-T6NFH3CC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WIJROCKQ.mjs +0 -148
- package/dist/lib/node-esm/chunk-WIJROCKQ.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -198
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/loaders/browser.mjs +0 -75
- package/dist/lib/node-esm/loaders/browser.mjs.map +0 -7
- package/dist/lib/node-esm/loaders/index.mjs +0 -67
- package/dist/lib/node-esm/loaders/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/plugin/browser.mjs +0 -10
- package/dist/lib/node-esm/plugin/browser.mjs.map +0 -7
- package/dist/lib/node-esm/plugin/index.mjs.map +0 -7
- package/dist/lib/node-esm/savers/browser.mjs +0 -27
- package/dist/lib/node-esm/savers/browser.mjs.map +0 -7
- package/dist/lib/node-esm/savers/index.mjs +0 -9
- package/dist/lib/node-esm/savers/index.mjs.map +0 -7
- package/dist/plugin/node-esm/chunk-XCZNYAQT.mjs +0 -221
- package/dist/plugin/node-esm/chunk-XCZNYAQT.mjs.map +0 -7
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { getDeep, setDeep } from "@dxos/util";
|
|
2
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
3
|
+
import isMatch from "lodash.ismatch";
|
|
4
|
+
import { InvalidConfigError } from "@dxos/protocols";
|
|
5
|
+
import { schema } from "@dxos/protocols/proto";
|
|
6
|
+
//#region src/config.ts
|
|
7
|
+
var configRootType = schema.getCodecForType("dxos.config.Config");
|
|
8
|
+
/**
|
|
9
|
+
* Maps the given objects onto a flattened set of (key x values).
|
|
10
|
+
* Expects parsed yaml content of the form:
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* ENV_VAR:
|
|
14
|
+
* path: config.selector.path
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param {object} spec
|
|
18
|
+
* @param {object} values
|
|
19
|
+
* @return {object}
|
|
20
|
+
*/
|
|
21
|
+
var mapFromKeyValues = (spec, values) => {
|
|
22
|
+
const config = {};
|
|
23
|
+
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
24
|
+
let value = values[key];
|
|
25
|
+
if (value !== void 0) {
|
|
26
|
+
if (type) switch (type) {
|
|
27
|
+
case "boolean":
|
|
28
|
+
value = String(value).toLowerCase() === "true" || value === "1";
|
|
29
|
+
break;
|
|
30
|
+
case "number":
|
|
31
|
+
value = Number(value);
|
|
32
|
+
break;
|
|
33
|
+
case "string": break;
|
|
34
|
+
case "json":
|
|
35
|
+
value = value ? JSON.parse(value) : null;
|
|
36
|
+
break;
|
|
37
|
+
default: throw new Error(`Invalid type: ${type}`);
|
|
38
|
+
}
|
|
39
|
+
setDeep(config, path.split("."), value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return config;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Maps the given flattend set of (key x values) onto a JSON object.
|
|
46
|
+
* @param {object} spec
|
|
47
|
+
* @param {object} values
|
|
48
|
+
*/
|
|
49
|
+
var mapToKeyValues = (spec, values) => {
|
|
50
|
+
const config = {};
|
|
51
|
+
for (const [key, { path, type }] of Object.entries(spec)) {
|
|
52
|
+
const value = getDeep(values, path.split("."));
|
|
53
|
+
if (value !== void 0) switch (type) {
|
|
54
|
+
case "json":
|
|
55
|
+
config[key] = JSON.stringify(value);
|
|
56
|
+
break;
|
|
57
|
+
default: config[key] = value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return config;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Validate config object.
|
|
64
|
+
*/
|
|
65
|
+
var validateConfig = (config) => {
|
|
66
|
+
if (!("version" in config)) throw new InvalidConfigError({ message: "Version not specified" });
|
|
67
|
+
if (config?.version !== 1) throw new InvalidConfigError({ message: `Invalid config version: ${config.version}` });
|
|
68
|
+
const error = configRootType.protoType.verify(config);
|
|
69
|
+
if (error) throw new InvalidConfigError({ message: String(error) });
|
|
70
|
+
return config;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Global configuration object.
|
|
74
|
+
* NOTE: Config objects are immutable.
|
|
75
|
+
*/
|
|
76
|
+
var Config = class {
|
|
77
|
+
_config;
|
|
78
|
+
/**
|
|
79
|
+
* Creates an immutable instance.
|
|
80
|
+
* @constructor
|
|
81
|
+
*/
|
|
82
|
+
constructor(config = {}, ...objects) {
|
|
83
|
+
this._config = validateConfig(defaultsDeep(config, ...objects, { version: 1 }));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Returns an immutable config JSON object.
|
|
87
|
+
*/
|
|
88
|
+
get values() {
|
|
89
|
+
return this._config;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the given config property.
|
|
93
|
+
*
|
|
94
|
+
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
95
|
+
* @param defaultValue Default value to return if option is not present in the config.
|
|
96
|
+
* @returns The config value or undefined if the option is not present.
|
|
97
|
+
*/
|
|
98
|
+
get(key, defaultValue) {
|
|
99
|
+
return getDeep(this._config, key.split(".")) ?? defaultValue;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get unique key.
|
|
103
|
+
*/
|
|
104
|
+
find(path, test) {
|
|
105
|
+
const values = getDeep(this._config, path.split("."));
|
|
106
|
+
if (!Array.isArray(values)) return;
|
|
107
|
+
return values.find((value) => isMatch(value, test));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns the given config property or throw if it doesn't exist.
|
|
111
|
+
*
|
|
112
|
+
* @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.
|
|
113
|
+
*/
|
|
114
|
+
getOrThrow(key) {
|
|
115
|
+
const value = getDeep(this._config, key.split("."));
|
|
116
|
+
if (!value) throw new Error(`Config option not present: ${key}`);
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
export { validateConfig as i, mapFromKeyValues as n, mapToKeyValues as r, Config as t };
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=chunk-config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-config.mjs","names":[],"sources":["../../src/config.ts"],"sourcesContent":["//\n// Copyright 2021 DXOS.org\n//\n\nimport defaultsDeep from 'lodash.defaultsdeep';\nimport isMatch from 'lodash.ismatch';\n\nimport { InvalidConfigError } from '@dxos/protocols';\nimport { schema } from '@dxos/protocols/proto';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\nimport { getDeep, setDeep } from '@dxos/util';\n\nimport { type ConfigKey, type DeepIndex, type ParseKey } from './types';\n\ntype MappingSpec = Record<string, { path: string; type?: string }>;\nconst configRootType = schema.getCodecForType('dxos.config.Config');\n\n/**\n * Maps the given objects onto a flattened set of (key x values).\n * Expects parsed yaml content of the form:\n *\n * ```\n * ENV_VAR:\n * path: config.selector.path\n * ```\n *\n * @param {object} spec\n * @param {object} values\n * @return {object}\n */\nexport const mapFromKeyValues = (spec: MappingSpec, values: Record<string, any>) => {\n const config = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n let value = values[key];\n if (value !== undefined) {\n if (type) {\n switch (type) {\n case 'boolean': {\n value = String(value).toLowerCase() === 'true' || value === '1';\n break;\n }\n\n case 'number': {\n value = Number(value);\n break;\n }\n\n case 'string': {\n break;\n }\n\n case 'json': {\n value = value ? JSON.parse(value) : null;\n break;\n }\n\n default: {\n throw new Error(`Invalid type: ${type}`);\n }\n }\n }\n\n setDeep(config, path.split('.'), value);\n }\n }\n\n return config;\n};\n\n/**\n * Maps the given flattend set of (key x values) onto a JSON object.\n * @param {object} spec\n * @param {object} values\n */\nexport const mapToKeyValues = (spec: MappingSpec, values: any) => {\n const config: Record<string, any> = {};\n\n for (const [key, { path, type }] of Object.entries(spec)) {\n const value = getDeep(values, path.split('.'));\n if (value !== undefined) {\n switch (type) {\n case 'json':\n config[key] = JSON.stringify(value);\n break;\n default:\n config[key] = value;\n }\n }\n }\n\n return config;\n};\n\n/**\n * Validate config object.\n */\nexport const validateConfig = (config: ConfigProto): ConfigProto => {\n if (!('version' in config)) {\n throw new InvalidConfigError({ message: 'Version not specified' });\n }\n\n if (config?.version !== 1) {\n throw new InvalidConfigError({ message: `Invalid config version: ${config.version}` });\n }\n\n const error = configRootType.protoType.verify(config);\n if (error) {\n throw new InvalidConfigError({ message: String(error) });\n }\n\n return config;\n};\n\n/**\n * Global configuration object.\n * NOTE: Config objects are immutable.\n */\nexport class Config {\n private readonly _config: any;\n\n /**\n * Creates an immutable instance.\n * @constructor\n */\n constructor(config: ConfigProto = {}, ...objects: ConfigProto[]) {\n this._config = validateConfig(defaultsDeep(config, ...objects, { version: 1 }));\n }\n\n /**\n * Returns an immutable config JSON object.\n */\n get values(): ConfigProto {\n return this._config;\n }\n\n /**\n * Returns the given config property.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n * @param defaultValue Default value to return if option is not present in the config.\n * @returns The config value or undefined if the option is not present.\n */\n get<K extends ConfigKey>(\n key: K,\n defaultValue?: DeepIndex<ConfigProto, ParseKey<K>>,\n ): DeepIndex<ConfigProto, ParseKey<K>> | undefined {\n return getDeep(this._config, key.split('.')) ?? defaultValue;\n }\n\n /**\n * Get unique key.\n */\n find<T = any>(path: string, test: object): T | undefined {\n const values = getDeep(this._config, path.split('.'));\n if (!Array.isArray(values)) {\n return;\n }\n\n return values.find((value) => isMatch(value, test));\n }\n\n /**\n * Returns the given config property or throw if it doesn't exist.\n *\n * @param key A key in the config object. Can be a nested property with keys separated by dots: 'services.signal.server'.\n */\n getOrThrow<K extends ConfigKey>(key: K): Exclude<DeepIndex<ConfigProto, ParseKey<K>>, undefined> {\n const value: DeepIndex<ConfigProto, ParseKey<K>> | undefined = getDeep(this._config, key.split('.'));\n if (!value) {\n throw new Error(`Config option not present: ${key}`);\n }\n return value;\n }\n}\n"],"mappings":";;;;;;AAeA,IAAM,iBAAiB,OAAO,gBAAgB,oBAAoB;;;;;;;;;;;;;;AAelE,IAAa,oBAAoB,MAAmB,WAAgC;CAClF,MAAM,SAAS,CAAC;CAEhB,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,WAAW,OAAO,QAAQ,IAAI,GAAG;EACxD,IAAI,QAAQ,OAAO;EACnB,IAAI,UAAU,KAAA,GAAW;GACvB,IAAI,MACF,QAAQ,MAAR;IACE,KAAK;KACH,QAAQ,OAAO,KAAK,CAAC,CAAC,YAAY,MAAM,UAAU,UAAU;KAC5D;IAGF,KAAK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;;;;CAKA,KAAc,MAAc,MAA6B;EACvD,MAAM,SAAS,QAAQ,KAAK,SAAS,KAAK,MAAM,GAAG,CAAC;EACpD,IAAI,CAAC,MAAM,QAAQ,MAAM,GACvB;EAGF,OAAO,OAAO,MAAM,UAAU,QAAQ,OAAO,IAAI,CAAC;CACpD;;;;;;CAOA,WAAgC,KAAiE;EAC/F,MAAM,QAAyD,QAAQ,KAAK,SAAS,IAAI,MAAM,GAAG,CAAC;EACnG,IAAI,CAAC,OACH,MAAM,IAAI,MAAM,8BAA8B,KAAK;EAErD,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { n as mapFromKeyValues } from "./chunk-config.mjs";
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
import { readFileSync } from "@dxos/node-std/fs";
|
|
4
|
+
import { resolve } from "@dxos/node-std/path";
|
|
5
|
+
import pkgUp from "pkg-up";
|
|
6
|
+
import { parse } from "yaml";
|
|
7
|
+
import { invariant } from "@dxos/invariant";
|
|
8
|
+
import { log } from "@dxos/log";
|
|
9
|
+
import { setDeep } from "@dxos/util";
|
|
10
|
+
//#region src/plugin/definitions.ts
|
|
11
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/plugin/definitions.ts";
|
|
12
|
+
var CWD = process.cwd();
|
|
13
|
+
var definitions = ({ configPath, envPath, devPath, mode = process.env.NODE_ENV, publicUrl = "", env }) => {
|
|
14
|
+
const KEYS_TO_FILE = {
|
|
15
|
+
__CONFIG_DEFAULTS__: configPath?.length ? configPath : resolve(CWD, "dx.yml"),
|
|
16
|
+
__CONFIG_ENVS__: envPath?.length ? envPath : resolve(CWD, "dx-env.yml")
|
|
17
|
+
};
|
|
18
|
+
if (mode !== "production") KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, "dx-local.yml");
|
|
19
|
+
return Object.entries(KEYS_TO_FILE).reduce((prev, [key, value]) => {
|
|
20
|
+
invariant(key, void 0, {
|
|
21
|
+
"~LogMeta": "~LogMeta",
|
|
22
|
+
F: __dxlog_file,
|
|
23
|
+
L: 38,
|
|
24
|
+
S: void 0,
|
|
25
|
+
A: ["key", ""]
|
|
26
|
+
});
|
|
27
|
+
let content = {};
|
|
28
|
+
try {
|
|
29
|
+
content = parse(readFileSync(value, "utf-8"));
|
|
30
|
+
if (key === "__CONFIG_ENVS__") content = mapFromKeyValues(content, process.env);
|
|
31
|
+
if (key === "__CONFIG_DEFAULTS__") {
|
|
32
|
+
Object.entries(process.env).forEach(([key, value]) => {
|
|
33
|
+
if (key.startsWith("DX_") || env?.includes(key)) setDeep(content, [
|
|
34
|
+
"runtime",
|
|
35
|
+
"app",
|
|
36
|
+
"env",
|
|
37
|
+
key
|
|
38
|
+
], value);
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
42
|
+
const commitHash = process.env.DX_COMMIT_HASH ?? execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).replace("\n", "");
|
|
43
|
+
const packagePath = pkgUp.sync();
|
|
44
|
+
const packageJson = packagePath && JSON.parse(readFileSync(packagePath, "utf-8"));
|
|
45
|
+
setDeep(content, [
|
|
46
|
+
"runtime",
|
|
47
|
+
"app",
|
|
48
|
+
"build",
|
|
49
|
+
"timestamp"
|
|
50
|
+
], timestamp);
|
|
51
|
+
setDeep(content, [
|
|
52
|
+
"runtime",
|
|
53
|
+
"app",
|
|
54
|
+
"build",
|
|
55
|
+
"commitHash"
|
|
56
|
+
], commitHash);
|
|
57
|
+
setDeep(content, [
|
|
58
|
+
"runtime",
|
|
59
|
+
"app",
|
|
60
|
+
"build",
|
|
61
|
+
"version"
|
|
62
|
+
], packageJson?.version);
|
|
63
|
+
} catch {}
|
|
64
|
+
}
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if (err.message.includes("YAMLException")) log.error(`Failed to parse file ${value}:`, err, {
|
|
67
|
+
"~LogMeta": "~LogMeta",
|
|
68
|
+
F: __dxlog_file,
|
|
69
|
+
L: 71,
|
|
70
|
+
S: void 0
|
|
71
|
+
});
|
|
72
|
+
else log(`Failed to load file ${value}:`, err, {
|
|
73
|
+
"~LogMeta": "~LogMeta",
|
|
74
|
+
F: __dxlog_file,
|
|
75
|
+
L: 73,
|
|
76
|
+
S: void 0
|
|
77
|
+
});
|
|
78
|
+
if (key === "__CONFIG_DEFAULTS__") throw new Error(`Failed to load default config file from ${value}`);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
...prev,
|
|
82
|
+
[key]: content
|
|
83
|
+
};
|
|
84
|
+
}, {
|
|
85
|
+
__CONFIG_DEFAULTS__: {},
|
|
86
|
+
__CONFIG_ENVS__: {},
|
|
87
|
+
__CONFIG_LOCAL__: {},
|
|
88
|
+
__DXOS_CONFIG__: {
|
|
89
|
+
dynamic: mode === "production",
|
|
90
|
+
publicUrl
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
export { definitions as t };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=chunk-definitions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-definitions.mjs","names":[],"sources":["../../src/plugin/definitions.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\nimport { execSync } from 'node:child_process';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport pkgUp from 'pkg-up';\nimport { parse } from 'yaml';\n\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { setDeep } from '@dxos/util';\n\nimport { mapFromKeyValues } from '../config';\nimport { type ConfigPluginOpts } from './types';\n\nconst CWD = process.cwd();\n\nexport const definitions = ({\n configPath,\n envPath,\n devPath,\n mode = process.env.NODE_ENV,\n publicUrl = '',\n env,\n}: ConfigPluginOpts) => {\n const KEYS_TO_FILE = {\n __CONFIG_DEFAULTS__: configPath?.length ? configPath : resolve(CWD, 'dx.yml'),\n __CONFIG_ENVS__: envPath?.length ? envPath : resolve(CWD, 'dx-env.yml'),\n } as { [key: string]: string };\n if (mode !== 'production') {\n KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, 'dx-local.yml');\n }\n\n return Object.entries(KEYS_TO_FILE).reduce(\n (prev, [key, value]) => {\n invariant(key);\n let content = {};\n try {\n content = parse(readFileSync(value, 'utf-8')) as any;\n\n // Map environment variables to config values.\n if (key === '__CONFIG_ENVS__') {\n content = mapFromKeyValues(content, process.env);\n }\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Load app environment variables into default config.\n Object.entries(process.env).forEach(([key, value]) => {\n if (key.startsWith('DX_') || env?.includes(key)) {\n setDeep(content, ['runtime', 'app', 'env', key], value);\n }\n });\n\n // Set build info automatically if available.\n try {\n const timestamp = new Date().toISOString();\n const commitHash =\n process.env.DX_COMMIT_HASH ??\n execSync('git rev-parse --short HEAD', { encoding: 'utf-8' }).replace('\\n', '');\n const packagePath = pkgUp.sync();\n const packageJson = packagePath && JSON.parse(readFileSync(packagePath, 'utf-8'));\n setDeep(content, ['runtime', 'app', 'build', 'timestamp'], timestamp);\n setDeep(content, ['runtime', 'app', 'build', 'commitHash'], commitHash);\n setDeep(content, ['runtime', 'app', 'build', 'version'], packageJson?.version);\n } catch {}\n }\n } catch (err: any) {\n if (err.message.includes('YAMLException')) {\n log.error(`Failed to parse file ${value}:`, err);\n } else {\n log(`Failed to load file ${value}:`, err);\n }\n\n if (key === '__CONFIG_DEFAULTS__') {\n // Default config is required.\n throw new Error(`Failed to load default config file from ${value}`);\n }\n }\n\n return {\n ...prev,\n [key]: content,\n };\n },\n {\n __CONFIG_DEFAULTS__: {},\n __CONFIG_ENVS__: {},\n __CONFIG_LOCAL__: {},\n __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },\n },\n );\n};\n"],"mappings":";;;;;;;;;;;AAiBA,IAAM,MAAM,QAAQ,IAAI;AAExB,IAAa,eAAe,EA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AAO;MAAS;KAAS,GAAG,aAAa,OAAO;IAC/E,QAAQ,CAAC;GACX;EACF,SAAS,KAAU;GACjB,IAAI,IAAI,QAAQ,SAAS,eAAe,GACtC,IAAI,MAAM,wBAAwB,MAAM,IAAI,KAAE;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;QAE/C,IAAI,uBAAuB,MAAM,IAAI,KAAE;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA,KAAA;GAAA,CAAC;GAG1C,IAAI,QAAQ,uBAEV,MAAM,IAAI,MAAM,2CAA2C,OAAO;EAEtE;EAEA,OAAO;GACL,GAAG;IACF,MAAM;EACT;CACF,GACA;EACE,qBAAqB,CAAC;EACtB,iBAAiB,CAAC;EAClB,kBAAkB,CAAC;EACnB,iBAAiB;GAAE,SAAS,SAAS;GAAc;EAAU;CAC/D,CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-types.mjs","names":[],"sources":["../../src/types.ts"],"sourcesContent":["//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nexport const FILE_DEFAULTS = 'defaults.yml';\nexport const FILE_ENVS = 'envs-map.yml';\nexport const FILE_DYNAMICS = 'config.yml';\n\ntype DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;\n\n/**\n * Returns all dot-separated nested keys for an object.\n *\n * Read more: https://stackoverflow.com/a/68404823.\n */\ntype DotNestedKeys<T> = (\n T extends object\n ? {\n [K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<DotNestedKeys<T[K]>>}`;\n }[Exclude<keyof T, symbol>]\n : ''\n) extends infer D\n ? Extract<D, string>\n : never;\n\n/**\n * Parse a dot separated nested key into an array of keys.\n *\n * Example: 'services.signal.server' -> ['services', 'signal', 'server'].\n */\nexport type ParseKey<K extends string> = K extends `${infer L}.${infer Rest}` ? [L, ...ParseKey<Rest>] : [K];\n\n/**\n * Array of types that can act as an object key.\n */\ntype Keys = (keyof any)[];\n\n/**\n * Retrieves a property type in a series of nested objects.\n *\n * Read more: https://stackoverflow.com/a/61648690.\n */\nexport type DeepIndex<T, KS extends Keys, Fail = undefined> = KS extends [infer F, ...infer R]\n ? F extends keyof Exclude<T, undefined>\n ? R extends Keys\n ? DeepIndex<Exclude<T, undefined>[F], R, Fail>\n : Fail\n : Fail\n : T;\n\n/**\n * Any nested dot separated key that can be in config.\n */\n// TODO(egorgripasov): Clean once old config deprecated.\nexport type ConfigKey = DotNestedKeys<ConfigProto>;\n"],"mappings":";AAMA,IAAa,gBAAgB;AAC7B,IAAa,YAAY;AACzB,IAAa,gBAAgB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { i as validateConfig, n as mapFromKeyValues, r as mapToKeyValues, t as Config } from "./chunk-config.mjs";
|
|
2
|
+
import { n as FILE_DYNAMICS, r as FILE_ENVS, t as FILE_DEFAULTS } from "./chunk-types.mjs";
|
|
3
|
+
import { dirname } from "@dxos/node-std/path";
|
|
4
|
+
import * as Yaml from "yaml";
|
|
5
|
+
import { invariant } from "@dxos/invariant";
|
|
6
|
+
import { isNode } from "@dxos/util";
|
|
7
|
+
import * as defs from "@dxos/protocols/proto/dxos/config";
|
|
8
|
+
import * as FileSystem from "@effect/platform/FileSystem";
|
|
9
|
+
import * as Context from "effect/Context";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Layer from "effect/Layer";
|
|
12
|
+
import * as Option from "effect/Option";
|
|
13
|
+
import { DX_CONFIG, DX_DATA, getProfileConfigPath, getProfilePath } from "@dxos/client-protocol";
|
|
14
|
+
import * as Match from "effect/Match";
|
|
15
|
+
export * from "#loaders";
|
|
16
|
+
export * from "#savers";
|
|
17
|
+
export * from "#plugin";
|
|
18
|
+
//#region src/config-service.ts
|
|
19
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/config-service.ts";
|
|
20
|
+
var memoryConfig = new Config({ runtime: { client: { edgeFeatures: {
|
|
21
|
+
subductionReplicator: true,
|
|
22
|
+
feedReplicator: true,
|
|
23
|
+
signaling: true,
|
|
24
|
+
agents: true
|
|
25
|
+
} } } });
|
|
26
|
+
var defaultConfig = new Config({ runtime: {
|
|
27
|
+
client: {
|
|
28
|
+
edgeFeatures: {
|
|
29
|
+
subductionReplicator: true,
|
|
30
|
+
feedReplicator: true,
|
|
31
|
+
signaling: true,
|
|
32
|
+
agents: true
|
|
33
|
+
},
|
|
34
|
+
storage: { persistent: true }
|
|
35
|
+
},
|
|
36
|
+
services: {
|
|
37
|
+
edge: { url: "wss://edge-production.dxos.workers.dev/" },
|
|
38
|
+
iceProviders: [{ urls: "https://edge-production.dxos.workers.dev/ice" }],
|
|
39
|
+
ai: { server: "https://ai-service.dxos.workers.dev" },
|
|
40
|
+
ipfs: {
|
|
41
|
+
server: "https://api.ipfs.dxos.network/api/v0",
|
|
42
|
+
gateway: "https://gateway.ipfs.dxos.network/ipfs"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} });
|
|
46
|
+
var ConfigService = class ConfigService extends Context.Tag("ConfigService")() {
|
|
47
|
+
static layerMemory = Layer.effect(ConfigService, Effect.succeed(memoryConfig));
|
|
48
|
+
static fromConfig = (config) => Layer.succeed(ConfigService, config);
|
|
49
|
+
static load = (args) => {
|
|
50
|
+
const defaultConfigPath = getProfileConfigPath(DX_CONFIG, args.profile);
|
|
51
|
+
return Effect.gen(function* () {
|
|
52
|
+
const fs = yield* FileSystem.FileSystem;
|
|
53
|
+
const configPath = Option.getOrElse(args.config, () => defaultConfigPath);
|
|
54
|
+
const configContent = yield* fs.readFileString(configPath);
|
|
55
|
+
const configValues = Yaml.parse(configContent);
|
|
56
|
+
return ConfigService.of(new Config(configValues, profileBuiltinDefaults(args.profile).values));
|
|
57
|
+
}).pipe(Effect.catchTag("SystemError", () => Effect.gen(function* () {
|
|
58
|
+
const configValues = defaultConfig.values;
|
|
59
|
+
const fs = yield* FileSystem.FileSystem;
|
|
60
|
+
const pathToCreate = Option.getOrElse(args.config, () => defaultConfigPath);
|
|
61
|
+
yield* fs.makeDirectory(dirname(pathToCreate), { recursive: true });
|
|
62
|
+
yield* fs.writeFileString(pathToCreate, Yaml.stringify(configValues));
|
|
63
|
+
return ConfigService.of(new Config(configValues));
|
|
64
|
+
})));
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Default config for a profile.
|
|
69
|
+
* Always merged with the default config.
|
|
70
|
+
*/
|
|
71
|
+
var profileBuiltinDefaults = (profile) => {
|
|
72
|
+
invariant(!profile.endsWith(".yml"), void 0, {
|
|
73
|
+
"~LogMeta": "~LogMeta",
|
|
74
|
+
F: __dxlog_file,
|
|
75
|
+
L: 98,
|
|
76
|
+
S: void 0,
|
|
77
|
+
A: ["!profile.endsWith('.yml')", ""]
|
|
78
|
+
});
|
|
79
|
+
return new Config({ runtime: { client: {
|
|
80
|
+
edgeFeatures: {
|
|
81
|
+
subductionReplicator: true,
|
|
82
|
+
feedReplicator: true,
|
|
83
|
+
signaling: true,
|
|
84
|
+
agents: true
|
|
85
|
+
},
|
|
86
|
+
storage: {
|
|
87
|
+
persistent: true,
|
|
88
|
+
dataRoot: getProfilePath(DX_DATA, profile)
|
|
89
|
+
}
|
|
90
|
+
} } });
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/edge-services.ts
|
|
94
|
+
/**
|
|
95
|
+
* Canonical names for EDGE (Cloudflare Worker) services.
|
|
96
|
+
* Used as keys into `runtime.services.edgeServices` and {@link EDGE_SERVICE_DEFAULTS}.
|
|
97
|
+
*/
|
|
98
|
+
var EdgeServiceName = Object.freeze({
|
|
99
|
+
Calls: "calls",
|
|
100
|
+
Image: "image",
|
|
101
|
+
Transcription: "transcription",
|
|
102
|
+
Discord: "discord",
|
|
103
|
+
CorsProxy: "cors-proxy",
|
|
104
|
+
ApiProxy: "api-proxy",
|
|
105
|
+
Introspect: "introspect",
|
|
106
|
+
ChatAgent: "chat-agent"
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* Canonical dev/test default endpoints for EDGE services.
|
|
110
|
+
* Single source of truth for the URLs previously hard-coded across plugins.
|
|
111
|
+
* Production values are supplied per-app via `dx.yml` (`runtime.services.edgeServices`).
|
|
112
|
+
*/
|
|
113
|
+
var EDGE_SERVICE_DEFAULTS = Object.freeze({
|
|
114
|
+
[EdgeServiceName.Calls]: "https://calls-service.dxos.workers.dev",
|
|
115
|
+
[EdgeServiceName.Image]: "https://image-service-main.dxos.workers.dev",
|
|
116
|
+
[EdgeServiceName.Transcription]: "https://calls-service.dxos.workers.dev",
|
|
117
|
+
[EdgeServiceName.Discord]: "https://discord-service.dxos.workers.dev",
|
|
118
|
+
[EdgeServiceName.CorsProxy]: "https://cors-proxy.dxos.workers.dev",
|
|
119
|
+
[EdgeServiceName.ApiProxy]: "https://api-proxy.dxos.workers.dev",
|
|
120
|
+
[EdgeServiceName.Introspect]: "https://mcp-introspect-service-labs.dxos.workers.dev/mcp",
|
|
121
|
+
[EdgeServiceName.ChatAgent]: "wss://chat-agent-labs.dxos.workers.dev"
|
|
122
|
+
});
|
|
123
|
+
/**
|
|
124
|
+
* Resolve the endpoint for an EDGE service.
|
|
125
|
+
* Prefers the matching `runtime.services.edgeServices` entry, falling back to the canonical
|
|
126
|
+
* {@link EDGE_SERVICE_DEFAULTS} entry.
|
|
127
|
+
* `name` is expected to be unique; on duplicates the last entry wins so a later override is
|
|
128
|
+
* not silently shadowed by an earlier one (proto cannot enforce uniqueness on a repeated field).
|
|
129
|
+
*/
|
|
130
|
+
var getEdgeServiceEndpoint = (config, name) => config.values.runtime?.services?.edgeServices?.findLast((service) => service.name === name)?.endpoint ?? EDGE_SERVICE_DEFAULTS[name];
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/telemetry.ts
|
|
133
|
+
/**
|
|
134
|
+
* Resolves the telemetry tag used as the `X-DXOS-Client-Tag` header on edge
|
|
135
|
+
* requests AND as the `ctx.tag` attribute / resource on observability traces.
|
|
136
|
+
*
|
|
137
|
+
* Keeping a single resolver ensures the same tag identifies a session across
|
|
138
|
+
* edge and telemetry tiers. Precedence:
|
|
139
|
+
*
|
|
140
|
+
* 1. `config.runtime.app.env.DX_TELEMETRY_TAG` — the explicit, deterministic
|
|
141
|
+
* path. Populated from `.env`/build-time by the app's config loaders.
|
|
142
|
+
* 2. `process.env.DX_TELEMETRY_TAG` — Node-only, for dev/CI convenience.
|
|
143
|
+
*
|
|
144
|
+
* Returns `undefined` when unset; callers should no-op on undefined rather
|
|
145
|
+
* than stamping empty strings.
|
|
146
|
+
*/
|
|
147
|
+
var resolveTelemetryTag = (config) => {
|
|
148
|
+
return config?.get("runtime.app.env.DX_TELEMETRY_TAG") ?? (isNode() ? process.env.DX_TELEMETRY_TAG : void 0);
|
|
149
|
+
};
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/preset.ts
|
|
152
|
+
var edgeUrl = (edge) => Match.value(edge).pipe(Match.when("local", () => "http://localhost:8787"), Match.when("dev", () => "https://edge.dxos.workers.dev"), Match.when("main", () => "https://edge-main.dxos.workers.dev"), Match.when("production", () => "https://edge-production.dxos.workers.dev"), Match.exhaustive);
|
|
153
|
+
var sandboxUrl = (sandbox) => Match.value(sandbox).pipe(Match.when("local", () => "http://localhost:8792"), Match.when("dev", () => "https://sandbox-service.dxos.workers.dev"), Match.when("main", () => "https://sandbox-service.dxos.workers.dev"), Match.when("production", () => "https://sandbox-service.dxos.workers.dev"), Match.exhaustive);
|
|
154
|
+
var configPreset = ({ edge = "main", sandbox } = {}) => new Config({
|
|
155
|
+
version: 1,
|
|
156
|
+
runtime: {
|
|
157
|
+
client: { edgeFeatures: {
|
|
158
|
+
signaling: true,
|
|
159
|
+
subductionReplicator: true,
|
|
160
|
+
feedReplicator: true
|
|
161
|
+
} },
|
|
162
|
+
services: {
|
|
163
|
+
edge: { url: edgeUrl(edge) },
|
|
164
|
+
...sandbox ? { sandbox: { url: sandboxUrl(sandbox) } } : {}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
//#endregion
|
|
169
|
+
export { Config, ConfigService, EDGE_SERVICE_DEFAULTS, EdgeServiceName, FILE_DEFAULTS, FILE_DYNAMICS, FILE_ENVS, configPreset, defaultConfig, defs, getEdgeServiceEndpoint, mapFromKeyValues, mapToKeyValues, memoryConfig, resolveTelemetryTag, validateConfig };
|
|
170
|
+
|
|
171
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/config-service.ts","../../src/edge-services.ts","../../src/telemetry.ts","../../src/preset.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as FileSystem from '@effect/platform/FileSystem';\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Option from 'effect/Option';\nimport { dirname } from 'node:path';\nimport * as Yaml from 'yaml';\n\nimport { DX_CONFIG, DX_DATA, getProfileConfigPath, getProfilePath } from '@dxos/client-protocol';\nimport { invariant } from '@dxos/invariant';\n\nimport { Config } from './config';\n\nexport const memoryConfig = new Config({\n runtime: {\n client: {\n edgeFeatures: {\n subductionReplicator: true,\n feedReplicator: true,\n signaling: true,\n agents: true,\n },\n },\n },\n});\n\nexport const defaultConfig = new Config({\n runtime: {\n client: {\n edgeFeatures: {\n subductionReplicator: true,\n feedReplicator: true,\n signaling: true,\n agents: true,\n },\n storage: {\n persistent: true,\n },\n },\n services: {\n edge: {\n url: 'wss://edge-production.dxos.workers.dev/',\n },\n iceProviders: [\n {\n urls: 'https://edge-production.dxos.workers.dev/ice',\n },\n ],\n ai: {\n server: 'https://ai-service.dxos.workers.dev',\n },\n ipfs: {\n server: 'https://api.ipfs.dxos.network/api/v0',\n gateway: 'https://gateway.ipfs.dxos.network/ipfs',\n },\n },\n },\n});\n\nexport class ConfigService extends Context.Tag('ConfigService')<ConfigService, Config>() {\n static layerMemory = Layer.effect(ConfigService, Effect.succeed(memoryConfig));\n\n static fromConfig = (config: Config) => Layer.succeed(ConfigService, config);\n\n static load = (args: { config: Option.Option<string>; profile: string }) => {\n const defaultConfigPath = getProfileConfigPath(DX_CONFIG, args.profile);\n return Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const configPath = Option.getOrElse(args.config, () => defaultConfigPath);\n const configContent = yield* fs.readFileString(configPath);\n const configValues = Yaml.parse(configContent);\n return ConfigService.of(new Config(configValues, profileBuiltinDefaults(args.profile).values));\n }).pipe(\n // If the config file doesn't exist, create it.\n Effect.catchTag('SystemError', () =>\n Effect.gen(function* () {\n const configValues = defaultConfig.values;\n const fs = yield* FileSystem.FileSystem;\n const pathToCreate = Option.getOrElse(args.config, () => defaultConfigPath);\n yield* fs.makeDirectory(dirname(pathToCreate), { recursive: true });\n yield* fs.writeFileString(pathToCreate, Yaml.stringify(configValues));\n return ConfigService.of(new Config(configValues));\n }),\n ),\n );\n };\n}\n\n/**\n * Default config for a profile.\n * Always merged with the default config.\n */\nconst profileBuiltinDefaults = (profile: string) => {\n invariant(!profile.endsWith('.yml'));\n\n return new Config({\n runtime: {\n client: {\n edgeFeatures: {\n subductionReplicator: true,\n feedReplicator: true,\n signaling: true,\n agents: true,\n },\n storage: {\n persistent: true,\n dataRoot: getProfilePath(DX_DATA, profile),\n },\n },\n },\n });\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type Config } from './config';\n\n/**\n * Canonical names for EDGE (Cloudflare Worker) services.\n * Used as keys into `runtime.services.edgeServices` and {@link EDGE_SERVICE_DEFAULTS}.\n */\nexport const EdgeServiceName = Object.freeze({\n Calls: 'calls',\n Image: 'image',\n Transcription: 'transcription',\n Discord: 'discord',\n CorsProxy: 'cors-proxy',\n ApiProxy: 'api-proxy',\n Introspect: 'introspect',\n ChatAgent: 'chat-agent',\n} as const);\n\nexport type EdgeServiceName = (typeof EdgeServiceName)[keyof typeof EdgeServiceName];\n\n/**\n * Canonical dev/test default endpoints for EDGE services.\n * Single source of truth for the URLs previously hard-coded across plugins.\n * Production values are supplied per-app via `dx.yml` (`runtime.services.edgeServices`).\n */\nexport const EDGE_SERVICE_DEFAULTS: Readonly<Record<EdgeServiceName, string>> = Object.freeze({\n [EdgeServiceName.Calls]: 'https://calls-service.dxos.workers.dev',\n [EdgeServiceName.Image]: 'https://image-service-main.dxos.workers.dev',\n [EdgeServiceName.Transcription]: 'https://calls-service.dxos.workers.dev',\n [EdgeServiceName.Discord]: 'https://discord-service.dxos.workers.dev',\n [EdgeServiceName.CorsProxy]: 'https://cors-proxy.dxos.workers.dev',\n [EdgeServiceName.ApiProxy]: 'https://api-proxy.dxos.workers.dev',\n [EdgeServiceName.Introspect]: 'https://mcp-introspect-service-labs.dxos.workers.dev/mcp',\n [EdgeServiceName.ChatAgent]: 'wss://chat-agent-labs.dxos.workers.dev',\n});\n\n/**\n * Resolve the endpoint for an EDGE service.\n * Prefers the matching `runtime.services.edgeServices` entry, falling back to the canonical\n * {@link EDGE_SERVICE_DEFAULTS} entry.\n * `name` is expected to be unique; on duplicates the last entry wins so a later override is\n * not silently shadowed by an earlier one (proto cannot enforce uniqueness on a repeated field).\n */\nexport const getEdgeServiceEndpoint = (config: Config, name: EdgeServiceName): string =>\n config.values.runtime?.services?.edgeServices?.findLast((service) => service.name === name)?.endpoint ??\n EDGE_SERVICE_DEFAULTS[name];\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { isNode } from '@dxos/util';\n\nimport { type Config } from './config';\n\n/**\n * Resolves the telemetry tag used as the `X-DXOS-Client-Tag` header on edge\n * requests AND as the `ctx.tag` attribute / resource on observability traces.\n *\n * Keeping a single resolver ensures the same tag identifies a session across\n * edge and telemetry tiers. Precedence:\n *\n * 1. `config.runtime.app.env.DX_TELEMETRY_TAG` — the explicit, deterministic\n * path. Populated from `.env`/build-time by the app's config loaders.\n * 2. `process.env.DX_TELEMETRY_TAG` — Node-only, for dev/CI convenience.\n *\n * Returns `undefined` when unset; callers should no-op on undefined rather\n * than stamping empty strings.\n */\nexport const resolveTelemetryTag = (config?: Config): string | undefined => {\n return config?.get('runtime.app.env.DX_TELEMETRY_TAG') ?? (isNode() ? process.env.DX_TELEMETRY_TAG : undefined);\n};\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Match from 'effect/Match';\n\nimport { Config } from './config';\n\nexport type ConfigPresetOptions = {\n /**\n * Edge service.\n * @default main\n */\n edge?: 'local' | 'dev' | 'main' | 'production';\n\n /**\n * Sandbox service (standalone worker; API at /api/sandbox).\n */\n sandbox?: 'local' | 'dev' | 'main' | 'production';\n};\n\nconst edgeUrl = (edge: NonNullable<ConfigPresetOptions['edge']>) =>\n Match.value(edge).pipe(\n Match.when('local', () => 'http://localhost:8787'),\n Match.when('dev', () => 'https://edge.dxos.workers.dev'),\n Match.when('main', () => 'https://edge-main.dxos.workers.dev'),\n Match.when('production', () => 'https://edge-production.dxos.workers.dev'),\n Match.exhaustive,\n );\n\n// TODO(burdon): Hosted environments share a single worker until per-env deployments exist.\nconst sandboxUrl = (sandbox: NonNullable<ConfigPresetOptions['sandbox']>) =>\n Match.value(sandbox).pipe(\n Match.when('local', () => 'http://localhost:8792'),\n Match.when('dev', () => 'https://sandbox-service.dxos.workers.dev'),\n Match.when('main', () => 'https://sandbox-service.dxos.workers.dev'),\n Match.when('production', () => 'https://sandbox-service.dxos.workers.dev'),\n Match.exhaustive,\n );\n\nexport const configPreset = ({ edge = 'main', sandbox }: ConfigPresetOptions = {}) =>\n new Config({\n version: 1,\n runtime: {\n client: {\n edgeFeatures: {\n signaling: true,\n subductionReplicator: true,\n feedReplicator: true,\n },\n },\n services: {\n edge: {\n url: edgeUrl(edge),\n },\n ...(sandbox ? { sandbox: { url: sandboxUrl(sandbox) } } : {}),\n },\n },\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBA,IAAa,eAAe,IAAI,OAAO,EACrC,SAAS,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AM,KAAK,aAAa,+BAA+B,GACvD,MAAM,KAAK,cAAc,oCAAoC,GAC7D,MAAM,KAAK,oBAAoB,0CAA0C,GACzE,MAAM,UACR;AAGF,IAAM,cAAc,YAClB,MAAM,MAAM,OAAO,CAAC,CAAC,KACnB,MAAM,KAAK,eAAe,uBAAuB,GACjD,MAAM,KAAK,aAAa,0CAA0C,GAClE,MAAM,KAAK,cAAc,0CAA0C,GACnE,MAAM,KAAK,oBAAoB,0CAA0C,GACzE,MAAM,UACR;AAEF,IAAa,gBAAgB,EAAE,OAAO,QAAQ,YAAiC,CAAC,MAC9E,IAAI,OAAO;CACT,SAAS;CACT,SAAS;EACP,QAAQ,EACN,cAAc;GACZ,WAAW;GACX,sBAAsB;GACtB,gBAAgB;EAClB,EACF;EACA,UAAU;GACR,MAAM,EACJ,KAAK,QAAQ,IAAI,EACnB;GACA,GAAI,UAAU,EAAE,SAAS,EAAE,KAAK,WAAW,OAAO,EAAE,EAAE,IAAI,CAAC;EAC7D;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { log } from "@dxos/log";
|
|
2
|
+
import localforage from "localforage";
|
|
3
|
+
//#region src/loaders/browser.ts
|
|
4
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/loaders/browser.ts";
|
|
5
|
+
var CONFIG_ENDPOINT = "/.well-known/dx/config";
|
|
6
|
+
var Profile = (_profile = "default") => ({});
|
|
7
|
+
var Local = () => {
|
|
8
|
+
return typeof __CONFIG_LOCAL__ !== "undefined" ? __CONFIG_LOCAL__ : {};
|
|
9
|
+
};
|
|
10
|
+
var Dynamics = async () => {
|
|
11
|
+
const { publicUrl = "", dynamic } = __DXOS_CONFIG__;
|
|
12
|
+
if (!dynamic) {
|
|
13
|
+
log("dynamics disabled", void 0, {
|
|
14
|
+
"~LogMeta": "~LogMeta",
|
|
15
|
+
F: __dxlog_file,
|
|
16
|
+
L: 28,
|
|
17
|
+
S: void 0
|
|
18
|
+
});
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
log("fetching config...", { publicUrl }, {
|
|
22
|
+
"~LogMeta": "~LogMeta",
|
|
23
|
+
F: __dxlog_file,
|
|
24
|
+
L: 32,
|
|
25
|
+
S: void 0
|
|
26
|
+
});
|
|
27
|
+
return await fetch(`${publicUrl}${CONFIG_ENDPOINT}`).then((res) => res.json()).catch((error) => {
|
|
28
|
+
log.warn("Failed to fetch dynamic config.", error, {
|
|
29
|
+
"~LogMeta": "~LogMeta",
|
|
30
|
+
F: __dxlog_file,
|
|
31
|
+
L: 36,
|
|
32
|
+
S: void 0
|
|
33
|
+
});
|
|
34
|
+
return {};
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var Envs = (_basePath) => {
|
|
38
|
+
return typeof __CONFIG_ENVS__ !== "undefined" ? __CONFIG_ENVS__ : {};
|
|
39
|
+
};
|
|
40
|
+
var Defaults = (_basePath) => {
|
|
41
|
+
return typeof __CONFIG_DEFAULTS__ !== "undefined" ? __CONFIG_DEFAULTS__ : {};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Settings config from browser storage.
|
|
45
|
+
*/
|
|
46
|
+
var Storage = async () => {
|
|
47
|
+
try {
|
|
48
|
+
const config = await localforage.getItem("org.dxos.settings.config");
|
|
49
|
+
if (config) return config;
|
|
50
|
+
} catch (err) {
|
|
51
|
+
log.warn("Failed to load config", { err }, {
|
|
52
|
+
"~LogMeta": "~LogMeta",
|
|
53
|
+
F: __dxlog_file,
|
|
54
|
+
L: 59,
|
|
55
|
+
S: void 0
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return {};
|
|
59
|
+
};
|
|
60
|
+
var Remote = (target, authenticationToken) => {
|
|
61
|
+
if (!target) return {};
|
|
62
|
+
try {
|
|
63
|
+
const url = new URL(target);
|
|
64
|
+
const protocol = url.protocol.slice(0, -1);
|
|
65
|
+
return { runtime: { client: {
|
|
66
|
+
remoteSource: url.origin + (protocol.startsWith("http") ? "/vault.html" : ""),
|
|
67
|
+
remoteSourceAuthenticationToken: authenticationToken
|
|
68
|
+
} } };
|
|
69
|
+
} catch (err) {
|
|
70
|
+
log.catch(err, void 0, {
|
|
71
|
+
"~LogMeta": "~LogMeta",
|
|
72
|
+
F: __dxlog_file,
|
|
73
|
+
L: 83,
|
|
74
|
+
S: void 0
|
|
75
|
+
});
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { Defaults, Dynamics, Envs, Local, Profile, Remote, Storage };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.mjs","names":[],"sources":["../../../src/loaders/browser.ts"],"sourcesContent":["//\n// Copyright 2021 DXOS.org\n//\n\n/* THIS FILE WILL BE LOADED BY CONTEXT REPLACEMENT PLUGIN IN BROWSER ENVS. */\n\nimport localforage from 'localforage';\n\nimport { log } from '@dxos/log';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\ndeclare const __DXOS_CONFIG__: { publicUrl?: string; dynamic?: boolean };\ndeclare const __CONFIG_ENVS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_DEFAULTS__: Partial<ConfigProto> | undefined;\ndeclare const __CONFIG_LOCAL__: Partial<ConfigProto> | undefined;\n\nconst CONFIG_ENDPOINT = '/.well-known/dx/config';\n\nexport const Profile = (_profile = 'default'): Partial<ConfigProto> => ({});\n\nexport const Local = (): Partial<ConfigProto> => {\n return typeof __CONFIG_LOCAL__ !== 'undefined' ? __CONFIG_LOCAL__ : {};\n};\n\nexport const Dynamics = async (): Promise<Partial<ConfigProto>> => {\n const { publicUrl = '', dynamic } = __DXOS_CONFIG__;\n if (!dynamic) {\n log('dynamics disabled');\n return {};\n }\n\n log('fetching config...', { publicUrl });\n return await fetch(`${publicUrl}${CONFIG_ENDPOINT}`)\n .then((res) => res.json())\n .catch((error) => {\n log.warn('Failed to fetch dynamic config.', error);\n return {};\n });\n};\n\nexport const Envs = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_ENVS__ !== 'undefined' ? __CONFIG_ENVS__ : {};\n};\n\nexport const Defaults = (_basePath?: string): Partial<ConfigProto> => {\n return typeof __CONFIG_DEFAULTS__ !== 'undefined' ? __CONFIG_DEFAULTS__ : {};\n};\n\n/**\n * Settings config from browser storage.\n */\nexport const Storage = async (): Promise<Partial<ConfigProto>> => {\n try {\n const config = await localforage.getItem<Partial<ConfigProto>>('org.dxos.settings.config');\n if (config) {\n return config;\n }\n } catch (err) {\n log.warn('Failed to load config', { err });\n }\n return {};\n};\n\nexport const Remote = (target: string | undefined, authenticationToken?: string): Partial<ConfigProto> => {\n if (!target) {\n return {};\n }\n\n try {\n const url = new URL(target);\n const protocol = url.protocol.slice(0, -1);\n\n return {\n runtime: {\n client: {\n // TODO(burdon): Remove vault.html.\n remoteSource: url.origin + (protocol.startsWith('http') ? '/vault.html' : ''),\n remoteSourceAuthenticationToken: authenticationToken,\n },\n },\n };\n } catch (err) {\n log.catch(err);\n return {};\n }\n};\n"],"mappings":";;;;AAgBA,IAAM,kBAAkB;AAExB,IAAa,WAAW,WAAW,eAAqC,CAAC;AAEzE,IAAa,cAAoC;CAC/C,OAAO,OAAO,qBAAqB,cAAc,mBAAmB,CAAC;AACvE;AAEA,IAAa,WAAW,YAA2C;CACjE,MAAM,EAAE,YAAY,IAAI,YAAY;CACpC,IAAI,CAAC,SAAS;EACZ,IAAI,qBAAkB,KAAA,GAAA;GAAA,YAAA;GAAA,GAAA;GAAA,GAAA;GAAA,GAAA,KAAA;EAAA,CAAC;EACvB,OAAO,CAAC;CACV;CAEA,IAAI,sBAAsB,EAAE,UAAU,GAAA;EAAA,YAAA;EAAA,GAAA;EAAA,GAAA;EAAA,GAAA,KAAA;CAAA,CAAC;CACvC,OAAO,MAAM,MAAM,GAAG,YAAY,iBAAiB,CAAA,CAChD,MAAM,QAAQ,IAAI,KAAK,CAAC,CAAA,CACxB,OAAO,UAAU;EAChB,IAAI,KAAK,mCAAmC,OAAI;GAAA,YAAA;GAAA,GAAA;GAAA,GAAA;GAAA,GAAA,KAAA;EAAA,CAAC;EACjD,OAAO,CAAC;CACV,CAAC;AACL;AAEA,IAAa,QAAQ,cAA6C;CAChE,OAAO,OAAO,oBAAoB,cAAc,kBAAkB,CAAC;AACrE;AAEA,IAAa,YAAY,cAA6C;CACpE,OAAO,OAAO,wBAAwB,cAAc,sBAAsB,CAAC;AAC7E;;;;AAKA,IAAa,UAAU,YAA2C;CAChE,IAAI;EACF,MAAM,SAAS,MAAM,YAAY,QAA8B,0BAA0B;EACzF,IAAI,QACF,OAAO;CAEX,SAAS,KAAK;EACZ,IAAI,KAAK,yBAAyB,EAAE,IAAI,GAAA;GAAA,YAAA;GAAA,GAAA;GAAA,GAAA;GAAA,GAAA,KAAA;EAAA,CAAC;CAC3C;CACA,OAAO,CAAC;AACV;AAEA,IAAa,UAAU,QAA4B,wBAAuD;CACxG,IAAI,CAAC,QACH,OAAO,CAAC;CAGV,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,MAAM;EAC1B,MAAM,WAAW,IAAI,SAAS,MAAM,GAAG,EAAE;EAEzC,OAAO,EACL,SAAS,EACP,QAAQ;GAEN,cAAc,IAAI,UAAU,SAAS,WAAW,MAAM,IAAI,gBAAgB;GAC1E,iCAAiC;EACnC,EACF,EACF;CACF,SAAS,KAAK;EACZ,IAAI,MAAM,KAAE,KAAA,GAAA;GAAA,YAAA;GAAA,GAAA;GAAA,GAAA;GAAA,GAAA,KAAA;EAAA,CAAC;EACb,OAAO,CAAC;CACV;AACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { n as mapFromKeyValues } from "./chunk-config.mjs";
|
|
2
|
+
import { r as FILE_ENVS } from "./chunk-types.mjs";
|
|
3
|
+
import fs from "@dxos/node-std/fs";
|
|
4
|
+
import path from "@dxos/node-std/path";
|
|
5
|
+
import { parse } from "yaml";
|
|
6
|
+
import { log } from "@dxos/log";
|
|
7
|
+
//#region src/loaders/index.ts
|
|
8
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/config/src/loaders/index.ts";
|
|
9
|
+
var DEFAULT_BASE_PATH = path.resolve(process.cwd(), "config");
|
|
10
|
+
var maybeLoadFile = (file) => {
|
|
11
|
+
try {
|
|
12
|
+
return parse(fs.readFileSync(file, { encoding: "utf8" }));
|
|
13
|
+
} catch (err) {}
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Profile
|
|
17
|
+
*/
|
|
18
|
+
var Profile = (profile = "default") => {
|
|
19
|
+
return maybeLoadFile(path.join(process.env.HOME ?? "~", `.config/dx/profile/${profile}.yml`));
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Development config.
|
|
23
|
+
*/
|
|
24
|
+
var Local = () => ({});
|
|
25
|
+
/**
|
|
26
|
+
* Provided dynamically by server.
|
|
27
|
+
*/
|
|
28
|
+
var Dynamics = () => ({});
|
|
29
|
+
/**
|
|
30
|
+
* ENV variable (key/value) map.
|
|
31
|
+
*/
|
|
32
|
+
var Envs = (basePath = DEFAULT_BASE_PATH) => {
|
|
33
|
+
const content = maybeLoadFile(path.resolve(basePath, FILE_ENVS));
|
|
34
|
+
return content ? mapFromKeyValues(content, process.env) : {};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* JSON config.
|
|
38
|
+
*/
|
|
39
|
+
var Defaults = (basePath = DEFAULT_BASE_PATH) => maybeLoadFile(path.resolve(basePath, "defaults.yml")) ?? {};
|
|
40
|
+
/**
|
|
41
|
+
* Load config from storage.
|
|
42
|
+
*/
|
|
43
|
+
var Storage = async () => ({});
|
|
44
|
+
var Remote = (target, authenticationToken) => {
|
|
45
|
+
if (!target) return {};
|
|
46
|
+
try {
|
|
47
|
+
const url = new URL(target);
|
|
48
|
+
const protocol = url.protocol.slice(0, -1);
|
|
49
|
+
return { runtime: { client: {
|
|
50
|
+
remoteSource: url.origin + (protocol.startsWith("http") ? "/vault.html" : ""),
|
|
51
|
+
remoteSourceAuthenticationToken: authenticationToken
|
|
52
|
+
} } };
|
|
53
|
+
} catch (err) {
|
|
54
|
+
log.catch(err, void 0, {
|
|
55
|
+
"~LogMeta": "~LogMeta",
|
|
56
|
+
F: __dxlog_file,
|
|
57
|
+
L: 87,
|
|
58
|
+
S: void 0
|
|
59
|
+
});
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { Defaults, Dynamics, Envs, Local, Profile, Remote, Storage };
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=loaders.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loaders.mjs","names":[],"sources":["../../src/loaders/index.ts"],"sourcesContent":["//\n// Copyright 2021 DXOS.org\n//\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { parse } from 'yaml';\n\nimport { log } from '@dxos/log';\nimport { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';\n\nimport { mapFromKeyValues } from '../config';\nimport { FILE_DEFAULTS, FILE_ENVS } from '../types';\n\n// TODO(burdon): Move code out of index file.\n\nconst DEFAULT_BASE_PATH = path.resolve(process.cwd(), 'config');\n\nconst maybeLoadFile = (file: string): any => {\n try {\n return parse(fs.readFileSync(file, { encoding: 'utf8' }));\n } catch (err: any) {\n // Ignored.\n }\n};\n\n//\n// NOTE: Export LocalStorage and Dynamics for typescript to typecheck browser code (see ConfigPlugin).\n//\n\n/**\n * Profile\n */\nexport const Profile = (profile = 'default') => {\n const configFile = path.join(process.env.HOME ?? '~', `.config/dx/profile/${profile}.yml`);\n return maybeLoadFile(configFile) as ConfigProto;\n};\n\n/**\n * Development config.\n */\n// TODO(burdon): Rename or reconcile with Profile above?\nexport const Local = (): Partial<ConfigProto> => ({});\n\n/**\n * Provided dynamically by server.\n */\nexport const Dynamics = (): Partial<ConfigProto> => ({});\n\n/**\n * ENV variable (key/value) map.\n */\nexport const Envs = (basePath = DEFAULT_BASE_PATH): Partial<ConfigProto> => {\n const content = maybeLoadFile(path.resolve(basePath, FILE_ENVS));\n return content ? mapFromKeyValues(content, process.env) : {};\n};\n\n/**\n * JSON config.\n */\nexport const Defaults = (basePath = DEFAULT_BASE_PATH): Partial<ConfigProto> =>\n maybeLoadFile(path.resolve(basePath, FILE_DEFAULTS)) ?? {};\n\n/**\n * Load config from storage.\n */\nexport const Storage = async (): Promise<Partial<ConfigProto>> => ({});\n\nexport const Remote = (target: string | undefined, authenticationToken?: string): Partial<ConfigProto> => {\n if (!target) {\n return {};\n }\n\n try {\n const url = new URL(target);\n const protocol = url.protocol.slice(0, -1);\n return {\n runtime: {\n client: {\n // TODO(burdon): Remove vault.html.\n remoteSource: url.origin + (protocol.startsWith('http') ? '/vault.html' : ''),\n remoteSourceAuthenticationToken: authenticationToken,\n },\n },\n };\n } catch (err) {\n log.catch(err);\n return {};\n }\n};\n"],"mappings":";;;;;;;;AAgBA,IAAM,oBAAoB,KAAK,QAAQ,QAAQ,IAAI,GAAG,QAAQ;AAE9D,IAAM,iBAAiB,SAAsB;CAC3C,IAAI;EACF,OAAO,MAAM,GAAG,aAAa,MAAM,EAAE,UAAU,OAAO,CAAC,CAAC;CAC1D,SAAS,KAAU,CAEnB;AACF;;;;AASA,IAAa,WAAW,UAAU,cAAc;CAE9C,OAAO,cADY,KAAK,KAAK,QAAQ,IAAI,QAAQ,KAAK,sBAAsB,QAAQ,KAC/D,CAAU;AACjC;;;;AAMA,IAAa,eAAqC,CAAC;;;;AAKnD,IAAa,kBAAwC,CAAC;;;;AAKtD,IAAa,QAAQ,WAAW,sBAA4C;CAC1E,MAAM,UAAU,cAAc,KAAK,QAAQ,UAAU,SAAS,CAAC;CAC/D,OAAO,UAAU,iBAAiB,SAAS,QAAQ,GAAG,IAAI,CAAC;AAC7D;;;;AAKA,IAAa,YAAY,WAAW,sBAClC,cAAc,KAAK,QAAQ,UAAA,cAAuB,CAAC,KAAK,CAAC;;;;AAK3D,IAAa,UAAU,aAA4C,CAAC;AAEpE,IAAa,UAAU,QAA4B,wBAAuD;CACxG,IAAI,CAAC,QACH,OAAO,CAAC;CAGV,IAAI;EACF,MAAM,MAAM,IAAI,IAAI,MAAM;EAC1B,MAAM,WAAW,IAAI,SAAS,MAAM,GAAG,EAAE;EACzC,OAAO,EACL,SAAS,EACP,QAAQ;GAEN,cAAc,IAAI,UAAU,SAAS,WAAW,MAAM,IAAI,gBAAgB;GAC1E,iCAAiC;EACnC,EACF,EACF;CACF,SAAS,KAAK;EACZ,IAAI,MAAM,KAAE,KAAA,GAAA;GAAA,YAAA;GAAA,GAAA;GAAA,GAAA;GAAA,GAAA,KAAA;EAAA,CAAC;EACb,OAAO,CAAC;CACV;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.mjs","names":[],"sources":["../../../src/plugin/browser.ts"],"sourcesContent":["//\n// Copyright 2022 DXOS.org\n//\n\n// Browser stub for plugin module - plugins are build-time only.\n\nexport type * from './types';\n\nexport const definitions = (): Record<string, unknown> => {\n throw new Error('Config plugin definitions are not available in the browser');\n};\n"],"mappings":";AAQA,IAAa,oBAA6C;CACxD,MAAM,IAAI,MAAM,4DAA4D;AAC9E"}
|