@quonfig/node 0.0.3 → 0.0.4

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/index.cjs CHANGED
@@ -1132,8 +1132,8 @@ function shouldLog(args) {
1132
1132
  var import_fs = require("fs");
1133
1133
  var import_path = require("path");
1134
1134
  var CONFIG_SUBDIRS = ["configs", "feature-flags", "segments", "schemas", "log-levels"];
1135
- function loadEnvelopeFromDatadir(datadir) {
1136
- const environmentId = loadEnvironmentId((0, import_path.join)(datadir, "environments.json"));
1135
+ function loadEnvelopeFromDatadir(datadir, environment) {
1136
+ const environmentId = resolveEnvironment((0, import_path.join)(datadir, "environments.json"), environment);
1137
1137
  const configs = [];
1138
1138
  for (const subdir of CONFIG_SUBDIRS) {
1139
1139
  const dir = (0, import_path.join)(datadir, subdir);
@@ -1154,7 +1154,12 @@ function loadEnvelopeFromDatadir(datadir) {
1154
1154
  }
1155
1155
  };
1156
1156
  }
1157
- function loadEnvironmentId(environmentsPath) {
1157
+ function resolveEnvironment(environmentsPath, environment) {
1158
+ if (!environment) {
1159
+ throw new Error(
1160
+ "[quonfig] Environment required for datadir mode; set the `environment` option or QUONFIG_ENVIRONMENT env var"
1161
+ );
1162
+ }
1158
1163
  if (!(0, import_fs.existsSync)(environmentsPath)) {
1159
1164
  throw new Error(`[quonfig] Datadir is missing environments.json: ${environmentsPath}`);
1160
1165
  }
@@ -1162,10 +1167,12 @@ function loadEnvironmentId(environmentsPath) {
1162
1167
  const candidates = normalizeEnvironmentCandidates(
1163
1168
  isWrappedEnvironmentList(environments) ? environments.environments : environments
1164
1169
  );
1165
- if (candidates.length === 0) {
1166
- return "";
1170
+ if (candidates.length > 0 && !candidates.includes(environment)) {
1171
+ throw new Error(
1172
+ `[quonfig] Environment "${environment}" not found in workspace; available environments: ${candidates.join(", ")}`
1173
+ );
1167
1174
  }
1168
- return candidates[0];
1175
+ return environment;
1169
1176
  }
1170
1177
  function isWrappedEnvironmentList(value) {
1171
1178
  return Boolean(
@@ -1545,6 +1552,7 @@ var Quonfig = class {
1545
1552
  initTimeout;
1546
1553
  datadir;
1547
1554
  datafile;
1555
+ requestedEnvironment;
1548
1556
  store;
1549
1557
  evaluator;
1550
1558
  resolver;
@@ -1575,6 +1583,7 @@ var Quonfig = class {
1575
1583
  this.initTimeout = options.initTimeout ?? DEFAULT_INIT_TIMEOUT;
1576
1584
  this.datadir = options.datadir;
1577
1585
  this.datafile = options.datafile;
1586
+ this.requestedEnvironment = options.environment || process.env.QUONFIG_ENVIRONMENT || "";
1578
1587
  this.instanceHash = (0, import_crypto3.randomUUID)();
1579
1588
  this.store = new ConfigStore();
1580
1589
  this.evaluator = new Evaluator(this.store);
@@ -1823,7 +1832,7 @@ var Quonfig = class {
1823
1832
  }
1824
1833
  loadLocalEnvelope() {
1825
1834
  if (this.datadir) {
1826
- return loadEnvelopeFromDatadir(this.datadir);
1835
+ return loadEnvelopeFromDatadir(this.datadir, this.requestedEnvironment);
1827
1836
  }
1828
1837
  if (typeof this.datafile === "string") {
1829
1838
  const raw = (0, import_fs2.readFileSync)(this.datafile, "utf-8");