@salla.sa/twilight-theme-engine 1.0.34 → 1.0.36
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-RERJJKYN.js → AddToCartForm-TH7W4EON.js} +3 -3
- package/dist/{AddToCartForm-RERJJKYN.js.map → AddToCartForm-TH7W4EON.js.map} +1 -1
- package/dist/{BlogAuthorPage-XNTLCH6M.js → BlogAuthorPage-JQLQRSWA.js} +15 -15
- package/dist/{BlogAuthorPage-XNTLCH6M.js.map → BlogAuthorPage-JQLQRSWA.js.map} +1 -1
- package/dist/{BlogCategoryPage-Y5HHX6Q4.js → BlogCategoryPage-FFC7WVFU.js} +15 -15
- package/dist/{BlogCategoryPage-Y5HHX6Q4.js.map → BlogCategoryPage-FFC7WVFU.js.map} +1 -1
- package/dist/{BlogPage-ND3KMAYL.js → BlogPage-WJSXLUQZ.js} +13 -13
- package/dist/{BlogPage-ND3KMAYL.js.map → BlogPage-WJSXLUQZ.js.map} +1 -1
- package/dist/{BlogSinglePage-OXMFEM3G.js → BlogSinglePage-X2TYH7UY.js} +13 -13
- package/dist/{BlogSinglePage-OXMFEM3G.js.map → BlogSinglePage-X2TYH7UY.js.map} +1 -1
- package/dist/{BlogTagPage-LOR275LH.js → BlogTagPage-HLCP45BG.js} +15 -15
- package/dist/{BlogTagPage-LOR275LH.js.map → BlogTagPage-HLCP45BG.js.map} +1 -1
- package/dist/{BrandsPage-BX3SWD23.js → BrandsPage-G4ZGM2WN.js} +13 -13
- package/dist/{BrandsPage-BX3SWD23.js.map → BrandsPage-G4ZGM2WN.js.map} +1 -1
- package/dist/{Breadcrumb-L33QVTUA.js → Breadcrumb-WWQ5CTRU.js} +13 -13
- package/dist/{Breadcrumb-L33QVTUA.js.map → Breadcrumb-WWQ5CTRU.js.map} +1 -1
- package/dist/{CartItem-ZNM7LS6N.js → CartItem-NLHDAKMB.js} +13 -13
- package/dist/{CartItem-ZNM7LS6N.js.map → CartItem-NLHDAKMB.js.map} +1 -1
- package/dist/{CartSummary-GA7VKMOQ.js → CartSummary-KNV3ME4N.js} +13 -13
- package/dist/{CartSummary-GA7VKMOQ.js.map → CartSummary-KNV3ME4N.js.map} +1 -1
- package/dist/{Copyright-SULJLAOX.js → Copyright-TR5VNHZJ.js} +3 -3
- package/dist/{Copyright-SULJLAOX.js.map → Copyright-TR5VNHZJ.js.map} +1 -1
- package/dist/{CustomerLayout-DPASUJXG.js → CustomerLayout-DPIFVHXE.js} +13 -13
- package/dist/{CustomerLayout-DPASUJXG.js.map → CustomerLayout-DPIFVHXE.js.map} +1 -1
- package/dist/{Footer-5LUYTER2.js → Footer-LR32SSXT.js} +13 -13
- package/dist/{Footer-5LUYTER2.js.map → Footer-LR32SSXT.js.map} +1 -1
- package/dist/{Header-V2QY52KP.js → Header-M6H5RVQP.js} +6 -6
- package/dist/{Header-V2QY52KP.js.map → Header-M6H5RVQP.js.map} +1 -1
- package/dist/{LoyaltyPage-WGBJSWMT.js → LoyaltyPage-QFOQTOY7.js} +14 -14
- package/dist/{LoyaltyPage-WGBJSWMT.js.map → LoyaltyPage-QFOQTOY7.js.map} +1 -1
- package/dist/{MainMenu-53YP6MTU.js → MainMenu-OKOU27GV.js} +7 -7
- package/dist/{MainMenu-53YP6MTU.js.map → MainMenu-OKOU27GV.js.map} +1 -1
- package/dist/{MasterLayout-GIYKSI2D.js → MasterLayout-TK2334FB.js} +13 -13
- package/dist/{MasterLayout-GIYKSI2D.js.map → MasterLayout-TK2334FB.js.map} +1 -1
- package/dist/{MobileMenu-FGHDWUS3.js → MobileMenu-EEIV7HEB.js} +14 -14
- package/dist/{MobileMenu-FGHDWUS3.js.map → MobileMenu-EEIV7HEB.js.map} +1 -1
- package/dist/{NotificationsPage-YUPDZQMH.js → NotificationsPage-RWIHWNNP.js} +13 -13
- package/dist/{NotificationsPage-YUPDZQMH.js.map → NotificationsPage-RWIHWNNP.js.map} +1 -1
- package/dist/{OrderSinglePage-NG45IOTR.js → OrderSinglePage-DXDN7VLA.js} +14 -14
- package/dist/{OrderSinglePage-NG45IOTR.js.map → OrderSinglePage-DXDN7VLA.js.map} +1 -1
- package/dist/{OrdersPage-X753G6LK.js → OrdersPage-RL7YOLJP.js} +14 -14
- package/dist/{OrdersPage-X753G6LK.js.map → OrdersPage-RL7YOLJP.js.map} +1 -1
- package/dist/{PageSingle-3IHQP3WO.js → PageSingle-NRXICTGC.js} +3 -3
- package/dist/{PageSingle-3IHQP3WO.js.map → PageSingle-NRXICTGC.js.map} +1 -1
- package/dist/{ProductDetails-3WTGYULJ.js → ProductDetails-KT4ZE2AV.js} +3 -3
- package/dist/{ProductDetails-3WTGYULJ.js.map → ProductDetails-KT4ZE2AV.js.map} +1 -1
- package/dist/{ProfilePage-DSDDUN5Y.js → ProfilePage-UKK374YN.js} +13 -13
- package/dist/{ProfilePage-DSDDUN5Y.js.map → ProfilePage-UKK374YN.js.map} +1 -1
- package/dist/{RenderWhenVisible-2BRWQDOQ.js → RenderWhenVisible-F44J5MMG.js} +4 -4
- package/dist/RenderWhenVisible-F44J5MMG.js.map +1 -0
- package/dist/{SeoCartWidget-M43SKEQJ.js → SeoCartWidget-B2ORFNKV.js} +13 -13
- package/dist/{SeoCartWidget-M43SKEQJ.js.map → SeoCartWidget-B2ORFNKV.js.map} +1 -1
- package/dist/{SettingsPage-JBT73EJP.js → SettingsPage-RHFJJVMQ.js} +13 -13
- package/dist/{SettingsPage-JBT73EJP.js.map → SettingsPage-RHFJJVMQ.js.map} +1 -1
- package/dist/{StoreClosedNotification-FCF2NBZR.js → StoreClosedNotification-3KPPYV52.js} +14 -14
- package/dist/{StoreClosedNotification-FCF2NBZR.js.map → StoreClosedNotification-3KPPYV52.js.map} +1 -1
- package/dist/{TestimonialsPage-4ZXBWLEW.js → TestimonialsPage-C7CC2TNJ.js} +3 -3
- package/dist/{TestimonialsPage-4ZXBWLEW.js.map → TestimonialsPage-C7CC2TNJ.js.map} +1 -1
- package/dist/{ThankYouPage-IDR5ZWIB.js → ThankYouPage-P6GGI3W7.js} +13 -13
- package/dist/{ThankYouPage-IDR5ZWIB.js.map → ThankYouPage-P6GGI3W7.js.map} +1 -1
- package/dist/{WalletPage-WTDVBQ4Z.js → WalletPage-HERQ6BL3.js} +14 -14
- package/dist/{WalletPage-WTDVBQ4Z.js.map → WalletPage-HERQ6BL3.js.map} +1 -1
- package/dist/{WishlistPage-Q4PLJ6VV.js → WishlistPage-XXIUSMI4.js} +14 -14
- package/dist/{WishlistPage-Q4PLJ6VV.js.map → WishlistPage-XXIUSMI4.js.map} +1 -1
- package/dist/api/apps.js +4 -4
- package/dist/api/brands.js +5 -5
- package/dist/api/cart.js +5 -5
- package/dist/api/category.js +5 -5
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +3 -3
- package/dist/api/home.js +4 -4
- package/dist/api/loyalty.js +5 -5
- package/dist/api/menu.js +4 -4
- package/dist/api/notification.js +4 -4
- package/dist/api/order.js +5 -5
- package/dist/api/page.js +5 -5
- package/dist/api/product.js +5 -5
- package/dist/api/profile.js +3 -3
- package/dist/api/store.d.ts.map +1 -1
- package/dist/api/store.js +4 -4
- package/dist/api/translations.js +4 -4
- package/dist/api/user.js +4 -4
- package/dist/api/wishlist.js +4 -4
- package/dist/{chunk-QOK3ANNB.js → chunk-2AGMXJVP.js} +4 -4
- package/dist/{chunk-QOK3ANNB.js.map → chunk-2AGMXJVP.js.map} +1 -1
- package/dist/{chunk-Z2BE6MDB.js → chunk-2KZORZZN.js} +14 -6
- package/dist/chunk-2KZORZZN.js.map +1 -0
- package/dist/{chunk-UPFFOL37.js → chunk-3Z6BI7K6.js} +7 -7
- package/dist/{chunk-UPFFOL37.js.map → chunk-3Z6BI7K6.js.map} +1 -1
- package/dist/{chunk-IXXPO4LJ.js → chunk-5JJZHYO2.js} +5 -5
- package/dist/{chunk-IXXPO4LJ.js.map → chunk-5JJZHYO2.js.map} +1 -1
- package/dist/{chunk-FQGCCV4T.js → chunk-5TRRUV7N.js} +3 -3
- package/dist/{chunk-FQGCCV4T.js.map → chunk-5TRRUV7N.js.map} +1 -1
- package/dist/{chunk-LG556DIE.js → chunk-6KI2QCPL.js} +3 -3
- package/dist/{chunk-LG556DIE.js.map → chunk-6KI2QCPL.js.map} +1 -1
- package/dist/{chunk-GQ7IBJ55.js → chunk-6MGDRMZM.js} +4 -4
- package/dist/{chunk-GQ7IBJ55.js.map → chunk-6MGDRMZM.js.map} +1 -1
- package/dist/{chunk-5ACY5CD3.js → chunk-6XWMNQ52.js} +10 -4
- package/dist/chunk-6XWMNQ52.js.map +1 -0
- package/dist/{chunk-LYY3EOAO.js → chunk-7RJIZQU3.js} +4 -4
- package/dist/{chunk-LYY3EOAO.js.map → chunk-7RJIZQU3.js.map} +1 -1
- package/dist/{chunk-PZCHYB7O.js → chunk-AMOU6U2D.js} +12 -12
- package/dist/{chunk-PZCHYB7O.js.map → chunk-AMOU6U2D.js.map} +1 -1
- package/dist/{chunk-WXOABH6J.js → chunk-AZ5HAIYQ.js} +26 -11
- package/dist/chunk-AZ5HAIYQ.js.map +1 -0
- package/dist/{chunk-L6UGY2OB.js → chunk-BWIESZJK.js} +3 -3
- package/dist/{chunk-L6UGY2OB.js.map → chunk-BWIESZJK.js.map} +1 -1
- package/dist/{chunk-Z2P4M6T6.js → chunk-CCCKRNO4.js} +3 -3
- package/dist/{chunk-Z2P4M6T6.js.map → chunk-CCCKRNO4.js.map} +1 -1
- package/dist/{chunk-U6BFS4JR.js → chunk-CGQMVUOD.js} +5 -5
- package/dist/{chunk-U6BFS4JR.js.map → chunk-CGQMVUOD.js.map} +1 -1
- package/dist/{chunk-J2TTL3AA.js → chunk-E2T4RCTH.js} +6 -6
- package/dist/{chunk-J2TTL3AA.js.map → chunk-E2T4RCTH.js.map} +1 -1
- package/dist/{chunk-TXYT42AU.js → chunk-E5EH32L7.js} +3 -3
- package/dist/{chunk-TXYT42AU.js.map → chunk-E5EH32L7.js.map} +1 -1
- package/dist/{chunk-6RGZYVQT.js → chunk-HPW7OJPF.js} +15 -15
- package/dist/{chunk-6RGZYVQT.js.map → chunk-HPW7OJPF.js.map} +1 -1
- package/dist/{chunk-6RIKW3YV.js → chunk-J62WEOQ2.js} +4 -4
- package/dist/{chunk-6RIKW3YV.js.map → chunk-J62WEOQ2.js.map} +1 -1
- package/dist/{chunk-Y5FBDMFV.js → chunk-JBXTU5NM.js} +22 -12
- package/dist/chunk-JBXTU5NM.js.map +1 -0
- package/dist/{chunk-OOYJHQLQ.js → chunk-KFH3OBFW.js} +4 -4
- package/dist/{chunk-OOYJHQLQ.js.map → chunk-KFH3OBFW.js.map} +1 -1
- package/dist/{chunk-KRB2TZAY.js → chunk-KJRL3SSW.js} +4 -4
- package/dist/{chunk-KRB2TZAY.js.map → chunk-KJRL3SSW.js.map} +1 -1
- package/dist/{chunk-LXIEAZZJ.js → chunk-KLTQ2UST.js} +3 -3
- package/dist/{chunk-LXIEAZZJ.js.map → chunk-KLTQ2UST.js.map} +1 -1
- package/dist/{chunk-6JLVUQWD.js → chunk-MCYEMXFY.js} +4 -4
- package/dist/{chunk-6JLVUQWD.js.map → chunk-MCYEMXFY.js.map} +1 -1
- package/dist/{chunk-C4S4VXWW.js → chunk-ME727LL4.js} +3 -3
- package/dist/{chunk-C4S4VXWW.js.map → chunk-ME727LL4.js.map} +1 -1
- package/dist/{chunk-NTOIR3NK.js → chunk-NX6BEOXW.js} +4 -4
- package/dist/{chunk-NTOIR3NK.js.map → chunk-NX6BEOXW.js.map} +1 -1
- package/dist/{chunk-FPQAYFHZ.js → chunk-OGGWNPF3.js} +3 -3
- package/dist/{chunk-FPQAYFHZ.js.map → chunk-OGGWNPF3.js.map} +1 -1
- package/dist/{chunk-STHBBSK2.js → chunk-QG2Q6HB5.js} +3 -3
- package/dist/{chunk-STHBBSK2.js.map → chunk-QG2Q6HB5.js.map} +1 -1
- package/dist/{chunk-CBQKQCKI.js → chunk-RBISDOPR.js} +4 -4
- package/dist/{chunk-CBQKQCKI.js.map → chunk-RBISDOPR.js.map} +1 -1
- package/dist/{chunk-57RYHNW2.js → chunk-RIZOT5FN.js} +3 -3
- package/dist/{chunk-57RYHNW2.js.map → chunk-RIZOT5FN.js.map} +1 -1
- package/dist/{chunk-47C6C2NN.js → chunk-TMR7TZMB.js} +4 -4
- package/dist/{chunk-47C6C2NN.js.map → chunk-TMR7TZMB.js.map} +1 -1
- package/dist/{chunk-5IEQLAAY.js → chunk-ULQMJUO2.js} +4 -4
- package/dist/{chunk-5IEQLAAY.js.map → chunk-ULQMJUO2.js.map} +1 -1
- package/dist/{chunk-6BVPVYLN.js → chunk-VZHYSYKG.js} +4 -4
- package/dist/{chunk-6BVPVYLN.js.map → chunk-VZHYSYKG.js.map} +1 -1
- package/dist/chunk-W6K6RYSC.js +14 -0
- package/dist/{chunk-3ABM2IWU.js.map → chunk-W6K6RYSC.js.map} +1 -1
- package/dist/{chunk-EV4JSMFZ.js → chunk-X26WB7AG.js} +3 -3
- package/dist/{chunk-EV4JSMFZ.js.map → chunk-X26WB7AG.js.map} +1 -1
- package/dist/{chunk-E3J2RXBS.js → chunk-XLGVT7QF.js} +3 -3
- package/dist/{chunk-E3J2RXBS.js.map → chunk-XLGVT7QF.js.map} +1 -1
- package/dist/{chunk-GCAIIFF3.js → chunk-XTOXFAP7.js} +3 -3
- package/dist/{chunk-GCAIIFF3.js.map → chunk-XTOXFAP7.js.map} +1 -1
- package/dist/{chunk-HYESKIWZ.js → chunk-ZNWNJZSM.js} +4 -4
- package/dist/{chunk-HYESKIWZ.js.map → chunk-ZNWNJZSM.js.map} +1 -1
- package/dist/{chunk-LCSALUZ2.js → chunk-ZPHPRT7H.js} +6 -6
- package/dist/{chunk-LCSALUZ2.js.map → chunk-ZPHPRT7H.js.map} +1 -1
- package/dist/components/cart/index.js +1 -1
- package/dist/components/common/RenderWhenVisible.d.ts.map +1 -1
- package/dist/components/common/index.js +1 -1
- package/dist/components/drawer/index.js +11 -11
- package/dist/components/home/index.js +14 -14
- package/dist/components/layout/index.js +5 -5
- package/dist/components/product/index.js +12 -12
- package/dist/components/store/index.js +13 -13
- package/dist/document-class-GLEKROWK.js +23 -0
- package/dist/{document-class-HFVPENQI.js.map → document-class-GLEKROWK.js.map} +1 -1
- package/dist/hooks/index.js +11 -11
- package/dist/hooks/useGtm.js +11 -11
- package/dist/hooks/useMoney.js +11 -11
- package/dist/hooks/useStore.js +11 -11
- package/dist/hooks/useUser.js +5 -5
- package/dist/index.js +11 -11
- package/dist/{navigation-B6TEUWEK.js → navigation-D7QS3NK2.js} +4 -4
- package/dist/{navigation-B6TEUWEK.js.map → navigation-D7QS3NK2.js.map} +1 -1
- package/dist/{navigation-RYSVWICZ.js → navigation-DQNNT2LY.js} +5 -5
- package/dist/{navigation-RYSVWICZ.js.map → navigation-DQNNT2LY.js.map} +1 -1
- package/dist/{not-found-XD534NFT.js → not-found-XFSCINJ2.js} +13 -13
- package/dist/{not-found-XD534NFT.js.map → not-found-XFSCINJ2.js.map} +1 -1
- package/dist/providers/index.js +11 -11
- package/dist/routes/account/orders.js +6 -6
- package/dist/routes/account.js +14 -14
- package/dist/routes/blog.js +10 -10
- package/dist/routes/brands.js +6 -6
- package/dist/routes/cart.js +19 -19
- package/dist/routes/home.js +16 -16
- package/dist/routes/index.js +3 -3
- package/dist/routes/loyalty.js +6 -6
- package/dist/routes/page.js +6 -6
- package/dist/routes/product-listing.js +16 -16
- package/dist/routes/product.js +14 -14
- package/dist/routes/seo-redirects.js +3 -3
- package/dist/routes/testimonials.js +2 -2
- package/dist/routes/thank-you.js +6 -6
- package/dist/skeleton.js +16 -16
- package/dist/tanstack/middleware/twilight.d.ts.map +1 -1
- package/dist/tanstack.js +16 -15
- package/dist/tanstack.js.map +1 -1
- package/dist/twilight/context.d.ts +22 -5
- package/dist/twilight/context.d.ts.map +1 -1
- package/dist/utils/cookies.d.ts +46 -6
- package/dist/utils/cookies.d.ts.map +1 -1
- package/dist/utils/index.js +4 -4
- package/dist/utils/runtime-env.d.ts +13 -0
- package/dist/utils/runtime-env.d.ts.map +1 -1
- package/dist/utils/theme-version.d.ts +33 -0
- package/dist/utils/theme-version.d.ts.map +1 -0
- package/dist/vite/index.js +2 -2
- package/package.json +1 -1
- package/dist/RenderWhenVisible-2BRWQDOQ.js.map +0 -1
- package/dist/chunk-3ABM2IWU.js +0 -14
- package/dist/chunk-5ACY5CD3.js.map +0 -1
- package/dist/chunk-WXOABH6J.js.map +0 -1
- package/dist/chunk-Y5FBDMFV.js.map +0 -1
- package/dist/chunk-Z2BE6MDB.js.map +0 -1
- package/dist/document-class-HFVPENQI.js +0 -23
package/dist/utils/cookies.d.ts
CHANGED
|
@@ -22,16 +22,36 @@ export declare const STORE_ID_COOKIE_NAME = "salla_sid";
|
|
|
22
22
|
/** Query parameter naming the store, on a host that serves more than one. */
|
|
23
23
|
export declare const STORE_ID_PARAM = "storeId";
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Which version of the theme's settings to render.
|
|
26
26
|
*
|
|
27
|
-
*
|
|
28
|
-
* API
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* A merchant's theme settings are versioned, and the storefront normally shows
|
|
28
|
+
* whichever version is live — the API answers with it, and names it back as
|
|
29
|
+
* `theme.profile.id`. Two places need a different one: the merchant's own theme
|
|
30
|
+
* editor, which previews a draft version before it is published, and a partner
|
|
31
|
+
* running a theme locally against a store whose settings they are editing. Both
|
|
32
|
+
* open the theme inside an iframe, and the version travels in that URL.
|
|
33
|
+
*
|
|
34
|
+
* Named `versionId` rather than the `version_id` the Dashboard uses internally,
|
|
35
|
+
* because it sits beside `?storeId=` and one URL should not spell two ids two
|
|
36
|
+
* ways. The value is the same one either way: the Optimus-encoded version id,
|
|
37
|
+
* which is exactly what `s-version-id` has always carried.
|
|
38
|
+
*
|
|
39
|
+
* The literal is a contract with `VERSION_COOKIE` in store-front-dispacher
|
|
40
|
+
* (`src/dispatch/preview.ts`), on the same terms as {@link STORE_ID_COOKIE_NAME}:
|
|
41
|
+
* nothing checks the two agree, and drift shows a merchant the wrong version of
|
|
42
|
+
* their own settings rather than failing.
|
|
31
43
|
*/
|
|
44
|
+
export declare const VERSION_ID_COOKIE_NAME = "salla_vid";
|
|
45
|
+
/** Query parameter naming the theme-settings version, where one may be named. */
|
|
46
|
+
export declare const VERSION_ID_PARAM = "versionId";
|
|
47
|
+
/** A store id in its canonical form, or null when it is not one. */
|
|
32
48
|
export declare function parseStoreId(raw: string | null | undefined): string | null;
|
|
49
|
+
/** A theme-settings version id in its canonical form, or null when it is not one. */
|
|
50
|
+
export declare function parseVersionId(raw: string | null | undefined): string | null;
|
|
33
51
|
/** The store id the dispatcher left in the cookie, or null when absent or malformed. */
|
|
34
52
|
export declare function extractStoreIdFromCookies(cookieHeader: string | null): string | null;
|
|
53
|
+
/** The version id the dispatcher left in the cookie, or null when absent or malformed. */
|
|
54
|
+
export declare function extractVersionIdFromCookies(cookieHeader: string | null): string | null;
|
|
35
55
|
/**
|
|
36
56
|
* The only hosts on which a request may name its own store.
|
|
37
57
|
*
|
|
@@ -59,6 +79,14 @@ export declare const STORE_ID_HOSTS: readonly string[];
|
|
|
59
79
|
* a rule like "anything ending in salla.design" is one wildcard DNS record away
|
|
60
80
|
* from admitting a host nobody meant to admit, and the list of hosts that serve
|
|
61
81
|
* more than one store is short and known.
|
|
82
|
+
*
|
|
83
|
+
* It gates {@link resolveRequestVersionId} as well, and the name has been left
|
|
84
|
+
* alone rather than generalised because one predicate that both call is the
|
|
85
|
+
* property worth keeping — a second, subtly different list is how a host ends up
|
|
86
|
+
* permitted to name one thing and not the other. A version is worth gating for
|
|
87
|
+
* the same reason a store is: on a merchant's own domain, honouring
|
|
88
|
+
* `?versionId=` would publish whatever draft settings they are still working on
|
|
89
|
+
* to anyone who guessed the URL.
|
|
62
90
|
*/
|
|
63
91
|
export declare function allowsRequestStoreId(host: string | null | undefined): boolean;
|
|
64
92
|
/**
|
|
@@ -75,7 +103,7 @@ export declare function hostIdentifiesStore(host: string | null | undefined): bo
|
|
|
75
103
|
/**
|
|
76
104
|
* The store this request names, on a host permitted to name one.
|
|
77
105
|
*
|
|
78
|
-
* The host check is inside
|
|
106
|
+
* The host check is inside the resolution rather than at a call site, because a
|
|
79
107
|
* call site is a thing someone can add without reading this comment. There is no
|
|
80
108
|
* way to ask "what store did the request name?" without also asking "is this a
|
|
81
109
|
* host that may say?" — get it wrong and the answer is a security bug that looks
|
|
@@ -87,6 +115,18 @@ export declare function hostIdentifiesStore(host: string | null | undefined): bo
|
|
|
87
115
|
* just typed.
|
|
88
116
|
*/
|
|
89
117
|
export declare function resolveRequestStoreId(url: string, cookieHeader: string | null, host: string | null | undefined): string | null;
|
|
118
|
+
/**
|
|
119
|
+
* The theme-settings version this request names, on a host permitted to name one.
|
|
120
|
+
*
|
|
121
|
+
* Same shape and the same host gate as {@link resolveRequestStoreId}, deliberately:
|
|
122
|
+
* both answer "what did this request ask to be shown?", both are reached only on
|
|
123
|
+
* a host that serves more than one thing, and a version that could be named where
|
|
124
|
+
* a store could not would be a second rule to keep in step with the first.
|
|
125
|
+
*
|
|
126
|
+
* Null is the ordinary answer, and it is not a failure — it means nothing
|
|
127
|
+
* addressed a version, so the store's own live one is what gets rendered.
|
|
128
|
+
*/
|
|
129
|
+
export declare function resolveRequestVersionId(url: string, cookieHeader: string | null, host: string | null | undefined): string | null;
|
|
90
130
|
/**
|
|
91
131
|
* Deletes the auth `token` cookie. This cookie is written client-side by the theme
|
|
92
132
|
* (TwilightProvider), not by the SDK — `salla.cookie.clearAll()` only clears its own
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/utils/cookies.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAC9C,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAEhD,6EAA6E;AAC7E,eAAO,MAAM,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 -1,13 +1,13 @@
|
|
|
1
1
|
export { formatSallaPlural } from '../chunk-BT6HEEAP.js';
|
|
2
2
|
export { stripUnsafeHtml } from '../chunk-RUHSV4Z6.js';
|
|
3
|
-
export { dispatchRouteChanged } from '../chunk-
|
|
3
|
+
export { dispatchRouteChanged } from '../chunk-X26WB7AG.js';
|
|
4
4
|
export { mergeHead, resolveHead, setHeadAdapter } from '../chunk-B3EFOE57.js';
|
|
5
5
|
export { sortOptions } from '../chunk-6Z4MOC4S.js';
|
|
6
6
|
export { buildBaseHead, buildHreflangAlternates, localeToOgLocale } from '../chunk-TZ3E5BN4.js';
|
|
7
7
|
export { color } from '../chunk-VVZNW5CB.js';
|
|
8
|
-
export { applyAppScopeMocks, registerThemeHookSlots } from '../chunk-
|
|
9
|
-
export { AUTH_TOKEN_COOKIE_NAME, clearAuthTokenCookie, extractTokenFromCookies, getSallaSDK, getStoreIdentifier } from '../chunk-
|
|
10
|
-
import '../chunk-
|
|
8
|
+
export { applyAppScopeMocks, registerThemeHookSlots } from '../chunk-6KI2QCPL.js';
|
|
9
|
+
export { AUTH_TOKEN_COOKIE_NAME, clearAuthTokenCookie, extractTokenFromCookies, getSallaSDK, getStoreIdentifier } from '../chunk-JBXTU5NM.js';
|
|
10
|
+
import '../chunk-6XWMNQ52.js';
|
|
11
11
|
export { asset, cdn, isPlaceholder } from '../chunk-ZCH7W7DZ.js';
|
|
12
12
|
export { mergeDocumentDescriptors, mergeElementAttrs, normalizeClasses, syncAttrsToElement, toReactProps } from '../chunk-CW625T2E.js';
|
|
13
13
|
import '../chunk-T72DAX7R.js';
|
|
@@ -4,6 +4,19 @@ export interface RuntimeEnv {
|
|
|
4
4
|
apiBase?: string;
|
|
5
5
|
/** Store identifier — `VITE_STORE_DOMAIN`. */
|
|
6
6
|
storeIdentifier?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The theme-settings version the request named, if any.
|
|
9
|
+
*
|
|
10
|
+
* Published for the same reason `storeIdentifier` is: the dispatcher strips
|
|
11
|
+
* `?versionId=` on the way in, so by the time the browser has the page its own
|
|
12
|
+
* URL no longer says which version it is showing. Without this the hydrated
|
|
13
|
+
* client would ask the API about the store's live version and quietly replace
|
|
14
|
+
* the draft it was handed.
|
|
15
|
+
*
|
|
16
|
+
* Absent — not empty — when nothing named one, so it drops out of the inline
|
|
17
|
+
* script entirely rather than publishing a value that means "live".
|
|
18
|
+
*/
|
|
19
|
+
versionId?: string;
|
|
7
20
|
}
|
|
8
21
|
/**
|
|
9
22
|
* A build-time `import.meta.env` var, falling back to the worker's runtime `process.env`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-env.d.ts","sourceRoot":"","sources":["../../src/utils/runtime-env.ts"],"names":[],"mappings":"AAOA,qFAAqF;AACrF,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,eAAe,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime-env.d.ts","sourceRoot":"","sources":["../../src/utils/runtime-env.ts"],"names":[],"mappings":"AAOA,qFAAqF;AACrF,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUvD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,UAAU,CAqB9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,UAAU,CAGlD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,GAAE,UAAgC,GAAG,MAAM,GAAG,IAAI,CAK3F"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The version this request asked for, or null when it asked for none.
|
|
3
|
+
*
|
|
4
|
+
* Deliberately excludes the version the *settings* name. This is the answer to
|
|
5
|
+
* "what did the caller address?", and it has to be available before any settings
|
|
6
|
+
* exist — React Query keys are built from it, and a key that means one thing
|
|
7
|
+
* during SSR and another after hydration is how a page refetches everything it
|
|
8
|
+
* was just handed.
|
|
9
|
+
*
|
|
10
|
+
* 1. what the request named, seeded by `twilightMiddleware` on a host permitted
|
|
11
|
+
* to name one;
|
|
12
|
+
* 2. what SSR resolved and published into the head, which is all the browser has
|
|
13
|
+
* once the dispatcher has stripped `?versionId=` from the URL.
|
|
14
|
+
*/
|
|
15
|
+
export declare function requestedThemeVersionId(): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* The version every Salla API call is answered with — what goes in `s-version-id`.
|
|
18
|
+
*
|
|
19
|
+
* The requested version outranks the settings, because a request that named one
|
|
20
|
+
* is the only reason this is ever anything but the live version: falling back to
|
|
21
|
+
* the settings there would let the first answer overwrite the question.
|
|
22
|
+
*
|
|
23
|
+
* The settings' own `theme.profile.id` stays as the fallback, unchanged. It is
|
|
24
|
+
* what this header has always carried, and on an ordinary storefront it still
|
|
25
|
+
* is — it keeps the rest of a page's calls pinned to the version the settings
|
|
26
|
+
* call resolved, rather than letting a version go live mid-render.
|
|
27
|
+
*
|
|
28
|
+
* Reading the settings is guarded because `getTwilightContext().settings` throws
|
|
29
|
+
* a `SettingsError` when they have not loaded — which is the normal state on the
|
|
30
|
+
* very first call, the settings call itself.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveThemeVersionId(): string | null;
|
|
33
|
+
//# sourceMappingURL=theme-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-version.d.ts","sourceRoot":"","sources":["../../src/utils/theme-version.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,IAAI,CAKvD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,GAAG,IAAI,CAUrD"}
|
package/dist/vite/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { tanstackHeadAdapter } from '../chunk-
|
|
1
|
+
import { tanstackHeadAdapter } from '../chunk-5TRRUV7N.js';
|
|
2
2
|
import { nextjsHeadAdapter } from '../chunk-HOSHJBPS.js';
|
|
3
3
|
import { setHeadAdapter } from '../chunk-B3EFOE57.js';
|
|
4
4
|
import { RouteId } from '../chunk-MTONGOJD.js';
|
|
5
|
-
import '../chunk-
|
|
5
|
+
import '../chunk-6XWMNQ52.js';
|
|
6
6
|
import '../chunk-T72DAX7R.js';
|
|
7
7
|
import '../chunk-DGUM43GV.js';
|
|
8
8
|
import { readFile, readdir } from 'fs/promises';
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/common/RenderWhenVisible.tsx"],"names":["RenderWhenVisible"],"mappings":";;;;AAEA,SAAS,eAAA,CAAgB,EAAE,MAAA,EAAO,EAAuB;AACvD,EAAA,uBAAO,GAAA,CAAC,SAAI,KAAA,EAAO,EAAE,WAAW,MAAA,EAAO,EAAG,WAAU,mCAAA,EAAoC,CAAA;AAC1F;AAGA,SAAS,WAAA,CAAY,EAAE,OAAA,EAAQ,EAA4C;AACzE,EAAA,SAAA,CAAU,MAAM,OAAA,CAAQ,IAAI,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AACxC,EAAA,OAAO,IAAA;AACT;AA0BO,IAAM,iBAAA,GAAoB,IAAA,CAAK,SAASA,kBAAAA,CAAkB;AAAA,EAC/D,QAAA;AAAA,EACA,UAAA,GAAa,MAAA;AAAA,EACb,WAAA;AAAA,EACA,SAAA;AAAA,EACA,EAAA;AAAA,EACA,eAAA,GAAkB,OAAA;AAAA,EAClB,aAAA,GAAgB;AAClB,CAAA,EAA2B;AACzB,EAAA,MAAM,GAAA,GAAM,O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CAAA,GAEA;AAAA;AAAA,GAEJ;AAEJ,CAAC","file":"RenderWhenVisible-2BRWQDOQ.js","sourcesContent":["import { memo, useState, useEffect, useRef, Suspense, type ReactNode } from 'react';\n\nfunction DefaultSkeleton({ height }: { height: string }) {\n return <div style={{ minHeight: height }} className=\"animate-pulse rounded bg-gray-100\" />;\n}\n\n/** Sibling of the children inside Suspense: its effect only runs once the boundary resolves. */\nfunction MarkMounted({ onMount }: { onMount: (mounted: boolean) => void }) {\n useEffect(() => onMount(true), [onMount]);\n return null;\n}\n\nexport interface RenderWhenVisibleProps {\n children: ReactNode;\n rootMargin?: string;\n placeholder?: ReactNode;\n className?: string;\n id?: string;\n estimatedHeight?: string;\n renderOnMount?: boolean;\n}\n\n/**\n * RenderWhenVisible — defers mounting children until the container enters the viewport.\n *\n * Children are NOT in the React tree at all until the Intersection Observer fires,\n * so no effects, API calls, or renders happen for off-screen sections.\n * Once rendered, children stay mounted permanently (no re-unmount on scroll away).\n *\n * The `estimatedHeight` prop prevents the zero-height collapse problem: without it\n * every unrendered section stacks at the top with 0px height, causing all observers\n * to fire at once on mount. It applies as a min-height until the children have\n * actually committed — through the Suspense window too, since a custom placeholder\n * may be shorter than the estimate. After that the section's height is owned by its\n * content, so shorter blocks don't leave reserved dead space below them.\n */\nexport const RenderWhenVisible = memo(function RenderWhenVisible({\n children,\n rootMargin = '50px',\n placeholder,\n className,\n id,\n estimatedHeight = '400px',\n renderOnMount = false,\n}: RenderWhenVisibleProps) {\n const ref = useRef<HTMLElement>(null);\n const [visible, setVisible] = useState(renderOnMount);\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n if (renderOnMount || visible) return;\n const el = ref.current;\n if (!el) return;\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n if (entry.isIntersecting) {\n setVisible(true);\n observer.disconnect();\n }\n },\n { rootMargin }\n );\n\n observer.observe(el);\n\n return () => observer.disconnect();\n }, [renderOnMount, visible, rootMargin]);\n\n const fallback = placeholder ?? <DefaultSkeleton height={estimatedHeight} />;\n\n return (\n <section\n ref={!visible ? ref : undefined}\n className={className}\n id={id}\n style={{ minHeight: mounted ? undefined : estimatedHeight }}\n >\n {visible ? (\n <Suspense fallback={fallback}>\n {children}\n <MarkMounted onMount={setMounted} />\n </Suspense>\n ) : (\n fallback\n )}\n </section>\n );\n});\n"]}
|
package/dist/chunk-3ABM2IWU.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { lazy } from 'react';
|
|
2
|
-
|
|
3
|
-
// src/components/cart/lazy.ts
|
|
4
|
-
var LazyCartItem = lazy(() => import('./CartItem-ZNM7LS6N.js').then((m) => ({ default: m.CartItem })));
|
|
5
|
-
var LazyCartSummary = lazy(
|
|
6
|
-
() => import('./CartSummary-GA7VKMOQ.js').then((m) => ({ default: m.CartSummary }))
|
|
7
|
-
);
|
|
8
|
-
var LazySeoCartWidget = lazy(
|
|
9
|
-
() => import('./SeoCartWidget-M43SKEQJ.js').then((m) => ({ default: m.SeoCartWidget }))
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export { LazyCartItem, LazyCartSummary, LazySeoCartWidget };
|
|
13
|
-
//# sourceMappingURL=chunk-3ABM2IWU.js.map
|
|
14
|
-
//# sourceMappingURL=chunk-3ABM2IWU.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/errors.ts","../src/providers/i18n-factory.ts","../src/twilight/context.ts"],"names":[],"mappings":";;;;;;AAAO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EACvC,YAAY,OAAA,EAAkB;AAC5B,IAAA,KAAA,CAAM,WAAW,qCAAqC,CAAA;AACtD,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AAAA,EACd;AACF;ACOO,SAAS,kBAAA,CACd,MAAA,EACA,YAAA,EACA,iBAAA,EACc;AACd,EAAA,MAAM,WAAW,cAAA,EAAe;AAChC,EAAA,MAAM,QAAA,GAAW,GAAG,MAAM,CAAA,MAA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AA,CAAE,GAAA;AAAA,IACtC,CAAA;AAAA,IACA,IAAI,IAAA,GAAO;AACT,MAAA,OAAO,IAAA,CAAK,IAAA;AAAA,IACd,CAAA;AAAA,IACA,IAAI,YAAA,GAAe;AACjB,MAAA,OAAO,IAAA,CAAK,YAAA;AAAA,IACd,CAAA;AAAA,IACA,IAAI,YAAA,GAAe;AACjB,MAAA,OAAO,IAAA,CAAK,YAAA;AAAA,IACd,CAAA;AAAA,IACA,IAAI,MAAA,GAAS;AACX,MAAA,OAAO,IAAA,CAAK,MAAA;AAAA,IACd;AAAA,GACF;AACF","file":"chunk-5ACY5CD3.js","sourcesContent":["export class SettingsError extends Error {\n constructor(message?: string) {\n super(message ?? 'Store settings could not be loaded.');\n this.name = 'SettingsError';\n }\n}\n","import { createInstance, type i18n as I18nInstance } from 'i18next';\nimport { initReactI18next } from 'react-i18next';\n\nexport type TranslationMessages = Record<string, Record<string, string>>;\n\n/**\n * Creates a new i18next instance for the given locale.\n *\n * @param locale - Active locale code, e.g. `'ar'`\n * @param translations - App translations from the Salla API (store-specific)\n * @param themeTranslations - Bundled theme translations (static defaults)\n */\nexport function createI18nInstance(\n locale: string,\n translations?: TranslationMessages,\n themeTranslations?: TranslationMessages\n): I18nInstance {\n const instance = createInstance();\n const transKey = `${locale}.trans`;\n\n instance.use(initReactI18next).init({\n lng: locale,\n fallbackLng: locale,\n ns: ['app', 'theme'],\n defaultNS: 'app',\n fallbackNS: 'theme',\n resources: {\n [locale]: {\n app: translations?.[transKey] ?? {},\n theme: themeTranslations?.[transKey] ?? {},\n },\n },\n interpolation: { escapeValue: false },\n react: { useSuspense: false },\n keySeparator: '.',\n nsSeparator: false,\n });\n\n return instance;\n}\n\n/**\n * Creates i18n instance for testing\n * @param locale - Locale code (default: 'ar')\n * @param translations - Optional translations\n */\nexport function createTestI18n(locale = 'ar', translations?: TranslationMessages): I18nInstance {\n return createI18nInstance(locale, translations);\n}\n","import type { QueryClient } from '@tanstack/react-query';\nimport type { i18n } from 'i18next';\nimport type { StoreContext } from '../api/store';\nimport type { AppSnippet, AppSettings } from '../api/apps';\nimport { FALLBACK_LOCALE, getLanguageInfo } from '../providers/locale-constants';\nimport type { TranslationMessages } from '../providers/i18n-factory';\nimport { createI18nInstance } from '../providers/i18n-factory';\nimport { SettingsError } from '../utils/errors';\nimport type { ActiveScope } from '../utils/cookies';\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface TwilightLocation<TSearch = Record<string, unknown>> {\n href: string;\n pathname: string;\n search: TSearch;\n searchStr: string;\n state: Record<string, unknown>;\n hash: string;\n}\n\nexport interface PageContext {\n slug: string;\n id?: string | number;\n title: string;\n url?: string;\n parent?: { id: string | number; name: string; url: string } | null;\n breadcrumbs?: { name: string; url: string }[];\n}\n\nexport interface TwilightContext {\n queryClient: QueryClient;\n settings: StoreContext;\n locale: string;\n routeId: string;\n location: TwilightLocation;\n authToken: string | null;\n /**\n * The selected market and, once bullet delivery confirmed one, its branch\n * allocation — the full object the SDK sends as `s-scope-*` headers. Seeded from\n * the `scope` cookie on the server; see {@link ActiveScope}.\n */\n scope: ActiveScope | null;\n /** `scope.id`, kept for callers that only need the market. */\n scopeId: string | null;\n /**\n * Which store this request is for, when something other than the hostname says\n * so — the `?storeId=` a preview was opened with, or the cookie remembering it.\n *\n * Null on a live storefront, where the hostname is the answer and there is\n * nothing to carry. See {@link resolveRequestStoreId}.\n */\n storeId: string | null;\n /**\n * The host this request arrived on, captured server-side.\n *\n * A theme worker is deployed with no vars and no bindings, so the request is\n * the only thing that knows which storefront it is serving. On the client this\n * is `window.location.host`; on the server nothing else has it.\n */\n requestHost: string | null;\n i18n: i18n;\n dir: 'ltr' | 'rtl';\n page?: PageContext;\n /** Installed apps' snippets, fetched in rootBeforeLoad so AppsSnippets can render CDN\n * <script> tags during SSR (React Query isn't dehydrated here, so useQuery has no SSR data). */\n appsSnippets?: AppSnippet[];\n /** Per-app public `app.*` buckets, fetched in rootBeforeLoad so rootHead can install the\n * `Salla.appScope` factory inline at parse time — ahead of the snippets' onReady callbacks. */\n appsSettings?: AppSettings;\n extras?: Record<string, unknown>;\n}\n\n// ============================================================================\n// Internal Store\n// ============================================================================\n\nconst DEFAULT_LOCATION: TwilightLocation = {\n href: '',\n pathname: '',\n search: {},\n searchStr: '',\n state: {},\n hash: '',\n};\n\ninterface ContextData {\n queryClient: QueryClient;\n settings: StoreContext | null;\n locale: string;\n routeId: string;\n location: TwilightLocation;\n authToken: string | null;\n scope: ActiveScope | null;\n storeId: string | null;\n requestHost: string | null;\n i18n?: i18n;\n page?: PageContext;\n appsSnippets?: AppSnippet[];\n appsSettings?: AppSettings;\n extras?: Record<string, unknown>;\n}\n\nconst DEFAULT_DATA: ContextData = {\n queryClient: null as unknown as QueryClient,\n settings: null,\n locale: FALLBACK_LOCALE,\n routeId: '',\n location: { ...DEFAULT_LOCATION },\n authToken: null,\n scope: null,\n storeId: null,\n requestHost: null,\n i18n: undefined,\n page: undefined,\n};\n\n// ============================================================================\n// Storage: AsyncLocalStorage (server) or module-level store (client)\n// ============================================================================\n\ntype AsyncLocalStore<T> = { getStore(): T | undefined; run(val: T, fn: () => unknown): unknown };\n\n// Initialize ALS at module load time for SSR — no race condition\nlet _als: AsyncLocalStore<ContextData> | null = null;\nif (typeof window === 'undefined') {\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const { AsyncLocalStorage } = require('node:async_hooks') as {\n AsyncLocalStorage: new <T>() => AsyncLocalStore<T>;\n };\n _als = new AsyncLocalStorage<ContextData>();\n } catch {\n _als = null;\n }\n}\n\nconst clientStore: ContextData = { ...DEFAULT_DATA };\n\nfunction getTwilightStore(): ContextData {\n if (_als) {\n const store = _als.getStore();\n if (!store)\n throw new Error('[Twilight] No request context. Wrap with runWithTwilightContext().');\n return store;\n }\n return clientStore;\n}\n\nfunction writableStore(): ContextData {\n if (_als) {\n const store = _als.getStore();\n if (store) return store;\n }\n return clientStore;\n}\n\nfunction mergeIntoStore(store: ContextData, partial: Partial<TwilightContext>): void {\n if ('queryClient' in partial && partial.queryClient) store.queryClient = partial.queryClient;\n if ('settings' in partial && partial.settings != null) store.settings = partial.settings;\n if ('locale' in partial && partial.locale != null) store.locale = partial.locale;\n if ('routeId' in partial && partial.routeId != null) store.routeId = partial.routeId;\n if ('location' in partial && partial.location != null)\n store.location = { ...store.location, ...partial.location };\n if ('authToken' in partial && partial.authToken !== undefined)\n store.authToken = partial.authToken ?? null;\n if ('scope' in partial && partial.scope !== undefined) store.scope = partial.scope ?? null;\n else if ('scopeId' in partial && partial.scopeId !== undefined)\n store.scope = partial.scopeId == null ? null : { id: partial.scopeId };\n if ('storeId' in partial && partial.storeId !== undefined)\n store.storeId = partial.storeId ?? null;\n if ('requestHost' in partial && partial.requestHost !== undefined)\n store.requestHost = partial.requestHost ?? null;\n if ('i18n' in partial && partial.i18n != null) store.i18n = partial.i18n;\n if ('page' in partial) store.page = partial.page;\n if ('appsSnippets' in partial) store.appsSnippets = partial.appsSnippets;\n if ('appsSettings' in partial) store.appsSettings = partial.appsSettings;\n if ('extras' in partial) store.extras = partial.extras;\n}\n\n// ============================================================================\n// Public API\n// ============================================================================\n\nexport function runWithTwilightContext<T>(partial: Partial<TwilightContext>, fn: () => T): T {\n if (_als) {\n const data: ContextData = { ...DEFAULT_DATA };\n mergeIntoStore(data, partial);\n return _als.run(data, fn) as T;\n }\n mergeIntoStore(clientStore, partial);\n return fn();\n}\n\n// Client-only subscription so React consumers (useRouteId/useIsHome/…) re-render\n// when navigation mutates the module store. Mirrors hooks/useWishlist.ts.\nconst listeners = new Set<() => void>();\n\nexport function subscribeTwilight(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\nexport function updateTwilightContext(partial: Partial<TwilightContext>): void {\n mergeIntoStore(getTwilightStore(), partial);\n // Server uses AsyncLocalStorage and has no React subscribers; notify on client only.\n if (typeof window !== 'undefined') {\n for (const listener of listeners) listener();\n }\n}\n\n/**\n * Whether store settings are available, without throwing.\n *\n * `getTwilightContext().settings` throws a `SettingsError` when the store is\n * empty, which is fatal inside a head function during hydration. Callers that\n * need to *test* availability must use this instead of a try/catch around the\n * getter. Returns false when there is no request context at all (server-side\n * calls outside `runWithTwilightContext`).\n */\nexport function hasTwilightSettings(): boolean {\n try {\n return getTwilightStore().settings != null;\n } catch {\n return false;\n }\n}\n\n/**\n * The store this request names and the host it arrived on, without throwing.\n *\n * Separate from {@link getTwilightContext} because store identity is read while\n * deciding *what to fetch* — before there is a context worth having — and on the\n * server outside a request the getter throws. A caller asking \"which store?\" has\n * a sane answer for \"none named\"; it has none for an exception.\n */\nexport function getRequestStore(): { storeId: string | null; requestHost: string | null } {\n try {\n const data = getTwilightStore();\n return { storeId: data.storeId, requestHost: data.requestHost };\n } catch {\n return { storeId: null, requestHost: null };\n }\n}\n\nexport function getTwilightContext(): TwilightContext {\n const data = getTwilightStore();\n return {\n get queryClient() {\n return data.queryClient;\n },\n get settings() {\n if (!data.settings) throw new SettingsError();\n return data.settings;\n },\n get locale() {\n return data.locale;\n },\n get routeId() {\n return data.routeId;\n },\n get location() {\n return data.location;\n },\n get authToken() {\n return data.authToken;\n },\n get scope() {\n return data.scope;\n },\n get scopeId() {\n return data.scope?.id ?? null;\n },\n get storeId() {\n return data.storeId;\n },\n get requestHost() {\n return data.requestHost;\n },\n get i18n() {\n if (!data.i18n) {\n const translations = data.queryClient?.getQueryData(['translations']) as\n TranslationMessages | undefined;\n data.i18n = createI18nInstance(data.locale, translations);\n }\n return data.i18n;\n },\n get dir() {\n return getLanguageInfo(data.locale).dir;\n },\n get page() {\n return data.page;\n },\n get appsSnippets() {\n return data.appsSnippets;\n },\n get appsSettings() {\n return data.appsSettings;\n },\n get extras() {\n return data.extras;\n },\n };\n}\n\n/** @internal Reset store for testing */\nexport function resetForTesting(): void {\n Object.assign(writableStore(), { ...DEFAULT_DATA });\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/client.ts"],"names":[],"mappings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A,CAAY,aAAA,EAAe,CAAA,OAAA,EAAU,KAAK,CAAA,CAAE,CAAA;AAAA,QAClE;AAIA,QAAA,MAAM,QAAQ,cAAA,EAAe;AAC7B,QAAA,IAAI,KAAA,EAAO;AACT,UAAA,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,WAAA,CAAY,QAAA,EAAU,MAAM,EAAE,CAAA;AAClD,UAAA,IAAI,KAAA,CAAM,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAI,WAAA,CAAY,UAAA,EAAY,MAAM,IAAI,CAAA;AACtE,UAAA,IAAI,KAAA,CAAM,eAAA;AACR,YAAA,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,WAAA,CAAY,qBAAA,EAAuB,MAAM,eAAe,CAAA;AAC9E,UAAA,IAAI,KAAA,CAAM,aAAA;AACR,YAAA,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,WAAA,CAAY,mBAAA,EAAqB,MAAM,aAAa,CAAA;AAAA,QAC5E;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-WXOABH6J.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 extractScopeFromCookies,\n extractTokenFromCookies,\n readSdkScope,\n type ActiveScope,\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 SCOPE_TYPE: 's-scope-type',\n SCOPE_ALLOCATION_TYPE: 's-scope-allocation-type',\n SCOPE_ALLOCATION_ID: 's-scope-allocation-id',\n} as const;\n\n/**\n * The header every Salla API call is answered by store.\n *\n * Exported because a caller that already knows which store it is asking about\n * must be able to say so on the request itself — see `store.settings`. Without\n * it the only way to name a store is the ambient resolver, and \"the identifier\n * I checked\" and \"the identifier that was sent\" become two different things.\n */\nexport const STORE_IDENTIFIER_HEADER = API_HEADERS.STORE_IDENTIFIER;\n\n/**\n * Active scope: the market plus its branch allocation, as the SDK stores it. On the\n * client it comes from `salla.storage.get('scope')`; before the SDK hydrates storage\n * it falls back to the `scope` cookie the theme mirrors that selection into (see\n * writeScopeCookie), then to the scope twilightMiddleware seeded from the same\n * cookie on the server. Requests vary by the `s-scope-*` headers, so React Query\n * keys must include this to avoid serving another branch'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 getActiveScope = (): ActiveScope | 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 = readSdkScope();\n if (fromStorage !== undefined) return fromStorage;\n\n if (typeof document !== 'undefined') {\n const fromCookie = extractScopeFromCookies(document.cookie);\n if (fromCookie != null) return fromCookie;\n }\n\n try {\n return getTwilightContext().scope;\n } catch {\n return null;\n }\n};\n\n/** {@link getActiveScope} reduced to the market id. */\nexport const getActiveScopeId = (): string | null => getActiveScope()?.id ?? null;\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 // Only when the caller did not say. `headers.set` here would otherwise\n // overwrite a per-request identifier with the ambient one, which is a\n // silent way to answer a question about one store with another's data.\n if (!request.headers.get(API_HEADERS.STORE_IDENTIFIER)) {\n request.headers.set(API_HEADERS.STORE_IDENTIFIER, getStoreIdentifier());\n }\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 // The same four the SDK's own client sends. The API resolves stock per\n // allocation: id alone asks about the market, not the branch the shopper chose.\n const scope = getActiveScope();\n if (scope) {\n request.headers.set(API_HEADERS.SCOPE_ID, scope.id);\n if (scope.type) request.headers.set(API_HEADERS.SCOPE_TYPE, scope.type);\n if (scope.allocation_type)\n request.headers.set(API_HEADERS.SCOPE_ALLOCATION_TYPE, scope.allocation_type);\n if (scope.allocation_id)\n request.headers.set(API_HEADERS.SCOPE_ALLOCATION_ID, scope.allocation_id);\n }\n },\n ],\n },\n});\n\nexport const cdn = ky.extend({\n prefix: 'https://cdn.salla.network',\n timeout: 5000,\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/cookies.ts","../src/utils/inline-script.ts","../src/utils/runtime-env.ts","../src/utils/store-identity.ts","../src/utils/sdk-helpers.ts"],"names":[],"mappings":";;;AAAO,IAAM,sBAAA,GAAyB;AAC/B,IAAM,iBAAA,GAAoB,OAAA;AAoB1B,IAAM,oBAAA,GAAuB,WAAA;AAG7B,IAAM,cAAA,GAAiB,SAAA;AAUvB,SAAS,aAAa,GAAA,EAA+C;AAC1E,EAAA,IAAI,CAAC,KAAK,OAAO,IAAA;AACjB,EAAA,OAAO,oBAAA,CAAqB,IAAA,CAAK,GAAG,CAAA,GAAI,GAAA,GAAM,IAAA;AAChD;AAGO,SAAS,0BAA0B,YAAA,EAA4C;AACpF,EAAA,OAAO,YAAA,CAAa,uBAAA,CAAwB,YAAA,EAAc,oBAAoB,CAAC,CAAA;AACjF;AAqBO,IAAM,cAAA,GAAoC,CAAC,sBAAsB,CAAA;AAGxE,SAAS,WAAW,IAAA,EAAsB;AACxC,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,IAAA,EAAK,CAAE,WAAA,EAAY;AAExC,EAAA,IAAI,OAAA,CAAQ,UAAA,CAAW,GAAG,CAAA,EAAG,OAAO,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,GAAG,CAAA,GAAI,CAAC,CAAA,IAAK,OAAA;AAClF,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,OAAA,CAAQ,GAAG,CAAA;AACjC,EAAA,OAAO,UAAU,EAAA,GAAK,OAAA,GAAU,OAAA,CAAQ,KAAA,CAAM,GAAG,KAAK,CAAA;AACxD;AAEA,SAAS,WAAW,QAAA,EAA2B;AAC7C,EAAA,OACE,QAAA,KAAa,eACb,QAAA,KAAa,WAAA,IACb,aA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AAA,IAAI,mBAAA,CAAoB,WAAW,CAAA,EAAG,OAAO,WAAA;AAE7C,EAAA,OAAO,OAAA,CAAQ,mBAAmB,CAAA,IAAK,OAAA,CAAQ,cAAc,CAAA,IAAK,EAAA;AACpE;;;AC/DA,IAAM,SAAA,GAAY,OAAO,MAAA,KAAW,WAAA;AAc7B,SAAS,mBAAmB,QAAA,EAA2B;AAC5D,EAAA,OAAO,uBAAuB,QAAQ,CAAA;AACxC;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-Y5FBDMFV.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 * Whether this host *is* a store, so its name can be used as the identifier.\n *\n * The exact inverse of {@link allowsRequestStoreId}, and deliberately written as\n * one so the two can never disagree: a host that may name its store is a host\n * that serves more than one, and a host that serves more than one cannot be the\n * answer to \"which store is this?\". `preview.salla.design` and `localhost:5188`\n * are not shops; asking the API about them earns a 422 and a page that reads as\n * a broken theme.\n */\nexport function hostIdentifiesStore(host: string | null | undefined): boolean {\n return Boolean(host) && !allowsRequestStoreId(host);\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 * The scope the Salla SDK persists as `scope`: the market (`id`/`type`) plus, once\n * bullet delivery confirms an address or branch, the allocation. The SDK sends all\n * four as request headers (`s-scope-id`, `s-scope-type`, `s-scope-allocation-type`,\n * `s-scope-allocation-id`) and the API resolves stock per allocation — a scope sent\n * without its allocation is a different question, answered from a different branch.\n */\nexport interface ActiveScope {\n id: string;\n type?: string;\n allocation_type?: string;\n allocation_id?: string;\n}\n\n/** The SDK stores the scope either as its full object or as a bare id. */\nfunction normalizeScope(raw: unknown): ActiveScope | null {\n if (raw == null) return null;\n if (typeof raw !== 'object') return { id: String(raw) };\n const s = raw as Record<string, unknown>;\n if (s.id == null) return null;\n const scope: ActiveScope = { id: String(s.id) };\n if (s.type != null) scope.type = String(s.type);\n if (s.allocation_type != null) scope.allocation_type = String(s.allocation_type);\n if (s.allocation_id != null) scope.allocation_id = String(s.allocation_id);\n return scope;\n}\n\n/**\n * Reads the active scope from the `scope` cookie, which Salla persists as a JSON\n * object (e.g. `{\"id\":123,\"type\":\"scope\",\"allocation_type\":\"branch\",\"allocation_id\":\"9\"}`).\n * Returns null when the cookie is missing or unparseable. Used server-side, where\n * `salla.storage` is absent.\n */\nexport function extractScopeFromCookies(cookieHeader: string | null): ActiveScope | null {\n const raw = extractTokenFromCookies(cookieHeader, SCOPE_COOKIE_NAME);\n if (!raw) return null;\n try {\n return normalizeScope(JSON.parse(raw));\n } catch {\n return null;\n }\n}\n\n/** {@link extractScopeFromCookies} reduced to the id. */\nexport function extractScopeIdFromCookies(cookieHeader: string | null): string | null {\n return extractScopeFromCookies(cookieHeader)?.id ?? null;\n}\n\n/**\n * The scope the Salla SDK persisted in its storage (`salla.storage.get('scope')`).\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 readSdkScope(): ActiveScope | null | undefined {\n const storage = typeof window !== 'undefined' ? window.salla?.storage : undefined;\n if (typeof storage?.get !== 'function') return undefined;\n return normalizeScope(storage.get(SCOPE_COOKIE_NAME));\n}\n\n/** {@link readSdkScope} reduced to the id; keeps the not-ready/none distinction. */\nexport function readSdkScopeId(): string | null | undefined {\n const scope = readSdkScope();\n return scope === undefined ? undefined : (scope?.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\nconst sameScope = (a: ActiveScope | null, b: ActiveScope | null): boolean =>\n JSON.stringify(a) === JSON.stringify(b);\n\n/**\n * Mirrors the scope 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 extractScopeFromCookies} parses it,\n * allocation included: the bullet-delivery component writes the same cookie with the\n * full object, and rewriting it with the id alone would drop the branch the server\n * needs. Returns true when the cookie was (re)written. Client-only; no-op on the server.\n */\nexport function writeScopeCookie(scope: ActiveScope | null): boolean {\n if (typeof document === 'undefined') return false;\n if (sameScope(extractScopeFromCookies(document.cookie), scope)) return false;\n\n if (scope == 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(scope));\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 scope = readSdkScope();\n return scope === undefined ? false : writeScopeCookie(scope);\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';\nimport { hostIdentifiesStore } from './cookies';\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 ||\n storeId ||\n (hostIdentifiesStore(requestHost) ? requestHost : null) ||\n 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","/**\n * @fileoverview Which store to ask about — the one answer, in one place.\n *\n * This lived in two places once. `api/store.ts` learned to read the store a\n * request names, and `utils/sdk-helpers.ts` — the copy `api/client.ts` actually\n * sets the `store-identifier` header from — did not. So the resolver that had\n * been taught the answer was consulted for a null check and thrown away, every\n * outgoing request carried an empty identifier, the API answered\n * `422 Store Identifier not found`, and every published theme rendered\n * \"Store Unavailable\" while its tests passed: the client's suite mocked the\n * resolver, and the resolver's suite never went near a request.\n *\n * Hence one module, imported by both. If a third place ever needs a store\n * identifier, it imports this — a second implementation is the bug, not a\n * refactor away from it.\n *\n * See `docs/store-identity.md` for the full picture, including the security\n * boundary on who may name a store.\n */\nimport { getRequestStore } from '../twilight/context';\nimport { hostIdentifiesStore } from './cookies';\nimport { getInjectedRuntimeEnv, readEnv } from './runtime-env';\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`, and only\n * on a host permitted to name one;\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 * but only when that host is a storefront. `preview.salla.design` and\n * `localhost` serve many stores, so their names identify none;\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 (hostIdentifiesStore(requestHost)) return requestHost as string;\n\n // The browser's own address, for a client render that reached neither of the\n // above — a live storefront, where the host is the store.\n const browserHost = typeof window !== 'undefined' ? window.location.host : null;\n if (hostIdentifiesStore(browserHost)) return browserHost as string;\n\n return readEnv('VITE_STORE_DOMAIN') || readEnv('STORE_DOMAIN') || '';\n}\n","export type { StoreContext } from '../api/store';\nimport { resolveStoreIdentifier } from './store-identity';\n\nconst isBrowser = typeof window !== 'undefined';\n\n/**\n * Which store to ask the API about — see {@link resolveStoreIdentifier}.\n *\n * A delegation, not a second implementation. This name is the one on the wire\n * (`api/client.ts` sets the `store-identifier` header from it) and the one\n * themes import from `@salla.sa/twilight-theme-engine/utils`, so it stays; what\n * it must never do again is answer differently from the resolver everything\n * else asks. It had its own copy of the order once, missing the store the\n * request names and preferring the build-time `VITE_STORE_DOMAIN` that a\n * deployed worker does not have — so every published theme sent an empty\n * identifier and rendered \"Store Unavailable\".\n */\nexport function getStoreIdentifier(explicit?: string): string {\n return resolveStoreIdentifier(explicit);\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":";;;;;AAQA,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;AAmDA,SAAS,iBAAiB,SAAA,EAA8D;AACtF,EAAA,IAAI,CAAC,WAAW,OAAO,MAAA;AAGvB,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,SAAS,CAAA,CAAE,GAAA,CAAI,CAAC,IAAA,MAAU,EAAE,QAAA,EAAU,IAAA,CAAK,IAAA,EAAM,GAAG,MAAK,CAAE,CAAA;AAClF;AAEO,IAAM,KAAA,GAAQ;AAAA,EACnB,QAAA,EAAU,OAAO,eAAA,KAA2D;AAC1E,IAAA,MAAM,UAAA,GAAa,mBAAmB,sBAAA,EAAuB;AAE7D,IAAA,IAAI,CAAC,UAAA,EAAY;AACf,MAAA,OAAA,CAAQ,KAAK,gDAAgD,CAAA;AAC7D,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,MAAM,aAAA,GAAgB,qBAAA,CAAsB,GAAA,CAAI,CAAC,CAAA,KAAM,aAAa,CAAC,CAAA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AAA,QACrB,cAAA;AAAe,OACjB;AAAA,MACA,OAAA,EAAS,MAAM,KAAA,CAAM,QAAA,CAAS,eAAe;AAAA,KAC9C;AAAA;AAEP","file":"chunk-Z2BE6MDB.js","sourcesContent":["import { queryOptions } from '@tanstack/react-query';\nimport { api, getActiveScope, getActiveScopeId, STORE_IDENTIFIER_HEADER } from './client';\nimport type { Store, Theme, Language } from '../types';\nimport { getTwilightContext } from '../twilight/context';\nimport { resolveStoreIdentifier } from '../utils/store-identity';\n\nexport { resolveStoreIdentifier };\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 * 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 // Sent explicitly rather than left to the client's own resolution, so\n // the identifier this function checked is the identifier that travels.\n // They agree today; a caller passing one and being answered about\n // another is the failure this makes impossible rather than unlikely.\n .get(`store/settings?${params}`, {\n timeout: 5000,\n headers: { [STORE_IDENTIFIER_HEADER]: identifier },\n })\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 getActiveScope(),\n ],\n queryFn: () => store.settings(storeIdentifier),\n }),\n },\n};\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export { RouteDocumentSync, TanStackDocumentSync, tanstackDocumentAdapter, useTanstackDocumentAttrs } from './chunk-PZCHYB7O.js';
|
|
2
|
-
import './chunk-Z4Y55HWX.js';
|
|
3
|
-
import './chunk-FQGCCV4T.js';
|
|
4
|
-
import './chunk-EV4JSMFZ.js';
|
|
5
|
-
import './chunk-B3EFOE57.js';
|
|
6
|
-
import './chunk-Z2BE6MDB.js';
|
|
7
|
-
import './chunk-GCAIIFF3.js';
|
|
8
|
-
import './chunk-TZ3E5BN4.js';
|
|
9
|
-
import './chunk-TXYT42AU.js';
|
|
10
|
-
import './chunk-LG556DIE.js';
|
|
11
|
-
import './chunk-E3J2RXBS.js';
|
|
12
|
-
import './chunk-MTONGOJD.js';
|
|
13
|
-
import './chunk-WXOABH6J.js';
|
|
14
|
-
import './chunk-Y5FBDMFV.js';
|
|
15
|
-
import './chunk-5ACY5CD3.js';
|
|
16
|
-
import './chunk-JWXJPJBO.js';
|
|
17
|
-
import './chunk-CW625T2E.js';
|
|
18
|
-
import './chunk-TYNZ5B2B.js';
|
|
19
|
-
import './chunk-T72DAX7R.js';
|
|
20
|
-
import './chunk-DF6FBKDN.js';
|
|
21
|
-
import './chunk-DGUM43GV.js';
|
|
22
|
-
//# sourceMappingURL=document-class-HFVPENQI.js.map
|
|
23
|
-
//# sourceMappingURL=document-class-HFVPENQI.js.map
|