@ecomiq/storefront 2.1.4 → 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 -103
- 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 -76
- 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/codegen.mjs +0 -801
- 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 -349
- 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 -74
- 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 -286
- package/src/styles.css +0 -76
- 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
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CatalogLink, CatalogLinkReference, ProductSort, ProductSummary, StorefrontClient } from "@ecomiq/core";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
3
|
+
declare function link(url: string, label?: string, reference?: null): string;
|
|
4
|
+
declare function link(url: string, label: string | undefined, reference: CatalogLinkReference): CatalogLink;
|
|
5
|
+
declare function link(url: string, label: string | undefined, reference: CatalogLinkReference | null | undefined): string | CatalogLink;
|
|
6
|
+
export type SettingOptions = {
|
|
7
|
+
readonly [value: string]: string;
|
|
8
|
+
};
|
|
9
|
+
export type SettingLimits = {
|
|
10
|
+
readonly min: number;
|
|
11
|
+
readonly max: number;
|
|
12
|
+
readonly step?: number;
|
|
13
|
+
};
|
|
14
|
+
declare function select<const Options extends SettingOptions>(value: Extract<keyof Options, string>, _label: string | undefined, _options: Options): Extract<keyof Options, string>;
|
|
15
|
+
export declare const setting: {
|
|
16
|
+
text: (value: string, _label?: string) => string;
|
|
17
|
+
richtext: (html: string, _label?: string) => string;
|
|
18
|
+
image: (url: string, _label?: string) => string;
|
|
19
|
+
video: (url: string, _label?: string) => string;
|
|
20
|
+
link: typeof link;
|
|
21
|
+
collection: (handle: string, _label?: string) => string;
|
|
22
|
+
category: (handle: string, _label?: string) => string;
|
|
23
|
+
product: (handle: string, _label?: string) => string;
|
|
24
|
+
products: (handles: string[], _label?: string) => string[];
|
|
25
|
+
number: (value: number, _label?: string) => number;
|
|
26
|
+
range: (value: number, _label: string | undefined, _limits: SettingLimits) => number;
|
|
27
|
+
toggle: (value: boolean, _label?: string) => boolean;
|
|
28
|
+
color: (value: string, _label?: string) => string;
|
|
29
|
+
select: typeof select;
|
|
30
|
+
scheme: (id: string, _label?: string) => string;
|
|
31
|
+
};
|
|
32
|
+
export type SectionGroup = "products" | "collections" | "content" | "reviews";
|
|
33
|
+
export type SectionCatalog = {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly description: string;
|
|
36
|
+
readonly group?: SectionGroup;
|
|
37
|
+
};
|
|
38
|
+
export type SectionRoot = Omit<ComponentProps<"section">, "className" | "children">;
|
|
39
|
+
export type SectionProps<Settings> = { readonly [Key in keyof Settings]?: Settings[Key] extends readonly unknown[] ? Settings[Key] : Settings[Key] extends object ? Partial<Settings[Key]> : Settings[Key]; } & {
|
|
40
|
+
readonly children?: ReactNode;
|
|
41
|
+
};
|
|
42
|
+
export declare function section<Settings extends object>(defaults: Settings, props: SectionProps<Settings>): Settings;
|
|
43
|
+
export type ProductSource = {
|
|
44
|
+
collection?: string;
|
|
45
|
+
category?: string;
|
|
46
|
+
products?: string[];
|
|
47
|
+
limit?: number;
|
|
48
|
+
sort?: ProductSort;
|
|
49
|
+
};
|
|
50
|
+
export declare function pickProducts(client: StorefrontClient, source: ProductSource): Promise<ProductSummary[]>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createContext, use } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/sources.tsx
|
|
4
|
+
const SourceData = createContext(null);
|
|
5
|
+
function SourceProvider({ value, children }) {
|
|
6
|
+
return /* @__PURE__ */ jsx(SourceData, {
|
|
7
|
+
value,
|
|
8
|
+
children
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function field(value, key) {
|
|
12
|
+
if (key === void 0 || typeof value !== "object" || value === null) return void 0;
|
|
13
|
+
return value[key];
|
|
14
|
+
}
|
|
15
|
+
function text(value) {
|
|
16
|
+
if (typeof value === "string") return value;
|
|
17
|
+
if (typeof value === "number") return String(value);
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
function sourceValue(data, path) {
|
|
21
|
+
const [kind, name, key] = path.split(".");
|
|
22
|
+
if (kind === "product") {
|
|
23
|
+
const product = field(data, "product");
|
|
24
|
+
if (name === "description") return text(field(data, "description"));
|
|
25
|
+
if (name === "image") {
|
|
26
|
+
const images = field(product, "images");
|
|
27
|
+
return text(field(product, "imageUrl")) || text(field(Array.isArray(images) ? images[0] : void 0, "url"));
|
|
28
|
+
}
|
|
29
|
+
if (name === "attributes") {
|
|
30
|
+
const specifications = field(product, "specifications");
|
|
31
|
+
const found = Array.isArray(specifications) ? specifications.find((item) => field(item, "key") === key) : void 0;
|
|
32
|
+
return text(field(found, "valueName")) || text(field(found, "value"));
|
|
33
|
+
}
|
|
34
|
+
return text(field(product, name));
|
|
35
|
+
}
|
|
36
|
+
if (kind === "collection") {
|
|
37
|
+
const collection = field(data, "collection");
|
|
38
|
+
if (name === "image") return text(field(collection, "imageUrl"));
|
|
39
|
+
return text(field(collection, name));
|
|
40
|
+
}
|
|
41
|
+
return text(field(data, name));
|
|
42
|
+
}
|
|
43
|
+
function source(path) {
|
|
44
|
+
return sourceValue(use(SourceData), path);
|
|
45
|
+
}
|
|
46
|
+
export { SourceProvider, source, sourceValue };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
export declare function SourceProvider({ value, children }: {
|
|
3
|
+
value: unknown;
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
}): ReactElement;
|
|
6
|
+
export declare function sourceValue(data: unknown, path: string): string;
|
|
7
|
+
export declare function source(path: string): string;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { apiCacheFetch, uncachedFetch } from "./api-cache-DsuIn5hX.js";
|
|
2
|
+
import { previewClient } from "./preview-BiIBif3C.js";
|
|
3
|
+
import { productPreviewClient } from "./product-preview-BspMAecJ.js";
|
|
4
|
+
import { observeStorefrontClient } from "./telemetry-HuZXWBPi.js";
|
|
5
|
+
import { worker } from "./worker-CNi-gzCu.js";
|
|
6
|
+
import { data } from "react-router";
|
|
7
|
+
import { ApiError, GraphQLResponseError, createClient } from "@ecomiq/core";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
// src/store.ts
|
|
10
|
+
const requestClients = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
const REQUEST_READS = /* @__PURE__ */ new Set([
|
|
12
|
+
"getSettings",
|
|
13
|
+
"getLayout",
|
|
14
|
+
"getStoreId",
|
|
15
|
+
"getCollections",
|
|
16
|
+
"getPaymentMethods",
|
|
17
|
+
"getCollectionBySlug",
|
|
18
|
+
"getPageBySlug",
|
|
19
|
+
"getCategoryBySlug",
|
|
20
|
+
"resolveUrl",
|
|
21
|
+
"getLinks",
|
|
22
|
+
"listArticles",
|
|
23
|
+
"getArticleBySlug",
|
|
24
|
+
"getSellers",
|
|
25
|
+
"getSellerBySlug",
|
|
26
|
+
"getProducts",
|
|
27
|
+
"getProductBySlug",
|
|
28
|
+
"getRelatedProducts",
|
|
29
|
+
"listProductReviews",
|
|
30
|
+
"listStoreReviews"
|
|
31
|
+
]);
|
|
32
|
+
function shareRequestReads(client) {
|
|
33
|
+
const reads = /* @__PURE__ */ new Map();
|
|
34
|
+
return new Proxy(client, { get(target, property, receiver) {
|
|
35
|
+
if (property === "clearCache") return () => {
|
|
36
|
+
reads.clear();
|
|
37
|
+
target.clearCache();
|
|
38
|
+
};
|
|
39
|
+
const value = Reflect.get(target, property, receiver);
|
|
40
|
+
if (typeof property !== "string" || !REQUEST_READS.has(property) || typeof value !== "function") return value;
|
|
41
|
+
return (...args) => {
|
|
42
|
+
const key = `${property}:${JSON.stringify(args)}`;
|
|
43
|
+
const shared = reads.get(key);
|
|
44
|
+
if (shared) return shared;
|
|
45
|
+
const read = Promise.resolve(Reflect.apply(value, target, args));
|
|
46
|
+
reads.set(key, read);
|
|
47
|
+
read.catch(() => {
|
|
48
|
+
if (reads.get(key) === read) reads.delete(key);
|
|
49
|
+
});
|
|
50
|
+
return read;
|
|
51
|
+
};
|
|
52
|
+
} });
|
|
53
|
+
}
|
|
54
|
+
function store(context) {
|
|
55
|
+
let client = requestClients.get(context);
|
|
56
|
+
if (client) return client;
|
|
57
|
+
const { env, ctx, sdkTiming, productPreview, cacheRevision } = context.get(worker);
|
|
58
|
+
const count = () => sdkTiming?.recordSubrequest();
|
|
59
|
+
const cached = productPreview || env.ECOMIQ_PREVIEW === "1" || cacheRevision === void 0 ? void 0 : apiCacheFetch(ctx, env.ECOMIQ_STORE, count, cacheRevision);
|
|
60
|
+
client = createClient({
|
|
61
|
+
domain: env.ECOMIQ_STORE,
|
|
62
|
+
baseUrl: env.ECOMIQ_API_URL,
|
|
63
|
+
storeId: env.ECOMIQ_STORE_ID,
|
|
64
|
+
fetch: cached ?? uncachedFetch(count)
|
|
65
|
+
});
|
|
66
|
+
if (env.ECOMIQ_PREVIEW === "1") client = previewClient(client);
|
|
67
|
+
if (productPreview) client = productPreviewClient(client, productPreview);
|
|
68
|
+
client = shareRequestReads(client);
|
|
69
|
+
if (sdkTiming) client = observeStorefrontClient(client, sdkTiming);
|
|
70
|
+
requestClients.set(context, client);
|
|
71
|
+
return client;
|
|
72
|
+
}
|
|
73
|
+
async function storeHeaders(client) {
|
|
74
|
+
return { headers: { "x-Store-Id": await client.getStoreId() } };
|
|
75
|
+
}
|
|
76
|
+
async function found(read, missing = (status) => status === 404) {
|
|
77
|
+
try {
|
|
78
|
+
return await read;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof ApiError && missing(error.status)) throw data(null, { status: 404 });
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const CollectionImagesSchema = z.record(z.string(), z.object({ products: z.array(z.object({ imageUrl: z.string() })) }).nullable());
|
|
85
|
+
async function collectionImageCandidates({ client, collections, pageSize }) {
|
|
86
|
+
const missing = [...new Map(collections.filter((collection) => !collection.imageUrl).map((collection) => [collection.id, collection])).values()].sort((left, right) => left.id.localeCompare(right.id));
|
|
87
|
+
const candidates = /* @__PURE__ */ new Map();
|
|
88
|
+
const batches = [];
|
|
89
|
+
for (let offset = 0; offset < missing.length; offset += 10) {
|
|
90
|
+
const batch = missing.slice(offset, offset + 10);
|
|
91
|
+
const variables = Object.fromEntries(batch.map((collection, index) => [`c${index}`, {
|
|
92
|
+
collectionId: collection.id,
|
|
93
|
+
pageSize,
|
|
94
|
+
includeFilters: false
|
|
95
|
+
}]));
|
|
96
|
+
const parameters = batch.map((_, index) => `$c${index}: StorefrontProductsInput!`).join(", ");
|
|
97
|
+
const fields = batch.map((_, index) => `c${index}: products(input: $c${index}) { products { imageUrl } }`).join("\n");
|
|
98
|
+
batches.push(client.graphql(`query CollectionImages(${parameters}) { ${fields} }`, CollectionImagesSchema, variables).catch(async (error) => {
|
|
99
|
+
const partial = CollectionImagesSchema.safeParse(error instanceof GraphQLResponseError ? error.data : null);
|
|
100
|
+
if (partial.success) return partial.data;
|
|
101
|
+
const result = {};
|
|
102
|
+
await Promise.all(batch.map(async (collection, index) => {
|
|
103
|
+
result[`c${index}`] = await client.getProducts({
|
|
104
|
+
collectionId: collection.id,
|
|
105
|
+
pageSize,
|
|
106
|
+
includeFilters: false
|
|
107
|
+
}).catch(() => null);
|
|
108
|
+
}));
|
|
109
|
+
return result;
|
|
110
|
+
}).then((result) => {
|
|
111
|
+
batch.forEach((collection, index) => {
|
|
112
|
+
candidates.set(collection.id, (result[`c${index}`]?.products ?? []).map((product) => product.imageUrl).filter((image) => image !== ""));
|
|
113
|
+
});
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
await Promise.all(batches);
|
|
117
|
+
return candidates;
|
|
118
|
+
}
|
|
119
|
+
async function withImages(client, collections) {
|
|
120
|
+
const candidates = await collectionImageCandidates({
|
|
121
|
+
client,
|
|
122
|
+
collections,
|
|
123
|
+
pageSize: 6
|
|
124
|
+
});
|
|
125
|
+
const used = /* @__PURE__ */ new Set();
|
|
126
|
+
return collections.map((collection) => {
|
|
127
|
+
const options = collection.imageUrl ? [collection.imageUrl] : candidates.get(collection.id) ?? [];
|
|
128
|
+
const image = options.find((option) => !used.has(option)) ?? options[0] ?? null;
|
|
129
|
+
if (image !== null) used.add(image);
|
|
130
|
+
return {
|
|
131
|
+
collection,
|
|
132
|
+
image
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async function readCountries(client) {
|
|
137
|
+
const { store } = await client.getSettings();
|
|
138
|
+
const names = new Intl.DisplayNames([store.language], { type: "region" });
|
|
139
|
+
return [{
|
|
140
|
+
code: store.countryCode,
|
|
141
|
+
name: names.of(store.countryCode) ?? store.countryCode
|
|
142
|
+
}];
|
|
143
|
+
}
|
|
144
|
+
async function readDocumentCountries(client) {
|
|
145
|
+
const [settings, countries] = await Promise.all([client.getSettings(), client.getCountries()]);
|
|
146
|
+
const names = new Intl.DisplayNames([settings.store.language], { type: "region" });
|
|
147
|
+
return countries.map((country) => ({
|
|
148
|
+
code: country.code,
|
|
149
|
+
name: names.of(country.code) ?? country.name
|
|
150
|
+
})).sort((a, b) => a.name.localeCompare(b.name, settings.store.language));
|
|
151
|
+
}
|
|
152
|
+
export { collectionImageCandidates, found, readCountries, readDocumentCountries, store, storeHeaders, withImages };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/store-contact.ts
|
|
2
|
+
function storefrontContact(settings) {
|
|
3
|
+
const business = settings.store.businessSettings;
|
|
4
|
+
const address = business.address;
|
|
5
|
+
return {
|
|
6
|
+
...settings.cms.settings.contact,
|
|
7
|
+
supportEmail: business.contactEmail,
|
|
8
|
+
phone: business.phone,
|
|
9
|
+
address: address === null ? null : [
|
|
10
|
+
address.address1,
|
|
11
|
+
address.address2,
|
|
12
|
+
address.district,
|
|
13
|
+
address.city,
|
|
14
|
+
address.province,
|
|
15
|
+
address.postalCode
|
|
16
|
+
].filter((part) => part !== null && part !== "").join(", ")
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export { storefrontContact };
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RouterContextProvider } from "react-router";
|
|
2
|
+
import { Collection, StorefrontClient } from "@ecomiq/core";
|
|
3
|
+
export declare function store(context: Readonly<RouterContextProvider>): StorefrontClient;
|
|
4
|
+
export declare function found<T>(read: Promise<T>, missing?: (status: number) => boolean): Promise<T>;
|
|
5
|
+
export declare function collectionImageCandidates({ client, collections, pageSize }: {
|
|
6
|
+
client: StorefrontClient;
|
|
7
|
+
collections: readonly Collection[];
|
|
8
|
+
pageSize: number;
|
|
9
|
+
}): Promise<ReadonlyMap<string, readonly string[]>>;
|
|
10
|
+
export declare function withImages(client: StorefrontClient, collections: Collection[]): Promise<{
|
|
11
|
+
collection: Collection;
|
|
12
|
+
image: string | null;
|
|
13
|
+
}[]>;
|
|
14
|
+
export declare function readCountries(client: StorefrontClient): Promise<{
|
|
15
|
+
code: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}[]>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { storefrontText } from "./storefront-text-D25ae1qf.js";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/storefront-language.tsx
|
|
5
|
+
const StorefrontLanguage = createContext({
|
|
6
|
+
language: "es",
|
|
7
|
+
locale: "es",
|
|
8
|
+
timeZone: "UTC",
|
|
9
|
+
translations: {}
|
|
10
|
+
});
|
|
11
|
+
function StorefrontLanguageProvider({ language, locale = language, timeZone = "UTC", translations = {}, children }) {
|
|
12
|
+
return /* @__PURE__ */ jsx(StorefrontLanguage, {
|
|
13
|
+
value: {
|
|
14
|
+
language,
|
|
15
|
+
locale,
|
|
16
|
+
timeZone,
|
|
17
|
+
translations
|
|
18
|
+
},
|
|
19
|
+
children
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function useStorefrontText() {
|
|
23
|
+
const { translations } = useContext(StorefrontLanguage);
|
|
24
|
+
return (source, values) => storefrontText(translations, source, values);
|
|
25
|
+
}
|
|
26
|
+
function useStorefrontLocale() {
|
|
27
|
+
return useContext(StorefrontLanguage);
|
|
28
|
+
}
|
|
29
|
+
export { StorefrontLanguageProvider, useStorefrontLocale, useStorefrontText };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StorefrontTextValues, StorefrontTranslations } from "./storefront-text.js";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
export declare function StorefrontLanguageProvider({ language, locale, timeZone, translations, children }: {
|
|
4
|
+
language: string;
|
|
5
|
+
locale?: string;
|
|
6
|
+
timeZone?: string;
|
|
7
|
+
translations?: StorefrontTranslations;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export declare function useStorefrontText(): (source: string, values?: StorefrontTextValues) => string;
|
|
11
|
+
export declare function useStorefrontLocale(): {
|
|
12
|
+
locale: string;
|
|
13
|
+
timeZone: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/storefront-text.ts
|
|
2
|
+
async function loadStorefrontTranslations(language) {
|
|
3
|
+
const code = language.split("-")[0];
|
|
4
|
+
if (code === "en") return (await import("./storefront-text-en-ljjjSS4q.js")).default;
|
|
5
|
+
if (code === "pt") return (await import("./storefront-text-pt-BtHaJLcp.js")).default;
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
function storefrontText(translations, source, values = {}) {
|
|
9
|
+
return (translations[source] ?? source).replace(/\{(\w+)\}/g, (token, key) => Object.hasOwn(values, key) ? String(values[key] ?? "") : token);
|
|
10
|
+
}
|
|
11
|
+
export { loadStorefrontTranslations, storefrontText };
|