@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.
Files changed (170) hide show
  1. package/dist/application/commerce-api.d.cts +1 -1
  2. package/dist/application/commerce-api.d.ts +1 -1
  3. package/dist/atoms/app/index.d.cts +9 -9
  4. package/dist/atoms/app/index.d.ts +9 -9
  5. package/dist/atoms/app/variant.d.cts +8 -8
  6. package/dist/atoms/app/variant.d.ts +8 -8
  7. package/dist/atoms/chat/chatState.d.cts +20 -20
  8. package/dist/atoms/chat/chatState.d.ts +20 -20
  9. package/dist/atoms/chat/form.d.cts +2 -2
  10. package/dist/atoms/chat/form.d.ts +2 -2
  11. package/dist/atoms/chat/index.cjs +1 -1
  12. package/dist/atoms/chat/index.d.cts +3 -3
  13. package/dist/atoms/chat/index.d.ts +2 -2
  14. package/dist/atoms/chat/index.js +1 -1
  15. package/dist/atoms/chat/lastMessage.d.ts +2 -2
  16. package/dist/atoms/chat/messageQueue.d.cts +6 -6
  17. package/dist/atoms/chat/messageQueue.d.ts +6 -6
  18. package/dist/atoms/chat/performanceMetrics.d.ts +6 -6
  19. package/dist/atoms/chat/renderedWidgetRefs.d.cts +2 -2
  20. package/dist/atoms/chat/renderedWidgetRefs.d.ts +3 -3
  21. package/dist/atoms/chat/replies.d.ts +3 -3
  22. package/dist/atoms/chat/suggestions.d.cts +2 -2
  23. package/dist/atoms/chat/suggestions.d.ts +2 -2
  24. package/dist/atoms/envive/enviveConfig.d.cts +13 -13
  25. package/dist/atoms/envive/enviveConfig.d.ts +13 -13
  26. package/dist/atoms/globalSearch/globalSearch.d.cts +5 -5
  27. package/dist/atoms/globalSearch/globalSearch.d.ts +6 -6
  28. package/dist/atoms/org/customerService.d.cts +6 -6
  29. package/dist/atoms/org/customerService.d.ts +6 -6
  30. package/dist/atoms/org/graphqlConfig.d.cts +5 -5
  31. package/dist/atoms/org/graphqlConfig.d.ts +5 -5
  32. package/dist/atoms/org/index.cjs +2 -3
  33. package/dist/atoms/org/index.d.cts +2 -2
  34. package/dist/atoms/org/index.d.ts +2 -2
  35. package/dist/atoms/org/index.js +3 -3
  36. package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
  37. package/dist/atoms/org/newOrgConfigAtom.d.ts +2 -2
  38. package/dist/atoms/org/orgAnalyticsConfig.cjs +1 -3
  39. package/dist/atoms/org/orgAnalyticsConfig.d.cts +7 -8
  40. package/dist/atoms/org/orgAnalyticsConfig.d.ts +7 -8
  41. package/dist/atoms/org/orgAnalyticsConfig.js +2 -3
  42. package/dist/atoms/search/chatSearch.cjs +1 -1
  43. package/dist/atoms/search/chatSearch.d.cts +17 -17
  44. package/dist/atoms/search/chatSearch.d.ts +17 -17
  45. package/dist/atoms/search/chatSearch.js +1 -1
  46. package/dist/atoms/search/searchAPI.cjs +1 -1
  47. package/dist/atoms/search/searchAPI.d.cts +13 -13
  48. package/dist/atoms/search/searchAPI.d.ts +13 -13
  49. package/dist/atoms/search/searchAPI.js +1 -1
  50. package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
  51. package/dist/contexts/amplitudeContext/amplitudeContext.cjs +1 -5
  52. package/dist/contexts/amplitudeContext/amplitudeContext.js +1 -5
  53. package/dist/contexts/enviveConfigContext/enviveConfigContext.cjs +18 -23
  54. package/dist/contexts/enviveConfigContext/enviveConfigContext.d.cts +10 -12
  55. package/dist/contexts/enviveConfigContext/enviveConfigContext.d.ts +10 -12
  56. package/dist/contexts/enviveConfigContext/enviveConfigContext.js +18 -23
  57. package/dist/contexts/enviveContext/enviveContext.cjs +41 -74
  58. package/dist/contexts/enviveContext/enviveContext.d.cts +15 -32
  59. package/dist/contexts/enviveContext/enviveContext.d.ts +15 -32
  60. package/dist/contexts/enviveContext/enviveContext.js +41 -74
  61. package/dist/contexts/enviveContext/index.d.cts +2 -2
  62. package/dist/contexts/enviveContext/index.d.ts +2 -2
  63. package/dist/contexts/enviveCssContext/enviveCssContext.cjs +31 -16
  64. package/dist/contexts/enviveCssContext/enviveCssContext.js +31 -16
  65. package/dist/contexts/graphqlContext/graphqlContext.cjs +3 -212
  66. package/dist/contexts/graphqlContext/graphqlContext.d.cts +2 -10
  67. package/dist/contexts/graphqlContext/graphqlContext.d.ts +2 -10
  68. package/dist/contexts/graphqlContext/graphqlContext.js +3 -212
  69. package/dist/contexts/graphqlContext/mockV3Config.cjs +31 -16
  70. package/dist/contexts/graphqlContext/mockV3Config.js +31 -16
  71. package/dist/contexts/hardcopyContext/hardcopyContext.cjs +9 -238
  72. package/dist/contexts/hardcopyContext/hardcopyContext.d.cts +5 -17
  73. package/dist/contexts/hardcopyContext/hardcopyContext.d.ts +5 -17
  74. package/dist/contexts/hardcopyContext/hardcopyContext.js +9 -238
  75. package/dist/contexts/hardcopyContext/index.d.cts +3 -2
  76. package/dist/contexts/hardcopyContext/index.d.ts +3 -2
  77. package/dist/contexts/newOrgConfigContext/newOrgConfigContext.cjs +10 -32
  78. package/dist/contexts/newOrgConfigContext/newOrgConfigContext.d.cts +2 -2
  79. package/dist/contexts/newOrgConfigContext/newOrgConfigContext.d.ts +2 -2
  80. package/dist/contexts/newOrgConfigContext/newOrgConfigContext.js +12 -34
  81. package/dist/contexts/pageContext/mapping.d.cts +1 -1
  82. package/dist/contexts/pageContext/mapping.d.ts +1 -1
  83. package/dist/contexts/pageContext/types.d.cts +1 -1
  84. package/dist/contexts/salesAgentContext/chatAPI.cjs +2 -2
  85. package/dist/contexts/salesAgentContext/chatAPI.js +2 -2
  86. package/dist/contexts/salesAgentContext/salesAgentService.cjs +1 -1
  87. package/dist/contexts/salesAgentContext/salesAgentService.js +1 -1
  88. package/dist/contexts/searchContext/searchContext.cjs +1 -1
  89. package/dist/contexts/searchContext/searchContext.js +1 -1
  90. package/dist/contexts/systemSettingsContext/systemSettingsContext.d.cts +2 -2
  91. package/dist/contexts/types.d.cts +2 -2
  92. package/dist/contexts/types.d.ts +2 -2
  93. package/dist/contexts/typesV3.cjs +31 -16
  94. package/dist/contexts/typesV3.d.cts +62 -31
  95. package/dist/contexts/typesV3.d.ts +62 -31
  96. package/dist/contexts/typesV3.js +31 -16
  97. package/dist/contexts/userIdentityContext/userIdentityContext.cjs +1 -1
  98. package/dist/contexts/userIdentityContext/userIdentityContext.d.cts +3 -3
  99. package/dist/contexts/userIdentityContext/userIdentityContext.d.ts +3 -3
  100. package/dist/contexts/userIdentityContext/userIdentityContext.js +1 -1
  101. package/dist/hooks/ChatToggle/useChatToggle.cjs +1 -1
  102. package/dist/hooks/ChatToggle/useChatToggle.js +1 -1
  103. package/dist/hooks/GrabAndScroll/useGrabAndScroll.d.cts +2 -2
  104. package/dist/hooks/GraphQLConfig/index.cjs +0 -1
  105. package/dist/hooks/GraphQLConfig/index.d.cts +2 -2
  106. package/dist/hooks/GraphQLConfig/index.d.ts +2 -2
  107. package/dist/hooks/GraphQLConfig/index.js +2 -2
  108. package/dist/hooks/GraphQLConfig/useGraphQLConfig.cjs +7 -66
  109. package/dist/hooks/GraphQLConfig/useGraphQLConfig.d.cts +5 -13
  110. package/dist/hooks/GraphQLConfig/useGraphQLConfig.d.ts +5 -13
  111. package/dist/hooks/GraphQLConfig/useGraphQLConfig.js +8 -66
  112. package/dist/hooks/Search/useSearch.cjs +3 -3
  113. package/dist/hooks/Search/useSearch.js +3 -3
  114. package/dist/services/amplitudeService/amplitudeService.cjs +4 -3
  115. package/dist/services/amplitudeService/amplitudeService.d.cts +1 -2
  116. package/dist/services/amplitudeService/amplitudeService.d.ts +1 -2
  117. package/dist/services/amplitudeService/amplitudeService.js +4 -3
  118. package/dist/services/enviveConfigService/enviveConfigService.cjs +25 -5
  119. package/dist/services/enviveConfigService/enviveConfigService.d.cts +24 -5
  120. package/dist/services/enviveConfigService/enviveConfigService.d.ts +24 -5
  121. package/dist/services/enviveConfigService/enviveConfigService.js +25 -6
  122. package/dist/services/enviveConfigService/fetchGraphQLConfig.cjs +181 -0
  123. package/dist/services/enviveConfigService/fetchGraphQLConfig.js +180 -0
  124. package/dist/services/enviveConfigService/index.cjs +2 -1
  125. package/dist/services/enviveConfigService/index.d.cts +2 -2
  126. package/dist/services/enviveConfigService/index.d.ts +2 -2
  127. package/dist/services/enviveConfigService/index.js +2 -2
  128. package/dist/services/hardcopyService/hardcopyService.cjs +232 -0
  129. package/dist/services/hardcopyService/hardcopyService.d.cts +39 -0
  130. package/dist/services/hardcopyService/hardcopyService.d.ts +39 -0
  131. package/dist/services/hardcopyService/hardcopyService.js +229 -0
  132. package/dist/services/hardcopyService/index.cjs +5 -0
  133. package/dist/services/hardcopyService/index.d.cts +2 -0
  134. package/dist/services/hardcopyService/index.d.ts +2 -0
  135. package/dist/services/hardcopyService/index.js +3 -0
  136. package/dist/services/userIdentityService/index.cjs +1 -0
  137. package/dist/services/userIdentityService/index.d.cts +2 -2
  138. package/dist/services/userIdentityService/index.d.ts +2 -2
  139. package/dist/services/userIdentityService/index.js +2 -2
  140. package/dist/services/userIdentityService/userIdentityService.cjs +13 -1
  141. package/dist/services/userIdentityService/userIdentityService.d.cts +12 -2
  142. package/dist/services/userIdentityService/userIdentityService.d.ts +12 -2
  143. package/dist/services/userIdentityService/userIdentityService.js +13 -2
  144. package/dist/types/enviveConfig.d.cts +1 -1
  145. package/dist/types/enviveConfig.d.ts +1 -1
  146. package/package.json +5 -1
  147. package/src/atoms/org/orgAnalyticsConfig.ts +0 -5
  148. package/src/contexts/amplitudeContext/amplitudeContext.tsx +0 -4
  149. package/src/contexts/enviveConfigContext/enviveConfigContext.tsx +37 -49
  150. package/src/contexts/enviveContext/enviveContext.tsx +72 -134
  151. package/src/contexts/enviveCssContext/enviveCssContext.tsx +32 -17
  152. package/src/contexts/graphqlContext/__tests__/graphqlContext.test.tsx +3 -36
  153. package/src/contexts/graphqlContext/graphqlContext.tsx +4 -304
  154. package/src/contexts/graphqlContext/mockV3Config.ts +30 -15
  155. package/src/contexts/hardcopyContext/hardcopyContext.tsx +12 -270
  156. package/src/contexts/newOrgConfigContext/__tests__/newOrgConfigContext.test.tsx +54 -478
  157. package/src/contexts/newOrgConfigContext/newOrgConfigContext.tsx +9 -26
  158. package/src/contexts/typesV3.ts +61 -30
  159. package/src/contexts/userIdentityContext/userIdentityContext.tsx +2 -2
  160. package/src/hooks/GraphQLConfig/useGraphQLConfig.ts +2 -62
  161. package/src/hooks/Search/__tests__/useSearch.test.tsx +2 -2
  162. package/src/services/amplitudeService/__tests__/amplitudeService.test.ts +3 -5
  163. package/src/services/amplitudeService/amplitudeService.ts +5 -3
  164. package/src/services/enviveConfigService/__tests__/fetchGraphQLConfig.test.ts +425 -0
  165. package/src/services/enviveConfigService/enviveConfigService.ts +41 -13
  166. package/src/services/enviveConfigService/fetchGraphQLConfig.ts +225 -0
  167. package/src/services/hardcopyService/__tests__/hardcopyService.test.ts +367 -0
  168. package/src/services/hardcopyService/hardcopyService.ts +271 -0
  169. package/src/services/hardcopyService/index.ts +1 -0
  170. package/src/services/userIdentityService/userIdentityService.ts +18 -0
@@ -1,29 +1,12 @@
1
1
  import { ReactNode, createContext, useCallback, useContext, useMemo } from 'react';
2
2
  import { useAtomValue } from 'jotai';
3
3
  import { baseUrlAtom, orgLevelApiKeyAtom } from 'src/atoms/envive/enviveConfig';
4
- import { getMerchantOrgIdQuery } from 'src/application/models/graphql/queries/getMerchantOrgIdQuery';
5
- import { validateGraphQLOrgId } from 'src/application/models/validators/validateGraphQLOrgId';
6
4
  import { ColorMapping } from 'src/application/models/colorsConfig';
7
5
  import { FrontendConfig } from 'src/application/models/frontendConfig';
8
- import Logger from 'src/application/logging/logger';
9
- import {
10
- CamelCasedPropertiesDeep,
11
- transformSnakeToCamel,
12
- validateAndTransformMountingConfig,
13
- validateAndTransformPageVariants,
14
- } from 'src/application/models';
15
- import { getColorsAndFrontendQuery } from 'src/application/models/graphql/queries/getColorsAndFrontendQuery';
6
+ import { CamelCasedPropertiesDeep } from 'src/application/models';
16
7
  import { FrontendConfigV3 } from 'src/application/models/frontendConfigV3';
17
8
  import { ColorMappingV3 } from 'src/application/models/colorsConfigV3';
18
- import { FloatingButtonLocation } from '@envive-ai/react-toolkit-v3/FloatingButton';
19
- import { mockV3ColorsConfig, mockV3FrontendConfig } from './mockV3Config';
20
- import { ConfigVersionEnum, WidgetConfigV3 } from '../typesV3';
21
- import {
22
- OrgPageConfig,
23
- PageVariantConfig,
24
- PageVariantTestType,
25
- WidgetMountingConfig,
26
- } from '../types';
9
+ import { OrgPageConfig } from '../types';
27
10
 
28
11
  export type ColorsConfigResponse = CamelCasedPropertiesDeep<ColorMapping>;
29
12
  export type FrontendConfigResponse = CamelCasedPropertiesDeep<FrontendConfig>;
@@ -38,136 +21,16 @@ export type GraphQlConfigValues = {
38
21
 
39
22
  interface GraphQLContextValue {
40
23
  executeQuery: <T>(query: string, variables?: Record<string, unknown>) => Promise<T>;
41
- getOrgId: () => Promise<string | undefined>;
42
- getColorsAndFrontendConfig: () => Promise<GraphQlConfigValues>;
43
- getV3Config: () => Promise<GraphQlConfigValues>;
44
- getConfig: () => Promise<GraphQlConfigValues>;
45
24
  isReady: boolean;
46
25
  }
47
26
 
48
27
  const GraphQLContext = createContext<GraphQLContextValue | null>(null);
49
28
 
50
- const logger = new Logger('graphqlContext');
51
-
52
29
  type GraphQLProviderProps = {
53
30
  children: ReactNode;
54
- requestV3Config?: boolean;
55
- mockV3ConfigToDeprecatedConfig?: boolean;
56
31
  };
57
32
 
58
- const DEFAULT_PAGE_VARIANTS: PageVariantConfig[] = [
59
- {
60
- variantId: 'plp',
61
- variantType: 'plp',
62
- plpIdExtractor: 'url-resolver-plp-id',
63
- widgetMounting: [],
64
- variantTests: [
65
- {
66
- testType: PageVariantTestType.UrlResolver,
67
- },
68
- ],
69
- },
70
- {
71
- variantId: 'pdp',
72
- variantType: 'pdp',
73
- productIdExtractor: 'url-resolver-product-id',
74
- widgetMounting: [],
75
- variantTests: [
76
- {
77
- testType: PageVariantTestType.UrlResolver,
78
- },
79
- ],
80
- },
81
- ];
82
-
83
- const mapPositionToCamelCase = (position: string): FloatingButtonLocation => {
84
- if (position === 'bottom-left') {
85
- return FloatingButtonLocation.BOTTOM_LEFT;
86
- }
87
- if (position === 'middle-left') {
88
- return FloatingButtonLocation.MIDDLE_LEFT;
89
- }
90
- if (position === 'middle-right') {
91
- return FloatingButtonLocation.MIDDLE_RIGHT;
92
- }
93
- if (position === 'bottom-right') {
94
- return FloatingButtonLocation.BOTTOM_RIGHT;
95
- }
96
- throw new Error(`Invalid position: ${position}`);
97
- };
98
-
99
- /**
100
- * This function is used to do some additional cleanup of the v3 frontend config to ensure that the config is in the correct format.
101
- */
102
- const v3FrontendConfigCleanup = (
103
- v3RootConfig: FrontendConfigV3Response,
104
- ): FrontendConfigV3Response => {
105
- const { uiConfigs } = v3RootConfig;
106
- if (!uiConfigs) {
107
- return v3RootConfig;
108
- }
109
- const { floatingButton, lookAndFeel } = uiConfigs as any;
110
- if (!floatingButton || !lookAndFeel) {
111
- return v3RootConfig;
112
- }
113
- const { fontSize, lineHeight } = lookAndFeel.typography as any;
114
- return {
115
- ...v3RootConfig,
116
- uiConfigs: {
117
- ...uiConfigs,
118
- floatingButton: {
119
- ...floatingButton,
120
- position: mapPositionToCamelCase(
121
- v3RootConfig.uiConfigs?.floatingButton?.position as string,
122
- ),
123
- },
124
- lookAndFeel: {
125
- ...lookAndFeel,
126
- chatHeaderLogoDarkSrc: lookAndFeel.chatHeaderLogoDarkSrc || lookAndFeel.chatHeaderLogoSrc,
127
- chatHeaderLogoLightSrc: lookAndFeel.chatHeaderLogoLightSrc || lookAndFeel.chatHeaderLogoSrc,
128
- typography: {
129
- ...lookAndFeel.typography,
130
- fontSize: {
131
- // The fonts sizes are defined differently in the backend config
132
- // so we need to map the values to the correct camel case keys
133
- b1: fontSize?.b1 || fontSize?.b_1,
134
- b2: fontSize?.b2 || fontSize?.b_2,
135
- b3: fontSize?.b3 || fontSize?.b_3,
136
- b4: fontSize?.b4 || fontSize?.b_4,
137
- b5: fontSize?.b5 || fontSize?.b_5,
138
- h1: fontSize?.h1 || fontSize?.h_1,
139
- h2: fontSize?.h2 || fontSize?.h_2,
140
- h3: fontSize?.h3 || fontSize?.h_3,
141
- l1: fontSize?.l1 || fontSize?.l_1,
142
- l2: fontSize?.l2 || fontSize?.l_2,
143
- t1: fontSize?.t1 || fontSize?.t_1,
144
- t2: fontSize?.t2 || fontSize?.t_2,
145
- t3: fontSize?.t3 || fontSize?.t_3,
146
- },
147
- lineHeight: {
148
- ...lookAndFeel.typography.lineHeight,
149
- '114': lineHeight?.lh_114 || lineHeight?.[114],
150
- '116': lineHeight?.lh_116 || lineHeight?.[116],
151
- '118': lineHeight?.lh_118 || lineHeight?.[118],
152
- '120': lineHeight?.lh_120 || lineHeight?.[120],
153
- '124': lineHeight?.lh_124 || lineHeight?.[124],
154
- '128': lineHeight?.lh_128 || lineHeight?.[128],
155
- '130': lineHeight?.lh_130 || lineHeight?.[130],
156
- '133': lineHeight?.lh_133 || lineHeight?.[133],
157
- '140': lineHeight?.lh_140 || lineHeight?.[140],
158
- '148': lineHeight?.lh_148 || lineHeight?.[148],
159
- },
160
- },
161
- },
162
- },
163
- };
164
- };
165
-
166
- export const GraphQLProvider = ({
167
- children,
168
- requestV3Config = false,
169
- mockV3ConfigToDeprecatedConfig = false,
170
- }: GraphQLProviderProps) => {
33
+ export const GraphQLProvider = ({ children }: GraphQLProviderProps) => {
171
34
  const apiKey = useAtomValue(orgLevelApiKeyAtom);
172
35
  const baseUrl = useAtomValue(baseUrlAtom);
173
36
  const isReady = useMemo(() => Boolean(apiKey && baseUrl), [apiKey, baseUrl]);
@@ -201,170 +64,7 @@ export const GraphQLProvider = ({
201
64
  [apiKey, baseUrl, isReady],
202
65
  );
203
66
 
204
- const getOrgId = useCallback(async () => {
205
- const response = await executeQuery(getMerchantOrgIdQuery);
206
- return validateGraphQLOrgId(response.me.org?.id);
207
- }, [executeQuery]);
208
-
209
- const getV3Config = useCallback(async (): Promise<GraphQlConfigValues> => {
210
- try {
211
- const query = await getColorsAndFrontendQuery();
212
- if (!query) {
213
- throw new Error('Colors and frontend config query is not defined');
214
- }
215
- const response = await executeQuery(query);
216
-
217
- // We may update this root config location in the future
218
- const v3RootConfig = response.me.getProductsConfigByVersion?.v_three_config?.values;
219
- const frontendValues = response.me.getProductsConfigByVersion?.frontend?.values;
220
-
221
- const v3FrontendConfig = v3FrontendConfigCleanup(
222
- transformSnakeToCamel(v3RootConfig) as FrontendConfigV3Response,
223
- );
224
-
225
- // Get merchant_override_css from frontend.values if v3RootConfig is not available
226
- const frontendMerchantOverrideCss = frontendValues?.merchant_override_css;
227
- const v3MerchantOverrideCss = v3FrontendConfig.uiConfigs?.merchantOverrideCss;
228
- const merchantOverrideCss = v3MerchantOverrideCss || frontendMerchantOverrideCss;
229
-
230
- const v3MountingConfigsArray = (transformSnakeToCamel(v3RootConfig?.mounting_configs) ??
231
- []) as unknown as { key: string; config: WidgetMountingConfig }[];
232
-
233
- const v3MountingConfigs = v3MountingConfigsArray.reduce(
234
- (acc, { key, config }) => {
235
- acc[key] = validateAndTransformMountingConfig(config, key);
236
- return acc;
237
- },
238
- {} as Record<string, WidgetMountingConfig>,
239
- );
240
-
241
- const v3widgetConfigsArray = (transformSnakeToCamel(v3RootConfig?.widget_configs) ??
242
- []) as unknown as WidgetConfigV3[];
243
- const v3WidgetConfigs = Object.fromEntries(
244
- v3widgetConfigsArray?.map(({ widgetConfigId, ...rest }: WidgetConfigV3) => [
245
- widgetConfigId,
246
- { widgetConfigId, ...rest } as WidgetConfigV3,
247
- ]),
248
- ) as Record<string, WidgetConfigV3>;
249
- const v3pageVariants: PageVariantConfig[] = Array.isArray(v3RootConfig?.page_variants)
250
- ? v3RootConfig?.page_variants.map(validateAndTransformPageVariants)
251
- : DEFAULT_PAGE_VARIANTS;
252
-
253
- const v3ColorsConfig = transformSnakeToCamel(v3RootConfig?.colors?.values);
254
- const isSemanticColors = !window.location.href.includes('globals=merchant');
255
- const isStorybook = window.top?.location.href.includes('?path=');
256
-
257
- // If no v3 colors are found, return the default mock config to allow unconfigured merchants to work by default
258
- if (!v3RootConfig?.colors || (isStorybook && isSemanticColors)) {
259
- logger.logDebug('GraphQLContext | Returning mock v3 config', {
260
- colorsConfig: mockV3ColorsConfig,
261
- frontendConfig: mockV3FrontendConfig as FrontendConfigV3Response,
262
- });
263
- const colorsConfig = mockV3ColorsConfig;
264
- const frontendConfig = mockV3FrontendConfig;
265
- return {
266
- colorsConfig,
267
- frontendConfig: frontendConfig as FrontendConfigV3Response,
268
- orgPageConfig: {
269
- pageVariants: DEFAULT_PAGE_VARIANTS,
270
- widgetConfigs: {},
271
- mountingConfigs: {},
272
- },
273
- };
274
- }
275
-
276
- logger.logDebug('GraphQLContext | Returning v3 config', {
277
- colorsConfig: v3ColorsConfig as ColorsConfigV3Response,
278
- frontendConfig: v3FrontendConfig,
279
- orgPageConfig: {
280
- pageVariants: v3pageVariants,
281
- widgetConfigs: v3WidgetConfigs,
282
- mountingConfigs: v3MountingConfigs,
283
- },
284
- });
285
-
286
- return {
287
- colorsConfig: v3ColorsConfig as ColorsConfigV3Response,
288
- frontendConfig: {
289
- ...(v3FrontendConfig as FrontendConfigV3Response),
290
- merchantOverrideCss,
291
- // Need to replace the automatic widget configs with the object based ones
292
- widgetConfigs: v3WidgetConfigs,
293
- },
294
- orgPageConfig: {
295
- pageVariants: v3pageVariants,
296
- widgetConfigs: v3WidgetConfigs,
297
- mountingConfigs: v3MountingConfigs,
298
- },
299
- // TODO: Add widgets and other config here
300
- };
301
- } catch (err) {
302
- logger.logError('Error fetching graphql colors and frontend config', err);
303
- return { colorsConfig: undefined, frontendConfig: undefined };
304
- }
305
- }, [executeQuery, mockV3ConfigToDeprecatedConfig]);
306
-
307
- const getColorsAndFrontendConfig = useCallback(async (): Promise<GraphQlConfigValues> => {
308
- try {
309
- const query = await getColorsAndFrontendQuery();
310
- if (!query) {
311
- throw new Error('Colors and frontend config query is not defined');
312
- }
313
- const response = await executeQuery(query);
314
- if (
315
- response.me.getProductsConfigByVersion?.version !== ConfigVersionEnum.V3 &&
316
- !mockV3ConfigToDeprecatedConfig
317
- ) {
318
- const colorsConfig = response.me.getProductsConfigByVersion?.colors?.values;
319
- const frontendConfig = response.me.getProductsConfigByVersion?.frontend?.values;
320
- const transformedColorConfig = transformSnakeToCamel(colorsConfig);
321
- const transformedFrontendConfig = transformSnakeToCamel(frontendConfig);
322
- return {
323
- colorsConfig: transformedColorConfig as ColorsConfigResponse,
324
- frontendConfig: transformedFrontendConfig as FrontendConfigResponse,
325
- };
326
- }
327
- // TODO: REMOVE MOCKED CONFIG ONCE WE HAVE THE NEW CONFIG IMPLEMENTED ON BACKEND
328
- const merchantColorsConfig = response.me.getProductsConfigByVersion?.colors?.values;
329
- const transformedMerchantColorConfig = transformSnakeToCamel(merchantColorsConfig);
330
-
331
- const isSemanticColors = !window.location.href.includes('globals=merchant');
332
-
333
- const colorsConfig = mockV3ColorsConfig;
334
- const frontendConfig = mockV3FrontendConfig;
335
-
336
- return {
337
- colorsConfig: isSemanticColors
338
- ? (colorsConfig as ColorsConfigV3Response)
339
- : (transformedMerchantColorConfig as ColorsConfigV3Response),
340
- frontendConfig: frontendConfig as FrontendConfigV3Response,
341
- };
342
- } catch (err) {
343
- logger.logError('Error fetching graphql colors and frontend config', err);
344
- return { colorsConfig: undefined, frontendConfig: undefined };
345
- }
346
- }, [executeQuery]);
347
-
348
- const getConfig = useCallback(async (): Promise<GraphQlConfigValues> => {
349
- if (requestV3Config) {
350
- logger.logDebug('GraphQLContext | Getting v3 config', requestV3Config);
351
- return getV3Config();
352
- }
353
- logger.logDebug('GraphQLContext | Getting colors and frontend config', requestV3Config);
354
- return getColorsAndFrontendConfig();
355
- }, [getColorsAndFrontendConfig, getV3Config, requestV3Config]);
356
-
357
- const value = useMemo(
358
- () => ({
359
- executeQuery,
360
- getOrgId,
361
- getColorsAndFrontendConfig,
362
- getV3Config,
363
- getConfig,
364
- isReady,
365
- }),
366
- [executeQuery, getOrgId, getColorsAndFrontendConfig, getV3Config, getConfig, isReady],
367
- );
67
+ const value = useMemo(() => ({ executeQuery, isReady }), [executeQuery, isReady]);
368
68
 
369
69
  return <GraphQLContext.Provider value={value}>{children}</GraphQLContext.Provider>;
370
70
  };
@@ -90,25 +90,40 @@ export const mockV3FrontendConfig: FrontendConfigV3 = {
90
90
  l2: '12px',
91
91
  },
92
92
  fontWeight: {
93
- rg: '400',
94
- md: '500',
95
- sb: '600',
93
+ bodyEmphasis: '500',
94
+ bodyStandard: '400',
95
+ header: '600',
96
+ title: '500',
96
97
  },
97
98
  letterSpacing: {
98
- '0': '0em',
99
- 'wide-1': '1px',
99
+ t1: '0em',
100
+ t2: '0em',
101
+ t3: '0em',
102
+ h1: '0em',
103
+ h2: '0em',
104
+ h3: '0em',
105
+ b1: '0em',
106
+ b2: '0em',
107
+ b3: '0em',
108
+ b4: '0em',
109
+ b5: '0em',
110
+ l1: '1px',
111
+ l2: '1px',
100
112
  },
101
113
  lineHeight: {
102
- '124': 1.24,
103
- '120': 1.2,
104
- '118': 1.18,
105
- '116': 1.16,
106
- '114': 1.14,
107
- '148': 1.48,
108
- '140': 1.4,
109
- '128': 1.28,
110
- '130': 1.3,
111
- '133': 1.33,
114
+ t1: 1.24,
115
+ t2: 1.14,
116
+ t3: 1.18,
117
+ h1: 1.2,
118
+ h2: 1.24,
119
+ h3: 1.16,
120
+ b1: 1.2,
121
+ b2: 1.48,
122
+ b3: 1.4,
123
+ b4: 1.3,
124
+ b5: 1.3,
125
+ l1: 1.28,
126
+ l2: 1.33,
112
127
  },
113
128
  },
114
129
  },