@journium/react 1.1.0 → 1.1.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/context.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import React, { ReactNode } from 'react';
2
- import { JourniumAnalytics } from '@journium/js';
2
+ import { init } from '@journium/js';
3
3
  import { JourniumConfig, JourniumLocalOptions } from '@journium/core';
4
+ type JourniumAnalyticsInstance = ReturnType<typeof init>;
4
5
  interface JourniumContextValue {
5
- analytics: JourniumAnalytics | null;
6
+ analytics: JourniumAnalyticsInstance | null;
6
7
  config: JourniumConfig | null;
7
8
  effectiveOptions: JourniumLocalOptions | null;
8
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAkD,SAAS,EAAE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtE,UAAU,oBAAoB;IAC5B,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,gBAAgB,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC/C;AAID,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAuC5D,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,oBAM9B,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAkD,SAAS,EAAE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtE,KAAK,yBAAyB,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AAEzD,UAAU,oBAAoB;IAC5B,SAAS,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC5C,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,gBAAgB,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC/C;AAID,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAuC5D,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,oBAM9B,CAAC"}
package/dist/index.cjs CHANGED
@@ -450,9 +450,9 @@ const fetchRemoteOptions = async (apiHost, publishableKey, fetchFn) => {
450
450
  'Content-Type': 'application/json',
451
451
  },
452
452
  });
453
- if (!response.ok) {
454
- throw new Error(`Options fetch failed: ${response.status} ${response.statusText}`);
455
- }
453
+ // if (!response.ok) {
454
+ // throw new Error(`Options fetch failed: ${response.status} ${response.statusText}`);
455
+ // }
456
456
  const data = await response.json();
457
457
  return data;
458
458
  }
@@ -707,18 +707,14 @@ class JourniumClient {
707
707
  this.flushTimer = null;
708
708
  this.initializationComplete = false;
709
709
  this.initializationFailed = false;
710
- this.disabled = false;
711
710
  this.optionsChangeCallbacks = new Set();
712
- // Validate required configuration - put in disabled state if invalid
711
+ // Validate required configuration
713
712
  if (!config.publishableKey || config.publishableKey.trim() === '') {
714
- this.disabled = true;
713
+ // Reject initialization with clear error
714
+ const errorMsg = 'Journium: publishableKey is required but not provided or is empty. SDK cannot be initialized.';
715
715
  Logger.setDebug(true);
716
- Logger.error('Journium: publishableKey is required but not provided or is empty. SDK will not function.');
717
- // Create minimal config to prevent crashes
718
- this.config = { publishableKey: '', apiHost: 'https://events.journium.app' };
719
- this.effectiveOptions = { debug: true };
720
- this.optionsStorageKey = 'jrnm_invalid_options';
721
- return;
716
+ Logger.error(errorMsg);
717
+ throw new Error(errorMsg);
722
718
  }
723
719
  // Set default apiHost if not provided
724
720
  this.config = {
@@ -782,24 +778,23 @@ class JourniumClient {
782
778
  }
783
779
  else {
784
780
  // Step 4: Fallback to cached config if fresh fetch failed
785
- const cachedRemoteOptions = this.loadCachedOptions();
781
+ /* const cachedRemoteOptions = this.loadCachedOptions();
782
+
786
783
  if (cachedRemoteOptions) {
787
- if (this.config.options) {
788
- this.effectiveOptions = mergeOptions(this.config.options, cachedRemoteOptions);
789
- Logger.log('Journium: Fresh config failed, using cached remote config merged with local options:', this.effectiveOptions);
790
- }
791
- else {
792
- this.effectiveOptions = cachedRemoteOptions;
793
- Logger.log('Journium: Fresh config failed, using cached remote config:', this.effectiveOptions);
794
- }
795
- }
796
- else {
797
- // Step 5: No remote config and no cached config - initialization fails
798
- Logger.error('Journium: Initialization failed - no remote config available and no cached config found');
799
- this.initializationFailed = true;
800
- this.initializationComplete = false;
801
- return;
802
- }
784
+ if (this.config.options) {
785
+ this.effectiveOptions = mergeOptions(this.config.options, cachedRemoteOptions);
786
+ Logger.log('Journium: Fresh config failed, using cached remote config merged with local options:', this.effectiveOptions);
787
+ } else {
788
+ this.effectiveOptions = cachedRemoteOptions;
789
+ Logger.log('Journium: Fresh config failed, using cached remote config:', this.effectiveOptions);
790
+ }
791
+ } else {
792
+ // Step 5: No remote config and no cached config - initialization fails
793
+ Logger.error('Journium: Initialization failed - no remote config available and no cached config found');
794
+ this.initializationFailed = true;
795
+ this.initializationComplete = false;
796
+ return;
797
+ } */
803
798
  }
804
799
  // Step 6: Update identity manager session timeout if provided
805
800
  if (this.effectiveOptions.sessionTimeout) {
@@ -839,11 +834,15 @@ class JourniumClient {
839
834
  // Race fetch against timeout
840
835
  const fetchPromise = fetchRemoteOptions(this.config.apiHost, this.config.publishableKey);
841
836
  const remoteOptionsResponse = await Promise.race([fetchPromise, timeoutPromise]);
842
- if (remoteOptionsResponse && remoteOptionsResponse.success) {
837
+ if (remoteOptionsResponse && remoteOptionsResponse.status === 'success') {
843
838
  Logger.log('Journium: Successfully fetched fresh remote config:', remoteOptionsResponse.config);
844
- return remoteOptionsResponse.config;
839
+ return remoteOptionsResponse.config || null;
845
840
  }
846
- else {
841
+ else if (remoteOptionsResponse && remoteOptionsResponse.status === 'error' && remoteOptionsResponse.errorCode === 'J_ERR_TENANT_NOT_FOUND') {
842
+ Logger.error('Journium: Invalid publishableKey is being used.');
843
+ return null;
844
+ }
845
+ {
847
846
  throw new Error('Remote config fetch unsuccessful');
848
847
  }
849
848
  }
@@ -951,11 +950,6 @@ class JourniumClient {
951
950
  }
952
951
  }
953
952
  identify(distinctId, attributes = {}) {
954
- // Don't identify if SDK is not properly configured or disabled
955
- if (this.disabled || !this.config || !this.config.publishableKey) {
956
- Logger.warn('Journium: identify() call rejected - SDK not ready or disabled');
957
- return;
958
- }
959
953
  // Don't identify if initialization failed
960
954
  if (this.initializationFailed) {
961
955
  Logger.warn('Journium: identify() call rejected - initialization failed');
@@ -972,11 +966,6 @@ class JourniumClient {
972
966
  Logger.log('Journium: User identified', { distinctId, attributes, previousDistinctId });
973
967
  }
974
968
  reset() {
975
- // Don't reset if SDK is not properly configured or disabled
976
- if (this.disabled || !this.config || !this.config.publishableKey) {
977
- Logger.warn('Journium: reset() call rejected - SDK not ready or disabled');
978
- return;
979
- }
980
969
  // Don't reset if initialization failed
981
970
  if (this.initializationFailed) {
982
971
  Logger.warn('Journium: reset() call rejected - initialization failed');
@@ -987,11 +976,6 @@ class JourniumClient {
987
976
  Logger.log('Journium: User identity reset');
988
977
  }
989
978
  track(event, properties = {}) {
990
- // Don't track if SDK is not properly configured or disabled
991
- if (this.disabled || !this.config || !this.config.publishableKey) {
992
- Logger.warn('Journium: track() call rejected - SDK not ready or disabled');
993
- return;
994
- }
995
979
  // Create minimal event without identity properties (will be added later if staging)
996
980
  const journiumEvent = {
997
981
  uuid: generateUuidv7(),
@@ -1043,10 +1027,6 @@ class JourniumClient {
1043
1027
  }
1044
1028
  }
1045
1029
  async flush() {
1046
- // Don't flush if SDK is not properly configured
1047
- if (!this.config || !this.config.publishableKey) {
1048
- return;
1049
- }
1050
1030
  // Don't flush if initialization failed
1051
1031
  if (this.initializationFailed) {
1052
1032
  Logger.warn('Journium: flush() call rejected - initialization failed');
@@ -1674,7 +1654,7 @@ const JourniumProvider = ({ children, config, }) => {
1674
1654
  const [analytics, setAnalytics] = React.useState(null);
1675
1655
  const [effectiveOptions, setEffectiveOptions] = React.useState(null);
1676
1656
  React.useEffect(() => {
1677
- const analyticsInstance = new JourniumAnalytics(config);
1657
+ const analyticsInstance = init(config);
1678
1658
  // Get initial effective options (may be empty during remote-first initialization)
1679
1659
  const initialEffective = analyticsInstance.getEffectiveOptions();
1680
1660
  setEffectiveOptions(initialEffective);
@@ -1760,7 +1740,6 @@ const useAutocapture = () => {
1760
1740
 
1761
1741
  exports.AutocaptureTracker = AutocaptureTracker;
1762
1742
  exports.BrowserIdentityManager = BrowserIdentityManager;
1763
- exports.JourniumAnalytics = JourniumAnalytics;
1764
1743
  exports.JourniumClient = JourniumClient;
1765
1744
  exports.JourniumProvider = JourniumProvider;
1766
1745
  exports.Logger = Logger;