@final-commerce/command-frame 0.10.0-staging.3 → 0.10.0-staging.5
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.
- package/dist/actions/adjust-inventory/mock.js +20 -0
- package/dist/actions/adjust-inventory/types.d.ts +13 -0
- package/dist/actions/adjust-inventory/types.js +1 -0
- package/dist/actions/get-custom-stock-actions/action.d.ts +5 -0
- package/dist/actions/get-custom-stock-actions/action.js +7 -0
- package/dist/actions/get-custom-stock-actions/mock.d.ts +2 -0
- package/dist/actions/get-custom-stock-actions/mock.js +11 -0
- package/dist/actions/get-custom-stock-actions/types.d.ts +12 -0
- package/dist/actions/get-custom-stock-actions/types.js +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/projects/render/mocks.js +2 -0
- package/dist/projects/render/types.d.ts +2 -1
- package/package.json +2 -2
|
@@ -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;
|
|
@@ -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>;
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare const command: {
|
|
|
38
38
|
readonly setActiveProduct: import(".").SetActiveProduct;
|
|
39
39
|
readonly adjustInventory: import(".").AdjustInventory;
|
|
40
40
|
readonly setVariantUnavailable: import(".").SetVariantUnavailable;
|
|
41
|
+
readonly getCustomStockActions: import(".").GetCustomStockActions;
|
|
41
42
|
readonly addOrderNote: import(".").AddOrderNote;
|
|
42
43
|
readonly addCartFee: import(".").AddCartFee;
|
|
43
44
|
readonly getCurrentCart: import(".").GetCurrentCart;
|
|
@@ -184,8 +185,9 @@ export type { SetActiveProductFee, SetActiveProductFeeParams, SetActiveProductFe
|
|
|
184
185
|
export type { SetActiveProductDiscount, SetActiveProductDiscountParams, SetActiveProductDiscountResponse, } from './actions/set-active-product-discount/types';
|
|
185
186
|
export type { GetActiveProduct, GetActiveProductResponse } from './actions/get-active-product/types';
|
|
186
187
|
export type { SetActiveProduct, SetActiveProductParams, SetActiveProductResponse, } from './actions/set-active-product/types';
|
|
187
|
-
export type { AdjustInventory, AdjustInventoryParams, AdjustInventoryResponse } from './actions/adjust-inventory/types';
|
|
188
188
|
export type { SetVariantUnavailable, SetVariantUnavailableParams, SetVariantUnavailableResponse, } from './actions/set-variant-unavailable/types';
|
|
189
|
+
export type { AdjustInventory, AdjustInventoryParams, AdjustInventoryResponse, ManualStockReason, } from './actions/adjust-inventory/types';
|
|
190
|
+
export type { CustomStockActionPayload, GetCustomStockActions, GetCustomStockActionsResponse, } from './actions/get-custom-stock-actions/types';
|
|
189
191
|
export type { AddOrderNote, AddOrderNoteParams, AddOrderNoteResponse } from './actions/add-order-note/types';
|
|
190
192
|
export type { AddCartFee, AddCartFeeParams, AddCartFeeResponse } from './actions/add-cart-fee/types';
|
|
191
193
|
export type { ClearCart, ClearCartResponse } from './actions/clear-cart/types';
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ import { getActiveProduct } from './actions/get-active-product/action';
|
|
|
37
37
|
import { setActiveProduct } from './actions/set-active-product/action';
|
|
38
38
|
import { adjustInventory } from './actions/adjust-inventory/action';
|
|
39
39
|
import { setVariantUnavailable } from './actions/set-variant-unavailable/action';
|
|
40
|
+
import { getCustomStockActions } from './actions/get-custom-stock-actions/action';
|
|
40
41
|
// Order Actions
|
|
41
42
|
import { addOrderNote } from './actions/add-order-note/action';
|
|
42
43
|
import { addCartFee } from './actions/add-cart-fee/action';
|
|
@@ -186,6 +187,7 @@ export const command = {
|
|
|
186
187
|
setActiveProduct,
|
|
187
188
|
adjustInventory,
|
|
188
189
|
setVariantUnavailable,
|
|
190
|
+
getCustomStockActions,
|
|
189
191
|
// Order Actions
|
|
190
192
|
addOrderNote,
|
|
191
193
|
addCartFee,
|
|
@@ -29,6 +29,7 @@ import { mockRemoveCartDiscount } from '../../actions/remove-cart-discount/mock'
|
|
|
29
29
|
import { mockUpdateCartItemQuantity } from '../../actions/update-cart-item-quantity/mock';
|
|
30
30
|
import { mockAdjustInventory } from '../../actions/adjust-inventory/mock';
|
|
31
31
|
import { mockSetVariantUnavailable } from '../../actions/set-variant-unavailable/mock';
|
|
32
|
+
import { mockGetCustomStockActions } from '../../actions/get-custom-stock-actions/mock';
|
|
32
33
|
import { mockAssignCustomer } from '../../actions/assign-customer/mock';
|
|
33
34
|
import { mockAuthenticateUser } from '../../actions/authenticate-user/mock';
|
|
34
35
|
import { mockCalculateRefundTotal } from '../../actions/calculate-refund-total/mock';
|
|
@@ -138,6 +139,7 @@ export const RENDER_MOCKS = {
|
|
|
138
139
|
updateCartItemQuantity: mockUpdateCartItemQuantity,
|
|
139
140
|
adjustInventory: mockAdjustInventory,
|
|
140
141
|
setVariantUnavailable: mockSetVariantUnavailable,
|
|
142
|
+
getCustomStockActions: mockGetCustomStockActions,
|
|
141
143
|
assignCustomer: mockAssignCustomer,
|
|
142
144
|
authenticateUser: mockAuthenticateUser,
|
|
143
145
|
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, GetCompositePrice, GetCompositeAvailability, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, SetVariantUnavailable, 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, GetCompositePrice, GetCompositeAvailability, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, SetVariantUnavailable, 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;
|
|
@@ -38,6 +38,7 @@ export interface RenderProviderActions {
|
|
|
38
38
|
setActiveProduct: SetActiveProduct;
|
|
39
39
|
adjustInventory: AdjustInventory;
|
|
40
40
|
setVariantUnavailable: SetVariantUnavailable;
|
|
41
|
+
getCustomStockActions: GetCustomStockActions;
|
|
41
42
|
addOrderNote: AddOrderNote;
|
|
42
43
|
addCartFee: AddCartFee;
|
|
43
44
|
clearCart: ClearCart;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@final-commerce/command-frame",
|
|
3
|
-
"version": "0.10.0-staging.
|
|
3
|
+
"version": "0.10.0-staging.5",
|
|
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.6.0-staging.
|
|
60
|
+
"@final-commerce/common": "2.6.0-staging.3"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@commitlint/cli": "^19.0.0",
|