@splitsoftware/openfeature-js-split-provider 1.2.0 → 1.4.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.
Files changed (38) hide show
  1. package/CHANGES.txt +14 -0
  2. package/README.md +37 -3
  3. package/es/lib/client-resolver.js +17 -0
  4. package/es/lib/context.js +28 -0
  5. package/es/lib/js-split-provider.js +66 -103
  6. package/es/lib/parsers.js +26 -0
  7. package/es/lib/readiness.js +64 -0
  8. package/es/lib/types.js +4 -0
  9. package/es/package.json +1 -0
  10. package/lib/index.js +1 -1
  11. package/lib/lib/client-resolver.js +21 -0
  12. package/lib/lib/context.js +32 -0
  13. package/lib/lib/js-split-provider.js +68 -105
  14. package/lib/lib/parsers.js +31 -0
  15. package/lib/lib/readiness.js +70 -0
  16. package/lib/lib/types.js +7 -0
  17. package/package.json +12 -7
  18. package/src/__tests__/nodeSuites/client.spec.js +17 -2
  19. package/src/__tests__/nodeSuites/client_redis.spec.js +9 -10
  20. package/src/__tests__/nodeSuites/provider.spec.js +191 -0
  21. package/src/index.ts +1 -1
  22. package/src/lib/__tests__/client-resolver.spec.ts +64 -0
  23. package/src/lib/__tests__/context.spec.ts +114 -0
  24. package/src/lib/__tests__/parsers.spec.ts +63 -0
  25. package/src/lib/__tests__/readiness.spec.ts +159 -0
  26. package/src/lib/client-resolver.ts +22 -0
  27. package/src/lib/context.ts +35 -0
  28. package/src/lib/js-split-provider.ts +120 -144
  29. package/src/lib/parsers.ts +32 -0
  30. package/src/lib/readiness.ts +103 -0
  31. package/src/lib/types.ts +41 -0
  32. package/types/index.d.ts +1 -1
  33. package/types/lib/client-resolver.d.ts +7 -0
  34. package/types/lib/context.d.ts +8 -0
  35. package/types/lib/js-split-provider.d.ts +16 -18
  36. package/types/lib/parsers.d.ts +3 -0
  37. package/types/lib/readiness.d.ts +16 -0
  38. package/types/lib/types.d.ts +32 -0
package/CHANGES.txt CHANGED
@@ -1,3 +1,17 @@
1
+ 1.4.0 (November 26, 2026)
2
+ - Added support for the `bucketingKey` evaluation context attribute: when it is a non-blank string, the provider evaluates with Split key { matchingKey: targetingKey, bucketingKey }.
3
+ - BREAKING-ish behavior change: `bucketingKey` is no longer forwarded to Split as a targeting attribute. Targeting rules on an attribute literally named `bucketingKey` stop matching.
4
+ - A `bucketingKey` longer than 250 characters now makes the evaluation return the default value (Split `control`, FLAG_NOT_FOUND) instead of being ignored.
5
+ - `bucketingKey` is trimmed; blank or non-string values are ignored with a warning.
6
+ - Fixed native ESM import failing with ERR_MODULE_NOT_FOUND on Node.js (relative imports now include `.js` extensions and the `es` build is marked as `"type": "module"`) (#26).
7
+ - Fixed `repository`, `homepage` and `bugs` URLs in package.json.
8
+ - Added a `types` condition to package.json `exports` so TypeScript resolves the type definitions with `moduleResolution` `node16`, `nodenext` and `bundler`.
9
+ - Added `tslib` as an explicit dependency (it was required by the build output but only installed transitively).
10
+
11
+ 1.3.0 (March 2, 2026)
12
+ - Updated ConfigurationChanged event to forward SDK_UPDATE metadata from Split (flagsChanged, metadata with type and names)
13
+ - Requires @splitsoftware/splitio ^11.10.0 for SDK_UPDATE metadata support
14
+
1
15
  1.2.0 (November 7, 2025)
2
16
  - Updated @openfeature/server-sdk to 1.20.0
3
17
  - Updated @splitsoftware/splitio to 11.8.0
package/README.md CHANGED
@@ -30,7 +30,9 @@ const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-pr
30
30
 
31
31
  const authorizationKey = 'your auth key'
32
32
  const provider = new OpenFeatureSplitProvider(authorizationKey);
33
- OpenFeature.setProvider(provider);
33
+ await OpenFeature.setProviderAndWait(provider);
34
+ const client = OpenFeature.getClient('my-app');
35
+ // safe to evaluate
34
36
  ```
35
37
 
36
38
  ### Register the Split provider with OpenFeature using splitFactory
@@ -42,7 +44,9 @@ const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-pr
42
44
  const authorizationKey = 'your auth key'
43
45
  const splitFactory = SplitFactory({core: {authorizationKey}});
44
46
  const provider = new OpenFeatureSplitProvider(splitFactory);
45
- OpenFeature.setProvider(provider);
47
+ await OpenFeature.setProviderAndWait(provider);
48
+ const client = OpenFeature.getClient('my-app');
49
+ // safe to evaluate
46
50
  ```
47
51
 
48
52
  ### Register the Split provider with OpenFeature using splitClient
@@ -54,7 +58,9 @@ const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-pr
54
58
  const authorizationKey = 'your auth key'
55
59
  const splitClient = SplitFactory({core: {authorizationKey}}).client();
56
60
  const provider = new OpenFeatureSplitProvider({splitClient});
57
- OpenFeature.setProvider(provider);
61
+ await OpenFeature.setProviderAndWait(provider);
62
+ const client = OpenFeature.getClient('my-app');
63
+ // safe to evaluate
58
64
  ```
59
65
 
60
66
  ## Use of OpenFeature with Split
@@ -85,6 +91,18 @@ OpenFeatureAPI.getInstance().setCtx(context)
85
91
  ```
86
92
  If the context was set at the client or api level, it is not required to provide it during flag evaluation.
87
93
 
94
+ ### Bucketing key
95
+ Set `bucketingKey` in the evaluation context to have Split bucket on a different key than the targeting key (Split's matching key + bucketing key). It is optional and sits next to `targetingKey` and `trafficType`:
96
+ ```js
97
+ const context = { targetingKey: 'user-123', bucketingKey: 'account-42' };
98
+ const value = await client.getBooleanValue('boolFlag', false, context);
99
+ ```
100
+ - `bucketingKey` is reserved: it is **not** forwarded to Split as an attribute.
101
+ - Leading/trailing whitespace is trimmed. A blank or non-string value is ignored (a warning is logged through the OpenFeature logger) and the targeting key alone is used.
102
+ - An empty targeting key (`''`) is treated as missing.
103
+ - A value longer than 250 characters is rejected by the Split SDK: the evaluation returns the default value (`FLAG_NOT_FOUND`, Split `control`).
104
+ - A targeting key is still required. `track` sends the targeting key only.
105
+
88
106
  ## Evaluate with details
89
107
  Use the get*Details(...) APIs to get the value and rich context (variant, reason, error code, metadata). This provider includes the Split treatment config as a raw JSON string under flagMetadata["config"]
90
108
 
@@ -94,6 +112,22 @@ const booleanTreatment = await client.getBooleanDetails('boolFlag', false, conte
94
112
  const config = booleanTreatment.flagMetadata.config
95
113
  ```
96
114
 
115
+ ## Configuration changed event (SDK_UPDATE)
116
+
117
+ 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).
118
+
119
+ Requires `@splitsoftware/splitio` **11.10.0 or later** (metadata was added in 11.10.0).
120
+
121
+ ```js
122
+ const { OpenFeature, ProviderEvents } = require('@openfeature/server-sdk');
123
+
124
+ const client = OpenFeature.getClient();
125
+ client.addHandler(ProviderEvents.ConfigurationChanged, (eventDetails) => {
126
+ console.log('Flags changed:', eventDetails.flagsChanged);
127
+ console.log('Event metadata:', eventDetails.metadata);
128
+ });
129
+ ```
130
+
97
131
  ## Tracking
98
132
 
99
133
  To use track(eventName, context, details) you must provide:
@@ -0,0 +1,17 @@
1
+ import { SplitFactory } from '@splitsoftware/splitio';
2
+ /**
3
+ * Resolves the Split client from the various supported constructor option shapes.
4
+ * Supports: API key (string), Split SDK/AsyncSDK (factory), or pre-built splitClient.
5
+ */
6
+ export function getSplitClient(options) {
7
+ if (typeof options === 'string') {
8
+ const splitFactory = SplitFactory({ core: { authorizationKey: options } });
9
+ return splitFactory.client();
10
+ }
11
+ try {
12
+ return options.client();
13
+ }
14
+ catch {
15
+ return options.splitClient;
16
+ }
17
+ }
@@ -0,0 +1,28 @@
1
+ import { DEFAULT_TRAFFIC_TYPE } from './types.js';
2
+ function readBucketingKey(value) {
3
+ if (value == null)
4
+ return {};
5
+ if (typeof value !== 'string')
6
+ return { bucketingKeyIssue: 'not a string' };
7
+ const bucketingKey = value.trim();
8
+ if (bucketingKey === '')
9
+ return { bucketingKeyIssue: 'blank' };
10
+ return { bucketingKey };
11
+ }
12
+ /**
13
+ * Transforms OpenFeature evaluation context into the consumer shape used by the Split API:
14
+ * targeting key, bucketing key (validated, trimmed), traffic type (with default),
15
+ * and remaining attributes. `bucketingKey` is never forwarded as an attribute.
16
+ */
17
+ export function transformContext(context, defaultTrafficType = DEFAULT_TRAFFIC_TYPE) {
18
+ const { targetingKey, bucketingKey, trafficType: ttVal, ...attributes } = context;
19
+ const trafficType = ttVal != null && typeof ttVal === 'string' && ttVal.trim() !== ''
20
+ ? ttVal
21
+ : defaultTrafficType;
22
+ return {
23
+ targetingKey,
24
+ ...readBucketingKey(bucketingKey),
25
+ trafficType,
26
+ attributes: JSON.parse(JSON.stringify(attributes)),
27
+ };
28
+ }
@@ -1,36 +1,44 @@
1
1
  import { FlagNotFoundError, OpenFeatureEventEmitter, ParseError, ProviderEvents, StandardResolutionReasons, TargetingKeyMissingError } from '@openfeature/server-sdk';
2
- import { SplitFactory } from '@splitsoftware/splitio';
3
- const CONTROL_VALUE_ERROR_MESSAGE = 'Received the "control" value from Split.';
4
- const CONTROL_TREATMENT = 'control';
2
+ import { getSplitClient } from './client-resolver.js';
3
+ import { transformContext } from './context.js';
4
+ import { parseValidJsonObject, parseValidNumber } from './parsers.js';
5
+ import { attachReadyEventHandlers, waitUntilReady } from './readiness.js';
6
+ import { CONTROL_TREATMENT, CONTROL_VALUE_ERROR_MESSAGE, DEFAULT_TRAFFIC_TYPE, PROVIDER_NAME } from './types.js';
5
7
  export class OpenFeatureSplitProvider {
6
- getSplitClient(options) {
7
- if (typeof (options) === 'string') {
8
- const splitFactory = SplitFactory({ core: { authorizationKey: options } });
9
- return splitFactory.client();
10
- }
11
- let splitClient;
12
- try {
13
- splitClient = options.client();
14
- }
15
- catch {
16
- splitClient = options.splitClient;
17
- }
18
- return splitClient;
19
- }
20
8
  constructor(options) {
21
9
  this.metadata = {
22
- name: 'split',
10
+ name: PROVIDER_NAME,
23
11
  };
12
+ this.runsOn = 'server';
13
+ // Invalid-bucketingKey reasons already warned about; repeats are logged at debug.
14
+ this.warnedBucketingKeyIssues = new Set();
24
15
  this.events = new OpenFeatureEventEmitter();
25
- // Asume 'user' as default traffic type'
26
- this.trafficType = 'user';
27
- this.client = this.getSplitClient(options);
28
- this.client.on(this.client.Event.SDK_UPDATE, () => {
29
- this.events.emit(ProviderEvents.ConfigurationChanged);
16
+ this.trafficType = DEFAULT_TRAFFIC_TYPE;
17
+ this.client = getSplitClient(options);
18
+ attachReadyEventHandlers(this.client, this.events, this.metadata.name);
19
+ this.client.on(this.client.Event.SDK_UPDATE, (updateMetadata) => {
20
+ const eventDetails = {
21
+ providerName: this.metadata.name,
22
+ ...(updateMetadata
23
+ ? {
24
+ metadata: { type: updateMetadata.type },
25
+ flagsChanged: updateMetadata.names || [],
26
+ }
27
+ : {}),
28
+ };
29
+ this.events.emit(ProviderEvents.ConfigurationChanged, eventDetails);
30
30
  });
31
31
  }
32
- async resolveBooleanEvaluation(flagKey, _, context) {
33
- const details = await this.evaluateTreatment(flagKey, this.transformContext(context));
32
+ /**
33
+ * Called by the SDK after the provider is set. Waits for the Split client to be ready.
34
+ * When this promise resolves, the SDK emits ProviderEvents.Ready.
35
+ */
36
+ async initialize(_context) {
37
+ void _context;
38
+ await waitUntilReady(this.client, this.events, this.metadata.name);
39
+ }
40
+ async resolveBooleanEvaluation(flagKey, _, context, logger) {
41
+ const details = await this.evaluateTreatment(flagKey, transformContext(context, this.trafficType), logger);
34
42
  const treatment = details.value.toLowerCase();
35
43
  if (treatment === 'on' || treatment === 'true') {
36
44
  return { ...details, value: true };
@@ -40,49 +48,58 @@ export class OpenFeatureSplitProvider {
40
48
  }
41
49
  throw new ParseError(`Invalid boolean value for ${treatment}`);
42
50
  }
43
- async resolveStringEvaluation(flagKey, _, context) {
44
- const details = await this.evaluateTreatment(flagKey, this.transformContext(context));
45
- return details;
51
+ async resolveStringEvaluation(flagKey, _, context, logger) {
52
+ return this.evaluateTreatment(flagKey, transformContext(context, this.trafficType), logger);
46
53
  }
47
- async resolveNumberEvaluation(flagKey, _, context) {
48
- const details = await this.evaluateTreatment(flagKey, this.transformContext(context));
49
- return { ...details, value: this.parseValidNumber(details.value) };
54
+ async resolveNumberEvaluation(flagKey, _, context, logger) {
55
+ const details = await this.evaluateTreatment(flagKey, transformContext(context, this.trafficType), logger);
56
+ return { ...details, value: parseValidNumber(details.value) };
50
57
  }
51
- async resolveObjectEvaluation(flagKey, _, context) {
52
- const details = await this.evaluateTreatment(flagKey, this.transformContext(context));
53
- return { ...details, value: this.parseValidJsonObject(details.value) };
58
+ async resolveObjectEvaluation(flagKey, _, context, logger) {
59
+ const details = await this.evaluateTreatment(flagKey, transformContext(context, this.trafficType), logger);
60
+ return { ...details, value: parseValidJsonObject(details.value) };
54
61
  }
55
- async evaluateTreatment(flagKey, consumer) {
62
+ async evaluateTreatment(flagKey, consumer, logger) {
56
63
  if (!consumer.targetingKey) {
57
64
  throw new TargetingKeyMissingError('The Split provider requires a targeting key.');
58
65
  }
59
66
  if (flagKey == null || flagKey === '') {
60
67
  throw new FlagNotFoundError('flagKey must be a non-empty string');
61
68
  }
62
- await new Promise((resolve, reject) => {
63
- this.readinessHandler(resolve, reject);
64
- });
65
- const { treatment: value, config } = await this.client.getTreatmentWithConfig(consumer.targetingKey, flagKey, consumer.attributes);
69
+ if (consumer.bucketingKeyIssue) {
70
+ const message = `Split provider: ignoring bucketingKey (${consumer.bucketingKeyIssue}); evaluating with the targeting key only.`;
71
+ if (this.warnedBucketingKeyIssues.has(consumer.bucketingKeyIssue)) {
72
+ logger?.debug(message);
73
+ }
74
+ else {
75
+ this.warnedBucketingKeyIssues.add(consumer.bucketingKeyIssue);
76
+ logger?.warn(message);
77
+ }
78
+ }
79
+ const splitKey = consumer.bucketingKey
80
+ ? { matchingKey: consumer.targetingKey, bucketingKey: consumer.bucketingKey }
81
+ : consumer.targetingKey;
82
+ await waitUntilReady(this.client, this.events, this.metadata.name);
83
+ const { treatment: value, config } = await this.client.getTreatmentWithConfig(splitKey, flagKey, consumer.attributes);
66
84
  if (value === CONTROL_TREATMENT) {
67
85
  throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE);
68
86
  }
69
- const flagMetadata = { config: config ? config : '' };
70
- const details = {
71
- value: value,
87
+ const flagMetadata = Object.freeze({ config: config ?? '' });
88
+ return {
89
+ value,
72
90
  variant: value,
73
- flagMetadata: flagMetadata,
91
+ flagMetadata,
74
92
  reason: StandardResolutionReasons.TARGETING_MATCH,
75
93
  };
76
- return details;
77
94
  }
78
95
  async track(trackingEventName, context, details) {
79
- // eventName is always required
80
- if (trackingEventName == null || trackingEventName === '')
96
+ if (trackingEventName == null || trackingEventName === '') {
81
97
  throw new ParseError('Missing eventName, required to track');
82
- // targetingKey is always required
83
- const { targetingKey, trafficType } = this.transformContext(context);
84
- if (targetingKey == null || targetingKey === '')
98
+ }
99
+ const { targetingKey, trafficType } = transformContext(context, this.trafficType);
100
+ if (targetingKey == null || targetingKey === '') {
85
101
  throw new TargetingKeyMissingError('Missing targetingKey, required to track');
102
+ }
86
103
  let value;
87
104
  let properties = {};
88
105
  if (details != null) {
@@ -98,58 +115,4 @@ export class OpenFeatureSplitProvider {
98
115
  async onClose() {
99
116
  return this.client.destroy();
100
117
  }
101
- //Transform the context into an object useful for the Split API, an key string with arbitrary Split 'Attributes'.
102
- transformContext(context) {
103
- const { targetingKey, trafficType: ttVal, ...attributes } = context;
104
- const trafficType = ttVal != null && typeof ttVal === 'string' && ttVal.trim() !== ''
105
- ? ttVal
106
- : this.trafficType;
107
- return {
108
- targetingKey,
109
- trafficType,
110
- // Stringify context objects include date.
111
- attributes: JSON.parse(JSON.stringify(attributes)),
112
- };
113
- }
114
- parseValidNumber(stringValue) {
115
- if (stringValue === undefined) {
116
- throw new ParseError(`Invalid 'undefined' value.`);
117
- }
118
- const result = Number.parseFloat(stringValue);
119
- if (Number.isNaN(result)) {
120
- throw new ParseError(`Invalid numeric value ${stringValue}`);
121
- }
122
- return result;
123
- }
124
- parseValidJsonObject(stringValue) {
125
- if (stringValue === undefined) {
126
- throw new ParseError(`Invalid 'undefined' JSON value.`);
127
- }
128
- // we may want to allow the parsing to be customized.
129
- try {
130
- const value = JSON.parse(stringValue);
131
- if (typeof value !== 'object') {
132
- throw new ParseError(`Flag value ${stringValue} had unexpected type ${typeof value}, expected "object"`);
133
- }
134
- return value;
135
- }
136
- catch (err) {
137
- throw new ParseError(`Error parsing ${stringValue} as JSON, ${err}`);
138
- }
139
- }
140
- async readinessHandler(onSdkReady, onSdkTimedOut) {
141
- const clientStatus = this.client.getStatus();
142
- if (clientStatus.isReady) {
143
- onSdkReady();
144
- }
145
- else {
146
- if (clientStatus.hasTimedout) {
147
- onSdkTimedOut();
148
- }
149
- else {
150
- this.client.on(this.client.Event.SDK_READY_TIMED_OUT, onSdkTimedOut);
151
- }
152
- this.client.on(this.client.Event.SDK_READY, onSdkReady);
153
- }
154
- }
155
118
  }
@@ -0,0 +1,26 @@
1
+ import { ParseError } from '@openfeature/server-sdk';
2
+ export function parseValidNumber(stringValue) {
3
+ if (stringValue === undefined) {
4
+ throw new ParseError(`Invalid 'undefined' value.`);
5
+ }
6
+ const result = Number.parseFloat(stringValue);
7
+ if (Number.isNaN(result)) {
8
+ throw new ParseError(`Invalid numeric value ${stringValue}`);
9
+ }
10
+ return result;
11
+ }
12
+ export function parseValidJsonObject(stringValue) {
13
+ if (stringValue === undefined) {
14
+ throw new ParseError(`Invalid 'undefined' JSON value.`);
15
+ }
16
+ try {
17
+ const value = JSON.parse(stringValue);
18
+ if (typeof value !== 'object') {
19
+ throw new ParseError(`Flag value ${stringValue} had unexpected type ${typeof value}, expected "object"`);
20
+ }
21
+ return value;
22
+ }
23
+ catch (err) {
24
+ throw new ParseError(`Error parsing ${stringValue} as JSON, ${err}`);
25
+ }
26
+ }
@@ -0,0 +1,64 @@
1
+ import { ProviderEvents } from '@openfeature/server-sdk';
2
+ import { PROVIDER_NAME } from './types.js';
3
+ /**
4
+ * Builds OpenFeature Ready event details including Split SDK ready metadata.
5
+ * Handles Split SDK not passing metadata (e.g. in consumer/Redis mode).
6
+ */
7
+ function buildReadyEventDetails(providerName, splitMetadata, readyFromCache) {
8
+ const metadata = {
9
+ readyFromCache,
10
+ initialCacheLoad: splitMetadata?.initialCacheLoad ?? false,
11
+ };
12
+ if (splitMetadata?.lastUpdateTimestamp != null) {
13
+ metadata.lastUpdateTimestamp = splitMetadata.lastUpdateTimestamp;
14
+ }
15
+ return {
16
+ providerName: providerName || PROVIDER_NAME,
17
+ metadata,
18
+ };
19
+ }
20
+ /**
21
+ * Registers Split SDK_READY and SDK_READY_FROM_CACHE listeners and forwards them
22
+ * as OpenFeature ProviderEvents.Ready with event metadata (initialCacheLoad, lastUpdateTimestamp, readyFromCache).
23
+ * If the client is already ready when attaching (e.g. localhost or reused client), emits Ready once
24
+ * with best-effort metadata so handlers always receive at least one Ready when the client is ready.
25
+ */
26
+ export function attachReadyEventHandlers(client, events, providerName = PROVIDER_NAME) {
27
+ client.on(client.Event.SDK_READY_FROM_CACHE, (splitMetadata) => {
28
+ events.emit(ProviderEvents.Ready, buildReadyEventDetails(providerName, splitMetadata, true));
29
+ });
30
+ client.on(client.Event.SDK_READY, (splitMetadata) => {
31
+ events.emit(ProviderEvents.Ready, buildReadyEventDetails(providerName, splitMetadata, false));
32
+ });
33
+ const status = client.getStatus();
34
+ if (status.isReady) {
35
+ events.emit(ProviderEvents.Ready, buildReadyEventDetails(providerName, undefined, false));
36
+ }
37
+ }
38
+ /**
39
+ * Returns a promise that resolves when the Split client is ready (SDK_READY),
40
+ * or rejects if the client has timed out (SDK_READY_TIMED_OUT).
41
+ * Used to gate evaluations until the SDK has synchronized with the backend.
42
+ */
43
+ export function waitUntilReady(client, events, providerName = PROVIDER_NAME) {
44
+ return new Promise((resolve, reject) => {
45
+ const status = client.getStatus();
46
+ if (status.isReady) {
47
+ emitReadyEvent(client, events, providerName);
48
+ resolve();
49
+ return;
50
+ }
51
+ if (status.hasTimedout) {
52
+ reject();
53
+ return;
54
+ }
55
+ client.on(client.Event.SDK_READY_TIMED_OUT, reject);
56
+ client.on(client.Event.SDK_READY, () => {
57
+ emitReadyEvent(client, events, providerName);
58
+ resolve();
59
+ });
60
+ });
61
+ }
62
+ export function emitReadyEvent(client, events, providerName = PROVIDER_NAME) {
63
+ events.emit(ProviderEvents.Ready, buildReadyEventDetails(providerName, undefined, false));
64
+ }
@@ -0,0 +1,4 @@
1
+ export const CONTROL_TREATMENT = 'control';
2
+ export const CONTROL_VALUE_ERROR_MESSAGE = 'Received the "control" value from Split.';
3
+ export const DEFAULT_TRAFFIC_TYPE = 'user';
4
+ export const PROVIDER_NAME = 'split';
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./lib/js-split-provider"), exports);
4
+ tslib_1.__exportStar(require("./lib/js-split-provider.js"), exports);
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSplitClient = void 0;
4
+ const splitio_1 = require("@splitsoftware/splitio");
5
+ /**
6
+ * Resolves the Split client from the various supported constructor option shapes.
7
+ * Supports: API key (string), Split SDK/AsyncSDK (factory), or pre-built splitClient.
8
+ */
9
+ function getSplitClient(options) {
10
+ if (typeof options === 'string') {
11
+ const splitFactory = (0, splitio_1.SplitFactory)({ core: { authorizationKey: options } });
12
+ return splitFactory.client();
13
+ }
14
+ try {
15
+ return options.client();
16
+ }
17
+ catch {
18
+ return options.splitClient;
19
+ }
20
+ }
21
+ exports.getSplitClient = getSplitClient;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformContext = void 0;
4
+ const types_js_1 = require("./types.js");
5
+ function readBucketingKey(value) {
6
+ if (value == null)
7
+ return {};
8
+ if (typeof value !== 'string')
9
+ return { bucketingKeyIssue: 'not a string' };
10
+ const bucketingKey = value.trim();
11
+ if (bucketingKey === '')
12
+ return { bucketingKeyIssue: 'blank' };
13
+ return { bucketingKey };
14
+ }
15
+ /**
16
+ * Transforms OpenFeature evaluation context into the consumer shape used by the Split API:
17
+ * targeting key, bucketing key (validated, trimmed), traffic type (with default),
18
+ * and remaining attributes. `bucketingKey` is never forwarded as an attribute.
19
+ */
20
+ function transformContext(context, defaultTrafficType = types_js_1.DEFAULT_TRAFFIC_TYPE) {
21
+ const { targetingKey, bucketingKey, trafficType: ttVal, ...attributes } = context;
22
+ const trafficType = ttVal != null && typeof ttVal === 'string' && ttVal.trim() !== ''
23
+ ? ttVal
24
+ : defaultTrafficType;
25
+ return {
26
+ targetingKey,
27
+ ...readBucketingKey(bucketingKey),
28
+ trafficType,
29
+ attributes: JSON.parse(JSON.stringify(attributes)),
30
+ };
31
+ }
32
+ exports.transformContext = transformContext;