@envive-ai/react-hooks 0.3.17 → 0.3.19
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 +14 -13
- package/dist/application/commerce-api.js +14 -13
- package/dist/application/logging/logger.cjs +16 -10
- package/dist/application/logging/logger.js +16 -10
- package/dist/application/models/guards/api/isApiFormResponse.cjs +9 -8
- package/dist/application/models/guards/api/isApiFormResponse.js +9 -8
- package/dist/application/models/guards/api/isApiFormSubmittedResponseAttributes.cjs +6 -5
- package/dist/application/models/guards/api/isApiFormSubmittedResponseAttributes.js +6 -5
- package/dist/application/models/guards/api/isApiOrderResponseAttributes.cjs +19 -18
- package/dist/application/models/guards/api/isApiOrderResponseAttributes.js +19 -18
- package/dist/application/models/guards/api/isApiOrgConfigResults.cjs +27 -26
- package/dist/application/models/guards/api/isApiOrgConfigResults.js +27 -26
- package/dist/application/models/guards/api/isApiOrganizationConfig.cjs +23 -22
- package/dist/application/models/guards/api/isApiOrganizationConfig.js +23 -22
- package/dist/application/models/guards/api/isApiProductResponseAttributes.cjs +12 -11
- package/dist/application/models/guards/api/isApiProductResponseAttributes.js +12 -11
- package/dist/application/models/guards/api/isApiResponse.cjs +7 -6
- package/dist/application/models/guards/api/isApiResponse.js +7 -6
- package/dist/application/models/guards/graphQL/isGraphQLColorsConfig.cjs +5 -4
- package/dist/application/models/guards/graphQL/isGraphQLColorsConfig.js +5 -4
- package/dist/application/models/validators/validateGraphQLFrontendConfig.cjs +15 -14
- package/dist/application/models/validators/validateGraphQLFrontendConfig.js +15 -14
- package/dist/application/utils/analyticsUtils.cjs +4 -3
- package/dist/application/utils/analyticsUtils.js +4 -3
- package/dist/application/utils/nextMessageRequestToApiRequest.cjs +3 -1
- package/dist/application/utils/nextMessageRequestToApiRequest.js +3 -1
- package/dist/application/utils/widgetTextRequestToApiRequest.cjs +2 -2
- package/dist/application/utils/widgetTextRequestToApiRequest.js +2 -2
- package/dist/atoms/app/index.d.cts +7 -7
- package/dist/atoms/app/variant.cjs +3 -2
- package/dist/atoms/app/variant.js +3 -2
- package/dist/atoms/chat/chatState.d.cts +18 -18
- package/dist/atoms/chat/chatState.d.ts +18 -18
- package/dist/atoms/chat/form.d.cts +2 -2
- package/dist/atoms/chat/form.d.ts +2 -2
- package/dist/atoms/chat/index.d.cts +2 -2
- package/dist/atoms/chat/index.d.ts +2 -2
- 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.cjs +3 -2
- package/dist/atoms/chat/performanceMetrics.d.cts +6 -6
- package/dist/atoms/chat/performanceMetrics.d.ts +6 -6
- package/dist/atoms/chat/performanceMetrics.js +3 -2
- 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 +2 -2
- 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.cjs +5 -4
- package/dist/atoms/envive/enviveConfig.d.cts +13 -13
- package/dist/atoms/envive/enviveConfig.d.ts +13 -13
- package/dist/atoms/envive/enviveConfig.js +5 -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.d.cts +4 -4
- package/dist/atoms/org/graphqlConfig.d.ts +4 -4
- 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 +5 -5
- package/dist/atoms/org/orgAnalyticsConfig.d.ts +5 -5
- package/dist/atoms/search/chatSearch.d.cts +17 -17
- package/dist/atoms/search/chatSearch.d.ts +17 -17
- package/dist/atoms/search/searchAPI.d.cts +13 -13
- package/dist/atoms/search/searchAPI.d.ts +13 -13
- package/dist/atoms/widget/chatPreviewLoading.d.cts +2 -2
- package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
- package/dist/contexts/amplitudeContext/amplitudeContext.cjs +4 -3
- package/dist/contexts/amplitudeContext/amplitudeContext.js +3 -2
- package/dist/contexts/enviveConfigContext/enviveConfigContext.cjs +26 -15
- package/dist/contexts/enviveConfigContext/enviveConfigContext.d.cts +2 -4
- package/dist/contexts/enviveConfigContext/enviveConfigContext.d.ts +2 -4
- package/dist/contexts/enviveConfigContext/enviveConfigContext.js +29 -16
- package/dist/contexts/enviveConfigContext/index.cjs +2 -1
- package/dist/contexts/enviveConfigContext/index.d.cts +2 -1
- package/dist/contexts/enviveConfigContext/index.d.ts +2 -1
- package/dist/contexts/enviveConfigContext/index.js +2 -1
- package/dist/contexts/enviveConfigContext/useEnviveConfig.cjs +12 -0
- package/dist/contexts/enviveConfigContext/useEnviveConfig.d.cts +7 -0
- package/dist/contexts/enviveConfigContext/useEnviveConfig.d.ts +7 -0
- package/dist/contexts/enviveConfigContext/useEnviveConfig.js +11 -0
- package/dist/contexts/enviveContext/WindowChatToggleBinder.cjs +7 -5
- package/dist/contexts/enviveContext/WindowChatToggleBinder.js +6 -4
- package/dist/contexts/enviveContext/enviveContext.cjs +34 -39
- package/dist/contexts/enviveContext/enviveContext.js +35 -40
- package/dist/contexts/featureFlagServiceContext/featureFlagServiceContext.cjs +7 -6
- package/dist/contexts/featureFlagServiceContext/featureFlagServiceContext.js +7 -6
- package/dist/contexts/graphqlContext/graphqlContext.cjs +8 -7
- package/dist/contexts/graphqlContext/graphqlContext.js +8 -7
- package/dist/contexts/hardcopyContext/hardcopyContext.cjs +9 -8
- package/dist/contexts/hardcopyContext/hardcopyContext.js +9 -8
- package/dist/contexts/localStorageContext/localStorageContext.cjs +4 -3
- package/dist/contexts/localStorageContext/localStorageContext.js +4 -3
- package/dist/contexts/pageContext/pageContext.cjs +3 -2
- package/dist/contexts/pageContext/pageContext.js +3 -2
- package/dist/contexts/salesAgentContext/chatAPI.cjs +3 -2
- package/dist/contexts/salesAgentContext/chatAPI.js +3 -2
- package/dist/contexts/salesAgentContext/salesAgentContext.cjs +4 -3
- package/dist/contexts/salesAgentContext/salesAgentContext.js +4 -3
- package/dist/contexts/salesAgentContext/salesAgentService.cjs +3 -2
- package/dist/contexts/salesAgentContext/salesAgentService.js +3 -2
- package/dist/contexts/searchContext/searchContext.cjs +8 -6
- package/dist/contexts/searchContext/searchContext.js +7 -5
- package/dist/contexts/sessionStorageContext/sessionStorageContext.cjs +3 -2
- package/dist/contexts/sessionStorageContext/sessionStorageContext.js +3 -2
- package/dist/contexts/systemSettingsContext/systemSettingsContext.d.cts +2 -2
- package/dist/contexts/types.d.cts +1 -1
- package/dist/contexts/types.d.ts +1 -1
- package/dist/contexts/typesV3.d.cts +1 -1
- package/dist/contexts/typesV3.d.ts +1 -1
- package/dist/contexts/uiConfigContext/index.cjs +0 -1
- package/dist/contexts/uiConfigContext/index.d.cts +2 -2
- package/dist/contexts/uiConfigContext/index.d.ts +2 -2
- package/dist/contexts/uiConfigContext/index.js +2 -2
- package/dist/contexts/uiConfigContext/uiConfigContext.cjs +13 -30
- package/dist/contexts/uiConfigContext/uiConfigContext.d.cts +5 -9
- package/dist/contexts/uiConfigContext/uiConfigContext.d.ts +5 -9
- package/dist/contexts/uiConfigContext/uiConfigContext.js +14 -29
- package/dist/contexts/userIdentityContext/userIdentityContext.cjs +7 -7
- package/dist/contexts/userIdentityContext/userIdentityContext.js +7 -7
- package/dist/contexts/widgetConfigContext/widgetConfigContext.cjs +4 -3
- package/dist/contexts/widgetConfigContext/widgetConfigContext.js +4 -3
- package/dist/hooks/CustomerSupportHandoff/useCustomerSupportHandoff.cjs +4 -3
- package/dist/hooks/CustomerSupportHandoff/useCustomerSupportHandoff.js +4 -3
- package/dist/hooks/SystemSettingsContext/useSystemSettingsContext.d.cts +2 -2
- package/dist/hooks/WidgetInteraction/useWidgetInteraction.cjs +2 -2
- package/dist/hooks/WidgetInteraction/useWidgetInteraction.js +2 -2
- package/dist/hooks/WidgetInteraction/utils.cjs +2 -1
- package/dist/hooks/WidgetInteraction/utils.js +2 -1
- package/dist/hooks/utils.d.ts +1 -1
- package/dist/services/amplitudeService/amplitudeService.cjs +8 -7
- package/dist/services/amplitudeService/amplitudeService.js +8 -7
- package/dist/services/ga4ProjectionService/ga4ProjectionService.cjs +3 -2
- package/dist/services/ga4ProjectionService/ga4ProjectionService.js +3 -2
- package/dist/services/userIdentityService/userIdentityService.cjs +8 -7
- package/dist/services/userIdentityService/userIdentityService.js +8 -7
- package/package.json +2 -2
- package/src/application/commerce-api.ts +14 -12
- package/src/application/logging/logger.ts +33 -8
- package/src/application/models/guards/api/isApiFormResponse.ts +9 -7
- package/src/application/models/guards/api/isApiFormSubmittedResponseAttributes.ts +6 -4
- package/src/application/models/guards/api/isApiOrderResponseAttributes.ts +19 -17
- package/src/application/models/guards/api/isApiOrgConfigResults.ts +40 -48
- package/src/application/models/guards/api/isApiOrganizationConfig.ts +25 -38
- package/src/application/models/guards/api/isApiProductResponseAttributes.ts +12 -10
- package/src/application/models/guards/api/isApiResponse.ts +7 -5
- package/src/application/models/guards/graphQL/isGraphQLColorsConfig.ts +5 -3
- package/src/application/models/validators/validateGraphQLFrontendConfig.ts +15 -13
- package/src/application/utils/analyticsUtils.ts +4 -4
- package/src/application/utils/nextMessageRequestToApiRequest.ts +2 -0
- package/src/application/utils/widgetTextRequestToApiRequest.ts +1 -2
- package/src/atoms/app/variant.ts +3 -1
- package/src/atoms/chat/performanceMetrics.ts +3 -1
- package/src/atoms/envive/enviveConfig.ts +5 -3
- package/src/contexts/amplitudeContext/amplitudeContext.tsx +1 -1
- package/src/contexts/enviveConfigContext/__tests__/enviveConfigContext.test.tsx +4 -3
- package/src/contexts/enviveConfigContext/enviveConfigContext.tsx +50 -35
- package/src/contexts/enviveConfigContext/index.ts +1 -0
- package/src/contexts/enviveConfigContext/useEnviveConfig.ts +9 -0
- package/src/contexts/enviveContext/WindowChatToggleBinder.tsx +6 -4
- package/src/contexts/enviveContext/enviveContext.tsx +40 -45
- package/src/contexts/featureFlagServiceContext/featureFlagServiceContext.tsx +11 -12
- package/src/contexts/graphqlContext/__tests__/graphqlContext.test.tsx +4 -4
- package/src/contexts/graphqlContext/graphqlContext.tsx +8 -6
- package/src/contexts/hardcopyContext/hardcopyContext.tsx +9 -7
- package/src/contexts/localStorageContext/__tests__/localStorageContext.test.tsx +6 -6
- package/src/contexts/localStorageContext/localStorageContext.tsx +4 -2
- package/src/contexts/pageContext/__tests__/pageContext.test.tsx +5 -5
- package/src/contexts/pageContext/pageContext.tsx +3 -1
- package/src/contexts/salesAgentContext/chatAPI.ts +5 -5
- package/src/contexts/salesAgentContext/salesAgentContext.tsx +4 -2
- package/src/contexts/salesAgentContext/salesAgentService.ts +4 -2
- package/src/contexts/searchContext/__tests__/searchContext.test.tsx +15 -12
- package/src/contexts/searchContext/searchContext.tsx +6 -4
- package/src/contexts/sessionStorageContext/sessionStorageContext.tsx +3 -1
- package/src/contexts/uiConfigContext/__tests__/uiConfigContext.test.tsx +7 -32
- package/src/contexts/uiConfigContext/uiConfigContext.tsx +17 -29
- package/src/contexts/userIdentityContext/__tests__/userIdentityContext.test.tsx +5 -5
- package/src/contexts/userIdentityContext/userIdentityContext.tsx +7 -6
- package/src/contexts/widgetConfigContext/__tests__/widgetConfigContext.test.tsx +7 -7
- package/src/contexts/widgetConfigContext/widgetConfigContext.tsx +4 -2
- package/src/hooks/CustomerSupportHandoff/useCustomerSupportHandoff.ts +4 -2
- package/src/hooks/Search/__tests__/useSearch.test.tsx +14 -8
- package/src/hooks/WidgetInteraction/useWidgetInteraction.ts +3 -2
- package/src/hooks/WidgetInteraction/utils.ts +3 -1
- package/src/services/amplitudeService/__tests__/amplitudeService.test.ts +3 -3
- package/src/services/amplitudeService/amplitudeService.ts +8 -6
- package/src/services/ga4ProjectionService/ga4ProjectionService.ts +3 -1
- package/src/services/userIdentityService/userIdentityService.ts +8 -8
|
@@ -5,6 +5,8 @@ import Logger from 'src/application/logging/logger';
|
|
|
5
5
|
|
|
6
6
|
const FEATURE_FLAGS_STORAGE_KEY = 'spiffy-feature-flags';
|
|
7
7
|
|
|
8
|
+
const logger = new Logger('featureFlagServiceContext');
|
|
9
|
+
|
|
8
10
|
export interface FullFlagValue {
|
|
9
11
|
resolved: boolean;
|
|
10
12
|
initial: boolean | undefined;
|
|
@@ -66,10 +68,7 @@ export class FeatureFlagService {
|
|
|
66
68
|
const featureFlagsObj = JSON.parse(featureFlags) as Record<string, boolean>;
|
|
67
69
|
return featureFlagsObj[featureGate];
|
|
68
70
|
} catch (err) {
|
|
69
|
-
|
|
70
|
-
'[spiffy-ai] getStoredFeatureGateOverrides: error parsing feature flags',
|
|
71
|
-
err,
|
|
72
|
-
);
|
|
71
|
+
logger.logError('getStoredFeatureGateOverrides: error parsing feature flags', err);
|
|
73
72
|
return undefined;
|
|
74
73
|
}
|
|
75
74
|
}
|
|
@@ -77,24 +76,24 @@ export class FeatureFlagService {
|
|
|
77
76
|
static getFeatureFlagOverride(featureGate: FeatureGates): boolean | undefined {
|
|
78
77
|
const queryOverride = FeatureFlagService.getQueryParamFeatureGateOverrides(featureGate);
|
|
79
78
|
if (queryOverride != null) {
|
|
80
|
-
|
|
81
|
-
`
|
|
79
|
+
logger.logDebug(
|
|
80
|
+
`isFeatureGateEnabled featureGate:${featureGate} overridden by URL param. New value: ${queryOverride}`,
|
|
82
81
|
);
|
|
83
82
|
return queryOverride;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
const windowOverride = FeatureFlagService.getWindowFeatureGateOverrides(featureGate);
|
|
87
86
|
if (windowOverride != null) {
|
|
88
|
-
|
|
89
|
-
`
|
|
87
|
+
logger.logDebug(
|
|
88
|
+
`isFeatureGateEnabled featureGate:${featureGate} overridden by window param. New value: ${windowOverride}`,
|
|
90
89
|
);
|
|
91
90
|
return windowOverride;
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
const storedOverride = FeatureFlagService.getStoredFeatureGateOverrides(featureGate);
|
|
95
94
|
if (storedOverride != null) {
|
|
96
|
-
|
|
97
|
-
`
|
|
95
|
+
logger.logDebug(
|
|
96
|
+
`isFeatureGateEnabled featureGate:${featureGate} overridden by stored value. New value: ${storedOverride}`,
|
|
98
97
|
);
|
|
99
98
|
return storedOverride;
|
|
100
99
|
}
|
|
@@ -111,8 +110,8 @@ export class FeatureFlagService {
|
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
if (gateValue == null || gateValue.value == null) {
|
|
114
|
-
|
|
115
|
-
`
|
|
113
|
+
logger.logDebug(
|
|
114
|
+
`isFeatureGateEnabled featureGate:${featureGate} value is undefined - returning false`,
|
|
116
115
|
);
|
|
117
116
|
return false;
|
|
118
117
|
}
|
|
@@ -8,9 +8,9 @@ import { getMerchantOrgIdQuery } from 'src/application/models/graphql/queries/ge
|
|
|
8
8
|
import { GraphQLProvider, useGraphQLClient } from '../graphqlContext';
|
|
9
9
|
|
|
10
10
|
// Mock the Logger to avoid console output in tests
|
|
11
|
-
vi.spyOn(Logger, 'logDebug').mockImplementation(() => {});
|
|
12
|
-
vi.spyOn(Logger, 'logWarn').mockImplementation(() => {});
|
|
13
|
-
vi.spyOn(Logger, 'logError').mockImplementation(() => {});
|
|
11
|
+
vi.spyOn(Logger.prototype, 'logDebug').mockImplementation(() => {});
|
|
12
|
+
vi.spyOn(Logger.prototype, 'logWarn').mockImplementation(() => {});
|
|
13
|
+
vi.spyOn(Logger.prototype, 'logError').mockImplementation(() => {});
|
|
14
14
|
|
|
15
15
|
// Mock fetch globally
|
|
16
16
|
global.fetch = vi.fn();
|
|
@@ -625,7 +625,7 @@ describe('GraphQLProvider', () => {
|
|
|
625
625
|
});
|
|
626
626
|
|
|
627
627
|
it('should handle errors and return undefined configs', async () => {
|
|
628
|
-
const logErrorSpy = vi.spyOn(Logger, 'logError');
|
|
628
|
+
const logErrorSpy = vi.spyOn(Logger.prototype, 'logError');
|
|
629
629
|
|
|
630
630
|
(global.fetch as any).mockRejectedValueOnce(new Error('Network error'));
|
|
631
631
|
|
|
@@ -47,6 +47,8 @@ interface GraphQLContextValue {
|
|
|
47
47
|
|
|
48
48
|
const GraphQLContext = createContext<GraphQLContextValue | null>(null);
|
|
49
49
|
|
|
50
|
+
const logger = new Logger('graphqlContext');
|
|
51
|
+
|
|
50
52
|
type GraphQLProviderProps = {
|
|
51
53
|
children: ReactNode;
|
|
52
54
|
requestV3Config?: boolean;
|
|
@@ -254,7 +256,7 @@ export const GraphQLProvider = ({
|
|
|
254
256
|
|
|
255
257
|
// If the v3 root config is not found and we are configured to return the deprecated config, we will return the mocked config
|
|
256
258
|
if ((!v3RootConfig && mockV3ConfigToDeprecatedConfig) || (isStorybook && isSemanticColors)) {
|
|
257
|
-
|
|
259
|
+
logger.logDebug('GraphQLContext | Returning mock v3 config', {
|
|
258
260
|
colorsConfig: mockV3ColorsConfig as ColorsConfigV3Response,
|
|
259
261
|
frontendConfig: mockV3FrontendConfig as FrontendConfigV3Response,
|
|
260
262
|
});
|
|
@@ -273,7 +275,7 @@ export const GraphQLProvider = ({
|
|
|
273
275
|
};
|
|
274
276
|
}
|
|
275
277
|
|
|
276
|
-
|
|
278
|
+
logger.logDebug('GraphQLContext | Returning v3 config', {
|
|
277
279
|
colorsConfig: v3ColorsConfig as ColorsConfigV3Response,
|
|
278
280
|
frontendConfig: v3FrontendConfig as FrontendConfigV3Response,
|
|
279
281
|
orgPageConfig: {
|
|
@@ -299,7 +301,7 @@ export const GraphQLProvider = ({
|
|
|
299
301
|
// TODO: Add widgets and other config here
|
|
300
302
|
};
|
|
301
303
|
} catch (err) {
|
|
302
|
-
|
|
304
|
+
logger.logError('Error fetching graphql colors and frontend config', err);
|
|
303
305
|
return { colorsConfig: undefined, frontendConfig: undefined };
|
|
304
306
|
}
|
|
305
307
|
}, [executeQuery, mockV3ConfigToDeprecatedConfig]);
|
|
@@ -340,17 +342,17 @@ export const GraphQLProvider = ({
|
|
|
340
342
|
frontendConfig: frontendConfig as FrontendConfigV3Response,
|
|
341
343
|
};
|
|
342
344
|
} catch (err) {
|
|
343
|
-
|
|
345
|
+
logger.logError('Error fetching graphql colors and frontend config', err);
|
|
344
346
|
return { colorsConfig: undefined, frontendConfig: undefined };
|
|
345
347
|
}
|
|
346
348
|
}, [executeQuery]);
|
|
347
349
|
|
|
348
350
|
const getConfig = useCallback(async (): Promise<GraphQlConfigValues> => {
|
|
349
351
|
if (requestV3Config) {
|
|
350
|
-
|
|
352
|
+
logger.logDebug('GraphQLContext | Getting v3 config', requestV3Config);
|
|
351
353
|
return getV3Config();
|
|
352
354
|
}
|
|
353
|
-
|
|
355
|
+
logger.logDebug('GraphQLContext | Getting colors and frontend config', requestV3Config);
|
|
354
356
|
return getColorsAndFrontendConfig();
|
|
355
357
|
}, [getColorsAndFrontendConfig, getV3Config, requestV3Config]);
|
|
356
358
|
|
|
@@ -15,6 +15,8 @@ import { WidgetTypeV3 } from '../typesV3';
|
|
|
15
15
|
import { useFeatureFlagService } from '../featureFlagServiceContext/featureFlagServiceContext';
|
|
16
16
|
import { useAmplitude } from '../amplitudeContext';
|
|
17
17
|
|
|
18
|
+
const logger = new Logger('hardcopyContext');
|
|
19
|
+
|
|
18
20
|
interface HardcopyRequest {
|
|
19
21
|
widgetType: WidgetTypeV3;
|
|
20
22
|
userEvent: UserEvent;
|
|
@@ -218,7 +220,7 @@ export const HardcopyProvider: React.FC<HardcopyProviderProps> = ({
|
|
|
218
220
|
const getHardcopyFromBackend = useCallback(
|
|
219
221
|
async (request: HardcopyRequest): Promise<HardcopyResponse> => {
|
|
220
222
|
if (hardcopyOverride?.[request.widgetType]) {
|
|
221
|
-
|
|
223
|
+
logger.logDebug('using hardcopy override', request.widgetType);
|
|
222
224
|
return hardcopyOverride[request.widgetType]!;
|
|
223
225
|
}
|
|
224
226
|
const overrideConfigVersion =
|
|
@@ -245,7 +247,7 @@ export const HardcopyProvider: React.FC<HardcopyProviderProps> = ({
|
|
|
245
247
|
const response = await CommerceApiClient.getHardcopy(widgetTextRequest);
|
|
246
248
|
if (response) {
|
|
247
249
|
const convertedResponse = convertToHardcopyResponse(response);
|
|
248
|
-
|
|
250
|
+
logger.logDebug('converted response', convertedResponse);
|
|
249
251
|
trackEvent({
|
|
250
252
|
eventName: EnviveMetricsEventName.WidgetTextResponse,
|
|
251
253
|
eventProps: {
|
|
@@ -258,11 +260,11 @@ export const HardcopyProvider: React.FC<HardcopyProviderProps> = ({
|
|
|
258
260
|
return convertedResponse;
|
|
259
261
|
}
|
|
260
262
|
} catch (error) {
|
|
261
|
-
|
|
263
|
+
logger.logError('error getting hardcopy from backend', error);
|
|
262
264
|
}
|
|
263
265
|
const mockResponse = MOCK_HARDCOPY_RESPONSE[request.widgetType];
|
|
264
266
|
if (mockResponse) {
|
|
265
|
-
|
|
267
|
+
logger.logDebug('no real response, using mock', mockResponse);
|
|
266
268
|
return mockResponse;
|
|
267
269
|
}
|
|
268
270
|
throw new Error(`No hardcopy response found for widget type: ${request.widgetType}`);
|
|
@@ -273,11 +275,11 @@ export const HardcopyProvider: React.FC<HardcopyProviderProps> = ({
|
|
|
273
275
|
const getHardcopy = useCallback(
|
|
274
276
|
async (request: HardcopyRequest): Promise<HardcopyResponse> => {
|
|
275
277
|
setIsLoading(true);
|
|
276
|
-
|
|
278
|
+
logger.logDebug('retrieving hardcopy', languages);
|
|
277
279
|
|
|
278
|
-
|
|
280
|
+
logger.logDebug('request', request);
|
|
279
281
|
const response = await getHardcopyFromBackend(request);
|
|
280
|
-
|
|
282
|
+
logger.logDebug('returning hardcopy response', response);
|
|
281
283
|
if (!response) {
|
|
282
284
|
setIsLoading(false);
|
|
283
285
|
throw new Error(`No hardcopy response found for widget type: ${request.widgetType}`);
|
|
@@ -5,9 +5,9 @@ import { LocalStorageEventListener } from 'src/application/models/localStorageEv
|
|
|
5
5
|
import { LocalStorageKeys, LocalStorageProvider, useLocalStorage } from '../localStorageContext';
|
|
6
6
|
|
|
7
7
|
// Mock the Logger to avoid console output in tests
|
|
8
|
-
vi.spyOn(Logger, 'logDebug').mockImplementation(() => {});
|
|
9
|
-
vi.spyOn(Logger, 'logWarn').mockImplementation(() => {});
|
|
10
|
-
vi.spyOn(Logger, 'logError').mockImplementation(() => {});
|
|
8
|
+
vi.spyOn(Logger.prototype, 'logDebug').mockImplementation(() => {});
|
|
9
|
+
vi.spyOn(Logger.prototype, 'logWarn').mockImplementation(() => {});
|
|
10
|
+
vi.spyOn(Logger.prototype, 'logError').mockImplementation(() => {});
|
|
11
11
|
|
|
12
12
|
// Component that uses the useLocalStorage hook
|
|
13
13
|
const MockLocalStorageComponent: React.FC = () => {
|
|
@@ -184,7 +184,7 @@ describe('LocalStorageProvider', () => {
|
|
|
184
184
|
});
|
|
185
185
|
|
|
186
186
|
it('should log error when localStorage is not available', async () => {
|
|
187
|
-
const logErrorSpy = vi.spyOn(Logger, 'logError');
|
|
187
|
+
const logErrorSpy = vi.spyOn(Logger.prototype, 'logError');
|
|
188
188
|
const originalLocalStorage = window.localStorage;
|
|
189
189
|
Object.defineProperty(window, 'localStorage', {
|
|
190
190
|
value: undefined,
|
|
@@ -558,7 +558,7 @@ describe('LocalStorageProvider', () => {
|
|
|
558
558
|
});
|
|
559
559
|
|
|
560
560
|
it('should log debug message when storage event is received', async () => {
|
|
561
|
-
const logDebugSpy = vi.spyOn(Logger, 'logDebug');
|
|
561
|
+
const logDebugSpy = vi.spyOn(Logger.prototype, 'logDebug');
|
|
562
562
|
|
|
563
563
|
const TestComponent: React.FC = () => {
|
|
564
564
|
const { attachListener, setItem, detachListener } = useLocalStorage();
|
|
@@ -602,7 +602,7 @@ describe('LocalStorageProvider', () => {
|
|
|
602
602
|
await waitFor(
|
|
603
603
|
() => {
|
|
604
604
|
expect(logDebugSpy).toHaveBeenCalledWith(
|
|
605
|
-
'
|
|
605
|
+
'Storage event key=test-key, value=',
|
|
606
606
|
'test-value',
|
|
607
607
|
);
|
|
608
608
|
},
|
|
@@ -20,6 +20,8 @@ interface LocalStorageContextType {
|
|
|
20
20
|
|
|
21
21
|
const LocalStorageContext = createContext<LocalStorageContextType | null>(null);
|
|
22
22
|
|
|
23
|
+
const logger = new Logger('localStorageContext');
|
|
24
|
+
|
|
23
25
|
export const LocalStorageProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
24
26
|
const isAvailable = useMemo(() => {
|
|
25
27
|
try {
|
|
@@ -31,7 +33,7 @@ export const LocalStorageProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
|
31
33
|
|
|
32
34
|
useEffect(() => {
|
|
33
35
|
if (!isAvailable) {
|
|
34
|
-
|
|
36
|
+
logger.logError('localStorage is not available', undefined);
|
|
35
37
|
}
|
|
36
38
|
}, [isAvailable]);
|
|
37
39
|
|
|
@@ -78,7 +80,7 @@ export const LocalStorageProvider: React.FC<{ children: React.ReactNode }> = ({
|
|
|
78
80
|
if (event.key !== listener.storageKey) {
|
|
79
81
|
return;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
logger.logDebug(`Storage event key=${event.key}, value=`, event.newValue);
|
|
82
84
|
listener.listener(event);
|
|
83
85
|
};
|
|
84
86
|
listenersCache.set(listener.storageKey, handler);
|
|
@@ -15,9 +15,9 @@ import { mapUrlResolverResponseToVariantInfo } from '../mapping';
|
|
|
15
15
|
import { PageProvider, usePage } from '../pageContext';
|
|
16
16
|
|
|
17
17
|
// Mock the Logger to avoid console output in tests
|
|
18
|
-
vi.spyOn(Logger, 'logInfo').mockImplementation(() => {});
|
|
19
|
-
vi.spyOn(Logger, 'logWarn').mockImplementation(() => {});
|
|
20
|
-
vi.spyOn(Logger, 'logError').mockImplementation(() => {});
|
|
18
|
+
vi.spyOn(Logger.prototype, 'logInfo').mockImplementation(() => {});
|
|
19
|
+
vi.spyOn(Logger.prototype, 'logWarn').mockImplementation(() => {});
|
|
20
|
+
vi.spyOn(Logger.prototype, 'logError').mockImplementation(() => {});
|
|
21
21
|
|
|
22
22
|
// Mock CommerceApiClient
|
|
23
23
|
const mockResolveUrl = vi.fn();
|
|
@@ -468,7 +468,7 @@ describe('PageProvider', () => {
|
|
|
468
468
|
|
|
469
469
|
describe('Error Handling', () => {
|
|
470
470
|
it('should log error and not crash when resolveUrl fails', async () => {
|
|
471
|
-
const errorSpy = vi.spyOn(Logger, 'logError');
|
|
471
|
+
const errorSpy = vi.spyOn(Logger.prototype, 'logError');
|
|
472
472
|
const error = new Error('Network error');
|
|
473
473
|
mockResolveUrl.mockRejectedValue(error);
|
|
474
474
|
|
|
@@ -487,7 +487,7 @@ describe('PageProvider', () => {
|
|
|
487
487
|
});
|
|
488
488
|
|
|
489
489
|
it('should handle invalid variant type gracefully', async () => {
|
|
490
|
-
const errorSpy = vi.spyOn(Logger, 'logError');
|
|
490
|
+
const errorSpy = vi.spyOn(Logger.prototype, 'logError');
|
|
491
491
|
|
|
492
492
|
const invalidResponse = {
|
|
493
493
|
variant_type: 'invalid_type',
|
|
@@ -21,6 +21,8 @@ import { VariantTypeEnum } from 'src/application/models';
|
|
|
21
21
|
import { mapApiUserEventToUserEvent, mapUrlResolverResponseToVariantInfo } from './mapping';
|
|
22
22
|
import { PageDetails } from './types';
|
|
23
23
|
|
|
24
|
+
const logger = new Logger('pageContext');
|
|
25
|
+
|
|
24
26
|
const PageContext = createContext<
|
|
25
27
|
| (PageDetails & {
|
|
26
28
|
isLoading: boolean;
|
|
@@ -104,7 +106,7 @@ export const PageProvider: React.FC<{
|
|
|
104
106
|
setIsSupported(response.ready);
|
|
105
107
|
} catch (e) {
|
|
106
108
|
setIsLoading(false);
|
|
107
|
-
|
|
109
|
+
logger.logError('Failed to resolve page URL', e, { pageUrl });
|
|
108
110
|
}
|
|
109
111
|
};
|
|
110
112
|
resolvePageUrl();
|
|
@@ -29,6 +29,8 @@ const TRACKED_USER_EVENTS = [
|
|
|
29
29
|
UserEventCategory.PdpVisit,
|
|
30
30
|
UserEventCategory.PlpVisit,
|
|
31
31
|
];
|
|
32
|
+
|
|
33
|
+
const logger = new Logger('chatAPI');
|
|
32
34
|
export interface SalesAgentChatAPI {
|
|
33
35
|
logPageVisit: ({ pageVisitCategory }: { pageVisitCategory: PageVisitCategory }) => void;
|
|
34
36
|
logUserEvent: (event: UserEvent) => void;
|
|
@@ -88,11 +90,9 @@ export const useSalesAgentChatAPI = (widget?: WidgetInteractionComponent) => {
|
|
|
88
90
|
const logUserEvent = useCallback(
|
|
89
91
|
(event: UserEvent) => {
|
|
90
92
|
if (!hasParsedVariantInfo) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{ event },
|
|
95
|
-
);
|
|
93
|
+
logger.logWarn('hasParsedVariantInfo is false, not logging user event', undefined, {
|
|
94
|
+
event,
|
|
95
|
+
});
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
if (TRACKED_USER_EVENTS.includes(event.category)) {
|
|
@@ -47,6 +47,8 @@ export interface MockSalesAgentData {
|
|
|
47
47
|
|
|
48
48
|
const SalesAgentContext = createContext<SalesAgent | undefined>(undefined);
|
|
49
49
|
|
|
50
|
+
const logger = new Logger('salesAgentContext');
|
|
51
|
+
|
|
50
52
|
export interface SalesAgentProviderProps {
|
|
51
53
|
children: ReactNode;
|
|
52
54
|
previewMode?: boolean;
|
|
@@ -99,7 +101,7 @@ export const SalesAgentProvider: React.FC<SalesAgentProviderProps> = ({
|
|
|
99
101
|
// Remove the pending message from the user events
|
|
100
102
|
requestPayload.userEvents?.map(userEvent => markUserEventsProcessed([userEvent.eventId]));
|
|
101
103
|
} catch (error) {
|
|
102
|
-
|
|
104
|
+
logger.logError('error sending message', error);
|
|
103
105
|
}
|
|
104
106
|
},
|
|
105
107
|
[getStreamingResponses, setIsInitialized, markUserEventsProcessed],
|
|
@@ -207,7 +209,7 @@ export const SalesAgentProvider: React.FC<SalesAgentProviderProps> = ({
|
|
|
207
209
|
try {
|
|
208
210
|
await hydrateMessages();
|
|
209
211
|
} catch (error) {
|
|
210
|
-
|
|
212
|
+
logger.logError('error hydrating messages', error);
|
|
211
213
|
} finally {
|
|
212
214
|
setIsHydrated(true);
|
|
213
215
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
Response,
|
|
13
13
|
UserEvent,
|
|
14
14
|
} from 'src/application/models';
|
|
15
|
-
import {
|
|
15
|
+
import { messageFromResponse } from 'src/application/utils';
|
|
16
16
|
import { appDetailsAtom } from 'src/atoms/app';
|
|
17
17
|
import { analyticsContextAtom } from 'src/atoms/app/variant';
|
|
18
18
|
import {
|
|
@@ -33,6 +33,8 @@ import { v4 as uuid } from 'uuid';
|
|
|
33
33
|
|
|
34
34
|
import { StatusCodeError } from './statusCodeError';
|
|
35
35
|
|
|
36
|
+
const logger = new Logger('salesAgentService');
|
|
37
|
+
|
|
36
38
|
interface SalesAgentService {
|
|
37
39
|
createResponsePayload: (payload: {
|
|
38
40
|
userEvents: UserEvent[];
|
|
@@ -223,7 +225,7 @@ const processStreamingResponse = async (
|
|
|
223
225
|
|
|
224
226
|
lastMessage = updateMessageState(message, lastMessage!, setMessages);
|
|
225
227
|
} catch (error: unknown) {
|
|
226
|
-
|
|
228
|
+
logger.logWarn('Failed to generate responses from stream', error, {
|
|
227
229
|
lastResponse: lastMessage,
|
|
228
230
|
response,
|
|
229
231
|
});
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { act, render, screen, waitFor } from '@testing-library/react';
|
|
3
3
|
import { Provider, useAtomValue } from 'jotai';
|
|
4
|
-
import {
|
|
5
|
-
EnviveConfigProvider,
|
|
6
|
-
useEnviveConfig,
|
|
7
|
-
} from 'src/contexts/enviveConfigContext/enviveConfigContext';
|
|
4
|
+
import { EnviveConfigProvider, useEnviveConfig } from 'src/contexts/enviveConfigContext';
|
|
8
5
|
import { LocalStorageProvider } from 'src/contexts/localStorageContext/localStorageContext';
|
|
9
6
|
import { GraphQLProvider } from 'src/contexts/graphqlContext/graphqlContext';
|
|
10
7
|
import { UserIdentityProvider } from 'src/contexts/userIdentityContext/userIdentityContext';
|
|
@@ -79,14 +76,20 @@ vi.mock('src/contexts/enviveConfigContext/enviveConfigContext', async () => {
|
|
|
79
76
|
});
|
|
80
77
|
|
|
81
78
|
// Mock Logger
|
|
82
|
-
vi.mock('src/application/logging/logger', () =>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
79
|
+
vi.mock('src/application/logging/logger', () => {
|
|
80
|
+
const MockLogger = vi.fn(function MockLogger() {
|
|
81
|
+
return {
|
|
82
|
+
logInfo: vi.fn(),
|
|
83
|
+
logWarn: vi.fn(),
|
|
84
|
+
logError: vi.fn(),
|
|
85
|
+
logDebug: vi.fn(),
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
default: MockLogger,
|
|
91
|
+
};
|
|
92
|
+
});
|
|
90
93
|
|
|
91
94
|
// Mock the search service adapter
|
|
92
95
|
vi.mock('src/atoms/search/searchServiceAdapter', () => ({
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { baseUrlAtom } from 'src/atoms/envive/enviveConfig';
|
|
10
10
|
import Logger from 'src/application/logging/logger';
|
|
11
11
|
import { useAppDetails } from 'src/hooks/AppDetails/useAppDetails';
|
|
12
|
-
import { useEnviveConfig } from 'src/contexts/enviveConfigContext
|
|
12
|
+
import { useEnviveConfig } from 'src/contexts/enviveConfigContext';
|
|
13
13
|
import { SessionRestartRequired } from 'src/types/exceptions/sessionExceptions';
|
|
14
14
|
import { UnsupportedProductException } from 'src/types/exceptions/unsupportedProductExceptions';
|
|
15
15
|
import { SearchParams, SearchResult } from 'src/application/models/api/search';
|
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
setSearchServiceFunction,
|
|
19
19
|
} from 'src/atoms/search/searchServiceAdapter';
|
|
20
20
|
|
|
21
|
+
const logger = new Logger('searchContext');
|
|
22
|
+
|
|
21
23
|
const transformProductResponses = (products: SearchResult['products']) =>
|
|
22
24
|
products.map(data => ({
|
|
23
25
|
id: data.id,
|
|
@@ -49,7 +51,7 @@ async function errorResponseBody(error: ResponseError) {
|
|
|
49
51
|
|
|
50
52
|
async function throwSessionRestartRequiredIf(errorMsg: string, error: unknown) {
|
|
51
53
|
if (!(error instanceof ResponseError)) {
|
|
52
|
-
|
|
54
|
+
logger.logInfo(errorMsg, error);
|
|
53
55
|
throw error;
|
|
54
56
|
}
|
|
55
57
|
|
|
@@ -63,7 +65,7 @@ async function throwSessionRestartRequiredIf(errorMsg: string, error: unknown) {
|
|
|
63
65
|
errorResponse?.app_code?.toUpperCase() === 'RESTART_SESSION' ||
|
|
64
66
|
errorResponse?.sub_code?.toUpperCase() === 'NOT_FOUND'
|
|
65
67
|
) {
|
|
66
|
-
|
|
68
|
+
logger.logInfo(
|
|
67
69
|
'Session does not exist. Re-start session',
|
|
68
70
|
error,
|
|
69
71
|
error.response,
|
|
@@ -72,7 +74,7 @@ async function throwSessionRestartRequiredIf(errorMsg: string, error: unknown) {
|
|
|
72
74
|
throw new SessionRestartRequired();
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
logger.logInfo(errorMsg, error);
|
|
76
78
|
throw error;
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -9,6 +9,8 @@ interface SessionStorageContextType {
|
|
|
9
9
|
|
|
10
10
|
const SessionStorageContext = createContext<SessionStorageContextType | null>(null);
|
|
11
11
|
|
|
12
|
+
const logger = new Logger('sessionStorageContext');
|
|
13
|
+
|
|
12
14
|
export const SessionStorageProvider: React.FC<{
|
|
13
15
|
children: React.ReactNode;
|
|
14
16
|
}> = ({ children }) => {
|
|
@@ -22,7 +24,7 @@ export const SessionStorageProvider: React.FC<{
|
|
|
22
24
|
|
|
23
25
|
useEffect(() => {
|
|
24
26
|
if (!isAvailable) {
|
|
25
|
-
|
|
27
|
+
logger.logError('sessionStorage is not available', undefined);
|
|
26
28
|
}
|
|
27
29
|
}, [isAvailable]);
|
|
28
30
|
|
|
@@ -6,13 +6,13 @@ import { SparkleIconColor } from '@envive-ai/react-toolkit-v3/WelcomeMessage';
|
|
|
6
6
|
import { ChatHeaderVariant } from '@envive-ai/react-toolkit-v3/ChatHeader';
|
|
7
7
|
import { Theme } from '@envive-ai/react-toolkit-v3/Tokens';
|
|
8
8
|
import { FloatingButtonLocation } from '@envive-ai/react-toolkit-v3/FloatingButton';
|
|
9
|
-
import {
|
|
9
|
+
import { useUiConfig } from '../uiConfigContext';
|
|
10
10
|
import { ConfigVersionEnum, OrgUIConfigV3 } from '../../typesV3';
|
|
11
11
|
|
|
12
12
|
// Mock the Logger to avoid console output in tests
|
|
13
|
-
vi.spyOn(Logger, 'logInfo').mockImplementation(() => {});
|
|
14
|
-
vi.spyOn(Logger, 'logWarn').mockImplementation(() => {});
|
|
15
|
-
vi.spyOn(Logger, 'logError').mockImplementation(() => {});
|
|
13
|
+
vi.spyOn(Logger.prototype, 'logInfo').mockImplementation(() => {});
|
|
14
|
+
vi.spyOn(Logger.prototype, 'logWarn').mockImplementation(() => {});
|
|
15
|
+
vi.spyOn(Logger.prototype, 'logError').mockImplementation(() => {});
|
|
16
16
|
|
|
17
17
|
// Mock the useNewOrgConfig hook
|
|
18
18
|
vi.mock('src/hooks/NewOrgConfig', () => ({
|
|
@@ -30,7 +30,7 @@ const MockUiConfigComponent: React.FC = () => {
|
|
|
30
30
|
setIsLoadingState(true);
|
|
31
31
|
try {
|
|
32
32
|
const config = await getUiConfig();
|
|
33
|
-
setUiConfig(config);
|
|
33
|
+
setUiConfig(config ?? null);
|
|
34
34
|
setError(null);
|
|
35
35
|
} catch (err: unknown) {
|
|
36
36
|
setError(err instanceof Error ? err.message : 'Unknown error');
|
|
@@ -74,7 +74,7 @@ const TestWrapper: React.FC<{
|
|
|
74
74
|
loading: mockNewOrgConfig.loading ?? false,
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
return
|
|
77
|
+
return children;
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
describe('UiConfigProvider', () => {
|
|
@@ -129,7 +129,7 @@ describe('UiConfigProvider', () => {
|
|
|
129
129
|
});
|
|
130
130
|
|
|
131
131
|
describe('useUiConfig Hook Integration', () => {
|
|
132
|
-
it('should provide
|
|
132
|
+
it('should provide ui config data via useUiConfig hook', async () => {
|
|
133
133
|
const mockUiConfig = createMockUiConfig();
|
|
134
134
|
|
|
135
135
|
render(
|
|
@@ -151,31 +151,6 @@ describe('UiConfigProvider', () => {
|
|
|
151
151
|
|
|
152
152
|
expect(screen.getByTestId('is-loading')).toHaveTextContent('false');
|
|
153
153
|
});
|
|
154
|
-
|
|
155
|
-
it('should throw error when used outside of UiConfigProvider', () => {
|
|
156
|
-
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
157
|
-
|
|
158
|
-
const TestComponent: React.FC = () => {
|
|
159
|
-
try {
|
|
160
|
-
useUiConfig();
|
|
161
|
-
return <div data-testid="no-error">No Error</div>;
|
|
162
|
-
} catch (error: unknown) {
|
|
163
|
-
return (
|
|
164
|
-
<div data-testid="error">
|
|
165
|
-
{error instanceof Error ? error.message : 'Unknown error'}
|
|
166
|
-
</div>
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
render(<TestComponent />);
|
|
172
|
-
|
|
173
|
-
expect(screen.getByTestId('error')).toHaveTextContent(
|
|
174
|
-
'useUiConfig must be used within a UiConfigProvider',
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
consoleSpy.mockRestore();
|
|
178
|
-
});
|
|
179
154
|
});
|
|
180
155
|
|
|
181
156
|
describe('getUiConfig', () => {
|
|
@@ -1,44 +1,32 @@
|
|
|
1
|
-
import { ReactNode, createContext, useCallback, useContext, useMemo, useState } from 'react';
|
|
2
1
|
import Logger from 'src/application/logging/logger';
|
|
3
2
|
import { useNewOrgConfig } from 'src/hooks/NewOrgConfig';
|
|
4
3
|
import { OrgUIConfigV3 } from '../typesV3';
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const logger = new Logger('uiConfigContext');
|
|
6
|
+
interface UiConfigHookResult {
|
|
7
|
+
getUiConfig: () => Promise<OrgUIConfigV3 | undefined>;
|
|
8
8
|
isLoading: boolean;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
export const useUiConfig = (): UiConfigHookResult => {
|
|
12
|
+
const { frontendConfig, loading } = useNewOrgConfig();
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const [isLoadingUiConfig, setIsLoadingUiConfig] = useState(false);
|
|
14
|
+
const getUiConfig = async (): Promise<OrgUIConfigV3 | undefined> => {
|
|
15
|
+
logger.logDebug('uiConfigContext | retrieving ui config');
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Logger.logInfo('uiConfigContext | retrieving ui config');
|
|
20
|
-
if (isFrontendConfigLoading) {
|
|
21
|
-
setIsLoadingUiConfig(false);
|
|
17
|
+
if (loading) {
|
|
18
|
+
logger.logDebug('uiConfigContext | frontend config still loading');
|
|
22
19
|
throw new Error('Frontend config is loading');
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
const response = frontendConfig?.uiConfigs as OrgUIConfigV3;
|
|
26
|
-
|
|
27
|
-
setIsLoadingUiConfig(false);
|
|
28
|
-
return response;
|
|
29
|
-
}, [frontendConfig, isFrontendConfigLoading]);
|
|
30
|
-
|
|
31
|
-
const isLoading = isFrontendConfigLoading || isLoadingUiConfig;
|
|
32
|
-
|
|
33
|
-
const value = useMemo(() => ({ getUiConfig, isLoading }), [getUiConfig, isLoading]);
|
|
22
|
+
const response = frontendConfig?.uiConfigs as OrgUIConfigV3 | undefined;
|
|
23
|
+
logger.logDebug('uiConfigContext | returning ui config response', response);
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
};
|
|
25
|
+
return response;
|
|
26
|
+
};
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
return context;
|
|
28
|
+
return {
|
|
29
|
+
getUiConfig,
|
|
30
|
+
isLoading: loading,
|
|
31
|
+
};
|
|
44
32
|
};
|