@final-commerce/command-frame 0.8.0 → 0.9.0-preprod.1

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,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,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 {};
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;
@@ -179,7 +180,8 @@ export type { SetActiveProductFee, SetActiveProductFeeParams, SetActiveProductFe
179
180
  export type { SetActiveProductDiscount, SetActiveProductDiscountParams, SetActiveProductDiscountResponse, } from './actions/set-active-product-discount/types';
180
181
  export type { GetActiveProduct, GetActiveProductResponse } from './actions/get-active-product/types';
181
182
  export type { SetActiveProduct, SetActiveProductParams, SetActiveProductResponse, } from './actions/set-active-product/types';
182
- export type { AdjustInventory, AdjustInventoryParams, AdjustInventoryResponse } from './actions/adjust-inventory/types';
183
+ export type { AdjustInventory, AdjustInventoryParams, AdjustInventoryResponse, ManualStockReason, } from './actions/adjust-inventory/types';
184
+ export type { CustomStockActionPayload, GetCustomStockActions, GetCustomStockActionsResponse, } from './actions/get-custom-stock-actions/types';
183
185
  export type { AddOrderNote, AddOrderNoteParams, AddOrderNoteResponse } from './actions/add-order-note/types';
184
186
  export type { AddCartFee, AddCartFeeParams, AddCartFeeResponse } from './actions/add-cart-fee/types';
185
187
  export type { ClearCart, ClearCartResponse } from './actions/clear-cart/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';
@@ -180,6 +181,7 @@ export const command = {
180
181
  getActiveProduct,
181
182
  setActiveProduct,
182
183
  adjustInventory,
184
+ getCustomStockActions,
183
185
  // Order Actions
184
186
  addOrderNote,
185
187
  addCartFee,
@@ -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';
@@ -132,6 +133,7 @@ export const RENDER_MOCKS = {
132
133
  removeProductFromCart: mockRemoveProductFromCart,
133
134
  updateCartItemQuantity: mockUpdateCartItemQuantity,
134
135
  adjustInventory: mockAdjustInventory,
136
+ getCustomStockActions: mockGetCustomStockActions,
135
137
  assignCustomer: mockAssignCustomer,
136
138
  authenticateUser: mockAuthenticateUser,
137
139
  calculateRefundTotal: mockCalculateRefundTotal,
@@ -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, 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, 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.8.0",
3
+ "version": "0.9.0-preprod.1",
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.0"
60
+ "@final-commerce/common": "2.5.0-preprod.1"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@commitlint/cli": "^19.0.0",