@vercel/flags-core 1.10.1 → 1.10.3
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/CHANGELOG.md +14 -0
- package/dist/{chunk-CAVQRHGX.js → chunk-2P2UTT7O.js} +65 -23
- package/dist/chunk-2P2UTT7O.js.map +1 -0
- package/dist/{chunk-EW4YJU7V.cjs → chunk-BEQ3MX7Z.cjs} +76 -34
- package/dist/chunk-BEQ3MX7Z.cjs.map +1 -0
- package/dist/{chunk-R3QYUMRA.cjs → chunk-EGGUENXP.cjs} +77 -35
- package/dist/chunk-EGGUENXP.cjs.map +1 -0
- package/dist/{chunk-ZY7CHPJG.js → chunk-OIOT7N7A.js} +65 -23
- package/dist/chunk-OIOT7N7A.js.map +1 -0
- package/dist/index.default.cjs +2 -2
- package/dist/index.default.d.cts +5 -2
- package/dist/index.default.d.ts +5 -2
- package/dist/index.default.js +1 -1
- package/dist/index.next-js.cjs +2 -2
- package/dist/index.next-js.d.cts +5 -2
- package/dist/index.next-js.d.ts +5 -2
- package/dist/index.next-js.js +1 -1
- package/dist/openfeature.default.cjs +2 -2
- package/dist/openfeature.default.js +1 -1
- package/dist/openfeature.next-js.cjs +2 -2
- package/dist/openfeature.next-js.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-CAVQRHGX.js.map +0 -1
- package/dist/chunk-EW4YJU7V.cjs.map +0 -1
- package/dist/chunk-R3QYUMRA.cjs.map +0 -1
- package/dist/chunk-ZY7CHPJG.js.map +0 -1
|
@@ -559,7 +559,7 @@ function bulkEvaluate(flags, shared) {
|
|
|
559
559
|
}
|
|
560
560
|
|
|
561
561
|
// package.json
|
|
562
|
-
var version = "1.10.
|
|
562
|
+
var version = "1.10.3";
|
|
563
563
|
|
|
564
564
|
// src/lib/report-value.ts
|
|
565
565
|
function internalReportValue(key, value, data) {
|
|
@@ -1087,19 +1087,28 @@ function unauthorizedMessage(sourceProjectId) {
|
|
|
1087
1087
|
if (!sourceProjectId) {
|
|
1088
1088
|
return "unauthorized (401)";
|
|
1089
1089
|
}
|
|
1090
|
-
return `unauthorized (401): this deployment is not allowed to read the flags of project "${sourceProjectId}". Check that the project is connected
|
|
1090
|
+
return `unauthorized (401): this deployment is not allowed to read the flags of project "${sourceProjectId}". Check that the project is connected. See https://vercel.com/docs/flags/vercel-flags/project-connections`;
|
|
1091
1091
|
}
|
|
1092
|
+
var oidcTokenMessage = [
|
|
1093
|
+
"@vercel/flags-core: Failed to get OIDC token.",
|
|
1094
|
+
"Are you running in a Vercel Environment where OIDC tokens are available?",
|
|
1095
|
+
"Did you mean to use an SDK Key instead? Use the environment variable FLAGS or pass it directly to the client."
|
|
1096
|
+
].join(" ");
|
|
1097
|
+
var missingCredentials = /`vc link|vercel login|^The 'x-vercel-oidc-token' header is missing from the request\.$/;
|
|
1098
|
+
var OidcTokenError = class extends Error {
|
|
1099
|
+
constructor(cause) {
|
|
1100
|
+
super(oidcTokenMessage, { cause });
|
|
1101
|
+
this.name = "OidcTokenError";
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1092
1104
|
async function getOidcToken() {
|
|
1093
1105
|
try {
|
|
1094
1106
|
return await _oidc.getVercelOidcToken.call(void 0, );
|
|
1095
|
-
} catch (
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
"Did you mean to use an SDK Key instead? Use the environment variable FLAGS or pass it directly to the client."
|
|
1101
|
-
].join(" ")
|
|
1102
|
-
);
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
if (error instanceof Error && missingCredentials.test(error.message)) {
|
|
1109
|
+
throw new OidcTokenError(error);
|
|
1110
|
+
}
|
|
1111
|
+
throw new Error(oidcTokenMessage, { cause: error });
|
|
1103
1112
|
}
|
|
1104
1113
|
}
|
|
1105
1114
|
function getProjectIdFromOidcToken(oidcToken) {
|
|
@@ -1142,13 +1151,24 @@ var Authentication = class {
|
|
|
1142
1151
|
}
|
|
1143
1152
|
return await getOidcToken();
|
|
1144
1153
|
}
|
|
1145
|
-
|
|
1154
|
+
getStaticBundledDefinitionsLookup() {
|
|
1146
1155
|
if (this.sdkKey) {
|
|
1147
1156
|
return { type: "sdk-key", sdkKey: this.sdkKey };
|
|
1148
1157
|
}
|
|
1149
1158
|
if (this.sourceProjectId) {
|
|
1150
1159
|
return { type: "project-id", projectId: this.sourceProjectId };
|
|
1151
1160
|
}
|
|
1161
|
+
const projectId = process.env.VERCEL_PROJECT_ID;
|
|
1162
|
+
if (projectId) {
|
|
1163
|
+
return { type: "project-id", projectId };
|
|
1164
|
+
}
|
|
1165
|
+
return void 0;
|
|
1166
|
+
}
|
|
1167
|
+
async resolveBundledDefinitionsLookup() {
|
|
1168
|
+
const lookup = this.getStaticBundledDefinitionsLookup();
|
|
1169
|
+
if (lookup) {
|
|
1170
|
+
return lookup;
|
|
1171
|
+
}
|
|
1152
1172
|
const oidcToken = await this.resolveToken();
|
|
1153
1173
|
return {
|
|
1154
1174
|
type: "project-id",
|
|
@@ -1218,7 +1238,7 @@ function getRuntimeIngest() {
|
|
|
1218
1238
|
try {
|
|
1219
1239
|
const context = globalThis[FLAGS_CONTEXT_SYMBOL];
|
|
1220
1240
|
return typeof _optionalChain([context, 'optionalAccess', _34 => _34.ingest]) === "function" ? context.ingest : void 0;
|
|
1221
|
-
} catch (
|
|
1241
|
+
} catch (e7) {
|
|
1222
1242
|
return void 0;
|
|
1223
1243
|
}
|
|
1224
1244
|
}
|
|
@@ -1236,7 +1256,7 @@ async function getEvaluatingOidcToken(auth) {
|
|
|
1236
1256
|
if (!auth.sdkKey) return void 0;
|
|
1237
1257
|
try {
|
|
1238
1258
|
return await _oidc.getVercelOidcToken.call(void 0, );
|
|
1239
|
-
} catch (
|
|
1259
|
+
} catch (e8) {
|
|
1240
1260
|
return void 0;
|
|
1241
1261
|
}
|
|
1242
1262
|
}
|
|
@@ -1348,7 +1368,7 @@ var Scheduler = (_class = class {
|
|
|
1348
1368
|
})();
|
|
1349
1369
|
try {
|
|
1350
1370
|
this.scheduleTask(this.pending);
|
|
1351
|
-
} catch (
|
|
1371
|
+
} catch (e9) {
|
|
1352
1372
|
}
|
|
1353
1373
|
this.maxTimeout = setTimeout(
|
|
1354
1374
|
() => this.resolveScheduledFlush("max_timeout"),
|
|
@@ -1575,7 +1595,7 @@ var UsageTracker = (_class4 = class {
|
|
|
1575
1595
|
void flush.finally(() => this.inflightFlushes.delete(flush));
|
|
1576
1596
|
try {
|
|
1577
1597
|
_optionalChain([this, 'access', _37 => _37.waitUntil, 'optionalCall', _38 => _38(flush)]);
|
|
1578
|
-
} catch (
|
|
1598
|
+
} catch (e10) {
|
|
1579
1599
|
}
|
|
1580
1600
|
} else {
|
|
1581
1601
|
this.scheduler.scheduleFlush();
|
|
@@ -1658,6 +1678,13 @@ var BundledSource = class {
|
|
|
1658
1678
|
}
|
|
1659
1679
|
return void 0;
|
|
1660
1680
|
}
|
|
1681
|
+
/**
|
|
1682
|
+
* Starts reading bundled definitions without waiting for the result.
|
|
1683
|
+
*/
|
|
1684
|
+
preload() {
|
|
1685
|
+
this.getResult().catch(() => {
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1661
1688
|
getResult() {
|
|
1662
1689
|
if (!this.promise) {
|
|
1663
1690
|
this.promise = this.options.readBundledDefinitions(this.options.auth);
|
|
@@ -1673,7 +1700,7 @@ function debug(clientName, event, details) {
|
|
|
1673
1700
|
}
|
|
1674
1701
|
try {
|
|
1675
1702
|
console.debug("@vercel/flags-core", { event, clientName, ..._optionalChain([details, 'optionalCall', _40 => _40()]) });
|
|
1676
|
-
} catch (
|
|
1703
|
+
} catch (e11) {
|
|
1677
1704
|
}
|
|
1678
1705
|
}
|
|
1679
1706
|
|
|
@@ -2012,7 +2039,7 @@ var DatafileCache = (_class5 = class {
|
|
|
2012
2039
|
});
|
|
2013
2040
|
try {
|
|
2014
2041
|
this.waitUntil(background);
|
|
2015
|
-
} catch (
|
|
2042
|
+
} catch (e12) {
|
|
2016
2043
|
}
|
|
2017
2044
|
}
|
|
2018
2045
|
/** Resets storage, age, and the failure deadline so a restarted client begins clean. */
|
|
@@ -2125,7 +2152,8 @@ async function fetchDatafile(options) {
|
|
|
2125
2152
|
return await Promise.race([fetchAttempt(attempt + 1), aborted]);
|
|
2126
2153
|
} catch (error) {
|
|
2127
2154
|
signal.throwIfAborted();
|
|
2128
|
-
if (attempt === maxAttempts - 1 || error instanceof DatafileHttpError && !error.retryable
|
|
2155
|
+
if (attempt === maxAttempts - 1 || error instanceof DatafileHttpError && !error.retryable || // Retrying will not produce a token that is not there.
|
|
2156
|
+
error instanceof OidcTokenError) {
|
|
2129
2157
|
throw error instanceof Error ? error : new Error("Unknown fetch error");
|
|
2130
2158
|
}
|
|
2131
2159
|
debug(options.clientName, "datafile.fetch.retry", () => ({
|
|
@@ -2543,7 +2571,7 @@ async function connectStream(config, callbacks) {
|
|
|
2543
2571
|
rejectInit(error);
|
|
2544
2572
|
}
|
|
2545
2573
|
_optionalChain([onDisconnect, 'optionalCall', _97 => _97()]);
|
|
2546
|
-
abortController.abort();
|
|
2574
|
+
abortController.abort(error);
|
|
2547
2575
|
break;
|
|
2548
2576
|
}
|
|
2549
2577
|
if (!response.ok) {
|
|
@@ -2579,7 +2607,7 @@ async function connectStream(config, callbacks) {
|
|
|
2579
2607
|
let message;
|
|
2580
2608
|
try {
|
|
2581
2609
|
message = JSON.parse(line);
|
|
2582
|
-
} catch (
|
|
2610
|
+
} catch (e13) {
|
|
2583
2611
|
console.warn(
|
|
2584
2612
|
"@vercel/flags-core: Failed to parse stream message, skipping"
|
|
2585
2613
|
);
|
|
@@ -2645,7 +2673,7 @@ async function connectStream(config, callbacks) {
|
|
|
2645
2673
|
}
|
|
2646
2674
|
if (error instanceof TokenResolutionError && !initialDataReceived) {
|
|
2647
2675
|
rejectInit(error.cause);
|
|
2648
|
-
abortController.abort();
|
|
2676
|
+
abortController.abort(error.cause);
|
|
2649
2677
|
break;
|
|
2650
2678
|
}
|
|
2651
2679
|
if (connectionAbort.signal.reason !== PING_TIMEOUT) {
|
|
@@ -2719,7 +2747,7 @@ var StreamSource = (_class9 = class extends TypedEmitter {
|
|
|
2719
2747
|
if (this.abortController === abortController) {
|
|
2720
2748
|
this.promise = void 0;
|
|
2721
2749
|
this.abortController = void 0;
|
|
2722
|
-
this.emit("exhausted");
|
|
2750
|
+
this.emit("exhausted", abortController.signal.reason);
|
|
2723
2751
|
}
|
|
2724
2752
|
},
|
|
2725
2753
|
{ once: true }
|
|
@@ -2780,7 +2808,7 @@ var UNKNOWN_FRESHNESS = {
|
|
|
2780
2808
|
assess: () => ({ status: "unknown" })
|
|
2781
2809
|
};
|
|
2782
2810
|
function isUnauthorizedError(error) {
|
|
2783
|
-
if (error instanceof UnauthorizedError) {
|
|
2811
|
+
if (error instanceof UnauthorizedError || error instanceof OidcTokenError) {
|
|
2784
2812
|
return true;
|
|
2785
2813
|
}
|
|
2786
2814
|
if (!(error instanceof Error)) {
|
|
@@ -2815,8 +2843,9 @@ var Controller = (_class10 = class {
|
|
|
2815
2843
|
// Build-step deduplication
|
|
2816
2844
|
__init23() {this.buildDataPromise = null}
|
|
2817
2845
|
__init24() {this.buildReadTracked = false}
|
|
2818
|
-
// Suppresses usage tracking while the credential is rejected
|
|
2819
|
-
//
|
|
2846
|
+
// Suppresses usage tracking while the credential is rejected or no OIDC
|
|
2847
|
+
// token is available. Set on an auth failure from any source, cleared as
|
|
2848
|
+
// soon as a source delivers data again.
|
|
2820
2849
|
__init25() {this.unauthorized = false}
|
|
2821
2850
|
constructor(options) {;_class10.prototype.__init18.call(this);_class10.prototype.__init19.call(this);_class10.prototype.__init20.call(this);_class10.prototype.__init21.call(this);_class10.prototype.__init22.call(this);_class10.prototype.__init23.call(this);_class10.prototype.__init24.call(this);_class10.prototype.__init25.call(this);_class10.prototype.__init26.call(this);_class10.prototype.__init27.call(this);_class10.prototype.__init28.call(this);_class10.prototype.__init29.call(this);_class10.prototype.__init30.call(this);_class10.prototype.__init31.call(this);_class10.prototype.__init32.call(this);_class10.prototype.__init33.call(this);_class10.prototype.__init34.call(this);
|
|
2822
2851
|
this.options = normalizeOptions(options);
|
|
@@ -2853,6 +2882,9 @@ var Controller = (_class10 = class {
|
|
|
2853
2882
|
auth: this.options.auth,
|
|
2854
2883
|
readBundledDefinitions
|
|
2855
2884
|
});
|
|
2885
|
+
if (!this.options.datafile && this.options.auth.getStaticBundledDefinitionsLookup()) {
|
|
2886
|
+
this.bundledSource.preload();
|
|
2887
|
+
}
|
|
2856
2888
|
this.wireSourceEvents();
|
|
2857
2889
|
if (this.options.datafile) {
|
|
2858
2890
|
this.cache.seed(tagData({ ...this.options.datafile }, "provided"));
|
|
@@ -2909,10 +2941,16 @@ var Controller = (_class10 = class {
|
|
|
2909
2941
|
this.transition("degraded", "stream-disconnected");
|
|
2910
2942
|
}
|
|
2911
2943
|
}}
|
|
2912
|
-
__init31() {this.onStreamExhausted = () => {
|
|
2944
|
+
__init31() {this.onStreamExhausted = (reason) => {
|
|
2913
2945
|
if (this.state !== "streaming" && this.state !== "degraded") {
|
|
2914
2946
|
return;
|
|
2915
2947
|
}
|
|
2948
|
+
if (isUnauthorizedError(reason)) {
|
|
2949
|
+
if (this.state === "streaming") {
|
|
2950
|
+
this.transition("degraded", "stream-auth-failed");
|
|
2951
|
+
}
|
|
2952
|
+
return;
|
|
2953
|
+
}
|
|
2916
2954
|
void this.activateFallbackSource().catch(() => {
|
|
2917
2955
|
});
|
|
2918
2956
|
}}
|
|
@@ -2924,7 +2962,7 @@ var Controller = (_class10 = class {
|
|
|
2924
2962
|
this.onSourceError(error);
|
|
2925
2963
|
if (this.state === "polling" && isUnauthorizedError(error)) {
|
|
2926
2964
|
this.pollingSource.stop();
|
|
2927
|
-
this.transition("degraded", "polling-
|
|
2965
|
+
this.transition("degraded", "polling-auth-failed");
|
|
2928
2966
|
}
|
|
2929
2967
|
}}
|
|
2930
2968
|
// ---------------------------------------------------------------------------
|
|
@@ -3053,7 +3091,7 @@ var Controller = (_class10 = class {
|
|
|
3053
3091
|
try {
|
|
3054
3092
|
const bundled = await this.bundledSource.tryLoad();
|
|
3055
3093
|
if (bundled) this.cache.seed(tagData({ ...bundled }, "bundled"));
|
|
3056
|
-
} catch (
|
|
3094
|
+
} catch (e14) {
|
|
3057
3095
|
}
|
|
3058
3096
|
}
|
|
3059
3097
|
if (this.headerSource.isEnabled()) {
|
|
@@ -3238,7 +3276,7 @@ var Controller = (_class10 = class {
|
|
|
3238
3276
|
}
|
|
3239
3277
|
try {
|
|
3240
3278
|
await this.cache.refresh();
|
|
3241
|
-
} catch (
|
|
3279
|
+
} catch (e15) {
|
|
3242
3280
|
throw this.noDefinitionsError(
|
|
3243
3281
|
". Initialize the client or provide a datafile."
|
|
3244
3282
|
);
|
|
@@ -3334,6 +3372,10 @@ var Controller = (_class10 = class {
|
|
|
3334
3372
|
this.transition("degraded", "stream-still-connecting");
|
|
3335
3373
|
return;
|
|
3336
3374
|
}
|
|
3375
|
+
if (outcome === "auth-failed") {
|
|
3376
|
+
this.transition("degraded", "stream-auth-failed");
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3337
3379
|
}
|
|
3338
3380
|
if (this.options.polling.enabled) {
|
|
3339
3381
|
if (this.state !== "polling") {
|
|
@@ -3366,7 +3408,7 @@ var Controller = (_class10 = class {
|
|
|
3366
3408
|
return "connected";
|
|
3367
3409
|
} catch (error) {
|
|
3368
3410
|
this.noteUnauthorized(error);
|
|
3369
|
-
return "failed";
|
|
3411
|
+
return isUnauthorizedError(error) ? "auth-failed" : "failed";
|
|
3370
3412
|
}
|
|
3371
3413
|
}
|
|
3372
3414
|
let timeoutId;
|
|
@@ -3400,7 +3442,7 @@ var Controller = (_class10 = class {
|
|
|
3400
3442
|
} catch (error) {
|
|
3401
3443
|
clearTimeout(timeoutId);
|
|
3402
3444
|
this.noteUnauthorized(error);
|
|
3403
|
-
return "failed";
|
|
3445
|
+
return isUnauthorizedError(error) ? "auth-failed" : "failed";
|
|
3404
3446
|
}
|
|
3405
3447
|
}
|
|
3406
3448
|
// ---------------------------------------------------------------------------
|
|
@@ -3551,7 +3593,7 @@ var Controller = (_class10 = class {
|
|
|
3551
3593
|
this.acceptLastResortFetch(await this.fetchOnce());
|
|
3552
3594
|
this.transition("degraded", "fetched-fallback");
|
|
3553
3595
|
return;
|
|
3554
|
-
} catch (
|
|
3596
|
+
} catch (e16) {
|
|
3555
3597
|
}
|
|
3556
3598
|
}
|
|
3557
3599
|
throw this.noDefinitionsError(". Bundled definitions not found.");
|
|
@@ -3596,7 +3638,7 @@ var Controller = (_class10 = class {
|
|
|
3596
3638
|
let fetched;
|
|
3597
3639
|
try {
|
|
3598
3640
|
fetched = await this.fetchOnce();
|
|
3599
|
-
} catch (
|
|
3641
|
+
} catch (e17) {
|
|
3600
3642
|
}
|
|
3601
3643
|
if (fetched) {
|
|
3602
3644
|
const remote = this.acceptLastResortFetch(fetched);
|
|
@@ -3704,7 +3746,7 @@ function setCacheLife() {
|
|
|
3704
3746
|
try {
|
|
3705
3747
|
_cache.cacheLife.call(void 0, { revalidate: 0, expire: 0 });
|
|
3706
3748
|
_cache.cacheLife.call(void 0, { stale: 60 });
|
|
3707
|
-
} catch (
|
|
3749
|
+
} catch (e18) {
|
|
3708
3750
|
}
|
|
3709
3751
|
}
|
|
3710
3752
|
var cachedFns = {
|
|
@@ -3754,4 +3796,4 @@ var { flagsClient, resetDefaultFlagsClient, createClient } = make(
|
|
|
3754
3796
|
|
|
3755
3797
|
|
|
3756
3798
|
exports.ResolutionReason = ResolutionReason; exports.evaluate = evaluate; exports.FallbackNotFoundError = FallbackNotFoundError; exports.FallbackEntryNotFoundError = FallbackEntryNotFoundError; exports.Controller = Controller; exports.flagsClient = flagsClient; exports.resetDefaultFlagsClient = resetDefaultFlagsClient; exports.createClient = createClient;
|
|
3757
|
-
//# sourceMappingURL=chunk-
|
|
3799
|
+
//# sourceMappingURL=chunk-EGGUENXP.cjs.map
|