@doswiftly/storefront-sdk 11.1.0 → 11.3.1
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/CHANGELOG.md +131 -0
- package/README.md +297 -2
- package/dist/core/auth/handlers.d.ts.map +1 -1
- package/dist/core/auth/handlers.js +29 -1
- package/dist/core/bot-protection/turnstile-manager.d.ts +0 -1
- package/dist/core/bot-protection/turnstile-manager.d.ts.map +1 -1
- package/dist/core/bot-protection/turnstile-manager.js +0 -1
- package/dist/core/cart/cart-recovery.d.ts +210 -0
- package/dist/core/cart/cart-recovery.d.ts.map +1 -0
- package/dist/core/cart/cart-recovery.js +271 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/react/components/AddToCartButton.d.ts +49 -0
- package/dist/react/components/AddToCartButton.d.ts.map +1 -0
- package/dist/react/components/AddToCartButton.js +47 -0
- package/dist/react/components/CartCount.d.ts +35 -0
- package/dist/react/components/CartCount.d.ts.map +1 -0
- package/dist/react/components/CartCount.js +23 -0
- package/dist/react/components/CartTotals.d.ts +54 -0
- package/dist/react/components/CartTotals.d.ts.map +1 -0
- package/dist/react/components/CartTotals.js +38 -0
- package/dist/react/components/Image.d.ts +42 -0
- package/dist/react/components/Image.d.ts.map +1 -0
- package/dist/react/components/Image.js +33 -0
- package/dist/react/components/Money.d.ts +32 -0
- package/dist/react/components/Money.d.ts.map +1 -0
- package/dist/react/components/Money.js +27 -0
- package/dist/react/components/PriceDisplay.d.ts +34 -0
- package/dist/react/components/PriceDisplay.d.ts.map +1 -0
- package/dist/react/components/PriceDisplay.js +21 -0
- package/dist/react/components/index.d.ts +15 -0
- package/dist/react/components/index.d.ts.map +1 -0
- package/dist/react/components/index.js +14 -0
- package/dist/react/cookies.d.ts +21 -0
- package/dist/react/cookies.d.ts.map +1 -1
- package/dist/react/cookies.js +29 -1
- package/dist/react/hooks/use-auth.d.ts +19 -46
- package/dist/react/hooks/use-auth.d.ts.map +1 -1
- package/dist/react/hooks/use-auth.js +24 -141
- package/dist/react/hooks/use-cart-manager.d.ts +75 -15
- package/dist/react/hooks/use-cart-manager.d.ts.map +1 -1
- package/dist/react/hooks/use-cart-manager.js +106 -194
- package/dist/react/hooks/use-login.d.ts +40 -0
- package/dist/react/hooks/use-login.d.ts.map +1 -0
- package/dist/react/hooks/use-login.js +75 -0
- package/dist/react/hooks/use-logout.d.ts +40 -0
- package/dist/react/hooks/use-logout.d.ts.map +1 -0
- package/dist/react/hooks/use-logout.js +50 -0
- package/dist/react/hooks/use-refresh-token.d.ts +40 -0
- package/dist/react/hooks/use-refresh-token.d.ts.map +1 -0
- package/dist/react/hooks/use-refresh-token.js +66 -0
- package/dist/react/index.d.ts +6 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +6 -1
- package/dist/react/server/get-storefront-client.d.ts +15 -5
- package/dist/react/server/get-storefront-client.d.ts.map +1 -1
- package/dist/react/stores/cart.store.d.ts +57 -10
- package/dist/react/stores/cart.store.d.ts.map +1 -1
- package/dist/react/stores/cart.store.js +112 -21
- package/dist/react/stores/store-context.d.ts.map +1 -1
- package/dist/react/stores/store-context.js +0 -2
- package/package.json +11 -4
- package/dist/__tests__/unit/test-helpers.d.ts +0 -46
- package/dist/__tests__/unit/test-helpers.d.ts.map +0 -1
- package/dist/__tests__/unit/test-helpers.js +0 -72
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartCount.d.ts","sourceRoot":"","sources":["../../../src/react/components/CartCount.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,WAAW,cAAc;IAC7B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACtC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,SAAS,EACT,SAAS,EACT,KAAK,EACL,aAAqB,GACtB,EAAE,cAAc,kDAYhB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<CartCount>` — render the cart item count with screen-reader-friendly
|
|
3
|
+
* semantics (`aria-live="polite"`).
|
|
4
|
+
*
|
|
5
|
+
* Receives `count` explicitly rather than reading from a store — the SDK's
|
|
6
|
+
* cart store tracks `cartId`, not line totals (which come from a GraphQL
|
|
7
|
+
* query in the consumer). This keeps the component reusable across data
|
|
8
|
+
* layers (React Query, SWR, Apollo, custom fetcher).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { data } = useCartQuery(cartId);
|
|
13
|
+
* <CartCount count={data?.totalQuantity ?? 0} />
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
'use client';
|
|
17
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
+
export function CartCount({ count, className, formatter, label, hideWhenEmpty = false, }) {
|
|
19
|
+
if (hideWhenEmpty && count === 0)
|
|
20
|
+
return null;
|
|
21
|
+
const text = formatter ? formatter(count) : String(count);
|
|
22
|
+
return (_jsxs("span", { className: className, "aria-live": "polite", "aria-atomic": "true", children: [_jsx("span", { "aria-hidden": "true", children: text }), _jsxs("span", { className: "sr-only", children: [text, label ? ` ${label}` : ''] })] }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<CartTotals>` — render a description list (`<dl>`) of cart financial
|
|
3
|
+
* breakdown rows: subtotal, optional discount / shipping / tax, total.
|
|
4
|
+
*
|
|
5
|
+
* Renders only the rows you pass. `subtotal`, `total`, and `currency` are
|
|
6
|
+
* required; everything else is optional and elided when undefined or zero
|
|
7
|
+
* (discount specifically — pass zero to hide rather than showing "-0,00").
|
|
8
|
+
*
|
|
9
|
+
* Labels are passed by the consumer (i18n is its responsibility). The
|
|
10
|
+
* component defaults to English labels so it works out of the box during
|
|
11
|
+
* prototyping.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <CartTotals
|
|
16
|
+
* subtotal={cart.cost.subtotal.amount * 100}
|
|
17
|
+
* shipping={cart.cost.shipping?.amount * 100}
|
|
18
|
+
* tax={cart.cost.tax?.amount * 100}
|
|
19
|
+
* total={cart.cost.total.amount * 100}
|
|
20
|
+
* currency={cart.cost.total.currencyCode}
|
|
21
|
+
* labels={{ subtotal: 'Suma częściowa', shipping: 'Dostawa', tax: 'Podatek', total: 'Razem' }}
|
|
22
|
+
* />
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import type { ReactNode } from 'react';
|
|
26
|
+
export interface CartTotalsLabels {
|
|
27
|
+
subtotal?: ReactNode;
|
|
28
|
+
discount?: ReactNode;
|
|
29
|
+
shipping?: ReactNode;
|
|
30
|
+
tax?: ReactNode;
|
|
31
|
+
total?: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
export interface CartTotalsProps {
|
|
34
|
+
/** Subtotal in minor units. */
|
|
35
|
+
subtotal: number;
|
|
36
|
+
/** Discount in minor units. Rendered as `−<amount>` when > 0. */
|
|
37
|
+
discount?: number;
|
|
38
|
+
/** Shipping in minor units. Rendered when provided (incl. 0 = free shipping). */
|
|
39
|
+
shipping?: number;
|
|
40
|
+
/** Tax in minor units. Rendered when provided. */
|
|
41
|
+
tax?: number;
|
|
42
|
+
/** Total in minor units. */
|
|
43
|
+
total: number;
|
|
44
|
+
/** ISO 4217 currency code shared by every line. */
|
|
45
|
+
currency: string;
|
|
46
|
+
/** Class applied to the wrapping `<dl>`. */
|
|
47
|
+
className?: string;
|
|
48
|
+
/** Class applied to each `<div>` row (subtotal, discount, etc.). */
|
|
49
|
+
rowClassName?: string;
|
|
50
|
+
/** Custom row labels. Defaults to English. */
|
|
51
|
+
labels?: CartTotalsLabels;
|
|
52
|
+
}
|
|
53
|
+
export declare function CartTotals({ subtotal, discount, shipping, tax, total, currency, className, rowClassName, labels, }: CartTotalsProps): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
//# sourceMappingURL=CartTotals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CartTotals.d.ts","sourceRoot":"","sources":["../../../src/react/components/CartTotals.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8CAA8C;IAC9C,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAUD,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,GAAG,EACH,KAAK,EACL,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,MAAM,GACP,EAAE,eAAe,2CAoCjB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<CartTotals>` — render a description list (`<dl>`) of cart financial
|
|
3
|
+
* breakdown rows: subtotal, optional discount / shipping / tax, total.
|
|
4
|
+
*
|
|
5
|
+
* Renders only the rows you pass. `subtotal`, `total`, and `currency` are
|
|
6
|
+
* required; everything else is optional and elided when undefined or zero
|
|
7
|
+
* (discount specifically — pass zero to hide rather than showing "-0,00").
|
|
8
|
+
*
|
|
9
|
+
* Labels are passed by the consumer (i18n is its responsibility). The
|
|
10
|
+
* component defaults to English labels so it works out of the box during
|
|
11
|
+
* prototyping.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <CartTotals
|
|
16
|
+
* subtotal={cart.cost.subtotal.amount * 100}
|
|
17
|
+
* shipping={cart.cost.shipping?.amount * 100}
|
|
18
|
+
* tax={cart.cost.tax?.amount * 100}
|
|
19
|
+
* total={cart.cost.total.amount * 100}
|
|
20
|
+
* currency={cart.cost.total.currencyCode}
|
|
21
|
+
* labels={{ subtotal: 'Suma częściowa', shipping: 'Dostawa', tax: 'Podatek', total: 'Razem' }}
|
|
22
|
+
* />
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
'use client';
|
|
26
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
27
|
+
import { Money } from './Money';
|
|
28
|
+
const DEFAULT_LABELS = {
|
|
29
|
+
subtotal: 'Subtotal',
|
|
30
|
+
discount: 'Discount',
|
|
31
|
+
shipping: 'Shipping',
|
|
32
|
+
tax: 'Tax',
|
|
33
|
+
total: 'Total',
|
|
34
|
+
};
|
|
35
|
+
export function CartTotals({ subtotal, discount, shipping, tax, total, currency, className, rowClassName, labels, }) {
|
|
36
|
+
const L = { ...DEFAULT_LABELS, ...labels };
|
|
37
|
+
return (_jsxs("dl", { className: className, children: [_jsxs("div", { className: rowClassName, children: [_jsx("dt", { children: L.subtotal }), _jsx("dd", { children: _jsx(Money, { amount: subtotal, currency: currency }) })] }), discount !== undefined && discount > 0 && (_jsxs("div", { className: rowClassName, children: [_jsx("dt", { children: L.discount }), _jsxs("dd", { children: [_jsx("span", { "aria-hidden": "true", children: "\u2212" }), _jsx(Money, { amount: discount, currency: currency })] })] })), shipping !== undefined && (_jsxs("div", { className: rowClassName, children: [_jsx("dt", { children: L.shipping }), _jsx("dd", { children: _jsx(Money, { amount: shipping, currency: currency }) })] })), tax !== undefined && (_jsxs("div", { className: rowClassName, children: [_jsx("dt", { children: L.tax }), _jsx("dd", { children: _jsx(Money, { amount: tax, currency: currency }) })] })), _jsxs("div", { className: rowClassName, children: [_jsx("dt", { children: L.total }), _jsx("dd", { children: _jsx(Money, { amount: total, currency: currency }) })] })] }));
|
|
38
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<Image>` — render a GraphQL `Image` payload as an `<img>` with thumbhash
|
|
3
|
+
* blur placeholder (via `thumbHashToDataURL` from core).
|
|
4
|
+
*
|
|
5
|
+
* Headless and framework-agnostic — does NOT depend on `next/image`. If you
|
|
6
|
+
* want Next.js `<Image>` optimisations, pass `data.url` to it directly; this
|
|
7
|
+
* component is for runtimes outside Next or when you don't need `next/image`'s
|
|
8
|
+
* trade-offs (CLS guard, prefetch).
|
|
9
|
+
*
|
|
10
|
+
* Lazy by default. Pass `priority` for above-the-fold images to switch to
|
|
11
|
+
* `loading="eager"` + `fetchPriority="high"`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <Image data={product.featuredImage} sizes="(max-width: 768px) 100vw, 800px" />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
import type { CSSProperties } from 'react';
|
|
19
|
+
import { type ImageData } from '../../core/image';
|
|
20
|
+
export interface ImageComponentProps {
|
|
21
|
+
/** Image payload from a GraphQL query (`url`, `altText`, `width`, `height`, `thumbhash`). */
|
|
22
|
+
data: ImageData;
|
|
23
|
+
/** Responsive `sizes` attribute. Defaults to `100vw`. */
|
|
24
|
+
sizes?: string;
|
|
25
|
+
/** Class name for styling — keeps the component headless. */
|
|
26
|
+
className?: string;
|
|
27
|
+
/** Inline style override. Merged with the blur placeholder background. */
|
|
28
|
+
style?: CSSProperties;
|
|
29
|
+
/**
|
|
30
|
+
* Above-the-fold flag. When true: `loading="eager"` + `fetchPriority="high"`.
|
|
31
|
+
* When false (default): `loading="lazy"` + `fetchPriority="auto"`.
|
|
32
|
+
*/
|
|
33
|
+
priority?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Alt text override. Defaults to `data.altText`. Pass an empty string
|
|
36
|
+
* (`alt=""`) when the image is purely decorative — explicit empty alt is the
|
|
37
|
+
* correct accessibility signal.
|
|
38
|
+
*/
|
|
39
|
+
alt?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function Image({ data, sizes, className, style, priority, alt }: ImageComponentProps): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
//# sourceMappingURL=Image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/react/components/Image.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEtE,MAAM,WAAW,mBAAmB;IAClC,6FAA6F;IAC7F,IAAI,EAAE,SAAS,CAAC;IAChB,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,mBAAmB,2CA6B1F"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<Image>` — render a GraphQL `Image` payload as an `<img>` with thumbhash
|
|
3
|
+
* blur placeholder (via `thumbHashToDataURL` from core).
|
|
4
|
+
*
|
|
5
|
+
* Headless and framework-agnostic — does NOT depend on `next/image`. If you
|
|
6
|
+
* want Next.js `<Image>` optimisations, pass `data.url` to it directly; this
|
|
7
|
+
* component is for runtimes outside Next or when you don't need `next/image`'s
|
|
8
|
+
* trade-offs (CLS guard, prefetch).
|
|
9
|
+
*
|
|
10
|
+
* Lazy by default. Pass `priority` for above-the-fold images to switch to
|
|
11
|
+
* `loading="eager"` + `fetchPriority="high"`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* <Image data={product.featuredImage} sizes="(max-width: 768px) 100vw, 800px" />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
'use client';
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
import { thumbHashToDataURL } from '../../core/image';
|
|
21
|
+
export function Image({ data, sizes, className, style, priority, alt }) {
|
|
22
|
+
const blurUrl = data.thumbhash ? thumbHashToDataURL(data.thumbhash) : undefined;
|
|
23
|
+
const effectiveAlt = alt ?? data.altText ?? '';
|
|
24
|
+
const composedStyle = blurUrl
|
|
25
|
+
? {
|
|
26
|
+
backgroundImage: `url(${blurUrl})`,
|
|
27
|
+
backgroundSize: 'cover',
|
|
28
|
+
backgroundPosition: 'center',
|
|
29
|
+
...style,
|
|
30
|
+
}
|
|
31
|
+
: style;
|
|
32
|
+
return (_jsx("img", { src: data.url, alt: effectiveAlt, width: data.width ?? undefined, height: data.height ?? undefined, sizes: sizes ?? '100vw', loading: priority ? 'eager' : 'lazy', decoding: "async", ...{ fetchpriority: priority ? 'high' : 'auto' }, style: composedStyle, className: className }));
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<Money>` — render a price in minor units (grosze / cents) as a locale-aware
|
|
3
|
+
* formatted string. Wraps `formatPrice` from core so consumers don't need to
|
|
4
|
+
* import the formatter manually.
|
|
5
|
+
*
|
|
6
|
+
* Headless: no styling, no currency context dependency. `currency` is required
|
|
7
|
+
* — render explicitly from your cart/product/shop data. This keeps the
|
|
8
|
+
* component usable both inside `StorefrontProvider` and in isolated rendering
|
|
9
|
+
* (server components, e-mail templates, PDFs).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <Money amount={9990} currency="PLN" /> // → "99,90 zł"
|
|
14
|
+
* <Money amount={1295} currency="USD" /> // → "$12.95"
|
|
15
|
+
* <Money amount={0} currency="EUR" /> // → "0,00 €"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface MoneyProps {
|
|
19
|
+
/** Amount in minor units (grosze, cents). 9990 = 99.90 PLN. */
|
|
20
|
+
amount: number;
|
|
21
|
+
/** ISO 4217 currency code (PLN, EUR, USD, …). Required — no implicit default. */
|
|
22
|
+
currency: string;
|
|
23
|
+
/** Optional class for styling — keeps the component headless. */
|
|
24
|
+
className?: string;
|
|
25
|
+
/**
|
|
26
|
+
* HTML element to render. Defaults to `<span>` so the price flows inline.
|
|
27
|
+
* Pass `'div'` (or `'p'`) when the price is a block-level item.
|
|
28
|
+
*/
|
|
29
|
+
as?: 'span' | 'div' | 'p' | 'strong' | 'em' | 'output';
|
|
30
|
+
}
|
|
31
|
+
export declare function Money({ amount, currency, className, as: As }: MoneyProps): import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
//# sourceMappingURL=Money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Money.d.ts","sourceRoot":"","sources":["../../../src/react/components/Money.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,MAAM,WAAW,UAAU;IACzB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,QAAQ,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,GAAG,GAAG,QAAQ,GAAG,IAAI,GAAG,QAAQ,CAAC;CACxD;AAED,wBAAgB,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,EAAW,EAAE,EAAE,UAAU,2CAMjF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<Money>` — render a price in minor units (grosze / cents) as a locale-aware
|
|
3
|
+
* formatted string. Wraps `formatPrice` from core so consumers don't need to
|
|
4
|
+
* import the formatter manually.
|
|
5
|
+
*
|
|
6
|
+
* Headless: no styling, no currency context dependency. `currency` is required
|
|
7
|
+
* — render explicitly from your cart/product/shop data. This keeps the
|
|
8
|
+
* component usable both inside `StorefrontProvider` and in isolated rendering
|
|
9
|
+
* (server components, e-mail templates, PDFs).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <Money amount={9990} currency="PLN" /> // → "99,90 zł"
|
|
14
|
+
* <Money amount={1295} currency="USD" /> // → "$12.95"
|
|
15
|
+
* <Money amount={0} currency="EUR" /> // → "0,00 €"
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
'use client';
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
import { formatPrice } from '../../core/format';
|
|
21
|
+
export function Money({ amount, currency, className, as: As = 'span' }) {
|
|
22
|
+
const formatted = formatPrice({
|
|
23
|
+
amount: (amount / 100).toString(),
|
|
24
|
+
currencyCode: currency,
|
|
25
|
+
});
|
|
26
|
+
return _jsx(As, { className: className, children: formatted });
|
|
27
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<PriceDisplay>` — render a single price or a sale-price layout (current
|
|
3
|
+
* price + strikethrough compare-at). Composes `<Money>` so locale + currency
|
|
4
|
+
* formatting stays consistent with the rest of the SDK.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* <PriceDisplay price={9990} currency="PLN" />
|
|
9
|
+
* // → "99,90 zł"
|
|
10
|
+
*
|
|
11
|
+
* <PriceDisplay price={7990} compareAtPrice={9990} currency="PLN" />
|
|
12
|
+
* // → "79,90 zł <s>99,90 zł</s>"
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface PriceDisplayProps {
|
|
16
|
+
/** Current price in minor units. */
|
|
17
|
+
price: number;
|
|
18
|
+
/**
|
|
19
|
+
* Original price in minor units before the discount. When provided AND
|
|
20
|
+
* strictly greater than `price`, renders as strikethrough next to the
|
|
21
|
+
* current price. Otherwise ignored.
|
|
22
|
+
*/
|
|
23
|
+
compareAtPrice?: number;
|
|
24
|
+
/** ISO 4217 currency code. */
|
|
25
|
+
currency: string;
|
|
26
|
+
/** Wrapping element class. */
|
|
27
|
+
className?: string;
|
|
28
|
+
/** Class for the *current* price portion. */
|
|
29
|
+
priceClassName?: string;
|
|
30
|
+
/** Class for the strikethrough compare-at portion. */
|
|
31
|
+
compareAtClassName?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function PriceDisplay({ price, compareAtPrice, currency, className, priceClassName, compareAtClassName, }: PriceDisplayProps): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
//# sourceMappingURL=PriceDisplay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PriceDisplay.d.ts","sourceRoot":"","sources":["../../../src/react/components/PriceDisplay.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,MAAM,WAAW,iBAAiB;IAChC,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,cAAc,EACd,QAAQ,EACR,SAAS,EACT,cAAc,EACd,kBAAkB,GACnB,EAAE,iBAAiB,2CAgBnB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<PriceDisplay>` — render a single price or a sale-price layout (current
|
|
3
|
+
* price + strikethrough compare-at). Composes `<Money>` so locale + currency
|
|
4
|
+
* formatting stays consistent with the rest of the SDK.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* <PriceDisplay price={9990} currency="PLN" />
|
|
9
|
+
* // → "99,90 zł"
|
|
10
|
+
*
|
|
11
|
+
* <PriceDisplay price={7990} compareAtPrice={9990} currency="PLN" />
|
|
12
|
+
* // → "79,90 zł <s>99,90 zł</s>"
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
'use client';
|
|
16
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
import { Money } from './Money';
|
|
18
|
+
export function PriceDisplay({ price, compareAtPrice, currency, className, priceClassName, compareAtClassName, }) {
|
|
19
|
+
const isOnSale = compareAtPrice !== undefined && compareAtPrice > price;
|
|
20
|
+
return (_jsxs("span", { className: className, children: [_jsx(Money, { amount: price, currency: currency, className: priceClassName }), isOnSale && (_jsxs(_Fragment, { children: [' ', _jsx("s", { className: compareAtClassName, children: _jsx(Money, { amount: compareAtPrice, currency: currency }) })] }))] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-built React components — headless, accessibility-aware, framework-agnostic.
|
|
3
|
+
*
|
|
4
|
+
* Every component is intentionally unstyled. Pass `className` (or `style`) to
|
|
5
|
+
* integrate with your CSS approach (Tailwind, CSS Modules, styled-components,
|
|
6
|
+
* vanilla CSS). Components compose `formatPrice` + `thumbHashToDataURL` from
|
|
7
|
+
* core and `useCartManager` from the hook layer.
|
|
8
|
+
*/
|
|
9
|
+
export { Money, type MoneyProps } from './Money';
|
|
10
|
+
export { Image, type ImageComponentProps } from './Image';
|
|
11
|
+
export { CartCount, type CartCountProps } from './CartCount';
|
|
12
|
+
export { AddToCartButton, type AddToCartButtonProps } from './AddToCartButton';
|
|
13
|
+
export { PriceDisplay, type PriceDisplayProps } from './PriceDisplay';
|
|
14
|
+
export { CartTotals, type CartTotalsProps, type CartTotalsLabels } from './CartTotals';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/components/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-built React components — headless, accessibility-aware, framework-agnostic.
|
|
3
|
+
*
|
|
4
|
+
* Every component is intentionally unstyled. Pass `className` (or `style`) to
|
|
5
|
+
* integrate with your CSS approach (Tailwind, CSS Modules, styled-components,
|
|
6
|
+
* vanilla CSS). Components compose `formatPrice` + `thumbHashToDataURL` from
|
|
7
|
+
* core and `useCartManager` from the hook layer.
|
|
8
|
+
*/
|
|
9
|
+
export { Money } from './Money';
|
|
10
|
+
export { Image } from './Image';
|
|
11
|
+
export { CartCount } from './CartCount';
|
|
12
|
+
export { AddToCartButton } from './AddToCartButton';
|
|
13
|
+
export { PriceDisplay } from './PriceDisplay';
|
|
14
|
+
export { CartTotals } from './CartTotals';
|
package/dist/react/cookies.d.ts
CHANGED
|
@@ -23,6 +23,27 @@ export declare function setCookie(name: string, value: string, options?: {
|
|
|
23
23
|
* Delete cookie (client-side only).
|
|
24
24
|
*/
|
|
25
25
|
export declare function deleteCookie(name: string, path?: string): void;
|
|
26
|
+
import type { CartCookieStore } from '../core/cart/cart-recovery';
|
|
27
|
+
/**
|
|
28
|
+
* Build a browser-side `CartCookieStore` backed by `document.cookie`.
|
|
29
|
+
*
|
|
30
|
+
* SSR-safe: when `document` is unavailable (Node / Edge SSR) `get` returns null
|
|
31
|
+
* and `set`/`clear` are no-ops — the runner falls back to creating a cart on
|
|
32
|
+
* first client-side interaction.
|
|
33
|
+
*
|
|
34
|
+
* Defaults: `maxAge = CART_COOKIE_MAX_AGE` (30 days), `samesite=lax`, `path=/`,
|
|
35
|
+
* `secure` auto-detected from `location.protocol`. Pass per-call `maxAge` via
|
|
36
|
+
* `set(cartId, { maxAge })` if needed.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* const runner = createCartRecoveryRunner({
|
|
41
|
+
* cartClient,
|
|
42
|
+
* cookieStore: createBrowserCartCookieStore(),
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function createBrowserCartCookieStore(): CartCookieStore;
|
|
26
47
|
/**
|
|
27
48
|
* Get preferred currency from cookie (async — works with Next.js cookies()).
|
|
28
49
|
* Falls back to document.cookie on client.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/react/cookies.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIrD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACpF,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,IAAI,CAG3D;
|
|
1
|
+
{"version":3,"file":"cookies.d.ts","sourceRoot":"","sources":["../../src/react/cookies.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIrD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACpF,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,IAAI,CAG3D;AAID,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,4BAA4B,IAAI,eAAe,CAQ9D;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYzE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYvE"}
|
package/dist/react/cookies.js
CHANGED
|
@@ -36,7 +36,35 @@ export function deleteCookie(name, path = '/') {
|
|
|
36
36
|
document.cookie = `${name}=;max-age=0;path=${path}`;
|
|
37
37
|
}
|
|
38
38
|
import { CURRENCY_COOKIE_NAME } from '../core/currency/cookie-config';
|
|
39
|
-
import { CART_COOKIE_NAME } from '../core/cart/cookie-config';
|
|
39
|
+
import { CART_COOKIE_NAME, CART_COOKIE_MAX_AGE } from '../core/cart/cookie-config';
|
|
40
|
+
/**
|
|
41
|
+
* Build a browser-side `CartCookieStore` backed by `document.cookie`.
|
|
42
|
+
*
|
|
43
|
+
* SSR-safe: when `document` is unavailable (Node / Edge SSR) `get` returns null
|
|
44
|
+
* and `set`/`clear` are no-ops — the runner falls back to creating a cart on
|
|
45
|
+
* first client-side interaction.
|
|
46
|
+
*
|
|
47
|
+
* Defaults: `maxAge = CART_COOKIE_MAX_AGE` (30 days), `samesite=lax`, `path=/`,
|
|
48
|
+
* `secure` auto-detected from `location.protocol`. Pass per-call `maxAge` via
|
|
49
|
+
* `set(cartId, { maxAge })` if needed.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* const runner = createCartRecoveryRunner({
|
|
54
|
+
* cartClient,
|
|
55
|
+
* cookieStore: createBrowserCartCookieStore(),
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function createBrowserCartCookieStore() {
|
|
60
|
+
return {
|
|
61
|
+
get: () => getCookie(CART_COOKIE_NAME),
|
|
62
|
+
set: (cartId, options) => {
|
|
63
|
+
setCookie(CART_COOKIE_NAME, cartId, { maxAge: options?.maxAge ?? CART_COOKIE_MAX_AGE });
|
|
64
|
+
},
|
|
65
|
+
clear: () => deleteCookie(CART_COOKIE_NAME),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
40
68
|
/**
|
|
41
69
|
* Get preferred currency from cookie (async — works with Next.js cookies()).
|
|
42
70
|
* Falls back to document.cookie on client.
|
|
@@ -1,56 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useAuth —
|
|
2
|
+
* useAuth — convenience facade composing `useLogin`, `useLogout`, and
|
|
3
|
+
* `useRefreshToken`. Preserves the pre-11.2 API for backward compatibility.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* - Zustand store (for client-side state)
|
|
5
|
+
* **Prefer the focused hooks** in new code — they tree-shake better, isolate
|
|
6
|
+
* state, and keep dependency arrays smaller:
|
|
7
7
|
*
|
|
8
|
-
* Does NOT use React Query — plain async + store updates.
|
|
9
|
-
* Template can wrap in useMutation() if React Query features are needed.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
8
|
* ```tsx
|
|
13
|
-
*
|
|
9
|
+
* // Smaller bundle, single-responsibility:
|
|
10
|
+
* const { login, isLoggingIn } = useLogin({ onSetToken });
|
|
11
|
+
* const { logout } = useLogout({ onClearToken });
|
|
14
12
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* // Convenience aggregator (legacy / mixed flows):
|
|
14
|
+
* const { login, logout, refreshToken, isLoading } = useAuth({ onSetToken, onClearToken });
|
|
17
15
|
* ```
|
|
16
|
+
*
|
|
17
|
+
* Centralizes dual-layer persistence:
|
|
18
|
+
* - httpOnly cookie (for SSR/middleware) — via `onSetToken`/`onClearToken`
|
|
19
|
+
* callbacks that hit your BFF route handlers
|
|
20
|
+
* - Zustand auth store (for client-side state).
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
onSetToken?: (token: string) => Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Called after logout to clear httpOnly cookie.
|
|
27
|
-
*/
|
|
28
|
-
onClearToken?: () => Promise<void>;
|
|
29
|
-
}
|
|
30
|
-
export interface LoginResult {
|
|
31
|
-
success: boolean;
|
|
32
|
-
userErrors: Array<{
|
|
33
|
-
message: string;
|
|
34
|
-
field?: string[];
|
|
35
|
-
}>;
|
|
36
|
-
accessToken?: string;
|
|
37
|
-
expiresAt?: string;
|
|
38
|
-
}
|
|
39
|
-
export interface LogoutResult {
|
|
40
|
-
success: boolean;
|
|
41
|
-
userErrors: Array<{
|
|
42
|
-
message: string;
|
|
43
|
-
field?: string[];
|
|
44
|
-
}>;
|
|
45
|
-
}
|
|
46
|
-
export interface TokenRefreshResult {
|
|
47
|
-
success: boolean;
|
|
48
|
-
userErrors: Array<{
|
|
49
|
-
message: string;
|
|
50
|
-
field?: string[];
|
|
51
|
-
}>;
|
|
52
|
-
accessToken?: string;
|
|
53
|
-
expiresAt?: string;
|
|
22
|
+
import { type UseLoginOptions, type LoginResult } from './use-login';
|
|
23
|
+
import { type UseLogoutOptions, type LogoutResult } from './use-logout';
|
|
24
|
+
import { type UseRefreshTokenOptions, type TokenRefreshResult } from './use-refresh-token';
|
|
25
|
+
export type { LoginResult, LogoutResult, TokenRefreshResult };
|
|
26
|
+
export interface UseAuthOptions extends UseLoginOptions, UseLogoutOptions, UseRefreshTokenOptions {
|
|
54
27
|
}
|
|
55
28
|
export declare function useAuth(options?: UseAuthOptions): {
|
|
56
29
|
login: (email: string, password: string) => Promise<LoginResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-auth.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-auth.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"use-auth.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EAAY,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAa,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAmB,KAAK,sBAAsB,EAAE,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE5G,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAE9D,MAAM,WAAW,cAAe,SAAQ,eAAe,EAAE,gBAAgB,EAAE,sBAAsB;CAAG;AAEpG,wBAAgB,OAAO,CAAC,OAAO,GAAE,cAAmB;;;;;;;;;EAoBnD"}
|