@dxos/config 0.8.3 → 0.8.4-main.03d5cd7b56

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 (107) hide show
  1. package/dist/lib/browser/chunk-VQRJY4AQ.mjs +11 -0
  2. package/dist/lib/browser/chunk-VQRJY4AQ.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-ZY4D4E3Q.mjs +146 -0
  4. package/dist/lib/browser/chunk-ZY4D4E3Q.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +137 -209
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/loaders/browser.mjs +73 -0
  8. package/dist/lib/browser/loaders/browser.mjs.map +7 -0
  9. package/dist/lib/browser/loaders/index.mjs +66 -0
  10. package/dist/lib/browser/loaders/index.mjs.map +7 -0
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/plugin/browser.mjs +8 -0
  13. package/dist/lib/browser/plugin/browser.mjs.map +7 -0
  14. package/dist/lib/browser/plugin/index.mjs +98 -0
  15. package/dist/lib/browser/plugin/index.mjs.map +7 -0
  16. package/dist/lib/browser/savers/browser.mjs +25 -0
  17. package/dist/lib/browser/savers/browser.mjs.map +7 -0
  18. package/dist/lib/browser/savers/index.mjs +7 -0
  19. package/dist/lib/browser/savers/index.mjs.map +7 -0
  20. package/dist/lib/node-esm/chunk-T6NFH3CC.mjs +13 -0
  21. package/dist/lib/node-esm/chunk-T6NFH3CC.mjs.map +7 -0
  22. package/dist/lib/node-esm/chunk-WIJROCKQ.mjs +148 -0
  23. package/dist/lib/node-esm/chunk-WIJROCKQ.mjs.map +7 -0
  24. package/dist/lib/node-esm/index.mjs +133 -289
  25. package/dist/lib/node-esm/index.mjs.map +4 -4
  26. package/dist/lib/node-esm/loaders/browser.mjs +75 -0
  27. package/dist/lib/node-esm/loaders/browser.mjs.map +7 -0
  28. package/dist/lib/node-esm/loaders/index.mjs +67 -0
  29. package/dist/lib/node-esm/loaders/index.mjs.map +7 -0
  30. package/dist/lib/node-esm/meta.json +1 -1
  31. package/dist/lib/node-esm/plugin/browser.mjs +10 -0
  32. package/dist/lib/node-esm/plugin/browser.mjs.map +7 -0
  33. package/dist/lib/node-esm/plugin/index.mjs +99 -0
  34. package/dist/lib/node-esm/plugin/index.mjs.map +7 -0
  35. package/dist/lib/node-esm/savers/browser.mjs +27 -0
  36. package/dist/lib/node-esm/savers/browser.mjs.map +7 -0
  37. package/dist/lib/node-esm/savers/index.mjs +9 -0
  38. package/dist/lib/node-esm/savers/index.mjs.map +7 -0
  39. package/dist/plugin/node-esm/{chunk-PAFU3TJI.mjs → chunk-XCZNYAQT.mjs} +27 -29
  40. package/dist/plugin/node-esm/chunk-XCZNYAQT.mjs.map +7 -0
  41. package/dist/plugin/node-esm/esbuild-plugin.mjs +2 -2
  42. package/dist/plugin/node-esm/meta.json +1 -1
  43. package/dist/plugin/node-esm/rollup-plugin.mjs +2 -2
  44. package/dist/plugin/node-esm/vite-plugin.mjs +6 -6
  45. package/dist/plugin/node-esm/vite-plugin.mjs.map +3 -3
  46. package/dist/types/src/config-service.d.ts +19 -0
  47. package/dist/types/src/config-service.d.ts.map +1 -0
  48. package/dist/types/src/config.d.ts +0 -1
  49. package/dist/types/src/config.d.ts.map +1 -1
  50. package/dist/types/src/index.d.ts +6 -3
  51. package/dist/types/src/index.d.ts.map +1 -1
  52. package/dist/types/src/loaders/browser.d.ts +11 -15
  53. package/dist/types/src/loaders/browser.d.ts.map +1 -1
  54. package/dist/types/src/loaders/index.d.ts.map +1 -1
  55. package/dist/types/src/plugin/browser.d.ts +3 -0
  56. package/dist/types/src/plugin/browser.d.ts.map +1 -0
  57. package/dist/types/src/plugin/definitions.d.ts +3 -3
  58. package/dist/types/src/plugin/definitions.d.ts.map +1 -1
  59. package/dist/types/src/plugin/esbuild-plugin.d.ts.map +1 -1
  60. package/dist/types/src/plugin/index.d.ts +1 -1
  61. package/dist/types/src/plugin/index.d.ts.map +1 -1
  62. package/dist/types/src/plugin/rollup-plugin.d.ts.map +1 -1
  63. package/dist/types/src/plugin/types.d.ts +4 -0
  64. package/dist/types/src/plugin/types.d.ts.map +1 -1
  65. package/dist/types/src/plugin/vite-plugin.d.ts +1 -1
  66. package/dist/types/src/plugin/vite-plugin.d.ts.map +1 -1
  67. package/dist/types/src/preset.d.ts +10 -0
  68. package/dist/types/src/preset.d.ts.map +1 -0
  69. package/dist/types/src/savers/browser.d.ts +2 -1
  70. package/dist/types/src/savers/browser.d.ts.map +1 -1
  71. package/dist/types/src/savers/index.d.ts.map +1 -1
  72. package/dist/types/src/telemetry.d.ts +17 -0
  73. package/dist/types/src/telemetry.d.ts.map +1 -0
  74. package/dist/types/src/testing/defaults.d.ts +6 -6
  75. package/dist/types/src/testing/defaults.d.ts.map +1 -1
  76. package/dist/types/src/testing/envs-map.d.ts +12 -14
  77. package/dist/types/src/testing/envs-map.d.ts.map +1 -1
  78. package/dist/types/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +50 -30
  80. package/src/config-service.ts +116 -0
  81. package/src/config.ts +4 -7
  82. package/src/index.ts +6 -3
  83. package/src/loaders/{browser.js → browser.ts} +15 -9
  84. package/src/loaders/index.ts +2 -2
  85. package/src/plugin/browser.ts +11 -0
  86. package/src/plugin/definitions.ts +6 -6
  87. package/src/plugin/index.ts +1 -1
  88. package/src/plugin/types.ts +5 -0
  89. package/src/plugin/vite-plugin.ts +8 -5
  90. package/src/preset.ts +40 -0
  91. package/src/savers/{browser.js → browser.ts} +3 -3
  92. package/src/telemetry.ts +25 -0
  93. package/src/testing/build.js +3 -2
  94. package/README.yml +0 -1
  95. package/dist/lib/node/index.cjs +0 -357
  96. package/dist/lib/node/index.cjs.map +0 -7
  97. package/dist/lib/node/meta.json +0 -1
  98. package/dist/plugin/node/chunk-SLXRWZWZ.cjs +0 -249
  99. package/dist/plugin/node/chunk-SLXRWZWZ.cjs.map +0 -7
  100. package/dist/plugin/node/esbuild-plugin.cjs +0 -45
  101. package/dist/plugin/node/esbuild-plugin.cjs.map +0 -7
  102. package/dist/plugin/node/meta.json +0 -1
  103. package/dist/plugin/node/rollup-plugin.cjs +0 -39
  104. package/dist/plugin/node/rollup-plugin.cjs.map +0 -7
  105. package/dist/plugin/node/vite-plugin.cjs +0 -50
  106. package/dist/plugin/node/vite-plugin.cjs.map +0 -7
  107. package/dist/plugin/node-esm/chunk-PAFU3TJI.mjs.map +0 -7
package/package.json CHANGED
@@ -1,15 +1,49 @@
1
1
  {
2
2
  "name": "@dxos/config",
3
- "version": "0.8.3",
3
+ "version": "0.8.4-main.03d5cd7b56",
4
4
  "description": "Config utilities",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
- "sideEffects": true,
13
+ "sideEffects": false,
10
14
  "type": "module",
15
+ "imports": {
16
+ "#loaders": {
17
+ "source": {
18
+ "browser": "./src/loaders/browser.ts",
19
+ "default": "./src/loaders/index.ts"
20
+ },
21
+ "types": "./dist/types/src/loaders/index.d.ts",
22
+ "browser": "./dist/lib/browser/loaders/browser.mjs",
23
+ "default": "./dist/lib/node-esm/loaders/index.mjs"
24
+ },
25
+ "#savers": {
26
+ "source": {
27
+ "browser": "./src/savers/browser.ts",
28
+ "default": "./src/savers/index.ts"
29
+ },
30
+ "types": "./dist/types/src/savers/index.d.ts",
31
+ "browser": "./dist/lib/browser/savers/browser.mjs",
32
+ "default": "./dist/lib/node-esm/savers/index.mjs"
33
+ },
34
+ "#plugin": {
35
+ "source": {
36
+ "browser": "./src/plugin/browser.ts",
37
+ "default": "./src/plugin/index.ts"
38
+ },
39
+ "types": "./dist/types/src/plugin/index.d.ts",
40
+ "browser": "./dist/lib/browser/plugin/browser.mjs",
41
+ "default": "./dist/lib/node-esm/plugin/index.mjs"
42
+ }
43
+ },
11
44
  "exports": {
12
45
  ".": {
46
+ "source": "./src/index.ts",
13
47
  "types": "./dist/types/src/index.d.ts",
14
48
  "browser": "./dist/lib/browser/index.mjs",
15
49
  "node": {
@@ -18,64 +52,50 @@
18
52
  }
19
53
  },
20
54
  "./esbuild-plugin": {
55
+ "source": "./src/esbuild-plugin/index.ts",
21
56
  "types": "./dist/types/src/esbuild-plugin/index.d.ts",
22
57
  "import": "./dist/plugin/node-esm/esbuild-plugin.mjs",
23
58
  "require": "./dist/plugin/node/esbuild-plugin.cjs"
24
59
  },
25
60
  "./rollup-plugin": {
61
+ "source": "./src/rollup-plugin/index.ts",
26
62
  "types": "./dist/types/src/rollup-plugin/index.d.ts",
27
63
  "import": "./dist/plugin/node-esm/rollup-plugin.mjs",
28
64
  "require": "./dist/plugin/node/rollup-plugin.cjs"
29
65
  },
30
66
  "./vite-plugin": {
67
+ "source": "./src/vite-plugin/index.ts",
31
68
  "types": "./dist/types/src/vite-plugin/index.d.ts",
32
69
  "import": "./dist/plugin/node-esm/vite-plugin.mjs",
33
70
  "require": "./dist/plugin/node/vite-plugin.cjs"
34
71
  }
35
72
  },
36
73
  "main": "dist/lib/node/index.cjs",
37
- "browser": {
38
- "./src/loaders/index.ts": "./src/loaders/browser.js",
39
- "./src/savers/index.ts": "./src/savers/browser.js",
40
- "./src/plugin/index.ts": false,
41
- "./dist/lib/node/index.cjs": "./dist/lib/browser/index.mjs"
42
- },
43
74
  "types": "dist/types/src/index.d.ts",
44
- "typesVersions": {
45
- "*": {
46
- "esbuild-plugin": [
47
- "dist/types/src/esbuild-plugin/index.d.ts"
48
- ],
49
- "rollup-plugin": [
50
- "dist/types/src/rollup-plugin/index.d.ts"
51
- ],
52
- "vite-plugin": [
53
- "dist/types/src/vite-plugin/index.d.ts"
54
- ]
55
- }
56
- },
57
75
  "files": [
58
76
  "dist",
59
77
  "src"
60
78
  ],
61
79
  "dependencies": {
62
- "boolean": "^3.0.1",
63
- "js-yaml": "^4.1.0",
80
+ "@effect/platform": "0.94.4",
81
+ "effect": "3.20.0",
64
82
  "localforage": "^1.10.0",
65
83
  "lodash.defaultsdeep": "^4.6.1",
66
84
  "lodash.ismatch": "^4.4.0",
67
85
  "pkg-up": "^3.1.0",
68
- "@dxos/log": "0.8.3",
69
- "@dxos/node-std": "0.8.3",
70
- "@dxos/protocols": "0.8.3",
71
- "@dxos/util": "0.8.3",
72
- "@dxos/tracing": "0.8.3"
86
+ "yaml": "^2.8.2",
87
+ "@dxos/client-protocol": "0.8.4-main.03d5cd7b56",
88
+ "@dxos/invariant": "0.8.4-main.03d5cd7b56",
89
+ "@dxos/log": "0.8.4-main.03d5cd7b56",
90
+ "@dxos/node-std": "0.8.4-main.03d5cd7b56",
91
+ "@dxos/tracing": "0.8.4-main.03d5cd7b56",
92
+ "@dxos/protocols": "0.8.4-main.03d5cd7b56",
93
+ "@dxos/util": "0.8.4-main.03d5cd7b56"
73
94
  },
74
95
  "devDependencies": {
75
- "@types/js-yaml": "^4.0.5",
76
96
  "@types/lodash.defaultsdeep": "^4.6.6",
77
97
  "@types/lodash.ismatch": "^4.4.9",
78
- "webpack": "^5.88.2"
98
+ "webpack": "^5.104.1"
79
99
  },
80
100
  "publishConfig": {
81
101
  "access": "public"
@@ -0,0 +1,116 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as FileSystem from '@effect/platform/FileSystem';
6
+ import * as Context from 'effect/Context';
7
+ import * as Effect from 'effect/Effect';
8
+ import * as Layer from 'effect/Layer';
9
+ import * as Option from 'effect/Option';
10
+ import { dirname } from 'node:path';
11
+ import * as Yaml from 'yaml';
12
+
13
+ import { DX_CONFIG, DX_DATA, getProfileConfigPath, getProfilePath } from '@dxos/client-protocol';
14
+ import { invariant } from '@dxos/invariant';
15
+
16
+ import { Config } from './config';
17
+
18
+ export const memoryConfig = new Config({
19
+ runtime: {
20
+ client: {
21
+ edgeFeatures: {
22
+ echoReplicator: true,
23
+ feedReplicator: true,
24
+ signaling: true,
25
+ agents: true,
26
+ },
27
+ },
28
+ },
29
+ });
30
+
31
+ export const defaultConfig = new Config({
32
+ runtime: {
33
+ client: {
34
+ edgeFeatures: {
35
+ echoReplicator: true,
36
+ feedReplicator: true,
37
+ signaling: true,
38
+ agents: true,
39
+ },
40
+ storage: {
41
+ persistent: true,
42
+ },
43
+ },
44
+ services: {
45
+ edge: {
46
+ url: 'wss://edge-production.dxos.workers.dev/',
47
+ },
48
+ iceProviders: [
49
+ {
50
+ urls: 'https://edge-production.dxos.workers.dev/ice',
51
+ },
52
+ ],
53
+ ai: {
54
+ server: 'https://ai-service.dxos.workers.dev',
55
+ },
56
+ ipfs: {
57
+ server: 'https://api.ipfs.dxos.network/api/v0',
58
+ gateway: 'https://gateway.ipfs.dxos.network/ipfs',
59
+ },
60
+ },
61
+ },
62
+ });
63
+
64
+ export class ConfigService extends Context.Tag('ConfigService')<ConfigService, Config>() {
65
+ static layerMemory = Layer.effect(ConfigService, Effect.succeed(memoryConfig));
66
+
67
+ static fromConfig = (config: Config) => Layer.succeed(ConfigService, config);
68
+
69
+ static load = (args: { config: Option.Option<string>; profile: string }) => {
70
+ const defaultConfigPath = getProfileConfigPath(DX_CONFIG, args.profile);
71
+ return Effect.gen(function* () {
72
+ const fs = yield* FileSystem.FileSystem;
73
+ const configPath = Option.getOrElse(args.config, () => defaultConfigPath);
74
+ const configContent = yield* fs.readFileString(configPath);
75
+ const configValues = Yaml.parse(configContent);
76
+ return ConfigService.of(new Config(configValues, profileBuiltinDefaults(args.profile).values));
77
+ }).pipe(
78
+ // If the config file doesn't exist, create it.
79
+ Effect.catchTag('SystemError', () =>
80
+ Effect.gen(function* () {
81
+ const configValues = defaultConfig.values;
82
+ const fs = yield* FileSystem.FileSystem;
83
+ const pathToCreate = Option.getOrElse(args.config, () => defaultConfigPath);
84
+ yield* fs.makeDirectory(dirname(pathToCreate), { recursive: true });
85
+ yield* fs.writeFileString(pathToCreate, Yaml.stringify(configValues));
86
+ return ConfigService.of(new Config(configValues));
87
+ }),
88
+ ),
89
+ );
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Default config for a profile.
95
+ * Always merged with the default config.
96
+ */
97
+ const profileBuiltinDefaults = (profile: string) => {
98
+ invariant(!profile.endsWith('.yml'));
99
+
100
+ return new Config({
101
+ runtime: {
102
+ client: {
103
+ edgeFeatures: {
104
+ echoReplicator: true,
105
+ feedReplicator: true,
106
+ signaling: true,
107
+ agents: true,
108
+ },
109
+ storage: {
110
+ persistent: true,
111
+ dataRoot: getProfilePath(DX_DATA, profile),
112
+ },
113
+ },
114
+ },
115
+ });
116
+ };
package/src/config.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import { boolean } from 'boolean';
6
5
  import defaultsDeep from 'lodash.defaultsdeep';
7
6
  import isMatch from 'lodash.ismatch';
8
7
 
@@ -19,7 +18,6 @@ const configRootType = schema.getCodecForType('dxos.config.Config');
19
18
 
20
19
  /**
21
20
  * Maps the given objects onto a flattened set of (key x values).
22
- *
23
21
  * Expects parsed yaml content of the form:
24
22
  *
25
23
  * ```
@@ -36,12 +34,11 @@ export const mapFromKeyValues = (spec: MappingSpec, values: Record<string, any>)
36
34
 
37
35
  for (const [key, { path, type }] of Object.entries(spec)) {
38
36
  let value = values[key];
39
-
40
37
  if (value !== undefined) {
41
38
  if (type) {
42
39
  switch (type) {
43
40
  case 'boolean': {
44
- value = boolean(value);
41
+ value = String(value).toLowerCase() === 'true' || value === '1';
45
42
  break;
46
43
  }
47
44
 
@@ -101,16 +98,16 @@ export const mapToKeyValues = (spec: MappingSpec, values: any) => {
101
98
  */
102
99
  export const validateConfig = (config: ConfigProto): ConfigProto => {
103
100
  if (!('version' in config)) {
104
- throw new InvalidConfigError('Version not specified');
101
+ throw new InvalidConfigError({ message: 'Version not specified' });
105
102
  }
106
103
 
107
104
  if (config?.version !== 1) {
108
- throw new InvalidConfigError(`Invalid config version: ${config.version}`);
105
+ throw new InvalidConfigError({ message: `Invalid config version: ${config.version}` });
109
106
  }
110
107
 
111
108
  const error = configRootType.protoType.verify(config);
112
109
  if (error) {
113
- throw new InvalidConfigError(error);
110
+ throw new InvalidConfigError({ message: String(error) });
114
111
  }
115
112
 
116
113
  return config;
package/src/index.ts CHANGED
@@ -8,7 +8,10 @@ export * as defs from '@dxos/protocols/proto/dxos/config';
8
8
  export { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
9
9
 
10
10
  export * from './config';
11
- export * from './loaders';
12
- export * from './savers';
13
- export * from './plugin';
11
+ export * from './config-service';
12
+ export * from '#loaders';
13
+ export * from '#savers';
14
+ export * from '#plugin';
15
+ export * from './telemetry';
14
16
  export * from './types';
17
+ export * from './preset';
@@ -4,19 +4,25 @@
4
4
 
5
5
  /* THIS FILE WILL BE LOADED BY CONTEXT REPLACEMENT PLUGIN IN BROWSER ENVS. */
6
6
 
7
- /* global __DXOS_CONFIG__ __CONFIG_ENVS__ __CONFIG_DEFAULTS__ __CONFIG_LOCAL__ */
8
-
9
7
  import localforage from 'localforage';
10
8
 
11
9
  import { log } from '@dxos/log';
10
+ import { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
11
+
12
+ declare const __DXOS_CONFIG__: { publicUrl?: string; dynamic?: boolean };
13
+ declare const __CONFIG_ENVS__: Partial<ConfigProto> | undefined;
14
+ declare const __CONFIG_DEFAULTS__: Partial<ConfigProto> | undefined;
15
+ declare const __CONFIG_LOCAL__: Partial<ConfigProto> | undefined;
12
16
 
13
17
  const CONFIG_ENDPOINT = '/.well-known/dx/config';
14
18
 
15
- export const Local = () => {
19
+ export const Profile = (_profile = 'default'): Partial<ConfigProto> => ({});
20
+
21
+ export const Local = (): Partial<ConfigProto> => {
16
22
  return typeof __CONFIG_LOCAL__ !== 'undefined' ? __CONFIG_LOCAL__ : {};
17
23
  };
18
24
 
19
- export const Dynamics = async () => {
25
+ export const Dynamics = async (): Promise<Partial<ConfigProto>> => {
20
26
  const { publicUrl = '', dynamic } = __DXOS_CONFIG__;
21
27
  if (!dynamic) {
22
28
  log('dynamics disabled');
@@ -32,20 +38,20 @@ export const Dynamics = async () => {
32
38
  });
33
39
  };
34
40
 
35
- export const Envs = () => {
41
+ export const Envs = (_basePath?: string): Partial<ConfigProto> => {
36
42
  return typeof __CONFIG_ENVS__ !== 'undefined' ? __CONFIG_ENVS__ : {};
37
43
  };
38
44
 
39
- export const Defaults = () => {
45
+ export const Defaults = (_basePath?: string): Partial<ConfigProto> => {
40
46
  return typeof __CONFIG_DEFAULTS__ !== 'undefined' ? __CONFIG_DEFAULTS__ : {};
41
47
  };
42
48
 
43
49
  /**
44
50
  * Settings config from browser storage.
45
51
  */
46
- export const Storage = async () => {
52
+ export const Storage = async (): Promise<Partial<ConfigProto>> => {
47
53
  try {
48
- const config = await localforage.getItem('dxos.org/settings/config');
54
+ const config = await localforage.getItem<Partial<ConfigProto>>('org.dxos.settings.config');
49
55
  if (config) {
50
56
  return config;
51
57
  }
@@ -55,7 +61,7 @@ export const Storage = async () => {
55
61
  return {};
56
62
  };
57
63
 
58
- export const Remote = (target, authenticationToken) => {
64
+ export const Remote = (target: string | undefined, authenticationToken?: string): Partial<ConfigProto> => {
59
65
  if (!target) {
60
66
  return {};
61
67
  }
@@ -2,9 +2,9 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import yaml from 'js-yaml';
6
5
  import fs from 'node:fs';
7
6
  import path from 'node:path';
7
+ import { parse } from 'yaml';
8
8
 
9
9
  import { log } from '@dxos/log';
10
10
  import { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
@@ -18,7 +18,7 @@ const DEFAULT_BASE_PATH = path.resolve(process.cwd(), 'config');
18
18
 
19
19
  const maybeLoadFile = (file: string): any => {
20
20
  try {
21
- return yaml.load(fs.readFileSync(file, { encoding: 'utf8' }));
21
+ return parse(fs.readFileSync(file, { encoding: 'utf8' }));
22
22
  } catch (err: any) {
23
23
  // Ignored.
24
24
  }
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ // Browser stub for plugin module - plugins are build-time only.
6
+
7
+ export type * from './types';
8
+
9
+ export const definitions = (): Record<string, unknown> => {
10
+ throw new Error('Config plugin definitions are not available in the browser');
11
+ };
@@ -2,17 +2,18 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import yaml from 'js-yaml';
6
5
  import { execSync } from 'node:child_process';
7
6
  import { readFileSync } from 'node:fs';
8
7
  import { resolve } from 'node:path';
9
8
  import pkgUp from 'pkg-up';
9
+ import { parse } from 'yaml';
10
10
 
11
+ import { invariant } from '@dxos/invariant';
11
12
  import { log } from '@dxos/log';
12
13
  import { setDeep } from '@dxos/util';
13
14
 
14
- import { type ConfigPluginOpts } from './types';
15
15
  import { mapFromKeyValues } from '../config';
16
+ import { type ConfigPluginOpts } from './types';
16
17
 
17
18
  const CWD = process.cwd();
18
19
 
@@ -28,17 +29,16 @@ export const definitions = ({
28
29
  __CONFIG_DEFAULTS__: configPath?.length ? configPath : resolve(CWD, 'dx.yml'),
29
30
  __CONFIG_ENVS__: envPath?.length ? envPath : resolve(CWD, 'dx-env.yml'),
30
31
  } as { [key: string]: string };
31
-
32
32
  if (mode !== 'production') {
33
33
  KEYS_TO_FILE.__CONFIG_LOCAL__ = devPath ?? resolve(CWD, 'dx-local.yml');
34
34
  }
35
35
 
36
36
  return Object.entries(KEYS_TO_FILE).reduce(
37
37
  (prev, [key, value]) => {
38
+ invariant(key);
38
39
  let content = {};
39
-
40
40
  try {
41
- content = yaml.load(readFileSync(value, 'utf-8')) as any;
41
+ content = parse(readFileSync(value, 'utf-8')) as any;
42
42
 
43
43
  // Map environment variables to config values.
44
44
  if (key === '__CONFIG_ENVS__') {
@@ -85,10 +85,10 @@ export const definitions = ({
85
85
  };
86
86
  },
87
87
  {
88
- __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },
89
88
  __CONFIG_DEFAULTS__: {},
90
89
  __CONFIG_ENVS__: {},
91
90
  __CONFIG_LOCAL__: {},
91
+ __DXOS_CONFIG__: { dynamic: mode === 'production', publicUrl },
92
92
  },
93
93
  );
94
94
  };
@@ -3,4 +3,4 @@
3
3
  //
4
4
 
5
5
  export * from './definitions';
6
- export * from './types';
6
+ export type * from './types';
@@ -3,6 +3,11 @@
3
3
  //
4
4
 
5
5
  export interface ConfigPluginOpts {
6
+ /**
7
+ * Root directory of the project.
8
+ */
9
+ root?: string;
10
+
6
11
  /**
7
12
  * Path to the DX config files, defaults to current working directory.
8
13
  */
@@ -3,17 +3,20 @@
3
3
  //
4
4
 
5
5
  import { resolve } from 'node:path';
6
- import type { Plugin } from 'vite';
6
+ import { type Plugin } from 'vite';
7
7
 
8
8
  import { definitions } from './definitions';
9
9
  import { type ConfigPluginOpts } from './types';
10
10
 
11
11
  export const ConfigPlugin = (options: ConfigPluginOpts = {}): Plugin => ({
12
12
  name: 'dxos-config',
13
- config: ({ root }) => {
14
- const configPath = root && resolve(root, options.configPath ?? 'dx.yml');
15
- const envPath = root && resolve(root, options.envPath ?? 'dx-env.yml');
16
- const devPath = root && resolve(root, options.devPath ?? 'dx-local.yml');
13
+ config: () => {
14
+ // Update paths.
15
+ const configPath = options.root && resolve(options.root, options.configPath ?? 'dx.yml');
16
+ const envPath = options.root && resolve(options.root, options.envPath ?? 'dx-env.yml');
17
+ // TODO(burdon): Change to dx-dev.yml?
18
+ const devPath = options.root && resolve(options.root, options.devPath ?? 'dx-local.yml');
19
+
17
20
  const define = Object.entries(definitions({ ...options, configPath, envPath, devPath })).reduce(
18
21
  (define, [key, value]) => {
19
22
  define[key] = JSON.stringify(value);
package/src/preset.ts ADDED
@@ -0,0 +1,40 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Match from 'effect/Match';
6
+
7
+ import { Config } from './config';
8
+
9
+ export type ConfigPresetOptions = {
10
+ /**
11
+ * Edge service.
12
+ * @default main
13
+ */
14
+ edge?: 'local' | 'dev' | 'main' | 'production';
15
+ };
16
+
17
+ export const configPreset = ({ edge = 'main' }: ConfigPresetOptions = {}) =>
18
+ new Config({
19
+ version: 1,
20
+ runtime: {
21
+ client: {
22
+ edgeFeatures: {
23
+ signaling: true,
24
+ echoReplicator: true,
25
+ feedReplicator: true,
26
+ },
27
+ },
28
+ services: {
29
+ edge: {
30
+ url: Match.value(edge).pipe(
31
+ Match.when('local', () => 'http://localhost:8787'),
32
+ Match.when('dev', () => 'https://edge.dxos.workers.dev'),
33
+ Match.when('main', () => 'https://edge-main.dxos.workers.dev'),
34
+ Match.when('production', () => 'https://edge-production.dxos.workers.dev'),
35
+ Match.exhaustive,
36
+ ),
37
+ },
38
+ },
39
+ },
40
+ });
@@ -7,10 +7,11 @@
7
7
  import localforage from 'localforage';
8
8
 
9
9
  import { log } from '@dxos/log';
10
+ import { type Config as ConfigProto } from '@dxos/protocols/proto/dxos/config';
10
11
 
11
12
  let PERFORMING_CONFIG_SAVE = false;
12
13
 
13
- export const SaveConfig = async (config) => {
14
+ export const SaveConfig = async (config: ConfigProto): Promise<void> => {
14
15
  if (PERFORMING_CONFIG_SAVE) {
15
16
  log.warn('Already performing config save');
16
17
  return;
@@ -18,10 +19,9 @@ export const SaveConfig = async (config) => {
18
19
  PERFORMING_CONFIG_SAVE = true;
19
20
 
20
21
  try {
21
- await localforage.setItem('dxos.org/settings/config', config);
22
+ await localforage.setItem('org.dxos.settings.config', config);
22
23
  } catch (err) {
23
24
  log.warn('Failed to save config', { err });
24
- return {};
25
25
  } finally {
26
26
  PERFORMING_CONFIG_SAVE = false;
27
27
  }
@@ -0,0 +1,25 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { isNode } from '@dxos/util';
6
+
7
+ import { type Config } from './config';
8
+
9
+ /**
10
+ * Resolves the telemetry tag used as the `X-DXOS-Client-Tag` header on edge
11
+ * requests AND as the `ctx.tag` attribute / resource on observability traces.
12
+ *
13
+ * Keeping a single resolver ensures the same tag identifies a session across
14
+ * edge and telemetry tiers. Precedence:
15
+ *
16
+ * 1. `config.runtime.app.env.DX_TELEMETRY_TAG` — the explicit, deterministic
17
+ * path. Populated from `.env`/build-time by the app's config loaders.
18
+ * 2. `process.env.DX_TELEMETRY_TAG` — Node-only, for dev/CI convenience.
19
+ *
20
+ * Returns `undefined` when unset; callers should no-op on undefined rather
21
+ * than stamping empty strings.
22
+ */
23
+ export const resolveTelemetryTag = (config?: Config): string | undefined => {
24
+ return config?.get('runtime.app.env.DX_TELEMETRY_TAG') ?? (isNode() ? process.env.DX_TELEMETRY_TAG : undefined);
25
+ };
@@ -5,9 +5,10 @@
5
5
  // This script is used to test whether the esbuild config plugin is properly injecting config constants.
6
6
  // TODO(wittjosiah): Automate this test.
7
7
 
8
- const { build } = require('esbuild');
9
8
  const { join } = require('node:path');
10
9
 
10
+ const { build } = require('esbuild');
11
+
11
12
  // eslint-disable-next-line
12
13
  // @ts-ignore
13
14
  const { ConfigPlugin } = require('../../dist/plugin/node/esbuild-plugin.cjs');
@@ -17,5 +18,5 @@ void build({
17
18
  outdir: join(__dirname, '../../out'),
18
19
  write: true,
19
20
  bundle: true,
20
- plugins: [ConfigPlugin()],
21
+ plugins: [ConfigPlugin({ root: __dirname })],
21
22
  });
package/README.yml DELETED
@@ -1 +0,0 @@
1
- apiReferenceUrl: https://docs.dxos.org/api/@dxos/config