@envive-ai/react-hooks 0.3.58 → 0.3.60

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 (104) hide show
  1. package/dist/application/commerce-api.cjs +1 -1
  2. package/dist/application/commerce-api.js +1 -1
  3. package/dist/application/models/graphql/index.cjs +0 -4
  4. package/dist/application/models/graphql/index.d.cts +2 -3
  5. package/dist/application/models/graphql/index.d.ts +2 -3
  6. package/dist/application/models/graphql/index.js +1 -3
  7. package/dist/application/models/graphql/queries/getMerchantColorsQuery.d.cts +2 -3
  8. package/dist/application/models/graphql/queries/getMerchantColorsQuery.d.ts +2 -3
  9. package/dist/application/models/graphql/queries/getWidgetConfigQuery.cjs +22 -3
  10. package/dist/application/models/graphql/queries/getWidgetConfigQuery.js +22 -3
  11. package/dist/application/models/index.cjs +0 -4
  12. package/dist/application/models/index.d.cts +2 -3
  13. package/dist/application/models/index.d.ts +2 -3
  14. package/dist/application/models/index.js +1 -3
  15. package/dist/application/utils/index.cjs +1 -1
  16. package/dist/application/utils/index.js +1 -1
  17. package/dist/atoms/app/index.d.cts +7 -7
  18. package/dist/atoms/app/index.d.ts +7 -7
  19. package/dist/atoms/chat/chatState.d.cts +19 -19
  20. package/dist/atoms/chat/chatState.d.ts +19 -19
  21. package/dist/atoms/chat/form.d.cts +2 -2
  22. package/dist/atoms/chat/form.d.ts +2 -2
  23. package/dist/atoms/chat/index.d.cts +2 -2
  24. package/dist/atoms/chat/lastMessage.d.cts +2 -2
  25. package/dist/atoms/chat/lastMessage.d.ts +2 -2
  26. package/dist/atoms/chat/messageQueue.d.cts +6 -6
  27. package/dist/atoms/chat/messageQueue.d.ts +6 -6
  28. package/dist/atoms/chat/performanceMetrics.d.cts +6 -6
  29. package/dist/atoms/chat/performanceMetrics.d.ts +6 -6
  30. package/dist/atoms/chat/renderedWidgetRefs.d.cts +2 -2
  31. package/dist/atoms/chat/renderedWidgetRefs.d.ts +2 -2
  32. package/dist/atoms/chat/replies.d.cts +3 -3
  33. package/dist/atoms/chat/replies.d.ts +3 -3
  34. package/dist/atoms/chat/suggestions.d.cts +2 -2
  35. package/dist/atoms/chat/suggestions.d.ts +2 -2
  36. package/dist/atoms/envive/enviveConfig.d.cts +13 -13
  37. package/dist/atoms/envive/enviveConfig.d.ts +14 -14
  38. package/dist/atoms/globalSearch/globalSearch.d.cts +5 -5
  39. package/dist/atoms/globalSearch/globalSearch.d.ts +5 -5
  40. package/dist/atoms/org/customerService.d.cts +6 -6
  41. package/dist/atoms/org/customerService.d.ts +6 -6
  42. package/dist/atoms/org/graphqlConfig.d.cts +4 -4
  43. package/dist/atoms/org/graphqlConfig.d.ts +4 -4
  44. package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
  45. package/dist/atoms/org/newOrgConfigAtom.d.ts +2 -2
  46. package/dist/atoms/org/orgAnalyticsConfig.d.cts +4 -4
  47. package/dist/atoms/org/orgAnalyticsConfig.d.ts +4 -4
  48. package/dist/atoms/search/chatSearch.d.cts +17 -17
  49. package/dist/atoms/search/chatSearch.d.ts +17 -17
  50. package/dist/atoms/search/searchAPI.d.cts +13 -13
  51. package/dist/atoms/search/searchAPI.d.ts +13 -13
  52. package/dist/atoms/search/types.d.cts +1 -1
  53. package/dist/atoms/widget/chatPreviewLoading.d.cts +2 -2
  54. package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
  55. package/dist/contexts/pageContext/pageContext.cjs +1 -1
  56. package/dist/contexts/pageContext/pageContext.js +1 -1
  57. package/dist/contexts/types.d.cts +1 -1
  58. package/dist/contexts/types.d.ts +1 -1
  59. package/dist/contexts/typesV3.cjs +1 -1
  60. package/dist/contexts/typesV3.d.cts +8 -1
  61. package/dist/contexts/typesV3.d.ts +8 -1
  62. package/dist/contexts/typesV3.js +1 -1
  63. package/dist/contexts/widgetConfigContext/widgetConfigContext.cjs +22 -31
  64. package/dist/contexts/widgetConfigContext/widgetConfigContext.js +22 -31
  65. package/dist/hooks/Intersection/useIntersection.cjs +14 -3
  66. package/dist/hooks/Intersection/useIntersection.js +14 -3
  67. package/dist/hooks/PageViewedEvent/usePageViewedEvent.cjs +1 -1
  68. package/dist/hooks/PageViewedEvent/usePageViewedEvent.js +1 -1
  69. package/dist/hooks/utils.d.cts +1 -1
  70. package/dist/hooks/utils.d.ts +1 -1
  71. package/dist/services/enviveConfigService/enviveConfigService.cjs +3 -24
  72. package/dist/services/enviveConfigService/enviveConfigService.js +4 -25
  73. package/dist/services/enviveConfigService/fetchGraphQLConfig.cjs +59 -54
  74. package/dist/services/enviveConfigService/fetchGraphQLConfig.js +60 -54
  75. package/dist/services/hardcopyService/hardcopyService.cjs +1 -1
  76. package/dist/services/hardcopyService/hardcopyService.js +1 -1
  77. package/dist/types/config-versions.cjs +1 -3
  78. package/dist/types/config-versions.js +2 -3
  79. package/package.json +1 -1
  80. package/src/application/models/graphql/index.ts +0 -1
  81. package/src/application/models/graphql/queries/getMerchantColorsQuery.ts +4 -15
  82. package/src/application/models/graphql/queries/getWidgetConfigQuery.ts +35 -14
  83. package/src/application/models/index.ts +0 -1
  84. package/src/contexts/pageContext/__tests__/pageContext.test.tsx +1 -2
  85. package/src/contexts/pageContext/pageContext.tsx +1 -2
  86. package/src/contexts/typesV3.ts +7 -0
  87. package/src/contexts/widgetConfigContext/__tests__/widgetConfigContext.test.tsx +52 -0
  88. package/src/contexts/widgetConfigContext/widgetConfigContext.tsx +39 -36
  89. package/src/hooks/Intersection/__tests__/useIntersection.test.ts +134 -0
  90. package/src/hooks/Intersection/useIntersection.ts +20 -4
  91. package/src/services/enviveConfigService/__tests__/enviveConfigService.test.ts +51 -75
  92. package/src/services/enviveConfigService/__tests__/fetchGraphQLConfig.test.ts +242 -90
  93. package/src/services/enviveConfigService/enviveConfigService.ts +15 -41
  94. package/src/services/enviveConfigService/fetchGraphQLConfig.ts +106 -68
  95. package/dist/application/models/graphql/queries/getColorsAndFrontendQuery.cjs +0 -18
  96. package/dist/application/models/graphql/queries/getColorsAndFrontendQuery.js +0 -18
  97. package/dist/application/models/graphql/queries/getMerchantColorsQuery.cjs +0 -18
  98. package/dist/application/models/graphql/queries/getMerchantColorsQuery.js +0 -18
  99. package/dist/application/models/graphql/queries/getMerchantFrontendConfigQuery.cjs +0 -18
  100. package/dist/application/models/graphql/queries/getMerchantFrontendConfigQuery.d.cts +0 -75
  101. package/dist/application/models/graphql/queries/getMerchantFrontendConfigQuery.d.ts +0 -75
  102. package/dist/application/models/graphql/queries/getMerchantFrontendConfigQuery.js +0 -18
  103. package/src/application/models/graphql/queries/getColorsAndFrontendQuery.ts +0 -13
  104. package/src/application/models/graphql/queries/getMerchantFrontendConfigQuery.ts +0 -103
@@ -3,35 +3,30 @@ import { EnviveConfigService } from '../enviveConfigService';
3
3
  const mockFetch = vi.fn();
4
4
  globalThis.fetch = mockFetch;
5
5
 
6
- const ORG_CONFIG_RESPONSE = {
7
- org: {
8
- org: {
9
- id: 'org-1',
10
- short_name: 'test-org',
11
- display_name: 'Test Org',
12
- domain: 'test.com',
13
- status: 'active',
14
- created_at: '2024-01-01T00:00:00.000Z',
15
- updated_at: '2024-01-01T00:00:00.000Z',
16
- },
17
- },
18
- gates: [],
19
- };
20
-
21
- function makeOkOrgConfigFetch(overrides: Record<string, unknown> = {}) {
22
- mockFetch.mockResolvedValueOnce({
23
- ok: true,
24
- json: () => Promise.resolve({ ...ORG_CONFIG_RESPONSE, ...overrides }),
25
- });
26
- }
27
-
28
- // productsConfig has no colors, so fetchGraphQLConfig falls back to its mock
29
- // config (see fetchGraphQLConfig.test.ts "no colors fallback") - fine here
30
- // since these tests only care about caching/fetch-count behaviour.
31
- function makeOkGraphqlFetch() {
6
+ // getWidgetConfig is the single config call now: it returns org identity +
7
+ // gates + experiment assignments alongside productsConfig (the separate
8
+ // GET /v1/org/config fetch was removed). productsConfig has no colors, so
9
+ // fetchUnifiedGraphQLConfig falls back to its mock config — fine here since
10
+ // these tests only care about caching / fetch-count behaviour.
11
+ function makeOkConfigFetch() {
32
12
  mockFetch.mockResolvedValueOnce({
33
13
  ok: true,
34
- json: () => Promise.resolve({ data: { me: { getProductsConfigByVersion: {} } } }),
14
+ json: () =>
15
+ Promise.resolve({
16
+ data: {
17
+ me: {
18
+ org: {
19
+ id: 'org-1',
20
+ shortName: 'test-org',
21
+ displayName: 'Test Org',
22
+ domain: 'test.com',
23
+ createdAt: '2024-01-01T00:00:00.000Z',
24
+ updatedAt: '2024-01-01T00:00:00.000Z',
25
+ },
26
+ getWidgetConfig: { productsConfig: {}, gates: [], experimentAssignments: [] },
27
+ },
28
+ },
29
+ }),
35
30
  });
36
31
  }
37
32
 
@@ -60,27 +55,25 @@ afterEach(() => {
60
55
  });
61
56
 
62
57
  describe('EnviveConfigService caching', () => {
63
- it('fetches org config + GraphQL config on a cold cache', async () => {
64
- makeOkOrgConfigFetch();
65
- makeOkGraphqlFetch();
58
+ it('fetches the unified config once on a cold cache', async () => {
59
+ makeOkConfigFetch();
66
60
 
67
61
  const result = await makeService().getEnviveConfig();
68
62
 
69
- expect(mockFetch).toHaveBeenCalledTimes(2);
63
+ expect(mockFetch).toHaveBeenCalledTimes(1);
70
64
  expect(result.org.org.id).toBe('org-1');
71
65
  });
72
66
 
73
67
  it('serves a warm cache to a new instance with identical params without hitting the network', async () => {
74
- makeOkOrgConfigFetch();
75
- makeOkGraphqlFetch();
68
+ makeOkConfigFetch();
76
69
  await makeService().getEnviveConfig();
77
- expect(mockFetch).toHaveBeenCalledTimes(2);
70
+ expect(mockFetch).toHaveBeenCalledTimes(1);
78
71
 
79
72
  // A fresh instance (as happens on the next page navigation) should read
80
73
  // from the sessionStorage cache instead of refetching.
81
74
  const result = await makeService().getEnviveConfig();
82
75
 
83
- expect(mockFetch).toHaveBeenCalledTimes(2);
76
+ expect(mockFetch).toHaveBeenCalledTimes(1);
84
77
  expect(result.org.org.id).toBe('org-1');
85
78
  });
86
79
 
@@ -88,18 +81,16 @@ describe('EnviveConfigService caching', () => {
88
81
  vi.useFakeTimers();
89
82
  vi.setSystemTime(new Date('2026-01-01T00:00:00.000Z'));
90
83
 
91
- makeOkOrgConfigFetch();
92
- makeOkGraphqlFetch();
84
+ makeOkConfigFetch();
93
85
  await makeService().getEnviveConfig();
94
- expect(mockFetch).toHaveBeenCalledTimes(2);
86
+ expect(mockFetch).toHaveBeenCalledTimes(1);
95
87
 
96
88
  vi.setSystemTime(new Date('2026-01-01T00:05:01.000Z'));
97
89
 
98
- makeOkOrgConfigFetch();
99
- makeOkGraphqlFetch();
90
+ makeOkConfigFetch();
100
91
  await makeService().getEnviveConfig();
101
92
 
102
- expect(mockFetch).toHaveBeenCalledTimes(4);
93
+ expect(mockFetch).toHaveBeenCalledTimes(2);
103
94
  });
104
95
 
105
96
  it.each(['envive_config_version', 'spiffy_config_version'])(
@@ -107,59 +98,51 @@ describe('EnviveConfigService caching', () => {
107
98
  async param => {
108
99
  window.history.replaceState({}, '', `/?${param}=1.2.3`);
109
100
 
110
- makeOkOrgConfigFetch();
111
- makeOkGraphqlFetch();
101
+ makeOkConfigFetch();
112
102
  await makeService().getEnviveConfig();
113
- expect(mockFetch).toHaveBeenCalledTimes(2);
103
+ expect(mockFetch).toHaveBeenCalledTimes(1);
114
104
 
115
- makeOkOrgConfigFetch();
116
- makeOkGraphqlFetch();
105
+ makeOkConfigFetch();
117
106
  await makeService().getEnviveConfig();
118
107
 
119
108
  // No cache read/write happened, so a second instance refetches instead
120
109
  // of reusing anything the first instance stored.
121
- expect(mockFetch).toHaveBeenCalledTimes(4);
110
+ expect(mockFetch).toHaveBeenCalledTimes(2);
122
111
  },
123
112
  );
124
113
 
125
114
  it('does not read a version-pinned cache entry after the override is removed', async () => {
126
115
  window.history.replaceState({}, '', '/?envive_config_version=1.2.3');
127
- makeOkOrgConfigFetch();
128
- makeOkGraphqlFetch();
116
+ makeOkConfigFetch();
129
117
  await makeService().getEnviveConfig();
130
118
 
131
119
  window.history.replaceState({}, '', '/');
132
- makeOkOrgConfigFetch();
133
- makeOkGraphqlFetch();
120
+ makeOkConfigFetch();
134
121
  await makeService().getEnviveConfig();
135
122
 
136
- expect(mockFetch).toHaveBeenCalledTimes(4);
123
+ expect(mockFetch).toHaveBeenCalledTimes(2);
137
124
  });
138
125
 
139
126
  it('keeps separate cache entries per userId', async () => {
140
- makeOkOrgConfigFetch();
141
- makeOkGraphqlFetch();
127
+ makeOkConfigFetch();
142
128
  await makeService({ userId: 'user-1' }).getEnviveConfig();
143
- expect(mockFetch).toHaveBeenCalledTimes(2);
129
+ expect(mockFetch).toHaveBeenCalledTimes(1);
144
130
 
145
- makeOkOrgConfigFetch();
146
- makeOkGraphqlFetch();
131
+ makeOkConfigFetch();
147
132
  await makeService({ userId: 'user-2' }).getEnviveConfig();
148
133
 
149
- expect(mockFetch).toHaveBeenCalledTimes(4);
134
+ expect(mockFetch).toHaveBeenCalledTimes(2);
150
135
  });
151
136
 
152
137
  it('keeps separate cache entries per namespace/source/baseUrl/apiKey', async () => {
153
- makeOkOrgConfigFetch();
154
- makeOkGraphqlFetch();
138
+ makeOkConfigFetch();
155
139
  await makeService({ namespace: 'ns-a' }).getEnviveConfig();
156
- expect(mockFetch).toHaveBeenCalledTimes(2);
140
+ expect(mockFetch).toHaveBeenCalledTimes(1);
157
141
 
158
- makeOkOrgConfigFetch();
159
- makeOkGraphqlFetch();
142
+ makeOkConfigFetch();
160
143
  await makeService({ namespace: 'ns-b' }).getEnviveConfig();
161
144
 
162
- expect(mockFetch).toHaveBeenCalledTimes(4);
145
+ expect(mockFetch).toHaveBeenCalledTimes(2);
163
146
  });
164
147
 
165
148
  it('fails open and still returns config when sessionStorage.setItem throws', async () => {
@@ -167,8 +150,7 @@ describe('EnviveConfigService caching', () => {
167
150
  throw new Error('quota exceeded');
168
151
  });
169
152
 
170
- makeOkOrgConfigFetch();
171
- makeOkGraphqlFetch();
153
+ makeOkConfigFetch();
172
154
 
173
155
  const result = await makeService().getEnviveConfig();
174
156
 
@@ -180,8 +162,7 @@ describe('EnviveConfigService caching', () => {
180
162
  throw new Error('storage disabled');
181
163
  });
182
164
 
183
- makeOkOrgConfigFetch();
184
- makeOkGraphqlFetch();
165
+ makeOkConfigFetch();
185
166
 
186
167
  const result = await makeService().getEnviveConfig();
187
168
 
@@ -190,17 +171,12 @@ describe('EnviveConfigService caching', () => {
190
171
 
191
172
  it('fails open and refetches when a cached entry is corrupted JSON', async () => {
192
173
  const service = makeService();
193
- // Seed a corrupted entry under whatever key the service reads from by
194
- // populating every session storage key with garbage after a real write,
195
- // then corrupting it directly.
196
- makeOkOrgConfigFetch();
197
- makeOkGraphqlFetch();
174
+ makeOkConfigFetch();
198
175
  await service.getEnviveConfig();
199
176
  const [key] = Object.keys(sessionStorage);
200
177
  sessionStorage.setItem(key, 'not json');
201
178
 
202
- makeOkOrgConfigFetch();
203
- makeOkGraphqlFetch();
179
+ makeOkConfigFetch();
204
180
  const result = await makeService().getEnviveConfig();
205
181
 
206
182
  expect(result.org.org.id).toBe('org-1');