@splitsoftware/splitio-commons 3.1.1-rc.5 → 3.1.1-rc.7

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,4 +1,4 @@
1
- 3.2.0 (August 28, 2026)
1
+ 3.2.0 (September 18, 2026)
2
2
  - Added support for AI configs.
3
3
  - Removed Configs SDK-related types and modules and moved them to the Configs SDK repository.
4
4
 
@@ -61,8 +61,9 @@ function sdkLifecycleFactory(params, isSharedClient) {
61
61
  }
62
62
  // Stop background jobs
63
63
  syncManager && syncManager.stop();
64
- serviceApi && serviceApi.stop();
65
64
  return __flush().then(function () {
65
+ // Stop the service API (the auth provider backoff retries specifically) after the final flush, so it can still authenticate using the still-valid cached credential
66
+ serviceApi && serviceApi.stop();
66
67
  // Cleanup storage
67
68
  return storage.destroy();
68
69
  });
@@ -10,18 +10,20 @@ var tslib_1 = require("tslib");
10
10
  * @param authProvider - `authProviderFactory` to use for authentication
11
11
  */
12
12
  function secureSplitHttpClientFactory(splitHttpClient, authProvider) {
13
- function makeRequest(url, options, latencyTracker, logErrorsAsInfo, token) {
14
- return splitHttpClient(url, tslib_1.__assign(tslib_1.__assign({}, options), { headers: tslib_1.__assign(tslib_1.__assign({}, options === null || options === void 0 ? void 0 : options.headers), { Authorization: "Bearer ".concat(token) }) }), latencyTracker, logErrorsAsInfo, true);
13
+ function makeRequest(url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, token) {
14
+ return splitHttpClient(url, token ? tslib_1.__assign(tslib_1.__assign({}, options), { headers: tslib_1.__assign(tslib_1.__assign({}, options === null || options === void 0 ? void 0 : options.headers), { Authorization: "Bearer ".concat(token) }) }) : options, latencyTracker, logErrorsAsInfo, newVersionHeader);
15
15
  }
16
- var httpClient = function (url, options, latencyTracker, logErrorsAsInfo) {
16
+ var httpClient = function (url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, useJwt) {
17
+ if (newVersionHeader === void 0) { newVersionHeader = true; }
18
+ if (useJwt === void 0) { useJwt = true; }
17
19
  return authProvider.credential().then(function (credential) {
18
- return makeRequest(url, options, latencyTracker, logErrorsAsInfo, credential.token)
20
+ return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, useJwt ? credential.token : undefined)
19
21
  .catch(function (error) {
20
22
  if (error.statusCode === 401) {
21
23
  // retry once for 401, in case the token has just expired
22
24
  authProvider.invalidate();
23
25
  return authProvider.credential().then(function (newCredential) {
24
- return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newCredential.token);
26
+ return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, useJwt ? newCredential.token : undefined);
25
27
  });
26
28
  }
27
29
  throw error;
@@ -84,7 +84,7 @@ function serviceApiFactory(settings, platform, telemetryTracker) {
84
84
  */
85
85
  postEventsBulk: function (body, headers) {
86
86
  var url = "".concat(urls.events, "/api/events/bulk");
87
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.EVENTS));
87
+ return secureSplitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.EVENTS), false, false, false);
88
88
  },
89
89
  /**
90
90
  * Post impressions.
@@ -94,12 +94,12 @@ function serviceApiFactory(settings, platform, telemetryTracker) {
94
94
  */
95
95
  postTestImpressionsBulk: function (body, headers) {
96
96
  var url = "".concat(urls.events, "/api/testImpressions/bulk");
97
- return splitHttpClient(url, {
97
+ return secureSplitHttpClient(url, {
98
98
  // Adding extra headers to send impressions in OPTIMIZED or DEBUG modes.
99
99
  method: 'POST',
100
100
  body: body,
101
101
  headers: (0, objectAssign_1.objectAssign)({ SplitSDKImpressionsMode: SplitSDKImpressionsMode }, headers)
102
- }, telemetryTracker.trackHttp(constants_1.IMPRESSIONS));
102
+ }, telemetryTracker.trackHttp(constants_1.IMPRESSIONS), false, false, false);
103
103
  },
104
104
  /**
105
105
  * Post impressions counts.
@@ -109,7 +109,7 @@ function serviceApiFactory(settings, platform, telemetryTracker) {
109
109
  */
110
110
  postTestImpressionsCount: function (body, headers) {
111
111
  var url = "".concat(urls.events, "/api/testImpressions/count");
112
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.IMPRESSIONS_COUNT));
112
+ return secureSplitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.IMPRESSIONS_COUNT), false, false, false);
113
113
  },
114
114
  /**
115
115
  * Post unique keys for client side.
@@ -119,7 +119,7 @@ function serviceApiFactory(settings, platform, telemetryTracker) {
119
119
  */
120
120
  postUniqueKeysBulkCs: function (body, headers) {
121
121
  var url = "".concat(urls.telemetry, "/api/v1/keys/cs");
122
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
122
+ return secureSplitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), false, false, false);
123
123
  },
124
124
  /**
125
125
  * Post unique keys for server side.
@@ -129,7 +129,7 @@ function serviceApiFactory(settings, platform, telemetryTracker) {
129
129
  */
130
130
  postUniqueKeysBulkSs: function (body, headers) {
131
131
  var url = "".concat(urls.telemetry, "/api/v1/keys/ss");
132
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
132
+ return secureSplitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), false, false, false);
133
133
  },
134
134
  postMetricsConfig: function (body, headers) {
135
135
  var url = "".concat(urls.telemetry, "/api/v1/metrics/config");
@@ -58,8 +58,9 @@ export function sdkLifecycleFactory(params, isSharedClient) {
58
58
  }
59
59
  // Stop background jobs
60
60
  syncManager && syncManager.stop();
61
- serviceApi && serviceApi.stop();
62
61
  return __flush().then(function () {
62
+ // Stop the service API (the auth provider backoff retries specifically) after the final flush, so it can still authenticate using the still-valid cached credential
63
+ serviceApi && serviceApi.stop();
63
64
  // Cleanup storage
64
65
  return storage.destroy();
65
66
  });
@@ -7,18 +7,20 @@ import { __assign } from "tslib";
7
7
  * @param authProvider - `authProviderFactory` to use for authentication
8
8
  */
9
9
  export function secureSplitHttpClientFactory(splitHttpClient, authProvider) {
10
- function makeRequest(url, options, latencyTracker, logErrorsAsInfo, token) {
11
- return splitHttpClient(url, __assign(__assign({}, options), { headers: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.headers), { Authorization: "Bearer ".concat(token) }) }), latencyTracker, logErrorsAsInfo, true);
10
+ function makeRequest(url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, token) {
11
+ return splitHttpClient(url, token ? __assign(__assign({}, options), { headers: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.headers), { Authorization: "Bearer ".concat(token) }) }) : options, latencyTracker, logErrorsAsInfo, newVersionHeader);
12
12
  }
13
- var httpClient = function (url, options, latencyTracker, logErrorsAsInfo) {
13
+ var httpClient = function (url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, useJwt) {
14
+ if (newVersionHeader === void 0) { newVersionHeader = true; }
15
+ if (useJwt === void 0) { useJwt = true; }
14
16
  return authProvider.credential().then(function (credential) {
15
- return makeRequest(url, options, latencyTracker, logErrorsAsInfo, credential.token)
17
+ return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, useJwt ? credential.token : undefined)
16
18
  .catch(function (error) {
17
19
  if (error.statusCode === 401) {
18
20
  // retry once for 401, in case the token has just expired
19
21
  authProvider.invalidate();
20
22
  return authProvider.credential().then(function (newCredential) {
21
- return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newCredential.token);
23
+ return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, useJwt ? newCredential.token : undefined);
22
24
  });
23
25
  }
24
26
  throw error;
@@ -81,7 +81,7 @@ export function serviceApiFactory(settings, platform, telemetryTracker) {
81
81
  */
82
82
  postEventsBulk: function (body, headers) {
83
83
  var url = "".concat(urls.events, "/api/events/bulk");
84
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(EVENTS));
84
+ return secureSplitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(EVENTS), false, false, false);
85
85
  },
86
86
  /**
87
87
  * Post impressions.
@@ -91,12 +91,12 @@ export function serviceApiFactory(settings, platform, telemetryTracker) {
91
91
  */
92
92
  postTestImpressionsBulk: function (body, headers) {
93
93
  var url = "".concat(urls.events, "/api/testImpressions/bulk");
94
- return splitHttpClient(url, {
94
+ return secureSplitHttpClient(url, {
95
95
  // Adding extra headers to send impressions in OPTIMIZED or DEBUG modes.
96
96
  method: 'POST',
97
97
  body: body,
98
98
  headers: objectAssign({ SplitSDKImpressionsMode: SplitSDKImpressionsMode }, headers)
99
- }, telemetryTracker.trackHttp(IMPRESSIONS));
99
+ }, telemetryTracker.trackHttp(IMPRESSIONS), false, false, false);
100
100
  },
101
101
  /**
102
102
  * Post impressions counts.
@@ -106,7 +106,7 @@ export function serviceApiFactory(settings, platform, telemetryTracker) {
106
106
  */
107
107
  postTestImpressionsCount: function (body, headers) {
108
108
  var url = "".concat(urls.events, "/api/testImpressions/count");
109
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(IMPRESSIONS_COUNT));
109
+ return secureSplitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(IMPRESSIONS_COUNT), false, false, false);
110
110
  },
111
111
  /**
112
112
  * Post unique keys for client side.
@@ -116,7 +116,7 @@ export function serviceApiFactory(settings, platform, telemetryTracker) {
116
116
  */
117
117
  postUniqueKeysBulkCs: function (body, headers) {
118
118
  var url = "".concat(urls.telemetry, "/api/v1/keys/cs");
119
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY));
119
+ return secureSplitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY), false, false, false);
120
120
  },
121
121
  /**
122
122
  * Post unique keys for server side.
@@ -126,7 +126,7 @@ export function serviceApiFactory(settings, platform, telemetryTracker) {
126
126
  */
127
127
  postUniqueKeysBulkSs: function (body, headers) {
128
128
  var url = "".concat(urls.telemetry, "/api/v1/keys/ss");
129
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY));
129
+ return secureSplitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(TELEMETRY), false, false, false);
130
130
  },
131
131
  postMetricsConfig: function (body, headers) {
132
132
  var url = "".concat(urls.telemetry, "/api/v1/metrics/config");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "3.1.1-rc.5",
3
+ "version": "3.1.1-rc.7",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -69,9 +69,10 @@ export function sdkLifecycleFactory(params: ISdkFactoryContext, isSharedClient?:
69
69
 
70
70
  // Stop background jobs
71
71
  syncManager && syncManager.stop();
72
- serviceApi && serviceApi.stop();
73
72
 
74
73
  return __flush().then(() => {
74
+ // Stop the service API (the auth provider backoff retries specifically) after the final flush, so it can still authenticate using the still-valid cached credential
75
+ serviceApi && serviceApi.stop();
75
76
  // Cleanup storage
76
77
  return storage.destroy();
77
78
  });
@@ -10,19 +10,19 @@ import { IAuthProvider } from './authProvider';
10
10
  */
11
11
  export function secureSplitHttpClientFactory(splitHttpClient: ISplitHttpClient, authProvider: IAuthProvider): ISecureSplitHttpClient {
12
12
 
13
- function makeRequest(url: string, options: IRequestOptions | undefined, latencyTracker: ((error?: NetworkError) => void) | undefined, logErrorsAsInfo: boolean | undefined, token: string): Promise<IResponse> {
14
- return splitHttpClient(url, { ...options, headers: { ...options?.headers, Authorization: `Bearer ${token}` } }, latencyTracker, logErrorsAsInfo, true);
13
+ function makeRequest(url: string, options: IRequestOptions | undefined, latencyTracker?: (error?: NetworkError) => void, logErrorsAsInfo?: boolean, newVersionHeader?: boolean, token?: string): Promise<IResponse> {
14
+ return splitHttpClient(url, token ? { ...options, headers: { ...options?.headers, Authorization: `Bearer ${token}` } } : options, latencyTracker, logErrorsAsInfo, newVersionHeader);
15
15
  }
16
16
 
17
- const httpClient = function (url: string, options?: IRequestOptions, latencyTracker?: (error?: NetworkError) => void, logErrorsAsInfo?: boolean): Promise<IResponse> {
17
+ const httpClient = function (url: string, options?: IRequestOptions, latencyTracker?: (error?: NetworkError) => void, logErrorsAsInfo?: boolean, newVersionHeader = true, useJwt = true): Promise<IResponse> {
18
18
  return authProvider.credential().then(credential => {
19
- return makeRequest(url, options, latencyTracker, logErrorsAsInfo, credential.token)
19
+ return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, useJwt ? credential.token : undefined)
20
20
  .catch((error: NetworkError) => {
21
21
  if (error.statusCode === 401) {
22
22
  // retry once for 401, in case the token has just expired
23
23
  authProvider.invalidate();
24
24
  return authProvider.credential().then(newCredential => {
25
- return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newCredential.token);
25
+ return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newVersionHeader, useJwt ? newCredential.token : undefined);
26
26
  });
27
27
  }
28
28
  throw error;
@@ -102,7 +102,7 @@ export function serviceApiFactory(
102
102
  */
103
103
  postEventsBulk(body: string, headers?: Record<string, string>) {
104
104
  const url = `${urls.events}/api/events/bulk`;
105
- return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(EVENTS));
105
+ return secureSplitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(EVENTS), false, false, false);
106
106
  },
107
107
 
108
108
  /**
@@ -113,10 +113,10 @@ export function serviceApiFactory(
113
113
  */
114
114
  postTestImpressionsBulk(body: string, headers?: Record<string, string>) {
115
115
  const url = `${urls.events}/api/testImpressions/bulk`;
116
- return splitHttpClient(url, {
116
+ return secureSplitHttpClient(url, {
117
117
  // Adding extra headers to send impressions in OPTIMIZED or DEBUG modes.
118
118
  method: 'POST', body, headers: objectAssign({ SplitSDKImpressionsMode }, headers)
119
- }, telemetryTracker.trackHttp(IMPRESSIONS));
119
+ }, telemetryTracker.trackHttp(IMPRESSIONS), false, false, false);
120
120
  },
121
121
 
122
122
  /**
@@ -127,7 +127,7 @@ export function serviceApiFactory(
127
127
  */
128
128
  postTestImpressionsCount(body: string, headers?: Record<string, string>) {
129
129
  const url = `${urls.events}/api/testImpressions/count`;
130
- return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(IMPRESSIONS_COUNT));
130
+ return secureSplitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(IMPRESSIONS_COUNT), false, false, false);
131
131
  },
132
132
 
133
133
  /**
@@ -138,7 +138,7 @@ export function serviceApiFactory(
138
138
  */
139
139
  postUniqueKeysBulkCs(body: string, headers?: Record<string, string>) {
140
140
  const url = `${urls.telemetry}/api/v1/keys/cs`;
141
- return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(TELEMETRY));
141
+ return secureSplitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(TELEMETRY), false, false, false);
142
142
  },
143
143
 
144
144
  /**
@@ -149,7 +149,7 @@ export function serviceApiFactory(
149
149
  */
150
150
  postUniqueKeysBulkSs(body: string, headers?: Record<string, string>) {
151
151
  const url = `${urls.telemetry}/api/v1/keys/ss`;
152
- return splitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(TELEMETRY));
152
+ return secureSplitHttpClient(url, { method: 'POST', body, headers }, telemetryTracker.trackHttp(TELEMETRY), false, false, false);
153
153
  },
154
154
 
155
155
  postMetricsConfig(body: string, headers?: Record<string, string>) {
@@ -35,7 +35,7 @@ export type IHealthCheckAPI = () => Promise<boolean>
35
35
 
36
36
  export type ISplitHttpClient = (url: string, options?: IRequestOptions, latencyTracker?: (error?: NetworkError) => void, logErrorsAsInfo?: boolean, newVersionHeader?: boolean) => Promise<IResponse>
37
37
 
38
- export type ISecureSplitHttpClient = ISplitHttpClient & { stop(): void }
38
+ export type ISecureSplitHttpClient = ((url: string, options?: IRequestOptions, latencyTracker?: (error?: NetworkError) => void, logErrorsAsInfo?: boolean, newVersionHeader?: boolean, useJwt?: boolean) => Promise<IResponse>) & { stop(): void }
39
39
 
40
40
  export type IFetchDefinitionChanges = (since: number, noCache?: boolean, till?: number, rbSince?: number) => Promise<IResponse>
41
41
 
@@ -73,7 +73,7 @@ export interface IServiceApi {
73
73
  postTestImpressionsCount: IPostTestImpressionsCount
74
74
  postMetricsConfig: IPostMetricsConfig
75
75
  postMetricsUsage: IPostMetricsUsage
76
- // lifecycle
76
+ // lifecycle: stops authProvider backoff retries
77
77
  stop(): void
78
78
  }
79
79