@final-commerce/command-frame 0.1.11 → 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.
@@ -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,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,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,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,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",
@@ -4,6 +4,7 @@ export interface AdjustInventoryParams {
4
4
  /** 'add' (increase), 'subtract' (decrease), or 'set' (recount). */
5
5
  stockType: 'add' | 'subtract' | 'set';
6
6
  variantId?: string;
7
+ productId?: string;
7
8
  }
8
9
  export interface AdjustInventoryResponse {
9
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,
@@ -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,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
  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,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,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,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
  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,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 {
@@ -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.11",
3
+ "version": "0.1.12",
4
4
  "description": "Commands Frame library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",