@quonfig/node 0.0.2 → 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 +39 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +39 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1115,7 +1115,10 @@ function shouldLog(args) {
|
|
|
1115
1115
|
while (loggerNameWithPrefix.includes(".")) {
|
|
1116
1116
|
const resolvedLevel = getConfig(loggerNameWithPrefix);
|
|
1117
1117
|
if (resolvedLevel !== void 0) {
|
|
1118
|
-
|
|
1118
|
+
const resolvedLevelNum = parseLevel(resolvedLevel);
|
|
1119
|
+
if (resolvedLevelNum !== void 0) {
|
|
1120
|
+
return resolvedLevelNum <= desiredLevel;
|
|
1121
|
+
}
|
|
1119
1122
|
}
|
|
1120
1123
|
loggerNameWithPrefix = loggerNameWithPrefix.slice(
|
|
1121
1124
|
0,
|
|
@@ -1129,8 +1132,8 @@ function shouldLog(args) {
|
|
|
1129
1132
|
var import_fs = require("fs");
|
|
1130
1133
|
var import_path = require("path");
|
|
1131
1134
|
var CONFIG_SUBDIRS = ["configs", "feature-flags", "segments", "schemas", "log-levels"];
|
|
1132
|
-
function loadEnvelopeFromDatadir(datadir) {
|
|
1133
|
-
const environmentId =
|
|
1135
|
+
function loadEnvelopeFromDatadir(datadir, environment) {
|
|
1136
|
+
const environmentId = resolveEnvironment((0, import_path.join)(datadir, "environments.json"), environment);
|
|
1134
1137
|
const configs = [];
|
|
1135
1138
|
for (const subdir of CONFIG_SUBDIRS) {
|
|
1136
1139
|
const dir = (0, import_path.join)(datadir, subdir);
|
|
@@ -1151,7 +1154,12 @@ function loadEnvelopeFromDatadir(datadir) {
|
|
|
1151
1154
|
}
|
|
1152
1155
|
};
|
|
1153
1156
|
}
|
|
1154
|
-
function
|
|
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
|
+
}
|
|
1155
1163
|
if (!(0, import_fs.existsSync)(environmentsPath)) {
|
|
1156
1164
|
throw new Error(`[quonfig] Datadir is missing environments.json: ${environmentsPath}`);
|
|
1157
1165
|
}
|
|
@@ -1159,10 +1167,12 @@ function loadEnvironmentId(environmentsPath) {
|
|
|
1159
1167
|
const candidates = normalizeEnvironmentCandidates(
|
|
1160
1168
|
isWrappedEnvironmentList(environments) ? environments.environments : environments
|
|
1161
1169
|
);
|
|
1162
|
-
if (candidates.length
|
|
1163
|
-
|
|
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
|
+
);
|
|
1164
1174
|
}
|
|
1165
|
-
return
|
|
1175
|
+
return environment;
|
|
1166
1176
|
}
|
|
1167
1177
|
function isWrappedEnvironmentList(value) {
|
|
1168
1178
|
return Boolean(
|
|
@@ -1519,6 +1529,9 @@ var BoundQuonfig = class _BoundQuonfig {
|
|
|
1519
1529
|
contexts: mergeContexts(this.boundContexts, args.contexts)
|
|
1520
1530
|
});
|
|
1521
1531
|
}
|
|
1532
|
+
async flush() {
|
|
1533
|
+
return this.client.flush();
|
|
1534
|
+
}
|
|
1522
1535
|
keys() {
|
|
1523
1536
|
return this.client.keys();
|
|
1524
1537
|
}
|
|
@@ -1539,6 +1552,7 @@ var Quonfig = class {
|
|
|
1539
1552
|
initTimeout;
|
|
1540
1553
|
datadir;
|
|
1541
1554
|
datafile;
|
|
1555
|
+
requestedEnvironment;
|
|
1542
1556
|
store;
|
|
1543
1557
|
evaluator;
|
|
1544
1558
|
resolver;
|
|
@@ -1569,6 +1583,7 @@ var Quonfig = class {
|
|
|
1569
1583
|
this.initTimeout = options.initTimeout ?? DEFAULT_INIT_TIMEOUT;
|
|
1570
1584
|
this.datadir = options.datadir;
|
|
1571
1585
|
this.datafile = options.datafile;
|
|
1586
|
+
this.requestedEnvironment = options.environment || process.env.QUONFIG_ENVIRONMENT || "";
|
|
1572
1587
|
this.instanceHash = (0, import_crypto3.randomUUID)();
|
|
1573
1588
|
this.store = new ConfigStore();
|
|
1574
1589
|
this.evaluator = new Evaluator(this.store);
|
|
@@ -1757,6 +1772,22 @@ var Quonfig = class {
|
|
|
1757
1772
|
inContext(contexts) {
|
|
1758
1773
|
return new BoundQuonfig(this, mergeContexts(this.globalContext, contexts));
|
|
1759
1774
|
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Flush pending telemetry data immediately. Useful in serverless environments
|
|
1777
|
+
* (Vercel, Lambda) where the process may be frozen before the background
|
|
1778
|
+
* timer fires.
|
|
1779
|
+
*
|
|
1780
|
+
* ```typescript
|
|
1781
|
+
* const value = quonfig.get("my-flag", contexts);
|
|
1782
|
+
* await quonfig.flush();
|
|
1783
|
+
* return NextResponse.json({ value });
|
|
1784
|
+
* ```
|
|
1785
|
+
*/
|
|
1786
|
+
async flush() {
|
|
1787
|
+
if (this.telemetryReporter) {
|
|
1788
|
+
await this.telemetryReporter.sync();
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1760
1791
|
/**
|
|
1761
1792
|
* Close the SDK. Stops SSE, polling, and telemetry.
|
|
1762
1793
|
*/
|
|
@@ -1801,7 +1832,7 @@ var Quonfig = class {
|
|
|
1801
1832
|
}
|
|
1802
1833
|
loadLocalEnvelope() {
|
|
1803
1834
|
if (this.datadir) {
|
|
1804
|
-
return loadEnvelopeFromDatadir(this.datadir);
|
|
1835
|
+
return loadEnvelopeFromDatadir(this.datadir, this.requestedEnvironment);
|
|
1805
1836
|
}
|
|
1806
1837
|
if (typeof this.datafile === "string") {
|
|
1807
1838
|
const raw = (0, import_fs2.readFileSync)(this.datafile, "utf-8");
|