@envive-ai/react-hooks 0.3.56 → 0.3.57
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/application/commerce-api.cjs +11 -12
- package/dist/application/commerce-api.js +11 -12
- package/dist/application/logging/index.cjs +13 -0
- package/dist/application/logging/index.d.cts +3 -0
- package/dist/application/logging/index.d.ts +3 -0
- package/dist/application/logging/index.js +4 -0
- package/dist/application/logging/logLevel.cjs +123 -0
- package/dist/application/logging/logLevel.d.cts +47 -0
- package/dist/application/logging/logLevel.d.ts +47 -0
- package/dist/application/logging/logLevel.js +115 -0
- package/dist/application/logging/logger.cjs +6 -1
- package/dist/application/logging/logger.d.cts +13 -0
- package/dist/application/logging/logger.d.ts +13 -0
- package/dist/application/logging/logger.js +7 -1
- package/dist/atoms/app/index.d.cts +7 -7
- package/dist/atoms/app/index.d.ts +7 -7
- package/dist/atoms/app/variant.d.cts +6 -6
- package/dist/atoms/app/variant.d.ts +6 -6
- package/dist/atoms/chat/chatState.d.cts +19 -19
- package/dist/atoms/chat/chatState.d.ts +1 -1
- package/dist/atoms/chat/form.d.cts +2 -2
- package/dist/atoms/chat/form.d.ts +2 -2
- package/dist/atoms/chat/index.d.cts +2 -2
- package/dist/atoms/chat/lastMessage.d.cts +2 -2
- package/dist/atoms/chat/lastMessage.d.ts +2 -2
- package/dist/atoms/chat/messageQueue.d.cts +6 -6
- package/dist/atoms/chat/messageQueue.d.ts +6 -6
- package/dist/atoms/chat/performanceMetrics.d.cts +6 -6
- package/dist/atoms/chat/performanceMetrics.d.ts +6 -6
- package/dist/atoms/chat/renderedWidgetRefs.d.cts +2 -2
- package/dist/atoms/chat/renderedWidgetRefs.d.ts +2 -2
- package/dist/atoms/chat/replies.d.cts +3 -3
- package/dist/atoms/chat/suggestions.d.cts +2 -2
- package/dist/atoms/chat/suggestions.d.ts +2 -2
- package/dist/atoms/envive/enviveConfig.d.cts +14 -14
- package/dist/atoms/envive/enviveConfig.d.ts +14 -14
- package/dist/atoms/globalSearch/globalSearch.d.cts +5 -5
- package/dist/atoms/globalSearch/globalSearch.d.ts +5 -5
- package/dist/atoms/org/customerService.d.cts +6 -6
- package/dist/atoms/org/customerService.d.ts +6 -6
- package/dist/atoms/org/graphqlConfig.d.cts +4 -4
- package/dist/atoms/org/graphqlConfig.d.ts +5 -5
- package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
- package/dist/atoms/org/newOrgConfigAtom.d.ts +3 -3
- package/dist/atoms/org/orgAnalyticsConfig.d.ts +5 -5
- package/dist/atoms/search/chatSearch.d.cts +17 -17
- package/dist/atoms/search/chatSearch.d.ts +17 -17
- package/dist/atoms/search/searchAPI.d.cts +13 -13
- package/dist/atoms/search/types.d.ts +1 -1
- package/dist/atoms/widget/chatPreviewLoading.d.cts +2 -2
- package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
- package/dist/contexts/salesAgentContext/salesAgentService.cjs +2 -2
- package/dist/contexts/salesAgentContext/salesAgentService.js +2 -2
- package/dist/contexts/systemSettingsContext/systemSettingsContext.d.ts +2 -2
- package/dist/contexts/types.d.cts +1 -1
- package/dist/contexts/types.d.ts +1 -1
- package/dist/contexts/typesV3.d.cts +1 -1
- package/dist/contexts/typesV3.d.ts +1 -1
- package/dist/hooks/ChatToggle/useChatToggle.cjs +10 -8
- package/dist/hooks/ChatToggle/useChatToggle.d.cts +4 -3
- package/dist/hooks/ChatToggle/useChatToggle.d.ts +4 -3
- package/dist/hooks/ChatToggle/useChatToggle.js +11 -9
- package/dist/hooks/GrabAndScroll/useGrabAndScroll.d.ts +2 -2
- package/dist/hooks/Intersection/useIntersection.cjs +7 -5
- package/dist/hooks/Intersection/useIntersection.js +7 -5
- package/dist/hooks/Search/useSearchInput.cjs +1 -1
- package/dist/hooks/Search/useSearchInput.js +1 -1
- package/dist/hooks/ShopifyUrlOperations/useShopifyUrlOperations.d.cts +2 -2
- package/dist/hooks/ShopifyUrlOperations/useShopifyUrlOperations.d.ts +2 -2
- package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.cjs +8 -6
- package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.js +8 -6
- package/dist/hooks/WidgetInteraction/types.cjs +40 -1
- package/dist/hooks/WidgetInteraction/types.d.cts +16 -2
- package/dist/hooks/WidgetInteraction/types.d.ts +16 -2
- package/dist/hooks/WidgetInteraction/types.js +41 -2
- package/dist/hooks/utils.d.cts +1 -1
- package/dist/hooks/utils.d.ts +1 -1
- package/dist/services/amplitudeService/amplitudeService.cjs +14 -5
- package/dist/services/amplitudeService/amplitudeService.js +14 -5
- package/package.json +5 -1
- package/src/application/__tests__/commerceApiStreaming.test.ts +171 -0
- package/src/application/commerce-api.ts +21 -21
- package/src/application/logging/__tests__/logger.test.ts +159 -0
- package/src/application/logging/index.ts +12 -0
- package/src/application/logging/logLevel.ts +162 -0
- package/src/application/logging/logger.ts +13 -0
- package/src/contexts/salesAgentContext/salesAgentService.ts +1 -1
- package/src/contexts/userIdentityContext/__tests__/userIdentityContext.test.tsx +4 -5
- package/src/hooks/ChatToggle/__tests__/useChatToggle.test.ts +273 -0
- package/src/hooks/ChatToggle/useChatToggle.ts +39 -12
- package/src/hooks/Intersection/useIntersection.ts +7 -4
- package/src/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.ts +8 -5
- package/src/hooks/WidgetInteraction/__tests__/chatTriggerWidget.test.ts +51 -0
- package/src/hooks/WidgetInteraction/types.ts +53 -0
- package/src/services/amplitudeService/__tests__/amplitudeService.test.ts +76 -0
- package/src/services/amplitudeService/amplitudeService.ts +37 -5
|
@@ -19,6 +19,33 @@ export { EnviveMetricsEventName, SpiffyMetricsEventName };
|
|
|
19
19
|
|
|
20
20
|
const logger = new Logger('amplitudeService');
|
|
21
21
|
|
|
22
|
+
// Amplitude's managed BigQuery data can surface supplementary Unicode as U+FFFD.
|
|
23
|
+
// Keep the widget-training payload ASCII-safe without changing the displayed text.
|
|
24
|
+
const UTF8_TRANSPORT_PREFIX = '__spiffy_utf8__:';
|
|
25
|
+
|
|
26
|
+
const containsSupplementaryUnicode = (value: string): boolean =>
|
|
27
|
+
Array.from(value).some(character => (character.codePointAt(0) ?? 0) > 0xffff);
|
|
28
|
+
|
|
29
|
+
const encodeSupplementaryUnicode = (value: unknown): unknown => {
|
|
30
|
+
if (typeof value === 'string') {
|
|
31
|
+
return containsSupplementaryUnicode(value)
|
|
32
|
+
? `${UTF8_TRANSPORT_PREFIX}${encodeURIComponent(value)}`
|
|
33
|
+
: value;
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
return value.map(encodeSupplementaryUnicode);
|
|
37
|
+
}
|
|
38
|
+
if (value !== null && typeof value === 'object') {
|
|
39
|
+
return Object.fromEntries(
|
|
40
|
+
Object.entries(value).map(([key, nestedValue]) => [
|
|
41
|
+
key,
|
|
42
|
+
encodeSupplementaryUnicode(nestedValue),
|
|
43
|
+
]),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
|
|
22
49
|
export interface TrackEventParams {
|
|
23
50
|
eventName: SpiffyMetricsEventName | EnviveMetricsEventName;
|
|
24
51
|
eventProps?: Record<string, unknown>;
|
|
@@ -428,10 +455,15 @@ export class AmplitudeService {
|
|
|
428
455
|
}
|
|
429
456
|
|
|
430
457
|
const mappedEventProps = AmplitudeService.mapEventProps({ eventName, eventProps });
|
|
458
|
+
const amplitudeEventProps =
|
|
459
|
+
eventName === EnviveMetricsEventName.WidgetTextResponse ||
|
|
460
|
+
eventName === EnviveMetricsEventName.WidgetTextClicked
|
|
461
|
+
? (encodeSupplementaryUnicode(mappedEventProps) as Record<string, unknown>)
|
|
462
|
+
: mappedEventProps;
|
|
431
463
|
|
|
432
464
|
const eventData = JSON.stringify({
|
|
433
465
|
eventName,
|
|
434
|
-
eventProps:
|
|
466
|
+
eventProps: amplitudeEventProps,
|
|
435
467
|
created_at: new Date().toISOString(),
|
|
436
468
|
});
|
|
437
469
|
const encoder = new TextEncoder();
|
|
@@ -444,16 +476,16 @@ export class AmplitudeService {
|
|
|
444
476
|
|
|
445
477
|
logger.logDebug(`amplitude tracking ${decoratedEventName}`, null, {
|
|
446
478
|
event_name: decoratedEventName,
|
|
447
|
-
props:
|
|
479
|
+
props: amplitudeEventProps,
|
|
448
480
|
});
|
|
449
481
|
|
|
450
482
|
this.amplitudeClient.track(
|
|
451
483
|
decoratedEventName,
|
|
452
484
|
{
|
|
453
485
|
...this.getDefaultTrackingProps(eventName),
|
|
454
|
-
...
|
|
455
|
-
...(
|
|
456
|
-
? this.eventPropsToPrefixedEventProps(eventName,
|
|
486
|
+
...amplitudeEventProps,
|
|
487
|
+
...(amplitudeEventProps
|
|
488
|
+
? this.eventPropsToPrefixedEventProps(eventName, amplitudeEventProps)
|
|
457
489
|
: {}),
|
|
458
490
|
},
|
|
459
491
|
{
|