@statsig/client-core 1.1.1 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/client-core",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "dependencies": {},
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -1,13 +1,13 @@
1
1
  import { DownloadConfigSpecsResponse } from './DownloadConfigSpecsResponse';
2
2
  import { ErrorBoundary } from './ErrorBoundary';
3
- import { DynamicConfigEvaluationOptions, ExperimentEvaluationOptions, FeatureGateEvaluationOptions, LayerEvaluationOptions } from './EvaluationOptions';
3
+ import { DynamicConfigEvaluationOptions, ExperimentEvaluationOptions, FeatureGateEvaluationOptions, LayerEvaluationOptions, ParameterStoreEvaluationOptions } from './EvaluationOptions';
4
4
  import { InitializeResponseWithUpdates } from './InitializeResponse';
5
5
  import { StatsigSession } from './SessionID';
6
6
  import { StatsigClientEventEmitterInterface } from './StatsigClientEventEmitter';
7
7
  import { EvaluationsDataAdapter, SpecsDataAdapter } from './StatsigDataAdapter';
8
8
  import { StatsigEvent } from './StatsigEvent';
9
9
  import { AnyStatsigOptions, StatsigRuntimeMutableOptions } from './StatsigOptionsCommon';
10
- import { DynamicConfig, Experiment, FeatureGate, Layer } from './StatsigTypes';
10
+ import { DynamicConfig, Experiment, FeatureGate, Layer, ParameterStore } from './StatsigTypes';
11
11
  import { StatsigUser } from './StatsigUser';
12
12
  import { Flatten } from './UtitlityTypes';
13
13
  export interface StatsigClientCommonInterface extends StatsigClientEventEmitterInterface {
@@ -58,6 +58,7 @@ export interface PrecomputedEvaluationsInterface extends StatsigClientCommonInte
58
58
  getDynamicConfig(name: string, options?: DynamicConfigEvaluationOptions): DynamicConfig;
59
59
  getExperiment(name: string, options?: ExperimentEvaluationOptions): Experiment;
60
60
  getLayer(name: string, options?: LayerEvaluationOptions): Layer;
61
+ getParameterStore(name: string, options?: ParameterStoreEvaluationOptions): ParameterStore;
61
62
  logEvent(event: StatsigEvent): void;
62
63
  logEvent(eventName: string, value?: string | number, metadata?: Record<string, string>): void;
63
64
  }
@@ -18,3 +18,4 @@ export type ExperimentEvaluationOptions = EvaluationOptionsCommon & {
18
18
  userPersistedValues?: unknown;
19
19
  };
20
20
  export type LayerEvaluationOptions = EvaluationOptionsCommon & {};
21
+ export type ParameterStoreEvaluationOptions = EvaluationOptionsCommon & {};
@@ -1,3 +1,4 @@
1
+ import { ParamStoreConfig } from './ParamStoreTypes';
1
2
  import { Flatten } from './UtitlityTypes';
2
3
  type EvaluationBase<T> = {
3
4
  id_type: string;
@@ -32,8 +33,8 @@ export type EvaluationDetails = {
32
33
  lcut?: number;
33
34
  receivedAt?: number;
34
35
  };
35
- export type DetailedEvaluation<T extends AnyEvaluation> = {
36
- evaluation: T | null;
36
+ export type DetailedStoreResult<T extends AnyEvaluation | ParamStoreConfig> = {
37
+ result: T | null;
37
38
  details: EvaluationDetails;
38
39
  };
39
40
  export {};
@@ -1,4 +1,5 @@
1
1
  import { DynamicConfigEvaluation, GateEvaluation, LayerEvaluation } from './EvaluationTypes';
2
+ import { ParamStoreConfig } from './ParamStoreTypes';
2
3
  import { StatsigUser } from './StatsigUser';
3
4
  type SessionReplayFields = {
4
5
  can_record_session?: boolean;
@@ -8,6 +9,7 @@ export type InitializeResponseWithUpdates = SessionReplayFields & {
8
9
  feature_gates: Record<string, GateEvaluation>;
9
10
  dynamic_configs: Record<string, DynamicConfigEvaluation>;
10
11
  layer_configs: Record<string, LayerEvaluation>;
12
+ param_stores?: Record<string, ParamStoreConfig>;
11
13
  time: number;
12
14
  has_updates: true;
13
15
  hash_used: 'none' | 'sha256' | 'djb2';
@@ -35,6 +35,5 @@ export declare class NetworkCore {
35
35
  private _getPopulatedURL;
36
36
  private _getPopulatedBody;
37
37
  private _attemptToEncodeString;
38
- private _attemptToCompressBody;
39
38
  }
40
39
  export {};
@@ -44,9 +44,6 @@ class NetworkCore {
44
44
  if (args.isStatsigEncodable) {
45
45
  body = this._attemptToEncodeString(args, body);
46
46
  }
47
- else if (args.isCompressable) {
48
- body = yield this._attemptToCompressBody(args, body);
49
- }
50
47
  return this._sendRequest(Object.assign({ method: 'POST', body }, args));
51
48
  });
52
49
  }
@@ -62,8 +59,7 @@ class NetworkCore {
62
59
  if (!_ensureValidSdkKey(args)) {
63
60
  return false;
64
61
  }
65
- let body = yield this._getPopulatedBody(args);
66
- body = yield this._attemptToCompressBody(args, body);
62
+ const body = yield this._getPopulatedBody(args);
67
63
  const url = yield this._getPopulatedURL(args);
68
64
  const nav = navigator;
69
65
  return nav.sendBeacon.bind(nav)(url, body);
@@ -162,25 +158,6 @@ class NetworkCore {
162
158
  return input;
163
159
  }
164
160
  }
165
- _attemptToCompressBody(args, body) {
166
- var _a;
167
- return __awaiter(this, void 0, void 0, function* () {
168
- if (!args.isCompressable ||
169
- this._options.disableCompression ||
170
- (0, __StatsigGlobal_1._getStatsigGlobalFlag)('no-compress') != null ||
171
- typeof CompressionStream === 'undefined' ||
172
- typeof TextEncoder === 'undefined') {
173
- return body;
174
- }
175
- const bytes = new TextEncoder().encode(body);
176
- const stream = new CompressionStream('gzip');
177
- const writer = stream.writable.getWriter();
178
- writer.write(bytes).catch(Log_1.Log.error);
179
- writer.close().catch(Log_1.Log.error);
180
- args.params = Object.assign(Object.assign({}, ((_a = args.params) !== null && _a !== void 0 ? _a : {})), { [NetworkConfig_1.NetworkParam.IsGzipped]: '1' });
181
- return yield new Response(stream.readable).arrayBuffer();
182
- });
183
- }
184
161
  }
185
162
  exports.NetworkCore = NetworkCore;
186
163
  const _ensureValidSdkKey = (args) => {
@@ -0,0 +1,65 @@
1
+ type ParamType = 'string' | 'boolean' | 'number' | 'array' | 'object';
2
+ type RefType = 'gate' | 'gated_value' | 'static' | 'layer' | 'dynamic_config' | 'experiment';
3
+ export type StaticParam = {
4
+ ref_type: 'static';
5
+ } & ({
6
+ param_type: 'boolean';
7
+ value: boolean;
8
+ } | {
9
+ param_type: 'number';
10
+ value: number;
11
+ } | {
12
+ param_type: 'string';
13
+ value: string;
14
+ } | {
15
+ param_type: 'object';
16
+ value: object;
17
+ } | {
18
+ param_type: 'array';
19
+ value: unknown[];
20
+ });
21
+ export type GateParam = {
22
+ ref_type: 'gate';
23
+ gate_name: string;
24
+ } & ({
25
+ param_type: 'boolean';
26
+ pass_value: boolean;
27
+ fail_value: boolean;
28
+ } | {
29
+ param_type: 'number';
30
+ pass_value: number;
31
+ fail_value: number;
32
+ } | {
33
+ param_type: 'string';
34
+ pass_value: string;
35
+ fail_value: string;
36
+ } | {
37
+ param_type: 'object';
38
+ pass_value: object;
39
+ fail_value: object;
40
+ } | {
41
+ param_type: 'array';
42
+ pass_value: unknown[];
43
+ fail_value: unknown[];
44
+ });
45
+ type Param<R extends RefType, T extends ParamType> = {
46
+ ref_type: R;
47
+ param_type: T;
48
+ };
49
+ export type LayerParam = Param<'layer', ParamType> & {
50
+ layer_name: string;
51
+ param_name: string;
52
+ };
53
+ export type DynamicConfigParam = Param<'dynamic_config', ParamType> & {
54
+ config_name: string;
55
+ param_name: string;
56
+ };
57
+ export type ExperimentParam = Param<'experiment', ParamType> & {
58
+ experiment_name: string;
59
+ param_name: string;
60
+ };
61
+ type AnyParam = GateParam | StaticParam | LayerParam | DynamicConfigParam | ExperimentParam;
62
+ export type ParamStoreConfig = {
63
+ [param_name: string]: AnyParam | undefined;
64
+ };
65
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -15,5 +15,6 @@ export declare const SessionID: {
15
15
  };
16
16
  export declare const StatsigSession: {
17
17
  get: (sdkKey: string) => Promise<StatsigSession>;
18
+ overrideInitialSessionID: (override: string, sdkKey: string) => void;
18
19
  };
19
20
  export {};
package/src/SessionID.js CHANGED
@@ -30,6 +30,9 @@ exports.StatsigSession = {
30
30
  const session = yield PROMISE_MAP[sdkKey];
31
31
  return _bumpSession(session);
32
32
  }),
33
+ overrideInitialSessionID: (override, sdkKey) => {
34
+ PROMISE_MAP[sdkKey] = _overrideSessionId(override, sdkKey);
35
+ },
33
36
  };
34
37
  function _loadSession(sdkKey) {
35
38
  return __awaiter(this, void 0, void 0, function* () {
@@ -48,6 +51,17 @@ function _loadSession(sdkKey) {
48
51
  };
49
52
  });
50
53
  }
54
+ function _overrideSessionId(override, sdkKey) {
55
+ const now = Date.now();
56
+ return Promise.resolve({
57
+ data: {
58
+ sessionID: override,
59
+ startTime: now,
60
+ lastUpdate: now,
61
+ },
62
+ sdkKey,
63
+ });
64
+ }
51
65
  function _bumpSession(session) {
52
66
  const now = Date.now();
53
67
  const data = session.data;
@@ -16,6 +16,7 @@ const ErrorBoundary_1 = require("./ErrorBoundary");
16
16
  const EventLogger_1 = require("./EventLogger");
17
17
  const Log_1 = require("./Log");
18
18
  const SafeJs_1 = require("./SafeJs");
19
+ const SessionID_1 = require("./SessionID");
19
20
  const StorageProvider_1 = require("./StorageProvider");
20
21
  class StatsigClientBase {
21
22
  constructor(sdkKey, adapter, network, options) {
@@ -25,6 +26,8 @@ class StatsigClientBase {
25
26
  const emitter = this.$emt.bind(this);
26
27
  (options === null || options === void 0 ? void 0 : options.logLevel) != null && (Log_1.Log.level = options.logLevel);
27
28
  (options === null || options === void 0 ? void 0 : options.disableStorage) && StorageProvider_1.Storage._setDisabled(true);
29
+ (options === null || options === void 0 ? void 0 : options.initialSessionID) &&
30
+ SessionID_1.StatsigSession.overrideInitialSessionID(options.initialSessionID, sdkKey);
28
31
  this._sdkKey = sdkKey;
29
32
  this._options = options !== null && options !== void 0 ? options : {};
30
33
  this._overrideAdapter = (_a = options === null || options === void 0 ? void 0 : options.overrideAdapter) !== null && _a !== void 0 ? _a : null;
@@ -5,7 +5,7 @@ export type StatsigEvent = {
5
5
  eventName: string;
6
6
  value?: string | number | null;
7
7
  metadata?: {
8
- [key: string]: string;
8
+ [key: string]: string | undefined;
9
9
  } | null;
10
10
  };
11
11
  export type StatsigEventInternal = Omit<StatsigEvent, 'metadata'> & {
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "1.1.1";
1
+ export declare const SDK_VERSION = "1.3.0";
2
2
  export type StatsigMetadata = {
3
3
  readonly [key: string]: string | undefined;
4
4
  readonly appVersion?: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StatsigMetadataProvider = exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '1.1.1';
4
+ exports.SDK_VERSION = '1.3.0';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
@@ -104,6 +104,12 @@ export type StatsigOptionsCommon<NetworkConfig extends NetworkConfigCommon> = St
104
104
  * returned to the caller of a check api (checkGate/getExperiment etc).
105
105
  */
106
106
  overrideAdapter?: OverrideAdapter;
107
+ /**
108
+ * Overrides the auto-generated SessionID with the provided string.
109
+ *
110
+ * Note: Sessions still expire and will be replaced with an auto-generated SessionID.
111
+ */
112
+ initialSessionID?: string;
107
113
  };
108
114
  export type AnyStatsigOptions = StatsigOptionsCommon<NetworkConfigCommon>;
109
115
  export type StatsigEnvironment = {
@@ -1,6 +1,12 @@
1
1
  import { DynamicConfigEvaluation, EvaluationDetails, GateEvaluation, LayerEvaluation } from './EvaluationTypes';
2
- import { AnyConfigBasedStatsigType, DynamicConfig, FeatureGate, Layer } from './StatsigTypes';
2
+ import { AnyConfigBasedStatsigType, DynamicConfig, Experiment, FeatureGate, Layer, TypedGet } from './StatsigTypes';
3
+ type Primitive = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
3
4
  export declare function _makeFeatureGate(name: string, details: EvaluationDetails, evaluation: GateEvaluation | null): FeatureGate;
4
5
  export declare function _makeDynamicConfig(name: string, details: EvaluationDetails, evaluation: DynamicConfigEvaluation | null): DynamicConfig;
6
+ export declare function _makeExperiment(name: string, details: EvaluationDetails, evaluation: DynamicConfigEvaluation | null): Experiment;
5
7
  export declare function _makeLayer(name: string, details: EvaluationDetails, evaluation: LayerEvaluation | null, exposeFunc?: (param: string) => void): Layer;
6
8
  export declare function _mergeOverride<T extends AnyConfigBasedStatsigType>(original: T, overridden: T | null | undefined, value: Record<string, unknown>, exposeFunc?: (param: string) => void): T;
9
+ export declare function _typeOf(input: unknown): Primitive | 'array';
10
+ export declare function _isTypeMatch<T>(a: unknown, b: unknown): a is T;
11
+ export declare function _makeTypedGet(value: Record<string, unknown> | undefined, exposeFunc?: (param: string) => void): TypedGet;
12
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._mergeOverride = exports._makeLayer = exports._makeDynamicConfig = exports._makeFeatureGate = void 0;
3
+ exports._makeTypedGet = exports._isTypeMatch = exports._typeOf = exports._mergeOverride = exports._makeLayer = exports._makeExperiment = exports._makeDynamicConfig = exports._makeFeatureGate = void 0;
4
4
  const DEFAULT_RULE = 'default';
5
5
  function _makeEvaluation(name, details, evaluation, value) {
6
6
  var _a;
@@ -18,9 +18,16 @@ function _makeFeatureGate(name, details, evaluation) {
18
18
  exports._makeFeatureGate = _makeFeatureGate;
19
19
  function _makeDynamicConfig(name, details, evaluation) {
20
20
  var _a;
21
- return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _a !== void 0 ? _a : {})), { groupName: null, get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) });
21
+ const value = (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _a !== void 0 ? _a : {};
22
+ return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, value)), { get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) });
22
23
  }
23
24
  exports._makeDynamicConfig = _makeDynamicConfig;
25
+ function _makeExperiment(name, details, evaluation) {
26
+ var _a;
27
+ const result = _makeDynamicConfig(name, details, evaluation);
28
+ return Object.assign(Object.assign({}, result), { groupName: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.group_name) !== null && _a !== void 0 ? _a : null });
29
+ }
30
+ exports._makeExperiment = _makeExperiment;
24
31
  function _makeLayer(name, details, evaluation, exposeFunc) {
25
32
  var _a, _b;
26
33
  return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, undefined)), { get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value, exposeFunc), groupName: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.group_name) !== null && _a !== void 0 ? _a : null, __value: (_b = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _b !== void 0 ? _b : {} });
@@ -30,10 +37,15 @@ function _mergeOverride(original, overridden, value, exposeFunc) {
30
37
  return Object.assign(Object.assign(Object.assign({}, original), overridden), { get: _makeTypedGet(value, exposeFunc) });
31
38
  }
32
39
  exports._mergeOverride = _mergeOverride;
40
+ function _typeOf(input) {
41
+ return Array.isArray(input) ? 'array' : typeof input;
42
+ }
43
+ exports._typeOf = _typeOf;
33
44
  function _isTypeMatch(a, b) {
34
45
  const typeOf = (x) => (Array.isArray(x) ? 'array' : typeof x);
35
46
  return typeOf(a) === typeOf(b);
36
47
  }
48
+ exports._isTypeMatch = _isTypeMatch;
37
49
  function _makeTypedGet(value, exposeFunc) {
38
50
  return (param, fallback) => {
39
51
  var _a;
@@ -48,3 +60,4 @@ function _makeTypedGet(value, exposeFunc) {
48
60
  return found;
49
61
  };
50
62
  }
63
+ exports._makeTypedGet = _makeTypedGet;
@@ -1,6 +1,8 @@
1
1
  import { EvaluationDetails, ExperimentEvaluation, GateEvaluation, LayerEvaluation } from './EvaluationTypes';
2
+ import { ParamStoreConfig } from './ParamStoreTypes';
2
3
  import { Flatten } from './UtitlityTypes';
3
4
  export type TypedGet = <T = unknown>(key: string, fallback?: T) => TypedReturn<T>;
5
+ export type ParamStoreTypedGet = <T = unknown>(key: string, fallback: T) => T;
4
6
  export type TypedReturn<T = unknown> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends Array<unknown> ? Array<unknown> : T extends object ? object : unknown;
5
7
  export type SpecType = 'gate' | 'dynamic_config' | 'experiment' | 'layer';
6
8
  export type FeatureGate = Flatten<{
@@ -19,7 +21,7 @@ export type Experiment = Flatten<{
19
21
  readonly __evaluation: ExperimentEvaluation | null;
20
22
  readonly get: TypedGet;
21
23
  }>;
22
- export type DynamicConfig = Flatten<Experiment>;
24
+ export type DynamicConfig = Flatten<Omit<Experiment, 'groupName'>>;
23
25
  export type Layer = Flatten<{
24
26
  readonly name: string;
25
27
  readonly ruleID: string;
@@ -29,5 +31,11 @@ export type Layer = Flatten<{
29
31
  readonly __evaluation: LayerEvaluation | null;
30
32
  readonly get: TypedGet;
31
33
  }>;
34
+ export type ParameterStore = Flatten<{
35
+ readonly name: string;
36
+ readonly details: EvaluationDetails;
37
+ readonly get: TypedGet;
38
+ readonly __configuration: ParamStoreConfig | null;
39
+ }>;
32
40
  export type AnyConfigBasedStatsigType = DynamicConfig | Experiment | Layer;
33
41
  export type AnyStatsigType = FeatureGate | AnyConfigBasedStatsigType;
package/src/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * from './Log';
17
17
  export * from './NetworkCore';
18
18
  export * from './NetworkConfig';
19
19
  export * from './OverrideAdapter';
20
+ export * from './ParamStoreTypes';
20
21
  export * from './SafeJs';
21
22
  export * from './SDKType';
22
23
  export * from './SessionID';
package/src/index.js CHANGED
@@ -38,6 +38,7 @@ __exportStar(require("./Log"), exports);
38
38
  __exportStar(require("./NetworkCore"), exports);
39
39
  __exportStar(require("./NetworkConfig"), exports);
40
40
  __exportStar(require("./OverrideAdapter"), exports);
41
+ __exportStar(require("./ParamStoreTypes"), exports);
41
42
  __exportStar(require("./SafeJs"), exports);
42
43
  __exportStar(require("./SDKType"), exports);
43
44
  __exportStar(require("./SessionID"), exports);