@splitsoftware/splitio-commons 1.12.1 → 1.12.2-rc.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,6 @@
1
+ 1.13.0 (January 4, 2024)
2
+ - Removed the getOptions method from the IPlatform interface to simplify the code. Request options can be handled inside the getFetch method.
3
+
1
4
  1.12.1 (December 12, 2023)
2
5
  - Updated PluggableStorage, for producer mode, and LocalStorage, for standalone mode, to clear the storage before initiating the synchronization process if it was previously synchronized with a different SDK key (i.e., a different environment) or different Split Filter criteria.
3
6
  - Bugfixing - Fixed an issue when tracking telemetry latencies for the new `getTreatmentsByFlagSet(s)` methods in Redis and Pluggable storages, which was causing the SDK to not track those stats.
@@ -58,7 +58,7 @@ function sdkFactory(params) {
58
58
  var impressionsTracker = (0, impressionsTracker_1.impressionsTrackerFactory)(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
59
59
  var eventTracker = (0, eventTracker_1.eventTrackerFactory)(settings, storage.events, integrationsManager, storage.telemetry);
60
60
  // splitApi is used by SyncManager and Browser signal listener
61
- var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
61
+ var splitApi = splitApiFactory && splitApiFactory(settings, platform.getFetch, telemetryTracker);
62
62
  var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
63
63
  var syncManager = syncManagerFactory && syncManagerFactory(ctx);
64
64
  ctx.syncManager = syncManager;
@@ -13,13 +13,14 @@ function userKeyToQueryParam(userKey) {
13
13
  * Factory of SplitApi objects, which group the collection of Split HTTP endpoints used by the SDK
14
14
  *
15
15
  * @param settings validated settings object
16
- * @param platform object containing environment-specific `getFetch` and `getOptions` dependencies
16
+ * @param getFetch environment-specific `getFetch` method
17
+ * @param telemetryTracker telemetry tracker
17
18
  */
18
- function splitApiFactory(settings, platform, telemetryTracker) {
19
+ function splitApiFactory(settings, getFetch, telemetryTracker) {
19
20
  var urls = settings.urls;
20
21
  var filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
21
22
  var SplitSDKImpressionsMode = settings.sync.impressionsMode;
22
- var splitHttpClient = (0, splitHttpClient_1.splitHttpClientFactory)(settings, platform.getFetch, platform.getOptions);
23
+ var splitHttpClient = (0, splitHttpClient_1.splitHttpClientFactory)(settings, getFetch);
23
24
  return {
24
25
  // @TODO throw errors if health check requests fail, to log them in the Synchronizer
25
26
  getSdkAPIHealthCheck: function () {
@@ -8,12 +8,10 @@ var messageNoFetch = 'Global fetch API is not available.';
8
8
  * Factory of Split HTTP clients, which are HTTP clients with predefined headers for Split endpoints.
9
9
  *
10
10
  * @param settings SDK settings, used to access authorizationKey, logger instance and metadata (SDK version, ip and hostname) to set additional headers
11
- * @param options global request options
12
- * @param fetch optional http client to use instead of the global Fetch (for environments where Fetch API is not available such as Node)
11
+ * @param getFetch retrieves the Fetch API for HTTP requests
13
12
  */
14
- function splitHttpClientFactory(settings, getFetch, getOptions) {
13
+ function splitHttpClientFactory(settings, getFetch) {
15
14
  var log = settings.log, authorizationKey = settings.core.authorizationKey, version = settings.version, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname;
16
- var options = getOptions && getOptions();
17
15
  var fetch = getFetch && getFetch();
18
16
  // if fetch is not available, log Error
19
17
  if (!fetch)
@@ -32,11 +30,11 @@ function splitHttpClientFactory(settings, getFetch, getOptions) {
32
30
  if (reqOpts === void 0) { reqOpts = {}; }
33
31
  if (latencyTracker === void 0) { latencyTracker = function () { }; }
34
32
  if (logErrorsAsInfo === void 0) { logErrorsAsInfo = false; }
35
- var request = (0, objectAssign_1.objectAssign)({
33
+ var request = {
36
34
  headers: reqOpts.headers ? (0, objectAssign_1.objectAssign)({}, headers, reqOpts.headers) : headers,
37
35
  method: reqOpts.method || 'GET',
38
36
  body: reqOpts.body
39
- }, options);
37
+ };
40
38
  // using `fetch(url, options)` signature to work with unfetch, a lightweight ponyfill of fetch API.
41
39
  return fetch ? fetch(url, request)
42
40
  // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
@@ -55,7 +55,7 @@ export function sdkFactory(params) {
55
55
  var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, strategy, integrationsManager, storage.telemetry);
56
56
  var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
57
57
  // splitApi is used by SyncManager and Browser signal listener
58
- var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
58
+ var splitApi = splitApiFactory && splitApiFactory(settings, platform.getFetch, telemetryTracker);
59
59
  var ctx = { splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, uniqueKeysTracker: uniqueKeysTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform };
60
60
  var syncManager = syncManagerFactory && syncManagerFactory(ctx);
61
61
  ctx.syncManager = syncManager;
@@ -10,13 +10,14 @@ function userKeyToQueryParam(userKey) {
10
10
  * Factory of SplitApi objects, which group the collection of Split HTTP endpoints used by the SDK
11
11
  *
12
12
  * @param settings validated settings object
13
- * @param platform object containing environment-specific `getFetch` and `getOptions` dependencies
13
+ * @param getFetch environment-specific `getFetch` method
14
+ * @param telemetryTracker telemetry tracker
14
15
  */
15
- export function splitApiFactory(settings, platform, telemetryTracker) {
16
+ export function splitApiFactory(settings, getFetch, telemetryTracker) {
16
17
  var urls = settings.urls;
17
18
  var filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
18
19
  var SplitSDKImpressionsMode = settings.sync.impressionsMode;
19
- var splitHttpClient = splitHttpClientFactory(settings, platform.getFetch, platform.getOptions);
20
+ var splitHttpClient = splitHttpClientFactory(settings, getFetch);
20
21
  return {
21
22
  // @TODO throw errors if health check requests fail, to log them in the Synchronizer
22
23
  getSdkAPIHealthCheck: function () {
@@ -5,12 +5,10 @@ var messageNoFetch = 'Global fetch API is not available.';
5
5
  * Factory of Split HTTP clients, which are HTTP clients with predefined headers for Split endpoints.
6
6
  *
7
7
  * @param settings SDK settings, used to access authorizationKey, logger instance and metadata (SDK version, ip and hostname) to set additional headers
8
- * @param options global request options
9
- * @param fetch optional http client to use instead of the global Fetch (for environments where Fetch API is not available such as Node)
8
+ * @param getFetch retrieves the Fetch API for HTTP requests
10
9
  */
11
- export function splitHttpClientFactory(settings, getFetch, getOptions) {
10
+ export function splitHttpClientFactory(settings, getFetch) {
12
11
  var log = settings.log, authorizationKey = settings.core.authorizationKey, version = settings.version, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname;
13
- var options = getOptions && getOptions();
14
12
  var fetch = getFetch && getFetch();
15
13
  // if fetch is not available, log Error
16
14
  if (!fetch)
@@ -29,11 +27,11 @@ export function splitHttpClientFactory(settings, getFetch, getOptions) {
29
27
  if (reqOpts === void 0) { reqOpts = {}; }
30
28
  if (latencyTracker === void 0) { latencyTracker = function () { }; }
31
29
  if (logErrorsAsInfo === void 0) { logErrorsAsInfo = false; }
32
- var request = objectAssign({
30
+ var request = {
33
31
  headers: reqOpts.headers ? objectAssign({}, headers, reqOpts.headers) : headers,
34
32
  method: reqOpts.method || 'GET',
35
33
  body: reqOpts.body
36
- }, options);
34
+ };
37
35
  // using `fetch(url, options)` signature to work with unfetch, a lightweight ponyfill of fetch API.
38
36
  return fetch ? fetch(url, request)
39
37
  // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.12.1",
3
+ "version": "1.12.2-rc.0",
4
4
  "description": "Split Javascript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -71,7 +71,7 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ICsSDK | SplitIO.
71
71
  const eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
72
72
 
73
73
  // splitApi is used by SyncManager and Browser signal listener
74
- const splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
74
+ const splitApi = splitApiFactory && splitApiFactory(settings, platform.getFetch, telemetryTracker);
75
75
 
76
76
  const ctx: ISdkFactoryContext = { splitApi, eventTracker, impressionsTracker, telemetryTracker, uniqueKeysTracker, sdkReadinessManager, readiness, settings, storage, platform };
77
77
 
@@ -2,6 +2,7 @@ import { IIntegrationManager, IIntegrationFactoryParams } from '../integrations/
2
2
  import { ISignalListener } from '../listeners/types';
3
3
  import { IReadinessManager, ISdkReadinessManager } from '../readiness/types';
4
4
  import type { sdkManagerFactory } from '../sdkManager';
5
+ import type { splitApiFactory } from '../services/splitApi';
5
6
  import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
6
7
  import { IStorageAsync, IStorageSync, IStorageFactoryParams } from '../storages/types';
7
8
  import { ISyncManager } from '../sync/types';
@@ -17,10 +18,6 @@ export interface IPlatform {
17
18
  * If provided, it is used to retrieve the Fetch API for HTTP requests. Otherwise, the global fetch is used.
18
19
  */
19
20
  getFetch?: () => (IFetch | undefined)
20
- /**
21
- * If provided, it is used to pass additional options to fetch calls.
22
- */
23
- getOptions?: () => object
24
21
  /**
25
22
  * If provided, it is used to retrieve the EventSource constructor for streaming support.
26
23
  */
@@ -79,7 +76,7 @@ export interface ISdkFactoryParams {
79
76
 
80
77
  // Factory of Split Api (HTTP Client Service).
81
78
  // It is not required when providing an asynchronous storage or offline SyncManager
82
- splitApiFactory?: (settings: ISettings, platform: IPlatform, telemetryTracker: ITelemetryTracker) => ISplitApi,
79
+ splitApiFactory?: typeof splitApiFactory,
83
80
 
84
81
  // SyncManager factory.
85
82
  // Not required when providing an asynchronous storage (consumer mode), but required in standalone mode to avoid SDK timeout.
@@ -17,18 +17,19 @@ function userKeyToQueryParam(userKey: string) {
17
17
  * Factory of SplitApi objects, which group the collection of Split HTTP endpoints used by the SDK
18
18
  *
19
19
  * @param settings validated settings object
20
- * @param platform object containing environment-specific `getFetch` and `getOptions` dependencies
20
+ * @param getFetch environment-specific `getFetch` method
21
+ * @param telemetryTracker telemetry tracker
21
22
  */
22
23
  export function splitApiFactory(
23
- settings: Pick<ISettings, 'urls' | 'sync' | 'log' | 'version' | 'runtime' | 'core'>,
24
- platform: Pick<IPlatform, 'getFetch' | 'getOptions'>,
24
+ settings: ISettings,
25
+ getFetch: IPlatform['getFetch'],
25
26
  telemetryTracker: ITelemetryTracker
26
27
  ): ISplitApi {
27
28
 
28
29
  const urls = settings.urls;
29
30
  const filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
30
31
  const SplitSDKImpressionsMode = settings.sync.impressionsMode;
31
- const splitHttpClient = splitHttpClientFactory(settings, platform.getFetch, platform.getOptions);
32
+ const splitHttpClient = splitHttpClientFactory(settings, getFetch);
32
33
 
33
34
  return {
34
35
  // @TODO throw errors if health check requests fail, to log them in the Synchronizer
@@ -1,7 +1,8 @@
1
- import { IFetch, IRequestOptions, IResponse, ISplitHttpClient, NetworkError } from './types';
1
+ import { IRequestOptions, IResponse, ISplitHttpClient, NetworkError } from './types';
2
2
  import { objectAssign } from '../utils/lang/objectAssign';
3
3
  import { ERROR_HTTP, ERROR_CLIENT_CANNOT_GET_READY } from '../logger/constants';
4
4
  import { ISettings } from '../types';
5
+ import { IPlatform } from '../sdkFactory/types';
5
6
 
6
7
  const messageNoFetch = 'Global fetch API is not available.';
7
8
 
@@ -9,13 +10,11 @@ const messageNoFetch = 'Global fetch API is not available.';
9
10
  * Factory of Split HTTP clients, which are HTTP clients with predefined headers for Split endpoints.
10
11
  *
11
12
  * @param settings SDK settings, used to access authorizationKey, logger instance and metadata (SDK version, ip and hostname) to set additional headers
12
- * @param options global request options
13
- * @param fetch optional http client to use instead of the global Fetch (for environments where Fetch API is not available such as Node)
13
+ * @param getFetch retrieves the Fetch API for HTTP requests
14
14
  */
15
- export function splitHttpClientFactory(settings: Pick<ISettings, 'log' | 'version' | 'runtime' | 'core'>, getFetch?: () => (IFetch | undefined), getOptions?: () => object): ISplitHttpClient {
15
+ export function splitHttpClientFactory(settings: ISettings, getFetch?: IPlatform['getFetch']): ISplitHttpClient {
16
16
 
17
17
  const { log, core: { authorizationKey }, version, runtime: { ip, hostname } } = settings;
18
- const options = getOptions && getOptions();
19
18
  const fetch = getFetch && getFetch();
20
19
 
21
20
  // if fetch is not available, log Error
@@ -33,11 +32,11 @@ export function splitHttpClientFactory(settings: Pick<ISettings, 'log' | 'versio
33
32
 
34
33
  return function httpClient(url: string, reqOpts: IRequestOptions = {}, latencyTracker: (error?: NetworkError) => void = () => { }, logErrorsAsInfo: boolean = false): Promise<IResponse> {
35
34
 
36
- const request = objectAssign({
35
+ const request = {
37
36
  headers: reqOpts.headers ? objectAssign({}, headers, reqOpts.headers) : headers,
38
37
  method: reqOpts.method || 'GET',
39
38
  body: reqOpts.body
40
- }, options);
39
+ };
41
40
 
42
41
  // using `fetch(url, options)` signature to work with unfetch, a lightweight ponyfill of fetch API.
43
42
  return fetch ? fetch(url, request)
@@ -2,6 +2,7 @@ import { IIntegrationManager, IIntegrationFactoryParams } from '../integrations/
2
2
  import { ISignalListener } from '../listeners/types';
3
3
  import { IReadinessManager, ISdkReadinessManager } from '../readiness/types';
4
4
  import type { sdkManagerFactory } from '../sdkManager';
5
+ import type { splitApiFactory } from '../services/splitApi';
5
6
  import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
6
7
  import { IStorageAsync, IStorageSync, IStorageFactoryParams } from '../storages/types';
7
8
  import { ISyncManager } from '../sync/types';
@@ -16,10 +17,6 @@ export interface IPlatform {
16
17
  * If provided, it is used to retrieve the Fetch API for HTTP requests. Otherwise, the global fetch is used.
17
18
  */
18
19
  getFetch?: () => (IFetch | undefined);
19
- /**
20
- * If provided, it is used to pass additional options to fetch calls.
21
- */
22
- getOptions?: () => object;
23
20
  /**
24
21
  * If provided, it is used to retrieve the EventSource constructor for streaming support.
25
22
  */
@@ -64,7 +61,7 @@ export interface ISdkFactoryParams {
64
61
  settings: ISettings;
65
62
  platform: IPlatform;
66
63
  storageFactory: (params: IStorageFactoryParams) => IStorageSync | IStorageAsync;
67
- splitApiFactory?: (settings: ISettings, platform: IPlatform, telemetryTracker: ITelemetryTracker) => ISplitApi;
64
+ splitApiFactory?: typeof splitApiFactory;
68
65
  syncManagerFactory?: (params: ISdkFactoryContextSync) => ISyncManager;
69
66
  sdkManagerFactory: typeof sdkManagerFactory;
70
67
  sdkClientMethodFactory: (params: ISdkFactoryContext) => ({
@@ -6,6 +6,7 @@ import { ITelemetryTracker } from '../trackers/types';
6
6
  * Factory of SplitApi objects, which group the collection of Split HTTP endpoints used by the SDK
7
7
  *
8
8
  * @param settings validated settings object
9
- * @param platform object containing environment-specific `getFetch` and `getOptions` dependencies
9
+ * @param getFetch environment-specific `getFetch` method
10
+ * @param telemetryTracker telemetry tracker
10
11
  */
11
- export declare function splitApiFactory(settings: Pick<ISettings, 'urls' | 'sync' | 'log' | 'version' | 'runtime' | 'core'>, platform: Pick<IPlatform, 'getFetch' | 'getOptions'>, telemetryTracker: ITelemetryTracker): ISplitApi;
12
+ export declare function splitApiFactory(settings: ISettings, getFetch: IPlatform['getFetch'], telemetryTracker: ITelemetryTracker): ISplitApi;
@@ -1,10 +1,10 @@
1
- import { IFetch, ISplitHttpClient } from './types';
1
+ import { ISplitHttpClient } from './types';
2
2
  import { ISettings } from '../types';
3
+ import { IPlatform } from '../sdkFactory/types';
3
4
  /**
4
5
  * Factory of Split HTTP clients, which are HTTP clients with predefined headers for Split endpoints.
5
6
  *
6
7
  * @param settings SDK settings, used to access authorizationKey, logger instance and metadata (SDK version, ip and hostname) to set additional headers
7
- * @param options global request options
8
- * @param fetch optional http client to use instead of the global Fetch (for environments where Fetch API is not available such as Node)
8
+ * @param getFetch retrieves the Fetch API for HTTP requests
9
9
  */
10
- export declare function splitHttpClientFactory(settings: Pick<ISettings, 'log' | 'version' | 'runtime' | 'core'>, getFetch?: () => (IFetch | undefined), getOptions?: () => object): ISplitHttpClient;
10
+ export declare function splitHttpClientFactory(settings: ISettings, getFetch?: IPlatform['getFetch']): ISplitHttpClient;