@doswiftly/cli 0.1.18 → 0.1.20
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/README.md +23 -323
- package/dist/commands/check.js +1 -1
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/deploy.d.ts +20 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +249 -17
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/doctor.js +3 -3
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.js +4 -4
- package/dist/commands/sdk.js +5 -5
- package/dist/commands/sdk.js.map +1 -1
- package/dist/commands/template.js +4 -4
- package/dist/commands/template.js.map +1 -1
- package/dist/commands/types.js +5 -5
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/verify.js +2 -2
- package/dist/commands/verify.js.map +1 -1
- package/dist/lib/package-manager.d.ts +1 -1
- package/dist/lib/package-manager.js +1 -1
- package/package.json +4 -4
- package/templates/storefront-minimal/.github/workflows/build-template.yml +10 -0
- package/templates/storefront-minimal/wrangler.toml +11 -0
- package/templates/storefront-nextjs/.github/workflows/build-template.yml +10 -0
- package/templates/storefront-nextjs/README.md +16 -12
- package/templates/storefront-nextjs/app/account/orders/page.tsx +2 -2
- package/templates/storefront-nextjs/app/account/page.tsx +2 -2
- package/templates/storefront-nextjs/app/auth/login/page.tsx +1 -1
- package/templates/storefront-nextjs/app/auth/register/page.tsx +1 -1
- package/templates/storefront-nextjs/app/cart/page.tsx +1 -1
- package/templates/storefront-nextjs/app/categories/[slug]/page.tsx +2 -2
- package/templates/storefront-nextjs/app/categories/page.tsx +1 -1
- package/templates/storefront-nextjs/app/collections/[slug]/page.tsx +1 -1
- package/templates/storefront-nextjs/app/collections/page.tsx +1 -1
- package/templates/storefront-nextjs/app/page.tsx +1 -1
- package/templates/storefront-nextjs/app/products/[slug]/page.tsx +1 -1
- package/templates/storefront-nextjs/app/products/page.tsx +2 -2
- package/templates/storefront-nextjs/app/search/page.tsx +1 -1
- package/templates/storefront-nextjs/components/auth/auth-guard.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/add-to-cart-button.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/cart-icon.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/currency-selector.tsx +2 -2
- package/templates/storefront-nextjs/components/commerce/product-filters.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/product-price.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/search-input.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/sort-select.tsx +1 -1
- package/templates/storefront-nextjs/components/providers.tsx +1 -1
- package/templates/storefront-nextjs/lib/currency.tsx +3 -3
- package/templates/storefront-nextjs/lib/format.ts +1 -1
- package/templates/storefront-nextjs/lib/graphql-queries.ts +3 -3
- package/templates/storefront-nextjs/package.dev.json +1 -1
- package/templates/storefront-nextjs/package.json +1 -1
- package/templates/storefront-nextjs/package.json.template +1 -1
- package/templates/storefront-nextjs/wrangler.toml +11 -0
- package/templates/storefront-nextjs-shadcn/.github/workflows/build-template.yml +10 -0
- package/templates/storefront-nextjs-shadcn/.github/workflows/deploy.yml +47 -0
- package/templates/storefront-nextjs-shadcn/.github/workflows/preview.yml +47 -0
- package/templates/storefront-nextjs-shadcn/CLAUDE.md +172 -35
- package/templates/storefront-nextjs-shadcn/README.md +29 -162
- package/templates/storefront-nextjs-shadcn/app/{about → [locale]/about}/page.tsx +17 -14
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/addresses/page.tsx +226 -0
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/error.tsx +46 -0
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/loading.tsx +19 -0
- package/templates/storefront-nextjs-shadcn/app/{account → [locale]/account}/loyalty/page.tsx +89 -193
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/orders/[id]/loading.tsx +60 -0
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/orders/[id]/page.tsx +119 -0
- package/templates/storefront-nextjs-shadcn/app/{account → [locale]/account}/orders/[id]/tracking/page.tsx +27 -25
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/orders/page.tsx +101 -0
- package/templates/storefront-nextjs-shadcn/app/{account → [locale]/account}/page.tsx +9 -7
- package/templates/storefront-nextjs-shadcn/app/[locale]/account/settings/page.tsx +208 -0
- package/templates/storefront-nextjs-shadcn/app/{auth → [locale]/auth}/forgot-password/page.tsx +24 -17
- package/templates/storefront-nextjs-shadcn/app/{auth → [locale]/auth}/login/page.tsx +5 -2
- package/templates/storefront-nextjs-shadcn/app/{auth → [locale]/auth}/register/page.tsx +5 -2
- package/templates/storefront-nextjs-shadcn/app/[locale]/blog/[slug]/loading.tsx +17 -0
- package/templates/storefront-nextjs-shadcn/app/{blog → [locale]/blog}/[slug]/page.tsx +44 -3
- package/templates/storefront-nextjs-shadcn/app/[locale]/blog/loading.tsx +19 -0
- package/templates/storefront-nextjs-shadcn/app/{brands → [locale]/brands}/page.tsx +2 -1
- package/templates/storefront-nextjs-shadcn/app/[locale]/cart/loading.tsx +26 -0
- package/templates/storefront-nextjs-shadcn/app/{cart → [locale]/cart}/page.tsx +20 -13
- package/templates/storefront-nextjs-shadcn/app/[locale]/categories/[slug]/category-products-client.tsx +58 -0
- package/templates/storefront-nextjs-shadcn/app/[locale]/categories/[slug]/loading.tsx +32 -0
- package/templates/storefront-nextjs-shadcn/app/[locale]/categories/[slug]/page.tsx +95 -0
- package/templates/storefront-nextjs-shadcn/app/{categories → [locale]/categories}/page.tsx +21 -12
- package/templates/storefront-nextjs-shadcn/app/[locale]/checkout/error.tsx +43 -0
- package/templates/storefront-nextjs-shadcn/app/[locale]/checkout/loading.tsx +31 -0
- package/templates/storefront-nextjs-shadcn/app/{checkout → [locale]/checkout}/page.tsx +334 -253
- package/templates/storefront-nextjs-shadcn/app/{checkout → [locale]/checkout}/success/[orderId]/page.tsx +36 -34
- package/templates/storefront-nextjs-shadcn/app/[locale]/collections/[handle]/loading.tsx +19 -0
- package/templates/storefront-nextjs-shadcn/app/{collections → [locale]/collections}/[handle]/page.tsx +6 -4
- package/templates/storefront-nextjs-shadcn/app/[locale]/collections/loading.tsx +18 -0
- package/templates/storefront-nextjs-shadcn/app/{collections → [locale]/collections}/page.tsx +20 -12
- package/templates/storefront-nextjs-shadcn/app/{contact → [locale]/contact}/page.tsx +24 -21
- package/templates/storefront-nextjs-shadcn/app/{error.tsx → [locale]/error.tsx} +13 -8
- package/templates/storefront-nextjs-shadcn/app/[locale]/layout.tsx +92 -0
- package/templates/storefront-nextjs-shadcn/app/{not-found.tsx → [locale]/not-found.tsx} +13 -18
- package/templates/storefront-nextjs-shadcn/app/{page.tsx → [locale]/page.tsx} +8 -4
- package/templates/storefront-nextjs-shadcn/app/[locale]/products/[slug]/error.tsx +43 -0
- package/templates/storefront-nextjs-shadcn/app/[locale]/products/[slug]/loading.tsx +29 -0
- package/templates/storefront-nextjs-shadcn/app/{products → [locale]/products}/[slug]/page.tsx +17 -14
- package/templates/storefront-nextjs-shadcn/app/{products → [locale]/products}/[slug]/product-client.tsx +18 -62
- package/templates/storefront-nextjs-shadcn/app/[locale]/products/loading.tsx +32 -0
- package/templates/storefront-nextjs-shadcn/app/{products → [locale]/products}/page.tsx +6 -3
- package/templates/storefront-nextjs-shadcn/app/[locale]/products/products-client.tsx +450 -0
- package/templates/storefront-nextjs-shadcn/app/[locale]/search/loading.tsx +18 -0
- package/templates/storefront-nextjs-shadcn/app/{wishlist → [locale]/wishlist}/page.tsx +27 -28
- package/templates/storefront-nextjs-shadcn/app/api/auth/clear-token/route.ts +2 -86
- package/templates/storefront-nextjs-shadcn/app/api/auth/set-token/route.ts +2 -124
- package/templates/storefront-nextjs-shadcn/app/global-error.tsx +117 -0
- package/templates/storefront-nextjs-shadcn/app/globals.css +8 -0
- package/templates/storefront-nextjs-shadcn/app/layout.tsx +8 -35
- package/templates/storefront-nextjs-shadcn/codegen.ts +48 -31
- package/templates/storefront-nextjs-shadcn/components/account/address-form.tsx +25 -20
- package/templates/storefront-nextjs-shadcn/components/account/address-list.tsx +11 -10
- package/templates/storefront-nextjs-shadcn/components/account/customer-info.fragment.graphql +36 -0
- package/templates/storefront-nextjs-shadcn/components/account/order-details.tsx +17 -13
- package/templates/storefront-nextjs-shadcn/components/account/order-history.tsx +42 -30
- package/templates/storefront-nextjs-shadcn/components/account/order-summary.fragment.graphql +36 -0
- package/templates/storefront-nextjs-shadcn/components/auth/account-menu.tsx +18 -16
- package/templates/storefront-nextjs-shadcn/components/auth/login-form.tsx +37 -58
- package/templates/storefront-nextjs-shadcn/components/auth/register-form.tsx +85 -66
- package/templates/storefront-nextjs-shadcn/components/blog/blog-card.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/blog/blog-sidebar.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/brand/brand-card.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/cart/cart-drawer.tsx +10 -6
- package/templates/storefront-nextjs-shadcn/components/cart/cart-icon.tsx +9 -6
- package/templates/storefront-nextjs-shadcn/components/cart/cart-item.tsx +8 -6
- package/templates/storefront-nextjs-shadcn/components/cart/cart-line.fragment.graphql +53 -0
- package/templates/storefront-nextjs-shadcn/components/cart/cart-summary.tsx +10 -8
- package/templates/storefront-nextjs-shadcn/components/cart/promo-code-input.tsx +8 -5
- package/templates/storefront-nextjs-shadcn/components/cart/shipping-estimator.tsx +38 -20
- package/templates/storefront-nextjs-shadcn/components/checkout/payment-method-card.tsx +15 -25
- package/templates/storefront-nextjs-shadcn/components/checkout/payment-step.tsx +10 -8
- package/templates/storefront-nextjs-shadcn/components/checkout/tax-breakdown.tsx +9 -6
- package/templates/storefront-nextjs-shadcn/components/commerce/currency-selector.tsx +7 -5
- package/templates/storefront-nextjs-shadcn/components/commerce/pagination.tsx +8 -5
- package/templates/storefront-nextjs-shadcn/components/commerce/product-actions.tsx +6 -4
- package/templates/storefront-nextjs-shadcn/components/commerce/search-input.tsx +10 -9
- package/templates/storefront-nextjs-shadcn/components/common/category-card.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/common/collection-card.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/common/price-display.tsx +35 -11
- package/templates/storefront-nextjs-shadcn/components/common/social-share.tsx +9 -6
- package/templates/storefront-nextjs-shadcn/components/discount/discount-breakdown.tsx +22 -12
- package/templates/storefront-nextjs-shadcn/components/discount/discount-code-input.tsx +18 -15
- package/templates/storefront-nextjs-shadcn/components/error/error-boundary.tsx +53 -28
- package/templates/storefront-nextjs-shadcn/components/filters/dynamic-attribute-filters.tsx +7 -5
- package/templates/storefront-nextjs-shadcn/components/filters/range-slider-filter.tsx +5 -5
- package/templates/storefront-nextjs-shadcn/components/gift-card/gift-card-balance.tsx +19 -15
- package/templates/storefront-nextjs-shadcn/components/gift-card/gift-card-input.tsx +13 -10
- package/templates/storefront-nextjs-shadcn/components/home/category-grid.tsx +10 -6
- package/templates/storefront-nextjs-shadcn/components/home/collection-card.fragment.graphql +21 -0
- package/templates/storefront-nextjs-shadcn/components/home/featured-collections.tsx +3 -13
- package/templates/storefront-nextjs-shadcn/components/home/featured-products.tsx +12 -8
- package/templates/storefront-nextjs-shadcn/components/home/hero-section.tsx +13 -8
- package/templates/storefront-nextjs-shadcn/components/home/index.ts +0 -1
- package/templates/storefront-nextjs-shadcn/components/home/newsletter-signup.tsx +10 -8
- package/templates/storefront-nextjs-shadcn/components/hydrated.tsx +24 -0
- package/templates/storefront-nextjs-shadcn/components/layout/breadcrumbs.tsx +41 -16
- package/templates/storefront-nextjs-shadcn/components/layout/category-node.fragment.graphql +22 -0
- package/templates/storefront-nextjs-shadcn/components/layout/currency-selector.tsx +7 -4
- package/templates/storefront-nextjs-shadcn/components/layout/footer.tsx +24 -23
- package/templates/storefront-nextjs-shadcn/components/layout/header.tsx +52 -34
- package/templates/storefront-nextjs-shadcn/components/layout/language-switcher.tsx +54 -0
- package/templates/storefront-nextjs-shadcn/components/layout/mobile-menu.tsx +33 -30
- package/templates/storefront-nextjs-shadcn/components/layout/navigation.tsx +27 -24
- package/templates/storefront-nextjs-shadcn/components/loyalty/points-balance.tsx +2 -11
- package/templates/storefront-nextjs-shadcn/components/loyalty/points-history.tsx +8 -25
- package/templates/storefront-nextjs-shadcn/components/loyalty/referral-section.tsx +32 -42
- package/templates/storefront-nextjs-shadcn/components/loyalty/rewards-catalog.tsx +17 -41
- package/templates/storefront-nextjs-shadcn/components/loyalty/tier-progress.tsx +2 -29
- package/templates/storefront-nextjs-shadcn/components/order/index.ts +6 -1
- package/templates/storefront-nextjs-shadcn/components/product/add-to-cart-button.tsx +6 -14
- package/templates/storefront-nextjs-shadcn/components/product/b2b-price-display.tsx +4 -2
- package/templates/storefront-nextjs-shadcn/components/product/filter-active-pills.tsx +72 -0
- package/templates/storefront-nextjs-shadcn/components/product/filter-mobile-sheet.tsx +87 -0
- package/templates/storefront-nextjs-shadcn/components/product/filter-price-range.tsx +140 -0
- package/templates/storefront-nextjs-shadcn/components/product/index.ts +9 -2
- package/templates/storefront-nextjs-shadcn/components/product/product-card.fragment.graphql +49 -0
- package/templates/storefront-nextjs-shadcn/components/product/product-card.tsx +11 -37
- package/templates/storefront-nextjs-shadcn/components/product/product-detail.fragment.graphql +52 -0
- package/templates/storefront-nextjs-shadcn/components/product/product-filters.tsx +179 -124
- package/templates/storefront-nextjs-shadcn/components/product/product-grid.tsx +3 -5
- package/templates/storefront-nextjs-shadcn/components/product/product-image.tsx +3 -7
- package/templates/storefront-nextjs-shadcn/components/product/product-price.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/product/product-reviews.tsx +5 -4
- package/templates/storefront-nextjs-shadcn/components/product/product-sort.tsx +44 -19
- package/templates/storefront-nextjs-shadcn/components/product/product-variant-selector.tsx +8 -23
- package/templates/storefront-nextjs-shadcn/components/product/product-variant.fragment.graphql +51 -0
- package/templates/storefront-nextjs-shadcn/components/product/review-card.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/product/review-form.tsx +26 -34
- package/templates/storefront-nextjs-shadcn/components/product/savings-display.tsx +17 -2
- package/templates/storefront-nextjs-shadcn/components/product/similar-products.tsx +3 -2
- package/templates/storefront-nextjs-shadcn/components/providers/index.ts +1 -1
- package/templates/storefront-nextjs-shadcn/components/providers/language-sync-provider.tsx +27 -0
- package/templates/storefront-nextjs-shadcn/components/providers/stores-provider.tsx +63 -0
- package/templates/storefront-nextjs-shadcn/components/providers/theme-provider.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/returns/index.ts +2 -2
- package/templates/storefront-nextjs-shadcn/components/returns/return-request-form.tsx +59 -72
- package/templates/storefront-nextjs-shadcn/components/search/search-bar.tsx +7 -4
- package/templates/storefront-nextjs-shadcn/components/search/search-results.tsx +3 -2
- package/templates/storefront-nextjs-shadcn/components/shipping/shipping-method-selector.tsx +12 -9
- package/templates/storefront-nextjs-shadcn/components/ui/empty-state.tsx +23 -12
- package/templates/storefront-nextjs-shadcn/components/ui/form.tsx +174 -0
- package/templates/storefront-nextjs-shadcn/components/ui/index.ts +30 -2
- package/templates/storefront-nextjs-shadcn/components/ui/progress.tsx +40 -0
- package/templates/storefront-nextjs-shadcn/components/ui/sheet.tsx +107 -0
- package/templates/storefront-nextjs-shadcn/components/ui/slider.tsx +33 -0
- package/templates/storefront-nextjs-shadcn/components/ui/textarea.tsx +24 -0
- package/templates/storefront-nextjs-shadcn/components/wishlist/wishlist-button.tsx +7 -4
- package/templates/storefront-nextjs-shadcn/components/wishlist/wishlist-icon.tsx +4 -2
- package/templates/storefront-nextjs-shadcn/components/wishlist/wishlist-item.tsx +2 -10
- package/templates/storefront-nextjs-shadcn/generated/graphql.ts +13387 -0
- package/templates/storefront-nextjs-shadcn/graphql/custom.example.graphql +159 -0
- package/templates/storefront-nextjs-shadcn/hooks/index.ts +3 -0
- package/templates/storefront-nextjs-shadcn/hooks/use-auth-sync.ts +42 -0
- package/templates/storefront-nextjs-shadcn/hooks/use-auth.ts +17 -295
- package/templates/storefront-nextjs-shadcn/hooks/use-cart-actions.ts +34 -229
- package/templates/storefront-nextjs-shadcn/hooks/use-cart-di.ts +67 -0
- package/templates/storefront-nextjs-shadcn/hooks/use-cart-sync.ts +16 -12
- package/templates/storefront-nextjs-shadcn/i18n/navigation.ts +12 -0
- package/templates/storefront-nextjs-shadcn/i18n/request.ts +17 -0
- package/templates/storefront-nextjs-shadcn/i18n/routing.ts +17 -0
- package/templates/storefront-nextjs-shadcn/lib/auth/routes.ts +4 -17
- package/templates/storefront-nextjs-shadcn/lib/graphql/client.ts +22 -99
- package/templates/storefront-nextjs-shadcn/lib/graphql/config.ts +33 -0
- package/templates/storefront-nextjs-shadcn/lib/graphql/fragments.ts +34 -0
- package/templates/storefront-nextjs-shadcn/lib/graphql/hooks.ts +720 -632
- package/templates/storefront-nextjs-shadcn/lib/graphql/query-keys.ts +88 -0
- package/templates/storefront-nextjs-shadcn/lib/graphql/server.ts +132 -182
- package/templates/storefront-nextjs-shadcn/lib/graphql/types.ts +62 -0
- package/templates/storefront-nextjs-shadcn/lib/theme/theme-config.ts +0 -17
- package/templates/storefront-nextjs-shadcn/messages/en.json +869 -0
- package/templates/storefront-nextjs-shadcn/messages/pl.json +869 -0
- package/templates/storefront-nextjs-shadcn/next-env.d.ts +6 -0
- package/templates/storefront-nextjs-shadcn/next.config.ts +6 -5
- package/templates/storefront-nextjs-shadcn/package.dev.json +1 -3
- package/templates/storefront-nextjs-shadcn/package.json +14 -14
- package/templates/storefront-nextjs-shadcn/package.json.template +6 -7
- package/templates/storefront-nextjs-shadcn/proxy.ts +115 -47
- package/templates/storefront-nextjs-shadcn/stores/cart-store.ts +24 -56
- package/templates/storefront-nextjs-shadcn/stores/checkout-store.ts +64 -75
- package/templates/storefront-nextjs-shadcn/stores/wishlist-store.ts +178 -177
- package/templates/storefront-nextjs-shadcn/tsconfig.json +23 -5
- package/templates/storefront-nextjs-shadcn/wrangler.toml +11 -0
- package/templates/storefront-nextjs-shadcn/CART_INTEGRATION.md +0 -282
- package/templates/storefront-nextjs-shadcn/GRAPHQL_DOCUMENT_NAMES.md +0 -190
- package/templates/storefront-nextjs-shadcn/GRAPHQL_ERROR_HANDLING.md +0 -263
- package/templates/storefront-nextjs-shadcn/GRAPHQL_FIXES_SUMMARY.md +0 -135
- package/templates/storefront-nextjs-shadcn/GRAPHQL_INTEGRATION_COMPLETE.md +0 -142
- package/templates/storefront-nextjs-shadcn/INTEGRATION_CHECKLIST.md +0 -448
- package/templates/storefront-nextjs-shadcn/PRODUCT_DETAIL_PAGE_IMPLEMENTATION.md +0 -307
- package/templates/storefront-nextjs-shadcn/THEME_CUSTOMIZATION.md +0 -245
- package/templates/storefront-nextjs-shadcn/app/account/addresses/page.tsx +0 -215
- package/templates/storefront-nextjs-shadcn/app/account/orders/[id]/page.tsx +0 -128
- package/templates/storefront-nextjs-shadcn/app/account/orders/page.tsx +0 -80
- package/templates/storefront-nextjs-shadcn/app/account/settings/page.tsx +0 -171
- package/templates/storefront-nextjs-shadcn/app/categories/[slug]/page.tsx +0 -78
- package/templates/storefront-nextjs-shadcn/app/products/products-client.tsx +0 -192
- package/templates/storefront-nextjs-shadcn/components/providers/currency-provider.tsx +0 -103
- package/templates/storefront-nextjs-shadcn/graphql/collections.example.ts +0 -168
- package/templates/storefront-nextjs-shadcn/graphql/products.example.ts +0 -160
- package/templates/storefront-nextjs-shadcn/lib/auth/cookies.ts +0 -220
- package/templates/storefront-nextjs-shadcn/lib/config.ts +0 -46
- package/templates/storefront-nextjs-shadcn/lib/currency/IMPLEMENTATION_SUMMARY.md +0 -254
- package/templates/storefront-nextjs-shadcn/lib/currency/README.md +0 -464
- package/templates/storefront-nextjs-shadcn/lib/currency/cookie-manager.test.ts +0 -328
- package/templates/storefront-nextjs-shadcn/lib/currency/cookie-manager.ts +0 -295
- package/templates/storefront-nextjs-shadcn/lib/currency/index.ts +0 -27
- package/templates/storefront-nextjs-shadcn/lib/format.ts +0 -226
- package/templates/storefront-nextjs-shadcn/lib/hooks.ts +0 -30
- package/templates/storefront-nextjs-shadcn/stores/auth-store.ts +0 -66
- package/templates/storefront-nextjs-shadcn/stores/currency-store.ts +0 -103
- /package/templates/storefront-nextjs-shadcn/app/{blog → [locale]/blog}/page.tsx +0 -0
- /package/templates/storefront-nextjs-shadcn/app/{brands → [locale]/brands}/[slug]/page.tsx +0 -0
- /package/templates/storefront-nextjs-shadcn/app/{returns → [locale]/returns}/page.tsx +0 -0
- /package/templates/storefront-nextjs-shadcn/app/{search → [locale]/search}/page.tsx +0 -0
- /package/templates/storefront-nextjs-shadcn/app/{search → [locale]/search}/search-client.tsx +0 -0
- /package/templates/storefront-nextjs-shadcn/app/{shipping → [locale]/shipping}/page.tsx +0 -0
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { NextConfig } from 'next';
|
|
2
|
+
import createNextIntlPlugin from 'next-intl/plugin';
|
|
3
|
+
|
|
4
|
+
const withNextIntl = createNextIntlPlugin();
|
|
2
5
|
|
|
3
6
|
const nextConfig: NextConfig = {
|
|
4
7
|
// Enable React strict mode for better development experience
|
|
5
8
|
reactStrictMode: true,
|
|
6
9
|
|
|
7
|
-
// Image optimization
|
|
10
|
+
// Image optimization — GraphQL API returns ready-to-use CDN URLs.
|
|
11
|
+
// Use url(transform: { maxWidth: 800 }) in queries. No client-side loader needed.
|
|
8
12
|
images: {
|
|
9
13
|
remotePatterns: [
|
|
10
14
|
{
|
|
@@ -21,11 +25,8 @@ const nextConfig: NextConfig = {
|
|
|
21
25
|
port: '8000',
|
|
22
26
|
},
|
|
23
27
|
],
|
|
24
|
-
// Allow dangerous URLs for local development
|
|
25
28
|
dangerouslyAllowSVG: true,
|
|
26
29
|
contentDispositionType: 'attachment',
|
|
27
|
-
// Disable image optimization for local development if needed
|
|
28
|
-
unoptimized: process.env.NODE_ENV === 'development',
|
|
29
30
|
},
|
|
30
31
|
|
|
31
32
|
// Experimental features
|
|
@@ -44,4 +45,4 @@ const nextConfig: NextConfig = {
|
|
|
44
45
|
},
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
export default nextConfig;
|
|
48
|
+
export default withNextIntl(nextConfig);
|
|
@@ -9,9 +9,7 @@
|
|
|
9
9
|
"lint": "next lint"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@doswiftly/
|
|
13
|
-
"graphql-request": "^7.1.2",
|
|
14
|
-
"graphql": "^16.10.0",
|
|
12
|
+
"@doswiftly/storefront-sdk": "file:../../@doswiftly/storefront-sdk",
|
|
15
13
|
"next": "latest",
|
|
16
14
|
"react": "^19",
|
|
17
15
|
"react-dom": "^19",
|
|
@@ -13,19 +13,16 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@doswiftly/storefront-operations": "{{STOREFRONT_OPS_VERSION}}",
|
|
16
|
-
"@
|
|
16
|
+
"@doswiftly/storefront-sdk": "^4.0.0",
|
|
17
17
|
"@tanstack/react-query": "^5.62.0",
|
|
18
|
-
"
|
|
19
|
-
"graphql": "^16.10.0",
|
|
20
|
-
"graphql-tag": "^2.12.6",
|
|
21
|
-
"js-cookie": "^3.0.5",
|
|
22
|
-
"next": "^15.1.9",
|
|
18
|
+
"next": "^16.1.7",
|
|
23
19
|
"react": "^19",
|
|
24
20
|
"react-dom": "^19",
|
|
25
21
|
"lucide-react": "latest",
|
|
26
22
|
"@radix-ui/react-accordion": "^1.2.0",
|
|
27
23
|
"@radix-ui/react-checkbox": "^1.1.0",
|
|
28
24
|
"@radix-ui/react-dialog": "^1.1.0",
|
|
25
|
+
"@radix-ui/react-slider": "^1.2.0",
|
|
29
26
|
"@radix-ui/react-label": "^2.1.0",
|
|
30
27
|
"@radix-ui/react-radio-group": "^1.2.0",
|
|
31
28
|
"@radix-ui/react-select": "^2.1.0",
|
|
@@ -37,24 +34,27 @@
|
|
|
37
34
|
"zustand": "^5.0.2",
|
|
38
35
|
"zod": "^3.23.8",
|
|
39
36
|
"sonner": "^1.7.1",
|
|
40
|
-
"next-
|
|
37
|
+
"next-intl": "^4.1.0",
|
|
38
|
+
"next-themes": "^0.4.4",
|
|
39
|
+
"react-hook-form": "^7.55.0",
|
|
40
|
+
"@hookform/resolvers": "^5.2.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@graphql-codegen/cli": "^5.0.3",
|
|
44
|
-
"@graphql-codegen/
|
|
45
|
-
"@graphql-
|
|
46
|
-
"
|
|
47
|
-
"@next/env": "^
|
|
48
|
-
"@opennextjs/cloudflare": "^1.
|
|
49
|
-
"@types/js-cookie": "^3.0.6",
|
|
44
|
+
"@graphql-codegen/client-preset": "^4.5.1",
|
|
45
|
+
"@graphql-typed-document-node/core": "^3.2.0",
|
|
46
|
+
"graphql": "^16.10.0",
|
|
47
|
+
"@next/env": "^16.0.0",
|
|
48
|
+
"@opennextjs/cloudflare": "^1.17.1",
|
|
50
49
|
"@types/node": "latest",
|
|
51
50
|
"@types/react": "latest",
|
|
52
51
|
"@types/react-dom": "latest",
|
|
52
|
+
"schema-dts": "^1.1.2",
|
|
53
53
|
"fast-check": "^3.15.0",
|
|
54
54
|
"typescript": "latest",
|
|
55
55
|
"@tailwindcss/postcss": "latest",
|
|
56
56
|
"tailwindcss": "latest",
|
|
57
57
|
"eslint": "latest",
|
|
58
|
-
"eslint-config-next": "^
|
|
58
|
+
"eslint-config-next": "^16.0.0"
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -12,15 +12,14 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@doswiftly/storefront-operations": "{{STOREFRONT_OPS_VERSION}}",
|
|
15
|
-
"@
|
|
15
|
+
"@doswiftly/storefront-sdk": "{{SDK_VERSION}}",
|
|
16
16
|
"@tanstack/react-query": "^5.62.0",
|
|
17
|
-
"graphql-request": "^7.1.2",
|
|
18
|
-
"graphql": "^16.10.0",
|
|
19
|
-
"graphql-tag": "^2.12.6",
|
|
20
17
|
"next": "latest",
|
|
21
18
|
"react": "^19",
|
|
22
19
|
"react-dom": "^19",
|
|
23
20
|
"lucide-react": "latest",
|
|
21
|
+
"@radix-ui/react-dialog": "^1.1.0",
|
|
22
|
+
"@radix-ui/react-slider": "^1.2.0",
|
|
24
23
|
"@radix-ui/react-slot": "^1.1.0",
|
|
25
24
|
"class-variance-authority": "^0.7.0",
|
|
26
25
|
"clsx": "^2.1.0",
|
|
@@ -30,9 +29,9 @@
|
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"@graphql-codegen/cli": "^5.0.3",
|
|
33
|
-
"@graphql-codegen/
|
|
34
|
-
"@graphql-
|
|
35
|
-
"
|
|
32
|
+
"@graphql-codegen/client-preset": "^4.5.1",
|
|
33
|
+
"@graphql-typed-document-node/core": "^3.2.0",
|
|
34
|
+
"graphql": "^16.10.0",
|
|
36
35
|
"@next/env": "latest",
|
|
37
36
|
"@types/node": "latest",
|
|
38
37
|
"@types/react": "latest",
|
|
@@ -1,80 +1,148 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
2
|
import type { NextRequest } from "next/server";
|
|
3
|
+
import createMiddleware from "next-intl/middleware";
|
|
4
|
+
import { defaultLocale, localePrefix } from "@/i18n/routing";
|
|
5
|
+
import {
|
|
6
|
+
AUTH_COOKIE_NAME,
|
|
7
|
+
LANGUAGE_COOKIE_NAME,
|
|
8
|
+
LANGUAGE_COOKIE_MAX_AGE,
|
|
9
|
+
matchesRoute,
|
|
10
|
+
} from "@doswiftly/storefront-sdk";
|
|
3
11
|
import {
|
|
4
12
|
protectedRoutes,
|
|
5
13
|
guestOnlyRoutes,
|
|
6
|
-
AUTH_COOKIE_NAME,
|
|
7
14
|
redirects,
|
|
8
|
-
matchesRoute,
|
|
9
15
|
} from "@/lib/auth/routes";
|
|
10
16
|
|
|
17
|
+
const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000";
|
|
18
|
+
const shopSlug = process.env.NEXT_PUBLIC_SHOP_SLUG || "demo-shop";
|
|
19
|
+
|
|
11
20
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* Security Model (3 layers):
|
|
15
|
-
* 1. Proxy function (this file) - Fast redirect based on cookie existence (UX layer)
|
|
16
|
-
* 2. AuthGuard component - Client-side validation via useAuth hook
|
|
17
|
-
* 3. GraphQL Backend - Ultimate security (validates token on every request)
|
|
18
|
-
*
|
|
19
|
-
* IMPORTANT: This proxy checks cookie EXISTENCE, not VALIDITY.
|
|
20
|
-
* Token validation happens in:
|
|
21
|
-
* - AuthGuard (client-side via useAuth hook)
|
|
22
|
-
* - GraphQL API (server-side, ultimate security)
|
|
21
|
+
* Fetch supported locales from backend (cached 60s).
|
|
22
|
+
* Backend is SSOT — merchant adds/removes language → immediately reflected.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* - Cannot make GraphQL requests to validate token
|
|
27
|
-
* - Provides instant redirect without waiting for client hydration
|
|
28
|
-
* - Prevents flash of protected content for unauthenticated users
|
|
29
|
-
*
|
|
30
|
-
* @see lib/auth/routes.ts - SSOT for route configuration
|
|
31
|
-
* @see components/auth/auth-guard.tsx - Client-side auth protection
|
|
24
|
+
* In-memory cache is acceptable in middleware context — warm instances benefit,
|
|
25
|
+
* cold starts make one extra backend call (graceful degradation).
|
|
32
26
|
*/
|
|
33
|
-
|
|
27
|
+
let cachedLocales: string[] | null = null;
|
|
28
|
+
let cacheExpiry = 0;
|
|
29
|
+
let cachedIntlMiddleware: ReturnType<typeof createMiddleware> | null = null;
|
|
30
|
+
let cachedLocaleRegex: RegExp | null = null;
|
|
31
|
+
|
|
32
|
+
async function getSupportedLocales(): Promise<string[]> {
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
if (cachedLocales && now < cacheExpiry) {
|
|
35
|
+
return cachedLocales;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const res = await fetch(`${apiUrl}/storefront/graphql`, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
"X-Shop-Slug": shopSlug,
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify({
|
|
46
|
+
query: `{ shop { supportedLanguages } }`,
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
const json = await res.json();
|
|
50
|
+
const locales: string[] =
|
|
51
|
+
json?.data?.shop?.supportedLanguages?.filter(Boolean);
|
|
52
|
+
|
|
53
|
+
if (locales && locales.length > 0) {
|
|
54
|
+
cachedLocales = locales;
|
|
55
|
+
cacheExpiry = now + 60_000; // 60s cache
|
|
56
|
+
// Rebuild derived caches when locales change
|
|
57
|
+
cachedIntlMiddleware = createMiddleware({
|
|
58
|
+
locales,
|
|
59
|
+
defaultLocale,
|
|
60
|
+
localePrefix,
|
|
61
|
+
localeCookie: {
|
|
62
|
+
name: LANGUAGE_COOKIE_NAME,
|
|
63
|
+
maxAge: LANGUAGE_COOKIE_MAX_AGE,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
cachedLocaleRegex = new RegExp(
|
|
67
|
+
`^\\/(${locales.join("|")})(\\\/|$)`
|
|
68
|
+
);
|
|
69
|
+
return locales;
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
// Backend unreachable — use cached or fallback
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return cachedLocales || [defaultLocale];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getIntlMiddleware(locales: string[]) {
|
|
79
|
+
if (cachedIntlMiddleware) return cachedIntlMiddleware;
|
|
80
|
+
cachedIntlMiddleware = createMiddleware({
|
|
81
|
+
locales,
|
|
82
|
+
defaultLocale,
|
|
83
|
+
localePrefix,
|
|
84
|
+
localeCookie: {
|
|
85
|
+
name: LANGUAGE_COOKIE_NAME,
|
|
86
|
+
maxAge: LANGUAGE_COOKIE_MAX_AGE,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
return cachedIntlMiddleware;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function getLocaleRegex(locales: string[]) {
|
|
93
|
+
if (cachedLocaleRegex) return cachedLocaleRegex;
|
|
94
|
+
cachedLocaleRegex = new RegExp(`^\\/(${locales.join("|")})(\\\/|$)`);
|
|
95
|
+
return cachedLocaleRegex;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function proxy(request: NextRequest) {
|
|
99
|
+
// Step 1: Get dynamic locales from backend
|
|
100
|
+
const locales = await getSupportedLocales();
|
|
101
|
+
|
|
102
|
+
// Step 2: next-intl locale detection & routing (cached middleware instance)
|
|
103
|
+
const handleI18nRouting = getIntlMiddleware(locales);
|
|
104
|
+
const response = handleI18nRouting(request);
|
|
105
|
+
|
|
106
|
+
// Step 3: Auth checks
|
|
34
107
|
const { pathname } = request.nextUrl;
|
|
35
108
|
const token = request.cookies.get(AUTH_COOKIE_NAME)?.value;
|
|
36
109
|
const hasToken = Boolean(token);
|
|
37
110
|
|
|
38
|
-
//
|
|
39
|
-
|
|
111
|
+
// Strip locale prefix for route matching (cached regex)
|
|
112
|
+
const localePattern = getLocaleRegex(locales);
|
|
113
|
+
const localeMatch = pathname.match(localePattern);
|
|
114
|
+
const urlLocalePrefix = localeMatch ? `/${localeMatch[1]}` : "";
|
|
115
|
+
const pathnameWithoutLocale = pathname.replace(localePattern, "/");
|
|
116
|
+
const matchPathname =
|
|
117
|
+
pathnameWithoutLocale === "" ? "/" : pathnameWithoutLocale;
|
|
118
|
+
|
|
119
|
+
if (matchesRoute(matchPathname, protectedRoutes)) {
|
|
40
120
|
if (!hasToken) {
|
|
41
|
-
const loginUrl = new URL(
|
|
42
|
-
|
|
121
|
+
const loginUrl = new URL(
|
|
122
|
+
`${urlLocalePrefix}${redirects.unauthenticated}`,
|
|
123
|
+
request.url
|
|
124
|
+
);
|
|
43
125
|
loginUrl.searchParams.set("redirect", pathname);
|
|
44
126
|
return NextResponse.redirect(loginUrl);
|
|
45
127
|
}
|
|
46
128
|
}
|
|
47
129
|
|
|
48
|
-
|
|
49
|
-
if (matchesRoute(pathname, guestOnlyRoutes)) {
|
|
130
|
+
if (matchesRoute(matchPathname, guestOnlyRoutes)) {
|
|
50
131
|
if (hasToken) {
|
|
51
132
|
return NextResponse.redirect(
|
|
52
|
-
new URL(
|
|
133
|
+
new URL(
|
|
134
|
+
`${urlLocalePrefix}${redirects.authenticated}`,
|
|
135
|
+
request.url
|
|
136
|
+
)
|
|
53
137
|
);
|
|
54
138
|
}
|
|
55
139
|
}
|
|
56
140
|
|
|
57
|
-
return
|
|
141
|
+
return response;
|
|
58
142
|
}
|
|
59
143
|
|
|
60
|
-
/**
|
|
61
|
-
* Matcher configuration
|
|
62
|
-
*
|
|
63
|
-
* Only run proxy on routes that need auth checks.
|
|
64
|
-
* This improves performance by skipping static assets, API routes, etc.
|
|
65
|
-
*
|
|
66
|
-
* Update this when adding new protected or guest-only route groups.
|
|
67
|
-
*/
|
|
68
144
|
export const config = {
|
|
69
145
|
matcher: [
|
|
70
|
-
|
|
71
|
-
* Match all request paths except:
|
|
72
|
-
* - _next/static (static files)
|
|
73
|
-
* - _next/image (image optimization files)
|
|
74
|
-
* - favicon.ico (favicon file)
|
|
75
|
-
* - public folder files (images, etc.)
|
|
76
|
-
* - API routes (handled separately)
|
|
77
|
-
*/
|
|
78
|
-
"/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
|
|
146
|
+
"/((?!api|trpc|_next|_vercel|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico)$).*)",
|
|
79
147
|
],
|
|
80
148
|
};
|
|
@@ -1,56 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setCartId: (cartId: string | null) => {
|
|
26
|
-
set({ cartId });
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
clearCart: () => {
|
|
30
|
-
set({ cartId: null, isOpen: false });
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
openCart: () => {
|
|
34
|
-
set({ isOpen: true });
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
closeCart: () => {
|
|
38
|
-
set({ isOpen: false });
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
toggleCart: () => {
|
|
42
|
-
set((state) => ({ isOpen: !state.isOpen }));
|
|
43
|
-
},
|
|
44
|
-
}),
|
|
45
|
-
{
|
|
46
|
-
name: 'cart-storage',
|
|
47
|
-
// Persist only cartId — server is the source of truth for items
|
|
48
|
-
partialize: (state) => ({ cartId: state.cartId }),
|
|
49
|
-
onRehydrateStorage: () => (state) => {
|
|
50
|
-
if (state) {
|
|
51
|
-
state.isHydrated = true;
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
)
|
|
56
|
-
);
|
|
1
|
+
/**
|
|
2
|
+
* Cart store — re-export facade from SDK.
|
|
3
|
+
*
|
|
4
|
+
* All cart state management is now in @doswiftly/storefront-sdk/react.
|
|
5
|
+
* This file preserves import compatibility for existing template consumers.
|
|
6
|
+
*/
|
|
7
|
+
export {
|
|
8
|
+
createCartStore,
|
|
9
|
+
CartProvider,
|
|
10
|
+
useCartStore,
|
|
11
|
+
useCartStoreApi,
|
|
12
|
+
selectCartId,
|
|
13
|
+
selectIsCartOpen,
|
|
14
|
+
selectCartIsLoading,
|
|
15
|
+
} from '@doswiftly/storefront-sdk/react';
|
|
16
|
+
|
|
17
|
+
export type {
|
|
18
|
+
CartState,
|
|
19
|
+
CartActions,
|
|
20
|
+
CartStoreConfig,
|
|
21
|
+
CartData,
|
|
22
|
+
CartLineInput,
|
|
23
|
+
CartLineUpdateInput,
|
|
24
|
+
} from '@doswiftly/storefront-sdk/react';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStore } from 'zustand/vanilla';
|
|
2
2
|
import { persist } from 'zustand/middleware';
|
|
3
|
+
import { createStoreContext } from '@doswiftly/storefront-sdk/react';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Address form state
|
|
@@ -19,7 +20,6 @@ export interface AddressForm {
|
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Checkout state interface
|
|
22
|
-
* Requirements: 22.4
|
|
23
23
|
*/
|
|
24
24
|
export interface CheckoutState {
|
|
25
25
|
// Checkout ID from backend
|
|
@@ -48,9 +48,6 @@ export interface CheckoutState {
|
|
|
48
48
|
acceptTerms: boolean;
|
|
49
49
|
acceptMarketing: boolean;
|
|
50
50
|
|
|
51
|
-
// Hydration state
|
|
52
|
-
isHydrated: boolean;
|
|
53
|
-
|
|
54
51
|
// Actions
|
|
55
52
|
setCheckoutId: (id: string | null) => void;
|
|
56
53
|
setEmail: (email: string) => void;
|
|
@@ -94,91 +91,83 @@ const initialState = {
|
|
|
94
91
|
appliedDiscountCodes: [],
|
|
95
92
|
acceptTerms: false,
|
|
96
93
|
acceptMarketing: false,
|
|
97
|
-
isHydrated: false,
|
|
98
94
|
};
|
|
99
95
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
* Requirements: 22.4
|
|
107
|
-
*/
|
|
108
|
-
export const useCheckoutStore = create<CheckoutState>()(
|
|
109
|
-
persist(
|
|
110
|
-
(set) => ({
|
|
111
|
-
...initialState,
|
|
96
|
+
export function createCheckoutStore() {
|
|
97
|
+
return createStore<CheckoutState>()(
|
|
98
|
+
persist(
|
|
99
|
+
(set) => ({
|
|
100
|
+
...initialState,
|
|
112
101
|
|
|
113
|
-
|
|
102
|
+
setCheckoutId: (id) => set({ checkoutId: id }),
|
|
114
103
|
|
|
115
|
-
|
|
104
|
+
setEmail: (email) => set({ email }),
|
|
116
105
|
|
|
117
|
-
|
|
106
|
+
setPhone: (phone) => set({ phone }),
|
|
118
107
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
108
|
+
setShippingAddress: (address) =>
|
|
109
|
+
set((state) => ({
|
|
110
|
+
shippingAddress: { ...state.shippingAddress, ...address },
|
|
111
|
+
})),
|
|
123
112
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
113
|
+
setBillingAddress: (address) =>
|
|
114
|
+
set((state) => ({
|
|
115
|
+
billingAddress: { ...state.billingAddress, ...address },
|
|
116
|
+
})),
|
|
128
117
|
|
|
129
|
-
|
|
118
|
+
setSameAsBilling: (same) => set({ sameAsBilling: same }),
|
|
130
119
|
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
setSelectedShippingRateHandle: (handle) =>
|
|
121
|
+
set({ selectedShippingRateHandle: handle }),
|
|
133
122
|
|
|
134
|
-
|
|
135
|
-
|
|
123
|
+
setSelectedPaymentMethodId: (id) =>
|
|
124
|
+
set({ selectedPaymentMethodId: id }),
|
|
136
125
|
|
|
137
|
-
|
|
126
|
+
setDiscountCode: (code) => set({ discountCode: code }),
|
|
138
127
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
128
|
+
addAppliedDiscountCode: (code) =>
|
|
129
|
+
set((state) => ({
|
|
130
|
+
appliedDiscountCodes: [...state.appliedDiscountCodes, code],
|
|
131
|
+
discountCode: '',
|
|
132
|
+
})),
|
|
144
133
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
134
|
+
removeAppliedDiscountCode: (code) =>
|
|
135
|
+
set((state) => ({
|
|
136
|
+
appliedDiscountCodes: state.appliedDiscountCodes.filter(
|
|
137
|
+
(c) => c !== code,
|
|
138
|
+
),
|
|
139
|
+
})),
|
|
151
140
|
|
|
152
|
-
|
|
141
|
+
setAcceptTerms: (accept) => set({ acceptTerms: accept }),
|
|
153
142
|
|
|
154
|
-
|
|
143
|
+
setAcceptMarketing: (accept) => set({ acceptMarketing: accept }),
|
|
155
144
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}),
|
|
161
|
-
}),
|
|
162
|
-
{
|
|
163
|
-
name: 'checkout-storage',
|
|
164
|
-
// Persist only essential checkout state
|
|
165
|
-
partialize: (state) => ({
|
|
166
|
-
checkoutId: state.checkoutId,
|
|
167
|
-
email: state.email,
|
|
168
|
-
phone: state.phone,
|
|
169
|
-
shippingAddress: state.shippingAddress,
|
|
170
|
-
billingAddress: state.billingAddress,
|
|
171
|
-
sameAsBilling: state.sameAsBilling,
|
|
172
|
-
selectedShippingRateHandle: state.selectedShippingRateHandle,
|
|
173
|
-
selectedPaymentMethodId: state.selectedPaymentMethodId,
|
|
174
|
-
appliedDiscountCodes: state.appliedDiscountCodes,
|
|
175
|
-
acceptMarketing: state.acceptMarketing,
|
|
145
|
+
resetCheckout: () =>
|
|
146
|
+
set({
|
|
147
|
+
...initialState,
|
|
148
|
+
}),
|
|
176
149
|
}),
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
150
|
+
{
|
|
151
|
+
name: 'checkout-storage',
|
|
152
|
+
partialize: (state) => ({
|
|
153
|
+
checkoutId: state.checkoutId,
|
|
154
|
+
email: state.email,
|
|
155
|
+
phone: state.phone,
|
|
156
|
+
shippingAddress: state.shippingAddress,
|
|
157
|
+
billingAddress: state.billingAddress,
|
|
158
|
+
sameAsBilling: state.sameAsBilling,
|
|
159
|
+
selectedShippingRateHandle: state.selectedShippingRateHandle,
|
|
160
|
+
selectedPaymentMethodId: state.selectedPaymentMethodId,
|
|
161
|
+
appliedDiscountCodes: state.appliedDiscountCodes,
|
|
162
|
+
acceptMarketing: state.acceptMarketing,
|
|
163
|
+
}),
|
|
181
164
|
},
|
|
182
|
-
|
|
183
|
-
)
|
|
184
|
-
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const {
|
|
170
|
+
Provider: CheckoutProvider,
|
|
171
|
+
useStore: useCheckoutStore,
|
|
172
|
+
useApi: useCheckoutStoreApi,
|
|
173
|
+
} = createStoreContext<CheckoutState>('CheckoutStore');
|