@envive-ai/react-hooks 0.3.18 → 0.3.19-alpha-marlo-0
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/atoms/app/index.d.cts +1 -1
- package/dist/atoms/app/index.d.ts +7 -7
- package/dist/atoms/app/variant.cjs +3 -2
- package/dist/atoms/app/variant.d.cts +6 -6
- 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 +3 -3
- package/dist/atoms/chat/form.d.ts +2 -2
- package/dist/atoms/chat/index.d.cts +3 -3
- package/dist/atoms/chat/index.d.ts +3 -3
- 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 +7 -7
- 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 +3 -3
- 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 +3 -3
- package/dist/atoms/chat/suggestions.d.cts +3 -3
- 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/searchAPI.d.cts +13 -13
- package/dist/atoms/search/types.d.cts +1 -1
- package/dist/atoms/search/utils.d.cts +1 -1
- 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 +74 -45
- package/dist/contexts/enviveContext/enviveContext.d.cts +8 -2
- package/dist/contexts/enviveContext/enviveContext.d.ts +8 -2
- package/dist/contexts/enviveContext/enviveContext.js +75 -46
- package/dist/contexts/enviveContext/index.d.cts +2 -2
- package/dist/contexts/enviveContext/index.d.ts +2 -2
- package/dist/contexts/enviveContext/types.d.cts +1 -1
- package/dist/contexts/enviveContext/types.d.ts +1 -1
- 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 +23 -4
- package/dist/contexts/pageContext/pageContext.d.cts +3 -1
- package/dist/contexts/pageContext/pageContext.d.ts +3 -1
- package/dist/contexts/pageContext/pageContext.js +24 -5
- package/dist/contexts/pageContext/types.d.ts +1 -1
- 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.ts +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/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/GrabAndScroll/useGrabAndScroll.d.cts +2 -2
- package/dist/hooks/GrabAndScroll/useGrabAndScroll.d.ts +2 -2
- package/dist/hooks/ShopifyUrlOperations/useShopifyUrlOperations.d.cts +2 -2
- package/dist/hooks/ShopifyUrlOperations/useShopifyUrlOperations.d.ts +2 -2
- package/dist/hooks/SystemSettingsContext/useSystemSettingsContext.d.ts +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.cts +1 -1
- package/dist/hooks/utils.d.ts +1 -1
- package/dist/services/amplitudeService/amplitudeService.cjs +15 -7
- package/dist/services/amplitudeService/amplitudeService.d.cts +2 -1
- package/dist/services/amplitudeService/amplitudeService.d.ts +2 -1
- package/dist/services/amplitudeService/amplitudeService.js +15 -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/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 +109 -50
- 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 +22 -2
- 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 +19 -6
- package/src/services/ga4ProjectionService/ga4ProjectionService.ts +3 -1
- package/src/services/userIdentityService/userIdentityService.ts +8 -8
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
3
|
class Logger {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
private readonly caller: string;
|
|
5
|
+
|
|
6
|
+
/* Creates a new Logger instance.
|
|
7
|
+
* @param caller - The caller of the logger.
|
|
8
|
+
*/
|
|
9
|
+
constructor(caller: string) {
|
|
10
|
+
this.caller = caller;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static getTimestamp(): string {
|
|
14
|
+
return new Date().toISOString();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
logInfo(message: string, ...args: unknown[]): void {
|
|
18
|
+
console.info(
|
|
19
|
+
`INFO: [envive-ai] ${Logger.getTimestamp()} - ${this.caller} - ${message}`,
|
|
20
|
+
...args,
|
|
21
|
+
);
|
|
6
22
|
}
|
|
7
23
|
|
|
8
|
-
|
|
9
|
-
console.debug(
|
|
24
|
+
logDebug(message: string, ...args: unknown[]): void {
|
|
25
|
+
console.debug(
|
|
26
|
+
`DEBUG: [envive-ai] ${Logger.getTimestamp()} - ${this.caller} - ${message}`,
|
|
27
|
+
...args,
|
|
28
|
+
);
|
|
10
29
|
}
|
|
11
30
|
|
|
12
|
-
|
|
13
|
-
console.error(
|
|
31
|
+
logError(message: string, error: unknown | undefined, ...args: unknown[]): void {
|
|
32
|
+
console.error(
|
|
33
|
+
`ERROR: [envive-ai] ${Logger.getTimestamp()} - ${this.caller} - ${message} error=${error}`,
|
|
34
|
+
args,
|
|
35
|
+
);
|
|
14
36
|
}
|
|
15
37
|
|
|
16
|
-
|
|
17
|
-
console.warn(
|
|
38
|
+
logWarn(message: string, error: unknown | undefined, ...args: unknown[]): void {
|
|
39
|
+
console.warn(
|
|
40
|
+
`WARN: [envive-ai] ${Logger.getTimestamp()} - ${this.caller} - ${message} error=${error}`,
|
|
41
|
+
args,
|
|
42
|
+
);
|
|
18
43
|
}
|
|
19
44
|
}
|
|
20
45
|
|
|
@@ -3,6 +3,8 @@ import { FormType } from '@spiffy-ai/commerce-api-client';
|
|
|
3
3
|
import { ApiFormResponseAttributes } from 'src/application/models/api/responseGenerics';
|
|
4
4
|
import { hasPropertyOfType } from 'src/application/models/guards/utils';
|
|
5
5
|
|
|
6
|
+
const logger = new Logger('isApiFormResponse');
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* Type guard to check if the provided data has the all of the properties (with the correct types) of
|
|
8
10
|
* a FormResponseAttribute
|
|
@@ -13,14 +15,14 @@ import { hasPropertyOfType } from 'src/application/models/guards/utils';
|
|
|
13
15
|
*/
|
|
14
16
|
export const isApiFormResponseAttributes = (data: unknown): data is ApiFormResponseAttributes => {
|
|
15
17
|
if (data == null || typeof data !== 'object') {
|
|
16
|
-
|
|
18
|
+
logger.logError('isApiFormResponseAttributes: data is null or not an object', undefined, {
|
|
17
19
|
data,
|
|
18
20
|
});
|
|
19
21
|
return false;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
if ('form_category' in data && typeof data.form_category !== 'object') {
|
|
23
|
-
|
|
25
|
+
logger.logError('isApiFormResponseAttributes: form_category is not an object', undefined, {
|
|
24
26
|
data,
|
|
25
27
|
});
|
|
26
28
|
return false;
|
|
@@ -31,7 +33,7 @@ export const isApiFormResponseAttributes = (data: unknown): data is ApiFormRespo
|
|
|
31
33
|
!hasPropertyOfType(data.form_category, 'form_type', 'string') ||
|
|
32
34
|
!Object.values(FormType).includes(data.form_category.form_type as FormType)
|
|
33
35
|
) {
|
|
34
|
-
|
|
36
|
+
logger.logError(
|
|
35
37
|
'isApiFormResponseAttributes: form_type is missing or not a valid form type',
|
|
36
38
|
undefined,
|
|
37
39
|
{
|
|
@@ -43,7 +45,7 @@ export const isApiFormResponseAttributes = (data: unknown): data is ApiFormRespo
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
if (!hasPropertyOfType(data, 'schema', 'object')) {
|
|
46
|
-
|
|
48
|
+
logger.logError('isApiFormResponseAttributes: schema is missing or not an object', undefined, {
|
|
47
49
|
data,
|
|
48
50
|
});
|
|
49
51
|
return false;
|
|
@@ -52,7 +54,7 @@ export const isApiFormResponseAttributes = (data: unknown): data is ApiFormRespo
|
|
|
52
54
|
// TODO: also wanna validate the fields of data.schema.properties but might wanna change the schema
|
|
53
55
|
// to not have the property name as a key in the object
|
|
54
56
|
if (!hasPropertyOfType(data.schema, 'properties', 'object')) {
|
|
55
|
-
|
|
57
|
+
logger.logError(
|
|
56
58
|
'isApiFormResponseAttributes: schema.properties is missing or not an object',
|
|
57
59
|
undefined,
|
|
58
60
|
{
|
|
@@ -63,7 +65,7 @@ export const isApiFormResponseAttributes = (data: unknown): data is ApiFormRespo
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
if (!hasPropertyOfType(data.schema, 'required', 'array')) {
|
|
66
|
-
|
|
68
|
+
logger.logError(
|
|
67
69
|
'isApiFormResponseAttributes: schema.required is missing or not an array',
|
|
68
70
|
undefined,
|
|
69
71
|
{ data },
|
|
@@ -76,7 +78,7 @@ export const isApiFormResponseAttributes = (data: unknown): data is ApiFormRespo
|
|
|
76
78
|
(key: unknown) => typeof key === 'string' && key in data.schema.properties,
|
|
77
79
|
)
|
|
78
80
|
) {
|
|
79
|
-
|
|
81
|
+
logger.logError(
|
|
80
82
|
'isApiFormResponseAttributes: schema.required contains invalid property keys',
|
|
81
83
|
undefined,
|
|
82
84
|
{
|
|
@@ -2,21 +2,23 @@ import Logger from 'src/application/logging/logger';
|
|
|
2
2
|
import { FormSubmittedAttributes, FormType } from '@spiffy-ai/commerce-api-client';
|
|
3
3
|
import { hasPropertyOfType } from 'src/application/models/guards/utils';
|
|
4
4
|
|
|
5
|
+
const logger = new Logger('isApiFormSubmittedResponseAttributes');
|
|
6
|
+
|
|
5
7
|
export const isApiFormSubmittedResponseAttributes = (
|
|
6
8
|
data: unknown,
|
|
7
9
|
): data is FormSubmittedAttributes => {
|
|
8
10
|
if (data == null || typeof data !== 'object') {
|
|
9
|
-
|
|
11
|
+
logger.logError('isApiFormSubmittedResponseAttributes', 'data is null or not an object', data);
|
|
10
12
|
return false;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
if (!hasPropertyOfType(data, 'filled_schema', 'object')) {
|
|
14
|
-
|
|
16
|
+
logger.logError('isApiFormSubmittedResponseAttributes', 'filled_schema is not an object', data);
|
|
15
17
|
return false;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
if (!hasPropertyOfType(data, 'form_response_id', 'string')) {
|
|
19
|
-
|
|
21
|
+
logger.logError(
|
|
20
22
|
'isApiFormSubmittedResponseAttributes',
|
|
21
23
|
'form_response_id is not a string',
|
|
22
24
|
data,
|
|
@@ -25,7 +27,7 @@ export const isApiFormSubmittedResponseAttributes = (
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
if (!('form_type' in data) || !Object.values(FormType).includes(data.form_type as FormType)) {
|
|
28
|
-
|
|
30
|
+
logger.logError(
|
|
29
31
|
'isApiFormSubmittedResponseAttributes',
|
|
30
32
|
'form_type is not a valid form type enum',
|
|
31
33
|
data,
|
|
@@ -2,6 +2,8 @@ import Logger from 'src/application/logging/logger';
|
|
|
2
2
|
import { OrderItemInfo, OrderResponseAttributes } from '@spiffy-ai/commerce-api-client';
|
|
3
3
|
import { hasPropertyOfType } from 'src/application/models/guards/utils';
|
|
4
4
|
|
|
5
|
+
const logger = new Logger('isApiOrderResponseAttributes');
|
|
6
|
+
|
|
5
7
|
// the client SDK generates date-time format types as `Date` but the openapi typescript generator
|
|
6
8
|
// does not correctly deserialize date-time values so they are always `string` at runtime instead of
|
|
7
9
|
// `Date` objects. These interfaces override the SDK types so that we can validate against the actual
|
|
@@ -26,37 +28,37 @@ export interface ApiOrderResponseAttributes extends Omit<
|
|
|
26
28
|
|
|
27
29
|
const isApiOrderItemInfo = (data: unknown): data is ApiOrderItemInfo => {
|
|
28
30
|
if (data == null || typeof data !== 'object') {
|
|
29
|
-
|
|
31
|
+
logger.logError('OrderItemInfo must be an object', undefined, { data });
|
|
30
32
|
return false;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
if (!hasPropertyOfType(data, 'order_item_id', 'string')) {
|
|
34
|
-
|
|
36
|
+
logger.logError('OrderItemInfo must have an order_item_id property', undefined, { data });
|
|
35
37
|
return false;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
if (!hasPropertyOfType(data, 'item_title', 'string')) {
|
|
39
|
-
|
|
41
|
+
logger.logError('OrderItemInfo must have an item_title property', undefined, { data });
|
|
40
42
|
return false;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
if (!hasPropertyOfType(data, 'item_price', 'number')) {
|
|
44
|
-
|
|
46
|
+
logger.logError('OrderItemInfo must have an item_price property', undefined, { data });
|
|
45
47
|
return false;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
if (!hasPropertyOfType(data, 'item_quantity', 'number')) {
|
|
49
|
-
|
|
51
|
+
logger.logError('OrderItemInfo must have an item_quantity property', undefined, { data });
|
|
50
52
|
return false;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
if (!hasPropertyOfType(data, 'image', 'string', true)) {
|
|
54
|
-
|
|
56
|
+
logger.logError('OrderItemInfo.image must be a string or null', undefined, { data });
|
|
55
57
|
return false;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
if (!hasPropertyOfType(data, 'fulfillment_display_status', 'string', true)) {
|
|
59
|
-
|
|
61
|
+
logger.logError(
|
|
60
62
|
'OrderItemInfo.fulfillment_display_status must be a string or null',
|
|
61
63
|
undefined,
|
|
62
64
|
{
|
|
@@ -67,24 +69,24 @@ const isApiOrderItemInfo = (data: unknown): data is ApiOrderItemInfo => {
|
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
if (!hasPropertyOfType(data, 'tracking_url', 'string', true)) {
|
|
70
|
-
|
|
72
|
+
logger.logError('OrderItemInfo.tracking_url must be a string or null', undefined, { data });
|
|
71
73
|
return false;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
if (!hasPropertyOfType(data, 'delivered_at', 'string', true)) {
|
|
75
|
-
|
|
77
|
+
logger.logError('OrderItemInfo.delivered_at must be a string or null', undefined, { data });
|
|
76
78
|
return false;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
if (!hasPropertyOfType(data, 'estimated_delivery_at', 'string', true)) {
|
|
80
|
-
|
|
82
|
+
logger.logError('OrderItemInfo.estimated_delivery_at must be a string or null', undefined, {
|
|
81
83
|
data,
|
|
82
84
|
});
|
|
83
85
|
return false;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
if (!hasPropertyOfType(data, 'in_transit_at', 'string', true)) {
|
|
87
|
-
|
|
89
|
+
logger.logError('OrderItemInfo.in_transit_at must be a string or null', undefined, { data });
|
|
88
90
|
return false;
|
|
89
91
|
}
|
|
90
92
|
|
|
@@ -93,12 +95,12 @@ const isApiOrderItemInfo = (data: unknown): data is ApiOrderItemInfo => {
|
|
|
93
95
|
|
|
94
96
|
export const isApiOrderResponseAttributes = (data: unknown): data is ApiOrderResponseAttributes => {
|
|
95
97
|
if (data == null || typeof data !== 'object') {
|
|
96
|
-
|
|
98
|
+
logger.logError('Order response attributes must be an object', undefined, { data });
|
|
97
99
|
return false;
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
if (!hasPropertyOfType(data, 'created_at', 'string')) {
|
|
101
|
-
|
|
103
|
+
logger.logError(
|
|
102
104
|
'Order response attributes must have a created_at property and have type string',
|
|
103
105
|
undefined,
|
|
104
106
|
{
|
|
@@ -109,7 +111,7 @@ export const isApiOrderResponseAttributes = (data: unknown): data is ApiOrderRes
|
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
if (!hasPropertyOfType(data, 'latest_event_date', 'string')) {
|
|
112
|
-
|
|
114
|
+
logger.logError(
|
|
113
115
|
'Order response attributes must have a latest_event_date property and have type string',
|
|
114
116
|
undefined,
|
|
115
117
|
{
|
|
@@ -123,7 +125,7 @@ export const isApiOrderResponseAttributes = (data: unknown): data is ApiOrderRes
|
|
|
123
125
|
!hasPropertyOfType(data, 'line_items', 'array') ||
|
|
124
126
|
!data.line_items.every((item: unknown) => isApiOrderItemInfo(item))
|
|
125
127
|
) {
|
|
126
|
-
|
|
128
|
+
logger.logError(
|
|
127
129
|
'Order response attributes must have a line_items property with at least one order item',
|
|
128
130
|
undefined,
|
|
129
131
|
{
|
|
@@ -134,7 +136,7 @@ export const isApiOrderResponseAttributes = (data: unknown): data is ApiOrderRes
|
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
if (!hasPropertyOfType(data, 'order_id', 'string')) {
|
|
137
|
-
|
|
139
|
+
logger.logError(
|
|
138
140
|
'Order response attributes must have an order_id property and have type string',
|
|
139
141
|
undefined,
|
|
140
142
|
{
|
|
@@ -145,7 +147,7 @@ export const isApiOrderResponseAttributes = (data: unknown): data is ApiOrderRes
|
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
if (!hasPropertyOfType(data, 'order_number', 'string')) {
|
|
148
|
-
|
|
150
|
+
logger.logError(
|
|
149
151
|
'Order response attributes must have an order_number property and have type string',
|
|
150
152
|
undefined,
|
|
151
153
|
{
|
|
@@ -15,22 +15,20 @@ interface ApiOrgConfigResults {
|
|
|
15
15
|
org: ApiOrgConfigOrganizationSettings;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const logger = new Logger('isApiOrgConfigResults');
|
|
19
|
+
|
|
18
20
|
const isApiOrgConfigExperiment = (data: unknown): data is ApiOrgConfigExperiment => {
|
|
19
21
|
if (data == null || typeof data !== 'object') {
|
|
20
|
-
|
|
22
|
+
logger.logDebug('isApiOrgConfigExperiment: data is not an object', undefined, {
|
|
21
23
|
data,
|
|
22
24
|
});
|
|
23
25
|
return false;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
if ('group' in data && typeof data.group !== 'string' && data.group !== undefined) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
data,
|
|
32
|
-
},
|
|
33
|
-
);
|
|
29
|
+
logger.logDebug('isApiOrgConfigExperiment: group is not a string or undefined', undefined, {
|
|
30
|
+
data,
|
|
31
|
+
});
|
|
34
32
|
return false;
|
|
35
33
|
}
|
|
36
34
|
|
|
@@ -39,28 +37,28 @@ const isApiOrgConfigExperiment = (data: unknown): data is ApiOrgConfigExperiment
|
|
|
39
37
|
typeof data.group_name !== 'string' &&
|
|
40
38
|
data.group_name !== undefined
|
|
41
39
|
) {
|
|
42
|
-
|
|
40
|
+
logger.logDebug('isApiOrgConfigExperiment: group_name is not a string', undefined, {
|
|
43
41
|
data,
|
|
44
42
|
});
|
|
45
43
|
return false;
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
if ('name' in data && typeof data.name !== 'string' && data.name !== undefined) {
|
|
49
|
-
|
|
47
|
+
logger.logDebug('isApiOrgConfigExperiment: name is not a string', undefined, {
|
|
50
48
|
data,
|
|
51
49
|
});
|
|
52
50
|
return false;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
if ('rule_id' in data && typeof data.rule_id !== 'string' && data.rule_id !== undefined) {
|
|
56
|
-
|
|
54
|
+
logger.logDebug('isApiOrgConfigExperiment: rule_id is not a string', undefined, {
|
|
57
55
|
data,
|
|
58
56
|
});
|
|
59
57
|
return false;
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
if ('value' in data && typeof data.value !== 'object' && data.value !== undefined) {
|
|
63
|
-
|
|
61
|
+
logger.logDebug('isApiOrgConfigExperiment: value is not an object', undefined, {
|
|
64
62
|
data,
|
|
65
63
|
});
|
|
66
64
|
return false;
|
|
@@ -71,28 +69,28 @@ const isApiOrgConfigExperiment = (data: unknown): data is ApiOrgConfigExperiment
|
|
|
71
69
|
|
|
72
70
|
const isApiOrgConfigFeatureGate = (data: unknown): data is ApiOrgConfigFeatureGate => {
|
|
73
71
|
if (data == null || typeof data !== 'object') {
|
|
74
|
-
|
|
72
|
+
logger.logDebug('isApiOrgConfigFeatureGate: data is not an object', undefined, {
|
|
75
73
|
data,
|
|
76
74
|
});
|
|
77
75
|
return false;
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
if ('name' in data && typeof data.name !== 'string' && data.name !== undefined) {
|
|
81
|
-
|
|
79
|
+
logger.logDebug('isApiOrgConfigFeatureGate: name is not a string', undefined, {
|
|
82
80
|
data,
|
|
83
81
|
});
|
|
84
82
|
return false;
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
if ('rule_id' in data && typeof data.rule_id !== 'string' && data.rule_id !== undefined) {
|
|
88
|
-
|
|
86
|
+
logger.logDebug('isApiOrgConfigFeatureGate: rule_id is not a string', undefined, {
|
|
89
87
|
data,
|
|
90
88
|
});
|
|
91
89
|
return false;
|
|
92
90
|
}
|
|
93
91
|
|
|
94
92
|
if ('value' in data && typeof data.value !== 'boolean' && data.value !== undefined) {
|
|
95
|
-
|
|
93
|
+
logger.logDebug('isApiOrgConfigFeatureGate: value is not a boolean', undefined, {
|
|
96
94
|
data,
|
|
97
95
|
});
|
|
98
96
|
return false;
|
|
@@ -103,35 +101,35 @@ const isApiOrgConfigFeatureGate = (data: unknown): data is ApiOrgConfigFeatureGa
|
|
|
103
101
|
|
|
104
102
|
const isApiOrganization = (data: unknown): data is ApiOrganization => {
|
|
105
103
|
if (data == null || typeof data !== 'object') {
|
|
106
|
-
|
|
104
|
+
logger.logDebug('isApiOrganization: data is not an object', undefined, {
|
|
107
105
|
data,
|
|
108
106
|
});
|
|
109
107
|
return false;
|
|
110
108
|
}
|
|
111
109
|
|
|
112
110
|
if (!('id' in data) || typeof data.id !== 'string') {
|
|
113
|
-
|
|
111
|
+
logger.logDebug('isApiOrganization: id is not a string', undefined, {
|
|
114
112
|
data,
|
|
115
113
|
});
|
|
116
114
|
return false;
|
|
117
115
|
}
|
|
118
116
|
|
|
119
117
|
if (!('display_name' in data) || typeof data.display_name !== 'string') {
|
|
120
|
-
|
|
118
|
+
logger.logDebug('isApiOrganization: display_name is not a string', undefined, {
|
|
121
119
|
data,
|
|
122
120
|
});
|
|
123
121
|
return false;
|
|
124
122
|
}
|
|
125
123
|
|
|
126
124
|
if (!('domain' in data) || typeof data.domain !== 'string') {
|
|
127
|
-
|
|
125
|
+
logger.logDebug('isApiOrganization: domain is not a string', undefined, {
|
|
128
126
|
data,
|
|
129
127
|
});
|
|
130
128
|
return false;
|
|
131
129
|
}
|
|
132
130
|
|
|
133
131
|
if (!('short_name' in data) || typeof data.short_name !== 'string') {
|
|
134
|
-
|
|
132
|
+
logger.logDebug('isApiOrganization: short_name is not a string', undefined, {
|
|
135
133
|
data,
|
|
136
134
|
});
|
|
137
135
|
return false;
|
|
@@ -141,8 +139,8 @@ const isApiOrganization = (data: unknown): data is ApiOrganization => {
|
|
|
141
139
|
!('status' in data) ||
|
|
142
140
|
!Object.values(OrganizationStatusEnum).includes(data.status as OrganizationStatusEnum)
|
|
143
141
|
) {
|
|
144
|
-
|
|
145
|
-
'
|
|
142
|
+
logger.logDebug(
|
|
143
|
+
'isApiOrganization: status is not a valid OrganizationStatusEnum value',
|
|
146
144
|
undefined,
|
|
147
145
|
{
|
|
148
146
|
data,
|
|
@@ -157,7 +155,7 @@ const isApiOrganization = (data: unknown): data is ApiOrganization => {
|
|
|
157
155
|
typeof data.created_at !== 'string' &&
|
|
158
156
|
data.created_at !== undefined
|
|
159
157
|
) {
|
|
160
|
-
|
|
158
|
+
logger.logDebug('isApiOrganization: created_at is not a Date', undefined, {
|
|
161
159
|
data,
|
|
162
160
|
});
|
|
163
161
|
return false;
|
|
@@ -169,7 +167,7 @@ const isApiOrganization = (data: unknown): data is ApiOrganization => {
|
|
|
169
167
|
typeof data.updated_at !== 'string' &&
|
|
170
168
|
data.updated_at !== undefined
|
|
171
169
|
) {
|
|
172
|
-
|
|
170
|
+
logger.logDebug('isApiOrganization: updated_at is not a Date', undefined, {
|
|
173
171
|
data,
|
|
174
172
|
});
|
|
175
173
|
return false;
|
|
@@ -182,24 +180,16 @@ const isApiOrgConfigOrganizationSettings = (
|
|
|
182
180
|
data: unknown,
|
|
183
181
|
): data is ApiOrgConfigOrganizationSettings => {
|
|
184
182
|
if (data == null || typeof data !== 'object') {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
{
|
|
189
|
-
data,
|
|
190
|
-
},
|
|
191
|
-
);
|
|
183
|
+
logger.logDebug('isApiOrgConfigOrganizationSettings: data is not an object', undefined, {
|
|
184
|
+
data,
|
|
185
|
+
});
|
|
192
186
|
return false;
|
|
193
187
|
}
|
|
194
188
|
|
|
195
189
|
if (!('org' in data) || !isApiOrganization(data.org)) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
{
|
|
200
|
-
data,
|
|
201
|
-
},
|
|
202
|
-
);
|
|
190
|
+
logger.logDebug('isApiOrgConfigOrganizationSettings: org is not an object', undefined, {
|
|
191
|
+
data,
|
|
192
|
+
});
|
|
203
193
|
return false;
|
|
204
194
|
}
|
|
205
195
|
|
|
@@ -215,7 +205,7 @@ const isApiOrgConfigOrganizationSettings = (
|
|
|
215
205
|
*/
|
|
216
206
|
export const isApiOrgConfigResults = (data: unknown): data is Required<ApiOrgConfigResults> => {
|
|
217
207
|
if (data == null || typeof data !== 'object') {
|
|
218
|
-
|
|
208
|
+
logger.logDebug('isApiOrgConfigResults: data is not an object', undefined, {
|
|
219
209
|
data,
|
|
220
210
|
});
|
|
221
211
|
return false;
|
|
@@ -226,7 +216,7 @@ export const isApiOrgConfigResults = (data: unknown): data is Required<ApiOrgCon
|
|
|
226
216
|
!Array.isArray(data.configs) ||
|
|
227
217
|
!data.configs.every(config => isApiOrganizationConfig(config))
|
|
228
218
|
) {
|
|
229
|
-
|
|
219
|
+
logger.logDebug('isApiOrgConfigResults: configs is not an array', undefined, {
|
|
230
220
|
data,
|
|
231
221
|
});
|
|
232
222
|
return false;
|
|
@@ -238,8 +228,8 @@ export const isApiOrgConfigResults = (data: unknown): data is Required<ApiOrgCon
|
|
|
238
228
|
(!Array.isArray(data.experiments) ||
|
|
239
229
|
!data.experiments.every(exp => isApiOrgConfigExperiment(exp)))
|
|
240
230
|
) {
|
|
241
|
-
|
|
242
|
-
'
|
|
231
|
+
logger.logDebug(
|
|
232
|
+
'isApiOrgConfigResults: experiments is not an array or contains invalid items',
|
|
243
233
|
undefined,
|
|
244
234
|
{
|
|
245
235
|
data,
|
|
@@ -253,8 +243,8 @@ export const isApiOrgConfigResults = (data: unknown): data is Required<ApiOrgCon
|
|
|
253
243
|
!Array.isArray(data.gates) ||
|
|
254
244
|
!data.gates.every(gate => isApiOrgConfigFeatureGate(gate))
|
|
255
245
|
) {
|
|
256
|
-
|
|
257
|
-
'
|
|
246
|
+
logger.logDebug(
|
|
247
|
+
'isApiOrgConfigResults: gates is not an array or contains invalid items',
|
|
258
248
|
undefined,
|
|
259
249
|
{
|
|
260
250
|
data,
|
|
@@ -264,10 +254,12 @@ export const isApiOrgConfigResults = (data: unknown): data is Required<ApiOrgCon
|
|
|
264
254
|
}
|
|
265
255
|
|
|
266
256
|
if (!('org' in data) || !isApiOrgConfigOrganizationSettings(data.org)) {
|
|
267
|
-
|
|
268
|
-
'
|
|
257
|
+
logger.logDebug(
|
|
258
|
+
'isApiOrgConfigResults: org is not an object or has invalid fields',
|
|
269
259
|
undefined,
|
|
270
|
-
{
|
|
260
|
+
{
|
|
261
|
+
data,
|
|
262
|
+
},
|
|
271
263
|
);
|
|
272
264
|
|
|
273
265
|
return false;
|