@vercel/flags-core 1.10.2 → 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.
@@ -576,7 +576,7 @@ function bulkEvaluate(flags, shared) {
576
576
  }
577
577
 
578
578
  // package.json
579
- var version = "1.10.2";
579
+ var version = "1.10.3";
580
580
 
581
581
  // src/lib/report-value.ts
582
582
  function internalReportValue(key, value, data) {
@@ -1106,17 +1106,26 @@ function unauthorizedMessage(sourceProjectId) {
1106
1106
  }
1107
1107
  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`;
1108
1108
  }
1109
+ var oidcTokenMessage = [
1110
+ "@vercel/flags-core: Failed to get OIDC token.",
1111
+ "Are you running in a Vercel Environment where OIDC tokens are available?",
1112
+ "Did you mean to use an SDK Key instead? Use the environment variable FLAGS or pass it directly to the client."
1113
+ ].join(" ");
1114
+ var missingCredentials = /`vc link|vercel login|^The 'x-vercel-oidc-token' header is missing from the request\.$/;
1115
+ var OidcTokenError = class extends Error {
1116
+ constructor(cause) {
1117
+ super(oidcTokenMessage, { cause });
1118
+ this.name = "OidcTokenError";
1119
+ }
1120
+ };
1109
1121
  async function getOidcToken() {
1110
1122
  try {
1111
1123
  return await _oidc.getVercelOidcToken.call(void 0, );
1112
- } catch (e7) {
1113
- throw new Error(
1114
- [
1115
- "@vercel/flags-core: Failed to get OIDC token.",
1116
- "Are you running in a Vercel Environment where OIDC tokens are available?",
1117
- "Did you mean to use an SDK Key instead? Use the environment variable FLAGS or pass it directly to the client."
1118
- ].join(" ")
1119
- );
1124
+ } catch (error) {
1125
+ if (error instanceof Error && missingCredentials.test(error.message)) {
1126
+ throw new OidcTokenError(error);
1127
+ }
1128
+ throw new Error(oidcTokenMessage, { cause: error });
1120
1129
  }
1121
1130
  }
1122
1131
  function getProjectIdFromOidcToken(oidcToken) {
@@ -1246,7 +1255,7 @@ function getRuntimeIngest() {
1246
1255
  try {
1247
1256
  const context = globalThis[FLAGS_CONTEXT_SYMBOL];
1248
1257
  return typeof _optionalChain([context, 'optionalAccess', _34 => _34.ingest]) === "function" ? context.ingest : void 0;
1249
- } catch (e8) {
1258
+ } catch (e7) {
1250
1259
  return void 0;
1251
1260
  }
1252
1261
  }
@@ -1264,7 +1273,7 @@ async function getEvaluatingOidcToken(auth) {
1264
1273
  if (!auth.sdkKey) return void 0;
1265
1274
  try {
1266
1275
  return await _oidc.getVercelOidcToken.call(void 0, );
1267
- } catch (e9) {
1276
+ } catch (e8) {
1268
1277
  return void 0;
1269
1278
  }
1270
1279
  }
@@ -1376,7 +1385,7 @@ var Scheduler = (_class = class {
1376
1385
  })();
1377
1386
  try {
1378
1387
  this.scheduleTask(this.pending);
1379
- } catch (e10) {
1388
+ } catch (e9) {
1380
1389
  }
1381
1390
  this.maxTimeout = setTimeout(
1382
1391
  () => this.resolveScheduledFlush("max_timeout"),
@@ -1603,7 +1612,7 @@ var UsageTracker = (_class4 = class {
1603
1612
  void flush.finally(() => this.inflightFlushes.delete(flush));
1604
1613
  try {
1605
1614
  _optionalChain([this, 'access', _37 => _37.waitUntil, 'optionalCall', _38 => _38(flush)]);
1606
- } catch (e11) {
1615
+ } catch (e10) {
1607
1616
  }
1608
1617
  } else {
1609
1618
  this.scheduler.scheduleFlush();
@@ -1708,7 +1717,7 @@ function debug(clientName, event, details) {
1708
1717
  }
1709
1718
  try {
1710
1719
  console.debug("@vercel/flags-core", { event, clientName, ..._optionalChain([details, 'optionalCall', _40 => _40()]) });
1711
- } catch (e12) {
1720
+ } catch (e11) {
1712
1721
  }
1713
1722
  }
1714
1723
 
@@ -2047,7 +2056,7 @@ var DatafileCache = (_class5 = class {
2047
2056
  });
2048
2057
  try {
2049
2058
  this.waitUntil(background);
2050
- } catch (e13) {
2059
+ } catch (e12) {
2051
2060
  }
2052
2061
  }
2053
2062
  /** Resets storage, age, and the failure deadline so a restarted client begins clean. */
@@ -2160,7 +2169,8 @@ async function fetchDatafile(options) {
2160
2169
  return await Promise.race([fetchAttempt(attempt + 1), aborted]);
2161
2170
  } catch (error) {
2162
2171
  signal.throwIfAborted();
2163
- if (attempt === maxAttempts - 1 || error instanceof DatafileHttpError && !error.retryable) {
2172
+ if (attempt === maxAttempts - 1 || error instanceof DatafileHttpError && !error.retryable || // Retrying will not produce a token that is not there.
2173
+ error instanceof OidcTokenError) {
2164
2174
  throw error instanceof Error ? error : new Error("Unknown fetch error");
2165
2175
  }
2166
2176
  debug(options.clientName, "datafile.fetch.retry", () => ({
@@ -2578,7 +2588,7 @@ async function connectStream(config, callbacks) {
2578
2588
  rejectInit(error);
2579
2589
  }
2580
2590
  _optionalChain([onDisconnect, 'optionalCall', _97 => _97()]);
2581
- abortController.abort();
2591
+ abortController.abort(error);
2582
2592
  break;
2583
2593
  }
2584
2594
  if (!response.ok) {
@@ -2614,7 +2624,7 @@ async function connectStream(config, callbacks) {
2614
2624
  let message;
2615
2625
  try {
2616
2626
  message = JSON.parse(line);
2617
- } catch (e14) {
2627
+ } catch (e13) {
2618
2628
  console.warn(
2619
2629
  "@vercel/flags-core: Failed to parse stream message, skipping"
2620
2630
  );
@@ -2680,7 +2690,7 @@ async function connectStream(config, callbacks) {
2680
2690
  }
2681
2691
  if (error instanceof TokenResolutionError && !initialDataReceived) {
2682
2692
  rejectInit(error.cause);
2683
- abortController.abort();
2693
+ abortController.abort(error.cause);
2684
2694
  break;
2685
2695
  }
2686
2696
  if (connectionAbort.signal.reason !== PING_TIMEOUT) {
@@ -2754,7 +2764,7 @@ var StreamSource = (_class9 = class extends TypedEmitter {
2754
2764
  if (this.abortController === abortController) {
2755
2765
  this.promise = void 0;
2756
2766
  this.abortController = void 0;
2757
- this.emit("exhausted");
2767
+ this.emit("exhausted", abortController.signal.reason);
2758
2768
  }
2759
2769
  },
2760
2770
  { once: true }
@@ -2815,7 +2825,7 @@ var UNKNOWN_FRESHNESS = {
2815
2825
  assess: () => ({ status: "unknown" })
2816
2826
  };
2817
2827
  function isUnauthorizedError(error) {
2818
- if (error instanceof UnauthorizedError) {
2828
+ if (error instanceof UnauthorizedError || error instanceof OidcTokenError) {
2819
2829
  return true;
2820
2830
  }
2821
2831
  if (!(error instanceof Error)) {
@@ -2850,8 +2860,9 @@ var Controller = (_class10 = class {
2850
2860
  // Build-step deduplication
2851
2861
  __init23() {this.buildDataPromise = null}
2852
2862
  __init24() {this.buildReadTracked = false}
2853
- // Suppresses usage tracking while the credential is rejected. Set on a 401
2854
- // from any source, cleared as soon as a source delivers data again.
2863
+ // Suppresses usage tracking while the credential is rejected or no OIDC
2864
+ // token is available. Set on an auth failure from any source, cleared as
2865
+ // soon as a source delivers data again.
2855
2866
  __init25() {this.unauthorized = false}
2856
2867
  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);
2857
2868
  this.options = normalizeOptions(options);
@@ -2947,10 +2958,16 @@ var Controller = (_class10 = class {
2947
2958
  this.transition("degraded", "stream-disconnected");
2948
2959
  }
2949
2960
  }}
2950
- __init31() {this.onStreamExhausted = () => {
2961
+ __init31() {this.onStreamExhausted = (reason) => {
2951
2962
  if (this.state !== "streaming" && this.state !== "degraded") {
2952
2963
  return;
2953
2964
  }
2965
+ if (isUnauthorizedError(reason)) {
2966
+ if (this.state === "streaming") {
2967
+ this.transition("degraded", "stream-auth-failed");
2968
+ }
2969
+ return;
2970
+ }
2954
2971
  void this.activateFallbackSource().catch(() => {
2955
2972
  });
2956
2973
  }}
@@ -2962,7 +2979,7 @@ var Controller = (_class10 = class {
2962
2979
  this.onSourceError(error);
2963
2980
  if (this.state === "polling" && isUnauthorizedError(error)) {
2964
2981
  this.pollingSource.stop();
2965
- this.transition("degraded", "polling-unauthorized");
2982
+ this.transition("degraded", "polling-auth-failed");
2966
2983
  }
2967
2984
  }}
2968
2985
  // ---------------------------------------------------------------------------
@@ -3091,7 +3108,7 @@ var Controller = (_class10 = class {
3091
3108
  try {
3092
3109
  const bundled = await this.bundledSource.tryLoad();
3093
3110
  if (bundled) this.cache.seed(tagData({ ...bundled }, "bundled"));
3094
- } catch (e15) {
3111
+ } catch (e14) {
3095
3112
  }
3096
3113
  }
3097
3114
  if (this.headerSource.isEnabled()) {
@@ -3276,7 +3293,7 @@ var Controller = (_class10 = class {
3276
3293
  }
3277
3294
  try {
3278
3295
  await this.cache.refresh();
3279
- } catch (e16) {
3296
+ } catch (e15) {
3280
3297
  throw this.noDefinitionsError(
3281
3298
  ". Initialize the client or provide a datafile."
3282
3299
  );
@@ -3372,6 +3389,10 @@ var Controller = (_class10 = class {
3372
3389
  this.transition("degraded", "stream-still-connecting");
3373
3390
  return;
3374
3391
  }
3392
+ if (outcome === "auth-failed") {
3393
+ this.transition("degraded", "stream-auth-failed");
3394
+ return;
3395
+ }
3375
3396
  }
3376
3397
  if (this.options.polling.enabled) {
3377
3398
  if (this.state !== "polling") {
@@ -3404,7 +3425,7 @@ var Controller = (_class10 = class {
3404
3425
  return "connected";
3405
3426
  } catch (error) {
3406
3427
  this.noteUnauthorized(error);
3407
- return "failed";
3428
+ return isUnauthorizedError(error) ? "auth-failed" : "failed";
3408
3429
  }
3409
3430
  }
3410
3431
  let timeoutId;
@@ -3438,7 +3459,7 @@ var Controller = (_class10 = class {
3438
3459
  } catch (error) {
3439
3460
  clearTimeout(timeoutId);
3440
3461
  this.noteUnauthorized(error);
3441
- return "failed";
3462
+ return isUnauthorizedError(error) ? "auth-failed" : "failed";
3442
3463
  }
3443
3464
  }
3444
3465
  // ---------------------------------------------------------------------------
@@ -3589,7 +3610,7 @@ var Controller = (_class10 = class {
3589
3610
  this.acceptLastResortFetch(await this.fetchOnce());
3590
3611
  this.transition("degraded", "fetched-fallback");
3591
3612
  return;
3592
- } catch (e17) {
3613
+ } catch (e16) {
3593
3614
  }
3594
3615
  }
3595
3616
  throw this.noDefinitionsError(". Bundled definitions not found.");
@@ -3634,7 +3655,7 @@ var Controller = (_class10 = class {
3634
3655
  let fetched;
3635
3656
  try {
3636
3657
  fetched = await this.fetchOnce();
3637
- } catch (e18) {
3658
+ } catch (e17) {
3638
3659
  }
3639
3660
  if (fetched) {
3640
3661
  const remote = this.acceptLastResortFetch(fetched);
@@ -3766,4 +3787,4 @@ var {
3766
3787
 
3767
3788
 
3768
3789
  exports.ResolutionReason = ResolutionReason; exports.evaluate = evaluate; exports.FallbackNotFoundError = FallbackNotFoundError; exports.FallbackEntryNotFoundError = FallbackEntryNotFoundError; exports.Controller = Controller; exports.flagsClient = flagsClient; exports.resetDefaultFlagsClient = resetDefaultFlagsClient; exports.createClient = createClient;
3769
- //# sourceMappingURL=chunk-POAWPAE3.cjs.map
3790
+ //# sourceMappingURL=chunk-BEQ3MX7Z.cjs.map