@envive-ai/react-hooks 0.2.6-alpha-5 → 0.2.6-alpha-7
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/{AmplitudeOperations-CNFlPr53.cjs → AmplitudeOperations-DbUiR0N_.cjs} +3 -3
- package/dist/{AmplitudeOperations-cmAprPCA.js → AmplitudeOperations-DjqOM3uE.js} +2 -2
- package/dist/{NewOrgConfig-Bicbf8I7.js → NewOrgConfig-C_1T1iOt.js} +2 -2
- package/dist/{NewOrgConfig-6dFyYjJG.cjs → NewOrgConfig-D2Kvqa1z.cjs} +2 -2
- package/dist/{TrackComponentVisibleEvent-BebTjNtS.js → TrackComponentVisibleEvent-BxOhr9Da.js} +4 -4
- package/dist/{TrackComponentVisibleEvent-COwxsJRE.cjs → TrackComponentVisibleEvent-CDbecFPM.cjs} +5 -5
- package/dist/amplitudeContext-BWmXliMI.cjs +243 -0
- package/dist/amplitudeContext-BjMlg5RV.js +227 -0
- package/dist/amplitudeTrackEventAtom-D66l5oFp.js +8 -0
- package/dist/amplitudeTrackEventAtom-f22P2U0u.cjs +15 -0
- package/dist/app-Bs2KxG_8.js +515 -0
- package/dist/app-DSnDDqcW.cjs +570 -0
- package/dist/application/models/graphql/index.d.ts +1 -1
- package/dist/application/models/guards/api/index.d.ts +2 -2
- package/dist/application/models/guards/utils.d.ts +1 -1
- package/dist/application/models/index.cjs +2 -2
- package/dist/application/models/index.d.ts +4 -4
- package/dist/application/models/index.js +2 -2
- package/dist/application/utils/index.cjs +5 -14
- package/dist/application/utils/index.d.cts +7 -8
- package/dist/application/utils/index.d.ts +8 -9
- package/dist/application/utils/index.js +5 -14
- package/dist/{atomStore-CZKe3itM.cjs → atomStore-BQVO5haU.cjs} +1 -1
- package/dist/{atomStore-BuopbV9k.js → atomStore-CfzCqWB9.js} +1 -1
- package/dist/atoms/app/index.cjs +17 -19
- package/dist/atoms/app/index.d.cts +7 -7
- package/dist/atoms/app/index.d.ts +7 -7
- package/dist/atoms/app/index.js +12 -14
- package/dist/atoms/atomStore/index.cjs +1 -1
- package/dist/atoms/atomStore/index.d.ts +1 -1
- package/dist/atoms/atomStore/index.js +1 -1
- package/dist/atoms/chat/index.cjs +15 -17
- package/dist/atoms/chat/index.d.cts +33 -34
- package/dist/atoms/chat/index.d.ts +34 -35
- package/dist/atoms/chat/index.js +15 -17
- package/dist/atoms/globalSearch/index.cjs +1 -1
- package/dist/atoms/globalSearch/index.d.cts +6 -6
- package/dist/atoms/globalSearch/index.d.ts +6 -6
- package/dist/atoms/globalSearch/index.js +1 -1
- package/dist/atoms/org/index.cjs +2 -2
- package/dist/atoms/org/index.d.cts +17 -17
- package/dist/atoms/org/index.d.ts +17 -17
- package/dist/atoms/org/index.js +2 -2
- package/dist/atoms/search/index.cjs +6 -6
- package/dist/atoms/search/index.d.cts +15 -15
- package/dist/atoms/search/index.d.ts +14 -14
- package/dist/atoms/search/index.js +6 -6
- package/dist/atoms/search/utils.cjs +1 -1
- package/dist/atoms/search/utils.d.cts +1 -1
- package/dist/atoms/search/utils.d.ts +1 -1
- package/dist/atoms/search/utils.js +1 -1
- package/dist/{cdnContext-CuZwc-PI.js → cdnContext-CJ2BNLAD.js} +2 -2
- package/dist/{cdnContext-ClAEcKhO.cjs → cdnContext-lkC-AE6A.cjs} +2 -2
- package/dist/chat-C5afTKUY.js +226 -0
- package/dist/{chat-BJL3nXR7.cjs → chat-CCjM6fS_.cjs} +6 -7
- package/dist/{chat-DCGriB7h.cjs → chat-CJ9D8n7g.cjs} +1 -1
- package/dist/{chat-ClvJ9xEj.js → chat-EJbfGWRr.js} +1 -1
- package/dist/chatState-BbI93m6r.js +33 -0
- package/dist/chatState-DlJpHAsW.cjs +119 -0
- package/dist/{common-DQPvV_S_.cjs → common-CuwWqIJ1.cjs} +1 -1
- package/dist/{common-c_4eX0qn.js → common-Df2bwzd2.js} +1 -1
- package/dist/{components-DKwVHIjq.cjs → components-BCfFLf9X.cjs} +1 -1
- package/dist/{components-CDpaMUjK.js → components-QGCWJ26c.js} +1 -1
- package/dist/config/index.cjs +4 -4
- package/dist/config/index.d.cts +4 -4
- package/dist/config/index.d.ts +4 -4
- package/dist/config/index.js +4 -4
- package/dist/config/locators/components/chat/index.cjs +1 -1
- package/dist/config/locators/components/chat/index.d.cts +1 -1
- package/dist/config/locators/components/chat/index.d.ts +1 -1
- package/dist/config/locators/components/chat/index.js +1 -1
- package/dist/config/locators/components/common/index.cjs +1 -1
- package/dist/config/locators/components/common/index.d.cts +1 -1
- package/dist/config/locators/components/common/index.d.ts +1 -1
- package/dist/config/locators/components/common/index.js +1 -1
- package/dist/config/locators/components/index.cjs +1 -1
- package/dist/config/locators/components/index.d.cts +1 -1
- package/dist/config/locators/components/index.d.ts +1 -1
- package/dist/config/locators/components/index.js +1 -1
- package/dist/config/locators/index.cjs +4 -4
- package/dist/config/locators/index.d.cts +4 -4
- package/dist/config/locators/index.d.ts +4 -4
- package/dist/config/locators/index.js +4 -4
- package/dist/contexts/amplitudeContext/index.cjs +18 -17
- package/dist/contexts/amplitudeContext/index.d.cts +11 -2
- package/dist/contexts/amplitudeContext/index.d.ts +11 -2
- package/dist/contexts/amplitudeContext/index.js +17 -15
- package/dist/contexts/cdnContext/index.cjs +3 -3
- package/dist/contexts/cdnContext/index.d.cts +1 -1
- package/dist/contexts/cdnContext/index.js +3 -3
- package/dist/contexts/enviveConfigContext/index.cjs +3 -3
- package/dist/contexts/enviveConfigContext/index.d.cts +1 -1
- package/dist/contexts/enviveConfigContext/index.js +3 -3
- package/dist/contexts/enviveCssContext/index.cjs +10 -10
- package/dist/contexts/enviveCssContext/index.js +10 -10
- package/dist/contexts/featureFlagContext/index.cjs +4 -4
- package/dist/contexts/featureFlagContext/index.js +4 -4
- package/dist/contexts/featureFlagServiceContext/index.cjs +3 -3
- package/dist/contexts/featureFlagServiceContext/index.d.cts +1 -1
- package/dist/contexts/featureFlagServiceContext/index.d.ts +1 -1
- package/dist/contexts/featureFlagServiceContext/index.js +3 -3
- package/dist/contexts/graphqlContext/index.cjs +4 -4
- package/dist/contexts/graphqlContext/index.js +4 -4
- package/dist/contexts/localStorageContext/index.cjs +2 -2
- package/dist/contexts/localStorageContext/index.d.cts +1 -1
- package/dist/contexts/localStorageContext/index.js +2 -2
- package/dist/contexts/newOrgConfigContext/index.cjs +9 -9
- package/dist/contexts/newOrgConfigContext/index.js +9 -9
- package/dist/contexts/searchContext/index.cjs +18 -19
- package/dist/contexts/searchContext/index.js +18 -19
- package/dist/contexts/sessionStorageContext/index.cjs +1 -1
- package/dist/contexts/sessionStorageContext/index.js +1 -1
- package/dist/contexts/shopifyUrlContext/index.cjs +2 -2
- package/dist/contexts/shopifyUrlContext/index.d.cts +1 -1
- package/dist/contexts/shopifyUrlContext/index.js +2 -2
- package/dist/contexts/systemSettingsContext/index.cjs +3 -3
- package/dist/contexts/systemSettingsContext/index.d.cts +2 -2
- package/dist/contexts/systemSettingsContext/index.js +3 -3
- package/dist/contexts/userIdentityContext/index.cjs +14 -16
- package/dist/contexts/userIdentityContext/index.js +12 -14
- package/dist/{dist-CIM4YRqp.js → dist-C38adNK1.js} +1 -1
- package/dist/{dist-BZX_Mgfn.cjs → dist-VxRI6eQv.cjs} +1 -1
- package/dist/{domObserver-CwieVNgj.cjs → domObserver-C2oQO8vi.cjs} +1 -1
- package/dist/{domObserver-B19-69gW.js → domObserver-DNeeSh1F.js} +1 -1
- package/dist/{enviveConfig-CBnoutoK.js → enviveConfig-Ciq4ASoV.js} +2 -2
- package/dist/{enviveConfig-BwIaVAAm.cjs → enviveConfig-Dp80h9yu.cjs} +2 -2
- package/dist/{enviveConfigContext-B4nejwV9.js → enviveConfigContext-CCjJUmwp.js} +2 -2
- package/dist/{enviveConfigContext-DgewMgYS.cjs → enviveConfigContext-DoYP8KSw.cjs} +2 -2
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.js +1 -1
- package/dist/{events-BHBRLPWS.js → events-CXiS1aTc.js} +1 -1
- package/dist/{events-C8LA-0Tp.cjs → events-DBin1Z7o.cjs} +1 -1
- package/dist/exceptions/index.cjs +1 -1
- package/dist/exceptions/index.d.ts +1 -1
- package/dist/exceptions/index.js +1 -1
- package/dist/{exceptions-BBXmiU8P.cjs → exceptions-BjDgLzGi.cjs} +1 -1
- package/dist/{exceptions--fSXOzkB.js → exceptions-CUGY31Ua.js} +1 -1
- package/dist/{featureFlagServiceContext-B7je7VZV.d.cts → featureFlagServiceContext-ClnlCJV5.d.cts} +1 -1
- package/dist/{featureFlagServiceContext-CZj3qPX7.js → featureFlagServiceContext-Cvp7NlpC.js} +2 -2
- package/dist/{featureFlagServiceContext-DiYIv0jI.d.ts → featureFlagServiceContext-CyPGEe2d.d.ts} +1 -1
- package/dist/{featureFlagServiceContext-BkamHViU.cjs → featureFlagServiceContext-DHtkQAtq.cjs} +2 -2
- package/dist/{globalSearch-C94-vEVh.cjs → globalSearch-Cpc8egsM.cjs} +1 -1
- package/dist/{globalSearch-Dlbnfasm.js → globalSearch-nmrfGLOn.js} +1 -1
- package/dist/{graphqlContext-Capum8x6.js → graphqlContext-0cg9fEUw.js} +3 -3
- package/dist/{graphqlContext-C3HXFiHx.cjs → graphqlContext-ChXlE8Ul.cjs} +3 -3
- package/dist/hooks/AmplitudeOperations/index.cjs +17 -15
- package/dist/hooks/AmplitudeOperations/index.d.cts +1 -1
- package/dist/hooks/AmplitudeOperations/index.js +17 -15
- package/dist/hooks/AppDetails/index.cjs +15 -17
- package/dist/hooks/AppDetails/index.js +15 -17
- package/dist/hooks/BlockBackButton/index.d.cts +1 -1
- package/dist/hooks/CdnOperations/index.cjs +3 -3
- package/dist/hooks/CdnOperations/index.d.cts +1 -1
- package/dist/hooks/CdnOperations/index.d.ts +1 -1
- package/dist/hooks/CdnOperations/index.js +3 -3
- package/dist/hooks/ChatToggle/index.cjs +21 -19
- package/dist/hooks/ChatToggle/index.d.cts +1 -1
- package/dist/hooks/ChatToggle/index.js +20 -18
- package/dist/hooks/ChatToggleAnalytics/index.cjs +19 -17
- package/dist/hooks/ChatToggleAnalytics/index.d.cts +1 -1
- package/dist/hooks/ChatToggleAnalytics/index.js +19 -17
- package/dist/hooks/Debounce/index.d.cts +1 -1
- package/dist/hooks/ElementObserver/index.cjs +1 -1
- package/dist/hooks/ElementObserver/index.d.cts +1 -1
- package/dist/hooks/ElementObserver/index.d.ts +1 -1
- package/dist/hooks/ElementObserver/index.js +1 -1
- package/dist/hooks/GraphQLConfig/index.cjs +5 -5
- package/dist/hooks/GraphQLConfig/index.d.cts +1 -1
- package/dist/hooks/GraphQLConfig/index.js +5 -5
- package/dist/hooks/IdentifyUser/index.cjs +14 -16
- package/dist/hooks/IdentifyUser/index.d.cts +1 -1
- package/dist/hooks/IdentifyUser/index.js +13 -15
- package/dist/hooks/ImageResolver/index.cjs +2 -2
- package/dist/hooks/ImageResolver/index.d.cts +1 -1
- package/dist/hooks/ImageResolver/index.js +2 -2
- package/dist/hooks/Intersection/index.cjs +1 -1
- package/dist/hooks/Intersection/index.js +1 -1
- package/dist/hooks/IsSmallScreen/index.d.cts +1 -1
- package/dist/hooks/LocalStorageOperations/index.cjs +2 -2
- package/dist/hooks/LocalStorageOperations/index.d.cts +1 -1
- package/dist/hooks/LocalStorageOperations/index.js +2 -2
- package/dist/hooks/MessageFilter/index.cjs +1 -1
- package/dist/hooks/MessageFilter/index.d.cts +1 -1
- package/dist/hooks/MessageFilter/index.js +1 -1
- package/dist/hooks/MessageScrollObserver/index.d.cts +1 -1
- package/dist/hooks/NewOrgConfig/index.cjs +10 -10
- package/dist/hooks/NewOrgConfig/index.d.cts +2 -2
- package/dist/hooks/NewOrgConfig/index.d.ts +2 -2
- package/dist/hooks/NewOrgConfig/index.js +10 -10
- package/dist/hooks/Search/index.cjs +25 -23
- package/dist/hooks/Search/index.js +25 -23
- package/dist/hooks/SearchOperations/index.cjs +19 -20
- package/dist/hooks/SearchOperations/index.js +19 -20
- package/dist/hooks/SessionStorageOperations/index.cjs +1 -1
- package/dist/hooks/SessionStorageOperations/index.js +1 -1
- package/dist/hooks/ShopifyUrlOperations/index.cjs +2 -2
- package/dist/hooks/ShopifyUrlOperations/index.d.cts +2 -2
- package/dist/hooks/ShopifyUrlOperations/index.d.ts +2 -2
- package/dist/hooks/ShopifyUrlOperations/index.js +2 -2
- package/dist/hooks/SystemSettingsContext/index.cjs +3 -3
- package/dist/hooks/SystemSettingsContext/index.d.cts +4 -4
- package/dist/hooks/SystemSettingsContext/index.d.ts +4 -4
- package/dist/hooks/SystemSettingsContext/index.js +3 -3
- package/dist/hooks/TrackComponentVisibleEvent/index.cjs +18 -16
- package/dist/hooks/TrackComponentVisibleEvent/index.js +18 -16
- package/dist/hooks/UpdateAnalyticsProps/index.cjs +20 -18
- package/dist/hooks/UpdateAnalyticsProps/index.js +17 -15
- package/dist/hooks/utils.cjs +1 -1
- package/dist/hooks/utils.d.cts +1 -1
- package/dist/hooks/utils.js +1 -1
- package/dist/{index-CAhGZxMI.d.ts → index-5li6ZMDu.d.ts} +1 -1
- package/dist/{index-ca7Qn8o0.d.cts → index-BbqT4BQv.d.cts} +1 -1
- package/dist/{index-w64il54a.d.cts → index-CAJq_8bO.d.cts} +1 -1
- package/dist/index-CMZcE7pk.d.cts +1 -1
- package/dist/{index-BQpWG3Jm.d.cts → index-ChiZg0yw.d.cts} +1 -1
- package/dist/{index-DNccxbJi.d.ts → index-CsmO1rDH.d.ts} +1 -1
- package/dist/{index-Dgu085Lu.d.ts → index-CuihhoIF.d.ts} +2 -2
- package/dist/{index-BR1G8yyg.d.ts → index-DtzPIcQp.d.ts} +1 -1
- package/dist/{index-ZQMda2Iu.d.ts → index-bEjLKG_Q.d.ts} +1 -1
- package/dist/{index-DiIHuPq2.d.ts → index-jFQefHda.d.ts} +1 -1
- package/dist/{index-BO-ZLYtR.d.ts → index-mv7KvWDq.d.ts} +1 -1
- package/dist/{index-ClVBVK15.d.cts → index-npqPeJ1g.d.cts} +1 -1
- package/dist/interceptors/index.cjs +1 -1
- package/dist/interceptors/index.d.cts +1 -1
- package/dist/interceptors/index.d.ts +1 -1
- package/dist/interceptors/index.js +1 -1
- package/dist/{localStorageContext-p_4U0RPI.js → localStorageContext-BFwvuEcf.js} +2 -2
- package/dist/{localStorageContext-CPrkpt8i.cjs → localStorageContext-CWc5xJ6U.cjs} +2 -2
- package/dist/{locators-BMQGmGLq.js → locators-C2fWd-74.js} +1 -1
- package/dist/{locators-DxYdak1F.cjs → locators-Cx3q6Z_h.cjs} +1 -1
- package/dist/{models-L2w8FYCa.js → models-Cw0QcbQv.js} +2 -2
- package/dist/{models-OyYkll03.cjs → models-Dl0_Ujgj.cjs} +2 -2
- package/dist/{newOrgConfigAtom-Dsk0fJNR.js → newOrgConfigAtom-BuQE_zPK.js} +1 -1
- package/dist/{newOrgConfigAtom-hs5A1pbZ.cjs → newOrgConfigAtom-rrYHmp1b.cjs} +1 -1
- package/dist/{newOrgConfigContext-BuqDUkPz.js → newOrgConfigContext-D-gU5ppl.js} +5 -5
- package/dist/{newOrgConfigContext-N4CQzvlH.cjs → newOrgConfigContext-d3RHl430.cjs} +5 -5
- package/dist/{nodeSelector-0gJ8Xayf.d.ts → nodeSelector-BAKg1h_y.d.ts} +1 -1
- package/dist/{nodeSelector-Cj-Xl1LP.d.cts → nodeSelector-BYEAyrsj.d.cts} +1 -1
- package/dist/org-15F128Ah.js +32 -0
- package/dist/org-CIFgIcO4.cjs +111 -0
- package/dist/{search-C_N_oRVZ.js → search--80x6CfL.js} +5 -5
- package/dist/{search-8bPfo07V.cjs → search-Ch6LKNh4.cjs} +5 -5
- package/dist/{searchContext-DdJbpDsU.cjs → searchContext-B0qEUoKb.cjs} +6 -6
- package/dist/{searchContext-BohH5i8s.js → searchContext-BkPoTq1o.js} +6 -6
- package/dist/{searchServiceAdapter-BSPZOg1r.js → searchServiceAdapter-B0h7psvh.js} +1 -1
- package/dist/{searchServiceAdapter-DrjFCiw8.cjs → searchServiceAdapter-BclWy4fE.cjs} +1 -1
- package/dist/{sessionStorageContext-CH37Dkb-.cjs → sessionStorageContext-BuWrJQwc.cjs} +1 -1
- package/dist/{sessionStorageContext-CqrutoVq.js → sessionStorageContext-DvFHbk81.js} +1 -1
- package/dist/{shopifyUrlContext-Ba6MQdNV.cjs → shopifyUrlContext-Bw1kAZ2P.cjs} +2 -2
- package/dist/{shopifyUrlContext-BI3fVtA5.js → shopifyUrlContext-DnJiUmMA.js} +2 -2
- package/dist/src/application/commerce-api.js +408 -0
- package/dist/src/application/logging/logger.js +16 -0
- package/dist/src/application/models/graphql/index.js +3 -0
- package/dist/src/application/models/graphql/queries/getMerchantColorsQuery.js +13 -0
- package/dist/src/application/models/graphql/queries/getMerchantFrontendConfigQuery.js +13 -0
- package/dist/src/application/models/graphql/queries/getMerchantOrgIdQuery.js +10 -0
- package/dist/src/application/models/guards/api/index.js +12 -0
- package/dist/src/application/models/guards/api/isApiFormResponse.js +59 -0
- package/dist/src/application/models/guards/api/isApiFormSubmittedResponseAttributes.js +22 -0
- package/dist/src/application/models/guards/api/isApiOrderResponseAttributes.js +91 -0
- package/dist/src/application/models/guards/api/isApiOrgConfigResults.js +188 -0
- package/dist/src/application/models/guards/api/isApiOrganizationConfig.js +115 -0
- package/dist/src/application/models/guards/api/isApiPDPEventAttributes.js +16 -0
- package/dist/src/application/models/guards/api/isApiPLPEventAttributes.js +26 -0
- package/dist/src/application/models/guards/api/isApiPageResponseAttributes.js +15 -0
- package/dist/src/application/models/guards/api/isApiProductResponseAttributes.js +65 -0
- package/dist/src/application/models/guards/api/isApiProductSearchAttributes.js +15 -0
- package/dist/src/application/models/guards/api/isApiProductSearchFilterAttributes.js +10 -0
- package/dist/src/application/models/guards/api/isApiQueryTypedEventAttributes.js +4 -0
- package/dist/src/application/models/guards/api/isApiResponse.js +33 -0
- package/dist/src/application/models/guards/api/isApiReviewResponseAttributes.js +22 -0
- package/dist/src/application/models/guards/api/isApiReviewRichInformation.js +23 -0
- package/dist/src/application/models/guards/api/isApiSearchEventAttributes.js +20 -0
- package/dist/src/application/models/guards/api/isApiSuggestion.js +24 -0
- package/dist/src/application/models/guards/api/isApiSuggestionClickedEventAttributes.js +4 -0
- package/dist/src/application/models/guards/api/isApiTextResponseAttributes.js +4 -0
- package/dist/src/application/models/guards/api/isApiUserEvent.js +18 -0
- package/dist/src/application/models/guards/graphQL/isGraphQLColorsConfig.js +41 -0
- package/dist/src/application/models/guards/isBaseEcommerceEvent.js +14 -0
- package/dist/src/application/models/guards/isGA4EcommerceEvent.js +14 -0
- package/dist/src/application/models/guards/isLegacyUAEcommerceEvent.js +14 -0
- package/dist/src/application/models/guards/isMobilePLPChatPlacementParameter.js +4 -0
- package/dist/src/application/models/guards/isSpanxTakeAQuizCtaParameter.js +1 -0
- package/dist/src/application/models/guards/isVariantInfo.js +28 -0
- package/dist/src/application/models/guards/utils.js +34 -0
- package/dist/src/application/models/index.js +34 -0
- package/dist/src/application/models/utils/snakeToCamelTransformer.js +71 -0
- package/dist/src/application/models/utils/stringToFulfillmentDisplayStatusEnumValue.js +65 -0
- package/dist/src/application/models/validators/validateGraphQLColorsConfig.js +9 -0
- package/dist/src/application/models/validators/validateGraphQLFrontendConfig.js +420 -0
- package/dist/src/application/models/validators/validateGraphQLOrgId.js +6 -0
- package/dist/src/application/models/validators/validateMobilePLPChatPlacementParameter.js +9 -0
- package/dist/src/application/models/validators/validateOrgConfigResults.js +44 -0
- package/dist/src/application/models/validators/validateOrganizationConfig.js +34 -0
- package/dist/src/application/models/validators/validateResponse.js +173 -0
- package/dist/src/application/models/validators/validateSuggestion.js +13 -0
- package/dist/src/application/models/validators/validateUserEvent.js +91 -0
- package/dist/src/application/utils/analyticsUtils.js +95 -0
- package/dist/src/application/utils/coreContextToApiContext.js +8 -0
- package/dist/src/application/utils/coreUserEventToApiUserEvent.js +90 -0
- package/dist/src/application/utils/divideArray.js +7 -0
- package/dist/src/application/utils/domObserver.js +85 -0
- package/dist/src/application/utils/elementObserver.js +186 -0
- package/dist/src/application/utils/imageFilter.js +11 -0
- package/dist/src/application/utils/index.js +21 -0
- package/dist/src/application/utils/merchantUtils.js +15 -0
- package/dist/src/application/utils/messageFromFormSubmittedEvent.js +19 -0
- package/dist/src/application/utils/messageFromQueryEvent.js +35 -0
- package/dist/src/application/utils/messageFromResponse.js +123 -0
- package/dist/src/application/utils/messageFromSuggestionEvent.js +27 -0
- package/dist/src/application/utils/mouseEventTypes.js +1 -0
- package/dist/src/application/utils/mutationHelper.js +33 -0
- package/dist/src/application/utils/nextMessageRequestToApiRequest.js +29 -0
- package/dist/src/application/utils/nodeSelector.js +101 -0
- package/dist/src/application/utils/overrides.js +144 -0
- package/dist/src/application/utils/stringUtils.js +47 -0
- package/dist/src/application/utils/supportedEventRequestToApiRequest.js +7 -0
- package/dist/src/application/utils/urlsParser.js +33 -0
- package/dist/src/application/utils/validation.js +5 -0
- package/dist/src/atoms/amplitude/amplitudeTrackEventAtom.js +4 -0
- package/dist/src/atoms/app/index.js +23 -0
- package/dist/src/atoms/app/variant.js +102 -0
- package/dist/src/atoms/atomStore/atomStore.js +28 -0
- package/dist/src/atoms/atomStore/index.js +1 -0
- package/dist/src/atoms/chat/chatState.js +32 -0
- package/dist/src/atoms/chat/form.js +16 -0
- package/dist/src/atoms/chat/index.js +23 -0
- package/dist/src/atoms/chat/lastMessage.js +10 -0
- package/dist/src/atoms/chat/messageQueue.js +68 -0
- package/dist/src/atoms/chat/performanceMetrics.js +70 -0
- package/dist/src/atoms/chat/renderedWidgetRefs.js +24 -0
- package/dist/src/atoms/chat/replies.js +42 -0
- package/dist/src/atoms/chat/suggestions.js +29 -0
- package/dist/src/atoms/envive/enviveConfig.js +67 -0
- package/dist/src/atoms/globalSearch/globalSearch.js +8 -0
- package/dist/src/atoms/globalSearch/index.js +1 -0
- package/dist/src/atoms/org/customerService.js +6 -0
- package/dist/src/atoms/org/graphqlConfig.js +8 -0
- package/dist/src/atoms/org/index.js +4 -0
- package/dist/src/atoms/org/newOrgConfigAtom.js +2 -0
- package/dist/src/atoms/org/orgAnalyticsConfig.js +8 -0
- package/dist/src/atoms/search/index.js +1 -0
- package/dist/src/atoms/search/productFilters.js +163 -0
- package/dist/src/atoms/search/productRetrievalAPI.js +50 -0
- package/dist/src/atoms/search/productRetrievalAdapter.js +14 -0
- package/dist/src/atoms/search/productSorter.js +13 -0
- package/dist/src/atoms/search/searchAPI.js +140 -0
- package/dist/src/atoms/search/searchServiceAdapter.js +14 -0
- package/dist/src/atoms/search/utils.js +15 -0
- package/dist/src/config/index.js +1 -0
- package/dist/src/config/locators/components/chat/entrypoints.js +10 -0
- package/dist/src/config/locators/components/chat/index.js +21 -0
- package/dist/src/config/locators/components/chat/preview.js +11 -0
- package/dist/src/config/locators/components/chat/variants/index.js +12 -0
- package/dist/src/config/locators/components/common/buttons.js +6 -0
- package/dist/src/config/locators/components/common/cards.js +17 -0
- package/dist/src/config/locators/components/common/index.js +4 -0
- package/dist/src/config/locators/components/common/links.js +1 -0
- package/dist/src/config/locators/components/common/tables.js +1 -0
- package/dist/src/config/locators/components/floating-button.js +2 -0
- package/dist/src/config/locators/components/index.js +3 -0
- package/dist/src/config/locators/components/report-issue.js +13 -0
- package/dist/src/config/locators/components/search/index.js +5 -0
- package/dist/src/config/locators/components/shadow-dom.js +1 -0
- package/dist/src/config/locators/embedded.js +20 -0
- package/dist/src/config/locators/index.js +4 -0
- package/dist/src/contexts/amplitudeContext/amplitudeContext.js +271 -0
- package/dist/src/contexts/amplitudeContext/index.js +1 -0
- package/dist/src/contexts/cdnContext/cdnContext.js +28 -0
- package/dist/src/contexts/cdnContext/index.js +1 -0
- package/dist/src/contexts/enviveConfigContext/enviveConfigContext.js +37 -0
- package/dist/src/contexts/enviveConfigContext/index.js +1 -0
- package/dist/src/contexts/enviveCssContext/enviveCssContext.js +31 -0
- package/dist/src/contexts/enviveCssContext/index.js +1 -0
- package/dist/src/contexts/featureFlagContext/featureFlagContext.js +109 -0
- package/dist/src/contexts/featureFlagContext/index.js +1 -0
- package/dist/src/contexts/featureFlagServiceContext/featureFlagServiceContext.js +47 -0
- package/dist/src/contexts/featureFlagServiceContext/index.js +1 -0
- package/dist/src/contexts/graphqlContext/graphqlContext.js +87 -0
- package/dist/src/contexts/graphqlContext/index.js +1 -0
- package/dist/src/contexts/localStorageContext/index.js +1 -0
- package/dist/src/contexts/localStorageContext/localStorageContext.js +95 -0
- package/dist/src/contexts/newOrgConfigContext/index.js +1 -0
- package/dist/src/contexts/newOrgConfigContext/newOrgConfigContext.js +33 -0
- package/dist/src/contexts/searchContext/index.js +1 -0
- package/dist/src/contexts/searchContext/searchContext.js +131 -0
- package/dist/src/contexts/sessionStorageContext/index.js +1 -0
- package/dist/src/contexts/sessionStorageContext/sessionStorageContext.js +43 -0
- package/dist/src/contexts/shopifyUrlContext/index.js +1 -0
- package/dist/src/contexts/shopifyUrlContext/shopifyUrlContext.js +62 -0
- package/dist/src/contexts/systemSettingsContext/index.js +1 -0
- package/dist/src/contexts/systemSettingsContext/systemSettingsContext.js +29 -0
- package/dist/src/contexts/userIdentityContext/index.js +1 -0
- package/dist/src/contexts/userIdentityContext/userIdentityContext.js +118 -0
- package/dist/src/events/index.js +51 -0
- package/dist/src/events/registerAnalyticsListeners.js +32 -0
- package/dist/src/exceptions/index.js +2 -0
- package/dist/src/exceptions/sessionExceptions.js +6 -0
- package/dist/src/exceptions/unsupportedProductExceptions.js +6 -0
- package/dist/src/hooks/AmplitudeOperations/index.js +1 -0
- package/dist/src/hooks/AmplitudeOperations/useAmplitudeOperations.js +24 -0
- package/dist/src/hooks/AppDetails/index.js +1 -0
- package/dist/src/hooks/AppDetails/useAppDetails.js +26 -0
- package/dist/src/hooks/BlockBackButton/index.js +1 -0
- package/dist/src/hooks/BlockBackButton/useBlockBackButton.js +23 -0
- package/dist/src/hooks/CdnOperations/index.js +1 -0
- package/dist/src/hooks/CdnOperations/useCdnOperations.js +13 -0
- package/dist/src/hooks/ChatToggle/index.js +1 -0
- package/dist/src/hooks/ChatToggle/useChatToggle.js +50 -0
- package/dist/src/hooks/ChatToggleAnalytics/index.js +1 -0
- package/dist/src/hooks/ChatToggleAnalytics/useChatToggleAnalytics.js +11 -0
- package/dist/src/hooks/CustomerSupportHandoff/index.js +1 -0
- package/dist/src/hooks/CustomerSupportHandoff/useCustomerSupportHandoff.js +32 -0
- package/dist/src/hooks/Debounce/index.js +1 -0
- package/dist/src/hooks/Debounce/useDebounce.js +13 -0
- package/dist/src/hooks/ElementObserver/index.js +1 -0
- package/dist/src/hooks/ElementObserver/useElementObserver.js +208 -0
- package/dist/src/hooks/GrabAndScroll/index.js +1 -0
- package/dist/src/hooks/GrabAndScroll/useGrabAndScroll.js +105 -0
- package/dist/src/hooks/GraphQLConfig/index.js +1 -0
- package/dist/src/hooks/GraphQLConfig/useGraphQLConfig.js +54 -0
- package/dist/src/hooks/IdentifyUser/index.js +1 -0
- package/dist/src/hooks/IdentifyUser/useIdentifyUser.js +28 -0
- package/dist/src/hooks/ImageResolver/index.js +1 -0
- package/dist/src/hooks/ImageResolver/useImageResolver.js +45 -0
- package/dist/src/hooks/Intersection/index.js +1 -0
- package/dist/src/hooks/Intersection/useIntersection.js +20 -0
- package/dist/src/hooks/IsSmallScreen/index.js +1 -0
- package/dist/src/hooks/IsSmallScreen/useIsSmallScreen.js +16 -0
- package/dist/src/hooks/LocalStorageOperations/index.js +1 -0
- package/dist/src/hooks/LocalStorageOperations/useLocalStorageOperations.js +64 -0
- package/dist/src/hooks/MessageFilter/index.js +1 -0
- package/dist/src/hooks/MessageFilter/useMessageFilter.js +37 -0
- package/dist/src/hooks/MessageScrollObserver/index.js +1 -0
- package/dist/src/hooks/MessageScrollObserver/useMessageScrollObserver.js +35 -0
- package/dist/src/hooks/NewOrgConfig/index.js +1 -0
- package/dist/src/hooks/NewOrgConfig/useNewOrgConfig.js +5 -0
- package/dist/src/hooks/Search/index.js +1 -0
- package/dist/src/hooks/Search/useRecommendedProducts.js +35 -0
- package/dist/src/hooks/Search/useSearch.js +224 -0
- package/dist/src/hooks/Search/useSearchInput.js +192 -0
- package/dist/src/hooks/SearchOperations/index.js +1 -0
- package/dist/src/hooks/SearchOperations/useSearchOperations.js +78 -0
- package/dist/src/hooks/SessionStorageOperations/index.js +1 -0
- package/dist/src/hooks/SessionStorageOperations/useSessionStorageOperations.js +20 -0
- package/dist/src/hooks/ShopifyUrlOperations/index.js +1 -0
- package/dist/src/hooks/ShopifyUrlOperations/useShopifyUrlOperations.js +34 -0
- package/dist/src/hooks/SnapCalculator/index.js +1 -0
- package/dist/src/hooks/SnapCalculator/useSnapCalculator.js +22 -0
- package/dist/src/hooks/SystemSettingsContext/index.js +1 -0
- package/dist/src/hooks/SystemSettingsContext/useSystemSettingsContext.js +9 -0
- package/dist/src/hooks/TrackComponentVisibleEvent/index.js +1 -0
- package/dist/src/hooks/TrackComponentVisibleEvent/useTrackComponentVisibleEvent.js +45 -0
- package/dist/src/hooks/UpdateAnalyticsProps/index.js +1 -0
- package/dist/src/hooks/UpdateAnalyticsProps/useUpdateAnalyticsProps.js +43 -0
- package/dist/src/hooks/utils.js +116 -0
- package/dist/src/interceptors/index.js +1 -0
- package/dist/src/interceptors/useMessageInterceptor.js +24 -0
- package/dist/src/types/ApiResponse.js +1 -0
- package/dist/src/types/FilterAttribute.js +3 -0
- package/dist/src/types/Message.js +24 -0
- package/dist/src/types/Suggestion.js +3 -0
- package/dist/src/types/index.js +4 -0
- package/dist/src/util/colorVar.js +3 -0
- package/dist/src/util/configVersion.js +4 -0
- package/dist/src/util/domInsertion.js +16 -0
- package/dist/{systemSettingsContext-CYce8iqH.cjs → systemSettingsContext-068vQuP2.cjs} +2 -2
- package/dist/{systemSettingsContext-D9BZ9EwQ.js → systemSettingsContext-DPdDfVhj.js} +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/{urlsParser-C-Vzs--G.cjs → urlsParser-bb8ciRFg.cjs} +1 -1
- package/dist/{urlsParser-G7Ocwg0M.js → urlsParser-v_1DKvyf.js} +1 -1
- package/dist/{useAppDetails-CSpw8teP.js → useAppDetails-BPXln8UE.js} +4 -4
- package/dist/{useAppDetails-DNG_-DI9.cjs → useAppDetails-eP2hBuid.cjs} +7 -7
- package/dist/{useGraphQLConfig-D1REGfFB.js → useGraphQLConfig-Btszi6cG.js} +2 -2
- package/dist/{useGraphQLConfig-CKtaLlQ-.cjs → useGraphQLConfig-v9veUbvJ.cjs} +2 -2
- package/dist/{useIntersection-BQMfiS4x.cjs → useIntersection-BcBCa890.cjs} +1 -1
- package/dist/{useIntersection-D-ol9eH8.js → useIntersection-BkMkuJcZ.js} +1 -1
- package/dist/{utils-sosM0bEk.d.ts → utils-BitIIghf.d.ts} +1 -1
- package/dist/{utils-hYTjy7hJ.cjs → utils-CJk5iwQI.cjs} +1 -1
- package/dist/utils-CWzuvlOR.js +607 -0
- package/dist/{utils-BBICrPjW.cjs → utils-CqVRbvfN.cjs} +1 -1
- package/dist/{utils-w4-xONRA.js → utils-DQhbbAnt.js} +1 -1
- package/dist/{utils-D_kATUj6.js → utils-D_nGHczN.js} +1 -1
- package/dist/utils-SjlIHajO.cjs +716 -0
- package/package.json +1 -1
- package/src/application/commerce-api.ts +2 -0
- package/src/application/utils/analyticsUtils.ts +31 -16
- package/src/atoms/amplitude/amplitudeTrackEventAtom.ts +1 -1
- package/src/atoms/chat/chatState.ts +12 -7
- package/src/atoms/chat/replies.ts +42 -40
- package/src/contexts/amplitudeContext/amplitudeContext.tsx +116 -130
- package/dist/amplitudeContext-CMTvCsJC.d.ts +0 -52
- package/dist/amplitudeContext-ZkerrMUa.d.cts +0 -52
- package/dist/amplitudeTrackEventAtom-D9vs8dpE.cjs +0 -15
- package/dist/amplitudeTrackEventAtom-iEIu11Om.js +0 -8
- package/dist/chat-ChCtIEwh.js +0 -227
- package/dist/chatState-BYB77nbx.cjs +0 -120
- package/dist/chatState-CzH7APPP.js +0 -34
- package/dist/org-C2kLSSe9.cjs +0 -111
- package/dist/org-CIczyLRP.js +0 -32
- package/dist/utils-DGpMn2pp.js +0 -1364
- package/dist/utils-DqxtxrFe.cjs +0 -1546
- /package/dist/{featureFlagServiceContext-DgoR6euC.js → featureFlagServiceContext-CISyb90N.js} +0 -0
- /package/dist/{featureFlagServiceContext-b-rYgf0u.cjs → featureFlagServiceContext-Csgo-MUv.cjs} +0 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { ContextEnvEnum, Configuration, CustomerServiceApi, DefaultApi, InferenceApi, ResponseError, UserEventCategory, ContextSourceEnum, V1OrgConfigGetSourceEnum, ResponseCategory, FormType, } from "@spiffy-ai/commerce-api-client";
|
|
3
|
+
import { ProductExperiment, } from "@envive-ai/types";
|
|
4
|
+
import { userIdAtom, chatIdAtom } from "src/atoms/app";
|
|
5
|
+
import { getAtomStore } from "src/atoms/atomStore";
|
|
6
|
+
import { baseUrlAtom, orgShortNameAtom, contextSourceAtom, envAtom, reactAppNameAtom, } from "src/atoms/envive/enviveConfig";
|
|
7
|
+
import { orgIdAtom, featureFlagServiceAtom } from "src/atoms/org";
|
|
8
|
+
import { UnsupportedProductException, SessionRestartRequired, } from "src/exceptions";
|
|
9
|
+
import Logger from "./logging/logger";
|
|
10
|
+
import { validateResponse, validateSuggestion, validateUserEvent, validateOrgConfigResults, } from "./models";
|
|
11
|
+
import { messageRequestToCommerceMessageRequest, messageFromResponse, messageFromQueryEvent, messageFromSuggestionEvent, messageFromFormSubmittedEvent, coreSupportedEventRequestToApiRequest, } from "./utils";
|
|
12
|
+
async function errorResponseBody(error) {
|
|
13
|
+
try {
|
|
14
|
+
return await error.response.json();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async function throwSessionRestartRequiredIf(errorMsg, error) {
|
|
21
|
+
var _b, _c, _d, _e;
|
|
22
|
+
if (!(error instanceof ResponseError)) {
|
|
23
|
+
Logger.logInfo(errorMsg, error);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
const errorResponse = await errorResponseBody(error);
|
|
27
|
+
if (((_b = errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.message) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === "unsupported product" || // for backward compatibility. newer versions of the API return sub_code instead of message
|
|
28
|
+
((_c = errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.app_code) === null || _c === void 0 ? void 0 : _c.toUpperCase()) === "PRODUCT_NOT_FOUND") {
|
|
29
|
+
throw new UnsupportedProductException();
|
|
30
|
+
}
|
|
31
|
+
else if (((_d = errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.app_code) === null || _d === void 0 ? void 0 : _d.toUpperCase()) === "RESTART_SESSION" ||
|
|
32
|
+
((_e = errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.sub_code) === null || _e === void 0 ? void 0 : _e.toUpperCase()) === "NOT_FOUND" // for backward compatibility. new API responses will contain "app_code"
|
|
33
|
+
) {
|
|
34
|
+
Logger.logInfo("Session does not exist. Re-start session", error, error.response, errorResponse);
|
|
35
|
+
throw new SessionRestartRequired();
|
|
36
|
+
}
|
|
37
|
+
Logger.logInfo(errorMsg, error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
class CommerceApiClient {
|
|
41
|
+
constructor(basePath) {
|
|
42
|
+
this.suggestionsAbortController = new AbortController();
|
|
43
|
+
this.responsesAbortController = new AbortController();
|
|
44
|
+
const atomStore = getAtomStore();
|
|
45
|
+
const baseUrl = atomStore.get(baseUrlAtom);
|
|
46
|
+
const path = basePath || baseUrl;
|
|
47
|
+
// API Key is now handled at the EnviveConfigProvider level
|
|
48
|
+
const config = new Configuration({
|
|
49
|
+
basePath: path,
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
Accept: "application/json",
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
this.defaultApi = new DefaultApi(config);
|
|
56
|
+
this.inferenceApi = new InferenceApi(config);
|
|
57
|
+
this.customerServiceApi = new CustomerServiceApi(config);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
_a = CommerceApiClient;
|
|
61
|
+
CommerceApiClient.getInstance = () => {
|
|
62
|
+
if (!_a.instance) {
|
|
63
|
+
_a.instance = new _a();
|
|
64
|
+
}
|
|
65
|
+
return _a.instance;
|
|
66
|
+
};
|
|
67
|
+
CommerceApiClient.resolveUrl = async (url) => {
|
|
68
|
+
var _b, _c;
|
|
69
|
+
const atomStore = getAtomStore();
|
|
70
|
+
const orgShortName = atomStore.get(orgShortNameAtom);
|
|
71
|
+
const orgId = atomStore.get(orgIdAtom);
|
|
72
|
+
const userId = atomStore.get(userIdAtom);
|
|
73
|
+
const chatId = atomStore.get(chatIdAtom);
|
|
74
|
+
const source = atomStore.get(contextSourceAtom);
|
|
75
|
+
const env = atomStore.get(envAtom);
|
|
76
|
+
const featureFlagService = atomStore.get(featureFlagServiceAtom);
|
|
77
|
+
const context = {
|
|
78
|
+
user_id: userId !== null && userId !== void 0 ? userId : "",
|
|
79
|
+
org_id: orgId !== null && orgId !== void 0 ? orgId : "",
|
|
80
|
+
org_short_name: orgShortName !== null && orgShortName !== void 0 ? orgShortName : "",
|
|
81
|
+
chat_id: chatId !== null && chatId !== void 0 ? chatId : "",
|
|
82
|
+
source: source !== null && source !== void 0 ? source : ContextSourceEnum.App,
|
|
83
|
+
env: (_b = env) !== null && _b !== void 0 ? _b : ContextEnvEnum.Dev, // Cast env to ContextEnvEnum
|
|
84
|
+
};
|
|
85
|
+
const featureGates = ((_c = featureFlagService === null || featureFlagService === void 0 ? void 0 : featureFlagService.featureFlagService) === null || _c === void 0 ? void 0 : _c.getFeatureFlags()) || {};
|
|
86
|
+
const urlResolvingRequest = {
|
|
87
|
+
url,
|
|
88
|
+
context,
|
|
89
|
+
feature_gates: featureGates,
|
|
90
|
+
};
|
|
91
|
+
const rawResponse = await _a.getInstance().inferenceApi.v1UrlResolvingPostRaw({
|
|
92
|
+
UrlResolvingRequest: urlResolvingRequest,
|
|
93
|
+
});
|
|
94
|
+
const responseBody = await rawResponse.raw.json();
|
|
95
|
+
return responseBody;
|
|
96
|
+
};
|
|
97
|
+
CommerceApiClient.reportSession = async (reportRequest) => {
|
|
98
|
+
await _a.getInstance().defaultApi.v1ChatsReportSessionIdPost({
|
|
99
|
+
ReportSessionRequest: reportRequest,
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
CommerceApiClient.getNextResponses = async (payload) => {
|
|
103
|
+
try {
|
|
104
|
+
const response = await _a.getInstance().inferenceApi.v1NextResponsesPost({
|
|
105
|
+
NextMessageRequest: messageRequestToCommerceMessageRequest(payload),
|
|
106
|
+
});
|
|
107
|
+
const messages = response
|
|
108
|
+
.map((resp) => validateResponse(resp))
|
|
109
|
+
.map((resp) => messageFromResponse(resp));
|
|
110
|
+
return messages.filter((m) => m != null);
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
Logger.logInfo("Failed to get next responses", err, {
|
|
114
|
+
payloadContext: payload === null || payload === void 0 ? void 0 : payload.context,
|
|
115
|
+
userEvents: payload === null || payload === void 0 ? void 0 : payload.userEvents,
|
|
116
|
+
});
|
|
117
|
+
await throwSessionRestartRequiredIf("Failed to get next responses", err);
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
CommerceApiClient.getNextResponseStreaming = (payload) => {
|
|
122
|
+
async function* generate(inferenceApi, abortController) {
|
|
123
|
+
// make sure streaming is enabled
|
|
124
|
+
try {
|
|
125
|
+
const response = await inferenceApi.v1NextResponsesPostRaw({
|
|
126
|
+
NextMessageRequest: messageRequestToCommerceMessageRequest(payload),
|
|
127
|
+
}, { signal: abortController.signal });
|
|
128
|
+
// Read the response as a stream of data
|
|
129
|
+
if (!response.raw.body) {
|
|
130
|
+
Logger.logError("[spiffy-ai] No body in the streamed response", undefined, {
|
|
131
|
+
response: response.raw,
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const reader = response.raw.body.getReader();
|
|
136
|
+
const decoder = new TextDecoder("utf-8");
|
|
137
|
+
let partial = "";
|
|
138
|
+
// TODO this function is recreated every time new data comes from the stream - define it outside of the generator
|
|
139
|
+
const safeParse = (line) => {
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(line); // Parse the JSON string
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
Logger.logError("[spiffy-ai] Error parsing streamed line", err, {
|
|
145
|
+
line,
|
|
146
|
+
partial,
|
|
147
|
+
});
|
|
148
|
+
// swallow the error and set the partial to our current chunk
|
|
149
|
+
partial = line;
|
|
150
|
+
return partial;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
// TODO this function is recreated every time new data comes from the stream - define it outside of the generator
|
|
154
|
+
const processChunk = (chunk) => {
|
|
155
|
+
// merge the partial with the incoming chunk
|
|
156
|
+
const lines = `${partial}${chunk}`.split("\n");
|
|
157
|
+
const parsedLines = lines
|
|
158
|
+
.map((line) => line.replace(/^data: /, "").trim()) // Remove the "data: " prefix
|
|
159
|
+
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
|
160
|
+
.map(safeParse)
|
|
161
|
+
.filter((v) => v); // and filter out the undefined values
|
|
162
|
+
return parsedLines;
|
|
163
|
+
};
|
|
164
|
+
while (true) {
|
|
165
|
+
// eslint-disable-next-line no-await-in-loop
|
|
166
|
+
const { done, value } = await reader.read();
|
|
167
|
+
if (done) {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
// Massage and parse the chunk of data
|
|
171
|
+
const chunk = decoder.decode(value);
|
|
172
|
+
const parsedLines = processChunk(chunk);
|
|
173
|
+
for (const parsedLine of parsedLines) {
|
|
174
|
+
const validatedResponse = validateResponse(parsedLine);
|
|
175
|
+
if (validatedResponse) {
|
|
176
|
+
yield validatedResponse;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
Logger.logError("[spiffy-ai] Failed to get next streaming responses", error, {
|
|
183
|
+
payloadContext: payload === null || payload === void 0 ? void 0 : payload.context,
|
|
184
|
+
userEvents: payload === null || payload === void 0 ? void 0 : payload.userEvents,
|
|
185
|
+
});
|
|
186
|
+
await throwSessionRestartRequiredIf("Failed to get next streaming responses", error);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
_a.getInstance().responsesAbortController.abort();
|
|
190
|
+
_a.getInstance().responsesAbortController =
|
|
191
|
+
new AbortController();
|
|
192
|
+
return generate(_a.getInstance().inferenceApi, _a.getInstance().responsesAbortController);
|
|
193
|
+
};
|
|
194
|
+
CommerceApiClient.getNextSuggestions = async (payload) => {
|
|
195
|
+
try {
|
|
196
|
+
_a.getInstance().suggestionsAbortController.abort();
|
|
197
|
+
_a.getInstance().suggestionsAbortController =
|
|
198
|
+
new AbortController();
|
|
199
|
+
const response = await _a.getInstance().inferenceApi.v1NextSuggestionsPost({
|
|
200
|
+
NextMessageRequest: messageRequestToCommerceMessageRequest(payload),
|
|
201
|
+
}, {
|
|
202
|
+
signal: _a.getInstance().suggestionsAbortController.signal,
|
|
203
|
+
});
|
|
204
|
+
const suggestions = response
|
|
205
|
+
.map((resp) => validateSuggestion(resp))
|
|
206
|
+
.filter((suggestion) => suggestion != null);
|
|
207
|
+
return suggestions;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
Logger.logInfo("Failed to get suggestions", error, {
|
|
211
|
+
payloadContext: payload === null || payload === void 0 ? void 0 : payload.context,
|
|
212
|
+
userEvents: payload === null || payload === void 0 ? void 0 : payload.userEvents,
|
|
213
|
+
});
|
|
214
|
+
await throwSessionRestartRequiredIf("Failed to get suggestions", error);
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Fetches the existing chat data for a given session and transforms them to reconstruct the chat history.
|
|
220
|
+
*
|
|
221
|
+
* @param orgId The organization Id
|
|
222
|
+
* @param chatId The existing chat Id
|
|
223
|
+
* @param userId The user Id
|
|
224
|
+
*
|
|
225
|
+
* @returns A list of messages that were exchanged in the chat, throws an error if the chat session has expired.
|
|
226
|
+
*/
|
|
227
|
+
CommerceApiClient.getResponses = async (orgId, chatId, userId) => {
|
|
228
|
+
var _b;
|
|
229
|
+
let data = {
|
|
230
|
+
responses: [],
|
|
231
|
+
suggestions: [],
|
|
232
|
+
user_events: [],
|
|
233
|
+
};
|
|
234
|
+
const request = {
|
|
235
|
+
org_id: orgId,
|
|
236
|
+
chat_id: chatId,
|
|
237
|
+
user_id: userId,
|
|
238
|
+
};
|
|
239
|
+
try {
|
|
240
|
+
data =
|
|
241
|
+
await _a.getInstance().defaultApi.v1GetSessionMessages(request);
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
await throwSessionRestartRequiredIf("Failed to get chat responses", error);
|
|
245
|
+
}
|
|
246
|
+
const responses = (_b = data === null || data === void 0 ? void 0 : data.responses) === null || _b === void 0 ? void 0 : _b.map((turn) => turn
|
|
247
|
+
.map((response) => validateResponse(response))
|
|
248
|
+
.filter((response) => response != null));
|
|
249
|
+
const suggestions = data === null || data === void 0 ? void 0 : data.suggestions.map((suggestion) => validateSuggestion(suggestion)).filter((suggestion) => suggestion != null);
|
|
250
|
+
const userEvents = data === null || data === void 0 ? void 0 : data.user_events.map((event) => validateUserEvent(event)).filter((event) => event != null);
|
|
251
|
+
// if a form has already been submitted, don't show it in the chat history
|
|
252
|
+
const formSubmittedUserEventsFormIds = userEvents
|
|
253
|
+
.filter((event) => event.category === UserEventCategory.FormSubmitted)
|
|
254
|
+
.map((event) => event.attributes.formResponseId);
|
|
255
|
+
const assistantMessages = responses
|
|
256
|
+
.map((turn) => turn
|
|
257
|
+
.filter((response) => !(response.category === ResponseCategory.Form &&
|
|
258
|
+
formSubmittedUserEventsFormIds.includes(response.id)))
|
|
259
|
+
.map((response) => messageFromResponse(response))
|
|
260
|
+
.filter((message) => message != null))
|
|
261
|
+
.filter((turn) => turn.length > 0);
|
|
262
|
+
const userMessages = userEvents
|
|
263
|
+
.map((event) => {
|
|
264
|
+
if ([UserEventCategory.QueryTyped, UserEventCategory.Search].includes(event.category)) {
|
|
265
|
+
return [messageFromQueryEvent(event)];
|
|
266
|
+
}
|
|
267
|
+
if (event.category === UserEventCategory.SuggestionClicked) {
|
|
268
|
+
return [messageFromSuggestionEvent(event, suggestions)];
|
|
269
|
+
}
|
|
270
|
+
if (event.category === UserEventCategory.FormSubmitted) {
|
|
271
|
+
const formResponse = responses
|
|
272
|
+
.flat()
|
|
273
|
+
.find((response) => response.id === event.attributes.formResponseId &&
|
|
274
|
+
event.attributes.formType !== FormType.Escalation);
|
|
275
|
+
if (formResponse && formResponse.category === ResponseCategory.Form) {
|
|
276
|
+
return [
|
|
277
|
+
messageFromFormSubmittedEvent(event, formResponse.attributes),
|
|
278
|
+
];
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return [];
|
|
282
|
+
})
|
|
283
|
+
.filter((message) => message.length > 0);
|
|
284
|
+
// Sort the messages chronologically to reconstruct the chat history
|
|
285
|
+
const sortedMessages = [...assistantMessages, ...userMessages].sort((a, b) => new Date(a[0].createdAt).getTime() - new Date(b[0].createdAt).getTime());
|
|
286
|
+
return { responses, userEvents, suggestions, messages: sortedMessages };
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
*
|
|
290
|
+
* @param payload
|
|
291
|
+
* @returns
|
|
292
|
+
*/
|
|
293
|
+
CommerceApiClient.isSupportedEvent = async (payload) => {
|
|
294
|
+
try {
|
|
295
|
+
const rawResponse = await _a.getInstance().inferenceApi.v1SupportedEventPostRaw({
|
|
296
|
+
SupportedEventRequest: coreSupportedEventRequestToApiRequest(payload),
|
|
297
|
+
});
|
|
298
|
+
// Get the actual HTTP response JSON
|
|
299
|
+
const httpResponseText = await rawResponse.raw.text();
|
|
300
|
+
const httpResponseJson = JSON.parse(httpResponseText);
|
|
301
|
+
return {
|
|
302
|
+
...httpResponseJson,
|
|
303
|
+
numberOfReviews: httpResponseJson.num_of_reviews,
|
|
304
|
+
merchant_tags: httpResponseJson.merchant_tags || [],
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
catch (err) {
|
|
308
|
+
Logger.logError("Failed to get response for v1SupportedEventPost", {
|
|
309
|
+
err,
|
|
310
|
+
});
|
|
311
|
+
return {
|
|
312
|
+
supported: false,
|
|
313
|
+
ready: false,
|
|
314
|
+
category: undefined,
|
|
315
|
+
collections: [],
|
|
316
|
+
numberOfReviews: undefined,
|
|
317
|
+
top_category: undefined,
|
|
318
|
+
merchant_tags: [],
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
CommerceApiClient.identifyUser = async (spiffyUserId, merchantUserId, uaDetails) => {
|
|
323
|
+
try {
|
|
324
|
+
await _a.getInstance().defaultApi.v1AnalyticsIdentifyPost({
|
|
325
|
+
AnalyticsIdentifyRequest: {
|
|
326
|
+
user_id: spiffyUserId,
|
|
327
|
+
os_name: uaDetails.os,
|
|
328
|
+
os_version: uaDetails.osVersion,
|
|
329
|
+
platform: uaDetails.os,
|
|
330
|
+
device_id: uaDetails.deviceModel,
|
|
331
|
+
device_brand: uaDetails.deviceBrand,
|
|
332
|
+
device_manufacturer: uaDetails.deviceManufacturer,
|
|
333
|
+
device_model: uaDetails.deviceModel,
|
|
334
|
+
user_properties: {
|
|
335
|
+
cdp_user_id: merchantUserId,
|
|
336
|
+
browser: uaDetails.browser,
|
|
337
|
+
browser_version: uaDetails.browserVersion,
|
|
338
|
+
user_agent: uaDetails.userAgent,
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
catch (err) {
|
|
344
|
+
Logger.logError("Failed to identify user", err);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
CommerceApiClient.mapContextSourceToV1OrgConfigGetSource = (source) => {
|
|
348
|
+
if (source === undefined)
|
|
349
|
+
return undefined;
|
|
350
|
+
switch (source) {
|
|
351
|
+
case ContextSourceEnum.Fork:
|
|
352
|
+
return V1OrgConfigGetSourceEnum.Fork;
|
|
353
|
+
case ContextSourceEnum.Playground:
|
|
354
|
+
return V1OrgConfigGetSourceEnum.Playground;
|
|
355
|
+
case ContextSourceEnum.App:
|
|
356
|
+
return V1OrgConfigGetSourceEnum.App;
|
|
357
|
+
case ContextSourceEnum.Test:
|
|
358
|
+
return V1OrgConfigGetSourceEnum.Test;
|
|
359
|
+
case ContextSourceEnum.Eval:
|
|
360
|
+
return V1OrgConfigGetSourceEnum.Test;
|
|
361
|
+
default: {
|
|
362
|
+
// This ensures that if new values are added to ContextSourceEnum, we catch it
|
|
363
|
+
const exhaustiveCheck = source;
|
|
364
|
+
return exhaustiveCheck;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
CommerceApiClient.getOrgConfig = async (user_id) => {
|
|
369
|
+
var _b;
|
|
370
|
+
try {
|
|
371
|
+
const atomStore = getAtomStore();
|
|
372
|
+
const reactAppName = atomStore.get(reactAppNameAtom);
|
|
373
|
+
const contextSource = atomStore.get(contextSourceAtom);
|
|
374
|
+
const featureFlagService = atomStore.get(featureFlagServiceAtom); // Get featureFlagService
|
|
375
|
+
const request = {
|
|
376
|
+
namespace: reactAppName,
|
|
377
|
+
user_id,
|
|
378
|
+
source: _a.mapContextSourceToV1OrgConfigGetSource(contextSource),
|
|
379
|
+
include_experiments: Object.values(ProductExperiment),
|
|
380
|
+
include_feature_gates: Object.entries(((_b = featureFlagService === null || featureFlagService === void 0 ? void 0 : featureFlagService.featureFlagService) === null || _b === void 0 ? void 0 : _b.getFeatureFlags()) || {})
|
|
381
|
+
.filter(([, isEnabled]) => isEnabled)
|
|
382
|
+
.map(([featureGateName]) => featureGateName), // Use featureFlagService
|
|
383
|
+
};
|
|
384
|
+
const response = await _a.getInstance().defaultApi.v1OrgConfigGet(request);
|
|
385
|
+
return validateOrgConfigResults(response);
|
|
386
|
+
}
|
|
387
|
+
catch (err) {
|
|
388
|
+
Logger.logError(`Failed to get org config`, err, { err });
|
|
389
|
+
return undefined;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
CommerceApiClient.addNoteToLatestConversation = async (spiffyUserId, email, customerServiceProvider) => {
|
|
393
|
+
Logger.logInfo(`addNoteToLatestConversation - user_id=${spiffyUserId} email=${email} customer_service_provider=${customerServiceProvider}`);
|
|
394
|
+
try {
|
|
395
|
+
await _a.getInstance().customerServiceApi.v1CustserviceAddNoteToLatestConversationPost({
|
|
396
|
+
AddNoteToLatestConversationRequest: {
|
|
397
|
+
spiffy_user_id: spiffyUserId,
|
|
398
|
+
email,
|
|
399
|
+
customer_service_provider: customerServiceProvider,
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
catch (err) {
|
|
404
|
+
Logger.logError("Failed to add note to latest conversation", { err });
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
CommerceApiClient.getCustomerServiceApi = () => _a.getInstance().customerServiceApi;
|
|
408
|
+
export default CommerceApiClient;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
class Logger {
|
|
3
|
+
static logInfo(message, ...args) {
|
|
4
|
+
console.info(`INFO: ${message}`, ...args);
|
|
5
|
+
}
|
|
6
|
+
static logDebug(message, ...args) {
|
|
7
|
+
console.debug(`DEBUG: ${message}`, ...args);
|
|
8
|
+
}
|
|
9
|
+
static logError(message, error, ...args) {
|
|
10
|
+
console.error(`ERROR: ${message} error=${error}`, args);
|
|
11
|
+
}
|
|
12
|
+
static logWarn(message, error, ...args) {
|
|
13
|
+
console.warn(`WARN: ${message} error=${error}`, args);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export default Logger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { configVersion } from '../../../../util/configVersion';
|
|
2
|
+
const getMerchantColorsQuery = () => `
|
|
3
|
+
query ($version: "${configVersion()}") {
|
|
4
|
+
me {
|
|
5
|
+
getProductsConfigByVersion(version: $version) {
|
|
6
|
+
colors {
|
|
7
|
+
values
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
export { getMerchantColorsQuery };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { configVersion } from '../../../../util/configVersion';
|
|
2
|
+
const getMerchantFrontendConfigQuery = () => `
|
|
3
|
+
query ($version: "${configVersion()}") {
|
|
4
|
+
me {
|
|
5
|
+
getProductsConfigByVersion(version: $version) {
|
|
6
|
+
frontend {
|
|
7
|
+
values
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
export { getMerchantFrontendConfigQuery };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './isApiPDPEventAttributes';
|
|
2
|
+
export * from './isApiQueryTypedEventAttributes';
|
|
3
|
+
export * from './isApiResponse';
|
|
4
|
+
export * from './isApiProductResponseAttributes';
|
|
5
|
+
export * from './isApiReviewResponseAttributes';
|
|
6
|
+
export * from './isApiReviewRichInformation';
|
|
7
|
+
export * from './isApiSearchEventAttributes';
|
|
8
|
+
export * from './isApiSuggestion';
|
|
9
|
+
export * from './isApiSuggestionClickedEventAttributes';
|
|
10
|
+
export * from './isApiTextResponseAttributes';
|
|
11
|
+
export * from './isApiUserEvent';
|
|
12
|
+
export * from './isApiProductSearchAttributes';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FormType } from '@spiffy-ai/commerce-api-client';
|
|
2
|
+
import Logger from 'src/application/logging/logger';
|
|
3
|
+
import { hasPropertyOfType } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Type guard to check if the provided data has the all of the properties (with the correct types) of
|
|
6
|
+
* a FormResponseAttribute
|
|
7
|
+
*
|
|
8
|
+
* @param data - The data to check
|
|
9
|
+
*
|
|
10
|
+
* @returns true if the data has the correct properties, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
export const isApiFormResponseAttributes = (data) => {
|
|
13
|
+
if (data == null || typeof data !== 'object') {
|
|
14
|
+
Logger.logError('isApiFormResponseAttributes: data is null or not an object', undefined, {
|
|
15
|
+
data,
|
|
16
|
+
});
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if ('form_category' in data && typeof data.form_category !== 'object') {
|
|
20
|
+
Logger.logError('isApiFormResponseAttributes: form_category is not an object', undefined, {
|
|
21
|
+
data,
|
|
22
|
+
});
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if ('form_category' in data && typeof data.form_category === 'object') {
|
|
26
|
+
if (!hasPropertyOfType(data.form_category, 'form_type', 'string') ||
|
|
27
|
+
!Object.values(FormType).includes(data.form_category.form_type)) {
|
|
28
|
+
Logger.logError('isApiFormResponseAttributes: form_type is missing or not a valid form type', undefined, {
|
|
29
|
+
data,
|
|
30
|
+
});
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (!hasPropertyOfType(data, 'schema', 'object')) {
|
|
35
|
+
Logger.logError('isApiFormResponseAttributes: schema is missing or not an object', undefined, {
|
|
36
|
+
data,
|
|
37
|
+
});
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// TODO: also wanna validate the fields of data.schema.properties but might wanna change the schema
|
|
41
|
+
// to not have the property name as a key in the object
|
|
42
|
+
if (!hasPropertyOfType(data.schema, 'properties', 'object')) {
|
|
43
|
+
Logger.logError('isApiFormResponseAttributes: schema.properties is missing or not an object', undefined, {
|
|
44
|
+
data,
|
|
45
|
+
});
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (!hasPropertyOfType(data.schema, 'required', 'array')) {
|
|
49
|
+
Logger.logError('isApiFormResponseAttributes: schema.required is missing or not an array', undefined, { data });
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
if (!data.schema.required.every((key) => typeof key === 'string' && key in data.schema.properties)) {
|
|
53
|
+
Logger.logError('isApiFormResponseAttributes: schema.required contains invalid property keys', undefined, {
|
|
54
|
+
data,
|
|
55
|
+
});
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FormType } from '@spiffy-ai/commerce-api-client';
|
|
2
|
+
import Logger from 'src/application/logging/logger';
|
|
3
|
+
import { hasPropertyOfType } from '../utils';
|
|
4
|
+
export const isApiFormSubmittedResponseAttributes = (data) => {
|
|
5
|
+
if (data == null || typeof data !== 'object') {
|
|
6
|
+
Logger.logError('isApiFormSubmittedResponseAttributes', 'data is null or not an object', data);
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (!hasPropertyOfType(data, 'filled_schema', 'object')) {
|
|
10
|
+
Logger.logError('isApiFormSubmittedResponseAttributes', 'filled_schema is not an object', data);
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
if (!hasPropertyOfType(data, 'form_response_id', 'string')) {
|
|
14
|
+
Logger.logError('isApiFormSubmittedResponseAttributes', 'form_response_id is not a string', data);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (!('form_type' in data) || !Object.values(FormType).includes(data.form_type)) {
|
|
18
|
+
Logger.logError('isApiFormSubmittedResponseAttributes', 'form_type is not a valid form type enum', data);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import Logger from 'src/application/logging/logger';
|
|
2
|
+
import { hasPropertyOfType } from '../utils';
|
|
3
|
+
const isApiOrderItemInfo = (data) => {
|
|
4
|
+
if (data == null || typeof data !== 'object') {
|
|
5
|
+
Logger.logError('OrderItemInfo must be an object', undefined, { data });
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (!hasPropertyOfType(data, 'order_item_id', 'string')) {
|
|
9
|
+
Logger.logError('OrderItemInfo must have an order_item_id property', undefined, { data });
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (!hasPropertyOfType(data, 'item_title', 'string')) {
|
|
13
|
+
Logger.logError('OrderItemInfo must have an item_title property', undefined, { data });
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (!hasPropertyOfType(data, 'item_price', 'number')) {
|
|
17
|
+
Logger.logError('OrderItemInfo must have an item_price property', undefined, { data });
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (!hasPropertyOfType(data, 'item_quantity', 'number')) {
|
|
21
|
+
Logger.logError('OrderItemInfo must have an item_quantity property', undefined, { data });
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (!hasPropertyOfType(data, 'image', 'string', true)) {
|
|
25
|
+
Logger.logError('OrderItemInfo.image must be a string or null', undefined, { data });
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (!hasPropertyOfType(data, 'fulfillment_display_status', 'string', true)) {
|
|
29
|
+
Logger.logError('OrderItemInfo.fulfillment_display_status must be a string or null', undefined, {
|
|
30
|
+
data,
|
|
31
|
+
});
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (!hasPropertyOfType(data, 'tracking_url', 'string', true)) {
|
|
35
|
+
Logger.logError('OrderItemInfo.tracking_url must be a string or null', undefined, { data });
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (!hasPropertyOfType(data, 'delivered_at', 'string', true)) {
|
|
39
|
+
Logger.logError('OrderItemInfo.delivered_at must be a string or null', undefined, { data });
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (!hasPropertyOfType(data, 'estimated_delivery_at', 'string', true)) {
|
|
43
|
+
Logger.logError('OrderItemInfo.estimated_delivery_at must be a string or null', undefined, {
|
|
44
|
+
data,
|
|
45
|
+
});
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (!hasPropertyOfType(data, 'in_transit_at', 'string', true)) {
|
|
49
|
+
Logger.logError('OrderItemInfo.in_transit_at must be a string or null', undefined, { data });
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
export const isApiOrderResponseAttributes = (data) => {
|
|
55
|
+
if (data == null || typeof data !== 'object') {
|
|
56
|
+
Logger.logError('Order response attributes must be an object', undefined, { data });
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (!hasPropertyOfType(data, 'created_at', 'string')) {
|
|
60
|
+
Logger.logError('Order response attributes must have a created_at property and have type string', undefined, {
|
|
61
|
+
data,
|
|
62
|
+
});
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (!hasPropertyOfType(data, 'latest_event_date', 'string')) {
|
|
66
|
+
Logger.logError('Order response attributes must have a latest_event_date property and have type string', undefined, {
|
|
67
|
+
data,
|
|
68
|
+
});
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (!hasPropertyOfType(data, 'line_items', 'array') ||
|
|
72
|
+
!data.line_items.every((item) => isApiOrderItemInfo(item))) {
|
|
73
|
+
Logger.logError('Order response attributes must have a line_items property with at least one order item', undefined, {
|
|
74
|
+
data,
|
|
75
|
+
});
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!hasPropertyOfType(data, 'order_id', 'string')) {
|
|
79
|
+
Logger.logError('Order response attributes must have an order_id property and have type string', undefined, {
|
|
80
|
+
data,
|
|
81
|
+
});
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (!hasPropertyOfType(data, 'order_number', 'string')) {
|
|
85
|
+
Logger.logError('Order response attributes must have an order_number property and have type string', undefined, {
|
|
86
|
+
data,
|
|
87
|
+
});
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
};
|