@ecomiq/storefront 2.1.3 → 3.0.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 -0
- package/README.md +150 -123
- package/dist/account-Dx4e3syi.js +258 -0
- package/dist/account-forms-AVk71ko7.js +39 -0
- package/dist/account-forms.d.ts +13 -0
- package/dist/account.d.ts +240 -0
- package/dist/address-defaults-BqjRhS82.js +14 -0
- package/dist/address-defaults.d.ts +11 -0
- package/dist/analytics/analytics-CG1Qagwl.js +148 -0
- package/dist/analytics/analytics.d.ts +1 -0
- package/dist/analytics/config-DJr-GRhs.js +62 -0
- package/dist/analytics/config.d.ts +22 -0
- package/dist/analytics/consent-B13rBpBs.js +57 -0
- package/dist/analytics/consent-banner-9QvRRy8v.js +239 -0
- package/dist/analytics/consent-banner.d.ts +20 -0
- package/dist/analytics/cookies-pLozllyB.js +100 -0
- package/dist/analytics/cookies.d.ts +6 -0
- package/dist/analytics/destinations-iECrlLIr.js +144 -0
- package/dist/analytics/events-Dt81tIp1.js +102 -0
- package/dist/analytics/events.d.ts +51 -0
- package/dist/analytics/tracker-p4yaoOyk.js +51 -0
- package/dist/api-cache-DsuIn5hX.js +159 -0
- package/dist/bank-accounts-DlEczQQ5.js +81 -0
- package/dist/bank-accounts.d.ts +4 -0
- package/dist/captcha-DAqaIx8m.js +117 -0
- package/dist/captcha.d.ts +34 -0
- package/dist/cart-D7DxZ2lD.js +30 -0
- package/dist/cart-actions-Bsub_FFG.js +116 -0
- package/dist/cart-actions.d.ts +15 -0
- package/dist/cart-drawer-B7PPsR69.js +22 -0
- package/dist/cart-drawer.d.ts +9 -0
- package/dist/cart-form-y9P1r_EX.js +81 -0
- package/dist/cart-form.d.ts +24 -0
- package/dist/cart-summary-ur2VWKr-.js +89 -0
- package/dist/cart-summary.d.ts +31 -0
- package/dist/cart.d.ts +4 -0
- package/dist/catalog-7gJ-l5hW.js +67 -0
- package/dist/catalog-hooks-B7ZP4wYY.js +312 -0
- package/dist/catalog-hooks.d.ts +111 -0
- package/dist/catalog.d.ts +5 -0
- package/dist/checkout-DVWSXANi.js +474 -0
- package/dist/checkout-form-CbOIdENC.js +131 -0
- package/dist/checkout-form.d.ts +20 -0
- package/dist/checkout.d.ts +86 -0
- package/dist/complaint-book-BvwLvfx0.js +117 -0
- package/dist/complaint-book.d.ts +62 -0
- package/dist/culqi-authentication-BGr20vAJ.js +204 -0
- package/dist/culqi-authentication.d.ts +15 -0
- package/dist/culqi-checkout-CTXpKgp_.js +55 -0
- package/dist/culqi-three-ds-HP3mfrvV.js +33 -0
- package/dist/culqi-three-ds.d.ts +29 -0
- package/dist/customer-avatar-CJXSDroK.js +12 -0
- package/dist/customer-avatar.d.ts +5 -0
- package/dist/customer-cookies-DHOgFAMV.js +45 -0
- package/dist/customer-csrf-C1oDX-Py.js +17 -0
- package/dist/customer-csrf.d.ts +3 -0
- package/dist/customer-document-fields-C1K-_DAD.js +70 -0
- package/dist/customer-document-fields.d.ts +9 -0
- package/dist/customer-login-form-C7AC6vXd.js +144 -0
- package/dist/customer-login-form.d.ts +17 -0
- package/dist/customer-registration-form-BEm_NEfP.js +93 -0
- package/dist/customer-registration-form.d.ts +8 -0
- package/dist/document-url-CGsAl5Tf.js +9 -0
- package/dist/documents-T1mzc_j8.js +38 -0
- package/dist/documents.d.ts +16 -0
- package/dist/entries/account.d.ts +11 -0
- package/dist/entries/account.js +10 -0
- package/dist/entries/analytics.d.ts +6 -0
- package/dist/entries/analytics.js +5 -0
- package/dist/entries/cart.d.ts +8 -0
- package/dist/entries/cart.js +7 -0
- package/dist/entries/checkout.d.ts +12 -0
- package/dist/entries/checkout.js +11 -0
- package/dist/entries/order.d.ts +11 -0
- package/dist/entries/order.js +11 -0
- package/dist/favicon-YpyhVJ9H.js +28 -0
- package/dist/favicon.d.ts +4 -0
- package/dist/form-BtQcbXlJ.js +18 -0
- package/dist/form-contracts-BNpHaTGJ.js +166 -0
- package/dist/form-contracts.d.ts +42 -0
- package/dist/form.d.ts +3 -0
- package/dist/hidden-CCWtOWKR.js +3 -0
- package/dist/hidden.d.ts +4 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +50 -0
- package/dist/invoice-fields-BG0HjL6T.js +103 -0
- package/dist/invoice-fields.d.ts +39 -0
- package/dist/links-kFxBZfdb.js +96 -0
- package/dist/links.d.ts +21 -0
- package/dist/mercadopago-checkout-DC7RXa8k.js +27 -0
- package/dist/mercadopago-dialog-UTQev0MG.js +180 -0
- package/dist/mercadopago-dialog.d.ts +21 -0
- package/dist/money-DtGOtDri.js +32 -0
- package/dist/money.d.ts +1 -0
- package/dist/optimistic-cart-BveVOHuh.js +53 -0
- package/dist/optimistic-cart.d.ts +16 -0
- package/dist/order-display-DTt5WBbc.js +112 -0
- package/dist/order-display.d.ts +20 -0
- package/dist/order-draft-DxV1Uhm3.js +38 -0
- package/dist/order-draft.d.ts +16 -0
- package/dist/order-pages-Dm6l5m0m.js +38 -0
- package/dist/order-pages.d.ts +12 -0
- package/dist/order-payment-continuation-D_d5PGA4.js +212 -0
- package/dist/order-payment-continuation.d.ts +10 -0
- package/dist/order-payment-in-review-x4gdLFHZ.js +65 -0
- package/dist/order-payment-in-review.d.ts +5 -0
- package/dist/order-status-BJXLJwxq.js +162 -0
- package/dist/order-status.d.ts +89 -0
- package/dist/order-view-9IlBg5AF.js +62 -0
- package/dist/order-view.d.ts +12 -0
- package/dist/page-action-Ctkf4xC6.js +7 -0
- package/dist/page-seo-a5FJl8x5.js +262 -0
- package/dist/page-seo.d.ts +34 -0
- package/dist/pages-Ca_Gt6mq.js +150 -0
- package/dist/pages.d.ts +45 -0
- package/dist/payment-dialog-frame-B-Q_xQ94.js +57 -0
- package/dist/payment-logo-BoPaGJc_.js +46 -0
- package/dist/payment-logo-svgs-By9lDTLK.js +20 -0
- package/dist/payment-logo.d.ts +11 -0
- package/dist/payment-logos-BYvdwYyJ.js +23 -0
- package/dist/payment-methods-B8ocTgFZ.js +73 -0
- package/dist/payment-methods.d.ts +58 -0
- package/dist/payment-return-5cjypwIw.js +7 -0
- package/dist/place-CmW4hBWY.js +13 -0
- package/dist/place.d.ts +4 -0
- package/dist/preview-BiIBif3C.js +427 -0
- package/dist/preview-address-Cf0sJ-9p.js +21 -0
- package/dist/preview-cart-Dg2CVktS.js +376 -0
- package/dist/product-preview-BspMAecJ.js +51 -0
- package/dist/product-preview.d.ts +5 -0
- package/dist/product-variants-BNDHvs1y.js +46 -0
- package/dist/product-variants.d.ts +12 -0
- package/dist/public-pages-XtwlaLwt.js +194 -0
- package/dist/public-pages.d.ts +67 -0
- package/dist/registration-CpDcv8ql.js +91 -0
- package/dist/registration.d.ts +12 -0
- package/dist/request-security-CRsRMgwj.js +76 -0
- package/dist/rich-text-M-Ju8RL4.js +9 -0
- package/dist/rich-text.d.ts +5 -0
- package/dist/route-text-DcJw2SsK.js +9 -0
- package/dist/route-text.d.ts +4 -0
- package/dist/section-preview-CmsMl3yu.js +83 -0
- package/dist/section-preview.d.ts +12 -0
- package/dist/sections/account-addresses.d.ts +18 -0
- package/dist/sections/account-addresses.js +375 -0
- package/dist/sections/account-order.d.ts +12 -0
- package/dist/sections/account-order.js +592 -0
- package/dist/sections/account-orders.d.ts +8 -0
- package/dist/sections/account-orders.js +359 -0
- package/dist/sections/account-profile.d.ts +16 -0
- package/dist/sections/account-profile.js +123 -0
- package/dist/sections/checkout.d.ts +24 -0
- package/dist/sections/checkout.js +963 -0
- package/dist/sections/complaint-book.d.ts +8 -0
- package/dist/sections/complaint-book.js +538 -0
- package/dist/sections/design-system.d.ts +1 -0
- package/dist/sections/design-system.js +310 -0
- package/dist/sections/draft-invoice.d.ts +20 -0
- package/dist/sections/draft-invoice.js +158 -0
- package/dist/sections/order-tracking.d.ts +19 -0
- package/dist/sections/order-tracking.js +141 -0
- package/dist/sections-CNUMWTF_.js +77 -0
- package/dist/sections.d.ts +19 -0
- package/dist/seo-GpDRhAAA.js +78 -0
- package/dist/session-CKvmFJyg.js +379 -0
- package/dist/session.d.ts +24 -0
- package/dist/settings-B0NO2A6Y.js +78 -0
- package/dist/settings.d.ts +51 -0
- package/dist/source-marker-DhqSkW7n.js +4 -0
- package/dist/sources-B-3JFJfb.js +46 -0
- package/dist/sources.d.ts +7 -0
- package/dist/store-8Q-_LFrQ.js +152 -0
- package/dist/store-contact--hY6CoFb.js +19 -0
- package/dist/store-contact.d.ts +6 -0
- package/dist/store.d.ts +17 -0
- package/dist/storefront-language-DrMjVbmk.js +29 -0
- package/dist/storefront-language.d.ts +14 -0
- package/dist/storefront-text-D25ae1qf.js +11 -0
- package/dist/storefront-text-en-ljjjSS4q.js +1030 -0
- package/dist/storefront-text-pt-BtHaJLcp.js +1030 -0
- package/dist/storefront-text.d.ts +4 -0
- package/dist/stripe-dialog-Ev9s3Z62.js +396 -0
- package/dist/stripe-dialog.d.ts +30 -0
- package/dist/telemetry-HuZXWBPi.js +114 -0
- package/dist/telemetry.d.ts +10 -0
- package/dist/templates-CAqoNyTW.js +40 -0
- package/dist/templates.d.ts +15 -0
- package/dist/urls-CpGQPxvf.js +71 -0
- package/dist/urls.d.ts +18 -0
- package/dist/use-checkout-CZcxXJXi.js +42 -0
- package/dist/use-checkout-payment-9R-zacrJ.js +80 -0
- package/dist/use-checkout-payment.d.ts +18 -0
- package/dist/use-checkout.d.ts +36 -0
- package/dist/use-culqi-checkout-CrjLAipU.js +109 -0
- package/dist/use-order-payment-BKIz_IO0.js +45 -0
- package/dist/use-order-payment.d.ts +18 -0
- package/dist/use-payment-token-CErx-tN-.js +105 -0
- package/dist/vite-payment-logos-kziu7wKb.js +27 -0
- package/dist/vite-payment-logos.d.ts +24 -0
- package/dist/vite-public-assets-DW2fgtVb.js +209 -0
- package/dist/vite-public-assets.d.ts +29 -0
- package/dist/vite-sections-DTBr0-Kg.js +464 -0
- package/dist/vite-sections.d.ts +21 -0
- package/dist/vite-theme-ui-BMO-CDi3.js +41 -0
- package/dist/vite-theme-ui.d.ts +10 -0
- package/dist/vite.d.ts +36 -0
- package/dist/vite.js +127 -0
- package/dist/voucher-payment-CVFDZ1L8.js +66 -0
- package/dist/worker-CNi-gzCu.js +86 -0
- package/dist/worker.d.ts +27 -0
- package/package.json +100 -81
- package/src/sections/account-addresses.tsx +215 -0
- package/src/sections/account-order.tsx +424 -0
- package/src/sections/account-orders.tsx +259 -0
- package/src/sections/account-profile.tsx +70 -0
- package/src/sections/checkout.tsx +586 -0
- package/src/sections/complaint-book.tsx +325 -0
- package/src/sections/design-system.tsx +146 -0
- package/src/sections/draft-invoice.tsx +105 -0
- package/src/sections/order-tracking.tsx +81 -0
- package/src/vite-client.d.ts +4 -0
- package/bin/ecomiq.mjs +0 -179
- package/public/design-bridge.js +0 -318
- package/src/api-proxy.ts +0 -194
- package/src/auth/create-storefront-auth.ts +0 -94
- package/src/auth/ecomiq-oauth-password-client.ts +0 -26
- package/src/auth/ecomiq-oauth-password-constants.ts +0 -24
- package/src/auth/ecomiq-oauth-password-plugin.ts +0 -294
- package/src/auth/ecomiq-oauth-password-types.ts +0 -24
- package/src/auth/ecomiq-storefront-sign-in.ts +0 -44
- package/src/auth/env.ts +0 -7
- package/src/auth/secure-cookies.ts +0 -23
- package/src/auth/storefront-auth-base-url.ts +0 -117
- package/src/auth/storefront-auth.ts +0 -7
- package/src/cart-session.ts +0 -239
- package/src/client.ts +0 -48
- package/src/cloud-runtime-client.ts +0 -378
- package/src/codegen.mjs +0 -789
- package/src/components/account/customer-addresses-panel.tsx +0 -678
- package/src/components/account/customer-order-detail-panel.tsx +0 -285
- package/src/components/account/customer-orders-panel.tsx +0 -192
- package/src/components/account/customer-profile-panel.tsx +0 -379
- package/src/components/checkout/cart-sync.ts +0 -143
- package/src/components/checkout/checkout-contact-section.tsx +0 -76
- package/src/components/checkout/checkout-external-update-banner.tsx +0 -15
- package/src/components/checkout/checkout-form-controls.tsx +0 -139
- package/src/components/checkout/checkout-line-items.tsx +0 -43
- package/src/components/checkout/checkout-order-summary.tsx +0 -165
- package/src/components/checkout/checkout-payment-section.tsx +0 -212
- package/src/components/checkout/checkout-session-view.tsx +0 -564
- package/src/components/checkout/checkout-shipping-address-section.tsx +0 -400
- package/src/components/checkout/checkout-shipping-section.tsx +0 -98
- package/src/components/checkout/checkout-states.tsx +0 -73
- package/src/components/checkout/checkout-step-card.tsx +0 -101
- package/src/components/checkout/checkout-steps.ts +0 -111
- package/src/components/checkout/form-schema.ts +0 -281
- package/src/components/checkout/format.ts +0 -15
- package/src/components/checkout/index.ts +0 -5
- package/src/components/checkout/map-customer-to-checkout.ts +0 -188
- package/src/components/checkout/types.ts +0 -41
- package/src/components/checkout/use-checkout-customer-prefill.ts +0 -409
- package/src/components/checkout/use-checkout-geo.ts +0 -50
- package/src/components/checkout/use-checkout-session.ts +0 -640
- package/src/components/hero.tsx +0 -291
- package/src/config.d.ts +0 -94
- package/src/config.mjs +0 -146
- package/src/format-money.ts +0 -31
- package/src/health.ts +0 -90
- package/src/hooks/index.ts +0 -9
- package/src/hooks/recently-viewed.ts +0 -125
- package/src/index.ts +0 -354
- package/src/link.tsx +0 -2
- package/src/pages/account/account-page-skeleton.tsx +0 -69
- package/src/pages/account/account-page-view.tsx +0 -270
- package/src/pages/account/account-shell.tsx +0 -101
- package/src/pages/account/parse-account-route.ts +0 -36
- package/src/pages/account.tsx +0 -16
- package/src/pages/api.$.ts +0 -20
- package/src/pages/api.auth.$.ts +0 -16
- package/src/pages/checkout.$checkoutId.tsx +0 -60
- package/src/pages/checkout.tsx +0 -31
- package/src/pages/pages.$pageSlug.tsx +0 -111
- package/src/pages/thank-you.tsx +0 -53
- package/src/providers/auth.tsx +0 -96
- package/src/providers/cart.tsx +0 -275
- package/src/providers/ecomiq.ts +0 -137
- package/src/providers/index.ts +0 -26
- package/src/proxy-api.ts +0 -20
- package/src/public-config.ts +0 -24
- package/src/review-submission.ts +0 -89
- package/src/runtime/context.ts +0 -2
- package/src/runtime/default-layout.tsx +0 -64
- package/src/runtime/head.ts +0 -149
- package/src/runtime/page.tsx +0 -143
- package/src/runtime/postcss-browser-stub.mjs +0 -5
- package/src/server-config-store.ts +0 -35
- package/src/server.ts +0 -301
- package/src/storefront-definition/contract.ts +0 -1
- package/src/storefront-definition/data.ts +0 -188
- package/src/storefront-definition/index.ts +0 -2
- package/src/storefront-definition/renderer.tsx +0 -1481
- package/src/storefront-layout.ts +0 -59
- package/src/storefront-runtime.ts +0 -173
- package/src/styles.css +0 -97
- package/src/ui/badge.tsx +0 -32
- package/src/ui/button.tsx +0 -31
- package/src/ui/card.tsx +0 -31
- package/src/ui/carousel.tsx +0 -218
- package/src/ui/cn.ts +0 -6
- package/src/ui/index.ts +0 -8
- package/src/ui/separator.tsx +0 -6
- package/src/ui/skeleton.tsx +0 -6
- package/src/ui/storefront-error.tsx +0 -49
- package/src/utils.ts +0 -36
- package/src/vite-inline.mjs +0 -263
- package/templates/__root.tsx +0 -83
- package/templates/router.tsx +0 -19
package/src/server.ts
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API storefront que solo corre en el servidor (TanStack Start RPC).
|
|
3
|
-
* En SSR ejecuta el handler localmente; en el cliente llama al Worker.
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* import { definePage, serverApi } from '@ecomiq/storefront'
|
|
7
|
-
*
|
|
8
|
-
* export default definePage({
|
|
9
|
-
* loader: () => serverApi.getProducts({ page: 1, pageSize: 12 }),
|
|
10
|
-
* component: ({ data }) => …,
|
|
11
|
-
* })
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Nota: cada `createServerFn` debe vivir en el top-level del módulo
|
|
15
|
-
* (el compilador de Start asigna IDs estables por call-site).
|
|
16
|
-
* El cliente storefront es singleton → el cache de settings se reutiliza.
|
|
17
|
-
*/
|
|
18
|
-
import { createServerFn } from '@tanstack/react-start'
|
|
19
|
-
import {
|
|
20
|
-
AddCartItemParamsSchema,
|
|
21
|
-
CartAddressesParamsSchema,
|
|
22
|
-
CartBuyerParamsSchema,
|
|
23
|
-
CartCheckoutParamsSchema,
|
|
24
|
-
CartCheckoutReadParamsSchema,
|
|
25
|
-
CartPromotionCodeParamsSchema,
|
|
26
|
-
CreateProductReviewParamsSchema,
|
|
27
|
-
GetCartParamsSchema,
|
|
28
|
-
GetDepartmentsParamsSchema,
|
|
29
|
-
GetDistrictsParamsSchema,
|
|
30
|
-
GetProvincesParamsSchema,
|
|
31
|
-
GetShippingOptionsParamsSchema,
|
|
32
|
-
ListProductReviewsParamsSchema,
|
|
33
|
-
ProductAutocompleteParamsSchema,
|
|
34
|
-
ProductDetailParamsSchema,
|
|
35
|
-
ProductsParamsSchema,
|
|
36
|
-
PutShippingMethodParamsSchema,
|
|
37
|
-
RelatedProductsParamsSchema,
|
|
38
|
-
RemoveCartItemParamsSchema,
|
|
39
|
-
UpdateCartItemQuantityParamsSchema,
|
|
40
|
-
type AddCartItemParams,
|
|
41
|
-
type CartAddressesParams,
|
|
42
|
-
type CartBuyerParams,
|
|
43
|
-
type CartCheckoutParams,
|
|
44
|
-
type CartCheckoutReadParams,
|
|
45
|
-
type CartPromotionCodeParams,
|
|
46
|
-
type CreateProductReviewParams,
|
|
47
|
-
type GetCartParams,
|
|
48
|
-
type GetDepartmentsParams,
|
|
49
|
-
type GetDistrictsParams,
|
|
50
|
-
type GetProvincesParams,
|
|
51
|
-
type GetShippingOptionsParams,
|
|
52
|
-
type ListProductReviewsParams,
|
|
53
|
-
type ProductAutocompleteParams,
|
|
54
|
-
type ProductDetailParams,
|
|
55
|
-
type ProductsParamsInput,
|
|
56
|
-
type PutShippingMethodParams,
|
|
57
|
-
type RelatedProductsParams,
|
|
58
|
-
type RemoveCartItemParams,
|
|
59
|
-
type UpdateCartItemQuantityParams,
|
|
60
|
-
type UploadPaymentReceiptParams,
|
|
61
|
-
CartTokenSchema,
|
|
62
|
-
EntityIdSchema,
|
|
63
|
-
} from '@ecomiq/core'
|
|
64
|
-
import { z } from 'zod'
|
|
65
|
-
import { getStorefrontClient } from './client'
|
|
66
|
-
import {
|
|
67
|
-
loadActiveCart,
|
|
68
|
-
submitCartItemQuantity,
|
|
69
|
-
submitCartItemRemoval,
|
|
70
|
-
submitProductToCart,
|
|
71
|
-
type AddProductToCartInput,
|
|
72
|
-
} from './cart-session'
|
|
73
|
-
import { submitProductReview } from './review-submission'
|
|
74
|
-
import {
|
|
75
|
-
loadActiveStorefrontHome,
|
|
76
|
-
loadActiveStorefrontPage,
|
|
77
|
-
} from './storefront-runtime'
|
|
78
|
-
|
|
79
|
-
const getSettingsFn = createServerFn({ method: 'GET' }).handler(() =>
|
|
80
|
-
getStorefrontClient().getSettings(),
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
const getActiveStorefrontHomeFn = createServerFn({ method: 'GET' }).handler(
|
|
84
|
-
() => loadActiveStorefrontHome(),
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
const getActiveStorefrontPageFn = createServerFn({ method: 'GET' })
|
|
88
|
-
.validator(z.object({ pathname: z.string().min(1).max(2_048) }))
|
|
89
|
-
.handler(({ data }) => loadActiveStorefrontPage(data.pathname))
|
|
90
|
-
|
|
91
|
-
const getStoreIdFn = createServerFn({ method: 'GET' }).handler(() =>
|
|
92
|
-
getStorefrontClient().getStoreId(),
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
const getCollectionsFn = createServerFn({ method: 'GET' }).handler(() =>
|
|
96
|
-
getStorefrontClient().getCollections(),
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
const getCollectionBySlugFn = createServerFn({ method: 'GET' })
|
|
100
|
-
.validator(z.object({ slug: z.string().min(1) }))
|
|
101
|
-
.handler(({ data }) => getStorefrontClient().getCollectionBySlug(data.slug))
|
|
102
|
-
|
|
103
|
-
const getPageBySlugFn = createServerFn({ method: 'GET' })
|
|
104
|
-
.validator(z.object({ slug: z.string().min(1) }))
|
|
105
|
-
.handler(({ data }) => getStorefrontClient().getPageBySlug(data.slug))
|
|
106
|
-
|
|
107
|
-
const getProductsFn = createServerFn({ method: 'GET' })
|
|
108
|
-
.validator(ProductsParamsSchema)
|
|
109
|
-
.handler(({ data }) => getStorefrontClient().getProducts(data))
|
|
110
|
-
|
|
111
|
-
const ProductBySlugServerParamsSchema = ProductDetailParamsSchema.extend({
|
|
112
|
-
slug: z.string().min(1),
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
const getProductBySlugFn = createServerFn({ method: 'GET' })
|
|
116
|
-
.validator(ProductBySlugServerParamsSchema)
|
|
117
|
-
.handler(({ data }) =>
|
|
118
|
-
getStorefrontClient().getProductBySlug(data.slug, { sellerId: data.sellerId }),
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
const getRelatedProductsFn = createServerFn({ method: 'GET' })
|
|
122
|
-
.validator(RelatedProductsParamsSchema)
|
|
123
|
-
.handler(({ data }) => getStorefrontClient().getRelatedProducts(data))
|
|
124
|
-
|
|
125
|
-
const autocompleteProductsFn = createServerFn({ method: 'GET' })
|
|
126
|
-
.validator(ProductAutocompleteParamsSchema)
|
|
127
|
-
.handler(({ data }) => getStorefrontClient().autocompleteProducts(data))
|
|
128
|
-
|
|
129
|
-
const listProductReviewsFn = createServerFn({ method: 'GET' })
|
|
130
|
-
.validator(ListProductReviewsParamsSchema)
|
|
131
|
-
.handler(({ data }) => getStorefrontClient().listProductReviews(data))
|
|
132
|
-
|
|
133
|
-
const submitProductReviewFn = createServerFn({ method: 'POST' })
|
|
134
|
-
.validator(CreateProductReviewParamsSchema)
|
|
135
|
-
.handler(({ data }) => submitProductReview(getStorefrontClient(), data))
|
|
136
|
-
|
|
137
|
-
const loadCartFn = createServerFn({ method: 'POST' })
|
|
138
|
-
.validator(GetCartParamsSchema)
|
|
139
|
-
.handler(({ data }) => loadActiveCart(getStorefrontClient(), data))
|
|
140
|
-
|
|
141
|
-
const setCartItemQuantityFn = createServerFn({ method: 'POST' })
|
|
142
|
-
.validator(UpdateCartItemQuantityParamsSchema)
|
|
143
|
-
.handler(({ data }) => submitCartItemQuantity(getStorefrontClient(), data))
|
|
144
|
-
|
|
145
|
-
const removeCartItemFn = createServerFn({ method: 'POST' })
|
|
146
|
-
.validator(RemoveCartItemParamsSchema)
|
|
147
|
-
.handler(({ data }) => submitCartItemRemoval(getStorefrontClient(), data))
|
|
148
|
-
|
|
149
|
-
const AddProductToCartServerSchema = z.object({
|
|
150
|
-
cartToken: CartTokenSchema.optional(),
|
|
151
|
-
currencyCode: z.string().length(3),
|
|
152
|
-
variantId: EntityIdSchema,
|
|
153
|
-
quantity: z.number().int().positive(),
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
const addProductToCartFn = createServerFn({ method: 'POST' })
|
|
157
|
-
.validator(AddProductToCartServerSchema)
|
|
158
|
-
.handler(({ data }) => submitProductToCart(getStorefrontClient(), data))
|
|
159
|
-
|
|
160
|
-
const addCartItemFn = createServerFn({ method: 'POST' })
|
|
161
|
-
.validator(AddCartItemParamsSchema)
|
|
162
|
-
.handler(({ data }) => getStorefrontClient().addCartItem(data))
|
|
163
|
-
|
|
164
|
-
const getCartCheckoutFn = createServerFn({ method: 'GET' })
|
|
165
|
-
.validator(CartCheckoutReadParamsSchema)
|
|
166
|
-
.handler(({ data }) => getStorefrontClient().getCartCheckout(data))
|
|
167
|
-
|
|
168
|
-
const getShippingOptionsFn = createServerFn({ method: 'GET' })
|
|
169
|
-
.validator(GetShippingOptionsParamsSchema)
|
|
170
|
-
.handler(({ data }) => getStorefrontClient().getShippingOptions(data))
|
|
171
|
-
|
|
172
|
-
const putCartShippingMethodFn = createServerFn({ method: 'POST' })
|
|
173
|
-
.validator(PutShippingMethodParamsSchema)
|
|
174
|
-
.handler(({ data }) => getStorefrontClient().putCartShippingMethod(data))
|
|
175
|
-
|
|
176
|
-
const patchCartBuyerFn = createServerFn({ method: 'POST' })
|
|
177
|
-
.validator(CartBuyerParamsSchema)
|
|
178
|
-
.handler(({ data }) => getStorefrontClient().patchCartBuyer(data))
|
|
179
|
-
|
|
180
|
-
const patchCartAddressesFn = createServerFn({ method: 'POST' })
|
|
181
|
-
.validator(CartAddressesParamsSchema)
|
|
182
|
-
.handler(({ data }) => getStorefrontClient().patchCartAddresses(data))
|
|
183
|
-
|
|
184
|
-
const checkoutCartFn = createServerFn({ method: 'POST' })
|
|
185
|
-
.validator(CartCheckoutParamsSchema)
|
|
186
|
-
.handler(({ data }) => getStorefrontClient().checkoutCart(data))
|
|
187
|
-
|
|
188
|
-
const CartPaymentReceiptServerSchema = z.object({
|
|
189
|
-
cartToken: CartTokenSchema,
|
|
190
|
-
fileBase64: z.string().min(1),
|
|
191
|
-
fileName: z.string().min(1),
|
|
192
|
-
mimeType: z.string().min(1).optional(),
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
const uploadPaymentReceiptFn = createServerFn({ method: 'POST' })
|
|
196
|
-
.validator(CartPaymentReceiptServerSchema)
|
|
197
|
-
.handler(({ data }) => {
|
|
198
|
-
const binary = Uint8Array.from(atob(data.fileBase64), (c) => c.charCodeAt(0))
|
|
199
|
-
const file = new Blob([binary], { type: data.mimeType ?? 'application/octet-stream' })
|
|
200
|
-
return getStorefrontClient().uploadPaymentReceipt({
|
|
201
|
-
cartToken: data.cartToken,
|
|
202
|
-
file,
|
|
203
|
-
fileName: data.fileName,
|
|
204
|
-
})
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
const addCartPromotionCodeFn = createServerFn({ method: 'POST' })
|
|
208
|
-
.validator(CartPromotionCodeParamsSchema)
|
|
209
|
-
.handler(({ data }) => getStorefrontClient().addCartPromotionCode(data))
|
|
210
|
-
|
|
211
|
-
const removeCartPromotionCodeFn = createServerFn({ method: 'POST' })
|
|
212
|
-
.validator(CartPromotionCodeParamsSchema)
|
|
213
|
-
.handler(({ data }) => getStorefrontClient().removeCartPromotionCode(data))
|
|
214
|
-
|
|
215
|
-
const getCountriesFn = createServerFn({ method: 'GET' }).handler(() =>
|
|
216
|
-
getStorefrontClient().getCountries(),
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
const getDepartmentsFn = createServerFn({ method: 'GET' })
|
|
220
|
-
.validator(GetDepartmentsParamsSchema)
|
|
221
|
-
.handler(({ data }) => getStorefrontClient().getDepartments(data))
|
|
222
|
-
|
|
223
|
-
const getProvincesFn = createServerFn({ method: 'GET' })
|
|
224
|
-
.validator(GetProvincesParamsSchema)
|
|
225
|
-
.handler(({ data }) => getStorefrontClient().getProvinces(data))
|
|
226
|
-
|
|
227
|
-
const getDistrictsFn = createServerFn({ method: 'GET' })
|
|
228
|
-
.validator(GetDistrictsParamsSchema)
|
|
229
|
-
.handler(({ data }) => getStorefrontClient().getDistricts(data))
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Cliente storefront server-only. Misma superficie útil que `createClient()`,
|
|
233
|
-
* pero cada método es una server function reutilizable desde cualquier página.
|
|
234
|
-
*/
|
|
235
|
-
export const serverApi = {
|
|
236
|
-
getSettings: () => getSettingsFn(),
|
|
237
|
-
getActiveStorefrontHome: () => getActiveStorefrontHomeFn(),
|
|
238
|
-
getActiveStorefrontPage: (pathname: string) =>
|
|
239
|
-
getActiveStorefrontPageFn({ data: { pathname } }),
|
|
240
|
-
getStoreId: () => getStoreIdFn(),
|
|
241
|
-
getCollections: () => getCollectionsFn(),
|
|
242
|
-
getCollectionBySlug: (slug: string) => getCollectionBySlugFn({ data: { slug } }),
|
|
243
|
-
getPageBySlug: (slug: string) => getPageBySlugFn({ data: { slug } }),
|
|
244
|
-
getProducts: (
|
|
245
|
-
params: ProductsParamsInput = {},
|
|
246
|
-
options: { signal?: AbortSignal } = {},
|
|
247
|
-
) => getProductsFn({ data: params, signal: options.signal }),
|
|
248
|
-
getProductBySlug: (slug: string, params: ProductDetailParams = {}) =>
|
|
249
|
-
getProductBySlugFn({ data: { slug, ...params } }),
|
|
250
|
-
getRelatedProducts: (params: RelatedProductsParams) =>
|
|
251
|
-
getRelatedProductsFn({ data: params }),
|
|
252
|
-
autocompleteProducts: (params: ProductAutocompleteParams) =>
|
|
253
|
-
autocompleteProductsFn({ data: params }),
|
|
254
|
-
listProductReviews: (params: ListProductReviewsParams) =>
|
|
255
|
-
listProductReviewsFn({ data: params }),
|
|
256
|
-
submitProductReview: (params: CreateProductReviewParams) =>
|
|
257
|
-
submitProductReviewFn({ data: params }),
|
|
258
|
-
loadCart: (params: GetCartParams) => loadCartFn({ data: params }),
|
|
259
|
-
setCartItemQuantity: (params: UpdateCartItemQuantityParams) =>
|
|
260
|
-
setCartItemQuantityFn({ data: params }),
|
|
261
|
-
removeCartItem: (params: RemoveCartItemParams) =>
|
|
262
|
-
removeCartItemFn({ data: params }),
|
|
263
|
-
addProductToCart: (params: AddProductToCartInput) =>
|
|
264
|
-
addProductToCartFn({ data: params }),
|
|
265
|
-
addCartItem: (params: AddCartItemParams) => addCartItemFn({ data: params }),
|
|
266
|
-
getCartCheckout: (params: CartCheckoutReadParams) =>
|
|
267
|
-
getCartCheckoutFn({ data: params }),
|
|
268
|
-
getShippingOptions: (params: GetShippingOptionsParams) =>
|
|
269
|
-
getShippingOptionsFn({ data: params }),
|
|
270
|
-
putCartShippingMethod: (params: PutShippingMethodParams) =>
|
|
271
|
-
putCartShippingMethodFn({ data: params }),
|
|
272
|
-
patchCartBuyer: (params: CartBuyerParams) => patchCartBuyerFn({ data: params }),
|
|
273
|
-
patchCartAddresses: (params: CartAddressesParams) =>
|
|
274
|
-
patchCartAddressesFn({ data: params }),
|
|
275
|
-
checkoutCart: (params: CartCheckoutParams) => checkoutCartFn({ data: params }),
|
|
276
|
-
uploadPaymentReceipt: async (params: UploadPaymentReceiptParams) => {
|
|
277
|
-
const buffer = await params.file.arrayBuffer()
|
|
278
|
-
const bytes = new Uint8Array(buffer)
|
|
279
|
-
let binary = ''
|
|
280
|
-
for (const byte of bytes) binary += String.fromCharCode(byte)
|
|
281
|
-
return uploadPaymentReceiptFn({
|
|
282
|
-
data: {
|
|
283
|
-
cartToken: params.cartToken,
|
|
284
|
-
fileBase64: btoa(binary),
|
|
285
|
-
fileName:
|
|
286
|
-
params.fileName ??
|
|
287
|
-
(params.file instanceof File ? params.file.name : 'receipt'),
|
|
288
|
-
mimeType: params.file.type || undefined,
|
|
289
|
-
},
|
|
290
|
-
})
|
|
291
|
-
},
|
|
292
|
-
addCartPromotionCode: (params: CartPromotionCodeParams) =>
|
|
293
|
-
addCartPromotionCodeFn({ data: params }),
|
|
294
|
-
removeCartPromotionCode: (params: CartPromotionCodeParams) =>
|
|
295
|
-
removeCartPromotionCodeFn({ data: params }),
|
|
296
|
-
getCountries: () => getCountriesFn(),
|
|
297
|
-
getDepartments: (params: GetDepartmentsParams) =>
|
|
298
|
-
getDepartmentsFn({ data: params }),
|
|
299
|
-
getProvinces: (params: GetProvincesParams) => getProvincesFn({ data: params }),
|
|
300
|
-
getDistricts: (params: GetDistrictsParams) => getDistrictsFn({ data: params }),
|
|
301
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@ecomiq/storefront-definition'
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Collection,
|
|
3
|
-
Collections,
|
|
4
|
-
ProductsParamsInput,
|
|
5
|
-
ProductsResponse,
|
|
6
|
-
ProductSummary,
|
|
7
|
-
} from '@ecomiq/core'
|
|
8
|
-
import {
|
|
9
|
-
type CollectionGridStorefrontSection,
|
|
10
|
-
type ProductGridStorefrontSection,
|
|
11
|
-
type StorefrontDefinition,
|
|
12
|
-
} from '@ecomiq/storefront-definition'
|
|
13
|
-
import { storefrontPageFor } from './renderer'
|
|
14
|
-
import type { DefinitionData } from './renderer'
|
|
15
|
-
|
|
16
|
-
const MAX_UNIQUE_PRODUCT_SOURCES = 12
|
|
17
|
-
const MANUAL_PRODUCT_PAGE_SIZE = 100
|
|
18
|
-
const MAX_MANUAL_PRODUCT_SCAN_PAGES = 5
|
|
19
|
-
|
|
20
|
-
export interface StorefrontRuntimeCatalogClient {
|
|
21
|
-
getProducts(params?: ProductsParamsInput): Promise<ProductsResponse>
|
|
22
|
-
getCollections(): Promise<Collections>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface ResolvedStorefrontDefinitionData
|
|
26
|
-
extends DefinitionData {
|
|
27
|
-
productsBySectionId: Record<string, ProductSummary[]>
|
|
28
|
-
collectionsBySectionId: Record<string, Collection[]>
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function emptyRendererData(): ResolvedStorefrontDefinitionData {
|
|
32
|
-
return {
|
|
33
|
-
productsBySectionId: {},
|
|
34
|
-
collectionsBySectionId: {},
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function productSourceKey(
|
|
39
|
-
section: ProductGridStorefrontSection,
|
|
40
|
-
): string | null {
|
|
41
|
-
if (section.source.kind === 'manual') return null
|
|
42
|
-
if (section.source.kind === 'collection') {
|
|
43
|
-
return `collection:${section.source.slug}`
|
|
44
|
-
}
|
|
45
|
-
return 'all'
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function loadProductSource(
|
|
49
|
-
section: ProductGridStorefrontSection,
|
|
50
|
-
client: StorefrontRuntimeCatalogClient,
|
|
51
|
-
): Promise<ProductSummary[]> {
|
|
52
|
-
const params: ProductsParamsInput = {
|
|
53
|
-
page: 1,
|
|
54
|
-
pageSize: section.limit,
|
|
55
|
-
sort: 'newest',
|
|
56
|
-
}
|
|
57
|
-
if (section.source.kind === 'collection') {
|
|
58
|
-
params.collection = section.source.slug
|
|
59
|
-
}
|
|
60
|
-
const response = await client.getProducts(params)
|
|
61
|
-
return response.products.slice(0, section.limit)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function scanManualProducts(
|
|
65
|
-
productIds: ReadonlySet<string>,
|
|
66
|
-
client: StorefrontRuntimeCatalogClient,
|
|
67
|
-
): Promise<Map<string, ProductSummary>> {
|
|
68
|
-
const found = new Map<string, ProductSummary>()
|
|
69
|
-
|
|
70
|
-
for (let page = 1; page <= MAX_MANUAL_PRODUCT_SCAN_PAGES; page += 1) {
|
|
71
|
-
const response = await client.getProducts({
|
|
72
|
-
page,
|
|
73
|
-
pageSize: MANUAL_PRODUCT_PAGE_SIZE,
|
|
74
|
-
sort: 'newest',
|
|
75
|
-
})
|
|
76
|
-
for (const product of response.products) {
|
|
77
|
-
if (productIds.has(product.id)) found.set(product.id, product)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
found.size === productIds.size ||
|
|
82
|
-
page >= response.totalPages ||
|
|
83
|
-
response.products.length === 0
|
|
84
|
-
) {
|
|
85
|
-
break
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return found
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function resolveStorefrontDefinitionData(
|
|
93
|
-
definition: StorefrontDefinition,
|
|
94
|
-
client: StorefrontRuntimeCatalogClient,
|
|
95
|
-
pageId?: string,
|
|
96
|
-
): Promise<ResolvedStorefrontDefinitionData> {
|
|
97
|
-
const data = emptyRendererData()
|
|
98
|
-
const page = storefrontPageFor(definition, pageId)
|
|
99
|
-
const sections = page?.sections ?? []
|
|
100
|
-
const productSections = sections.filter(
|
|
101
|
-
(section): section is ProductGridStorefrontSection =>
|
|
102
|
-
section.enabled && section.type === 'product-grid',
|
|
103
|
-
)
|
|
104
|
-
const collectionSections = sections.filter(
|
|
105
|
-
(section): section is CollectionGridStorefrontSection =>
|
|
106
|
-
section.enabled && section.type === 'collection-grid',
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
const sourceSections = new Map<string, ProductGridStorefrontSection>()
|
|
110
|
-
for (const section of productSections) {
|
|
111
|
-
const sourceKey = productSourceKey(section)
|
|
112
|
-
if (!sourceKey) continue
|
|
113
|
-
const current = sourceSections.get(sourceKey)
|
|
114
|
-
if (current) {
|
|
115
|
-
if (section.limit > current.limit) sourceSections.set(sourceKey, section)
|
|
116
|
-
continue
|
|
117
|
-
}
|
|
118
|
-
if (sourceSections.size >= MAX_UNIQUE_PRODUCT_SOURCES) continue
|
|
119
|
-
sourceSections.set(sourceKey, section)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const sourceRequests = new Map<string, Promise<ProductSummary[]>>()
|
|
123
|
-
for (const [sourceKey, section] of sourceSections) {
|
|
124
|
-
sourceRequests.set(
|
|
125
|
-
sourceKey,
|
|
126
|
-
loadProductSource(section, client).catch(() => []),
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const manualIds = new Set(
|
|
131
|
-
productSections.flatMap((section) =>
|
|
132
|
-
section.source.kind === 'manual' ? section.source.productIds : [],
|
|
133
|
-
),
|
|
134
|
-
)
|
|
135
|
-
const manualProducts =
|
|
136
|
-
manualIds.size > 0
|
|
137
|
-
? scanManualProducts(manualIds, client).catch(
|
|
138
|
-
() => new Map<string, ProductSummary>(),
|
|
139
|
-
)
|
|
140
|
-
: Promise.resolve(new Map<string, ProductSummary>())
|
|
141
|
-
|
|
142
|
-
await Promise.all(
|
|
143
|
-
productSections.map(async (section) => {
|
|
144
|
-
if (section.source.kind === 'manual') {
|
|
145
|
-
const productsById = await manualProducts
|
|
146
|
-
data.productsBySectionId[section.id] = section.source.productIds
|
|
147
|
-
.map((productId) => productsById.get(productId))
|
|
148
|
-
.filter(
|
|
149
|
-
(product): product is ProductSummary => product !== undefined,
|
|
150
|
-
)
|
|
151
|
-
.slice(0, section.limit)
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const sourceKey = productSourceKey(section)
|
|
156
|
-
const products = sourceKey
|
|
157
|
-
? await (sourceRequests.get(sourceKey) ?? Promise.resolve([]))
|
|
158
|
-
: []
|
|
159
|
-
data.productsBySectionId[section.id] = products.slice(0, section.limit)
|
|
160
|
-
}),
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
if (collectionSections.length > 0) {
|
|
164
|
-
const collections = await client.getCollections().catch(() => [])
|
|
165
|
-
const collectionsBySlug = new Map(
|
|
166
|
-
collections.map((collection) => [collection.slug, collection]),
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
for (const section of collectionSections) {
|
|
170
|
-
if (section.source.kind === 'manual') {
|
|
171
|
-
data.collectionsBySectionId[section.id] = section.source.slugs
|
|
172
|
-
.map((slug) => collectionsBySlug.get(slug))
|
|
173
|
-
.filter(
|
|
174
|
-
(collection): collection is Collection =>
|
|
175
|
-
collection !== undefined,
|
|
176
|
-
)
|
|
177
|
-
.slice(0, section.limit)
|
|
178
|
-
continue
|
|
179
|
-
}
|
|
180
|
-
data.collectionsBySectionId[section.id] = collections.slice(
|
|
181
|
-
0,
|
|
182
|
-
section.limit,
|
|
183
|
-
)
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return data
|
|
188
|
-
}
|