@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
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  EvaluationContext,
3
+ EventDetails,
3
4
  FlagNotFoundError,
4
5
  JsonValue,
6
+ Logger,
5
7
  OpenFeatureEventEmitter,
6
8
  ParseError,
7
9
  Provider,
@@ -11,72 +13,84 @@ import {
11
13
  TargetingKeyMissingError,
12
14
  TrackingEventDetails
13
15
  } from '@openfeature/server-sdk';
14
- import { SplitFactory } from '@splitsoftware/splitio';
15
16
  import type SplitIO from '@splitsoftware/splitio/types/splitio';
16
-
17
- type SplitProviderOptions = {
18
- splitClient: SplitIO.IClient | SplitIO.IAsyncClient;
19
- }
20
-
21
- type Consumer = {
22
- targetingKey: string | undefined;
23
- trafficType: string;
24
- attributes: SplitIO.Attributes;
25
- };
26
-
27
- const CONTROL_VALUE_ERROR_MESSAGE = 'Received the "control" value from Split.';
28
- const CONTROL_TREATMENT = 'control';
17
+ import { getSplitClient } from './client-resolver.js';
18
+ import { transformContext } from './context.js';
19
+ import { parseValidJsonObject, parseValidNumber } from './parsers.js';
20
+ import { attachReadyEventHandlers, waitUntilReady } from './readiness.js';
21
+ import {
22
+ CONTROL_TREATMENT,
23
+ CONTROL_VALUE_ERROR_MESSAGE,
24
+ DEFAULT_TRAFFIC_TYPE,
25
+ PROVIDER_NAME,
26
+ SplitProviderConstructorOptions,
27
+ type Consumer
28
+ } from './types.js';
29
29
 
30
30
  export class OpenFeatureSplitProvider implements Provider {
31
- metadata = {
32
- name: 'split',
33
- };
31
+ readonly metadata = {
32
+ name: PROVIDER_NAME,
33
+ } as const;
34
+
35
+ readonly runsOn = 'server' as const;
34
36
 
35
37
  private client: SplitIO.IClient | SplitIO.IAsyncClient;
36
38
  private trafficType: string;
39
+ // Invalid-bucketingKey reasons already warned about; repeats are logged at debug.
40
+ private readonly warnedBucketingKeyIssues = new Set<string>();
37
41
  public readonly events = new OpenFeatureEventEmitter();
38
42
 
39
- private getSplitClient(options: SplitProviderOptions | string | SplitIO.ISDK | SplitIO.IAsyncSDK) {
40
- if (typeof(options) === 'string') {
41
- const splitFactory = SplitFactory({core: { authorizationKey: options } });
42
- return splitFactory.client();
43
- }
44
-
45
- let splitClient;
46
- try {
47
- splitClient = (options as SplitIO.ISDK | SplitIO.IAsyncSDK).client();
48
- } catch {
49
- splitClient = (options as SplitProviderOptions).splitClient
50
- }
51
-
52
- return splitClient;
43
+ constructor(
44
+ options: SplitProviderConstructorOptions
45
+ ) {
46
+ this.trafficType = DEFAULT_TRAFFIC_TYPE;
47
+ this.client = getSplitClient(options);
48
+
49
+ attachReadyEventHandlers(this.client, this.events, this.metadata.name);
50
+
51
+ this.client.on(
52
+ this.client.Event.SDK_UPDATE,
53
+ (updateMetadata: SplitIO.SdkUpdateMetadata) => {
54
+ const eventDetails: EventDetails = {
55
+ providerName: this.metadata.name,
56
+ ...(updateMetadata
57
+ ? {
58
+ metadata: { type: updateMetadata.type },
59
+ flagsChanged: updateMetadata.names || [],
60
+ }
61
+ : {}),
62
+ };
63
+ this.events.emit(ProviderEvents.ConfigurationChanged, eventDetails);
64
+ }
65
+ );
53
66
  }
54
-
55
- constructor(options: SplitProviderOptions | string | SplitIO.ISDK | SplitIO.IAsyncSDK) {
56
- // Asume 'user' as default traffic type'
57
- this.trafficType = 'user';
58
- this.client = this.getSplitClient(options);
59
- this.client.on(this.client.Event.SDK_UPDATE, () => {
60
- this.events.emit(ProviderEvents.ConfigurationChanged);
61
- });
67
+
68
+ /**
69
+ * Called by the SDK after the provider is set. Waits for the Split client to be ready.
70
+ * When this promise resolves, the SDK emits ProviderEvents.Ready.
71
+ */
72
+ async initialize(_context?: EvaluationContext): Promise<void> {
73
+ void _context;
74
+ await waitUntilReady(this.client, this.events, this.metadata.name);
62
75
  }
63
76
 
64
77
  public async resolveBooleanEvaluation(
65
78
  flagKey: string,
66
79
  _: boolean,
67
- context: EvaluationContext
80
+ context: EvaluationContext,
81
+ logger: Logger
68
82
  ): Promise<ResolutionDetails<boolean>> {
69
83
  const details = await this.evaluateTreatment(
70
84
  flagKey,
71
- this.transformContext(context)
85
+ transformContext(context, this.trafficType),
86
+ logger
72
87
  );
73
88
  const treatment = details.value.toLowerCase();
74
89
 
75
- if ( treatment === 'on' || treatment === 'true' ) {
90
+ if (treatment === 'on' || treatment === 'true') {
76
91
  return { ...details, value: true };
77
92
  }
78
-
79
- if ( treatment === 'off' || treatment === 'false' ) {
93
+ if (treatment === 'off' || treatment === 'false') {
80
94
  return { ...details, value: false };
81
95
  }
82
96
 
@@ -86,42 +100,48 @@ export class OpenFeatureSplitProvider implements Provider {
86
100
  public async resolveStringEvaluation(
87
101
  flagKey: string,
88
102
  _: string,
89
- context: EvaluationContext
103
+ context: EvaluationContext,
104
+ logger: Logger
90
105
  ): Promise<ResolutionDetails<string>> {
91
- const details = await this.evaluateTreatment(
106
+ return this.evaluateTreatment(
92
107
  flagKey,
93
- this.transformContext(context)
108
+ transformContext(context, this.trafficType),
109
+ logger
94
110
  );
95
- return details;
96
111
  }
97
112
 
98
113
  public async resolveNumberEvaluation(
99
114
  flagKey: string,
100
115
  _: number,
101
- context: EvaluationContext
116
+ context: EvaluationContext,
117
+ logger: Logger
102
118
  ): Promise<ResolutionDetails<number>> {
103
119
  const details = await this.evaluateTreatment(
104
120
  flagKey,
105
- this.transformContext(context)
121
+ transformContext(context, this.trafficType),
122
+ logger
106
123
  );
107
- return { ...details, value: this.parseValidNumber(details.value) };
124
+ return { ...details, value: parseValidNumber(details.value) };
108
125
  }
109
126
 
110
127
  public async resolveObjectEvaluation<U extends JsonValue>(
111
128
  flagKey: string,
112
129
  _: U,
113
- context: EvaluationContext
130
+ context: EvaluationContext,
131
+ logger: Logger
114
132
  ): Promise<ResolutionDetails<U>> {
115
133
  const details = await this.evaluateTreatment(
116
134
  flagKey,
117
- this.transformContext(context)
135
+ transformContext(context, this.trafficType),
136
+ logger
118
137
  );
119
- return { ...details, value: this.parseValidJsonObject(details.value) };
138
+ return { ...details, value: parseValidJsonObject<U>(details.value) };
120
139
  }
121
140
 
122
141
  private async evaluateTreatment(
123
142
  flagKey: string,
124
- consumer: Consumer
143
+ consumer: Consumer,
144
+ logger?: Logger
125
145
  ): Promise<ResolutionDetails<string>> {
126
146
  if (!consumer.targetingKey) {
127
147
  throw new TargetingKeyMissingError(
@@ -129,31 +149,38 @@ export class OpenFeatureSplitProvider implements Provider {
129
149
  );
130
150
  }
131
151
  if (flagKey == null || flagKey === '') {
132
- throw new FlagNotFoundError(
133
- 'flagKey must be a non-empty string'
134
- );
152
+ throw new FlagNotFoundError('flagKey must be a non-empty string');
135
153
  }
136
-
137
- await new Promise((resolve, reject) => {
138
- this.readinessHandler(resolve, reject);
139
- });
140
-
141
- const { treatment: value, config }: SplitIO.TreatmentWithConfig = await this.client.getTreatmentWithConfig(
142
- consumer.targetingKey,
143
- flagKey,
144
- consumer.attributes
145
- );
154
+ if (consumer.bucketingKeyIssue) {
155
+ const message = `Split provider: ignoring bucketingKey (${consumer.bucketingKeyIssue}); evaluating with the targeting key only.`;
156
+ if (this.warnedBucketingKeyIssues.has(consumer.bucketingKeyIssue)) {
157
+ logger?.debug(message);
158
+ } else {
159
+ this.warnedBucketingKeyIssues.add(consumer.bucketingKeyIssue);
160
+ logger?.warn(message);
161
+ }
162
+ }
163
+ const splitKey: SplitIO.SplitKey = consumer.bucketingKey
164
+ ? { matchingKey: consumer.targetingKey, bucketingKey: consumer.bucketingKey }
165
+ : consumer.targetingKey;
166
+
167
+ await waitUntilReady(this.client, this.events, this.metadata.name);
168
+ const { treatment: value, config }: SplitIO.TreatmentWithConfig =
169
+ await this.client.getTreatmentWithConfig(
170
+ splitKey,
171
+ flagKey,
172
+ consumer.attributes
173
+ );
146
174
  if (value === CONTROL_TREATMENT) {
147
175
  throw new FlagNotFoundError(CONTROL_VALUE_ERROR_MESSAGE);
148
176
  }
149
- const flagMetadata = { config: config ? config : '' };
150
- const details: ResolutionDetails<string> = {
151
- value: value,
177
+ const flagMetadata = Object.freeze({ config: config ?? '' });
178
+ return {
179
+ value,
152
180
  variant: value,
153
- flagMetadata: flagMetadata,
181
+ flagMetadata,
154
182
  reason: StandardResolutionReasons.TARGETING_MATCH,
155
183
  };
156
- return details;
157
184
  }
158
185
 
159
186
  async track(
@@ -161,17 +188,21 @@ export class OpenFeatureSplitProvider implements Provider {
161
188
  context: EvaluationContext,
162
189
  details: TrackingEventDetails
163
190
  ): Promise<void> {
164
-
165
- // eventName is always required
166
- if (trackingEventName == null || trackingEventName === '')
191
+ if (trackingEventName == null || trackingEventName === '') {
167
192
  throw new ParseError('Missing eventName, required to track');
193
+ }
168
194
 
169
- // targetingKey is always required
170
- const { targetingKey, trafficType } = this.transformContext(context);
171
- if (targetingKey == null || targetingKey === '')
172
- throw new TargetingKeyMissingError('Missing targetingKey, required to track');
195
+ const { targetingKey, trafficType } = transformContext(
196
+ context,
197
+ this.trafficType
198
+ );
199
+ if (targetingKey == null || targetingKey === '') {
200
+ throw new TargetingKeyMissingError(
201
+ 'Missing targetingKey, required to track'
202
+ );
203
+ }
173
204
 
174
- let value;
205
+ let value: number | undefined;
175
206
  let properties: SplitIO.Properties = {};
176
207
  if (details != null) {
177
208
  if (details.value != null) {
@@ -180,73 +211,18 @@ export class OpenFeatureSplitProvider implements Provider {
180
211
  if (details.properties != null) {
181
212
  properties = details.properties as SplitIO.Properties;
182
213
  }
183
- }
184
-
185
- this.client.track(targetingKey, trafficType, trackingEventName, value, properties);
186
- }
187
-
188
- public async onClose?(): Promise<void> {
189
- return this.client.destroy();
190
- }
214
+ }
191
215
 
192
- //Transform the context into an object useful for the Split API, an key string with arbitrary Split 'Attributes'.
193
- private transformContext(context: EvaluationContext): Consumer {
194
- const { targetingKey, trafficType: ttVal, ...attributes } = context;
195
- const trafficType =
196
- ttVal != null && typeof ttVal === 'string' && ttVal.trim() !== ''
197
- ? ttVal
198
- : this.trafficType;
199
- return {
216
+ this.client.track(
200
217
  targetingKey,
201
218
  trafficType,
202
- // Stringify context objects include date.
203
- attributes: JSON.parse(JSON.stringify(attributes)),
204
- };
205
- }
206
-
207
- private parseValidNumber(stringValue: string | undefined) {
208
- if (stringValue === undefined) {
209
- throw new ParseError(`Invalid 'undefined' value.`);
210
- }
211
- const result = Number.parseFloat(stringValue);
212
- if (Number.isNaN(result)) {
213
- throw new ParseError(`Invalid numeric value ${stringValue}`);
214
- }
215
- return result;
216
- }
217
-
218
- private parseValidJsonObject<T extends JsonValue>(
219
- stringValue: string | undefined
220
- ): T {
221
- if (stringValue === undefined) {
222
- throw new ParseError(`Invalid 'undefined' JSON value.`);
223
- }
224
- // we may want to allow the parsing to be customized.
225
- try {
226
- const value = JSON.parse(stringValue);
227
- if (typeof value !== 'object') {
228
- throw new ParseError(
229
- `Flag value ${stringValue} had unexpected type ${typeof value}, expected "object"`
230
- );
231
- }
232
- return value;
233
- } catch (err) {
234
- throw new ParseError(`Error parsing ${stringValue} as JSON, ${err}`);
235
- }
219
+ trackingEventName,
220
+ value,
221
+ properties
222
+ );
236
223
  }
237
224
 
238
- private async readinessHandler(onSdkReady: (params?: unknown) => void, onSdkTimedOut: () => void): Promise<void> {
239
-
240
- const clientStatus = this.client.getStatus();
241
- if (clientStatus.isReady) {
242
- onSdkReady();
243
- } else {
244
- if (clientStatus.hasTimedout) {
245
- onSdkTimedOut();
246
- } else {
247
- this.client.on(this.client.Event.SDK_READY_TIMED_OUT, onSdkTimedOut);
248
- }
249
- this.client.on(this.client.Event.SDK_READY, onSdkReady);
250
- }
225
+ public async onClose?(): Promise<void> {
226
+ return this.client.destroy();
251
227
  }
252
228
  }
@@ -0,0 +1,32 @@
1
+ import { ParseError } from '@openfeature/server-sdk';
2
+ import type { JsonValue } from '@openfeature/server-sdk';
3
+
4
+ export function parseValidNumber(stringValue: string | undefined): number {
5
+ if (stringValue === undefined) {
6
+ throw new ParseError(`Invalid 'undefined' value.`);
7
+ }
8
+ const result = Number.parseFloat(stringValue);
9
+ if (Number.isNaN(result)) {
10
+ throw new ParseError(`Invalid numeric value ${stringValue}`);
11
+ }
12
+ return result;
13
+ }
14
+
15
+ export function parseValidJsonObject<T extends JsonValue>(
16
+ stringValue: string | undefined
17
+ ): T {
18
+ if (stringValue === undefined) {
19
+ throw new ParseError(`Invalid 'undefined' JSON value.`);
20
+ }
21
+ try {
22
+ const value = JSON.parse(stringValue);
23
+ if (typeof value !== 'object') {
24
+ throw new ParseError(
25
+ `Flag value ${stringValue} had unexpected type ${typeof value}, expected "object"`
26
+ );
27
+ }
28
+ return value;
29
+ } catch (err) {
30
+ throw new ParseError(`Error parsing ${stringValue} as JSON, ${err}`);
31
+ }
32
+ }
@@ -0,0 +1,103 @@
1
+ import type { OpenFeatureEventEmitter } from '@openfeature/server-sdk';
2
+ import { ProviderEvents } from '@openfeature/server-sdk';
3
+ import type SplitIO from '@splitsoftware/splitio/types/splitio';
4
+ import { PROVIDER_NAME } from './types.js';
5
+
6
+ /**
7
+ * Builds OpenFeature Ready event details including Split SDK ready metadata.
8
+ * Handles Split SDK not passing metadata (e.g. in consumer/Redis mode).
9
+ */
10
+ function buildReadyEventDetails(
11
+ providerName: string,
12
+ splitMetadata: SplitIO.SdkReadyMetadata | undefined,
13
+ readyFromCache: boolean
14
+ ) {
15
+ const metadata: Record<string, string | boolean | number> = {
16
+ readyFromCache,
17
+ initialCacheLoad: splitMetadata?.initialCacheLoad ?? false,
18
+ };
19
+ if (splitMetadata?.lastUpdateTimestamp != null) {
20
+ metadata.lastUpdateTimestamp = splitMetadata.lastUpdateTimestamp;
21
+ }
22
+ return {
23
+ providerName: providerName || PROVIDER_NAME,
24
+ metadata,
25
+ };
26
+ }
27
+
28
+ /**
29
+ * Registers Split SDK_READY and SDK_READY_FROM_CACHE listeners and forwards them
30
+ * as OpenFeature ProviderEvents.Ready with event metadata (initialCacheLoad, lastUpdateTimestamp, readyFromCache).
31
+ * If the client is already ready when attaching (e.g. localhost or reused client), emits Ready once
32
+ * with best-effort metadata so handlers always receive at least one Ready when the client is ready.
33
+ */
34
+ export function attachReadyEventHandlers(
35
+ client: SplitIO.IClient | SplitIO.IAsyncClient,
36
+ events: OpenFeatureEventEmitter,
37
+ providerName: string = PROVIDER_NAME
38
+ ): void {
39
+ client.on(
40
+ client.Event.SDK_READY_FROM_CACHE,
41
+ (splitMetadata: SplitIO.SdkReadyMetadata) => {
42
+ events.emit(
43
+ ProviderEvents.Ready,
44
+ buildReadyEventDetails(providerName, splitMetadata, true)
45
+ );
46
+ }
47
+ );
48
+ client.on(client.Event.SDK_READY, (splitMetadata: SplitIO.SdkReadyMetadata) => {
49
+ events.emit(
50
+ ProviderEvents.Ready,
51
+ buildReadyEventDetails(providerName, splitMetadata, false)
52
+ );
53
+ });
54
+
55
+ const status = client.getStatus();
56
+ if (status.isReady) {
57
+ events.emit(
58
+ ProviderEvents.Ready,
59
+ buildReadyEventDetails(providerName, undefined, false)
60
+ );
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Returns a promise that resolves when the Split client is ready (SDK_READY),
66
+ * or rejects if the client has timed out (SDK_READY_TIMED_OUT).
67
+ * Used to gate evaluations until the SDK has synchronized with the backend.
68
+ */
69
+ export function waitUntilReady(
70
+ client: SplitIO.IClient | SplitIO.IAsyncClient,
71
+ events: OpenFeatureEventEmitter,
72
+ providerName: string = PROVIDER_NAME
73
+ ): Promise<void> {
74
+ return new Promise((resolve, reject) => {
75
+ const status = client.getStatus();
76
+ if (status.isReady) {
77
+ emitReadyEvent(client, events, providerName);
78
+ resolve();
79
+ return;
80
+ }
81
+ if (status.hasTimedout) {
82
+ reject();
83
+ return;
84
+ }
85
+ client.on(client.Event.SDK_READY_TIMED_OUT, reject);
86
+ client.on(client.Event.SDK_READY, () => {
87
+ emitReadyEvent(client, events, providerName);
88
+ resolve();
89
+ });
90
+ });
91
+ }
92
+
93
+ export function emitReadyEvent(
94
+ client: SplitIO.IClient | SplitIO.IAsyncClient,
95
+ events: OpenFeatureEventEmitter,
96
+ providerName: string = PROVIDER_NAME
97
+ ): void {
98
+ events.emit(
99
+ ProviderEvents.Ready,
100
+ buildReadyEventDetails(providerName, undefined, false)
101
+ );
102
+ }
103
+
@@ -0,0 +1,41 @@
1
+ import type SplitIO from '@splitsoftware/splitio/types/splitio';
2
+
3
+ /**
4
+ * Options when providing an existing Split client to the provider.
5
+ */
6
+ export type SplitProviderOptions = {
7
+ splitClient: SplitIO.IClient | SplitIO.IAsyncClient;
8
+ };
9
+
10
+ /**
11
+ * Why a `bucketingKey` present in the evaluation context was ignored.
12
+ */
13
+ export type BucketingKeyIssue = 'blank' | 'not a string';
14
+
15
+ /**
16
+ * Consumer representation used for Split API calls:
17
+ * targeting key, optional bucketing key, traffic type, and attributes.
18
+ */
19
+ export type Consumer = {
20
+ targetingKey: string | undefined;
21
+ /** Valid (non-blank string) bucketing key, trimmed. */
22
+ bucketingKey?: string;
23
+ /** Set when a `bucketingKey` was present but ignored. */
24
+ bucketingKeyIssue?: BucketingKeyIssue;
25
+ trafficType: string;
26
+ attributes: SplitIO.Attributes;
27
+ };
28
+
29
+ /**
30
+ * Union of all constructor argument types for the Split OpenFeature provider.
31
+ */
32
+ export type SplitProviderConstructorOptions =
33
+ | SplitProviderOptions
34
+ | string
35
+ | SplitIO.ISDK
36
+ | SplitIO.IAsyncSDK;
37
+
38
+ export const CONTROL_TREATMENT = 'control';
39
+ export const CONTROL_VALUE_ERROR_MESSAGE = 'Received the "control" value from Split.';
40
+ export const DEFAULT_TRAFFIC_TYPE = 'user';
41
+ export const PROVIDER_NAME = 'split';
package/types/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './lib/js-split-provider';
1
+ export * from './lib/js-split-provider.js';
@@ -0,0 +1,7 @@
1
+ import type SplitIO from '@splitsoftware/splitio/types/splitio';
2
+ import type { SplitProviderConstructorOptions } from './types.js';
3
+ /**
4
+ * Resolves the Split client from the various supported constructor option shapes.
5
+ * Supports: API key (string), Split SDK/AsyncSDK (factory), or pre-built splitClient.
6
+ */
7
+ export declare function getSplitClient(options: SplitProviderConstructorOptions): SplitIO.IClient | SplitIO.IAsyncClient;
@@ -0,0 +1,8 @@
1
+ import type { EvaluationContext } from '@openfeature/server-sdk';
2
+ import type { Consumer } from './types.js';
3
+ /**
4
+ * Transforms OpenFeature evaluation context into the consumer shape used by the Split API:
5
+ * targeting key, bucketing key (validated, trimmed), traffic type (with default),
6
+ * and remaining attributes. `bucketingKey` is never forwarded as an attribute.
7
+ */
8
+ export declare function transformContext(context: EvaluationContext, defaultTrafficType?: string): Consumer;
@@ -1,27 +1,25 @@
1
- import { EvaluationContext, JsonValue, OpenFeatureEventEmitter, Provider, ResolutionDetails, TrackingEventDetails } from '@openfeature/server-sdk';
2
- import type SplitIO from '@splitsoftware/splitio/types/splitio';
3
- type SplitProviderOptions = {
4
- splitClient: SplitIO.IClient | SplitIO.IAsyncClient;
5
- };
1
+ import { EvaluationContext, JsonValue, Logger, OpenFeatureEventEmitter, Provider, ResolutionDetails, TrackingEventDetails } from '@openfeature/server-sdk';
2
+ import { SplitProviderConstructorOptions } from './types.js';
6
3
  export declare class OpenFeatureSplitProvider implements Provider {
7
- metadata: {
8
- name: string;
4
+ readonly metadata: {
5
+ readonly name: "split";
9
6
  };
7
+ readonly runsOn: "server";
10
8
  private client;
11
9
  private trafficType;
10
+ private readonly warnedBucketingKeyIssues;
12
11
  readonly events: OpenFeatureEventEmitter;
13
- private getSplitClient;
14
- constructor(options: SplitProviderOptions | string | SplitIO.ISDK | SplitIO.IAsyncSDK);
15
- resolveBooleanEvaluation(flagKey: string, _: boolean, context: EvaluationContext): Promise<ResolutionDetails<boolean>>;
16
- resolveStringEvaluation(flagKey: string, _: string, context: EvaluationContext): Promise<ResolutionDetails<string>>;
17
- resolveNumberEvaluation(flagKey: string, _: number, context: EvaluationContext): Promise<ResolutionDetails<number>>;
18
- resolveObjectEvaluation<U extends JsonValue>(flagKey: string, _: U, context: EvaluationContext): Promise<ResolutionDetails<U>>;
12
+ constructor(options: SplitProviderConstructorOptions);
13
+ /**
14
+ * Called by the SDK after the provider is set. Waits for the Split client to be ready.
15
+ * When this promise resolves, the SDK emits ProviderEvents.Ready.
16
+ */
17
+ initialize(_context?: EvaluationContext): Promise<void>;
18
+ resolveBooleanEvaluation(flagKey: string, _: boolean, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<boolean>>;
19
+ resolveStringEvaluation(flagKey: string, _: string, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<string>>;
20
+ resolveNumberEvaluation(flagKey: string, _: number, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<number>>;
21
+ resolveObjectEvaluation<U extends JsonValue>(flagKey: string, _: U, context: EvaluationContext, logger: Logger): Promise<ResolutionDetails<U>>;
19
22
  private evaluateTreatment;
20
23
  track(trackingEventName: string, context: EvaluationContext, details: TrackingEventDetails): Promise<void>;
21
24
  onClose?(): Promise<void>;
22
- private transformContext;
23
- private parseValidNumber;
24
- private parseValidJsonObject;
25
- private readinessHandler;
26
25
  }
27
- export {};
@@ -0,0 +1,3 @@
1
+ import type { JsonValue } from '@openfeature/server-sdk';
2
+ export declare function parseValidNumber(stringValue: string | undefined): number;
3
+ export declare function parseValidJsonObject<T extends JsonValue>(stringValue: string | undefined): T;
@@ -0,0 +1,16 @@
1
+ import type { OpenFeatureEventEmitter } from '@openfeature/server-sdk';
2
+ import type SplitIO from '@splitsoftware/splitio/types/splitio';
3
+ /**
4
+ * Registers Split SDK_READY and SDK_READY_FROM_CACHE listeners and forwards them
5
+ * as OpenFeature ProviderEvents.Ready with event metadata (initialCacheLoad, lastUpdateTimestamp, readyFromCache).
6
+ * If the client is already ready when attaching (e.g. localhost or reused client), emits Ready once
7
+ * with best-effort metadata so handlers always receive at least one Ready when the client is ready.
8
+ */
9
+ export declare function attachReadyEventHandlers(client: SplitIO.IClient | SplitIO.IAsyncClient, events: OpenFeatureEventEmitter, providerName?: string): void;
10
+ /**
11
+ * Returns a promise that resolves when the Split client is ready (SDK_READY),
12
+ * or rejects if the client has timed out (SDK_READY_TIMED_OUT).
13
+ * Used to gate evaluations until the SDK has synchronized with the backend.
14
+ */
15
+ export declare function waitUntilReady(client: SplitIO.IClient | SplitIO.IAsyncClient, events: OpenFeatureEventEmitter, providerName?: string): Promise<void>;
16
+ export declare function emitReadyEvent(client: SplitIO.IClient | SplitIO.IAsyncClient, events: OpenFeatureEventEmitter, providerName?: string): void;
@@ -0,0 +1,32 @@
1
+ import type SplitIO from '@splitsoftware/splitio/types/splitio';
2
+ /**
3
+ * Options when providing an existing Split client to the provider.
4
+ */
5
+ export type SplitProviderOptions = {
6
+ splitClient: SplitIO.IClient | SplitIO.IAsyncClient;
7
+ };
8
+ /**
9
+ * Why a `bucketingKey` present in the evaluation context was ignored.
10
+ */
11
+ export type BucketingKeyIssue = 'blank' | 'not a string';
12
+ /**
13
+ * Consumer representation used for Split API calls:
14
+ * targeting key, optional bucketing key, traffic type, and attributes.
15
+ */
16
+ export type Consumer = {
17
+ targetingKey: string | undefined;
18
+ /** Valid (non-blank string) bucketing key, trimmed. */
19
+ bucketingKey?: string;
20
+ /** Set when a `bucketingKey` was present but ignored. */
21
+ bucketingKeyIssue?: BucketingKeyIssue;
22
+ trafficType: string;
23
+ attributes: SplitIO.Attributes;
24
+ };
25
+ /**
26
+ * Union of all constructor argument types for the Split OpenFeature provider.
27
+ */
28
+ export type SplitProviderConstructorOptions = SplitProviderOptions | string | SplitIO.ISDK | SplitIO.IAsyncSDK;
29
+ export declare const CONTROL_TREATMENT = "control";
30
+ export declare const CONTROL_VALUE_ERROR_MESSAGE = "Received the \"control\" value from Split.";
31
+ export declare const DEFAULT_TRAFFIC_TYPE = "user";
32
+ export declare const PROVIDER_NAME = "split";