mixpanel-browser 2.77.0 → 2.79.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 (68) hide show
  1. package/.claude/settings.local.json +6 -9
  2. package/.eslintrc.json +12 -0
  3. package/.github/workflows/openfeature-provider-tests.yml +31 -0
  4. package/CHANGELOG.md +11 -0
  5. package/build.sh +2 -2
  6. package/dist/async-modules/{mixpanel-recorder-wIWnMDLA.min.js → mixpanel-recorder-D5HJyV2E.min.js} +2 -2
  7. package/dist/async-modules/mixpanel-recorder-D5HJyV2E.min.js.map +1 -0
  8. package/dist/async-modules/{mixpanel-recorder-DLKbUIEE.js → mixpanel-recorder-P6SEnnPV.js} +57 -33
  9. package/dist/async-modules/mixpanel-targeting-1L9FyetZ.min.js +2 -0
  10. package/dist/async-modules/mixpanel-targeting-1L9FyetZ.min.js.map +1 -0
  11. package/dist/async-modules/{mixpanel-targeting-CmVvUyFM.js → mixpanel-targeting-BBMVbgJF.js} +24 -13
  12. package/dist/mixpanel-core.cjs.d.ts +46 -1
  13. package/dist/mixpanel-core.cjs.js +671 -272
  14. package/dist/mixpanel-recorder.js +57 -33
  15. package/dist/mixpanel-recorder.min.js +1 -1
  16. package/dist/mixpanel-recorder.min.js.map +1 -1
  17. package/dist/mixpanel-targeting.js +24 -13
  18. package/dist/mixpanel-targeting.min.js +1 -1
  19. package/dist/mixpanel-targeting.min.js.map +1 -1
  20. package/dist/mixpanel-with-async-modules.cjs.d.ts +46 -1
  21. package/dist/mixpanel-with-async-modules.cjs.js +673 -274
  22. package/dist/mixpanel-with-async-recorder.cjs.d.ts +46 -1
  23. package/dist/mixpanel-with-async-recorder.cjs.js +673 -274
  24. package/dist/mixpanel-with-recorder.d.ts +46 -1
  25. package/dist/mixpanel-with-recorder.js +596 -197
  26. package/dist/mixpanel-with-recorder.min.d.ts +46 -1
  27. package/dist/mixpanel-with-recorder.min.js +1 -1
  28. package/dist/mixpanel.amd.d.ts +46 -1
  29. package/dist/mixpanel.amd.js +596 -197
  30. package/dist/mixpanel.cjs.d.ts +46 -1
  31. package/dist/mixpanel.cjs.js +596 -197
  32. package/dist/mixpanel.globals.js +673 -274
  33. package/dist/mixpanel.min.js +200 -189
  34. package/dist/mixpanel.module.d.ts +46 -1
  35. package/dist/mixpanel.module.js +596 -197
  36. package/dist/mixpanel.umd.d.ts +46 -1
  37. package/dist/mixpanel.umd.js +596 -197
  38. package/package.json +1 -1
  39. package/packages/openfeature-web-provider/README.md +357 -0
  40. package/packages/openfeature-web-provider/package-lock.json +1636 -0
  41. package/packages/openfeature-web-provider/package.json +51 -0
  42. package/packages/openfeature-web-provider/rollup.config.browser.mjs +26 -0
  43. package/packages/openfeature-web-provider/src/MixpanelProvider.ts +302 -0
  44. package/packages/openfeature-web-provider/src/index.ts +1 -0
  45. package/packages/openfeature-web-provider/src/types.ts +72 -0
  46. package/packages/openfeature-web-provider/test/MixpanelProvider.spec.ts +484 -0
  47. package/packages/openfeature-web-provider/tsconfig.json +15 -0
  48. package/src/autocapture/index.js +7 -2
  49. package/src/config.js +1 -1
  50. package/src/flags/CLAUDE.md +24 -0
  51. package/src/flags/flags-persistence.js +176 -0
  52. package/src/flags/index.js +278 -98
  53. package/src/index.d.ts +46 -1
  54. package/src/mixpanel-core.js +27 -8
  55. package/src/recorder/idb-config.js +16 -0
  56. package/src/recorder/recording-registry.js +7 -2
  57. package/src/recorder/session-recording.js +9 -4
  58. package/src/recorder-manager.js +7 -2
  59. package/src/request-queue.js +1 -2
  60. package/src/shared-lock.js +2 -3
  61. package/src/storage/indexed-db.js +16 -15
  62. package/src/storage/local-storage.js +5 -3
  63. package/src/utils.js +25 -12
  64. package/testServer.js +2 -0
  65. package/tsconfig.base.json +9 -0
  66. package/dist/async-modules/mixpanel-recorder-wIWnMDLA.min.js.map +0 -1
  67. package/dist/async-modules/mixpanel-targeting-CTcftSJC.min.js +0 -2
  68. package/dist/async-modules/mixpanel-targeting-CTcftSJC.min.js.map +0 -1
@@ -27,7 +27,7 @@
27
27
  }
28
28
 
29
29
  var Config = {
30
- LIB_VERSION: '2.77.0'
30
+ LIB_VERSION: '2.79.0'
31
31
  };
32
32
 
33
33
  // Window global names for async modules
@@ -1340,7 +1340,8 @@
1340
1340
  if (_localStorageSupported !== null && !forceCheck) {
1341
1341
  return _localStorageSupported;
1342
1342
  }
1343
- return _localStorageSupported = _testStorageSupported(storage || win.localStorage);
1343
+
1344
+ return _localStorageSupported = _testStorageSupported(storage);
1344
1345
  };
1345
1346
 
1346
1347
  var _sessionStorageSupported = null;
@@ -1348,7 +1349,8 @@
1348
1349
  if (_sessionStorageSupported !== null && !forceCheck) {
1349
1350
  return _sessionStorageSupported;
1350
1351
  }
1351
- return _sessionStorageSupported = _testStorageSupported(storage || win.sessionStorage);
1352
+
1353
+ return _sessionStorageSupported = _testStorageSupported(storage);
1352
1354
  };
1353
1355
 
1354
1356
  function _storageWrapper(storage, name, is_supported_fn) {
@@ -1391,17 +1393,26 @@
1391
1393
  };
1392
1394
  }
1393
1395
 
1394
- // Safari errors out accessing localStorage/sessionStorage when cookies are disabled,
1395
- // so create dummy storage wrappers that silently fail as a fallback.
1396
- var windowLocalStorage = null, windowSessionStorage = null;
1397
- try {
1398
- windowLocalStorage = win.localStorage;
1399
- windowSessionStorage = win.sessionStorage;
1400
- // eslint-disable-next-line no-empty
1401
- } catch (_err) {}
1396
+ // Safari and other browsers may error out accessing localStorage/sessionStorage
1397
+ // when cookies are disabled, so wrap access in a try-catch.
1398
+ var getLocalStorage = function() {
1399
+ try {
1400
+ return win.localStorage; // eslint-disable-line no-restricted-properties
1401
+ } catch (_err) {
1402
+ return null;
1403
+ }
1404
+ };
1405
+
1406
+ var getSessionStorage = function() {
1407
+ try {
1408
+ return win.sessionStorage; // eslint-disable-line no-restricted-properties
1409
+ } catch (_err) {
1410
+ return null;
1411
+ }
1412
+ };
1402
1413
 
1403
- _.localStorage = _storageWrapper(windowLocalStorage, 'localStorage', localStorageSupported);
1404
- _.sessionStorage = _storageWrapper(windowSessionStorage, 'sessionStorage', sessionStorageSupported);
1414
+ _.localStorage = _storageWrapper(getLocalStorage(), 'localStorage', localStorageSupported);
1415
+ _.sessionStorage = _storageWrapper(getSessionStorage(), 'sessionStorage', sessionStorageSupported);
1405
1416
 
1406
1417
  _.register_event = (function() {
1407
1418
  // written by Dean Edwards, 2005
@@ -165,8 +165,47 @@ export interface AutocaptureConfig {
165
165
  block_element_callback?: (element: Element, event: Event) => boolean;
166
166
  }
167
167
 
168
+ /**
169
+ * Network-only variant lookup - no persistence. Default behavior.
170
+ */
171
+ export interface NetworkOnlyFlagsPolicy {
172
+ variantLookupPolicy: "networkOnly";
173
+ }
174
+
175
+ /**
176
+ * Network-first variant lookup - prioritizes freshness.
177
+ * Attempts network fetch first, falls back to persisted variants on failure.
178
+ */
179
+ export interface NetworkFirstFlagsPolicy {
180
+ variantLookupPolicy: "networkFirst";
181
+ /**
182
+ * Time-to-live in milliseconds. Persisted variants older than this are discarded.
183
+ * Defaults to 24 hours.
184
+ */
185
+ persistenceTtlMs?: number;
186
+ }
187
+
188
+ /**
189
+ * Serves persisted variants immediately while a network fetch runs in the background.
190
+ * Once the fetch succeeds, its result replaces the cached variants for the rest of the session.
191
+ */
192
+ export interface PersistenceUntilNetworkSuccessFlagsPolicy {
193
+ variantLookupPolicy: "persistenceUntilNetworkSuccess";
194
+ /**
195
+ * Time-to-live in milliseconds. Persisted variants older than this are discarded.
196
+ * Defaults to 24 hours.
197
+ */
198
+ persistenceTtlMs?: number;
199
+ }
200
+
201
+ export type FlagsPersistencePolicy =
202
+ | NetworkOnlyFlagsPolicy
203
+ | NetworkFirstFlagsPolicy
204
+ | PersistenceUntilNetworkSuccessFlagsPolicy;
205
+
168
206
  export interface FlagsConfig {
169
- context: Dict;
207
+ context?: Dict;
208
+ persistence?: FlagsPersistencePolicy;
170
209
  }
171
210
 
172
211
  export interface BeforeSendHookPayload {
@@ -349,6 +388,8 @@ export interface FlagsVariant {
349
388
  experiment_id?: string;
350
389
  is_experiment_active?: boolean;
351
390
  is_qa_tester?: boolean;
391
+ variant_source?: string;
392
+ persisted_at_in_ms?: number;
352
393
  }
353
394
 
354
395
  export interface FlagsUpdateContextOptions {
@@ -357,6 +398,7 @@ export interface FlagsUpdateContextOptions {
357
398
 
358
399
  export interface FlagsManager {
359
400
  are_flags_ready(): boolean;
401
+ load_flags(): Promise<void>;
360
402
  get_variant(
361
403
  featureName: string,
362
404
  fallback: FlagsVariant
@@ -364,12 +406,15 @@ export interface FlagsManager {
364
406
  get_variant_sync(featureName: string, fallback: FlagsVariant): FlagsVariant;
365
407
  get_variant_value(featureName: string, fallbackValue: any): Promise<any>;
366
408
  get_variant_value_sync(featureName: string, fallbackValue: any): any;
409
+ get_all_variants(): Promise<Map<string, FlagsVariant>>;
410
+ get_all_variants_sync(): Map<string, FlagsVariant>;
367
411
  is_enabled(featureName: string, fallbackValue?: boolean): Promise<boolean>;
368
412
  is_enabled_sync(featureName: string, fallbackValue?: boolean): boolean;
369
413
  update_context(
370
414
  context: Dict,
371
415
  options?: FlagsUpdateContextOptions
372
416
  ): Promise<void>;
417
+ when_ready(): Promise<void>;
373
418
  }
374
419
 
375
420
  export interface Mixpanel {