@splitsoftware/splitio-commons 1.3.1-rc.0 → 1.3.1-rc.1

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,5 @@
1
- 1.3.1 (TBD)
1
+ 1.3.1 (April 19, 2022)
2
+ - Bugfixing - Added peer dependencies to avoid issues when requiring some third-party dependencies used by modules of the package (Related to issue https://github.com/splitio/javascript-client/issues/662).
2
3
  - Bugfixing - Updated `ready` method to rejects the promise with an Error object instead of a string value (Related to issue https://github.com/splitio/javascript-client/issues/654).
3
4
 
4
5
  1.3.0 (April 6, 2022)
@@ -12,26 +12,25 @@ var messageNoFetch = 'Global fetch API is not available.';
12
12
  * @param fetch optional http client to use instead of the global Fetch (for environments where Fetch API is not available such as Node)
13
13
  */
14
14
  function splitHttpClientFactory(settings, getFetch, getOptions) {
15
- var log = settings.log;
15
+ var log = settings.log, authorizationKey = settings.core.authorizationKey, version = settings.version, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname;
16
16
  var options = getOptions && getOptions();
17
17
  var fetch = getFetch && getFetch();
18
18
  // if fetch is not available, log Error
19
19
  if (!fetch)
20
20
  log.error(constants_1.ERROR_CLIENT_CANNOT_GET_READY, [messageNoFetch]);
21
+ var headers = {
22
+ 'Accept': 'application/json',
23
+ 'Content-Type': 'application/json',
24
+ 'Authorization': "Bearer " + authorizationKey,
25
+ 'SplitSDKVersion': version
26
+ };
27
+ if (ip)
28
+ headers['SplitSDKMachineIP'] = ip;
29
+ if (hostname)
30
+ headers['SplitSDKMachineName'] = hostname;
21
31
  return function httpClient(url, reqOpts, logErrorsAsInfo) {
22
32
  if (reqOpts === void 0) { reqOpts = {}; }
23
33
  if (logErrorsAsInfo === void 0) { logErrorsAsInfo = false; }
24
- var authorizationKey = settings.core.authorizationKey, version = settings.version, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname;
25
- var headers = {
26
- 'Accept': 'application/json',
27
- 'Content-Type': 'application/json',
28
- 'Authorization': "Bearer " + authorizationKey,
29
- 'SplitSDKVersion': version
30
- };
31
- if (ip)
32
- headers['SplitSDKMachineIP'] = ip;
33
- if (hostname)
34
- headers['SplitSDKMachineName'] = hostname;
35
34
  var request = (0, objectAssign_1.objectAssign)({
36
35
  headers: reqOpts.headers ? (0, objectAssign_1.objectAssign)({}, headers, reqOpts.headers) : headers,
37
36
  method: reqOpts.method || 'GET',
@@ -21,7 +21,7 @@ function impressionsTrackerFactory(settings, impressionsCache, integrationsManag
21
21
  observer,
22
22
  // if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
23
23
  countsCache) {
24
- var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname;
24
+ var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
25
25
  return {
26
26
  track: function (impressions, attributes) {
27
27
  if (settings.userConsent === constants_2.CONSENT_DECLINED)
@@ -62,7 +62,7 @@ countsCache) {
62
62
  attributes: attributes,
63
63
  ip: ip,
64
64
  hostname: hostname,
65
- sdkLanguageVersion: settings.version
65
+ sdkLanguageVersion: version
66
66
  };
67
67
  // Wrap in a timeout because we don't want it to be blocking.
68
68
  setTimeout(function () {
@@ -9,26 +9,25 @@ var messageNoFetch = 'Global fetch API is not available.';
9
9
  * @param fetch optional http client to use instead of the global Fetch (for environments where Fetch API is not available such as Node)
10
10
  */
11
11
  export function splitHttpClientFactory(settings, getFetch, getOptions) {
12
- var log = settings.log;
12
+ var log = settings.log, authorizationKey = settings.core.authorizationKey, version = settings.version, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname;
13
13
  var options = getOptions && getOptions();
14
14
  var fetch = getFetch && getFetch();
15
15
  // if fetch is not available, log Error
16
16
  if (!fetch)
17
17
  log.error(ERROR_CLIENT_CANNOT_GET_READY, [messageNoFetch]);
18
+ var headers = {
19
+ 'Accept': 'application/json',
20
+ 'Content-Type': 'application/json',
21
+ 'Authorization': "Bearer " + authorizationKey,
22
+ 'SplitSDKVersion': version
23
+ };
24
+ if (ip)
25
+ headers['SplitSDKMachineIP'] = ip;
26
+ if (hostname)
27
+ headers['SplitSDKMachineName'] = hostname;
18
28
  return function httpClient(url, reqOpts, logErrorsAsInfo) {
19
29
  if (reqOpts === void 0) { reqOpts = {}; }
20
30
  if (logErrorsAsInfo === void 0) { logErrorsAsInfo = false; }
21
- var authorizationKey = settings.core.authorizationKey, version = settings.version, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname;
22
- var headers = {
23
- 'Accept': 'application/json',
24
- 'Content-Type': 'application/json',
25
- 'Authorization': "Bearer " + authorizationKey,
26
- 'SplitSDKVersion': version
27
- };
28
- if (ip)
29
- headers['SplitSDKMachineIP'] = ip;
30
- if (hostname)
31
- headers['SplitSDKMachineName'] = hostname;
32
31
  var request = objectAssign({
33
32
  headers: reqOpts.headers ? objectAssign({}, headers, reqOpts.headers) : headers,
34
33
  method: reqOpts.method || 'GET',
@@ -18,7 +18,7 @@ export function impressionsTrackerFactory(settings, impressionsCache, integratio
18
18
  observer,
19
19
  // if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
20
20
  countsCache) {
21
- var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname;
21
+ var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
22
22
  return {
23
23
  track: function (impressions, attributes) {
24
24
  if (settings.userConsent === CONSENT_DECLINED)
@@ -59,7 +59,7 @@ countsCache) {
59
59
  attributes: attributes,
60
60
  ip: ip,
61
61
  hostname: hostname,
62
- sdkLanguageVersion: settings.version
62
+ sdkLanguageVersion: version
63
63
  };
64
64
  // Wrap in a timeout because we don't want it to be blocking.
65
65
  setTimeout(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.3.1-rc.0",
3
+ "version": "1.3.1-rc.1",
4
4
  "description": "Split Javascript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -14,26 +14,24 @@ const messageNoFetch = 'Global fetch API is not available.';
14
14
  */
15
15
  export function splitHttpClientFactory(settings: Pick<ISettings, 'log' | 'version' | 'runtime' | 'core'>, getFetch?: () => (IFetch | undefined), getOptions?: () => object): ISplitHttpClient {
16
16
 
17
- const log = settings.log;
17
+ const { log, core: { authorizationKey }, version, runtime: { ip, hostname } } = settings;
18
18
  const options = getOptions && getOptions();
19
19
  const fetch = getFetch && getFetch();
20
20
 
21
21
  // if fetch is not available, log Error
22
22
  if (!fetch) log.error(ERROR_CLIENT_CANNOT_GET_READY, [messageNoFetch]);
23
23
 
24
- return function httpClient(url: string, reqOpts: IRequestOptions = {}, logErrorsAsInfo: boolean = false): Promise<IResponse> {
25
-
26
- const { core: { authorizationKey }, version, runtime: { ip, hostname } } = settings;
24
+ const headers: Record<string, string> = {
25
+ 'Accept': 'application/json',
26
+ 'Content-Type': 'application/json',
27
+ 'Authorization': `Bearer ${authorizationKey}`,
28
+ 'SplitSDKVersion': version
29
+ };
27
30
 
28
- const headers: Record<string, string> = {
29
- 'Accept': 'application/json',
30
- 'Content-Type': 'application/json',
31
- 'Authorization': `Bearer ${authorizationKey}`,
32
- 'SplitSDKVersion': version
33
- };
31
+ if (ip) headers['SplitSDKMachineIP'] = ip;
32
+ if (hostname) headers['SplitSDKMachineName'] = hostname;
34
33
 
35
- if (ip) headers['SplitSDKMachineIP'] = ip;
36
- if (hostname) headers['SplitSDKMachineName'] = hostname;
34
+ return function httpClient(url: string, reqOpts: IRequestOptions = {}, logErrorsAsInfo: boolean = false): Promise<IResponse> {
37
35
 
38
36
  const request = objectAssign({
39
37
  headers: reqOpts.headers ? objectAssign({}, headers, reqOpts.headers) : headers,
@@ -28,7 +28,7 @@ export function impressionsTrackerFactory(
28
28
  countsCache?: IImpressionCountsCacheSync
29
29
  ): IImpressionsTracker {
30
30
 
31
- const { log, impressionListener, runtime: { ip, hostname } } = settings;
31
+ const { log, impressionListener, runtime: { ip, hostname }, version } = settings;
32
32
 
33
33
  return {
34
34
  track(impressions: ImpressionDTO[], attributes?: SplitIO.Attributes) {
@@ -76,7 +76,7 @@ export function impressionsTrackerFactory(
76
76
  attributes,
77
77
  ip,
78
78
  hostname,
79
- sdkLanguageVersion: settings.version
79
+ sdkLanguageVersion: version
80
80
  };
81
81
 
82
82
  // Wrap in a timeout because we don't want it to be blocking.
@@ -1,5 +1,5 @@
1
1
  import { ILogger } from '../../logger/types';
2
- import { Method, MethodExceptions, MethodLatencies } from '../../sync/submitters/types';
2
+ import { Method } from '../../sync/submitters/types';
3
3
  import { KeyBuilderSS } from '../KeyBuilderSS';
4
4
  import { TelemetryCacheAsync } from '../types';
5
5
  import { Redis } from 'ioredis';
@@ -14,8 +14,6 @@ export declare class TelemetryCacheInRedis implements TelemetryCacheAsync {
14
14
  * @param redis Redis client.
15
15
  */
16
16
  constructor(log: ILogger, keys: KeyBuilderSS, redis: Redis);
17
- recordLatency(method: Method, latencyMs: number): Promise<number>;
18
- recordException(method: Method): Promise<number>;
19
- popExceptions(): Promise<MethodExceptions>;
20
- popLatencies(): Promise<MethodLatencies>;
17
+ recordLatency(method: Method, latencyMs: number): Promise<number | void>;
18
+ recordException(method: Method): Promise<number | void>;
21
19
  }
@@ -13,8 +13,6 @@ export declare class TelemetryCachePluggable implements TelemetryCacheAsync {
13
13
  * @param wrapper Adapted wrapper storage.
14
14
  */
15
15
  constructor(log: ILogger, keys: KeyBuilderSS, wrapper: IPluggableStorageWrapper);
16
- recordLatency(method: Method, latencyMs: number): Promise<number>;
17
- recordException(method: Method): Promise<number>;
18
- popExceptions(): void;
19
- popLatencies(): void;
16
+ recordLatency(method: Method, latencyMs: number): Promise<number | void>;
17
+ recordException(method: Method): Promise<number | void>;
20
18
  }
@@ -0,0 +1,4 @@
1
+ import { TelemetryCacheAsync, TelemetryCacheSync } from '../storages/types';
2
+ import { ISettings } from '../types';
3
+ import { ITelemetryTracker } from './types';
4
+ export declare function telemetryTrackerFactory(settings: ISettings, telemetryCache?: TelemetryCacheAsync | TelemetryCacheSync, now?: () => number): ITelemetryTracker;