@cimplify/sdk 0.108.0 → 0.110.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/LICENSE +21 -0
- package/dist/advanced.d.mts +4 -3
- package/dist/advanced.d.ts +4 -3
- package/dist/advanced.js +24 -24
- package/dist/advanced.mjs +5 -5
- package/dist/animation-4EXBXRVX.js +27 -0
- package/dist/animation-6DICNWUP.mjs +6 -0
- package/dist/audio-DhvyjqdA.d.mts +249 -0
- package/dist/audio-m0w8cnxq.d.ts +249 -0
- package/dist/avatars.d.mts +110 -0
- package/dist/avatars.d.ts +110 -0
- package/dist/avatars.js +82 -0
- package/dist/avatars.mjs +5 -0
- package/dist/backend-gUCzs5Kg.d.mts +3866 -0
- package/dist/backend-gUCzs5Kg.d.ts +3866 -0
- package/dist/{catalogue-B4eLL8Mi.d.ts → catalogue-CPTMyBUz.d.mts} +109 -221
- package/dist/catalogue-DzrTXP3v.d.mts +541 -0
- package/dist/catalogue-DzrTXP3v.d.ts +541 -0
- package/dist/{catalogue-OT89_Ifs.d.mts → catalogue-OTuS5zp-.d.ts} +109 -221
- package/dist/chunk-22BD3RHN.mjs +1809 -0
- package/dist/chunk-25T4JHEA.mjs +21 -0
- package/dist/chunk-2AQ237Y4.js +508 -0
- package/dist/chunk-2IC4H6OV.mjs +48 -0
- package/dist/chunk-2LHLG4OB.mjs +71 -0
- package/dist/chunk-2O2CG465.js +1709 -0
- package/dist/chunk-2Q4DTHXK.js +316 -0
- package/dist/chunk-2QTQ6BUH.mjs +46 -0
- package/dist/chunk-2UN4SFLR.mjs +100 -0
- package/dist/chunk-2V75I7K3.js +454 -0
- package/dist/chunk-2V7IL4HC.js +10 -0
- package/dist/chunk-34XBXUMW.js +296 -0
- package/dist/chunk-3C4C654I.js +71 -0
- package/dist/chunk-3DAD2LDF.mjs +72 -0
- package/dist/chunk-3GXH2NFD.mjs +4 -0
- package/dist/chunk-3O47ZFW3.js +961 -0
- package/dist/chunk-3OY3VYNF.mjs +11 -0
- package/dist/chunk-3S6WPBZL.js +2936 -0
- package/dist/chunk-3TUOUP5T.js +399 -0
- package/dist/chunk-3VEH23I5.mjs +1380 -0
- package/dist/chunk-3ZYSAW2T.mjs +263 -0
- package/dist/chunk-4ANVF274.js +103 -0
- package/dist/chunk-4C7I3ELN.js +388 -0
- package/dist/chunk-4DYKAYFO.mjs +8 -0
- package/dist/chunk-4ZDR72SG.js +329 -0
- package/dist/chunk-52YS45RR.js +1066 -0
- package/dist/chunk-5325XSCH.js +107 -0
- package/dist/chunk-5AD5X6AV.js +13 -0
- package/dist/chunk-5BYDGGWO.mjs +197 -0
- package/dist/chunk-5C3C7VDM.mjs +55 -0
- package/dist/chunk-5HFMY3D7.js +660 -0
- package/dist/chunk-5LH2QN3T.js +1862 -0
- package/dist/chunk-5PJEXSOW.js +44 -0
- package/dist/chunk-5SXDH3Y7.js +90 -0
- package/dist/chunk-5YFBGGCK.mjs +502 -0
- package/dist/chunk-5YWN6H5Q.mjs +133 -0
- package/dist/chunk-66QP3SMN.js +402 -0
- package/dist/chunk-6DAEZKIG.mjs +385 -0
- package/dist/chunk-6DATW7TB.mjs +420 -0
- package/dist/{chunk-JRGK3NXR.mjs → chunk-6ETDAU62.mjs} +72 -212
- package/dist/chunk-6H254EVP.mjs +178 -0
- package/dist/chunk-6PFNJPBJ.mjs +820 -0
- package/dist/chunk-6PJWXIFX.mjs +357 -0
- package/dist/chunk-6SWKWCMS.js +80 -0
- package/dist/chunk-6VVXXX7S.js +808 -0
- package/dist/chunk-6WUBSMTX.js +1403 -0
- package/dist/chunk-73SGZLAQ.mjs +35 -0
- package/dist/chunk-76L2V6KD.mjs +4 -0
- package/dist/chunk-7AAIAVAA.js +1531 -0
- package/dist/chunk-7ARSJPV3.mjs +93 -0
- package/dist/chunk-7BHW5GTC.mjs +1234 -0
- package/dist/chunk-7DQSDKDU.js +6 -0
- package/dist/chunk-7IQQQENP.mjs +401 -0
- package/dist/chunk-7KFTYENS.js +11357 -0
- package/dist/chunk-7SM6XSPZ.js +3171 -0
- package/dist/chunk-7SXOHAIR.mjs +28 -0
- package/dist/chunk-A2MAX6S4.js +90 -0
- package/dist/chunk-A33OORT7.mjs +1530 -0
- package/dist/{chunk-U6ACF76H.mjs → chunk-A36JRXXH.mjs} +1075 -1845
- package/dist/chunk-A7BU3BK4.js +52 -0
- package/dist/chunk-A7MQSN2V.mjs +77 -0
- package/dist/chunk-A7V4L2IT.mjs +416 -0
- package/dist/chunk-AABEK6XU.js +226 -0
- package/dist/chunk-AGV33FWC.mjs +5005 -0
- package/dist/chunk-AHNR3BXI.js +108 -0
- package/dist/chunk-AQ5RLBU2.mjs +286 -0
- package/dist/chunk-AQOE6WCG.js +1270 -0
- package/dist/chunk-ATAWRACV.mjs +62 -0
- package/dist/chunk-ATCURNUV.js +14 -0
- package/dist/chunk-AWPV33OO.js +6 -0
- package/dist/chunk-AYJPHKYV.js +337 -0
- package/dist/chunk-AZ5BGWHB.js +162 -0
- package/dist/chunk-AZAXD44P.js +1373 -0
- package/dist/chunk-BBGKQIJJ.mjs +406 -0
- package/dist/chunk-BP4JLSUA.js +1453 -0
- package/dist/{chunk-SUCE7FWA.mjs → chunk-BTUSVHIE.mjs} +539 -978
- package/dist/chunk-BU6OK542.mjs +818 -0
- package/dist/chunk-CVSRWM6W.js +418 -0
- package/dist/chunk-CYBMFMJD.mjs +247 -0
- package/dist/chunk-DDJLDOUX.mjs +217 -0
- package/dist/{chunk-V32BCG7M.js → chunk-DFZWHNRG.js} +75 -215
- package/dist/chunk-DJ2C7AVG.js +644 -0
- package/dist/chunk-DS2VU4WW.mjs +102 -0
- package/dist/chunk-DSAG7T5P.js +7290 -0
- package/dist/chunk-E2QPPH7I.js +327 -0
- package/dist/chunk-E65WCTIG.mjs +1187 -0
- package/dist/{chunk-33VCYWVL.mjs → chunk-E6QQKDNE.mjs} +30 -42
- package/dist/chunk-ECDK6QBF.mjs +981 -0
- package/dist/chunk-EIB4OWVQ.mjs +620 -0
- package/dist/chunk-EQUZYCGO.js +250 -0
- package/dist/chunk-F3UJ6ZRM.mjs +313 -0
- package/dist/chunk-F63N2ZTQ.js +7023 -0
- package/dist/chunk-F6XRYEM3.mjs +26 -0
- package/dist/chunk-FE6VCE4K.js +5030 -0
- package/dist/chunk-FLWD6GRR.js +1372 -0
- package/dist/chunk-FQBFWJBS.mjs +110 -0
- package/dist/chunk-FXVJ2HFU.js +26 -0
- package/dist/chunk-FZMQMQBW.js +312 -0
- package/dist/chunk-G3EEC44R.js +53 -0
- package/dist/{chunk-KG3WT4PR.mjs → chunk-GCKWKLZF.mjs} +73 -104
- package/dist/chunk-GCX7TY4D.mjs +6826 -0
- package/dist/chunk-GDB6TCSD.js +450 -0
- package/dist/chunk-GDCV4IWO.mjs +21 -0
- package/dist/chunk-GDZT5LZ5.js +170 -0
- package/dist/chunk-GHPUYD4I.mjs +213 -0
- package/dist/chunk-GHS6MIL6.mjs +1432 -0
- package/dist/chunk-GPS2THCL.mjs +11 -0
- package/dist/{chunk-EV2EVOYS.js → chunk-GTJWQAGU.js} +31 -42
- package/dist/chunk-GVTI6UJQ.mjs +130 -0
- package/dist/chunk-GXKI64OT.mjs +1138 -0
- package/dist/chunk-GYDYF2WX.js +275 -0
- package/dist/chunk-GYLP6UG4.mjs +705 -0
- package/dist/chunk-H3OQKK6X.js +1158 -0
- package/dist/chunk-H5DFSCJ6.js +40 -0
- package/dist/chunk-HAGEIC2L.mjs +186 -0
- package/dist/chunk-HAJ4JRFO.js +293 -0
- package/dist/chunk-HDR72GB6.js +188 -0
- package/dist/chunk-HF5HPS4T.mjs +40 -0
- package/dist/chunk-HK6LOFDS.js +218 -0
- package/dist/chunk-HMWYTXCY.mjs +143 -0
- package/dist/chunk-HPCSRCMA.js +89 -0
- package/dist/chunk-HSEO6TPU.js +247 -0
- package/dist/chunk-I5FOHCLH.js +132 -0
- package/dist/chunk-IDLW4NWA.mjs +85 -0
- package/dist/chunk-IIDZ5WUX.js +61 -0
- package/dist/chunk-IR74FJHU.js +2332 -0
- package/dist/chunk-IRVFYAKP.mjs +100 -0
- package/dist/{chunk-XBL3TMPC.mjs → chunk-IZDWAL53.mjs} +1795 -3287
- package/dist/chunk-J2KZXIU3.js +51 -0
- package/dist/chunk-J2U6PJSO.js +91 -0
- package/dist/chunk-J5AJNY2N.js +283 -0
- package/dist/chunk-J6KQZ4FO.mjs +821 -0
- package/dist/{chunk-OWW5GUSB.js → chunk-JGBCIKJV.js} +7 -6
- package/dist/chunk-JKGTBMU7.mjs +25 -0
- package/dist/chunk-JR3TNEQC.js +422 -0
- package/dist/chunk-JURRXY2J.mjs +29 -0
- package/dist/chunk-K3HW5I2A.mjs +317 -0
- package/dist/chunk-K46SMZ66.mjs +103 -0
- package/dist/chunk-K4UDGE3Z.mjs +6 -0
- package/dist/chunk-KDQOR4QQ.mjs +350 -0
- package/dist/chunk-KDTVOLHI.mjs +288 -0
- package/dist/chunk-KGHJH5KJ.mjs +35 -0
- package/dist/chunk-KIZOA5LX.mjs +140 -0
- package/dist/chunk-KK6HYVBI.mjs +242 -0
- package/dist/chunk-KMKWGXMK.js +856 -0
- package/dist/chunk-KPA6K5IB.js +80 -0
- package/dist/chunk-KU7O4IXU.mjs +260 -0
- package/dist/chunk-KVFNRJOR.mjs +11142 -0
- package/dist/chunk-KZJRSXHK.js +2432 -0
- package/dist/chunk-LHWPRUJL.js +79 -0
- package/dist/chunk-LIV3KXJG.mjs +369 -0
- package/dist/chunk-LKV4LACG.js +21 -0
- package/dist/chunk-LUY45X3U.mjs +263 -0
- package/dist/chunk-LYEZZEEF.mjs +17 -0
- package/dist/chunk-M5EXQZYY.mjs +1519 -0
- package/dist/chunk-ME6HGG4I.mjs +1338 -0
- package/dist/chunk-MEXP6DA6.js +31 -0
- package/dist/chunk-MG52AW3H.js +902 -0
- package/dist/chunk-MIPO6F72.js +334 -0
- package/dist/{chunk-5QW7CQBA.js → chunk-MKIJQL5Q.js} +211 -321
- package/dist/chunk-MN3YETVN.mjs +17 -0
- package/dist/chunk-MOBSBXVE.mjs +2391 -0
- package/dist/chunk-MOMOZEUM.mjs +88 -0
- package/dist/chunk-MRFUNRAP.js +62 -0
- package/dist/chunk-MTIHEW2M.js +433 -0
- package/dist/chunk-N4RGGDEL.mjs +73 -0
- package/dist/chunk-NH654HAT.js +10 -0
- package/dist/chunk-NHJUGZUR.mjs +253 -0
- package/dist/chunk-NMQT4HG3.mjs +757 -0
- package/dist/chunk-NPSYB6DC.mjs +906 -0
- package/dist/chunk-NW2GPMSO.js +857 -0
- package/dist/chunk-NXKQOQ6L.js +76 -0
- package/dist/chunk-NXLAZIJZ.js +309 -0
- package/dist/chunk-NYWNA5CF.js +148 -0
- package/dist/chunk-NZTKLY2W.js +1442 -0
- package/dist/chunk-O2ICABUD.js +36 -0
- package/dist/chunk-OIVVQQ22.js +862 -0
- package/dist/chunk-OKC2B4O3.mjs +312 -0
- package/dist/chunk-OLWFPDBK.js +2220 -0
- package/dist/chunk-OMTVH334.js +3779 -0
- package/dist/chunk-OQRVEM56.mjs +362 -0
- package/dist/chunk-OXMIBOD4.js +337 -0
- package/dist/chunk-PBL6YL5L.mjs +288 -0
- package/dist/chunk-PDOELNNQ.js +97 -0
- package/dist/chunk-PDQJY2GZ.js +136 -0
- package/dist/chunk-PKOZXD2Q.js +1274 -0
- package/dist/chunk-PPF2BYFL.mjs +2191 -0
- package/dist/chunk-PQTQKNKD.js +539 -0
- package/dist/chunk-PRSR4FAV.mjs +81 -0
- package/dist/chunk-PTRNO5UD.js +95 -0
- package/dist/chunk-Q2Y3VMKH.js +2000 -0
- package/dist/chunk-QCZOE65N.js +96 -0
- package/dist/chunk-QDYFLATW.mjs +52 -0
- package/dist/chunk-QQABGCMM.js +22 -0
- package/dist/chunk-QS6TRHMR.js +345 -0
- package/dist/chunk-R56P64LB.mjs +208 -0
- package/dist/chunk-RCQ2MPBV.js +428 -0
- package/dist/chunk-RFVRPYR2.mjs +856 -0
- package/dist/chunk-RKBLPGPV.js +11521 -0
- package/dist/chunk-RM2V4IND.mjs +327 -0
- package/dist/chunk-RQXN5A34.mjs +613 -0
- package/dist/chunk-RUVGVNOF.mjs +2687 -0
- package/dist/chunk-SAFJIGYB.mjs +165 -0
- package/dist/chunk-SKQFLBDD.js +263 -0
- package/dist/chunk-SMK6JU2F.mjs +2092 -0
- package/dist/{chunk-UVRPC2P7.js → chunk-SNNEOS5Z.js} +1984 -3476
- package/dist/chunk-SPCRQ6NO.mjs +1246 -0
- package/dist/chunk-SWX4SALA.mjs +19 -0
- package/dist/{chunk-JVODCGFP.mjs → chunk-SYEO2WV4.mjs} +128 -238
- package/dist/chunk-T2QQMX2N.js +10 -0
- package/dist/chunk-T3AFF3L7.mjs +57 -0
- package/dist/chunk-T6Z2EXYL.js +712 -0
- package/dist/chunk-T7LOXGYX.js +118 -0
- package/dist/chunk-TJCAE7RC.mjs +1315 -0
- package/dist/chunk-TJI3K6RP.js +137 -0
- package/dist/chunk-TL2SVO4P.mjs +55 -0
- package/dist/chunk-TM63CYGN.mjs +399 -0
- package/dist/chunk-TU5RYTYU.mjs +13 -0
- package/dist/chunk-TVJZ4GPS.js +1553 -0
- package/dist/chunk-TWM6DLYF.js +371 -0
- package/dist/chunk-U63OC4TQ.js +30 -0
- package/dist/{chunk-L5GKVQVJ.js → chunk-U6BVSJZ6.js} +25 -57
- package/dist/chunk-U6UVWEAK.mjs +792 -0
- package/dist/chunk-UCEPNO6N.mjs +11048 -0
- package/dist/{chunk-ANT574FD.js → chunk-UCR5HRYM.js} +74 -105
- package/dist/chunk-UG5BTOTF.mjs +334 -0
- package/dist/chunk-UGH37BQW.mjs +157 -0
- package/dist/chunk-V7ZRH3PY.mjs +271 -0
- package/dist/chunk-VBGHBL3E.mjs +1394 -0
- package/dist/chunk-VRBDAS5I.js +920 -0
- package/dist/chunk-VVE3Y76O.js +230 -0
- package/dist/chunk-W65JIRI4.mjs +1182 -0
- package/dist/chunk-WHYKAT7G.js +62 -0
- package/dist/{chunk-YOIVZ6OA.mjs → chunk-WIZRUIZB.mjs} +25 -57
- package/dist/chunk-WKWTDZS7.js +385 -0
- package/dist/chunk-WLMINRC4.mjs +78 -0
- package/dist/chunk-WOF3AD3J.js +22 -0
- package/dist/chunk-WWKMOA76.js +1262 -0
- package/dist/chunk-X5A5FOWW.js +615 -0
- package/dist/chunk-X6CN6KQF.mjs +192 -0
- package/dist/chunk-XD2PMH46.mjs +517 -0
- package/dist/chunk-XJA2NGTI.mjs +88 -0
- package/dist/chunk-XJIHN3BY.mjs +8 -0
- package/dist/chunk-XK6UDWJS.js +203 -0
- package/dist/chunk-XPG3N5CF.mjs +415 -0
- package/dist/chunk-XVZ2NKSU.mjs +74 -0
- package/dist/chunk-XYP45OLE.js +117 -0
- package/dist/chunk-XZSDGZX6.mjs +301 -0
- package/dist/chunk-Y2EMGN4T.mjs +120 -0
- package/dist/chunk-Y3XWP5XW.mjs +298 -0
- package/dist/chunk-Y4K22JL6.js +228 -0
- package/dist/chunk-Y65LXQGA.mjs +3164 -0
- package/dist/chunk-Y66WVMO5.mjs +87 -0
- package/dist/chunk-Y7JWLB25.mjs +7280 -0
- package/dist/chunk-YCDXAJKU.js +175 -0
- package/dist/chunk-YRDQCCIS.js +152 -0
- package/dist/chunk-YV52DGSA.js +111 -0
- package/dist/chunk-YXGZQPUD.js +94 -0
- package/dist/chunk-Z3A3AFVU.mjs +102 -0
- package/dist/chunk-ZCY6YKKP.mjs +475 -0
- package/dist/chunk-ZEQHXVU5.js +215 -0
- package/dist/chunk-ZF7JCXCI.js +284 -0
- package/dist/chunk-ZJBRUH6V.js +29 -0
- package/dist/chunk-ZMIL4ZOA.js +365 -0
- package/dist/chunk-ZR5ULMN2.mjs +337 -0
- package/dist/chunk-ZXREOYOW.js +87 -0
- package/dist/{client-BSP9U1O1.d.mts → client-CX_WR0-J.d.mts} +2 -2
- package/dist/client-Dytx_ZTC.d.ts +230 -0
- package/dist/{client-B878xeAP.d.ts → client-dqOhP9Nc.d.ts} +2 -2
- package/dist/client-hTKbCuhG.d.mts +230 -0
- package/dist/clock-B-UAjkKa.d.mts +5 -0
- package/dist/clock-B-UAjkKa.d.ts +5 -0
- package/dist/config-BlXQluJR.d.mts +36 -0
- package/dist/config-BlXQluJR.d.ts +36 -0
- package/dist/courier-Cnn-edJ4.d.ts +95 -0
- package/dist/courier-FmGfkvIN.d.mts +95 -0
- package/dist/crowd-DdHFbqKK.d.ts +186 -0
- package/dist/crowd-hOVSAmA3.d.mts +186 -0
- package/dist/danfo-BEBapFlX.d.mts +146 -0
- package/dist/danfo-UQ_PTIIx.d.ts +146 -0
- package/dist/{elements-Bty6Qs_N.d.mts → elements-DdsRig-2.d.mts} +1548 -257
- package/dist/{elements-Bty6Qs_N.d.ts → elements-DdsRig-2.d.ts} +1548 -257
- package/dist/engines/godot.d.mts +56 -0
- package/dist/engines/godot.d.ts +56 -0
- package/dist/engines/godot.js +28 -0
- package/dist/engines/godot.mjs +3 -0
- package/dist/engines/wasm.d.mts +11 -0
- package/dist/engines/wasm.d.ts +11 -0
- package/dist/engines/wasm.js +178 -0
- package/dist/engines/wasm.mjs +176 -0
- package/dist/fallback-CrG_lTFk.d.mts +270 -0
- package/dist/fallback-CrG_lTFk.d.ts +270 -0
- package/dist/fallback-KDB4Y2CE.mjs +6 -0
- package/dist/fallback-Y26TQENE.js +19 -0
- package/dist/features-CZB4rmcD.d.mts +118 -0
- package/dist/features-CZB4rmcD.d.ts +118 -0
- package/dist/fit-BWiE7rgA.d.mts +44 -0
- package/dist/fit-DK0oT7zO.d.ts +44 -0
- package/dist/five-a-side-Bv1AOUy3.d.mts +115 -0
- package/dist/five-a-side-EC51SJY1.d.ts +115 -0
- package/dist/fluid-ARr0qUIL.d.ts +939 -0
- package/dist/fluid-DLlEj2cs.d.mts +939 -0
- package/dist/game/conformance.d.mts +84 -0
- package/dist/game/conformance.d.ts +84 -0
- package/dist/game/conformance.js +1025 -0
- package/dist/game/conformance.mjs +994 -0
- package/dist/game/heap.d.mts +40 -0
- package/dist/game/heap.d.ts +40 -0
- package/dist/game/heap.js +48 -0
- package/dist/game/heap.mjs +7 -0
- package/dist/game/kit/canvas.d.mts +240 -0
- package/dist/game/kit/canvas.d.ts +240 -0
- package/dist/game/kit/canvas.js +3566 -0
- package/dist/game/kit/canvas.mjs +1039 -0
- package/dist/game/kit/courier.d.mts +17 -0
- package/dist/game/kit/courier.d.ts +17 -0
- package/dist/game/kit/courier.js +66 -0
- package/dist/game/kit/courier.mjs +49 -0
- package/dist/game/kit/danfo.d.mts +11 -0
- package/dist/game/kit/danfo.d.ts +11 -0
- package/dist/game/kit/danfo.js +109 -0
- package/dist/game/kit/danfo.mjs +44 -0
- package/dist/game/kit/engine.d.mts +29 -0
- package/dist/game/kit/engine.d.ts +29 -0
- package/dist/game/kit/engine.js +183 -0
- package/dist/game/kit/engine.mjs +30 -0
- package/dist/game/kit/five-a-side.d.mts +11 -0
- package/dist/game/kit/five-a-side.d.ts +11 -0
- package/dist/game/kit/five-a-side.js +86 -0
- package/dist/game/kit/five-a-side.mjs +41 -0
- package/dist/game/kit/frontier.d.mts +344 -0
- package/dist/game/kit/frontier.d.ts +344 -0
- package/dist/game/kit/frontier.js +435 -0
- package/dist/game/kit/frontier.mjs +14 -0
- package/dist/game/kit/genesis.d.mts +752 -0
- package/dist/game/kit/genesis.d.ts +752 -0
- package/dist/game/kit/genesis.js +380 -0
- package/dist/game/kit/genesis.mjs +15 -0
- package/dist/game/kit/ludo.d.mts +15 -0
- package/dist/game/kit/ludo.d.ts +15 -0
- package/dist/game/kit/ludo.js +87 -0
- package/dist/game/kit/ludo.mjs +42 -0
- package/dist/game/kit/runner.d.mts +12 -0
- package/dist/game/kit/runner.d.ts +12 -0
- package/dist/game/kit/runner.js +83 -0
- package/dist/game/kit/runner.mjs +46 -0
- package/dist/game/kit/shootout.d.mts +13 -0
- package/dist/game/kit/shootout.d.ts +13 -0
- package/dist/game/kit/shootout.js +122 -0
- package/dist/game/kit/shootout.mjs +57 -0
- package/dist/game/kit/slots.d.mts +392 -0
- package/dist/game/kit/slots.d.ts +392 -0
- package/dist/game/kit/slots.js +215 -0
- package/dist/game/kit/slots.mjs +6 -0
- package/dist/game/kit/tycoon.d.mts +16 -0
- package/dist/game/kit/tycoon.d.ts +16 -0
- package/dist/game/kit/tycoon.js +145 -0
- package/dist/game/kit/tycoon.mjs +44 -0
- package/dist/game/kit/word.d.mts +11 -0
- package/dist/game/kit/word.d.ts +11 -0
- package/dist/game/kit/word.js +78 -0
- package/dist/game/kit/word.mjs +41 -0
- package/dist/game/kit/worlds.d.mts +18 -0
- package/dist/game/kit/worlds.d.ts +18 -0
- package/dist/game/kit/worlds.js +74 -0
- package/dist/game/kit/worlds.mjs +49 -0
- package/dist/game/kit.d.mts +53 -0
- package/dist/game/kit.d.ts +53 -0
- package/dist/game/kit.js +2610 -0
- package/dist/game/kit.mjs +101 -0
- package/dist/game/prepared.d.mts +14 -0
- package/dist/game/prepared.d.ts +14 -0
- package/dist/game/prepared.js +81 -0
- package/dist/game/prepared.mjs +32 -0
- package/dist/game-Bx8onkhX.d.mts +1451 -0
- package/dist/game-fgQy2YIm.d.ts +1451 -0
- package/dist/game-theme-CBTw1b_d.d.mts +35 -0
- package/dist/game-theme-Dg-ict5A.d.ts +35 -0
- package/dist/game.d.mts +3546 -0
- package/dist/game.d.ts +3546 -0
- package/dist/game.js +4455 -0
- package/dist/game.mjs +50 -0
- package/dist/graphics-C6YjWYvP.d.ts +5 -0
- package/dist/graphics-Dk2yQnYN.d.mts +5 -0
- package/dist/guest-DrsA00XD.d.mts +732 -0
- package/dist/guest-wIdfoT05.d.ts +732 -0
- package/dist/hit-stop-BKkVwTq7.d.mts +43 -0
- package/dist/hit-stop-D-8pPYnM.d.ts +43 -0
- package/dist/hot-Crn9XpHJ.d.ts +29 -0
- package/dist/hot-DH3nOhQD.d.mts +29 -0
- package/dist/{index-CQStGb3B.d.mts → index-6gkHMGAq.d.mts} +2 -2
- package/dist/index-B8ybCKJI.d.ts +41 -0
- package/dist/{index-DJwXmoaP.d.ts → index-B98Xac8e.d.ts} +2 -2
- package/dist/{index-B7oA_1XI.d.ts → index-B_ByTtIT.d.ts} +2 -2
- package/dist/index-DHjNHb1c.d.mts +41 -0
- package/dist/{index-DhUSTAhT.d.mts → index-DbAN_VQE.d.mts} +2 -2
- package/dist/index.d.mts +134 -24
- package/dist/index.d.ts +134 -24
- package/dist/index.js +407 -248
- package/dist/index.mjs +184 -58
- package/dist/interactives-authoring.d.mts +231 -0
- package/dist/interactives-authoring.d.ts +231 -0
- package/dist/interactives-authoring.js +1743 -0
- package/dist/interactives-authoring.mjs +1704 -0
- package/dist/interactives-canvas.global.js +148 -0
- package/dist/interactives-guest.d.mts +20 -0
- package/dist/interactives-guest.d.ts +20 -0
- package/dist/interactives-guest.js +63 -0
- package/dist/interactives-guest.json +1 -0
- package/dist/interactives-guest.mjs +61 -0
- package/dist/interactives-jsc.global.js +9357 -0
- package/dist/interactives-meters.d.mts +93 -0
- package/dist/interactives-meters.d.ts +93 -0
- package/dist/interactives-meters.js +252 -0
- package/dist/interactives-meters.mjs +68 -0
- package/dist/interactives-production.d.mts +430 -0
- package/dist/interactives-production.d.ts +430 -0
- package/dist/interactives-production.js +1231 -0
- package/dist/interactives-production.mjs +1170 -0
- package/dist/interactives-record.d.mts +112 -0
- package/dist/interactives-record.d.ts +112 -0
- package/dist/interactives-record.js +302 -0
- package/dist/interactives-record.mjs +295 -0
- package/dist/interactives-runtime.d.mts +61 -0
- package/dist/interactives-runtime.d.ts +61 -0
- package/dist/interactives-runtime.js +442 -0
- package/dist/interactives-runtime.mjs +25 -0
- package/dist/interactives-studio-kernel.global.js +1 -0
- package/dist/interactives-studio.d.mts +806 -0
- package/dist/interactives-studio.d.ts +806 -0
- package/dist/interactives-studio.js +5741 -0
- package/dist/interactives-studio.mjs +5651 -0
- package/dist/interactives-tick.d.mts +90 -0
- package/dist/interactives-tick.d.ts +90 -0
- package/dist/interactives-tick.js +203 -0
- package/dist/interactives-tick.mjs +6 -0
- package/dist/interactives-web.d.mts +762 -0
- package/dist/interactives-web.d.ts +762 -0
- package/dist/interactives-web.js +5000 -0
- package/dist/interactives-web.mjs +4628 -0
- package/dist/interactives.d.mts +2430 -0
- package/dist/interactives.d.ts +2430 -0
- package/dist/interactives.js +5723 -0
- package/dist/interactives.mjs +4333 -0
- package/dist/juice-CoHxlpKA.d.ts +42 -0
- package/dist/juice-DQztFS43.d.mts +42 -0
- package/dist/launch-T2f4_Di4.d.mts +151 -0
- package/dist/launch-d6oreMzR.d.ts +151 -0
- package/dist/library-DXYaMFhi.d.mts +69 -0
- package/dist/library-DXYaMFhi.d.ts +69 -0
- package/dist/link-BUTqGmyi.d.mts +38 -0
- package/dist/link-BUTqGmyi.d.ts +38 -0
- package/dist/lint.js +104 -204
- package/dist/lint.mjs +103 -203
- package/dist/local-D8_I6UeL.d.mts +6967 -0
- package/dist/local-VZkqsCzR.d.ts +6967 -0
- package/dist/lockstep-BLf6dglI.d.mts +321 -0
- package/dist/lockstep-D50Ia0JW.d.ts +321 -0
- package/dist/ludo-B8ClkDqr.d.ts +205 -0
- package/dist/ludo-BOuohQ-M.d.mts +205 -0
- package/dist/mock/cli.mjs +200 -56
- package/dist/mock/library.js +200 -56
- package/dist/mock/library.mjs +200 -56
- package/dist/mock/msw.js +200 -56
- package/dist/mock/msw.mjs +200 -56
- package/dist/native-BodxSh03.d.mts +16 -0
- package/dist/native-DUHMT8gA.d.ts +16 -0
- package/dist/network-ZXLD7l1b.d.mts +19 -0
- package/dist/network-ZXLD7l1b.d.ts +19 -0
- package/dist/online-XeymeM9s.d.ts +381 -0
- package/dist/online-d7W_Al9a.d.mts +381 -0
- package/dist/params-DxFb5G_U.d.mts +155 -0
- package/dist/params-DxFb5G_U.d.ts +155 -0
- package/dist/play-BRRlfLhX.d.ts +940 -0
- package/dist/play-ClrMd_e8.d.mts +940 -0
- package/dist/policy-CCw8tXLm.d.mts +3078 -0
- package/dist/policy-CMqOSQIu.d.ts +3078 -0
- package/dist/ports-B_0v_P3A.d.mts +13 -0
- package/dist/ports-CGU_3e_0.d.ts +13 -0
- package/dist/prefetch-BHnicOQj.d.ts +117 -0
- package/dist/prefetch-CBXgYacv.d.mts +117 -0
- package/dist/{price-CSztR02F.d.mts → price-BOzexBww.d.mts} +1 -1
- package/dist/{price-C_vasx9A.d.ts → price-C1h9sPxE.d.ts} +1 -1
- package/dist/protocol-C8qbpUbT.d.mts +242 -0
- package/dist/protocol-C8qbpUbT.d.ts +242 -0
- package/dist/rapier-AZHT4YI7.js +7886 -0
- package/dist/rapier-ODEPCQA6.mjs +7792 -0
- package/dist/react.d.mts +157 -15
- package/dist/react.d.ts +157 -15
- package/dist/react.js +5564 -5904
- package/dist/react.mjs +5451 -5808
- package/dist/runner-CQcLL7By.d.ts +189 -0
- package/dist/runner-D46Yj-wE.d.mts +189 -0
- package/dist/runtime-BRWfkf_q.d.mts +51 -0
- package/dist/runtime-DyuBMkKM.d.ts +51 -0
- package/dist/scheduling-D2ajXpMC.d.ts +224 -0
- package/dist/scheduling-DSRbbaZb.d.mts +224 -0
- package/dist/schema-BrWxzKp6.d.mts +63 -0
- package/dist/schema-BrWxzKp6.d.ts +63 -0
- package/dist/server/evict.js +34 -37
- package/dist/server/evict.mjs +34 -37
- package/dist/server/tanstack.d.mts +49 -3
- package/dist/server/tanstack.d.ts +49 -3
- package/dist/server/tanstack.js +169 -117
- package/dist/server/tanstack.mjs +166 -118
- package/dist/{server-Dckg4Vdr.d.ts → server-D29IIuDV.d.ts} +136 -130
- package/dist/{server-B6dW7-Lj.d.mts → server-DQMWPnc8.d.mts} +136 -130
- package/dist/server.d.mts +45 -5
- package/dist/server.d.ts +45 -5
- package/dist/server.js +171 -227
- package/dist/server.mjs +165 -225
- package/dist/session-grant-CJ27DwrT.d.mts +19 -0
- package/dist/session-grant-CJ27DwrT.d.ts +19 -0
- package/dist/shootout-BJZeX6FG.d.ts +140 -0
- package/dist/shootout-tcZd1Rxt.d.mts +140 -0
- package/dist/state-replica-stMtdkVD.d.mts +42 -0
- package/dist/state-replica-stMtdkVD.d.ts +42 -0
- package/dist/studio-CowqWqez.d.mts +14 -0
- package/dist/studio-CowqWqez.d.ts +14 -0
- package/dist/styles.css +1 -1
- package/dist/template-AhCdB1kW.d.mts +190 -0
- package/dist/template-BkEGVTQj.d.ts +190 -0
- package/dist/terrain-BMxEc6Oc.d.ts +429 -0
- package/dist/terrain-C-XC1Oui.d.mts +429 -0
- package/dist/testing/msw.d.mts +28 -4
- package/dist/testing/msw.d.ts +28 -4
- package/dist/testing/msw.js +15 -21
- package/dist/testing/msw.mjs +15 -21
- package/dist/testing/suite.d.mts +6 -5
- package/dist/testing/suite.d.ts +6 -5
- package/dist/testing/suite.js +89 -124
- package/dist/testing/suite.mjs +81 -116
- package/dist/testing.d.mts +27 -1227
- package/dist/testing.d.ts +27 -1227
- package/dist/testing.js +127 -131
- package/dist/testing.mjs +19 -23
- package/dist/tick-transport-C8QEh8Uw.d.mts +50 -0
- package/dist/tick-transport-UjHY3xK1.d.ts +50 -0
- package/dist/timeline-protocol-hp6e8zFB.d.mts +47 -0
- package/dist/timeline-protocol-hp6e8zFB.d.ts +47 -0
- package/dist/tokens-DhanQRQS.d.mts +21 -0
- package/dist/tokens-K8yxwd6G.d.ts +21 -0
- package/dist/tree-C-Io2Hbx.d.mts +35 -0
- package/dist/tree-CP_qSW4H.d.ts +35 -0
- package/dist/tycoon-B5KHk2Xx.d.mts +255 -0
- package/dist/tycoon-hmHo-3HX.d.ts +255 -0
- package/dist/types-BQkxPwZP.d.mts +219 -0
- package/dist/types-D_f6UUxM.d.ts +219 -0
- package/dist/ui-DwHicuFv.d.mts +563 -0
- package/dist/ui-hi7S2YcH.d.ts +563 -0
- package/dist/{sign-in-DQlIdqsi.d.mts → url-52ndUruG.d.mts} +15 -1
- package/dist/{sign-in-DQlIdqsi.d.ts → url-52ndUruG.d.ts} +15 -1
- package/dist/utils.d.mts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +37 -37
- package/dist/utils.mjs +4 -4
- package/dist/vars-Dc_PrhBK.d.mts +511 -0
- package/dist/vars-Dc_PrhBK.d.ts +511 -0
- package/dist/vm-IUARFFAI.mjs +63 -0
- package/dist/vm-N7L6MGGH.js +65 -0
- package/dist/weave-delivery-CW-Kstut.d.mts +360 -0
- package/dist/weave-delivery-CW-Kstut.d.ts +360 -0
- package/dist/web-Dss74a7v.d.ts +883 -0
- package/dist/web-f9ZQPoyw.d.mts +883 -0
- package/dist/web-transport-C7MkBL0a.d.ts +19 -0
- package/dist/web-transport-aYEqXMd9.d.mts +19 -0
- package/dist/weight-CPGjsgjV.d.ts +92 -0
- package/dist/weight-tF1ODR1p.d.mts +92 -0
- package/dist/word-BcX9Jcmv.d.mts +70 -0
- package/dist/word-C7sVPLHm.d.ts +70 -0
- package/dist/world-PvILHDR1.d.ts +2285 -0
- package/dist/world-qekkXjJv.d.mts +2285 -0
- package/dist/worlds-Br2Pb0Cs.d.ts +109 -0
- package/dist/worlds-D5ydYr7d.d.mts +109 -0
- package/engines/c/cimplify.h +108 -0
- package/engines/c/cimplify.lib.js +11 -0
- package/engines/godot/addons/cimplify/cimplify.gd +97 -0
- package/engines/rust/interactives-ctx/Cargo.toml +9 -0
- package/engines/rust/interactives-ctx/src/lib.rs +189 -0
- package/package.json +189 -3
- package/vendor/rapier3d-compat/LICENSE +201 -0
- package/vendor/rapier3d-compat/PATCHES.md +61 -0
- package/dist/chunk-2P4KXFB6.js +0 -274
- package/dist/chunk-3G6RQLXK.mjs +0 -21
- package/dist/chunk-3V4DVXV3.mjs +0 -254
- package/dist/chunk-EDK3LNM6.js +0 -2436
- package/dist/chunk-F7J3HK27.js +0 -4549
- package/dist/chunk-U4MW6PYU.mjs +0 -23
- package/dist/chunk-XREIZ56K.js +0 -26
package/dist/chunk-EDK3LNM6.js
DELETED
|
@@ -1,2436 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkXREIZ56K_js = require('./chunk-XREIZ56K.js');
|
|
4
|
-
var chunkF7J3HK27_js = require('./chunk-F7J3HK27.js');
|
|
5
|
-
var chunkANT574FD_js = require('./chunk-ANT574FD.js');
|
|
6
|
-
|
|
7
|
-
// src/types/observability.ts
|
|
8
|
-
var SESSION_CHANGE_SOURCE = {
|
|
9
|
-
RESPONSE: "response",
|
|
10
|
-
MANUAL: "manual",
|
|
11
|
-
CLEAR: "clear"
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
// src/utils/purchase-intent-resolver.ts
|
|
15
|
-
var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
16
|
-
var DEFAULT_MAX_POLL_ATTEMPTS = 60;
|
|
17
|
-
var DEFAULT_MAX_ACTION_STEPS = 4;
|
|
18
|
-
var DEFAULT_MAX_TERMS_REVIEW_STEPS = 4;
|
|
19
|
-
function nonnegativeInteger(value, fallback) {
|
|
20
|
-
if (value === void 0 || !Number.isFinite(value)) return fallback;
|
|
21
|
-
return Math.max(0, Math.floor(value));
|
|
22
|
-
}
|
|
23
|
-
function abortError() {
|
|
24
|
-
const error = new Error("Purchase-intent resolution was cancelled.");
|
|
25
|
-
error.name = "AbortError";
|
|
26
|
-
return error;
|
|
27
|
-
}
|
|
28
|
-
async function abortableWait(milliseconds, signal) {
|
|
29
|
-
if (signal?.aborted) throw abortError();
|
|
30
|
-
if (milliseconds <= 0) return;
|
|
31
|
-
await new Promise((resolve, reject) => {
|
|
32
|
-
const timer = setTimeout(() => {
|
|
33
|
-
signal?.removeEventListener("abort", onAbort);
|
|
34
|
-
resolve();
|
|
35
|
-
}, milliseconds);
|
|
36
|
-
const onAbort = () => {
|
|
37
|
-
clearTimeout(timer);
|
|
38
|
-
reject(abortError());
|
|
39
|
-
};
|
|
40
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
var PurchaseIntentResolver = class {
|
|
44
|
-
constructor(dependencies) {
|
|
45
|
-
this.confirmation = dependencies.confirmation;
|
|
46
|
-
this.wait = dependencies.wait ?? abortableWait;
|
|
47
|
-
}
|
|
48
|
-
async resolve(intentId, options) {
|
|
49
|
-
const pollIntervalMs = nonnegativeInteger(
|
|
50
|
-
options.pollIntervalMs,
|
|
51
|
-
DEFAULT_POLL_INTERVAL_MS
|
|
52
|
-
);
|
|
53
|
-
const maxPollAttempts = nonnegativeInteger(
|
|
54
|
-
options.maxPollAttempts,
|
|
55
|
-
DEFAULT_MAX_POLL_ATTEMPTS
|
|
56
|
-
);
|
|
57
|
-
const maxActionSteps = nonnegativeInteger(options.maxActionSteps, DEFAULT_MAX_ACTION_STEPS);
|
|
58
|
-
const maxTermsReviewSteps = nonnegativeInteger(
|
|
59
|
-
options.maxTermsReviewSteps,
|
|
60
|
-
DEFAULT_MAX_TERMS_REVIEW_STEPS
|
|
61
|
-
);
|
|
62
|
-
let request = options.confirmation;
|
|
63
|
-
let pollAttempts = 0;
|
|
64
|
-
let actionSteps = 0;
|
|
65
|
-
let termsReviewSteps = 0;
|
|
66
|
-
const requestOptions = { signal: options.signal, timeoutMs: options.requestTimeoutMs };
|
|
67
|
-
this.ensureActive(options.signal);
|
|
68
|
-
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.CONFIRMING);
|
|
69
|
-
let responseResult = options.initialResponse ? chunkF7J3HK27_js.ok(options.initialResponse) : await this.confirmation.confirm(intentId, request, requestOptions);
|
|
70
|
-
while (responseResult.ok) {
|
|
71
|
-
this.ensureActive(options.signal);
|
|
72
|
-
const response = responseResult.value;
|
|
73
|
-
switch (response.status) {
|
|
74
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.ORDER_CREATED:
|
|
75
|
-
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.COMPLETED, response);
|
|
76
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.COMPLETED, response });
|
|
77
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.PAYMENT_FAILED:
|
|
78
|
-
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.FAILED, response);
|
|
79
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.FAILED, response });
|
|
80
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.PAYMENT_OUTCOME_UNKNOWN:
|
|
81
|
-
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.OUTCOME_UNKNOWN, response);
|
|
82
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.OUTCOME_UNKNOWN, response });
|
|
83
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.COLLECTION_PROCESSING:
|
|
84
|
-
if (pollAttempts >= maxPollAttempts) {
|
|
85
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.TIMED_OUT, response });
|
|
86
|
-
}
|
|
87
|
-
pollAttempts += 1;
|
|
88
|
-
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.POLLING, response);
|
|
89
|
-
await this.wait(pollIntervalMs, options.signal);
|
|
90
|
-
responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
91
|
-
continue;
|
|
92
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.REDIRECT_REQUIRED:
|
|
93
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.CARD_POPUP_REQUIRED:
|
|
94
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.AUTHORIZATION_REQUIRED: {
|
|
95
|
-
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.AWAITING_ACTION, response);
|
|
96
|
-
if (!options.onActionRequired || actionSteps >= maxActionSteps) {
|
|
97
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.ACTION_REQUIRED, response });
|
|
98
|
-
}
|
|
99
|
-
actionSteps += 1;
|
|
100
|
-
const decision = await options.onActionRequired(response);
|
|
101
|
-
if (decision === chunkANT574FD_js.PURCHASE_INTENT_ACTION_DECISION.STOP) {
|
|
102
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.ACTION_REQUIRED, response });
|
|
103
|
-
}
|
|
104
|
-
if (typeof decision === "object" && decision.kind === chunkANT574FD_js.PURCHASE_INTENT_ACTION_DECISION.SUBMIT) {
|
|
105
|
-
if (!this.confirmation.submitAction) {
|
|
106
|
-
return chunkF7J3HK27_js.err(
|
|
107
|
-
new chunkANT574FD_js.CimplifyError(
|
|
108
|
-
chunkANT574FD_js.PURCHASE_INTENT_ERROR_CODE.ACTION_UNSUPPORTED,
|
|
109
|
-
"This confirmation transport cannot submit purchase-intent actions.",
|
|
110
|
-
false
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
responseResult = await this.confirmation.submitAction(
|
|
115
|
-
intentId,
|
|
116
|
-
response.attempt_id,
|
|
117
|
-
decision.request,
|
|
118
|
-
requestOptions
|
|
119
|
-
);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (decision !== chunkANT574FD_js.PURCHASE_INTENT_ACTION_DECISION.CONTINUE) {
|
|
123
|
-
return chunkF7J3HK27_js.err(
|
|
124
|
-
new chunkANT574FD_js.CimplifyError(
|
|
125
|
-
chunkANT574FD_js.PURCHASE_INTENT_ERROR_CODE.ACTION_UNSUPPORTED,
|
|
126
|
-
"The action callback returned an unsupported decision.",
|
|
127
|
-
false
|
|
128
|
-
)
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
await this.wait(pollIntervalMs, options.signal);
|
|
132
|
-
responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.TERMS_CHANGED: {
|
|
136
|
-
this.notify(options, chunkANT574FD_js.PURCHASE_INTENT_RESOLVE_STATUS.REVIEWING_TERMS, response);
|
|
137
|
-
if (!options.onTermsChanged || termsReviewSteps >= maxTermsReviewSteps) {
|
|
138
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
139
|
-
}
|
|
140
|
-
termsReviewSteps += 1;
|
|
141
|
-
const replacementRequest = await options.onTermsChanged(response);
|
|
142
|
-
if (!replacementRequest) {
|
|
143
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
144
|
-
}
|
|
145
|
-
request = replacementRequest;
|
|
146
|
-
responseResult = await this.confirmation.confirm(intentId, request, requestOptions);
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.SELECTION_UNAVAILABLE:
|
|
150
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.OFFER_ENDED:
|
|
151
|
-
case chunkANT574FD_js.PURCHASE_INTENT_CONFIRM_STATUS.SOURCE_UNAVAILABLE:
|
|
152
|
-
return chunkF7J3HK27_js.ok({ kind: chunkANT574FD_js.PURCHASE_INTENT_RESOLUTION_KIND.REVIEW_REQUIRED, response });
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return responseResult;
|
|
156
|
-
}
|
|
157
|
-
ensureActive(signal) {
|
|
158
|
-
if (signal?.aborted) throw abortError();
|
|
159
|
-
}
|
|
160
|
-
notify(options, status, response) {
|
|
161
|
-
try {
|
|
162
|
-
options.onStatusChange?.(status, response);
|
|
163
|
-
} catch {
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
// src/purchase-intent.ts
|
|
169
|
-
var PURCHASE_INTENT_ROUTE = {
|
|
170
|
-
DIRECT_COLLECTION: "/api/v1/purchase-intents",
|
|
171
|
-
HOSTED_SESSION_COLLECTION: "/v1/checkout/sessions",
|
|
172
|
-
PREPARE: "prepare",
|
|
173
|
-
REFRESH: "refresh",
|
|
174
|
-
CONFIRM: "confirm",
|
|
175
|
-
REPLAY: "replay",
|
|
176
|
-
ATTEMPTS: "attempts",
|
|
177
|
-
ACTIONS: "actions"
|
|
178
|
-
};
|
|
179
|
-
function directIntentPath(intentId) {
|
|
180
|
-
const normalized = intentId.trim();
|
|
181
|
-
if (!normalized) throw new TypeError("intentId must not be empty");
|
|
182
|
-
return `${PURCHASE_INTENT_ROUTE.DIRECT_COLLECTION}/${encodeURIComponent(normalized)}`;
|
|
183
|
-
}
|
|
184
|
-
function hostedSessionPath(sessionId) {
|
|
185
|
-
const normalized = sessionId.trim();
|
|
186
|
-
if (!normalized) throw new TypeError("sessionId must not be empty");
|
|
187
|
-
return `${PURCHASE_INTENT_ROUTE.HOSTED_SESSION_COLLECTION}/${encodeURIComponent(normalized)}`;
|
|
188
|
-
}
|
|
189
|
-
var PurchaseIntentService = class {
|
|
190
|
-
constructor(transport) {
|
|
191
|
-
this.transport = transport;
|
|
192
|
-
this.resolver = new PurchaseIntentResolver({ confirmation: this });
|
|
193
|
-
}
|
|
194
|
-
mint(request, options) {
|
|
195
|
-
return chunkF7J3HK27_js.safe(
|
|
196
|
-
this.transport.post(PURCHASE_INTENT_ROUTE.DIRECT_COLLECTION, request, {
|
|
197
|
-
idempotencyKey: request.client_intent_key,
|
|
198
|
-
signal: options?.signal,
|
|
199
|
-
timeoutMs: options?.timeoutMs
|
|
200
|
-
})
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
get(intentId, options) {
|
|
204
|
-
return chunkF7J3HK27_js.safe(
|
|
205
|
-
this.transport.get(this.intentPath(intentId), {
|
|
206
|
-
signal: options?.signal,
|
|
207
|
-
timeoutMs: options?.timeoutMs
|
|
208
|
-
})
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
refresh(intentId, expectedRevision, options) {
|
|
212
|
-
const request = {
|
|
213
|
-
expected_intent_revision: expectedRevision
|
|
214
|
-
};
|
|
215
|
-
return chunkF7J3HK27_js.safe(
|
|
216
|
-
this.transport.post(
|
|
217
|
-
`${this.intentPath(intentId)}/${PURCHASE_INTENT_ROUTE.REFRESH}`,
|
|
218
|
-
request,
|
|
219
|
-
{
|
|
220
|
-
signal: options?.signal,
|
|
221
|
-
timeoutMs: options?.timeoutMs
|
|
222
|
-
}
|
|
223
|
-
)
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
confirm(intentId, request, options) {
|
|
227
|
-
return chunkF7J3HK27_js.safe(
|
|
228
|
-
this.transport.post(
|
|
229
|
-
`${this.intentPath(intentId)}/${PURCHASE_INTENT_ROUTE.CONFIRM}`,
|
|
230
|
-
request,
|
|
231
|
-
{
|
|
232
|
-
idempotencyKey: request.idempotency_key,
|
|
233
|
-
signal: options?.signal,
|
|
234
|
-
timeoutMs: options?.timeoutMs
|
|
235
|
-
}
|
|
236
|
-
)
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
submitAction(intentId, attemptId, request, options) {
|
|
240
|
-
const normalizedAttemptId = attemptId.trim();
|
|
241
|
-
if (!normalizedAttemptId) throw new TypeError("attemptId must not be empty");
|
|
242
|
-
return chunkF7J3HK27_js.safe(
|
|
243
|
-
this.transport.post(
|
|
244
|
-
`${this.intentPath(intentId)}/${PURCHASE_INTENT_ROUTE.ATTEMPTS}/${encodeURIComponent(normalizedAttemptId)}/${PURCHASE_INTENT_ROUTE.ACTIONS}`,
|
|
245
|
-
request,
|
|
246
|
-
{
|
|
247
|
-
signal: options?.signal,
|
|
248
|
-
timeoutMs: options?.timeoutMs
|
|
249
|
-
}
|
|
250
|
-
)
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
resolve(intentId, options) {
|
|
254
|
-
return this.resolver.resolve(intentId, options);
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Bind subsequent preparation/confirmation to one hosted checkout-session
|
|
258
|
-
* owner. The session ID is a route authority, not an intent-owner rewrite.
|
|
259
|
-
*/
|
|
260
|
-
forHostedSession(sessionId) {
|
|
261
|
-
return new HostedPurchaseIntentService(this.transport, sessionId);
|
|
262
|
-
}
|
|
263
|
-
intentPath(intentId) {
|
|
264
|
-
return directIntentPath(intentId);
|
|
265
|
-
}
|
|
266
|
-
};
|
|
267
|
-
var HostedPurchaseIntentService = class {
|
|
268
|
-
constructor(transport, sessionId) {
|
|
269
|
-
this.transport = transport;
|
|
270
|
-
this.sessionPath = hostedSessionPath(sessionId);
|
|
271
|
-
this.resolver = new PurchaseIntentResolver({ confirmation: this });
|
|
272
|
-
}
|
|
273
|
-
prepare(request, options) {
|
|
274
|
-
return chunkF7J3HK27_js.safe(
|
|
275
|
-
this.transport.post(
|
|
276
|
-
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.PREPARE}`,
|
|
277
|
-
request,
|
|
278
|
-
{
|
|
279
|
-
idempotencyKey: request.idempotency_key,
|
|
280
|
-
signal: options?.signal,
|
|
281
|
-
timeoutMs: options?.timeoutMs
|
|
282
|
-
}
|
|
283
|
-
)
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
confirm(_intentId, request, options) {
|
|
287
|
-
return chunkF7J3HK27_js.safe(
|
|
288
|
-
this.transport.post(
|
|
289
|
-
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.CONFIRM}`,
|
|
290
|
-
request,
|
|
291
|
-
{
|
|
292
|
-
idempotencyKey: request.idempotency_key,
|
|
293
|
-
signal: options?.signal,
|
|
294
|
-
timeoutMs: options?.timeoutMs
|
|
295
|
-
}
|
|
296
|
-
)
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
replay(options) {
|
|
300
|
-
return chunkF7J3HK27_js.safe(
|
|
301
|
-
this.transport.get(
|
|
302
|
-
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.REPLAY}`,
|
|
303
|
-
{
|
|
304
|
-
signal: options?.signal,
|
|
305
|
-
timeoutMs: options?.timeoutMs
|
|
306
|
-
}
|
|
307
|
-
)
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
submitAction(_intentId, attemptId, request, options) {
|
|
311
|
-
const normalized = attemptId.trim();
|
|
312
|
-
if (!normalized) throw new TypeError("attemptId must not be empty");
|
|
313
|
-
return chunkF7J3HK27_js.safe(
|
|
314
|
-
this.transport.post(
|
|
315
|
-
`${this.sessionPath}/${PURCHASE_INTENT_ROUTE.ATTEMPTS}/${encodeURIComponent(normalized)}/${PURCHASE_INTENT_ROUTE.ACTIONS}`,
|
|
316
|
-
request,
|
|
317
|
-
{
|
|
318
|
-
signal: options?.signal,
|
|
319
|
-
timeoutMs: options?.timeoutMs
|
|
320
|
-
}
|
|
321
|
-
)
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
resolve(intentId, options) {
|
|
325
|
-
return this.resolver.resolve(intentId, options);
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
// src/store-credit.ts
|
|
330
|
-
var StoreCreditQueries = class {
|
|
331
|
-
constructor(client) {
|
|
332
|
-
this.client = client;
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* The shopper's available store-credit balance, in the business's default
|
|
336
|
-
* currency. Requires a signed-in customer; returns an error otherwise.
|
|
337
|
-
*/
|
|
338
|
-
async balance() {
|
|
339
|
-
return chunkF7J3HK27_js.safe(this.client.get("/api/v1/store-credit/balance"));
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
// src/internal/analytics-session.ts
|
|
344
|
-
var ANALYTICS_SESSION_IDLE_TIMEOUT_MS = 30 * 60 * 1e3;
|
|
345
|
-
var ANALYTICS_SESSION_STORAGE_KEY_PREFIX = "cimplify_analytics_session:v2:";
|
|
346
|
-
var ANALYTICS_SESSION_STATE_VERSION = 2;
|
|
347
|
-
var MICROSECONDS_PER_MILLISECOND = 1e3;
|
|
348
|
-
var MICROSECONDS_PER_SECOND = 1e6;
|
|
349
|
-
var AnalyticsSessionCoordinator = class {
|
|
350
|
-
constructor(identity) {
|
|
351
|
-
this.identity = identity;
|
|
352
|
-
this.fallbackState = null;
|
|
353
|
-
}
|
|
354
|
-
beginEvent(nowMs = Date.now()) {
|
|
355
|
-
const state = this.resolveActiveState(nowMs);
|
|
356
|
-
state.lastActivityAtMs = nowMs;
|
|
357
|
-
const occurredAt = reserveOccurredAt(state, nowMs, 1);
|
|
358
|
-
this.write(state);
|
|
359
|
-
return toEventContext(state, occurredAt);
|
|
360
|
-
}
|
|
361
|
-
beginPage(path, nowMs = Date.now()) {
|
|
362
|
-
const existing = this.read();
|
|
363
|
-
const expired = !existing || isExpired(existing, nowMs);
|
|
364
|
-
const state = expired ? newSession(nowMs) : existing;
|
|
365
|
-
const previousPage = expired ? void 0 : durationFor(state.activePage, nowMs);
|
|
366
|
-
state.lastActivityAtMs = nowMs;
|
|
367
|
-
state.activePage = { path, enteredAtMs: nowMs };
|
|
368
|
-
const occurredAt = reserveOccurredAt(state, nowMs, previousPage ? 2 : 1);
|
|
369
|
-
this.write(state);
|
|
370
|
-
return {
|
|
371
|
-
session: toEventContext(state, occurredAt),
|
|
372
|
-
previousPage
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
current() {
|
|
376
|
-
const state = this.read();
|
|
377
|
-
if (!state || isExpired(state, Date.now())) return null;
|
|
378
|
-
return toContext(state);
|
|
379
|
-
}
|
|
380
|
-
markBootstrapped(sessionId) {
|
|
381
|
-
const state = this.read();
|
|
382
|
-
if (!state || state.id !== sessionId) return;
|
|
383
|
-
state.bootstrapped = true;
|
|
384
|
-
this.write(state);
|
|
385
|
-
}
|
|
386
|
-
reset() {
|
|
387
|
-
this.fallbackState = null;
|
|
388
|
-
try {
|
|
389
|
-
sessionStorage.removeItem(this.storageKey());
|
|
390
|
-
} catch {
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
resolveActiveState(nowMs) {
|
|
394
|
-
const state = this.read();
|
|
395
|
-
return !state || isExpired(state, nowMs) ? newSession(nowMs) : state;
|
|
396
|
-
}
|
|
397
|
-
read() {
|
|
398
|
-
try {
|
|
399
|
-
const serialized = sessionStorage.getItem(this.storageKey());
|
|
400
|
-
if (!serialized) return this.fallbackState;
|
|
401
|
-
const state = JSON.parse(serialized);
|
|
402
|
-
if (!isPersistedSession(state)) {
|
|
403
|
-
sessionStorage.removeItem(this.storageKey());
|
|
404
|
-
return this.fallbackState;
|
|
405
|
-
}
|
|
406
|
-
this.fallbackState = state;
|
|
407
|
-
return state;
|
|
408
|
-
} catch {
|
|
409
|
-
return this.fallbackState;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
write(state) {
|
|
413
|
-
this.fallbackState = state;
|
|
414
|
-
try {
|
|
415
|
-
sessionStorage.setItem(this.storageKey(), JSON.stringify(state));
|
|
416
|
-
} catch {
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
storageKey() {
|
|
420
|
-
return `${ANALYTICS_SESSION_STORAGE_KEY_PREFIX}${encodeURIComponent(this.identity)}`;
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
function newSession(nowMs) {
|
|
424
|
-
return {
|
|
425
|
-
version: ANALYTICS_SESSION_STATE_VERSION,
|
|
426
|
-
id: generateSessionId(),
|
|
427
|
-
startedAtMs: nowMs,
|
|
428
|
-
lastActivityAtMs: nowMs,
|
|
429
|
-
bootstrapped: false
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
function toContext(state) {
|
|
433
|
-
return {
|
|
434
|
-
id: state.id,
|
|
435
|
-
startedAt: new Date(state.startedAtMs).toISOString(),
|
|
436
|
-
requiresBootstrap: !state.bootstrapped
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
function toEventContext(state, occurredAtMicros) {
|
|
440
|
-
return {
|
|
441
|
-
...toContext(state),
|
|
442
|
-
occurredAt: formatEpochMicros(occurredAtMicros)
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
function reserveOccurredAt(state, nowMs, eventCount) {
|
|
446
|
-
const wallClockMicros = Math.trunc(nowMs) * MICROSECONDS_PER_MILLISECOND;
|
|
447
|
-
const occurredAtMicros = Math.max(
|
|
448
|
-
wallClockMicros,
|
|
449
|
-
(state.lastOccurredAtMicros ?? wallClockMicros - 1) + 1
|
|
450
|
-
);
|
|
451
|
-
state.lastOccurredAtMicros = occurredAtMicros + eventCount - 1;
|
|
452
|
-
return occurredAtMicros;
|
|
453
|
-
}
|
|
454
|
-
function formatEpochMicros(epochMicros) {
|
|
455
|
-
const epochMillis = Math.floor(epochMicros / MICROSECONDS_PER_MILLISECOND);
|
|
456
|
-
const microsWithinSecond = epochMicros % MICROSECONDS_PER_SECOND;
|
|
457
|
-
const millisecondIso = new Date(epochMillis).toISOString();
|
|
458
|
-
return `${millisecondIso.slice(0, -5)}.${String(microsWithinSecond).padStart(6, "0")}Z`;
|
|
459
|
-
}
|
|
460
|
-
function durationFor(activePage, nowMs) {
|
|
461
|
-
if (!activePage || nowMs < activePage.enteredAtMs) return void 0;
|
|
462
|
-
return {
|
|
463
|
-
path: activePage.path,
|
|
464
|
-
timeOnPageSeconds: Math.floor((nowMs - activePage.enteredAtMs) / 1e3)
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
function isExpired(state, nowMs) {
|
|
468
|
-
return nowMs - state.lastActivityAtMs >= ANALYTICS_SESSION_IDLE_TIMEOUT_MS;
|
|
469
|
-
}
|
|
470
|
-
function isPersistedSession(value) {
|
|
471
|
-
if (!value || typeof value !== "object") return false;
|
|
472
|
-
const state = value;
|
|
473
|
-
return state.version === ANALYTICS_SESSION_STATE_VERSION && typeof state.id === "string" && state.id.length > 0 && typeof state.startedAtMs === "number" && Number.isFinite(state.startedAtMs) && typeof state.lastActivityAtMs === "number" && Number.isFinite(state.lastActivityAtMs) && (state.lastOccurredAtMicros === void 0 || typeof state.lastOccurredAtMicros === "number" && Number.isSafeInteger(state.lastOccurredAtMicros)) && typeof state.bootstrapped === "boolean" && (!state.activePage || typeof state.activePage.path === "string" && typeof state.activePage.enteredAtMs === "number" && Number.isFinite(state.activePage.enteredAtMs));
|
|
474
|
-
}
|
|
475
|
-
function generateSessionId() {
|
|
476
|
-
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
477
|
-
return crypto.randomUUID();
|
|
478
|
-
}
|
|
479
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (character) => {
|
|
480
|
-
const random = Math.random() * 16 | 0;
|
|
481
|
-
const value = character === "x" ? random : random & 3 | 8;
|
|
482
|
-
return value.toString(16);
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
// src/activity.ts
|
|
487
|
-
var VISITOR_ID_STORAGE_KEY = "cimplify_visitor_id";
|
|
488
|
-
var ACTIVITY_RETRY_POLICY = {
|
|
489
|
-
maxRetries: 1,
|
|
490
|
-
jitterRatio: 0.2
|
|
491
|
-
};
|
|
492
|
-
var PAGE_VIEW_TRACKER_KEY = /* @__PURE__ */ Symbol.for("@cimplify/sdk.page-view-tracker-hub");
|
|
493
|
-
var PAGE_VIEW_TRACKER_VERSION = 2;
|
|
494
|
-
function trackerHost() {
|
|
495
|
-
return window;
|
|
496
|
-
}
|
|
497
|
-
function currentWindowTrackerHub() {
|
|
498
|
-
const candidate = trackerHost()[PAGE_VIEW_TRACKER_KEY];
|
|
499
|
-
return candidate?.version === PAGE_VIEW_TRACKER_VERSION && candidate.registrations instanceof Map && typeof candidate.recordAll === "function" ? candidate : null;
|
|
500
|
-
}
|
|
501
|
-
function weakReference(target) {
|
|
502
|
-
const WeakReference = globalThis.WeakRef;
|
|
503
|
-
if (WeakReference) return new WeakReference(target);
|
|
504
|
-
return { deref: () => target };
|
|
505
|
-
}
|
|
506
|
-
function latestLiveOwner(registration) {
|
|
507
|
-
let latest = null;
|
|
508
|
-
for (const [token, reference] of registration.owners) {
|
|
509
|
-
const owner = reference.deref();
|
|
510
|
-
if (!owner || owner.released) {
|
|
511
|
-
registration.owners.delete(token);
|
|
512
|
-
} else {
|
|
513
|
-
latest = owner;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return latest;
|
|
517
|
-
}
|
|
518
|
-
function recordRegistration(registration, path) {
|
|
519
|
-
if (path === registration.lastPath) return;
|
|
520
|
-
const owner = registration.activeOwner && !registration.activeOwner.released ? registration.activeOwner : latestLiveOwner(registration);
|
|
521
|
-
if (!owner) return;
|
|
522
|
-
registration.activeOwner = owner;
|
|
523
|
-
registration.lastPath = path;
|
|
524
|
-
owner.recorder(path);
|
|
525
|
-
}
|
|
526
|
-
function createWindowTrackerHub() {
|
|
527
|
-
const originalPushState = window.history.pushState;
|
|
528
|
-
const originalReplaceState = window.history.replaceState;
|
|
529
|
-
const hub = {
|
|
530
|
-
version: PAGE_VIEW_TRACKER_VERSION,
|
|
531
|
-
registrations: /* @__PURE__ */ new Map(),
|
|
532
|
-
originalPushState,
|
|
533
|
-
originalReplaceState
|
|
534
|
-
};
|
|
535
|
-
hub.recordAll = () => {
|
|
536
|
-
const path = window.location.pathname;
|
|
537
|
-
for (const registration of hub.registrations.values()) {
|
|
538
|
-
recordRegistration(registration, path);
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
hub.patchedPushState = function(...args) {
|
|
542
|
-
originalPushState.apply(this, args);
|
|
543
|
-
hub.recordAll();
|
|
544
|
-
};
|
|
545
|
-
hub.patchedReplaceState = function(...args) {
|
|
546
|
-
originalReplaceState.apply(this, args);
|
|
547
|
-
hub.recordAll();
|
|
548
|
-
};
|
|
549
|
-
hub.popstateListener = () => hub.recordAll();
|
|
550
|
-
window.history.pushState = hub.patchedPushState;
|
|
551
|
-
window.history.replaceState = hub.patchedReplaceState;
|
|
552
|
-
window.addEventListener("popstate", hub.popstateListener);
|
|
553
|
-
trackerHost()[PAGE_VIEW_TRACKER_KEY] = hub;
|
|
554
|
-
return hub;
|
|
555
|
-
}
|
|
556
|
-
function pageViewTrackerIdentity(client) {
|
|
557
|
-
return JSON.stringify([client.getBaseUrl(), client.getPublicKey().trim()]);
|
|
558
|
-
}
|
|
559
|
-
function acquireWindowPageViewTracker(identity, recorder) {
|
|
560
|
-
const hub = currentWindowTrackerHub() ?? createWindowTrackerHub();
|
|
561
|
-
let registration = hub.registrations.get(identity);
|
|
562
|
-
const isNewIdentity = !registration;
|
|
563
|
-
if (!registration) {
|
|
564
|
-
registration = { owners: /* @__PURE__ */ new Map(), activeOwner: null, lastPath: null };
|
|
565
|
-
hub.registrations.set(identity, registration);
|
|
566
|
-
}
|
|
567
|
-
const owner = {
|
|
568
|
-
token: Symbol(identity),
|
|
569
|
-
recorder,
|
|
570
|
-
released: false
|
|
571
|
-
};
|
|
572
|
-
registration.owners.set(owner.token, weakReference(owner));
|
|
573
|
-
registration.activeOwner = owner;
|
|
574
|
-
if (isNewIdentity) {
|
|
575
|
-
recordRegistration(registration, window.location.pathname);
|
|
576
|
-
}
|
|
577
|
-
let released = false;
|
|
578
|
-
return () => {
|
|
579
|
-
if (released) return;
|
|
580
|
-
released = true;
|
|
581
|
-
owner.released = true;
|
|
582
|
-
registration.owners.delete(owner.token);
|
|
583
|
-
if (registration.activeOwner === owner) {
|
|
584
|
-
registration.activeOwner = latestLiveOwner(registration);
|
|
585
|
-
}
|
|
586
|
-
if (registration.activeOwner) return;
|
|
587
|
-
if (hub.registrations.get(identity) === registration) {
|
|
588
|
-
hub.registrations.delete(identity);
|
|
589
|
-
}
|
|
590
|
-
if (hub.registrations.size !== 0) return;
|
|
591
|
-
window.removeEventListener("popstate", hub.popstateListener);
|
|
592
|
-
if (window.history.pushState === hub.patchedPushState) {
|
|
593
|
-
window.history.pushState = hub.originalPushState;
|
|
594
|
-
}
|
|
595
|
-
if (window.history.replaceState === hub.patchedReplaceState) {
|
|
596
|
-
window.history.replaceState = hub.originalReplaceState;
|
|
597
|
-
}
|
|
598
|
-
if (currentWindowTrackerHub() === hub) {
|
|
599
|
-
delete trackerHost()[PAGE_VIEW_TRACKER_KEY];
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
var ActivityService = class {
|
|
604
|
-
constructor(client) {
|
|
605
|
-
this.client = client;
|
|
606
|
-
this.localGeneration = 0;
|
|
607
|
-
this.bootstrapRequest = null;
|
|
608
|
-
this.sessions = this.createSessionCoordinator();
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Record session start (landing, referrer, UTM, device). Fire-and-forget,
|
|
612
|
-
* at most once per 30-minute-idle analytics session; called automatically
|
|
613
|
-
* by the track* methods.
|
|
614
|
-
*/
|
|
615
|
-
startSession() {
|
|
616
|
-
if (typeof window === "undefined") return;
|
|
617
|
-
const session = this.sessions.beginEvent();
|
|
618
|
-
void this.bootstrapSession(session, false, this.captureGeneration()).catch(() => {
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
/** Rebind an existing analytics session after the server authenticates a customer. */
|
|
622
|
-
refreshIdentity() {
|
|
623
|
-
if (typeof window === "undefined") return;
|
|
624
|
-
const session = this.sessions.current();
|
|
625
|
-
if (!session) return;
|
|
626
|
-
void this.bootstrapSession(session, true, this.captureGeneration()).catch(() => {
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
/** A signed-out browser starts a fresh anonymous analytics session. */
|
|
630
|
-
resetSession() {
|
|
631
|
-
this.invalidatePendingActivity();
|
|
632
|
-
this.sessions.reset();
|
|
633
|
-
}
|
|
634
|
-
/** Drop the old storefront's analytics state before binding this service to the new one. */
|
|
635
|
-
resetForStorefrontIdentityChange() {
|
|
636
|
-
this.invalidatePendingActivity();
|
|
637
|
-
this.sessions.reset();
|
|
638
|
-
this.sessions = this.createSessionCoordinator();
|
|
639
|
-
}
|
|
640
|
-
buildSessionPayload(session) {
|
|
641
|
-
const params = new URLSearchParams(window.location.search);
|
|
642
|
-
const utm = (key) => params.get(`utm_${key}`) || void 0;
|
|
643
|
-
const { visitorId, isNewVisitor } = resolveVisitor();
|
|
644
|
-
let timezone;
|
|
645
|
-
try {
|
|
646
|
-
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
647
|
-
} catch {
|
|
648
|
-
}
|
|
649
|
-
return {
|
|
650
|
-
analytics_session_id: session.id,
|
|
651
|
-
started_at: session.startedAt,
|
|
652
|
-
landing_page: window.location.pathname,
|
|
653
|
-
landing_url: window.location.href,
|
|
654
|
-
referrer_url: document.referrer || void 0,
|
|
655
|
-
utm_source: utm("source"),
|
|
656
|
-
utm_medium: utm("medium"),
|
|
657
|
-
utm_campaign: utm("campaign"),
|
|
658
|
-
utm_term: utm("term"),
|
|
659
|
-
utm_content: utm("content"),
|
|
660
|
-
social_commerce_ref: params.get("social_commerce_ref") || void 0,
|
|
661
|
-
screen_width: window.screen?.width,
|
|
662
|
-
screen_height: window.screen?.height,
|
|
663
|
-
viewport_width: window.innerWidth,
|
|
664
|
-
viewport_height: window.innerHeight,
|
|
665
|
-
pixel_density: window.devicePixelRatio,
|
|
666
|
-
language: navigator.language,
|
|
667
|
-
timezone,
|
|
668
|
-
fingerprint: visitorId,
|
|
669
|
-
is_new_visitor: isNewVisitor
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
/** Route-level page view. Product/category interactions are tracked separately. */
|
|
673
|
-
trackPageView(options = {}) {
|
|
674
|
-
if (typeof window === "undefined") return;
|
|
675
|
-
const pagePath = options.pagePath ?? currentPath() ?? "";
|
|
676
|
-
const transition = this.sessions.beginPage(pagePath);
|
|
677
|
-
const events = [];
|
|
678
|
-
if (transition.previousPage) {
|
|
679
|
-
events.push({
|
|
680
|
-
type: "page_duration",
|
|
681
|
-
page_path: transition.previousPage.path,
|
|
682
|
-
time_on_page: transition.previousPage.timeOnPageSeconds
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
events.push({
|
|
686
|
-
type: "page_view",
|
|
687
|
-
page_path: pagePath,
|
|
688
|
-
page_title: options.pageTitle ?? currentTitle()
|
|
689
|
-
});
|
|
690
|
-
this.sendEvents(events, transition.session);
|
|
691
|
-
}
|
|
692
|
-
trackProductView(productId, options = {}) {
|
|
693
|
-
if (typeof window === "undefined") return;
|
|
694
|
-
const event = {
|
|
695
|
-
type: "product_view",
|
|
696
|
-
product_id: productId,
|
|
697
|
-
product_name: options.productName,
|
|
698
|
-
category_id: options.categoryId,
|
|
699
|
-
price: options.price,
|
|
700
|
-
page_path: options.pagePath ?? currentPath()
|
|
701
|
-
};
|
|
702
|
-
this.sendEvents([event]);
|
|
703
|
-
}
|
|
704
|
-
trackCategoryView(categoryId, options = {}) {
|
|
705
|
-
if (typeof window === "undefined") return;
|
|
706
|
-
const event = {
|
|
707
|
-
type: "category_view",
|
|
708
|
-
category_id: categoryId,
|
|
709
|
-
category_name: options.categoryName,
|
|
710
|
-
page_path: options.pagePath ?? currentPath()
|
|
711
|
-
};
|
|
712
|
-
this.sendEvents([event]);
|
|
713
|
-
}
|
|
714
|
-
async getState() {
|
|
715
|
-
return chunkF7J3HK27_js.safe(this.client.get("/api/v1/activity/state"));
|
|
716
|
-
}
|
|
717
|
-
async getRecommendations(options) {
|
|
718
|
-
const params = new URLSearchParams();
|
|
719
|
-
if (options?.location_id) params.set("location_id", options.location_id);
|
|
720
|
-
if (options?.limit) params.set("limit", String(options.limit));
|
|
721
|
-
const query = params.toString();
|
|
722
|
-
const path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
|
|
723
|
-
return chunkF7J3HK27_js.safe(this.client.get(path));
|
|
724
|
-
}
|
|
725
|
-
async dismissMessage(code) {
|
|
726
|
-
return chunkF7J3HK27_js.safe(
|
|
727
|
-
this.client.post("/api/v1/activity/messages/dismiss", { code })
|
|
728
|
-
);
|
|
729
|
-
}
|
|
730
|
-
/** Records a page view now and on every route change; returns a stop fn. */
|
|
731
|
-
autoTrackPageViews() {
|
|
732
|
-
if (typeof window === "undefined") return () => {
|
|
733
|
-
};
|
|
734
|
-
return acquireWindowPageViewTracker(pageViewTrackerIdentity(this.client), (path) => {
|
|
735
|
-
try {
|
|
736
|
-
this.trackPageView({ pagePath: path });
|
|
737
|
-
} catch {
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
sendEvents(events, session) {
|
|
742
|
-
if (typeof window === "undefined") return;
|
|
743
|
-
void this.postEvents(events, session ?? this.sessions.beginEvent()).catch(() => {
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
hasStorefrontIdentity() {
|
|
747
|
-
return this.client.getPublicKey().trim().length > 0;
|
|
748
|
-
}
|
|
749
|
-
async postEvents(events, session) {
|
|
750
|
-
if (!this.hasStorefrontIdentity()) return;
|
|
751
|
-
const generation = this.captureGeneration();
|
|
752
|
-
await this.bootstrapSession(session, false, generation);
|
|
753
|
-
if (!this.isCurrentGeneration(generation)) return;
|
|
754
|
-
await this.client.post(
|
|
755
|
-
"/api/v1/activity/events",
|
|
756
|
-
{
|
|
757
|
-
analytics_session_id: session.id,
|
|
758
|
-
occurred_at: session.occurredAt,
|
|
759
|
-
events
|
|
760
|
-
},
|
|
761
|
-
{ retryPolicy: ACTIVITY_RETRY_POLICY }
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
bootstrapSession(session, force = false, generation = this.captureGeneration()) {
|
|
765
|
-
if (!this.hasStorefrontIdentity()) return Promise.resolve();
|
|
766
|
-
if (!force && !session.requiresBootstrap) return Promise.resolve();
|
|
767
|
-
if (!force && this.bootstrapRequest?.sessionId === session.id && sameActivityGeneration(this.bootstrapRequest.generation, generation)) {
|
|
768
|
-
return this.bootstrapRequest.promise;
|
|
769
|
-
}
|
|
770
|
-
const promise = this.client.post("/api/v1/activity/session", this.buildSessionPayload(session), {
|
|
771
|
-
retryPolicy: ACTIVITY_RETRY_POLICY
|
|
772
|
-
}).then(() => {
|
|
773
|
-
if (this.isCurrentGeneration(generation)) {
|
|
774
|
-
this.sessions.markBootstrapped(session.id);
|
|
775
|
-
}
|
|
776
|
-
}).finally(() => {
|
|
777
|
-
if (this.bootstrapRequest?.promise === promise) {
|
|
778
|
-
this.bootstrapRequest = null;
|
|
779
|
-
}
|
|
780
|
-
});
|
|
781
|
-
this.bootstrapRequest = { sessionId: session.id, generation, promise };
|
|
782
|
-
return promise;
|
|
783
|
-
}
|
|
784
|
-
captureGeneration() {
|
|
785
|
-
return {
|
|
786
|
-
local: this.localGeneration,
|
|
787
|
-
publicKey: this.client.getPublicKeyEpoch(),
|
|
788
|
-
session: this.client.getSessionEpoch()
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
isCurrentGeneration(generation) {
|
|
792
|
-
return sameActivityGeneration(generation, this.captureGeneration());
|
|
793
|
-
}
|
|
794
|
-
invalidatePendingActivity() {
|
|
795
|
-
this.localGeneration += 1;
|
|
796
|
-
this.bootstrapRequest = null;
|
|
797
|
-
}
|
|
798
|
-
createSessionCoordinator() {
|
|
799
|
-
return new AnalyticsSessionCoordinator(pageViewTrackerIdentity(this.client));
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
function sameActivityGeneration(left, right) {
|
|
803
|
-
return left.local === right.local && left.publicKey === right.publicKey && left.session === right.session;
|
|
804
|
-
}
|
|
805
|
-
function currentPath() {
|
|
806
|
-
if (typeof window !== "undefined") {
|
|
807
|
-
return window.location.pathname;
|
|
808
|
-
}
|
|
809
|
-
return void 0;
|
|
810
|
-
}
|
|
811
|
-
function currentTitle() {
|
|
812
|
-
if (typeof document !== "undefined" && document.title) {
|
|
813
|
-
return document.title;
|
|
814
|
-
}
|
|
815
|
-
return void 0;
|
|
816
|
-
}
|
|
817
|
-
function resolveVisitor() {
|
|
818
|
-
try {
|
|
819
|
-
const existing = localStorage.getItem(VISITOR_ID_STORAGE_KEY);
|
|
820
|
-
if (existing) {
|
|
821
|
-
return { visitorId: existing, isNewVisitor: false };
|
|
822
|
-
}
|
|
823
|
-
const visitorId = typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `v_${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
824
|
-
localStorage.setItem(VISITOR_ID_STORAGE_KEY, visitorId);
|
|
825
|
-
return { visitorId, isNewVisitor: true };
|
|
826
|
-
} catch {
|
|
827
|
-
return {};
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
// src/subscriptions.ts
|
|
832
|
-
var SubscriptionService = class {
|
|
833
|
-
constructor(client) {
|
|
834
|
-
this.client = client;
|
|
835
|
-
}
|
|
836
|
-
async list() {
|
|
837
|
-
return chunkF7J3HK27_js.safe(this.client.get("/api/v1/subscriptions"));
|
|
838
|
-
}
|
|
839
|
-
async get(id) {
|
|
840
|
-
const encodedId = encodeURIComponent(id);
|
|
841
|
-
return chunkF7J3HK27_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
|
|
842
|
-
}
|
|
843
|
-
async cancel(id, reason, opts) {
|
|
844
|
-
const encodedId = encodeURIComponent(id);
|
|
845
|
-
const idempotencyKey = opts?.idempotencyKey ?? chunkF7J3HK27_js.generateIdempotencyKey();
|
|
846
|
-
return chunkF7J3HK27_js.safe(
|
|
847
|
-
this.client.post(
|
|
848
|
-
`/api/v1/subscriptions/${encodedId}/cancel`,
|
|
849
|
-
{ reason },
|
|
850
|
-
{ idempotencyKey }
|
|
851
|
-
)
|
|
852
|
-
);
|
|
853
|
-
}
|
|
854
|
-
async pause(id) {
|
|
855
|
-
const encodedId = encodeURIComponent(id);
|
|
856
|
-
return chunkF7J3HK27_js.safe(
|
|
857
|
-
this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
|
|
858
|
-
);
|
|
859
|
-
}
|
|
860
|
-
async resume(id) {
|
|
861
|
-
const encodedId = encodeURIComponent(id);
|
|
862
|
-
return chunkF7J3HK27_js.safe(
|
|
863
|
-
this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
|
|
864
|
-
);
|
|
865
|
-
}
|
|
866
|
-
async skipNextRenewal(id, opts) {
|
|
867
|
-
const encodedId = encodeURIComponent(id);
|
|
868
|
-
const idempotencyKey = opts?.idempotencyKey ?? chunkF7J3HK27_js.generateIdempotencyKey();
|
|
869
|
-
return chunkF7J3HK27_js.safe(
|
|
870
|
-
this.client.post(
|
|
871
|
-
`/api/v1/subscriptions/${encodedId}/skip`,
|
|
872
|
-
void 0,
|
|
873
|
-
{ idempotencyKey }
|
|
874
|
-
)
|
|
875
|
-
);
|
|
876
|
-
}
|
|
877
|
-
};
|
|
878
|
-
|
|
879
|
-
// src/uploads.ts
|
|
880
|
-
var UploadService = class {
|
|
881
|
-
constructor(client) {
|
|
882
|
-
this.client = client;
|
|
883
|
-
}
|
|
884
|
-
async init(filename, contentType2, sizeBytes, opts) {
|
|
885
|
-
const idempotencyKey = opts?.idempotencyKey ?? chunkF7J3HK27_js.generateIdempotencyKey();
|
|
886
|
-
return chunkF7J3HK27_js.safe(
|
|
887
|
-
this.client.post(
|
|
888
|
-
"/api/v1/uploads/init",
|
|
889
|
-
{
|
|
890
|
-
filename,
|
|
891
|
-
content_type: contentType2,
|
|
892
|
-
size_bytes: sizeBytes
|
|
893
|
-
},
|
|
894
|
-
{ idempotencyKey }
|
|
895
|
-
)
|
|
896
|
-
);
|
|
897
|
-
}
|
|
898
|
-
async confirm(uploadId) {
|
|
899
|
-
return chunkF7J3HK27_js.safe(
|
|
900
|
-
this.client.post("/api/v1/uploads/confirm", {
|
|
901
|
-
upload_id: uploadId
|
|
902
|
-
})
|
|
903
|
-
);
|
|
904
|
-
}
|
|
905
|
-
async upload(file) {
|
|
906
|
-
const initResult = await this.init(file.name, file.type, file.size);
|
|
907
|
-
if (!initResult.ok) return initResult;
|
|
908
|
-
const { upload_id, upload_url } = initResult.value;
|
|
909
|
-
try {
|
|
910
|
-
const uploadResponse = await fetch(upload_url, {
|
|
911
|
-
method: "PUT",
|
|
912
|
-
body: file,
|
|
913
|
-
headers: { "Content-Type": file.type }
|
|
914
|
-
});
|
|
915
|
-
if (!uploadResponse.ok) {
|
|
916
|
-
return {
|
|
917
|
-
ok: false,
|
|
918
|
-
error: new chunkANT574FD_js.CimplifyError(
|
|
919
|
-
"UPLOAD_FAILED",
|
|
920
|
-
`Upload failed with status ${uploadResponse.status}`,
|
|
921
|
-
true
|
|
922
|
-
)
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
} catch (error) {
|
|
926
|
-
return {
|
|
927
|
-
ok: false,
|
|
928
|
-
error: new chunkANT574FD_js.CimplifyError(
|
|
929
|
-
"UPLOAD_FAILED",
|
|
930
|
-
error instanceof Error ? error.message : "Upload failed",
|
|
931
|
-
true
|
|
932
|
-
)
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
return this.confirm(upload_id);
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
|
|
939
|
-
// src/places.ts
|
|
940
|
-
var PlacesService = class {
|
|
941
|
-
constructor(client) {
|
|
942
|
-
this.client = client;
|
|
943
|
-
}
|
|
944
|
-
async autocomplete(input, sessionToken) {
|
|
945
|
-
return chunkF7J3HK27_js.safe(
|
|
946
|
-
this.client.post("/api/v1/places/autocomplete", {
|
|
947
|
-
input,
|
|
948
|
-
sessionToken
|
|
949
|
-
})
|
|
950
|
-
);
|
|
951
|
-
}
|
|
952
|
-
async details(placeId, sessionToken) {
|
|
953
|
-
return chunkF7J3HK27_js.safe(
|
|
954
|
-
this.client.post("/api/v1/places/details", {
|
|
955
|
-
place_id: placeId,
|
|
956
|
-
sessionToken
|
|
957
|
-
})
|
|
958
|
-
);
|
|
959
|
-
}
|
|
960
|
-
};
|
|
961
|
-
|
|
962
|
-
// src/delivery.ts
|
|
963
|
-
var DeliveryService = class {
|
|
964
|
-
constructor(client) {
|
|
965
|
-
this.client = client;
|
|
966
|
-
}
|
|
967
|
-
async getFee(dropoffLat, dropoffLng, country) {
|
|
968
|
-
const params = new URLSearchParams();
|
|
969
|
-
params.set("dropoff_lat", String(dropoffLat));
|
|
970
|
-
params.set("dropoff_lng", String(dropoffLng));
|
|
971
|
-
if (country) params.set("country", country);
|
|
972
|
-
return chunkF7J3HK27_js.safe(this.client.get(`/api/v1/delivery/fee?${params.toString()}`));
|
|
973
|
-
}
|
|
974
|
-
async getOptions(queryOrLatitude, longitude, legacyOptions) {
|
|
975
|
-
const query = typeof queryOrLatitude === "number" ? {
|
|
976
|
-
...legacyOptions,
|
|
977
|
-
dropoffLat: queryOrLatitude,
|
|
978
|
-
dropoffLng: longitude
|
|
979
|
-
} : queryOrLatitude ?? {};
|
|
980
|
-
const params = new URLSearchParams();
|
|
981
|
-
if (query.dropoffLat != null) params.set("dropoff_lat", String(query.dropoffLat));
|
|
982
|
-
if (query.dropoffLng != null) params.set("dropoff_lng", String(query.dropoffLng));
|
|
983
|
-
if (query.country) params.set("country", query.country);
|
|
984
|
-
if (query.currency) params.set("currency", query.currency);
|
|
985
|
-
if (query.orderValue != null) params.set("order_value", String(query.orderValue));
|
|
986
|
-
return chunkF7J3HK27_js.safe(
|
|
987
|
-
this.client.get(`/api/v1/delivery/options?${params.toString()}`)
|
|
988
|
-
);
|
|
989
|
-
}
|
|
990
|
-
};
|
|
991
|
-
|
|
992
|
-
// src/chat-wire.ts
|
|
993
|
-
function senderType(message) {
|
|
994
|
-
if (message.sender_side === "account") return "customer";
|
|
995
|
-
if (message.sender_side === "system") return "system";
|
|
996
|
-
return message.authorship === "ai" ? "bot" : "agent";
|
|
997
|
-
}
|
|
998
|
-
function contentType(message) {
|
|
999
|
-
if (message.content_type === "rich") {
|
|
1000
|
-
return message.structured_content?.["kind"] === "reaction" ? "reaction" : "interactive";
|
|
1001
|
-
}
|
|
1002
|
-
if (message.content_type === "media") {
|
|
1003
|
-
const mime = message.media[0]?.mime_type ?? "";
|
|
1004
|
-
if (mime.startsWith("image/")) return "image";
|
|
1005
|
-
if (mime.startsWith("video/")) return "video";
|
|
1006
|
-
if (mime.startsWith("audio/")) return "audio";
|
|
1007
|
-
return "document";
|
|
1008
|
-
}
|
|
1009
|
-
return "text";
|
|
1010
|
-
}
|
|
1011
|
-
function unresolvedReply(id) {
|
|
1012
|
-
return { id, sender_type: "system", preview: "Earlier message" };
|
|
1013
|
-
}
|
|
1014
|
-
function chatMessagesFromWire(messages) {
|
|
1015
|
-
const converted = messages.map((message) => ({
|
|
1016
|
-
id: message.id,
|
|
1017
|
-
sequence: message.sequence,
|
|
1018
|
-
sender_type: senderType(message),
|
|
1019
|
-
content: message.content,
|
|
1020
|
-
content_type: contentType(message),
|
|
1021
|
-
attachments: Array.isArray(message.media) ? message.media : [],
|
|
1022
|
-
metadata: message.structured_content ?? {},
|
|
1023
|
-
reply_to: message.reply_to_message_id ? unresolvedReply(message.reply_to_message_id) : void 0,
|
|
1024
|
-
edited_at: message.edited_at,
|
|
1025
|
-
deleted_at: message.deleted_at,
|
|
1026
|
-
created_at: message.created_at
|
|
1027
|
-
}));
|
|
1028
|
-
const byId = new Map(converted.map((message) => [message.id, message]));
|
|
1029
|
-
return converted.map((message) => {
|
|
1030
|
-
const targetId = message.reply_to?.id;
|
|
1031
|
-
const target = targetId ? byId.get(targetId) : void 0;
|
|
1032
|
-
if (!targetId || !target) return message;
|
|
1033
|
-
return {
|
|
1034
|
-
...message,
|
|
1035
|
-
reply_to: {
|
|
1036
|
-
id: targetId,
|
|
1037
|
-
sender_type: target.sender_type,
|
|
1038
|
-
preview: chunkXREIZ56K_js.messagePreview(target.content)
|
|
1039
|
-
}
|
|
1040
|
-
};
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
function chatMessageFromWire(message) {
|
|
1044
|
-
return chatMessagesFromWire([message])[0];
|
|
1045
|
-
}
|
|
1046
|
-
function chatRealtimeUpdateFromWire(envelope) {
|
|
1047
|
-
if (envelope.type === "message_created" && envelope.data) {
|
|
1048
|
-
return {
|
|
1049
|
-
kind: "message",
|
|
1050
|
-
message: chatMessageFromWire(envelope.data)
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
if (envelope.type === "message_updated" && envelope.data) {
|
|
1054
|
-
return {
|
|
1055
|
-
kind: "message_updated",
|
|
1056
|
-
message: chatMessageFromWire(envelope.data)
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
if (envelope.type === "read" && envelope.data) {
|
|
1060
|
-
const read = envelope.data;
|
|
1061
|
-
if (read.reader_side === "business" && typeof read.occurred_at === "string") {
|
|
1062
|
-
return { kind: "business_read", occurredAt: read.occurred_at };
|
|
1063
|
-
}
|
|
1064
|
-
return { kind: "none" };
|
|
1065
|
-
}
|
|
1066
|
-
if (envelope.type === "history_imported") {
|
|
1067
|
-
return { kind: "reload" };
|
|
1068
|
-
}
|
|
1069
|
-
if (envelope.type === "ai_mode_changed" && envelope.data) {
|
|
1070
|
-
const mode = envelope.data.mode;
|
|
1071
|
-
if (mode === "auto" || mode === "assist" || mode === "off") {
|
|
1072
|
-
return { kind: "ai_mode", mode };
|
|
1073
|
-
}
|
|
1074
|
-
return { kind: "none" };
|
|
1075
|
-
}
|
|
1076
|
-
if (envelope.type === "handoff_requested") {
|
|
1077
|
-
return { kind: "handoff" };
|
|
1078
|
-
}
|
|
1079
|
-
if (envelope.type === "resync") {
|
|
1080
|
-
return { kind: "resync", latestSequence: envelope.latest_sequence };
|
|
1081
|
-
}
|
|
1082
|
-
return { kind: "none" };
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
// src/support.ts
|
|
1086
|
-
var SupportService = class {
|
|
1087
|
-
constructor(client) {
|
|
1088
|
-
this.client = client;
|
|
1089
|
-
}
|
|
1090
|
-
/**
|
|
1091
|
-
* Retry verified external-history discovery for the current storefront.
|
|
1092
|
-
* Launch scope is intentionally WhatsApp-only because it is the registered
|
|
1093
|
-
* bidirectional transport. Results are per envelope and omit provider ids,
|
|
1094
|
-
* contact values, account ids, and message bodies.
|
|
1095
|
-
*/
|
|
1096
|
-
async claimExternalChats() {
|
|
1097
|
-
if (!this.client.getAccessToken()) {
|
|
1098
|
-
return chunkF7J3HK27_js.err(new chunkANT574FD_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1099
|
-
}
|
|
1100
|
-
return chunkF7J3HK27_js.safe(
|
|
1101
|
-
(async () => {
|
|
1102
|
-
const businessId = await this.client.resolveBusinessId();
|
|
1103
|
-
return this.client.post("/v1/me/chats/external-claims", {
|
|
1104
|
-
business_id: businessId
|
|
1105
|
-
});
|
|
1106
|
-
})()
|
|
1107
|
-
);
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* Peek at the conversation without creating one: resolves the existing
|
|
1111
|
-
* thread (or null) so a page load can hydrate history without littering
|
|
1112
|
-
* the inbox with empty threads.
|
|
1113
|
-
*/
|
|
1114
|
-
async peekConversation() {
|
|
1115
|
-
const result = await chunkF7J3HK27_js.safe(
|
|
1116
|
-
this.client.get("/api/v1/support/conversation")
|
|
1117
|
-
);
|
|
1118
|
-
if (!result.ok) return result;
|
|
1119
|
-
if (!result.value.conversation) return chunkF7J3HK27_js.ok(null);
|
|
1120
|
-
return chunkF7J3HK27_js.ok({
|
|
1121
|
-
conversation: result.value.conversation,
|
|
1122
|
-
messages: chatMessagesFromWire(result.value.messages)
|
|
1123
|
-
});
|
|
1124
|
-
}
|
|
1125
|
-
/** Open (or resume) the customer's widget conversation. */
|
|
1126
|
-
async openConversation(opts) {
|
|
1127
|
-
const idempotencyKey = opts?.idempotencyKey ?? chunkF7J3HK27_js.generateIdempotencyKey();
|
|
1128
|
-
const result = await chunkF7J3HK27_js.safe(
|
|
1129
|
-
this.client.post("/api/v1/support/conversation", void 0, {
|
|
1130
|
-
idempotencyKey
|
|
1131
|
-
})
|
|
1132
|
-
);
|
|
1133
|
-
if (!result.ok) return result;
|
|
1134
|
-
return chunkF7J3HK27_js.ok({
|
|
1135
|
-
conversation: result.value.conversation,
|
|
1136
|
-
messages: chatMessagesFromWire(result.value.messages)
|
|
1137
|
-
});
|
|
1138
|
-
}
|
|
1139
|
-
/**
|
|
1140
|
-
* Send a message in the active conversation.
|
|
1141
|
-
*
|
|
1142
|
-
* The idempotency key doubles as the message `client_id`: the backend
|
|
1143
|
-
* dedupes on it, so client retries of the same send never insert twice.
|
|
1144
|
-
* `replyToMessageId` quotes another message by its `ChatMessage.id`; the
|
|
1145
|
-
* server resolves it thread-scoped and echoes the quote as `reply_to`.
|
|
1146
|
-
*/
|
|
1147
|
-
async sendMessage(content, opts) {
|
|
1148
|
-
const idempotencyKey = opts?.idempotencyKey ?? chunkF7J3HK27_js.generateIdempotencyKey();
|
|
1149
|
-
const result = await chunkF7J3HK27_js.safe(
|
|
1150
|
-
this.client.post(
|
|
1151
|
-
"/api/v1/support/conversation/messages",
|
|
1152
|
-
{
|
|
1153
|
-
content,
|
|
1154
|
-
client_id: idempotencyKey,
|
|
1155
|
-
reply_to_message_id: opts?.replyToMessageId,
|
|
1156
|
-
upload_ids: opts?.attachments?.map((a) => a.upload_id)
|
|
1157
|
-
},
|
|
1158
|
-
{ idempotencyKey }
|
|
1159
|
-
)
|
|
1160
|
-
);
|
|
1161
|
-
return result.ok ? chunkF7J3HK27_js.ok(chatMessageFromWire(result.value.message)) : result;
|
|
1162
|
-
}
|
|
1163
|
-
/**
|
|
1164
|
-
* Poll for messages. `after` pages forward (live updates); `before` pages
|
|
1165
|
-
* backward for scrollback into older history.
|
|
1166
|
-
*/
|
|
1167
|
-
async getMessages(options = {}) {
|
|
1168
|
-
const params = new URLSearchParams();
|
|
1169
|
-
if (options.afterSequence !== void 0)
|
|
1170
|
-
params.set("after_sequence", String(options.afterSequence));
|
|
1171
|
-
if (options.beforeSequence !== void 0)
|
|
1172
|
-
params.set("before_sequence", String(options.beforeSequence));
|
|
1173
|
-
if (options.limit) params.set("limit", String(options.limit));
|
|
1174
|
-
const query = params.toString();
|
|
1175
|
-
const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
|
|
1176
|
-
const result = await chunkF7J3HK27_js.safe(this.client.get(path));
|
|
1177
|
-
return result.ok ? chunkF7J3HK27_js.ok(chatMessagesFromWire(result.value)) : result;
|
|
1178
|
-
}
|
|
1179
|
-
/** React to a message in the active conversation by its `ChatMessage.id`. */
|
|
1180
|
-
async reactToMessage(messageId, emoji) {
|
|
1181
|
-
const clientId = chunkF7J3HK27_js.generateIdempotencyKey();
|
|
1182
|
-
const result = await chunkF7J3HK27_js.safe(
|
|
1183
|
-
this.client.post(
|
|
1184
|
-
`/api/v1/support/conversation/messages/${messageId}/reactions`,
|
|
1185
|
-
{ emoji, client_id: clientId },
|
|
1186
|
-
{ idempotencyKey: clientId }
|
|
1187
|
-
)
|
|
1188
|
-
);
|
|
1189
|
-
return result.ok ? chunkF7J3HK27_js.ok(chatMessageFromWire(result.value.message)) : result;
|
|
1190
|
-
}
|
|
1191
|
-
/** Ask for a person: flags the thread for the merchant's inbox. */
|
|
1192
|
-
async requestHuman(opts) {
|
|
1193
|
-
const idempotencyKey = opts?.idempotencyKey ?? chunkF7J3HK27_js.generateIdempotencyKey();
|
|
1194
|
-
return chunkF7J3HK27_js.safe(
|
|
1195
|
-
this.client.post(
|
|
1196
|
-
"/api/v1/support/conversation/handoff",
|
|
1197
|
-
void 0,
|
|
1198
|
-
{ idempotencyKey }
|
|
1199
|
-
)
|
|
1200
|
-
);
|
|
1201
|
-
}
|
|
1202
|
-
};
|
|
1203
|
-
|
|
1204
|
-
// src/session.ts
|
|
1205
|
-
var CLAIM_TIMEOUT_MS = 15e3;
|
|
1206
|
-
var CLAIM_PATH = "/api/v1/auth/session/claim";
|
|
1207
|
-
var SessionService = class {
|
|
1208
|
-
constructor(client) {
|
|
1209
|
-
this.client = client;
|
|
1210
|
-
this.claimInFlight = null;
|
|
1211
|
-
this.claimInFlightToken = null;
|
|
1212
|
-
this.lastClaimedAccessToken = null;
|
|
1213
|
-
this.claimedName = null;
|
|
1214
|
-
this.client.events.on(chunkF7J3HK27_js.SESSION_CLEARED, () => {
|
|
1215
|
-
this.lastClaimedAccessToken = null;
|
|
1216
|
-
this.claimedName = null;
|
|
1217
|
-
});
|
|
1218
|
-
this.client.events.on(chunkF7J3HK27_js.SESSION_CLAIMED, (event) => {
|
|
1219
|
-
if (event.customerName) this.claimedName = event.customerName;
|
|
1220
|
-
});
|
|
1221
|
-
}
|
|
1222
|
-
/** The verified customer this session is bound to, null while anonymous. */
|
|
1223
|
-
get claimedCustomerName() {
|
|
1224
|
-
return this.claimedName;
|
|
1225
|
-
}
|
|
1226
|
-
/** Adopt a session another holder already bound for this bearer. */
|
|
1227
|
-
adopt(accessToken, session) {
|
|
1228
|
-
this.lastClaimedAccessToken = accessToken;
|
|
1229
|
-
this.claimedName = session.customerName || null;
|
|
1230
|
-
this.client.adoptSessionToken(session.sessionToken);
|
|
1231
|
-
this.client.publishSessionClaimed(this.claimedName);
|
|
1232
|
-
this.client.events.emit(chunkF7J3HK27_js.SESSION_CLAIMED, session);
|
|
1233
|
-
}
|
|
1234
|
-
/**
|
|
1235
|
-
* Bind the anonymous session to the verified Link identity in one server
|
|
1236
|
-
* transaction: verify the bearer, rotate the session token (adopted here),
|
|
1237
|
-
* fold the guest cart under the customer and re-price it. A repeat for the
|
|
1238
|
-
* same account and session returns the same session.
|
|
1239
|
-
*
|
|
1240
|
-
* Idempotent and single-flight: concurrent calls share one request, and a
|
|
1241
|
-
* token already claimed by this instance short-circuits without a network
|
|
1242
|
-
* round trip. A session already bound to another Link account is rejected
|
|
1243
|
-
* rather than transferring that account's cart. Emits `session:claimed` on
|
|
1244
|
-
* the client's event channel.
|
|
1245
|
-
*/
|
|
1246
|
-
async claim() {
|
|
1247
|
-
const accessToken = this.client.getAccessToken();
|
|
1248
|
-
if (!accessToken) {
|
|
1249
|
-
return chunkF7J3HK27_js.err(new chunkANT574FD_js.CimplifyError("not_authenticated", "No access token to claim with"));
|
|
1250
|
-
}
|
|
1251
|
-
if (this.claimInFlight) {
|
|
1252
|
-
if (this.claimInFlightToken === accessToken) return this.claimInFlight;
|
|
1253
|
-
await this.claimInFlight;
|
|
1254
|
-
return this.claim();
|
|
1255
|
-
}
|
|
1256
|
-
if (this.lastClaimedAccessToken === accessToken) {
|
|
1257
|
-
return chunkF7J3HK27_js.err(new chunkANT574FD_js.CimplifyError("already_claimed", "Session already claimed for this token"));
|
|
1258
|
-
}
|
|
1259
|
-
const epoch = this.client.getSessionEpoch();
|
|
1260
|
-
this.claimInFlightToken = accessToken;
|
|
1261
|
-
this.claimInFlight = (async () => {
|
|
1262
|
-
const result = await chunkF7J3HK27_js.safe(
|
|
1263
|
-
this.client.post(
|
|
1264
|
-
CLAIM_PATH,
|
|
1265
|
-
{ access_token: accessToken },
|
|
1266
|
-
{ timeoutMs: CLAIM_TIMEOUT_MS }
|
|
1267
|
-
)
|
|
1268
|
-
);
|
|
1269
|
-
if (result.ok) {
|
|
1270
|
-
if (this.client.getSessionEpoch() !== epoch) {
|
|
1271
|
-
return chunkF7J3HK27_js.err(
|
|
1272
|
-
new chunkANT574FD_js.CimplifyError("session_cleared", "Session was cleared during the claim")
|
|
1273
|
-
);
|
|
1274
|
-
}
|
|
1275
|
-
this.adopt(accessToken, {
|
|
1276
|
-
sessionToken: result.value.session_token,
|
|
1277
|
-
customerName: result.value.customer.name,
|
|
1278
|
-
customer: result.value.customer,
|
|
1279
|
-
cart: result.value.cart
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
return result;
|
|
1283
|
-
})();
|
|
1284
|
-
try {
|
|
1285
|
-
return await this.claimInFlight;
|
|
1286
|
-
} finally {
|
|
1287
|
-
this.claimInFlight = null;
|
|
1288
|
-
this.claimInFlightToken = null;
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
};
|
|
1292
|
-
|
|
1293
|
-
// src/internal/cross-tab-session.ts
|
|
1294
|
-
var CROSS_TAB_SESSION_HUB_KEY = /* @__PURE__ */ Symbol.for("@cimplify/sdk.cross-tab-session-hub");
|
|
1295
|
-
var SESSION_SYNC_STORAGE_KEY = "cimplify_session_sync";
|
|
1296
|
-
var MAX_RECENT_ENVELOPES = 64;
|
|
1297
|
-
function hubHost() {
|
|
1298
|
-
return window;
|
|
1299
|
-
}
|
|
1300
|
-
function currentHub() {
|
|
1301
|
-
const candidate = hubHost()[CROSS_TAB_SESSION_HUB_KEY];
|
|
1302
|
-
return candidate?.subscribers instanceof Map && candidate.recentEnvelopes instanceof Set && typeof candidate.storageListener === "function" && typeof candidate.dispatch === "function" ? candidate : null;
|
|
1303
|
-
}
|
|
1304
|
-
function subscriberReference(target) {
|
|
1305
|
-
const WeakReference = globalThis.WeakRef;
|
|
1306
|
-
if (WeakReference) return new WeakReference(target);
|
|
1307
|
-
return { deref: () => target };
|
|
1308
|
-
}
|
|
1309
|
-
function pruneSubscribers(hub) {
|
|
1310
|
-
for (const [token, reference] of hub.subscribers) {
|
|
1311
|
-
if (!reference.deref()) hub.subscribers.delete(token);
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
function parseSessionSyncPayload(serialized) {
|
|
1315
|
-
if (!serialized) return null;
|
|
1316
|
-
try {
|
|
1317
|
-
const payload = JSON.parse(serialized);
|
|
1318
|
-
return (payload.type === "claimed" || payload.type === "cleared") && typeof payload.token === "string" && payload.token.length > 0 && typeof payload.at === "number" && Number.isFinite(payload.at) && (payload.name === void 0 || payload.name === null || typeof payload.name === "string") ? payload : null;
|
|
1319
|
-
} catch {
|
|
1320
|
-
return null;
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
function sessionSyncEnvelopeKey(payload) {
|
|
1324
|
-
const name = payload.name === void 0 ? ["missing"] : ["present", payload.name];
|
|
1325
|
-
return JSON.stringify([payload.type, payload.token, name, payload.at]);
|
|
1326
|
-
}
|
|
1327
|
-
function rememberEnvelope(hub, envelope) {
|
|
1328
|
-
if (hub.recentEnvelopes.has(envelope)) return false;
|
|
1329
|
-
hub.recentEnvelopes.add(envelope);
|
|
1330
|
-
if (hub.recentEnvelopes.size > MAX_RECENT_ENVELOPES) {
|
|
1331
|
-
const oldest = hub.recentEnvelopes.values().next().value;
|
|
1332
|
-
if (oldest) hub.recentEnvelopes.delete(oldest);
|
|
1333
|
-
}
|
|
1334
|
-
return true;
|
|
1335
|
-
}
|
|
1336
|
-
function createHub() {
|
|
1337
|
-
const hub = {
|
|
1338
|
-
subscribers: /* @__PURE__ */ new Map(),
|
|
1339
|
-
recentEnvelopes: /* @__PURE__ */ new Set()
|
|
1340
|
-
};
|
|
1341
|
-
hub.dispatch = (payload) => {
|
|
1342
|
-
if (!rememberEnvelope(hub, sessionSyncEnvelopeKey(payload))) return;
|
|
1343
|
-
for (const [token, reference] of hub.subscribers) {
|
|
1344
|
-
const subscriber = reference.deref();
|
|
1345
|
-
if (!subscriber) {
|
|
1346
|
-
hub.subscribers.delete(token);
|
|
1347
|
-
continue;
|
|
1348
|
-
}
|
|
1349
|
-
try {
|
|
1350
|
-
subscriber.notify(payload);
|
|
1351
|
-
} catch {
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
};
|
|
1355
|
-
hub.storageListener = (event) => {
|
|
1356
|
-
const storageEvent = event;
|
|
1357
|
-
if (storageEvent.key !== SESSION_SYNC_STORAGE_KEY) return;
|
|
1358
|
-
const payload = parseSessionSyncPayload(storageEvent.newValue);
|
|
1359
|
-
if (payload) hub.dispatch(payload);
|
|
1360
|
-
};
|
|
1361
|
-
window.addEventListener("storage", hub.storageListener);
|
|
1362
|
-
hubHost()[CROSS_TAB_SESSION_HUB_KEY] = hub;
|
|
1363
|
-
return hub;
|
|
1364
|
-
}
|
|
1365
|
-
function publishLocalSessionSync(payload) {
|
|
1366
|
-
if (typeof window === "undefined" || typeof window.addEventListener !== "function") return;
|
|
1367
|
-
(currentHub() ?? createHub()).dispatch(payload);
|
|
1368
|
-
}
|
|
1369
|
-
function subscribeCrossTabSession(notify) {
|
|
1370
|
-
if (typeof window === "undefined" || typeof window.addEventListener !== "function") {
|
|
1371
|
-
return () => {
|
|
1372
|
-
};
|
|
1373
|
-
}
|
|
1374
|
-
const hub = currentHub() ?? createHub();
|
|
1375
|
-
pruneSubscribers(hub);
|
|
1376
|
-
const token = /* @__PURE__ */ Symbol("cross-tab-session-subscriber");
|
|
1377
|
-
const subscriber = { notify };
|
|
1378
|
-
hub.subscribers.set(token, subscriberReference(subscriber));
|
|
1379
|
-
let unsubscribed = false;
|
|
1380
|
-
return () => {
|
|
1381
|
-
if (unsubscribed) return;
|
|
1382
|
-
unsubscribed = true;
|
|
1383
|
-
subscriber.notify = () => {
|
|
1384
|
-
};
|
|
1385
|
-
hub.subscribers.delete(token);
|
|
1386
|
-
pruneSubscribers(hub);
|
|
1387
|
-
if (hub.subscribers.size !== 0) return;
|
|
1388
|
-
window.removeEventListener("storage", hub.storageListener);
|
|
1389
|
-
if (currentHub() === hub) delete hubHost()[CROSS_TAB_SESSION_HUB_KEY];
|
|
1390
|
-
};
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
// src/client.ts
|
|
1394
|
-
var SESSION_TOKEN_STORAGE_KEY = "cimplify_session_token";
|
|
1395
|
-
var ORDER_TOKEN_PREFIX = "cimplify_ot_";
|
|
1396
|
-
var SESSION_TOKEN_HEADER = "x-session-token";
|
|
1397
|
-
var LOCATION_ID_QUERY_PARAMETER = "location_id";
|
|
1398
|
-
var ORDER_TOKEN_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
1399
|
-
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
1400
|
-
var DEFAULT_MAX_RETRIES = 3;
|
|
1401
|
-
var DEFAULT_RETRY_DELAY_MS = 1e3;
|
|
1402
|
-
var MAX_RETRY_AFTER_MS = 3e4;
|
|
1403
|
-
function sleep(ms, signal) {
|
|
1404
|
-
if (signal?.aborted) {
|
|
1405
|
-
return Promise.reject(new chunkANT574FD_js.CimplifyError(chunkANT574FD_js.ErrorCode.CANCELLED, "Request was cancelled.", true));
|
|
1406
|
-
}
|
|
1407
|
-
return new Promise((resolve, reject) => {
|
|
1408
|
-
const timer = setTimeout(() => {
|
|
1409
|
-
signal?.removeEventListener("abort", onAbort);
|
|
1410
|
-
resolve();
|
|
1411
|
-
}, ms);
|
|
1412
|
-
const onAbort = () => {
|
|
1413
|
-
clearTimeout(timer);
|
|
1414
|
-
reject(new chunkANT574FD_js.CimplifyError(chunkANT574FD_js.ErrorCode.CANCELLED, "Request was cancelled.", true));
|
|
1415
|
-
};
|
|
1416
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1417
|
-
});
|
|
1418
|
-
}
|
|
1419
|
-
function parseRetryAfterMs(value) {
|
|
1420
|
-
if (!value) return null;
|
|
1421
|
-
const seconds = Number(value);
|
|
1422
|
-
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
1423
|
-
return Math.min(seconds * 1e3, MAX_RETRY_AFTER_MS);
|
|
1424
|
-
}
|
|
1425
|
-
const retryAt = Date.parse(value);
|
|
1426
|
-
if (!Number.isFinite(retryAt)) return null;
|
|
1427
|
-
return Math.min(Math.max(0, retryAt - Date.now()), MAX_RETRY_AFTER_MS);
|
|
1428
|
-
}
|
|
1429
|
-
function withPositiveJitter(delayMs, jitterRatio = 0) {
|
|
1430
|
-
const boundedRatio = Math.min(Math.max(jitterRatio, 0), 1);
|
|
1431
|
-
if (boundedRatio === 0 || delayMs === 0) return delayMs;
|
|
1432
|
-
return Math.round(delayMs + delayMs * boundedRatio * Math.random());
|
|
1433
|
-
}
|
|
1434
|
-
function nextInit(cacheOptions) {
|
|
1435
|
-
if (!cacheOptions) return {};
|
|
1436
|
-
const next = {};
|
|
1437
|
-
if (cacheOptions.revalidate !== void 0) next.revalidate = cacheOptions.revalidate;
|
|
1438
|
-
if (cacheOptions.tags && cacheOptions.tags.length > 0) next.tags = [...cacheOptions.tags];
|
|
1439
|
-
if (next.revalidate === void 0 && !next.tags) return {};
|
|
1440
|
-
return { next };
|
|
1441
|
-
}
|
|
1442
|
-
function mergeOptionHeaders(base, opts) {
|
|
1443
|
-
if (!opts) return base;
|
|
1444
|
-
const merged = { ...base };
|
|
1445
|
-
if (opts.headers) {
|
|
1446
|
-
for (const [k, v] of Object.entries(opts.headers)) {
|
|
1447
|
-
merged[k] = v;
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
if (opts.idempotencyKey) {
|
|
1451
|
-
merged["Idempotency-Key"] = opts.idempotencyKey;
|
|
1452
|
-
}
|
|
1453
|
-
return merged;
|
|
1454
|
-
}
|
|
1455
|
-
function generateSessionToken() {
|
|
1456
|
-
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
1457
|
-
return crypto.randomUUID();
|
|
1458
|
-
}
|
|
1459
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1460
|
-
const r = Math.random() * 16 | 0;
|
|
1461
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
1462
|
-
return v.toString(16);
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
function isRetryable(error) {
|
|
1466
|
-
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
1467
|
-
return true;
|
|
1468
|
-
}
|
|
1469
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
1470
|
-
return true;
|
|
1471
|
-
}
|
|
1472
|
-
if (error instanceof chunkANT574FD_js.CimplifyError) {
|
|
1473
|
-
return error.retryable;
|
|
1474
|
-
}
|
|
1475
|
-
return false;
|
|
1476
|
-
}
|
|
1477
|
-
function toNetworkError(error, isTestMode) {
|
|
1478
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
1479
|
-
return chunkANT574FD_js.enrichError(
|
|
1480
|
-
new chunkANT574FD_js.CimplifyError(
|
|
1481
|
-
chunkANT574FD_js.ErrorCode.TIMEOUT,
|
|
1482
|
-
"Request timed out. Please check your connection and try again.",
|
|
1483
|
-
true
|
|
1484
|
-
),
|
|
1485
|
-
{ isTestMode }
|
|
1486
|
-
);
|
|
1487
|
-
}
|
|
1488
|
-
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
1489
|
-
return chunkANT574FD_js.enrichError(
|
|
1490
|
-
new chunkANT574FD_js.CimplifyError(
|
|
1491
|
-
chunkANT574FD_js.ErrorCode.NETWORK_ERROR,
|
|
1492
|
-
"Network error. Please check your internet connection.",
|
|
1493
|
-
true
|
|
1494
|
-
),
|
|
1495
|
-
{ isTestMode }
|
|
1496
|
-
);
|
|
1497
|
-
}
|
|
1498
|
-
if (error instanceof chunkANT574FD_js.CimplifyError) {
|
|
1499
|
-
return chunkANT574FD_js.enrichError(error, { isTestMode });
|
|
1500
|
-
}
|
|
1501
|
-
return chunkANT574FD_js.enrichError(
|
|
1502
|
-
new chunkANT574FD_js.CimplifyError(
|
|
1503
|
-
chunkANT574FD_js.ErrorCode.UNKNOWN_ERROR,
|
|
1504
|
-
error instanceof Error ? error.message : "An unknown error occurred",
|
|
1505
|
-
false
|
|
1506
|
-
),
|
|
1507
|
-
{ isTestMode }
|
|
1508
|
-
);
|
|
1509
|
-
}
|
|
1510
|
-
function deriveUrls() {
|
|
1511
|
-
const hostname = typeof window !== "undefined" ? window.location.hostname : "";
|
|
1512
|
-
if (hostname === "localhost" || hostname === "127.0.0.1") {
|
|
1513
|
-
const protocol = window.location.protocol;
|
|
1514
|
-
return {
|
|
1515
|
-
baseUrl: `${protocol}//${hostname}:8082`,
|
|
1516
|
-
linkApiUrl: `${protocol}//${hostname}:8080`
|
|
1517
|
-
};
|
|
1518
|
-
}
|
|
1519
|
-
return {
|
|
1520
|
-
baseUrl: "https://storefronts.cimplify.io",
|
|
1521
|
-
linkApiUrl: "https://api.cimplify.io"
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
function normalizeUrl(url) {
|
|
1525
|
-
const trimmed = url.trim();
|
|
1526
|
-
if (!trimmed) return trimmed;
|
|
1527
|
-
return trimmed.replace(/\/+$/, "");
|
|
1528
|
-
}
|
|
1529
|
-
function getEnvPublicKey() {
|
|
1530
|
-
try {
|
|
1531
|
-
const env = globalThis.process;
|
|
1532
|
-
return env?.env.NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY || void 0;
|
|
1533
|
-
} catch {
|
|
1534
|
-
return void 0;
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
var CimplifyClient = class {
|
|
1538
|
-
constructor(config = {}) {
|
|
1539
|
-
this.accessToken = null;
|
|
1540
|
-
this.sessionToken = null;
|
|
1541
|
-
this.sessionEpoch = 0;
|
|
1542
|
-
this.context = {};
|
|
1543
|
-
this.businessId = null;
|
|
1544
|
-
this.businessIdResolvePromise = null;
|
|
1545
|
-
this.publicKeyEpoch = 0;
|
|
1546
|
-
this.stopCrossTabSessionWatch = null;
|
|
1547
|
-
this.latestSessionSyncAt = Number.NEGATIVE_INFINITY;
|
|
1548
|
-
this.latestSessionSyncOrderKey = null;
|
|
1549
|
-
this.inflightRequests = /* @__PURE__ */ new Map();
|
|
1550
|
-
/**
|
|
1551
|
-
* App-level event channel. Subscribe to surface mutation rollbacks, outbox
|
|
1552
|
-
* activity, and dead-letter notifications to consumer code (toasts,
|
|
1553
|
-
* Sentry, analytics, etc.). The SDK emits but never auto-consumes — the
|
|
1554
|
-
* consumer decides how to react.
|
|
1555
|
-
*/
|
|
1556
|
-
this.events = chunkF7J3HK27_js.createClientEvents();
|
|
1557
|
-
this.stopPageViewTracking = null;
|
|
1558
|
-
this.publicKey = config.publicKey || getEnvPublicKey() || "";
|
|
1559
|
-
const urls = deriveUrls();
|
|
1560
|
-
this.baseUrl = config.baseUrl ? normalizeUrl(config.baseUrl) : urls.baseUrl;
|
|
1561
|
-
this.linkApiUrl = config.linkApiUrl ? normalizeUrl(config.linkApiUrl) : urls.linkApiUrl;
|
|
1562
|
-
this.credentials = config.credentials || "include";
|
|
1563
|
-
this.timeout = config.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
1564
|
-
this.maxRetries = config.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
1565
|
-
this.retryDelay = config.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
|
|
1566
|
-
this.hooks = config.hooks ?? {};
|
|
1567
|
-
this.authorizationAdapters = config.authorizationAdapterRegistry ?? chunkF7J3HK27_js.createDefaultPaymentAuthorizationAdapterRegistry();
|
|
1568
|
-
this.fetchImpl = (config.fetch ?? globalThis.fetch).bind(globalThis);
|
|
1569
|
-
this.sessionToken = this.loadSessionToken() ?? this.mintSessionToken();
|
|
1570
|
-
const persistedSessionSync = this.loadSessionSyncPayload();
|
|
1571
|
-
if (persistedSessionSync) this.observeSessionSync(persistedSessionSync);
|
|
1572
|
-
this.stopCrossTabSessionWatch = subscribeCrossTabSession((payload) => {
|
|
1573
|
-
this.applyCrossTabSession(payload);
|
|
1574
|
-
});
|
|
1575
|
-
if (!this.publicKey && !config.suppressPublicKeyWarning) {
|
|
1576
|
-
console.warn(
|
|
1577
|
-
'[Cimplify] No public key found. Set NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY in your environment, or pass { publicKey: "cpk_..." } to createCimplifyClient().'
|
|
1578
|
-
);
|
|
1579
|
-
}
|
|
1580
|
-
if (config.trackPageViews !== false) {
|
|
1581
|
-
this.stopPageViewTracking = this.activity.autoTrackPageViews();
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
buildUrl(base, path) {
|
|
1585
|
-
const url = `${base}${path}`;
|
|
1586
|
-
const locationId = this.context.location_id;
|
|
1587
|
-
if (!locationId) return url;
|
|
1588
|
-
const fragmentIndex = url.indexOf("#");
|
|
1589
|
-
const urlWithoutFragment = fragmentIndex === -1 ? url : url.slice(0, fragmentIndex);
|
|
1590
|
-
const fragment = fragmentIndex === -1 ? "" : url.slice(fragmentIndex);
|
|
1591
|
-
const queryIndex = urlWithoutFragment.indexOf("?");
|
|
1592
|
-
const query = queryIndex === -1 ? "" : urlWithoutFragment.slice(queryIndex + 1);
|
|
1593
|
-
if (new URLSearchParams(query).has(LOCATION_ID_QUERY_PARAMETER)) return url;
|
|
1594
|
-
const separator = queryIndex === -1 ? "?" : "&";
|
|
1595
|
-
return `${urlWithoutFragment}${separator}${LOCATION_ID_QUERY_PARAMETER}=${encodeURIComponent(locationId)}${fragment}`;
|
|
1596
|
-
}
|
|
1597
|
-
stopTrackingPageViews() {
|
|
1598
|
-
this.stopPageViewTracking?.();
|
|
1599
|
-
this.stopPageViewTracking = null;
|
|
1600
|
-
}
|
|
1601
|
-
/** Release window-level subscriptions and automatic tracking owned by this client. */
|
|
1602
|
-
destroy() {
|
|
1603
|
-
this.stopTrackingPageViews();
|
|
1604
|
-
this.stopCrossTabSessionWatch?.();
|
|
1605
|
-
this.stopCrossTabSessionWatch = null;
|
|
1606
|
-
}
|
|
1607
|
-
getAccessToken() {
|
|
1608
|
-
return this.accessToken;
|
|
1609
|
-
}
|
|
1610
|
-
getPublicKey() {
|
|
1611
|
-
return this.publicKey;
|
|
1612
|
-
}
|
|
1613
|
-
getBaseUrl() {
|
|
1614
|
-
return this.baseUrl;
|
|
1615
|
-
}
|
|
1616
|
-
getLinkApiUrl() {
|
|
1617
|
-
return this.linkApiUrl;
|
|
1618
|
-
}
|
|
1619
|
-
getCredentialsMode() {
|
|
1620
|
-
return this.credentials;
|
|
1621
|
-
}
|
|
1622
|
-
isTestMode() {
|
|
1623
|
-
return this.publicKey.trim().startsWith("cpk_test_");
|
|
1624
|
-
}
|
|
1625
|
-
setAccessToken(token) {
|
|
1626
|
-
const previous = this.accessToken;
|
|
1627
|
-
this.accessToken = token;
|
|
1628
|
-
if (previous !== token) {
|
|
1629
|
-
this.sessionEpoch++;
|
|
1630
|
-
}
|
|
1631
|
-
this.hooks.onSessionChange?.({
|
|
1632
|
-
previousToken: previous,
|
|
1633
|
-
newToken: token,
|
|
1634
|
-
source: SESSION_CHANGE_SOURCE.MANUAL
|
|
1635
|
-
});
|
|
1636
|
-
this.events.emit(chunkF7J3HK27_js.AUTH_TOKEN_CHANGED, { token });
|
|
1637
|
-
}
|
|
1638
|
-
/**
|
|
1639
|
-
* Zero-UI claim: a freshly verified customer identity (OTP verify, silent
|
|
1640
|
-
* refresh restore) binds the anonymous session so the conversation, cart
|
|
1641
|
-
* and orders survive a cleared browser. Best-effort by design — a failed
|
|
1642
|
-
* claim leaves the session anonymous, exactly as it was. Called by the
|
|
1643
|
-
* merchant auth flows, never by the raw token setter. Global Link clients
|
|
1644
|
-
* have no storefront tenant and therefore activate without this step.
|
|
1645
|
-
*/
|
|
1646
|
-
autoClaimSession() {
|
|
1647
|
-
if (typeof window === "undefined" || !this.sessionToken || !this.accessToken) return;
|
|
1648
|
-
void this.session.claim();
|
|
1649
|
-
}
|
|
1650
|
-
/**
|
|
1651
|
-
* Adopt a server-rotated session token (claim flow). The old token stays
|
|
1652
|
-
* in flight-safe use until the next request; the storage swap makes the
|
|
1653
|
-
* rotation durable across reloads.
|
|
1654
|
-
*/
|
|
1655
|
-
adoptSessionToken(token) {
|
|
1656
|
-
if (!token || token === this.sessionToken) return;
|
|
1657
|
-
this.sessionToken = token;
|
|
1658
|
-
this.sessionEpoch++;
|
|
1659
|
-
this.saveSessionToken(token);
|
|
1660
|
-
}
|
|
1661
|
-
clearSession() {
|
|
1662
|
-
const previous = this.accessToken;
|
|
1663
|
-
this.accessToken = null;
|
|
1664
|
-
this._activity?.resetSession();
|
|
1665
|
-
this.sessionToken = null;
|
|
1666
|
-
this.sessionEpoch++;
|
|
1667
|
-
try {
|
|
1668
|
-
this.safeStorage()?.removeItem(SESSION_TOKEN_STORAGE_KEY);
|
|
1669
|
-
} catch {
|
|
1670
|
-
}
|
|
1671
|
-
this.sessionToken = this.mintSessionToken();
|
|
1672
|
-
if (this.sessionToken) {
|
|
1673
|
-
this.broadcastSessionSync({ type: "cleared", token: this.sessionToken });
|
|
1674
|
-
}
|
|
1675
|
-
this.hooks.onSessionChange?.({
|
|
1676
|
-
previousToken: previous,
|
|
1677
|
-
newToken: null,
|
|
1678
|
-
source: SESSION_CHANGE_SOURCE.CLEAR
|
|
1679
|
-
});
|
|
1680
|
-
this.events.emit(chunkF7J3HK27_js.AUTH_TOKEN_CHANGED, { token: null });
|
|
1681
|
-
this.events.emit(chunkF7J3HK27_js.SESSION_CLEARED, {});
|
|
1682
|
-
}
|
|
1683
|
-
getSessionEpoch() {
|
|
1684
|
-
return this.sessionEpoch;
|
|
1685
|
-
}
|
|
1686
|
-
/** Monotonic fence for async work scoped to the current storefront tenant. */
|
|
1687
|
-
getPublicKeyEpoch() {
|
|
1688
|
-
return this.publicKeyEpoch;
|
|
1689
|
-
}
|
|
1690
|
-
getSessionToken() {
|
|
1691
|
-
return this.sessionToken;
|
|
1692
|
-
}
|
|
1693
|
-
/** Whether the current transport session is known to have been claimed for
|
|
1694
|
-
* a Link identity, even when its in-memory bearer is absent after reload or
|
|
1695
|
-
* a failed refresh. The sync marker is written only after canonical claim
|
|
1696
|
-
* rotation and is replaced with `cleared` when a fresh session is minted. */
|
|
1697
|
-
hasClaimedSessionAuthority() {
|
|
1698
|
-
if (!this.sessionToken) return false;
|
|
1699
|
-
try {
|
|
1700
|
-
const payload = parseSessionSyncPayload(
|
|
1701
|
-
this.safeStorage()?.getItem(SESSION_SYNC_STORAGE_KEY) ?? null
|
|
1702
|
-
);
|
|
1703
|
-
if (!payload) return false;
|
|
1704
|
-
return payload.type === "claimed" && payload.token === this.sessionToken;
|
|
1705
|
-
} catch {
|
|
1706
|
-
return false;
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
publishSessionClaimed(customerName) {
|
|
1710
|
-
if (!this.sessionToken) return;
|
|
1711
|
-
this.broadcastSessionSync({
|
|
1712
|
-
type: "claimed",
|
|
1713
|
-
token: this.sessionToken,
|
|
1714
|
-
name: customerName
|
|
1715
|
-
});
|
|
1716
|
-
}
|
|
1717
|
-
broadcastSessionSync(payload) {
|
|
1718
|
-
const envelope = {
|
|
1719
|
-
...payload,
|
|
1720
|
-
at: this.nextSessionSyncTimestamp()
|
|
1721
|
-
};
|
|
1722
|
-
try {
|
|
1723
|
-
this.safeStorage()?.setItem(SESSION_SYNC_STORAGE_KEY, JSON.stringify(envelope));
|
|
1724
|
-
} catch {
|
|
1725
|
-
}
|
|
1726
|
-
publishLocalSessionSync(envelope);
|
|
1727
|
-
}
|
|
1728
|
-
applyCrossTabSession(payload) {
|
|
1729
|
-
if (!this.observeSessionSync(payload)) return;
|
|
1730
|
-
if (payload.token === this.sessionToken) return;
|
|
1731
|
-
if (payload.type === "claimed") {
|
|
1732
|
-
this.sessionToken = payload.token;
|
|
1733
|
-
this.sessionEpoch++;
|
|
1734
|
-
this.events.emit(chunkF7J3HK27_js.SESSION_CLAIMED, {
|
|
1735
|
-
sessionToken: payload.token,
|
|
1736
|
-
customerName: payload.name ?? "",
|
|
1737
|
-
customer: null,
|
|
1738
|
-
cart: null
|
|
1739
|
-
});
|
|
1740
|
-
} else {
|
|
1741
|
-
this.accessToken = null;
|
|
1742
|
-
this._activity?.resetSession();
|
|
1743
|
-
this.sessionToken = payload.token;
|
|
1744
|
-
this.sessionEpoch++;
|
|
1745
|
-
this.events.emit(chunkF7J3HK27_js.AUTH_TOKEN_CHANGED, { token: null });
|
|
1746
|
-
this.events.emit(chunkF7J3HK27_js.SESSION_CLEARED, {});
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
observeSessionSync(payload) {
|
|
1750
|
-
if (payload.at < this.latestSessionSyncAt) return false;
|
|
1751
|
-
const envelope = sessionSyncEnvelopeKey(payload);
|
|
1752
|
-
if (payload.at === this.latestSessionSyncAt && this.latestSessionSyncOrderKey !== null && envelope <= this.latestSessionSyncOrderKey) {
|
|
1753
|
-
return false;
|
|
1754
|
-
}
|
|
1755
|
-
this.latestSessionSyncAt = payload.at;
|
|
1756
|
-
this.latestSessionSyncOrderKey = envelope;
|
|
1757
|
-
return true;
|
|
1758
|
-
}
|
|
1759
|
-
nextSessionSyncTimestamp() {
|
|
1760
|
-
const now = Date.now();
|
|
1761
|
-
return Number.isFinite(this.latestSessionSyncAt) ? Math.max(now, this.latestSessionSyncAt + 1) : now;
|
|
1762
|
-
}
|
|
1763
|
-
setOrderToken(orderId, token) {
|
|
1764
|
-
try {
|
|
1765
|
-
const entry = JSON.stringify({ token, storedAt: Date.now() });
|
|
1766
|
-
this.safeStorage()?.setItem(`${ORDER_TOKEN_PREFIX}${orderId}`, entry);
|
|
1767
|
-
} catch {
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
getOrderToken(orderId) {
|
|
1771
|
-
try {
|
|
1772
|
-
const storage = this.safeStorage();
|
|
1773
|
-
if (!storage) return null;
|
|
1774
|
-
const raw = storage.getItem(`${ORDER_TOKEN_PREFIX}${orderId}`);
|
|
1775
|
-
if (!raw) return null;
|
|
1776
|
-
const entry = JSON.parse(raw);
|
|
1777
|
-
if (Date.now() - entry.storedAt > ORDER_TOKEN_TTL_MS) {
|
|
1778
|
-
storage.removeItem(`${ORDER_TOKEN_PREFIX}${orderId}`);
|
|
1779
|
-
return null;
|
|
1780
|
-
}
|
|
1781
|
-
return entry.token;
|
|
1782
|
-
} catch {
|
|
1783
|
-
return null;
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
clearOrderTokens() {
|
|
1787
|
-
try {
|
|
1788
|
-
const storage = this.safeStorage();
|
|
1789
|
-
if (!storage) return;
|
|
1790
|
-
const keysToRemove = [];
|
|
1791
|
-
for (let i = 0; i < storage.length; i++) {
|
|
1792
|
-
const key = storage.key(i);
|
|
1793
|
-
if (key?.startsWith(ORDER_TOKEN_PREFIX)) {
|
|
1794
|
-
keysToRemove.push(key);
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
keysToRemove.forEach((k) => storage.removeItem(k));
|
|
1798
|
-
} catch {
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
setLocationId(locationId) {
|
|
1802
|
-
if (locationId) {
|
|
1803
|
-
this.context.location_id = locationId;
|
|
1804
|
-
} else {
|
|
1805
|
-
delete this.context.location_id;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
getLocationId() {
|
|
1809
|
-
return this.context.location_id ?? null;
|
|
1810
|
-
}
|
|
1811
|
-
setBusinessId(businessId) {
|
|
1812
|
-
const normalized = businessId.trim();
|
|
1813
|
-
if (!normalized) {
|
|
1814
|
-
return;
|
|
1815
|
-
}
|
|
1816
|
-
this.businessId = normalized;
|
|
1817
|
-
}
|
|
1818
|
-
// Set the storefront public key after construction. Needed by hosts that
|
|
1819
|
-
// create the client before they know the key (e.g. the Link element, which
|
|
1820
|
-
// receives it in its INIT message) — without it, storefront calls carry no
|
|
1821
|
-
// X-API-Key and the business can't be resolved.
|
|
1822
|
-
setPublicKey(publicKey) {
|
|
1823
|
-
const normalized = publicKey.trim();
|
|
1824
|
-
if (normalized === this.publicKey) return;
|
|
1825
|
-
const restartPageViewTracking = this.stopPageViewTracking !== null;
|
|
1826
|
-
if (restartPageViewTracking) {
|
|
1827
|
-
this.stopTrackingPageViews();
|
|
1828
|
-
}
|
|
1829
|
-
this.publicKey = normalized;
|
|
1830
|
-
this.publicKeyEpoch += 1;
|
|
1831
|
-
this.businessId = null;
|
|
1832
|
-
this.businessIdResolvePromise = null;
|
|
1833
|
-
this.inflightRequests.clear();
|
|
1834
|
-
this._activity?.resetForStorefrontIdentityChange();
|
|
1835
|
-
delete this.context.location_id;
|
|
1836
|
-
if (this.accessToken !== null) {
|
|
1837
|
-
this.setAccessToken(null);
|
|
1838
|
-
}
|
|
1839
|
-
this.events.emit(chunkF7J3HK27_js.SESSION_CLEARED, {});
|
|
1840
|
-
if (restartPageViewTracking) {
|
|
1841
|
-
this.stopPageViewTracking = this.activity.autoTrackPageViews();
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
getBusinessId() {
|
|
1845
|
-
return this.businessId;
|
|
1846
|
-
}
|
|
1847
|
-
async resolveBusinessId() {
|
|
1848
|
-
if (this.businessId) {
|
|
1849
|
-
return this.businessId;
|
|
1850
|
-
}
|
|
1851
|
-
if (this.businessIdResolvePromise) {
|
|
1852
|
-
return this.businessIdResolvePromise;
|
|
1853
|
-
}
|
|
1854
|
-
const publicKeyEpoch = this.publicKeyEpoch;
|
|
1855
|
-
const resolution = (async () => {
|
|
1856
|
-
const result = await this.business.getInfo();
|
|
1857
|
-
if (!result.ok || !result.value?.id) {
|
|
1858
|
-
throw new chunkANT574FD_js.CimplifyError(
|
|
1859
|
-
chunkANT574FD_js.ErrorCode.NOT_FOUND,
|
|
1860
|
-
"Unable to resolve business ID from the current public key.",
|
|
1861
|
-
true
|
|
1862
|
-
);
|
|
1863
|
-
}
|
|
1864
|
-
if (this.publicKeyEpoch !== publicKeyEpoch) {
|
|
1865
|
-
throw new chunkANT574FD_js.CimplifyError(
|
|
1866
|
-
chunkANT574FD_js.ErrorCode.TENANT_CONTEXT_CHANGED,
|
|
1867
|
-
"The storefront tenant changed while resolving its business identity.",
|
|
1868
|
-
true
|
|
1869
|
-
);
|
|
1870
|
-
}
|
|
1871
|
-
this.businessId = result.value.id;
|
|
1872
|
-
return result.value.id;
|
|
1873
|
-
})();
|
|
1874
|
-
this.businessIdResolvePromise = resolution;
|
|
1875
|
-
try {
|
|
1876
|
-
return await resolution;
|
|
1877
|
-
} finally {
|
|
1878
|
-
if (this.businessIdResolvePromise === resolution) {
|
|
1879
|
-
this.businessIdResolvePromise = null;
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
}
|
|
1883
|
-
async authedFetch(url, options, timeoutMs, retryPolicy, signal) {
|
|
1884
|
-
return this.resilientFetch(url, options, timeoutMs, retryPolicy, signal);
|
|
1885
|
-
}
|
|
1886
|
-
// Storage guards: even the `window.localStorage` property access throws in
|
|
1887
|
-
// some sandboxed iframes and strict private-browsing modes. These run in the
|
|
1888
|
-
// constructor at module load, so a throw would white-screen the whole app —
|
|
1889
|
-
// fall back to an in-memory session token instead.
|
|
1890
|
-
safeStorage() {
|
|
1891
|
-
try {
|
|
1892
|
-
if (typeof window !== "undefined" && window.localStorage) {
|
|
1893
|
-
return window.localStorage;
|
|
1894
|
-
}
|
|
1895
|
-
} catch {
|
|
1896
|
-
}
|
|
1897
|
-
return null;
|
|
1898
|
-
}
|
|
1899
|
-
loadSessionToken() {
|
|
1900
|
-
try {
|
|
1901
|
-
return this.safeStorage()?.getItem(SESSION_TOKEN_STORAGE_KEY) ?? null;
|
|
1902
|
-
} catch {
|
|
1903
|
-
return null;
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
loadSessionSyncPayload() {
|
|
1907
|
-
try {
|
|
1908
|
-
return parseSessionSyncPayload(this.safeStorage()?.getItem(SESSION_SYNC_STORAGE_KEY) ?? null);
|
|
1909
|
-
} catch {
|
|
1910
|
-
return null;
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
/**
|
|
1914
|
-
* Mint the session token client-side so the very first request already
|
|
1915
|
-
* carries it. Without this, parallel first-load requests each get a
|
|
1916
|
-
* different server-minted token and last-writer-wins splits the session
|
|
1917
|
-
* (cart writes and chat conversations land on dropped tokens).
|
|
1918
|
-
*
|
|
1919
|
-
* Browser-only: minting on a server-shared client instance would pin
|
|
1920
|
-
* every visitor to one session, so SSR keeps the lazy server-minted flow.
|
|
1921
|
-
*/
|
|
1922
|
-
mintSessionToken() {
|
|
1923
|
-
if (typeof window === "undefined") {
|
|
1924
|
-
return null;
|
|
1925
|
-
}
|
|
1926
|
-
const token = generateSessionToken();
|
|
1927
|
-
this.saveSessionToken(token);
|
|
1928
|
-
return token;
|
|
1929
|
-
}
|
|
1930
|
-
saveSessionToken(token) {
|
|
1931
|
-
try {
|
|
1932
|
-
this.safeStorage()?.setItem(SESSION_TOKEN_STORAGE_KEY, token);
|
|
1933
|
-
} catch {
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
captureSessionToken(response) {
|
|
1937
|
-
if (typeof window === "undefined") return;
|
|
1938
|
-
if (this.sessionToken) return;
|
|
1939
|
-
const token = response.headers.get(SESSION_TOKEN_HEADER);
|
|
1940
|
-
if (token) {
|
|
1941
|
-
this.sessionToken = token;
|
|
1942
|
-
this.saveSessionToken(token);
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1945
|
-
getHeaders() {
|
|
1946
|
-
const headers = {
|
|
1947
|
-
"Content-Type": "application/json"
|
|
1948
|
-
};
|
|
1949
|
-
const trimmedPublicKey = this.publicKey.trim();
|
|
1950
|
-
if (trimmedPublicKey) {
|
|
1951
|
-
headers["X-API-Key"] = trimmedPublicKey;
|
|
1952
|
-
}
|
|
1953
|
-
if (this.accessToken) {
|
|
1954
|
-
headers["Authorization"] = `Bearer ${this.accessToken}`;
|
|
1955
|
-
}
|
|
1956
|
-
if (this.sessionToken) {
|
|
1957
|
-
headers[SESSION_TOKEN_HEADER] = this.sessionToken;
|
|
1958
|
-
}
|
|
1959
|
-
if (typeof window !== "undefined") {
|
|
1960
|
-
headers["X-Storefront-Host"] = window.location.host;
|
|
1961
|
-
const preview = new URLSearchParams(window.location.search).get("preview");
|
|
1962
|
-
if (preview) {
|
|
1963
|
-
headers["X-Storefront-Preview"] = preview;
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
|
-
return headers;
|
|
1967
|
-
}
|
|
1968
|
-
async resilientFetch(url, options, timeoutMs, retryPolicy, signal) {
|
|
1969
|
-
const method = options.method || "GET";
|
|
1970
|
-
const path = url.replace(this.baseUrl, "").replace(this.linkApiUrl, "");
|
|
1971
|
-
const startTime = Date.now();
|
|
1972
|
-
let retryCount = 0;
|
|
1973
|
-
const context = {
|
|
1974
|
-
method,
|
|
1975
|
-
path,
|
|
1976
|
-
url,
|
|
1977
|
-
body: options.body ? JSON.parse(options.body) : void 0,
|
|
1978
|
-
startTime
|
|
1979
|
-
};
|
|
1980
|
-
this.hooks.onRequestStart?.(context);
|
|
1981
|
-
let lastError;
|
|
1982
|
-
const configuredMaxRetries = Math.max(0, Math.floor(this.maxRetries));
|
|
1983
|
-
const maxRetries = Math.min(
|
|
1984
|
-
configuredMaxRetries,
|
|
1985
|
-
Math.max(0, Math.floor(retryPolicy?.maxRetries ?? configuredMaxRetries))
|
|
1986
|
-
);
|
|
1987
|
-
const jitterRatio = retryPolicy?.jitterRatio ?? 0;
|
|
1988
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1989
|
-
try {
|
|
1990
|
-
if (signal?.aborted) {
|
|
1991
|
-
throw new chunkANT574FD_js.CimplifyError(chunkANT574FD_js.ErrorCode.CANCELLED, "Request was cancelled.", true);
|
|
1992
|
-
}
|
|
1993
|
-
const controller = new AbortController();
|
|
1994
|
-
const timeoutId = setTimeout(() => controller.abort(), timeoutMs ?? this.timeout);
|
|
1995
|
-
const onAbort = () => controller.abort();
|
|
1996
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
1997
|
-
let response;
|
|
1998
|
-
try {
|
|
1999
|
-
response = await this.fetchImpl(url, {
|
|
2000
|
-
...options,
|
|
2001
|
-
signal: controller.signal
|
|
2002
|
-
});
|
|
2003
|
-
} finally {
|
|
2004
|
-
clearTimeout(timeoutId);
|
|
2005
|
-
signal?.removeEventListener("abort", onAbort);
|
|
2006
|
-
}
|
|
2007
|
-
this.captureSessionToken(response);
|
|
2008
|
-
if (response.ok) {
|
|
2009
|
-
this.hooks.onRequestSuccess?.({
|
|
2010
|
-
...context,
|
|
2011
|
-
status: response.status,
|
|
2012
|
-
durationMs: Date.now() - startTime
|
|
2013
|
-
});
|
|
2014
|
-
return response;
|
|
2015
|
-
}
|
|
2016
|
-
if ((response.status === 429 || response.status === 503) && attempt < maxRetries) {
|
|
2017
|
-
retryCount++;
|
|
2018
|
-
const retryAfterMs = parseRetryAfterMs(response.headers.get("Retry-After"));
|
|
2019
|
-
const retryBaseMs = retryAfterMs ?? this.retryDelay * Math.pow(2, attempt);
|
|
2020
|
-
const jitteredDelayMs = withPositiveJitter(retryBaseMs, jitterRatio);
|
|
2021
|
-
const delay = retryAfterMs === null ? jitteredDelayMs : Math.min(jitteredDelayMs, MAX_RETRY_AFTER_MS);
|
|
2022
|
-
this.hooks.onRetry?.({
|
|
2023
|
-
...context,
|
|
2024
|
-
attempt: retryCount,
|
|
2025
|
-
delayMs: delay,
|
|
2026
|
-
error: new Error(`Retryable: ${response.status}`)
|
|
2027
|
-
});
|
|
2028
|
-
await sleep(delay, signal);
|
|
2029
|
-
continue;
|
|
2030
|
-
}
|
|
2031
|
-
if (response.status >= 400 && response.status < 500) {
|
|
2032
|
-
this.hooks.onRequestError?.({
|
|
2033
|
-
...context,
|
|
2034
|
-
error: new chunkANT574FD_js.CimplifyError(
|
|
2035
|
-
`HTTP_${response.status}`,
|
|
2036
|
-
`Request failed with status ${response.status}`,
|
|
2037
|
-
false
|
|
2038
|
-
),
|
|
2039
|
-
status: response.status,
|
|
2040
|
-
durationMs: Date.now() - startTime,
|
|
2041
|
-
retryCount,
|
|
2042
|
-
retryable: false
|
|
2043
|
-
});
|
|
2044
|
-
return response;
|
|
2045
|
-
}
|
|
2046
|
-
if (response.status >= 500 && attempt < maxRetries) {
|
|
2047
|
-
retryCount++;
|
|
2048
|
-
const delay = withPositiveJitter(this.retryDelay * Math.pow(2, attempt), jitterRatio);
|
|
2049
|
-
this.hooks.onRetry?.({
|
|
2050
|
-
...context,
|
|
2051
|
-
attempt: retryCount,
|
|
2052
|
-
delayMs: delay,
|
|
2053
|
-
error: new Error(`Server error: ${response.status}`)
|
|
2054
|
-
});
|
|
2055
|
-
await sleep(delay, signal);
|
|
2056
|
-
continue;
|
|
2057
|
-
}
|
|
2058
|
-
this.hooks.onRequestError?.({
|
|
2059
|
-
...context,
|
|
2060
|
-
error: new chunkANT574FD_js.CimplifyError(
|
|
2061
|
-
chunkANT574FD_js.ErrorCode.SERVER_ERROR,
|
|
2062
|
-
`Server error ${response.status} after ${retryCount} retries`,
|
|
2063
|
-
false
|
|
2064
|
-
),
|
|
2065
|
-
status: response.status,
|
|
2066
|
-
durationMs: Date.now() - startTime,
|
|
2067
|
-
retryCount,
|
|
2068
|
-
retryable: false
|
|
2069
|
-
});
|
|
2070
|
-
return response;
|
|
2071
|
-
} catch (error) {
|
|
2072
|
-
lastError = error;
|
|
2073
|
-
if (signal?.aborted) {
|
|
2074
|
-
throw new chunkANT574FD_js.CimplifyError(chunkANT574FD_js.ErrorCode.CANCELLED, "Request was cancelled.", true);
|
|
2075
|
-
}
|
|
2076
|
-
const networkError = toNetworkError(error, this.isTestMode());
|
|
2077
|
-
const errorRetryable = isRetryable(error);
|
|
2078
|
-
if (!errorRetryable || attempt >= maxRetries) {
|
|
2079
|
-
this.hooks.onRequestError?.({
|
|
2080
|
-
...context,
|
|
2081
|
-
error: networkError,
|
|
2082
|
-
durationMs: Date.now() - startTime,
|
|
2083
|
-
retryCount,
|
|
2084
|
-
retryable: errorRetryable
|
|
2085
|
-
});
|
|
2086
|
-
throw networkError;
|
|
2087
|
-
}
|
|
2088
|
-
retryCount++;
|
|
2089
|
-
const delay = withPositiveJitter(this.retryDelay * Math.pow(2, attempt), jitterRatio);
|
|
2090
|
-
this.hooks.onRetry?.({
|
|
2091
|
-
...context,
|
|
2092
|
-
attempt: retryCount,
|
|
2093
|
-
delayMs: delay,
|
|
2094
|
-
error: networkError
|
|
2095
|
-
});
|
|
2096
|
-
await sleep(delay, signal);
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
const finalError = toNetworkError(lastError, this.isTestMode());
|
|
2100
|
-
this.hooks.onRequestError?.({
|
|
2101
|
-
...context,
|
|
2102
|
-
error: finalError,
|
|
2103
|
-
durationMs: Date.now() - startTime,
|
|
2104
|
-
retryCount,
|
|
2105
|
-
retryable: false
|
|
2106
|
-
});
|
|
2107
|
-
throw finalError;
|
|
2108
|
-
}
|
|
2109
|
-
getDedupeKey(type, payload, cacheOptions) {
|
|
2110
|
-
const cacheKey = cacheOptions ? `|${JSON.stringify(cacheOptions)}` : "";
|
|
2111
|
-
const identityKey = JSON.stringify([
|
|
2112
|
-
this.publicKey.trim(),
|
|
2113
|
-
this.publicKeyEpoch,
|
|
2114
|
-
this.sessionEpoch,
|
|
2115
|
-
this.context.location_id ?? null
|
|
2116
|
-
]);
|
|
2117
|
-
return `${type}:${identityKey}:${JSON.stringify(payload)}${cacheKey}`;
|
|
2118
|
-
}
|
|
2119
|
-
async deduplicatedRequest(key, requestFn) {
|
|
2120
|
-
const existing = this.inflightRequests.get(key);
|
|
2121
|
-
if (existing) {
|
|
2122
|
-
return existing;
|
|
2123
|
-
}
|
|
2124
|
-
const request = requestFn().finally(() => {
|
|
2125
|
-
if (this.inflightRequests.get(key) === request) {
|
|
2126
|
-
this.inflightRequests.delete(key);
|
|
2127
|
-
}
|
|
2128
|
-
});
|
|
2129
|
-
this.inflightRequests.set(key, request);
|
|
2130
|
-
return request;
|
|
2131
|
-
}
|
|
2132
|
-
async get(path, opts) {
|
|
2133
|
-
const request = async () => {
|
|
2134
|
-
const response = await this.authedFetch(
|
|
2135
|
-
this.buildUrl(this.baseUrl, path),
|
|
2136
|
-
{
|
|
2137
|
-
method: "GET",
|
|
2138
|
-
credentials: this.credentials,
|
|
2139
|
-
headers: this.getHeaders(),
|
|
2140
|
-
...nextInit(opts?.cacheOptions)
|
|
2141
|
-
},
|
|
2142
|
-
opts?.timeoutMs,
|
|
2143
|
-
opts?.retryPolicy,
|
|
2144
|
-
opts?.signal
|
|
2145
|
-
);
|
|
2146
|
-
return this.handleRestResponse(response);
|
|
2147
|
-
};
|
|
2148
|
-
if (opts?.signal) return request();
|
|
2149
|
-
const key = this.getDedupeKey("get", path, opts?.cacheOptions);
|
|
2150
|
-
return this.deduplicatedRequest(key, request);
|
|
2151
|
-
}
|
|
2152
|
-
async post(path, body, opts) {
|
|
2153
|
-
const response = await this.authedFetch(
|
|
2154
|
-
this.buildUrl(this.baseUrl, path),
|
|
2155
|
-
{
|
|
2156
|
-
method: "POST",
|
|
2157
|
-
credentials: this.credentials,
|
|
2158
|
-
headers: mergeOptionHeaders(this.getHeaders(), opts),
|
|
2159
|
-
body: body ? JSON.stringify(body) : void 0
|
|
2160
|
-
},
|
|
2161
|
-
opts?.timeoutMs,
|
|
2162
|
-
opts?.retryPolicy,
|
|
2163
|
-
opts?.signal
|
|
2164
|
-
);
|
|
2165
|
-
return this.handleRestResponse(response);
|
|
2166
|
-
}
|
|
2167
|
-
async patch(path, body, opts) {
|
|
2168
|
-
const response = await this.authedFetch(
|
|
2169
|
-
this.buildUrl(this.baseUrl, path),
|
|
2170
|
-
{
|
|
2171
|
-
method: "PATCH",
|
|
2172
|
-
credentials: this.credentials,
|
|
2173
|
-
headers: mergeOptionHeaders(this.getHeaders(), opts),
|
|
2174
|
-
body: body ? JSON.stringify(body) : void 0
|
|
2175
|
-
},
|
|
2176
|
-
opts?.timeoutMs,
|
|
2177
|
-
opts?.retryPolicy,
|
|
2178
|
-
opts?.signal
|
|
2179
|
-
);
|
|
2180
|
-
return this.handleRestResponse(response);
|
|
2181
|
-
}
|
|
2182
|
-
async delete(path, opts) {
|
|
2183
|
-
const response = await this.authedFetch(
|
|
2184
|
-
this.buildUrl(this.baseUrl, path),
|
|
2185
|
-
{
|
|
2186
|
-
method: "DELETE",
|
|
2187
|
-
credentials: this.credentials,
|
|
2188
|
-
headers: mergeOptionHeaders(this.getHeaders(), opts)
|
|
2189
|
-
},
|
|
2190
|
-
opts?.timeoutMs,
|
|
2191
|
-
opts?.retryPolicy,
|
|
2192
|
-
opts?.signal
|
|
2193
|
-
);
|
|
2194
|
-
return this.handleRestResponse(response);
|
|
2195
|
-
}
|
|
2196
|
-
async linkGet(path, opts) {
|
|
2197
|
-
const request = async () => {
|
|
2198
|
-
const response = await this.authedFetch(
|
|
2199
|
-
`${this.linkApiUrl}${path}`,
|
|
2200
|
-
{
|
|
2201
|
-
method: "GET",
|
|
2202
|
-
credentials: this.credentials,
|
|
2203
|
-
headers: this.getHeaders(),
|
|
2204
|
-
...nextInit(opts?.cacheOptions)
|
|
2205
|
-
},
|
|
2206
|
-
opts?.timeoutMs,
|
|
2207
|
-
opts?.retryPolicy,
|
|
2208
|
-
opts?.signal
|
|
2209
|
-
);
|
|
2210
|
-
return this.handleRestResponse(response);
|
|
2211
|
-
};
|
|
2212
|
-
if (opts?.signal) return request();
|
|
2213
|
-
const key = this.getDedupeKey("linkGet", path, opts?.cacheOptions);
|
|
2214
|
-
return this.deduplicatedRequest(key, request);
|
|
2215
|
-
}
|
|
2216
|
-
async linkPost(path, body, opts) {
|
|
2217
|
-
const response = await this.authedFetch(
|
|
2218
|
-
`${this.linkApiUrl}${path}`,
|
|
2219
|
-
{
|
|
2220
|
-
method: "POST",
|
|
2221
|
-
credentials: this.credentials,
|
|
2222
|
-
headers: mergeOptionHeaders(this.getHeaders(), opts),
|
|
2223
|
-
body: body ? JSON.stringify(body) : void 0
|
|
2224
|
-
},
|
|
2225
|
-
opts?.timeoutMs,
|
|
2226
|
-
opts?.retryPolicy,
|
|
2227
|
-
opts?.signal
|
|
2228
|
-
);
|
|
2229
|
-
return this.handleRestResponse(response);
|
|
2230
|
-
}
|
|
2231
|
-
async linkDelete(path, opts) {
|
|
2232
|
-
const response = await this.authedFetch(
|
|
2233
|
-
`${this.linkApiUrl}${path}`,
|
|
2234
|
-
{
|
|
2235
|
-
method: "DELETE",
|
|
2236
|
-
credentials: this.credentials,
|
|
2237
|
-
headers: mergeOptionHeaders(this.getHeaders(), opts)
|
|
2238
|
-
},
|
|
2239
|
-
opts?.timeoutMs,
|
|
2240
|
-
opts?.retryPolicy,
|
|
2241
|
-
opts?.signal
|
|
2242
|
-
);
|
|
2243
|
-
return this.handleRestResponse(response);
|
|
2244
|
-
}
|
|
2245
|
-
async handleRestResponse(response) {
|
|
2246
|
-
const json = await response.json();
|
|
2247
|
-
if (!response.ok) {
|
|
2248
|
-
const errorCode = typeof json.error === "object" && json.error?.error_code || typeof json.error === "object" && json.error?.code || chunkANT574FD_js.ErrorCode.API_ERROR;
|
|
2249
|
-
const errorMessage = typeof json.error === "object" && json.error?.error_message || typeof json.error === "object" && json.error?.message || typeof json.error === "string" && json.error || typeof json.message === "string" && json.message || "An error occurred";
|
|
2250
|
-
const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
|
|
2251
|
-
if (errorCode === chunkANT574FD_js.ErrorCode.IDEMPOTENCY_MISMATCH) {
|
|
2252
|
-
const originalCreatedAt = typeof json.error === "object" && json.error?.original_created_at || "";
|
|
2253
|
-
throw new chunkANT574FD_js.IdempotencyMismatchError(errorMessage, originalCreatedAt);
|
|
2254
|
-
}
|
|
2255
|
-
const error = chunkANT574FD_js.enrichError(new chunkANT574FD_js.CimplifyError(errorCode, errorMessage, retryable), {
|
|
2256
|
-
isTestMode: this.isTestMode()
|
|
2257
|
-
});
|
|
2258
|
-
if ((response.status === 401 || error.code === chunkANT574FD_js.ErrorCode.UNAUTHORIZED) && this.accessToken) {
|
|
2259
|
-
console.warn(
|
|
2260
|
-
"[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
|
|
2261
|
-
);
|
|
2262
|
-
}
|
|
2263
|
-
throw error;
|
|
2264
|
-
}
|
|
2265
|
-
if (json?.success === false || json?.error?.code || json?.error?.message) {
|
|
2266
|
-
const error = chunkANT574FD_js.enrichError(
|
|
2267
|
-
new chunkANT574FD_js.CimplifyError(
|
|
2268
|
-
json.error?.code || chunkANT574FD_js.ErrorCode.API_ERROR,
|
|
2269
|
-
json.error?.message || "An error occurred",
|
|
2270
|
-
json.error?.retryable || false
|
|
2271
|
-
),
|
|
2272
|
-
{ isTestMode: this.isTestMode() }
|
|
2273
|
-
);
|
|
2274
|
-
throw error;
|
|
2275
|
-
}
|
|
2276
|
-
if (json?.data !== void 0) {
|
|
2277
|
-
return json.data;
|
|
2278
|
-
}
|
|
2279
|
-
return json;
|
|
2280
|
-
}
|
|
2281
|
-
get catalogue() {
|
|
2282
|
-
if (!this._catalogue) {
|
|
2283
|
-
this._catalogue = new chunkF7J3HK27_js.CatalogueQueries(this);
|
|
2284
|
-
}
|
|
2285
|
-
return this._catalogue;
|
|
2286
|
-
}
|
|
2287
|
-
get cart() {
|
|
2288
|
-
if (!this._cart) {
|
|
2289
|
-
this._cart = new chunkF7J3HK27_js.CartOperations(this);
|
|
2290
|
-
}
|
|
2291
|
-
return this._cart;
|
|
2292
|
-
}
|
|
2293
|
-
get checkout() {
|
|
2294
|
-
if (!this._checkout) {
|
|
2295
|
-
this._checkout = new chunkF7J3HK27_js.CheckoutService(this);
|
|
2296
|
-
}
|
|
2297
|
-
return this._checkout;
|
|
2298
|
-
}
|
|
2299
|
-
get purchaseIntents() {
|
|
2300
|
-
if (!this._purchaseIntents) {
|
|
2301
|
-
this._purchaseIntents = new PurchaseIntentService(this);
|
|
2302
|
-
}
|
|
2303
|
-
return this._purchaseIntents;
|
|
2304
|
-
}
|
|
2305
|
-
get orders() {
|
|
2306
|
-
if (!this._orders) {
|
|
2307
|
-
this._orders = new chunkF7J3HK27_js.OrderQueries(this);
|
|
2308
|
-
}
|
|
2309
|
-
return this._orders;
|
|
2310
|
-
}
|
|
2311
|
-
get storeCredit() {
|
|
2312
|
-
if (!this._storeCredit) {
|
|
2313
|
-
this._storeCredit = new StoreCreditQueries(this);
|
|
2314
|
-
}
|
|
2315
|
-
return this._storeCredit;
|
|
2316
|
-
}
|
|
2317
|
-
get subscriptions() {
|
|
2318
|
-
if (!this._subscriptions) {
|
|
2319
|
-
this._subscriptions = new SubscriptionService(this);
|
|
2320
|
-
}
|
|
2321
|
-
return this._subscriptions;
|
|
2322
|
-
}
|
|
2323
|
-
get uploads() {
|
|
2324
|
-
if (!this._uploads) {
|
|
2325
|
-
this._uploads = new UploadService(this);
|
|
2326
|
-
}
|
|
2327
|
-
return this._uploads;
|
|
2328
|
-
}
|
|
2329
|
-
get places() {
|
|
2330
|
-
if (!this._places) {
|
|
2331
|
-
this._places = new PlacesService(this);
|
|
2332
|
-
}
|
|
2333
|
-
return this._places;
|
|
2334
|
-
}
|
|
2335
|
-
get link() {
|
|
2336
|
-
if (!this._link) {
|
|
2337
|
-
this._link = new chunkF7J3HK27_js.LinkService(this);
|
|
2338
|
-
}
|
|
2339
|
-
return this._link;
|
|
2340
|
-
}
|
|
2341
|
-
get auth() {
|
|
2342
|
-
if (!this._auth) {
|
|
2343
|
-
this._auth = new chunkF7J3HK27_js.AuthService(this);
|
|
2344
|
-
}
|
|
2345
|
-
return this._auth;
|
|
2346
|
-
}
|
|
2347
|
-
get business() {
|
|
2348
|
-
if (!this._business) {
|
|
2349
|
-
this._business = new chunkF7J3HK27_js.BusinessService(this);
|
|
2350
|
-
}
|
|
2351
|
-
return this._business;
|
|
2352
|
-
}
|
|
2353
|
-
get inventory() {
|
|
2354
|
-
if (!this._inventory) {
|
|
2355
|
-
this._inventory = new chunkF7J3HK27_js.InventoryService(this);
|
|
2356
|
-
}
|
|
2357
|
-
return this._inventory;
|
|
2358
|
-
}
|
|
2359
|
-
get scheduling() {
|
|
2360
|
-
if (!this._scheduling) {
|
|
2361
|
-
this._scheduling = new chunkF7J3HK27_js.SchedulingService(this);
|
|
2362
|
-
}
|
|
2363
|
-
return this._scheduling;
|
|
2364
|
-
}
|
|
2365
|
-
get lite() {
|
|
2366
|
-
if (!this._lite) {
|
|
2367
|
-
this._lite = new chunkF7J3HK27_js.LiteService(this);
|
|
2368
|
-
}
|
|
2369
|
-
return this._lite;
|
|
2370
|
-
}
|
|
2371
|
-
get fx() {
|
|
2372
|
-
if (!this._fx) {
|
|
2373
|
-
this._fx = new chunkF7J3HK27_js.FxService(this);
|
|
2374
|
-
}
|
|
2375
|
-
return this._fx;
|
|
2376
|
-
}
|
|
2377
|
-
get activity() {
|
|
2378
|
-
if (!this._activity) {
|
|
2379
|
-
this._activity = new ActivityService(this);
|
|
2380
|
-
}
|
|
2381
|
-
return this._activity;
|
|
2382
|
-
}
|
|
2383
|
-
get delivery() {
|
|
2384
|
-
if (!this._delivery) {
|
|
2385
|
-
this._delivery = new DeliveryService(this);
|
|
2386
|
-
}
|
|
2387
|
-
return this._delivery;
|
|
2388
|
-
}
|
|
2389
|
-
get support() {
|
|
2390
|
-
if (!this._support) {
|
|
2391
|
-
this._support = new SupportService(this);
|
|
2392
|
-
}
|
|
2393
|
-
return this._support;
|
|
2394
|
-
}
|
|
2395
|
-
get session() {
|
|
2396
|
-
if (!this._session) {
|
|
2397
|
-
this._session = new SessionService(this);
|
|
2398
|
-
}
|
|
2399
|
-
return this._session;
|
|
2400
|
-
}
|
|
2401
|
-
buildWsUrl(path) {
|
|
2402
|
-
const protocol = this.baseUrl.startsWith("https") ? "wss:" : "ws:";
|
|
2403
|
-
const host = this.baseUrl.replace(/^https?:\/\//, "");
|
|
2404
|
-
const params = new URLSearchParams();
|
|
2405
|
-
if (this.publicKey) params.set("api_key", this.publicKey);
|
|
2406
|
-
if (this.sessionToken) params.set("session_token", this.sessionToken);
|
|
2407
|
-
const query = params.toString();
|
|
2408
|
-
return `${protocol}//${host}${path}${query ? `?${query}` : ""}`;
|
|
2409
|
-
}
|
|
2410
|
-
elements(businessId, options) {
|
|
2411
|
-
if (businessId) {
|
|
2412
|
-
this.setBusinessId(businessId);
|
|
2413
|
-
}
|
|
2414
|
-
return chunkF7J3HK27_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
|
|
2415
|
-
}
|
|
2416
|
-
};
|
|
2417
|
-
function createCimplifyClient(config = {}) {
|
|
2418
|
-
return new CimplifyClient(config);
|
|
2419
|
-
}
|
|
2420
|
-
|
|
2421
|
-
exports.ActivityService = ActivityService;
|
|
2422
|
-
exports.CimplifyClient = CimplifyClient;
|
|
2423
|
-
exports.DeliveryService = DeliveryService;
|
|
2424
|
-
exports.HostedPurchaseIntentService = HostedPurchaseIntentService;
|
|
2425
|
-
exports.PURCHASE_INTENT_ROUTE = PURCHASE_INTENT_ROUTE;
|
|
2426
|
-
exports.PlacesService = PlacesService;
|
|
2427
|
-
exports.PurchaseIntentResolver = PurchaseIntentResolver;
|
|
2428
|
-
exports.PurchaseIntentService = PurchaseIntentService;
|
|
2429
|
-
exports.SESSION_CHANGE_SOURCE = SESSION_CHANGE_SOURCE;
|
|
2430
|
-
exports.SessionService = SessionService;
|
|
2431
|
-
exports.StoreCreditQueries = StoreCreditQueries;
|
|
2432
|
-
exports.SubscriptionService = SubscriptionService;
|
|
2433
|
-
exports.SupportService = SupportService;
|
|
2434
|
-
exports.UploadService = UploadService;
|
|
2435
|
-
exports.chatRealtimeUpdateFromWire = chatRealtimeUpdateFromWire;
|
|
2436
|
-
exports.createCimplifyClient = createCimplifyClient;
|