@wikala/spmkt 4.0.0-alpha.1 → 4.0.0-alpha.3
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/dist/core/api/address.d.ts +6 -1
- package/dist/core/api/address.js +6 -1
- package/dist/core/api/address.js.map +1 -1
- package/dist/core/api/cart.d.ts +2 -21
- package/dist/core/api/cart.js +4 -30
- package/dist/core/api/cart.js.map +1 -1
- package/dist/core/api/checkout.d.ts +2 -9
- package/dist/core/api/checkout.js +3 -10
- package/dist/core/api/checkout.js.map +1 -1
- package/dist/core/api/index.d.ts +4 -4
- package/dist/core/api/product.d.ts +2 -10
- package/dist/core/api/product.js +0 -12
- package/dist/core/api/product.js.map +1 -1
- package/dist/core/events.d.ts +4 -3
- package/dist/core/events.js.map +1 -1
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +17 -13
- package/dist/core/money.d.ts +2 -0
- package/dist/core/money.js +5 -0
- package/dist/core/money.js.map +1 -1
- package/dist/core/page-events.d.ts +17 -0
- package/dist/core/page-events.js +37 -3
- package/dist/core/page-events.js.map +1 -1
- package/dist/core/state.d.ts +8 -1
- package/dist/core/state.js +75 -3
- package/dist/core/state.js.map +1 -1
- package/dist/core/stores/cart.d.ts +19 -20
- package/dist/core/stores/cart.js +38 -46
- package/dist/core/stores/cart.js.map +1 -1
- package/dist/core/stores/checkout.d.ts +10 -12
- package/dist/core/stores/checkout.js +19 -24
- package/dist/core/stores/checkout.js.map +1 -1
- package/dist/core/stores/index.d.ts +2 -2
- package/dist/core/types.d.ts +29 -7
- package/dist/elements/add-to-cart/add-to-cart.d.ts +23 -8
- package/dist/elements/add-to-cart/add-to-cart.js +62 -28
- package/dist/elements/add-to-cart/add-to-cart.js.map +1 -1
- package/dist/elements/add-to-cart/index.d.ts +1 -1
- package/dist/elements/address-book/address-book.d.ts +20 -15
- package/dist/elements/address-book/address-book.js +98 -34
- package/dist/elements/address-book/address-book.js.map +1 -1
- package/dist/elements/carousel/carousel.d.ts +11 -1
- package/dist/elements/carousel/carousel.js +22 -5
- package/dist/elements/carousel/carousel.js.map +1 -1
- package/dist/elements/cart/cart.d.ts +27 -27
- package/dist/elements/cart/cart.js +195 -80
- package/dist/elements/cart/cart.js.map +1 -1
- package/dist/elements/checkout/checkout.d.ts +13 -20
- package/dist/elements/checkout/checkout.js +73 -40
- package/dist/elements/checkout/checkout.js.map +1 -1
- package/dist/elements/checkout-delivery/checkout-delivery.d.ts +2 -9
- package/dist/elements/checkout-delivery/checkout-delivery.js +1 -8
- package/dist/elements/checkout-delivery/checkout-delivery.js.map +1 -1
- package/dist/elements/checkout-payment/checkout-payment.d.ts +2 -9
- package/dist/elements/checkout-payment/checkout-payment.js +2 -9
- package/dist/elements/checkout-payment/checkout-payment.js.map +1 -1
- package/dist/elements/collection/collection.d.ts +5 -9
- package/dist/elements/collection/collection.js +20 -20
- package/dist/elements/collection/collection.js.map +1 -1
- package/dist/elements/dialog/dialog.d.ts +7 -3
- package/dist/elements/dialog/dialog.js +12 -4
- package/dist/elements/dialog/dialog.js.map +1 -1
- package/dist/elements/mini-cart/mini-cart.d.ts +15 -15
- package/dist/elements/mini-cart/mini-cart.js +74 -62
- package/dist/elements/mini-cart/mini-cart.js.map +1 -1
- package/dist/elements/order-confirmation/index.d.ts +3 -0
- package/dist/elements/order-confirmation/index.js +7 -0
- package/dist/elements/order-confirmation/index.js.map +1 -0
- package/dist/elements/order-confirmation/order-confirmation.d.ts +35 -0
- package/dist/elements/order-confirmation/order-confirmation.js +123 -0
- package/dist/elements/order-confirmation/order-confirmation.js.map +1 -0
- package/dist/elements/quick-view/quick-view.d.ts +10 -7
- package/dist/elements/quick-view/quick-view.js +11 -5
- package/dist/elements/quick-view/quick-view.js.map +1 -1
- package/dist/elements/related/related.d.ts +8 -13
- package/dist/elements/related/related.js +20 -17
- package/dist/elements/related/related.js.map +1 -1
- package/dist/elements/shared/paged-section.js +1 -1
- package/dist/elements/shared/paged-section.js.map +1 -1
- package/dist/elements/shared/totals.d.ts +53 -0
- package/dist/elements/shared/totals.js +82 -0
- package/dist/elements/shared/totals.js.map +1 -0
- package/dist/elements/variant-picker/variant-picker.d.ts +5 -3
- package/dist/elements/variant-picker/variant-picker.js +6 -4
- package/dist/elements/variant-picker/variant-picker.js.map +1 -1
- package/dist/lit/fragments.d.ts +11 -10
- package/dist/lit/fragments.js +9 -10
- package/dist/lit/fragments.js.map +1 -1
- package/dist/locales/en.json +48 -3
- package/dist/locales/sr.json +49 -3
- package/package.json +1 -1
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type { CheckoutAddress } from '../types';
|
|
1
|
+
import type { CheckoutAddress, SavedAddress } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* GET /api/addresses: the signed-in customer's address book, default first, each with its country (the
|
|
4
|
+
* storefront session authenticates, as for the changes below).
|
|
5
|
+
*/
|
|
6
|
+
export declare function fetchAddresses(signal?: AbortSignal): Promise<SavedAddress[]>;
|
|
2
7
|
/**
|
|
3
8
|
* POST /api/addresses: saves an address to the signed-in customer's address book (the session cookie
|
|
4
9
|
* authenticates; 422 per field). Returns it with its id.
|
package/dist/core/api/address.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { del, post } from "../request.js";
|
|
1
|
+
import { del, get, post } from "../request.js";
|
|
2
|
+
async function fetchAddresses(signal) {
|
|
3
|
+
const response = await get("/api/addresses", { signal });
|
|
4
|
+
return Array.isArray(response?.data) ? response.data : [];
|
|
5
|
+
}
|
|
2
6
|
async function saveAddress(address, signal) {
|
|
3
7
|
const response = await post("/api/addresses", address, { signal });
|
|
4
8
|
return response.data;
|
|
@@ -12,6 +16,7 @@ async function setDefaultAddress(id, signal) {
|
|
|
12
16
|
}
|
|
13
17
|
export {
|
|
14
18
|
deleteAddress,
|
|
19
|
+
fetchAddresses,
|
|
15
20
|
saveAddress,
|
|
16
21
|
setDefaultAddress
|
|
17
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sources":["../../../src/core/api/address.ts"],"sourcesContent":["import { del, post } from '../request'\nimport type { CheckoutAddress } from '../types'\n\n/**\n * POST /api/addresses: saves an address to the signed-in customer's address book (the session cookie\n * authenticates; 422 per field). Returns it with its id.\n */\nexport async function saveAddress(address: CheckoutAddress, signal?: AbortSignal): Promise<CheckoutAddress> {\n const response = await post<{ data: CheckoutAddress }>('/api/addresses', address, { signal })\n return response.data\n}\n\n/** DELETE /api/addresses/{id}: removes an address from the signed-in customer's address book. */\nexport async function deleteAddress(id: number, signal?: AbortSignal): Promise<void> {\n await del(`/api/addresses/${id}`, { signal })\n}\n\n/** POST /api/addresses/{id}/default: makes it the customer's default address (the others stop being it). */\nexport async function setDefaultAddress(id: number, signal?: AbortSignal): Promise<CheckoutAddress> {\n const response = await post<{ data: CheckoutAddress }>(`/api/addresses/${id}/default`, {}, { signal })\n return response.data\n}\n"],"names":[],"mappings":";AAOA,eAAsB,YAAY,SAA0B,QAAgD;AAC1G,QAAM,WAAW,MAAM,KAAgC,kBAAkB,SAAS,EAAE,QAAQ;AAC5F,SAAO,SAAS;AAClB;AAGA,eAAsB,cAAc,IAAY,QAAqC;AACnF,QAAM,IAAI,kBAAkB,EAAE,IAAI,EAAE,QAAQ;AAC9C;AAGA,eAAsB,kBAAkB,IAAY,QAAgD;AAClG,QAAM,WAAW,MAAM,KAAgC,kBAAkB,EAAE,YAAY,CAAA,GAAI,EAAE,QAAQ;AACrG,SAAO,SAAS;AAClB;"}
|
|
1
|
+
{"version":3,"file":"address.js","sources":["../../../src/core/api/address.ts"],"sourcesContent":["import { del, get, post } from '../request'\nimport type { CheckoutAddress, SavedAddress } from '../types'\n\n/**\n * GET /api/addresses: the signed-in customer's address book, default first, each with its country (the\n * storefront session authenticates, as for the changes below).\n */\nexport async function fetchAddresses(signal?: AbortSignal): Promise<SavedAddress[]> {\n const response = await get<{ data?: SavedAddress[] }>('/api/addresses', { signal })\n return Array.isArray(response?.data) ? response.data : []\n}\n\n/**\n * POST /api/addresses: saves an address to the signed-in customer's address book (the session cookie\n * authenticates; 422 per field). Returns it with its id.\n */\nexport async function saveAddress(address: CheckoutAddress, signal?: AbortSignal): Promise<CheckoutAddress> {\n const response = await post<{ data: CheckoutAddress }>('/api/addresses', address, { signal })\n return response.data\n}\n\n/** DELETE /api/addresses/{id}: removes an address from the signed-in customer's address book. */\nexport async function deleteAddress(id: number, signal?: AbortSignal): Promise<void> {\n await del(`/api/addresses/${id}`, { signal })\n}\n\n/** POST /api/addresses/{id}/default: makes it the customer's default address (the others stop being it). */\nexport async function setDefaultAddress(id: number, signal?: AbortSignal): Promise<CheckoutAddress> {\n const response = await post<{ data: CheckoutAddress }>(`/api/addresses/${id}/default`, {}, { signal })\n return response.data\n}\n"],"names":[],"mappings":";AAOA,eAAsB,eAAe,QAA+C;AAClF,QAAM,WAAW,MAAM,IAA+B,kBAAkB,EAAE,QAAQ;AAClF,SAAO,MAAM,QAAQ,UAAU,IAAI,IAAI,SAAS,OAAO,CAAA;AACzD;AAMA,eAAsB,YAAY,SAA0B,QAAgD;AAC1G,QAAM,WAAW,MAAM,KAAgC,kBAAkB,SAAS,EAAE,QAAQ;AAC5F,SAAO,SAAS;AAClB;AAGA,eAAsB,cAAc,IAAY,QAAqC;AACnF,QAAM,IAAI,kBAAkB,EAAE,IAAI,EAAE,QAAQ;AAC9C;AAGA,eAAsB,kBAAkB,IAAY,QAAgD;AAClG,QAAM,WAAW,MAAM,KAAgC,kBAAkB,EAAE,YAAY,CAAA,GAAI,EAAE,QAAQ;AACrG,SAAO,SAAS;AAClB;"}
|
package/dist/core/api/cart.d.ts
CHANGED
|
@@ -4,17 +4,6 @@ export interface AddToCartInput {
|
|
|
4
4
|
id: number;
|
|
5
5
|
qty: number;
|
|
6
6
|
}
|
|
7
|
-
/** Theme fragments (views/fragments/<name>) the server renders after the change, by name. */
|
|
8
|
-
export type Fragments = Record<string, string>;
|
|
9
|
-
/** A cart endpoint's answer when fragments were asked for: the cart plus the rendered fragments. */
|
|
10
|
-
export interface CartWithFragments {
|
|
11
|
-
cart: Cart;
|
|
12
|
-
fragments: Fragments;
|
|
13
|
-
}
|
|
14
|
-
/** ?fragments=a,b on a URL, when there are any. */
|
|
15
|
-
declare function fragmentQuery(fragments?: readonly string[]): {
|
|
16
|
-
fragments: string;
|
|
17
|
-
} | undefined;
|
|
18
7
|
/**
|
|
19
8
|
* POST /cart in "add" mode: adds qty to the line. A sold-out product or an expired location answers
|
|
20
9
|
* 400 { message } (HttpError); bad input answers 422 (ValidationError).
|
|
@@ -27,17 +16,9 @@ export declare function fetchCart(signal?: AbortSignal): Promise<Cart>;
|
|
|
27
16
|
* an `error`.
|
|
28
17
|
*/
|
|
29
18
|
export declare function setCartQuantity(id: number, qty: number, options?: {
|
|
30
|
-
fragments?: readonly string[];
|
|
31
19
|
signal?: AbortSignal;
|
|
32
|
-
}): Promise<
|
|
20
|
+
}): Promise<Cart>;
|
|
33
21
|
/** POST /cart/coupon. An unknown or unusable code answers 400 { message } (HttpError). */
|
|
34
22
|
export declare function postCoupon(code: string, options?: {
|
|
35
|
-
fragments?: readonly string[];
|
|
36
23
|
signal?: AbortSignal;
|
|
37
|
-
}): Promise<
|
|
38
|
-
/**
|
|
39
|
-
* Theme fragments of the cart page without changing anything: GET /shopping-cart?fragments=... (for the mini
|
|
40
|
-
* cart). Answers { sections: {}, fragments }.
|
|
41
|
-
*/
|
|
42
|
-
export declare function fetchCartFragments(fragments: readonly string[], signal?: AbortSignal): Promise<Fragments>;
|
|
43
|
-
export { fragmentQuery };
|
|
24
|
+
}): Promise<Cart>;
|
package/dist/core/api/cart.js
CHANGED
|
@@ -1,44 +1,18 @@
|
|
|
1
1
|
import { get, post } from "../request.js";
|
|
2
|
-
function fragmentQuery(fragments) {
|
|
3
|
-
return fragments?.length ? { fragments: fragments.join(",") } : void 0;
|
|
4
|
-
}
|
|
5
|
-
function split(response) {
|
|
6
|
-
const { fragments = {}, ...cart } = response;
|
|
7
|
-
return { cart, fragments };
|
|
8
|
-
}
|
|
9
2
|
function postToCart(input, signal) {
|
|
10
3
|
return post("/cart", { id: input.id, qty: input.qty, mode: "add" }, { signal });
|
|
11
4
|
}
|
|
12
5
|
function fetchCart(signal) {
|
|
13
6
|
return get("/cart", { signal });
|
|
14
7
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"/cart",
|
|
18
|
-
{ id, qty },
|
|
19
|
-
{ query: fragmentQuery(options.fragments), signal: options.signal }
|
|
20
|
-
);
|
|
21
|
-
return split(response);
|
|
22
|
-
}
|
|
23
|
-
async function postCoupon(code, options = {}) {
|
|
24
|
-
const response = await post(
|
|
25
|
-
"/cart/coupon",
|
|
26
|
-
{ coupon_code: code },
|
|
27
|
-
{ query: fragmentQuery(options.fragments), signal: options.signal }
|
|
28
|
-
);
|
|
29
|
-
return split(response);
|
|
8
|
+
function setCartQuantity(id, qty, options = {}) {
|
|
9
|
+
return post("/cart", { id, qty }, { signal: options.signal });
|
|
30
10
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
query: fragmentQuery(fragments),
|
|
34
|
-
signal
|
|
35
|
-
});
|
|
36
|
-
return response?.fragments ?? {};
|
|
11
|
+
function postCoupon(code, options = {}) {
|
|
12
|
+
return post("/cart/coupon", { coupon_code: code }, { signal: options.signal });
|
|
37
13
|
}
|
|
38
14
|
export {
|
|
39
15
|
fetchCart,
|
|
40
|
-
fetchCartFragments,
|
|
41
|
-
fragmentQuery,
|
|
42
16
|
postCoupon,
|
|
43
17
|
postToCart,
|
|
44
18
|
setCartQuantity
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart.js","sources":["../../../src/core/api/cart.ts"],"sourcesContent":["import { get, post } from '../request'\nimport type { Cart } from '../types'\n\nexport interface AddToCartInput {\n /** Product id; for a virtual product, the selected variant's id */\n id: number\n qty: number\n}\n\n
|
|
1
|
+
{"version":3,"file":"cart.js","sources":["../../../src/core/api/cart.ts"],"sourcesContent":["import { get, post } from '../request'\nimport type { Cart } from '../types'\n\nexport interface AddToCartInput {\n /** Product id; for a virtual product, the selected variant's id */\n id: number\n qty: number\n}\n\n/**\n * POST /cart in \"add\" mode: adds qty to the line. A sold-out product or an expired location answers\n * 400 { message } (HttpError); bad input answers 422 (ValidationError).\n */\nexport function postToCart(input: AddToCartInput, signal?: AbortSignal): Promise<Cart> {\n return post<Cart>('/cart', { id: input.id, qty: input.qty, mode: 'add' }, { signal })\n}\n\nexport function fetchCart(signal?: AbortSignal): Promise<Cart> {\n return get<Cart>('/cart', { signal })\n}\n\n/**\n * POST /cart in \"set\" mode: the line's quantity becomes qty, and 0 removes it. (DELETE /cart/{id} cannot be\n * used: it always answers 400 on the platform.) A quantity over the stock is accepted, and the line carries\n * an `error`.\n */\nexport function setCartQuantity(\n id: number,\n qty: number,\n options: { signal?: AbortSignal } = {},\n): Promise<Cart> {\n return post<Cart>('/cart', { id, qty }, { signal: options.signal })\n}\n\n/** POST /cart/coupon. An unknown or unusable code answers 400 { message } (HttpError). */\nexport function postCoupon(code: string, options: { signal?: AbortSignal } = {}): Promise<Cart> {\n return post<Cart>('/cart/coupon', { coupon_code: code }, { signal: options.signal })\n}\n"],"names":[],"mappings":";AAaO,SAAS,WAAW,OAAuB,QAAqC;AACrF,SAAO,KAAW,SAAS,EAAE,IAAI,MAAM,IAAI,KAAK,MAAM,KAAK,MAAM,MAAA,GAAS,EAAE,QAAQ;AACtF;AAEO,SAAS,UAAU,QAAqC;AAC7D,SAAO,IAAU,SAAS,EAAE,QAAQ;AACtC;AAOO,SAAS,gBACd,IACA,KACA,UAAoC,CAAA,GACrB;AACf,SAAO,KAAW,SAAS,EAAE,IAAI,IAAA,GAAO,EAAE,QAAQ,QAAQ,QAAQ;AACpE;AAGO,SAAS,WAAW,MAAc,UAAoC,IAAmB;AAC9F,SAAO,KAAW,gBAAgB,EAAE,aAAa,KAAA,GAAQ,EAAE,QAAQ,QAAQ,QAAQ;AACrF;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Cart, CheckoutAddress, DeliveryOption, DeliveryType, PaymentMethodOption, PlacedOrder, ReservationDay } from '../types';
|
|
2
|
-
import { type Fragments } from './cart';
|
|
3
2
|
/** POST /cart/identity: whether an account exists for the e-mail (the server answers 200, or 404 for none). */
|
|
4
3
|
export declare function hasAccount(email: string, signal?: AbortSignal): Promise<boolean>;
|
|
5
4
|
/** POST /checkout/email: a guest's e-mail is valid and deliverable; 422 (ValidationError) when not. */
|
|
@@ -23,14 +22,10 @@ export interface SummaryInput {
|
|
|
23
22
|
country_id?: number;
|
|
24
23
|
state_id?: number | null;
|
|
25
24
|
}
|
|
26
|
-
/** POST /cart/summary: sets tax and shipping for the choice and returns the cart
|
|
25
|
+
/** POST /cart/summary: sets tax and shipping for the choice and returns the cart. */
|
|
27
26
|
export declare function fetchSummary(input: SummaryInput, options?: {
|
|
28
|
-
fragments?: readonly string[];
|
|
29
27
|
signal?: AbortSignal;
|
|
30
|
-
}): Promise<
|
|
31
|
-
cart: Cart;
|
|
32
|
-
fragments: Fragments;
|
|
33
|
-
}>;
|
|
28
|
+
}): Promise<Cart>;
|
|
34
29
|
export interface PaymentMethodsInput {
|
|
35
30
|
method: 'delivery' | 'pickup';
|
|
36
31
|
/** The delivery cost id, for delivery */
|
|
@@ -66,7 +61,6 @@ export interface GatewayRedirect {
|
|
|
66
61
|
export interface OrderPlaced {
|
|
67
62
|
kind: 'order';
|
|
68
63
|
order: PlacedOrder;
|
|
69
|
-
fragments: Fragments;
|
|
70
64
|
}
|
|
71
65
|
/**
|
|
72
66
|
* POST /checkout (signed in) or /checkout/guest. Refusals (stock, delivery and payment mismatch, reCAPTCHA)
|
|
@@ -74,7 +68,6 @@ export interface OrderPlaced {
|
|
|
74
68
|
*/
|
|
75
69
|
export declare function placeOrder(input: OrderInput, options: {
|
|
76
70
|
guest: boolean;
|
|
77
|
-
fragments?: readonly string[];
|
|
78
71
|
signal?: AbortSignal;
|
|
79
72
|
}): Promise<GatewayRedirect | OrderPlaced>;
|
|
80
73
|
export interface AgeCheckInput extends CheckoutAddress {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { HttpError } from "../errors.js";
|
|
2
2
|
import { post, get } from "../request.js";
|
|
3
|
-
import { fragmentQuery } from "./cart.js";
|
|
4
3
|
async function hasAccount(email, signal) {
|
|
5
4
|
try {
|
|
6
5
|
await post("/cart/identity", { email }, { signal });
|
|
@@ -27,12 +26,8 @@ function fetchReservationSlots(deliveryMethodId, signal) {
|
|
|
27
26
|
{ signal }
|
|
28
27
|
);
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
query: fragmentQuery(options.fragments),
|
|
33
|
-
signal: options.signal
|
|
34
|
-
});
|
|
35
|
-
return { cart, fragments };
|
|
29
|
+
function fetchSummary(input, options = {}) {
|
|
30
|
+
return post("/cart/summary", input, { signal: options.signal });
|
|
36
31
|
}
|
|
37
32
|
function fetchPaymentMethods(input, signal) {
|
|
38
33
|
return post("/cart/payment-methods", input, { signal });
|
|
@@ -42,7 +37,6 @@ async function placeOrder(input, options) {
|
|
|
42
37
|
options.guest ? "/checkout/guest" : "/checkout",
|
|
43
38
|
input,
|
|
44
39
|
{
|
|
45
|
-
query: fragmentQuery(options.fragments),
|
|
46
40
|
signal: options.signal,
|
|
47
41
|
// Gateways can take a while to sign the payload; keep spmkt 3's generous limit
|
|
48
42
|
timeout: 6e4
|
|
@@ -51,8 +45,7 @@ async function placeOrder(input, options) {
|
|
|
51
45
|
if (typeof response.url === "string" && response.payload && typeof response.payload === "object") {
|
|
52
46
|
return { kind: "gateway", url: response.url, payload: response.payload };
|
|
53
47
|
}
|
|
54
|
-
|
|
55
|
-
return { kind: "order", order, fragments };
|
|
48
|
+
return { kind: "order", order: response };
|
|
56
49
|
}
|
|
57
50
|
function checkAge(input, signal) {
|
|
58
51
|
return post("/cart/age-checker", input, { signal });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkout.js","sources":["../../../src/core/api/checkout.ts"],"sourcesContent":["import { HttpError } from '../errors'\nimport { get, post } from '../request'\nimport type {\n Cart,\n CheckoutAddress,\n DeliveryOption,\n DeliveryType,\n PaymentMethodOption,\n PlacedOrder,\n ReservationDay,\n} from '../types'\
|
|
1
|
+
{"version":3,"file":"checkout.js","sources":["../../../src/core/api/checkout.ts"],"sourcesContent":["import { HttpError } from '../errors'\nimport { get, post } from '../request'\nimport type {\n Cart,\n CheckoutAddress,\n DeliveryOption,\n DeliveryType,\n PaymentMethodOption,\n PlacedOrder,\n ReservationDay,\n} from '../types'\n\n/** POST /cart/identity: whether an account exists for the e-mail (the server answers 200, or 404 for none). */\nexport async function hasAccount(email: string, signal?: AbortSignal): Promise<boolean> {\n try {\n await post('/cart/identity', { email }, { signal })\n return true\n } catch (error) {\n if (error instanceof HttpError && error.status === 404) return false\n throw error\n }\n}\n\n/** POST /checkout/email: a guest's e-mail is valid and deliverable; 422 (ValidationError) when not. */\nexport async function validateGuestEmail(email: string, signal?: AbortSignal): Promise<void> {\n await post('/checkout/email', { email }, { signal })\n}\n\n/** POST /cart/address: validates an address and returns it with country and state filled in; 422 per field. */\nexport async function validateAddress(\n address: CheckoutAddress,\n signal?: AbortSignal,\n): Promise<CheckoutAddress> {\n const response = await post<{ data: CheckoutAddress }>('/cart/address', address, { signal })\n return response.data\n}\n\n/**\n * POST /cart/delivery-methods: how the cart can be delivered to an address (or a saved address, by id).\n * When it cannot, 400 { message } (HttpError).\n */\nexport function fetchDeliveryOptions(\n address: CheckoutAddress | { id: number },\n signal?: AbortSignal,\n): Promise<DeliveryOption[]> {\n return post<DeliveryOption[]>('/cart/delivery-methods', address, { signal })\n}\n\n/** POST /cart/reservation-slots for a delivery method that takes reservations. */\nexport function fetchReservationSlots(\n deliveryMethodId: number,\n signal?: AbortSignal,\n): Promise<ReservationDay[]> {\n return post<ReservationDay[]>(\n '/cart/reservation-slots',\n { delivery_method_id: deliveryMethodId },\n { signal },\n )\n}\n\nexport interface SummaryInput {\n delivery_method_id: number\n delivery_cost_id?: number | null\n /** A saved address, or the guest's country and state */\n address_id?: number\n country_id?: number\n state_id?: number | null\n}\n\n/** POST /cart/summary: sets tax and shipping for the choice and returns the cart. */\nexport function fetchSummary(input: SummaryInput, options: { signal?: AbortSignal } = {}): Promise<Cart> {\n return post<Cart>('/cart/summary', input, { signal: options.signal })\n}\n\nexport interface PaymentMethodsInput {\n method: 'delivery' | 'pickup'\n /** The delivery cost id, for delivery */\n rate_id?: number | null\n address_type?: 'personal' | 'business' | null\n}\n\n/** POST /cart/payment-methods */\nexport function fetchPaymentMethods(\n input: PaymentMethodsInput,\n signal?: AbortSignal,\n): Promise<PaymentMethodOption[]> {\n return post<PaymentMethodOption[]>('/cart/payment-methods', input, { signal })\n}\n\n/** What POST /checkout and /checkout/guest take besides the addresses. */\nexport interface OrderInput {\n idempotency_key: string\n payment_method_id: number\n delivery_method_id: number\n delivery_cost_id?: number | null\n reservation_slot?: string | null\n note?: string | null\n recaptcha_token?: string | null\n /** Guests */\n email?: string\n shipping_address?: CheckoutAddress\n billing_address?: CheckoutAddress\n /** Signed in, for delivery: saved addresses */\n shipping_address_id?: number\n billing_address_id?: number\n}\n\n/** A two-step payment method: the browser posts `payload` to `url` (the gateway's page). */\nexport interface GatewayRedirect {\n kind: 'gateway'\n url: string\n payload: Record<string, string | number>\n}\n\n/** An instant payment method: the order is placed. */\nexport interface OrderPlaced {\n kind: 'order'\n order: PlacedOrder\n}\n\n/**\n * POST /checkout (signed in) or /checkout/guest. Refusals (stock, delivery and payment mismatch, reCAPTCHA)\n * answer 400 { message, errors } (HttpError); invalid fields 422 (ValidationError).\n */\nexport async function placeOrder(\n input: OrderInput,\n options: { guest: boolean; signal?: AbortSignal },\n): Promise<GatewayRedirect | OrderPlaced> {\n const response = await post<Record<string, unknown>>(\n options.guest ? '/checkout/guest' : '/checkout',\n input,\n {\n signal: options.signal,\n // Gateways can take a while to sign the payload; keep spmkt 3's generous limit\n timeout: 60_000,\n },\n )\n if (typeof response.url === 'string' && response.payload && typeof response.payload === 'object') {\n return { kind: 'gateway', url: response.url, payload: response.payload as GatewayRedirect['payload'] }\n }\n return { kind: 'order', order: response as unknown as PlacedOrder }\n}\n\nexport interface AgeCheckInput extends CheckoutAddress {\n /** YYYY-MM-DD */\n date_of_birth: string\n}\n\n/** POST /cart/age-checker. With age verification off, the server answers { uuid: 'na', status: 'accepted' }. */\nexport function checkAge(\n input: AgeCheckInput,\n signal?: AbortSignal,\n): Promise<{ uuid: string; status: string }> {\n return post('/cart/age-checker', input, { signal })\n}\n\n/** GET /cart/delivery-types for the cart's retail location (pickup and delivery availability). */\nexport function fetchDeliveryTypes(signal?: AbortSignal): Promise<DeliveryType[]> {\n return get<DeliveryType[]>('/cart/delivery-types', { signal })\n}\n"],"names":[],"mappings":";;AAaA,eAAsB,WAAW,OAAe,QAAwC;AACtF,MAAI;AACF,UAAM,KAAK,kBAAkB,EAAE,SAAS,EAAE,QAAQ;AAClD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa,MAAM,WAAW,IAAK,QAAO;AAC/D,UAAM;AAAA,EACR;AACF;AAGA,eAAsB,mBAAmB,OAAe,QAAqC;AAC3F,QAAM,KAAK,mBAAmB,EAAE,SAAS,EAAE,QAAQ;AACrD;AAGA,eAAsB,gBACpB,SACA,QAC0B;AAC1B,QAAM,WAAW,MAAM,KAAgC,iBAAiB,SAAS,EAAE,QAAQ;AAC3F,SAAO,SAAS;AAClB;AAMO,SAAS,qBACd,SACA,QAC2B;AAC3B,SAAO,KAAuB,0BAA0B,SAAS,EAAE,QAAQ;AAC7E;AAGO,SAAS,sBACd,kBACA,QAC2B;AAC3B,SAAO;AAAA,IACL;AAAA,IACA,EAAE,oBAAoB,iBAAA;AAAA,IACtB,EAAE,OAAA;AAAA,EAAO;AAEb;AAYO,SAAS,aAAa,OAAqB,UAAoC,IAAmB;AACvG,SAAO,KAAW,iBAAiB,OAAO,EAAE,QAAQ,QAAQ,QAAQ;AACtE;AAUO,SAAS,oBACd,OACA,QACgC;AAChC,SAAO,KAA4B,yBAAyB,OAAO,EAAE,QAAQ;AAC/E;AAqCA,eAAsB,WACpB,OACA,SACwC;AACxC,QAAM,WAAW,MAAM;AAAA,IACrB,QAAQ,QAAQ,oBAAoB;AAAA,IACpC;AAAA,IACA;AAAA,MACE,QAAQ,QAAQ;AAAA;AAAA,MAEhB,SAAS;AAAA,IAAA;AAAA,EACX;AAEF,MAAI,OAAO,SAAS,QAAQ,YAAY,SAAS,WAAW,OAAO,SAAS,YAAY,UAAU;AAChG,WAAO,EAAE,MAAM,WAAW,KAAK,SAAS,KAAK,SAAS,SAAS,QAAA;AAAA,EACjE;AACA,SAAO,EAAE,MAAM,SAAS,OAAO,SAAA;AACjC;AAQO,SAAS,SACd,OACA,QAC2C;AAC3C,SAAO,KAAK,qBAAqB,OAAO,EAAE,QAAQ;AACpD;AAGO,SAAS,mBAAmB,QAA+C;AAChF,SAAO,IAAoB,wBAAwB,EAAE,QAAQ;AAC/D;"}
|
package/dist/core/api/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { postToCart, fetchCart, setCartQuantity, postCoupon
|
|
2
|
-
export type { AddToCartInput
|
|
1
|
+
export { postToCart, fetchCart, setCartQuantity, postCoupon } from './cart';
|
|
2
|
+
export type { AddToCartInput } from './cart';
|
|
3
3
|
export { hasAccount, validateGuestEmail, validateAddress, fetchDeliveryOptions, fetchReservationSlots, fetchSummary, fetchPaymentMethods, fetchDeliveryTypes, placeOrder, checkAge, } from './checkout';
|
|
4
4
|
export type { SummaryInput, PaymentMethodsInput, OrderInput, GatewayRedirect, OrderPlaced, AgeCheckInput, } from './checkout';
|
|
5
|
-
export { saveAddress, deleteAddress, setDefaultAddress } from './address';
|
|
5
|
+
export { fetchAddresses, saveAddress, deleteAddress, setDefaultAddress } from './address';
|
|
6
6
|
export { sendAccountForm, changeName, changeEmail, changePassword, changeDateOfBirth, resendVerification, } from './account';
|
|
7
7
|
export { suggest } from './search';
|
|
8
|
-
export { productUrl
|
|
8
|
+
export { productUrl } from './product';
|
|
9
9
|
export { submitReview, voteOnReview, uploadReviewImage, deleteReviewImage } from './reviews';
|
|
10
10
|
export type { ReviewInput } from './reviews';
|
|
11
11
|
export { askQuestion } from './questions';
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A product's own storefront endpoint (GET /products/{id}). Themes ask it for
|
|
3
|
-
*
|
|
2
|
+
* A product's own storefront endpoint (GET /products/{id}). Themes ask it for the product page's sections
|
|
3
|
+
* (?sections=template:product/main for the quick view); mi2 for JSON.
|
|
4
4
|
*/
|
|
5
5
|
export declare function productUrl(id: number): string;
|
|
6
|
-
/**
|
|
7
|
-
* POST /products/{id}/related: the next related products, skipping those already shown. With
|
|
8
|
-
* `fragments`, the theme renders them (the response is a FragmentResponse); without, it is JSON.
|
|
9
|
-
*/
|
|
10
|
-
export declare function fetchRelated<T = unknown>(id: number, shownIds: number[], options?: {
|
|
11
|
-
fragments?: string[];
|
|
12
|
-
signal?: AbortSignal;
|
|
13
|
-
}): Promise<T>;
|
package/dist/core/api/product.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
-
import { post } from "../request.js";
|
|
2
1
|
function productUrl(id) {
|
|
3
2
|
return `/products/${id}`;
|
|
4
3
|
}
|
|
5
|
-
function fetchRelated(id, shownIds, options = {}) {
|
|
6
|
-
return post(
|
|
7
|
-
`/products/${id}/related`,
|
|
8
|
-
{ relatedIds: shownIds },
|
|
9
|
-
{
|
|
10
|
-
query: options.fragments?.length ? { fragments: options.fragments.join(",") } : void 0,
|
|
11
|
-
signal: options.signal
|
|
12
|
-
}
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
4
|
export {
|
|
16
|
-
fetchRelated,
|
|
17
5
|
productUrl
|
|
18
6
|
};
|
|
19
7
|
//# sourceMappingURL=product.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product.js","sources":["../../../src/core/api/product.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"product.js","sources":["../../../src/core/api/product.ts"],"sourcesContent":["/**\n * A product's own storefront endpoint (GET /products/{id}). Themes ask it for the product page's sections\n * (?sections=template:product/main for the quick view); mi2 for JSON.\n */\nexport function productUrl(id: number): string {\n return `/products/${id}`\n}\n"],"names":[],"mappings":"AAIO,SAAS,WAAW,IAAoB;AAC7C,SAAO,aAAa,EAAE;AACxB;"}
|
package/dist/core/events.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PlacedOrder } from './types';
|
|
1
2
|
/** GA4's item shape, used by every commerce event so analytics adapters pass it through. */
|
|
2
3
|
export interface Ga4Item {
|
|
3
4
|
item_id: string;
|
|
@@ -81,9 +82,9 @@ export interface SpmktEventMap {
|
|
|
81
82
|
'spmkt:checkout-step': {
|
|
82
83
|
step: 'cart' | 'delivery' | 'payment' | 'done';
|
|
83
84
|
};
|
|
84
|
-
/**
|
|
85
|
-
'spmkt:
|
|
86
|
-
|
|
85
|
+
/** An instant payment method placed the order (spmkt-checkout shows its confirmation) */
|
|
86
|
+
'spmkt:order-placed': {
|
|
87
|
+
order: PlacedOrder;
|
|
87
88
|
};
|
|
88
89
|
/** Page event of the order confirmation; dispatched once per order id */
|
|
89
90
|
'spmkt:purchase': {
|
package/dist/core/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sources":["../../src/core/events.ts"],"sourcesContent":["/** GA4's item shape, used by every commerce event so analytics adapters pass it through. */\nexport interface Ga4Item {\n item_id: string\n item_name: string\n price?: number\n quantity?: number\n item_variant?: string\n item_brand?: string\n item_category?: string\n item_list_name?: string\n index?: number\n}\n\n/**\n * Every event spmkt dispatches, with its detail. Events bubble and are composed; core dispatches\n * store-level events on document, elements dispatch on themselves. Part of the public API.\n */\nexport interface SpmktEventMap {\n 'spmkt:view-item': { currency: string; value: number; items: Ga4Item[] }\n 'spmkt:view-item-list': { item_list_name?: string; items: Ga4Item[] }\n 'spmkt:select-item': { item_list_name?: string; items: Ga4Item[] }\n 'spmkt:search': { search_term: string }\n /** A sign-in or registration through the shop's own form (page events after the redirect) */\n 'spmkt:login': { method: string }\n 'spmkt:sign-up': { method: string }\n 'spmkt:add-to-cart': { currency: string; value: number; items: Ga4Item[] }\n 'spmkt:remove-from-cart': { currency: string; value: number; items: Ga4Item[] }\n /** Page event of the cart page */\n 'spmkt:view-cart': { currency: string; value: number; items: Ga4Item[] }\n /** The delivery step was entered */\n 'spmkt:begin-checkout': { currency: string; value: number; items: Ga4Item[]; coupon?: string }\n /** The delivery step was completed */\n 'spmkt:add-shipping-info': {\n currency: string\n value: number\n items: Ga4Item[]\n coupon?: string\n shipping_tier?: string\n }\n /** An order is being placed */\n 'spmkt:add-payment-info': {\n currency: string\n value: number\n items: Ga4Item[]\n coupon?: string\n payment_type?: string\n }\n /** The checkout showed another step */\n 'spmkt:checkout-step': { step: 'cart' | 'delivery' | 'payment' | 'done' }\n /**
|
|
1
|
+
{"version":3,"file":"events.js","sources":["../../src/core/events.ts"],"sourcesContent":["import type { PlacedOrder } from './types'\n\n/** GA4's item shape, used by every commerce event so analytics adapters pass it through. */\nexport interface Ga4Item {\n item_id: string\n item_name: string\n price?: number\n quantity?: number\n item_variant?: string\n item_brand?: string\n item_category?: string\n item_list_name?: string\n index?: number\n}\n\n/**\n * Every event spmkt dispatches, with its detail. Events bubble and are composed; core dispatches\n * store-level events on document, elements dispatch on themselves. Part of the public API.\n */\nexport interface SpmktEventMap {\n 'spmkt:view-item': { currency: string; value: number; items: Ga4Item[] }\n 'spmkt:view-item-list': { item_list_name?: string; items: Ga4Item[] }\n 'spmkt:select-item': { item_list_name?: string; items: Ga4Item[] }\n 'spmkt:search': { search_term: string }\n /** A sign-in or registration through the shop's own form (page events after the redirect) */\n 'spmkt:login': { method: string }\n 'spmkt:sign-up': { method: string }\n 'spmkt:add-to-cart': { currency: string; value: number; items: Ga4Item[] }\n 'spmkt:remove-from-cart': { currency: string; value: number; items: Ga4Item[] }\n /** Page event of the cart page */\n 'spmkt:view-cart': { currency: string; value: number; items: Ga4Item[] }\n /** The delivery step was entered */\n 'spmkt:begin-checkout': { currency: string; value: number; items: Ga4Item[]; coupon?: string }\n /** The delivery step was completed */\n 'spmkt:add-shipping-info': {\n currency: string\n value: number\n items: Ga4Item[]\n coupon?: string\n shipping_tier?: string\n }\n /** An order is being placed */\n 'spmkt:add-payment-info': {\n currency: string\n value: number\n items: Ga4Item[]\n coupon?: string\n payment_type?: string\n }\n /** The checkout showed another step */\n 'spmkt:checkout-step': { step: 'cart' | 'delivery' | 'payment' | 'done' }\n /** An instant payment method placed the order (spmkt-checkout shows its confirmation) */\n 'spmkt:order-placed': { order: PlacedOrder }\n /** Page event of the order confirmation; dispatched once per order id */\n 'spmkt:purchase': {\n transaction_id: string\n currency: string\n value: number\n tax?: number\n shipping?: number\n coupon?: string\n items: Ga4Item[]\n }\n 'spmkt:cart-changed': { count: number; subtotal: number }\n 'spmkt:compare-changed': { ids: number[] }\n /** A variant picker showed another variant (the product section was re-rendered for it) */\n 'spmkt:variant-change': { id: number }\n 'spmkt:location-changed': { id: number }\n 'spmkt:dialog-open': { id: string }\n 'spmkt:dialog-close': { id: string }\n 'spmkt:tab-change': { panel: string }\n 'spmkt:slide-change': { index: number }\n}\n\nexport type SpmktEventName = keyof SpmktEventMap\nexport type SpmktEvent<N extends SpmktEventName> = CustomEvent<SpmktEventMap[N]>\ntype SpmktDomEvents = { [N in SpmktEventName]: SpmktEvent<N> }\n\ndeclare global {\n // addEventListener('spmkt:...') on elements and document is typed\n interface GlobalEventHandlersEventMap extends SpmktDomEvents {}\n}\n\nexport function dispatch<N extends SpmktEventName>(\n target: EventTarget,\n name: N,\n detail: SpmktEventMap[N],\n): boolean {\n return target.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }))\n}\n\n/** addEventListener with the detail typed; returns the remover. */\nexport function on<N extends SpmktEventName>(\n target: EventTarget,\n name: N,\n handler: (event: SpmktEvent<N>) => void,\n options?: AddEventListenerOptions,\n): () => void {\n const listener = handler as EventListener\n target.addEventListener(name, listener, options)\n return () => target.removeEventListener(name, listener, options)\n}\n"],"names":[],"mappings":"AAmFO,SAAS,SACd,QACA,MACA,QACS;AACT,SAAO,OAAO,cAAc,IAAI,YAAY,MAAM,EAAE,QAAQ,SAAS,MAAM,UAAU,KAAA,CAAM,CAAC;AAC9F;AAGO,SAAS,GACd,QACA,MACA,SACA,SACY;AACZ,QAAM,WAAW;AACjB,SAAO,iBAAiB,MAAM,UAAU,OAAO;AAC/C,SAAO,MAAM,OAAO,oBAAoB,MAAM,UAAU,OAAO;AACjE;"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -3,15 +3,15 @@ export type { ConfigureOptions } from './config';
|
|
|
3
3
|
export { RequestError, HttpError, ValidationError, SessionExpiredError, TimeoutError, NetworkError, isAbortError, } from './errors';
|
|
4
4
|
export { request, get, post, del, getText, toQueryString, withQuery, shopRequestUrl } from './request';
|
|
5
5
|
export type { Query, QueryValue, RequestOptions } from './request';
|
|
6
|
-
export { formatMoney, numberFormat, setMoneyFormat, moneyFormat } from './money';
|
|
6
|
+
export { formatMoney, numberFormat, phpRound, setMoneyFormat, moneyFormat } from './money';
|
|
7
7
|
export type { FormatMoneyOptions } from './money';
|
|
8
8
|
export { configureI18n, currentLocale, intlLocale, t, plural } from './i18n';
|
|
9
9
|
export type { Message, Messages, Params } from './i18n';
|
|
10
10
|
export { dispatch, on } from './events';
|
|
11
11
|
export type { Ga4Item, SpmktEventMap, SpmktEventName, SpmktEvent } from './events';
|
|
12
|
-
export { dispatchPageEvents, PAGE_EVENTS } from './page-events';
|
|
12
|
+
export { dispatchPageEvents, firstPurchase, orderToPurchase, PAGE_EVENTS } from './page-events';
|
|
13
13
|
export type { PageEventName } from './page-events';
|
|
14
|
-
export { hydrate, onHydrate, readState, storefront, normalizeState, DEFAULT_STATE } from './state';
|
|
14
|
+
export { hydrate, onHydrate, readState, storefront, normalizeState, normalizeCart, DEFAULT_STATE, EMPTY_CART, } from './state';
|
|
15
15
|
export type { MoneyFormat, RetailLocationSummary, StorefrontState } from './types';
|
|
16
16
|
export * from './api';
|
|
17
17
|
export * from './stores';
|
|
@@ -19,4 +19,4 @@ export { readCookie, writeCookie, deleteCookie } from './cookies';
|
|
|
19
19
|
export { recaptchaToken } from './recaptcha';
|
|
20
20
|
export { installSignOutCleanup } from './session';
|
|
21
21
|
export { installBusyForms, installRecaptchaForms } from './forms';
|
|
22
|
-
export type { Cart, CartLine, CheckoutFlags, CheckoutAddress, DeliveryCost, DeliveryOption, DeliveryType, ReservationDay, PaymentMethodOption, OrderItem, PlacedOrder, CompareItem, LocationAvailability, Review, SearchSuggestion, UploadedImage, } from './types';
|
|
22
|
+
export type { Cart, CartLine, CheckoutFlags, CheckoutAddress, DeliveryCost, DeliveryOption, DeliveryType, ReservationDay, PaymentMethodOption, OrderItem, PlacedOrder, SavedAddress, CompareItem, LocationAvailability, Review, SearchSuggestion, UploadedImage, } from './types';
|
package/dist/core/index.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import { configure, isDebug, shopUrl } from "./config.js";
|
|
2
2
|
import { HttpError, NetworkError, RequestError, SessionExpiredError, TimeoutError, ValidationError, isAbortError } from "./errors.js";
|
|
3
3
|
import { del, get, getText, post, request, shopRequestUrl, toQueryString, withQuery } from "./request.js";
|
|
4
|
-
import { formatMoney, moneyFormat, numberFormat, setMoneyFormat } from "./money.js";
|
|
4
|
+
import { formatMoney, moneyFormat, numberFormat, phpRound, setMoneyFormat } from "./money.js";
|
|
5
5
|
import { configureI18n, currentLocale, intlLocale, plural, t } from "./i18n.js";
|
|
6
6
|
import { dispatch, on } from "./events.js";
|
|
7
|
-
import { PAGE_EVENTS, dispatchPageEvents } from "./page-events.js";
|
|
8
|
-
import { DEFAULT_STATE, hydrate, normalizeState, onHydrate, readState, storefront } from "./state.js";
|
|
7
|
+
import { PAGE_EVENTS, dispatchPageEvents, firstPurchase, orderToPurchase } from "./page-events.js";
|
|
8
|
+
import { DEFAULT_STATE, EMPTY_CART, hydrate, normalizeCart, normalizeState, onHydrate, readState, storefront } from "./state.js";
|
|
9
9
|
import { deleteCookie, readCookie, writeCookie } from "./cookies.js";
|
|
10
10
|
import { recaptchaToken } from "./recaptcha.js";
|
|
11
11
|
import { installSignOutCleanup } from "./session.js";
|
|
12
12
|
import { installBusyForms, installRecaptchaForms } from "./forms.js";
|
|
13
13
|
import { COMPARE_COOKIE, clearCompare, compareIds, compareItems, compareMax, compareUrl, removeFromCompare, toggleCompare } from "./stores/compare.js";
|
|
14
14
|
import { EMPTY_DRAFT, checkoutDraft, clearCheckoutDraft, updateDraft } from "./stores/checkout-draft.js";
|
|
15
|
-
import { addOrderCheck, beginCheckout,
|
|
16
|
-
import { addToCart, applyCoupon, cartCount, cartEmptied, cartLineToItem, cartPending, cartSubtotal,
|
|
15
|
+
import { addOrderCheck, beginCheckout, checkoutPending, chooseAddress, chooseDelivery, chooseKind, chooseSlot, completeDelivery, confirmAddress, confirmIdentity, deliveryComplete, loadDeliveryOptions, loadPaymentMethods, orderInput, passOrderChecks, postToGateway, stepToShow, submitOrder, summaryPriced } from "./stores/checkout.js";
|
|
16
|
+
import { addToCart, applyCoupon, cart, cartCount, cartEmptied, cartLineToItem, cartLines, cartPending, cartSubtotal, setQuantity, takeCart } from "./stores/cart.js";
|
|
17
17
|
import { askQuestion } from "./api/questions.js";
|
|
18
18
|
import { availabilityByLocation, setPreferredLocation } from "./api/location.js";
|
|
19
19
|
import { changeDateOfBirth, changeEmail, changeName, changePassword, resendVerification, sendAccountForm } from "./api/account.js";
|
|
20
20
|
import { changeLocation, locationPending, preferredLocation, retailLocations } from "./stores/location.js";
|
|
21
21
|
import { checkAge, fetchDeliveryOptions, fetchDeliveryTypes, fetchPaymentMethods, fetchReservationSlots, fetchSummary, hasAccount, placeOrder, validateAddress, validateGuestEmail } from "./api/checkout.js";
|
|
22
22
|
import { customerName, customerSignedIn } from "./stores/customer.js";
|
|
23
|
-
import { deleteAddress, saveAddress, setDefaultAddress } from "./api/address.js";
|
|
23
|
+
import { deleteAddress, fetchAddresses, saveAddress, setDefaultAddress } from "./api/address.js";
|
|
24
24
|
import { deleteReviewImage, submitReview, uploadReviewImage, voteOnReview } from "./api/reviews.js";
|
|
25
|
-
import { fetchCart,
|
|
26
|
-
import {
|
|
25
|
+
import { fetchCart, postCoupon, postToCart, setCartQuantity } from "./api/cart.js";
|
|
26
|
+
import { productUrl } from "./api/product.js";
|
|
27
27
|
import { suggest } from "./api/search.js";
|
|
28
28
|
export {
|
|
29
29
|
COMPARE_COOKIE,
|
|
30
30
|
DEFAULT_STATE,
|
|
31
|
+
EMPTY_CART,
|
|
31
32
|
EMPTY_DRAFT,
|
|
32
33
|
HttpError,
|
|
33
34
|
NetworkError,
|
|
@@ -42,19 +43,19 @@ export {
|
|
|
42
43
|
askQuestion,
|
|
43
44
|
availabilityByLocation,
|
|
44
45
|
beginCheckout,
|
|
46
|
+
cart,
|
|
45
47
|
cartCount,
|
|
46
48
|
cartEmptied,
|
|
47
49
|
cartLineToItem,
|
|
50
|
+
cartLines,
|
|
48
51
|
cartPending,
|
|
49
52
|
cartSubtotal,
|
|
50
|
-
cartSummary,
|
|
51
53
|
changeDateOfBirth,
|
|
52
54
|
changeEmail,
|
|
53
55
|
changeLocation,
|
|
54
56
|
changeName,
|
|
55
57
|
changePassword,
|
|
56
58
|
checkAge,
|
|
57
|
-
checkoutCart,
|
|
58
59
|
checkoutDraft,
|
|
59
60
|
checkoutPending,
|
|
60
61
|
chooseAddress,
|
|
@@ -82,14 +83,14 @@ export {
|
|
|
82
83
|
deliveryComplete,
|
|
83
84
|
dispatch,
|
|
84
85
|
dispatchPageEvents,
|
|
86
|
+
fetchAddresses,
|
|
85
87
|
fetchCart,
|
|
86
|
-
fetchCartFragments,
|
|
87
88
|
fetchDeliveryOptions,
|
|
88
89
|
fetchDeliveryTypes,
|
|
89
90
|
fetchPaymentMethods,
|
|
90
|
-
fetchRelated,
|
|
91
91
|
fetchReservationSlots,
|
|
92
92
|
fetchSummary,
|
|
93
|
+
firstPurchase,
|
|
93
94
|
formatMoney,
|
|
94
95
|
get,
|
|
95
96
|
getText,
|
|
@@ -105,12 +106,15 @@ export {
|
|
|
105
106
|
loadPaymentMethods,
|
|
106
107
|
locationPending,
|
|
107
108
|
moneyFormat,
|
|
109
|
+
normalizeCart,
|
|
108
110
|
normalizeState,
|
|
109
111
|
numberFormat,
|
|
110
112
|
on,
|
|
111
113
|
onHydrate,
|
|
112
114
|
orderInput,
|
|
115
|
+
orderToPurchase,
|
|
113
116
|
passOrderChecks,
|
|
117
|
+
phpRound,
|
|
114
118
|
placeOrder,
|
|
115
119
|
plural,
|
|
116
120
|
post,
|
|
@@ -129,7 +133,6 @@ export {
|
|
|
129
133
|
saveAddress,
|
|
130
134
|
sendAccountForm,
|
|
131
135
|
setCartQuantity,
|
|
132
|
-
setCheckoutCart,
|
|
133
136
|
setDefaultAddress,
|
|
134
137
|
setMoneyFormat,
|
|
135
138
|
setPreferredLocation,
|
|
@@ -141,6 +144,7 @@ export {
|
|
|
141
144
|
submitOrder,
|
|
142
145
|
submitReview,
|
|
143
146
|
suggest,
|
|
147
|
+
summaryPriced,
|
|
144
148
|
t,
|
|
145
149
|
takeCart,
|
|
146
150
|
toQueryString,
|
package/dist/core/money.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { MoneyFormat } from './types';
|
|
2
2
|
export declare function setMoneyFormat(next: MoneyFormat): void;
|
|
3
3
|
export declare function moneyFormat(): Readonly<MoneyFormat>;
|
|
4
|
+
/** PHP's round(): half away from zero, signs kept (1.005 -> 1.01, -2.5 -> -3). */
|
|
5
|
+
export declare function phpRound(value: number, decimals?: number): number;
|
|
4
6
|
/** PHP number_format(). */
|
|
5
7
|
export declare function numberFormat(value: number, decimals?: number, decimal?: string, thousands?: string): string;
|
|
6
8
|
export interface FormatMoneyOptions {
|
package/dist/core/money.js
CHANGED
|
@@ -9,6 +9,10 @@ function roundHalfUp(value, decimals) {
|
|
|
9
9
|
const factor = 10 ** decimals;
|
|
10
10
|
return Math.round(Number((Math.abs(value) * factor).toPrecision(15))) / factor;
|
|
11
11
|
}
|
|
12
|
+
function phpRound(value, decimals = 0) {
|
|
13
|
+
const rounded = roundHalfUp(value, decimals);
|
|
14
|
+
return value < 0 && rounded !== 0 ? -rounded : rounded;
|
|
15
|
+
}
|
|
12
16
|
function numberFormat(value, decimals = 0, decimal = ".", thousands = ",") {
|
|
13
17
|
const rounded = roundHalfUp(value, decimals);
|
|
14
18
|
const [whole = "0", fraction] = rounded.toFixed(decimals).split(".");
|
|
@@ -25,6 +29,7 @@ export {
|
|
|
25
29
|
formatMoney,
|
|
26
30
|
moneyFormat,
|
|
27
31
|
numberFormat,
|
|
32
|
+
phpRound,
|
|
28
33
|
setMoneyFormat
|
|
29
34
|
};
|
|
30
35
|
//# sourceMappingURL=money.js.map
|
package/dist/core/money.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"money.js","sources":["../../src/core/money.ts"],"sourcesContent":["import type { MoneyFormat } from './types'\n\n/**\n * Money exactly as the server prints it. The server's fmt_money() can be overridden per instance\n * (core prints \"$1,234\", the mi-srbija extension \"1.234,50 RSD\"), so the format comes from the page state\n * rather than Intl: the separators and a pattern with an {amount} placeholder.\n */\nlet format: MoneyFormat = { thousands: ',', decimal: '.', pattern: '{amount}' }\n\nexport function setMoneyFormat(next: MoneyFormat): void {\n format = { ...next }\n}\n\nexport function moneyFormat(): Readonly<MoneyFormat> {\n return format\n}\n\n/** Rounds half away from zero like PHP's round(), without binary float surprises (1.005 -> 1.01). */\nfunction roundHalfUp(value: number, decimals: number): number {\n const factor = 10 ** decimals\n return Math.round(Number((Math.abs(value) * factor).toPrecision(15))) / factor\n}\n\n/** PHP number_format(). */\nexport function numberFormat(value: number, decimals = 0, decimal = '.', thousands = ','): string {\n const rounded = roundHalfUp(value, decimals)\n const [whole = '0', fraction] = rounded.toFixed(decimals).split('.')\n const grouped = whole.replace(/\\B(?=(\\d{3})+(?!\\d))/g, thousands)\n const sign = value < 0 && rounded !== 0 ? '-' : ''\n return sign + grouped + (fraction !== undefined ? decimal + fraction : '')\n}\n\nexport interface FormatMoneyOptions {\n /** 'auto' (the default) is ProductPricePresenter's rule: no decimals for whole amounts, else 2 */\n decimals?: number | 'auto'\n}\n\nexport function formatMoney(amount: number, options: FormatMoneyOptions = {}): string {\n const decimals =\n options.decimals === undefined || options.decimals === 'auto'\n ? Math.floor(amount) === amount\n ? 0\n : 2\n : options.decimals\n const number = numberFormat(amount, decimals, format.decimal, format.thousands)\n return format.pattern.replace('{amount}', number).trim()\n}\n"],"names":[],"mappings":"AAOA,IAAI,SAAsB,EAAE,WAAW,KAAK,SAAS,KAAK,SAAS,WAAA;AAE5D,SAAS,eAAe,MAAyB;AACtD,WAAS,EAAE,GAAG,KAAA;AAChB;AAEO,SAAS,cAAqC;AACnD,SAAO;AACT;AAGA,SAAS,YAAY,OAAe,UAA0B;AAC5D,QAAM,SAAS,MAAM;AACrB,SAAO,KAAK,MAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,QAAQ,YAAY,EAAE,CAAC,CAAC,IAAI;AAC1E;AAGO,SAAS,aAAa,OAAe,WAAW,GAAG,UAAU,KAAK,YAAY,KAAa;AAChG,QAAM,UAAU,YAAY,OAAO,QAAQ;AAC3C,QAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,QAAQ,QAAQ,QAAQ,EAAE,MAAM,GAAG;AACnE,QAAM,UAAU,MAAM,QAAQ,yBAAyB,SAAS;AAChE,QAAM,OAAO,QAAQ,KAAK,YAAY,IAAI,MAAM;AAChD,SAAO,OAAO,WAAW,aAAa,SAAY,UAAU,WAAW;AACzE;AAOO,SAAS,YAAY,QAAgB,UAA8B,IAAY;AACpF,QAAM,WACJ,QAAQ,aAAa,UAAa,QAAQ,aAAa,SACnD,KAAK,MAAM,MAAM,MAAM,SACrB,IACA,IACF,QAAQ;AACd,QAAM,SAAS,aAAa,QAAQ,UAAU,OAAO,SAAS,OAAO,SAAS;AAC9E,SAAO,OAAO,QAAQ,QAAQ,YAAY,MAAM,EAAE,KAAA;AACpD;"}
|
|
1
|
+
{"version":3,"file":"money.js","sources":["../../src/core/money.ts"],"sourcesContent":["import type { MoneyFormat } from './types'\n\n/**\n * Money exactly as the server prints it. The server's fmt_money() can be overridden per instance\n * (core prints \"$1,234\", the mi-srbija extension \"1.234,50 RSD\"), so the format comes from the page state\n * rather than Intl: the separators and a pattern with an {amount} placeholder.\n */\nlet format: MoneyFormat = { thousands: ',', decimal: '.', pattern: '{amount}' }\n\nexport function setMoneyFormat(next: MoneyFormat): void {\n format = { ...next }\n}\n\nexport function moneyFormat(): Readonly<MoneyFormat> {\n return format\n}\n\n/** Rounds half away from zero like PHP's round(), without binary float surprises (1.005 -> 1.01). */\nfunction roundHalfUp(value: number, decimals: number): number {\n const factor = 10 ** decimals\n return Math.round(Number((Math.abs(value) * factor).toPrecision(15))) / factor\n}\n\n/** PHP's round(): half away from zero, signs kept (1.005 -> 1.01, -2.5 -> -3). */\nexport function phpRound(value: number, decimals = 0): number {\n const rounded = roundHalfUp(value, decimals)\n return value < 0 && rounded !== 0 ? -rounded : rounded\n}\n\n/** PHP number_format(). */\nexport function numberFormat(value: number, decimals = 0, decimal = '.', thousands = ','): string {\n const rounded = roundHalfUp(value, decimals)\n const [whole = '0', fraction] = rounded.toFixed(decimals).split('.')\n const grouped = whole.replace(/\\B(?=(\\d{3})+(?!\\d))/g, thousands)\n const sign = value < 0 && rounded !== 0 ? '-' : ''\n return sign + grouped + (fraction !== undefined ? decimal + fraction : '')\n}\n\nexport interface FormatMoneyOptions {\n /** 'auto' (the default) is ProductPricePresenter's rule: no decimals for whole amounts, else 2 */\n decimals?: number | 'auto'\n}\n\nexport function formatMoney(amount: number, options: FormatMoneyOptions = {}): string {\n const decimals =\n options.decimals === undefined || options.decimals === 'auto'\n ? Math.floor(amount) === amount\n ? 0\n : 2\n : options.decimals\n const number = numberFormat(amount, decimals, format.decimal, format.thousands)\n return format.pattern.replace('{amount}', number).trim()\n}\n"],"names":[],"mappings":"AAOA,IAAI,SAAsB,EAAE,WAAW,KAAK,SAAS,KAAK,SAAS,WAAA;AAE5D,SAAS,eAAe,MAAyB;AACtD,WAAS,EAAE,GAAG,KAAA;AAChB;AAEO,SAAS,cAAqC;AACnD,SAAO;AACT;AAGA,SAAS,YAAY,OAAe,UAA0B;AAC5D,QAAM,SAAS,MAAM;AACrB,SAAO,KAAK,MAAM,QAAQ,KAAK,IAAI,KAAK,IAAI,QAAQ,YAAY,EAAE,CAAC,CAAC,IAAI;AAC1E;AAGO,SAAS,SAAS,OAAe,WAAW,GAAW;AAC5D,QAAM,UAAU,YAAY,OAAO,QAAQ;AAC3C,SAAO,QAAQ,KAAK,YAAY,IAAI,CAAC,UAAU;AACjD;AAGO,SAAS,aAAa,OAAe,WAAW,GAAG,UAAU,KAAK,YAAY,KAAa;AAChG,QAAM,UAAU,YAAY,OAAO,QAAQ;AAC3C,QAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,QAAQ,QAAQ,QAAQ,EAAE,MAAM,GAAG;AACnE,QAAM,UAAU,MAAM,QAAQ,yBAAyB,SAAS;AAChE,QAAM,OAAO,QAAQ,KAAK,YAAY,IAAI,MAAM;AAChD,SAAO,OAAO,WAAW,aAAa,SAAY,UAAU,WAAW;AACzE;AAOO,SAAS,YAAY,QAAgB,UAA8B,IAAY;AACpF,QAAM,WACJ,QAAQ,aAAa,UAAa,QAAQ,aAAa,SACnD,KAAK,MAAM,MAAM,MAAM,SACrB,IACA,IACF,QAAQ;AACd,QAAM,SAAS,aAAa,QAAQ,UAAU,OAAO,SAAS,OAAO,SAAS;AAC9E,SAAO,OAAO,QAAQ,QAAQ,YAAY,MAAM,EAAE,KAAA;AACpD;"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type SpmktEventMap } from './events';
|
|
2
|
+
import type { PlacedOrder } from './types';
|
|
1
3
|
/**
|
|
2
4
|
* Events a page (or a re-rendered region of it) announces from the server, as
|
|
3
5
|
* <script type="application/json" data-spmkt-event="view-item-list">{...detail}</script>.
|
|
@@ -11,3 +13,18 @@ export type PageEventName = (typeof PAGE_EVENTS)[number];
|
|
|
11
13
|
* Returns how many events were dispatched.
|
|
12
14
|
*/
|
|
13
15
|
export declare function dispatchPageEvents(root?: ParentNode, target?: EventTarget): number;
|
|
16
|
+
/**
|
|
17
|
+
* Whether this order's purchase was not announced yet in this tab, and remembers it: a reload of the success
|
|
18
|
+
* page, or Back to it, must not count the order twice. Without storage every announcement goes out. The page
|
|
19
|
+
* events and spmkt-order-confirmation share it, so an order is announced once whichever page confirms it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function firstPurchase(detail: {
|
|
22
|
+
transaction_id?: unknown;
|
|
23
|
+
}): boolean;
|
|
24
|
+
type Purchase = SpmktEventMap['spmkt:purchase'];
|
|
25
|
+
/**
|
|
26
|
+
* The purchase event of a placed order. The same as Ga4Events::purchaseDetail() on the platform (one fixture
|
|
27
|
+
* checks both); null for an order without an id.
|
|
28
|
+
*/
|
|
29
|
+
export declare function orderToPurchase(order: PlacedOrder): Purchase | null;
|
|
30
|
+
export {};
|