@cartbase/storefront 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/package.json +4 -1
- package/src/api/auth.ts +108 -108
- package/src/api/carts.ts +523 -523
- package/src/api/categories.ts +184 -184
- package/src/api/checkout.ts +526 -526
- package/src/api/collections.ts +130 -130
- package/src/api/consent.ts +75 -75
- package/src/api/content.ts +125 -125
- package/src/api/customers.ts +303 -303
- package/src/api/gift-cards.ts +112 -112
- package/src/api/http.ts +181 -180
- package/src/api/index.ts +30 -30
- package/src/api/menus.ts +77 -77
- package/src/api/metaobjects.ts +136 -136
- package/src/api/orders.ts +290 -290
- package/src/api/redirects.ts +37 -37
- package/src/api/regions.ts +200 -200
- package/src/api/search.ts +163 -163
- package/src/api/store.ts +56 -35
- package/src/api/types.ts +91 -91
- package/src/cart-drawer/context.tsx +778 -778
- package/src/cart-drawer/cross-sell-carousel.tsx +211 -211
- package/src/cart-drawer/cross-sell-sidebar.tsx +158 -158
- package/src/cart-drawer/gift-wrap.tsx +82 -82
- package/src/cart-drawer/item/index.tsx +162 -162
- package/src/cart-drawer/item/upsell.tsx +110 -110
- package/src/cart-drawer/labels.ts +123 -123
- package/src/cart-drawer/mutation-queue.ts +78 -78
- package/src/cart-drawer/notes.tsx +131 -131
- package/src/cart-drawer/payment-badges.tsx +36 -96
- package/src/cart-drawer/sticky-footer.tsx +73 -73
- package/src/cart-drawer/summary-breakdown.tsx +197 -197
- package/src/checkout/address-error-copy.ts +117 -117
- package/src/checkout/boxnow-locker-selector.tsx +410 -410
- package/src/checkout/compare-addresses.ts +40 -40
- package/src/checkout/discount-section.tsx +218 -218
- package/src/checkout/error-copy-codes.ts +63 -63
- package/src/checkout/geocode.ts +154 -154
- package/src/checkout/gift-card-section.tsx +224 -224
- package/src/checkout/index.ts +72 -72
- package/src/checkout/labels.ts +495 -495
- package/src/checkout/payment-button.tsx +372 -372
- package/src/checkout/payment-error-copy.ts +154 -154
- package/src/checkout/promotion-error-copy.ts +91 -91
- package/src/common/country-flag.tsx +52 -52
- package/src/common/country-select.tsx +11 -11
- package/src/common/icons/cartbase-mark.ts +9 -0
- package/src/common/icons/payment-marks.ts +73 -0
- package/src/common/icons/social-marks.ts +61 -0
- package/src/common/index.ts +35 -20
- package/src/common/market-select.tsx +57 -57
- package/src/common/payment-icons.tsx +54 -0
- package/src/common/powered-by-cartbase.tsx +47 -0
- package/src/common/social-links.tsx +65 -0
- package/src/index.ts +12 -12
- package/src/lib/country-name.ts +59 -59
- package/src/lib/get-product-price.ts +133 -133
- package/src/lib/media-image.tsx +39 -39
- package/src/lib/payment-constants.ts +53 -53
- package/src/lib/platform.ts +13 -13
- package/src/lib/price.tsx +39 -39
- package/src/lib/store-api-error.ts +36 -36
- package/src/lib/variant-caption.ts +32 -32
- package/src/locales/bg.ts +3 -0
- package/src/locales/context.ts +37 -37
- package/src/locales/en.ts +26 -26
- package/src/locales/es.ts +3 -0
- package/src/locales/index.ts +19 -19
- package/src/locales/provider.tsx +59 -59
- package/src/locales/types.ts +77 -77
- package/src/order/index.ts +62 -62
- package/src/order/labels.ts +79 -79
- package/src/order/order-totals.tsx +250 -250
- package/src/primitives/select-field.tsx +93 -93
- package/src/products/image-gallery.tsx +43 -43
- package/src/products/option-select.tsx +67 -67
- package/src/products/product-info.tsx +5 -5
- package/src/products/product-price.tsx +69 -69
- package/src/products/product-promises.tsx +61 -61
- package/src/products/product-specs.tsx +65 -65
- package/src/products/product-tabs.tsx +123 -123
- package/src/products/purchase-options.tsx +130 -130
- package/src/products/sets.ts +110 -110
- package/src/products/variant-matching.ts +71 -71
- package/src/products/variant-url.ts +74 -74
- package/src/reviews-ui/lightbox-state.ts +46 -46
- package/src/reviews-ui/review-header.tsx +166 -166
- package/src/reviews-ui/review-lightbox.tsx +271 -271
- package/src/reviews-ui/review-list.tsx +193 -193
- package/src/reviews-ui/review-widget.tsx +219 -218
- package/src/reviews-ui/widget-options.ts +55 -55
- package/src/store/category-template.tsx +136 -136
- package/src/store/index.ts +40 -40
- package/src/store/labels.ts +10 -0
- package/src/tracking/chatgpt-pixel.tsx +99 -99
- package/src/tracking/consent-init.tsx +62 -62
- package/src/tracking/events.ts +348 -348
- package/src/tracking/ga4.tsx +93 -93
- package/src/tracking/google-ads.ts +84 -84
- package/src/tracking/gtm.tsx +60 -60
- package/src/tracking/inline-script.ts +49 -49
- package/src/tracking/oaiq.ts +206 -206
- package/src/tracking/tiktok-pixel.tsx +91 -91
- package/src/tracking/track-init.tsx +56 -56
- package/src/tracking/track-order-purchase.tsx +122 -122
- package/src/tracking/ttq.ts +180 -180
- package/src/tracking/use-tracking-config.ts +54 -54
- package/theme/index.css +25 -25
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Cartbase
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cartbase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cartbase/storefront",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Storefront SDK + UI component library for Cartbase stores: typed API client, checkout orchestration, cart drawer, product/catalog components, tracking. Source-shipped TypeScript — add it to transpilePackages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -203,6 +203,9 @@
|
|
|
203
203
|
"./common/country-select": "./src/common/country-select.tsx",
|
|
204
204
|
"./common/language-select": "./src/common/language-select.tsx",
|
|
205
205
|
"./common/skeleton": "./src/common/skeleton.tsx",
|
|
206
|
+
"./common/payment-icons": "./src/common/payment-icons.tsx",
|
|
207
|
+
"./common/social-links": "./src/common/social-links.tsx",
|
|
208
|
+
"./common/powered-by-cartbase": "./src/common/powered-by-cartbase.tsx",
|
|
206
209
|
"./reviews-ui": "./src/reviews-ui/index.ts",
|
|
207
210
|
"./locales": "./src/locales/index.ts",
|
|
208
211
|
"./locales/en": "./src/locales/en.ts",
|
package/src/api/auth.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @cartbase/storefront/api/auth — passwordless code login (customer-accounts
|
|
3
|
-
* card §2, Shopify Customer Account API direction).
|
|
4
|
-
*
|
|
5
|
-
* Ground truth: src/app/api/store/auth/code/{request,verify}/route.ts +
|
|
6
|
-
* src/lib/customer-auth/{codes,session}.ts.
|
|
7
|
-
*
|
|
8
|
-
* ## Session discipline (READ THIS before wiring auth)
|
|
9
|
-
*
|
|
10
|
-
* `verifyLoginCode` mints a REAL Supabase session. The `access_token` is the
|
|
11
|
-
* SAME `authorization: Bearer <jwt>` every /api/store/* route accepts — wire
|
|
12
|
-
* it into `StorefrontClient` via `getAuthToken` and every subsequent call
|
|
13
|
-
* (customers/me, orders, documents, cart-attach) is authenticated:
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* const { access_token, refresh_token } = await verifyLoginCode(client, { email, code })
|
|
17
|
-
* // persist both; then construct/refresh the client with:
|
|
18
|
-
* // getAuthToken: () => readStoredAccessToken()
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* Tokens expire (`expires_in` seconds / `expires_at` epoch-seconds): refresh
|
|
22
|
-
* with the Supabase client (`supabase.auth.setSession({access_token,
|
|
23
|
-
* refresh_token})` then `refreshSession()`) — the Cartbase API does not proxy
|
|
24
|
-
* token refresh. Password login (supabase.auth.signInWithPassword
|
|
25
|
-
* client-side) yields an equivalent JWT and needs nothing from this module.
|
|
26
|
-
*
|
|
27
|
-
* ## Security posture (server-enforced; the SDK adds nothing)
|
|
28
|
-
* - request NEVER reveals whether the email is registered (`{ok:true}`
|
|
29
|
-
* always — no enumeration oracle); the 6-digit code exists only in the
|
|
30
|
-
* sent email.
|
|
31
|
-
* - Codes: hashed at rest, TTL 10 min, single-use, one live code per email
|
|
32
|
-
* (a new request supersedes prior codes), 5-wrong-attempt lockout.
|
|
33
|
-
* - Rate limits (per 15-min window): 5 requests per email, 20 per IP →
|
|
34
|
-
* `429 rate_limited` — the ONLY distinguishable request failure.
|
|
35
|
-
* - Every verify failure is `401 invalid_code` (generic, no oracle).
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
import type { StorefrontClient } from "./http"
|
|
39
|
-
import type { StoreCustomer } from "./customers"
|
|
40
|
-
|
|
41
|
-
export interface RequestLoginCodeInput {
|
|
42
|
-
email: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface RequestLoginCodeResponse {
|
|
46
|
-
/** Always true — success is deliberately indistinguishable per email. */
|
|
47
|
-
ok: true
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* POST /api/store/auth/code/request — passwordless login step 1: email a
|
|
52
|
-
* 6-digit one-time code. Always `{ok: true}` (no enumeration oracle);
|
|
53
|
-
* first-time emails register lazily at VERIFY, not here.
|
|
54
|
-
*
|
|
55
|
-
* Auth: anon (x-client-id only).
|
|
56
|
-
* Errors: 429 rate_limited (5/email or 20/IP per 15 min) ·
|
|
57
|
-
* 400 validation_failed (malformed email) · 400 missing_client_id.
|
|
58
|
-
* Settings: the `auth-code` email template (notifications) carries the code.
|
|
59
|
-
*/
|
|
60
|
-
export async function requestLoginCode(
|
|
61
|
-
client: StorefrontClient,
|
|
62
|
-
input: RequestLoginCodeInput
|
|
63
|
-
): Promise<RequestLoginCodeResponse> {
|
|
64
|
-
return client.post("/api/store/auth/code/request", input)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface VerifyLoginCodeInput {
|
|
68
|
-
email: string
|
|
69
|
-
/** Exactly 6 digits (leading zeros count) — anything else → 400. */
|
|
70
|
-
code: string
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* The minted session — a real Supabase token pair plus the resolved
|
|
75
|
-
* customer (addresses embedded).
|
|
76
|
-
*/
|
|
77
|
-
export interface CustomerSessionResponse {
|
|
78
|
-
/** Supabase JWT — send as `authorization: Bearer <access_token>`. */
|
|
79
|
-
access_token: string
|
|
80
|
-
refresh_token: string
|
|
81
|
-
/** Seconds until expiry. */
|
|
82
|
-
expires_in: number
|
|
83
|
-
/** Unix epoch seconds of expiry (may be absent). */
|
|
84
|
-
expires_at: number | undefined
|
|
85
|
-
/** `"bearer"` */
|
|
86
|
-
token_type: string
|
|
87
|
-
customer: StoreCustomer
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* POST /api/store/auth/code/verify — passwordless login step 2: exchange
|
|
92
|
-
* (email, code) for a session. This is ALSO passwordless registration — a
|
|
93
|
-
* first-time email lazy-creates the customer (account_status per the store
|
|
94
|
-
* approval policy) and triggers the welcome email.
|
|
95
|
-
*
|
|
96
|
-
* Auth: anon (x-client-id only).
|
|
97
|
-
* Errors: 401 invalid_code (wrong/expired/consumed/locked-out — always
|
|
98
|
-
* generic) · 400 validation_failed (email shape, non-6-digit code) ·
|
|
99
|
-
* 400 missing_client_id.
|
|
100
|
-
* Settings: store approval policy (`account_status` of new customers);
|
|
101
|
-
* `account-welcome` email template.
|
|
102
|
-
*/
|
|
103
|
-
export async function verifyLoginCode(
|
|
104
|
-
client: StorefrontClient,
|
|
105
|
-
input: VerifyLoginCodeInput
|
|
106
|
-
): Promise<CustomerSessionResponse> {
|
|
107
|
-
return client.post("/api/store/auth/code/verify", input)
|
|
108
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @cartbase/storefront/api/auth — passwordless code login (customer-accounts
|
|
3
|
+
* card §2, Shopify Customer Account API direction).
|
|
4
|
+
*
|
|
5
|
+
* Ground truth: src/app/api/store/auth/code/{request,verify}/route.ts +
|
|
6
|
+
* src/lib/customer-auth/{codes,session}.ts.
|
|
7
|
+
*
|
|
8
|
+
* ## Session discipline (READ THIS before wiring auth)
|
|
9
|
+
*
|
|
10
|
+
* `verifyLoginCode` mints a REAL Supabase session. The `access_token` is the
|
|
11
|
+
* SAME `authorization: Bearer <jwt>` every /api/store/* route accepts — wire
|
|
12
|
+
* it into `StorefrontClient` via `getAuthToken` and every subsequent call
|
|
13
|
+
* (customers/me, orders, documents, cart-attach) is authenticated:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const { access_token, refresh_token } = await verifyLoginCode(client, { email, code })
|
|
17
|
+
* // persist both; then construct/refresh the client with:
|
|
18
|
+
* // getAuthToken: () => readStoredAccessToken()
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Tokens expire (`expires_in` seconds / `expires_at` epoch-seconds): refresh
|
|
22
|
+
* with the Supabase client (`supabase.auth.setSession({access_token,
|
|
23
|
+
* refresh_token})` then `refreshSession()`) — the Cartbase API does not proxy
|
|
24
|
+
* token refresh. Password login (supabase.auth.signInWithPassword
|
|
25
|
+
* client-side) yields an equivalent JWT and needs nothing from this module.
|
|
26
|
+
*
|
|
27
|
+
* ## Security posture (server-enforced; the SDK adds nothing)
|
|
28
|
+
* - request NEVER reveals whether the email is registered (`{ok:true}`
|
|
29
|
+
* always — no enumeration oracle); the 6-digit code exists only in the
|
|
30
|
+
* sent email.
|
|
31
|
+
* - Codes: hashed at rest, TTL 10 min, single-use, one live code per email
|
|
32
|
+
* (a new request supersedes prior codes), 5-wrong-attempt lockout.
|
|
33
|
+
* - Rate limits (per 15-min window): 5 requests per email, 20 per IP →
|
|
34
|
+
* `429 rate_limited` — the ONLY distinguishable request failure.
|
|
35
|
+
* - Every verify failure is `401 invalid_code` (generic, no oracle).
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
import type { StorefrontClient } from "./http"
|
|
39
|
+
import type { StoreCustomer } from "./customers"
|
|
40
|
+
|
|
41
|
+
export interface RequestLoginCodeInput {
|
|
42
|
+
email: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface RequestLoginCodeResponse {
|
|
46
|
+
/** Always true — success is deliberately indistinguishable per email. */
|
|
47
|
+
ok: true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* POST /api/store/auth/code/request — passwordless login step 1: email a
|
|
52
|
+
* 6-digit one-time code. Always `{ok: true}` (no enumeration oracle);
|
|
53
|
+
* first-time emails register lazily at VERIFY, not here.
|
|
54
|
+
*
|
|
55
|
+
* Auth: anon (x-client-id only).
|
|
56
|
+
* Errors: 429 rate_limited (5/email or 20/IP per 15 min) ·
|
|
57
|
+
* 400 validation_failed (malformed email) · 400 missing_client_id.
|
|
58
|
+
* Settings: the `auth-code` email template (notifications) carries the code.
|
|
59
|
+
*/
|
|
60
|
+
export async function requestLoginCode(
|
|
61
|
+
client: StorefrontClient,
|
|
62
|
+
input: RequestLoginCodeInput
|
|
63
|
+
): Promise<RequestLoginCodeResponse> {
|
|
64
|
+
return client.post("/api/store/auth/code/request", input)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface VerifyLoginCodeInput {
|
|
68
|
+
email: string
|
|
69
|
+
/** Exactly 6 digits (leading zeros count) — anything else → 400. */
|
|
70
|
+
code: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The minted session — a real Supabase token pair plus the resolved
|
|
75
|
+
* customer (addresses embedded).
|
|
76
|
+
*/
|
|
77
|
+
export interface CustomerSessionResponse {
|
|
78
|
+
/** Supabase JWT — send as `authorization: Bearer <access_token>`. */
|
|
79
|
+
access_token: string
|
|
80
|
+
refresh_token: string
|
|
81
|
+
/** Seconds until expiry. */
|
|
82
|
+
expires_in: number
|
|
83
|
+
/** Unix epoch seconds of expiry (may be absent). */
|
|
84
|
+
expires_at: number | undefined
|
|
85
|
+
/** `"bearer"` */
|
|
86
|
+
token_type: string
|
|
87
|
+
customer: StoreCustomer
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* POST /api/store/auth/code/verify — passwordless login step 2: exchange
|
|
92
|
+
* (email, code) for a session. This is ALSO passwordless registration — a
|
|
93
|
+
* first-time email lazy-creates the customer (account_status per the store
|
|
94
|
+
* approval policy) and triggers the welcome email.
|
|
95
|
+
*
|
|
96
|
+
* Auth: anon (x-client-id only).
|
|
97
|
+
* Errors: 401 invalid_code (wrong/expired/consumed/locked-out — always
|
|
98
|
+
* generic) · 400 validation_failed (email shape, non-6-digit code) ·
|
|
99
|
+
* 400 missing_client_id.
|
|
100
|
+
* Settings: store approval policy (`account_status` of new customers);
|
|
101
|
+
* `account-welcome` email template.
|
|
102
|
+
*/
|
|
103
|
+
export async function verifyLoginCode(
|
|
104
|
+
client: StorefrontClient,
|
|
105
|
+
input: VerifyLoginCodeInput
|
|
106
|
+
): Promise<CustomerSessionResponse> {
|
|
107
|
+
return client.post("/api/store/auth/code/verify", input)
|
|
108
|
+
}
|