@pisell/pisellos 2.3.129 → 2.3.130
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/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
- package/dist/modules/FulfillmentTiming/index.js +407 -0
- package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
- package/dist/modules/FulfillmentTiming/types.js +1 -0
- package/dist/modules/OpenData/types.d.ts +6 -0
- package/dist/modules/Order/index.d.ts +6 -0
- package/dist/modules/Order/index.js +55 -12
- package/dist/modules/Order/pickupTiming.d.ts +46 -0
- package/dist/modules/Order/pickupTiming.js +53 -0
- package/dist/modules/Order/types.d.ts +5 -1
- package/dist/modules/Order/utils.js +16 -6
- package/dist/modules/Payment/index.js +9 -10
- package/dist/modules/Schedule/index.d.ts +8 -0
- package/dist/modules/Schedule/index.js +141 -39
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/plugins/request.d.ts +7 -0
- package/dist/server/utils/small-ticket.d.ts +1 -85
- package/dist/server/utils/small-ticket.js +2 -2542
- package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/dist/shared/payment/loadPaymentMethods.js +66 -0
- package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
- package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
- package/dist/shared/receipt/small-ticket.d.ts +85 -0
- package/dist/shared/receipt/small-ticket.js +2576 -0
- package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
- package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
- package/dist/solution/BaseSales/index.d.ts +24 -0
- package/dist/solution/BaseSales/index.js +1221 -1038
- package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/dist/solution/BaseSales/pickupTiming.js +589 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +3 -3
- package/dist/solution/BookingTicket/utils/cartView.js +3 -1
- package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/dist/solution/OrderInvoicePreview/index.js +269 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
- package/dist/solution/UnifiedBookingSales/index.js +872 -707
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +21 -1
- package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
- package/lib/modules/FulfillmentTiming/index.js +359 -0
- package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
- package/lib/modules/FulfillmentTiming/types.js +5 -0
- package/lib/modules/OpenData/types.d.ts +6 -0
- package/lib/modules/Order/index.d.ts +6 -0
- package/lib/modules/Order/index.js +39 -8
- package/lib/modules/Order/pickupTiming.d.ts +46 -0
- package/lib/modules/Order/pickupTiming.js +61 -0
- package/lib/modules/Order/types.d.ts +5 -1
- package/lib/modules/Order/utils.js +12 -4
- package/lib/modules/Payment/index.js +3 -4
- package/lib/modules/Schedule/index.d.ts +8 -0
- package/lib/modules/Schedule/index.js +68 -12
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +11 -0
- package/lib/plugins/request.d.ts +7 -0
- package/lib/server/utils/small-ticket.d.ts +1 -85
- package/lib/server/utils/small-ticket.js +9 -2305
- package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/lib/shared/payment/loadPaymentMethods.js +40 -0
- package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
- package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
- package/lib/shared/receipt/small-ticket.d.ts +85 -0
- package/lib/shared/receipt/small-ticket.js +2342 -0
- package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
- package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
- package/lib/solution/BaseSales/index.d.ts +24 -0
- package/lib/solution/BaseSales/index.js +97 -1
- package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/lib/solution/BaseSales/pickupTiming.js +269 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +3 -3
- package/lib/solution/BookingTicket/utils/cartView.js +3 -1
- package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/lib/solution/OrderInvoicePreview/index.js +192 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
- package/lib/solution/UnifiedBookingSales/index.js +130 -46
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Module, ModuleOptions, PisellCore } from '../../types';
|
|
2
|
+
import { BaseModule } from '../../modules/BaseModule';
|
|
3
|
+
import type { InvoiceLayoutConfig } from '../../modules/OpenData';
|
|
4
|
+
import { type SmallTicketData } from '../../shared/receipt/small-ticket';
|
|
5
|
+
export interface OrderInvoicePreviewInput {
|
|
6
|
+
orderId: string | number;
|
|
7
|
+
tenantId: string | number;
|
|
8
|
+
shopId: string | number;
|
|
9
|
+
/** Changes on login/logout, without exposing credentials in state or cache keys. */
|
|
10
|
+
identity: string;
|
|
11
|
+
businessCode: string;
|
|
12
|
+
channel: string;
|
|
13
|
+
locale: string;
|
|
14
|
+
sourceRevision: string;
|
|
15
|
+
shop?: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
export interface OrderInvoicePreviewResult {
|
|
18
|
+
identity: string;
|
|
19
|
+
sourceRevision: string;
|
|
20
|
+
generatedAt: string;
|
|
21
|
+
locale: string;
|
|
22
|
+
orderId: string | number;
|
|
23
|
+
source: Record<string, any>;
|
|
24
|
+
shop: Record<string, any>;
|
|
25
|
+
layout: InvoiceLayoutConfig;
|
|
26
|
+
smallTicketData: SmallTicketData;
|
|
27
|
+
}
|
|
28
|
+
export interface OrderInvoicePreviewState {
|
|
29
|
+
status: 'idle' | 'loading' | 'ready' | 'error';
|
|
30
|
+
result: OrderInvoicePreviewResult | null;
|
|
31
|
+
error: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** Read-only, page-owned solution. No Order, Schedule, quotation or payment modules. */
|
|
34
|
+
export declare class OrderInvoicePreviewImpl extends BaseModule implements Module {
|
|
35
|
+
isSolution: boolean;
|
|
36
|
+
private request;
|
|
37
|
+
private state;
|
|
38
|
+
private listeners;
|
|
39
|
+
private generation;
|
|
40
|
+
private disposed;
|
|
41
|
+
private input?;
|
|
42
|
+
private activeKey;
|
|
43
|
+
private pending?;
|
|
44
|
+
private snapshotCache;
|
|
45
|
+
constructor(name?: string);
|
|
46
|
+
initialize(core: PisellCore, _options: ModuleOptions): void;
|
|
47
|
+
getState: () => OrderInvoicePreviewState;
|
|
48
|
+
subscribe: (listener: () => void) => (() => void);
|
|
49
|
+
private publish;
|
|
50
|
+
private getScope;
|
|
51
|
+
private loadContext;
|
|
52
|
+
private loadSource;
|
|
53
|
+
prepare(input: OrderInvoicePreviewInput): Promise<OrderInvoicePreviewResult>;
|
|
54
|
+
retry(): Promise<OrderInvoicePreviewResult>;
|
|
55
|
+
destroy(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OrderInvoicePreviewImpl = void 0;
|
|
7
|
+
var _BaseModule = require("../../modules/BaseModule");
|
|
8
|
+
var _loadCustomerInvoiceLayout = require("../../shared/receipt/loadCustomerInvoiceLayout");
|
|
9
|
+
var _smallTicket = require("../../shared/receipt/small-ticket");
|
|
10
|
+
var _loadSalesOrderSnapshot = require("../../shared/sales/loadSalesOrderSnapshot");
|
|
11
|
+
var _loadPaymentMethods = require("../../shared/payment/loadPaymentMethods");
|
|
12
|
+
// Page-runtime cache shared by preview instances, scoped to host, shop and identity.
|
|
13
|
+
const contextCaches = new WeakMap();
|
|
14
|
+
/** Read-only, page-owned solution. No Order, Schedule, quotation or payment modules. */
|
|
15
|
+
class OrderInvoicePreviewImpl extends _BaseModule.BaseModule {
|
|
16
|
+
isSolution = true;
|
|
17
|
+
request;
|
|
18
|
+
state = {
|
|
19
|
+
status: 'idle',
|
|
20
|
+
result: null,
|
|
21
|
+
error: null
|
|
22
|
+
};
|
|
23
|
+
listeners = new Set();
|
|
24
|
+
generation = 0;
|
|
25
|
+
disposed = false;
|
|
26
|
+
input;
|
|
27
|
+
activeKey = '';
|
|
28
|
+
pending;
|
|
29
|
+
snapshotCache = new Map();
|
|
30
|
+
constructor(name = 'orderInvoicePreview') {
|
|
31
|
+
super(name);
|
|
32
|
+
}
|
|
33
|
+
initialize(core, _options) {
|
|
34
|
+
this.core = core;
|
|
35
|
+
const request = core.getPlugin('request');
|
|
36
|
+
if (!request) throw new Error('OrderInvoicePreview requires request plugin');
|
|
37
|
+
this.request = request;
|
|
38
|
+
}
|
|
39
|
+
getState = () => this.state;
|
|
40
|
+
subscribe = listener => {
|
|
41
|
+
this.listeners.add(listener);
|
|
42
|
+
return () => {
|
|
43
|
+
this.listeners.delete(listener);
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
publish(state) {
|
|
47
|
+
this.state = state;
|
|
48
|
+
this.listeners.forEach(listener => listener());
|
|
49
|
+
}
|
|
50
|
+
getScope(input) {
|
|
51
|
+
return JSON.stringify([input.tenantId, input.shopId, input.identity, input.businessCode, input.channel]);
|
|
52
|
+
}
|
|
53
|
+
loadContext(input) {
|
|
54
|
+
let cache = contextCaches.get(this.request);
|
|
55
|
+
if (!cache) {
|
|
56
|
+
cache = new Map();
|
|
57
|
+
contextCaches.set(this.request, cache);
|
|
58
|
+
}
|
|
59
|
+
const key = JSON.stringify([input.tenantId, input.shopId, input.identity, input.locale]);
|
|
60
|
+
const cached = cache.get(key);
|
|
61
|
+
if (cached) return cached;
|
|
62
|
+
const task = Promise.all([this.request.get('/shop/show', {}, {
|
|
63
|
+
manualErrorHandling: true,
|
|
64
|
+
skipErrorHandler: true
|
|
65
|
+
}), (0, _loadPaymentMethods.loadPaymentMethods)(this.request, {
|
|
66
|
+
transport: 'remote',
|
|
67
|
+
filterPaymentMethods: false
|
|
68
|
+
})]).then(([response, methods]) => {
|
|
69
|
+
const shop = response?.data;
|
|
70
|
+
if (!shop || typeof shop !== 'object' || Array.isArray(shop)) throw new Error('Invoice shop information is unavailable');
|
|
71
|
+
if (String(shop.id) !== String(input.shopId)) throw new Error('Invoice shop identity mismatch');
|
|
72
|
+
return {
|
|
73
|
+
shop,
|
|
74
|
+
methods
|
|
75
|
+
};
|
|
76
|
+
}).catch(error => {
|
|
77
|
+
if (cache.get(key) === task) cache.delete(key);
|
|
78
|
+
throw error;
|
|
79
|
+
});
|
|
80
|
+
cache.set(key, task);
|
|
81
|
+
return task;
|
|
82
|
+
}
|
|
83
|
+
loadSource(input) {
|
|
84
|
+
const key = JSON.stringify([this.getScope(input), input.orderId, input.sourceRevision]);
|
|
85
|
+
const cached = this.snapshotCache.get(key);
|
|
86
|
+
if (cached) return cached;
|
|
87
|
+
const task = (0, _loadSalesOrderSnapshot.loadSalesOrderSnapshot)(this.request, {
|
|
88
|
+
lookup: input.orderId,
|
|
89
|
+
transport: 'remote'
|
|
90
|
+
}).then(response => {
|
|
91
|
+
if (response?.code !== 200 || !response.data || typeof response.data !== 'object' || Array.isArray(response.data)) {
|
|
92
|
+
throw new Error(response?.message || 'Invoice order is unavailable');
|
|
93
|
+
}
|
|
94
|
+
const source = response.data;
|
|
95
|
+
if (source.order_id != null && String(source.order_id) !== String(input.orderId)) {
|
|
96
|
+
throw new Error('Invoice order identity mismatch');
|
|
97
|
+
}
|
|
98
|
+
return source;
|
|
99
|
+
}).catch(error => {
|
|
100
|
+
if (this.snapshotCache.get(key) === task) this.snapshotCache.delete(key);
|
|
101
|
+
throw error;
|
|
102
|
+
});
|
|
103
|
+
this.snapshotCache.set(key, task);
|
|
104
|
+
return task;
|
|
105
|
+
}
|
|
106
|
+
prepare(input) {
|
|
107
|
+
if (this.disposed) return Promise.reject(new Error('Invoice preview disposed'));
|
|
108
|
+
const currentShop = this.core.getPlugin('app')?.getData?.()?.('shop_id');
|
|
109
|
+
if (currentShop != null && String(currentShop) !== String(input.shopId)) {
|
|
110
|
+
return Promise.reject(new Error('Invoice shop changed'));
|
|
111
|
+
}
|
|
112
|
+
const key = JSON.stringify([this.getScope(input), input.orderId, input.sourceRevision, input.locale]);
|
|
113
|
+
if (key === this.activeKey) {
|
|
114
|
+
if (this.pending) return this.pending;
|
|
115
|
+
if (this.state.status === 'ready' && this.state.result) return Promise.resolve(this.state.result);
|
|
116
|
+
}
|
|
117
|
+
if (this.input && this.getScope(this.input) !== this.getScope(input)) this.snapshotCache.clear();
|
|
118
|
+
this.input = input;
|
|
119
|
+
this.activeKey = key;
|
|
120
|
+
const generation = ++this.generation;
|
|
121
|
+
this.publish({
|
|
122
|
+
status: 'loading',
|
|
123
|
+
result: null,
|
|
124
|
+
error: null
|
|
125
|
+
});
|
|
126
|
+
const task = (async () => {
|
|
127
|
+
const [snapshot, context, layout] = await Promise.all([this.loadSource(input), this.loadContext(input), (0, _loadCustomerInvoiceLayout.loadCustomerInvoiceLayout)(this.request, input)]);
|
|
128
|
+
const source = (0, _loadPaymentMethods.withPaymentMethodNames)(snapshot, context.methods);
|
|
129
|
+
const getData = this.core.getPlugin('app')?.getData?.();
|
|
130
|
+
if (getData?.('shop_id') != null && String(getData('shop_id')) !== String(input.shopId)) throw new Error('Invoice shop changed');
|
|
131
|
+
const coreData = getData?.('core');
|
|
132
|
+
const shop = {
|
|
133
|
+
...(coreData?.core?.shop || coreData?.shop || {}),
|
|
134
|
+
...(getData?.('shop_info') || {}),
|
|
135
|
+
...input.shop,
|
|
136
|
+
...context.shop,
|
|
137
|
+
...(getData?.('tax_country_code') ? {
|
|
138
|
+
tax_country_code: getData('tax_country_code')
|
|
139
|
+
} : {})
|
|
140
|
+
};
|
|
141
|
+
if (generation !== this.generation || this.disposed) throw new Error('Invoice request superseded');
|
|
142
|
+
const requestedLocale = input.locale.toLowerCase().replace(/_/g, '-');
|
|
143
|
+
const locale = requestedLocale.startsWith('zh-tw') || requestedLocale.startsWith('zh-hk') ? 'zh_HK' : requestedLocale.startsWith('zh') ? 'zh_CN' : requestedLocale.startsWith('ja') ? 'ja' : requestedLocale.startsWith('pt') ? 'pt' : 'en';
|
|
144
|
+
const result = {
|
|
145
|
+
identity: key,
|
|
146
|
+
orderId: input.orderId,
|
|
147
|
+
sourceRevision: input.sourceRevision,
|
|
148
|
+
generatedAt: new Date().toISOString(),
|
|
149
|
+
locale,
|
|
150
|
+
source,
|
|
151
|
+
shop,
|
|
152
|
+
layout,
|
|
153
|
+
smallTicketData: (0, _smallTicket.buildSmallTicketData)({
|
|
154
|
+
order: source,
|
|
155
|
+
shopInfo: shop,
|
|
156
|
+
locales: [locale]
|
|
157
|
+
})
|
|
158
|
+
};
|
|
159
|
+
this.publish({
|
|
160
|
+
status: 'ready',
|
|
161
|
+
result,
|
|
162
|
+
error: null
|
|
163
|
+
});
|
|
164
|
+
return result;
|
|
165
|
+
})().catch(error => {
|
|
166
|
+
if (generation === this.generation && !this.disposed) {
|
|
167
|
+
this.publish({
|
|
168
|
+
status: 'error',
|
|
169
|
+
result: null,
|
|
170
|
+
error: error instanceof Error ? error.message : String(error)
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
throw error;
|
|
174
|
+
}).finally(() => {
|
|
175
|
+
if (this.pending === task) this.pending = undefined;
|
|
176
|
+
});
|
|
177
|
+
this.pending = task;
|
|
178
|
+
return task;
|
|
179
|
+
}
|
|
180
|
+
retry() {
|
|
181
|
+
if (!this.input) return Promise.reject(new Error('Invoice input is missing'));
|
|
182
|
+
return this.prepare(this.input);
|
|
183
|
+
}
|
|
184
|
+
destroy() {
|
|
185
|
+
this.disposed = true;
|
|
186
|
+
this.generation++;
|
|
187
|
+
this.listeners.clear();
|
|
188
|
+
this.snapshotCache.clear();
|
|
189
|
+
if (this.core.getModule(this.name) === this) super.destroy();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.OrderInvoicePreviewImpl = OrderInvoicePreviewImpl;
|
|
@@ -59,6 +59,13 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
59
59
|
protected defaultName: string;
|
|
60
60
|
protected defaultVersion: string;
|
|
61
61
|
protected store: UnifiedBookingSalesState;
|
|
62
|
+
protected pickupTimingEnabled: boolean;
|
|
63
|
+
private runtimeOpenDataScope;
|
|
64
|
+
private runtimeOpenDataSnapshot;
|
|
65
|
+
private runtimeOpenDataModule;
|
|
66
|
+
private runtimeOpenDataCore;
|
|
67
|
+
private runtimeOpenDataGeneration;
|
|
68
|
+
private runtimeOpenDataDestroyed;
|
|
62
69
|
private unifiedProductCatalog;
|
|
63
70
|
private availabilityRuntimeOffsetMinutes;
|
|
64
71
|
private availabilityScheduleCatalog;
|
|
@@ -142,12 +149,14 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
142
149
|
private resolveDiscountAction;
|
|
143
150
|
private resetCachedCustomerDiscountState;
|
|
144
151
|
private refreshLegacySessionCustomerDiscounts;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
private getRuntimeOpenDataScope;
|
|
153
|
+
private resetRuntimeOpenData;
|
|
154
|
+
protected prepareInvoiceTemplateAtSolutionReady(injectedOpenData?: OpenDataConfig): Promise<void>;
|
|
155
|
+
protected loadOpenDataConfig(): Promise<OpenDataConfig | null>;
|
|
156
|
+
/** A successful configuration belongs to this business runtime until an explicit refresh. */
|
|
149
157
|
loadOpenData(params: UnifiedBookingSalesLoadOpenDataParams): Promise<OpenDataConfig>;
|
|
150
158
|
getOpenData(): Promise<OpenDataConfig | null>;
|
|
159
|
+
protected loadPickupTimingOpenData(_force: boolean): Promise<Record<string, unknown>>;
|
|
151
160
|
private resetAllergyItemRuleState;
|
|
152
161
|
private fetchAllergyItemRuleConfigs;
|
|
153
162
|
private ensureAllergyItemRuleConfigsLoaded;
|
|
@@ -55,7 +55,6 @@ var _platform = require("../../utils/platform");
|
|
|
55
55
|
var _itemRule = require("../../model/strategy/adapter/itemRule");
|
|
56
56
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
57
57
|
const OPEN_DATA_SECTION_CODES = ['sale', 'reservation', 'fulfillment', 'menu', 'workflow', 'documents', 'basic', 'checkout', 'availability'];
|
|
58
|
-
const OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
|
|
59
58
|
function normalizePositiveInteger(value) {
|
|
60
59
|
const normalized = Number(value);
|
|
61
60
|
if (!Number.isInteger(normalized) || normalized <= 0) return undefined;
|
|
@@ -1199,6 +1198,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1199
1198
|
defaultName = 'unifiedBookingSales';
|
|
1200
1199
|
defaultVersion = '1.0.0';
|
|
1201
1200
|
store = {};
|
|
1201
|
+
pickupTimingEnabled = true;
|
|
1202
|
+
runtimeOpenDataScope = null;
|
|
1203
|
+
runtimeOpenDataSnapshot = null;
|
|
1204
|
+
runtimeOpenDataModule = null;
|
|
1205
|
+
runtimeOpenDataCore;
|
|
1206
|
+
runtimeOpenDataGeneration = 0;
|
|
1207
|
+
runtimeOpenDataDestroyed = false;
|
|
1202
1208
|
unifiedProductCatalog = [];
|
|
1203
1209
|
availabilityRuntimeOffsetMinutes = null;
|
|
1204
1210
|
availabilityScheduleCatalog = null;
|
|
@@ -1218,16 +1224,16 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1218
1224
|
allergyItemRuleConfigs = [];
|
|
1219
1225
|
allergyItemRuleConfigsPromise = null;
|
|
1220
1226
|
async initialize(core, options = {}) {
|
|
1227
|
+
this.resetRuntimeOpenData();
|
|
1228
|
+
this.runtimeOpenDataDestroyed = false;
|
|
1229
|
+
const openDataGeneration = this.runtimeOpenDataGeneration;
|
|
1221
1230
|
this.availabilityScheduleCatalog = null;
|
|
1222
|
-
this.openDataTarget = null;
|
|
1223
1231
|
this.availabilityRuntimeOffsetMinutes = (0, _localClock.captureRuntimeOffsetMinutes)();
|
|
1224
1232
|
this.clearAvailabilityRemoteResourceState();
|
|
1225
1233
|
this.resetAllergyItemRuleState();
|
|
1226
1234
|
await super.initialize(core, options);
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
if (this.otherParams?.openData && openDataBusinessCode && openDataChannel) {
|
|
1230
|
-
this.openDataTarget = `${openDataBusinessCode}+${openDataChannel}`;
|
|
1235
|
+
if (this.runtimeOpenDataDestroyed || openDataGeneration !== this.runtimeOpenDataGeneration) {
|
|
1236
|
+
throw new Error('Store settings changed. Please try again.');
|
|
1231
1237
|
}
|
|
1232
1238
|
this.captureAvailabilityScheduleCatalog();
|
|
1233
1239
|
}
|
|
@@ -1305,7 +1311,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1305
1311
|
const businessCode = String(this.otherParams?.businessCode ?? this.otherParams?.business_code ?? '').trim();
|
|
1306
1312
|
const channel = String(this.otherParams?.channel ?? '').trim();
|
|
1307
1313
|
const currentTarget = businessCode && channel ? `${businessCode}+${channel}` : null;
|
|
1308
|
-
let openData = !currentTarget || this.openDataTarget === currentTarget ? this.otherParams?.openData : null;
|
|
1314
|
+
let openData = (!currentTarget || this.openDataTarget === currentTarget) && (this.runtimeOpenDataScope === null || this.runtimeOpenDataScope === this.getRuntimeOpenDataScope()) ? this.otherParams?.openData : null;
|
|
1309
1315
|
if (!openData && this.store.openData) {
|
|
1310
1316
|
try {
|
|
1311
1317
|
openData = await this.getOpenData();
|
|
@@ -1369,6 +1375,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1369
1375
|
const previousScope = this.getAvailabilityScopeDescriptor(this.otherParams || {});
|
|
1370
1376
|
const previousItemRuleConfig = this.otherParams?.itemRule;
|
|
1371
1377
|
const explicitlySetsOpenData = Object.prototype.hasOwnProperty.call(params, 'openData');
|
|
1378
|
+
const nextParams = cover ? params : {
|
|
1379
|
+
...this.otherParams,
|
|
1380
|
+
...params
|
|
1381
|
+
};
|
|
1382
|
+
if (explicitlySetsOpenData || this.getRuntimeOpenDataScope() !== this.getRuntimeOpenDataScope(nextParams)) {
|
|
1383
|
+
this.clearOpenDataCache();
|
|
1384
|
+
}
|
|
1372
1385
|
await super.setOtherParams(params, {
|
|
1373
1386
|
cover
|
|
1374
1387
|
});
|
|
@@ -1385,6 +1398,8 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1385
1398
|
}
|
|
1386
1399
|
}
|
|
1387
1400
|
async destroy() {
|
|
1401
|
+
this.runtimeOpenDataDestroyed = true;
|
|
1402
|
+
this.clearOpenDataCache();
|
|
1388
1403
|
this.availabilityScheduleCatalog = null;
|
|
1389
1404
|
this.availabilityRuntimeOffsetMinutes = null;
|
|
1390
1405
|
await this.resetAvailabilityProjectionState('destroy');
|
|
@@ -1685,52 +1700,117 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1685
1700
|
action: this.resolveDiscountAction(this.resolveDiscountOrderIdentity(tempOrder))
|
|
1686
1701
|
});
|
|
1687
1702
|
}
|
|
1703
|
+
getRuntimeOpenDataScope(otherParams = this.otherParams) {
|
|
1704
|
+
return JSON.stringify({
|
|
1705
|
+
shop: this.getPickupTimingContextData('shop_id'),
|
|
1706
|
+
appShop: this.appPlugin ? this.getAppData('shop_id') : undefined,
|
|
1707
|
+
tenant: this.appPlugin ? this.getAppData('tenant_id') : undefined,
|
|
1708
|
+
businessCode: String(otherParams?.businessCode ?? otherParams?.business_code ?? '').trim(),
|
|
1709
|
+
channel: String(otherParams?.channel || super.getSubmitOrderSalesChannel()).trim(),
|
|
1710
|
+
platform: (0, _platform.normalizeRuntimePlatform)(otherParams?.platform),
|
|
1711
|
+
timezone: this.getPickupTimingContextData('timezone'),
|
|
1712
|
+
businessTimezone: otherParams?.businessTimezone,
|
|
1713
|
+
cacheId: otherParams === this.otherParams ? this.cacheId : otherParams?.cacheId
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
resetRuntimeOpenData() {
|
|
1717
|
+
this.runtimeOpenDataGeneration += 1;
|
|
1718
|
+
this.runtimeOpenDataScope = null;
|
|
1719
|
+
this.runtimeOpenDataSnapshot = null;
|
|
1720
|
+
this.runtimeOpenDataModule = null;
|
|
1721
|
+
this.runtimeOpenDataCore = undefined;
|
|
1722
|
+
this.openDataTarget = null;
|
|
1723
|
+
this.loadOpenDataInFlight = null;
|
|
1724
|
+
this.loadOpenDataInFlightTarget = null;
|
|
1725
|
+
this.otherParams = {
|
|
1726
|
+
...this.otherParams,
|
|
1727
|
+
openData: null
|
|
1728
|
+
};
|
|
1729
|
+
this.store.openData?.clearCache?.();
|
|
1730
|
+
}
|
|
1731
|
+
async prepareInvoiceTemplateAtSolutionReady(injectedOpenData) {
|
|
1732
|
+
const businessCode = this.getBookingTicketBusinessCode();
|
|
1733
|
+
if (!businessCode || !this.store.openData) return;
|
|
1734
|
+
if (injectedOpenData) {
|
|
1735
|
+
this.otherParams.openData = injectedOpenData;
|
|
1736
|
+
this.openDataTarget = `${businessCode}+${this.getSubmitOrderSalesChannel()}`;
|
|
1737
|
+
}
|
|
1738
|
+
try {
|
|
1739
|
+
await this.loadOpenDataConfig();
|
|
1740
|
+
} catch (error) {
|
|
1741
|
+
console.warn('[UnifiedBookingSales] Invoice 模板预加载失败,使用默认配置', error);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
async loadOpenDataConfig() {
|
|
1745
|
+
const businessCode = this.getBookingTicketBusinessCode();
|
|
1746
|
+
if (!businessCode) return null;
|
|
1747
|
+
return this.loadOpenData({
|
|
1748
|
+
businessCode,
|
|
1749
|
+
channel: this.getSubmitOrderSalesChannel()
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1688
1752
|
|
|
1689
|
-
/**
|
|
1690
|
-
* Loads OpenData without borrowing BookingTicket. Cache ownership is tied to the exact
|
|
1691
|
-
* business/channel target so a reused solution instance cannot leak another entry's menus.
|
|
1692
|
-
*/
|
|
1753
|
+
/** A successful configuration belongs to this business runtime until an explicit refresh. */
|
|
1693
1754
|
async loadOpenData(params) {
|
|
1694
|
-
|
|
1755
|
+
const module = this.store.openData;
|
|
1756
|
+
if (!module) {
|
|
1695
1757
|
throw new Error('[UnifiedBookingSales] openData 模块未初始化');
|
|
1696
1758
|
}
|
|
1759
|
+
if (this.runtimeOpenDataDestroyed) {
|
|
1760
|
+
throw new Error('Store settings changed. Please try again.');
|
|
1761
|
+
}
|
|
1697
1762
|
const businessCode = String(params.businessCode || '').trim();
|
|
1698
1763
|
const channel = String(params.channel || '').trim();
|
|
1699
1764
|
if (!businessCode || !channel) {
|
|
1700
1765
|
throw new Error('[UnifiedBookingSales] OpenData 需要 businessCode 与 channel');
|
|
1701
1766
|
}
|
|
1702
1767
|
const target = `${businessCode}+${channel}`;
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1768
|
+
this.otherParams.businessCode = businessCode;
|
|
1769
|
+
this.otherParams.channel = channel;
|
|
1770
|
+
const scope = this.getRuntimeOpenDataScope();
|
|
1771
|
+
if (params.force) {
|
|
1772
|
+
this.clearOpenDataCache();
|
|
1773
|
+
}
|
|
1774
|
+
if (this.runtimeOpenDataScope !== scope || this.runtimeOpenDataModule !== module || this.runtimeOpenDataCore !== this.core) {
|
|
1775
|
+
// Only the first, explicitly injected target may seed a new runtime snapshot.
|
|
1776
|
+
const injectedOpenData = this.runtimeOpenDataScope === null && (!this.openDataTarget || this.openDataTarget === target) && isRecord(this.otherParams.openData) ? this.otherParams.openData : null;
|
|
1777
|
+
if (this.runtimeOpenDataScope !== null) {
|
|
1778
|
+
// The caller's Pickup Timing scope already changes with this runtime scope.
|
|
1779
|
+
this.resetRuntimeOpenData();
|
|
1708
1780
|
}
|
|
1709
|
-
|
|
1781
|
+
this.runtimeOpenDataScope = scope;
|
|
1782
|
+
this.runtimeOpenDataModule = module;
|
|
1783
|
+
this.runtimeOpenDataCore = this.core;
|
|
1784
|
+
this.runtimeOpenDataSnapshot = injectedOpenData;
|
|
1710
1785
|
}
|
|
1711
1786
|
if (this.loadOpenDataInFlight) {
|
|
1712
|
-
|
|
1713
|
-
|
|
1787
|
+
return this.loadOpenDataInFlight;
|
|
1788
|
+
}
|
|
1789
|
+
const generation = this.runtimeOpenDataGeneration;
|
|
1790
|
+
const core = this.core;
|
|
1791
|
+
const request = (async () => {
|
|
1792
|
+
let openData = this.runtimeOpenDataSnapshot;
|
|
1793
|
+
if (openData) {
|
|
1794
|
+
await module.ensureInvoiceTemplateSettings?.(target, openData);
|
|
1795
|
+
} else {
|
|
1796
|
+
openData = await module.fetchOpenData({
|
|
1797
|
+
scope: 'board',
|
|
1798
|
+
target,
|
|
1799
|
+
section_code: [...OPEN_DATA_SECTION_CODES]
|
|
1800
|
+
});
|
|
1714
1801
|
}
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1802
|
+
if (this.runtimeOpenDataDestroyed || generation !== this.runtimeOpenDataGeneration || scope !== this.getRuntimeOpenDataScope() || module !== this.store.openData || core !== this.core) {
|
|
1803
|
+
throw new Error('Store settings changed. Please try again.');
|
|
1804
|
+
}
|
|
1805
|
+
this.runtimeOpenDataSnapshot = openData;
|
|
1806
|
+
this.openDataTarget = target;
|
|
1807
|
+
this.otherParams.openData = openData;
|
|
1808
|
+
return openData;
|
|
1809
|
+
})();
|
|
1718
1810
|
this.loadOpenDataInFlightTarget = target;
|
|
1719
|
-
const request = this.store.openData.fetchOpenData({
|
|
1720
|
-
scope: 'board',
|
|
1721
|
-
target,
|
|
1722
|
-
section_code: [...OPEN_DATA_SECTION_CODES]
|
|
1723
|
-
});
|
|
1724
1811
|
this.loadOpenDataInFlight = request;
|
|
1725
1812
|
try {
|
|
1726
|
-
|
|
1727
|
-
if (this.loadOpenDataInFlight === request) {
|
|
1728
|
-
this.openDataTarget = target;
|
|
1729
|
-
this.otherParams.openData = openData;
|
|
1730
|
-
this.otherParams.businessCode = businessCode;
|
|
1731
|
-
this.otherParams.channel = channel;
|
|
1732
|
-
}
|
|
1733
|
-
return openData;
|
|
1813
|
+
return await request;
|
|
1734
1814
|
} finally {
|
|
1735
1815
|
if (this.loadOpenDataInFlight === request) {
|
|
1736
1816
|
this.loadOpenDataInFlight = null;
|
|
@@ -1739,13 +1819,19 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1739
1819
|
}
|
|
1740
1820
|
}
|
|
1741
1821
|
async getOpenData() {
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1822
|
+
return this.loadOpenDataConfig();
|
|
1823
|
+
}
|
|
1824
|
+
async loadPickupTimingOpenData(_force) {
|
|
1825
|
+
const scope = this.getPickupTimingScope();
|
|
1826
|
+
const businessCode = String(this.otherParams?.businessCode ?? this.otherParams?.business_code ?? '').trim();
|
|
1827
|
+
const config = await this.loadOpenData({
|
|
1746
1828
|
businessCode,
|
|
1747
|
-
channel
|
|
1829
|
+
channel: this.getSubmitOrderSalesChannel()
|
|
1748
1830
|
});
|
|
1831
|
+
if (scope !== this.getPickupTimingScope()) {
|
|
1832
|
+
throw new Error('Store settings changed. Please try again.');
|
|
1833
|
+
}
|
|
1834
|
+
return config;
|
|
1749
1835
|
}
|
|
1750
1836
|
resetAllergyItemRuleState() {
|
|
1751
1837
|
this.allergyItemRuleConfigs = [];
|
|
@@ -1840,10 +1926,8 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1840
1926
|
});
|
|
1841
1927
|
}
|
|
1842
1928
|
clearOpenDataCache() {
|
|
1843
|
-
this.
|
|
1844
|
-
this.
|
|
1845
|
-
this.loadOpenDataInFlightTarget = null;
|
|
1846
|
-
super.clearOpenDataCache();
|
|
1929
|
+
this.resetRuntimeOpenData();
|
|
1930
|
+
this.resetPickupTimingCache();
|
|
1847
1931
|
}
|
|
1848
1932
|
async getInvoiceLayoutConfig() {
|
|
1849
1933
|
const openData = await this.getOpenData();
|
|
@@ -1863,7 +1947,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1863
1947
|
const businessCode = String(this.otherParams?.businessCode || '').trim();
|
|
1864
1948
|
const channel = String(this.otherParams?.channel || '').trim();
|
|
1865
1949
|
if (!businessCode || !channel) return false;
|
|
1866
|
-
return this.openDataTarget === `${businessCode}+${channel}
|
|
1950
|
+
return this.openDataTarget === `${businessCode}+${channel}` && this.runtimeOpenDataScope === this.getRuntimeOpenDataScope();
|
|
1867
1951
|
}
|
|
1868
1952
|
|
|
1869
1953
|
/**
|
package/lib/solution/index.d.ts
CHANGED
package/lib/solution/index.js
CHANGED
|
@@ -123,4 +123,15 @@ Object.keys(_UnifiedBookingSales).forEach(function (key) {
|
|
|
123
123
|
return _UnifiedBookingSales[key];
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
|
+
});
|
|
127
|
+
var _OrderInvoicePreview = require("./OrderInvoicePreview");
|
|
128
|
+
Object.keys(_OrderInvoicePreview).forEach(function (key) {
|
|
129
|
+
if (key === "default" || key === "__esModule") return;
|
|
130
|
+
if (key in exports && exports[key] === _OrderInvoicePreview[key]) return;
|
|
131
|
+
Object.defineProperty(exports, key, {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function () {
|
|
134
|
+
return _OrderInvoicePreview[key];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
126
137
|
});
|