@final-commerce/command-frame 0.9.0-online.1 → 0.9.0-online.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/CommonTypes.d.ts +3 -1
- package/dist/actions/get-address-options/action.d.ts +6 -0
- package/dist/actions/get-address-options/action.js +8 -0
- package/dist/actions/get-address-options/mock.d.ts +3 -0
- package/dist/actions/get-address-options/mock.js +15 -0
- package/dist/actions/get-address-options/types.d.ts +25 -0
- package/dist/actions/get-address-options/types.js +8 -0
- package/dist/actions/get-shipping-options/action.d.ts +6 -0
- package/dist/actions/get-shipping-options/action.js +8 -0
- package/dist/actions/get-shipping-options/mock.d.ts +3 -0
- package/dist/actions/get-shipping-options/mock.js +15 -0
- package/dist/actions/get-shipping-options/types.d.ts +43 -0
- package/dist/actions/get-shipping-options/types.js +1 -0
- package/dist/actions/select-shipping-option/action.d.ts +6 -0
- package/dist/actions/select-shipping-option/action.js +8 -0
- package/dist/actions/select-shipping-option/mock.d.ts +3 -0
- package/dist/actions/select-shipping-option/mock.js +31 -0
- package/dist/actions/select-shipping-option/types.d.ts +15 -0
- package/dist/actions/select-shipping-option/types.js +1 -0
- package/dist/actions/set-order-address/action.d.ts +6 -0
- package/dist/actions/set-order-address/action.js +8 -0
- package/dist/actions/set-order-address/mock.d.ts +7 -0
- package/dist/actions/set-order-address/mock.js +29 -0
- package/dist/actions/set-order-address/types.d.ts +19 -0
- package/dist/actions/set-order-address/types.js +1 -0
- package/dist/demo/shipping.d.ts +8 -0
- package/dist/demo/shipping.js +69 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/projects/render/mocks.js +8 -0
- package/dist/projects/render/types.d.ts +6 -1
- package/package.json +2 -2
package/dist/CommonTypes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './common-types';
|
|
2
|
-
import type { Tax, Tip, Address, MetadataItem, PosDataItem, CartFeeTaxEntry, CartFeeItem, CartDiscountItem, OrderNote, NonRevenueItem, DiscountDetail, FeeDetail, DiscountLineItem, FeeLineItem, LineItem, TipPayment, RefundedTipPayment, PaymentMethod, Discount, CustomFee, Summary, CustomSale, RefundedCustomSale, RefundItem, RefundedLineItem, ActiveStation, ActiveSession, ActiveOutlet, ActiveUser, ActiveUserRole, ActiveOrder, ActiveCart, ActivePark, ActiveCompany, ActiveCustomSales, ActiveProduct, ActiveCustomer, FullProduct, ProductVariant, Inventory, ResolvedModifier, ResolvedModifierChoice, ModifierSelectionType, ModifierSelection, ModifierChoiceSelection, CartLineModifier, ProdModifierBreakdown, OrderLineItemModifier, CustomerNote, Attribute, AttributeOption, Category, Transaction, ActiveSplitPayment, BookingAvailability, BookingSlot, BookingSlotResource, BookingResource, Booking, CartReservation, OrderReservation } from '@final-commerce/common/pos-types';
|
|
2
|
+
import type { Tax, Tip, Address, MetadataItem, PosDataItem, CartFeeTaxEntry, CartFeeItem, CartDiscountItem, OrderNote, NonRevenueItem, DiscountDetail, FeeDetail, DiscountLineItem, FeeLineItem, LineItem, TipPayment, RefundedTipPayment, PaymentMethod, Discount, CustomFee, Summary, CustomSale, RefundedCustomSale, RefundItem, RefundedLineItem, ActiveStation, ActiveSession, ActiveOutlet, ActiveUser, ActiveUserRole, ActiveOrder, ActiveCart, ActivePark, ActiveCompany, ActiveCustomSales, ActiveProduct, ActiveCustomer, FullProduct, ProductVariant, Inventory, ResolvedModifier, ResolvedModifierChoice, ModifierSelectionType, ModifierSelection, ModifierChoiceSelection, CartLineModifier, ProdModifierBreakdown, OrderLineItemModifier, CustomerNote, Attribute, AttributeOption, Category, Transaction, ActiveSplitPayment, BookingAvailability, BookingSlot, BookingSlotResource, BookingResource, Booking, CartReservation, OrderReservation, CartAddress, CartShipping } from '@final-commerce/common/pos-types';
|
|
3
3
|
export { CurrencyCode, ProductType as CFProductType, UserTypes as CFUserTypes } from '@final-commerce/common';
|
|
4
4
|
/** Open record used as a base for active entities. */
|
|
5
5
|
export type CFActiveEntity = Record<string, unknown>;
|
|
@@ -72,6 +72,8 @@ export type CFActiveOrder = ActiveOrder;
|
|
|
72
72
|
export type CFActiveCustomSales = ActiveCustomSales;
|
|
73
73
|
export type CFNonRevenueItem = NonRevenueItem;
|
|
74
74
|
export type CFActiveCart = ActiveCart;
|
|
75
|
+
export type CFCartAddress = CartAddress;
|
|
76
|
+
export type CFCartShipping = CartShipping;
|
|
75
77
|
export type CFActivePark = ActivePark;
|
|
76
78
|
export type CFActiveCompany = ActiveCompany;
|
|
77
79
|
/** Tile kinds a SmartGrid cell can represent. Mirrors common's `BaseTile['type']`. */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GetAddressOptions action
|
|
3
|
+
* Calls the getAddressOptions action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from '../../client';
|
|
6
|
+
export const getAddressOptions = async (params) => {
|
|
7
|
+
return await commandFrameClient.call('getAddressOptions', params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CANADA_PROVINCES, listCountries } from '@final-commerce/common';
|
|
2
|
+
/** Standalone mock: the same country and province lists the runtime serves. The demo store is in Canada. */
|
|
3
|
+
export const mockGetAddressOptions = async (params) => {
|
|
4
|
+
console.log('[Mock] getAddressOptions called', params);
|
|
5
|
+
const french = params?.locale?.toLowerCase().startsWith('fr') ?? false;
|
|
6
|
+
const provinces = CANADA_PROVINCES.map((p) => ({ code: p.code, name: french ? p.nameFr : p.name }));
|
|
7
|
+
return {
|
|
8
|
+
countries: listCountries(params?.locale ?? 'en').map((c) => ({
|
|
9
|
+
...c,
|
|
10
|
+
provinces: c.code === 'CA' ? provinces : [],
|
|
11
|
+
})),
|
|
12
|
+
defaultCountry: 'CA',
|
|
13
|
+
timestamp: new Date().toISOString(),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface AddressProvinceOption {
|
|
2
|
+
/** Province code, e.g. `QC`. This is what goes in the address's `state`. */
|
|
3
|
+
code: string;
|
|
4
|
+
/** In the requested locale where we have it (English or French). */
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AddressCountryOption {
|
|
8
|
+
/** ISO 3166-1 alpha-2, e.g. `CA`. This is what goes in the address's `country`. */
|
|
9
|
+
code: string;
|
|
10
|
+
name: string;
|
|
11
|
+
/** Empty when the country has no province list; the form then shows a free text field. */
|
|
12
|
+
provinces: AddressProvinceOption[];
|
|
13
|
+
}
|
|
14
|
+
export interface GetAddressOptionsParams {
|
|
15
|
+
/** BCP 47 locale for the names, e.g. `fr-CA`. Defaults to `en`. */
|
|
16
|
+
locale?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface GetAddressOptionsResponse {
|
|
19
|
+
/** Sorted by name in the requested locale. */
|
|
20
|
+
countries: AddressCountryOption[];
|
|
21
|
+
/** The store's own country, to preselect. Null when it isn't known. */
|
|
22
|
+
defaultCountry: string | null;
|
|
23
|
+
timestamp: string;
|
|
24
|
+
}
|
|
25
|
+
export type GetAddressOptions = (params?: GetAddressOptionsParams) => Promise<GetAddressOptionsResponse>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Get Address Options Types
|
|
2
|
+
//
|
|
3
|
+
// What an address form offers: countries, and the provinces of the countries that
|
|
4
|
+
// have them (Canada today). A flow renders these as dropdowns and keeps no list of
|
|
5
|
+
// its own, so what the shopper picks is always a code the shipping rules match.
|
|
6
|
+
//
|
|
7
|
+
// Served by the till and by the storefront runtime.
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GetShippingOptions action
|
|
3
|
+
* Calls the getShippingOptions action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from '../../client';
|
|
6
|
+
export const getShippingOptions = async () => {
|
|
7
|
+
return await commandFrameClient.call('getShippingOptions', undefined);
|
|
8
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MOCK_SHIPPING_ZONES, mockShippingOptions } from '../../demo/shipping';
|
|
2
|
+
/** Standalone mock: the demo store's zones run through the real resolver, as the website would. */
|
|
3
|
+
export const mockGetShippingOptions = async () => {
|
|
4
|
+
console.log('[Mock] getShippingOptions called');
|
|
5
|
+
const { resolution, options } = mockShippingOptions();
|
|
6
|
+
const message = resolution.message ??
|
|
7
|
+
(options.length === 0 && resolution.reason === 'NO_COVERAGE' ? 'Sorry, we only ship within Canada.' : null);
|
|
8
|
+
return {
|
|
9
|
+
required: MOCK_SHIPPING_ZONES.length > 0,
|
|
10
|
+
options,
|
|
11
|
+
reason: resolution.reason,
|
|
12
|
+
message,
|
|
13
|
+
timestamp: new Date().toISOString(),
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ShippingNoOptionReason, ShippingOptionType } from '@final-commerce/common';
|
|
2
|
+
export interface ShippingPickupView {
|
|
3
|
+
outletId: string;
|
|
4
|
+
/** The store's name, e.g. "Duckworth Street". */
|
|
5
|
+
name: string;
|
|
6
|
+
/** One line per open day, e.g. "Mon–Fri 9:00 AM – 6:00 PM". Empty when the store set no hours. */
|
|
7
|
+
hours: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface ShippingOptionView {
|
|
10
|
+
optionId: string;
|
|
11
|
+
type: ShippingOptionType | `${ShippingOptionType}`;
|
|
12
|
+
/** "Standard shipping", or "Pickup at Duckworth Street". */
|
|
13
|
+
name: string;
|
|
14
|
+
/** What this option costs on this cart, minor units, before its tax. */
|
|
15
|
+
amount: number;
|
|
16
|
+
/** "$10.00" or "Free". */
|
|
17
|
+
priceText: string;
|
|
18
|
+
/** "Add $20.00 more for free shipping", when a free-shipping line exists and isn't reached. */
|
|
19
|
+
freeShippingHint: string | null;
|
|
20
|
+
/** "Arrives Tue, Oct 20 – Fri, Oct 23", counted in business days from today. Null for pickup. */
|
|
21
|
+
arrivalText: string | null;
|
|
22
|
+
pickup: ShippingPickupView | null;
|
|
23
|
+
/** The option on the cart now. The cheapest is chosen by default. */
|
|
24
|
+
selected: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface GetShippingOptionsResponse {
|
|
27
|
+
/**
|
|
28
|
+
* False when this store doesn't ship at all (no shipping set up) or the cart has
|
|
29
|
+
* nothing to ship: show no shipping step.
|
|
30
|
+
*/
|
|
31
|
+
required: boolean;
|
|
32
|
+
/** Ship options cheapest first, then pickups. */
|
|
33
|
+
options: ShippingOptionView[];
|
|
34
|
+
/** Why there is nothing to choose; null when `options` isn't empty. */
|
|
35
|
+
reason: ShippingNoOptionReason | `${ShippingNoOptionReason}` | null;
|
|
36
|
+
/**
|
|
37
|
+
* What to tell the customer: the store's "we don't ship here" message, or the
|
|
38
|
+
* default for the reason ("Sorry, we only ship within Canada."). Null when there are options.
|
|
39
|
+
*/
|
|
40
|
+
message: string | null;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
}
|
|
43
|
+
export type GetShippingOptions = () => Promise<GetShippingOptionsResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SelectShippingOption action
|
|
3
|
+
* Calls the selectShippingOption action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from '../../client';
|
|
6
|
+
export const selectShippingOption = async (params) => {
|
|
7
|
+
return await commandFrameClient.call('selectShippingOption', params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from '../../demo/database';
|
|
2
|
+
import { mockShippingOptions } from '../../demo/shipping';
|
|
3
|
+
/** Standalone mock: refuses an option the cart isn't offered, like the runtime does. */
|
|
4
|
+
export const mockSelectShippingOption = async (params) => {
|
|
5
|
+
console.log('[Mock] selectShippingOption called', params);
|
|
6
|
+
if (!params)
|
|
7
|
+
throw new Error('Params required');
|
|
8
|
+
const previous = MOCK_CART.shippingTotal ?? 0;
|
|
9
|
+
if (params.optionId === null) {
|
|
10
|
+
MOCK_CART.shipping = null;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const option = mockShippingOptions().resolution.options.find((o) => o.optionId === params.optionId);
|
|
14
|
+
if (!option)
|
|
15
|
+
throw new Error('selectShippingOption: this option is not offered for this cart');
|
|
16
|
+
MOCK_CART.shipping = {
|
|
17
|
+
zoneId: option.zoneId,
|
|
18
|
+
optionId: option.optionId,
|
|
19
|
+
type: option.type,
|
|
20
|
+
name: option.name,
|
|
21
|
+
amount: option.amount,
|
|
22
|
+
minDays: option.minDays,
|
|
23
|
+
maxDays: option.maxDays,
|
|
24
|
+
outletId: option.outletId,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
MOCK_CART.shippingTotal = MOCK_CART.shipping?.amount ?? 0;
|
|
28
|
+
MOCK_CART.total += MOCK_CART.shippingTotal - previous;
|
|
29
|
+
mockPublishEvent('cart', 'cart-updated', { shipping: MOCK_CART.shipping });
|
|
30
|
+
return { shipping: MOCK_CART.shipping, cart: MOCK_CART, timestamp: new Date().toISOString() };
|
|
31
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CFActiveCart, CFCartShipping } from '../../CommonTypes';
|
|
2
|
+
export interface SelectShippingOptionParams {
|
|
3
|
+
/** An `optionId` from `getShippingOptions`. `null` takes shipping off the cart. */
|
|
4
|
+
optionId: string | null;
|
|
5
|
+
}
|
|
6
|
+
export interface SelectShippingOptionResponse {
|
|
7
|
+
shipping: CFCartShipping | null;
|
|
8
|
+
cart: CFActiveCart;
|
|
9
|
+
timestamp: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* THROWS for an option this cart isn't offered: one from another address, a
|
|
13
|
+
* website-only option at the till, or one the store has since removed.
|
|
14
|
+
*/
|
|
15
|
+
export type SelectShippingOption = (params: SelectShippingOptionParams) => Promise<SelectShippingOptionResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SetOrderAddress action
|
|
3
|
+
* Calls the setOrderAddress action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from '../../client';
|
|
6
|
+
export const setOrderAddress = async (params) => {
|
|
7
|
+
return await commandFrameClient.call('setOrderAddress', params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SetOrderAddress } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Standalone mock of putting an address on the cart. It refuses what the runtime refuses (no
|
|
4
|
+
* country, an unreadable one, a shipping address without street and city) so a checkout form
|
|
5
|
+
* that looks finished in preview doesn't lose orders on the published site.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mockSetOrderAddress: SetOrderAddress;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { normalizeAddress } from '@final-commerce/common';
|
|
2
|
+
import { MOCK_CART, mockPublishEvent } from '../../demo/database';
|
|
3
|
+
/**
|
|
4
|
+
* Standalone mock of putting an address on the cart. It refuses what the runtime refuses (no
|
|
5
|
+
* country, an unreadable one, a shipping address without street and city) so a checkout form
|
|
6
|
+
* that looks finished in preview doesn't lose orders on the published site.
|
|
7
|
+
*/
|
|
8
|
+
export const mockSetOrderAddress = async (params) => {
|
|
9
|
+
console.log('[Mock] setOrderAddress called', params);
|
|
10
|
+
if (!params || (params.type !== 'shipping' && params.type !== 'billing')) {
|
|
11
|
+
throw new Error("setOrderAddress: type must be 'shipping' or 'billing'");
|
|
12
|
+
}
|
|
13
|
+
const key = params.type === 'shipping' ? 'shippingAddress' : 'billingAddress';
|
|
14
|
+
let address = params.address;
|
|
15
|
+
if (address) {
|
|
16
|
+
const read = normalizeAddress(address);
|
|
17
|
+
if (!read.country)
|
|
18
|
+
throw new Error('setOrderAddress: choose a country');
|
|
19
|
+
if (params.type === 'shipping' && (!address.address1?.trim() || !address.city?.trim())) {
|
|
20
|
+
throw new Error('setOrderAddress: a shipping address needs a street and a city');
|
|
21
|
+
}
|
|
22
|
+
address = { ...address, country: read.country, state: read.province ?? address.state, fromCustomer: false };
|
|
23
|
+
}
|
|
24
|
+
MOCK_CART[key] = address;
|
|
25
|
+
if (params.type === 'shipping')
|
|
26
|
+
MOCK_CART.shipping = null;
|
|
27
|
+
mockPublishEvent('cart', 'cart-updated', { [key]: address });
|
|
28
|
+
return { address, cart: MOCK_CART, timestamp: new Date().toISOString() };
|
|
29
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CFActiveCart, CFCartAddress } from '../../CommonTypes';
|
|
2
|
+
export type OrderAddressType = 'shipping' | 'billing';
|
|
3
|
+
export interface SetOrderAddressParams {
|
|
4
|
+
type: OrderAddressType;
|
|
5
|
+
/** `null` clears it. Country and province may be codes or names; the runtime stores codes. */
|
|
6
|
+
address: CFCartAddress | null;
|
|
7
|
+
}
|
|
8
|
+
export interface SetOrderAddressResponse {
|
|
9
|
+
/** As stored: country as ISO-2, province as its code, postal code tidied. */
|
|
10
|
+
address: CFCartAddress | null;
|
|
11
|
+
/** The cart after the change. A new shipping address re-checks the chosen shipping option. */
|
|
12
|
+
cart: CFActiveCart;
|
|
13
|
+
timestamp: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* THROWS when the address can't be used: no country, a country we can't read, or a
|
|
17
|
+
* shipping address without a street and city. The message says which, for the form.
|
|
18
|
+
*/
|
|
19
|
+
export type SetOrderAddress = (params: SetOrderAddressParams) => Promise<SetOrderAddressResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ShippingZoneRule } from '@final-commerce/common';
|
|
2
|
+
import type { ShippingOptionView } from '../actions/get-shipping-options/types';
|
|
3
|
+
export declare const MOCK_SHIPPING_ZONES: ShippingZoneRule[];
|
|
4
|
+
/** The demo cart's options, shaped like the runtime's answer. The mock runs as the website. */
|
|
5
|
+
export declare function mockShippingOptions(): {
|
|
6
|
+
resolution: import("@final-commerce/common").ShippingResolution;
|
|
7
|
+
options: ShippingOptionView[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { resolveShipping } from '@final-commerce/common';
|
|
2
|
+
import { MOCK_CART, MOCK_OUTLET_MAIN } from './database';
|
|
3
|
+
/*
|
|
4
|
+
* The demo store's Settings › Shipping, so a flow previewed against the mocks meets the real rules
|
|
5
|
+
* (common's `resolveShipping`) rather than a canned list: Canada $10 (free over $100) or Express,
|
|
6
|
+
* Quebec at $15, pickup at the demo store, and nowhere else.
|
|
7
|
+
*/
|
|
8
|
+
export const MOCK_SHIPPING_ZONES = [
|
|
9
|
+
{
|
|
10
|
+
id: 'zone_canada',
|
|
11
|
+
kind: 'country',
|
|
12
|
+
places: [{ country: 'CA' }],
|
|
13
|
+
ships: true,
|
|
14
|
+
options: [
|
|
15
|
+
{
|
|
16
|
+
id: 'opt_standard',
|
|
17
|
+
type: 'ship',
|
|
18
|
+
name: 'Standard shipping',
|
|
19
|
+
price: 1000,
|
|
20
|
+
freeOver: 10000,
|
|
21
|
+
minDays: 3,
|
|
22
|
+
maxDays: 6,
|
|
23
|
+
channels: ['web', 'pos'],
|
|
24
|
+
},
|
|
25
|
+
{ id: 'opt_express', type: 'ship', name: 'Express', price: 2000, minDays: 1, maxDays: 2, channels: ['web'] },
|
|
26
|
+
{ id: 'opt_pickup', type: 'pickup', price: 0, channels: ['web'], outletId: MOCK_OUTLET_MAIN.id },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'zone_quebec',
|
|
31
|
+
kind: 'province',
|
|
32
|
+
places: [{ country: 'CA', province: 'QC' }],
|
|
33
|
+
ships: true,
|
|
34
|
+
options: [
|
|
35
|
+
{
|
|
36
|
+
id: 'opt_quebec',
|
|
37
|
+
type: 'ship',
|
|
38
|
+
name: 'Standard shipping',
|
|
39
|
+
price: 1500,
|
|
40
|
+
minDays: 4,
|
|
41
|
+
maxDays: 7,
|
|
42
|
+
channels: ['web', 'pos'],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
const STORE_NAME = MOCK_OUTLET_MAIN.name ?? 'the store';
|
|
48
|
+
const money = (amount) => (amount === 0 ? 'Free' : `$${(amount / 100).toFixed(2)}`);
|
|
49
|
+
/** The demo cart's options, shaped like the runtime's answer. The mock runs as the website. */
|
|
50
|
+
export function mockShippingOptions() {
|
|
51
|
+
const resolution = resolveShipping({
|
|
52
|
+
zones: MOCK_SHIPPING_ZONES,
|
|
53
|
+
address: MOCK_CART.shippingAddress,
|
|
54
|
+
itemsTotal: MOCK_CART.subtotal,
|
|
55
|
+
channel: 'web',
|
|
56
|
+
});
|
|
57
|
+
const options = resolution.options.map((option) => ({
|
|
58
|
+
optionId: option.optionId,
|
|
59
|
+
type: option.type,
|
|
60
|
+
name: option.type === 'pickup' ? `Pickup at ${STORE_NAME}` : (option.name ?? ''),
|
|
61
|
+
amount: option.amount,
|
|
62
|
+
priceText: money(option.amount),
|
|
63
|
+
freeShippingHint: option.amountToFree ? `Add ${money(option.amountToFree)} more for free shipping` : null,
|
|
64
|
+
arrivalText: option.minDays != null ? `Arrives in ${option.minDays}–${option.maxDays} business days` : null,
|
|
65
|
+
pickup: option.type === 'pickup' ? { outletId: MOCK_OUTLET_MAIN.id, name: STORE_NAME, hours: [] } : null,
|
|
66
|
+
selected: MOCK_CART.shipping?.optionId === option.optionId,
|
|
67
|
+
}));
|
|
68
|
+
return { resolution, options };
|
|
69
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -55,6 +55,10 @@ export declare const command: {
|
|
|
55
55
|
readonly chargeMoto: import(".").ChargeMoto;
|
|
56
56
|
readonly startCheckout: import(".").StartCheckout;
|
|
57
57
|
readonly attachCheckoutContact: import(".").AttachCheckoutContact;
|
|
58
|
+
readonly getAddressOptions: import(".").GetAddressOptions;
|
|
59
|
+
readonly setOrderAddress: import(".").SetOrderAddress;
|
|
60
|
+
readonly getShippingOptions: import(".").GetShippingOptions;
|
|
61
|
+
readonly selectShippingOption: import(".").SelectShippingOption;
|
|
58
62
|
readonly setOutlet: import(".").SetOutlet;
|
|
59
63
|
readonly resumeCheckout: import(".").ResumeCheckout;
|
|
60
64
|
readonly addCustomerNote: import(".").AddCustomerNote;
|
|
@@ -204,6 +208,10 @@ export type { CreatePaymentLink, CreatePaymentLinkParams, CreatePaymentLinkRespo
|
|
|
204
208
|
export type { ChargeMoto, ChargeMotoParams, ChargeMotoResponse, ChargeMotoCardFields, } from './actions/charge-moto/types';
|
|
205
209
|
export type { StartCheckout, StartCheckoutParams, StartCheckoutResponse, StartCheckoutContact, StartCheckoutOrder, } from './actions/start-checkout/types';
|
|
206
210
|
export type { AttachCheckoutContact, AttachCheckoutContactParams, AttachCheckoutContactResponse, } from './actions/attach-checkout-contact/types';
|
|
211
|
+
export type { GetAddressOptions, GetAddressOptionsParams, GetAddressOptionsResponse, AddressCountryOption, AddressProvinceOption, } from './actions/get-address-options/types';
|
|
212
|
+
export type { SetOrderAddress, SetOrderAddressParams, SetOrderAddressResponse, OrderAddressType, } from './actions/set-order-address/types';
|
|
213
|
+
export type { GetShippingOptions, GetShippingOptionsResponse, ShippingOptionView, ShippingPickupView, } from './actions/get-shipping-options/types';
|
|
214
|
+
export type { SelectShippingOption, SelectShippingOptionParams, SelectShippingOptionResponse, } from './actions/select-shipping-option/types';
|
|
207
215
|
export type { SetOutlet, SetOutletParams, SetOutletResponse } from './actions/set-outlet/types';
|
|
208
216
|
export type { ResumeCheckout, ResumeCheckoutParams, ResumeCheckoutResponse, ResumeCheckoutResult, } from './actions/resume-checkout/types';
|
|
209
217
|
export type { AddCustomerNote, AddCustomerNoteParams, AddCustomerNoteResponse, } from './actions/add-customer-note/types';
|
package/dist/index.js
CHANGED
|
@@ -55,6 +55,10 @@ import { createPaymentLink } from './actions/create-payment-link/action';
|
|
|
55
55
|
import { chargeMoto } from './actions/charge-moto/action';
|
|
56
56
|
import { startCheckout } from './actions/start-checkout/action';
|
|
57
57
|
import { attachCheckoutContact } from './actions/attach-checkout-contact/action';
|
|
58
|
+
import { getAddressOptions } from './actions/get-address-options/action';
|
|
59
|
+
import { setOrderAddress } from './actions/set-order-address/action';
|
|
60
|
+
import { getShippingOptions } from './actions/get-shipping-options/action';
|
|
61
|
+
import { selectShippingOption } from './actions/select-shipping-option/action';
|
|
58
62
|
import { setOutlet } from './actions/set-outlet/action';
|
|
59
63
|
import { resumeCheckout } from './actions/resume-checkout/action';
|
|
60
64
|
// Customer Actions
|
|
@@ -206,6 +210,10 @@ export const command = {
|
|
|
206
210
|
chargeMoto,
|
|
207
211
|
startCheckout,
|
|
208
212
|
attachCheckoutContact,
|
|
213
|
+
getAddressOptions,
|
|
214
|
+
setOrderAddress,
|
|
215
|
+
getShippingOptions,
|
|
216
|
+
selectShippingOption,
|
|
209
217
|
setOutlet,
|
|
210
218
|
resumeCheckout,
|
|
211
219
|
// Customer Actions
|
|
@@ -36,6 +36,10 @@ import { mockCreatePaymentLink } from '../../actions/create-payment-link/mock';
|
|
|
36
36
|
import { mockChargeMoto } from '../../actions/charge-moto/mock';
|
|
37
37
|
import { mockStartCheckout } from '../../actions/start-checkout/mock';
|
|
38
38
|
import { mockAttachCheckoutContact } from '../../actions/attach-checkout-contact/mock';
|
|
39
|
+
import { mockGetAddressOptions } from '../../actions/get-address-options/mock';
|
|
40
|
+
import { mockSetOrderAddress } from '../../actions/set-order-address/mock';
|
|
41
|
+
import { mockGetShippingOptions } from '../../actions/get-shipping-options/mock';
|
|
42
|
+
import { mockSelectShippingOption } from '../../actions/select-shipping-option/mock';
|
|
39
43
|
import { mockGetOutlets } from '../../actions/get-outlets/mock';
|
|
40
44
|
import { mockSetOutlet } from '../../actions/set-outlet/mock';
|
|
41
45
|
import { mockResumeCheckout } from '../../actions/resume-checkout/mock';
|
|
@@ -148,6 +152,10 @@ export const RENDER_MOCKS = {
|
|
|
148
152
|
chargeMoto: mockChargeMoto,
|
|
149
153
|
startCheckout: mockStartCheckout,
|
|
150
154
|
attachCheckoutContact: mockAttachCheckoutContact,
|
|
155
|
+
getAddressOptions: mockGetAddressOptions,
|
|
156
|
+
setOrderAddress: mockSetOrderAddress,
|
|
157
|
+
getShippingOptions: mockGetShippingOptions,
|
|
158
|
+
selectShippingOption: mockSelectShippingOption,
|
|
151
159
|
getOutlets: mockGetOutlets,
|
|
152
160
|
setOutlet: mockSetOutlet,
|
|
153
161
|
resumeCheckout: mockResumeCheckout,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, GetCustomStockActions, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, GetProductModifierSelections, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, RedeemRefund, GetRefundPlan, CheckPermission, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount, GetActiveOrder, GetActiveCustomer, SetActiveCustomer, GetActiveOutlet, GetActiveStation, GetActiveSession, GetActiveUser, SetActiveUser, SetActiveRefund, RemoveProductDiscount, RemoveProductFee, RemoveProductNote, RemoveCartFee, RemoveOrderNote, RemoveCustomSale, RemoveNonRevenueItem, CanTransition, GetAvailableTransitions, ApplyTransition, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms, GetBookingResources, GetBookingAvailability, GetBookings, HoldBooking, AddBookingToCart, RemoveBookingFromCart, CancelBooking, CreatePaymentLink, ChargeMoto, StartCheckout, AttachCheckoutContact, GetOutlets, SetOutlet, ResumeCheckout, GetTimeClockStatus } from '../../index';
|
|
1
|
+
import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, GetCustomStockActions, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, GetProductModifierSelections, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, RedeemRefund, GetRefundPlan, CheckPermission, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount, GetActiveOrder, GetActiveCustomer, SetActiveCustomer, GetActiveOutlet, GetActiveStation, GetActiveSession, GetActiveUser, SetActiveUser, SetActiveRefund, RemoveProductDiscount, RemoveProductFee, RemoveProductNote, RemoveCartFee, RemoveOrderNote, RemoveCustomSale, RemoveNonRevenueItem, CanTransition, GetAvailableTransitions, ApplyTransition, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms, GetBookingResources, GetBookingAvailability, GetBookings, HoldBooking, AddBookingToCart, RemoveBookingFromCart, CancelBooking, CreatePaymentLink, ChargeMoto, StartCheckout, AttachCheckoutContact, GetAddressOptions, SetOrderAddress, GetShippingOptions, SelectShippingOption, GetOutlets, SetOutlet, ResumeCheckout, GetTimeClockStatus } from '../../index';
|
|
2
2
|
export interface RenderProviderActions {
|
|
3
3
|
exampleFunction: ExampleFunction;
|
|
4
4
|
getProducts: GetProducts;
|
|
@@ -60,6 +60,11 @@ export interface RenderProviderActions {
|
|
|
60
60
|
*/
|
|
61
61
|
startCheckout: StartCheckout;
|
|
62
62
|
attachCheckoutContact: AttachCheckoutContact;
|
|
63
|
+
/** Shipping, on the till (ship-to) and the website alike. The runtime prices; the flow renders. */
|
|
64
|
+
getAddressOptions: GetAddressOptions;
|
|
65
|
+
setOrderAddress: SetOrderAddress;
|
|
66
|
+
getShippingOptions: GetShippingOptions;
|
|
67
|
+
selectShippingOption: SelectShippingOption;
|
|
63
68
|
getOutlets: GetOutlets;
|
|
64
69
|
setOutlet: SetOutlet;
|
|
65
70
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@final-commerce/command-frame",
|
|
3
|
-
"version": "0.9.0-online.
|
|
3
|
+
"version": "0.9.0-online.3",
|
|
4
4
|
"description": "Commands Frame library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"ignoreBranchesMissingTickets": true
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@final-commerce/common": "2.5.1-online.
|
|
60
|
+
"@final-commerce/common": "2.5.1-online.4"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@commitlint/cli": "^19.0.0",
|