@splitsoftware/openfeature-web-split-provider 1.1.0 → 1.2.0

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/CHANGES.txt CHANGED
@@ -1,3 +1,9 @@
1
+ 1.2.0 (November 27, 2026)
2
+ - Added support for the `bucketingKey` evaluation context attribute: the provider uses the Split key { matchingKey: targetingKey, bucketingKey }. Changing only the bucketingKey switches to the client for the new key. Blank or non-string values are ignored, and a bucketingKey over 250 characters is ignored and the client uses the targeting key only. A bucketingKey without a targeting key is also ignored.
3
+ - Ignored bucketingKey values are reported as a warning through the Split SDK logger (visible when SDK logging is enabled with `debug`). The warning names the reason, never the value.
4
+ - Behavior change: `bucketingKey` is no longer forwarded to Split as a targeting attribute.
5
+ - Behavior change: the context set before the provider is initialized is now applied (previously the factory key was used until the next context change).
6
+
1
7
  1.1.0 (March 2, 2026)
2
8
  - Added ProviderEvents.Ready payload with Split SdkReadyMetadata
3
9
  - Updated ConfigurationChanged to forward SdkUpdateMetadata in metadata
package/README.md CHANGED
@@ -52,6 +52,17 @@ const context: EvaluationContext = {
52
52
  await OpenFeature.setContext(context)
53
53
  ```
54
54
 
55
+ ### Bucketing key
56
+ Set `bucketingKey` next to `targetingKey` to have Split bucket on a different key than the one used for matching (Split key `{ matchingKey: targetingKey, bucketingKey }`):
57
+ ```js
58
+ await OpenFeature.setContext({ targetingKey: 'user-123', bucketingKey: 'account-42' });
59
+ ```
60
+ - Changing only `bucketingKey` switches to the Split client for the new key, the same as changing the targeting key.
61
+ - `bucketingKey` is reserved: it is **not** forwarded to Split as an attribute.
62
+ - It is trimmed, and ignored (targeting key used alone) when it has no targeting key, is blank, is not a string, or is longer than 250 characters.
63
+ - An ignored `bucketingKey` logs a warning with the reason (never the value) through the Split SDK logger, so it shows when SDK logging is enabled (`debug: 'WARN'` or `factory.Logger.setLogLevel('WARN')`).
64
+ - The context set before the provider (`setContext` before `setProvider`) is applied when the provider initializes.
65
+
55
66
  ## Configuration changed event (SDK_UPDATE)
56
67
 
57
68
  When the Split SDK emits the `SDK_UPDATE` **event** (flags or segments changed), the provider emits OpenFeature’s `ConfigurationChanged` and forwards the event metadata. The metadata shape matches [javascript-commons SdkUpdateMetadata](https://github.com/splitio/javascript-commons): `type` is `'FLAGS_UPDATE' | 'SEGMENTS_UPDATE'` and `names` is the list of flag or segment names that were updated. Handlers receive [Provider Event Details](https://openfeature.dev/specification/types#provider-event-details): `flagsChanged` (when `type === 'FLAGS_UPDATE'`, the `names` array) and `metadata` (`type` as string).
package/es/lib/context.js CHANGED
@@ -1,15 +1,55 @@
1
1
  import { __rest } from "tslib";
2
+ /** Split SDK limit for key values. */
3
+ var KEY_MAX_LENGTH = 250;
4
+ /** Trimmed bucketing key, or the reason it cannot be used. The reason never includes the value. */
5
+ function parseBucketingKey(value) {
6
+ if (value === undefined || value === null)
7
+ return {};
8
+ if (typeof value !== 'string')
9
+ return { reason: 'it is not a string' };
10
+ var bucketingKey = value.trim();
11
+ if (!bucketingKey)
12
+ return { reason: 'it is blank' };
13
+ if (bucketingKey.length > KEY_MAX_LENGTH)
14
+ return { reason: "it is longer than ".concat(KEY_MAX_LENGTH, " characters") };
15
+ return { value: bucketingKey };
16
+ }
17
+ function readBucketingKey(value) {
18
+ return parseBucketingKey(value).value;
19
+ }
20
+ /**
21
+ * Warning for a bucketingKey in the context that will not be used, or undefined when there is nothing to report.
22
+ * Names the reason only, never the value.
23
+ */
24
+ export function bucketingKeyWarning(context) {
25
+ var _a = parseBucketingKey(context.bucketingKey), value = _a.value, reason = _a.reason;
26
+ if (reason) {
27
+ return "bucketingKey ignored because ".concat(reason).concat(context.targetingKey ? '; using the targeting key only' : '', ".");
28
+ }
29
+ if (value && !context.targetingKey)
30
+ return 'bucketingKey ignored because the context has no targetingKey.';
31
+ return undefined;
32
+ }
2
33
  /**
3
34
  * Transform OpenFeature evaluation context into a consumer object for the Split API.
35
+ * `bucketingKey` is reserved: it is never forwarded as an attribute.
4
36
  */
5
37
  export function transformContext(context, defaultTrafficType) {
6
- var targetingKey = context.targetingKey, ttVal = context.trafficType, attributes = __rest(context, ["targetingKey", "trafficType"]);
38
+ var targetingKey = context.targetingKey, bucketingKey = context.bucketingKey, ttVal = context.trafficType, attributes = __rest(context, ["targetingKey", "bucketingKey", "trafficType"]);
7
39
  var trafficType = ttVal != null && typeof ttVal === 'string' && ttVal.trim() !== ''
8
40
  ? ttVal
9
41
  : defaultTrafficType;
10
42
  return {
11
43
  targetingKey: targetingKey,
44
+ bucketingKey: readBucketingKey(bucketingKey),
12
45
  trafficType: trafficType,
13
46
  attributes: JSON.parse(JSON.stringify(attributes)),
14
47
  };
15
48
  }
49
+ /** Split key for a consumer: `{ matchingKey, bucketingKey }` or the targeting key alone. */
50
+ export function toSplitKey(_a) {
51
+ var targetingKey = _a.targetingKey, bucketingKey = _a.bucketingKey;
52
+ if (!targetingKey)
53
+ return undefined;
54
+ return bucketingKey ? { matchingKey: targetingKey, bucketingKey: bucketingKey } : targetingKey;
55
+ }
@@ -1,24 +1,48 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars */
3
3
  import { ParseError, ProviderEvents, OpenFeatureEventEmitter, } from "@openfeature/web-sdk";
4
- import { transformContext } from "./context";
4
+ import { bucketingKeyWarning, toSplitKey, transformContext } from "./context";
5
5
  import { attachSplitReadyHandlers, attachSplitUpdateHandler } from "./events";
6
6
  import { evaluateTreatment } from "./evaluation";
7
7
  import { parseBooleanTreatment, parseValidJsonObject, parseValidNumber } from "./parsers";
8
8
  var OpenFeatureSplitProvider = /** @class */ (function () {
9
9
  function OpenFeatureSplitProvider(splitFactory) {
10
10
  this.metadata = { name: "split" };
11
+ /** Readiness of the bound client (rejects if it timed out). */
12
+ this.ready = Promise.resolve();
11
13
  this.events = new OpenFeatureEventEmitter();
12
14
  this.trafficType = 'user';
13
15
  this.factory = splitFactory;
14
16
  this.client = splitFactory.client();
15
17
  }
16
- OpenFeatureSplitProvider.prototype.initialize = function () {
18
+ /**
19
+ * Warn through the Split SDK logger, so it follows the SDK log settings (`debug`, `factory.Logger`).
20
+ * `settings.log` is internal: the public typings only expose `factory.Logger`, which has no `warn`.
21
+ */
22
+ OpenFeatureSplitProvider.prototype.warn = function (message) {
23
+ var _a, _b, _c;
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ (_c = (_b = (_a = this.factory.settings) === null || _a === void 0 ? void 0 : _a.log) === null || _b === void 0 ? void 0 : _b.warn) === null || _c === void 0 ? void 0 : _c.call(_b, "[".concat(this.metadata.name, "-openfeature] ").concat(message));
26
+ };
27
+ /** Warn once per context set; evaluations reuse the context and would repeat it. */
28
+ OpenFeatureSplitProvider.prototype.warnIfBucketingKeyIgnored = function (context) {
29
+ var warning = bucketingKeyWarning(context);
30
+ if (warning)
31
+ this.warn(warning);
32
+ };
33
+ OpenFeatureSplitProvider.prototype.initialize = function (context) {
17
34
  return __awaiter(this, void 0, void 0, function () {
35
+ var key;
18
36
  var _this = this;
19
37
  return __generator(this, function (_a) {
20
38
  switch (_a.label) {
21
- case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
39
+ case 0:
40
+ if (context)
41
+ this.warnIfBucketingKeyIgnored(context);
42
+ key = context && toSplitKey(transformContext(context, this.trafficType));
43
+ if (key)
44
+ this.client = this.factory.client(key);
45
+ this.ready = new Promise(function (resolve, reject) {
22
46
  try {
23
47
  attachSplitReadyHandlers(_this.client, _this.events, { onSdkReady: resolve, onSdkTimedOut: reject }, _this.metadata.name);
24
48
  attachSplitUpdateHandler(_this.client, _this.events, _this.metadata.name);
@@ -26,7 +50,8 @@ var OpenFeatureSplitProvider = /** @class */ (function () {
26
50
  catch (_a) {
27
51
  reject();
28
52
  }
29
- })];
53
+ });
54
+ return [4 /*yield*/, this.ready];
30
55
  case 1:
31
56
  _a.sent();
32
57
  return [2 /*return*/];
@@ -36,24 +61,35 @@ var OpenFeatureSplitProvider = /** @class */ (function () {
36
61
  };
37
62
  OpenFeatureSplitProvider.prototype.onContextChange = function (oldContext, newContext) {
38
63
  var _this = this;
39
- var oldTargetingKey = oldContext.targetingKey;
40
- var newTargetingKey = newContext.targetingKey, newTrafficType = newContext.trafficType;
64
+ this.warnIfBucketingKeyIgnored(newContext);
65
+ var newTrafficType = newContext.trafficType;
41
66
  this.trafficType =
42
67
  newTrafficType && newTrafficType !== this.trafficType
43
68
  ? newTrafficType
44
69
  : this.trafficType;
45
- if (newTargetingKey && newTargetingKey !== oldTargetingKey) {
46
- this.client = this.factory.client(newTargetingKey);
47
- return new Promise(function (resolve, reject) {
48
- var emitContextChange = function () {
49
- _this.events.emit(ProviderEvents.ConfigurationChanged);
50
- resolve();
51
- };
52
- attachSplitReadyHandlers(_this.client, _this.events, { onSdkReady: emitContextChange, onSdkTimedOut: reject }, _this.metadata.name);
53
- attachSplitUpdateHandler(_this.client, _this.events, _this.metadata.name);
54
- });
70
+ var oldConsumer = transformContext(oldContext, this.trafficType);
71
+ var newConsumer = transformContext(newContext, this.trafficType);
72
+ var newKey = toSplitKey(newConsumer);
73
+ var keyChanged = newConsumer.targetingKey !== oldConsumer.targetingKey ||
74
+ newConsumer.bucketingKey !== oldConsumer.bucketingKey;
75
+ if (!newKey || !keyChanged) {
76
+ // Same client: OpenFeature marks the provider READY when this resolves, so wait if it is still loading
77
+ // (a timeout during that load must still surface as ERROR). If it already timed out, that was reported
78
+ // and this.ready stays rejected, so resolve instead of moving the provider to ERROR on a no-key change.
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ var _a = this.client.__getStatus(), isReady = _a.isReady, hasTimedout = _a.hasTimedout;
81
+ return isReady || hasTimedout ? Promise.resolve() : this.ready;
55
82
  }
56
- return Promise.resolve();
83
+ this.client = this.factory.client(newKey);
84
+ this.ready = new Promise(function (resolve, reject) {
85
+ var emitContextChange = function () {
86
+ _this.events.emit(ProviderEvents.ConfigurationChanged);
87
+ resolve();
88
+ };
89
+ attachSplitReadyHandlers(_this.client, _this.events, { onSdkReady: emitContextChange, onSdkTimedOut: reject }, _this.metadata.name);
90
+ attachSplitUpdateHandler(_this.client, _this.events, _this.metadata.name);
91
+ });
92
+ return this.ready;
57
93
  };
58
94
  OpenFeatureSplitProvider.prototype.resolveBooleanEvaluation = function (flagKey, _, context, _logger) {
59
95
  var details = evaluateTreatment(this.client, flagKey, transformContext(context, this.trafficType));
@@ -1,19 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformContext = void 0;
3
+ exports.toSplitKey = exports.transformContext = exports.bucketingKeyWarning = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ /** Split SDK limit for key values. */
6
+ var KEY_MAX_LENGTH = 250;
7
+ /** Trimmed bucketing key, or the reason it cannot be used. The reason never includes the value. */
8
+ function parseBucketingKey(value) {
9
+ if (value === undefined || value === null)
10
+ return {};
11
+ if (typeof value !== 'string')
12
+ return { reason: 'it is not a string' };
13
+ var bucketingKey = value.trim();
14
+ if (!bucketingKey)
15
+ return { reason: 'it is blank' };
16
+ if (bucketingKey.length > KEY_MAX_LENGTH)
17
+ return { reason: "it is longer than ".concat(KEY_MAX_LENGTH, " characters") };
18
+ return { value: bucketingKey };
19
+ }
20
+ function readBucketingKey(value) {
21
+ return parseBucketingKey(value).value;
22
+ }
23
+ /**
24
+ * Warning for a bucketingKey in the context that will not be used, or undefined when there is nothing to report.
25
+ * Names the reason only, never the value.
26
+ */
27
+ function bucketingKeyWarning(context) {
28
+ var _a = parseBucketingKey(context.bucketingKey), value = _a.value, reason = _a.reason;
29
+ if (reason) {
30
+ return "bucketingKey ignored because ".concat(reason).concat(context.targetingKey ? '; using the targeting key only' : '', ".");
31
+ }
32
+ if (value && !context.targetingKey)
33
+ return 'bucketingKey ignored because the context has no targetingKey.';
34
+ return undefined;
35
+ }
36
+ exports.bucketingKeyWarning = bucketingKeyWarning;
5
37
  /**
6
38
  * Transform OpenFeature evaluation context into a consumer object for the Split API.
39
+ * `bucketingKey` is reserved: it is never forwarded as an attribute.
7
40
  */
8
41
  function transformContext(context, defaultTrafficType) {
9
- var targetingKey = context.targetingKey, ttVal = context.trafficType, attributes = tslib_1.__rest(context, ["targetingKey", "trafficType"]);
42
+ var targetingKey = context.targetingKey, bucketingKey = context.bucketingKey, ttVal = context.trafficType, attributes = tslib_1.__rest(context, ["targetingKey", "bucketingKey", "trafficType"]);
10
43
  var trafficType = ttVal != null && typeof ttVal === 'string' && ttVal.trim() !== ''
11
44
  ? ttVal
12
45
  : defaultTrafficType;
13
46
  return {
14
47
  targetingKey: targetingKey,
48
+ bucketingKey: readBucketingKey(bucketingKey),
15
49
  trafficType: trafficType,
16
50
  attributes: JSON.parse(JSON.stringify(attributes)),
17
51
  };
18
52
  }
19
53
  exports.transformContext = transformContext;
54
+ /** Split key for a consumer: `{ matchingKey, bucketingKey }` or the targeting key alone. */
55
+ function toSplitKey(_a) {
56
+ var targetingKey = _a.targetingKey, bucketingKey = _a.bucketingKey;
57
+ if (!targetingKey)
58
+ return undefined;
59
+ return bucketingKey ? { matchingKey: targetingKey, bucketingKey: bucketingKey } : targetingKey;
60
+ }
61
+ exports.toSplitKey = toSplitKey;
@@ -11,17 +11,41 @@ var parsers_1 = require("./parsers");
11
11
  var OpenFeatureSplitProvider = /** @class */ (function () {
12
12
  function OpenFeatureSplitProvider(splitFactory) {
13
13
  this.metadata = { name: "split" };
14
+ /** Readiness of the bound client (rejects if it timed out). */
15
+ this.ready = Promise.resolve();
14
16
  this.events = new web_sdk_1.OpenFeatureEventEmitter();
15
17
  this.trafficType = 'user';
16
18
  this.factory = splitFactory;
17
19
  this.client = splitFactory.client();
18
20
  }
19
- OpenFeatureSplitProvider.prototype.initialize = function () {
21
+ /**
22
+ * Warn through the Split SDK logger, so it follows the SDK log settings (`debug`, `factory.Logger`).
23
+ * `settings.log` is internal: the public typings only expose `factory.Logger`, which has no `warn`.
24
+ */
25
+ OpenFeatureSplitProvider.prototype.warn = function (message) {
26
+ var _a, _b, _c;
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ (_c = (_b = (_a = this.factory.settings) === null || _a === void 0 ? void 0 : _a.log) === null || _b === void 0 ? void 0 : _b.warn) === null || _c === void 0 ? void 0 : _c.call(_b, "[".concat(this.metadata.name, "-openfeature] ").concat(message));
29
+ };
30
+ /** Warn once per context set; evaluations reuse the context and would repeat it. */
31
+ OpenFeatureSplitProvider.prototype.warnIfBucketingKeyIgnored = function (context) {
32
+ var warning = (0, context_1.bucketingKeyWarning)(context);
33
+ if (warning)
34
+ this.warn(warning);
35
+ };
36
+ OpenFeatureSplitProvider.prototype.initialize = function (context) {
20
37
  return tslib_1.__awaiter(this, void 0, void 0, function () {
38
+ var key;
21
39
  var _this = this;
22
40
  return tslib_1.__generator(this, function (_a) {
23
41
  switch (_a.label) {
24
- case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
42
+ case 0:
43
+ if (context)
44
+ this.warnIfBucketingKeyIgnored(context);
45
+ key = context && (0, context_1.toSplitKey)((0, context_1.transformContext)(context, this.trafficType));
46
+ if (key)
47
+ this.client = this.factory.client(key);
48
+ this.ready = new Promise(function (resolve, reject) {
25
49
  try {
26
50
  (0, events_1.attachSplitReadyHandlers)(_this.client, _this.events, { onSdkReady: resolve, onSdkTimedOut: reject }, _this.metadata.name);
27
51
  (0, events_1.attachSplitUpdateHandler)(_this.client, _this.events, _this.metadata.name);
@@ -29,7 +53,8 @@ var OpenFeatureSplitProvider = /** @class */ (function () {
29
53
  catch (_a) {
30
54
  reject();
31
55
  }
32
- })];
56
+ });
57
+ return [4 /*yield*/, this.ready];
33
58
  case 1:
34
59
  _a.sent();
35
60
  return [2 /*return*/];
@@ -39,24 +64,35 @@ var OpenFeatureSplitProvider = /** @class */ (function () {
39
64
  };
40
65
  OpenFeatureSplitProvider.prototype.onContextChange = function (oldContext, newContext) {
41
66
  var _this = this;
42
- var oldTargetingKey = oldContext.targetingKey;
43
- var newTargetingKey = newContext.targetingKey, newTrafficType = newContext.trafficType;
67
+ this.warnIfBucketingKeyIgnored(newContext);
68
+ var newTrafficType = newContext.trafficType;
44
69
  this.trafficType =
45
70
  newTrafficType && newTrafficType !== this.trafficType
46
71
  ? newTrafficType
47
72
  : this.trafficType;
48
- if (newTargetingKey && newTargetingKey !== oldTargetingKey) {
49
- this.client = this.factory.client(newTargetingKey);
50
- return new Promise(function (resolve, reject) {
51
- var emitContextChange = function () {
52
- _this.events.emit(web_sdk_1.ProviderEvents.ConfigurationChanged);
53
- resolve();
54
- };
55
- (0, events_1.attachSplitReadyHandlers)(_this.client, _this.events, { onSdkReady: emitContextChange, onSdkTimedOut: reject }, _this.metadata.name);
56
- (0, events_1.attachSplitUpdateHandler)(_this.client, _this.events, _this.metadata.name);
57
- });
73
+ var oldConsumer = (0, context_1.transformContext)(oldContext, this.trafficType);
74
+ var newConsumer = (0, context_1.transformContext)(newContext, this.trafficType);
75
+ var newKey = (0, context_1.toSplitKey)(newConsumer);
76
+ var keyChanged = newConsumer.targetingKey !== oldConsumer.targetingKey ||
77
+ newConsumer.bucketingKey !== oldConsumer.bucketingKey;
78
+ if (!newKey || !keyChanged) {
79
+ // Same client: OpenFeature marks the provider READY when this resolves, so wait if it is still loading
80
+ // (a timeout during that load must still surface as ERROR). If it already timed out, that was reported
81
+ // and this.ready stays rejected, so resolve instead of moving the provider to ERROR on a no-key change.
82
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
+ var _a = this.client.__getStatus(), isReady = _a.isReady, hasTimedout = _a.hasTimedout;
84
+ return isReady || hasTimedout ? Promise.resolve() : this.ready;
58
85
  }
59
- return Promise.resolve();
86
+ this.client = this.factory.client(newKey);
87
+ this.ready = new Promise(function (resolve, reject) {
88
+ var emitContextChange = function () {
89
+ _this.events.emit(web_sdk_1.ProviderEvents.ConfigurationChanged);
90
+ resolve();
91
+ };
92
+ (0, events_1.attachSplitReadyHandlers)(_this.client, _this.events, { onSdkReady: emitContextChange, onSdkTimedOut: reject }, _this.metadata.name);
93
+ (0, events_1.attachSplitUpdateHandler)(_this.client, _this.events, _this.metadata.name);
94
+ });
95
+ return this.ready;
60
96
  };
61
97
  OpenFeatureSplitProvider.prototype.resolveBooleanEvaluation = function (flagKey, _, context, _logger) {
62
98
  var details = (0, evaluation_1.evaluateTreatment)(this.client, flagKey, (0, context_1.transformContext)(context, this.trafficType));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/openfeature-web-split-provider",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Split OpenFeature Web Provider",
5
5
  "files": [
6
6
  "README.md",
@@ -0,0 +1,145 @@
1
+ import { ProviderEvents } from '@openfeature/web-sdk';
2
+ import { OpenFeatureSplitProvider } from '../lib/js-split-provider';
3
+
4
+ const keyId = (key) => (typeof key === 'string' ? key : `${key.matchingKey}|${key.bucketingKey}`);
5
+
6
+ function makeClient() {
7
+ return {
8
+ __getStatus: () => ({ isReady: true }),
9
+ Event: { SDK_READY: 'SDK_READY', SDK_READY_FROM_CACHE: 'SDK_READY_FROM_CACHE', SDK_READY_TIMED_OUT: 'SDK_READY_TIMED_OUT', SDK_UPDATE: 'SDK_UPDATE' },
10
+ on: jest.fn(),
11
+ getTreatmentWithConfig: jest.fn(() => ({ treatment: 'on', config: null })),
12
+ };
13
+ }
14
+
15
+ /** Mock browser factory: one cached client per key, like the SDK. */
16
+ function makeFactory() {
17
+ const clients = {};
18
+ const factory = {
19
+ client: jest.fn((key = 'factory-key') => (clients[keyId(key)] ||= makeClient())),
20
+ settings: { log: { warn: jest.fn(), error: jest.fn(), info: jest.fn() } },
21
+ };
22
+ return { factory, clients };
23
+ }
24
+
25
+ /** factory.client calls made after the constructor. */
26
+ const clientCalls = (factory) => factory.client.mock.calls.slice(1).map((c) => c[0]);
27
+
28
+ describe('bucketingKey', () => {
29
+ test('initialize(context) binds { matchingKey, bucketingKey } and evaluates with that client', async () => {
30
+ const { factory, clients } = makeFactory();
31
+ const provider = new OpenFeatureSplitProvider(factory);
32
+ await provider.initialize({ targetingKey: 'u1', bucketingKey: 'b1' });
33
+ expect(clientCalls(factory)).toEqual([{ matchingKey: 'u1', bucketingKey: 'b1' }]);
34
+ provider.resolveStringEvaluation('flag', 'x', { targetingKey: 'u1', bucketingKey: 'b1', plan: 'pro' }, console);
35
+ expect(clients['u1|b1'].getTreatmentWithConfig).toHaveBeenCalledWith('flag', { plan: 'pro' });
36
+ });
37
+
38
+ test('initialize without a targeting key keeps the factory client', async () => {
39
+ const { factory } = makeFactory();
40
+ await new OpenFeatureSplitProvider(factory).initialize({ bucketingKey: 'b1' });
41
+ await new OpenFeatureSplitProvider(factory).initialize();
42
+ expect(factory.client.mock.calls.map((c) => c[0])).toEqual([undefined, undefined]);
43
+ });
44
+
45
+ describe('onContextChange', () => {
46
+ const base = { targetingKey: 'u1', bucketingKey: 'b1' };
47
+ let factory, clients, provider;
48
+
49
+ beforeEach(async () => {
50
+ ({ factory, clients } = makeFactory());
51
+ provider = new OpenFeatureSplitProvider(factory);
52
+ await provider.initialize(base);
53
+ factory.client.mockClear();
54
+ });
55
+
56
+ test('bucketingKey-only change binds a new client and emits ConfigurationChanged', async () => {
57
+ const emit = jest.spyOn(provider.events, 'emit');
58
+ await provider.onContextChange(base, { targetingKey: 'u1', bucketingKey: 'b2' });
59
+ expect(factory.client.mock.calls.map((c) => c[0])).toEqual([{ matchingKey: 'u1', bucketingKey: 'b2' }]);
60
+ expect(emit).toHaveBeenCalledWith(ProviderEvents.ConfigurationChanged);
61
+ });
62
+
63
+ test('removing the bucketingKey binds the targeting-key client', async () => {
64
+ await provider.onContextChange(base, { targetingKey: 'u1' });
65
+ expect(factory.client.mock.calls.map((c) => c[0])).toEqual(['u1']);
66
+ provider.resolveBooleanEvaluation('flag', false, { targetingKey: 'u1' }, console);
67
+ expect(clients.u1.getTreatmentWithConfig).toHaveBeenCalled();
68
+ });
69
+
70
+ test.each([
71
+ ['attributes-only change', { ...base, plan: 'pro' }],
72
+ ['bucketingKey only whitespace-different', { targetingKey: 'u1', bucketingKey: ' b1 ' }],
73
+ ['no targeting key', { bucketingKey: 'b2' }],
74
+ ])('%s: no new client', async (_, newContext) => {
75
+ await provider.onContextChange(base, newContext);
76
+ expect(factory.client).not.toHaveBeenCalled();
77
+ });
78
+ });
79
+
80
+ test('attribute-only change resolves when the bound client timed out', async () => {
81
+ const { factory, clients } = makeFactory();
82
+ const provider = new OpenFeatureSplitProvider(factory);
83
+ clients['u1|b1'] = {
84
+ ...makeClient(),
85
+ __getStatus: () => ({ isReady: false, isReadyFromCache: false, hasTimedout: true }),
86
+ };
87
+ await expect(provider.initialize({ targetingKey: 'u1', bucketingKey: 'b1' })).rejects.toBeUndefined();
88
+ factory.client.mockClear();
89
+
90
+ await expect(
91
+ provider.onContextChange({ targetingKey: 'u1', bucketingKey: 'b1' }, { targetingKey: 'u1', bucketingKey: 'b1', plan: 'pro' })
92
+ ).resolves.toBeUndefined();
93
+ expect(factory.client).not.toHaveBeenCalled();
94
+ });
95
+
96
+ describe('warnings', () => {
97
+ const warnings = (factory) => factory.settings.log.warn.mock.calls.map((c) => c[0]);
98
+
99
+ test('initialize warns through the Split logger with the reason, never the value', async () => {
100
+ const { factory } = makeFactory();
101
+ await new OpenFeatureSplitProvider(factory).initialize({ targetingKey: 'u1', bucketingKey: 'x'.repeat(251) });
102
+ expect(warnings(factory)).toEqual([
103
+ '[split-openfeature] bucketingKey ignored because it is longer than 250 characters; using the targeting key only.',
104
+ ]);
105
+ expect(factory.settings.log.error).not.toHaveBeenCalled();
106
+ expect(factory.settings.log.info).not.toHaveBeenCalled();
107
+ });
108
+
109
+ test('initialize warns when a bucketingKey comes without a targeting key', async () => {
110
+ const { factory } = makeFactory();
111
+ await new OpenFeatureSplitProvider(factory).initialize({ bucketingKey: 'b1' });
112
+ expect(warnings(factory)).toEqual(['[split-openfeature] bucketingKey ignored because the context has no targetingKey.']);
113
+ });
114
+
115
+ test.each([
116
+ ['non-string', { targetingKey: 'u1', bucketingKey: 7 }, 'it is not a string'],
117
+ ['blank', { targetingKey: 'u1', bucketingKey: ' ' }, 'it is blank'],
118
+ ['too long', { targetingKey: 'u2', bucketingKey: 'b'.repeat(251) }, 'it is longer than 250 characters'],
119
+ ['no targeting key', { bucketingKey: 'b2' }, 'the context has no targetingKey'],
120
+ ])('onContextChange warns for a %s bucketingKey', async (_, newContext, reason) => {
121
+ const { factory } = makeFactory();
122
+ const provider = new OpenFeatureSplitProvider(factory);
123
+ await provider.initialize({ targetingKey: 'u1', bucketingKey: 'b1' });
124
+ await provider.onContextChange({ targetingKey: 'u1', bucketingKey: 'b1' }, newContext);
125
+ expect(warnings(factory)).toHaveLength(1);
126
+ expect(warnings(factory)[0]).toContain(`bucketingKey ignored because ${reason}`);
127
+ expect(warnings(factory)[0]).not.toMatch(/for attribute/i);
128
+ });
129
+
130
+ test('valid contexts and evaluations do not warn', async () => {
131
+ const { factory } = makeFactory();
132
+ const provider = new OpenFeatureSplitProvider(factory);
133
+ await provider.initialize({ targetingKey: 'u1', bucketingKey: 'b1' });
134
+ await provider.onContextChange({ targetingKey: 'u1', bucketingKey: 'b1' }, { targetingKey: 'u1' });
135
+ provider.resolveBooleanEvaluation('flag', false, { targetingKey: 'u1', bucketingKey: ' ' }, console);
136
+ expect(factory.settings.log.warn).not.toHaveBeenCalled();
137
+ });
138
+
139
+ test('a factory without settings.log does not throw', async () => {
140
+ const { factory } = makeFactory();
141
+ delete factory.settings;
142
+ await expect(new OpenFeatureSplitProvider(factory).initialize({ bucketingKey: 'b1' })).resolves.toBeUndefined();
143
+ });
144
+ });
145
+ });
@@ -1,4 +1,4 @@
1
- import { transformContext } from '../lib/context';
1
+ import { bucketingKeyWarning, toSplitKey, transformContext } from '../lib/context';
2
2
 
3
3
  describe('context', () => {
4
4
  describe('transformContext', () => {
@@ -61,4 +61,86 @@ describe('context', () => {
61
61
  expect(result.attributes.nested).not.toBe(attrs.nested);
62
62
  });
63
63
  });
64
+
65
+ describe('transformContext bucketingKey', () => {
66
+ test('valid bucketingKey is trimmed and not forwarded as an attribute', () => {
67
+ const result = transformContext({ targetingKey: 'u1', bucketingKey: ' b1 ', plan: 'pro' }, 'user');
68
+ expect(result.bucketingKey).toBe('b1');
69
+ expect(result.attributes).toEqual({ plan: 'pro' });
70
+ });
71
+
72
+ test.each([undefined, null, '', ' ', 7, true, { x: 1 }, 'b'.repeat(251)])(
73
+ 'unusable bucketingKey %p is ignored and not forwarded',
74
+ (value) => {
75
+ const result = transformContext({ targetingKey: 'u1', bucketingKey: value }, 'user');
76
+ expect(result.bucketingKey).toBeUndefined();
77
+ expect(result.attributes).toEqual({});
78
+ }
79
+ );
80
+
81
+ test('other spellings stay attributes', () => {
82
+ const result = transformContext({ targetingKey: 'u1', BucketingKey: 'x', bucketing_key: 'y' }, 'user');
83
+ expect(result.bucketingKey).toBeUndefined();
84
+ expect(result.attributes).toEqual({ BucketingKey: 'x', bucketing_key: 'y' });
85
+ });
86
+ });
87
+
88
+ describe('toSplitKey', () => {
89
+ const key = (context) => toSplitKey(transformContext(context, 'user'));
90
+
91
+ test('targeting + bucketing key gives a composite key', () => {
92
+ expect(key({ targetingKey: 'u1', bucketingKey: 'b1' })).toEqual({ matchingKey: 'u1', bucketingKey: 'b1' });
93
+ });
94
+
95
+ test('no bucketingKey gives the targeting key', () => {
96
+ expect(key({ targetingKey: 'u1' })).toBe('u1');
97
+ });
98
+
99
+ test('missing or empty targeting key gives undefined', () => {
100
+ expect(key({ bucketingKey: 'b1' })).toBeUndefined();
101
+ expect(key({ targetingKey: '', bucketingKey: 'b1' })).toBeUndefined();
102
+ });
103
+ });
104
+
105
+ describe('bucketingKeyWarning', () => {
106
+ test.each([
107
+ [7, 'it is not a string'],
108
+ [true, 'it is not a string'],
109
+ [{ x: 1 }, 'it is not a string'],
110
+ ['', 'it is blank'],
111
+ [' ', 'it is blank'],
112
+ ['b'.repeat(251), 'it is longer than 250 characters'],
113
+ ])('unusable bucketingKey %p names the reason', (value, reason) => {
114
+ const warning = bucketingKeyWarning({ targetingKey: 'u1', bucketingKey: value });
115
+ expect(warning).toBe(`bucketingKey ignored because ${reason}; using the targeting key only.`);
116
+ });
117
+
118
+ test('invalid bucketingKey without a targeting key does not mention the targeting key', () => {
119
+ expect(bucketingKeyWarning({ bucketingKey: ' ' })).toBe('bucketingKey ignored because it is blank.');
120
+ expect(bucketingKeyWarning({ targetingKey: '', bucketingKey: 7 })).toBe('bucketingKey ignored because it is not a string.');
121
+ });
122
+
123
+ test('never includes the value', () => {
124
+ const secret = 's3cr3t-'.repeat(40);
125
+ expect(bucketingKeyWarning({ targetingKey: 'u1', bucketingKey: secret })).not.toContain('s3cr3t');
126
+ expect(bucketingKeyWarning({ bucketingKey: 's3cr3t' })).not.toContain('s3cr3t');
127
+ });
128
+
129
+ test.each([{}, { targetingKey: '' }])('valid bucketingKey without a targeting key: %p', (context) => {
130
+ expect(bucketingKeyWarning({ ...context, bucketingKey: 'b1' })).toBe(
131
+ 'bucketingKey ignored because the context has no targetingKey.'
132
+ );
133
+ });
134
+
135
+ test.each([
136
+ { targetingKey: 'u1' },
137
+ { targetingKey: 'u1', bucketingKey: null },
138
+ { bucketingKey: null },
139
+ { targetingKey: 'u1', bucketingKey: ' b1 ' },
140
+ { targetingKey: 'u1', bucketingKey: 'b'.repeat(250) },
141
+ {},
142
+ ])('nothing to report for %p', (context) => {
143
+ expect(bucketingKeyWarning(context)).toBeUndefined();
144
+ });
145
+ });
64
146
  });
@@ -0,0 +1,81 @@
1
+ import { OpenFeature, ProviderEvents } from '@openfeature/web-sdk';
2
+ import { SplitFactory } from '@splitsoftware/splitio-browserjs';
3
+ import { OpenFeatureSplitProvider } from '../../lib/js-split-provider';
4
+
5
+ // Context switching on one initialized provider with the real browser SDK (localhost mode):
6
+ // evaluate → add bucketingKey → evaluate → change it → remove it → blank → close.
7
+ describe('bucketingKey with the localhost browser SDK', () => {
8
+ let impressions;
9
+ let client;
10
+ let events;
11
+
12
+ beforeAll(async () => {
13
+ impressions = [];
14
+ const factory = SplitFactory({
15
+ core: { authorizationKey: 'localhost', key: 'factory-key' },
16
+ features: { my_feature: 'on' },
17
+ impressionListener: { logImpression: (data) => impressions.push({ ...data.impression, attributes: data.attributes }) },
18
+ });
19
+ events = [];
20
+ [ProviderEvents.Reconciling, ProviderEvents.ContextChanged, ProviderEvents.Error].forEach((e) =>
21
+ OpenFeature.addHandler(e, () => events.push(e))
22
+ );
23
+ await OpenFeature.setContext({ targetingKey: 'u1' });
24
+ await OpenFeature.setProviderAndWait(new OpenFeatureSplitProvider(factory));
25
+ client = OpenFeature.getClient();
26
+ });
27
+
28
+ afterAll(async () => {
29
+ await OpenFeature.close();
30
+ });
31
+
32
+ /** Evaluates with no invocation context and returns the impression's [keyName, bucketingKey]. */
33
+ async function evaluate() {
34
+ const before = impressions.length;
35
+ const details = client.getBooleanDetails('my_feature', false);
36
+ expect(details.errorCode).toBeUndefined();
37
+ expect(details.value).toBe(true);
38
+ await new Promise((r) => setTimeout(r, 0)); // the impression listener is called asynchronously
39
+ expect(impressions.length).toBe(before + 1);
40
+ const imp = impressions[impressions.length - 1];
41
+ return [imp.keyName, imp.bucketingKey];
42
+ }
43
+
44
+ test('initial context is applied at initialize', async () => {
45
+ expect(await evaluate()).toEqual(['u1', undefined]);
46
+ });
47
+
48
+ test('add, change, remove and blank bucketingKey switch the key; no Error', async () => {
49
+ events.length = 0;
50
+ await OpenFeature.setContext({ targetingKey: 'u1', bucketingKey: 'b1' });
51
+ expect(await evaluate()).toEqual(['u1', 'b1']);
52
+
53
+ await OpenFeature.setContext({ targetingKey: 'u1', bucketingKey: ' b2 ' });
54
+ expect(await evaluate()).toEqual(['u1', 'b2']);
55
+
56
+ await OpenFeature.setContext({ targetingKey: 'u1' });
57
+ expect(await evaluate()).toEqual(['u1', undefined]);
58
+
59
+ await OpenFeature.setContext({ targetingKey: 'u1', bucketingKey: 'b1' });
60
+ expect(await evaluate()).toEqual(['u1', 'b1']);
61
+
62
+ await OpenFeature.setContext({ targetingKey: 'u1', bucketingKey: ' ' });
63
+ expect(await evaluate()).toEqual(['u1', undefined]);
64
+
65
+ expect(events).not.toContain(ProviderEvents.Error);
66
+ expect(events.filter((e) => e === ProviderEvents.ContextChanged)).toHaveLength(5);
67
+ });
68
+
69
+ test('over-length bucketingKey falls back to the targeting key; no Error', async () => {
70
+ events.length = 0;
71
+ await OpenFeature.setContext({ targetingKey: 'u2', bucketingKey: 'b'.repeat(251) });
72
+ expect(await evaluate()).toEqual(['u2', undefined]);
73
+ expect(events).not.toContain(ProviderEvents.Error);
74
+ });
75
+
76
+ test('bucketingKey is not sent as an attribute; other spellings are', async () => {
77
+ await OpenFeature.setContext({ targetingKey: 'u1', bucketingKey: 'b1', plan: 'pro', BucketingKey: 'x' });
78
+ expect(await evaluate()).toEqual(['u1', 'b1']);
79
+ expect(impressions[impressions.length - 1].attributes).toEqual({ plan: 'pro', BucketingKey: 'x' });
80
+ });
81
+ });
@@ -1,21 +1,62 @@
1
1
  import type { EvaluationContext } from "@openfeature/web-sdk";
2
+ import type SplitIO from "@splitsoftware/splitio-browserjs/types/splitio";
2
3
  import type { Consumer } from "./types";
3
4
 
5
+ /** Split SDK limit for key values. */
6
+ const KEY_MAX_LENGTH = 250;
7
+
8
+ type BucketingKeyRead = { value?: string; reason?: string };
9
+
10
+ /** Trimmed bucketing key, or the reason it cannot be used. The reason never includes the value. */
11
+ function parseBucketingKey(value: unknown): BucketingKeyRead {
12
+ if (value === undefined || value === null) return {};
13
+ if (typeof value !== 'string') return { reason: 'it is not a string' };
14
+ const bucketingKey = value.trim();
15
+ if (!bucketingKey) return { reason: 'it is blank' };
16
+ if (bucketingKey.length > KEY_MAX_LENGTH) return { reason: `it is longer than ${KEY_MAX_LENGTH} characters` };
17
+ return { value: bucketingKey };
18
+ }
19
+
20
+ function readBucketingKey(value: unknown): string | undefined {
21
+ return parseBucketingKey(value).value;
22
+ }
23
+
24
+ /**
25
+ * Warning for a bucketingKey in the context that will not be used, or undefined when there is nothing to report.
26
+ * Names the reason only, never the value.
27
+ */
28
+ export function bucketingKeyWarning(context: EvaluationContext): string | undefined {
29
+ const { value, reason } = parseBucketingKey(context.bucketingKey);
30
+ if (reason) {
31
+ return `bucketingKey ignored because ${reason}${context.targetingKey ? '; using the targeting key only' : ''}.`;
32
+ }
33
+ if (value && !context.targetingKey) return 'bucketingKey ignored because the context has no targetingKey.';
34
+ return undefined;
35
+ }
36
+
4
37
  /**
5
38
  * Transform OpenFeature evaluation context into a consumer object for the Split API.
39
+ * `bucketingKey` is reserved: it is never forwarded as an attribute.
6
40
  */
7
41
  export function transformContext(
8
42
  context: EvaluationContext,
9
43
  defaultTrafficType: string
10
44
  ): Consumer {
11
- const { targetingKey, trafficType: ttVal, ...attributes } = context;
45
+ const { targetingKey, bucketingKey, trafficType: ttVal, ...attributes } = context;
12
46
  const trafficType =
13
47
  ttVal != null && typeof ttVal === 'string' && ttVal.trim() !== ''
14
48
  ? ttVal
15
49
  : defaultTrafficType;
16
50
  return {
17
51
  targetingKey,
52
+ bucketingKey: readBucketingKey(bucketingKey),
18
53
  trafficType,
19
54
  attributes: JSON.parse(JSON.stringify(attributes)),
20
55
  };
21
56
  }
57
+
58
+ /** Split key for a consumer: `{ matchingKey, bucketingKey }` or the targeting key alone. */
59
+ export function toSplitKey({ targetingKey, bucketingKey }: Consumer): SplitIO.SplitKey | undefined {
60
+ if (!targetingKey) return undefined;
61
+ return bucketingKey ? { matchingKey: targetingKey, bucketingKey } : targetingKey;
62
+ }
@@ -12,7 +12,7 @@ import {
12
12
  } from "@openfeature/web-sdk";
13
13
  import type SplitIO from "@splitsoftware/splitio-browserjs/types/splitio";
14
14
 
15
- import { transformContext } from "./context";
15
+ import { bucketingKeyWarning, toSplitKey, transformContext } from "./context";
16
16
  import { attachSplitReadyHandlers, attachSplitUpdateHandler } from "./events";
17
17
  import { evaluateTreatment } from "./evaluation";
18
18
  import { parseBooleanTreatment, parseValidJsonObject, parseValidNumber } from "./parsers";
@@ -23,6 +23,8 @@ export class OpenFeatureSplitProvider implements Provider {
23
23
  private client: SplitIO.IBrowserClient;
24
24
  private factory: SplitIO.IBrowserSDK;
25
25
  private trafficType: string;
26
+ /** Readiness of the bound client (rejects if it timed out). */
27
+ private ready: Promise<void> = Promise.resolve();
26
28
  public events = new OpenFeatureEventEmitter();
27
29
 
28
30
  constructor(splitFactory: SplitIO.IBrowserSDK) {
@@ -31,8 +33,28 @@ export class OpenFeatureSplitProvider implements Provider {
31
33
  this.client = splitFactory.client();
32
34
  }
33
35
 
34
- async initialize(): Promise<void> {
35
- await new Promise<void>((resolve, reject) => {
36
+ /**
37
+ * Warn through the Split SDK logger, so it follows the SDK log settings (`debug`, `factory.Logger`).
38
+ * `settings.log` is internal: the public typings only expose `factory.Logger`, which has no `warn`.
39
+ */
40
+ private warn(message: string): void {
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
+ (this.factory as any).settings?.log?.warn?.(`[${this.metadata.name}-openfeature] ${message}`);
43
+ }
44
+
45
+ /** Warn once per context set; evaluations reuse the context and would repeat it. */
46
+ private warnIfBucketingKeyIgnored(context: EvaluationContext): void {
47
+ const warning = bucketingKeyWarning(context);
48
+ if (warning) this.warn(warning);
49
+ }
50
+
51
+ async initialize(context?: EvaluationContext): Promise<void> {
52
+ if (context) this.warnIfBucketingKeyIgnored(context);
53
+ // Apply the context set before the provider. The SDK returns the factory client for the factory key.
54
+ const key = context && toSplitKey(transformContext(context, this.trafficType));
55
+ if (key) this.client = this.factory.client(key);
56
+
57
+ this.ready = new Promise<void>((resolve, reject) => {
36
58
  try {
37
59
  attachSplitReadyHandlers(
38
60
  this.client,
@@ -45,34 +67,49 @@ export class OpenFeatureSplitProvider implements Provider {
45
67
  reject();
46
68
  }
47
69
  });
70
+ await this.ready;
48
71
  }
49
72
 
50
73
  onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void> {
51
- const { targetingKey: oldTargetingKey } = oldContext;
52
- const { targetingKey: newTargetingKey, trafficType: newTrafficType } = newContext;
74
+ this.warnIfBucketingKeyIgnored(newContext);
75
+ const { trafficType: newTrafficType } = newContext;
53
76
 
54
77
  this.trafficType =
55
78
  newTrafficType && newTrafficType !== this.trafficType
56
79
  ? (newTrafficType as string)
57
80
  : this.trafficType;
58
81
 
59
- if (newTargetingKey && newTargetingKey !== oldTargetingKey) {
60
- this.client = this.factory.client(newTargetingKey);
61
- return new Promise((resolve, reject) => {
62
- const emitContextChange = () => {
63
- this.events.emit(ProviderEvents.ConfigurationChanged);
64
- resolve();
65
- };
66
- attachSplitReadyHandlers(
67
- this.client,
68
- this.events,
69
- { onSdkReady: emitContextChange, onSdkTimedOut: reject },
70
- this.metadata.name
71
- );
72
- attachSplitUpdateHandler(this.client, this.events, this.metadata.name);
73
- });
82
+ const oldConsumer = transformContext(oldContext, this.trafficType);
83
+ const newConsumer = transformContext(newContext, this.trafficType);
84
+ const newKey = toSplitKey(newConsumer);
85
+ const keyChanged =
86
+ newConsumer.targetingKey !== oldConsumer.targetingKey ||
87
+ newConsumer.bucketingKey !== oldConsumer.bucketingKey;
88
+
89
+ if (!newKey || !keyChanged) {
90
+ // Same client: OpenFeature marks the provider READY when this resolves, so wait if it is still loading
91
+ // (a timeout during that load must still surface as ERROR). If it already timed out, that was reported
92
+ // and this.ready stays rejected, so resolve instead of moving the provider to ERROR on a no-key change.
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ const { isReady, hasTimedout } = (this.client as any).__getStatus();
95
+ return isReady || hasTimedout ? Promise.resolve() : this.ready;
74
96
  }
75
- return Promise.resolve();
97
+
98
+ this.client = this.factory.client(newKey);
99
+ this.ready = new Promise((resolve, reject) => {
100
+ const emitContextChange = () => {
101
+ this.events.emit(ProviderEvents.ConfigurationChanged);
102
+ resolve();
103
+ };
104
+ attachSplitReadyHandlers(
105
+ this.client,
106
+ this.events,
107
+ { onSdkReady: emitContextChange, onSdkTimedOut: reject },
108
+ this.metadata.name
109
+ );
110
+ attachSplitUpdateHandler(this.client, this.events, this.metadata.name);
111
+ });
112
+ return this.ready;
76
113
  }
77
114
 
78
115
  resolveBooleanEvaluation(
package/src/lib/types.ts CHANGED
@@ -2,6 +2,8 @@ import type SplitIO from "@splitsoftware/splitio-browserjs/types/splitio";
2
2
 
3
3
  export type Consumer = {
4
4
  targetingKey: string | undefined;
5
+ /** Trimmed bucketing key, or undefined when missing or unusable (blank, not a string, > 250 chars). */
6
+ bucketingKey: string | undefined;
5
7
  trafficType: string;
6
8
  attributes: SplitIO.Attributes;
7
9
  };
@@ -1,6 +1,15 @@
1
1
  import type { EvaluationContext } from "@openfeature/web-sdk";
2
+ import type SplitIO from "@splitsoftware/splitio-browserjs/types/splitio";
2
3
  import type { Consumer } from "./types";
4
+ /**
5
+ * Warning for a bucketingKey in the context that will not be used, or undefined when there is nothing to report.
6
+ * Names the reason only, never the value.
7
+ */
8
+ export declare function bucketingKeyWarning(context: EvaluationContext): string | undefined;
3
9
  /**
4
10
  * Transform OpenFeature evaluation context into a consumer object for the Split API.
11
+ * `bucketingKey` is reserved: it is never forwarded as an attribute.
5
12
  */
6
13
  export declare function transformContext(context: EvaluationContext, defaultTrafficType: string): Consumer;
14
+ /** Split key for a consumer: `{ matchingKey, bucketingKey }` or the targeting key alone. */
15
+ export declare function toSplitKey({ targetingKey, bucketingKey }: Consumer): SplitIO.SplitKey | undefined;
@@ -7,9 +7,18 @@ export declare class OpenFeatureSplitProvider implements Provider {
7
7
  private client;
8
8
  private factory;
9
9
  private trafficType;
10
+ /** Readiness of the bound client (rejects if it timed out). */
11
+ private ready;
10
12
  events: OpenFeatureEventEmitter;
11
13
  constructor(splitFactory: SplitIO.IBrowserSDK);
12
- initialize(): Promise<void>;
14
+ /**
15
+ * Warn through the Split SDK logger, so it follows the SDK log settings (`debug`, `factory.Logger`).
16
+ * `settings.log` is internal: the public typings only expose `factory.Logger`, which has no `warn`.
17
+ */
18
+ private warn;
19
+ /** Warn once per context set; evaluations reuse the context and would repeat it. */
20
+ private warnIfBucketingKeyIgnored;
21
+ initialize(context?: EvaluationContext): Promise<void>;
13
22
  onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>;
14
23
  resolveBooleanEvaluation(flagKey: string, _: boolean, context: EvaluationContext, _logger: Logger): ResolutionDetails<boolean>;
15
24
  resolveStringEvaluation(flagKey: string, _: string, context: EvaluationContext, _logger: Logger): ResolutionDetails<string>;
@@ -1,6 +1,8 @@
1
1
  import type SplitIO from "@splitsoftware/splitio-browserjs/types/splitio";
2
2
  export type Consumer = {
3
3
  targetingKey: string | undefined;
4
+ /** Trimmed bucketing key, or undefined when missing or unusable (blank, not a string, > 250 chars). */
5
+ bucketingKey: string | undefined;
4
6
  trafficType: string;
5
7
  attributes: SplitIO.Attributes;
6
8
  };