@pisell/pisellos 2.3.129 → 2.3.131

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.
Files changed (102) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/modules/BusinessAvailability/index.d.ts +30 -0
  4. package/dist/modules/BusinessAvailability/index.js +204 -0
  5. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  6. package/dist/modules/FulfillmentTiming/index.js +407 -0
  7. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  8. package/dist/modules/FulfillmentTiming/types.js +1 -0
  9. package/dist/modules/OpenData/types.d.ts +8 -0
  10. package/dist/modules/Order/index.d.ts +11 -2
  11. package/dist/modules/Order/index.js +370 -253
  12. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  13. package/dist/modules/Order/pickupTiming.js +53 -0
  14. package/dist/modules/Order/types.d.ts +13 -1
  15. package/dist/modules/Order/utils.js +16 -6
  16. package/dist/modules/Payment/index.js +9 -10
  17. package/dist/modules/Schedule/index.d.ts +8 -0
  18. package/dist/modules/Schedule/index.js +141 -39
  19. package/dist/modules/index.d.ts +1 -0
  20. package/dist/modules/index.js +1 -0
  21. package/dist/plugins/request.d.ts +7 -0
  22. package/dist/server/utils/small-ticket.d.ts +1 -85
  23. package/dist/server/utils/small-ticket.js +2 -2542
  24. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  25. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  26. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  27. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
  28. package/dist/shared/receipt/small-ticket.d.ts +85 -0
  29. package/dist/shared/receipt/small-ticket.js +2576 -0
  30. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  31. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  32. package/dist/solution/BaseSales/index.d.ts +28 -15
  33. package/dist/solution/BaseSales/index.js +1346 -1101
  34. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  35. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  36. package/dist/solution/BaseSales/types.d.ts +11 -0
  37. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  38. package/dist/solution/BookingByStep/index.d.ts +1 -1
  39. package/dist/solution/BookingTicket/index.d.ts +2 -2
  40. package/dist/solution/BookingTicket/index.js +41 -13
  41. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  42. package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
  43. package/dist/solution/OrderInvoicePreview/index.js +269 -0
  44. package/dist/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  45. package/dist/solution/UnifiedBookingSales/businessAvailability.js +292 -0
  46. package/dist/solution/UnifiedBookingSales/index.d.ts +24 -4
  47. package/dist/solution/UnifiedBookingSales/index.js +953 -709
  48. package/dist/solution/UnifiedBookingSales/types.d.ts +2 -0
  49. package/dist/solution/index.d.ts +1 -0
  50. package/dist/solution/index.js +2 -1
  51. package/lib/index.d.ts +2 -0
  52. package/lib/index.js +21 -1
  53. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  54. package/lib/modules/BusinessAvailability/index.d.ts +30 -0
  55. package/lib/modules/BusinessAvailability/index.js +146 -0
  56. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  57. package/lib/modules/FulfillmentTiming/index.js +359 -0
  58. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  59. package/lib/modules/FulfillmentTiming/types.js +5 -0
  60. package/lib/modules/OpenData/types.d.ts +8 -0
  61. package/lib/modules/Order/index.d.ts +11 -2
  62. package/lib/modules/Order/index.js +101 -14
  63. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  64. package/lib/modules/Order/pickupTiming.js +61 -0
  65. package/lib/modules/Order/types.d.ts +13 -1
  66. package/lib/modules/Order/utils.js +12 -4
  67. package/lib/modules/Payment/index.js +3 -4
  68. package/lib/modules/Schedule/index.d.ts +8 -0
  69. package/lib/modules/Schedule/index.js +68 -12
  70. package/lib/modules/index.d.ts +1 -0
  71. package/lib/modules/index.js +11 -0
  72. package/lib/plugins/request.d.ts +7 -0
  73. package/lib/server/utils/small-ticket.d.ts +1 -85
  74. package/lib/server/utils/small-ticket.js +9 -2305
  75. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  76. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  77. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  78. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
  79. package/lib/shared/receipt/small-ticket.d.ts +85 -0
  80. package/lib/shared/receipt/small-ticket.js +2342 -0
  81. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  82. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  83. package/lib/solution/BaseSales/index.d.ts +28 -15
  84. package/lib/solution/BaseSales/index.js +161 -25
  85. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  86. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  87. package/lib/solution/BaseSales/types.d.ts +11 -0
  88. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  89. package/lib/solution/BookingByStep/index.d.ts +1 -1
  90. package/lib/solution/BookingTicket/index.d.ts +2 -2
  91. package/lib/solution/BookingTicket/index.js +37 -4
  92. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  93. package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
  94. package/lib/solution/OrderInvoicePreview/index.js +192 -0
  95. package/lib/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  96. package/lib/solution/UnifiedBookingSales/businessAvailability.js +138 -0
  97. package/lib/solution/UnifiedBookingSales/index.d.ts +24 -4
  98. package/lib/solution/UnifiedBookingSales/index.js +184 -46
  99. package/lib/solution/UnifiedBookingSales/types.d.ts +2 -0
  100. package/lib/solution/index.d.ts +1 -0
  101. package/lib/solution/index.js +11 -0
  102. package/package.json +1 -1
@@ -0,0 +1,27 @@
1
+ import { type BusinessAvailability } from '../../modules/BusinessAvailability';
2
+ import type { ScheduleModule } from '../../modules/Schedule';
3
+ interface BusinessAvailabilityHost {
4
+ loadOpenData: () => Promise<Record<string, unknown> | null>;
5
+ getSchedule: () => ScheduleModule | undefined;
6
+ getTimezone: () => string;
7
+ getScope: () => string;
8
+ now?: () => Date;
9
+ }
10
+ /** Read successful configuration once per business runtime; evaluate the clock on demand. */
11
+ export declare class BusinessAvailabilityController {
12
+ private readonly host;
13
+ private runtime?;
14
+ constructor(host: BusinessAvailabilityHost);
15
+ invalidate(): void;
16
+ private now;
17
+ private getRuntime;
18
+ private assertCurrent;
19
+ private loadConfig;
20
+ private loadSchedules;
21
+ private error;
22
+ /** Synchronous final cart-commit check; deliberately never starts a load. */
23
+ getCachedAvailability(): BusinessAvailability;
24
+ getAvailability(): Promise<BusinessAvailability>;
25
+ assertAvailable(): void;
26
+ }
27
+ export {};
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BusinessAvailabilityController = void 0;
7
+ var _lodashEs = require("lodash-es");
8
+ var _BusinessAvailability = require("../../modules/BusinessAvailability");
9
+ async function withTimeout(request) {
10
+ let timer;
11
+ try {
12
+ return await Promise.race([request, new Promise((_, reject) => {
13
+ timer = setTimeout(() => reject(new Error('Unable to load business settings. Please try again.')), 30_000);
14
+ })]);
15
+ } finally {
16
+ if (timer !== undefined) clearTimeout(timer);
17
+ }
18
+ }
19
+
20
+ /** Read successful configuration once per business runtime; evaluate the clock on demand. */
21
+ class BusinessAvailabilityController {
22
+ runtime;
23
+ constructor(host) {
24
+ this.host = host;
25
+ }
26
+ invalidate() {
27
+ this.runtime = undefined;
28
+ }
29
+ now() {
30
+ return this.host.now?.() ?? new Date();
31
+ }
32
+ getRuntime() {
33
+ const scope = this.host.getScope();
34
+ if (this.runtime?.scope !== scope) this.runtime = {
35
+ scope
36
+ };
37
+ return this.runtime;
38
+ }
39
+ assertCurrent(runtime) {
40
+ if (this.runtime !== runtime || runtime.scope !== this.host.getScope()) {
41
+ throw new Error('Store settings changed. Please try again.');
42
+ }
43
+ }
44
+ async loadConfig(runtime) {
45
+ if (runtime.config) return runtime.config;
46
+ if (!runtime.configRequest) {
47
+ runtime.configRequest = (async () => {
48
+ const data = await withTimeout(this.host.loadOpenData());
49
+ this.assertCurrent(runtime);
50
+ if (!data) throw new Error('Business settings are unavailable. Please try again.');
51
+ const config = (0, _lodashEs.cloneDeep)((0, _BusinessAvailability.normalizeBusinessAvailabilityConfig)(data));
52
+ runtime.config = config;
53
+ return config;
54
+ })();
55
+ }
56
+ const request = runtime.configRequest;
57
+ try {
58
+ return await request;
59
+ } finally {
60
+ if (runtime.configRequest === request) runtime.configRequest = undefined;
61
+ }
62
+ }
63
+ async loadSchedules(runtime) {
64
+ if (runtime.schedules) return runtime.schedules;
65
+ if (!runtime.scheduleRequest) {
66
+ runtime.scheduleRequest = (async () => {
67
+ const schedule = this.host.getSchedule();
68
+ if (!schedule) throw new Error('Business operating-hours schedule is unavailable. Please try again.');
69
+ await withTimeout(schedule.loadAllSchedule({
70
+ useCache: true
71
+ }));
72
+ this.assertCurrent(runtime);
73
+ const schedules = (0, _lodashEs.cloneDeep)(schedule.getScheduleListByIds(runtime.config.scheduleIds) || []);
74
+ runtime.schedules = schedules;
75
+ return schedules;
76
+ })();
77
+ }
78
+ const request = runtime.scheduleRequest;
79
+ try {
80
+ return await request;
81
+ } finally {
82
+ if (runtime.scheduleRequest === request) runtime.scheduleRequest = undefined;
83
+ }
84
+ }
85
+ error(reason, runtime) {
86
+ return {
87
+ status: 'error',
88
+ behavior: 'hide_all',
89
+ message: null,
90
+ nextChangeAt: this.now().getTime() + 60_000,
91
+ requirePaymentOnSubmit: runtime?.config?.requirePaymentOnSubmit ?? true,
92
+ error: reason instanceof Error ? reason.message : 'Business settings are unavailable. Please try again.'
93
+ };
94
+ }
95
+
96
+ /** Synchronous final cart-commit check; deliberately never starts a load. */
97
+ getCachedAvailability() {
98
+ const runtime = this.getRuntime();
99
+ try {
100
+ this.assertCurrent(runtime);
101
+ if (!runtime.config) throw new Error('Business settings are still loading. Please try again.');
102
+ return (0, _BusinessAvailability.computeBusinessAvailability)({
103
+ config: runtime.config,
104
+ schedules: runtime.schedules || [],
105
+ timezone: this.host.getTimezone(),
106
+ now: this.now()
107
+ });
108
+ } catch (reason) {
109
+ return this.error(reason, runtime);
110
+ }
111
+ }
112
+ async getAvailability() {
113
+ const runtime = this.getRuntime();
114
+ try {
115
+ const config = await this.loadConfig(runtime);
116
+ this.assertCurrent(runtime);
117
+ if (!config.paused && !config.invalidScheduleIds && config.scheduleIds.length) {
118
+ await this.loadSchedules(runtime);
119
+ }
120
+ this.assertCurrent(runtime);
121
+ return this.getCachedAvailability();
122
+ } catch (reason) {
123
+ return this.error(reason, runtime);
124
+ }
125
+ }
126
+ assertAvailable() {
127
+ const availability = this.getCachedAvailability();
128
+ if (availability.status !== 'open') {
129
+ const error = new Error(availability.error || (availability.status === 'paused' ? 'Ordering is temporarily paused.' : 'Ordering is currently closed.'));
130
+ Object.assign(error, {
131
+ code: 'BUSINESS_UNAVAILABLE',
132
+ businessAvailability: availability
133
+ });
134
+ throw error;
135
+ }
136
+ }
137
+ }
138
+ exports.BusinessAvailabilityController = BusinessAvailabilityController;
@@ -5,9 +5,11 @@ import type { LoadScheduleAvailableDateParams, ScheduleItem } from '../../module
5
5
  import type { ProductListLoadProductsParams, ProductListStoreQueryParams } from '../../modules/ProductList';
6
6
  import type { AvailabilityDateRange, AvailabilityOccupancy, AvailabilityProduct, AvailabilityResource, GetProductTimeRangesRequest } from '../../modules/ResourcePlanner';
7
7
  import type { AvailabilityContextRef, ContextualAvailabilityQuery, ContextualAvailabilityQueryResult, ContextualCommitAvailabilitySelectionParams, ContextualProductTimeRangeGroup, UnifiedBookingSalesAddRetailProductParams, UnifiedBookingSalesApplyPlannerDiscountsParams, UnifiedBookingSalesCommitAvailabilitySelectionResult, UnifiedBookingSalesDiscountResult, UnifiedBookingSalesLoadProductsByScheduleDateParams, UnifiedBookingSalesLoadOpenDataParams, UnifiedBookingSalesPrepareAvailabilityProjectionParams, UnifiedBookingSalesPolicyResponse, UnifiedBookingSalesResolveProductAllergyRequirementParams, UnifiedBookingSalesStageRetailProductsParams, UnifiedBookingSalesState } from './types';
8
+ import type { BusinessAvailability } from '../../modules/BusinessAvailability';
8
9
  import { BookingTicket } from '../BookingTicket';
9
10
  import type { AllergyRequirement } from '../../model/strategy/adapter/itemRule';
10
11
  export * from './types';
12
+ export type { BusinessAvailability, BusinessClosedBehavior } from '../../modules/BusinessAvailability';
11
13
  export { AvailabilityError } from '../../modules/ResourcePlanner';
12
14
  /**
13
15
  * Converts Rules/Order discount internals into a small UI-facing diagnostic. The result keeps
@@ -59,6 +61,14 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
59
61
  protected defaultName: string;
60
62
  protected defaultVersion: string;
61
63
  protected store: UnifiedBookingSalesState;
64
+ protected pickupTimingEnabled: boolean;
65
+ private businessAvailabilityController?;
66
+ private runtimeOpenDataScope;
67
+ private runtimeOpenDataSnapshot;
68
+ private runtimeOpenDataModule;
69
+ private runtimeOpenDataCore;
70
+ private runtimeOpenDataGeneration;
71
+ private runtimeOpenDataDestroyed;
62
72
  private unifiedProductCatalog;
63
73
  private availabilityRuntimeOffsetMinutes;
64
74
  private availabilityScheduleCatalog;
@@ -79,6 +89,14 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
79
89
  private allergyItemRuleConfigsPromise;
80
90
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
81
91
  protected getSubmitOrderSalesChannel(): string;
92
+ /** Only the explicit Kiosk Sales consumer entry enables this policy; POS stays unchanged. */
93
+ protected isBusinessAvailabilityEnabled(): boolean;
94
+ protected getBusinessAvailabilityScope(): string;
95
+ private getBusinessAvailabilityController;
96
+ getBusinessAvailability(): Promise<BusinessAvailability>;
97
+ /** Internal final-write assertion; does not fetch OpenData or Schedule. */
98
+ assertBusinessAvailability(): void;
99
+ protected getSubModuleHooks(moduleName: string): any;
82
100
  private createAvailabilityFacadeError;
83
101
  private getAvailabilityScopeDescriptor;
84
102
  private normalizeAvailabilityIdList;
@@ -142,12 +160,14 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
142
160
  private resolveDiscountAction;
143
161
  private resetCachedCustomerDiscountState;
144
162
  private refreshLegacySessionCustomerDiscounts;
145
- /**
146
- * Loads OpenData without borrowing BookingTicket. Cache ownership is tied to the exact
147
- * business/channel target so a reused solution instance cannot leak another entry's menus.
148
- */
163
+ private getRuntimeOpenDataScope;
164
+ private resetRuntimeOpenData;
165
+ protected prepareInvoiceTemplateAtSolutionReady(injectedOpenData?: OpenDataConfig): Promise<void>;
166
+ protected loadOpenDataConfig(): Promise<OpenDataConfig | null>;
167
+ /** A successful configuration belongs to this business runtime until an explicit refresh. */
149
168
  loadOpenData(params: UnifiedBookingSalesLoadOpenDataParams): Promise<OpenDataConfig>;
150
169
  getOpenData(): Promise<OpenDataConfig | null>;
170
+ protected loadPickupTimingOpenData(_force: boolean): Promise<Record<string, unknown>>;
151
171
  private resetAllergyItemRuleState;
152
172
  private fetchAllergyItemRuleConfigs;
153
173
  private ensureAllergyItemRuleConfigsLoaded;
@@ -49,13 +49,13 @@ Object.keys(_types).forEach(function (key) {
49
49
  });
50
50
  });
51
51
  var _remoteOccupancyCache = require("./remoteOccupancyCache");
52
+ var _businessAvailability = require("./businessAvailability");
52
53
  var _BookingTicket = require("../BookingTicket");
53
54
  var _localClock = require("../../modules/ResourcePlanner/localClock");
54
55
  var _platform = require("../../utils/platform");
55
56
  var _itemRule = require("../../model/strategy/adapter/itemRule");
56
57
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
58
  const OPEN_DATA_SECTION_CODES = ['sale', 'reservation', 'fulfillment', 'menu', 'workflow', 'documents', 'basic', 'checkout', 'availability'];
58
- const OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
59
59
  function normalizePositiveInteger(value) {
60
60
  const normalized = Number(value);
61
61
  if (!Number.isInteger(normalized) || normalized <= 0) return undefined;
@@ -1199,6 +1199,14 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1199
1199
  defaultName = 'unifiedBookingSales';
1200
1200
  defaultVersion = '1.0.0';
1201
1201
  store = {};
1202
+ pickupTimingEnabled = true;
1203
+ businessAvailabilityController;
1204
+ runtimeOpenDataScope = null;
1205
+ runtimeOpenDataSnapshot = null;
1206
+ runtimeOpenDataModule = null;
1207
+ runtimeOpenDataCore;
1208
+ runtimeOpenDataGeneration = 0;
1209
+ runtimeOpenDataDestroyed = false;
1202
1210
  unifiedProductCatalog = [];
1203
1211
  availabilityRuntimeOffsetMinutes = null;
1204
1212
  availabilityScheduleCatalog = null;
@@ -1218,16 +1226,16 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1218
1226
  allergyItemRuleConfigs = [];
1219
1227
  allergyItemRuleConfigsPromise = null;
1220
1228
  async initialize(core, options = {}) {
1229
+ this.resetRuntimeOpenData();
1230
+ this.runtimeOpenDataDestroyed = false;
1231
+ const openDataGeneration = this.runtimeOpenDataGeneration;
1221
1232
  this.availabilityScheduleCatalog = null;
1222
- this.openDataTarget = null;
1223
1233
  this.availabilityRuntimeOffsetMinutes = (0, _localClock.captureRuntimeOffsetMinutes)();
1224
1234
  this.clearAvailabilityRemoteResourceState();
1225
1235
  this.resetAllergyItemRuleState();
1226
1236
  await super.initialize(core, options);
1227
- const openDataBusinessCode = String(this.otherParams?.businessCode ?? this.otherParams?.business_code ?? '').trim();
1228
- const openDataChannel = String(this.otherParams?.channel ?? '').trim();
1229
- if (this.otherParams?.openData && openDataBusinessCode && openDataChannel) {
1230
- this.openDataTarget = `${openDataBusinessCode}+${openDataChannel}`;
1237
+ if (this.runtimeOpenDataDestroyed || openDataGeneration !== this.runtimeOpenDataGeneration) {
1238
+ throw new Error('Store settings changed. Please try again.');
1231
1239
  }
1232
1240
  this.captureAvailabilityScheduleCatalog();
1233
1241
  }
@@ -1235,6 +1243,57 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1235
1243
  const channel = String(this.otherParams?.channel ?? '').trim();
1236
1244
  return channel || super.getSubmitOrderSalesChannel();
1237
1245
  }
1246
+
1247
+ /** Only the explicit Kiosk Sales consumer entry enables this policy; POS stays unchanged. */
1248
+ isBusinessAvailabilityEnabled() {
1249
+ return this.otherParams?.enableBusinessAvailability === true && ['pc', 'h5', 'kiosk'].includes((0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform));
1250
+ }
1251
+ getBusinessAvailabilityScope() {
1252
+ return `${this.getRuntimeOpenDataScope()}:${this.runtimeOpenDataGeneration}`;
1253
+ }
1254
+ getBusinessAvailabilityController() {
1255
+ if (!this.businessAvailabilityController) {
1256
+ this.businessAvailabilityController = new _businessAvailability.BusinessAvailabilityController({
1257
+ loadOpenData: () => this.loadOpenDataConfig(),
1258
+ getSchedule: () => this.store.schedule,
1259
+ getTimezone: () => String(this.otherParams?.businessTimezone || this.getPickupTimingContextData('timezone') || ''),
1260
+ getScope: () => this.getBusinessAvailabilityScope()
1261
+ });
1262
+ }
1263
+ return this.businessAvailabilityController;
1264
+ }
1265
+ getBusinessAvailability() {
1266
+ return this.getBusinessAvailabilityController().getAvailability();
1267
+ }
1268
+
1269
+ /** Internal final-write assertion; does not fetch OpenData or Schedule. */
1270
+ assertBusinessAvailability() {
1271
+ if (this.isBusinessAvailabilityEnabled()) this.getBusinessAvailabilityController().assertAvailable();
1272
+ }
1273
+ getSubModuleHooks(moduleName) {
1274
+ const hooks = super.getSubModuleHooks(moduleName);
1275
+ if (moduleName !== 'order' || !this.isBusinessAvailabilityEnabled()) return hooks;
1276
+ let lastScope;
1277
+ let lastExistingScope;
1278
+ let scopeToken = {};
1279
+ return {
1280
+ ...hooks,
1281
+ getCartIntentScope: () => {
1282
+ const scope = this.getBusinessAvailabilityScope();
1283
+ const existingScope = hooks?.getCartIntentScope?.();
1284
+ if (scope !== lastScope || !Object.is(existingScope, lastExistingScope)) {
1285
+ lastScope = scope;
1286
+ lastExistingScope = existingScope;
1287
+ scopeToken = {};
1288
+ }
1289
+ return scopeToken;
1290
+ },
1291
+ beforeCartIntentCommit: context => {
1292
+ this.assertBusinessAvailability();
1293
+ hooks?.beforeCartIntentCommit?.(context);
1294
+ }
1295
+ };
1296
+ }
1238
1297
  createAvailabilityFacadeError(code, message, details) {
1239
1298
  return new _ResourcePlanner.AvailabilityError(code, message, details);
1240
1299
  }
@@ -1305,7 +1364,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1305
1364
  const businessCode = String(this.otherParams?.businessCode ?? this.otherParams?.business_code ?? '').trim();
1306
1365
  const channel = String(this.otherParams?.channel ?? '').trim();
1307
1366
  const currentTarget = businessCode && channel ? `${businessCode}+${channel}` : null;
1308
- let openData = !currentTarget || this.openDataTarget === currentTarget ? this.otherParams?.openData : null;
1367
+ let openData = (!currentTarget || this.openDataTarget === currentTarget) && (this.runtimeOpenDataScope === null || this.runtimeOpenDataScope === this.getRuntimeOpenDataScope()) ? this.otherParams?.openData : null;
1309
1368
  if (!openData && this.store.openData) {
1310
1369
  try {
1311
1370
  openData = await this.getOpenData();
@@ -1369,6 +1428,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1369
1428
  const previousScope = this.getAvailabilityScopeDescriptor(this.otherParams || {});
1370
1429
  const previousItemRuleConfig = this.otherParams?.itemRule;
1371
1430
  const explicitlySetsOpenData = Object.prototype.hasOwnProperty.call(params, 'openData');
1431
+ const nextParams = cover ? params : {
1432
+ ...this.otherParams,
1433
+ ...params
1434
+ };
1435
+ if (explicitlySetsOpenData || this.getRuntimeOpenDataScope() !== this.getRuntimeOpenDataScope(nextParams)) {
1436
+ this.clearOpenDataCache();
1437
+ }
1372
1438
  await super.setOtherParams(params, {
1373
1439
  cover
1374
1440
  });
@@ -1385,6 +1451,8 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1385
1451
  }
1386
1452
  }
1387
1453
  async destroy() {
1454
+ this.runtimeOpenDataDestroyed = true;
1455
+ this.clearOpenDataCache();
1388
1456
  this.availabilityScheduleCatalog = null;
1389
1457
  this.availabilityRuntimeOffsetMinutes = null;
1390
1458
  await this.resetAvailabilityProjectionState('destroy');
@@ -1685,52 +1753,118 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1685
1753
  action: this.resolveDiscountAction(this.resolveDiscountOrderIdentity(tempOrder))
1686
1754
  });
1687
1755
  }
1756
+ getRuntimeOpenDataScope(otherParams = this.otherParams) {
1757
+ return JSON.stringify({
1758
+ shop: this.getPickupTimingContextData('shop_id'),
1759
+ appShop: this.appPlugin ? this.getAppData('shop_id') : undefined,
1760
+ tenant: this.appPlugin ? this.getAppData('tenant_id') : undefined,
1761
+ businessCode: String(otherParams?.businessCode ?? otherParams?.business_code ?? '').trim(),
1762
+ channel: String(otherParams?.channel || super.getSubmitOrderSalesChannel()).trim(),
1763
+ platform: (0, _platform.normalizeRuntimePlatform)(otherParams?.platform),
1764
+ timezone: this.getPickupTimingContextData('timezone'),
1765
+ businessTimezone: otherParams?.businessTimezone,
1766
+ cacheId: otherParams === this.otherParams ? this.cacheId : otherParams?.cacheId
1767
+ });
1768
+ }
1769
+ resetRuntimeOpenData() {
1770
+ this.businessAvailabilityController?.invalidate();
1771
+ this.runtimeOpenDataGeneration += 1;
1772
+ this.runtimeOpenDataScope = null;
1773
+ this.runtimeOpenDataSnapshot = null;
1774
+ this.runtimeOpenDataModule = null;
1775
+ this.runtimeOpenDataCore = undefined;
1776
+ this.openDataTarget = null;
1777
+ this.loadOpenDataInFlight = null;
1778
+ this.loadOpenDataInFlightTarget = null;
1779
+ this.otherParams = {
1780
+ ...this.otherParams,
1781
+ openData: null
1782
+ };
1783
+ this.store.openData?.clearCache?.();
1784
+ }
1785
+ async prepareInvoiceTemplateAtSolutionReady(injectedOpenData) {
1786
+ const businessCode = this.getBookingTicketBusinessCode();
1787
+ if (!businessCode || !this.store.openData) return;
1788
+ if (injectedOpenData) {
1789
+ this.otherParams.openData = injectedOpenData;
1790
+ this.openDataTarget = `${businessCode}+${this.getSubmitOrderSalesChannel()}`;
1791
+ }
1792
+ try {
1793
+ await this.loadOpenDataConfig();
1794
+ } catch (error) {
1795
+ console.warn('[UnifiedBookingSales] Invoice 模板预加载失败,使用默认配置', error);
1796
+ }
1797
+ }
1798
+ async loadOpenDataConfig() {
1799
+ const businessCode = this.getBookingTicketBusinessCode();
1800
+ if (!businessCode) return null;
1801
+ return this.loadOpenData({
1802
+ businessCode,
1803
+ channel: this.getSubmitOrderSalesChannel()
1804
+ });
1805
+ }
1688
1806
 
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
- */
1807
+ /** A successful configuration belongs to this business runtime until an explicit refresh. */
1693
1808
  async loadOpenData(params) {
1694
- if (!this.store.openData) {
1809
+ const module = this.store.openData;
1810
+ if (!module) {
1695
1811
  throw new Error('[UnifiedBookingSales] openData 模块未初始化');
1696
1812
  }
1813
+ if (this.runtimeOpenDataDestroyed) {
1814
+ throw new Error('Store settings changed. Please try again.');
1815
+ }
1697
1816
  const businessCode = String(params.businessCode || '').trim();
1698
1817
  const channel = String(params.channel || '').trim();
1699
1818
  if (!businessCode || !channel) {
1700
1819
  throw new Error('[UnifiedBookingSales] OpenData 需要 businessCode 与 channel');
1701
1820
  }
1702
1821
  const target = `${businessCode}+${channel}`;
1703
- const cachedData = this.store.openData.getOpenData();
1704
- const lastFetchedAt = this.store.openData.getLastFetchedAt();
1705
- if (!params.force && this.openDataTarget === target && cachedData && lastFetchedAt && Date.now() - lastFetchedAt < OPEN_DATA_CACHE_TTL) {
1706
- if (typeof this.store.openData.ensureInvoiceTemplateSettings === 'function') {
1707
- await this.store.openData.ensureInvoiceTemplateSettings(target);
1822
+ this.otherParams.businessCode = businessCode;
1823
+ this.otherParams.channel = channel;
1824
+ const scope = this.getRuntimeOpenDataScope();
1825
+ if (params.force) {
1826
+ this.clearOpenDataCache();
1827
+ }
1828
+ if (this.runtimeOpenDataScope !== scope || this.runtimeOpenDataModule !== module || this.runtimeOpenDataCore !== this.core) {
1829
+ // Only the first, explicitly injected target may seed a new runtime snapshot.
1830
+ const injectedOpenData = this.runtimeOpenDataScope === null && (!this.openDataTarget || this.openDataTarget === target) && isRecord(this.otherParams.openData) ? this.otherParams.openData : null;
1831
+ if (this.runtimeOpenDataScope !== null) {
1832
+ // The caller's Pickup Timing scope already changes with this runtime scope.
1833
+ this.resetRuntimeOpenData();
1708
1834
  }
1709
- return cachedData;
1835
+ this.runtimeOpenDataScope = scope;
1836
+ this.runtimeOpenDataModule = module;
1837
+ this.runtimeOpenDataCore = this.core;
1838
+ this.runtimeOpenDataSnapshot = injectedOpenData;
1710
1839
  }
1711
1840
  if (this.loadOpenDataInFlight) {
1712
- if (this.loadOpenDataInFlightTarget === target) {
1713
- return await this.loadOpenDataInFlight;
1841
+ return this.loadOpenDataInFlight;
1842
+ }
1843
+ const generation = this.runtimeOpenDataGeneration;
1844
+ const core = this.core;
1845
+ const request = (async () => {
1846
+ let openData = this.runtimeOpenDataSnapshot;
1847
+ if (openData) {
1848
+ await module.ensureInvoiceTemplateSettings?.(target, openData);
1849
+ } else {
1850
+ openData = await module.fetchOpenData({
1851
+ scope: 'board',
1852
+ target,
1853
+ section_code: [...OPEN_DATA_SECTION_CODES]
1854
+ });
1714
1855
  }
1715
- await this.loadOpenDataInFlight;
1716
- return this.loadOpenData(params);
1717
- }
1856
+ if (this.runtimeOpenDataDestroyed || generation !== this.runtimeOpenDataGeneration || scope !== this.getRuntimeOpenDataScope() || module !== this.store.openData || core !== this.core) {
1857
+ throw new Error('Store settings changed. Please try again.');
1858
+ }
1859
+ this.runtimeOpenDataSnapshot = openData;
1860
+ this.openDataTarget = target;
1861
+ this.otherParams.openData = openData;
1862
+ return openData;
1863
+ })();
1718
1864
  this.loadOpenDataInFlightTarget = target;
1719
- const request = this.store.openData.fetchOpenData({
1720
- scope: 'board',
1721
- target,
1722
- section_code: [...OPEN_DATA_SECTION_CODES]
1723
- });
1724
1865
  this.loadOpenDataInFlight = request;
1725
1866
  try {
1726
- const openData = await request;
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;
1867
+ return await request;
1734
1868
  } finally {
1735
1869
  if (this.loadOpenDataInFlight === request) {
1736
1870
  this.loadOpenDataInFlight = null;
@@ -1739,13 +1873,19 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1739
1873
  }
1740
1874
  }
1741
1875
  async getOpenData() {
1742
- const businessCode = String(this.otherParams?.businessCode || '').trim();
1743
- const channel = String(this.otherParams?.channel || '').trim();
1744
- if (!businessCode || !channel) return null;
1745
- return this.loadOpenData({
1876
+ return this.loadOpenDataConfig();
1877
+ }
1878
+ async loadPickupTimingOpenData(_force) {
1879
+ const scope = this.getPickupTimingScope();
1880
+ const businessCode = String(this.otherParams?.businessCode ?? this.otherParams?.business_code ?? '').trim();
1881
+ const config = await this.loadOpenData({
1746
1882
  businessCode,
1747
- channel
1883
+ channel: this.getSubmitOrderSalesChannel()
1748
1884
  });
1885
+ if (scope !== this.getPickupTimingScope()) {
1886
+ throw new Error('Store settings changed. Please try again.');
1887
+ }
1888
+ return config;
1749
1889
  }
1750
1890
  resetAllergyItemRuleState() {
1751
1891
  this.allergyItemRuleConfigs = [];
@@ -1840,10 +1980,8 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1840
1980
  });
1841
1981
  }
1842
1982
  clearOpenDataCache() {
1843
- this.openDataTarget = null;
1844
- this.loadOpenDataInFlight = null;
1845
- this.loadOpenDataInFlightTarget = null;
1846
- super.clearOpenDataCache();
1983
+ this.resetRuntimeOpenData();
1984
+ this.resetPickupTimingCache();
1847
1985
  }
1848
1986
  async getInvoiceLayoutConfig() {
1849
1987
  const openData = await this.getOpenData();
@@ -1863,7 +2001,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1863
2001
  const businessCode = String(this.otherParams?.businessCode || '').trim();
1864
2002
  const channel = String(this.otherParams?.channel || '').trim();
1865
2003
  if (!businessCode || !channel) return false;
1866
- return this.openDataTarget === `${businessCode}+${channel}`;
2004
+ return this.openDataTarget === `${businessCode}+${channel}` && this.runtimeOpenDataScope === this.getRuntimeOpenDataScope();
1867
2005
  }
1868
2006
 
1869
2007
  /**
@@ -216,6 +216,8 @@ export interface UnifiedBookingSalesDiscountResult {
216
216
  summaryAfter?: unknown;
217
217
  }
218
218
  export interface UnifiedBookingSalesApi {
219
+ /** Uses cached business settings and evaluates the current store-local clock. */
220
+ getBusinessAvailability: () => Promise<import('../../modules/BusinessAvailability').BusinessAvailability>;
219
221
  loadOpenData: (params: UnifiedBookingSalesLoadOpenDataParams) => Promise<OpenDataConfig>;
220
222
  /** Returns the latest OpenData payload cached by this solution instance. */
221
223
  getOpenData: () => Promise<OpenDataConfig | null>;
@@ -9,3 +9,4 @@ export * from './ScanOrder';
9
9
  export * from './BaseSales';
10
10
  export * from './VenueBooking';
11
11
  export * from './UnifiedBookingSales';
12
+ export * from './OrderInvoicePreview';
@@ -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
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.129",
4
+ "version": "2.3.131",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",