@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.d.cts CHANGED
@@ -102,6 +102,8 @@ interface QuonfigOptions {
102
102
  initTimeout?: number;
103
103
  datadir?: string;
104
104
  datafile?: string | object;
105
+ /** Environment name to use in datadir mode. Supersedes the QUONFIG_ENVIRONMENT env var. */
106
+ environment?: string;
105
107
  }
106
108
  interface EvalMatch {
107
109
  isMatch: boolean;
@@ -229,6 +231,7 @@ declare class Quonfig {
229
231
  private readonly initTimeout;
230
232
  private readonly datadir?;
231
233
  private readonly datafile?;
234
+ private readonly requestedEnvironment;
232
235
  private store;
233
236
  private evaluator;
234
237
  private resolver;
package/dist/index.d.ts CHANGED
@@ -102,6 +102,8 @@ interface QuonfigOptions {
102
102
  initTimeout?: number;
103
103
  datadir?: string;
104
104
  datafile?: string | object;
105
+ /** Environment name to use in datadir mode. Supersedes the QUONFIG_ENVIRONMENT env var. */
106
+ environment?: string;
105
107
  }
106
108
  interface EvalMatch {
107
109
  isMatch: boolean;
@@ -229,6 +231,7 @@ declare class Quonfig {
229
231
  private readonly initTimeout;
230
232
  private readonly datadir?;
231
233
  private readonly datafile?;
234
+ private readonly requestedEnvironment;
232
235
  private store;
233
236
  private evaluator;
234
237
  private resolver;
package/dist/index.js CHANGED
@@ -1039,8 +1039,8 @@ function shouldLog(args) {
1039
1039
  import { existsSync, readdirSync, readFileSync } from "fs";
1040
1040
  import { join } from "path";
1041
1041
  var CONFIG_SUBDIRS = ["configs", "feature-flags", "segments", "schemas", "log-levels"];
1042
- function loadEnvelopeFromDatadir(datadir) {
1043
- const environmentId = loadEnvironmentId(join(datadir, "environments.json"));
1042
+ function loadEnvelopeFromDatadir(datadir, environment) {
1043
+ const environmentId = resolveEnvironment(join(datadir, "environments.json"), environment);
1044
1044
  const configs = [];
1045
1045
  for (const subdir of CONFIG_SUBDIRS) {
1046
1046
  const dir = join(datadir, subdir);
@@ -1061,7 +1061,12 @@ function loadEnvelopeFromDatadir(datadir) {
1061
1061
  }
1062
1062
  };
1063
1063
  }
1064
- function loadEnvironmentId(environmentsPath) {
1064
+ function resolveEnvironment(environmentsPath, environment) {
1065
+ if (!environment) {
1066
+ throw new Error(
1067
+ "[quonfig] Environment required for datadir mode; set the `environment` option or QUONFIG_ENVIRONMENT env var"
1068
+ );
1069
+ }
1065
1070
  if (!existsSync(environmentsPath)) {
1066
1071
  throw new Error(`[quonfig] Datadir is missing environments.json: ${environmentsPath}`);
1067
1072
  }
@@ -1069,10 +1074,12 @@ function loadEnvironmentId(environmentsPath) {
1069
1074
  const candidates = normalizeEnvironmentCandidates(
1070
1075
  isWrappedEnvironmentList(environments) ? environments.environments : environments
1071
1076
  );
1072
- if (candidates.length === 0) {
1073
- return "";
1077
+ if (candidates.length > 0 && !candidates.includes(environment)) {
1078
+ throw new Error(
1079
+ `[quonfig] Environment "${environment}" not found in workspace; available environments: ${candidates.join(", ")}`
1080
+ );
1074
1081
  }
1075
- return candidates[0];
1082
+ return environment;
1076
1083
  }
1077
1084
  function isWrappedEnvironmentList(value) {
1078
1085
  return Boolean(
@@ -1452,6 +1459,7 @@ var Quonfig = class {
1452
1459
  initTimeout;
1453
1460
  datadir;
1454
1461
  datafile;
1462
+ requestedEnvironment;
1455
1463
  store;
1456
1464
  evaluator;
1457
1465
  resolver;
@@ -1482,6 +1490,7 @@ var Quonfig = class {
1482
1490
  this.initTimeout = options.initTimeout ?? DEFAULT_INIT_TIMEOUT;
1483
1491
  this.datadir = options.datadir;
1484
1492
  this.datafile = options.datafile;
1493
+ this.requestedEnvironment = options.environment || process.env.QUONFIG_ENVIRONMENT || "";
1485
1494
  this.instanceHash = randomUUID();
1486
1495
  this.store = new ConfigStore();
1487
1496
  this.evaluator = new Evaluator(this.store);
@@ -1730,7 +1739,7 @@ var Quonfig = class {
1730
1739
  }
1731
1740
  loadLocalEnvelope() {
1732
1741
  if (this.datadir) {
1733
- return loadEnvelopeFromDatadir(this.datadir);
1742
+ return loadEnvelopeFromDatadir(this.datadir, this.requestedEnvironment);
1734
1743
  }
1735
1744
  if (typeof this.datafile === "string") {
1736
1745
  const raw = readFileSync2(this.datafile, "utf-8");