@envive-ai/react-hooks 0.3.63 → 0.3.64

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 (92) hide show
  1. package/dist/application/models/featureGates.cjs +2 -1
  2. package/dist/application/models/featureGates.d.cts +2 -1
  3. package/dist/application/models/featureGates.d.ts +2 -1
  4. package/dist/application/models/featureGates.js +2 -1
  5. package/dist/application/utils/elementObserver.d.cts +2 -2
  6. package/dist/atoms/app/index.d.cts +7 -7
  7. package/dist/atoms/app/variant.d.cts +6 -6
  8. package/dist/atoms/chat/chatState.d.cts +19 -19
  9. package/dist/atoms/chat/chatState.d.ts +19 -19
  10. package/dist/atoms/chat/form.d.cts +2 -2
  11. package/dist/atoms/chat/form.d.ts +2 -2
  12. package/dist/atoms/chat/index.d.cts +2 -2
  13. package/dist/atoms/chat/index.d.ts +3 -3
  14. package/dist/atoms/chat/lastMessage.d.cts +2 -2
  15. package/dist/atoms/chat/lastMessage.d.ts +2 -2
  16. package/dist/atoms/chat/messageQueue.d.cts +7 -7
  17. package/dist/atoms/chat/messageQueue.d.ts +6 -6
  18. package/dist/atoms/chat/performanceMetrics.d.cts +6 -6
  19. package/dist/atoms/chat/performanceMetrics.d.ts +6 -6
  20. package/dist/atoms/chat/renderedWidgetRefs.d.cts +3 -3
  21. package/dist/atoms/chat/renderedWidgetRefs.d.ts +2 -2
  22. package/dist/atoms/chat/replies.d.cts +3 -3
  23. package/dist/atoms/chat/replies.d.ts +3 -3
  24. package/dist/atoms/chat/suggestions.d.cts +3 -3
  25. package/dist/atoms/chat/suggestions.d.ts +2 -2
  26. package/dist/atoms/envive/enviveConfig.d.cts +14 -14
  27. package/dist/atoms/envive/enviveConfig.d.ts +14 -14
  28. package/dist/atoms/globalSearch/globalSearch.d.cts +5 -5
  29. package/dist/atoms/globalSearch/globalSearch.d.ts +5 -5
  30. package/dist/atoms/org/customerService.d.cts +6 -6
  31. package/dist/atoms/org/customerService.d.ts +6 -6
  32. package/dist/atoms/org/graphqlConfig.d.cts +4 -4
  33. package/dist/atoms/org/graphqlConfig.d.ts +4 -4
  34. package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
  35. package/dist/atoms/org/newOrgConfigAtom.d.ts +2 -2
  36. package/dist/atoms/org/orgAnalyticsConfig.d.cts +4 -4
  37. package/dist/atoms/org/orgAnalyticsConfig.d.ts +4 -4
  38. package/dist/atoms/search/chatSearch.d.cts +17 -17
  39. package/dist/atoms/search/chatSearch.d.ts +17 -17
  40. package/dist/atoms/search/searchAPI.d.cts +13 -13
  41. package/dist/atoms/search/searchAPI.d.ts +13 -13
  42. package/dist/atoms/search/types.d.cts +1 -1
  43. package/dist/atoms/search/utils.d.cts +1 -1
  44. package/dist/atoms/widget/chatPreviewLoading.d.cts +2 -2
  45. package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
  46. package/dist/contexts/systemSettingsContext/systemSettingsContext.d.cts +2 -2
  47. package/dist/contexts/types.d.cts +1 -1
  48. package/dist/contexts/types.d.ts +1 -1
  49. package/dist/contexts/typesV3.d.cts +1 -1
  50. package/dist/contexts/typesV3.d.ts +1 -1
  51. package/dist/hooks/GrabAndScroll/useGrabAndScroll.d.cts +2 -2
  52. package/dist/hooks/Intersection/useIntersection.cjs +9 -2
  53. package/dist/hooks/Intersection/useIntersection.d.cts +2 -2
  54. package/dist/hooks/Intersection/useIntersection.d.ts +2 -2
  55. package/dist/hooks/Intersection/useIntersection.js +9 -2
  56. package/dist/hooks/SystemSettingsContext/useSystemSettingsContext.d.cts +2 -2
  57. package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.cjs +12 -3
  58. package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.d.cts +2 -1
  59. package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.d.ts +2 -1
  60. package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.js +13 -4
  61. package/dist/hooks/WidgetLoadDiagnostics/index.cjs +4 -0
  62. package/dist/hooks/WidgetLoadDiagnostics/index.d.cts +2 -0
  63. package/dist/hooks/WidgetLoadDiagnostics/index.d.ts +2 -0
  64. package/dist/hooks/WidgetLoadDiagnostics/index.js +3 -0
  65. package/dist/hooks/WidgetLoadDiagnostics/useWidgetLoadDiagnostics.cjs +122 -0
  66. package/dist/hooks/WidgetLoadDiagnostics/useWidgetLoadDiagnostics.d.cts +48 -0
  67. package/dist/hooks/WidgetLoadDiagnostics/useWidgetLoadDiagnostics.d.ts +48 -0
  68. package/dist/hooks/WidgetLoadDiagnostics/useWidgetLoadDiagnostics.js +120 -0
  69. package/dist/hooks/utils.d.cts +1 -1
  70. package/dist/hooks/utils.d.ts +1 -1
  71. package/dist/services/amplitudeService/eventNames.cjs +2 -1
  72. package/dist/services/amplitudeService/eventNames.d.cts +2 -1
  73. package/dist/services/amplitudeService/eventNames.d.ts +2 -1
  74. package/dist/services/amplitudeService/eventNames.js +2 -1
  75. package/dist/services/ga4ProjectionService/ga4EventSchema.cjs +3 -2
  76. package/dist/services/ga4ProjectionService/ga4EventSchema.js +3 -2
  77. package/dist/services/hardcopyService/hardcopyService.cjs +12 -3
  78. package/dist/services/hardcopyService/hardcopyService.d.cts +3 -1
  79. package/dist/services/hardcopyService/hardcopyService.d.ts +3 -1
  80. package/dist/services/hardcopyService/hardcopyService.js +12 -3
  81. package/package.json +5 -1
  82. package/src/application/models/featureGates.ts +6 -0
  83. package/src/hooks/Intersection/useIntersection.ts +11 -0
  84. package/src/hooks/TrackComponentVisibleEvent/__tests__/useTrackComponentVisibleEvent.test.tsx +64 -0
  85. package/src/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.ts +23 -4
  86. package/src/hooks/WidgetLoadDiagnostics/__tests__/useWidgetLoadDiagnostics.test.ts +161 -0
  87. package/src/hooks/WidgetLoadDiagnostics/index.ts +5 -0
  88. package/src/hooks/WidgetLoadDiagnostics/useWidgetLoadDiagnostics.ts +178 -0
  89. package/src/services/amplitudeService/eventNames.ts +4 -0
  90. package/src/services/ga4ProjectionService/ga4EventSchema.ts +5 -0
  91. package/src/services/hardcopyService/__tests__/hardcopyService.test.ts +16 -5
  92. package/src/services/hardcopyService/hardcopyService.ts +10 -2
@@ -48,4 +48,8 @@ export enum EnviveMetricsEventName {
48
48
  WidgetTextRequest = 'Widget Text Request',
49
49
  WidgetTextResponse = 'Widget Text Response',
50
50
  WidgetTextClicked = 'Widget Text Clicked',
51
+ // Operational diagnostics for widget loading (see useWidgetLoadDiagnostics). A single event
52
+ // with a `type` discriminator (widget_mounted | widget_load_outcome | widget_load_stalled)
53
+ // so eng can measure the layered load net and, crucially, the negative space between layers.
54
+ Diagnostics = 'Diagnostics',
51
55
  }
@@ -156,4 +156,9 @@ export const GA4_EVENT_SCHEMA: Record<EnviveMetricsEventName, GA4EventSchemaEntr
156
156
  [EnviveMetricsEventName.WidgetTextClicked]: {
157
157
  gaEventName: null,
158
158
  },
159
+
160
+ // Internal eng operational monitoring — never projected to merchant GA4.
161
+ [EnviveMetricsEventName.Diagnostics]: {
162
+ gaEventName: null,
163
+ },
159
164
  };
@@ -92,6 +92,7 @@ describe('HardcopyService', () => {
92
92
  titleLabel: 'Hello World',
93
93
  promptButtonTexts: ['Prompt 1', 'Prompt 2'],
94
94
  },
95
+ servedFrom: 'api',
95
96
  });
96
97
  });
97
98
 
@@ -383,7 +384,11 @@ describe('HardcopyService', () => {
383
384
  userEvent: {} as any,
384
385
  });
385
386
 
386
- expect(result).toBe(MOCK_HARDCOPY_RESPONSE[WidgetTypeV3.PromptCarouselV3]);
387
+ expect(result).toEqual({
388
+ ...MOCK_HARDCOPY_RESPONSE[WidgetTypeV3.PromptCarouselV3],
389
+ servedFrom: 'static',
390
+ fallbackReason: 'error',
391
+ });
387
392
  });
388
393
 
389
394
  it('returns the MOCK_HARDCOPY_RESPONSE entry when the API returns falsy', async () => {
@@ -394,7 +399,11 @@ describe('HardcopyService', () => {
394
399
  userEvent: {} as any,
395
400
  });
396
401
 
397
- expect(result).toBe(MOCK_HARDCOPY_RESPONSE[WidgetTypeV3.SocialProofV3]);
402
+ expect(result).toEqual({
403
+ ...MOCK_HARDCOPY_RESPONSE[WidgetTypeV3.SocialProofV3],
404
+ servedFrom: 'static',
405
+ fallbackReason: 'error',
406
+ });
398
407
  });
399
408
 
400
409
  it('does not fire WidgetTextResponse when falling back to mock', async () => {
@@ -437,9 +446,11 @@ describe('HardcopyService', () => {
437
446
 
438
447
  await vi.advanceTimersByTimeAsync(HARDCOPY_TIMEOUT_MS);
439
448
 
440
- await expect(resultPromise).resolves.toBe(
441
- MOCK_HARDCOPY_RESPONSE[WidgetTypeV3.PromptCarouselV3],
442
- );
449
+ await expect(resultPromise).resolves.toEqual({
450
+ ...MOCK_HARDCOPY_RESPONSE[WidgetTypeV3.PromptCarouselV3],
451
+ servedFrom: 'static',
452
+ fallbackReason: 'timeout',
453
+ });
443
454
  } finally {
444
455
  vi.useRealTimers();
445
456
  }
@@ -49,6 +49,10 @@ export type HardcopyResponse = {
49
49
  language: string;
50
50
  rawValues?: Record<string, WidgetString | WidgetString[]>;
51
51
  values: Record<string, string | string[]>;
52
+ // How the copy was served, for widget-load diagnostics: 'api' = live backend response,
53
+ // 'static' = fell back to the bundled MOCK_HARDCOPY_RESPONSE after a backend error or timeout.
54
+ servedFrom?: 'api' | 'static';
55
+ fallbackReason?: 'timeout' | 'error';
52
56
  };
53
57
 
54
58
  export interface IHardcopyService {
@@ -265,6 +269,8 @@ export class HardcopyService implements IHardcopyService {
265
269
  },
266
270
  });
267
271
 
272
+ // Reason the API path failed, surfaced on the static fallback for widget-load diagnostics.
273
+ let fallbackReason: 'timeout' | 'error' | undefined;
268
274
  try {
269
275
  const response = await withTimeout(
270
276
  CommerceApiClient.getHardcopy(widgetTextRequest),
@@ -287,16 +293,18 @@ export class HardcopyService implements IHardcopyService {
287
293
  : {}),
288
294
  },
289
295
  });
290
- return convertedResponse;
296
+ return { ...convertedResponse, servedFrom: 'api' };
291
297
  }
292
298
  } catch (error) {
293
299
  logger.logError('error getting hardcopy from backend', error);
300
+ fallbackReason =
301
+ error instanceof Error && error.message.includes('timed out') ? 'timeout' : 'error';
294
302
  }
295
303
 
296
304
  const mockResponse = MOCK_HARDCOPY_RESPONSE[request.widgetType];
297
305
  if (mockResponse) {
298
306
  logger.logDebug('no real response, using mock', mockResponse);
299
- return mockResponse;
307
+ return { ...mockResponse, servedFrom: 'static', fallbackReason: fallbackReason ?? 'error' };
300
308
  }
301
309
  throw new Error(`No hardcopy response found for widget type: ${request.widgetType}`);
302
310
  }