@pisell/pisellos 0.10.96 → 0.10.98
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/modules/OpenData/index.d.ts +2 -12
- package/dist/modules/OpenData/index.js +95 -169
- package/dist/modules/ResourcePlanner/planner.js +24 -5
- package/dist/server/index.d.ts +0 -4
- package/dist/server/index.js +580 -759
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Sales/index.d.ts +2 -2
- package/dist/solution/Sales/index.js +36 -68
- package/dist/solution/Sales/types.d.ts +2 -8
- package/dist/solution/Sales/types.js +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/OpenData/index.d.ts +2 -12
- package/lib/modules/OpenData/index.js +12 -58
- package/lib/modules/ResourcePlanner/planner.js +24 -5
- package/lib/server/index.d.ts +0 -4
- package/lib/server/index.js +51 -136
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Sales/index.d.ts +2 -2
- package/lib/solution/Sales/index.js +13 -39
- package/lib/solution/Sales/types.d.ts +2 -8
- package/lib/solution/Sales/types.js +1 -1
- package/package.json +1 -1
|
@@ -342,7 +342,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
342
342
|
date: string;
|
|
343
343
|
status: string;
|
|
344
344
|
week: string;
|
|
345
|
-
weekNum: 0 |
|
|
345
|
+
weekNum: 0 | 1 | 2 | 5 | 4 | 3 | 6;
|
|
346
346
|
}[]>;
|
|
347
347
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
348
348
|
private getScheduleDataByIds;
|
|
@@ -2,7 +2,7 @@ import dayjs from 'dayjs';
|
|
|
2
2
|
import { Module, ModuleOptions, PisellCore } from '../../types';
|
|
3
3
|
import { BaseModule } from '../../modules/BaseModule';
|
|
4
4
|
import type { RequestPlugin } from '../../plugins/request';
|
|
5
|
-
import { SalesState, SalesModuleAPI, Reservation, SalesResourceBookingItem, SalesResourceBookingItemWithGroups, SalesTimelineHighlights, ChangeBookingStatusParams, GetResourceBookingItemParams, SalesPrintLocalOrderReceiptOptions, CloudOrderInvoiceRequest
|
|
5
|
+
import { SalesState, SalesModuleAPI, Reservation, SalesResourceBookingItem, SalesResourceBookingItemWithGroups, SalesTimelineHighlights, ChangeBookingStatusParams, GetResourceBookingItemParams, SalesPrintLocalOrderReceiptOptions, CloudOrderInvoiceRequest } from './types';
|
|
6
6
|
import type { BookingData } from '../../server/modules/order/types';
|
|
7
7
|
export * from './types';
|
|
8
8
|
/**
|
|
@@ -55,7 +55,7 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
|
|
|
55
55
|
private logInvoiceOpenDataFallback;
|
|
56
56
|
private resolveInvoiceConfigs;
|
|
57
57
|
printLocalOrderReceipt<T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions): Promise<T>;
|
|
58
|
-
printCloudOrderInvoice(input: CloudOrderInvoiceRequest): Promise<
|
|
58
|
+
printCloudOrderInvoice(input: CloudOrderInvoiceRequest): Promise<void>;
|
|
59
59
|
/** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
|
|
60
60
|
clearOpenDataCache(): void;
|
|
61
61
|
destroy(): Promise<void>;
|
|
@@ -34,7 +34,6 @@ export * from "./types";
|
|
|
34
34
|
var UNPAID_PAYMENT_STATUSES = new Set(['unpaid', 'partially_paid', 'payment_processing']);
|
|
35
35
|
var INVOICE_OPEN_DATA_SECTION_CODES = ['documents'];
|
|
36
36
|
var INVOICE_OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
|
|
37
|
-
|
|
38
37
|
/**
|
|
39
38
|
* Sales 解决方案基础骨架
|
|
40
39
|
*
|
|
@@ -468,98 +467,67 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
468
467
|
key: "printCloudOrderInvoice",
|
|
469
468
|
value: function () {
|
|
470
469
|
var _printCloudOrderInvoice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(input) {
|
|
471
|
-
var _lookup$data
|
|
472
|
-
var
|
|
470
|
+
var _lookup$data;
|
|
471
|
+
var orderId, channel, openData, requestOptions, lookup, businessCode, settings, result;
|
|
473
472
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
474
473
|
while (1) switch (_context7.prev = _context7.next) {
|
|
475
474
|
case 0:
|
|
475
|
+
orderId = input === null || input === void 0 ? void 0 : input.order_id;
|
|
476
|
+
channel = typeof (input === null || input === void 0 ? void 0 : input.channel) === 'string' ? input.channel.trim() : '';
|
|
477
|
+
if (channel) {
|
|
478
|
+
_context7.next = 4;
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
throw new Error('Cloud Invoice requires a channel');
|
|
482
|
+
case 4:
|
|
476
483
|
openData = this.invoiceOpenDataModule;
|
|
477
484
|
if (openData) {
|
|
478
|
-
_context7.next =
|
|
485
|
+
_context7.next = 7;
|
|
479
486
|
break;
|
|
480
487
|
}
|
|
481
488
|
throw new Error('Cloud Invoice is not initialized');
|
|
482
|
-
case
|
|
483
|
-
orderId = typeof (input === null || input === void 0 ? void 0 : input.order_id) === 'string' ? input.order_id.trim() : Number.isSafeInteger(input === null || input === void 0 ? void 0 : input.order_id) ? String(input.order_id) : '';
|
|
484
|
-
channel = typeof (input === null || input === void 0 ? void 0 : input.channel) === 'string' ? input.channel.trim() : '';
|
|
485
|
-
messageUuid = typeof (input === null || input === void 0 ? void 0 : input.message_uuid) === 'string' ? input.message_uuid.trim() : '';
|
|
486
|
-
if (!(!/^[1-9]\d*$/.test(orderId) || !channel || !messageUuid)) {
|
|
487
|
-
_context7.next = 8;
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
throw new Error('Cloud Invoice requires order_id, channel and message_uuid');
|
|
491
|
-
case 8:
|
|
492
|
-
scope = openData.captureCloudInvoiceScope(input.shop_id);
|
|
493
|
-
event = {
|
|
494
|
-
order_id: orderId,
|
|
495
|
-
channel: channel,
|
|
496
|
-
message_uuid: messageUuid,
|
|
497
|
-
shop_id: scope.shopId
|
|
498
|
-
};
|
|
489
|
+
case 7:
|
|
499
490
|
requestOptions = {
|
|
500
491
|
osServer: true,
|
|
501
492
|
customToast: function customToast() {}
|
|
502
493
|
};
|
|
503
|
-
_context7.next =
|
|
504
|
-
return this.request.post('/shop/local/cloud-order-invoice/lookup',
|
|
505
|
-
|
|
494
|
+
_context7.next = 10;
|
|
495
|
+
return this.request.post('/shop/local/cloud-order-invoice/lookup', {
|
|
496
|
+
order_id: orderId
|
|
497
|
+
}, requestOptions);
|
|
498
|
+
case 10:
|
|
506
499
|
lookup = _context7.sent;
|
|
507
|
-
scope.assertCurrent();
|
|
508
500
|
if (!((lookup === null || lookup === void 0 ? void 0 : lookup.status) !== true || lookup.code !== 200)) {
|
|
509
|
-
_context7.next =
|
|
501
|
+
_context7.next = 13;
|
|
510
502
|
break;
|
|
511
503
|
}
|
|
512
504
|
throw new Error((lookup === null || lookup === void 0 ? void 0 : lookup.message) || 'Cloud Invoice order lookup failed');
|
|
513
|
-
case
|
|
514
|
-
|
|
515
|
-
if (!(typeof accepted === 'string' && accepted.trim())) {
|
|
516
|
-
_context7.next = 20;
|
|
517
|
-
break;
|
|
518
|
-
}
|
|
519
|
-
return _context7.abrupt("return", {
|
|
520
|
-
task_uuid: accepted
|
|
521
|
-
});
|
|
522
|
-
case 20:
|
|
523
|
-
rawBusinessCode = (_lookup$data2 = lookup.data) === null || _lookup$data2 === void 0 ? void 0 : _lookup$data2.business_code;
|
|
524
|
-
businessCode = typeof rawBusinessCode === 'string' ? rawBusinessCode.trim() : '';
|
|
505
|
+
case 13:
|
|
506
|
+
businessCode = (_lookup$data = lookup.data) === null || _lookup$data === void 0 || (_lookup$data = _lookup$data.business_code) === null || _lookup$data === void 0 ? void 0 : _lookup$data.trim();
|
|
525
507
|
if (businessCode) {
|
|
526
|
-
_context7.next =
|
|
508
|
+
_context7.next = 16;
|
|
527
509
|
break;
|
|
528
510
|
}
|
|
529
511
|
throw new Error('Cloud Invoice order has no business_code');
|
|
530
|
-
case
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
break;
|
|
535
|
-
}
|
|
536
|
-
throw new Error('Cloud Invoice lookup has no device_id');
|
|
537
|
-
case 27:
|
|
538
|
-
_context7.next = 29;
|
|
539
|
-
return openData.loadCloudInvoiceTemplate("".concat(businessCode, "+").concat(channel), scope);
|
|
540
|
-
case 29:
|
|
512
|
+
case 16:
|
|
513
|
+
_context7.next = 18;
|
|
514
|
+
return openData.loadCloudInvoiceTemplate("".concat(businessCode, "+").concat(channel));
|
|
515
|
+
case 18:
|
|
541
516
|
settings = _context7.sent;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
517
|
+
_context7.next = 21;
|
|
518
|
+
return this.request.post('/shop/local/cloud-order-invoice/submit', {
|
|
519
|
+
order_id: orderId,
|
|
545
520
|
business_code: businessCode,
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
taskUuid = submitted === null || submitted === void 0 || (_submitted$data = submitted.data) === null || _submitted$data === void 0 ? void 0 : _submitted$data.task_uuid;
|
|
553
|
-
if (!((submitted === null || submitted === void 0 ? void 0 : submitted.status) !== true || submitted.code !== 200 || typeof taskUuid !== 'string' || !taskUuid.trim())) {
|
|
554
|
-
_context7.next = 38;
|
|
521
|
+
template_settings: settings
|
|
522
|
+
}, requestOptions);
|
|
523
|
+
case 21:
|
|
524
|
+
result = _context7.sent;
|
|
525
|
+
if (!((result === null || result === void 0 ? void 0 : result.status) !== true || result.code !== 200)) {
|
|
526
|
+
_context7.next = 24;
|
|
555
527
|
break;
|
|
556
528
|
}
|
|
557
|
-
throw new Error((
|
|
558
|
-
case
|
|
559
|
-
return _context7.abrupt("return", {
|
|
560
|
-
task_uuid: taskUuid
|
|
561
|
-
});
|
|
562
|
-
case 39:
|
|
529
|
+
throw new Error((result === null || result === void 0 ? void 0 : result.message) || 'Cloud Invoice dispatch failed');
|
|
530
|
+
case 24:
|
|
563
531
|
case "end":
|
|
564
532
|
return _context7.stop();
|
|
565
533
|
}
|
|
@@ -56,17 +56,11 @@ export interface SalesPrintLocalOrderReceiptOptions {
|
|
|
56
56
|
/** 当前销售入口;缺失或为 system 时按 pos 处理。 */
|
|
57
57
|
channel?: string;
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
59
|
+
/** Native cloud-order notification. */
|
|
60
60
|
export interface CloudOrderInvoiceRequest {
|
|
61
|
-
shop_id: string | number;
|
|
62
61
|
order_id: string | number;
|
|
63
|
-
message_uuid: string;
|
|
64
62
|
channel: string;
|
|
65
63
|
}
|
|
66
|
-
export interface CloudOrderInvoiceResult {
|
|
67
|
-
/** DeviceTask accepted for this message on the current device. */
|
|
68
|
-
task_uuid: string;
|
|
69
|
-
}
|
|
70
64
|
/**
|
|
71
65
|
* Sales 解决方案状态
|
|
72
66
|
*
|
|
@@ -101,7 +95,7 @@ export interface SalesModuleAPI {
|
|
|
101
95
|
changeBookingStatus: (params: ChangeBookingStatusParams) => Promise<any>;
|
|
102
96
|
/** 按本地订单标识打印小票;本地未命中时由 OS Server 负责远端兜底。 */
|
|
103
97
|
printLocalOrderReceipt: <T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions) => Promise<T>;
|
|
104
|
-
printCloudOrderInvoice: (request: CloudOrderInvoiceRequest) => Promise<
|
|
98
|
+
printCloudOrderInvoice: (request: CloudOrderInvoiceRequest) => Promise<void>;
|
|
105
99
|
/** 清除 Legacy Sales 独立维护的 Documents OpenData 缓存。 */
|
|
106
100
|
clearOpenDataCache: () => void;
|
|
107
101
|
/** 获取资源维度的预约占用列表 */
|
|
@@ -14,7 +14,7 @@ export var SalesHooks = /*#__PURE__*/function (SalesHooks) {
|
|
|
14
14
|
* 当前不要直接把 OrderData 当作最终 UI 数据结构。
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
/**
|
|
17
|
+
/** Native cloud-order notification. */
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Sales 解决方案状态
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _examples.BUY_X_GET_Y_FREE_STRATEGY;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _examples.ITEM_REWARD_STRATEGY;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "PromotionAdapter", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _adapter.PromotionAdapter;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "PromotionEvaluator", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _evaluator.PromotionEvaluator;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "default", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _adapter.default;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _evaluator = require("./evaluator");
|
|
43
|
+
var _adapter = _interopRequireWildcard(require("./adapter"));
|
|
44
|
+
var _examples = require("./examples");
|
|
45
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
46
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -6,13 +6,6 @@ export * from './types';
|
|
|
6
6
|
export * from './contactInfo';
|
|
7
7
|
export * from './salesSettings';
|
|
8
8
|
export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, resolveInvoiceReceiptLocales, } from './utils';
|
|
9
|
-
interface InvoiceShopScope {
|
|
10
|
-
shopId: string;
|
|
11
|
-
tenantId: string;
|
|
12
|
-
}
|
|
13
|
-
interface CloudInvoiceScope extends InvoiceShopScope {
|
|
14
|
-
assertCurrent(): void;
|
|
15
|
-
}
|
|
16
9
|
export declare class OpenDataModule extends BaseModule implements Module {
|
|
17
10
|
protected defaultName: string;
|
|
18
11
|
protected defaultVersion: string;
|
|
@@ -26,7 +19,6 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
26
19
|
private otherParams;
|
|
27
20
|
private fetchRevision;
|
|
28
21
|
private invoiceTemplateCacheRevision;
|
|
29
|
-
private cloudInvoiceTemplates;
|
|
30
22
|
private invoiceTemplateDocumentCache;
|
|
31
23
|
private invoiceTemplateDocumentInFlight;
|
|
32
24
|
constructor(name?: string, version?: string);
|
|
@@ -41,10 +33,8 @@ export declare class OpenDataModule extends BaseModule implements Module {
|
|
|
41
33
|
private shouldSkipInvoiceTemplateDocument;
|
|
42
34
|
fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
|
|
43
35
|
private requestOpenData;
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
loadCloudInvoiceTemplate(target: string, scope: CloudInvoiceScope): Promise<InvoiceTemplateSettings>;
|
|
47
|
-
private fetchCloudInvoiceTemplate;
|
|
36
|
+
/** Cloud orders must resolve their own channel's template before printing. */
|
|
37
|
+
loadCloudInvoiceTemplate(target: string): Promise<InvoiceTemplateSettings>;
|
|
48
38
|
getOpenData(): OpenDataConfig | null;
|
|
49
39
|
getInvoiceLayoutConfig(): InvoiceLayoutConfig;
|
|
50
40
|
getInvoiceTemplateSettings(): InvoiceTemplateSettings;
|
|
@@ -120,13 +120,6 @@ function isLegacyInvoiceTemplate(value) {
|
|
|
120
120
|
const numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
121
121
|
return !numericLike.test(normalized);
|
|
122
122
|
}
|
|
123
|
-
function readInvoiceShopScope(app) {
|
|
124
|
-
const getData = app?.getData?.();
|
|
125
|
-
return {
|
|
126
|
-
shopId: String(getData?.('shop_id') ?? '').trim(),
|
|
127
|
-
tenantId: String(getData?.('tenant_id') ?? '').trim()
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
123
|
class OpenDataModule extends _BaseModule.BaseModule {
|
|
131
124
|
defaultName = 'openData';
|
|
132
125
|
defaultVersion = '1.0.0';
|
|
@@ -140,9 +133,6 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
140
133
|
otherParams = {};
|
|
141
134
|
fetchRevision = 0;
|
|
142
135
|
invoiceTemplateCacheRevision = 0;
|
|
143
|
-
// Cloud printing only caches successful resolutions. Regular sales screens
|
|
144
|
-
// deliberately retain DEFAULT after a failed Document lookup.
|
|
145
|
-
cloudInvoiceTemplates = new Map();
|
|
146
136
|
invoiceTemplateDocumentCache = new Map();
|
|
147
137
|
invoiceTemplateDocumentInFlight = new Map();
|
|
148
138
|
constructor(name, version) {
|
|
@@ -192,7 +182,7 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
192
182
|
}
|
|
193
183
|
async fetchOpenData(params) {
|
|
194
184
|
const fetchRevision = ++this.fetchRevision;
|
|
195
|
-
const response = await this.requestOpenData(params
|
|
185
|
+
const response = await this.requestOpenData(params);
|
|
196
186
|
if (response?.status === false) {
|
|
197
187
|
throw new Error(response?.message || '获取 OpenData 配置失败');
|
|
198
188
|
}
|
|
@@ -206,9 +196,12 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
206
196
|
}
|
|
207
197
|
return data;
|
|
208
198
|
}
|
|
209
|
-
requestOpenData(params,
|
|
210
|
-
|
|
211
|
-
|
|
199
|
+
requestOpenData(params, background = false) {
|
|
200
|
+
const getData = this.appPlugin?.getData?.();
|
|
201
|
+
const shopId = getData?.('shop_id');
|
|
202
|
+
const tenantId = getData?.('tenant_id');
|
|
203
|
+
if (!shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
|
|
204
|
+
return this.request.post(`/open/my-pisell/${encodeURIComponent(String(shopId))}/setting`, {
|
|
212
205
|
scope: params.scope,
|
|
213
206
|
target: params.target,
|
|
214
207
|
section_code: params.section_code
|
|
@@ -216,8 +209,8 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
216
209
|
pisell2: true,
|
|
217
210
|
isPisell2: true,
|
|
218
211
|
prefix: false,
|
|
219
|
-
headers:
|
|
220
|
-
'Tenant-Id':
|
|
212
|
+
headers: tenantId ? {
|
|
213
|
+
'Tenant-Id': String(tenantId)
|
|
221
214
|
} : {},
|
|
222
215
|
...(background ? {
|
|
223
216
|
customToast: () => {},
|
|
@@ -227,51 +220,13 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
227
220
|
});
|
|
228
221
|
}
|
|
229
222
|
|
|
230
|
-
/**
|
|
231
|
-
|
|
232
|
-
const scope = readInvoiceShopScope(this.appPlugin);
|
|
233
|
-
if (!scope.shopId || scope.shopId !== String(expectedShopId).trim()) {
|
|
234
|
-
throw new Error('Cloud Invoice shop does not match the active shop');
|
|
235
|
-
}
|
|
236
|
-
const revision = this.invoiceTemplateCacheRevision;
|
|
237
|
-
return {
|
|
238
|
-
...scope,
|
|
239
|
-
assertCurrent: () => {
|
|
240
|
-
const current = readInvoiceShopScope(this.appPlugin);
|
|
241
|
-
if (revision !== this.invoiceTemplateCacheRevision || current.shopId !== scope.shopId || current.tenantId !== scope.tenantId) {
|
|
242
|
-
throw new Error('Cloud Invoice shop context changed');
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
async loadCloudInvoiceTemplate(target, scope) {
|
|
248
|
-
scope.assertCurrent();
|
|
249
|
-
const key = JSON.stringify([scope.tenantId, scope.shopId, target]);
|
|
250
|
-
const existing = this.cloudInvoiceTemplates.get(key);
|
|
251
|
-
if (existing && existing.expiresAt > Date.now()) return existing.request;
|
|
252
|
-
const request = this.fetchCloudInvoiceTemplate(target, scope);
|
|
253
|
-
const entry = {
|
|
254
|
-
request,
|
|
255
|
-
expiresAt: Infinity
|
|
256
|
-
};
|
|
257
|
-
this.cloudInvoiceTemplates.set(key, entry);
|
|
258
|
-
try {
|
|
259
|
-
const settings = await request;
|
|
260
|
-
scope.assertCurrent();
|
|
261
|
-
entry.expiresAt = Date.now() + 5 * 60 * 1000;
|
|
262
|
-
return settings;
|
|
263
|
-
} catch (error) {
|
|
264
|
-
if (this.cloudInvoiceTemplates.get(key) === entry) this.cloudInvoiceTemplates.delete(key);
|
|
265
|
-
throw error;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
async fetchCloudInvoiceTemplate(target, scope) {
|
|
223
|
+
/** Cloud orders must resolve their own channel's template before printing. */
|
|
224
|
+
async loadCloudInvoiceTemplate(target) {
|
|
269
225
|
const response = await this.requestOpenData({
|
|
270
226
|
scope: 'board',
|
|
271
227
|
target,
|
|
272
228
|
section_code: ['documents']
|
|
273
|
-
},
|
|
274
|
-
scope.assertCurrent();
|
|
229
|
+
}, true);
|
|
275
230
|
if (response?.status !== true || response.code !== 200 || !isRecord(response.data)) {
|
|
276
231
|
throw new Error(response?.message || 'Cloud Invoice settings unavailable');
|
|
277
232
|
}
|
|
@@ -440,7 +395,6 @@ class OpenDataModule extends _BaseModule.BaseModule {
|
|
|
440
395
|
clearCache() {
|
|
441
396
|
this.fetchRevision += 1;
|
|
442
397
|
this.invoiceTemplateCacheRevision += 1;
|
|
443
|
-
this.cloudInvoiceTemplates.clear();
|
|
444
398
|
this.invoiceTemplateDocumentCache.clear();
|
|
445
399
|
this.invoiceTemplateDocumentInFlight.clear();
|
|
446
400
|
this.store.data = null;
|
|
@@ -15,6 +15,23 @@ const DEFAULT_BUSINESS_HOURS = {
|
|
|
15
15
|
startTime: '00:00',
|
|
16
16
|
endTime: '00:00'
|
|
17
17
|
};
|
|
18
|
+
// Only factory-owned snapshots are immutable. A caller may provide a mutable
|
|
19
|
+
// projection, or freeze its outer object without freezing its products/cells.
|
|
20
|
+
const immutableProjections = new WeakSet();
|
|
21
|
+
const projectionStaticIndices = new WeakMap();
|
|
22
|
+
function getProjectionStaticIndex(projection, key, build) {
|
|
23
|
+
if (!immutableProjections.has(projection)) return build(projection);
|
|
24
|
+
let indices = projectionStaticIndices.get(projection);
|
|
25
|
+
if (!indices) {
|
|
26
|
+
indices = {};
|
|
27
|
+
projectionStaticIndices.set(projection, indices);
|
|
28
|
+
}
|
|
29
|
+
const existing = indices[key];
|
|
30
|
+
if (existing) return existing;
|
|
31
|
+
const index = build(projection);
|
|
32
|
+
indices[key] = index;
|
|
33
|
+
return index;
|
|
34
|
+
}
|
|
18
35
|
function availabilityError(code, message, details) {
|
|
19
36
|
return new _types.AvailabilityError(code, message, details);
|
|
20
37
|
}
|
|
@@ -799,10 +816,12 @@ function createAvailabilityProjection(input) {
|
|
|
799
816
|
resources,
|
|
800
817
|
resourceOccupancies
|
|
801
818
|
};
|
|
802
|
-
|
|
819
|
+
const projection = deepFreeze({
|
|
803
820
|
...projectionBase,
|
|
804
821
|
cells: buildCells(projectionBase)
|
|
805
822
|
});
|
|
823
|
+
immutableProjections.add(projection);
|
|
824
|
+
return projection;
|
|
806
825
|
}
|
|
807
826
|
function uniqByOccupancy(occupancies) {
|
|
808
827
|
const map = new Map();
|
|
@@ -1919,8 +1938,8 @@ function queryAvailabilityProjection(projection, request, runtimeOptions = {}) {
|
|
|
1919
1938
|
assertRangesWithinProjection(projection, request.selectedRanges);
|
|
1920
1939
|
}
|
|
1921
1940
|
const productIdSet = request.productIds?.length ? new Set(request.productIds.map(String)) : null;
|
|
1922
|
-
const productIndex =
|
|
1923
|
-
const cellIndex =
|
|
1941
|
+
const productIndex = getProjectionStaticIndex(projection, 'productIndex', buildProductIndex);
|
|
1942
|
+
const cellIndex = getProjectionStaticIndex(projection, 'cellIndex', buildAvailabilityCellIndex);
|
|
1924
1943
|
const groupResourceIndex = buildGroupResourceIndex({
|
|
1925
1944
|
projection,
|
|
1926
1945
|
resourceIds: request.resourceIds,
|
|
@@ -2195,14 +2214,14 @@ function validateAvailabilitySelection(projection, params, runtimeOptions = {})
|
|
|
2195
2214
|
const normalizedPartySize = normalizePartySize(params.partySize);
|
|
2196
2215
|
const normalizedBookingCount = normalizeBookingCount(params.bookingCount);
|
|
2197
2216
|
assertRangesWithinProjection(projection, [params.candidate]);
|
|
2198
|
-
const productIndex =
|
|
2217
|
+
const productIndex = getProjectionStaticIndex(projection, 'productIndex', buildProductIndex);
|
|
2199
2218
|
const evaluatedAt = formatDateTime((0, _localClock.localDateToScalar)(new Date()), projection.meta.timezone, (0, _localClock.extractFixedOffsetMinutes)(projection.meta.now) ?? (0, _localClock.captureRuntimeOffsetMinutes)());
|
|
2200
2219
|
const evaluated = evaluateCandidate(projection, params.candidate, {
|
|
2201
2220
|
partySize: normalizedPartySize,
|
|
2202
2221
|
evaluatedAt,
|
|
2203
2222
|
requirementSelections: params.requirementSelections,
|
|
2204
2223
|
allowImplicitSelection: false,
|
|
2205
|
-
cellIndex:
|
|
2224
|
+
cellIndex: getProjectionStaticIndex(projection, 'cellIndex', buildAvailabilityCellIndex),
|
|
2206
2225
|
productIndex,
|
|
2207
2226
|
groupResourceIndex: buildGroupResourceIndex({
|
|
2208
2227
|
projection,
|
package/lib/server/index.d.ts
CHANGED
|
@@ -66,7 +66,6 @@ declare class Server {
|
|
|
66
66
|
private localPaymentUpdateQueues;
|
|
67
67
|
private paymentIdentityRefreshes;
|
|
68
68
|
private receiptFulfillmentConfigInFlight;
|
|
69
|
-
private cloudInvoiceSubmissions;
|
|
70
69
|
private floorPlanQuerySubscribers;
|
|
71
70
|
private moduleRegistry;
|
|
72
71
|
constructor(core: PisellCore);
|
|
@@ -548,10 +547,7 @@ declare class Server {
|
|
|
548
547
|
private shouldLookupLocalPrintOrder;
|
|
549
548
|
private getLocalPrintOrderLookup;
|
|
550
549
|
private mergeLocalPrintOrderInput;
|
|
551
|
-
private getCloudInvoiceDevice;
|
|
552
|
-
private assertCloudInvoiceContext;
|
|
553
550
|
private loadCloudInvoiceOrder;
|
|
554
|
-
private resolveCloudOrderInvoice;
|
|
555
551
|
private handleCloudOrderInvoice;
|
|
556
552
|
private handleLocalPrintOrder;
|
|
557
553
|
private normalizeRequestedReceiptLocales;
|