expf-sigma-node.js 3.2.11 → 3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/sigma.js +297 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expf-sigma-node.js",
3
- "version": "3.2.11",
3
+ "version": "3.3.0",
4
4
  "description": "expf-sigma-node.js lets you manage features flags and remote config across web, server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.",
5
5
  "main": "public/sigma.js",
6
6
  "keywords": [
package/public/sigma.js CHANGED
@@ -135,9 +135,6 @@ var SigmaUserData = class {
135
135
  version: os.version || void 0
136
136
  };
137
137
  }
138
- setUserId(userId) {
139
- this.user.userId = userId;
140
- }
141
138
  setIp(ip) {
142
139
  this.user.ip = ip;
143
140
  }
@@ -151,11 +148,133 @@ var SigmaUserData = class {
151
148
  });
152
149
  }
153
150
  }
151
+ setGeo(data) {
152
+ if (!data || typeof data !== "object" || Array.isArray(data))
153
+ return;
154
+ this.user.geo = data;
155
+ }
154
156
  clearFlags() {
155
157
  this.user.featureFlags = [];
156
158
  }
157
- setGeo(data) {
158
- this.user.geo = data;
159
+ removeInjectedProperties() {
160
+ this.user.appVersion = null;
161
+ this.user.userId = null;
162
+ this.user.profileId = null;
163
+ this.user.deviceId = null;
164
+ this.user.email = null;
165
+ this.user.custom = { name: null, value: null };
166
+ }
167
+ setUserId(userId) {
168
+ if (!userId)
169
+ this.user.userId = null;
170
+ this.user.userId = userId;
171
+ }
172
+ setDeviceId(deviceId) {
173
+ if (!deviceId)
174
+ this.user.deviceId = null;
175
+ this.user.deviceId = deviceId;
176
+ }
177
+ setProfileId(profileId) {
178
+ if (!profileId)
179
+ this.user.profileId = null;
180
+ this.user.profileId = profileId;
181
+ }
182
+ setEmail(email) {
183
+ if (!email)
184
+ this.user.email = null;
185
+ this.user.email = email;
186
+ }
187
+ setAppVersion(appVersion) {
188
+ if (!appVersion)
189
+ this.user.appVersion = null;
190
+ this.user.appVersion = appVersion;
191
+ }
192
+ setBrowserName(browserName) {
193
+ if (!browserName)
194
+ return;
195
+ this.user.browser.name = browserName;
196
+ }
197
+ setBrowserVersion(browserVersion) {
198
+ if (!browserVersion)
199
+ return;
200
+ this.user.browser.version = browserVersion;
201
+ }
202
+ setOsName(osName) {
203
+ if (!osName)
204
+ return;
205
+ this.user.os.name = osName;
206
+ }
207
+ setOsVersion(osVersion) {
208
+ if (!osVersion)
209
+ return;
210
+ this.user.os.version = osVersion;
211
+ }
212
+ setGeoCountry(country) {
213
+ this.user.geo.country = country;
214
+ }
215
+ setGeoCode(code) {
216
+ this.user.geo.code = code;
217
+ }
218
+ setGeoState(state) {
219
+ this.user.geo.state = state;
220
+ }
221
+ setGeoCity(city) {
222
+ this.user.geo.city = city;
223
+ }
224
+ setGeoIp(ip) {
225
+ this.user.geo.ip = ip;
226
+ }
227
+ setCustomProperty(key, value) {
228
+ if (typeof key !== "string")
229
+ return;
230
+ this.user.custom = { ...this.user.custom, [key]: value };
231
+ }
232
+ removeUserId() {
233
+ this.user.userId = null;
234
+ }
235
+ removeDeviceId() {
236
+ this.user.deviceId = null;
237
+ }
238
+ removeProfileId() {
239
+ this.user.profileId = null;
240
+ }
241
+ removeEmail() {
242
+ this.user.email = null;
243
+ }
244
+ removeAppVersion() {
245
+ this.user.appVersion = null;
246
+ }
247
+ removeBrowserName() {
248
+ this.user.browser.name = null;
249
+ }
250
+ removeBrowserVersion() {
251
+ this.user.browser.version = null;
252
+ }
253
+ removeOsName() {
254
+ this.user.os.name = null;
255
+ }
256
+ removeOsVersion() {
257
+ this.user.os.version = null;
258
+ }
259
+ removeGeoCountry() {
260
+ this.user.geo.country = null;
261
+ }
262
+ removeGeoCode() {
263
+ this.user.geo.code = null;
264
+ }
265
+ removeGeoState() {
266
+ this.user.geo.state = null;
267
+ }
268
+ removeGeoCity() {
269
+ this.user.geo.city = null;
270
+ }
271
+ removeGeoIp() {
272
+ this.user.geo.ip = null;
273
+ }
274
+ removeCustomProperty(key) {
275
+ if (!key || typeof key !== "string")
276
+ return;
277
+ delete this.user.custom[key];
159
278
  }
160
279
  };
161
280
 
@@ -1066,6 +1185,8 @@ function doTypeConversion(type, value) {
1066
1185
  return parseFloat(value);
1067
1186
  case "json":
1068
1187
  try {
1188
+ if (value === "")
1189
+ return JSON.parse("{}");
1069
1190
  return JSON.parse(value);
1070
1191
  } catch (e) {
1071
1192
  console.error(errorTypesInConfig.invalidJson.replace("%value%", value), e);
@@ -1139,7 +1260,7 @@ function generateFilteredList(array, name) {
1139
1260
  }
1140
1261
 
1141
1262
  // package.json
1142
- var version = "3.2.11";
1263
+ var version = "3.3.0";
1143
1264
 
1144
1265
  // src/helpers/sdkVersion.js
1145
1266
  var sdkVersion = version;
@@ -1173,11 +1294,11 @@ var Sigma = class {
1173
1294
  ip: this.userData.ip || null,
1174
1295
  email: this.userData.email || null,
1175
1296
  appVersion: this.userData.appVersion || null,
1176
- custom: this.userData.custom || null,
1297
+ custom: this.userData.custom || {},
1177
1298
  deviceCategory: this.userData.deviceCategory || null,
1178
1299
  browser: this.userData.browser || this.sigmaUserData.getUserBrowser(this.userData.ua),
1179
1300
  os: this.userData.os || this.sigmaUserData.getUserOs(this.userData.ua),
1180
- geo: this.userData.geo || null,
1301
+ geo: this.userData.geo || {},
1181
1302
  domain: this.userData.domain || null,
1182
1303
  url: this.userData.url || null,
1183
1304
  query: this.userData.query || null,
@@ -1271,7 +1392,7 @@ var Sigma = class {
1271
1392
  } else if (this.userData.geo) {
1272
1393
  this.geoCache.set(sigmaGeoData, JSON.stringify(this.userData.geo));
1273
1394
  } else {
1274
- this.geoCache.set(sigmaGeoData, JSON.stringify({ location: "none" }));
1395
+ this.geoCache.set(sigmaGeoData, JSON.stringify({}));
1275
1396
  }
1276
1397
  }
1277
1398
  recordLastUpdateInCache() {
@@ -1297,7 +1418,7 @@ var Sigma = class {
1297
1418
  await this.getUserGeoData();
1298
1419
  } catch {
1299
1420
  if (!this.geoCache.get(sigmaGeoData)) {
1300
- this.geoCache.set(sigmaGeoData, JSON.stringify({ location: "none" }));
1421
+ this.geoCache.set(sigmaGeoData, JSON.stringify({}));
1301
1422
  }
1302
1423
  errorMessages.APIRequestErrorGeoData.token = this.token;
1303
1424
  errorMessages.APIRequestErrorGeoData.userData = JSON.stringify(this.userData);
@@ -1491,8 +1612,8 @@ var Sigma = class {
1491
1612
  checkConditionSignForHash(condition) {
1492
1613
  return signsForHash.includes(condition);
1493
1614
  }
1494
- experimentDefinition(experiment, forcedUserInGroup) {
1495
- if (forcedUserInGroup) {
1615
+ experimentDefinition(experiment, forcedUserInGroup, forcedUser) {
1616
+ if (forcedUserInGroup || forcedUser) {
1496
1617
  return experiment;
1497
1618
  } else if (experiment.targets && experiment.targets.conditions.length > 0 && this.checkTargetConditions(experiment)) {
1498
1619
  return experiment;
@@ -1525,7 +1646,7 @@ var Sigma = class {
1525
1646
  splitById = this.getSplitById(sigmaDataLs.experiments[i]);
1526
1647
  forcedUser = checkForcedList(sigmaDataLs.experiments[i].forced_user_list, splitById);
1527
1648
  groupName = this.findUserInForcedGroup(sigmaDataLs.experiments[i]);
1528
- experiment = this.experimentDefinition(sigmaDataLs.experiments[i], groupName);
1649
+ experiment = this.experimentDefinition(sigmaDataLs.experiments[i], groupName, forcedUser);
1529
1650
  break;
1530
1651
  }
1531
1652
  }
@@ -1610,8 +1731,9 @@ var Sigma = class {
1610
1731
  let layer = null;
1611
1732
  let bounds = [];
1612
1733
  let splitById = this.getSplitById(sigmaDataLs.experiments[i]);
1734
+ let forcedUser = checkForcedList(sigmaDataLs.experiments[i].forced_user_list, splitById);
1613
1735
  let userInGroupExperiment = this.findUserInForcedGroup(sigmaDataLs.experiments[i]);
1614
- let experiment = this.experimentDefinition(sigmaDataLs.experiments[i], userInGroupExperiment);
1736
+ let experiment = this.experimentDefinition(sigmaDataLs.experiments[i], userInGroupExperiment, forcedUser);
1615
1737
  if (experiment) {
1616
1738
  if (checkBoolValue(experiment["layer_id"]) && !userInGroupExperiment) {
1617
1739
  layer = experiment["layer_id"];
@@ -1622,7 +1744,7 @@ var Sigma = class {
1622
1744
  experiment.salt,
1623
1745
  experiment.allocation,
1624
1746
  experiment.groups,
1625
- checkForcedList(experiment.forced_user_list, splitById),
1747
+ forcedUser,
1626
1748
  layer,
1627
1749
  bounds,
1628
1750
  splitById
@@ -1741,6 +1863,166 @@ var Sigma = class {
1741
1863
  }
1742
1864
  return isSuccessRule;
1743
1865
  }
1866
+ clearCacheByKeys(keys) {
1867
+ for (const key in keys) {
1868
+ this.cache.remove(keys[key]);
1869
+ }
1870
+ }
1871
+ clearUserProperties() {
1872
+ this.clearCacheByKeys([
1873
+ sigmaUserId,
1874
+ sigmaDeviceId,
1875
+ sigmaProfileId,
1876
+ sigmaExpiration,
1877
+ sigmaExperiments
1878
+ ]);
1879
+ this.sigmaUserData.removeInjectedProperties();
1880
+ }
1881
+ overwriteGeoCache(key, value) {
1882
+ const geoCache = this.geoCache.parse(sigmaGeoData);
1883
+ geoCache[key] = value;
1884
+ this.geoCache.set(sigmaGeoData, JSON.stringify(geoCache));
1885
+ }
1886
+ editUserProperties() {
1887
+ return {
1888
+ setUserId: (userId) => {
1889
+ this.sigmaUserData.setUserId(userId);
1890
+ this.cache.set(sigmaUserId, userId);
1891
+ return this.editUserProperties();
1892
+ },
1893
+ setDeviceId: (deviceId) => {
1894
+ this.sigmaUserData.setDeviceId(deviceId);
1895
+ this.cache.set(sigmaDeviceId, deviceId);
1896
+ return this.editUserProperties();
1897
+ },
1898
+ setProfileId: (profileId) => {
1899
+ this.sigmaUserData.setProfileId(profileId);
1900
+ this.cache.set(sigmaProfileId, profileId);
1901
+ return this.editUserProperties();
1902
+ },
1903
+ setEmail: (email) => {
1904
+ this.sigmaUserData.setEmail(email);
1905
+ return this.editUserProperties();
1906
+ },
1907
+ setAppVersion: (appVersion) => {
1908
+ this.sigmaUserData.setAppVersion(appVersion);
1909
+ return this.editUserProperties();
1910
+ },
1911
+ setBrowserName: (browserName) => {
1912
+ this.sigmaUserData.setBrowserName(browserName);
1913
+ return this.editUserProperties();
1914
+ },
1915
+ setBrowserVersion: (browserVersion) => {
1916
+ this.sigmaUserData.setBrowserVersion(browserVersion);
1917
+ return this.editUserProperties();
1918
+ },
1919
+ setOsName: (osName) => {
1920
+ this.sigmaUserData.setOsName(osName);
1921
+ return this.editUserProperties();
1922
+ },
1923
+ setOsVersion: (osVersion) => {
1924
+ this.sigmaUserData.setOsVersion(osVersion);
1925
+ return this.editUserProperties();
1926
+ },
1927
+ setGeoCountry: (country) => {
1928
+ this.sigmaUserData.setGeoCountry(country);
1929
+ this.overwriteGeoCache("country", country);
1930
+ return this.editUserProperties();
1931
+ },
1932
+ setGeoCode: (code) => {
1933
+ this.sigmaUserData.setGeoCode(code);
1934
+ this.overwriteGeoCache("code", code);
1935
+ return this.editUserProperties();
1936
+ },
1937
+ setGeoState: (state) => {
1938
+ this.sigmaUserData.setGeoState(state);
1939
+ this.overwriteGeoCache("state", state);
1940
+ return this.editUserProperties();
1941
+ },
1942
+ setGeoCity: (city) => {
1943
+ this.sigmaUserData.setGeoCity(city);
1944
+ this.overwriteGeoCache("city", city);
1945
+ return this.editUserProperties();
1946
+ },
1947
+ setGeoIp: (ip) => {
1948
+ this.sigmaUserData.setGeoIp(ip);
1949
+ this.overwriteGeoCache("ip", ip);
1950
+ return this.editUserProperties();
1951
+ },
1952
+ setCustomProperty: (key, value) => {
1953
+ this.sigmaUserData.setCustomProperty(key, value);
1954
+ return this.editUserProperties();
1955
+ },
1956
+ removeUserId: () => {
1957
+ this.sigmaUserData.removeUserId();
1958
+ this.cache.remove(sigmaUserId);
1959
+ return this.editUserProperties();
1960
+ },
1961
+ removeDeviceId: () => {
1962
+ this.sigmaUserData.removeDeviceId();
1963
+ this.cache.remove(sigmaDeviceId);
1964
+ return this.editUserProperties();
1965
+ },
1966
+ removeProfileId: () => {
1967
+ this.sigmaUserData.removeProfileId();
1968
+ this.cache.remove(sigmaProfileId);
1969
+ return this.editUserProperties();
1970
+ },
1971
+ removeAppVersion: () => {
1972
+ this.sigmaUserData.removeAppVersion();
1973
+ return this.editUserProperties();
1974
+ },
1975
+ removeBrowserName: () => {
1976
+ this.sigmaUserData.removeBrowserName();
1977
+ return this.editUserProperties();
1978
+ },
1979
+ removeBrowserVersion: () => {
1980
+ this.sigmaUserData.removeBrowserVersion();
1981
+ return this.editUserProperties();
1982
+ },
1983
+ removeEmail: () => {
1984
+ this.sigmaUserData.removeEmail();
1985
+ return this.editUserProperties();
1986
+ },
1987
+ removeOsName: () => {
1988
+ this.sigmaUserData.removeOsName();
1989
+ return this.editUserProperties();
1990
+ },
1991
+ removeOsVersion: () => {
1992
+ this.sigmaUserData.removeOsVersion();
1993
+ return this.editUserProperties();
1994
+ },
1995
+ removeGeoCountry: () => {
1996
+ this.sigmaUserData.removeGeoCountry();
1997
+ this.overwriteGeoCache("country", null);
1998
+ return this.editUserProperties();
1999
+ },
2000
+ removeGeoCode: () => {
2001
+ this.sigmaUserData.removeGeoCode();
2002
+ this.overwriteGeoCache("code", null);
2003
+ return this.editUserProperties();
2004
+ },
2005
+ removeGeoState: () => {
2006
+ this.sigmaUserData.removeGeoState();
2007
+ this.overwriteGeoCache("state", null);
2008
+ return this.editUserProperties();
2009
+ },
2010
+ removeGeoCity: () => {
2011
+ this.sigmaUserData.removeGeoCity();
2012
+ this.overwriteGeoCache("city", null);
2013
+ return this.editUserProperties();
2014
+ },
2015
+ removeGeoIp: () => {
2016
+ this.sigmaUserData.removeGeoIp();
2017
+ this.overwriteGeoCache("ip", null);
2018
+ return this.editUserProperties();
2019
+ },
2020
+ removeCustomProperty: (key) => {
2021
+ this.sigmaUserData.removeCustomProperty(key);
2022
+ return this.editUserProperties();
2023
+ }
2024
+ };
2025
+ }
1744
2026
  };
1745
2027
  var sigma_default = Sigma;
1746
2028
  // Annotate the CommonJS export names for ESM import in node: