@envive-ai/react-hooks 0.1.0 → 0.1.2
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/adapters/amplitude/index.cjs +14 -0
- package/dist/adapters/amplitude/index.d.cts +4 -0
- package/dist/adapters/amplitude/index.d.ts +4 -0
- package/dist/adapters/amplitude/index.js +12 -0
- package/dist/api-B2euFL-5.cjs +268 -0
- package/dist/api-CxGedDxj.cjs +5057 -0
- package/dist/api-NJEaveju.js +4113 -0
- package/dist/api-XRr_lAG6.js +189 -0
- package/dist/application/config/index.cjs +34 -0
- package/dist/application/config/index.d.cts +14 -0
- package/dist/application/config/index.d.ts +14 -0
- package/dist/application/config/index.js +32 -0
- package/dist/application/models/graphql/index.cjs +13 -0
- package/dist/application/models/graphql/index.d.cts +2 -0
- package/dist/application/models/graphql/index.d.ts +2 -0
- package/dist/application/models/graphql/index.js +12 -0
- package/dist/application/models/guards/api/index.cjs +15 -0
- package/dist/application/models/guards/api/index.d.cts +3 -0
- package/dist/application/models/guards/api/index.d.ts +3 -0
- package/dist/application/models/guards/api/index.js +4 -0
- package/dist/application/models/index.cjs +72 -0
- package/dist/application/models/index.d.cts +10 -0
- package/dist/application/models/index.d.ts +10 -0
- package/dist/application/models/index.js +12 -0
- package/dist/application/models/utilityTypes/index.cjs +1 -0
- package/dist/application/models/utilityTypes/index.d.cts +2 -0
- package/dist/application/models/utilityTypes/index.d.ts +2 -0
- package/dist/application/models/utilityTypes/index.js +3 -0
- package/dist/application/models/variantInfo/index.cjs +1 -0
- package/dist/application/models/variantInfo/index.d.cts +2 -0
- package/dist/application/models/variantInfo/index.d.ts +2 -0
- package/dist/application/models/variantInfo/index.js +3 -0
- package/dist/application/service/customerService/index.cjs +4 -0
- package/dist/application/service/customerService/index.d.cts +3 -0
- package/dist/application/service/customerService/index.d.ts +3 -0
- package/dist/application/service/customerService/index.js +4 -0
- package/dist/application/service/index.cjs +761 -0
- package/dist/application/service/index.d.cts +407 -0
- package/dist/application/service/index.d.ts +407 -0
- package/dist/application/service/index.js +727 -0
- package/dist/application/utils/index.cjs +38 -0
- package/dist/application/utils/index.d.cts +254 -0
- package/dist/application/utils/index.d.ts +254 -0
- package/dist/application/utils/index.js +12 -0
- package/dist/atomStore-B3tsg6mF.cjs +0 -0
- package/dist/atomStore-BFtpknLM.js +31 -0
- package/dist/atomStore-CeJm9Llb.cjs +57 -0
- package/dist/atomStore-FSZd_20F.js +1 -0
- package/dist/atoms/app/index.cjs +17 -0
- package/dist/atoms/app/index.d.cts +33 -0
- package/dist/atoms/app/index.d.ts +33 -0
- package/dist/atoms/app/index.js +12 -0
- package/dist/atoms/atomStore/index.cjs +7 -0
- package/dist/atoms/atomStore/index.d.cts +23 -0
- package/dist/atoms/atomStore/index.d.ts +23 -0
- package/dist/atoms/atomStore/index.js +4 -0
- package/dist/atoms/chat/index.cjs +41 -0
- package/dist/atoms/chat/index.d.cts +159 -0
- package/dist/atoms/chat/index.d.ts +159 -0
- package/dist/atoms/chat/index.js +12 -0
- package/dist/atoms/globalSearch/index.cjs +6 -0
- package/dist/atoms/globalSearch/index.d.cts +23 -0
- package/dist/atoms/globalSearch/index.d.ts +23 -0
- package/dist/atoms/globalSearch/index.js +3 -0
- package/dist/atoms/org/index.cjs +41 -0
- package/dist/atoms/org/index.d.cts +93 -0
- package/dist/atoms/org/index.d.ts +93 -0
- package/dist/atoms/org/index.js +13 -0
- package/dist/atoms/search/index.cjs +44 -0
- package/dist/atoms/search/index.d.cts +11 -0
- package/dist/atoms/search/index.d.ts +11 -0
- package/dist/atoms/search/index.js +14 -0
- package/dist/{bandolier-Ble8jEa8.js → bandolier-C7PAIw02.js} +16 -7
- package/dist/{bandolier-Bm2xAt_j.cjs → bandolier-oMkFDJMF.cjs} +55 -46
- package/dist/{carpe-Da7b-LCW.cjs → carpe-C0ccKuR9.cjs} +34 -25
- package/dist/{carpe-W13mhRRP.js → carpe-DFc78_lJ.js} +16 -7
- package/dist/chat-CCgyDehy.cjs +151 -0
- package/dist/chat-Dk6KPb1K.js +25 -0
- package/dist/components-CScS7Ii-.cjs +28 -0
- package/dist/components-DAQxVIn9.js +10 -0
- package/dist/config/locators/components/chat/index.cjs +23 -0
- package/dist/config/locators/components/chat/index.d.cts +2 -0
- package/dist/config/locators/components/chat/index.d.ts +2 -0
- package/dist/config/locators/components/chat/index.js +3 -0
- package/dist/config/locators/components/chat/variants/index.cjs +28 -0
- package/dist/config/locators/components/chat/variants/index.d.cts +15 -0
- package/dist/config/locators/components/chat/variants/index.d.ts +15 -0
- package/dist/config/locators/components/chat/variants/index.js +16 -0
- package/dist/config/locators/components/index.cjs +5 -0
- package/dist/config/locators/components/index.d.cts +2 -0
- package/dist/config/locators/components/index.d.ts +2 -0
- package/dist/config/locators/components/index.js +3 -0
- package/dist/config/locators/components/search/index.cjs +12 -0
- package/dist/config/locators/components/search/index.d.cts +7 -0
- package/dist/config/locators/components/search/index.d.ts +7 -0
- package/dist/config/locators/components/search/index.js +8 -0
- package/dist/config/locators/index.cjs +47 -0
- package/dist/config/locators/index.d.cts +24 -0
- package/dist/config/locators/index.d.ts +24 -0
- package/dist/config/locators/index.js +6 -0
- package/dist/contexts/index.cjs +19 -3
- package/dist/contexts/index.d.cts +16 -22
- package/dist/contexts/index.d.ts +19 -26
- package/dist/contexts/index.js +15 -4
- package/dist/contexts-DO75-Kmx.js +7152 -0
- package/dist/contexts-iAzSvZjb.cjs +7331 -0
- package/dist/{coterie-DOWcJAYv.js → coterie-BGT8hqFR.js} +18 -7
- package/dist/{coterie-3y0D9ko4.cjs → coterie-Cp9FAJTQ.cjs} +25 -14
- package/dist/customerService-CUyZzowx.js +22 -0
- package/dist/customerService-DqPw_XKf.cjs +35 -0
- package/dist/custservice-types-D8Npo-5Z.js +22 -0
- package/dist/custservice-types-E9_OSaZ7.cjs +34 -0
- package/dist/{default-D_KPZdPJ.cjs → default-BAXPatxf.cjs} +1 -1
- package/dist/default-BR3225LZ.js +4 -0
- package/dist/default-DR6YjE9B.cjs +4 -0
- package/dist/{default-C2fEZKXk.js → default-wf_IORgo.js} +1 -1
- package/dist/divIds-BWvq-i6I.js +22 -0
- package/dist/{divIds-DnZNd7rA.cjs → divIds-CFyAjjp3.cjs} +6 -99
- package/dist/{dreamlandBaby-DCIsuU9R.cjs → dreamlandBaby-BzuMvUFS.cjs} +27 -18
- package/dist/{dreamlandBaby-DvSaZGrz.js → dreamlandBaby-DZvM81LQ.js} +16 -7
- package/dist/embedded-BlXJUbik.cjs +130 -0
- package/dist/embedded-C1jvFj3v.js +22 -0
- package/dist/events/index.cjs +4 -0
- package/dist/events/index.d.cts +45 -0
- package/dist/events/index.d.ts +45 -0
- package/dist/events/index.js +3 -0
- package/dist/events-ClCDFK7t.js +77 -0
- package/dist/events-Da7gpmGv.cjs +89 -0
- package/dist/featureFlagService-CroFRxvD.d.cts +17 -0
- package/dist/featureFlagService-NkJ2fuEj.d.ts +17 -0
- package/dist/featureGates-BMWXU0dS.d.ts +90 -0
- package/dist/featureGates-N_gyHCTn.d.cts +90 -0
- package/dist/{fiveCbd-CkOlVby_.cjs → fiveCbd-DE-tDY3d.cjs} +31 -22
- package/dist/{fiveCbd-B1SESMCO.js → fiveCbd-HNBPqPtX.js} +16 -7
- package/dist/{forLoveAndLemons-DmwYZIk0.js → forLoveAndLemons-BKmJJ9pq.js} +13 -5
- package/dist/{forLoveAndLemons-CfYPMnKS.cjs → forLoveAndLemons-BeVEBOiu.cjs} +17 -9
- package/dist/frontendConfig-KeNqU1wa.d.cts +790 -0
- package/dist/frontendConfig-cPvCTWm6.d.ts +790 -0
- package/dist/globalSearch-BC0rOX3E.js +13 -0
- package/dist/globalSearch-hxbXekus.cjs +38 -0
- package/dist/{greenpan-BtOi45lf.js → greenpan-BX1viAZB.js} +16 -7
- package/dist/{greenpan-Bsl3ir59.cjs → greenpan-chd3aa5I.cjs} +29 -20
- package/dist/{grooveLife-6_dtYsRk.js → grooveLife-CHot3rZw.js} +17 -8
- package/dist/{grooveLife-Cmm1PSCL.cjs → grooveLife-DEob7rK0.cjs} +28 -19
- package/dist/{homegrownCannabis-CO0uY_mp.cjs → homegrownCannabis-CoIjcehi.cjs} +27 -16
- package/dist/{homegrownCannabis-C-kw-74X.js → homegrownCannabis-CwkS1qDA.js} +17 -6
- package/dist/hooks/index.cjs +26 -3
- package/dist/hooks/index.d.cts +220 -299
- package/dist/hooks/index.d.ts +220 -299
- package/dist/hooks/index.js +15 -4
- package/dist/index-BdNKc2ix.d.cts +8 -0
- package/dist/index-BkhvV8RZ.d.cts +202 -0
- package/dist/index-BrXuc_Ck.d.cts +24 -0
- package/dist/{chatElementDisplayLocation-CX8fuNao.d.cts → index-C4zjAR1c.d.cts} +18 -30
- package/dist/index-CGB6CAmr.d.ts +6 -0
- package/dist/index-CIco0cCQ.d.ts +183 -0
- package/dist/index-COG1kOZG.d.ts +749 -0
- package/dist/index-CVxe7FpL.d.cts +6 -0
- package/dist/index-Cn1SeI5y.d.cts +183 -0
- package/dist/index-Cqg6ltII.d.ts +38 -0
- package/dist/index-CzMrMKx-.d.ts +202 -0
- package/dist/index-DE_7Q8qK.d.ts +94 -0
- package/dist/index-Da0UzyI9.d.ts +24 -0
- package/dist/index-DbWWcYax.d.cts +749 -0
- package/dist/index-DtoVXd6O.d.cts +97 -0
- package/dist/index-JClBRnSX.d.cts +94 -0
- package/dist/index-ghzD_356.d.ts +8 -0
- package/dist/index-hdbCEjYy.d.cts +38 -0
- package/dist/index-luJrHgPN.d.ts +97 -0
- package/dist/{chatElementDisplayLocation-CwptS9tx.d.ts → index-tfRj22E1.d.ts} +18 -30
- package/dist/interceptors/index.cjs +14 -0
- package/dist/interceptors/index.d.cts +25 -0
- package/dist/interceptors/index.d.ts +25 -0
- package/dist/interceptors/index.js +13 -0
- package/dist/{jackArcher-CLVmwwpI.js → jackArcher-BA-pkB4A.js} +16 -7
- package/dist/{jackArcher-DdYTIzAV.cjs → jackArcher-bewC0q1T.cjs} +33 -24
- package/dist/{jordanCraig-_u3-w4Hp.cjs → jordanCraig-B5k9nlAw.cjs} +76 -67
- package/dist/{jordanCraig-Am-Oor-O.js → jordanCraig-BsQ1mYbt.js} +16 -7
- package/dist/{kindredBravely-eWp-ud_E.js → kindredBravely-BxYkCpGY.js} +15 -6
- package/dist/{kindredBravely-CWovIDSc.cjs → kindredBravely-DsN0fo3s.cjs} +26 -17
- package/dist/{kutFromTheKloth-Q589bAOC.cjs → kutFromTheKloth-BQTCu3ct.cjs} +27 -18
- package/dist/{kutFromTheKloth-BMV4BuGQ.js → kutFromTheKloth-bukOQM3P.js} +16 -7
- package/dist/{larryAndSerges-BMUlTgI-.js → larryAndSerges-D1ecaT5a.js} +14 -5
- package/dist/{larryAndSerges-CEau764j.cjs → larryAndSerges-bj7fgy9b.cjs} +21 -12
- package/dist/{leapsAndRebounds-DHAtRTJD.cjs → leapsAndRebounds-BfneG_0c.cjs} +29 -20
- package/dist/{leapsAndRebounds-DGMzPO7T.js → leapsAndRebounds-DhNpZETg.js} +16 -7
- package/dist/locators-C2DX_nX6.js +1 -0
- package/dist/locators-CUpyd9Wt.cjs +0 -0
- package/dist/{longevityrx-jH2JLhNH.js → longevityrx-CnoGcw0w.js} +16 -7
- package/dist/{longevityrx-CZW8Hxzi.cjs → longevityrx-D0goIuX0.cjs} +24 -15
- package/dist/{lookOptic-CA6RwLbG.cjs → lookOptic-C4afLPZP.cjs} +24 -15
- package/dist/{lookOptic-BGXP5P_V.js → lookOptic-uJWIKpER.js} +16 -7
- package/dist/{mantraBrand-DByNqpnL.cjs → mantraBrand-8JUlYtCE.cjs} +45 -36
- package/dist/{mantraBrand-Cm9_PBCT.js → mantraBrand-DuwKHM26.js} +17 -8
- package/dist/{medterra-B0wxj_PV.js → medterra-BQec8rzn.js} +16 -7
- package/dist/{medterra-DnPN2ksU.cjs → medterra-DH067P-V.cjs} +36 -27
- package/dist/{modells-Bmz8Ag5M.js → modells-DAgLE2xo.js} +16 -7
- package/dist/{modells-CoYgkLSp.cjs → modells-DUFnLmAz.cjs} +30 -21
- package/dist/nodeSelector-DpKXszfU.d.ts +30 -0
- package/dist/nodeSelector-vKB44CDB.d.cts +30 -0
- package/dist/org-C11APG3v.js +63 -0
- package/dist/org-CnHL2I9B.cjs +106 -0
- package/dist/{pressedFloral-DjBiSoUl.cjs → pressedFloral-DVZVfOSQ.cjs} +35 -26
- package/dist/{pressedFloral-DSKs_oVG.js → pressedFloral-MdbuoRyA.js} +16 -7
- package/dist/search-CvHb1M3S.js +542 -0
- package/dist/search-bSYdOBhY.cjs +743 -0
- package/dist/search-filter-types-BsJjrxk0.d.ts +101 -0
- package/dist/search-filter-types-CqaGK3nM.d.cts +101 -0
- package/dist/{skinPerfection-B_3xzVNS.cjs → skinPerfection-BcEWICQN.cjs} +24 -15
- package/dist/{skinPerfection-IDrBuAPt.js → skinPerfection-bGiYxq1i.js} +16 -7
- package/dist/{snapSupplements-BStTsdOZ.cjs → snapSupplements-BXSXTjqF.cjs} +24 -15
- package/dist/{snapSupplements-BJk5T5ba.js → snapSupplements-D7hHhdC9.js} +16 -7
- package/dist/{spanx-BYg0LE7R.js → spanx-5-0yX3iK.js} +18 -9
- package/dist/{spanx-LwU1zSzq.cjs → spanx-lUzP6Lva.cjs} +30 -21
- package/dist/{spanxStaging-CfSmuKYB.js → spanxStaging-HglCMJag.js} +18 -9
- package/dist/{spanxStaging-OZLV9qix.cjs → spanxStaging-hreMR0MS.cjs} +34 -25
- package/dist/suggestionBarV2-types-B0RbMStE.js +9 -0
- package/dist/suggestionBarV2-types-DG3Ekk44.cjs +15 -0
- package/dist/{supergoop-CIlrHND_.js → supergoop-C9DDT3lY.js} +17 -7
- package/dist/{supergoop-BqPXDnKk.cjs → supergoop-CkjtuRck.cjs} +28 -18
- package/dist/test-types-C9b_OdfO.d.ts +39 -0
- package/dist/test-types-CpKCxk8U.d.cts +39 -0
- package/dist/types/index.cjs +6 -0
- package/dist/types/index.d.cts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +4 -0
- package/dist/types-BE4faOO_.d.cts +32 -0
- package/dist/{types-C4T5UOIW.cjs → types-BUjohkXp.cjs} +58 -58
- package/dist/{types-CYNvLeSA.js → types-BVsTRyxL.js} +58 -58
- package/dist/types-TD8g7LnH.d.ts +32 -0
- package/dist/{uniqueVintage-B30mOqbH.cjs → uniqueVintage-DIMGtYAU.cjs} +46 -37
- package/dist/{uniqueVintage-CFueJOhO.js → uniqueVintage-DPWA5Ed6.js} +16 -7
- package/dist/useMessageInterceptor-B-P_rw73.cjs +72 -0
- package/dist/useMessageInterceptor-C2RZM-fo.js +57 -0
- package/dist/utilityTypes-BVikejDo.js +1 -0
- package/dist/utilityTypes-C4h2wgAK.cjs +0 -0
- package/dist/variant-BGjOVpY3.d.cts +12 -0
- package/dist/variant-XITncuI3.d.ts +12 -0
- package/dist/variantInfo-CNRTY0gH.cjs +0 -0
- package/dist/variantInfo-CzhR5W6h.js +1 -0
- package/dist/{venaCbd-T0CqVD4k.js → venaCbd-B-znfAsl.js} +16 -7
- package/dist/{venaCbd-DHGZy49P.cjs → venaCbd-BOwOtpOz.cjs} +29 -20
- package/dist/{westonJonBoucher-BdMzs_Yg.cjs → westonJonBoucher-CraTzRVt.cjs} +29 -20
- package/dist/{westonJonBoucher-b4TCQ4ev.js → westonJonBoucher-DCRagGu3.js} +16 -7
- package/dist/{wineEnthusiast-BqR0i_54.js → wineEnthusiast-Bv7umajk.js} +16 -7
- package/dist/{wineEnthusiast-BLGlOjgr.cjs → wineEnthusiast-sVuATrq6.cjs} +28 -19
- package/dist/{wolfMattress-CyyO-LoC.js → wolfMattress-BUH-Rhov.js} +17 -6
- package/dist/{wolfMattress-DNGZOivg.cjs → wolfMattress-DpVHIEnJ.cjs} +29 -18
- package/dist/{wolfTactical-BmXYlFjr.cjs → wolfTactical-BcvF_sy-.cjs} +28 -19
- package/dist/{wolfTactical-3Mm2fvVF.js → wolfTactical-Q14A1fpw.js} +16 -7
- package/package.json +101 -3
- package/src/adapters/amplitude/amplitudeAdapter.ts +1 -1
- package/src/adapters/spiffy/commerce/api.ts +1 -1
- package/src/adapters/spiffy/commerce/graphql.ts +61 -37
- package/src/application/config/index.ts +1 -0
- package/src/application/models/index.ts +102 -17
- package/src/application/models/supportedOrgs.ts +89 -65
- package/src/application/service/index.ts +32 -0
- package/src/application/service/pageVariantService.ts +201 -114
- package/src/application/service/searchService.ts +1 -1
- package/src/application/service/windowFrontendConfigService.ts +40 -18
- package/src/application/utils/index.ts +22 -3
- package/src/atoms/app/variant.ts +48 -29
- package/src/atoms/atomStore/index.ts +1 -0
- package/src/atoms/chat/messageQueue.ts +34 -17
- package/src/atoms/chat/performanceMetrics.ts +51 -38
- package/src/atoms/chat/renderedWidgetRefs.ts +14 -15
- package/src/atoms/globalSearch/index.ts +1 -0
- package/src/atoms/org/org.ts +1 -3
- package/src/atoms/org/orgUIConfig.ts +31 -24
- package/src/contexts/chatContext.tsx +124 -72
- package/src/events/registerAnalyticsListeners.ts +13 -9
- package/src/hooks/useFileUpload.ts +9 -7
- package/src/hooks/useSearch.tsx +4 -7
- package/src/initialize.ts +2 -2
- package/src/interceptors/index.ts +3 -0
- package/src/main.tsx +11 -26
- package/src/types/index.ts +4 -0
- package/dist/GridInsertionService-CEYo9pGj.js +0 -22
- package/dist/GridInsertionService-CS_bnPh0.cjs +0 -28
- package/dist/contexts-BRjfVq_k.js +0 -5064
- package/dist/contexts-BYArqZtK.cjs +0 -5164
- package/dist/custservice-types-CFIFwZ-r.js +0 -10
- package/dist/custservice-types-CkfxZiHY.cjs +0 -16
- package/dist/default-CBUq6Q6G.cjs +0 -4
- package/dist/default-CGIFZK6m.js +0 -4
- package/dist/divIds-Bss-btao.js +0 -49
- package/dist/models-DHdb7QWn.js +0 -51
- package/dist/models-ixxUsGL_.cjs +0 -69
- package/dist/suggestionBarV2-types-BllzwsBD.js +0 -34
- package/dist/suggestionBarV2-types-CaovchMP.cjs +0 -46
- package/src/atoms/index.ts +0 -5
- package/src/index.ts +0 -31
- package/src/main.ts +0 -85
- /package/dist/{cdnService-zQfKk3Eb.js → cdnService-DvDSpfVJ.js} +0 -0
- /package/dist/{cdnService-CZ-aXcY6.cjs → cdnService-dJU3sHpF.cjs} +0 -0
- /package/dist/{entrypoints-YLQsbBRD.js → entrypoints-CmmOszXO.js} +0 -0
- /package/dist/{entrypoints-D_JUvkgy.cjs → entrypoints-fowCLUT2.cjs} +0 -0
- /package/dist/{socialProofClasses-CrQBWdSA.cjs → socialProofClasses-BYLiEXpU.cjs} +0 -0
- /package/dist/{socialProofClasses-Bhv2Vulz.js → socialProofClasses-CkJufEGb.js} +0 -0
- /package/src/atoms/{atomStore.ts → atomStore/atomStore.ts} +0 -0
- /package/src/atoms/{globalSearch.ts → globalSearch/globalSearch.ts} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { v4 as uuid } from
|
|
2
|
-
import { createVisitUserEvent } from
|
|
3
|
-
import CommerceApiClient from
|
|
4
|
-
import Logger from
|
|
5
|
-
import { getAtomStore } from
|
|
6
|
-
import { featureFlagServiceAtom } from
|
|
1
|
+
import { v4 as uuid } from "uuid";
|
|
2
|
+
import { createVisitUserEvent } from "src/hooks/utils";
|
|
3
|
+
import CommerceApiClient from "src/adapters/spiffy/commerce/api";
|
|
4
|
+
import Logger from "src/application/logging/logger";
|
|
5
|
+
import { getAtomStore } from "src/atoms/atomStore/atomStore";
|
|
6
|
+
import { featureFlagServiceAtom } from "src/atoms/org/org";
|
|
7
7
|
import {
|
|
8
8
|
CategoryExtractor,
|
|
9
9
|
CategoryExtractorType,
|
|
@@ -12,26 +12,31 @@ import {
|
|
|
12
12
|
PageVariantConfig,
|
|
13
13
|
PageVariantTest,
|
|
14
14
|
PageVariantTestType,
|
|
15
|
-
} from
|
|
16
|
-
import { ShopifyUrlService } from
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
} from "src/contexts/types";
|
|
16
|
+
import { ShopifyUrlService } from "src/application/service/shopifyUrlService";
|
|
17
|
+
import {
|
|
18
|
+
Message,
|
|
19
|
+
MessageRole,
|
|
20
|
+
MessageType,
|
|
21
|
+
VariantInfo,
|
|
22
|
+
} from "src/application/models";
|
|
23
|
+
import { FeatureGates } from "src/application/models/featureGates";
|
|
24
|
+
import { appDetailsAtom } from "src/atoms/app";
|
|
20
25
|
|
|
21
26
|
import {
|
|
22
27
|
PageVisitCategory,
|
|
23
28
|
type SupportedEventProductCategory,
|
|
24
|
-
} from
|
|
29
|
+
} from "@spiffy-ai/commerce-api-client";
|
|
25
30
|
import {
|
|
26
31
|
SupportedEvent,
|
|
27
32
|
urlResolverAtom,
|
|
28
33
|
UrlResolverResponse,
|
|
29
34
|
UrlResolvingPDPConfig,
|
|
30
35
|
UrlResolvingPLPConfig,
|
|
31
|
-
} from
|
|
32
|
-
import { tellExtensionAboutInjectionError } from
|
|
33
|
-
import { chatAtom, lastAssistantMessageAtom } from
|
|
34
|
-
import { StringUtils } from
|
|
36
|
+
} from "src/atoms/app/variant";
|
|
37
|
+
import { tellExtensionAboutInjectionError } from "src/extension";
|
|
38
|
+
import { chatAtom, lastAssistantMessageAtom } from "src/atoms/chat";
|
|
39
|
+
import { StringUtils } from "../utils/stringUtils";
|
|
35
40
|
|
|
36
41
|
/**
|
|
37
42
|
* This class is used to resolve the PageVariants for the Spiffy App.
|
|
@@ -49,13 +54,16 @@ class PageVariantService {
|
|
|
49
54
|
responseStreaming: boolean;
|
|
50
55
|
messages: Message[][];
|
|
51
56
|
lastAssistantMessage?: Message[] | null | undefined;
|
|
52
|
-
}
|
|
57
|
+
}
|
|
53
58
|
): Promise<boolean> => {
|
|
54
59
|
switch (test.testType) {
|
|
55
60
|
case PageVariantTestType.UrlResolver: {
|
|
56
61
|
const url = window._spiffy.variantUrlOverride ?? window.location.href;
|
|
57
62
|
const response = await PageVariantService.getCachedUrlResolver(url);
|
|
58
|
-
return
|
|
63
|
+
return (
|
|
64
|
+
response.ready &&
|
|
65
|
+
response.variant_type === pageVariantConfig.variantType
|
|
66
|
+
);
|
|
59
67
|
}
|
|
60
68
|
case PageVariantTestType.ShopifyPDP:
|
|
61
69
|
return ShopifyUrlService.isOnPdpPage();
|
|
@@ -83,23 +91,43 @@ class PageVariantService {
|
|
|
83
91
|
// The 'fallback' testType will always evaluate to true
|
|
84
92
|
return true;
|
|
85
93
|
case PageVariantTestType.CatalogCategory:
|
|
86
|
-
return PageVariantService.checkCatalogCategory(
|
|
94
|
+
return PageVariantService.checkCatalogCategory(
|
|
95
|
+
test.category,
|
|
96
|
+
pageVariantConfig
|
|
97
|
+
);
|
|
87
98
|
case PageVariantTestType.TopCatalogCategory:
|
|
88
|
-
return PageVariantService.checkInTopCategory(
|
|
99
|
+
return PageVariantService.checkInTopCategory(
|
|
100
|
+
test.topCategory,
|
|
101
|
+
pageVariantConfig
|
|
102
|
+
);
|
|
89
103
|
case PageVariantTestType.HasReviews:
|
|
90
|
-
return PageVariantService.checkHasReviews(
|
|
104
|
+
return PageVariantService.checkHasReviews(
|
|
105
|
+
pageVariantConfig,
|
|
106
|
+
test.reviewMinimum
|
|
107
|
+
);
|
|
91
108
|
case PageVariantTestType.InCollection:
|
|
92
|
-
return PageVariantService.checkInCollection(
|
|
109
|
+
return PageVariantService.checkInCollection(
|
|
110
|
+
test.collections,
|
|
111
|
+
pageVariantConfig
|
|
112
|
+
);
|
|
93
113
|
case PageVariantTestType.HasMerchantTag:
|
|
94
|
-
return PageVariantService.checkHasMerchantTag(
|
|
114
|
+
return PageVariantService.checkHasMerchantTag(
|
|
115
|
+
test.merchantTags,
|
|
116
|
+
pageVariantConfig
|
|
117
|
+
);
|
|
95
118
|
case PageVariantTestType.UserHasInteracted:
|
|
96
119
|
return PageVariantService.userHasInteracted(atomValues?.messages);
|
|
97
120
|
case PageVariantTestType.UserHasNotInteracted:
|
|
98
121
|
return PageVariantService.userHasNotInteracted(atomValues?.messages);
|
|
99
122
|
case PageVariantTestType.isLoading:
|
|
100
|
-
return PageVariantService.isLoading(
|
|
123
|
+
return PageVariantService.isLoading(
|
|
124
|
+
atomValues?.messages,
|
|
125
|
+
atomValues?.responseStreaming
|
|
126
|
+
);
|
|
101
127
|
case PageVariantTestType.isProductComparison:
|
|
102
|
-
return PageVariantService.isProductComparison(
|
|
128
|
+
return PageVariantService.isProductComparison(
|
|
129
|
+
atomValues?.lastAssistantMessage
|
|
130
|
+
);
|
|
103
131
|
default:
|
|
104
132
|
// If there is a testType that we do not cover - default to false
|
|
105
133
|
Logger.logInfo(`[Spiffy] pageTest - ${test} not supported`);
|
|
@@ -117,7 +145,9 @@ class PageVariantService {
|
|
|
117
145
|
return cachedUrlResolver;
|
|
118
146
|
}
|
|
119
147
|
|
|
120
|
-
const response = (await CommerceApiClient.resolveUrl(
|
|
148
|
+
const response = (await CommerceApiClient.resolveUrl(
|
|
149
|
+
url
|
|
150
|
+
)) as UrlResolverResponse;
|
|
121
151
|
|
|
122
152
|
// Store in atom cache for this URL (will be persisted to sessionStorage automatically)
|
|
123
153
|
atomStore.set(urlResolverAtom, { url, response });
|
|
@@ -135,9 +165,11 @@ class PageVariantService {
|
|
|
135
165
|
*/
|
|
136
166
|
private static readonly checkCatalogCategory = async (
|
|
137
167
|
category: SupportedEventProductCategory | string,
|
|
138
|
-
pageVariantConfig: PageVariantConfig
|
|
168
|
+
pageVariantConfig: PageVariantConfig
|
|
139
169
|
): Promise<boolean> => {
|
|
140
|
-
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
170
|
+
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
171
|
+
pageVariantConfig
|
|
172
|
+
);
|
|
141
173
|
if (supportedEventResponse && supportedEventResponse.category) {
|
|
142
174
|
return supportedEventResponse?.category === category;
|
|
143
175
|
}
|
|
@@ -147,9 +179,11 @@ class PageVariantService {
|
|
|
147
179
|
|
|
148
180
|
private static readonly checkInTopCategory = async (
|
|
149
181
|
topCategory: string[],
|
|
150
|
-
pageVariantConfig: PageVariantConfig
|
|
182
|
+
pageVariantConfig: PageVariantConfig
|
|
151
183
|
): Promise<boolean> => {
|
|
152
|
-
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
184
|
+
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
185
|
+
pageVariantConfig
|
|
186
|
+
);
|
|
153
187
|
if (supportedEventResponse && supportedEventResponse?.top_category) {
|
|
154
188
|
return topCategory.includes(supportedEventResponse?.top_category);
|
|
155
189
|
}
|
|
@@ -159,9 +193,11 @@ class PageVariantService {
|
|
|
159
193
|
|
|
160
194
|
private static readonly checkHasReviews = async (
|
|
161
195
|
pageVariantConfig: PageVariantConfig,
|
|
162
|
-
reviewMinimum: number = 0
|
|
196
|
+
reviewMinimum: number = 0
|
|
163
197
|
): Promise<boolean> => {
|
|
164
|
-
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
198
|
+
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
199
|
+
pageVariantConfig
|
|
200
|
+
);
|
|
165
201
|
if (supportedEventResponse?.numberOfReviews) {
|
|
166
202
|
return supportedEventResponse.numberOfReviews >= reviewMinimum;
|
|
167
203
|
}
|
|
@@ -170,12 +206,14 @@ class PageVariantService {
|
|
|
170
206
|
|
|
171
207
|
private static readonly checkInCollection = async (
|
|
172
208
|
collections: string[],
|
|
173
|
-
pageVariantConfig: PageVariantConfig
|
|
209
|
+
pageVariantConfig: PageVariantConfig
|
|
174
210
|
): Promise<boolean> => {
|
|
175
|
-
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
211
|
+
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
212
|
+
pageVariantConfig
|
|
213
|
+
);
|
|
176
214
|
if (supportedEventResponse?.collections) {
|
|
177
215
|
return supportedEventResponse.collections.some((collection) =>
|
|
178
|
-
collections.includes(collection)
|
|
216
|
+
collections.includes(collection)
|
|
179
217
|
);
|
|
180
218
|
}
|
|
181
219
|
return false;
|
|
@@ -183,12 +221,16 @@ class PageVariantService {
|
|
|
183
221
|
|
|
184
222
|
private static readonly checkHasMerchantTag = async (
|
|
185
223
|
merchantTags: string[],
|
|
186
|
-
pageVariantConfig: PageVariantConfig
|
|
224
|
+
pageVariantConfig: PageVariantConfig
|
|
187
225
|
): Promise<boolean> => {
|
|
188
|
-
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
226
|
+
const supportedEventResponse = await PageVariantService.checkSupportedEvent(
|
|
227
|
+
pageVariantConfig
|
|
228
|
+
);
|
|
189
229
|
|
|
190
230
|
if (supportedEventResponse?.merchant_tags) {
|
|
191
|
-
return supportedEventResponse.merchant_tags.some((tag) =>
|
|
231
|
+
return supportedEventResponse.merchant_tags.some((tag) =>
|
|
232
|
+
merchantTags.includes(tag)
|
|
233
|
+
);
|
|
192
234
|
}
|
|
193
235
|
|
|
194
236
|
return false;
|
|
@@ -204,17 +246,24 @@ class PageVariantService {
|
|
|
204
246
|
return messages.some((m) => m.some((msg) => msg.role === MessageRole.User));
|
|
205
247
|
};
|
|
206
248
|
|
|
207
|
-
private static readonly userHasNotInteracted = (
|
|
249
|
+
private static readonly userHasNotInteracted = (
|
|
250
|
+
msgs?: Message[][]
|
|
251
|
+
): boolean => {
|
|
208
252
|
if (msgs) {
|
|
209
253
|
return !msgs.some((m) => m.some((msg) => msg.role === MessageRole.User));
|
|
210
254
|
}
|
|
211
255
|
|
|
212
256
|
const atomStore = getAtomStore();
|
|
213
257
|
const chat = atomStore.get(chatAtom);
|
|
214
|
-
return !chat.messages.some((m) =>
|
|
258
|
+
return !chat.messages.some((m) =>
|
|
259
|
+
m.some((msg) => msg.role === MessageRole.User)
|
|
260
|
+
);
|
|
215
261
|
};
|
|
216
262
|
|
|
217
|
-
private static readonly isLoading = (
|
|
263
|
+
private static readonly isLoading = (
|
|
264
|
+
msgs?: Message[][],
|
|
265
|
+
responseStream?: boolean
|
|
266
|
+
): boolean => {
|
|
218
267
|
if (msgs) {
|
|
219
268
|
return responseStream || (!responseStream && msgs.length === 0);
|
|
220
269
|
}
|
|
@@ -225,15 +274,20 @@ class PageVariantService {
|
|
|
225
274
|
};
|
|
226
275
|
|
|
227
276
|
private static readonly isProductComparison = (
|
|
228
|
-
lastMsg: Message[] | null | undefined
|
|
277
|
+
lastMsg: Message[] | null | undefined
|
|
229
278
|
): boolean => {
|
|
230
279
|
if (lastMsg) {
|
|
231
|
-
return
|
|
280
|
+
return (
|
|
281
|
+
lastMsg?.filter((msg) => msg.type === MessageType.Product).length === 2
|
|
282
|
+
);
|
|
232
283
|
}
|
|
233
284
|
|
|
234
285
|
const atomStore = getAtomStore();
|
|
235
286
|
const lastAssistantMessage = atomStore.get(lastAssistantMessageAtom);
|
|
236
|
-
return
|
|
287
|
+
return (
|
|
288
|
+
lastAssistantMessage?.filter((msg) => msg.type === MessageType.Product)
|
|
289
|
+
.length === 2
|
|
290
|
+
);
|
|
237
291
|
};
|
|
238
292
|
|
|
239
293
|
private static readonly checkPlpIds = async ({
|
|
@@ -244,12 +298,12 @@ class PageVariantService {
|
|
|
244
298
|
plpIdExtractor: IdExtractor;
|
|
245
299
|
}): Promise<boolean> => {
|
|
246
300
|
let currentPlpId: string | null;
|
|
247
|
-
if (plpIdExtractor ===
|
|
248
|
-
currentPlpId = await PageVariantService.getIdFromUrlResolver(
|
|
301
|
+
if (plpIdExtractor === "url-resolver-plp-id") {
|
|
302
|
+
currentPlpId = await PageVariantService.getIdFromUrlResolver("plpId");
|
|
249
303
|
} else {
|
|
250
304
|
currentPlpId = await PageVariantService.getId(plpIdExtractor);
|
|
251
305
|
}
|
|
252
|
-
const result = plpIds.includes(currentPlpId ??
|
|
306
|
+
const result = plpIds.includes(currentPlpId ?? "");
|
|
253
307
|
return result;
|
|
254
308
|
};
|
|
255
309
|
|
|
@@ -270,12 +324,14 @@ class PageVariantService {
|
|
|
270
324
|
productIdExtractor: IdExtractor;
|
|
271
325
|
}): Promise<boolean> => {
|
|
272
326
|
let currentProductId: string | null;
|
|
273
|
-
if (productIdExtractor ===
|
|
274
|
-
currentProductId = await PageVariantService.getIdFromUrlResolver(
|
|
327
|
+
if (productIdExtractor === "url-resolver-product-id") {
|
|
328
|
+
currentProductId = await PageVariantService.getIdFromUrlResolver(
|
|
329
|
+
"productId"
|
|
330
|
+
);
|
|
275
331
|
} else {
|
|
276
332
|
currentProductId = await PageVariantService.getId(productIdExtractor);
|
|
277
333
|
}
|
|
278
|
-
const result = productIds.includes(currentProductId ??
|
|
334
|
+
const result = productIds.includes(currentProductId ?? "");
|
|
279
335
|
return result;
|
|
280
336
|
};
|
|
281
337
|
|
|
@@ -295,7 +351,10 @@ class PageVariantService {
|
|
|
295
351
|
const urlMap = Object.entries(extractor.map);
|
|
296
352
|
|
|
297
353
|
const matched = urlMap.find(([, urls]) => {
|
|
298
|
-
const hostMatched = StringUtils.findMatchingPattern(
|
|
354
|
+
const hostMatched = StringUtils.findMatchingPattern(
|
|
355
|
+
urls,
|
|
356
|
+
window.location
|
|
357
|
+
);
|
|
299
358
|
if (hostMatched) {
|
|
300
359
|
return hostMatched;
|
|
301
360
|
}
|
|
@@ -312,53 +371,58 @@ class PageVariantService {
|
|
|
312
371
|
|
|
313
372
|
Logger.logError(
|
|
314
373
|
`[spiffy-ai] PageVariantService.getCategory error - extractor=${extractor} not supported`,
|
|
315
|
-
undefined
|
|
374
|
+
undefined
|
|
316
375
|
);
|
|
317
376
|
return null;
|
|
318
377
|
}
|
|
319
378
|
|
|
320
379
|
static async getId(extractor?: IdExtractor): Promise<string | null> {
|
|
321
|
-
if (!extractor || extractor ===
|
|
380
|
+
if (!extractor || extractor === "null") {
|
|
322
381
|
Logger.logDebug(
|
|
323
|
-
`[spiffy-ai] PageVariantService.getId - extractor=${extractor} is null or not supported
|
|
382
|
+
`[spiffy-ai] PageVariantService.getId - extractor=${extractor} is null or not supported`
|
|
324
383
|
);
|
|
325
384
|
return null;
|
|
326
385
|
}
|
|
327
386
|
|
|
328
387
|
// Handle URL resolver extractors
|
|
329
|
-
if (extractor ===
|
|
330
|
-
return PageVariantService.getIdFromUrlResolver(
|
|
388
|
+
if (extractor === "url-resolver-product-id") {
|
|
389
|
+
return PageVariantService.getIdFromUrlResolver("productId");
|
|
331
390
|
}
|
|
332
391
|
|
|
333
|
-
if (extractor ===
|
|
334
|
-
return PageVariantService.getIdFromUrlResolver(
|
|
392
|
+
if (extractor === "url-resolver-plp-id") {
|
|
393
|
+
return PageVariantService.getIdFromUrlResolver("plpId");
|
|
335
394
|
}
|
|
336
395
|
|
|
337
396
|
// Handle regular extractors
|
|
338
397
|
return ShopifyUrlService.getPlpOrPdpId(extractor);
|
|
339
398
|
}
|
|
340
399
|
|
|
341
|
-
private static readonly getIdFromUrlResolver = async (
|
|
400
|
+
private static readonly getIdFromUrlResolver = async (
|
|
401
|
+
field: "productId" | "plpId"
|
|
402
|
+
) => {
|
|
342
403
|
const url = window._spiffy.variantUrlOverride ?? window.location.href;
|
|
343
404
|
const response = await this.getCachedUrlResolver(url);
|
|
344
405
|
// PDP
|
|
345
|
-
if (field ===
|
|
406
|
+
if (field === "productId" && response.variant_type === "pdp") {
|
|
346
407
|
let productId: string | undefined;
|
|
347
|
-
if (
|
|
408
|
+
if (
|
|
409
|
+
response.user_event?.attributes &&
|
|
410
|
+
"product_id" in response.user_event.attributes
|
|
411
|
+
) {
|
|
348
412
|
productId = response.user_event.attributes.product_id;
|
|
349
413
|
}
|
|
350
414
|
return productId ?? null;
|
|
351
415
|
}
|
|
352
416
|
|
|
353
417
|
// PLP
|
|
354
|
-
if (field ===
|
|
418
|
+
if (field === "plpId" && response.variant_type === "plp") {
|
|
355
419
|
let plpId: string | undefined;
|
|
356
420
|
if (
|
|
357
|
-
response.user_event?.category ===
|
|
421
|
+
response.user_event?.category === "plp_visit" &&
|
|
358
422
|
response.user_event.attributes &&
|
|
359
|
-
|
|
423
|
+
"attributes" in response.user_event.attributes &&
|
|
360
424
|
response.user_event.attributes.attributes &&
|
|
361
|
-
|
|
425
|
+
"id" in response.user_event.attributes.attributes
|
|
362
426
|
) {
|
|
363
427
|
plpId = response.user_event.attributes.attributes.id;
|
|
364
428
|
}
|
|
@@ -500,24 +564,29 @@ class PageVariantService {
|
|
|
500
564
|
* return any matches.
|
|
501
565
|
*/
|
|
502
566
|
static readonly getVariantInfoWithPageConfig = async (
|
|
503
|
-
orgPageConfig: OrgPageConfig
|
|
567
|
+
orgPageConfig: OrgPageConfig
|
|
504
568
|
): Promise<[VariantInfo, PageVariantConfig] | undefined> => {
|
|
505
569
|
// First check if there is a variant override set
|
|
506
570
|
if (window?._spiffy?.variantInfoOverride) {
|
|
507
|
-
Logger.logDebug(
|
|
571
|
+
Logger.logDebug(
|
|
572
|
+
"[spiffy-ai] Found variantInfoOverride",
|
|
573
|
+
window._spiffy.variantInfoOverride
|
|
574
|
+
);
|
|
508
575
|
const matchingPageVariantConfig = orgPageConfig.pageVariants.find(
|
|
509
|
-
(pageVariant) =>
|
|
576
|
+
(pageVariant) =>
|
|
577
|
+
pageVariant.variantId ===
|
|
578
|
+
window._spiffy.variantInfoOverride?.variantId
|
|
510
579
|
);
|
|
511
580
|
if (matchingPageVariantConfig) {
|
|
512
581
|
Logger.logInfo(
|
|
513
|
-
|
|
514
|
-
window._spiffy.variantInfoOverride
|
|
582
|
+
"[spiffy-ai] Returning overriden variantInfo",
|
|
583
|
+
window._spiffy.variantInfoOverride
|
|
515
584
|
);
|
|
516
585
|
return [window._spiffy.variantInfoOverride, matchingPageVariantConfig];
|
|
517
586
|
}
|
|
518
587
|
Logger.logWarn(
|
|
519
|
-
|
|
520
|
-
window._spiffy.variantInfoOverride
|
|
588
|
+
"[spiffy-ai] Found variantInfoOverride but no matching pageVariantConfig",
|
|
589
|
+
window._spiffy.variantInfoOverride
|
|
521
590
|
);
|
|
522
591
|
}
|
|
523
592
|
|
|
@@ -562,7 +631,9 @@ class PageVariantService {
|
|
|
562
631
|
// return the first variant that passes all of its tests
|
|
563
632
|
for await (const pageVariant of [...orgPageConfig.pageVariants]) {
|
|
564
633
|
const testResults = await Promise.all(
|
|
565
|
-
pageVariant.variantTests.map((test) =>
|
|
634
|
+
pageVariant.variantTests.map((test) =>
|
|
635
|
+
PageVariantService.pageTest(test, pageVariant)
|
|
636
|
+
)
|
|
566
637
|
);
|
|
567
638
|
|
|
568
639
|
if (testResults.every((result) => result)) {
|
|
@@ -579,11 +650,13 @@ class PageVariantService {
|
|
|
579
650
|
}
|
|
580
651
|
|
|
581
652
|
Logger.logWarn(
|
|
582
|
-
|
|
653
|
+
"[spiffy-ai] no pageVariantConfig matched",
|
|
583
654
|
undefined,
|
|
584
|
-
orgPageConfig.pageVariants
|
|
655
|
+
orgPageConfig.pageVariants
|
|
656
|
+
);
|
|
657
|
+
await tellExtensionAboutInjectionError(
|
|
658
|
+
new Error("No pagevariantConfig matched")
|
|
585
659
|
);
|
|
586
|
-
await tellExtensionAboutInjectionError(new Error('No pagevariantConfig matched'));
|
|
587
660
|
|
|
588
661
|
return undefined;
|
|
589
662
|
};
|
|
@@ -598,23 +671,23 @@ class PageVariantService {
|
|
|
598
671
|
* @returns The supported event response from the backend, or undefined if the page is not supported.
|
|
599
672
|
*/
|
|
600
673
|
static readonly checkSupportedEvent = async (
|
|
601
|
-
pageVariantConfig: PageVariantConfig
|
|
674
|
+
pageVariantConfig: PageVariantConfig
|
|
602
675
|
): Promise<SupportedEvent | undefined> => {
|
|
603
676
|
try {
|
|
604
677
|
const variantInfo = await this.parsePageVariantConfig(
|
|
605
678
|
pageVariantConfig,
|
|
606
|
-
window.location.href
|
|
679
|
+
window.location.href
|
|
607
680
|
);
|
|
608
681
|
|
|
609
682
|
const usesURLResolver = pageVariantConfig.variantTests.some(
|
|
610
|
-
(test) => test.testType === PageVariantTestType.UrlResolver
|
|
683
|
+
(test) => test.testType === PageVariantTestType.UrlResolver
|
|
611
684
|
);
|
|
612
685
|
|
|
613
686
|
if (
|
|
614
687
|
!variantInfo ||
|
|
615
|
-
(variantInfo.variant ===
|
|
616
|
-
(variantInfo.variant ===
|
|
617
|
-
(variantInfo.variant ===
|
|
688
|
+
(variantInfo.variant === "plp" && !variantInfo.plpId) ||
|
|
689
|
+
(variantInfo.variant === "pdp" && !variantInfo.productId) ||
|
|
690
|
+
(variantInfo.variant === "page_visit" && !variantInfo.url)
|
|
618
691
|
) {
|
|
619
692
|
return undefined;
|
|
620
693
|
}
|
|
@@ -625,7 +698,7 @@ class PageVariantService {
|
|
|
625
698
|
const visitEvent = createVisitUserEvent({ variantInfo });
|
|
626
699
|
|
|
627
700
|
if (!visitEvent) {
|
|
628
|
-
Logger.logWarn(
|
|
701
|
+
Logger.logWarn("spiffy-ai] no visitEvent found", variantInfo);
|
|
629
702
|
return undefined;
|
|
630
703
|
}
|
|
631
704
|
|
|
@@ -648,15 +721,16 @@ class PageVariantService {
|
|
|
648
721
|
numberOfReviews: 0,
|
|
649
722
|
} as SupportedEvent;
|
|
650
723
|
|
|
651
|
-
if (variantInfo.variant ===
|
|
652
|
-
const { top_category } =
|
|
724
|
+
if (variantInfo.variant === "plp") {
|
|
725
|
+
const { top_category } =
|
|
726
|
+
response.specific_details as UrlResolvingPLPConfig;
|
|
653
727
|
return {
|
|
654
728
|
...basicResponse,
|
|
655
729
|
top_category,
|
|
656
730
|
};
|
|
657
731
|
}
|
|
658
732
|
|
|
659
|
-
if (variantInfo.variant ===
|
|
733
|
+
if (variantInfo.variant === "pdp") {
|
|
660
734
|
const { collections, number_of_reviews, merchant_tags } =
|
|
661
735
|
response.specific_details as UrlResolvingPDPConfig;
|
|
662
736
|
return {
|
|
@@ -669,7 +743,9 @@ class PageVariantService {
|
|
|
669
743
|
|
|
670
744
|
return basicResponse;
|
|
671
745
|
} catch (error) {
|
|
672
|
-
Logger.logError(
|
|
746
|
+
Logger.logError("spiffy-ai] error checking supported event", error, {
|
|
747
|
+
pageVariantConfig,
|
|
748
|
+
});
|
|
673
749
|
return undefined;
|
|
674
750
|
}
|
|
675
751
|
};
|
|
@@ -684,21 +760,27 @@ class PageVariantService {
|
|
|
684
760
|
*/
|
|
685
761
|
private static readonly parsePageVariantConfig = async (
|
|
686
762
|
pageVariantConfig: PageVariantConfig,
|
|
687
|
-
url: string
|
|
763
|
+
url: string
|
|
688
764
|
): Promise<VariantInfo | undefined> => {
|
|
689
765
|
if (window?._spiffy?.variantInfoOverride) {
|
|
690
766
|
return window._spiffy.variantInfoOverride;
|
|
691
767
|
}
|
|
692
768
|
|
|
693
|
-
if (pageVariantConfig.variantType ===
|
|
694
|
-
let productId: string =
|
|
695
|
-
if (pageVariantConfig.productIdExtractor ===
|
|
696
|
-
productId =
|
|
769
|
+
if (pageVariantConfig.variantType === "pdp") {
|
|
770
|
+
let productId: string = "";
|
|
771
|
+
if (pageVariantConfig.productIdExtractor === "url-resolver-product-id") {
|
|
772
|
+
productId =
|
|
773
|
+
(await PageVariantService.getIdFromUrlResolver("productId")) ?? "";
|
|
697
774
|
} else {
|
|
698
|
-
productId =
|
|
775
|
+
productId =
|
|
776
|
+
(await PageVariantService.getId(
|
|
777
|
+
pageVariantConfig.productIdExtractor
|
|
778
|
+
)) ?? "";
|
|
699
779
|
}
|
|
700
780
|
const parentProductId =
|
|
701
|
-
(await PageVariantService.getId(
|
|
781
|
+
(await PageVariantService.getId(
|
|
782
|
+
pageVariantConfig.parentProductIdExtractor
|
|
783
|
+
)) ?? "";
|
|
702
784
|
return {
|
|
703
785
|
variantId: pageVariantConfig.variantId,
|
|
704
786
|
variant: pageVariantConfig.variantType,
|
|
@@ -708,12 +790,14 @@ class PageVariantService {
|
|
|
708
790
|
};
|
|
709
791
|
}
|
|
710
792
|
|
|
711
|
-
if (pageVariantConfig.variantType ===
|
|
712
|
-
let plpId: string =
|
|
713
|
-
if (pageVariantConfig.plpIdExtractor ===
|
|
714
|
-
plpId = (await PageVariantService.getIdFromUrlResolver(
|
|
793
|
+
if (pageVariantConfig.variantType === "plp") {
|
|
794
|
+
let plpId: string = "";
|
|
795
|
+
if (pageVariantConfig.plpIdExtractor === "url-resolver-plp-id") {
|
|
796
|
+
plpId = (await PageVariantService.getIdFromUrlResolver("plpId")) ?? "";
|
|
715
797
|
} else {
|
|
716
|
-
plpId =
|
|
798
|
+
plpId =
|
|
799
|
+
(await PageVariantService.getId(pageVariantConfig.plpIdExtractor)) ??
|
|
800
|
+
"";
|
|
717
801
|
}
|
|
718
802
|
return {
|
|
719
803
|
variantId: pageVariantConfig.variantId,
|
|
@@ -723,18 +807,21 @@ class PageVariantService {
|
|
|
723
807
|
};
|
|
724
808
|
}
|
|
725
809
|
|
|
726
|
-
if (pageVariantConfig.variantType ===
|
|
727
|
-
const pageVisitCategory =
|
|
728
|
-
|
|
729
|
-
currentTest
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
810
|
+
if (pageVariantConfig.variantType === "page_visit") {
|
|
811
|
+
const pageVisitCategory =
|
|
812
|
+
pageVariantConfig.variantTests.reduce<PageVisitCategory | null>(
|
|
813
|
+
(acc, currentTest) =>
|
|
814
|
+
currentTest.testType === PageVariantTestType.PageCategory
|
|
815
|
+
? PageVariantService.getCategory(currentTest.extractor)
|
|
816
|
+
: acc,
|
|
817
|
+
null
|
|
818
|
+
);
|
|
734
819
|
|
|
735
820
|
// This *should* only be the result of invalid config. Should we throw an error here or handle it with a default value?
|
|
736
821
|
if (pageVisitCategory === null) {
|
|
737
|
-
throw new Error(
|
|
822
|
+
throw new Error(
|
|
823
|
+
"[spiffy-ai] - Invalid variant config produced invalid pageVisitCategory"
|
|
824
|
+
);
|
|
738
825
|
}
|
|
739
826
|
|
|
740
827
|
return {
|
|
@@ -745,28 +832,28 @@ class PageVariantService {
|
|
|
745
832
|
};
|
|
746
833
|
}
|
|
747
834
|
|
|
748
|
-
if (pageVariantConfig.variantType ===
|
|
835
|
+
if (pageVariantConfig.variantType === "homepage") {
|
|
749
836
|
return {
|
|
750
837
|
variantId: pageVariantConfig.variantId,
|
|
751
|
-
variant:
|
|
838
|
+
variant: "page_visit",
|
|
752
839
|
pageVisitCategory: PageVisitCategory.Homepage,
|
|
753
840
|
url,
|
|
754
841
|
};
|
|
755
842
|
}
|
|
756
843
|
|
|
757
|
-
if (pageVariantConfig.variantType ===
|
|
844
|
+
if (pageVariantConfig.variantType === "search") {
|
|
758
845
|
return {
|
|
759
846
|
variantId: pageVariantConfig.variantId,
|
|
760
|
-
variant:
|
|
847
|
+
variant: "page_visit",
|
|
761
848
|
pageVisitCategory: PageVisitCategory.Search,
|
|
762
849
|
url,
|
|
763
850
|
};
|
|
764
851
|
}
|
|
765
852
|
|
|
766
|
-
if (pageVariantConfig.variantType ===
|
|
853
|
+
if (pageVariantConfig.variantType === "other") {
|
|
767
854
|
return {
|
|
768
855
|
variantId: pageVariantConfig.variantId,
|
|
769
|
-
variant:
|
|
856
|
+
variant: "page_visit",
|
|
770
857
|
pageVisitCategory: PageVisitCategory.Other,
|
|
771
858
|
url,
|
|
772
859
|
};
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
ResponseError,
|
|
5
5
|
SearchApi,
|
|
6
6
|
} from "@spiffy-ai/commerce-api-client";
|
|
7
|
-
import { getAtomStore } from "src/atoms/atomStore";
|
|
7
|
+
import { getAtomStore } from "src/atoms/atomStore/atomStore";
|
|
8
8
|
import { apiKeyAtom } from "src/atoms/org/org";
|
|
9
9
|
import { appDetailsAtom } from "src/atoms/app";
|
|
10
10
|
import Logger from "src/application/logging/logger";
|