@splitsoftware/splitio-commons 3.1.0 → 3.1.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.
Files changed (35) hide show
  1. package/CHANGES.txt +4 -0
  2. package/cjs/evaluator/condition/index.js +1 -1
  3. package/cjs/evaluator/index.js +26 -46
  4. package/cjs/listeners/browser.js +2 -2
  5. package/cjs/sdkClient/client.js +18 -17
  6. package/cjs/services/authProvider.js +1 -1
  7. package/cjs/storages/utils.js +1 -0
  8. package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
  9. package/esm/evaluator/condition/index.js +1 -1
  10. package/esm/evaluator/index.js +26 -46
  11. package/esm/listeners/browser.js +2 -2
  12. package/esm/sdkClient/client.js +18 -17
  13. package/esm/services/authProvider.js +1 -1
  14. package/esm/storages/utils.js +1 -0
  15. package/esm/sync/submitters/impressionsSubmitter.js +5 -4
  16. package/package.json +1 -1
  17. package/src/dtos/types.ts +7 -0
  18. package/src/evaluator/Engine.ts +3 -3
  19. package/src/evaluator/condition/index.ts +2 -2
  20. package/src/evaluator/index.ts +33 -79
  21. package/src/evaluator/types.ts +3 -6
  22. package/src/listeners/browser.ts +2 -2
  23. package/src/sdkClient/client.ts +24 -25
  24. package/src/sdkFactory/types.ts +0 -4
  25. package/src/services/authProvider.ts +1 -1
  26. package/src/storages/utils.ts +1 -0
  27. package/src/sync/submitters/impressionsSubmitter.ts +6 -6
  28. package/src/sync/submitters/types.ts +2 -1
  29. package/types/splitio.d.ts +1 -171
  30. package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +0 -70
  31. package/cjs/evaluator/fallbackConfigsCalculator/index.js +0 -25
  32. package/esm/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +0 -64
  33. package/esm/evaluator/fallbackConfigsCalculator/index.js +0 -21
  34. package/src/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.ts +0 -76
  35. package/src/evaluator/fallbackConfigsCalculator/index.ts +0 -24
@@ -2290,133 +2290,9 @@ declare namespace SplitIO {
2290
2290
  split(featureFlagName: string): SplitViewAsync;
2291
2291
  }
2292
2292
 
2293
- /**
2294
- * Fallback configuration objects returned by the `client.getConfig` method when the SDK is not ready or the provided config name is not found.
2295
- */
2296
- type FallbackConfigs = {
2297
- /**
2298
- * Fallback config for all config names.
2299
- */
2300
- global?: Config;
2301
- /**
2302
- * Fallback configs for specific config names. It takes precedence over the global fallback config.
2303
- */
2304
- byName?: {
2305
- [configName: string]: Config;
2306
- };
2307
- }
2308
-
2309
- /**
2310
- * Configs SDK settings.
2311
- */
2312
- interface ConfigsClientSettings {
2313
- /**
2314
- * SDK key used to authenticate with Harness services.
2315
- *
2316
- * @see {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/account-settings/api-keys/}
2317
- */
2318
- sdkKey: string;
2319
- /**
2320
- * Log level for SDK logging.
2321
- * - `'none'`: No logging
2322
- * - `'error'`: Log errors only
2323
- * - `'warn'`: Log warnings and errors
2324
- * - `'info'`: Log info, warnings, and errors
2325
- * - `'debug'`: Log debug info and above
2326
- * @defaultValue `'none'`
2327
- */
2328
- logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
2329
- /**
2330
- * Synchronization configuration.
2331
- */
2332
- sync?: {
2333
- /**
2334
- * Polling rate for configs and segments refresh, in seconds. Minimum value: 5.
2335
- *
2336
- * @defaultValue `60`
2337
- */
2338
- pollingRate?: number;
2339
- /**
2340
- * Push rate for events and impressions, in seconds. Minimum value: 60.
2341
- *
2342
- * @defaultValue `60`
2343
- */
2344
- pushRate?: number;
2345
- /**
2346
- * Maximum queue size for events and impressions. When the queue reaches this size, a flush is triggered. Minimum value: 1000.
2347
- *
2348
- * @defaultValue `10000`
2349
- */
2350
- queueSize?: number;
2351
- /**
2352
- * Time in seconds before emitting the `SDK_READY_TIMED_OUT` event.
2353
- * A value of `-1` disables the timeout and thus the event is never emitted.
2354
- *
2355
- * @defaultValue `10`
2356
- */
2357
- readyTimeout?: number;
2358
- /**
2359
- * Base URLs used by the SDK for different services.
2360
- */
2361
- serviceEndpoints?: {
2362
- /**
2363
- * String property to override the base URL where the SDK will get JWT authentication credentials.
2364
- *
2365
- * @defaultValue `'https://auth.split.io'`
2366
- */
2367
- auth?: string;
2368
- /**
2369
- * String property to override the base URL where the SDK will get rollout plan related data, like configs and segments definitions.
2370
- *
2371
- * @defaultValue `'https://configs.split.io'`
2372
- */
2373
- configs?: string;
2374
- /**
2375
- * String property to override the base URL where the SDK will post event-related information like impressions.
2376
- *
2377
- * @defaultValue `'https://events.split.io'`
2378
- */
2379
- events?: string;
2380
- };
2381
- };
2382
- /**
2383
- * Fallback configuration objects returned by the `client.getConfig` method when the SDK is not ready or the provided config name is not found.
2384
- */
2385
- fallbackConfigs?: FallbackConfigs;
2386
- /**
2387
- * Custom options object for HTTP(S) requests.
2388
- * If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
2389
- */
2390
- requestOptions?: {
2391
- /**
2392
- * Custom Node.js HTTP(S) Agent used by the SDK for HTTP(S) requests.
2393
- *
2394
- * You can use it, for example, for certificate pinning or setting a network proxy:
2395
- *
2396
- * ```
2397
- * const { ConfigsClient } = require('@splitsoftware/configs');
2398
- * const { HttpsProxyAgent } = require('https-proxy-agent');
2399
- *
2400
- * const proxyAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY || 'http://10.10.1.10:1080');
2401
- *
2402
- * const client = ConfigsClient({
2403
- * ...
2404
- * requestOptions: {
2405
- * agent: proxyAgent
2406
- * }
2407
- * })
2408
- * ```
2409
- *
2410
- * @see {@link https://nodejs.org/api/https.html#class-httpsagent}
2411
- *
2412
- * @defaultValue `undefined`
2413
- */
2414
- agent?: RequestOptions['agent'];
2415
- };
2416
- }
2417
2293
 
2418
2294
  /**
2419
- * Target for a config evaluation.
2295
+ * Target for an evaluation.
2420
2296
  */
2421
2297
  interface Target {
2422
2298
  /**
@@ -2434,50 +2310,4 @@ declare namespace SplitIO {
2434
2310
  type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
2435
2311
  type JsonArray = JsonValue[];
2436
2312
  type JsonObject = { [key: string]: JsonValue; };
2437
-
2438
- /**
2439
- * Config object returned by getConfig.
2440
- */
2441
- type Config = {
2442
- /**
2443
- * The name of the variant.
2444
- */
2445
- variant: string;
2446
- /**
2447
- * The config value, a raw JSON object.
2448
- */
2449
- value: JsonObject;
2450
- }
2451
-
2452
- /**
2453
- * Configs SDK client interface.
2454
- */
2455
- interface ConfigsClient extends Omit<IStatusInterface, 'ready' | 'whenReadyFromCache'> {
2456
- /**
2457
- * Destroys the client.
2458
- *
2459
- * @returns A promise that resolves once all clients are destroyed.
2460
- */
2461
- destroy(): Promise<void>;
2462
- /**
2463
- * Gets the config object for a given config name and optional target. If no target is provided, the default variant of the config is returned.
2464
- *
2465
- * @param configName - The name of the config we want to get.
2466
- * @param target - The target of the config evaluation.
2467
- * @param options - An object of type EvaluationOptions for advanced evaluation options.
2468
- * @returns The config object.
2469
- */
2470
- getConfig(configName: string, target?: Target, options?: EvaluationOptions): Config;
2471
- /**
2472
- * Tracks an event to be fed to the results product on Harness FME user interface.
2473
- *
2474
- * @param trafficKey - The key that identifies the entity related to this event.
2475
- * @param trafficType - The traffic type of the entity related to this event. See {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/fme-settings/traffic-types/}
2476
- * @param eventType - The event type corresponding to this event.
2477
- * @param value - The value of this event.
2478
- * @param properties - The properties of this event. Values can be string, number, boolean or null.
2479
- * @returns Whether the event was added to the queue successfully or not.
2480
- */
2481
- track(trafficKey: SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): boolean;
2482
- }
2483
2313
  }
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sanitizeFallbacks = exports.isValidConfig = exports.isValidConfigName = void 0;
4
- var lang_1 = require("../../../utils/lang");
5
- var CONFIG_NAME_DISCARD_REASON = 'Invalid config name (max 100 chars, no spaces)';
6
- var VARIANT_DISCARD_REASON = 'Invalid variant (max 100 chars and must match pattern)';
7
- var VALUE_DISCARD_REASON = 'Invalid value (must be an object)';
8
- var VARIANT_PATTERN = /^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$/;
9
- function isValidConfigName(name) {
10
- return name.length <= 100 && !name.includes(' ');
11
- }
12
- exports.isValidConfigName = isValidConfigName;
13
- function isValidConfig(config) {
14
- if (!(0, lang_1.isObject)(config))
15
- return false;
16
- if (!(0, lang_1.isString)(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant))
17
- return false;
18
- if (!(0, lang_1.isObject)(config.value))
19
- return false;
20
- return true;
21
- }
22
- exports.isValidConfig = isValidConfig;
23
- function sanitizeGlobal(logger, config) {
24
- if (config === undefined)
25
- return undefined;
26
- if (!isValidConfig(config)) {
27
- if (!(0, lang_1.isObject)(config) || !(0, lang_1.isString)(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
28
- logger.error("Fallback configs - Discarded fallback: ".concat(VARIANT_DISCARD_REASON));
29
- }
30
- else {
31
- logger.error("Fallback configs - Discarded fallback: ".concat(VALUE_DISCARD_REASON));
32
- }
33
- return undefined;
34
- }
35
- return config;
36
- }
37
- function sanitizeByName(logger, byNameFallbacks) {
38
- var sanitizedByName = {};
39
- if (!(0, lang_1.isObject)(byNameFallbacks))
40
- return sanitizedByName;
41
- Object.keys(byNameFallbacks).forEach(function (configName) {
42
- var config = byNameFallbacks[configName];
43
- if (!isValidConfigName(configName)) {
44
- logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(CONFIG_NAME_DISCARD_REASON));
45
- return;
46
- }
47
- if (!isValidConfig(config)) {
48
- if (!(0, lang_1.isObject)(config) || !(0, lang_1.isString)(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
49
- logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(VARIANT_DISCARD_REASON));
50
- }
51
- else {
52
- logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(VALUE_DISCARD_REASON));
53
- }
54
- return;
55
- }
56
- sanitizedByName[configName] = config;
57
- });
58
- return sanitizedByName;
59
- }
60
- function sanitizeFallbacks(logger, fallbacks) {
61
- if (!(0, lang_1.isObject)(fallbacks)) {
62
- logger.error('Fallback configs - Discarded configuration: it must be an object with optional `global` and `byName` properties');
63
- return;
64
- }
65
- return {
66
- global: sanitizeGlobal(logger, fallbacks.global),
67
- byName: sanitizeByName(logger, fallbacks.byName)
68
- };
69
- }
70
- exports.sanitizeFallbacks = sanitizeFallbacks;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FallbackConfigsCalculator = exports.FALLBACK_PREFIX = void 0;
4
- var constants_1 = require("../../utils/constants");
5
- exports.FALLBACK_PREFIX = 'fallback - ';
6
- function FallbackConfigsCalculator(fallbacks) {
7
- if (fallbacks === void 0) { fallbacks = {}; }
8
- return function (configName, label) {
9
- var _a;
10
- if (label === void 0) { label = ''; }
11
- var fallback = ((_a = fallbacks.byName) === null || _a === void 0 ? void 0 : _a[configName]) || fallbacks.global;
12
- return fallback ?
13
- {
14
- treatment: fallback.variant,
15
- config: fallback.value,
16
- label: "".concat(exports.FALLBACK_PREFIX).concat(label),
17
- } :
18
- {
19
- treatment: constants_1.CONTROL,
20
- config: null,
21
- label: label,
22
- };
23
- };
24
- }
25
- exports.FallbackConfigsCalculator = FallbackConfigsCalculator;
@@ -1,64 +0,0 @@
1
- import { isObject, isString } from '../../../utils/lang';
2
- var CONFIG_NAME_DISCARD_REASON = 'Invalid config name (max 100 chars, no spaces)';
3
- var VARIANT_DISCARD_REASON = 'Invalid variant (max 100 chars and must match pattern)';
4
- var VALUE_DISCARD_REASON = 'Invalid value (must be an object)';
5
- var VARIANT_PATTERN = /^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$/;
6
- export function isValidConfigName(name) {
7
- return name.length <= 100 && !name.includes(' ');
8
- }
9
- export function isValidConfig(config) {
10
- if (!isObject(config))
11
- return false;
12
- if (!isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant))
13
- return false;
14
- if (!isObject(config.value))
15
- return false;
16
- return true;
17
- }
18
- function sanitizeGlobal(logger, config) {
19
- if (config === undefined)
20
- return undefined;
21
- if (!isValidConfig(config)) {
22
- if (!isObject(config) || !isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
23
- logger.error("Fallback configs - Discarded fallback: ".concat(VARIANT_DISCARD_REASON));
24
- }
25
- else {
26
- logger.error("Fallback configs - Discarded fallback: ".concat(VALUE_DISCARD_REASON));
27
- }
28
- return undefined;
29
- }
30
- return config;
31
- }
32
- function sanitizeByName(logger, byNameFallbacks) {
33
- var sanitizedByName = {};
34
- if (!isObject(byNameFallbacks))
35
- return sanitizedByName;
36
- Object.keys(byNameFallbacks).forEach(function (configName) {
37
- var config = byNameFallbacks[configName];
38
- if (!isValidConfigName(configName)) {
39
- logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(CONFIG_NAME_DISCARD_REASON));
40
- return;
41
- }
42
- if (!isValidConfig(config)) {
43
- if (!isObject(config) || !isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
44
- logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(VARIANT_DISCARD_REASON));
45
- }
46
- else {
47
- logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(VALUE_DISCARD_REASON));
48
- }
49
- return;
50
- }
51
- sanitizedByName[configName] = config;
52
- });
53
- return sanitizedByName;
54
- }
55
- export function sanitizeFallbacks(logger, fallbacks) {
56
- if (!isObject(fallbacks)) {
57
- logger.error('Fallback configs - Discarded configuration: it must be an object with optional `global` and `byName` properties');
58
- return;
59
- }
60
- return {
61
- global: sanitizeGlobal(logger, fallbacks.global),
62
- byName: sanitizeByName(logger, fallbacks.byName)
63
- };
64
- }
@@ -1,21 +0,0 @@
1
- import { CONTROL } from '../../utils/constants';
2
- export var FALLBACK_PREFIX = 'fallback - ';
3
- export function FallbackConfigsCalculator(fallbacks) {
4
- if (fallbacks === void 0) { fallbacks = {}; }
5
- return function (configName, label) {
6
- var _a;
7
- if (label === void 0) { label = ''; }
8
- var fallback = ((_a = fallbacks.byName) === null || _a === void 0 ? void 0 : _a[configName]) || fallbacks.global;
9
- return fallback ?
10
- {
11
- treatment: fallback.variant,
12
- config: fallback.value,
13
- label: "".concat(FALLBACK_PREFIX).concat(label),
14
- } :
15
- {
16
- treatment: CONTROL,
17
- config: null,
18
- label: label,
19
- };
20
- };
21
- }
@@ -1,76 +0,0 @@
1
- import SplitIO from '../../../../types/splitio';
2
- import { ILogger } from '../../../logger/types';
3
- import { isObject, isString } from '../../../utils/lang';
4
-
5
- const CONFIG_NAME_DISCARD_REASON = 'Invalid config name (max 100 chars, no spaces)';
6
- const VARIANT_DISCARD_REASON = 'Invalid variant (max 100 chars and must match pattern)';
7
- const VALUE_DISCARD_REASON = 'Invalid value (must be an object)';
8
-
9
- const VARIANT_PATTERN = /^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$/;
10
-
11
- export function isValidConfigName(name: string): boolean {
12
- return name.length <= 100 && !name.includes(' ');
13
- }
14
-
15
- export function isValidConfig(config?: SplitIO.Config): boolean {
16
- if (!isObject(config)) return false;
17
- if (!isString(config!.variant) || config!.variant.length > 100 || !VARIANT_PATTERN.test(config!.variant)) return false;
18
- if (!isObject(config!.value)) return false;
19
- return true;
20
- }
21
-
22
- function sanitizeGlobal(logger: ILogger, config?: SplitIO.Config): SplitIO.Config | undefined {
23
- if (config === undefined) return undefined;
24
- if (!isValidConfig(config)) {
25
- if (!isObject(config) || !isString(config!.variant) || config!.variant.length > 100 || !VARIANT_PATTERN.test(config!.variant)) {
26
- logger.error(`Fallback configs - Discarded fallback: ${VARIANT_DISCARD_REASON}`);
27
- } else {
28
- logger.error(`Fallback configs - Discarded fallback: ${VALUE_DISCARD_REASON}`);
29
- }
30
- return undefined;
31
- }
32
- return config;
33
- }
34
-
35
- function sanitizeByName(
36
- logger: ILogger,
37
- byNameFallbacks?: Record<string, SplitIO.Config>
38
- ): Record<string, SplitIO.Config> {
39
- const sanitizedByName: Record<string, SplitIO.Config> = {};
40
-
41
- if (!isObject(byNameFallbacks)) return sanitizedByName;
42
-
43
- Object.keys(byNameFallbacks!).forEach((configName) => {
44
- const config = byNameFallbacks![configName];
45
-
46
- if (!isValidConfigName(configName)) {
47
- logger.error(`Fallback configs - Discarded config '${configName}': ${CONFIG_NAME_DISCARD_REASON}`);
48
- return;
49
- }
50
-
51
- if (!isValidConfig(config)) {
52
- if (!isObject(config) || !isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
53
- logger.error(`Fallback configs - Discarded config '${configName}': ${VARIANT_DISCARD_REASON}`);
54
- } else {
55
- logger.error(`Fallback configs - Discarded config '${configName}': ${VALUE_DISCARD_REASON}`);
56
- }
57
- return;
58
- }
59
-
60
- sanitizedByName[configName] = config;
61
- });
62
-
63
- return sanitizedByName;
64
- }
65
-
66
- export function sanitizeFallbacks(logger: ILogger, fallbacks: SplitIO.FallbackConfigs): SplitIO.FallbackConfigs | undefined {
67
- if (!isObject(fallbacks)) {
68
- logger.error('Fallback configs - Discarded configuration: it must be an object with optional `global` and `byName` properties');
69
- return;
70
- }
71
-
72
- return {
73
- global: sanitizeGlobal(logger, fallbacks.global),
74
- byName: sanitizeByName(logger, fallbacks.byName)
75
- };
76
- }
@@ -1,24 +0,0 @@
1
- import { IFallbackCalculator } from '../fallbackTreatmentsCalculator/index';
2
- import { CONTROL } from '../../utils/constants';
3
- import SplitIO from '../../../types/splitio';
4
-
5
- export const FALLBACK_PREFIX = 'fallback - ';
6
-
7
- export function FallbackConfigsCalculator(fallbacks: SplitIO.FallbackConfigs = {}): IFallbackCalculator {
8
-
9
- return (configName: string, label = '') => {
10
- const fallback = fallbacks.byName?.[configName] || fallbacks.global;
11
-
12
- return fallback ?
13
- {
14
- treatment: fallback.variant,
15
- config: fallback.value,
16
- label: `${FALLBACK_PREFIX}${label}`,
17
- } :
18
- {
19
- treatment: CONTROL,
20
- config: null,
21
- label,
22
- };
23
- };
24
- }