@pisell/pisellos 2.2.189 → 2.2.191

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 (65) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  3. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -7
  4. package/dist/modules/Cart/utils/cartProduct.js +13 -2
  5. package/dist/modules/Order/index.d.ts +1 -3
  6. package/dist/modules/Order/index.js +88 -114
  7. package/dist/modules/Order/types.d.ts +10 -6
  8. package/dist/modules/Order/utils.d.ts +9 -2
  9. package/dist/modules/Order/utils.js +36 -13
  10. package/dist/modules/SalesSummary/types.d.ts +3 -1
  11. package/dist/modules/SalesSummary/utils.js +7 -3
  12. package/dist/server/modules/order/index.d.ts +126 -6
  13. package/dist/server/modules/order/index.js +1204 -285
  14. package/dist/server/modules/order/types.d.ts +0 -2
  15. package/dist/server/modules/products/index.d.ts +90 -6
  16. package/dist/server/modules/products/index.js +1017 -361
  17. package/dist/solution/BaseSales/index.js +54 -39
  18. package/dist/solution/BaseSales/types.d.ts +8 -5
  19. package/dist/solution/BaseSales/types.js +2 -3
  20. package/dist/solution/BaseSales/utils/cartPromotion.js +7 -7
  21. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  22. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +29 -14
  23. package/dist/solution/BaseSales/utils.d.ts +1 -1
  24. package/dist/solution/BaseSales/utils.js +22 -19
  25. package/dist/solution/BookingByStep/index.d.ts +1 -1
  26. package/dist/solution/ScanOrder/index.js +7 -5
  27. package/dist/solution/ScanOrder/types.d.ts +8 -5
  28. package/dist/solution/ScanOrder/types.js +2 -3
  29. package/dist/solution/ScanOrder/utils.d.ts +1 -1
  30. package/dist/solution/ScanOrder/utils.js +26 -23
  31. package/dist/solution/VenueBooking/index.js +5 -3
  32. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  33. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  34. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  35. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  36. package/lib/modules/Cart/utils/cartProduct.js +9 -2
  37. package/lib/modules/Order/index.d.ts +1 -3
  38. package/lib/modules/Order/index.js +50 -63
  39. package/lib/modules/Order/types.d.ts +10 -6
  40. package/lib/modules/Order/utils.d.ts +9 -2
  41. package/lib/modules/Order/utils.js +41 -10
  42. package/lib/modules/SalesSummary/types.d.ts +3 -1
  43. package/lib/modules/SalesSummary/utils.js +5 -3
  44. package/lib/server/modules/order/index.d.ts +126 -6
  45. package/lib/server/modules/order/index.js +722 -42
  46. package/lib/server/modules/order/types.d.ts +0 -2
  47. package/lib/server/modules/products/index.d.ts +90 -6
  48. package/lib/server/modules/products/index.js +492 -30
  49. package/lib/solution/BaseSales/index.js +26 -8
  50. package/lib/solution/BaseSales/types.d.ts +8 -5
  51. package/lib/solution/BaseSales/utils/cartPromotion.js +6 -6
  52. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  53. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +32 -16
  54. package/lib/solution/BaseSales/utils.d.ts +1 -1
  55. package/lib/solution/BaseSales/utils.js +11 -7
  56. package/lib/solution/BookingByStep/index.d.ts +1 -1
  57. package/lib/solution/ScanOrder/index.js +4 -4
  58. package/lib/solution/ScanOrder/types.d.ts +8 -5
  59. package/lib/solution/ScanOrder/utils.d.ts +1 -1
  60. package/lib/solution/ScanOrder/utils.js +12 -8
  61. package/lib/solution/VenueBooking/index.js +2 -2
  62. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  63. package/package.json +1 -1
  64. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  65. package/lib/solution/Checkout/appointmentDemo.json +0 -1
@@ -2,6 +2,44 @@ import { Module, ModuleOptions, PisellCore } from '../../../types';
2
2
  import { BaseModule } from '../../../modules/BaseModule';
3
3
  import type { RouteDefinition } from '../../types';
4
4
  import { OrderData, OrderId } from './types';
5
+ /** 订单模块流程调试日志条目 */
6
+ interface OrderFlowLogEntry {
7
+ ts: string;
8
+ step: string;
9
+ metadata?: Record<string, unknown>;
10
+ }
11
+ /** 单笔订单 SQLite 写入记录 */
12
+ interface OrderWriteStatEntry {
13
+ ts: string;
14
+ writeSeq: number;
15
+ source: string;
16
+ writeMethod: string;
17
+ orderId: OrderId | null;
18
+ storageKey: string;
19
+ mergeAction?: 'insert' | 'update' | 'snapshot' | 'singleUpdate';
20
+ }
21
+ declare global {
22
+ interface Window {
23
+ /** 订单模块流程调试日志,可在 DevTools 直接查看 */
24
+ __orderModuleFlowLogs?: OrderFlowLogEntry[];
25
+ /** 按 storageKey 聚合的 SQLite 写入次数,便于排查重复写 */
26
+ __orderModuleWriteStats?: Record<string, OrderWriteStatEntry[]>;
27
+ /** 清空订单流程调试日志 */
28
+ clearOrderModuleFlowLogs?: () => void;
29
+ /** 导出订单流程调试日志 JSON 字符串 */
30
+ exportOrderModuleFlowLogs?: () => string;
31
+ /** 导出按订单聚合的写入统计 */
32
+ exportOrderModuleWriteStats?: () => string;
33
+ /** 汇总写入次数 Top N(默认 20) */
34
+ summarizeOrderModuleWrites?: (topN?: number) => Array<{
35
+ storageKey: string;
36
+ orderId: OrderId | null;
37
+ writeCount: number;
38
+ sources: string[];
39
+ lastWriteAt: string;
40
+ }>;
41
+ }
42
+ }
5
43
  /**
6
44
  * Order 模块 - 基础框架
7
45
  */
@@ -19,6 +57,12 @@ export declare class OrderModule extends BaseModule implements Module {
19
57
  private logger;
20
58
  private storage;
21
59
  private orderSQLiteSaveQueue;
60
+ /** 全局递增的 SQLite 写入序号,便于日志关联同一次操作 */
61
+ private orderFlowWriteSeq;
62
+ /** 按 storageKey 记录最近一次 SQLite 写入来源与时间,用于去重 */
63
+ private recentSqliteWriteByStorageKey;
64
+ /** 最近一次 SSE 全量拉取完成时间 */
65
+ private lastServerFullFetchAtMs;
22
66
  constructor(name?: string, version?: string);
23
67
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
24
68
  /**
@@ -33,6 +77,60 @@ export declare class OrderModule extends BaseModule implements Module {
33
77
  * @param metadata 日志元数据
34
78
  */
35
79
  private logError;
80
+ /**
81
+ * 初始化 window 上的订单流程调试日志数组及辅助方法。
82
+ *
83
+ * @example
84
+ * window.clearOrderModuleFlowLogs()
85
+ * // 操作完成后:
86
+ * copy(window.exportOrderModuleFlowLogs?.() || '[]')
87
+ */
88
+ private initOrderFlowLogs;
89
+ /**
90
+ * 写入 window 订单流程调试日志。
91
+ *
92
+ * @example
93
+ * this.pushOrderFlowLog('mergeOrdersToStore.start', { count: 3 })
94
+ */
95
+ private pushOrderFlowLog;
96
+ /** 当前内存 store 快照信息,供流程日志使用 */
97
+ private getOrderStoreSnapshot;
98
+ /**
99
+ * 记录一次 SQLite 写入到 window 统计,用于排查同一订单被多次写入的原因。
100
+ *
101
+ * @example
102
+ * this.trackOrderWrite('upsertOrdersFromRemote', 'bulkUpdate', orders, 'insert')
103
+ */
104
+ private trackOrderWrite;
105
+ /**
106
+ * 记录订单最近一次 SQLite 写入,供 pubsub 回声去重使用。
107
+ *
108
+ * @example
109
+ * this.recordRecentSqliteWrite('upsertOrdersFromRemote', orders)
110
+ */
111
+ private recordRecentSqliteWrite;
112
+ /**
113
+ * 过滤 pubsub 触发的冗余 SQLite patch(业务 API 刚写入过的 update 回声)。
114
+ *
115
+ * @example
116
+ * const { toWrite, skipped } = this.filterRedundantPatchOrders('pubsub.bodyUpsert', orders, mergeActions)
117
+ */
118
+ private filterRedundantPatchOrders;
119
+ /**
120
+ * 过滤 pubsub HTTP 增量拉取 ids:本地刚由业务 API 写入的单可跳过 HTTP。
121
+ *
122
+ * @example
123
+ * const ids = this.filterRedundantHttpRefreshIds([99331, 99332])
124
+ */
125
+ private filterRedundantHttpRefreshIds;
126
+ /**
127
+ * 解析 pubsub 消息会走哪条同步分支,便于对照为何触发 HTTP 重拉或 body 直写。
128
+ *
129
+ * @example
130
+ * this.resolveSyncMessageRoute(msg)
131
+ * // => { route: 'httpRefresh.batchIds', ... }
132
+ */
133
+ private resolveSyncMessageRoute;
36
134
  private getOrderSyncThrottleMs;
37
135
  preload(): Promise<void>;
38
136
  getOrders(): OrderData[];
@@ -120,6 +218,14 @@ export declare class OrderModule extends BaseModule implements Module {
120
218
  private normalizeOrderSyncPayload;
121
219
  private uniqueOrderIds;
122
220
  private getIdKey;
221
+ /**
222
+ * 解析订单 SQLite 主键,规则与宿主 OrderDataSource.getOrderStorageKey 一致。
223
+ *
224
+ * @example
225
+ * const key = this.getOrderStorageKey({ order_id: 1001, external_sale_number: 'S-1001' })
226
+ * // => 'S-1001'
227
+ */
228
+ private getOrderStorageKey;
123
229
  /**
124
230
  * 当前订单拉取窗口:
125
231
  * - 优先使用 createdAtQuery.sales_time_between(已按营业日边界初始化)
@@ -132,22 +238,35 @@ export declare class OrderModule extends BaseModule implements Module {
132
238
  private setStorageItem;
133
239
  private loadOrdersFromSQLite;
134
240
  /**
135
- * 串行执行订单 SQLite 保存任务,保证 clear + bulkAdd 组合不会被其它订单保存插入。
241
+ * 串行执行订单 SQLite 写入任务,避免快照替换与增量 upsert 并发交错。
136
242
  *
137
243
  * @example
138
244
  * await this.runInOrderSQLiteSaveQueue(async () => {
139
- * await this.dbManager.clear(INDEXDB_STORE_NAME)
140
- * await this.dbManager.bulkAdd(INDEXDB_STORE_NAME, orders)
245
+ * await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, orders)
141
246
  * })
142
247
  */
143
248
  private runInOrderSQLiteSaveQueue;
144
249
  /**
145
- * 保存订单列表到 SQLite,内部会先清空 orders 表再批量写入当前快照。
250
+ * 批量增量 upsert 订单到 SQLite,不清空表;用于 pubsub / HTTP 增量合并。
251
+ *
252
+ * @example
253
+ * await this.patchOrdersInSQLite(freshOrders)
254
+ */
255
+ private patchOrdersInSQLite;
256
+ /**
257
+ * 单条 upsert 订单到 SQLite;用于 overwriteExistingOrder 等单条覆盖场景。
258
+ *
259
+ * @example
260
+ * await this.updateOrderInSQLite(freshOrder)
261
+ */
262
+ private updateOrderInSQLite;
263
+ /**
264
+ * 全量快照替换 orders 表(clear + bulkAdd),用于 SSE 全量拉取与营业日窗口裁剪。
146
265
  *
147
266
  * @example
148
- * await this.saveOrdersToSQLite(this.store.list)
267
+ * await this.replaceOrdersSnapshotInSQLite(orderList)
149
268
  */
150
- private saveOrdersToSQLite;
269
+ private replaceOrdersSnapshotInSQLite;
151
270
  /**
152
271
  * 清空订单模块的内存数据和本地 SQLite 订单表。
153
272
  *
@@ -156,3 +275,4 @@ export declare class OrderModule extends BaseModule implements Module {
156
275
  */
157
276
  clear(): Promise<void>;
158
277
  }
278
+ export {};