@shellapps/experience 1.15.0 → 1.15.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/dist/index.mjs CHANGED
@@ -1807,6 +1807,7 @@ var DataTTracker = class {
1807
1807
  var FeatureFlagClient = class {
1808
1808
  constructor(transport, appId, debug = false) {
1809
1809
  this.profileId = null;
1810
+ this.sessionId = null;
1810
1811
  this.flagCache = /* @__PURE__ */ new Map();
1811
1812
  this.cacheTimeoutMs = 5 * 60 * 1e3;
1812
1813
  // 5 minutes
@@ -1820,9 +1821,17 @@ var FeatureFlagClient = class {
1820
1821
  this.profileId = profileId;
1821
1822
  this.flagCache.clear();
1822
1823
  }
1824
+ setSessionId(sessionId) {
1825
+ this.sessionId = sessionId;
1826
+ }
1827
+ /** Returns profileId if logged in, otherwise sessionId as anonymous identifier */
1828
+ getResolverId() {
1829
+ return this.profileId || this.sessionId || void 0;
1830
+ }
1823
1831
  async fetchFlags() {
1824
1832
  try {
1825
- const flags = await this.transport.fetchFlags(this.appId, this.profileId || void 0);
1833
+ const resolverId = this.getResolverId();
1834
+ const flags = await this.transport.fetchFlags(this.appId, resolverId);
1826
1835
  const now = Date.now();
1827
1836
  for (const [key, value] of Object.entries(flags)) {
1828
1837
  this.flagCache.set(key, {
@@ -1918,8 +1927,9 @@ var FeatureFlagClient = class {
1918
1927
  const baseEndpoint = endpoint || this.transport["config"].endpoint;
1919
1928
  const streamUrl = `${baseEndpoint}/api/v1/flags/${this.appId}/resolve/stream`;
1920
1929
  const url = new URL(streamUrl);
1921
- if (this.profileId) {
1922
- url.searchParams.set("profileId", this.profileId);
1930
+ const resolverId = this.getResolverId();
1931
+ if (resolverId) {
1932
+ url.searchParams.set("profileId", resolverId);
1923
1933
  }
1924
1934
  try {
1925
1935
  this.eventSource = new EventSource(url.toString());
@@ -2351,6 +2361,7 @@ var _Experience = class _Experience {
2351
2361
  this.autoTracker = new AutoTracker(this.batcher, this.sessionManager.getSessionId());
2352
2362
  this.dataTTracker = new DataTTracker(this.batcher, this.sessionManager.getSessionId());
2353
2363
  this.flagClient = new FeatureFlagClient(this.transport, this.config.appId, this.config.debug);
2364
+ this.flagClient.setSessionId(this.sessionManager.getSessionId());
2354
2365
  this.offlineQueue = new OfflineQueue(this.transport, this.config.debug);
2355
2366
  this.setupFailureHandling();
2356
2367
  this.enableFeatures();