@final-commerce/command-frame 0.8.1-online.1 → 0.8.1-online.2
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/add-booking-to-cart/mock.js +12 -8
- package/dist/actions/add-product-to-cart/mock.js +4 -0
- package/dist/actions/get-products/mock.js +13 -0
- package/dist/actions/get-products/types.d.ts +16 -0
- package/dist/actions/resume-parked-order/mock.d.ts +1 -1
- package/dist/actions/resume-parked-order/mock.js +16 -10
- package/dist/actions/update-cart-item-quantity/mock.js +7 -1
- package/package.json +2 -2
|
@@ -2,14 +2,6 @@ import { MOCK_CART, MOCK_PRODUCTS, mockPublishEvent } from '../../demo/database'
|
|
|
2
2
|
import { mockHoldBooking } from '../hold-booking/mock';
|
|
3
3
|
export const mockAddBookingToCart = async (params) => {
|
|
4
4
|
console.log('[Mock] addBookingToCart called', params);
|
|
5
|
-
// One call, two effects — the window is claimed AND the service is in the cart. The claim goes
|
|
6
|
-
// first and its refusal propagates: a cart line for a window somebody else took is worse than
|
|
7
|
-
// no line at all.
|
|
8
|
-
const held = await mockHoldBooking(params);
|
|
9
|
-
if (!held.success || !held.booking) {
|
|
10
|
-
return { success: false, reason: held.reason, timestamp: new Date().toISOString() };
|
|
11
|
-
}
|
|
12
|
-
const booking = held.booking;
|
|
13
5
|
// An unknown product used to be sold as "Booking" at zero. The host refuses it, and a mock that
|
|
14
6
|
// quietly sells something no catalogue contains teaches a screen a case that cannot happen.
|
|
15
7
|
const product = MOCK_PRODUCTS.find(({ _id }) => _id === params.productId);
|
|
@@ -27,6 +19,18 @@ export const mockAddBookingToCart = async (params) => {
|
|
|
27
19
|
timestamp: new Date().toISOString(),
|
|
28
20
|
};
|
|
29
21
|
}
|
|
22
|
+
// Same refusal and text as the host (kaching add-booking-to-cart).
|
|
23
|
+
if (product.notSoldInPos || variant?.notSoldInPos) {
|
|
24
|
+
return { success: false, reason: `${product.name} is not sold in POS`, timestamp: new Date().toISOString() };
|
|
25
|
+
}
|
|
26
|
+
// One call, two effects — the window is claimed AND the service is in the cart. Like the host, the
|
|
27
|
+
// claim comes after the product checks and before the line; its refusal propagates: a cart line for
|
|
28
|
+
// a window somebody else took is worse than no line at all.
|
|
29
|
+
const held = await mockHoldBooking(params);
|
|
30
|
+
if (!held.success || !held.booking) {
|
|
31
|
+
return { success: false, reason: held.reason, timestamp: new Date().toISOString() };
|
|
32
|
+
}
|
|
33
|
+
const booking = held.booking;
|
|
30
34
|
const price = variant?.price ?? product.minPrice ?? 0;
|
|
31
35
|
const reservation = {
|
|
32
36
|
internalId: `res_${booking.id}`,
|
|
@@ -21,6 +21,10 @@ export const mockAddProductToCart = async (params) => {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
+
// Same refusal and text as the host (kaching add-product-to-cart).
|
|
25
|
+
if (product.notSoldInPos || variant.notSoldInPos) {
|
|
26
|
+
throw new Error(`${product.name} is not sold in POS`);
|
|
27
|
+
}
|
|
24
28
|
// A measured variant carries a resolved unit; the host does the same. What the unit can
|
|
25
29
|
// express is its precision — 1.5 of a kilogram is a sale, 1.5 of a piece is a typo.
|
|
26
30
|
const unit = variant.unitId ? resolveUnit(variant.unitId) : undefined;
|
|
@@ -11,6 +11,19 @@ export const mockGetProducts = async (params) => {
|
|
|
11
11
|
if (!JSON.stringify(query).includes('productType')) {
|
|
12
12
|
products = products.filter((p) => p.productType !== 'booking');
|
|
13
13
|
}
|
|
14
|
+
// Same as the host: `true` = flagged, `false` = not flagged (missing counts).
|
|
15
|
+
for (const flag of ['notSoldInPos', 'notSoldOnline']) {
|
|
16
|
+
if (typeof query[flag] === 'boolean')
|
|
17
|
+
products = products.filter((p) => !!p[flag] === query[flag]);
|
|
18
|
+
}
|
|
19
|
+
if (!params?.includeUnlisted) {
|
|
20
|
+
// Same as the host: flagged variants are stripped, a product left with none is dropped.
|
|
21
|
+
if (query.notSoldInPos === undefined)
|
|
22
|
+
products = products.filter((p) => !p.notSoldInPos);
|
|
23
|
+
products = products
|
|
24
|
+
.filter((p) => !p.variants.length || p.variants.some((v) => !v.notSoldInPos))
|
|
25
|
+
.map((p) => ({ ...p, variants: p.variants.filter((v) => !v.notSoldInPos) }));
|
|
26
|
+
}
|
|
14
27
|
if (query.searchValue) {
|
|
15
28
|
const search = String(query.searchValue).toLowerCase();
|
|
16
29
|
products = products.filter((p) => p.name.toLowerCase().includes(search) || p.sku?.toLowerCase().includes(search));
|
|
@@ -42,8 +42,24 @@ export interface GetProductsParams {
|
|
|
42
42
|
};
|
|
43
43
|
supplier?: string;
|
|
44
44
|
externalId?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Product-level flag filter. `true` = only products flagged `notSoldInPos`; `false` = only
|
|
47
|
+
* products NOT flagged (a missing field counts as not flagged). On a till, naming it switches off
|
|
48
|
+
* the default exclusion, so `true` works without `includeUnlisted`.
|
|
49
|
+
*/
|
|
50
|
+
notSoldInPos?: boolean;
|
|
51
|
+
/** Product-level flag filter: `true` = flagged `notSoldOnline`; `false` = sold online (missing counts). On a storefront, naming it switches off the default exclusion. */
|
|
52
|
+
notSoldOnline?: boolean;
|
|
45
53
|
[key: string]: any;
|
|
46
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* The sales-channel flag follows the host channel: `notSoldInPos` on a till, `notSoldOnline` on a
|
|
57
|
+
* storefront. Products with that flag are left out unless this is `true` (default `false`) or the
|
|
58
|
+
* query names that flag. They still cannot be sold: `addProductToCart` / `addBookingToCart` refuse a
|
|
59
|
+
* product or a variant with it. Without it, flagged variants are also stripped from `variants[]`
|
|
60
|
+
* and a product whose every variant is flagged is left out — whatever the query says.
|
|
61
|
+
*/
|
|
62
|
+
includeUnlisted?: boolean;
|
|
47
63
|
/** Defaults to 0. */
|
|
48
64
|
offset?: number;
|
|
49
65
|
/** Defaults to 100. */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ResumeParkedOrder } from
|
|
1
|
+
import { ResumeParkedOrder } from './types';
|
|
2
2
|
export declare const mockResumeParkedOrder: ResumeParkedOrder;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { MOCK_PARKED_ORDERS, MOCK_CART, resetMockCart, mockPublishEvent } from
|
|
1
|
+
import { MOCK_PARKED_ORDERS, MOCK_CART, MOCK_PRODUCTS, resetMockCart, mockPublishEvent } from '../../demo/database';
|
|
2
2
|
export const mockResumeParkedOrder = async (params) => {
|
|
3
|
-
console.log(
|
|
3
|
+
console.log('[Mock] resumeParkedOrder called', params);
|
|
4
4
|
const orderId = params?.orderId;
|
|
5
5
|
let orderToResume = null;
|
|
6
6
|
let index = -1;
|
|
7
7
|
if (orderId) {
|
|
8
|
-
index = MOCK_PARKED_ORDERS.findIndex(o => o._id === orderId);
|
|
8
|
+
index = MOCK_PARKED_ORDERS.findIndex((o) => o._id === orderId);
|
|
9
9
|
if (index !== -1)
|
|
10
10
|
orderToResume = MOCK_PARKED_ORDERS[index];
|
|
11
11
|
}
|
|
@@ -17,8 +17,14 @@ export const mockResumeParkedOrder = async (params) => {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
if (!orderToResume) {
|
|
20
|
-
throw new Error(
|
|
20
|
+
throw new Error('Parked order not found');
|
|
21
21
|
}
|
|
22
|
+
// Same refusal and text as the host, before anything is restored: the parked order stays.
|
|
23
|
+
const notSoldNames = orderToResume.lineItems
|
|
24
|
+
.filter((li) => MOCK_PRODUCTS.some((p) => p.variants.some((v) => v._id === li.variantId && (p.notSoldInPos || v.notSoldInPos))))
|
|
25
|
+
.map((li) => li.name);
|
|
26
|
+
if (notSoldNames.length)
|
|
27
|
+
throw new Error(`${notSoldNames.join(', ')} is not sold in POS`);
|
|
22
28
|
// Restore to MOCK_CART
|
|
23
29
|
// Logic to convert Order back to Cart (simplified)
|
|
24
30
|
resetMockCart();
|
|
@@ -26,7 +32,7 @@ export const mockResumeParkedOrder = async (params) => {
|
|
|
26
32
|
MOCK_CART.customer = orderToResume.customer; // Cast if needed
|
|
27
33
|
// MOCK_CART.products = orderToResume.lineItems... (Mapping needed)
|
|
28
34
|
// For Mock demo, we'll do a best effort mapping
|
|
29
|
-
MOCK_CART.products = orderToResume.lineItems.map(li => ({
|
|
35
|
+
MOCK_CART.products = orderToResume.lineItems.map((li) => ({
|
|
30
36
|
id: li.productId,
|
|
31
37
|
name: li.name,
|
|
32
38
|
quantity: li.quantity,
|
|
@@ -36,8 +42,8 @@ export const mockResumeParkedOrder = async (params) => {
|
|
|
36
42
|
sku: li.sku,
|
|
37
43
|
images: [li.image],
|
|
38
44
|
stock: 100,
|
|
39
|
-
taxTableId:
|
|
40
|
-
attributes: li.attributes
|
|
45
|
+
taxTableId: '',
|
|
46
|
+
attributes: li.attributes,
|
|
41
47
|
}));
|
|
42
48
|
MOCK_CART.subtotal = orderToResume.summary.subtotalAfterFees;
|
|
43
49
|
MOCK_CART.total = orderToResume.summary.total;
|
|
@@ -46,11 +52,11 @@ export const mockResumeParkedOrder = async (params) => {
|
|
|
46
52
|
// Remove from parked
|
|
47
53
|
MOCK_PARKED_ORDERS.splice(index, 1);
|
|
48
54
|
// Refresh the restored cart and the order lists.
|
|
49
|
-
mockPublishEvent(
|
|
50
|
-
mockPublishEvent(
|
|
55
|
+
mockPublishEvent('cart', 'parked-order-resumed', { orderId });
|
|
56
|
+
mockPublishEvent('orders', 'parked-order-resumed', { orderId });
|
|
51
57
|
return {
|
|
52
58
|
success: true,
|
|
53
59
|
order: orderToResume,
|
|
54
|
-
timestamp: new Date().toISOString()
|
|
60
|
+
timestamp: new Date().toISOString(),
|
|
55
61
|
};
|
|
56
62
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MOCK_CART, mockPublishEvent } from '../../demo/database';
|
|
1
|
+
import { MOCK_CART, MOCK_PRODUCTS, mockPublishEvent } from '../../demo/database';
|
|
2
2
|
import { extendPrice, isValidQuantity } from '@final-commerce/common';
|
|
3
3
|
export const mockUpdateCartItemQuantity = (params) => {
|
|
4
4
|
console.log('[Mock] updateCartItemQuantity called', params);
|
|
@@ -44,6 +44,12 @@ export const mockUpdateCartItemQuantity = (params) => {
|
|
|
44
44
|
timestamp: new Date().toISOString(),
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
+
// Same refusal and text as the host: raising a line not sold in POS (lowering always works).
|
|
48
|
+
const source = MOCK_PRODUCTS.find((p) => p.variants.some((v) => v._id === product.variantId));
|
|
49
|
+
const variant = source?.variants.find((v) => v._id === product.variantId);
|
|
50
|
+
if (quantity > previousQuantity && (source?.notSoldInPos || variant?.notSoldInPos)) {
|
|
51
|
+
throw new Error(`${source?.name} is not sold in POS`);
|
|
52
|
+
}
|
|
47
53
|
// Update quantity
|
|
48
54
|
product.quantity = quantity;
|
|
49
55
|
// Difference of the two ROUNDED extensions — rounding the delta itself would let the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@final-commerce/command-frame",
|
|
3
|
-
"version": "0.8.1-online.
|
|
3
|
+
"version": "0.8.1-online.2",
|
|
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.1-online.
|
|
60
|
+
"@final-commerce/common": "2.4.1-online.3"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@commitlint/cli": "^19.0.0",
|