@vercel/flags-core 1.10.2 → 1.11.0-31e6462-20261026142820

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 CHANGED
@@ -1,13 +1,15 @@
1
1
  # @vercel/flags-core
2
2
 
3
- ## 1.10.2
3
+ ## 1.11.0-31e6462-20261026142820
4
+
5
+ ### Minor Changes
6
+
7
+ - [#539](https://github.com/vercel/flags/pull/539) [`fc7da82`](https://github.com/vercel/flags/commit/fc7da82d4cffb9d4662335e984e09fec22ba4a6b) Thanks [@vincent-derks](https://github.com/vincent-derks)! - Add a `projectId` option to read the flags of a connected project.
4
8
 
5
9
  ### Patch Changes
6
10
 
7
11
  - [#567](https://github.com/vercel/flags/pull/567) [`5f738f0`](https://github.com/vercel/flags/commit/5f738f08f182838d0efb13fd3efb89751d48cb0a) Thanks [@vincent-derks](https://github.com/vincent-derks)! - Improve guidance for authorization errors.
8
12
 
9
- - [#573](https://github.com/vercel/flags/pull/573) [`e2a1a39`](https://github.com/vercel/flags/commit/e2a1a394e3de4b271c8305bae6cbcf053814ab70) Thanks [@luismeyer](https://github.com/luismeyer)! - Read embedded flag definitions when the client is created, using the SDK key or `VERCEL_PROJECT_ID` in OIDC mode.
10
-
11
13
  ## 1.10.1
12
14
 
13
15
  ### Patch Changes
package/README.md CHANGED
@@ -33,6 +33,18 @@ export default app;
33
33
 
34
34
  Outside Vercel, pass an SDK key explicitly: `createClient(process.env.FLAGS)`.
35
35
 
36
+ ### Read a connected project's flags
37
+
38
+ Grant your project access from the source project's **Flags → Connections** page, then create a client with the source project's ID:
39
+
40
+ ```ts
41
+ const sharedClient = createClient({ projectId: 'prj_source' });
42
+ ```
43
+
44
+ The client uses your project's OIDC token. Both projects must belong to the same team. Connections apply across environments; the token selects the source environment, with custom environments mapped to preview. Run `vercel env pull` in your project for local development. The `projectId` option cannot be combined with an SDK key.
45
+
46
+ See [Project Connections](https://vercel.com/docs/flags/vercel-flags/project-connections) for permissions and setup.
47
+
36
48
  ## Header-driven reads on Vercel
37
49
 
38
50
  When `VERCEL=1`, the client defaults to `vercel: true`. Initialization loads provided
@@ -559,7 +559,7 @@ function bulkEvaluate(flags, shared) {
559
559
  }
560
560
 
561
561
  // package.json
562
- var version = "1.10.2";
562
+ var version = "1.11.0-31e6462-20261026142820";
563
563
 
564
564
  // src/lib/report-value.ts
565
565
  function internalReportValue(key, value, data) {
@@ -1063,6 +1063,10 @@ var _oidc = require('@vercel/oidc');
1063
1063
 
1064
1064
  // src/utils/sdk-keys.ts
1065
1065
  var SDK_KEY_REGEX = /^vf_(?:server|client)_/;
1066
+ var PROJECT_ID_REGEX = /^[A-Za-z0-9_]{1,64}$/;
1067
+ function isValidProjectId(value) {
1068
+ return PROJECT_ID_REGEX.test(value);
1069
+ }
1066
1070
  function parseSdkKeyFromFlagsConnectionString(text) {
1067
1071
  if (SDK_KEY_REGEX.test(text)) return text;
1068
1072
  try {
@@ -1120,7 +1124,21 @@ function getProjectIdFromOidcToken(oidcToken) {
1120
1124
  var Authentication = class {
1121
1125
 
1122
1126
 
1123
- constructor(sdkKeyOrConnectionString) {
1127
+ constructor(sdkKeyOrConnectionString, options = {}) {
1128
+ if (options.projectId !== void 0) {
1129
+ if (typeof options.projectId !== "string" || !isValidProjectId(options.projectId)) {
1130
+ throw new Error(
1131
+ `@vercel/flags-core: Invalid projectId "${options.projectId}". Expected a project id like "prj_\u2026" (letters, digits and underscores, up to 64 characters)`
1132
+ );
1133
+ }
1134
+ if (sdkKeyOrConnectionString !== void 0) {
1135
+ throw new Error(
1136
+ "@vercel/flags-core: projectId cannot be combined with an SDK key. Connected projects are read with the OIDC token of this deployment."
1137
+ );
1138
+ }
1139
+ this.sourceProjectId = options.projectId;
1140
+ return;
1141
+ }
1124
1142
  if (sdkKeyOrConnectionString !== void 0) {
1125
1143
  if (typeof sdkKeyOrConnectionString !== "string") {
1126
1144
  throw new Error(
@@ -1142,24 +1160,13 @@ var Authentication = class {
1142
1160
  }
1143
1161
  return await getOidcToken();
1144
1162
  }
1145
- getStaticBundledDefinitionsLookup() {
1163
+ async resolveBundledDefinitionsLookup() {
1146
1164
  if (this.sdkKey) {
1147
1165
  return { type: "sdk-key", sdkKey: this.sdkKey };
1148
1166
  }
1149
1167
  if (this.sourceProjectId) {
1150
1168
  return { type: "project-id", projectId: this.sourceProjectId };
1151
1169
  }
1152
- const projectId = process.env.VERCEL_PROJECT_ID;
1153
- if (projectId) {
1154
- return { type: "project-id", projectId };
1155
- }
1156
- return void 0;
1157
- }
1158
- async resolveBundledDefinitionsLookup() {
1159
- const lookup = this.getStaticBundledDefinitionsLookup();
1160
- if (lookup) {
1161
- return lookup;
1162
- }
1163
1170
  const oidcToken = await this.resolveToken();
1164
1171
  return {
1165
1172
  type: "project-id",
@@ -1669,13 +1676,6 @@ var BundledSource = class {
1669
1676
  }
1670
1677
  return void 0;
1671
1678
  }
1672
- /**
1673
- * Starts reading bundled definitions without waiting for the result.
1674
- */
1675
- preload() {
1676
- this.getResult().catch(() => {
1677
- });
1678
- }
1679
1679
  getResult() {
1680
1680
  if (!this.promise) {
1681
1681
  this.promise = this.options.readBundledDefinitions(this.options.auth);
@@ -2871,9 +2871,6 @@ var Controller = (_class10 = class {
2871
2871
  auth: this.options.auth,
2872
2872
  readBundledDefinitions
2873
2873
  });
2874
- if (!this.options.datafile && this.options.auth.getStaticBundledDefinitionsLookup()) {
2875
- this.bundledSource.preload();
2876
- }
2877
2874
  this.wireSourceEvents();
2878
2875
  if (this.options.datafile) {
2879
2876
  this.cache.seed(tagData({ ...this.options.datafile }, "provided"));
@@ -3683,8 +3680,8 @@ function make(createRawClient, defaults) {
3683
3680
  const optionsOnly = typeof sdkKeyOrConnectionStringOrOptions === "object" && sdkKeyOrConnectionStringOrOptions !== null;
3684
3681
  const sdkKeyOrConnectionString = optionsOnly ? void 0 : sdkKeyOrConnectionStringOrOptions;
3685
3682
  const createClientOptions = optionsOnly ? sdkKeyOrConnectionStringOrOptions : options;
3686
- const { experimental_reportExposures, ...controllerOptions } = _nullishCoalesce(createClientOptions, () => ( {}));
3687
- const auth = new Authentication(sdkKeyOrConnectionString);
3683
+ const { experimental_reportExposures, projectId, ...controllerOptions } = _nullishCoalesce(createClientOptions, () => ( {}));
3684
+ const auth = new Authentication(sdkKeyOrConnectionString, { projectId });
3688
3685
  const waitUntil2 = _nullishCoalesce(controllerOptions.waitUntil, () => ( defaults.waitUntil));
3689
3686
  const controller = new Controller({
3690
3687
  auth,
@@ -3775,4 +3772,4 @@ var { flagsClient, resetDefaultFlagsClient, createClient } = make(
3775
3772
 
3776
3773
 
3777
3774
  exports.ResolutionReason = ResolutionReason; exports.evaluate = evaluate; exports.FallbackNotFoundError = FallbackNotFoundError; exports.FallbackEntryNotFoundError = FallbackEntryNotFoundError; exports.Controller = Controller; exports.flagsClient = flagsClient; exports.resetDefaultFlagsClient = resetDefaultFlagsClient; exports.createClient = createClient;
3778
- //# sourceMappingURL=chunk-WVS63L4A.cjs.map
3775
+ //# sourceMappingURL=chunk-J73HQYK2.cjs.map