@envive-ai/react-hooks 0.3.32 → 0.3.33
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.d.cts +1 -1
- package/dist/application/commerce-api.d.ts +1 -1
- package/dist/atoms/app/index.d.cts +9 -9
- package/dist/atoms/app/index.d.ts +9 -9
- package/dist/atoms/app/variant.d.cts +8 -8
- package/dist/atoms/app/variant.d.ts +8 -8
- package/dist/atoms/chat/chatState.d.cts +20 -20
- package/dist/atoms/chat/chatState.d.ts +20 -20
- 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 +3 -3
- package/dist/atoms/chat/index.d.ts +2 -2
- package/dist/atoms/chat/index.js +1 -1
- 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.ts +6 -6
- package/dist/atoms/chat/renderedWidgetRefs.d.cts +2 -2
- package/dist/atoms/chat/renderedWidgetRefs.d.ts +3 -3
- package/dist/atoms/chat/replies.d.ts +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 +13 -13
- package/dist/atoms/envive/enviveConfig.d.ts +13 -13
- package/dist/atoms/globalSearch/globalSearch.d.cts +5 -5
- package/dist/atoms/globalSearch/globalSearch.d.ts +6 -6
- 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 +5 -5
- package/dist/atoms/org/graphqlConfig.d.ts +5 -5
- package/dist/atoms/org/index.cjs +2 -3
- package/dist/atoms/org/index.d.cts +2 -2
- package/dist/atoms/org/index.d.ts +2 -2
- package/dist/atoms/org/index.js +3 -3
- package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
- package/dist/atoms/org/newOrgConfigAtom.d.ts +2 -2
- package/dist/atoms/org/orgAnalyticsConfig.cjs +1 -3
- package/dist/atoms/org/orgAnalyticsConfig.d.cts +7 -8
- package/dist/atoms/org/orgAnalyticsConfig.d.ts +7 -8
- package/dist/atoms/org/orgAnalyticsConfig.js +2 -3
- 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.ts +2 -2
- package/dist/contexts/amplitudeContext/amplitudeContext.cjs +1 -5
- package/dist/contexts/amplitudeContext/amplitudeContext.js +1 -5
- package/dist/contexts/enviveConfigContext/enviveConfigContext.cjs +18 -23
- package/dist/contexts/enviveConfigContext/enviveConfigContext.d.cts +10 -12
- package/dist/contexts/enviveConfigContext/enviveConfigContext.d.ts +10 -12
- package/dist/contexts/enviveConfigContext/enviveConfigContext.js +18 -23
- package/dist/contexts/enviveContext/enviveContext.cjs +41 -74
- package/dist/contexts/enviveContext/enviveContext.d.cts +15 -32
- package/dist/contexts/enviveContext/enviveContext.d.ts +15 -32
- package/dist/contexts/enviveContext/enviveContext.js +41 -74
- package/dist/contexts/enviveContext/index.d.cts +2 -2
- package/dist/contexts/enviveContext/index.d.ts +2 -2
- package/dist/contexts/enviveCssContext/enviveCssContext.cjs +31 -16
- package/dist/contexts/enviveCssContext/enviveCssContext.js +31 -16
- package/dist/contexts/graphqlContext/graphqlContext.cjs +3 -212
- package/dist/contexts/graphqlContext/graphqlContext.d.cts +2 -10
- package/dist/contexts/graphqlContext/graphqlContext.d.ts +2 -10
- package/dist/contexts/graphqlContext/graphqlContext.js +3 -212
- package/dist/contexts/graphqlContext/mockV3Config.cjs +31 -16
- package/dist/contexts/graphqlContext/mockV3Config.js +31 -16
- package/dist/contexts/hardcopyContext/hardcopyContext.cjs +9 -238
- package/dist/contexts/hardcopyContext/hardcopyContext.d.cts +5 -17
- package/dist/contexts/hardcopyContext/hardcopyContext.d.ts +5 -17
- package/dist/contexts/hardcopyContext/hardcopyContext.js +9 -238
- package/dist/contexts/hardcopyContext/index.d.cts +3 -2
- package/dist/contexts/hardcopyContext/index.d.ts +3 -2
- package/dist/contexts/newOrgConfigContext/newOrgConfigContext.cjs +10 -32
- package/dist/contexts/newOrgConfigContext/newOrgConfigContext.d.cts +2 -2
- package/dist/contexts/newOrgConfigContext/newOrgConfigContext.d.ts +2 -2
- package/dist/contexts/newOrgConfigContext/newOrgConfigContext.js +12 -34
- package/dist/contexts/pageContext/mapping.d.cts +1 -1
- package/dist/contexts/pageContext/mapping.d.ts +1 -1
- package/dist/contexts/pageContext/types.d.cts +1 -1
- package/dist/contexts/salesAgentContext/chatAPI.cjs +2 -2
- package/dist/contexts/salesAgentContext/chatAPI.js +2 -2
- package/dist/contexts/salesAgentContext/salesAgentService.cjs +1 -1
- package/dist/contexts/salesAgentContext/salesAgentService.js +1 -1
- 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/types.d.cts +2 -2
- package/dist/contexts/types.d.ts +2 -2
- package/dist/contexts/typesV3.cjs +31 -16
- package/dist/contexts/typesV3.d.cts +62 -31
- package/dist/contexts/typesV3.d.ts +62 -31
- package/dist/contexts/typesV3.js +31 -16
- package/dist/contexts/userIdentityContext/userIdentityContext.cjs +1 -1
- package/dist/contexts/userIdentityContext/userIdentityContext.d.cts +3 -3
- package/dist/contexts/userIdentityContext/userIdentityContext.d.ts +3 -3
- package/dist/contexts/userIdentityContext/userIdentityContext.js +1 -1
- package/dist/hooks/ChatToggle/useChatToggle.cjs +1 -1
- package/dist/hooks/ChatToggle/useChatToggle.js +1 -1
- package/dist/hooks/GrabAndScroll/useGrabAndScroll.d.cts +2 -2
- package/dist/hooks/GraphQLConfig/index.cjs +0 -1
- package/dist/hooks/GraphQLConfig/index.d.cts +2 -2
- package/dist/hooks/GraphQLConfig/index.d.ts +2 -2
- package/dist/hooks/GraphQLConfig/index.js +2 -2
- package/dist/hooks/GraphQLConfig/useGraphQLConfig.cjs +7 -66
- package/dist/hooks/GraphQLConfig/useGraphQLConfig.d.cts +5 -13
- package/dist/hooks/GraphQLConfig/useGraphQLConfig.d.ts +5 -13
- package/dist/hooks/GraphQLConfig/useGraphQLConfig.js +8 -66
- package/dist/hooks/Search/useSearch.cjs +3 -3
- package/dist/hooks/Search/useSearch.js +3 -3
- package/dist/services/amplitudeService/amplitudeService.cjs +4 -3
- package/dist/services/amplitudeService/amplitudeService.d.cts +1 -2
- package/dist/services/amplitudeService/amplitudeService.d.ts +1 -2
- package/dist/services/amplitudeService/amplitudeService.js +4 -3
- package/dist/services/enviveConfigService/enviveConfigService.cjs +25 -5
- package/dist/services/enviveConfigService/enviveConfigService.d.cts +24 -5
- package/dist/services/enviveConfigService/enviveConfigService.d.ts +24 -5
- package/dist/services/enviveConfigService/enviveConfigService.js +25 -6
- package/dist/services/enviveConfigService/fetchGraphQLConfig.cjs +181 -0
- package/dist/services/enviveConfigService/fetchGraphQLConfig.js +180 -0
- package/dist/services/enviveConfigService/index.cjs +2 -1
- package/dist/services/enviveConfigService/index.d.cts +2 -2
- package/dist/services/enviveConfigService/index.d.ts +2 -2
- package/dist/services/enviveConfigService/index.js +2 -2
- package/dist/services/hardcopyService/hardcopyService.cjs +232 -0
- package/dist/services/hardcopyService/hardcopyService.d.cts +39 -0
- package/dist/services/hardcopyService/hardcopyService.d.ts +39 -0
- package/dist/services/hardcopyService/hardcopyService.js +229 -0
- package/dist/services/hardcopyService/index.cjs +5 -0
- package/dist/services/hardcopyService/index.d.cts +2 -0
- package/dist/services/hardcopyService/index.d.ts +2 -0
- package/dist/services/hardcopyService/index.js +3 -0
- package/dist/services/userIdentityService/index.cjs +1 -0
- package/dist/services/userIdentityService/index.d.cts +2 -2
- package/dist/services/userIdentityService/index.d.ts +2 -2
- package/dist/services/userIdentityService/index.js +2 -2
- package/dist/services/userIdentityService/userIdentityService.cjs +13 -1
- package/dist/services/userIdentityService/userIdentityService.d.cts +12 -2
- package/dist/services/userIdentityService/userIdentityService.d.ts +12 -2
- package/dist/services/userIdentityService/userIdentityService.js +13 -2
- package/dist/types/enviveConfig.d.cts +1 -1
- package/dist/types/enviveConfig.d.ts +1 -1
- package/package.json +5 -1
- package/src/atoms/org/orgAnalyticsConfig.ts +0 -5
- package/src/contexts/amplitudeContext/amplitudeContext.tsx +0 -4
- package/src/contexts/enviveConfigContext/enviveConfigContext.tsx +37 -49
- package/src/contexts/enviveContext/enviveContext.tsx +72 -134
- package/src/contexts/enviveCssContext/enviveCssContext.tsx +32 -17
- package/src/contexts/graphqlContext/__tests__/graphqlContext.test.tsx +3 -36
- package/src/contexts/graphqlContext/graphqlContext.tsx +4 -304
- package/src/contexts/graphqlContext/mockV3Config.ts +30 -15
- package/src/contexts/hardcopyContext/hardcopyContext.tsx +12 -270
- package/src/contexts/newOrgConfigContext/__tests__/newOrgConfigContext.test.tsx +54 -478
- package/src/contexts/newOrgConfigContext/newOrgConfigContext.tsx +9 -26
- package/src/contexts/typesV3.ts +61 -30
- package/src/contexts/userIdentityContext/userIdentityContext.tsx +2 -2
- package/src/hooks/GraphQLConfig/useGraphQLConfig.ts +2 -62
- package/src/hooks/Search/__tests__/useSearch.test.tsx +2 -2
- package/src/services/amplitudeService/__tests__/amplitudeService.test.ts +3 -5
- package/src/services/amplitudeService/amplitudeService.ts +5 -3
- package/src/services/enviveConfigService/__tests__/fetchGraphQLConfig.test.ts +425 -0
- package/src/services/enviveConfigService/enviveConfigService.ts +41 -13
- package/src/services/enviveConfigService/fetchGraphQLConfig.ts +225 -0
- package/src/services/hardcopyService/__tests__/hardcopyService.test.ts +367 -0
- package/src/services/hardcopyService/hardcopyService.ts +271 -0
- package/src/services/hardcopyService/index.ts +1 -0
- package/src/services/userIdentityService/userIdentityService.ts +18 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { v4 as uuid } from 'uuid';
|
|
2
|
+
import CommerceApiClient from 'src/application/commerce-api';
|
|
3
|
+
import { WidgetString, WidgetText } from 'src/application/models/api/widgetText';
|
|
4
|
+
import { WidgetTextRequest } from 'src/application/models/api/widgetTextRequest';
|
|
5
|
+
import { toCamelCase } from 'src/application/models/utils/snakeToCamelTransformer';
|
|
6
|
+
import { getQueryParam } from 'src/application/utils';
|
|
7
|
+
import { UserEvent } from 'src/application/models';
|
|
8
|
+
import Logger from 'src/application/logging/logger';
|
|
9
|
+
import { AppDetails } from 'src/atoms/app';
|
|
10
|
+
import { WidgetTypeV3 } from 'src/contexts/typesV3';
|
|
11
|
+
import { EnviveMetricsEventName, TrackEventParams } from '../amplitudeService';
|
|
12
|
+
|
|
13
|
+
const logger = new Logger('hardcopyService');
|
|
14
|
+
|
|
15
|
+
export interface HardcopyRequest {
|
|
16
|
+
widgetType: WidgetTypeV3;
|
|
17
|
+
userEvent: UserEvent;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type HardcopyResponse = {
|
|
21
|
+
responseId: string;
|
|
22
|
+
language: string;
|
|
23
|
+
rawValues?: Record<string, WidgetString | WidgetString[]>;
|
|
24
|
+
values: Record<string, string | string[]>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface IHardcopyService {
|
|
28
|
+
getHardcopy(request: HardcopyRequest): Promise<HardcopyResponse>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface HardcopyServiceConfig {
|
|
32
|
+
getAppDetails: () => AppDetails;
|
|
33
|
+
getFeatureFlags: () => Record<string, boolean>;
|
|
34
|
+
trackEvent?: (params: TrackEventParams) => Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Sample responses used both as fallback when the backend fails and by MockHardcopyService.
|
|
38
|
+
export const MOCK_HARDCOPY_RESPONSE: Partial<Record<WidgetTypeV3, HardcopyResponse>> = {
|
|
39
|
+
[WidgetTypeV3.PromptCarouselV3]: {
|
|
40
|
+
responseId: uuid(),
|
|
41
|
+
language: 'en',
|
|
42
|
+
values: {
|
|
43
|
+
promptButtonTexts: [
|
|
44
|
+
'What are your best sellers?',
|
|
45
|
+
'Show me summer dresses',
|
|
46
|
+
'Do you have free shipping?',
|
|
47
|
+
'What sizes are available?',
|
|
48
|
+
'Can I return items?',
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
[WidgetTypeV3.TitledPromptCarouselV3]: {
|
|
53
|
+
responseId: 'mock-response-id',
|
|
54
|
+
language: 'en',
|
|
55
|
+
values: {
|
|
56
|
+
titleLabel: 'Need some help?',
|
|
57
|
+
promptButtonTexts: [
|
|
58
|
+
'What are your best sellers?',
|
|
59
|
+
'Show me summer dresses',
|
|
60
|
+
'Do you have free shipping?',
|
|
61
|
+
'What sizes are available?',
|
|
62
|
+
'Can I return items?',
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
[WidgetTypeV3.SocialProofV3]: {
|
|
67
|
+
responseId: 'mock-response-id',
|
|
68
|
+
language: 'en',
|
|
69
|
+
values: {
|
|
70
|
+
titleLabel: 'Shopping Assistant',
|
|
71
|
+
numberOfCustomersText: '123 customers',
|
|
72
|
+
customerQueryText: 'found what they were looking for...',
|
|
73
|
+
primaryButtonText: 'Start shopping',
|
|
74
|
+
secondaryButtonTitleText: 'Popular searches',
|
|
75
|
+
secondaryButtonTexts: [
|
|
76
|
+
'Why should I buy from you?',
|
|
77
|
+
'How do I return an item?',
|
|
78
|
+
'New arrivals',
|
|
79
|
+
'Sale items',
|
|
80
|
+
'Popular items',
|
|
81
|
+
],
|
|
82
|
+
textFieldPlaceholderText: 'Ask me anything...',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
[WidgetTypeV3.TypingAnimationV3]: {
|
|
86
|
+
responseId: 'mock-response-id',
|
|
87
|
+
language: 'en',
|
|
88
|
+
values: {
|
|
89
|
+
titleLabel: 'Shopping Assistant',
|
|
90
|
+
headlineText: 'Need help finding',
|
|
91
|
+
animatedTextSequence: [
|
|
92
|
+
'the perfect gift for your loved ones?',
|
|
93
|
+
'something special for the holidays?',
|
|
94
|
+
'the ideal present for someone special?',
|
|
95
|
+
],
|
|
96
|
+
hintText: 'Ask me anything',
|
|
97
|
+
promptButtonTexts: [
|
|
98
|
+
'What are your best sellers?',
|
|
99
|
+
'Show me summer dresses',
|
|
100
|
+
'Do you have free shipping?',
|
|
101
|
+
'What sizes are available?',
|
|
102
|
+
],
|
|
103
|
+
textFieldAriaLabel: 'Ask me anything',
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
[WidgetTypeV3.ChatPreviewComparisonV3]: {
|
|
107
|
+
responseId: 'mock-response-id',
|
|
108
|
+
language: 'en',
|
|
109
|
+
values: {
|
|
110
|
+
titleLabel: 'Shopping Assistant',
|
|
111
|
+
headlineText: 'Need help comparing?',
|
|
112
|
+
textFieldPlaceholderText: 'Ask me anything...',
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
[WidgetTypeV3.ChatPreviewLoadingV3]: {
|
|
116
|
+
responseId: 'mock-response-id',
|
|
117
|
+
language: 'en',
|
|
118
|
+
values: {
|
|
119
|
+
titleLabel: 'Shopping Assistant',
|
|
120
|
+
textFieldPlaceholderText: 'Ask me anything...',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
[WidgetTypeV3.ChatPreviewV3]: {
|
|
124
|
+
responseId: 'mock-response-id',
|
|
125
|
+
language: 'en',
|
|
126
|
+
values: {
|
|
127
|
+
titleLabel: 'Shopping Assistant',
|
|
128
|
+
textFieldPlaceholderText: 'Ask me anything...',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
[WidgetTypeV3.PromptButtonCarouselWithImageV3]: {
|
|
132
|
+
responseId: 'mock-response-id',
|
|
133
|
+
language: 'en',
|
|
134
|
+
values: {
|
|
135
|
+
titleLabel: 'Need some help?',
|
|
136
|
+
promptButtonsTexts: ['Help me find a product', "What's on your mind?", 'Talk to a human'],
|
|
137
|
+
textFieldPlaceholderText: 'Ask me anything...',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
[WidgetTypeV3.ProductCardV3]: {
|
|
141
|
+
responseId: 'mock-response-id',
|
|
142
|
+
language: 'en',
|
|
143
|
+
values: {
|
|
144
|
+
headline: 'Discover Your Perfect Style',
|
|
145
|
+
animatedText: [
|
|
146
|
+
'the perfect outfit for any occasion',
|
|
147
|
+
'trending fashion that fits your lifestyle',
|
|
148
|
+
'quality pieces that last',
|
|
149
|
+
],
|
|
150
|
+
prompts: [
|
|
151
|
+
'What are your best sellers?',
|
|
152
|
+
'Show me summer dresses',
|
|
153
|
+
'Do you have free shipping?',
|
|
154
|
+
'What sizes are available?',
|
|
155
|
+
'Can I return items?',
|
|
156
|
+
],
|
|
157
|
+
placeholder: 'Ask me anything...',
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
[WidgetTypeV3.FloatingChatV3]: {
|
|
161
|
+
responseId: 'mock-response-id',
|
|
162
|
+
language: 'en',
|
|
163
|
+
values: {
|
|
164
|
+
welcomeMessageTitle: 'Welcome to Envive AI',
|
|
165
|
+
welcomeMessageText:
|
|
166
|
+
'Your personal shopper trained on the collective knowledge of thousands of real experts!',
|
|
167
|
+
chatFooterTextFieldPlaceholderText: 'Ask me anything...',
|
|
168
|
+
disclaimerText: 'This is a disclaimer...',
|
|
169
|
+
leftToggleLabel: 'Shop with AI',
|
|
170
|
+
rightToggleLabel: 'Live support',
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
[WidgetTypeV3.FullPageSalesAgentV3]: {
|
|
174
|
+
responseId: 'mock-response-id',
|
|
175
|
+
language: 'en',
|
|
176
|
+
values: {
|
|
177
|
+
welcomeMessageTitle: 'Welcome to Envive AI',
|
|
178
|
+
welcomeMessageText:
|
|
179
|
+
'Your personal shopper trained on the collective knowledge of thousands of real experts!',
|
|
180
|
+
chatFooterTextFieldPlaceholderText: 'Ask me anything...',
|
|
181
|
+
disclaimerText: 'This is a disclaimer...',
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const convertToHardcopyResponse = (response: WidgetText): HardcopyResponse => ({
|
|
187
|
+
responseId: response.responseId,
|
|
188
|
+
language: response.language,
|
|
189
|
+
rawValues: response.values,
|
|
190
|
+
values: Object.fromEntries(
|
|
191
|
+
Object.entries(response.values).map(([key, value]) => [
|
|
192
|
+
toCamelCase(key),
|
|
193
|
+
value.length === 1 ? value[0].value : value.map(v => v.value),
|
|
194
|
+
]),
|
|
195
|
+
),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
export class HardcopyService implements IHardcopyService {
|
|
199
|
+
constructor(private config: HardcopyServiceConfig) {}
|
|
200
|
+
|
|
201
|
+
async getHardcopy(request: HardcopyRequest): Promise<HardcopyResponse> {
|
|
202
|
+
const overrideConfigVersion =
|
|
203
|
+
getQueryParam('spiffy_config_version') || getQueryParam('envive_config_version') || undefined;
|
|
204
|
+
|
|
205
|
+
const widgetTextRequest: WidgetTextRequest = {
|
|
206
|
+
requestId: uuid(),
|
|
207
|
+
widgetType: request.widgetType,
|
|
208
|
+
context: this.config.getAppDetails(),
|
|
209
|
+
featureFlags: this.config.getFeatureFlags(),
|
|
210
|
+
language: navigator.languages[0] || 'en',
|
|
211
|
+
overrideConfigVersion,
|
|
212
|
+
url: window.location.href,
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
this.config.trackEvent?.({
|
|
216
|
+
eventName: EnviveMetricsEventName.WidgetTextRequest,
|
|
217
|
+
eventProps: {
|
|
218
|
+
widget_type: request.widgetType,
|
|
219
|
+
request_id: widgetTextRequest.requestId,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
try {
|
|
224
|
+
const response = await CommerceApiClient.getHardcopy(widgetTextRequest);
|
|
225
|
+
if (response) {
|
|
226
|
+
const convertedResponse = convertToHardcopyResponse(response);
|
|
227
|
+
logger.logDebug('converted response', convertedResponse);
|
|
228
|
+
this.config.trackEvent?.({
|
|
229
|
+
eventName: EnviveMetricsEventName.WidgetTextResponse,
|
|
230
|
+
eventProps: {
|
|
231
|
+
widget_type: request.widgetType,
|
|
232
|
+
response_id: response.responseId,
|
|
233
|
+
widget_text: response.values,
|
|
234
|
+
request_id: widgetTextRequest.requestId,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
return convertedResponse;
|
|
238
|
+
}
|
|
239
|
+
} catch (error) {
|
|
240
|
+
logger.logError('error getting hardcopy from backend', error);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const mockResponse = MOCK_HARDCOPY_RESPONSE[request.widgetType];
|
|
244
|
+
if (mockResponse) {
|
|
245
|
+
logger.logDebug('no real response, using mock', mockResponse);
|
|
246
|
+
return mockResponse;
|
|
247
|
+
}
|
|
248
|
+
throw new Error(`No hardcopy response found for widget type: ${request.widgetType}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export class MockHardcopyService implements IHardcopyService {
|
|
253
|
+
constructor(private overrides: Partial<Record<WidgetTypeV3, HardcopyResponse>> = {}) {}
|
|
254
|
+
|
|
255
|
+
async getHardcopy(request: HardcopyRequest): Promise<HardcopyResponse> {
|
|
256
|
+
const fallbackWidgetType =
|
|
257
|
+
request.widgetType === WidgetTypeV3.ProductCardV3
|
|
258
|
+
? WidgetTypeV3.ImagePromptCardV3
|
|
259
|
+
: request.widgetType;
|
|
260
|
+
|
|
261
|
+
const response =
|
|
262
|
+
this.overrides[request.widgetType] ??
|
|
263
|
+
this.overrides[fallbackWidgetType] ??
|
|
264
|
+
MOCK_HARDCOPY_RESPONSE[request.widgetType];
|
|
265
|
+
|
|
266
|
+
if (!response) {
|
|
267
|
+
throw new Error(`No hardcopy response found for widget type: ${request.widgetType}`);
|
|
268
|
+
}
|
|
269
|
+
return response;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hardcopyService';
|
|
@@ -6,6 +6,11 @@ import { ExecutionContext } from '@envive-ai/analytics/dist/analytics/EnviveAnal
|
|
|
6
6
|
|
|
7
7
|
const logger = new Logger('userIdentityService');
|
|
8
8
|
|
|
9
|
+
export interface IUserIdentityService {
|
|
10
|
+
getUserIdOrDefault(): Promise<string>;
|
|
11
|
+
initializeUser(atomStore?: ReturnType<typeof getAtomStore>): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
type UserIdentityServiceProps = {
|
|
10
15
|
apiKey: string;
|
|
11
16
|
};
|
|
@@ -62,3 +67,16 @@ export class UserIdentityService {
|
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
}
|
|
70
|
+
|
|
71
|
+
export class MockUserIdentityService {
|
|
72
|
+
constructor(private readonly userId: string = 'mock-user-id') {}
|
|
73
|
+
|
|
74
|
+
async getUserIdOrDefault(): Promise<string> {
|
|
75
|
+
return this.userId;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async initializeUser(atomStore?: ReturnType<typeof getAtomStore>): Promise<void> {
|
|
79
|
+
const store = atomStore || getAtomStore();
|
|
80
|
+
store.set(userIdAtom, this.userId);
|
|
81
|
+
}
|
|
82
|
+
}
|