@final-commerce/command-frame 0.8.1-online.2 → 0.9.0-online.2

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.
Files changed (41) hide show
  1. package/dist/CommonTypes.d.ts +3 -1
  2. package/dist/actions/adjust-inventory/mock.js +20 -0
  3. package/dist/actions/adjust-inventory/types.d.ts +13 -0
  4. package/dist/actions/adjust-inventory/types.js +1 -0
  5. package/dist/actions/get-address-options/action.d.ts +6 -0
  6. package/dist/actions/get-address-options/action.js +8 -0
  7. package/dist/actions/get-address-options/mock.d.ts +3 -0
  8. package/dist/actions/get-address-options/mock.js +15 -0
  9. package/dist/actions/get-address-options/types.d.ts +25 -0
  10. package/dist/actions/get-address-options/types.js +8 -0
  11. package/dist/actions/get-custom-stock-actions/action.d.ts +5 -0
  12. package/dist/actions/get-custom-stock-actions/action.js +7 -0
  13. package/dist/actions/get-custom-stock-actions/mock.d.ts +2 -0
  14. package/dist/actions/get-custom-stock-actions/mock.js +11 -0
  15. package/dist/actions/get-custom-stock-actions/types.d.ts +12 -0
  16. package/dist/actions/get-custom-stock-actions/types.js +2 -0
  17. package/dist/actions/get-shipping-options/action.d.ts +6 -0
  18. package/dist/actions/get-shipping-options/action.js +8 -0
  19. package/dist/actions/get-shipping-options/mock.d.ts +3 -0
  20. package/dist/actions/get-shipping-options/mock.js +15 -0
  21. package/dist/actions/get-shipping-options/types.d.ts +43 -0
  22. package/dist/actions/get-shipping-options/types.js +1 -0
  23. package/dist/actions/select-shipping-option/action.d.ts +6 -0
  24. package/dist/actions/select-shipping-option/action.js +8 -0
  25. package/dist/actions/select-shipping-option/mock.d.ts +3 -0
  26. package/dist/actions/select-shipping-option/mock.js +31 -0
  27. package/dist/actions/select-shipping-option/types.d.ts +15 -0
  28. package/dist/actions/select-shipping-option/types.js +1 -0
  29. package/dist/actions/set-order-address/action.d.ts +6 -0
  30. package/dist/actions/set-order-address/action.js +8 -0
  31. package/dist/actions/set-order-address/mock.d.ts +7 -0
  32. package/dist/actions/set-order-address/mock.js +29 -0
  33. package/dist/actions/set-order-address/types.d.ts +19 -0
  34. package/dist/actions/set-order-address/types.js +1 -0
  35. package/dist/demo/shipping.d.ts +8 -0
  36. package/dist/demo/shipping.js +69 -0
  37. package/dist/index.d.ts +11 -1
  38. package/dist/index.js +10 -0
  39. package/dist/projects/render/mocks.js +10 -0
  40. package/dist/projects/render/types.d.ts +7 -1
  41. package/package.json +2 -2
@@ -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']`. */
@@ -1,6 +1,26 @@
1
1
  import { MOCK_PRODUCTS } from '../../demo/database';
2
+ // Same rules and messages as the kaching handler.
3
+ const STOCK_TYPE_BY_REASON = {
4
+ STOCK_RECEIVED: 'add',
5
+ RESTOCK_RETURN: 'add',
6
+ DAMAGE: 'subtract',
7
+ THEFT: 'subtract',
8
+ LOSS: 'subtract',
9
+ INVENTORY_RECOUNT: 'set',
10
+ };
2
11
  export const mockAdjustInventory = async (params) => {
3
12
  console.log('[Mock] adjustInventory called', params);
13
+ if (params?.specificAction != null) {
14
+ const { specificAction, stockType, customActionId } = params;
15
+ if (customActionId)
16
+ throw new Error('Pass either customActionId or specificAction, not both');
17
+ const reasonStockType = STOCK_TYPE_BY_REASON[specificAction];
18
+ if (!reasonStockType)
19
+ throw new Error(`Unknown specificAction: ${specificAction}`);
20
+ if (reasonStockType !== stockType) {
21
+ throw new Error(`specificAction ${specificAction} requires stockType '${reasonStockType}', got '${stockType}'`);
22
+ }
23
+ }
4
24
  let newStock = 0;
5
25
  // Real handler keys off variantId (falling back to the active product's
6
26
  // variant); mirror that here by finding the owning product for the variant.
@@ -1,3 +1,5 @@
1
+ /** The manual reasons a person can pick, as hub-api's InventorySpecificActionType names them. */
2
+ export type ManualStockReason = 'STOCK_RECEIVED' | 'RESTOCK_RETURN' | 'DAMAGE' | 'THEFT' | 'LOSS' | 'INVENTORY_RECOUNT';
1
3
  export interface AdjustInventoryParams {
2
4
  /** String to preserve precision. */
3
5
  amount: string;
@@ -5,6 +7,17 @@ export interface AdjustInventoryParams {
5
7
  stockType: 'add' | 'subtract' | 'set';
6
8
  /** Variant to adjust. Omit to use the active product's selected variant. */
7
9
  variantId?: string;
10
+ /**
11
+ * A company action from getCustomStockActions. The movement is recorded under its name;
12
+ * `stockType` must match its baseAction (ADD → 'add', REMOVE → 'subtract', RECOUNT → 'set').
13
+ */
14
+ customActionId?: string;
15
+ /**
16
+ * A built-in reason to record instead of the host's default for `stockType`. Must match it:
17
+ * STOCK_RECEIVED / RESTOCK_RETURN → 'add', DAMAGE / THEFT / LOSS → 'subtract', INVENTORY_RECOUNT → 'set'.
18
+ * Rejected together with `customActionId`.
19
+ */
20
+ specificAction?: ManualStockReason;
8
21
  }
9
22
  export interface AdjustInventoryResponse {
10
23
  success: boolean;
@@ -1 +1,2 @@
1
+ // Adjust Inventory Types
1
2
  export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * GetAddressOptions action
3
+ * Calls the getAddressOptions action on the parent window
4
+ */
5
+ import type { GetAddressOptions } from './types';
6
+ export declare const getAddressOptions: GetAddressOptions;
@@ -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,3 @@
1
+ import type { GetAddressOptions } from './types';
2
+ /** Standalone mock: the same country and province lists the runtime serves. The demo store is in Canada. */
3
+ export declare const mockGetAddressOptions: GetAddressOptions;
@@ -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,5 @@
1
+ /**
2
+ * Get custom stock actions action — the company's own stock adjustment actions.
3
+ */
4
+ import type { GetCustomStockActions } from './types';
5
+ export declare const getCustomStockActions: GetCustomStockActions;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Get custom stock actions action — the company's own stock adjustment actions.
3
+ */
4
+ import { commandFrameClient } from '../../client';
5
+ export const getCustomStockActions = async () => {
6
+ return await commandFrameClient.call('getCustomStockActions');
7
+ };
@@ -0,0 +1,2 @@
1
+ import { GetCustomStockActions } from './types';
2
+ export declare const mockGetCustomStockActions: GetCustomStockActions;
@@ -0,0 +1,11 @@
1
+ export const mockGetCustomStockActions = async () => {
2
+ console.log('[Mock] getCustomStockActions called');
3
+ return {
4
+ customStockActions: [
5
+ { _id: 'mock_custom_action_1', name: 'Opening stock', baseAction: 'ADD' },
6
+ { _id: 'mock_custom_action_2', name: 'Exhibition loan', baseAction: 'REMOVE' },
7
+ { _id: 'mock_custom_action_3', name: 'Year-end count', baseAction: 'RECOUNT' },
8
+ ],
9
+ timestamp: new Date().toISOString(),
10
+ };
11
+ };
@@ -0,0 +1,12 @@
1
+ export interface CustomStockActionPayload {
2
+ _id: string;
3
+ /** Name the company gave the action, shown in pickers and stock history. */
4
+ name: string;
5
+ /** What the action does to stock — pass the matching `stockType` to adjustInventory. */
6
+ baseAction: 'ADD' | 'REMOVE' | 'RECOUNT';
7
+ }
8
+ export interface GetCustomStockActionsResponse {
9
+ customStockActions: CustomStockActionPayload[];
10
+ timestamp: string;
11
+ }
12
+ export type GetCustomStockActions = () => Promise<GetCustomStockActionsResponse>;
@@ -0,0 +1,2 @@
1
+ // Get Custom Stock Actions Types
2
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * GetShippingOptions action
3
+ * Calls the getShippingOptions action on the parent window
4
+ */
5
+ import type { GetShippingOptions } from './types';
6
+ export declare const getShippingOptions: GetShippingOptions;
@@ -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,3 @@
1
+ import type { GetShippingOptions } from './types';
2
+ /** Standalone mock: the demo store's zones run through the real resolver, as the website would. */
3
+ export declare const mockGetShippingOptions: GetShippingOptions;
@@ -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,6 @@
1
+ /**
2
+ * SelectShippingOption action
3
+ * Calls the selectShippingOption action on the parent window
4
+ */
5
+ import type { SelectShippingOption } from './types';
6
+ export declare const selectShippingOption: SelectShippingOption;
@@ -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,3 @@
1
+ import type { SelectShippingOption } from './types';
2
+ /** Standalone mock: refuses an option the cart isn't offered, like the runtime does. */
3
+ export declare const mockSelectShippingOption: SelectShippingOption;
@@ -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,6 @@
1
+ /**
2
+ * SetOrderAddress action
3
+ * Calls the setOrderAddress action on the parent window
4
+ */
5
+ import type { SetOrderAddress } from './types';
6
+ export declare const setOrderAddress: SetOrderAddress;
@@ -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
@@ -35,6 +35,7 @@ export declare const command: {
35
35
  readonly getActiveProduct: import(".").GetActiveProduct;
36
36
  readonly setActiveProduct: import(".").SetActiveProduct;
37
37
  readonly adjustInventory: import(".").AdjustInventory;
38
+ readonly getCustomStockActions: import(".").GetCustomStockActions;
38
39
  readonly addOrderNote: import(".").AddOrderNote;
39
40
  readonly addCartFee: import(".").AddCartFee;
40
41
  readonly getCurrentCart: import(".").GetCurrentCart;
@@ -54,6 +55,10 @@ export declare const command: {
54
55
  readonly chargeMoto: import(".").ChargeMoto;
55
56
  readonly startCheckout: import(".").StartCheckout;
56
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;
57
62
  readonly setOutlet: import(".").SetOutlet;
58
63
  readonly resumeCheckout: import(".").ResumeCheckout;
59
64
  readonly addCustomerNote: import(".").AddCustomerNote;
@@ -183,7 +188,8 @@ export type { SetActiveProductFee, SetActiveProductFeeParams, SetActiveProductFe
183
188
  export type { SetActiveProductDiscount, SetActiveProductDiscountParams, SetActiveProductDiscountResponse, } from './actions/set-active-product-discount/types';
184
189
  export type { GetActiveProduct, GetActiveProductResponse } from './actions/get-active-product/types';
185
190
  export type { SetActiveProduct, SetActiveProductParams, SetActiveProductResponse, } from './actions/set-active-product/types';
186
- export type { AdjustInventory, AdjustInventoryParams, AdjustInventoryResponse } from './actions/adjust-inventory/types';
191
+ export type { AdjustInventory, AdjustInventoryParams, AdjustInventoryResponse, ManualStockReason, } from './actions/adjust-inventory/types';
192
+ export type { CustomStockActionPayload, GetCustomStockActions, GetCustomStockActionsResponse, } from './actions/get-custom-stock-actions/types';
187
193
  export type { AddOrderNote, AddOrderNoteParams, AddOrderNoteResponse } from './actions/add-order-note/types';
188
194
  export type { AddCartFee, AddCartFeeParams, AddCartFeeResponse } from './actions/add-cart-fee/types';
189
195
  export type { ClearCart, ClearCartResponse } from './actions/clear-cart/types';
@@ -202,6 +208,10 @@ export type { CreatePaymentLink, CreatePaymentLinkParams, CreatePaymentLinkRespo
202
208
  export type { ChargeMoto, ChargeMotoParams, ChargeMotoResponse, ChargeMotoCardFields, } from './actions/charge-moto/types';
203
209
  export type { StartCheckout, StartCheckoutParams, StartCheckoutResponse, StartCheckoutContact, StartCheckoutOrder, } from './actions/start-checkout/types';
204
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';
205
215
  export type { SetOutlet, SetOutletParams, SetOutletResponse } from './actions/set-outlet/types';
206
216
  export type { ResumeCheckout, ResumeCheckoutParams, ResumeCheckoutResponse, ResumeCheckoutResult, } from './actions/resume-checkout/types';
207
217
  export type { AddCustomerNote, AddCustomerNoteParams, AddCustomerNoteResponse, } from './actions/add-customer-note/types';
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ import { setActiveProductDiscount } from './actions/set-active-product-discount/
34
34
  import { getActiveProduct } from './actions/get-active-product/action';
35
35
  import { setActiveProduct } from './actions/set-active-product/action';
36
36
  import { adjustInventory } from './actions/adjust-inventory/action';
37
+ import { getCustomStockActions } from './actions/get-custom-stock-actions/action';
37
38
  // Order Actions
38
39
  import { addOrderNote } from './actions/add-order-note/action';
39
40
  import { addCartFee } from './actions/add-cart-fee/action';
@@ -54,6 +55,10 @@ import { createPaymentLink } from './actions/create-payment-link/action';
54
55
  import { chargeMoto } from './actions/charge-moto/action';
55
56
  import { startCheckout } from './actions/start-checkout/action';
56
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';
57
62
  import { setOutlet } from './actions/set-outlet/action';
58
63
  import { resumeCheckout } from './actions/resume-checkout/action';
59
64
  // Customer Actions
@@ -184,6 +189,7 @@ export const command = {
184
189
  getActiveProduct,
185
190
  setActiveProduct,
186
191
  adjustInventory,
192
+ getCustomStockActions,
187
193
  // Order Actions
188
194
  addOrderNote,
189
195
  addCartFee,
@@ -204,6 +210,10 @@ export const command = {
204
210
  chargeMoto,
205
211
  startCheckout,
206
212
  attachCheckoutContact,
213
+ getAddressOptions,
214
+ setOrderAddress,
215
+ getShippingOptions,
216
+ selectShippingOption,
207
217
  setOutlet,
208
218
  resumeCheckout,
209
219
  // Customer Actions
@@ -26,6 +26,7 @@ import { mockRemoveProductFromCart } from '../../actions/remove-product-from-car
26
26
  import { mockRemoveCartDiscount } from '../../actions/remove-cart-discount/mock';
27
27
  import { mockUpdateCartItemQuantity } from '../../actions/update-cart-item-quantity/mock';
28
28
  import { mockAdjustInventory } from '../../actions/adjust-inventory/mock';
29
+ import { mockGetCustomStockActions } from '../../actions/get-custom-stock-actions/mock';
29
30
  import { mockAssignCustomer } from '../../actions/assign-customer/mock';
30
31
  import { mockAuthenticateUser } from '../../actions/authenticate-user/mock';
31
32
  import { mockCalculateRefundTotal } from '../../actions/calculate-refund-total/mock';
@@ -35,6 +36,10 @@ import { mockCreatePaymentLink } from '../../actions/create-payment-link/mock';
35
36
  import { mockChargeMoto } from '../../actions/charge-moto/mock';
36
37
  import { mockStartCheckout } from '../../actions/start-checkout/mock';
37
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';
38
43
  import { mockGetOutlets } from '../../actions/get-outlets/mock';
39
44
  import { mockSetOutlet } from '../../actions/set-outlet/mock';
40
45
  import { mockResumeCheckout } from '../../actions/resume-checkout/mock';
@@ -137,6 +142,7 @@ export const RENDER_MOCKS = {
137
142
  removeProductFromCart: mockRemoveProductFromCart,
138
143
  updateCartItemQuantity: mockUpdateCartItemQuantity,
139
144
  adjustInventory: mockAdjustInventory,
145
+ getCustomStockActions: mockGetCustomStockActions,
140
146
  assignCustomer: mockAssignCustomer,
141
147
  authenticateUser: mockAuthenticateUser,
142
148
  calculateRefundTotal: mockCalculateRefundTotal,
@@ -146,6 +152,10 @@ export const RENDER_MOCKS = {
146
152
  chargeMoto: mockChargeMoto,
147
153
  startCheckout: mockStartCheckout,
148
154
  attachCheckoutContact: mockAttachCheckoutContact,
155
+ getAddressOptions: mockGetAddressOptions,
156
+ setOrderAddress: mockSetOrderAddress,
157
+ getShippingOptions: mockGetShippingOptions,
158
+ selectShippingOption: mockSelectShippingOption,
149
159
  getOutlets: mockGetOutlets,
150
160
  setOutlet: mockSetOutlet,
151
161
  resumeCheckout: mockResumeCheckout,
@@ -1,4 +1,4 @@
1
- import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, 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;
@@ -35,6 +35,7 @@ export interface RenderProviderActions {
35
35
  getActiveProduct: GetActiveProduct;
36
36
  setActiveProduct: SetActiveProduct;
37
37
  adjustInventory: AdjustInventory;
38
+ getCustomStockActions: GetCustomStockActions;
38
39
  addOrderNote: AddOrderNote;
39
40
  addCartFee: AddCartFee;
40
41
  clearCart: ClearCart;
@@ -59,6 +60,11 @@ export interface RenderProviderActions {
59
60
  */
60
61
  startCheckout: StartCheckout;
61
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;
62
68
  getOutlets: GetOutlets;
63
69
  setOutlet: SetOutlet;
64
70
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.8.1-online.2",
3
+ "version": "0.9.0-online.2",
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.4.1-online.3"
60
+ "@final-commerce/common": "2.5.1-online.3"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@commitlint/cli": "^19.0.0",