@final-commerce/command-frame 0.1.18 → 0.1.19

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Remove product from cart action
3
+ * Calls the removeProductFromCart action on the parent window
4
+ */
5
+ import type { RemoveProductFromCart } from "./types";
6
+ export declare const removeProductFromCart: RemoveProductFromCart;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Remove product from cart action
3
+ * Calls the removeProductFromCart action on the parent window
4
+ */
5
+ import { commandFrameClient } from "../../client";
6
+ export const removeProductFromCart = async (params) => {
7
+ return await commandFrameClient.call("removeProductFromCart", params);
8
+ };
@@ -0,0 +1,2 @@
1
+ import { RemoveProductFromCart } from "./types";
2
+ export declare const mockRemoveProductFromCart: RemoveProductFromCart;
@@ -0,0 +1,32 @@
1
+ import { MOCK_CART, mockPublishEvent } from "../../demo/database";
2
+ export const mockRemoveProductFromCart = async (params) => {
3
+ console.log("[Mock] removeProductFromCart called", params);
4
+ if (!params?.internalId) {
5
+ throw new Error('internalId is required');
6
+ }
7
+ const { internalId } = params;
8
+ // Find the product in the cart
9
+ const productIndex = MOCK_CART.products.findIndex(p => p.internalId === internalId);
10
+ if (productIndex === -1) {
11
+ throw new Error(`Cart item with internalId ${internalId} not found`);
12
+ }
13
+ const product = MOCK_CART.products[productIndex];
14
+ // Remove from cart
15
+ MOCK_CART.products.splice(productIndex, 1);
16
+ // Recalculate totals
17
+ const lineTotal = product.price * product.quantity;
18
+ MOCK_CART.subtotal -= lineTotal;
19
+ MOCK_CART.total -= lineTotal;
20
+ MOCK_CART.amountToBeCharged = MOCK_CART.total;
21
+ MOCK_CART.remainingBalance = MOCK_CART.total;
22
+ // Publish product-deleted event
23
+ mockPublishEvent('cart', 'product-deleted', {
24
+ product: product,
25
+ internalId: internalId
26
+ });
27
+ return {
28
+ success: true,
29
+ internalId: internalId,
30
+ timestamp: new Date().toISOString()
31
+ };
32
+ };
@@ -0,0 +1,11 @@
1
+ export interface RemoveProductFromCartParams {
2
+ /** The unique identifier for the specific cart item to remove. */
3
+ internalId: string;
4
+ }
5
+ export interface RemoveProductFromCartResponse {
6
+ success: boolean;
7
+ /** The unique identifier of the removed cart item. */
8
+ internalId: string;
9
+ timestamp: string;
10
+ }
11
+ export type RemoveProductFromCart = (params?: RemoveProductFromCartParams) => Promise<RemoveProductFromCartResponse>;
@@ -0,0 +1,2 @@
1
+ // Remove Product From Cart Types
2
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Update cart item quantity action
3
+ * Calls the updateCartItemQuantity action on the parent window
4
+ */
5
+ import type { UpdateCartItemQuantity } from "./types";
6
+ export declare const updateCartItemQuantity: UpdateCartItemQuantity;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Update cart item quantity action
3
+ * Calls the updateCartItemQuantity action on the parent window
4
+ */
5
+ import { commandFrameClient } from "../../client";
6
+ export const updateCartItemQuantity = async (params) => {
7
+ return await commandFrameClient.call("updateCartItemQuantity", params);
8
+ };
@@ -0,0 +1,2 @@
1
+ import { UpdateCartItemQuantity } from "./types";
2
+ export declare const mockUpdateCartItemQuantity: UpdateCartItemQuantity;
@@ -0,0 +1,60 @@
1
+ import { MOCK_CART, mockPublishEvent } from "../../demo/database";
2
+ export const mockUpdateCartItemQuantity = async (params) => {
3
+ console.log("[Mock] updateCartItemQuantity called", params);
4
+ if (!params?.internalId) {
5
+ throw new Error('internalId is required');
6
+ }
7
+ if (params.quantity === undefined || params.quantity === null) {
8
+ throw new Error('quantity is required');
9
+ }
10
+ const { internalId, quantity } = params;
11
+ // Find the product in the cart
12
+ const productIndex = MOCK_CART.products.findIndex(p => p.internalId === internalId);
13
+ if (productIndex === -1) {
14
+ throw new Error(`Cart item with internalId ${internalId} not found`);
15
+ }
16
+ const product = MOCK_CART.products[productIndex];
17
+ const previousQuantity = product.quantity;
18
+ // If quantity is 0, remove the item
19
+ if (quantity === 0) {
20
+ MOCK_CART.products.splice(productIndex, 1);
21
+ // Recalculate totals
22
+ const lineTotal = product.price * previousQuantity;
23
+ MOCK_CART.subtotal -= lineTotal;
24
+ MOCK_CART.total -= lineTotal;
25
+ MOCK_CART.amountToBeCharged = MOCK_CART.total;
26
+ MOCK_CART.remainingBalance = MOCK_CART.total;
27
+ // Publish product-deleted event
28
+ mockPublishEvent('cart', 'product-deleted', {
29
+ product: product,
30
+ internalId: internalId
31
+ });
32
+ return {
33
+ success: true,
34
+ internalId: internalId,
35
+ quantity: 0,
36
+ timestamp: new Date().toISOString()
37
+ };
38
+ }
39
+ // Update quantity
40
+ const quantityDelta = quantity - previousQuantity;
41
+ product.quantity = quantity;
42
+ // Recalculate totals
43
+ const lineTotalDelta = product.price * quantityDelta;
44
+ MOCK_CART.subtotal += lineTotalDelta;
45
+ MOCK_CART.total += lineTotalDelta;
46
+ MOCK_CART.amountToBeCharged = MOCK_CART.total;
47
+ MOCK_CART.remainingBalance = MOCK_CART.total;
48
+ // Publish product-updated event
49
+ mockPublishEvent('cart', 'product-updated', {
50
+ product: product,
51
+ previousQuantity: previousQuantity,
52
+ newQuantity: quantity
53
+ });
54
+ return {
55
+ success: true,
56
+ internalId: internalId,
57
+ quantity: quantity,
58
+ timestamp: new Date().toISOString()
59
+ };
60
+ };
@@ -0,0 +1,15 @@
1
+ export interface UpdateCartItemQuantityParams {
2
+ /** The unique identifier for the specific cart item to update. */
3
+ internalId: string;
4
+ /** The new quantity. If set to 0, the item will be removed from the cart. */
5
+ quantity: number;
6
+ }
7
+ export interface UpdateCartItemQuantityResponse {
8
+ success: boolean;
9
+ /** The unique identifier of the updated cart item. */
10
+ internalId: string;
11
+ /** The new quantity after the update. */
12
+ quantity: number;
13
+ timestamp: string;
14
+ }
15
+ export type UpdateCartItemQuantity = (params?: UpdateCartItemQuantityParams) => Promise<UpdateCartItemQuantityResponse>;
@@ -0,0 +1,2 @@
1
+ // Update Cart Item Quantity Types
2
+ export {};
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ export declare const command: {
10
10
  readonly getRefunds: import("./actions/get-refunds/types").GetRefunds;
11
11
  readonly addProductDiscount: import("./actions/add-product-discount/types").AddProductDiscount;
12
12
  readonly addProductToCart: import("./actions/add-product-to-cart/types").AddProductToCart;
13
+ readonly removeProductFromCart: import("./actions/remove-product-from-cart/types").RemoveProductFromCart;
14
+ readonly updateCartItemQuantity: import("./actions/update-cart-item-quantity/types").UpdateCartItemQuantity;
13
15
  readonly addCartDiscount: import("./actions/add-cart-discount/types").AddCartDiscount;
14
16
  readonly getContext: import("./actions/get-context/types").GetContext;
15
17
  readonly getFinalContext: import("./actions/get-final-context/types").GetFinalContext;
@@ -65,6 +67,8 @@ export type { InitiateRefund, InitiateRefundParams, InitiateRefundResponse } fro
65
67
  export type { GetCurrentCart, GetCurrentCartResponse } from "./actions/get-current-cart/types";
66
68
  export type { AddProductDiscount, AddProductDiscountParams, AddProductDiscountResponse } from "./actions/add-product-discount/types";
67
69
  export type { AddProductToCart, AddProductToCartParams, AddProductToCartResponse } from "./actions/add-product-to-cart/types";
70
+ export type { RemoveProductFromCart, RemoveProductFromCartParams, RemoveProductFromCartResponse } from "./actions/remove-product-from-cart/types";
71
+ export type { UpdateCartItemQuantity, UpdateCartItemQuantityParams, UpdateCartItemQuantityResponse } from "./actions/update-cart-item-quantity/types";
68
72
  export type { AddCartDiscount, AddCartDiscountParams, AddCartDiscountResponse } from "./actions/add-cart-discount/types";
69
73
  export type { GetContext, GetContextResponse } from "./actions/get-context/types";
70
74
  export type { GetFinalContext, GetFinalContextResponse } from "./actions/get-final-context/types";
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@ import { getContext } from "./actions/get-context/action";
12
12
  import { getFinalContext } from "./actions/get-final-context/action";
13
13
  import { addProductDiscount } from "./actions/add-product-discount/action";
14
14
  import { addProductToCart } from "./actions/add-product-to-cart/action";
15
+ import { removeProductFromCart } from "./actions/remove-product-from-cart/action";
16
+ import { updateCartItemQuantity } from "./actions/update-cart-item-quantity/action";
15
17
  // Product Actions
16
18
  import { addProductNote } from "./actions/add-product-note/action";
17
19
  import { addProductFee } from "./actions/add-product-fee/action";
@@ -64,6 +66,8 @@ export const command = {
64
66
  getRefunds,
65
67
  addProductDiscount,
66
68
  addProductToCart,
69
+ removeProductFromCart,
70
+ updateCartItemQuantity,
67
71
  addCartDiscount,
68
72
  getContext,
69
73
  getFinalContext,
@@ -8,6 +8,8 @@ import { mockAddProductDiscount } from "../../actions/add-product-discount/mock"
8
8
  import { mockAddProductFee } from "../../actions/add-product-fee/mock";
9
9
  import { mockAddProductNote } from "../../actions/add-product-note/mock";
10
10
  import { mockAddProductToCart } from "../../actions/add-product-to-cart/mock";
11
+ import { mockRemoveProductFromCart } from "../../actions/remove-product-from-cart/mock";
12
+ import { mockUpdateCartItemQuantity } from "../../actions/update-cart-item-quantity/mock";
11
13
  import { mockAdjustInventory } from "../../actions/adjust-inventory/mock";
12
14
  import { mockAssignCustomer } from "../../actions/assign-customer/mock";
13
15
  import { mockAuthenticateUser } from "../../actions/authenticate-user/mock";
@@ -55,6 +57,8 @@ export const RENDER_MOCKS = {
55
57
  addProductFee: mockAddProductFee,
56
58
  addProductNote: mockAddProductNote,
57
59
  addProductToCart: mockAddProductToCart,
60
+ removeProductFromCart: mockRemoveProductFromCart,
61
+ updateCartItemQuantity: mockUpdateCartItemQuantity,
58
62
  adjustInventory: mockAdjustInventory,
59
63
  assignCustomer: mockAssignCustomer,
60
64
  authenticateUser: mockAuthenticateUser,
@@ -1,4 +1,4 @@
1
- import type { ExampleFunction, GetProducts, AddCustomSale, GetCustomers, AssignCustomer, AddCustomer, GetCategories, GetOrders, GetRefunds, AddProductDiscount, AddProductToCart, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, InitiateRefund, CashPayment, TapToPayPayment, TerminalPayment, VendaraPayment, AddCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, TriggerWebhook, TriggerZapierWebhook, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, GetCurrentCart } from "../../index";
1
+ import type { ExampleFunction, GetProducts, AddCustomSale, GetCustomers, AssignCustomer, AddCustomer, GetCategories, GetOrders, GetRefunds, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, InitiateRefund, CashPayment, TapToPayPayment, TerminalPayment, VendaraPayment, AddCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, TriggerWebhook, TriggerZapierWebhook, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, GetCurrentCart } from "../../index";
2
2
  export interface RenderProviderActions {
3
3
  exampleFunction: ExampleFunction;
4
4
  getProducts: GetProducts;
@@ -11,6 +11,8 @@ export interface RenderProviderActions {
11
11
  getRefunds: GetRefunds;
12
12
  addProductDiscount: AddProductDiscount;
13
13
  addProductToCart: AddProductToCart;
14
+ removeProductFromCart: RemoveProductFromCart;
15
+ updateCartItemQuantity: UpdateCartItemQuantity;
14
16
  addCartDiscount: AddCartDiscount;
15
17
  getContext: GetContext;
16
18
  getFinalContext: GetFinalContext;
@@ -27,6 +27,11 @@ export const cartTopic = {
27
27
  name: "Product Deleted",
28
28
  description: "Published when a product is removed from the cart"
29
29
  },
30
+ {
31
+ id: "product-updated",
32
+ name: "Product Updated",
33
+ description: "Published when a product's quantity is updated in the cart"
34
+ },
30
35
  {
31
36
  id: "cart-discount-added",
32
37
  name: "Cart Discount Added",
@@ -0,0 +1,14 @@
1
+ import type { CFActiveProduct } from "../../../../CommonTypes";
2
+ import type { TopicEvent } from "../../../types";
3
+ /**
4
+ * Payload for cart product-updated event
5
+ */
6
+ export interface CartProductUpdatedPayload {
7
+ product: CFActiveProduct;
8
+ previousQuantity: number;
9
+ newQuantity: number;
10
+ }
11
+ /**
12
+ * Typed event for cart product-updated
13
+ */
14
+ export type CartProductUpdatedEvent = TopicEvent<CartProductUpdatedPayload>;
@@ -0,0 +1 @@
1
+ export {};
@@ -6,6 +6,7 @@ export * from "./cart-created/types";
6
6
  export * from "./customer-assigned/types";
7
7
  export * from "./product-added/types";
8
8
  export * from "./product-deleted/types";
9
+ export * from "./product-updated/types";
9
10
  export * from "./cart-discount-added/types";
10
11
  export * from "./cart-discount-removed/types";
11
12
  export * from "./cart-fee-added/types";
@@ -14,9 +15,10 @@ import type { CartCreatedPayload } from "./cart-created/types";
14
15
  import type { CartCustomerAssignedPayload } from "./customer-assigned/types";
15
16
  import type { ProductAddedPayload } from "./product-added/types";
16
17
  import type { ProductDeletedPayload } from "./product-deleted/types";
18
+ import type { CartProductUpdatedPayload } from "./product-updated/types";
17
19
  import type { CartDiscountAddedPayload } from "./cart-discount-added/types";
18
20
  import type { CartDiscountRemovedPayload } from "./cart-discount-removed/types";
19
21
  import type { CartFeeAddedPayload } from "./cart-fee-added/types";
20
22
  import type { CartFeeRemovedPayload } from "./cart-fee-removed/types";
21
- export type CartEventPayload = CartCreatedPayload | CartCustomerAssignedPayload | ProductAddedPayload | ProductDeletedPayload | CartDiscountAddedPayload | CartDiscountRemovedPayload | CartFeeAddedPayload | CartFeeRemovedPayload;
22
- export type CartEventType = "cart-created" | "customer-assigned" | "product-added" | "product-deleted" | "cart-discount-added" | "cart-discount-removed" | "cart-fee-added" | "cart-fee-removed";
23
+ export type CartEventPayload = CartCreatedPayload | CartCustomerAssignedPayload | ProductAddedPayload | ProductDeletedPayload | CartProductUpdatedPayload | CartDiscountAddedPayload | CartDiscountRemovedPayload | CartFeeAddedPayload | CartFeeRemovedPayload;
24
+ export type CartEventType = "cart-created" | "customer-assigned" | "product-added" | "product-deleted" | "product-updated" | "cart-discount-added" | "cart-discount-removed" | "cart-fee-added" | "cart-fee-removed";
@@ -7,6 +7,7 @@ export * from "./cart-created/types";
7
7
  export * from "./customer-assigned/types";
8
8
  export * from "./product-added/types";
9
9
  export * from "./product-deleted/types";
10
+ export * from "./product-updated/types";
10
11
  export * from "./cart-discount-added/types";
11
12
  export * from "./cart-discount-removed/types";
12
13
  export * from "./cart-fee-added/types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Commands Frame library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",