@final-commerce/command-frame 0.1.39 → 0.1.41-develop
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/CommonTypes.d.ts +85 -37
- package/dist/CommonTypes.js +44 -0
- package/dist/actions/add-product/mock.js +7 -5
- package/dist/actions/add-product/types.d.ts +2 -2
- package/dist/actions/edit-product/mock.js +3 -1
- package/dist/actions/get-context/mock.js +1 -0
- package/dist/actions/get-current-company-custom-extensions/mock.js +2 -2
- package/dist/actions/get-custom-extensions/mock.js +2 -2
- package/dist/actions/resume-parked-order/mock.js +3 -3
- package/dist/common-types/custom-extensions.d.ts +1 -1
- package/dist/demo/database.d.ts +1 -1
- package/dist/demo/database.js +66 -60
- package/dist/demo/mocks/custom-tables.js +3 -3
- package/dist/projects/render/mocks.js +4 -0
- package/dist/projects/render/types.d.ts +3 -1
- package/dist/provider.d.ts +6 -0
- package/dist/provider.js +26 -7
- package/package.json +3 -2
package/dist/CommonTypes.d.ts
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
1
|
export * from "./common-types";
|
|
2
|
+
export declare enum CurrencyCode {
|
|
3
|
+
USD = "USD",
|
|
4
|
+
EUR = "EUR",
|
|
5
|
+
GBP = "GBP",
|
|
6
|
+
CAD = "CAD",
|
|
7
|
+
AUD = "AUD",
|
|
8
|
+
NZD = "NZD",
|
|
9
|
+
CHF = "CHF",
|
|
10
|
+
CNY = "CNY",
|
|
11
|
+
INR = "INR",
|
|
12
|
+
MXN = "MXN",
|
|
13
|
+
BRL = "BRL",
|
|
14
|
+
ZAR = "ZAR",
|
|
15
|
+
SGD = "SGD",
|
|
16
|
+
HKD = "HKD",
|
|
17
|
+
SEK = "SEK",
|
|
18
|
+
NOK = "NOK",
|
|
19
|
+
DKK = "DKK",
|
|
20
|
+
PLN = "PLN",
|
|
21
|
+
THB = "THB",
|
|
22
|
+
MYR = "MYR",
|
|
23
|
+
PHP = "PHP",
|
|
24
|
+
IDR = "IDR",
|
|
25
|
+
AED = "AED",
|
|
26
|
+
SAR = "SAR",
|
|
27
|
+
ILS = "ILS",
|
|
28
|
+
TRY = "TRY",
|
|
29
|
+
RUB = "RUB",
|
|
30
|
+
JPY = "JPY",
|
|
31
|
+
KRW = "KRW",
|
|
32
|
+
VND = "VND",
|
|
33
|
+
CLP = "CLP",
|
|
34
|
+
ISK = "ISK",
|
|
35
|
+
HUF = "HUF",
|
|
36
|
+
TWD = "TWD",
|
|
37
|
+
KWD = "KWD",
|
|
38
|
+
BHD = "BHD",
|
|
39
|
+
OMR = "OMR",
|
|
40
|
+
JOD = "JOD",
|
|
41
|
+
TND = "TND",
|
|
42
|
+
LYD = "LYD",
|
|
43
|
+
IQD = "IQD"
|
|
44
|
+
}
|
|
2
45
|
export declare enum CFProductType {
|
|
3
46
|
SIMPLE = "simple",
|
|
4
47
|
VARIABLE = "variable"
|
|
@@ -51,7 +94,7 @@ export interface CFTax {
|
|
|
51
94
|
id: string;
|
|
52
95
|
name: string;
|
|
53
96
|
percentage: number;
|
|
54
|
-
amount:
|
|
97
|
+
amount: number;
|
|
55
98
|
taxTableName: string;
|
|
56
99
|
taxTableId: string;
|
|
57
100
|
}
|
|
@@ -82,11 +125,11 @@ export interface CFCategory {
|
|
|
82
125
|
}
|
|
83
126
|
export interface CFProductVariant {
|
|
84
127
|
sku: string;
|
|
85
|
-
price:
|
|
86
|
-
salePrice:
|
|
128
|
+
price: number;
|
|
129
|
+
salePrice: number;
|
|
87
130
|
isOnSale: boolean;
|
|
88
131
|
barcode?: string;
|
|
89
|
-
costPrice?:
|
|
132
|
+
costPrice?: number;
|
|
90
133
|
manageStock: boolean;
|
|
91
134
|
externalId?: string;
|
|
92
135
|
inventory?: CFInventory[];
|
|
@@ -121,8 +164,10 @@ export interface CFProduct {
|
|
|
121
164
|
sku?: string;
|
|
122
165
|
productType: CFProductType;
|
|
123
166
|
variants: CFProductVariant[];
|
|
124
|
-
|
|
125
|
-
|
|
167
|
+
currency: CurrencyCode;
|
|
168
|
+
minorUnits: number;
|
|
169
|
+
minPrice?: number;
|
|
170
|
+
maxPrice?: number;
|
|
126
171
|
status?: string;
|
|
127
172
|
isDeleted?: boolean;
|
|
128
173
|
}
|
|
@@ -172,40 +217,40 @@ export interface CFActiveCustomer extends CFCustomer {
|
|
|
172
217
|
id?: string;
|
|
173
218
|
}
|
|
174
219
|
export interface CFTip {
|
|
175
|
-
amount:
|
|
220
|
+
amount: number;
|
|
176
221
|
percentage: number;
|
|
177
222
|
}
|
|
178
223
|
export interface CFSummary {
|
|
179
|
-
discountTotal:
|
|
180
|
-
shippingTotal?:
|
|
181
|
-
total:
|
|
182
|
-
totalTaxes:
|
|
183
|
-
subTotal:
|
|
224
|
+
discountTotal: number;
|
|
225
|
+
shippingTotal?: number | null;
|
|
226
|
+
total: number;
|
|
227
|
+
totalTaxes: number;
|
|
228
|
+
subTotal: number;
|
|
184
229
|
taxes: CFTax[];
|
|
185
230
|
tip?: CFTip | null;
|
|
186
231
|
isTaxInclusive: boolean;
|
|
187
232
|
}
|
|
188
233
|
export interface CFCartDiscountItem {
|
|
189
234
|
label: string;
|
|
190
|
-
amount:
|
|
235
|
+
amount: number;
|
|
191
236
|
percentage: number;
|
|
192
237
|
}
|
|
193
238
|
export interface CFCartFeeItem {
|
|
194
239
|
id: string;
|
|
195
240
|
label: string;
|
|
196
|
-
amount:
|
|
241
|
+
amount: number;
|
|
197
242
|
percentage: number;
|
|
198
243
|
taxTableId?: string;
|
|
199
|
-
tax?:
|
|
244
|
+
tax?: number;
|
|
200
245
|
taxName: string;
|
|
201
246
|
}
|
|
202
247
|
export interface CFTipPayment {
|
|
203
|
-
amount:
|
|
248
|
+
amount: number;
|
|
204
249
|
tipTo: string;
|
|
205
250
|
percentage: number;
|
|
206
251
|
}
|
|
207
252
|
export interface CFRefundedTipPayment {
|
|
208
|
-
amount:
|
|
253
|
+
amount: number;
|
|
209
254
|
percentage: number;
|
|
210
255
|
transactionId: string;
|
|
211
256
|
tipTo: string;
|
|
@@ -213,11 +258,11 @@ export interface CFRefundedTipPayment {
|
|
|
213
258
|
export interface CFPaymentMethod {
|
|
214
259
|
transactionId: string;
|
|
215
260
|
paymentType: string;
|
|
216
|
-
amount:
|
|
261
|
+
amount: number;
|
|
217
262
|
timestamp: string;
|
|
218
263
|
processor: string;
|
|
219
264
|
saleId?: string;
|
|
220
|
-
change?:
|
|
265
|
+
change?: number | null;
|
|
221
266
|
tip?: CFTipPayment | null;
|
|
222
267
|
cashRounding?: number;
|
|
223
268
|
emv?: string | null;
|
|
@@ -233,13 +278,13 @@ export interface CFPosDataItem {
|
|
|
233
278
|
}
|
|
234
279
|
export interface CFDiscountDetail {
|
|
235
280
|
percentage: number;
|
|
236
|
-
amount:
|
|
281
|
+
amount: number;
|
|
237
282
|
const?: string;
|
|
238
283
|
}
|
|
239
284
|
export interface CFFeeDetail {
|
|
240
285
|
percentage: number;
|
|
241
|
-
amount:
|
|
242
|
-
tax:
|
|
286
|
+
amount: number;
|
|
287
|
+
tax: number;
|
|
243
288
|
taxTableId: string;
|
|
244
289
|
}
|
|
245
290
|
export interface CFDiscountLineItem {
|
|
@@ -257,12 +302,12 @@ export interface CFLineItem {
|
|
|
257
302
|
internalId?: string;
|
|
258
303
|
name: string;
|
|
259
304
|
quantity: number;
|
|
260
|
-
price:
|
|
305
|
+
price: number;
|
|
261
306
|
taxes: CFTax[];
|
|
262
307
|
discount: CFDiscountLineItem;
|
|
263
308
|
fee: CFFeeLineItem;
|
|
264
|
-
totalTax:
|
|
265
|
-
total:
|
|
309
|
+
totalTax: number;
|
|
310
|
+
total: number;
|
|
266
311
|
metadata: CFMetadataItem[];
|
|
267
312
|
image: string;
|
|
268
313
|
sku: string;
|
|
@@ -276,21 +321,21 @@ export interface CFLineItem {
|
|
|
276
321
|
export interface CFCustomSale {
|
|
277
322
|
customSaleId: string;
|
|
278
323
|
name: string;
|
|
279
|
-
price:
|
|
324
|
+
price: number;
|
|
280
325
|
quantity: number;
|
|
281
326
|
applyTaxes: boolean;
|
|
282
|
-
total:
|
|
283
|
-
totalTax:
|
|
327
|
+
total: number;
|
|
328
|
+
totalTax: number;
|
|
284
329
|
taxes: CFTax[];
|
|
285
330
|
discount: {
|
|
286
331
|
cartDiscount: CFDiscountDetail;
|
|
287
332
|
};
|
|
288
333
|
fee: {
|
|
289
334
|
cartFee: {
|
|
290
|
-
amount:
|
|
335
|
+
amount: number;
|
|
291
336
|
label: string;
|
|
292
337
|
percentage: number;
|
|
293
|
-
tax:
|
|
338
|
+
tax: number;
|
|
294
339
|
taxTableId: string;
|
|
295
340
|
};
|
|
296
341
|
};
|
|
@@ -303,11 +348,11 @@ export interface CFRefundedLineItem {
|
|
|
303
348
|
internalId?: string;
|
|
304
349
|
name: string;
|
|
305
350
|
quantity: number;
|
|
306
|
-
price:
|
|
351
|
+
price: number;
|
|
307
352
|
taxes: CFTax[];
|
|
308
353
|
discount: CFDiscountLineItem;
|
|
309
|
-
totalTax:
|
|
310
|
-
total:
|
|
354
|
+
totalTax: number;
|
|
355
|
+
total: number;
|
|
311
356
|
image: string;
|
|
312
357
|
sku: string;
|
|
313
358
|
note?: string;
|
|
@@ -326,12 +371,15 @@ export interface CFRefundItem {
|
|
|
326
371
|
timestamp: string | undefined;
|
|
327
372
|
summary?: CFSummary;
|
|
328
373
|
refundPayment: CFPaymentMethod[];
|
|
329
|
-
balance?:
|
|
374
|
+
balance?: number;
|
|
330
375
|
receiptId?: string;
|
|
331
|
-
currency
|
|
376
|
+
currency: CurrencyCode;
|
|
377
|
+
minorUnits: number;
|
|
332
378
|
}
|
|
333
379
|
export interface CFOrder {
|
|
334
380
|
_id: string;
|
|
381
|
+
currency: CurrencyCode;
|
|
382
|
+
minorUnits: number;
|
|
335
383
|
receiptId?: string;
|
|
336
384
|
companyId: string;
|
|
337
385
|
externalId: string | null;
|
|
@@ -354,7 +402,7 @@ export interface CFOrder {
|
|
|
354
402
|
lineItems: CFLineItem[];
|
|
355
403
|
customSales: CFCustomSale[];
|
|
356
404
|
refund?: CFRefundItem[];
|
|
357
|
-
balance:
|
|
405
|
+
balance: number;
|
|
358
406
|
signature?: string | null;
|
|
359
407
|
}
|
|
360
408
|
export interface CFActiveUserRole {
|
|
@@ -425,7 +473,6 @@ export interface CFActiveOrder extends CFOrder {
|
|
|
425
473
|
outlet?: CFActiveOutlet;
|
|
426
474
|
isDeleted?: boolean;
|
|
427
475
|
newOrder?: boolean;
|
|
428
|
-
currency?: string;
|
|
429
476
|
station?: CFActiveStation;
|
|
430
477
|
}
|
|
431
478
|
export interface CFActiveCustomSales {
|
|
@@ -475,6 +522,7 @@ export interface CFContextRender {
|
|
|
475
522
|
buildVersion: string | null;
|
|
476
523
|
buildSourceId: string | null;
|
|
477
524
|
buildIsPremium: boolean;
|
|
525
|
+
isOffline: boolean;
|
|
478
526
|
user: Record<string, any> | null;
|
|
479
527
|
company: Omit<Record<string, any>, 'settings'> | null;
|
|
480
528
|
station: Record<string, any> | null;
|
package/dist/CommonTypes.js
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
1
|
export * from "./common-types";
|
|
2
|
+
export var CurrencyCode;
|
|
3
|
+
(function (CurrencyCode) {
|
|
4
|
+
CurrencyCode["USD"] = "USD";
|
|
5
|
+
CurrencyCode["EUR"] = "EUR";
|
|
6
|
+
CurrencyCode["GBP"] = "GBP";
|
|
7
|
+
CurrencyCode["CAD"] = "CAD";
|
|
8
|
+
CurrencyCode["AUD"] = "AUD";
|
|
9
|
+
CurrencyCode["NZD"] = "NZD";
|
|
10
|
+
CurrencyCode["CHF"] = "CHF";
|
|
11
|
+
CurrencyCode["CNY"] = "CNY";
|
|
12
|
+
CurrencyCode["INR"] = "INR";
|
|
13
|
+
CurrencyCode["MXN"] = "MXN";
|
|
14
|
+
CurrencyCode["BRL"] = "BRL";
|
|
15
|
+
CurrencyCode["ZAR"] = "ZAR";
|
|
16
|
+
CurrencyCode["SGD"] = "SGD";
|
|
17
|
+
CurrencyCode["HKD"] = "HKD";
|
|
18
|
+
CurrencyCode["SEK"] = "SEK";
|
|
19
|
+
CurrencyCode["NOK"] = "NOK";
|
|
20
|
+
CurrencyCode["DKK"] = "DKK";
|
|
21
|
+
CurrencyCode["PLN"] = "PLN";
|
|
22
|
+
CurrencyCode["THB"] = "THB";
|
|
23
|
+
CurrencyCode["MYR"] = "MYR";
|
|
24
|
+
CurrencyCode["PHP"] = "PHP";
|
|
25
|
+
CurrencyCode["IDR"] = "IDR";
|
|
26
|
+
CurrencyCode["AED"] = "AED";
|
|
27
|
+
CurrencyCode["SAR"] = "SAR";
|
|
28
|
+
CurrencyCode["ILS"] = "ILS";
|
|
29
|
+
CurrencyCode["TRY"] = "TRY";
|
|
30
|
+
CurrencyCode["RUB"] = "RUB";
|
|
31
|
+
CurrencyCode["JPY"] = "JPY";
|
|
32
|
+
CurrencyCode["KRW"] = "KRW";
|
|
33
|
+
CurrencyCode["VND"] = "VND";
|
|
34
|
+
CurrencyCode["CLP"] = "CLP";
|
|
35
|
+
CurrencyCode["ISK"] = "ISK";
|
|
36
|
+
CurrencyCode["HUF"] = "HUF";
|
|
37
|
+
CurrencyCode["TWD"] = "TWD";
|
|
38
|
+
CurrencyCode["KWD"] = "KWD";
|
|
39
|
+
CurrencyCode["BHD"] = "BHD";
|
|
40
|
+
CurrencyCode["OMR"] = "OMR";
|
|
41
|
+
CurrencyCode["JOD"] = "JOD";
|
|
42
|
+
CurrencyCode["TND"] = "TND";
|
|
43
|
+
CurrencyCode["LYD"] = "LYD";
|
|
44
|
+
CurrencyCode["IQD"] = "IQD";
|
|
45
|
+
})(CurrencyCode || (CurrencyCode = {}));
|
|
2
46
|
// Enums
|
|
3
47
|
export var CFProductType;
|
|
4
48
|
(function (CFProductType) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { CFProductType } from "../../CommonTypes";
|
|
1
|
+
import { CFProductType, CurrencyCode } from "../../CommonTypes";
|
|
2
2
|
export const mockAddProduct = async (params) => {
|
|
3
3
|
console.log("[Mock] addProduct called", params);
|
|
4
4
|
const hasVariants = params.variants && params.variants.length > 0;
|
|
5
5
|
return {
|
|
6
6
|
product: {
|
|
7
7
|
_id: "mock_product_" + Date.now(),
|
|
8
|
+
currency: CurrencyCode.USD,
|
|
9
|
+
minorUnits: 2,
|
|
8
10
|
name: params.name,
|
|
9
11
|
description: params.description,
|
|
10
12
|
categories: params.categories || [],
|
|
@@ -14,15 +16,15 @@ export const mockAddProduct = async (params) => {
|
|
|
14
16
|
sku: params.sku,
|
|
15
17
|
productType: hasVariants ? CFProductType.VARIABLE : CFProductType.SIMPLE,
|
|
16
18
|
attributes: [],
|
|
17
|
-
minPrice: params.price ||
|
|
18
|
-
maxPrice: params.price ||
|
|
19
|
+
minPrice: params.price || 0,
|
|
20
|
+
maxPrice: params.price || 0,
|
|
19
21
|
variants: hasVariants
|
|
20
22
|
? params.variants.map((v, i) => ({ ...v, _id: `mock_variant_${Date.now()}_${i}` }))
|
|
21
23
|
: [{
|
|
22
24
|
_id: `mock_variant_${Date.now()}_0`,
|
|
23
25
|
sku: params.sku || "",
|
|
24
|
-
price: params.price ||
|
|
25
|
-
salePrice:
|
|
26
|
+
price: params.price || 0,
|
|
27
|
+
salePrice: 0,
|
|
26
28
|
isOnSale: false,
|
|
27
29
|
manageStock: params.manageStock || false,
|
|
28
30
|
attributes: [],
|
|
@@ -7,9 +7,9 @@ export interface AddProductParams {
|
|
|
7
7
|
images?: string[];
|
|
8
8
|
status?: 'active' | 'inactive';
|
|
9
9
|
/** For simple products: set price directly */
|
|
10
|
-
price?:
|
|
10
|
+
price?: number;
|
|
11
11
|
sku?: string;
|
|
12
|
-
costPrice?:
|
|
12
|
+
costPrice?: number;
|
|
13
13
|
manageStock?: boolean;
|
|
14
14
|
/** For variable products: provide variants array */
|
|
15
15
|
variants?: Omit<CFProductVariant, '_id'>[];
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { CFProductType } from "../../CommonTypes";
|
|
1
|
+
import { CFProductType, CurrencyCode } from "../../CommonTypes";
|
|
2
2
|
export const mockEditProduct = async (params) => {
|
|
3
3
|
console.log("[Mock] editProduct called", params);
|
|
4
4
|
return {
|
|
5
5
|
product: {
|
|
6
6
|
_id: params.productId,
|
|
7
|
+
currency: CurrencyCode.USD,
|
|
8
|
+
minorUnits: 2,
|
|
7
9
|
name: params.changes.name || "Updated Product",
|
|
8
10
|
description: params.changes.description,
|
|
9
11
|
categories: params.changes.categories || [],
|
|
@@ -14,7 +14,7 @@ export const mockGetCurrentCompanyCustomExtensions = async (params) => {
|
|
|
14
14
|
"https://example.com/images/loyalty-1.png",
|
|
15
15
|
"https://example.com/images/loyalty-2.png"
|
|
16
16
|
],
|
|
17
|
-
price:
|
|
17
|
+
price: 2999,
|
|
18
18
|
website: "https://loyalty-extension.example.com",
|
|
19
19
|
isDeleted: false,
|
|
20
20
|
createdAt: "2024-01-01T10:00:00.000Z",
|
|
@@ -29,7 +29,7 @@ export const mockGetCurrentCompanyCustomExtensions = async (params) => {
|
|
|
29
29
|
short_description: "Real-time inventory insights",
|
|
30
30
|
long_description: "Get detailed insights into your inventory with real-time tracking, low stock alerts, and comprehensive reporting.",
|
|
31
31
|
main_image: "https://example.com/images/inventory-extension.png",
|
|
32
|
-
price:
|
|
32
|
+
price: 4999,
|
|
33
33
|
isDeleted: false,
|
|
34
34
|
createdAt: "2024-01-05T08:00:00.000Z",
|
|
35
35
|
updatedAt: "2024-01-05T08:00:00.000Z",
|
|
@@ -14,7 +14,7 @@ export const mockGetCustomExtensions = async () => {
|
|
|
14
14
|
"https://example.com/images/loyalty-1.png",
|
|
15
15
|
"https://example.com/images/loyalty-2.png"
|
|
16
16
|
],
|
|
17
|
-
price:
|
|
17
|
+
price: 2999,
|
|
18
18
|
website: "https://loyalty-extension.example.com",
|
|
19
19
|
isDeleted: false,
|
|
20
20
|
createdAt: "2024-01-01T10:00:00.000Z",
|
|
@@ -29,7 +29,7 @@ export const mockGetCustomExtensions = async () => {
|
|
|
29
29
|
short_description: "Real-time inventory insights",
|
|
30
30
|
long_description: "Get detailed insights into your inventory with real-time tracking, low stock alerts, and comprehensive reporting.",
|
|
31
31
|
main_image: "https://example.com/images/inventory-extension.png",
|
|
32
|
-
price:
|
|
32
|
+
price: 4999,
|
|
33
33
|
isDeleted: false,
|
|
34
34
|
createdAt: "2024-01-05T08:00:00.000Z",
|
|
35
35
|
updatedAt: "2024-01-05T08:00:00.000Z",
|
|
@@ -30,7 +30,7 @@ export const mockResumeParkedOrder = async (params) => {
|
|
|
30
30
|
id: li.productId,
|
|
31
31
|
name: li.name,
|
|
32
32
|
quantity: li.quantity,
|
|
33
|
-
price:
|
|
33
|
+
price: li.price,
|
|
34
34
|
internalId: li.internalId || li.productId,
|
|
35
35
|
variantId: li.variantId,
|
|
36
36
|
sku: li.sku,
|
|
@@ -39,8 +39,8 @@ export const mockResumeParkedOrder = async (params) => {
|
|
|
39
39
|
taxTableId: "",
|
|
40
40
|
attributes: li.attributes
|
|
41
41
|
}));
|
|
42
|
-
MOCK_CART.subtotal =
|
|
43
|
-
MOCK_CART.total =
|
|
42
|
+
MOCK_CART.subtotal = orderToResume.summary.subTotal;
|
|
43
|
+
MOCK_CART.total = orderToResume.summary.total;
|
|
44
44
|
MOCK_CART.amountToBeCharged = MOCK_CART.total;
|
|
45
45
|
MOCK_CART.remainingBalance = MOCK_CART.total;
|
|
46
46
|
// Remove from parked
|
package/dist/demo/database.d.ts
CHANGED
|
@@ -53,4 +53,4 @@ export declare const safeSerialize: <T>(data: T) => T;
|
|
|
53
53
|
type MockEventCallback = (event: any) => void;
|
|
54
54
|
export declare const mockPublishEvent: (topic: string, eventType: string, data: any) => void;
|
|
55
55
|
export declare const mockSubscribeToTopic: (topic: string, callback: MockEventCallback) => void;
|
|
56
|
-
export declare const createOrderFromCart: (paymentType: string, amount: number
|
|
56
|
+
export declare const createOrderFromCart: (paymentType: string, amount: number, processor?: string) => CFActiveOrder;
|
package/dist/demo/database.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Mock Database for Standalone/Demo Mode
|
|
3
3
|
* Stores mock data that mimics the Render environment
|
|
4
4
|
*/
|
|
5
|
-
import { CFProductType, CFUserTypes, } from "../CommonTypes";
|
|
5
|
+
import { CFProductType, CFUserTypes, CurrencyCode, } from "../CommonTypes";
|
|
6
6
|
export * from './mocks';
|
|
7
7
|
// Asset Imports - Using Remote URLs to avoid build complexity with asset copying
|
|
8
8
|
const ASSETS_BASE_URL = "https://raw.githubusercontent.com/Final-Commerce/command-frame/refs/heads/main/src/demo/assets";
|
|
@@ -195,6 +195,8 @@ const createSimpleProduct = (id, name, price, image, categories, description) =>
|
|
|
195
195
|
companyId: COMPANY_ID,
|
|
196
196
|
externalId: `ext_${id}`,
|
|
197
197
|
sku,
|
|
198
|
+
currency: CurrencyCode.USD,
|
|
199
|
+
minorUnits: 2,
|
|
198
200
|
minPrice: price,
|
|
199
201
|
maxPrice: price,
|
|
200
202
|
status: "active",
|
|
@@ -202,7 +204,6 @@ const createSimpleProduct = (id, name, price, image, categories, description) =>
|
|
|
202
204
|
taxTable: "tax_standard",
|
|
203
205
|
description,
|
|
204
206
|
images: [image],
|
|
205
|
-
// Render stores product categories as an array of category IDs
|
|
206
207
|
categories: categories.map(c => c._id),
|
|
207
208
|
attributes: [],
|
|
208
209
|
variants: [
|
|
@@ -210,7 +211,7 @@ const createSimpleProduct = (id, name, price, image, categories, description) =>
|
|
|
210
211
|
_id: `${id}_var_main`,
|
|
211
212
|
sku,
|
|
212
213
|
price,
|
|
213
|
-
salePrice:
|
|
214
|
+
salePrice: 0,
|
|
214
215
|
isOnSale: false,
|
|
215
216
|
manageStock: true,
|
|
216
217
|
externalId: `ext_${id}_var`,
|
|
@@ -229,6 +230,8 @@ const createVariableProduct = (id, name, basePrice, largePrice, image, categorie
|
|
|
229
230
|
companyId: COMPANY_ID,
|
|
230
231
|
externalId: `ext_${id}`,
|
|
231
232
|
sku: skuBase,
|
|
233
|
+
currency: CurrencyCode.USD,
|
|
234
|
+
minorUnits: 2,
|
|
232
235
|
minPrice: basePrice,
|
|
233
236
|
maxPrice: largePrice,
|
|
234
237
|
status: "active",
|
|
@@ -236,7 +239,6 @@ const createVariableProduct = (id, name, basePrice, largePrice, image, categorie
|
|
|
236
239
|
taxTable: "tax_standard",
|
|
237
240
|
description,
|
|
238
241
|
images: [image],
|
|
239
|
-
// Render stores product categories as an array of category IDs
|
|
240
242
|
categories: categories.map(c => c._id),
|
|
241
243
|
attributes: [{ name: "Size", values: ["Small", "Large"] }],
|
|
242
244
|
variants: [
|
|
@@ -244,7 +246,7 @@ const createVariableProduct = (id, name, basePrice, largePrice, image, categorie
|
|
|
244
246
|
_id: `${id}_var_small`,
|
|
245
247
|
sku: `${skuBase}-S`,
|
|
246
248
|
price: basePrice,
|
|
247
|
-
salePrice:
|
|
249
|
+
salePrice: 0,
|
|
248
250
|
isOnSale: false,
|
|
249
251
|
manageStock: true,
|
|
250
252
|
externalId: `ext_${id}_var_s`,
|
|
@@ -255,7 +257,7 @@ const createVariableProduct = (id, name, basePrice, largePrice, image, categorie
|
|
|
255
257
|
_id: `${id}_var_large`,
|
|
256
258
|
sku: `${skuBase}-L`,
|
|
257
259
|
price: largePrice,
|
|
258
|
-
salePrice:
|
|
260
|
+
salePrice: 0,
|
|
259
261
|
isOnSale: false,
|
|
260
262
|
manageStock: true,
|
|
261
263
|
externalId: `ext_${id}_var_l`,
|
|
@@ -265,23 +267,23 @@ const createVariableProduct = (id, name, basePrice, largePrice, image, categorie
|
|
|
265
267
|
]
|
|
266
268
|
};
|
|
267
269
|
};
|
|
268
|
-
export const MOCK_PRODUCT_BASIL_ALMOND = createSimpleProduct("prod_basil_almond", "Basil Almond Paste",
|
|
269
|
-
export const MOCK_PRODUCT_BEER = createVariableProduct("prod_beer", "Beer Paste",
|
|
270
|
-
export const MOCK_PRODUCT_BEET = createSimpleProduct("prod_beet", "Beet Paste",
|
|
271
|
-
export const MOCK_PRODUCT_CARAMELIZED = createVariableProduct("prod_caramelized", "Caramelized Paste",
|
|
272
|
-
export const MOCK_PRODUCT_GARLIC_ONION = createVariableProduct("prod_garlic_onion", "Garlic Onion Paste",
|
|
273
|
-
export const MOCK_PRODUCT_GARLIC = createSimpleProduct("prod_garlic", "Garlic Paste",
|
|
274
|
-
export const MOCK_PRODUCT_GINGER_LIME = createVariableProduct("prod_ginger_lime", "Ginger Lime Paste",
|
|
275
|
-
export const MOCK_PRODUCT_LEMON = createSimpleProduct("prod_lemon", "Lemon Paste",
|
|
276
|
-
export const MOCK_PRODUCT_RED_PEPPER = createVariableProduct("prod_red_pepper", "Red Pepper Paste",
|
|
277
|
-
export const MOCK_PRODUCT_ROASTED_TOMATO = createVariableProduct("prod_roasted_tomato", "Roasted Tomato Paste",
|
|
278
|
-
export const MOCK_PRODUCT_MINT_LEMON = createSimpleProduct("prod_mint_lemon", "Mint Lemon Paste",
|
|
270
|
+
export const MOCK_PRODUCT_BASIL_ALMOND = createSimpleProduct("prod_basil_almond", "Basil Almond Paste", 1200, basilAlmondImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_SPECIALTY, MOCK_CATEGORY_VEGAN], "A rich blend of fresh basil and roasted almonds.");
|
|
271
|
+
export const MOCK_PRODUCT_BEER = createVariableProduct("prod_beer", "Beer Paste", 1500, 2500, beerImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_SPECIALTY], "Unique paste infused with dark lager.");
|
|
272
|
+
export const MOCK_PRODUCT_BEET = createSimpleProduct("prod_beet", "Beet Paste", 1000, beetImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_BASIC, MOCK_CATEGORY_VEGAN], "Earthy and sweet beet paste, perfect for salads.");
|
|
273
|
+
export const MOCK_PRODUCT_CARAMELIZED = createVariableProduct("prod_caramelized", "Caramelized Paste", 1400, 2200, caramelizedImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_SPECIALTY, MOCK_CATEGORY_VEGAN], "Slow-cooked caramelized onion paste.");
|
|
274
|
+
export const MOCK_PRODUCT_GARLIC_ONION = createVariableProduct("prod_garlic_onion", "Garlic Onion Paste", 1100, 1800, garlicOnionImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_BASIC, MOCK_CATEGORY_VEGAN], "Classic savory base for any dish.");
|
|
275
|
+
export const MOCK_PRODUCT_GARLIC = createSimpleProduct("prod_garlic", "Garlic Paste", 900, garlicImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_BASIC, MOCK_CATEGORY_VEGAN], "Pure, intense garlic paste.");
|
|
276
|
+
export const MOCK_PRODUCT_GINGER_LIME = createVariableProduct("prod_ginger_lime", "Ginger Lime Paste", 1300, 2000, gingerLimeImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_SPECIALTY, MOCK_CATEGORY_SPICY, MOCK_CATEGORY_VEGAN], "Zesty and spicy, great for asian cuisine.");
|
|
277
|
+
export const MOCK_PRODUCT_LEMON = createSimpleProduct("prod_lemon", "Lemon Paste", 1050, lemonImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_BASIC, MOCK_CATEGORY_VEGAN], "Bright citrus flavor concentrate.");
|
|
278
|
+
export const MOCK_PRODUCT_RED_PEPPER = createVariableProduct("prod_red_pepper", "Red Pepper Paste", 1250, 1900, redPepperImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_BASIC, MOCK_CATEGORY_SPICY, MOCK_CATEGORY_VEGAN], "Roasted red peppers with a hint of spice.");
|
|
279
|
+
export const MOCK_PRODUCT_ROASTED_TOMATO = createVariableProduct("prod_roasted_tomato", "Roasted Tomato Paste", 1150, 1850, roastedTomatoImg, [MOCK_CATEGORY_PASTES, MOCK_CATEGORY_BASIC, MOCK_CATEGORY_VEGAN], "Deep, umami-rich tomato flavor.");
|
|
280
|
+
export const MOCK_PRODUCT_MINT_LEMON = createSimpleProduct("prod_mint_lemon", "Mint Lemon Paste", 1200, lemonImg, // Reusing lemon image for now
|
|
279
281
|
[MOCK_CATEGORY_PASTES, MOCK_CATEGORY_SPECIALTY, MOCK_CATEGORY_VEGAN], "Refreshing mint and lemon blend.");
|
|
280
|
-
export const MOCK_PRODUCT_CHILI_GARLIC = createVariableProduct("prod_chili_garlic", "Chili Garlic Paste",
|
|
282
|
+
export const MOCK_PRODUCT_CHILI_GARLIC = createVariableProduct("prod_chili_garlic", "Chili Garlic Paste", 1050, 1650, redPepperImg, // Reusing red pepper image
|
|
281
283
|
[MOCK_CATEGORY_PASTES, MOCK_CATEGORY_BASIC, MOCK_CATEGORY_SPICY, MOCK_CATEGORY_VEGAN], "Spicy garlic paste with chili flakes.");
|
|
282
|
-
export const MOCK_PRODUCT_HABANERO = createSimpleProduct("prod_habanero", "Habanero Paste",
|
|
284
|
+
export const MOCK_PRODUCT_HABANERO = createSimpleProduct("prod_habanero", "Habanero Paste", 1400, redPepperImg, // Reusing red pepper image
|
|
283
285
|
[MOCK_CATEGORY_PASTES, MOCK_CATEGORY_SPICY, MOCK_CATEGORY_VEGAN], "Extremely spicy habanero concentrate.");
|
|
284
|
-
export const MOCK_PRODUCT_BLACK_GARLIC = createSimpleProduct("prod_black_garlic", "Black Garlic Paste",
|
|
286
|
+
export const MOCK_PRODUCT_BLACK_GARLIC = createSimpleProduct("prod_black_garlic", "Black Garlic Paste", 1800, garlicImg, // Reusing garlic image
|
|
285
287
|
[MOCK_CATEGORY_PASTES, MOCK_CATEGORY_SPECIALTY, MOCK_CATEGORY_VEGAN], "Fermented black garlic paste, sweet and savory.");
|
|
286
288
|
// --- ORDERS ---
|
|
287
289
|
// Helper to create line item
|
|
@@ -295,12 +297,12 @@ const createLineItem = (product, variantIndex = 0, quantity = 1) => {
|
|
|
295
297
|
price: variant.price,
|
|
296
298
|
taxes: [],
|
|
297
299
|
discount: {
|
|
298
|
-
itemDiscount: { percentage: 0, amount:
|
|
299
|
-
cartDiscount: { percentage: 0, amount:
|
|
300
|
+
itemDiscount: { percentage: 0, amount: 0 },
|
|
301
|
+
cartDiscount: { percentage: 0, amount: 0 }
|
|
300
302
|
},
|
|
301
|
-
fee: { itemFee: { percentage: 0, amount:
|
|
302
|
-
totalTax:
|
|
303
|
-
total:
|
|
303
|
+
fee: { itemFee: { percentage: 0, amount: 0, tax: 0, taxTableId: "" } },
|
|
304
|
+
totalTax: 0,
|
|
305
|
+
total: variant.price * quantity,
|
|
304
306
|
metadata: [],
|
|
305
307
|
image: product.images?.[0] || "",
|
|
306
308
|
sku: variant.sku,
|
|
@@ -310,17 +312,19 @@ const createLineItem = (product, variantIndex = 0, quantity = 1) => {
|
|
|
310
312
|
};
|
|
311
313
|
export const MOCK_ORDER_1 = {
|
|
312
314
|
_id: "order_1001",
|
|
315
|
+
currency: CurrencyCode.USD,
|
|
316
|
+
minorUnits: 2,
|
|
313
317
|
receiptId: "1001-0001",
|
|
314
318
|
companyId: COMPANY_ID,
|
|
315
319
|
externalId: null,
|
|
316
320
|
status: "completed",
|
|
317
321
|
customer: MOCK_CUSTOMER_1,
|
|
318
322
|
summary: {
|
|
319
|
-
total:
|
|
320
|
-
subTotal:
|
|
321
|
-
discountTotal:
|
|
322
|
-
shippingTotal:
|
|
323
|
-
totalTaxes:
|
|
323
|
+
total: 2100,
|
|
324
|
+
subTotal: 2100,
|
|
325
|
+
discountTotal: 0,
|
|
326
|
+
shippingTotal: 0,
|
|
327
|
+
totalTaxes: 0,
|
|
324
328
|
taxes: [],
|
|
325
329
|
isTaxInclusive: false
|
|
326
330
|
},
|
|
@@ -330,7 +334,7 @@ export const MOCK_ORDER_1 = {
|
|
|
330
334
|
{
|
|
331
335
|
transactionId: "trans_cash_1",
|
|
332
336
|
paymentType: "cash",
|
|
333
|
-
amount:
|
|
337
|
+
amount: 2100,
|
|
334
338
|
timestamp: new Date().toISOString(),
|
|
335
339
|
processor: "cash"
|
|
336
340
|
}
|
|
@@ -346,11 +350,11 @@ export const MOCK_ORDER_1 = {
|
|
|
346
350
|
billing: MOCK_CUSTOMER_1.billing || null,
|
|
347
351
|
shipping: null,
|
|
348
352
|
lineItems: [
|
|
349
|
-
createLineItem(MOCK_PRODUCT_GARLIC, 0, 1),
|
|
350
|
-
createLineItem(MOCK_PRODUCT_BASIL_ALMOND, 0, 1)
|
|
353
|
+
createLineItem(MOCK_PRODUCT_GARLIC, 0, 1),
|
|
354
|
+
createLineItem(MOCK_PRODUCT_BASIL_ALMOND, 0, 1)
|
|
351
355
|
],
|
|
352
356
|
customSales: [],
|
|
353
|
-
balance:
|
|
357
|
+
balance: 0,
|
|
354
358
|
user: MOCK_USER_LUIGI,
|
|
355
359
|
outlet: MOCK_OUTLET_MAIN,
|
|
356
360
|
station: MOCK_STATION_1,
|
|
@@ -358,17 +362,19 @@ export const MOCK_ORDER_1 = {
|
|
|
358
362
|
};
|
|
359
363
|
export const MOCK_ORDER_2 = {
|
|
360
364
|
_id: "order_1002",
|
|
365
|
+
currency: CurrencyCode.USD,
|
|
366
|
+
minorUnits: 2,
|
|
361
367
|
receiptId: "1001-0002",
|
|
362
368
|
companyId: COMPANY_ID,
|
|
363
369
|
externalId: null,
|
|
364
370
|
status: "completed",
|
|
365
371
|
customer: MOCK_CUSTOMER_2,
|
|
366
372
|
summary: {
|
|
367
|
-
total:
|
|
368
|
-
subTotal:
|
|
369
|
-
discountTotal:
|
|
370
|
-
shippingTotal:
|
|
371
|
-
totalTaxes:
|
|
373
|
+
total: 3000,
|
|
374
|
+
subTotal: 3000,
|
|
375
|
+
discountTotal: 0,
|
|
376
|
+
shippingTotal: 0,
|
|
377
|
+
totalTaxes: 0,
|
|
372
378
|
taxes: [],
|
|
373
379
|
isTaxInclusive: false
|
|
374
380
|
},
|
|
@@ -378,7 +384,7 @@ export const MOCK_ORDER_2 = {
|
|
|
378
384
|
{
|
|
379
385
|
transactionId: "trans_card_1",
|
|
380
386
|
paymentType: "credit_card",
|
|
381
|
-
amount:
|
|
387
|
+
amount: 3000,
|
|
382
388
|
timestamp: new Date(Date.now() - 3600000).toISOString(),
|
|
383
389
|
processor: "stripe"
|
|
384
390
|
}
|
|
@@ -394,10 +400,10 @@ export const MOCK_ORDER_2 = {
|
|
|
394
400
|
billing: null,
|
|
395
401
|
shipping: null,
|
|
396
402
|
lineItems: [
|
|
397
|
-
createLineItem(MOCK_PRODUCT_BEER, 0, 2)
|
|
403
|
+
createLineItem(MOCK_PRODUCT_BEER, 0, 2)
|
|
398
404
|
],
|
|
399
405
|
customSales: [],
|
|
400
|
-
balance:
|
|
406
|
+
balance: 0,
|
|
401
407
|
user: MOCK_USER_MARIO,
|
|
402
408
|
outlet: MOCK_OUTLET_MAIN,
|
|
403
409
|
station: MOCK_STATION_2,
|
|
@@ -499,53 +505,53 @@ export const createOrderFromCart = (paymentType, amount, processor = "cash") =>
|
|
|
499
505
|
const receiptId = `receipt_${Date.now()}`;
|
|
500
506
|
// Map cart products to line items
|
|
501
507
|
const lineItems = MOCK_CART.products.map(p => {
|
|
502
|
-
// Find original product to get attributes/variants if needed
|
|
503
|
-
// For simplicity, we use what's in cart
|
|
504
508
|
return {
|
|
505
509
|
productId: p.id,
|
|
506
510
|
variantId: p.variantId,
|
|
507
511
|
name: p.name,
|
|
508
512
|
quantity: p.quantity,
|
|
509
|
-
price:
|
|
513
|
+
price: p.price,
|
|
510
514
|
taxes: [],
|
|
511
515
|
discount: {
|
|
512
|
-
itemDiscount: { percentage: 0, amount:
|
|
513
|
-
cartDiscount: { percentage: 0, amount:
|
|
516
|
+
itemDiscount: { percentage: 0, amount: 0, const: "0" },
|
|
517
|
+
cartDiscount: { percentage: 0, amount: 0, const: "0" }
|
|
514
518
|
},
|
|
515
|
-
fee: { itemFee: { percentage: 0, amount:
|
|
516
|
-
totalTax:
|
|
517
|
-
total:
|
|
519
|
+
fee: { itemFee: { percentage: 0, amount: 0, tax: 0, taxTableId: "" } },
|
|
520
|
+
totalTax: 0,
|
|
521
|
+
total: p.price * p.quantity,
|
|
518
522
|
metadata: [],
|
|
519
523
|
image: p.images?.[0] || "",
|
|
520
524
|
sku: p.sku || "",
|
|
521
|
-
stock: 100,
|
|
525
|
+
stock: 100,
|
|
522
526
|
attributes: p.attributes || ""
|
|
523
527
|
};
|
|
524
528
|
});
|
|
525
|
-
const
|
|
529
|
+
const totalNum = MOCK_CART.total;
|
|
526
530
|
const newOrder = {
|
|
527
531
|
_id: orderId,
|
|
532
|
+
currency: CurrencyCode.USD,
|
|
533
|
+
minorUnits: 2,
|
|
528
534
|
receiptId,
|
|
529
535
|
companyId: COMPANY_ID,
|
|
530
536
|
externalId: null,
|
|
531
537
|
status: "completed",
|
|
532
538
|
customer: MOCK_CART.customer ? MOCK_CART.customer : null,
|
|
533
539
|
summary: {
|
|
534
|
-
total:
|
|
535
|
-
subTotal:
|
|
536
|
-
discountTotal:
|
|
537
|
-
shippingTotal:
|
|
538
|
-
totalTaxes:
|
|
540
|
+
total: totalNum,
|
|
541
|
+
subTotal: totalNum,
|
|
542
|
+
discountTotal: 0,
|
|
543
|
+
shippingTotal: 0,
|
|
544
|
+
totalTaxes: 0,
|
|
539
545
|
taxes: [],
|
|
540
546
|
isTaxInclusive: false
|
|
541
547
|
},
|
|
542
|
-
cartDiscount: MOCK_CART.discount ? { label: MOCK_CART.discount.label || "Discount", amount:
|
|
548
|
+
cartDiscount: MOCK_CART.discount ? { label: MOCK_CART.discount.label || "Discount", amount: 0, percentage: MOCK_CART.discount.value } : null,
|
|
543
549
|
cartFees: [],
|
|
544
550
|
paymentMethods: [
|
|
545
551
|
{
|
|
546
552
|
transactionId: `trans_${Date.now()}`,
|
|
547
553
|
paymentType,
|
|
548
|
-
amount
|
|
554
|
+
amount,
|
|
549
555
|
timestamp: new Date().toISOString(),
|
|
550
556
|
processor
|
|
551
557
|
}
|
|
@@ -562,7 +568,7 @@ export const createOrderFromCart = (paymentType, amount, processor = "cash") =>
|
|
|
562
568
|
shipping: MOCK_CART.customer?.shipping || null,
|
|
563
569
|
lineItems,
|
|
564
570
|
customSales: [],
|
|
565
|
-
balance:
|
|
571
|
+
balance: 0,
|
|
566
572
|
user: MOCK_USER_LUIGI,
|
|
567
573
|
outlet: MOCK_OUTLET_MAIN,
|
|
568
574
|
station: MOCK_STATION_1,
|
|
@@ -235,7 +235,7 @@ export const MOCK_CUSTOM_EXTENSIONS = [
|
|
|
235
235
|
"https://example.com/images/loyalty-1.png",
|
|
236
236
|
"https://example.com/images/loyalty-2.png"
|
|
237
237
|
],
|
|
238
|
-
price:
|
|
238
|
+
price: 2999,
|
|
239
239
|
website: "https://loyalty-extension.example.com",
|
|
240
240
|
isDeleted: false,
|
|
241
241
|
createdAt: "2024-01-01T10:00:00.000Z",
|
|
@@ -250,7 +250,7 @@ export const MOCK_CUSTOM_EXTENSIONS = [
|
|
|
250
250
|
short_description: "Real-time inventory insights",
|
|
251
251
|
long_description: "Get detailed insights into your inventory with real-time tracking, low stock alerts, and comprehensive reporting.",
|
|
252
252
|
main_image: "https://example.com/images/inventory-extension.png",
|
|
253
|
-
price:
|
|
253
|
+
price: 4999,
|
|
254
254
|
isDeleted: false,
|
|
255
255
|
createdAt: "2024-01-05T08:00:00.000Z",
|
|
256
256
|
updatedAt: "2024-01-05T08:00:00.000Z",
|
|
@@ -264,7 +264,7 @@ export const MOCK_CUSTOM_EXTENSIONS = [
|
|
|
264
264
|
short_description: "Automated email marketing",
|
|
265
265
|
long_description: "Create and manage email campaigns, automate customer communications, and track engagement metrics.",
|
|
266
266
|
main_image: "https://example.com/images/email-extension.png",
|
|
267
|
-
price:
|
|
267
|
+
price: 3999,
|
|
268
268
|
isDeleted: false,
|
|
269
269
|
createdAt: "2024-01-08T12:00:00.000Z",
|
|
270
270
|
updatedAt: "2024-01-08T12:00:00.000Z",
|
|
@@ -59,6 +59,8 @@ import { mockGetCustomExtensionCustomTables } from "../../actions/get-custom-ext
|
|
|
59
59
|
import { mockGetSecretsKeys } from "../../actions/get-secrets-keys/mock";
|
|
60
60
|
import { mockGetSecretVal } from "../../actions/get-secret-val/mock";
|
|
61
61
|
import { mockSetSecretVal } from "../../actions/set-secret-val/mock";
|
|
62
|
+
import { mockGetUsers } from "../../actions/get-users/mock";
|
|
63
|
+
import { mockGetRoles } from "../../actions/get-roles/mock";
|
|
62
64
|
export const RENDER_MOCKS = {
|
|
63
65
|
addCartDiscount: mockAddCartDiscount,
|
|
64
66
|
addCartFee: mockAddCartFee,
|
|
@@ -121,4 +123,6 @@ export const RENDER_MOCKS = {
|
|
|
121
123
|
getSecretsKeys: mockGetSecretsKeys,
|
|
122
124
|
getSecretVal: mockGetSecretVal,
|
|
123
125
|
setSecretVal: mockSetSecretVal,
|
|
126
|
+
getUsers: mockGetUsers,
|
|
127
|
+
getRoles: mockGetRoles,
|
|
124
128
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
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, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal } 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, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles } from "../../index";
|
|
2
2
|
export interface RenderProviderActions {
|
|
3
3
|
exampleFunction: ExampleFunction;
|
|
4
4
|
getProducts: GetProducts;
|
|
@@ -61,4 +61,6 @@ export interface RenderProviderActions {
|
|
|
61
61
|
getSecretsKeys: GetSecretsKeys;
|
|
62
62
|
getSecretVal: GetSecretVal;
|
|
63
63
|
setSecretVal: SetSecretVal;
|
|
64
|
+
getUsers: GetUsers;
|
|
65
|
+
getRoles: GetRoles;
|
|
64
66
|
}
|
package/dist/provider.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type ActionHandlers = Map<string, ActionHandler>;
|
|
|
3
3
|
export declare class CommandFrameProvider<TActions extends object = any> {
|
|
4
4
|
private handlers;
|
|
5
5
|
private origin;
|
|
6
|
+
private isWildcardPattern;
|
|
6
7
|
private debug;
|
|
7
8
|
private destroyed;
|
|
8
9
|
private boundHandleMessage;
|
|
@@ -10,6 +11,11 @@ export declare class CommandFrameProvider<TActions extends object = any> {
|
|
|
10
11
|
origin?: string;
|
|
11
12
|
debug?: boolean;
|
|
12
13
|
});
|
|
14
|
+
/**
|
|
15
|
+
* Supports "*" (allow all), exact match, and wildcard subdomain
|
|
16
|
+
* patterns like "https://*.example.com".
|
|
17
|
+
*/
|
|
18
|
+
private isOriginAllowed;
|
|
13
19
|
register<TParams = any, TResponse = any>(action: string, handler: ActionHandler<TParams, TResponse>): void;
|
|
14
20
|
unregister(action: string): void;
|
|
15
21
|
private handleMessage;
|
package/dist/provider.js
CHANGED
|
@@ -4,6 +4,7 @@ export class CommandFrameProvider {
|
|
|
4
4
|
this.destroyed = false;
|
|
5
5
|
this.origin = options.origin || "*";
|
|
6
6
|
this.debug = options.debug || false;
|
|
7
|
+
this.isWildcardPattern = this.origin !== "*" && this.origin.includes("*");
|
|
7
8
|
this.boundHandleMessage = this.handleMessage.bind(this);
|
|
8
9
|
if (typeof window !== "undefined") {
|
|
9
10
|
window.addEventListener("message", this.boundHandleMessage);
|
|
@@ -23,6 +24,22 @@ export class CommandFrameProvider {
|
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Supports "*" (allow all), exact match, and wildcard subdomain
|
|
29
|
+
* patterns like "https://*.example.com".
|
|
30
|
+
*/
|
|
31
|
+
isOriginAllowed(eventOrigin) {
|
|
32
|
+
if (this.origin === "*")
|
|
33
|
+
return true;
|
|
34
|
+
if (!this.isWildcardPattern)
|
|
35
|
+
return eventOrigin === this.origin;
|
|
36
|
+
const wildcardIndex = this.origin.indexOf("*.");
|
|
37
|
+
const prefix = this.origin.slice(0, wildcardIndex);
|
|
38
|
+
const suffix = this.origin.slice(wildcardIndex + 1);
|
|
39
|
+
return (eventOrigin.startsWith(prefix) &&
|
|
40
|
+
eventOrigin.endsWith(suffix) &&
|
|
41
|
+
eventOrigin.length > prefix.length + suffix.length);
|
|
42
|
+
}
|
|
26
43
|
register(action, handler) {
|
|
27
44
|
if (this.destroyed) {
|
|
28
45
|
if (this.debug) {
|
|
@@ -56,7 +73,7 @@ export class CommandFrameProvider {
|
|
|
56
73
|
if (!request || typeof request !== "object" || !("action" in request)) {
|
|
57
74
|
return;
|
|
58
75
|
}
|
|
59
|
-
if (this.
|
|
76
|
+
if (!this.isOriginAllowed(event.origin)) {
|
|
60
77
|
if (this.debug) {
|
|
61
78
|
console.warn("[CommandFrameProvider] Origin mismatch", {
|
|
62
79
|
expected: this.origin,
|
|
@@ -65,6 +82,7 @@ export class CommandFrameProvider {
|
|
|
65
82
|
}
|
|
66
83
|
return;
|
|
67
84
|
}
|
|
85
|
+
const targetOrigin = this.isWildcardPattern ? event.origin : this.origin;
|
|
68
86
|
if (!request.action || !request.requestId) {
|
|
69
87
|
if (this.debug) {
|
|
70
88
|
console.warn("[CommandFrameProvider] Invalid request format", {
|
|
@@ -92,7 +110,7 @@ export class CommandFrameProvider {
|
|
|
92
110
|
this.sendResponse(event.source, request.requestId, {
|
|
93
111
|
success: false,
|
|
94
112
|
error: `Unknown action: ${request.action}`
|
|
95
|
-
});
|
|
113
|
+
}, targetOrigin);
|
|
96
114
|
}
|
|
97
115
|
return;
|
|
98
116
|
}
|
|
@@ -103,7 +121,7 @@ export class CommandFrameProvider {
|
|
|
103
121
|
this.sendResponse(event.source, request.requestId, {
|
|
104
122
|
success: true,
|
|
105
123
|
data: result
|
|
106
|
-
});
|
|
124
|
+
}, targetOrigin);
|
|
107
125
|
if (this.debug) {
|
|
108
126
|
console.log("[CommandFrameProvider] Action executed", {
|
|
109
127
|
action: request.action,
|
|
@@ -125,7 +143,7 @@ export class CommandFrameProvider {
|
|
|
125
143
|
this.sendResponse(event.source, request.requestId, {
|
|
126
144
|
success: false,
|
|
127
145
|
error: errorMessage
|
|
128
|
-
});
|
|
146
|
+
}, targetOrigin);
|
|
129
147
|
if (this.debug) {
|
|
130
148
|
console.error("[CommandFrameProvider] Action failed", {
|
|
131
149
|
action: request.action,
|
|
@@ -143,7 +161,7 @@ export class CommandFrameProvider {
|
|
|
143
161
|
}
|
|
144
162
|
}
|
|
145
163
|
}
|
|
146
|
-
sendResponse(target, requestId, response) {
|
|
164
|
+
sendResponse(target, requestId, response, targetOrigin) {
|
|
147
165
|
const message = {
|
|
148
166
|
requestId,
|
|
149
167
|
...response
|
|
@@ -151,10 +169,11 @@ export class CommandFrameProvider {
|
|
|
151
169
|
if (this.debug) {
|
|
152
170
|
console.log("[CommandFrameProvider] Sending response", {
|
|
153
171
|
requestId,
|
|
154
|
-
success: response.success
|
|
172
|
+
success: response.success,
|
|
173
|
+
targetOrigin
|
|
155
174
|
});
|
|
156
175
|
}
|
|
157
|
-
target.postMessage(message,
|
|
176
|
+
target.postMessage(message, targetOrigin);
|
|
158
177
|
}
|
|
159
178
|
destroy() {
|
|
160
179
|
if (this.destroyed) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@final-commerce/command-frame",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41-develop",
|
|
4
4
|
"description": "Commands Frame library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -44,5 +44,6 @@
|
|
|
44
44
|
"@typescript-eslint/parser": "^8.48.0",
|
|
45
45
|
"prettier": "^3.7.1",
|
|
46
46
|
"typescript": "^5.0.0"
|
|
47
|
-
}
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {}
|
|
48
49
|
}
|