@final-commerce/command-frame 0.1.10 → 0.1.12

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 (53) hide show
  1. package/dist/actions/add-cart-discount/types.d.ts +3 -0
  2. package/dist/actions/add-cart-fee/types.d.ts +4 -0
  3. package/dist/actions/add-custom-sale/mock.js +21 -1
  4. package/dist/actions/add-custom-sale/types.d.ts +1 -0
  5. package/dist/actions/add-customer/mock.js +1 -0
  6. package/dist/actions/add-customer/types.d.ts +1 -0
  7. package/dist/actions/add-customer-note/mock.js +13 -0
  8. package/dist/actions/add-order-note/mock.js +10 -0
  9. package/dist/actions/add-product-discount/mock.js +19 -0
  10. package/dist/actions/add-product-discount/types.d.ts +3 -0
  11. package/dist/actions/add-product-fee/mock.js +18 -0
  12. package/dist/actions/add-product-fee/types.d.ts +3 -0
  13. package/dist/actions/add-product-note/mock.js +11 -0
  14. package/dist/actions/add-product-note/types.d.ts +1 -0
  15. package/dist/actions/add-product-to-cart/types.d.ts +5 -0
  16. package/dist/actions/adjust-inventory/mock.js +26 -8
  17. package/dist/actions/adjust-inventory/types.d.ts +3 -0
  18. package/dist/actions/assign-customer/mock.js +1 -0
  19. package/dist/actions/calculate-refund-total/types.d.ts +1 -0
  20. package/dist/actions/cash-payment/action.js +5 -1
  21. package/dist/actions/cash-payment/mock.js +35 -3
  22. package/dist/actions/cash-payment/types.d.ts +2 -0
  23. package/dist/actions/delete-parked-order/mock.js +7 -0
  24. package/dist/actions/get-categories/types.d.ts +1 -0
  25. package/dist/actions/get-customers/types.d.ts +3 -0
  26. package/dist/actions/get-line-items-by-order/types.d.ts +1 -0
  27. package/dist/actions/get-orders/types.d.ts +5 -0
  28. package/dist/actions/get-products/types.d.ts +3 -0
  29. package/dist/actions/get-refunds/types.d.ts +4 -0
  30. package/dist/actions/initiate-refund/mock.js +1 -0
  31. package/dist/actions/initiate-refund/types.d.ts +1 -0
  32. package/dist/actions/open-cash-drawer/mock.js +1 -0
  33. package/dist/actions/park-order/mock.js +14 -2
  34. package/dist/actions/partial-payment/action.js +5 -1
  35. package/dist/actions/partial-payment/mock.js +7 -2
  36. package/dist/actions/partial-payment/types.d.ts +3 -0
  37. package/dist/actions/process-partial-refund/types.d.ts +4 -0
  38. package/dist/actions/remove-customer-from-cart/mock.js +1 -0
  39. package/dist/actions/resume-parked-order/mock.js +46 -2
  40. package/dist/actions/select-all-refund-items/types.d.ts +1 -0
  41. package/dist/actions/set-refund-stock-action/types.d.ts +1 -0
  42. package/dist/actions/show-confirmation/mock.js +4 -1
  43. package/dist/actions/show-notification/mock.js +1 -0
  44. package/dist/actions/switch-user/types.d.ts +2 -0
  45. package/dist/actions/tap-to-pay-payment/mock.js +2 -0
  46. package/dist/actions/tap-to-pay-payment/types.d.ts +1 -0
  47. package/dist/actions/terminal-payment/mock.js +4 -2
  48. package/dist/actions/terminal-payment/types.d.ts +1 -0
  49. package/dist/actions/trigger-webhook/types.d.ts +4 -0
  50. package/dist/actions/vendara-payment/types.d.ts +1 -0
  51. package/dist/demo/database.d.ts +1 -0
  52. package/dist/demo/database.js +1 -0
  53. package/package.json +1 -1
@@ -1,6 +1,9 @@
1
1
  export interface AddCartDiscountParams {
2
+ /** The discount amount. If isPercent is true, this is a percentage (0-100). */
2
3
  amount: number;
4
+ /** Defaults to `false`. */
3
5
  isPercent?: boolean;
6
+ /** Defaults to "Discount". */
4
7
  label?: string;
5
8
  }
6
9
  export interface AddCartDiscountResponse {
@@ -1,7 +1,11 @@
1
1
  export interface AddCartFeeParams {
2
+ /** The fee amount. If isPercent is true, this is a percentage. */
2
3
  amount: number;
4
+ /** Defaults to `false`. */
3
5
  isPercent?: boolean;
6
+ /** Defaults to "Fee". */
4
7
  label?: string;
8
+ /** Defaults to `false`. */
5
9
  applyTaxes?: boolean;
6
10
  taxTableId?: string;
7
11
  }
@@ -1,14 +1,34 @@
1
+ import { MOCK_CART } from "../../demo/database";
1
2
  export const mockAddCustomSale = async (params) => {
2
3
  console.log("[Mock] addCustomSale called", params);
3
4
  if (!params)
4
5
  throw new Error("Params required");
5
6
  // Simple mock ID generation
6
7
  const mockId = 'sale_' + Math.random().toString(36).substr(2, 9);
8
+ const price = Number(params.price);
9
+ const quantity = 1; // Default to 1 for custom sale usually
10
+ const customSale = {
11
+ id: mockId,
12
+ name: params.label,
13
+ price: price,
14
+ quantity: quantity,
15
+ applyTaxes: params.applyTaxes ?? false,
16
+ taxTableId: params.taxTableId
17
+ };
18
+ if (!MOCK_CART.customSales) {
19
+ MOCK_CART.customSales = [];
20
+ }
21
+ MOCK_CART.customSales.push(customSale);
22
+ // Update Cart Totals
23
+ MOCK_CART.subtotal += price * quantity;
24
+ MOCK_CART.total += price * quantity;
25
+ MOCK_CART.amountToBeCharged = MOCK_CART.total;
26
+ MOCK_CART.remainingBalance = MOCK_CART.total;
7
27
  return {
8
28
  success: true,
9
29
  customSaleId: mockId,
10
30
  label: params.label,
11
- price: Number(params.price),
31
+ price: price,
12
32
  applyTaxes: params.applyTaxes ?? false,
13
33
  timestamp: new Date().toISOString()
14
34
  };
@@ -2,6 +2,7 @@ export interface AddCustomSaleParams {
2
2
  label: string;
3
3
  price: number | string;
4
4
  applyTaxes?: boolean;
5
+ taxTableId?: string;
5
6
  }
6
7
  export interface AddCustomSaleResponse {
7
8
  success: boolean;
@@ -10,6 +10,7 @@ export const mockAddCustomer = async (params) => {
10
10
  updatedAt: new Date().toISOString()
11
11
  };
12
12
  MOCK_CUSTOMERS.push(newCustomer);
13
+ window.alert(`Demo: Customer Created!\nName: ${newCustomer.firstName} ${newCustomer.lastName}\nEmail: ${newCustomer.email}`);
13
14
  return {
14
15
  success: true,
15
16
  customer: newCustomer,
@@ -1,5 +1,6 @@
1
1
  import { CFCustomer } from "../../CommonTypes";
2
2
  export interface AddCustomerParams {
3
+ /** Requires all fields except those generated by the server/database. */
3
4
  customer: Omit<CFCustomer, '_id' | 'createdAt' | 'updatedAt'>;
4
5
  }
5
6
  export interface AddCustomerResponse {
@@ -1,5 +1,18 @@
1
+ import { MOCK_CUSTOMERS } from "../../demo/database";
1
2
  export const mockAddCustomerNote = async (params) => {
2
3
  console.log("[Mock] addCustomerNote called", params);
4
+ if (params?.customerId && params.note) {
5
+ const customer = MOCK_CUSTOMERS.find(c => c._id === params.customerId);
6
+ if (customer) {
7
+ if (!customer.notes) {
8
+ customer.notes = [];
9
+ }
10
+ customer.notes.push({
11
+ message: params.note,
12
+ createdAt: new Date().toISOString()
13
+ });
14
+ }
15
+ }
3
16
  return {
4
17
  success: true,
5
18
  customerId: params?.customerId || "",
@@ -1,5 +1,15 @@
1
+ import { MOCK_CART } from "../../demo/database";
1
2
  export const mockAddOrderNote = async (params) => {
2
3
  console.log("[Mock] addOrderNote called", params);
4
+ // In Render, AddOrderNote usually adds a note to the active cart if it's not checked out yet.
5
+ if (params?.note) {
6
+ if (MOCK_CART.orderNotes) {
7
+ MOCK_CART.orderNotes += "\n" + params.note;
8
+ }
9
+ else {
10
+ MOCK_CART.orderNotes = params.note;
11
+ }
12
+ }
3
13
  return {
4
14
  success: true,
5
15
  note: params?.note || "",
@@ -1,5 +1,24 @@
1
+ import { MOCK_CART } from "../../demo/database";
1
2
  export const mockAddProductDiscount = async (params) => {
2
3
  console.log("[Mock] addProductDiscount called", params);
4
+ if (params && (params.amount > 0 || params.amount < 0)) { // Allow 0 to clear discount if logic permits
5
+ let item = null;
6
+ if (params.cartItemId) {
7
+ item = MOCK_CART.products.find(p => p.internalId === params.cartItemId);
8
+ }
9
+ else if (MOCK_CART.products.length > 0) {
10
+ item = MOCK_CART.products[MOCK_CART.products.length - 1];
11
+ }
12
+ if (item) {
13
+ item.discount = {
14
+ value: params.amount,
15
+ isPercent: params.isPercent || false,
16
+ label: params.label
17
+ };
18
+ // Recalculate cart totals (simplified)
19
+ // Ideally, this should trigger a full recalculation function
20
+ }
21
+ }
3
22
  return {
4
23
  success: true,
5
24
  amount: params?.amount || 0,
@@ -1,6 +1,9 @@
1
1
  export interface AddProductDiscountParams {
2
+ /** The discount amount. If isPercent is true, this is a percentage. */
2
3
  amount: number;
4
+ /** Defaults to `false`. */
3
5
  isPercent?: boolean;
6
+ /** Defaults to "Discount". */
4
7
  label?: string;
5
8
  cartItemId?: string;
6
9
  }
@@ -1,5 +1,23 @@
1
+ import { MOCK_CART } from "../../demo/database";
1
2
  export const mockAddProductFee = async (params) => {
2
3
  console.log("[Mock] addProductFee called", params);
4
+ if (params) {
5
+ let item = null;
6
+ if (params.cartItemId) {
7
+ item = MOCK_CART.products.find(p => p.internalId === params.cartItemId);
8
+ }
9
+ else if (MOCK_CART.products.length > 0) {
10
+ item = MOCK_CART.products[MOCK_CART.products.length - 1];
11
+ }
12
+ if (item) {
13
+ item.fee = {
14
+ label: params.label || "Fee",
15
+ amount: params.amount,
16
+ isPercent: params.isPercent || false,
17
+ applyTaxes: params.applyTaxes || false
18
+ };
19
+ }
20
+ }
3
21
  return {
4
22
  success: true,
5
23
  amount: params?.amount || 0,
@@ -1,7 +1,10 @@
1
1
  export interface AddProductFeeParams {
2
2
  amount: number;
3
+ /** Defaults to `false`. */
3
4
  isPercent?: boolean;
5
+ /** Defaults to "Fee". */
4
6
  label?: string;
7
+ /** Defaults to `false`. */
5
8
  applyTaxes?: boolean;
6
9
  taxTableId?: string;
7
10
  cartItemId?: string;
@@ -1,5 +1,16 @@
1
+ import { MOCK_CART } from "../../demo/database";
1
2
  export const mockAddProductNote = async (params) => {
2
3
  console.log("[Mock] addProductNote called", params);
4
+ if (params?.note && params.cartItemId) {
5
+ const item = MOCK_CART.products.find(p => p.internalId === params.cartItemId);
6
+ if (item) {
7
+ item.note = params.note;
8
+ }
9
+ }
10
+ else if (params?.note && MOCK_CART.products.length > 0) {
11
+ // Fallback to last added item if no ID provided (common behavior in some POS flows)
12
+ MOCK_CART.products[MOCK_CART.products.length - 1].note = params.note;
13
+ }
3
14
  return {
4
15
  success: true,
5
16
  note: params?.note || "",
@@ -1,5 +1,6 @@
1
1
  export interface AddProductNoteParams {
2
2
  note: string;
3
+ /** The internalId of the cart item to modify. If not provided, it may attempt to modify the active product context. */
3
4
  cartItemId?: string;
4
5
  }
5
6
  export interface AddProductNoteResponse {
@@ -1,10 +1,15 @@
1
1
  import type { AddProductDiscountParams } from "../add-product-discount/types";
2
2
  import type { AddProductFeeParams } from "../add-product-fee/types";
3
3
  export interface AddProductToCartParams {
4
+ /** ID of the variant to add. Optional but recommended. */
4
5
  variantId?: string;
6
+ /** Defaults to 1. */
5
7
  quantity?: number;
8
+ /** Array of discounts to apply immediately. */
6
9
  discounts?: AddProductDiscountParams[];
10
+ /** Array of fees to apply immediately. */
7
11
  fees?: AddProductFeeParams[];
12
+ /** Note or array of notes to add immediately. */
8
13
  notes?: string | string[];
9
14
  }
10
15
  export interface AddProductToCartResponse {
@@ -1,13 +1,31 @@
1
+ import { MOCK_PRODUCTS } from "../../demo/database";
1
2
  export const mockAdjustInventory = async (params) => {
2
3
  console.log("[Mock] adjustInventory called", params);
3
- // Simulate updating inventory
4
- let newStock = 100;
5
- if (params?.stockType === 'add')
6
- newStock += Number(params.amount);
7
- if (params?.stockType === 'subtract')
8
- newStock -= Number(params.amount);
9
- if (params?.stockType === 'set')
10
- newStock = Number(params.amount);
4
+ let newStock = 0;
5
+ if (params && params.productId) {
6
+ const product = MOCK_PRODUCTS.find(p => p._id === params.productId);
7
+ if (product) {
8
+ // Find variant
9
+ const variant = params.variantId
10
+ ? product.variants.find(v => v._id === params.variantId)
11
+ : product.variants[0];
12
+ if (variant && variant.inventory && variant.inventory.length > 0) {
13
+ const currentStock = variant.inventory[0].stock || 0;
14
+ const changeAmount = Number(params.amount);
15
+ if (params.stockType === 'add') {
16
+ newStock = currentStock + changeAmount;
17
+ }
18
+ else if (params.stockType === 'subtract') {
19
+ newStock = currentStock - changeAmount;
20
+ }
21
+ else {
22
+ newStock = changeAmount;
23
+ }
24
+ // Update mock DB
25
+ variant.inventory[0].stock = newStock;
26
+ }
27
+ }
28
+ }
11
29
  return {
12
30
  success: true,
13
31
  amount: params?.amount || "0",
@@ -1,7 +1,10 @@
1
1
  export interface AdjustInventoryParams {
2
+ /** String to preserve precision. */
2
3
  amount: string;
4
+ /** 'add' (increase), 'subtract' (decrease), or 'set' (recount). */
3
5
  stockType: 'add' | 'subtract' | 'set';
4
6
  variantId?: string;
7
+ productId?: string;
5
8
  }
6
9
  export interface AdjustInventoryResponse {
7
10
  success: boolean;
@@ -6,6 +6,7 @@ export const mockAssignCustomer = async (params) => {
6
6
  throw new Error("Customer not found in mock DB");
7
7
  }
8
8
  MOCK_CART.customer = customer;
9
+ window.alert(`Demo: Customer Assigned to Cart\nName: ${customer.firstName} ${customer.lastName}`);
9
10
  return {
10
11
  success: true,
11
12
  customer,
@@ -1,5 +1,6 @@
1
1
  import { CFRefundedLineItem, CFRefundedCustomSale } from "../../CommonTypes";
2
2
  export interface CalculateRefundTotalParams {
3
+ /** Optional order ID to set as the active order context for the calculation. */
3
4
  orderId?: string;
4
5
  }
5
6
  export interface CalculateRefundTotalResponse {
@@ -4,5 +4,9 @@
4
4
  */
5
5
  import { commandFrameClient } from "../../client";
6
6
  export const cashPayment = async (params) => {
7
- return await commandFrameClient.call("cashPayment", params);
7
+ const finalParams = {
8
+ ...params,
9
+ openChangeCalculator: params?.openChangeCalculator ?? true
10
+ };
11
+ return await commandFrameClient.call("cashPayment", finalParams);
8
12
  };
@@ -1,12 +1,44 @@
1
- import { createOrderFromCart } from "../../demo/database";
1
+ import { createOrderFromCart, MOCK_CART } from "../../demo/database";
2
2
  export const mockCashPayment = async (params) => {
3
3
  console.log("[Mock] cashPayment called", params);
4
- const amount = params?.amount || 0;
4
+ // Default to true to match action behavior
5
+ const openChangeCalculator = params?.openChangeCalculator ?? true;
6
+ let amount = params?.amount || MOCK_CART.total;
7
+ if (openChangeCalculator) {
8
+ try {
9
+ const input = window.prompt(`Total Due: $${MOCK_CART.total.toFixed(2)}\nEnter amount tendered:`, amount.toString());
10
+ if (input === null) {
11
+ // User cancelled
12
+ return {
13
+ success: false,
14
+ amount: 0,
15
+ openChangeCalculator,
16
+ paymentType: "cash",
17
+ order: null,
18
+ timestamp: new Date().toISOString()
19
+ };
20
+ }
21
+ const tendered = parseFloat(input);
22
+ if (!isNaN(tendered)) {
23
+ amount = tendered;
24
+ const change = tendered - MOCK_CART.total;
25
+ if (change >= 0) {
26
+ window.alert(`Change Due: $${change.toFixed(2)}`);
27
+ }
28
+ else {
29
+ window.alert(`Warning: Tendered amount is less than total. Short by: $${Math.abs(change).toFixed(2)}`);
30
+ }
31
+ }
32
+ }
33
+ catch (e) {
34
+ console.warn("Could not open prompt/alert (possibly in non-interactive environment)", e);
35
+ }
36
+ }
5
37
  const order = createOrderFromCart("cash", amount, "cash");
6
38
  return {
7
39
  success: true,
8
40
  amount,
9
- openChangeCalculator: params?.openChangeCalculator || false,
41
+ openChangeCalculator,
10
42
  paymentType: "cash",
11
43
  order,
12
44
  timestamp: new Date().toISOString()
@@ -1,6 +1,8 @@
1
1
  import { CFOrder } from "../../CommonTypes";
2
2
  export interface CashPaymentParams {
3
+ /** If not provided, uses the cart total. */
3
4
  amount?: number;
5
+ /** Defaults to false. */
4
6
  openChangeCalculator?: boolean;
5
7
  }
6
8
  export interface CashPaymentResponse {
@@ -1,5 +1,12 @@
1
+ import { MOCK_PARKED_ORDERS } from "../../demo/database";
1
2
  export const mockDeleteParkedOrder = async (params) => {
2
3
  console.log("[Mock] deleteParkedOrder called", params);
4
+ if (params?.orderId) {
5
+ const index = MOCK_PARKED_ORDERS.findIndex(o => o._id === params.orderId);
6
+ if (index !== -1) {
7
+ MOCK_PARKED_ORDERS.splice(index, 1);
8
+ }
9
+ }
3
10
  return {
4
11
  success: true,
5
12
  orderId: params?.orderId || "",
@@ -1,5 +1,6 @@
1
1
  import { CFCategory } from "../../CommonTypes";
2
2
  export interface GetCategoriesParams {
3
+ /** MongoDB-like query object. */
3
4
  query?: {
4
5
  name?: string | {
5
6
  $regex?: string;
@@ -1,5 +1,6 @@
1
1
  import { CFCustomer } from "../../CommonTypes";
2
2
  export interface GetCustomersParams {
3
+ /** MongoDB-like query object. */
3
4
  query?: {
4
5
  email?: string | {
5
6
  $regex?: string;
@@ -23,7 +24,9 @@ export interface GetCustomersParams {
23
24
  outletId?: string;
24
25
  [key: string]: any;
25
26
  };
27
+ /** Defaults to 0. */
26
28
  offset?: number;
29
+ /** Defaults to 100. */
27
30
  limit?: number;
28
31
  }
29
32
  export interface GetCustomersResponse {
@@ -1,5 +1,6 @@
1
1
  import { CFLineItem, CFCustomSale } from "../../CommonTypes";
2
2
  export interface GetLineItemsByOrderParams {
3
+ /** If not provided, uses the currently active order. */
3
4
  orderId?: string;
4
5
  }
5
6
  export interface GetLineItemsByOrderResponse {
@@ -1,12 +1,17 @@
1
1
  import { CFOrder } from "../../CommonTypes";
2
2
  export interface GetOrdersParams {
3
+ /** e.g. 'completed', 'parked', 'refunded'. */
3
4
  status?: string;
4
5
  customerId?: string;
5
6
  sessionId?: string;
7
+ /** Default: 50. */
6
8
  limit?: number;
9
+ /** Default: 0. */
7
10
  offset?: number;
8
11
  searchValue?: string;
12
+ /** Default: 'createdAt'. */
9
13
  sortBy?: string;
14
+ /** Default: 'descending'. */
10
15
  sortDirection?: 'ascending' | 'descending';
11
16
  }
12
17
  export interface GetOrdersResponse {
@@ -1,5 +1,6 @@
1
1
  import { CFProduct } from "../../CommonTypes";
2
2
  export interface GetProductsParams {
3
+ /** MongoDB-like query object. */
3
4
  query?: {
4
5
  name?: string | {
5
6
  $regex?: string;
@@ -21,7 +22,9 @@ export interface GetProductsParams {
21
22
  externalId?: string;
22
23
  [key: string]: any;
23
24
  };
25
+ /** Defaults to 0. */
24
26
  offset?: number;
27
+ /** Defaults to 100. */
25
28
  limit?: number;
26
29
  }
27
30
  export interface GetProductsResponse {
@@ -3,9 +3,13 @@ export interface GetRefundsParams {
3
3
  orderId?: string;
4
4
  sessionId?: string;
5
5
  outletId?: string;
6
+ /** Default: 50. */
6
7
  limit?: number;
8
+ /** Default: 0. */
7
9
  offset?: number;
10
+ /** Default: 'createdAt'. */
8
11
  sortBy?: string;
12
+ /** Default: 'desc'. */
9
13
  sortDirection?: 'asc' | 'desc';
10
14
  }
11
15
  export interface GetRefundsResponse {
@@ -1,5 +1,6 @@
1
1
  export const mockInitiateRefund = async (params) => {
2
2
  console.log("[Mock] initiateRefund called", params);
3
+ window.alert(`Demo: Initiating Refund for Order: ${params?.orderId || "Current Active Order"}\n(Refund UI would open here)`);
3
4
  return {
4
5
  success: true,
5
6
  orderId: params?.orderId || "mock_order_id",
@@ -1,4 +1,5 @@
1
1
  export interface InitiateRefundParams {
2
+ /** The ID of the order to refund. If not provided, uses the currently active order. */
2
3
  orderId?: string;
3
4
  }
4
5
  export interface InitiateRefundResponse {
@@ -1,5 +1,6 @@
1
1
  export const mockOpenCashDrawer = async () => {
2
2
  console.log("[Mock] openCashDrawer called");
3
+ window.alert("Demo: *Click* Cash Drawer Opened!");
3
4
  return {
4
5
  success: true,
5
6
  timestamp: new Date().toISOString()
@@ -1,9 +1,21 @@
1
- import { MOCK_ORDERS } from "../../demo/database";
1
+ import { MOCK_PARKED_ORDERS, createOrderFromCart, MOCK_ORDERS } from "../../demo/database";
2
2
  export const mockParkOrder = async () => {
3
3
  console.log("[Mock] parkOrder called");
4
+ // Create a temporary order to capture cart state
5
+ // We use createOrderFromCart which resets the cart and pushes to MOCK_ORDERS
6
+ const tempOrder = createOrderFromCart("none", 0, "none");
7
+ // Modify to reflect parked status
8
+ tempOrder.status = "parked";
9
+ tempOrder.paymentMethods = []; // clear dummy payment
10
+ // Move from MOCK_ORDERS to MOCK_PARKED_ORDERS
11
+ const foundIndex = MOCK_ORDERS.findIndex(o => o._id === tempOrder._id);
12
+ if (foundIndex !== -1) {
13
+ MOCK_ORDERS.splice(foundIndex, 1);
14
+ }
15
+ MOCK_PARKED_ORDERS.push(tempOrder);
4
16
  return {
5
17
  success: true,
6
- order: MOCK_ORDERS[0],
18
+ order: tempOrder,
7
19
  timestamp: new Date().toISOString()
8
20
  };
9
21
  };
@@ -4,5 +4,9 @@
4
4
  */
5
5
  import { commandFrameClient } from "../../client";
6
6
  export const partialPayment = async (params) => {
7
- return await commandFrameClient.call("partialPayment", params);
7
+ const finalParams = {
8
+ ...params,
9
+ openUI: params?.openUI ?? true
10
+ };
11
+ return await commandFrameClient.call("partialPayment", finalParams);
8
12
  };
@@ -1,12 +1,17 @@
1
1
  import { MOCK_ORDERS } from "../../demo/database";
2
2
  export const mockPartialPayment = async (params) => {
3
3
  console.log("[Mock] partialPayment called", params);
4
+ const openUI = params?.openUI ?? true;
5
+ if (openUI) {
6
+ // Simulate UI opening
7
+ window.alert("Demo: Split Payment UI would open here.");
8
+ }
4
9
  return {
5
10
  success: true,
6
11
  amount: params?.amount,
7
12
  isPercent: params?.isPercent || false,
8
- openUI: params?.openUI || false,
9
- order: params?.openUI ? null : MOCK_ORDERS[0],
13
+ openUI,
14
+ order: openUI ? null : MOCK_ORDERS[0],
10
15
  timestamp: new Date().toISOString()
11
16
  };
12
17
  };
@@ -1,7 +1,10 @@
1
1
  import { CFOrder } from "../../CommonTypes";
2
2
  export interface PartialPaymentParams {
3
+ /** The payment amount (required if openUI is false). */
3
4
  amount?: number;
5
+ /** Defaults to false. */
4
6
  isPercent?: boolean;
7
+ /** If true, opens the split payment UI. */
5
8
  openUI?: boolean;
6
9
  }
7
10
  export interface PartialPaymentResponse {
@@ -1,7 +1,11 @@
1
1
  export interface ProcessPartialRefundParams {
2
+ /** Optional refund reason. */
2
3
  reason?: string;
4
+ /** Optional: specify which order to refund (sets it as active). */
3
5
  orderId?: string;
6
+ /** Optional items to refund. */
4
7
  items?: {
8
+ /** internalId or variantId or customSaleId. */
5
9
  itemKey: string;
6
10
  quantity: number;
7
11
  type?: 'product' | 'customSale' | 'fee' | 'tip';
@@ -1,6 +1,7 @@
1
1
  import { MOCK_CART } from "../../demo/database";
2
2
  export const mockRemoveCustomerFromCart = async () => {
3
3
  console.log("[Mock] removeCustomerFromCart called");
4
+ // Actually remove the customer from the mock cart
4
5
  MOCK_CART.customer = null;
5
6
  return {
6
7
  success: true,
@@ -1,9 +1,53 @@
1
- import { MOCK_ORDERS } from "../../demo/database";
1
+ import { MOCK_PARKED_ORDERS, MOCK_CART, resetMockCart } from "../../demo/database";
2
2
  export const mockResumeParkedOrder = async (params) => {
3
3
  console.log("[Mock] resumeParkedOrder called", params);
4
+ const orderId = params?.orderId;
5
+ let orderToResume = null;
6
+ let index = -1;
7
+ if (orderId) {
8
+ index = MOCK_PARKED_ORDERS.findIndex(o => o._id === orderId);
9
+ if (index !== -1)
10
+ orderToResume = MOCK_PARKED_ORDERS[index];
11
+ }
12
+ else {
13
+ // Resume last if no ID
14
+ if (MOCK_PARKED_ORDERS.length > 0) {
15
+ index = MOCK_PARKED_ORDERS.length - 1;
16
+ orderToResume = MOCK_PARKED_ORDERS[index];
17
+ }
18
+ }
19
+ if (!orderToResume) {
20
+ throw new Error("Parked order not found");
21
+ }
22
+ // Restore to MOCK_CART
23
+ // Logic to convert Order back to Cart (simplified)
24
+ resetMockCart();
25
+ // Copy properties back
26
+ MOCK_CART.customer = orderToResume.customer; // Cast if needed
27
+ // MOCK_CART.products = orderToResume.lineItems... (Mapping needed)
28
+ // For Mock demo, we'll do a best effort mapping
29
+ MOCK_CART.products = orderToResume.lineItems.map(li => ({
30
+ id: li.productId,
31
+ name: li.name,
32
+ quantity: li.quantity,
33
+ price: parseFloat(li.price),
34
+ internalId: li.internalId || li.productId,
35
+ variantId: li.variantId,
36
+ sku: li.sku,
37
+ images: [li.image],
38
+ stock: 100,
39
+ taxTableId: "",
40
+ attributes: li.attributes
41
+ }));
42
+ MOCK_CART.subtotal = parseFloat(orderToResume.summary.subTotal);
43
+ MOCK_CART.total = parseFloat(orderToResume.summary.total);
44
+ MOCK_CART.amountToBeCharged = MOCK_CART.total;
45
+ MOCK_CART.remainingBalance = MOCK_CART.total;
46
+ // Remove from parked
47
+ MOCK_PARKED_ORDERS.splice(index, 1);
4
48
  return {
5
49
  success: true,
6
- order: MOCK_ORDERS[0],
50
+ order: orderToResume,
7
51
  timestamp: new Date().toISOString()
8
52
  };
9
53
  };
@@ -1,4 +1,5 @@
1
1
  export interface SelectAllRefundItemsParams {
2
+ /** Optional. Sets specific order as active before selecting. */
2
3
  orderId?: string;
3
4
  }
4
5
  export interface SelectAllRefundItemsResponse {
@@ -1,5 +1,6 @@
1
1
  export interface SetRefundStockActionParams {
2
2
  orderId?: string;
3
+ /** The 'key' field from getLineItemsByOrder response (internalId || variantId || productId). */
3
4
  itemKey: string;
4
5
  action: 'RESTOCK' | 'REFUND_DAMAGE';
5
6
  }
@@ -1,6 +1,9 @@
1
1
  export const mockShowConfirmation = async (params) => {
2
2
  console.log("[Mock] showConfirmation called", params);
3
- // Simulate user confirming
3
+ const confirmed = window.confirm(`Confirmation Required:\n${params?.message || "Are you sure?"}`);
4
+ if (!confirmed) {
5
+ throw new Error("User cancelled confirmation");
6
+ }
4
7
  return {
5
8
  success: true,
6
9
  message: params?.message || "",
@@ -1,5 +1,6 @@
1
1
  export const mockShowNotification = async (params) => {
2
2
  console.log("[Mock] showNotification called", params);
3
+ window.alert(`Notification: ${params?.message || "No message"}`);
3
4
  return {
4
5
  success: true,
5
6
  message: params?.message || "",
@@ -1,6 +1,8 @@
1
1
  export interface SwitchUserParams {
2
2
  mode: 'dialog' | 'role' | 'specific';
3
+ /** Required if mode is 'role'. */
3
4
  roleIds?: string[];
5
+ /** Required if mode is 'specific'. */
4
6
  userId?: string;
5
7
  }
6
8
  export interface SwitchUserResponse {
@@ -1,6 +1,8 @@
1
1
  import { MOCK_ORDERS } from "../../demo/database";
2
2
  export const mockTapToPayPayment = async (params) => {
3
3
  console.log("[Mock] tapToPayPayment called", params);
4
+ // Simulate Tap to Pay interaction
5
+ window.alert("Demo: Processing Tap to Pay...\n(Please tap card or device on screen)");
4
6
  return {
5
7
  success: true,
6
8
  amount: params?.amount || null,
@@ -1,5 +1,6 @@
1
1
  import { CFOrder } from "../../CommonTypes";
2
2
  export interface TapToPayPaymentParams {
3
+ /** If not provided, uses the cart total. */
3
4
  amount?: number;
4
5
  }
5
6
  export interface TapToPayPaymentResponse {
@@ -1,7 +1,9 @@
1
- import { createOrderFromCart } from "../../demo/database";
1
+ import { createOrderFromCart, MOCK_CART } from "../../demo/database";
2
2
  export const mockTerminalPayment = async (params) => {
3
3
  console.log("[Mock] terminalPayment called", params);
4
- const amount = params?.amount || 0;
4
+ // Simulate terminal interaction
5
+ window.alert("Demo: Processing Terminal Payment...\n(Please tap, insert, or swipe card on terminal)");
6
+ const amount = params?.amount || MOCK_CART.total;
5
7
  // Mocking terminal payment success immediately
6
8
  const order = createOrderFromCart("card", amount, "stripe_terminal");
7
9
  return {
@@ -1,5 +1,6 @@
1
1
  import { CFOrder } from "../../CommonTypes";
2
2
  export interface TerminalPaymentParams {
3
+ /** If not provided, uses the cart total. */
3
4
  amount?: number;
4
5
  }
5
6
  export interface TerminalPaymentResponse {
@@ -1,11 +1,15 @@
1
1
  export type TriggerWebhookPresetType = 'product' | 'cart' | 'order' | 'customer';
2
2
  export interface TriggerWebhookParams {
3
3
  webhookUrl: string;
4
+ /** Public key for authentication. */
4
5
  publicKey?: string;
6
+ /** Defaults to false. */
5
7
  presetData?: boolean;
6
8
  presetType?: TriggerWebhookPresetType;
9
+ /** Defaults to false. */
7
10
  isCustomHook?: boolean;
8
11
  customHookData?: string;
12
+ /** 'json' or 'form-urlencoded'. Defaults to 'json'. */
9
13
  payloadType?: string;
10
14
  dynamicDataFields?: unknown[];
11
15
  }
@@ -1,5 +1,6 @@
1
1
  import { CFOrder } from "../../CommonTypes";
2
2
  export interface VendaraPaymentParams {
3
+ /** If not provided, uses the cart total. */
3
4
  amount?: number;
4
5
  }
5
6
  export interface VendaraPaymentResponse {
@@ -36,6 +36,7 @@ export declare const MOCK_CUSTOMERS: CFCustomer[];
36
36
  export declare const MOCK_CATEGORIES: CFCategory[];
37
37
  export declare const MOCK_PRODUCTS: CFProduct[];
38
38
  export declare const MOCK_ORDERS: CFActiveOrder[];
39
+ export declare const MOCK_PARKED_ORDERS: CFActiveOrder[];
39
40
  export declare const MOCK_USER: CFActiveUser;
40
41
  export declare const MOCK_STATION: CFActiveStation;
41
42
  export declare const MOCK_OUTLET: CFActiveOutlet;
@@ -403,6 +403,7 @@ export const MOCK_PRODUCTS = [
403
403
  MOCK_PRODUCT_ROASTED_TOMATO
404
404
  ];
405
405
  export const MOCK_ORDERS = [MOCK_ORDER_1, MOCK_ORDER_2];
406
+ export const MOCK_PARKED_ORDERS = [];
406
407
  // Compatibility Exports
407
408
  export const MOCK_USER = MOCK_USERS[0];
408
409
  export const MOCK_STATION = MOCK_STATIONS[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Commands Frame library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",