@pisell/pisellos 0.10.80 → 0.10.82

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 (42) hide show
  1. package/dist/modules/ProductList/index.js +5 -0
  2. package/dist/modules/ResourcePlanner/planner.js +2 -1
  3. package/dist/solution/BookingByStep/index.d.ts +1 -1
  4. package/dist/solution/BookingTicket/index.d.ts +1 -1
  5. package/dist/solution/BookingTicket/index.js +36 -31
  6. package/dist/solution/ScanOrder/index.d.ts +0 -1
  7. package/dist/solution/ScanOrder/index.js +62 -59
  8. package/dist/solution/ScanOrder/types.d.ts +2 -0
  9. package/dist/solution/ScanOrder/types.js +2 -0
  10. package/dist/solution/UnifiedBookingSales/index.d.ts +11 -1
  11. package/dist/solution/UnifiedBookingSales/index.js +1485 -1163
  12. package/dist/solution/UnifiedBookingSales/types.d.ts +5 -0
  13. package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +11 -5
  14. package/dist/solution/VenueBooking/index.js +111 -104
  15. package/dist/solution/VenueBooking/types.d.ts +2 -0
  16. package/dist/solution/VenueBooking/types.js +3 -1
  17. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +1 -0
  18. package/dist/solution/VenueBooking/utils/smartPricing.js +6 -1
  19. package/dist/utils/hostLogger.d.ts +10 -0
  20. package/dist/utils/hostLogger.js +20 -0
  21. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  22. package/lib/modules/ProductList/index.js +5 -0
  23. package/lib/modules/ResourcePlanner/planner.js +2 -1
  24. package/lib/solution/BookingByStep/index.d.ts +1 -1
  25. package/lib/solution/BookingTicket/index.d.ts +1 -1
  26. package/lib/solution/BookingTicket/index.js +5 -4
  27. package/lib/solution/ScanOrder/index.d.ts +0 -1
  28. package/lib/solution/ScanOrder/index.js +47 -41
  29. package/lib/solution/ScanOrder/types.d.ts +2 -0
  30. package/lib/solution/ScanOrder/types.js +1 -0
  31. package/lib/solution/UnifiedBookingSales/index.d.ts +11 -1
  32. package/lib/solution/UnifiedBookingSales/index.js +269 -57
  33. package/lib/solution/UnifiedBookingSales/types.d.ts +5 -0
  34. package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +9 -5
  35. package/lib/solution/VenueBooking/index.js +38 -47
  36. package/lib/solution/VenueBooking/types.d.ts +2 -0
  37. package/lib/solution/VenueBooking/types.js +3 -1
  38. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +1 -0
  39. package/lib/solution/VenueBooking/utils/smartPricing.js +6 -1
  40. package/lib/utils/hostLogger.d.ts +10 -0
  41. package/lib/utils/hostLogger.js +25 -0
  42. package/package.json +1 -1
@@ -22,22 +22,26 @@ function readVenueCatalogList(response, description) {
22
22
  throw venueCatalogError('VENUE_CATALOG_LOAD_FAILED', response?.message || `${description} could not be loaded.`);
23
23
  }
24
24
  const total = response.data.total ?? response.data.total_count ?? response.data.total_num;
25
- if (total != null && Number.isFinite(Number(total)) && Number(total) > list.length) {
25
+ if (total == null ? list.length >= 999 : !Number.isSafeInteger(Number(total)) || Number(total) < 0 || Number(total) > list.length) {
26
26
  throw venueCatalogError('VENUE_CATALOG_INCOMPLETE', `${description} is incomplete. A complete catalog response is required.`);
27
27
  }
28
+ if (list.some(row => !Number.isSafeInteger(Number(row?.form_record_id)) || Number(row.form_record_id) <= 0)) {
29
+ throw venueCatalogError('VENUE_CATALOG_INCOMPLETE', `${description} contains a record without a valid menu ID.`);
30
+ }
28
31
  return list;
29
32
  }
30
33
  function validateVenueMenus(records, ids) {
31
- return ids.map(id => {
34
+ return ids.flatMap(id => {
32
35
  const menu = records.find(row => Number(row.form_record_id) === id);
33
- const config = menu?.partyroom_package;
34
- if (!menu || !['product_all', 'products', 'product_collection'].includes(config?.type) || !Array.isArray(menu.schedule) || menu.schedule.some(value => !Number.isSafeInteger(Number(value)) || Number(value) <= 0) || config.type !== 'product_all' && (!Array.isArray(config.products) || config.products.some(row => {
36
+ if (!menu || menu.deleted_at || menu.status && menu.status !== 'valid') return [];
37
+ const config = menu.partyroom_package;
38
+ if (!['product_all', 'products', 'product_collection'].includes(config?.type) || !Array.isArray(menu.schedule) || menu.schedule.some(value => !Number.isSafeInteger(Number(value)) || Number(value) <= 0) || config.type !== 'product_all' && (!Array.isArray(config.products) || config.products.some(row => {
35
39
  const value = Number(row?.[config.type === 'products' ? 'product_id' : 'product_collection_id']);
36
40
  return !Number.isSafeInteger(value) || value <= 0;
37
41
  }))) {
38
42
  throw venueCatalogError('VENUE_MENU_INCOMPLETE', 'The configured menu is incomplete. Reload the booking page.');
39
43
  }
40
- return (0, _lodashEs.cloneDeep)(menu);
44
+ return [(0, _lodashEs.cloneDeep)(menu)];
41
45
  });
42
46
  }
43
47
 
@@ -22,6 +22,7 @@ Object.keys(_types).forEach(function (key) {
22
22
  });
23
23
  var _utils = require("./utils");
24
24
  var _types2 = require("../BookingByStep/types");
25
+ var _hostLogger = require("../../utils/hostLogger");
25
26
  var _ProductList = require("../../modules/ProductList");
26
27
  var _Date = require("../../modules/Date");
27
28
  var _Schedule = require("../../modules/Schedule");
@@ -107,7 +108,11 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
107
108
  return {
108
109
  cacheId: this.cacheId,
109
110
  solutionName: this.name,
110
- moduleName: 'venueBooking'
111
+ moduleName: 'venueBooking',
112
+ host: this.window?.location?.host,
113
+ platform: this.otherParams?.platform,
114
+ channel: this.otherParams?.channel,
115
+ businessCode: this.otherParams?.businessCode
111
116
  };
112
117
  }
113
118
  safeStringify(value) {
@@ -163,20 +168,19 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
163
168
  const extra = {
164
169
  ...(params.extra || {})
165
170
  };
166
- const logger = this.store.scanOrderLogger;
167
- if (!logger) {
168
- if ((params.level || 'info') === 'error') {
169
- console.error('[VenueBooking][log-fallback]', params.title, {
170
- payload,
171
- extra
172
- });
173
- } else {}
174
- return;
175
- }
176
- await logger.addLog({
177
- ...params,
178
- payload,
179
- extra
171
+ (0, _hostLogger.writeHostLog)(this.core, {
172
+ type: params.level || 'info',
173
+ title: params.title,
174
+ ...(params.timestamp ? {
175
+ date: params.timestamp
176
+ } : {}),
177
+ metadata: {
178
+ module: 'venueBooking',
179
+ action: params.payload?.method || 'addLog',
180
+ payload,
181
+ extra,
182
+ context: this.getLoggerContext()
183
+ }
180
184
  });
181
185
  }
182
186
  logMethodStart(method, payload = {}) {
@@ -223,12 +227,10 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
223
227
  super(name, version);
224
228
  }
225
229
  getRegisteredModuleNames() {
226
- return ['scanOrderLogger', 'products', 'order', 'salesSummary', 'venueProducts', 'addonProducts', 'date', 'schedule', 'quotation', 'openData'];
230
+ return ['products', 'order', 'salesSummary', 'venueProducts', 'addonProducts', 'date', 'schedule', 'quotation', 'openData'];
227
231
  }
228
232
  createSubModule(moduleName) {
229
233
  switch (moduleName) {
230
- case 'scanOrderLogger':
231
- return (0, _types2.createModule)('scanOrderLogger', this.name);
232
234
  case 'venueProducts':
233
235
  return new _ProductList.ProductList(`${this.name}_venueProducts`);
234
236
  case 'addonProducts':
@@ -323,9 +325,8 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
323
325
  useCache: true
324
326
  });
325
327
  } catch (error) {
326
- console.error('[VenueBooking] 预加载 holder 表单失败', {
327
- formId,
328
- error
328
+ this.logMethodError('preloadHolderForms', error, {
329
+ formId
329
330
  });
330
331
  }
331
332
  }
@@ -421,6 +422,9 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
421
422
  }
422
423
  }
423
424
  async initialize(core, options = {}) {
425
+ this.core = core;
426
+ this.otherParams = options.otherParams || {};
427
+ this.cacheId = this.otherParams.cacheId;
424
428
  this.logMethodStart('initialize');
425
429
  this.store = {
426
430
  ...this.store,
@@ -443,8 +447,6 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
443
447
  this.store.slotConfig = {
444
448
  ...this.baseSlotConfig
445
449
  };
446
- this.otherParams = options.otherParams || {};
447
- this.cacheId = this.otherParams?.cacheId;
448
450
  this.itemRuleRuntimeConfig = this.otherParams?.venueBookingItemRule || this.otherParams?.itemRule || {};
449
451
  this.itemRuleConfigs = [];
450
452
  this.itemRuleConfigsPromise = null;
@@ -455,18 +457,9 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
455
457
  failures: []
456
458
  };
457
459
  await super.initialize(core, options);
458
- if (this.store.scanOrderLogger) {
459
- this.store.scanOrderLogger.setProvider(this.otherParams?.loggerProvider || 'feishu');
460
- this.store.scanOrderLogger.setProviderConfig(this.otherParams?.loggerConfig || {
461
- feishu: {
462
- webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/8f069b14-9d39-4728-8f78-b56f393bfde8',
463
- errorHook: 'https://open.feishu.cn/open-apis/bot/v2/hook/bdefae5e-f233-4705-8688-946887d9543d'
464
- }
465
- });
466
- this.store.scanOrderLogger.setContext(this.getLoggerContext());
467
- }
468
- // 注册基础模块(order, salesSummary, products, logger)
469
- const baseModules = ['scanOrderLogger', 'products', 'order', 'salesSummary'];
460
+
461
+ // 注册基础业务模块;日志统一使用 app 插件提供的宿主 logger。
462
+ const baseModules = ['products', 'order', 'salesSummary'];
470
463
  baseModules.forEach(step => {
471
464
  const targetModule = (0, _types2.createModule)(step, this.name);
472
465
  if (targetModule) {
@@ -474,13 +467,6 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
474
467
  const initialState = step === 'salesSummary' ? {
475
468
  summary: this.store.order?.getTempOrder()?.summary || (0, _utils.createEmptySummary)()
476
469
  } : {};
477
- const loggerProvider = this.otherParams?.loggerProvider || 'feishu';
478
- const loggerConfig = this.otherParams?.loggerConfig || {
479
- // feishu: {
480
- // webhook: 'https://open.feishu.cn/open-apis/bot/v2/hook/8f069b14-9d39-4728-8f78-b56f393bfde8',
481
- // errorHook: 'https://open.feishu.cn/open-apis/bot/v2/hook/bdefae5e-f233-4705-8688-946887d9543d',
482
- // },
483
- };
484
470
  this.core.registerModule(targetModule, {
485
471
  initialState,
486
472
  otherParams: {
@@ -488,10 +474,7 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
488
474
  fatherModule: this.name,
489
475
  openCache: this.otherParams?.cacheId ? true : false,
490
476
  cacheId: this.otherParams?.cacheId,
491
- salesSummaryModuleName: `${this.name}_salesSummary`,
492
- provider: loggerProvider,
493
- providerConfig: loggerConfig,
494
- context: this.getLoggerContext()
477
+ salesSummaryModuleName: `${this.name}_salesSummary`
495
478
  }
496
479
  });
497
480
  } else {
@@ -610,7 +593,6 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
610
593
  } catch (error) {
611
594
  this.store.status = 'error';
612
595
  this.store.error = error instanceof Error ? error.message : '初始化失败';
613
- console.error('[VenueBooking] 初始化失败', error);
614
596
  this.logMethodError('initialize', error, {
615
597
  status: this.store.status
616
598
  });
@@ -690,6 +672,15 @@ class VenueBookingImpl extends _BaseSales.BaseSalesImpl {
690
672
  const walletIds = this.smartPricingCustomerId === null ? [] : orderWalletIds?.length ? orderWalletIds : fallbackWalletIds;
691
673
  return {
692
674
  evaluator: this.core?.context?.dataVariantEvaluator,
675
+ reportWarning: title => {
676
+ void this.addVenueBookingLog({
677
+ level: 'warning',
678
+ title,
679
+ payload: {
680
+ method: 'smartPricing'
681
+ }
682
+ });
683
+ },
693
684
  scheduleList: this.store.schedule?.getScheduleList?.() || [],
694
685
  menuList: this.otherParams?.menuList || this.otherParams?.openData?.menuList || this.core?.context?.menuList || [],
695
686
  customerId: this.resolveCustomerIdForSmartPricing(),
@@ -133,6 +133,7 @@ export interface VenueBookingState {
133
133
  products?: ProductList;
134
134
  order?: OrderModule;
135
135
  salesSummary?: SalesSummaryModule;
136
+ /** @deprecated Retained for compatibility; solution logs use app.getApp().logger. */
136
137
  scanOrderLogger?: ScanOrderLoggerModule;
137
138
  venueProducts?: ProductList;
138
139
  addonProducts?: ProductList;
@@ -149,6 +150,7 @@ export interface VenueBookingState {
149
150
  };
150
151
  holder?: HolderModule;
151
152
  }
153
+ /** @deprecated Configure the host app logger; VenueBooking no longer selects a provider. */
152
154
  export interface VenueBookingLoggerRuntimeConfig {
153
155
  provider?: ScanOrderLoggerProviderType;
154
156
  providerConfig?: ScanOrderLoggerProviderConfig;
@@ -22,4 +22,6 @@ const DEFAULT_SLOT_CONFIG = exports.DEFAULT_SLOT_CONFIG = {
22
22
 
23
23
  // ─── 时段选择 & 合并 ───
24
24
 
25
- // ─── Store 状态 ───
25
+ // ─── Store 状态 ───
26
+
27
+ /** @deprecated Configure the host app logger; VenueBooking no longer selects a provider. */
@@ -16,6 +16,7 @@ export interface VenueBookingSmartPricingContext {
16
16
  orderType?: string;
17
17
  strategy_context?: Record<string, any>;
18
18
  strategyConfigs?: StrategyConfig[];
19
+ reportWarning?: (message: string) => void;
19
20
  }
20
21
  /** 从商品上读取展示/算价用的 price 字段 */
21
22
  export declare function extractProductPrice(product: DataVariantProduct): string | null;
@@ -49,7 +49,12 @@ function buildDataVariantBusinessData(products, context, scheduleDateTime) {
49
49
  function formatProductsWithDataVariant(products, context, scheduleDateTime) {
50
50
  const evaluator = context.evaluator;
51
51
  if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
52
- console.warn('[VenueBooking][smartPricing] dataVariantEvaluator 未注入,跳过智能定价格式化');
52
+ const message = '[VenueBooking][smartPricing] dataVariantEvaluator 未注入,跳过智能定价格式化';
53
+ try {
54
+ if (context.reportWarning) context.reportWarning(message);else console.warn(message);
55
+ } catch {
56
+ console.warn(message);
57
+ }
53
58
  return products;
54
59
  }
55
60
 
@@ -0,0 +1,10 @@
1
+ import type { LogConsoleType } from '../plugins/app-types/logger';
2
+ import type { PisellCore } from '../types';
3
+ export interface HostLogItem {
4
+ type: LogConsoleType;
5
+ title: string;
6
+ date?: string;
7
+ metadata?: Record<string, any>;
8
+ }
9
+ /** Use the same host logger as Order, without letting diagnostics interrupt sales. */
10
+ export declare function writeHostLog(core: PisellCore | undefined, log: HostLogItem): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.writeHostLog = writeHostLog;
7
+ /** Use the same host logger as Order, without letting diagnostics interrupt sales. */
8
+ function writeHostLog(core, log) {
9
+ const fallback = () => {
10
+ const method = log.type === 'warning' ? 'warn' : log.type;
11
+ };
12
+ try {
13
+ const logger = core?.getPlugin('app')?.getApp?.()?.logger;
14
+ if (typeof logger?.addLog !== 'function') {
15
+ fallback();
16
+ return;
17
+ }
18
+ const result = logger.addLog(log);
19
+ if (result && typeof result.then === 'function') {
20
+ void Promise.resolve(result).catch(fallback);
21
+ }
22
+ } catch {
23
+ fallback();
24
+ }
25
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.10.80",
4
+ "version": "0.10.82",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",