@envive-ai/react-hooks 0.3.45 → 0.3.47
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 +73 -3
- package/dist/application/commerce-api.d.cts +16 -1
- package/dist/application/commerce-api.d.ts +16 -1
- package/dist/application/commerce-api.js +73 -3
- package/dist/application/models/api/userEvent.d.cts +9 -2
- package/dist/application/models/api/userEvent.d.ts +9 -2
- package/dist/application/models/api/widgetText.d.cts +2 -1
- package/dist/application/models/api/widgetText.d.ts +2 -1
- package/dist/application/models/featureGates.cjs +2 -1
- package/dist/application/models/featureGates.d.cts +2 -1
- package/dist/application/models/featureGates.d.ts +2 -1
- package/dist/application/models/featureGates.js +2 -1
- package/dist/application/models/graphql/queries/getProductOptionsQuery.cjs +33 -0
- package/dist/application/models/graphql/queries/getProductOptionsQuery.d.cts +28 -0
- package/dist/application/models/graphql/queries/getProductOptionsQuery.d.ts +28 -0
- package/dist/application/models/graphql/queries/getProductOptionsQuery.js +32 -0
- package/dist/application/models/index.cjs +1 -1
- package/dist/application/models/index.js +1 -1
- package/dist/application/models/validators/validateGraphQLFrontendConfig.cjs +1 -1
- package/dist/application/models/validators/validateGraphQLFrontendConfig.js +1 -1
- package/dist/application/models/validators/validateResponse.cjs +2 -1
- package/dist/application/models/validators/validateResponse.js +2 -1
- package/dist/application/models/validators/validateUserEvent.cjs +3 -3
- package/dist/application/models/validators/validateUserEvent.js +3 -3
- package/dist/application/utils/elementObserver.d.cts +2 -2
- package/dist/application/utils/elementObserver.d.ts +2 -2
- package/dist/application/utils/index.cjs +2 -0
- package/dist/application/utils/index.d.cts +2 -1
- package/dist/application/utils/index.d.ts +2 -1
- package/dist/application/utils/index.js +2 -1
- package/dist/application/utils/messageFromAddToCartEvent.cjs +32 -0
- package/dist/application/utils/messageFromAddToCartEvent.d.cts +19 -0
- package/dist/application/utils/messageFromAddToCartEvent.d.ts +19 -0
- package/dist/application/utils/messageFromAddToCartEvent.js +31 -0
- package/dist/application/utils/widgetTextFromApiWidgetTextResponse.cjs +3 -2
- package/dist/application/utils/widgetTextFromApiWidgetTextResponse.js +3 -2
- package/dist/atoms/app/index.cjs +1 -1
- package/dist/atoms/app/index.d.cts +7 -7
- package/dist/atoms/app/index.d.ts +7 -7
- package/dist/atoms/app/index.js +1 -1
- package/dist/atoms/app/variant.cjs +2 -2
- package/dist/atoms/app/variant.d.cts +7 -7
- package/dist/atoms/app/variant.d.ts +7 -7
- package/dist/atoms/app/variant.js +2 -2
- package/dist/atoms/chat/chatState.d.cts +19 -19
- package/dist/atoms/chat/chatState.d.ts +19 -19
- package/dist/atoms/chat/form.d.cts +2 -2
- package/dist/atoms/chat/form.d.ts +2 -2
- package/dist/atoms/chat/index.cjs +1 -1
- package/dist/atoms/chat/index.d.cts +2 -2
- package/dist/atoms/chat/index.d.ts +2 -2
- package/dist/atoms/chat/index.js +1 -1
- 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/replies.d.ts +2 -2
- package/dist/atoms/chat/suggestions.d.cts +2 -2
- package/dist/atoms/chat/suggestions.d.ts +2 -2
- package/dist/atoms/envive/enviveConfig.cjs +7 -4
- package/dist/atoms/envive/enviveConfig.d.cts +16 -14
- package/dist/atoms/envive/enviveConfig.d.ts +16 -14
- package/dist/atoms/envive/enviveConfig.js +6 -4
- 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.cjs +1 -1
- package/dist/atoms/org/graphqlConfig.d.cts +6 -6
- package/dist/atoms/org/graphqlConfig.d.ts +6 -6
- package/dist/atoms/org/graphqlConfig.js +1 -1
- package/dist/atoms/org/index.cjs +1 -1
- package/dist/atoms/org/index.js +1 -1
- package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
- package/dist/atoms/org/newOrgConfigAtom.d.ts +2 -2
- package/dist/atoms/org/orgAnalyticsConfig.d.cts +4 -4
- package/dist/atoms/org/orgAnalyticsConfig.d.ts +4 -4
- package/dist/atoms/search/chatSearch.cjs +1 -1
- package/dist/atoms/search/chatSearch.d.cts +17 -17
- package/dist/atoms/search/chatSearch.d.ts +17 -17
- package/dist/atoms/search/chatSearch.js +1 -1
- package/dist/atoms/search/searchAPI.cjs +1 -1
- package/dist/atoms/search/searchAPI.d.cts +13 -13
- package/dist/atoms/search/searchAPI.d.ts +13 -13
- package/dist/atoms/search/searchAPI.js +1 -1
- package/dist/atoms/widget/chatPreviewLoading.d.cts +2 -2
- package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
- package/dist/contexts/enviveConfigContext/enviveConfigContext.cjs +6 -4
- package/dist/contexts/enviveConfigContext/enviveConfigContext.d.cts +3 -1
- package/dist/contexts/enviveConfigContext/enviveConfigContext.d.ts +3 -1
- package/dist/contexts/enviveConfigContext/enviveConfigContext.js +6 -4
- package/dist/contexts/enviveContext/enviveContext.cjs +7 -3
- package/dist/contexts/enviveContext/enviveContext.d.cts +5 -1
- package/dist/contexts/enviveContext/enviveContext.d.ts +5 -1
- package/dist/contexts/enviveContext/enviveContext.js +7 -3
- package/dist/contexts/enviveContext/types.d.cts +1 -1
- package/dist/contexts/enviveContext/types.d.ts +1 -1
- package/dist/contexts/featureFlagServiceContext/featureFlagServiceContext.cjs +2 -97
- package/dist/contexts/featureFlagServiceContext/featureFlagServiceContext.d.cts +3 -25
- package/dist/contexts/featureFlagServiceContext/featureFlagServiceContext.d.ts +3 -25
- package/dist/contexts/featureFlagServiceContext/featureFlagServiceContext.js +3 -97
- package/dist/contexts/featureFlagServiceContext/index.cjs +2 -1
- package/dist/contexts/featureFlagServiceContext/index.d.cts +2 -1
- package/dist/contexts/featureFlagServiceContext/index.d.ts +2 -1
- package/dist/contexts/featureFlagServiceContext/index.js +2 -1
- package/dist/contexts/graphqlContext/mockV3Config.cjs +1 -1
- package/dist/contexts/graphqlContext/mockV3Config.js +1 -1
- package/dist/contexts/localStorageContext/index.cjs +2 -1
- package/dist/contexts/localStorageContext/index.d.cts +2 -1
- package/dist/contexts/localStorageContext/index.d.ts +2 -1
- package/dist/contexts/localStorageContext/index.js +2 -1
- package/dist/contexts/localStorageContext/localStorageContext.cjs +5 -11
- package/dist/contexts/localStorageContext/localStorageContext.d.cts +3 -7
- package/dist/contexts/localStorageContext/localStorageContext.d.ts +3 -7
- package/dist/contexts/localStorageContext/localStorageContext.js +3 -8
- package/dist/contexts/localStorageContext/localStorageKeys.cjs +12 -0
- package/dist/contexts/localStorageContext/localStorageKeys.d.cts +9 -0
- package/dist/contexts/localStorageContext/localStorageKeys.d.ts +9 -0
- package/dist/contexts/localStorageContext/localStorageKeys.js +11 -0
- package/dist/contexts/pageContext/pageContext.cjs +2 -2
- package/dist/contexts/pageContext/pageContext.js +2 -2
- package/dist/contexts/salesAgentContext/chatAPI.cjs +15 -4
- package/dist/contexts/salesAgentContext/chatAPI.d.cts +4 -1
- package/dist/contexts/salesAgentContext/chatAPI.d.ts +4 -1
- package/dist/contexts/salesAgentContext/chatAPI.js +16 -5
- package/dist/contexts/salesAgentContext/salesAgentContext.cjs +15 -4
- package/dist/contexts/salesAgentContext/salesAgentContext.d.cts +2 -1
- package/dist/contexts/salesAgentContext/salesAgentContext.d.ts +2 -1
- package/dist/contexts/salesAgentContext/salesAgentContext.js +16 -5
- package/dist/contexts/salesAgentContext/salesAgentService.cjs +12 -4
- package/dist/contexts/salesAgentContext/salesAgentService.js +12 -4
- package/dist/contexts/searchContext/searchContext.cjs +1 -1
- package/dist/contexts/searchContext/searchContext.js +1 -1
- package/dist/contexts/systemSettingsContext/systemSettingsContext.d.cts +2 -2
- package/dist/contexts/systemSettingsContext/systemSettingsContext.d.ts +2 -2
- package/dist/contexts/types.cjs +1 -1
- package/dist/contexts/types.d.cts +3 -1
- package/dist/contexts/types.d.ts +3 -1
- package/dist/contexts/types.js +1 -1
- package/dist/contexts/typesV3.cjs +1 -1
- package/dist/contexts/typesV3.d.cts +11 -2
- package/dist/contexts/typesV3.d.ts +12 -3
- package/dist/contexts/typesV3.js +1 -1
- package/dist/contexts/widgetConfigContext/widgetConfigContext.cjs +1 -1
- package/dist/contexts/widgetConfigContext/widgetConfigContext.js +1 -1
- package/dist/hooks/AddToCart/addToCartErrorMessage.cjs +7 -0
- package/dist/hooks/AddToCart/addToCartErrorMessage.d.cts +5 -0
- package/dist/hooks/AddToCart/addToCartErrorMessage.d.ts +5 -0
- package/dist/hooks/AddToCart/addToCartErrorMessage.js +6 -0
- package/dist/hooks/AddToCart/createAddToCartUserEvent.cjs +20 -0
- package/dist/hooks/AddToCart/createAddToCartUserEvent.d.cts +17 -0
- package/dist/hooks/AddToCart/createAddToCartUserEvent.d.ts +17 -0
- package/dist/hooks/AddToCart/createAddToCartUserEvent.js +19 -0
- package/dist/hooks/AddToCart/index.cjs +9 -0
- package/dist/hooks/AddToCart/index.d.cts +5 -0
- package/dist/hooks/AddToCart/index.d.ts +5 -0
- package/dist/hooks/AddToCart/index.js +6 -0
- package/dist/hooks/AddToCart/parseAddToCartFunction.cjs +27 -0
- package/dist/hooks/AddToCart/parseAddToCartFunction.d.cts +13 -0
- package/dist/hooks/AddToCart/parseAddToCartFunction.d.ts +13 -0
- package/dist/hooks/AddToCart/parseAddToCartFunction.js +27 -0
- package/dist/hooks/AddToCart/useAddToCart.cjs +24 -0
- package/dist/hooks/AddToCart/useAddToCart.d.cts +14 -0
- package/dist/hooks/AddToCart/useAddToCart.d.ts +14 -0
- package/dist/hooks/AddToCart/useAddToCart.js +23 -0
- package/dist/hooks/ChatToggle/useChatToggle.cjs +1 -1
- package/dist/hooks/ChatToggle/useChatToggle.js +1 -1
- package/dist/hooks/LocalStorageOperations/useLocalStorageOperations.cjs +6 -5
- package/dist/hooks/LocalStorageOperations/useLocalStorageOperations.js +3 -2
- package/dist/hooks/PageViewedEvent/usePageViewedEvent.cjs +6 -3
- package/dist/hooks/PageViewedEvent/usePageViewedEvent.js +6 -3
- package/dist/hooks/ProductDetails/index.cjs +9 -0
- package/dist/hooks/ProductDetails/index.d.cts +4 -0
- package/dist/hooks/ProductDetails/index.d.ts +4 -0
- package/dist/hooks/ProductDetails/index.js +4 -0
- package/dist/hooks/ProductDetails/useProductDetails.cjs +53 -0
- package/dist/hooks/ProductDetails/useProductDetails.d.cts +20 -0
- package/dist/hooks/ProductDetails/useProductDetails.d.ts +20 -0
- package/dist/hooks/ProductDetails/useProductDetails.js +52 -0
- package/dist/hooks/ProductDetails/variantSelection.cjs +42 -0
- package/dist/hooks/ProductDetails/variantSelection.d.cts +35 -0
- package/dist/hooks/ProductDetails/variantSelection.d.ts +35 -0
- package/dist/hooks/ProductDetails/variantSelection.js +38 -0
- package/dist/hooks/Search/useSearch.cjs +3 -3
- package/dist/hooks/Search/useSearch.d.cts +1 -1
- package/dist/hooks/Search/useSearch.d.ts +1 -1
- package/dist/hooks/Search/useSearch.js +3 -3
- package/dist/hooks/SystemSettingsContext/useSystemSettingsContext.d.cts +2 -2
- package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.cjs +11 -2
- package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.d.cts +1 -10
- package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.d.ts +1 -10
- package/dist/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.js +11 -2
- package/dist/hooks/WidgetInteraction/types.cjs +13 -3
- package/dist/hooks/WidgetInteraction/types.d.cts +29 -4
- package/dist/hooks/WidgetInteraction/types.d.ts +29 -4
- package/dist/hooks/WidgetInteraction/types.js +13 -3
- package/dist/hooks/WidgetInteraction/utils.cjs +2 -2
- package/dist/hooks/WidgetInteraction/utils.js +2 -2
- package/dist/hooks/utils.d.cts +1 -1
- package/dist/hooks/utils.d.ts +1 -1
- package/dist/services/amplitudeService/amplitudeService.cjs +18 -11
- package/dist/services/amplitudeService/amplitudeService.d.cts +5 -2
- package/dist/services/amplitudeService/amplitudeService.d.ts +5 -2
- package/dist/services/amplitudeService/amplitudeService.js +16 -8
- package/dist/services/enviveConfigService/enviveConfigService.cjs +36 -4
- package/dist/services/enviveConfigService/enviveConfigService.d.cts +4 -1
- package/dist/services/enviveConfigService/enviveConfigService.d.ts +4 -1
- package/dist/services/enviveConfigService/enviveConfigService.js +35 -3
- package/dist/services/enviveConfigService/fetchGraphQLConfig.cjs +9 -8
- package/dist/services/enviveConfigService/fetchGraphQLConfig.js +9 -7
- package/dist/services/featureFlagService/index.cjs +101 -0
- package/dist/services/featureFlagService/index.d.cts +28 -0
- package/dist/services/featureFlagService/index.d.ts +28 -0
- package/dist/services/featureFlagService/index.js +101 -0
- package/dist/services/ga4ProjectionService/ga4EventSchema.cjs +8 -2
- package/dist/services/ga4ProjectionService/ga4EventSchema.js +8 -2
- package/dist/services/hardcopyService/hardcopyService.cjs +4 -3
- package/dist/services/hardcopyService/hardcopyService.d.cts +1 -1
- package/dist/services/hardcopyService/hardcopyService.d.ts +1 -1
- package/dist/services/hardcopyService/hardcopyService.js +4 -3
- package/dist/services/urlResolverWarmupService/index.cjs +54 -0
- package/dist/services/urlResolverWarmupService/index.d.cts +40 -0
- package/dist/services/urlResolverWarmupService/index.d.ts +40 -0
- package/dist/services/urlResolverWarmupService/index.js +54 -0
- package/dist/types/enviveConfig.d.cts +6 -2
- package/dist/types/enviveConfig.d.ts +6 -2
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +18 -2
- package/src/application/__tests__/commerceApiAddToCartRehydration.test.ts +126 -0
- package/src/application/commerce-api.ts +142 -23
- package/src/application/models/api/userEvent.ts +8 -1
- package/src/application/models/api/widgetText.ts +3 -0
- package/src/application/models/featureGates.ts +5 -0
- package/src/application/models/graphql/queries/getProductOptionsQuery.ts +59 -0
- package/src/application/models/validators/__tests__/validateUserEvent.test.ts +41 -0
- package/src/application/models/validators/validateResponse.ts +1 -0
- package/src/application/models/validators/validateUserEvent.ts +7 -2
- package/src/application/utils/__tests__/messageFromAddToCartEvent.test.ts +109 -0
- package/src/application/utils/index.ts +1 -0
- package/src/application/utils/messageFromAddToCartEvent.ts +32 -0
- package/src/application/utils/widgetTextFromApiWidgetTextResponse.ts +1 -0
- package/src/atoms/app/index.ts +1 -1
- package/src/atoms/app/variant.ts +1 -1
- package/src/atoms/envive/enviveConfig.ts +6 -1
- package/src/atoms/org/graphqlConfig.ts +1 -1
- package/src/contexts/enviveConfigContext/enviveConfigContext.tsx +5 -0
- package/src/contexts/enviveContext/enviveContext.tsx +10 -0
- package/src/contexts/featureFlagServiceContext/featureFlagServiceContext.tsx +6 -173
- package/src/contexts/localStorageContext/localStorageContext.tsx +2 -5
- package/src/contexts/localStorageContext/localStorageKeys.ts +8 -0
- package/src/contexts/pageContext/pageContext.tsx +1 -1
- package/src/contexts/salesAgentContext/__tests__/chatAPI.test.tsx +63 -0
- package/src/contexts/salesAgentContext/chatAPI.ts +20 -1
- package/src/contexts/salesAgentContext/salesAgentContext.tsx +17 -0
- package/src/contexts/salesAgentContext/salesAgentService.ts +12 -3
- package/src/contexts/types.ts +2 -0
- package/src/contexts/typesV3.ts +14 -0
- package/src/hooks/AddToCart/__tests__/parseAddToCartFunction.test.ts +31 -0
- package/src/hooks/AddToCart/__tests__/useAddToCart.test.tsx +204 -0
- package/src/hooks/AddToCart/addToCartErrorMessage.ts +2 -0
- package/src/hooks/AddToCart/createAddToCartUserEvent.ts +25 -0
- package/src/hooks/AddToCart/index.ts +4 -0
- package/src/hooks/AddToCart/parseAddToCartFunction.ts +31 -0
- package/src/hooks/AddToCart/useAddToCart.ts +35 -0
- package/src/hooks/PageViewedEvent/__tests__/usePageViewedEvent.test.ts +4 -4
- package/src/hooks/PageViewedEvent/usePageViewedEvent.ts +5 -1
- package/src/hooks/ProductDetails/__tests__/useProductDetails.test.tsx +129 -0
- package/src/hooks/ProductDetails/__tests__/variantSelection.test.ts +145 -0
- package/src/hooks/ProductDetails/index.ts +2 -0
- package/src/hooks/ProductDetails/useProductDetails.ts +62 -0
- package/src/hooks/ProductDetails/variantSelection.ts +61 -0
- package/src/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.ts +15 -0
- package/src/hooks/WidgetInteraction/types.ts +43 -2
- package/src/hooks/WidgetInteraction/utils.ts +1 -1
- package/src/services/amplitudeService/__tests__/amplitudeService.test.ts +8 -8
- package/src/services/amplitudeService/amplitudeService.ts +43 -23
- package/src/services/enviveConfigService/__tests__/enviveConfigService.test.ts +208 -0
- package/src/services/enviveConfigService/enviveConfigService.ts +62 -2
- package/src/services/enviveConfigService/fetchGraphQLConfig.ts +17 -6
- package/src/services/featureFlagService/index.ts +176 -0
- package/src/services/ga4ProjectionService/__tests__/ga4ProjectionService.test.ts +36 -0
- package/src/services/ga4ProjectionService/ga4EventSchema.ts +7 -0
- package/src/services/hardcopyService/__tests__/hardcopyService.test.ts +47 -1
- package/src/services/hardcopyService/hardcopyService.ts +5 -0
- package/src/services/urlResolverWarmupService/__tests__/urlResolverWarmupService.test.ts +85 -0
- package/src/services/urlResolverWarmupService/index.ts +89 -0
- package/src/types/enviveConfig.ts +3 -0
|
@@ -28,6 +28,10 @@ import {
|
|
|
28
28
|
UserEvent,
|
|
29
29
|
} from 'src/application/models';
|
|
30
30
|
import { OrgConfig } from 'src/application/models/api/orgConfigResults';
|
|
31
|
+
import {
|
|
32
|
+
ProductDetails,
|
|
33
|
+
getProductOptionsQuery,
|
|
34
|
+
} from 'src/application/models/graphql/queries/getProductOptionsQuery';
|
|
31
35
|
import { ProductExperiment } from 'src/application/models/productExperiment';
|
|
32
36
|
import { validateOrgConfigResults } from 'src/application/models/validators/validateOrgConfigResults';
|
|
33
37
|
import { validateResponse } from 'src/application/models/validators/validateResponse';
|
|
@@ -35,6 +39,7 @@ import { validateSuggestion } from 'src/application/models/validators/validateSu
|
|
|
35
39
|
import { validateUserEvent } from 'src/application/models/validators/validateUserEvent';
|
|
36
40
|
import {
|
|
37
41
|
getQueryParam,
|
|
42
|
+
messageFromAddToCartEvent,
|
|
38
43
|
messageFromQueryEvent,
|
|
39
44
|
messageFromResponse,
|
|
40
45
|
messageFromSuggestionEvent,
|
|
@@ -146,7 +151,26 @@ class CommerceApiClient {
|
|
|
146
151
|
this.productsApi = new ProductsApi(config);
|
|
147
152
|
}
|
|
148
153
|
|
|
154
|
+
// Dedupes concurrent resolutions of the same URL: the injection bundle
|
|
155
|
+
// warms this call before React mounts, and PageProvider may request the
|
|
156
|
+
// same URL while the warm-up is still in flight.
|
|
157
|
+
private static inFlightUrlResolutions = new Map<string, Promise<unknown>>();
|
|
158
|
+
|
|
149
159
|
static resolveUrl = async (url: string) => {
|
|
160
|
+
const inFlight = CommerceApiClient.inFlightUrlResolutions.get(url);
|
|
161
|
+
if (inFlight) {
|
|
162
|
+
return inFlight;
|
|
163
|
+
}
|
|
164
|
+
const request = CommerceApiClient.resolveUrlUncached(url);
|
|
165
|
+
CommerceApiClient.inFlightUrlResolutions.set(url, request);
|
|
166
|
+
try {
|
|
167
|
+
return await request;
|
|
168
|
+
} finally {
|
|
169
|
+
CommerceApiClient.inFlightUrlResolutions.delete(url);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
private static resolveUrlUncached = async (url: string) => {
|
|
150
174
|
const atomStore = getAtomStore();
|
|
151
175
|
const orgShortName = atomStore.get(orgShortNameAtom);
|
|
152
176
|
const orgId = atomStore.get(orgIdAtom);
|
|
@@ -405,33 +429,64 @@ class CommerceApiClient {
|
|
|
405
429
|
)
|
|
406
430
|
.filter(turn => turn.length > 0);
|
|
407
431
|
|
|
408
|
-
const userMessages: Message[][] =
|
|
409
|
-
.
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
432
|
+
const userMessages: Message[][] = (
|
|
433
|
+
await Promise.all(
|
|
434
|
+
userEvents.map(async event => {
|
|
435
|
+
if ([UserEventCategory.QueryTyped, UserEventCategory.Search].includes(event.category)) {
|
|
436
|
+
return [messageFromQueryEvent(event)];
|
|
437
|
+
}
|
|
413
438
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
439
|
+
if (event.category === UserEventCategory.SuggestionClicked) {
|
|
440
|
+
return [messageFromSuggestionEvent(event, suggestions)];
|
|
441
|
+
}
|
|
417
442
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
443
|
+
if (event.category === UserEventCategory.AddToCart) {
|
|
444
|
+
// Historical events never carried a client-local productTitle (it's
|
|
445
|
+
// dropped before hitting the backend), so resolve it here: first for
|
|
446
|
+
// free from a matching Product response already fetched above, then
|
|
447
|
+
// as a fallback via the cached product-details call.
|
|
448
|
+
const matchedProduct = responses
|
|
449
|
+
.flat()
|
|
450
|
+
.find(
|
|
451
|
+
response =>
|
|
452
|
+
response.category === ResponseCategory.Product &&
|
|
453
|
+
response.attributes.id === event.attributes.productId,
|
|
454
|
+
);
|
|
455
|
+
let productTitle =
|
|
456
|
+
matchedProduct?.category === ResponseCategory.Product
|
|
457
|
+
? matchedProduct.attributes.title
|
|
458
|
+
: undefined;
|
|
459
|
+
if (!productTitle) {
|
|
460
|
+
try {
|
|
461
|
+
const details = await CommerceApiClient.retrieveProductDetails(
|
|
462
|
+
event.attributes.productId,
|
|
463
|
+
);
|
|
464
|
+
productTitle = details?.title;
|
|
465
|
+
} catch {
|
|
466
|
+
productTitle = undefined;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return [messageFromAddToCartEvent(event, productTitle)];
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (event.category === UserEventCategory.FormSubmitted) {
|
|
473
|
+
const formResponse = responses
|
|
474
|
+
.flat()
|
|
475
|
+
.find(
|
|
476
|
+
response =>
|
|
477
|
+
response.id === event.attributes.formResponseId &&
|
|
478
|
+
event.attributes.formType !== FormType.Escalation,
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
if (formResponse && formResponse.category === ResponseCategory.Form) {
|
|
482
|
+
return [messageFromFormSubmittedEvent(event, formResponse.attributes)];
|
|
483
|
+
}
|
|
429
484
|
}
|
|
430
|
-
}
|
|
431
485
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
486
|
+
return [];
|
|
487
|
+
}),
|
|
488
|
+
)
|
|
489
|
+
).filter((message): message is Message[] => message.length > 0);
|
|
435
490
|
|
|
436
491
|
// Sort the messages chronologically to reconstruct the chat history
|
|
437
492
|
const sortedMessages = [...assistantMessages, ...userMessages].sort(
|
|
@@ -494,6 +549,70 @@ class CommerceApiClient {
|
|
|
494
549
|
}
|
|
495
550
|
};
|
|
496
551
|
|
|
552
|
+
// Caches resolved product details by productId for the lifetime of the
|
|
553
|
+
// session: variant selection, the display of the add-to-cart chat message,
|
|
554
|
+
// and useProductDetails all resolve the same product repeatedly. Failed
|
|
555
|
+
// requests are evicted so a later call can retry.
|
|
556
|
+
private static productDetailsCache = new Map<string, Promise<ProductDetails | undefined>>();
|
|
557
|
+
|
|
558
|
+
static retrieveProductDetails = (productId: string): Promise<ProductDetails | undefined> => {
|
|
559
|
+
const cached = CommerceApiClient.productDetailsCache.get(productId);
|
|
560
|
+
if (cached) {
|
|
561
|
+
return cached;
|
|
562
|
+
}
|
|
563
|
+
const request = CommerceApiClient.retrieveProductDetailsUncached(productId).catch(err => {
|
|
564
|
+
CommerceApiClient.productDetailsCache.delete(productId);
|
|
565
|
+
throw err;
|
|
566
|
+
});
|
|
567
|
+
CommerceApiClient.productDetailsCache.set(productId, request);
|
|
568
|
+
return request;
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Retrieves variant-level product details for a single product via the GraphQL
|
|
573
|
+
* `me.productOptions` query on POST /v1/graphql. Only meaningful for products
|
|
574
|
+
* that offer variations.
|
|
575
|
+
*
|
|
576
|
+
* @param productId - The product ID to retrieve details for
|
|
577
|
+
* @returns ProductDetails, or undefined when the product has no options data
|
|
578
|
+
* @throws on network/HTTP failure or GraphQL errors
|
|
579
|
+
*/
|
|
580
|
+
private static retrieveProductDetailsUncached = async (
|
|
581
|
+
productId: string,
|
|
582
|
+
): Promise<ProductDetails | undefined> => {
|
|
583
|
+
const atomStore = getAtomStore();
|
|
584
|
+
const baseUrl = atomStore.get(baseUrlAtom);
|
|
585
|
+
const apiKey = atomStore.get(orgLevelApiKeyAtom);
|
|
586
|
+
|
|
587
|
+
try {
|
|
588
|
+
const response = await fetch(`${baseUrl}/v1/graphql`, {
|
|
589
|
+
method: 'POST',
|
|
590
|
+
headers: {
|
|
591
|
+
'Content-Type': 'application/json',
|
|
592
|
+
Authorization: `Bearer ${apiKey}`,
|
|
593
|
+
},
|
|
594
|
+
body: JSON.stringify({
|
|
595
|
+
query: getProductOptionsQuery(),
|
|
596
|
+
variables: { productId },
|
|
597
|
+
}),
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
if (!response.ok) {
|
|
601
|
+
throw new ResponseError(response, `GraphQL request failed: ${response.statusText}`);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const result = await response.json();
|
|
605
|
+
if (result.errors) {
|
|
606
|
+
throw new Error(`GraphQL errors: ${JSON.stringify(result.errors)}`);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return result.data?.me?.productOptions ?? undefined;
|
|
610
|
+
} catch (err) {
|
|
611
|
+
await throwSessionRestartRequiredIf('Failed to retrieve product details', err);
|
|
612
|
+
return undefined;
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
|
|
497
616
|
/**
|
|
498
617
|
*
|
|
499
618
|
* @param payload
|
|
@@ -12,7 +12,14 @@ import {
|
|
|
12
12
|
import { CamelCasedPropertiesDeep } from 'src/application/models/utilityTypes';
|
|
13
13
|
|
|
14
14
|
// TODO flatten these out or explore new typescript openapi generator fork
|
|
15
|
-
export interface PDPAttributes extends CamelCasedPropertiesDeep<ApiPDPAttributes> {
|
|
15
|
+
export interface PDPAttributes extends CamelCasedPropertiesDeep<ApiPDPAttributes> {
|
|
16
|
+
/**
|
|
17
|
+
* Client-local only: never serialized to the backend (coreUserEventToApiUserEvent
|
|
18
|
+
* hand-picks fields and ignores this one). Lets the live add-to-cart chat message
|
|
19
|
+
* show a resolved product title instead of the raw productId.
|
|
20
|
+
*/
|
|
21
|
+
productTitle?: string;
|
|
22
|
+
}
|
|
16
23
|
|
|
17
24
|
export interface PLPAttributes extends CamelCasedPropertiesDeep<ApiPLPAttributes> {}
|
|
18
25
|
|
|
@@ -8,4 +8,7 @@ export type WidgetText = {
|
|
|
8
8
|
requestId: string;
|
|
9
9
|
language: string;
|
|
10
10
|
values: Record<string, WidgetString[]>;
|
|
11
|
+
// Served-method attribution keyed by overridden slot name. Forwarded verbatim
|
|
12
|
+
// to the widget-text analytics events; the frontend never interprets it.
|
|
13
|
+
aiSuggestionsAttributionBySlot?: Record<string, unknown> | null;
|
|
11
14
|
};
|
|
@@ -27,6 +27,11 @@ export enum FeatureGates {
|
|
|
27
27
|
IsAiSuggestionsVariantEnabled = 'is_ai_suggestions_variant_enabled',
|
|
28
28
|
IsAiSuggestionsVariantAEnabled = 'is_ai_suggestions_variant_a_enabled',
|
|
29
29
|
IsAiSuggestionsVariantBEnabled = 'is_ai_suggestions_variant_b_enabled',
|
|
30
|
+
// Serves the agentic storefront (FullPageSalesAgentV3 welcome overlay)
|
|
31
|
+
// independently of the pdp/plp variant_b experiment. The backend serves the
|
|
32
|
+
// storefront under this gate and falls back to variant_b only until this
|
|
33
|
+
// ships, so an org can run the storefront without opting pdp/plp into variant_b.
|
|
34
|
+
IsAiSuggestionsStorefrontEnabled = 'is_ai_suggestions_storefront_enabled',
|
|
30
35
|
IsVoiceInputEnabled = 'is_voice_input_enabled',
|
|
31
36
|
// Statsig experiments / unified getWidgetConfig endpoint migration. When
|
|
32
37
|
// true, EnviveConfigService calls getWidgetConfig (experiment-aware)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Fetches variant-level product details (options, availability, pricing,
|
|
2
|
+
// images) for a single product. Only meaningful for products that offer
|
|
3
|
+
// variations — non-variant PDP surfaces should keep using the REST
|
|
4
|
+
// /v1/products/retrieve path (CommerceApiClient.retrieveProducts).
|
|
5
|
+
export const getProductOptionsQuery = () => `
|
|
6
|
+
query($productId: String!) {
|
|
7
|
+
me {
|
|
8
|
+
productOptions(productId: $productId) {
|
|
9
|
+
productId
|
|
10
|
+
virtualParentId
|
|
11
|
+
title
|
|
12
|
+
options {
|
|
13
|
+
name
|
|
14
|
+
values
|
|
15
|
+
}
|
|
16
|
+
variants {
|
|
17
|
+
variantId
|
|
18
|
+
available
|
|
19
|
+
originalPrice
|
|
20
|
+
salePrice
|
|
21
|
+
imageUrl
|
|
22
|
+
url
|
|
23
|
+
options {
|
|
24
|
+
name
|
|
25
|
+
value
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
export interface ProductVariantOption {
|
|
34
|
+
name: string;
|
|
35
|
+
value: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ProductVariant {
|
|
39
|
+
variantId: string;
|
|
40
|
+
available: boolean;
|
|
41
|
+
originalPrice?: number;
|
|
42
|
+
salePrice?: number;
|
|
43
|
+
imageUrl?: string;
|
|
44
|
+
url?: string;
|
|
45
|
+
options: ProductVariantOption[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ProductOption {
|
|
49
|
+
name: string;
|
|
50
|
+
values: string[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ProductDetails {
|
|
54
|
+
productId: string;
|
|
55
|
+
virtualParentId?: string;
|
|
56
|
+
title: string;
|
|
57
|
+
options: ProductOption[];
|
|
58
|
+
variants: ProductVariant[];
|
|
59
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { UserEventCategory } from '@spiffy-ai/commerce-api-client';
|
|
2
|
+
import { validateUserEvent } from 'src/application/models/validators/validateUserEvent';
|
|
3
|
+
|
|
4
|
+
describe('validateUserEvent', () => {
|
|
5
|
+
it('preserves productId, parentProductId, and url for an AddToCart event', () => {
|
|
6
|
+
const result = validateUserEvent({
|
|
7
|
+
event_id: 'event-1',
|
|
8
|
+
created_at: '2026-07-20T00:00:00.000Z',
|
|
9
|
+
category: UserEventCategory.AddToCart,
|
|
10
|
+
attributes: {
|
|
11
|
+
product_id: 'product-1',
|
|
12
|
+
parent_product_id: 'parent-1',
|
|
13
|
+
url: 'https://example.com/product-1',
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
expect(result).toEqual({
|
|
18
|
+
eventId: 'event-1',
|
|
19
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
20
|
+
category: UserEventCategory.AddToCart,
|
|
21
|
+
attributes: {
|
|
22
|
+
productId: 'product-1',
|
|
23
|
+
parentProductId: 'parent-1',
|
|
24
|
+
url: 'https://example.com/product-1',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('does not fall through to AppLoaded for an AddToCart event', () => {
|
|
30
|
+
const result = validateUserEvent({
|
|
31
|
+
event_id: 'event-1',
|
|
32
|
+
created_at: '2026-07-20T00:00:00.000Z',
|
|
33
|
+
category: UserEventCategory.AddToCart,
|
|
34
|
+
attributes: {
|
|
35
|
+
product_id: 'product-1',
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
expect(result?.category).toBe(UserEventCategory.AddToCart);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -48,6 +48,7 @@ export const validateResponse = (data: unknown): Response | undefined => {
|
|
|
48
48
|
category: ResponseCategory.Product,
|
|
49
49
|
attributes: {
|
|
50
50
|
id: data.attributes.id,
|
|
51
|
+
itemGroupId: data.attributes.item_group_id,
|
|
51
52
|
description: data.attributes.description,
|
|
52
53
|
imageUrl: data.attributes.image_url,
|
|
53
54
|
imageUrls: data.attributes.image_urls,
|
|
@@ -16,11 +16,16 @@ export const validateUserEvent = (data: unknown): UserEvent | undefined => {
|
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
// PdpVisit and AddToCart share the same attributes structure
|
|
20
|
+
if (
|
|
21
|
+
(data.category === UserEventCategory.PdpVisit ||
|
|
22
|
+
data.category === UserEventCategory.AddToCart) &&
|
|
23
|
+
isApiPDPAttributes(data.attributes)
|
|
24
|
+
) {
|
|
20
25
|
return {
|
|
21
26
|
eventId: data.event_id,
|
|
22
27
|
createdAt: data.created_at,
|
|
23
|
-
category:
|
|
28
|
+
category: data.category,
|
|
24
29
|
attributes: {
|
|
25
30
|
productId: data.attributes.product_id,
|
|
26
31
|
parentProductId: data.attributes.parent_product_id,
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { UserEventCategory } from '@spiffy-ai/commerce-api-client';
|
|
2
|
+
import { MessageRole, MessageType, UserEvent } from 'src/application/models';
|
|
3
|
+
import { messageFromAddToCartEvent } from '../messageFromAddToCartEvent';
|
|
4
|
+
|
|
5
|
+
describe('messageFromAddToCartEvent', () => {
|
|
6
|
+
it('builds a user message from an AddToCart event', () => {
|
|
7
|
+
const event: UserEvent = {
|
|
8
|
+
eventId: 'event-1',
|
|
9
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
10
|
+
category: UserEventCategory.AddToCart,
|
|
11
|
+
attributes: {
|
|
12
|
+
productId: 'product-1',
|
|
13
|
+
parentProductId: '',
|
|
14
|
+
url: '',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
expect(messageFromAddToCartEvent(event)).toEqual({
|
|
19
|
+
id: 'event-1',
|
|
20
|
+
role: MessageRole.User,
|
|
21
|
+
type: MessageType.QueryTyped,
|
|
22
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
23
|
+
metadata: {
|
|
24
|
+
content: 'Add product-1 to my cart',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('returns undefined for a non-AddToCart event', () => {
|
|
30
|
+
const event: UserEvent = {
|
|
31
|
+
eventId: 'event-1',
|
|
32
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
33
|
+
category: UserEventCategory.AppLoaded,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
expect(messageFromAddToCartEvent(event)).toBeUndefined();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('prefers the explicit productTitle override parameter', () => {
|
|
40
|
+
const event: UserEvent = {
|
|
41
|
+
eventId: 'event-1',
|
|
42
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
43
|
+
category: UserEventCategory.AddToCart,
|
|
44
|
+
attributes: {
|
|
45
|
+
productId: 'product-1',
|
|
46
|
+
parentProductId: '',
|
|
47
|
+
url: '',
|
|
48
|
+
productTitle: 'Attribute Title',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
expect(messageFromAddToCartEvent(event, 'Override Title')).toEqual({
|
|
53
|
+
id: 'event-1',
|
|
54
|
+
role: MessageRole.User,
|
|
55
|
+
type: MessageType.QueryTyped,
|
|
56
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
57
|
+
metadata: {
|
|
58
|
+
content: 'Add Override Title to my cart',
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('falls back to event.attributes.productTitle when no override is passed', () => {
|
|
64
|
+
const event: UserEvent = {
|
|
65
|
+
eventId: 'event-1',
|
|
66
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
67
|
+
category: UserEventCategory.AddToCart,
|
|
68
|
+
attributes: {
|
|
69
|
+
productId: 'product-1',
|
|
70
|
+
parentProductId: '',
|
|
71
|
+
url: '',
|
|
72
|
+
productTitle: 'Attribute Title',
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
expect(messageFromAddToCartEvent(event)).toEqual({
|
|
77
|
+
id: 'event-1',
|
|
78
|
+
role: MessageRole.User,
|
|
79
|
+
type: MessageType.QueryTyped,
|
|
80
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
81
|
+
metadata: {
|
|
82
|
+
content: 'Add Attribute Title to my cart',
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('falls back to the raw productId when neither a title override nor an attribute title is present', () => {
|
|
88
|
+
const event: UserEvent = {
|
|
89
|
+
eventId: 'event-1',
|
|
90
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
91
|
+
category: UserEventCategory.AddToCart,
|
|
92
|
+
attributes: {
|
|
93
|
+
productId: 'product-1',
|
|
94
|
+
parentProductId: '',
|
|
95
|
+
url: '',
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
expect(messageFromAddToCartEvent(event)).toEqual({
|
|
100
|
+
id: 'event-1',
|
|
101
|
+
role: MessageRole.User,
|
|
102
|
+
type: MessageType.QueryTyped,
|
|
103
|
+
createdAt: '2026-07-20T00:00:00.000Z',
|
|
104
|
+
metadata: {
|
|
105
|
+
content: 'Add product-1 to my cart',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -6,6 +6,7 @@ export * from './divideArray';
|
|
|
6
6
|
export * from './domObserver';
|
|
7
7
|
export * from './elementObserver';
|
|
8
8
|
export * from './imageFilter';
|
|
9
|
+
export * from './messageFromAddToCartEvent';
|
|
9
10
|
export * from './messageFromFormSubmittedEvent';
|
|
10
11
|
export * from './messageFromQueryEvent';
|
|
11
12
|
export * from './messageFromResponse';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { UserEventCategory } from '@spiffy-ai/commerce-api-client';
|
|
2
|
+
import { Message, MessageRole, MessageType, UserEvent } from 'src/application/models';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Transforms an AddToCart UserEvent object into a Message object for presentation.
|
|
6
|
+
*
|
|
7
|
+
* @param event The user event object received from the server
|
|
8
|
+
* @param productTitle Resolved product title to display instead of the raw
|
|
9
|
+
* productId. Falls back to `event.attributes.productTitle` (set on freshly
|
|
10
|
+
* created, not-yet-serialized events) and finally to the productId itself.
|
|
11
|
+
*
|
|
12
|
+
* @returns A Message if the event is an AddToCart event, otherwise undefined
|
|
13
|
+
*/
|
|
14
|
+
export const messageFromAddToCartEvent = (
|
|
15
|
+
event: UserEvent,
|
|
16
|
+
productTitle?: string,
|
|
17
|
+
): Message | undefined => {
|
|
18
|
+
if (event.category === UserEventCategory.AddToCart) {
|
|
19
|
+
const label = productTitle ?? event.attributes.productTitle ?? event.attributes.productId;
|
|
20
|
+
return {
|
|
21
|
+
id: event.eventId,
|
|
22
|
+
role: MessageRole.User,
|
|
23
|
+
type: MessageType.QueryTyped,
|
|
24
|
+
createdAt: event.createdAt,
|
|
25
|
+
metadata: {
|
|
26
|
+
content: `Add ${label} to my cart`,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return undefined;
|
|
32
|
+
};
|
package/src/atoms/app/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ContextEnvEnum, ContextSourceEnum } from '@spiffy-ai/commerce-api-clien
|
|
|
2
2
|
import { atom } from 'jotai';
|
|
3
3
|
import { atomWithStorage } from 'jotai/utils';
|
|
4
4
|
import { VariantInfo } from 'src/application/models';
|
|
5
|
-
import { UserIdentityContextType } from 'src/contexts/userIdentityContext/userIdentityContext';
|
|
5
|
+
import type { UserIdentityContextType } from 'src/contexts/userIdentityContext/userIdentityContext';
|
|
6
6
|
import { v4 as uuid } from 'uuid';
|
|
7
7
|
import { contextSourceAtom, envAtom, orgIdAtom, orgShortNameAtom } from '../envive/enviveConfig';
|
|
8
8
|
|
package/src/atoms/app/variant.ts
CHANGED
|
@@ -255,7 +255,7 @@ const getPageVisitContext = (pageVisitCategory: PageVisitCategory | undefined) =
|
|
|
255
255
|
}
|
|
256
256
|
if (pageVisitCategory === PageVisitCategory.FullPage) {
|
|
257
257
|
return {
|
|
258
|
-
page_type: '
|
|
258
|
+
page_type: 'adaptive_storefront',
|
|
259
259
|
page_id: window.location.href,
|
|
260
260
|
};
|
|
261
261
|
}
|
|
@@ -2,7 +2,7 @@ import Logger from 'src/application/logging/logger';
|
|
|
2
2
|
import { atom } from 'jotai';
|
|
3
3
|
import { EnviveConfig } from 'src/contexts/types';
|
|
4
4
|
import { ContextSourceEnum } from '@spiffy-ai/commerce-api-client';
|
|
5
|
-
import { LocalStorageKeys } from 'src/contexts/localStorageContext';
|
|
5
|
+
import { LocalStorageKeys } from 'src/contexts/localStorageContext/localStorageKeys';
|
|
6
6
|
|
|
7
7
|
const logger = new Logger('enviveConfig');
|
|
8
8
|
|
|
@@ -49,6 +49,11 @@ export const orgIdAtom = atom(get => {
|
|
|
49
49
|
return config?.orgId;
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
export const addToCartCallbackAtom = atom(get => {
|
|
53
|
+
const config = get(enviveConfigAtom);
|
|
54
|
+
return config?.addToCart;
|
|
55
|
+
});
|
|
56
|
+
|
|
52
57
|
export const contextSourceAtom = atom(get => {
|
|
53
58
|
const config = get(enviveConfigAtom);
|
|
54
59
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { atom } from 'jotai';
|
|
2
2
|
import { ColorMapping } from 'src/application/models/colorsConfig';
|
|
3
3
|
import { FrontendConfig } from 'src/application/models/frontendConfig';
|
|
4
|
-
import { FeatureFlagContextType } from 'src/contexts/featureFlagServiceContext/featureFlagServiceContext';
|
|
4
|
+
import type { FeatureFlagContextType } from 'src/contexts/featureFlagServiceContext/featureFlagServiceContext';
|
|
5
5
|
|
|
6
6
|
export const internalGraphQLColorsConfigAtom = atom<ColorMapping | undefined>(undefined);
|
|
7
7
|
const internalGraphQLFrontendConfigAtom = atom<FrontendConfig | undefined>(undefined);
|
|
@@ -3,6 +3,7 @@ import { useSetAtom } from 'jotai';
|
|
|
3
3
|
import { enviveConfigAtom } from 'src/atoms/envive/enviveConfig';
|
|
4
4
|
import Logger from 'src/application/logging/logger';
|
|
5
5
|
import { OrgConfigFeatureGate } from 'src/application/models';
|
|
6
|
+
import { AddToCartCallback } from 'src/types/enviveConfig';
|
|
6
7
|
|
|
7
8
|
const logger = new Logger('enviveConfigContext');
|
|
8
9
|
|
|
@@ -24,6 +25,7 @@ interface EnviveConfigProviderProps {
|
|
|
24
25
|
publicKey?: string;
|
|
25
26
|
featureOverrides?: Record<string, boolean>;
|
|
26
27
|
featureGates?: OrgConfigFeatureGate[];
|
|
28
|
+
addToCart?: AddToCartCallback;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export const EnviveConfigProvider: React.FC<EnviveConfigProviderProps> = ({
|
|
@@ -44,6 +46,7 @@ export const EnviveConfigProvider: React.FC<EnviveConfigProviderProps> = ({
|
|
|
44
46
|
publicKey,
|
|
45
47
|
featureOverrides,
|
|
46
48
|
featureGates,
|
|
49
|
+
addToCart,
|
|
47
50
|
}) => {
|
|
48
51
|
const setEnviveConfig = useSetAtom(enviveConfigAtom);
|
|
49
52
|
|
|
@@ -65,6 +68,7 @@ export const EnviveConfigProvider: React.FC<EnviveConfigProviderProps> = ({
|
|
|
65
68
|
publicKey,
|
|
66
69
|
featureOverrides,
|
|
67
70
|
featureGates,
|
|
71
|
+
addToCart,
|
|
68
72
|
}),
|
|
69
73
|
[
|
|
70
74
|
identifyingPrefix,
|
|
@@ -83,6 +87,7 @@ export const EnviveConfigProvider: React.FC<EnviveConfigProviderProps> = ({
|
|
|
83
87
|
publicKey,
|
|
84
88
|
featureOverrides,
|
|
85
89
|
featureGates,
|
|
90
|
+
addToCart,
|
|
86
91
|
],
|
|
87
92
|
);
|
|
88
93
|
|
|
@@ -7,6 +7,7 @@ import { resolvedBaseConfigVersionAtom } from 'src/atoms/envive/resolvedBaseConf
|
|
|
7
7
|
import { IHardcopyService } from 'src/services/hardcopyService';
|
|
8
8
|
import { IUserIdentityService } from 'src/services/userIdentityService';
|
|
9
9
|
import Logger from 'src/application/logging/logger';
|
|
10
|
+
import { AddToCartCallback } from 'src/types/enviveConfig';
|
|
10
11
|
import { AmplitudeProvider } from '../amplitudeContext';
|
|
11
12
|
import { EnviveConfigProvider } from '../enviveConfigContext';
|
|
12
13
|
import { EnviveCssProvider } from '../enviveCssContext';
|
|
@@ -51,8 +52,11 @@ interface EnviveProviderProps extends AgentWrapperProps {
|
|
|
51
52
|
enviveOn?: boolean;
|
|
52
53
|
cdnUrl?: string;
|
|
53
54
|
reactAppName?: string;
|
|
55
|
+
env?: string;
|
|
56
|
+
contextSource?: string;
|
|
54
57
|
previewMode?: boolean;
|
|
55
58
|
mockSalesAgentData?: any;
|
|
59
|
+
addToCart?: AddToCartCallback;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
const SearchAgentWrapper: React.FC<AgentWrapperProps> = ({ children, enabledAgents }) => {
|
|
@@ -100,7 +104,10 @@ export const EnviveProvider: React.FC<EnviveProviderProps> = ({
|
|
|
100
104
|
enviveOn,
|
|
101
105
|
cdnUrl,
|
|
102
106
|
reactAppName,
|
|
107
|
+
env,
|
|
108
|
+
contextSource,
|
|
103
109
|
identifyingPrefix,
|
|
110
|
+
addToCart,
|
|
104
111
|
}) => {
|
|
105
112
|
const { extensionService } = services;
|
|
106
113
|
const [enviveServiceConfig, setEnviveServiceConfig] = useState<EnviveServiceConfig | null>(null);
|
|
@@ -196,6 +203,9 @@ export const EnviveProvider: React.FC<EnviveProviderProps> = ({
|
|
|
196
203
|
enviveOn={enviveOn}
|
|
197
204
|
cdnUrl={cdnUrl}
|
|
198
205
|
reactAppName={reactAppName}
|
|
206
|
+
env={env}
|
|
207
|
+
contextSource={contextSource}
|
|
208
|
+
addToCart={addToCart}
|
|
199
209
|
>
|
|
200
210
|
<NewOrgConfigProvider config={enviveServiceConfig.orgConfig ?? {}}>
|
|
201
211
|
<LocalStorageProvider>
|