@salla.sa/twilight-theme-engine 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AddToCartForm-VXGCOHDM.js → AddToCartForm-IWVO64M7.js} +3 -3
- package/dist/{AddToCartForm-VXGCOHDM.js.map → AddToCartForm-IWVO64M7.js.map} +1 -1
- package/dist/{BlogAuthorPage-SW4ON5XJ.js → BlogAuthorPage-UONQGYTP.js} +13 -13
- package/dist/{BlogAuthorPage-SW4ON5XJ.js.map → BlogAuthorPage-UONQGYTP.js.map} +1 -1
- package/dist/{BlogCategoryPage-B2DJLJL7.js → BlogCategoryPage-CAJTWGJ6.js} +13 -13
- package/dist/{BlogCategoryPage-B2DJLJL7.js.map → BlogCategoryPage-CAJTWGJ6.js.map} +1 -1
- package/dist/{BlogPage-MHXGHBUO.js → BlogPage-I2IWYXVG.js} +11 -11
- package/dist/{BlogPage-MHXGHBUO.js.map → BlogPage-I2IWYXVG.js.map} +1 -1
- package/dist/{BlogSinglePage-LB26NVFT.js → BlogSinglePage-K5HNRZEZ.js} +11 -11
- package/dist/{BlogSinglePage-LB26NVFT.js.map → BlogSinglePage-K5HNRZEZ.js.map} +1 -1
- package/dist/{BlogTagPage-YGERJE5Q.js → BlogTagPage-4JRERM6S.js} +13 -13
- package/dist/{BlogTagPage-YGERJE5Q.js.map → BlogTagPage-4JRERM6S.js.map} +1 -1
- package/dist/{BrandsPage-IVIOQFUA.js → BrandsPage-CT4FPSXN.js} +11 -11
- package/dist/{BrandsPage-IVIOQFUA.js.map → BrandsPage-CT4FPSXN.js.map} +1 -1
- package/dist/{Breadcrumb-O7G52SSJ.js → Breadcrumb-7PRRXYSW.js} +11 -11
- package/dist/{Breadcrumb-O7G52SSJ.js.map → Breadcrumb-7PRRXYSW.js.map} +1 -1
- package/dist/{CartItem-BKINMGDW.js → CartItem-D2CHYGEH.js} +11 -11
- package/dist/{CartItem-BKINMGDW.js.map → CartItem-D2CHYGEH.js.map} +1 -1
- package/dist/{CartSummary-SWPZE5UA.js → CartSummary-N47IDRQR.js} +11 -11
- package/dist/{CartSummary-SWPZE5UA.js.map → CartSummary-N47IDRQR.js.map} +1 -1
- package/dist/{Copyright-OUFZSYUC.js → Copyright-3PU36ZHD.js} +3 -3
- package/dist/{Copyright-OUFZSYUC.js.map → Copyright-3PU36ZHD.js.map} +1 -1
- package/dist/{CustomerLayout-ANZGEYJT.js → CustomerLayout-WY6V5RLJ.js} +11 -11
- package/dist/{CustomerLayout-ANZGEYJT.js.map → CustomerLayout-WY6V5RLJ.js.map} +1 -1
- package/dist/{Footer-NKQBTZPC.js → Footer-OF6HYDT7.js} +11 -11
- package/dist/{Footer-NKQBTZPC.js.map → Footer-OF6HYDT7.js.map} +1 -1
- package/dist/{Header-I3GZLFSJ.js → Header-LDRXI6GS.js} +4 -4
- package/dist/{Header-I3GZLFSJ.js.map → Header-LDRXI6GS.js.map} +1 -1
- package/dist/{LoyaltyPage-CCSYQCHG.js → LoyaltyPage-WWK4OBN7.js} +12 -12
- package/dist/{LoyaltyPage-CCSYQCHG.js.map → LoyaltyPage-WWK4OBN7.js.map} +1 -1
- package/dist/{MainMenu-DYKJZUXQ.js → MainMenu-G3S7VA6V.js} +6 -6
- package/dist/{MainMenu-DYKJZUXQ.js.map → MainMenu-G3S7VA6V.js.map} +1 -1
- package/dist/{MasterLayout-SYTQADVT.js → MasterLayout-R2SPK6UT.js} +11 -11
- package/dist/{MasterLayout-SYTQADVT.js.map → MasterLayout-R2SPK6UT.js.map} +1 -1
- package/dist/{MobileMenu-EQ5J2E6S.js → MobileMenu-5UTAZN25.js} +12 -12
- package/dist/{MobileMenu-EQ5J2E6S.js.map → MobileMenu-5UTAZN25.js.map} +1 -1
- package/dist/{NotificationsPage-SOTUJ2MC.js → NotificationsPage-OBEEYRYG.js} +11 -11
- package/dist/{NotificationsPage-SOTUJ2MC.js.map → NotificationsPage-OBEEYRYG.js.map} +1 -1
- package/dist/{OrderSinglePage-AZONXICQ.js → OrderSinglePage-GES4DPXH.js} +12 -12
- package/dist/{OrderSinglePage-AZONXICQ.js.map → OrderSinglePage-GES4DPXH.js.map} +1 -1
- package/dist/{OrdersPage-7ESRJSJV.js → OrdersPage-LNSRSB4C.js} +12 -12
- package/dist/{OrdersPage-7ESRJSJV.js.map → OrdersPage-LNSRSB4C.js.map} +1 -1
- package/dist/{PageSingle-OOD3A7VA.js → PageSingle-MFCH3CEI.js} +3 -3
- package/dist/{PageSingle-OOD3A7VA.js.map → PageSingle-MFCH3CEI.js.map} +1 -1
- package/dist/{ProductDetails-N2PG47ZF.js → ProductDetails-IT7NJKFR.js} +3 -3
- package/dist/{ProductDetails-N2PG47ZF.js.map → ProductDetails-IT7NJKFR.js.map} +1 -1
- package/dist/{ProfilePage-OHWKBB6E.js → ProfilePage-3SFVX5TR.js} +11 -11
- package/dist/{ProfilePage-OHWKBB6E.js.map → ProfilePage-3SFVX5TR.js.map} +1 -1
- package/dist/{SeoCartWidget-JV64FLXE.js → SeoCartWidget-S6OZ55C4.js} +11 -11
- package/dist/{SeoCartWidget-JV64FLXE.js.map → SeoCartWidget-S6OZ55C4.js.map} +1 -1
- package/dist/{SettingsPage-ADRCOT7F.js → SettingsPage-B6PQYWWH.js} +11 -11
- package/dist/{SettingsPage-ADRCOT7F.js.map → SettingsPage-B6PQYWWH.js.map} +1 -1
- package/dist/{StoreClosedNotification-FTYE7ZL3.js → StoreClosedNotification-JLYGKTZH.js} +12 -12
- package/dist/{StoreClosedNotification-FTYE7ZL3.js.map → StoreClosedNotification-JLYGKTZH.js.map} +1 -1
- package/dist/{TestimonialsPage-FBCNAU5C.js → TestimonialsPage-CZ2LIFOH.js} +3 -3
- package/dist/{TestimonialsPage-FBCNAU5C.js.map → TestimonialsPage-CZ2LIFOH.js.map} +1 -1
- package/dist/{ThankYouPage-SB53OMFR.js → ThankYouPage-IGGPBXT2.js} +11 -11
- package/dist/{ThankYouPage-SB53OMFR.js.map → ThankYouPage-IGGPBXT2.js.map} +1 -1
- package/dist/{WalletPage-XG37YGN7.js → WalletPage-RQBVIZV4.js} +12 -12
- package/dist/{WalletPage-XG37YGN7.js.map → WalletPage-RQBVIZV4.js.map} +1 -1
- package/dist/{WishlistPage-PM37IPUH.js → WishlistPage-LBU6IZAK.js} +12 -12
- package/dist/{WishlistPage-PM37IPUH.js.map → WishlistPage-LBU6IZAK.js.map} +1 -1
- package/dist/api/apps.js +3 -3
- package/dist/api/brands.js +3 -3
- package/dist/api/cart.js +3 -3
- package/dist/api/category.js +3 -3
- package/dist/api/client.d.ts +9 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +2 -2
- package/dist/api/home.js +3 -3
- package/dist/api/loyalty.js +3 -3
- package/dist/api/menu.js +3 -3
- package/dist/api/notification.js +3 -3
- package/dist/api/order.js +3 -3
- package/dist/api/page.js +3 -3
- package/dist/api/product.js +3 -3
- package/dist/api/profile.js +2 -2
- package/dist/api/store.d.ts +2 -24
- package/dist/api/store.d.ts.map +1 -1
- package/dist/api/store.js +3 -3
- package/dist/api/translations.js +3 -3
- package/dist/api/user.js +3 -3
- package/dist/api/wishlist.js +3 -3
- package/dist/{chunk-GUAM3RX2.js → chunk-3KRYKGMY.js} +3 -3
- package/dist/{chunk-GUAM3RX2.js.map → chunk-3KRYKGMY.js.map} +1 -1
- package/dist/{chunk-4HXLDKIV.js → chunk-3MEAEE7K.js} +3 -3
- package/dist/{chunk-4HXLDKIV.js.map → chunk-3MEAEE7K.js.map} +1 -1
- package/dist/{chunk-GLRQJVTK.js → chunk-3Z7TBM7W.js} +3 -3
- package/dist/{chunk-GLRQJVTK.js.map → chunk-3Z7TBM7W.js.map} +1 -1
- package/dist/{chunk-C7ZFBA7A.js → chunk-66CUW6VR.js} +4 -4
- package/dist/{chunk-C7ZFBA7A.js.map → chunk-66CUW6VR.js.map} +1 -1
- package/dist/{chunk-AIODAVGT.js → chunk-6MREJTVB.js} +3 -3
- package/dist/{chunk-AIODAVGT.js.map → chunk-6MREJTVB.js.map} +1 -1
- package/dist/{chunk-NGGPWAAN.js → chunk-75HMCUTB.js} +3 -3
- package/dist/{chunk-NGGPWAAN.js.map → chunk-75HMCUTB.js.map} +1 -1
- package/dist/{chunk-SSZUSUPD.js → chunk-ALUEX3YC.js} +3 -3
- package/dist/{chunk-SSZUSUPD.js.map → chunk-ALUEX3YC.js.map} +1 -1
- package/dist/{chunk-P5M6ZWBT.js → chunk-AU7PMZV4.js} +3 -3
- package/dist/{chunk-P5M6ZWBT.js.map → chunk-AU7PMZV4.js.map} +1 -1
- package/dist/{chunk-5V5MFZEC.js → chunk-C3UUGHTX.js} +3 -3
- package/dist/{chunk-5V5MFZEC.js.map → chunk-C3UUGHTX.js.map} +1 -1
- package/dist/{chunk-BJPYNISN.js → chunk-DOOZU75W.js} +3 -3
- package/dist/{chunk-BJPYNISN.js.map → chunk-DOOZU75W.js.map} +1 -1
- package/dist/{chunk-6CRRDUBY.js → chunk-EIFCJLBN.js} +3 -3
- package/dist/{chunk-6CRRDUBY.js.map → chunk-EIFCJLBN.js.map} +1 -1
- package/dist/{chunk-7TI7IGND.js → chunk-ELOCFIZE.js} +5 -5
- package/dist/{chunk-7TI7IGND.js.map → chunk-ELOCFIZE.js.map} +1 -1
- package/dist/{chunk-BQDXQ6P7.js → chunk-EXRS5IAC.js} +3 -3
- package/dist/{chunk-BQDXQ6P7.js.map → chunk-EXRS5IAC.js.map} +1 -1
- package/dist/{chunk-EQYBGXF4.js → chunk-EZSYN4P3.js} +8 -5
- package/dist/chunk-EZSYN4P3.js.map +1 -0
- package/dist/{chunk-WBHBCGQI.js → chunk-F27YMAOM.js} +3 -3
- package/dist/{chunk-WBHBCGQI.js.map → chunk-F27YMAOM.js.map} +1 -1
- package/dist/chunk-FE6ULRVJ.js +14 -0
- package/dist/{chunk-MRITQZH2.js.map → chunk-FE6ULRVJ.js.map} +1 -1
- package/dist/{chunk-HUPUM4VJ.js → chunk-GL3ZWX64.js} +3 -3
- package/dist/{chunk-HUPUM4VJ.js.map → chunk-GL3ZWX64.js.map} +1 -1
- package/dist/{chunk-JYF7VBSH.js → chunk-I4PD6BEP.js} +3 -3
- package/dist/{chunk-JYF7VBSH.js.map → chunk-I4PD6BEP.js.map} +1 -1
- package/dist/{chunk-ZYMBBAEK.js → chunk-IK6X5HMK.js} +3 -3
- package/dist/{chunk-ZYMBBAEK.js.map → chunk-IK6X5HMK.js.map} +1 -1
- package/dist/{chunk-RM33XVYB.js → chunk-JTJKKF6S.js} +11 -11
- package/dist/{chunk-RM33XVYB.js.map → chunk-JTJKKF6S.js.map} +1 -1
- package/dist/{chunk-W7IJFM5X.js → chunk-K5V67DOI.js} +8 -8
- package/dist/{chunk-W7IJFM5X.js.map → chunk-K5V67DOI.js.map} +1 -1
- package/dist/{chunk-P2SWZ265.js → chunk-NGYYCFTS.js} +3 -3
- package/dist/{chunk-P2SWZ265.js.map → chunk-NGYYCFTS.js.map} +1 -1
- package/dist/{chunk-57C2UPS7.js → chunk-NMOAEWI6.js} +6 -6
- package/dist/{chunk-57C2UPS7.js.map → chunk-NMOAEWI6.js.map} +1 -1
- package/dist/{chunk-GSNKBCDJ.js → chunk-NR2XM4KT.js} +3 -3
- package/dist/{chunk-GSNKBCDJ.js.map → chunk-NR2XM4KT.js.map} +1 -1
- package/dist/{chunk-W3V547Y7.js → chunk-OEGDGMRX.js} +3 -3
- package/dist/{chunk-W3V547Y7.js.map → chunk-OEGDGMRX.js.map} +1 -1
- package/dist/{chunk-ZYKBHBBH.js → chunk-QZ6I5CA7.js} +10 -23
- package/dist/chunk-QZ6I5CA7.js.map +1 -0
- package/dist/{chunk-EQZNBNXU.js → chunk-WBLT4Y4A.js} +5 -5
- package/dist/{chunk-EQZNBNXU.js.map → chunk-WBLT4Y4A.js.map} +1 -1
- package/dist/{chunk-H5MWYWOK.js → chunk-WS4563U3.js} +5 -5
- package/dist/{chunk-H5MWYWOK.js.map → chunk-WS4563U3.js.map} +1 -1
- package/dist/{chunk-RCH73ORE.js → chunk-YFINXDSK.js} +4 -4
- package/dist/{chunk-RCH73ORE.js.map → chunk-YFINXDSK.js.map} +1 -1
- package/dist/{chunk-QCWPF7W4.js → chunk-YZUNEFDM.js} +21 -14
- package/dist/chunk-YZUNEFDM.js.map +1 -0
- package/dist/{chunk-3CPZ4SMV.js → chunk-ZAJOW3MZ.js} +3 -3
- package/dist/{chunk-3CPZ4SMV.js.map → chunk-ZAJOW3MZ.js.map} +1 -1
- package/dist/{chunk-IK2A36AH.js → chunk-ZCLXL3VH.js} +3 -3
- package/dist/{chunk-IK2A36AH.js.map → chunk-ZCLXL3VH.js.map} +1 -1
- package/dist/components/cart/index.js +1 -1
- package/dist/components/common/index.js +1 -1
- package/dist/components/drawer/index.js +9 -9
- package/dist/components/home/index.js +12 -12
- package/dist/components/layout/index.js +5 -5
- package/dist/components/product/index.js +10 -10
- package/dist/components/store/index.js +11 -11
- package/dist/{document-class-VVEBZ36M.js → document-class-44DOTPY6.js} +9 -9
- package/dist/{document-class-VVEBZ36M.js.map → document-class-44DOTPY6.js.map} +1 -1
- package/dist/hooks/index.js +9 -9
- package/dist/hooks/useGtm.js +9 -9
- package/dist/hooks/useMoney.js +9 -9
- package/dist/hooks/useStore.js +9 -9
- package/dist/hooks/useUser.js +4 -4
- package/dist/index.js +9 -9
- package/dist/{not-found-ZOHONXYT.js → not-found-XS5AQUB3.js} +11 -11
- package/dist/{not-found-ZOHONXYT.js.map → not-found-XS5AQUB3.js.map} +1 -1
- package/dist/providers/index.js +9 -9
- package/dist/routes/account/orders.js +4 -4
- package/dist/routes/account.js +12 -12
- package/dist/routes/blog.js +8 -8
- package/dist/routes/brands.js +4 -4
- package/dist/routes/cart.js +17 -17
- package/dist/routes/home.js +14 -14
- package/dist/routes/loyalty.js +4 -4
- package/dist/routes/page.js +4 -4
- package/dist/routes/product-listing.js +14 -14
- package/dist/routes/product.js +12 -12
- package/dist/routes/testimonials.js +1 -1
- package/dist/routes/thank-you.js +4 -4
- package/dist/skeleton.js +14 -14
- package/dist/tanstack.js +8 -8
- package/dist/utils/cookies.d.ts +11 -0
- package/dist/utils/cookies.d.ts.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist/utils/runtime-env.d.ts.map +1 -1
- package/dist/utils/sdk-helpers.d.ts +10 -4
- package/dist/utils/sdk-helpers.d.ts.map +1 -1
- package/dist/utils/store-identity.d.ts +28 -0
- package/dist/utils/store-identity.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-EQYBGXF4.js.map +0 -1
- package/dist/chunk-MRITQZH2.js +0 -14
- package/dist/chunk-QCWPF7W4.js.map +0 -1
- package/dist/chunk-ZYKBHBBH.js.map +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which store to ask about, in the order the answers can be trusted.
|
|
3
|
+
*
|
|
4
|
+
* A deployed theme worker is published with **no vars and no bindings** — the
|
|
5
|
+
* script metadata carries `main_module`, compatibility settings, assets and tags
|
|
6
|
+
* and nothing else — so `VITE_STORE_DOMAIN` exists only where a build baked it
|
|
7
|
+
* in, which is local development. In production this function used to reach the
|
|
8
|
+
* end of that chain and return the empty string, `store.settings` refused to
|
|
9
|
+
* call with no identifier, and the root loader threw "Store Unavailable" — a
|
|
10
|
+
* theme that renders its own failure page for every visitor of every store.
|
|
11
|
+
*
|
|
12
|
+
* The order:
|
|
13
|
+
*
|
|
14
|
+
* 1. what the caller passed, which is always deliberate;
|
|
15
|
+
* 2. the store this request names — the `?storeId=` a preview was opened with,
|
|
16
|
+
* then the cookie remembering it — seeded by `twilightMiddleware`, and only
|
|
17
|
+
* on a host permitted to name one;
|
|
18
|
+
* 3. what SSR already resolved and published, so the hydrated client asks about
|
|
19
|
+
* the same store the server rendered instead of resolving again from a URL
|
|
20
|
+
* that no longer names it;
|
|
21
|
+
* 4. the request's own host, which *is* the identity of a live storefront —
|
|
22
|
+
* but only when that host is a storefront. `preview.salla.design` and
|
|
23
|
+
* `localhost` serve many stores, so their names identify none;
|
|
24
|
+
* 5. `VITE_STORE_DOMAIN`, last, because a build-time constant is a development
|
|
25
|
+
* convenience and must never outrank what the request actually said.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveStoreIdentifier(explicit?: string): string;
|
|
28
|
+
//# sourceMappingURL=store-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store-identity.d.ts","sourceRoot":"","sources":["../../src/utils/store-identity.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAiBhE"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/client.ts"],"names":[],"mappings":";;;;;;AAqBA,IAAM,iBAAA,GAAoB,kBAAA,EAAmB,CAC1C,MAAA,CAAO,MAAqB;AAC3B,EAAA,IAAI;AACF,IAAA,OAAO,SAAA,CAAU,sBAAsB,CAAA,IAAK,IAAA;AAAA,EAC9C,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF,CAAC,CAAA,CACA,OAAO,MAAqB;AAC3B,EAAA,MAAM,UAAA,GACJ,OAAO,QAAA,KAAa,WAAA,GAChB,wBAAwB,QAAA,CAAS,MAAA,EAAQ,sBAAsB,CAAA,GAC/D,IAAA;AACN,EAAA,IAAI,YAAY,OAAO,UAAA;AACvB,EAAA,MAAM,UAAU,OAAO,MAAA,KAAW,WAAA,GAAc,MAAA,CAAO,OAAO,OAAA,GAAU,MAAA;AACxE,EAAA,MAAM,WAAA,GACJ,OAAO,OAAA,EAAS,GAAA,KAAQ,aAAa,OAAA,CAAQ,GAAA,CAAI,sBAAsB,CAAA,GAAI,IAAA;AAC7E,EAAA,IAAI,OAAO,WAAA,KAAgB,QAAA,IAAY,WAAA,EAAa,OAAO,WAAA;AAE3D,EAAA,MAAM,aAAa,OAAO,MAAA,KA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IAAA,EAAM;AACrB,YAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,WAAA,CAAY,UAAA,EAAY,MAAA,CAAO,SAAS,CAAC,CAAA;AAAA,UAC/D;AAAA,QACF,CAAA,CAAA,MAAQ;AAAA,QAER;AAEA,QAAA,MAAM,KAAA,GAAQ,aAAa,iBAAA,EAAkB;AAC7C,QAAA,IAAI,KAAA,EAAO;AACT,UAAA,OAAA,CAAQ,QAAQ,GAAA,CAAI,WAAA,CAAY,aAAA,EAAe,CAAA,OAAA,EAAU,KAAK,CAAA,CAAE,CAAA;AAAA,QAClE;AAEA,QAAA,MAAM,UAAU,gBAAA,EAAiB;AACjC,QAAA,IAAI,WAAW,IAAA,EAAM;AACnB,UAAA,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,WAAA,CAAY,QAAA,EAAU,OAAO,CAAA;AAAA,QACnD;AAAA,MACF;AAAA;AACF;AAEJ,CAAC;AAEM,IAAM,GAAA,GAAM,GAAG,MAAA,CAAO;AAAA,EAC3B,MAAA,EAAQ,2BAAA;AAAA,EACR,OAAA,EAAS;AACX,CAAC","file":"chunk-EQYBGXF4.js","sourcesContent":["import ky from 'ky';\nimport { createIsomorphicFn } from '@tanstack/react-start';\nimport { getCookie } from '@tanstack/react-start/server';\nimport { getStoreIdentifier } from '../utils/sdk-helpers';\n// import { getInjectedRuntimeEnv, readEnv } from '../utils/runtime-env';\nimport { getTwilightContext } from '../twilight/context';\nimport {\n AUTH_TOKEN_COOKIE_NAME,\n extractScopeIdFromCookies,\n extractTokenFromCookies,\n readSdkScopeId,\n} from '../utils/cookies';\n\n// The twilight module store doesn't reliably carry authToken into every scope: on the\n// SERVER workerd has no AsyncLocalStorage, and on BOTH sides this api client can live in a\n// different module instance than the one rootBeforeLoad populates (engine subpath import vs\n// engine-internal relative import). So `getTwilightContext().authToken` is often null even\n// for logged-in users → API calls (orders/customer/…) return `token_not_provided` (400).\n// Read the token directly from the request cookie (server) or document.cookie / salla.storage\n// (client) as a fallback. The server-only import is stripped from the client bundle by\n// createIsomorphicFn.\nconst readFallbackToken = createIsomorphicFn()\n .server((): string | null => {\n try {\n return getCookie(AUTH_TOKEN_COOKIE_NAME) ?? null;\n } catch {\n return null;\n }\n })\n .client((): string | null => {\n const fromCookie =\n typeof document !== 'undefined'\n ? extractTokenFromCookies(document.cookie, AUTH_TOKEN_COOKIE_NAME)\n : null;\n if (fromCookie) return fromCookie;\n const storage = typeof window !== 'undefined' ? window.salla?.storage : undefined;\n const fromStorage =\n typeof storage?.get === 'function' ? storage.get(AUTH_TOKEN_COOKIE_NAME) : null;\n if (typeof fromStorage === 'string' && fromStorage) return fromStorage;\n // `?token=` webview injection lands only on the SDK's axios instance\n const fromSdkApi = typeof window !== 'undefined' ? window.salla?.api?.token : undefined;\n return typeof fromSdkApi === 'string' && fromSdkApi ? fromSdkApi : null;\n });\n\n/**\n * The auth token as the api client sees it: twilight context first, cookie/storage fallback.\n * Use this (not `getTwilightContext().authToken`, which is often null for logged-in users —\n * see the note above) to decide whether an authenticated-only query should run.\n */\nexport const getAuthToken = (): string | null =>\n getTwilightContext().authToken ?? readFallbackToken();\n\nconst API_HEADERS = {\n ACCEPT: 'accept',\n ACCEPT_LANGUAGE: 'accept-language',\n APP_OS: 's-app-os',\n APP_VERSION: 's-app-version',\n RAY: 's-ray',\n SOURCE: 's-source',\n THEME_TYPE: 's-theme-type',\n STORE_API_VERSION: 's-store-api-version',\n REQUESTED_WITH: 'x-requested-with',\n CF_PROXY_WHITELIST: 's-cf-proxy-whitelist-id',\n STORE_IDENTIFIER: 'store-identifier',\n AUTHORIZATION: 'Authorization',\n VERSION_ID: 's-version-id',\n SCOPE_ID: 's-scope-id',\n} as const;\n\n/**\n * Active branch/scope id. On the client it comes from the branch Salla persists\n * in storage (`salla.storage.get('scope').id`); before the SDK hydrates storage it\n * falls back to the `scope` cookie the theme mirrors that selection into\n * (see writeScopeCookie), then to the id twilightMiddleware seeded from the same\n * cookie on the server. Requests vary by `s-scope-id`, so React Query keys must\n * include this to avoid serving another scope's cached categories/products.\n *\n * The cookie step matters for hydration: the SDK is not guaranteed to have\n * populated `salla.storage` by the time the client rebuilds a dehydrated query\n * key, and without it the client would compute null against a scoped SSR key.\n */\nexport const getActiveScopeId = (): string | null => {\n // `!== undefined`, not `!= null`: a null here is the SDK authoritatively saying \"no branch\n // selected\", which must beat a cookie left over from the previous selection. Only a\n // not-yet-ready storage API (undefined) falls through to the cookie.\n const fromStorage = readSdkScopeId();\n if (fromStorage !== undefined) return fromStorage;\n\n if (typeof document !== 'undefined') {\n const fromCookie = extractScopeIdFromCookies(document.cookie);\n if (fromCookie != null) return fromCookie;\n }\n\n try {\n const { scopeId } = getTwilightContext();\n return scopeId != null ? String(scopeId) : null;\n } catch {\n return null;\n }\n};\n\nconst sharedHeaders = (locale: string) => ({\n [API_HEADERS.ACCEPT]: 'application/json' as const,\n [API_HEADERS.ACCEPT_LANGUAGE]: locale,\n [API_HEADERS.APP_OS]: 'browser',\n [API_HEADERS.APP_VERSION]: '2.14.363',\n [API_HEADERS.RAY]: '50',\n [API_HEADERS.SOURCE]: 'twilight',\n [API_HEADERS.THEME_TYPE]: 'react',\n [API_HEADERS.STORE_API_VERSION]: 'swoole',\n [API_HEADERS.REQUESTED_WITH]: 'XMLHttpRequest',\n [API_HEADERS.CF_PROXY_WHITELIST]: '019a2f78-a64c-7edb-proxy-whitelist-id-9a3a-17afda90f03a',\n});\n\n/**\n * Store API base. `VITE_API_URL` override points a preview at a branch backend; unset → prod\n * `api.salla.dev`. Resolution order matters: the value the SSR worker resolved (published into\n * the head, since worker `vars` are server-only `process.env` and never reach the browser\n * bundle) wins, so the hydrated client keeps talking to the backend that rendered the page.\n */\n\n// const STORE_API_BASE = getInjectedRuntimeEnv().apiBase || readEnv('VITE_API_URL') || 'https://api.salla.dev/store/v1';\n\nexport const api = ky.extend({\n prefix: 'https://api.salla.dev/store/v1', // TODO: check env\n timeout: 8000,\n hooks: {\n beforeRequest: [\n ({ request }) => {\n const { locale, authToken } = getTwilightContext();\n const headers = sharedHeaders(locale);\n for (const [key, value] of Object.entries(headers)) {\n request.headers.set(key, value);\n }\n request.headers.set(API_HEADERS.STORE_IDENTIFIER, getStoreIdentifier());\n\n try {\n const profileId = getTwilightContext().settings?.theme?.profile?.id;\n if (profileId != null) {\n request.headers.set(API_HEADERS.VERSION_ID, String(profileId));\n }\n } catch {\n // settings not loaded yet — skip VERSION_ID header\n }\n\n const token = authToken ?? readFallbackToken();\n if (token) {\n request.headers.set(API_HEADERS.AUTHORIZATION, `Bearer ${token}`);\n }\n\n const scopeId = getActiveScopeId();\n if (scopeId != null) {\n request.headers.set(API_HEADERS.SCOPE_ID, scopeId);\n }\n },\n ],\n },\n});\n\nexport const cdn = ky.extend({\n prefix: 'https://cdn.salla.network',\n timeout: 5000,\n});\n"]}
|
package/dist/chunk-MRITQZH2.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { lazy } from 'react';
|
|
2
|
-
|
|
3
|
-
// src/components/cart/lazy.ts
|
|
4
|
-
var LazyCartItem = lazy(() => import('./CartItem-BKINMGDW.js').then((m) => ({ default: m.CartItem })));
|
|
5
|
-
var LazyCartSummary = lazy(
|
|
6
|
-
() => import('./CartSummary-SWPZE5UA.js').then((m) => ({ default: m.CartSummary }))
|
|
7
|
-
);
|
|
8
|
-
var LazySeoCartWidget = lazy(
|
|
9
|
-
() => import('./SeoCartWidget-JV64FLXE.js').then((m) => ({ default: m.SeoCartWidget }))
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export { LazyCartItem, LazyCartSummary, LazySeoCartWidget };
|
|
13
|
-
//# sourceMappingURL=chunk-MRITQZH2.js.map
|
|
14
|
-
//# sourceMappingURL=chunk-MRITQZH2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/cookies.ts","../src/utils/inline-script.ts","../src/utils/runtime-env.ts","../src/utils/sdk-helpers.ts"],"names":[],"mappings":";;;AAAO,IAA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AM,OAAA,GAAW,YAAoB,GAAA,EAAK,iBAAA;AAC1C,IAAA,IAAI,SAAS,OAAO,OAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AAAA,EAER;AACA,EAAA,MAAM,QAAA,GAAW,uBAAsB,CAAE,eAAA;AACzC,EAAA,IAAI,UAAU,OAAO,QAAA;AACrB,EAAA,IAAI,SAAA,EAAW,OAAO,MAAA,CAAO,QAAA,CAAS,IAAA;AACtC,EAAA,OACG,OAAO,YAAY,WAAA,KACjB,OAAA,CAAQ,KAAK,iBAAA,IAAqB,OAAA,CAAQ,KAAK,YAAA,CAAA,IAClD,EAAA;AAEJ;AAKO,SAAS,WAAA,GAA+C;AAC7D,EAAA,IAAI,CAAC,WAAW,OAAO,MAAA;AACvB,EAAA,OAAO,MAAA,CAAO,KAAA;AAChB;AAoBO,SAAS,cAAc,MAAA,EAAsB;AAClD,EAAA,MAAM,MAAM,WAAA,EAAY;AACxB,EAAA,IAAI,CAAC,GAAA,IAAO,CAAC,MAAA,EAAQ;AACrB,EAAA,IAAI;AACF,IAAA,GAAA,CAAI,IAAA,EAAM,YAAY,MAAM,CAAA;AAC5B,IAAA,GAAA,CAAI,GAAA,EAAK,SAAA,GAAY,iBAAA,EAAmB,MAAM,CAAA;AAG9C,IAAA,GAAA,CAAI,MAAA,EAAQ,GAAA,GAAM,oBAAA,EAAsB,MAAM,CAAA;AAAA,EAChD,CAAA,CAAA,MAAQ;AAAA,EAER;AACF","file":"chunk-QCWPF7W4.js","sourcesContent":["export const AUTH_TOKEN_COOKIE_NAME = 'token';\nexport const SCOPE_COOKIE_NAME = 'scope';\n\n/**\n * Which store this request is for, when the hostname does not say.\n *\n * A live storefront is reached at its own domain, so the hostname identifies it\n * and nothing else is needed. A preview is not: every theme under review is\n * served from the one preview hostname, so the store has to be named some other\n * way — the dispatcher takes it from `?storeId=` and puts it here, the same way\n * it remembers which theme to serve.\n *\n * Written by the dispatcher rather than the theme, and set on the *forwarded\n * request* as well as the response, because the response cookie only arrives in\n * time for the second page load and the first one has to render too.\n *\n * The literal is a contract with `STORE_COOKIE` in store-front-dispacher\n * (`src/dispatch/preview.ts`), and **nothing checks the two agree**. Drift does\n * not fail loudly — it renders somebody else's shop. Grep both repos before\n * changing it.\n */\nexport const STORE_ID_COOKIE_NAME = 'salla_sid';\n\n/** Query parameter naming the store, on a host that serves more than one. */\nexport const STORE_ID_PARAM = 'storeId';\n\n/**\n * A store id is an integer, and anything else is not a store id.\n *\n * Validated rather than passed through because this value ends up in an upstream\n * API path. Leading zeroes, signs, decimals and whitespace are all rejected: the\n * point is a single canonical form, not the widest set of things that could be\n * coerced into a number.\n */\nexport function parseStoreId(raw: string | null | undefined): string | null {\n if (!raw) return null;\n return /^[1-9][0-9]{0,18}$/.test(raw) ? raw : null;\n}\n\n/** The store id the dispatcher left in the cookie, or null when absent or malformed. */\nexport function extractStoreIdFromCookies(cookieHeader: string | null): string | null {\n return parseStoreId(extractTokenFromCookies(cookieHeader, STORE_ID_COOKIE_NAME));\n}\n\n/**\n * The only hosts on which a request may name its own store.\n *\n * **This is a security boundary, not a convenience.** On a merchant's own domain\n * the hostname *is* the store, and it is the only thing that may decide. A theme\n * that also honoured `?storeId=` there would let anyone open\n * `https://reefperfumes.com/?storeId=<someone else>` and be served a different\n * merchant's shop from the domain its owner controls — their branding, their\n * customers' address bar, somebody else's catalogue — and the cookie would keep\n * serving it for the rest of that browser's session. Salla points SaaS domains\n * at this dispatcher, so those hostnames are real and reachable.\n *\n * The override exists for one situation: a host that serves many stores and so\n * cannot identify one from its name. That is the preview host, where every theme\n * under review answers on the same address, and local development.\n *\n * Adding an entry grants that host the ability to render any store on request.\n * Add nothing that a merchant's traffic reaches.\n */\nexport const STORE_ID_HOSTS: readonly string[] = ['preview.salla.design'];\n\n/** The hostname alone — a port never distinguishes one host's authority from another's. */\nfunction hostnameOf(host: string): string {\n const trimmed = host.trim().toLowerCase();\n // IPv6 literals are bracketed, and the colons inside them are not a port.\n if (trimmed.startsWith('[')) return trimmed.slice(0, trimmed.indexOf(']') + 1) || trimmed;\n const colon = trimmed.indexOf(':');\n return colon === -1 ? trimmed : trimmed.slice(0, colon);\n}\n\nfunction isLoopback(hostname: string): boolean {\n return (\n hostname === 'localhost' ||\n hostname === '127.0.0.1' ||\n hostname === '[::1]' ||\n hostname.endsWith('.localhost')\n );\n}\n\n/**\n * Whether this host is allowed to let the request choose a store.\n *\n * Deliberately an allowlist of exact hostnames plus loopback. No suffix matching:\n * a rule like \"anything ending in salla.design\" is one wildcard DNS record away\n * from admitting a host nobody meant to admit, and the list of hosts that serve\n * more than one store is short and known.\n */\nexport function allowsRequestStoreId(host: string | null | undefined): boolean {\n if (!host) return false;\n const hostname = hostnameOf(host);\n return STORE_ID_HOSTS.includes(hostname) || isLoopback(hostname);\n}\n\n/**\n * The store this request names, on a host permitted to name one.\n *\n * The host check is inside this function rather than at its call site, because a\n * call site is a thing someone can add without reading this comment. There is no\n * way to ask \"what store did the request name?\" without also asking \"is this a\n * host that may say?\" — get it wrong and the answer is a security bug that looks\n * like a feature.\n *\n * Between the two permitted sources the URL wins, the same precedence the\n * dispatcher uses for the theme and for the same reason: a link is how someone\n * switches, and a cookie they cannot see should never beat the address they\n * just typed.\n */\nexport function resolveRequestStoreId(\n url: string,\n cookieHeader: string | null,\n host: string | null | undefined\n): string | null {\n if (!allowsRequestStoreId(host)) return null;\n\n let fromQuery: string | null = null;\n try {\n fromQuery = parseStoreId(new URL(url).searchParams.get(STORE_ID_PARAM));\n } catch {\n /* a relative or malformed URL simply names no store */\n }\n return fromQuery ?? extractStoreIdFromCookies(cookieHeader);\n}\n\n/**\n * Deletes the auth `token` cookie. This cookie is written client-side by the theme\n * (TwilightProvider), not by the SDK — `salla.cookie.clearAll()` only clears its own\n * allowlist and leaves `token` behind — so logout must clear it here. Client-only.\n */\nexport function clearAuthTokenCookie(): void {\n if (typeof document === 'undefined') return;\n document.cookie = `${AUTH_TOKEN_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;\n}\n\nexport function extractTokenFromCookies(\n cookieHeader: string | null,\n cookieName: string\n): string | null {\n if (!cookieHeader) return null;\n\n const prefix = `${cookieName}=`;\n let start = 0;\n\n while (start < cookieHeader.length) {\n const idx = cookieHeader.indexOf(prefix, start);\n if (idx === -1) return null;\n\n const prevChar = idx > 0 ? cookieHeader[idx - 1] : '';\n if (prevChar === '' || prevChar === ';' || prevChar === ' ') {\n let end = cookieHeader.indexOf(';', idx);\n if (end === -1) end = cookieHeader.length;\n\n const value = cookieHeader.slice(idx + prefix.length, end).trim();\n try {\n return decodeURIComponent(value) || null;\n } catch {\n return value || null;\n }\n }\n\n start = idx + prefix.length;\n }\n\n return null;\n}\n\n/**\n * Reads the active scope id from the `scope` cookie, which Salla persists as a\n * JSON object (e.g. `{\"id\":123,\"type\":\"branch\"}`). Returns null when the cookie\n * is missing or unparseable. Used server-side, where `salla.storage` is absent.\n */\nexport function extractScopeIdFromCookies(cookieHeader: string | null): string | null {\n const raw = extractTokenFromCookies(cookieHeader, SCOPE_COOKIE_NAME);\n if (!raw) return null;\n try {\n const scope = JSON.parse(raw) as { id?: number | string | null };\n return scope?.id != null ? String(scope.id) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * The branch the Salla SDK persisted in its storage (`salla.storage.get('scope')`),\n * which it stores either as `{ id, type }` or as a bare id.\n *\n * Returns `undefined` when the SDK storage API isn't ready yet — deliberately\n * distinct from `null` (\"no branch selected\"), so callers can't mistake a\n * not-yet-hydrated SDK for a cleared selection. Client-only.\n */\nexport function readSdkScopeId(): string | null | undefined {\n const storage = typeof window !== 'undefined' ? window.salla?.storage : undefined;\n if (typeof storage?.get !== 'function') return undefined;\n\n const scope = storage.get(SCOPE_COOKIE_NAME) as\n { id?: number | string | null } | number | string | null;\n const id = typeof scope === 'object' && scope !== null ? scope.id : scope;\n return id != null ? String(id) : null;\n}\n\n/** One year — the SDK keeps the selected branch in localStorage indefinitely. */\nconst SCOPE_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;\n\n/**\n * Mirrors the branch the Salla SDK selected into the `scope` cookie so the SERVER\n * can see it. The SDK persists the selection in localStorage ONLY and writes no\n * cookie, so without this the server computes scope=null for every visitor who\n * picked a branch while the client computes the branch id — the dehydrated settings\n * query key never matches and the client refetches store settings on every page\n * load (SAL-122).\n *\n * Written in the SDK's own JSON shape so {@link extractScopeIdFromCookies} parses it.\n * Returns true when the cookie was (re)written. Client-only; no-op on the server.\n */\nexport function writeScopeCookie(scopeId: string | null): boolean {\n if (typeof document === 'undefined') return false;\n if (extractScopeIdFromCookies(document.cookie) === scopeId) return false;\n\n if (scopeId == null) {\n document.cookie = `${SCOPE_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;\n return true;\n }\n\n const value = encodeURIComponent(JSON.stringify({ id: scopeId }));\n document.cookie = `${SCOPE_COOKIE_NAME}=${value}; path=/; max-age=${SCOPE_COOKIE_MAX_AGE}; samesite=lax`;\n return true;\n}\n\n/**\n * Keeps the `scope` cookie in step with the SDK's selected branch. Call on every\n * client navigation; it no-ops while the SDK storage API is still hydrating so a\n * late-loading SDK can't wipe a valid cookie.\n */\nexport function syncScopeCookie(): boolean {\n const scopeId = readSdkScopeId();\n return scopeId === undefined ? false : writeScopeCookie(scopeId);\n}\n","/**\n * Escape a JSON-stringified value for safe embedding inside an inline `<script>` body.\n *\n * The head injects script bodies raw, so a `</script>` inside partner-set data would break out\n * of the tag; U+2028/U+2029 are line terminators in JS but not in JSON, so they must go too.\n */\nexport function escapeForInlineScript(value: string): string {\n return value\n .replace(/</g, '\\\\u003c')\n .replace(/>/g, '\\\\u003e')\n .replace(/&/g, '\\\\u0026')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n","import { escapeForInlineScript } from './inline-script';\nimport { getRequestStore } from '../twilight/context';\n\n/** Where `rootHead` publishes the SSR-resolved env for the browser bundle to read. */\nconst RUNTIME_ENV_KEY = '__SALLA_RUNTIME_ENV__';\n\n/** The env values that must agree between the SSR render and the hydrated client. */\nexport interface RuntimeEnv {\n /** Store API base — `VITE_API_URL`. */\n apiBase?: string;\n /** Store identifier — `VITE_STORE_DOMAIN`. */\n storeIdentifier?: string;\n}\n\n/**\n * A build-time `import.meta.env` var, falling back to the worker's runtime `process.env`\n * (wrangler `vars`, exposed via the `nodejs_compat_populate_process_env` flag).\n */\nexport function readEnv(key: string): string | undefined {\n try {\n const vite = (import.meta as unknown as { env?: Record<string, string | undefined> }).env?.[\n key\n ];\n if (vite) return vite;\n } catch {\n /* import.meta.env not available in all environments */\n }\n return typeof process !== 'undefined' ? process.env?.[key] : undefined;\n}\n\n/**\n * What this runtime resolves from its own env — server-side that includes the worker vars.\n * Prefers what the server already published, so re-rendering the head during hydration yields\n * the same script instead of dropping it.\n */\nexport function resolveRuntimeEnv(): RuntimeEnv {\n const injected = getInjectedRuntimeEnv();\n const { storeId, requestHost } = getRequestStore();\n return {\n apiBase: injected.apiBase || readEnv('VITE_API_URL'),\n // The request outranks the build-time var here for the same reason it does\n // in `resolveStoreIdentifier`, and this is the copy that reaches the\n // browser: publish the store SSR actually rendered, or hydration resolves\n // again from a URL whose `?storeId=` the dispatcher has already stripped and\n // queries a different store than the markup it is hydrating.\n storeIdentifier:\n injected.storeIdentifier || storeId || requestHost || readEnv('VITE_STORE_DOMAIN'),\n };\n}\n\n/**\n * The env the SSR worker resolved, as handed to the browser by `rootHead`. Empty on the server\n * and on a client whose head carried nothing.\n *\n * Worker `vars` are *runtime* env: they live in `process.env` on the server only, while\n * `import.meta.env` is substituted at build time. A bundle built without those vars therefore\n * sees `undefined` in the browser and silently falls back to the production defaults — SSR\n * would render off the configured backend while every post-hydration fetch hits another one.\n */\nexport function getInjectedRuntimeEnv(): RuntimeEnv {\n const holder = globalThis as typeof globalThis & { [RUNTIME_ENV_KEY]?: RuntimeEnv };\n return holder[RUNTIME_ENV_KEY] ?? {};\n}\n\n/**\n * Inline head `<script>` body publishing the server-resolved env, or null when there is nothing\n * to publish (no overrides configured — the defaults already agree on both sides).\n */\nexport function renderRuntimeEnvScript(env: RuntimeEnv = resolveRuntimeEnv()): string | null {\n const set = Object.entries(env).filter(([, value]) => Boolean(value));\n if (!set.length) return null;\n const json = escapeForInlineScript(JSON.stringify(Object.fromEntries(set)));\n return `window.${RUNTIME_ENV_KEY}=${json};`;\n}\n","export type { StoreContext } from '../api/store';\nimport { getInjectedRuntimeEnv } from './runtime-env';\n\nconst isBrowser = typeof window !== 'undefined';\n\n/**\n * Get the store identifier. Priority: explicit > VITE_STORE_DOMAIN (build-time) > the identifier\n * the SSR worker resolved (published into the head — wrangler `vars` are server-only, so\n * without this the browser would fall back to its own host and request a different store than\n * the one that was rendered) > window.location.host > runtime env (process.env).\n */\nexport function getStoreIdentifier(explicit?: string): string {\n if (explicit) return explicit;\n try {\n const viteEnv = (import.meta as any).env?.VITE_STORE_DOMAIN;\n if (viteEnv) return viteEnv;\n } catch {\n /* import.meta not available in all environments */\n }\n const injected = getInjectedRuntimeEnv().storeIdentifier;\n if (injected) return injected;\n if (isBrowser) return window.location.host;\n return (\n (typeof process !== 'undefined' &&\n (process.env?.VITE_STORE_DOMAIN || process.env?.STORE_DOMAIN)) ||\n ''\n );\n}\n\n/**\n * Get Salla SDK instance if available\n */\nexport function getSallaSDK(): typeof window.salla | undefined {\n if (!isBrowser) return undefined;\n return window.salla;\n}\n\n/**\n * Push the active route locale onto the Salla SDK.\n *\n * Why this is needed (and why it must run on every navigation):\n * - The SDK seeds its locale from `navigator.language` — the theme sets no `s-lang`\n * cookie or `window.locale` — so an English browser starts the SDK in `en` even on\n * an `/ar` store.\n * - The SDK fixes its axios `accept-language` header ONCE, at init. `salla.lang.setLocale`\n * only swaps UI translations (it never touches the header), and `salla.init()` is a\n * no-op after `Salla.status === 'ready'`, so the header never refreshes on its own.\n * - `profile::info.fetched` (login / profile refresh on navigation) overrides the header\n * to the *account's* language.\n *\n * Net result without this: `salla.api.*` calls (cart/product details) return data in the\n * wrong locale — e.g. English cart item names on `/ar/cart` — intermittently, depending on\n * load order and whether a profile fetch ran. Re-asserting the URL locale here keeps the\n * header correct. No-op on the server and until the SDK exposes the methods.\n */\nexport function syncSdkLocale(locale: string): void {\n const sdk = getSallaSDK();\n if (!sdk || !locale) return;\n try {\n sdk.lang?.setLocale?.(locale);\n sdk.api?.setHeader?.('accept-language', locale);\n // The localization modal swaps `/${user.language_code}/` in the URL on submit;\n // the SDK never sets this locally, so without it the switch reloads the same page.\n sdk.config?.set?.('user.language_code', locale);\n } catch {\n // SDK partially loaded — the header is re-asserted on the next navigation.\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/store.ts"],"names":[],"mappings":";;;;;AAMA,IAAM,qBAAA,GAAwB;AAAA,EAC5B,OAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,gBAAA;AAAA,EACA,mBAAA;AAAA,EACA,YAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,iBAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAA;AAoEO,SAAS,uBAAuB,QAAA,EAA2B;AAChE,EAAA,IAAI,UAAU,OAAO,QAAA;AAErB,EAAA,MAAM,EAAE,OAAA,EAAS,WAAA,EAAY,GAAI,eAAA,EAAgB;AACjD,EAAA,IAAI,SAAS,OAAO,OAAA;AAEpB,EAAA,MAAM,QAAA,GAAW,uBAAsB,CAAE,eAAA;AACzC,EAAA,IAAI,UAAU,OAAO,QAAA;AAErB,EAAA,IAAI,aAAa,OAAO,WAAA;AAExB,EAAA,MAAM,SAAA,GAAY,OAAO,MAAA,KAAW,WAAA;AACpC,EAAA,IAAI,SAAA,EAAW,OAAO,MAAA,CAAO,QAAA,CAAS,IAAA;AAEtC,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAW,YAAyD,GAAA,EACtE,iBAAA;AACJ,IAAA,IAAI,SAAS,OAAO,OAAA;AAAA,EACt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,OAAO;AAAA,QACL,OAAO,IAAA,CAAK,KAAA;AAAA,QACZ,OAAO,IAAA,CAAK,KAAA;AAAA,QACZ,SAAA;AAAA,QACA,YAAY,IAAA,CAAK,UAAA;AAAA,QACjB,mBAAmB,IAAA,CAAK,iBAAA;AAAA,QACxB,SAAS,IAAA,CAAK,OAAA;AAAA,QACd,OAAO,IAAA,CAAK,KAAA;AAAA,QACZ,WAAW,IAAA,CAAK,SAAA;AAAA,QAChB,YAAY,IAAA,CAAK;AAAA,OACnB;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,OAAA,CAAQ,KAAA,CAAM,4BAA4B,KAAK,CAAA;AAC/C,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF,CAAA;AAAA,EAEA,OAAA,EAAS;AAAA,IACP,QAAA,EAAU,CAAC,eAAA,KACT,YAAA,CAAkC;AAAA,MAChC,QAAA,EAAU;AAAA,QACR,OAAA;AAAA,QACA,UAAA;AAAA,QACA,eAAA;AAAA,QACA,oBAAmB,CAAE,MAAA;AAAA,QACrB,gBAAA;AAAiB,OACnB;AAAA,MACA,OAAA,EAAS,MAAM,KAAA,CAAM,QAAA,CAAS,eAAe;AAAA,KAC9C;AAAA;AAEP","file":"chunk-ZYKBHBBH.js","sourcesContent":["import { queryOptions } from '@tanstack/react-query';\nimport { api, getActiveScopeId } from './client';\nimport type { Store, Theme, Language } from '../types';\nimport { getTwilightContext, getRequestStore } from '../twilight/context';\nimport { getInjectedRuntimeEnv } from '../utils/runtime-env';\n\nconst DEFAULT_INCLUDE_ITEMS = [\n 'store',\n 'settings',\n 'theme',\n 'theme_settings',\n 'external_services',\n 'currencies',\n 'languages',\n 'payments',\n 'product_widgets',\n 'rating',\n 'ratings',\n];\n\n/**\n * Raw API response for settings endpoint.\n * Languages come as object: { \"AR\": { code, name, ... }, \"EN\": {...} }\n */\ninterface SettingsApiResponse {\n store?: Store;\n theme?: Theme;\n languages?: Record<string, Language>;\n currencies?: Record<\n string,\n { code: string; name: string; symbol: string; amount: number; country_code: string }\n >;\n external_services?: Record<string, unknown>;\n headers?: Record<string, unknown>;\n login?: { url: string; turnstile_site_key: string };\n affiliate?: { utm_url: string; cta_enabled: boolean };\n debug?: boolean;\n trace_console?: boolean;\n policy_url?: string;\n}\n\n/**\n * Central settings context - single source of truth for all API data.\n * Contains everything from the settings endpoint response after processing.\n */\nexport interface StoreContext {\n store?: Store;\n theme?: Theme;\n /** Languages as array after conversion from API object format */\n languages?: Language[];\n currencies?: Record<\n string,\n { code: string; name: string; symbol: string; amount: number; country_code: string }\n >;\n external_services?: Record<string, unknown>;\n headers?: Record<string, unknown>;\n login?: { url: string; turnstile_site_key: string };\n affiliate?: { utm_url: string; cta_enabled: boolean };\n debug?: boolean;\n trace_console?: boolean; // todo:: remove it\n policy_url?: string;\n}\n\n/**\n * Which store to ask about, in the order the answers can be trusted.\n *\n * A deployed theme worker is published with **no vars and no bindings** — the\n * script metadata carries `main_module`, compatibility settings, assets and tags\n * and nothing else — so `VITE_STORE_DOMAIN` exists only where a build baked it\n * in, which is local development. In production this function used to reach the\n * end of that chain and return the empty string, `store.settings` refused to\n * call with no identifier, and the root loader threw \"Store Unavailable\" — a\n * theme that renders its own failure page for every visitor of every store.\n *\n * The order:\n *\n * 1. what the caller passed, which is always deliberate;\n * 2. the store this request names — the `?storeId=` a preview was opened with,\n * then the cookie remembering it — seeded by `twilightMiddleware`;\n * 3. what SSR already resolved and published, so the hydrated client asks about\n * the same store the server rendered instead of resolving again from a URL\n * that no longer names it;\n * 4. the request's own host, which *is* the identity of a live storefront;\n * 5. `VITE_STORE_DOMAIN`, last, because a build-time constant is a development\n * convenience and must never outrank what the request actually said.\n */\nexport function resolveStoreIdentifier(explicit?: string): string {\n if (explicit) return explicit;\n\n const { storeId, requestHost } = getRequestStore();\n if (storeId) return storeId;\n\n const injected = getInjectedRuntimeEnv().storeIdentifier;\n if (injected) return injected;\n\n if (requestHost) return requestHost;\n\n const isBrowser = typeof window !== 'undefined';\n if (isBrowser) return window.location.host;\n\n try {\n const viteEnv = (import.meta as { env?: { VITE_STORE_DOMAIN?: string } }).env\n ?.VITE_STORE_DOMAIN;\n if (viteEnv) return viteEnv;\n } catch {\n /* import.meta not available in all environments */\n }\n return (typeof process !== 'undefined' && process.env?.STORE_DOMAIN) || '';\n}\n\n/**\n * Converts languages object from API to array format.\n * API returns: { \"AR\": { code, name, ... }, \"EN\": { ... } }\n * We need: [{ code, name, ... }, { code, name, ... }]\n * todo:: return the languages as object from the APIs to avoid this\n */\nfunction languagesToArray(languages?: Record<string, Language>): Language[] | undefined {\n if (!languages) return undefined;\n // The SDK's localization modal reads `lang.iso_code` (not `code`) when a language is\n // selected — without it the switch navigates to `/undefined/...`.\n return Object.values(languages).map((lang) => ({ iso_code: lang.code, ...lang }));\n}\n\nexport const store = {\n settings: async (storeIdentifier?: string): Promise<StoreContext | null> => {\n const identifier = storeIdentifier ?? resolveStoreIdentifier();\n\n if (!identifier) {\n console.warn('[store.settings] No store identifier available');\n return null;\n }\n\n const includeParams = DEFAULT_INCLUDE_ITEMS.map((i) => `include[]=${i}`).join('&');\n const scopeId = getActiveScopeId();\n const params = scopeId != null ? `${includeParams}&scope=${scopeId}` : includeParams;\n\n try {\n const json = await api\n .get(`store/settings?${params}`, { timeout: 5000 })\n .json<{ data?: SettingsApiResponse }>();\n\n const data = json?.data;\n if (!data) return null;\n\n // Convert languages from object to array\n const languages = languagesToArray(data.languages);\n\n return {\n store: data.store,\n theme: data.theme,\n languages,\n currencies: data.currencies,\n external_services: data.external_services,\n headers: data.headers,\n login: data.login,\n affiliate: data.affiliate,\n policy_url: data.policy_url,\n };\n } catch (error) {\n console.error('[store.settings] Failed:', error);\n return null;\n }\n },\n\n queries: {\n settings: (storeIdentifier?: string) =>\n queryOptions<StoreContext | null>({\n queryKey: [\n 'store',\n 'settings',\n storeIdentifier,\n getTwilightContext().locale,\n getActiveScopeId(),\n ],\n queryFn: () => store.settings(storeIdentifier),\n }),\n },\n};\n"]}
|