@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 +3 -2
- package/dist/context.d.ts.map +1 -1
- package/dist/index.cjs +32 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +33 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React$1, { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { init } from '@journium/js';
|
|
3
3
|
export * from '@journium/js';
|
|
4
4
|
import { JourniumConfig, JourniumLocalOptions } from '@journium/core';
|
|
5
5
|
|
|
6
|
+
type JourniumAnalyticsInstance = ReturnType<typeof init>;
|
|
6
7
|
interface JourniumContextValue {
|
|
7
|
-
analytics:
|
|
8
|
+
analytics: JourniumAnalyticsInstance | null;
|
|
8
9
|
config: JourniumConfig | null;
|
|
9
10
|
effectiveOptions: JourniumLocalOptions | null;
|
|
10
11
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -448,9 +448,9 @@ const fetchRemoteOptions = async (apiHost, publishableKey, fetchFn) => {
|
|
|
448
448
|
'Content-Type': 'application/json',
|
|
449
449
|
},
|
|
450
450
|
});
|
|
451
|
-
if (!response.ok) {
|
|
452
|
-
|
|
453
|
-
}
|
|
451
|
+
// if (!response.ok) {
|
|
452
|
+
// throw new Error(`Options fetch failed: ${response.status} ${response.statusText}`);
|
|
453
|
+
// }
|
|
454
454
|
const data = await response.json();
|
|
455
455
|
return data;
|
|
456
456
|
}
|
|
@@ -705,18 +705,14 @@ class JourniumClient {
|
|
|
705
705
|
this.flushTimer = null;
|
|
706
706
|
this.initializationComplete = false;
|
|
707
707
|
this.initializationFailed = false;
|
|
708
|
-
this.disabled = false;
|
|
709
708
|
this.optionsChangeCallbacks = new Set();
|
|
710
|
-
// Validate required configuration
|
|
709
|
+
// Validate required configuration
|
|
711
710
|
if (!config.publishableKey || config.publishableKey.trim() === '') {
|
|
712
|
-
|
|
711
|
+
// Reject initialization with clear error
|
|
712
|
+
const errorMsg = 'Journium: publishableKey is required but not provided or is empty. SDK cannot be initialized.';
|
|
713
713
|
Logger.setDebug(true);
|
|
714
|
-
Logger.error(
|
|
715
|
-
|
|
716
|
-
this.config = { publishableKey: '', apiHost: 'https://events.journium.app' };
|
|
717
|
-
this.effectiveOptions = { debug: true };
|
|
718
|
-
this.optionsStorageKey = 'jrnm_invalid_options';
|
|
719
|
-
return;
|
|
714
|
+
Logger.error(errorMsg);
|
|
715
|
+
throw new Error(errorMsg);
|
|
720
716
|
}
|
|
721
717
|
// Set default apiHost if not provided
|
|
722
718
|
this.config = {
|
|
@@ -780,24 +776,23 @@ class JourniumClient {
|
|
|
780
776
|
}
|
|
781
777
|
else {
|
|
782
778
|
// Step 4: Fallback to cached config if fresh fetch failed
|
|
783
|
-
const cachedRemoteOptions = this.loadCachedOptions();
|
|
779
|
+
/* const cachedRemoteOptions = this.loadCachedOptions();
|
|
780
|
+
|
|
784
781
|
if (cachedRemoteOptions) {
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
782
|
+
if (this.config.options) {
|
|
783
|
+
this.effectiveOptions = mergeOptions(this.config.options, cachedRemoteOptions);
|
|
784
|
+
Logger.log('Journium: Fresh config failed, using cached remote config merged with local options:', this.effectiveOptions);
|
|
785
|
+
} else {
|
|
786
|
+
this.effectiveOptions = cachedRemoteOptions;
|
|
787
|
+
Logger.log('Journium: Fresh config failed, using cached remote config:', this.effectiveOptions);
|
|
788
|
+
}
|
|
789
|
+
} else {
|
|
790
|
+
// Step 5: No remote config and no cached config - initialization fails
|
|
791
|
+
Logger.error('Journium: Initialization failed - no remote config available and no cached config found');
|
|
792
|
+
this.initializationFailed = true;
|
|
793
|
+
this.initializationComplete = false;
|
|
794
|
+
return;
|
|
795
|
+
} */
|
|
801
796
|
}
|
|
802
797
|
// Step 6: Update identity manager session timeout if provided
|
|
803
798
|
if (this.effectiveOptions.sessionTimeout) {
|
|
@@ -837,11 +832,15 @@ class JourniumClient {
|
|
|
837
832
|
// Race fetch against timeout
|
|
838
833
|
const fetchPromise = fetchRemoteOptions(this.config.apiHost, this.config.publishableKey);
|
|
839
834
|
const remoteOptionsResponse = await Promise.race([fetchPromise, timeoutPromise]);
|
|
840
|
-
if (remoteOptionsResponse && remoteOptionsResponse.success) {
|
|
835
|
+
if (remoteOptionsResponse && remoteOptionsResponse.status === 'success') {
|
|
841
836
|
Logger.log('Journium: Successfully fetched fresh remote config:', remoteOptionsResponse.config);
|
|
842
|
-
return remoteOptionsResponse.config;
|
|
837
|
+
return remoteOptionsResponse.config || null;
|
|
843
838
|
}
|
|
844
|
-
else {
|
|
839
|
+
else if (remoteOptionsResponse && remoteOptionsResponse.status === 'error' && remoteOptionsResponse.errorCode === 'J_ERR_TENANT_NOT_FOUND') {
|
|
840
|
+
Logger.error('Journium: Invalid publishableKey is being used.');
|
|
841
|
+
return null;
|
|
842
|
+
}
|
|
843
|
+
{
|
|
845
844
|
throw new Error('Remote config fetch unsuccessful');
|
|
846
845
|
}
|
|
847
846
|
}
|
|
@@ -949,11 +948,6 @@ class JourniumClient {
|
|
|
949
948
|
}
|
|
950
949
|
}
|
|
951
950
|
identify(distinctId, attributes = {}) {
|
|
952
|
-
// Don't identify if SDK is not properly configured or disabled
|
|
953
|
-
if (this.disabled || !this.config || !this.config.publishableKey) {
|
|
954
|
-
Logger.warn('Journium: identify() call rejected - SDK not ready or disabled');
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
951
|
// Don't identify if initialization failed
|
|
958
952
|
if (this.initializationFailed) {
|
|
959
953
|
Logger.warn('Journium: identify() call rejected - initialization failed');
|
|
@@ -970,11 +964,6 @@ class JourniumClient {
|
|
|
970
964
|
Logger.log('Journium: User identified', { distinctId, attributes, previousDistinctId });
|
|
971
965
|
}
|
|
972
966
|
reset() {
|
|
973
|
-
// Don't reset if SDK is not properly configured or disabled
|
|
974
|
-
if (this.disabled || !this.config || !this.config.publishableKey) {
|
|
975
|
-
Logger.warn('Journium: reset() call rejected - SDK not ready or disabled');
|
|
976
|
-
return;
|
|
977
|
-
}
|
|
978
967
|
// Don't reset if initialization failed
|
|
979
968
|
if (this.initializationFailed) {
|
|
980
969
|
Logger.warn('Journium: reset() call rejected - initialization failed');
|
|
@@ -985,11 +974,6 @@ class JourniumClient {
|
|
|
985
974
|
Logger.log('Journium: User identity reset');
|
|
986
975
|
}
|
|
987
976
|
track(event, properties = {}) {
|
|
988
|
-
// Don't track if SDK is not properly configured or disabled
|
|
989
|
-
if (this.disabled || !this.config || !this.config.publishableKey) {
|
|
990
|
-
Logger.warn('Journium: track() call rejected - SDK not ready or disabled');
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
977
|
// Create minimal event without identity properties (will be added later if staging)
|
|
994
978
|
const journiumEvent = {
|
|
995
979
|
uuid: generateUuidv7(),
|
|
@@ -1041,10 +1025,6 @@ class JourniumClient {
|
|
|
1041
1025
|
}
|
|
1042
1026
|
}
|
|
1043
1027
|
async flush() {
|
|
1044
|
-
// Don't flush if SDK is not properly configured
|
|
1045
|
-
if (!this.config || !this.config.publishableKey) {
|
|
1046
|
-
return;
|
|
1047
|
-
}
|
|
1048
1028
|
// Don't flush if initialization failed
|
|
1049
1029
|
if (this.initializationFailed) {
|
|
1050
1030
|
Logger.warn('Journium: flush() call rejected - initialization failed');
|
|
@@ -1672,7 +1652,7 @@ const JourniumProvider = ({ children, config, }) => {
|
|
|
1672
1652
|
const [analytics, setAnalytics] = useState(null);
|
|
1673
1653
|
const [effectiveOptions, setEffectiveOptions] = useState(null);
|
|
1674
1654
|
useEffect(() => {
|
|
1675
|
-
const analyticsInstance =
|
|
1655
|
+
const analyticsInstance = init(config);
|
|
1676
1656
|
// Get initial effective options (may be empty during remote-first initialization)
|
|
1677
1657
|
const initialEffective = analyticsInstance.getEffectiveOptions();
|
|
1678
1658
|
setEffectiveOptions(initialEffective);
|
|
@@ -1756,5 +1736,5 @@ const useAutocapture = () => {
|
|
|
1756
1736
|
return { startAutocapture, stopAutocapture };
|
|
1757
1737
|
};
|
|
1758
1738
|
|
|
1759
|
-
export { AutocaptureTracker, BrowserIdentityManager,
|
|
1739
|
+
export { AutocaptureTracker, BrowserIdentityManager, JourniumClient, JourniumProvider, Logger, PageviewTracker, fetchRemoteOptions, generateId, generateUuidv7, getCurrentTimestamp, getCurrentUrl, getPageTitle, getReferrer, init, isBrowser, isNode, mergeOptions, useAutoTrackPageview, useAutocapture, useIdentify, useJournium, useReset, useTrackEvent, useTrackPageview };
|
|
1760
1740
|
//# sourceMappingURL=index.mjs.map
|