@pisell/pisellos 2.3.105 → 2.3.107

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 (78) hide show
  1. package/dist/modules/Discount/index.js +4 -1
  2. package/dist/modules/Discount/types.d.ts +10 -0
  3. package/dist/modules/OpenData/index.d.ts +15 -2
  4. package/dist/modules/OpenData/index.js +307 -19
  5. package/dist/modules/OpenData/types.d.ts +55 -0
  6. package/dist/modules/OpenData/types.js +7 -1
  7. package/dist/modules/OpenData/utils.d.ts +21 -1
  8. package/dist/modules/OpenData/utils.js +138 -0
  9. package/dist/modules/Order/index.d.ts +3 -1
  10. package/dist/modules/Order/index.js +89 -16
  11. package/dist/modules/Order/types.d.ts +13 -0
  12. package/dist/modules/Order/utils.d.ts +4 -1
  13. package/dist/modules/Order/utils.js +57 -3
  14. package/dist/modules/ResourcePlanner/planner.d.ts +2 -2
  15. package/dist/modules/ResourcePlanner/planner.js +172 -49
  16. package/dist/modules/ResourcePlanner/types.d.ts +19 -0
  17. package/dist/modules/Rules/index.js +1 -1
  18. package/dist/plugins/request.d.ts +2 -1
  19. package/dist/plugins/request.js +4 -2
  20. package/dist/server/index.d.ts +15 -0
  21. package/dist/server/index.js +1734 -1285
  22. package/dist/server/modules/order/types.d.ts +50 -0
  23. package/dist/server/modules/order/types.js +2 -0
  24. package/dist/server/utils/small-ticket.d.ts +4 -1
  25. package/dist/server/utils/small-ticket.js +461 -96
  26. package/dist/solution/BaseSales/index.d.ts +5 -1
  27. package/dist/solution/BaseSales/index.js +120 -45
  28. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
  29. package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  30. package/dist/solution/BookingByStep/index.d.ts +1 -1
  31. package/dist/solution/BookingTicket/index.d.ts +8 -3
  32. package/dist/solution/BookingTicket/index.js +558 -443
  33. package/dist/solution/Sales/index.d.ts +16 -1
  34. package/dist/solution/Sales/index.js +338 -63
  35. package/dist/solution/Sales/types.d.ts +10 -0
  36. package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
  37. package/dist/solution/UnifiedBookingSales/index.js +614 -462
  38. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -1
  39. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  40. package/lib/modules/Discount/index.js +4 -1
  41. package/lib/modules/Discount/types.d.ts +10 -0
  42. package/lib/modules/OpenData/index.d.ts +15 -2
  43. package/lib/modules/OpenData/index.js +230 -3
  44. package/lib/modules/OpenData/types.d.ts +55 -0
  45. package/lib/modules/OpenData/types.js +9 -1
  46. package/lib/modules/OpenData/utils.d.ts +21 -1
  47. package/lib/modules/OpenData/utils.js +126 -0
  48. package/lib/modules/Order/index.d.ts +3 -1
  49. package/lib/modules/Order/index.js +69 -1
  50. package/lib/modules/Order/types.d.ts +13 -0
  51. package/lib/modules/Order/utils.d.ts +4 -1
  52. package/lib/modules/Order/utils.js +58 -1
  53. package/lib/modules/ResourcePlanner/planner.d.ts +2 -2
  54. package/lib/modules/ResourcePlanner/planner.js +141 -35
  55. package/lib/modules/ResourcePlanner/types.d.ts +19 -0
  56. package/lib/modules/Rules/index.js +1 -1
  57. package/lib/plugins/request.d.ts +2 -1
  58. package/lib/plugins/request.js +3 -2
  59. package/lib/server/index.d.ts +15 -0
  60. package/lib/server/index.js +455 -105
  61. package/lib/server/modules/order/types.d.ts +50 -0
  62. package/lib/server/modules/order/types.js +1 -0
  63. package/lib/server/utils/small-ticket.d.ts +4 -1
  64. package/lib/server/utils/small-ticket.js +427 -72
  65. package/lib/solution/BaseSales/index.d.ts +5 -1
  66. package/lib/solution/BaseSales/index.js +84 -7
  67. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
  68. package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  69. package/lib/solution/BookingByStep/index.d.ts +1 -1
  70. package/lib/solution/BookingTicket/index.d.ts +8 -3
  71. package/lib/solution/BookingTicket/index.js +60 -15
  72. package/lib/solution/Sales/index.d.ts +16 -1
  73. package/lib/solution/Sales/index.js +168 -1
  74. package/lib/solution/Sales/types.d.ts +10 -0
  75. package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
  76. package/lib/solution/UnifiedBookingSales/index.js +128 -35
  77. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -1
  78. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import type { OpenDataConfig } from '../../modules/OpenData';
1
+ import type { InvoiceLayoutConfig, InvoiceTemplateSettings, OpenDataConfig } from '../../modules/OpenData';
2
2
  import type { ProductListLoadProductsParams, ProductListStoreQueryParams } from '../../modules/ProductList';
3
3
  import type { ProductData } from '../../modules/Product/types';
4
4
  import type { LoadScheduleAvailableDateParams } from '../../modules/Schedule/types';
@@ -217,7 +217,13 @@ export interface UnifiedBookingSalesDiscountResult {
217
217
  }
218
218
  export interface UnifiedBookingSalesApi {
219
219
  loadOpenData: (params: UnifiedBookingSalesLoadOpenDataParams) => Promise<OpenDataConfig>;
220
+ /** Returns the latest OpenData payload cached by this solution instance. */
220
221
  getOpenData: () => Promise<OpenDataConfig | null>;
222
+ /** Returns the normalized Documents Invoice layout for the active target. */
223
+ getInvoiceLayoutConfig: () => Promise<InvoiceLayoutConfig>;
224
+ /** Returns the Native Invoice template settings for the active target. */
225
+ getInvoiceTemplateSettings: () => Promise<InvoiceTemplateSettings>;
226
+ /** Date-first calendar availability backed by ScheduleModule. */
221
227
  loadScheduleAvailableDate: (params: LoadScheduleAvailableDateParams) => Promise<unknown>;
222
228
  loadProductsByScheduleDate: (params: UnifiedBookingSalesLoadProductsByScheduleDateParams) => Promise<unknown[]>;
223
229
  queryProducts: (params?: ProductListStoreQueryParams) => Promise<ProductData[]>;
@@ -1,46 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
7
- enumerable: true,
8
- get: function () {
9
- return _examples.BUY_X_GET_Y_FREE_STRATEGY;
10
- }
11
- });
12
- Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
13
- enumerable: true,
14
- get: function () {
15
- return _examples.ITEM_REWARD_STRATEGY;
16
- }
17
- });
18
- Object.defineProperty(exports, "PromotionAdapter", {
19
- enumerable: true,
20
- get: function () {
21
- return _adapter.PromotionAdapter;
22
- }
23
- });
24
- Object.defineProperty(exports, "PromotionEvaluator", {
25
- enumerable: true,
26
- get: function () {
27
- return _evaluator.PromotionEvaluator;
28
- }
29
- });
30
- Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
31
- enumerable: true,
32
- get: function () {
33
- return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
34
- }
35
- });
36
- Object.defineProperty(exports, "default", {
37
- enumerable: true,
38
- get: function () {
39
- return _adapter.default;
40
- }
41
- });
42
- var _evaluator = require("./evaluator");
43
- var _adapter = _interopRequireWildcard(require("./adapter"));
44
- var _examples = require("./examples");
45
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
46
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
1
+ "use strict";
@@ -95,7 +95,10 @@ class DiscountModule extends _BaseModule.BaseModule {
95
95
  return {
96
96
  discountList: goodPassList,
97
97
  availableWalletIds,
98
- virtualCurrencyList
98
+ virtualCurrencyList,
99
+ availableWalletPassList: availableWalletPassList.map(item => ({
100
+ ...(item || {})
101
+ }))
99
102
  };
100
103
  }
101
104
  normalizeVirtualCurrencyList(value) {
@@ -68,10 +68,20 @@ export interface DiscountWithReason {
68
68
  discountList: Discount[];
69
69
  unavailableReasonKey: DiscountFilterRejectKey | null;
70
70
  }
71
+ export interface WalletPassPrepareConfigItem {
72
+ id?: number | string | null;
73
+ tag?: string | null;
74
+ product_id?: number | string | null;
75
+ product_name?: string | null;
76
+ par_value?: string | number | null;
77
+ used_par_value?: string | number | null;
78
+ [key: string]: any;
79
+ }
71
80
  export interface DiscountPrepareConfigResult {
72
81
  discountList: Discount[];
73
82
  availableWalletIds: number[];
74
83
  virtualCurrencyList?: VirtualCurrencyAsset[];
84
+ availableWalletPassList?: WalletPassPrepareConfigItem[];
75
85
  }
76
86
  export interface VirtualCurrencyAsset extends Record<string, any> {
77
87
  id: number;
@@ -1,9 +1,9 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
3
  import type { ScheduleModule } from '../Schedule';
4
- import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult } from './types';
4
+ import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
5
5
  export * from './types';
6
- export { computeAvailability } from './utils';
6
+ export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, resolveInvoiceReceiptLocales, } from './utils';
7
7
  export declare class OpenDataModule extends BaseModule implements Module {
8
8
  protected defaultName: string;
9
9
  protected defaultVersion: string;
@@ -15,6 +15,10 @@ export declare class OpenDataModule extends BaseModule implements Module {
15
15
  private openCache;
16
16
  private fatherModule;
17
17
  private otherParams;
18
+ private fetchRevision;
19
+ private invoiceTemplateCacheRevision;
20
+ private invoiceTemplateDocumentCache;
21
+ private invoiceTemplateDocumentInFlight;
18
22
  constructor(name?: string, version?: string);
19
23
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
20
24
  /**
@@ -24,8 +28,17 @@ export declare class OpenDataModule extends BaseModule implements Module {
24
28
  * openDataModule.updateOtherParams({ openCache: true, cacheId: 'cache-2' })
25
29
  */
26
30
  updateOtherParams(params: Record<string, any>): void;
31
+ private shouldSkipInvoiceTemplateDocument;
27
32
  fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
28
33
  getOpenData(): OpenDataConfig | null;
34
+ getInvoiceLayoutConfig(): InvoiceLayoutConfig;
35
+ getInvoiceTemplateSettings(): InvoiceTemplateSettings;
36
+ ensureInvoiceTemplateSettings(target: string): Promise<InvoiceTemplateSettings>;
37
+ private commitInvoiceTemplateSettings;
38
+ private resolveInvoiceTemplateSettings;
39
+ private buildInvoiceTemplateCacheKey;
40
+ private fetchInvoiceTemplateDocument;
41
+ private logInvoiceTemplateDocumentFallback;
29
42
  getLastFetchedAt(): number | null;
30
43
  /** 清除内存与 sessionStorage 镜像中的 OpenData,供宿主切店时调用。 */
31
44
  clearCache(): void;
@@ -5,7 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  OpenDataModule: true,
8
- computeAvailability: true
8
+ computeAvailability: true,
9
+ getDefaultInvoiceLayoutConfig: true,
10
+ getDefaultInvoiceTemplateSettings: true,
11
+ normalizeInvoiceLayoutConfig: true,
12
+ normalizeInvoiceLayoutFromTemplateSettings: true,
13
+ normalizeInvoiceTemplateSettings: true,
14
+ normalizeRawInvoiceTemplateSettings: true,
15
+ resolveInvoiceReceiptLocales: true
9
16
  };
10
17
  exports.OpenDataModule = void 0;
11
18
  Object.defineProperty(exports, "computeAvailability", {
@@ -14,6 +21,48 @@ Object.defineProperty(exports, "computeAvailability", {
14
21
  return _utils.computeAvailability;
15
22
  }
16
23
  });
24
+ Object.defineProperty(exports, "getDefaultInvoiceLayoutConfig", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _utils.getDefaultInvoiceLayoutConfig;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "getDefaultInvoiceTemplateSettings", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _utils.getDefaultInvoiceTemplateSettings;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "normalizeInvoiceLayoutConfig", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _utils.normalizeInvoiceLayoutConfig;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "normalizeInvoiceLayoutFromTemplateSettings", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _utils.normalizeInvoiceLayoutFromTemplateSettings;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "normalizeInvoiceTemplateSettings", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _utils.normalizeInvoiceTemplateSettings;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "normalizeRawInvoiceTemplateSettings", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _utils.normalizeRawInvoiceTemplateSettings;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "resolveInvoiceReceiptLocales", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _utils.resolveInvoiceReceiptLocales;
64
+ }
65
+ });
17
66
  var _BaseModule = require("../BaseModule");
18
67
  var _utils = require("./utils");
19
68
  var _types = require("./types");
@@ -28,6 +77,25 @@ Object.keys(_types).forEach(function (key) {
28
77
  }
29
78
  });
30
79
  });
80
+ function isRecord(value) {
81
+ return !!value && typeof value === 'object' && !Array.isArray(value);
82
+ }
83
+ function resolveInvoiceDocumentId(value) {
84
+ if (typeof value === 'number') {
85
+ return Number.isSafeInteger(value) && value > 0 ? String(value) : null;
86
+ }
87
+ if (typeof value !== 'string') return null;
88
+ const normalized = value.trim();
89
+ if (!/^\d+$/.test(normalized)) return null;
90
+ const numericId = Number(normalized);
91
+ return Number.isSafeInteger(numericId) && numericId > 0 ? String(numericId) : null;
92
+ }
93
+ function isLegacyInvoiceTemplate(value) {
94
+ if (typeof value !== 'string' || value.trim().length === 0) return false;
95
+ const normalized = value.trim();
96
+ const numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
97
+ return !numericLike.test(normalized);
98
+ }
31
99
  class OpenDataModule extends _BaseModule.BaseModule {
32
100
  defaultName = 'openData';
33
101
  defaultVersion = '1.0.0';
@@ -39,6 +107,10 @@ class OpenDataModule extends _BaseModule.BaseModule {
39
107
  openCache = false;
40
108
  fatherModule;
41
109
  otherParams = {};
110
+ fetchRevision = 0;
111
+ invoiceTemplateCacheRevision = 0;
112
+ invoiceTemplateDocumentCache = new Map();
113
+ invoiceTemplateDocumentInFlight = new Map();
42
114
  constructor(name, version) {
43
115
  super(name, version);
44
116
  }
@@ -47,6 +119,12 @@ class OpenDataModule extends _BaseModule.BaseModule {
47
119
  this.store = options.store;
48
120
  this.store.data = options.initialState?.data ?? null;
49
121
  this.store.lastFetchedAt = options.initialState?.lastFetchedAt ?? null;
122
+ // Document 解析结果只在当前模块实例内复用。页面刷新后即使恢复了原始
123
+ // OpenData,也必须重新查询一次 NocoBase,以取得当前模板内容。
124
+ this.store.invoiceTemplateSettings = null;
125
+ this.store.invoiceTemplateTarget = null;
126
+ this.store.invoiceTemplateDocumentId = null;
127
+ this.store.invoiceTemplateCacheKey = null;
50
128
  this.otherParams = options.otherParams || {};
51
129
  if (this.otherParams.cacheId) {
52
130
  this.openCache = this.otherParams.openCache ?? false;
@@ -74,7 +152,11 @@ class OpenDataModule extends _BaseModule.BaseModule {
74
152
  this.cacheId = this.otherParams.cacheId;
75
153
  this.fatherModule = this.otherParams.fatherModule;
76
154
  }
155
+ shouldSkipInvoiceTemplateDocument() {
156
+ return String(this.otherParams?.platform || '').trim().toLowerCase() === 'h5';
157
+ }
77
158
  async fetchOpenData(params) {
159
+ const fetchRevision = ++this.fetchRevision;
78
160
  const getData = this.appPlugin?.getData?.();
79
161
  const shopId = getData?.('shop_id');
80
162
  if (!shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
@@ -95,21 +177,166 @@ class OpenDataModule extends _BaseModule.BaseModule {
95
177
  throw new Error(response?.message || '获取 OpenData 配置失败');
96
178
  }
97
179
  const data = response?.data || {};
98
- this.store.data = data;
99
- this.store.lastFetchedAt = Date.now();
180
+ const resolvedInvoiceTemplate = await this.resolveInvoiceTemplateSettings(data, params.target);
181
+ // clearCache() 或后续请求发生后,旧响应不得复活已失效的 target 配置。
182
+ if (fetchRevision === this.fetchRevision) {
183
+ this.store.data = data;
184
+ this.store.lastFetchedAt = Date.now();
185
+ this.commitInvoiceTemplateSettings(params.target, resolvedInvoiceTemplate);
186
+ }
100
187
  return data;
101
188
  }
102
189
  getOpenData() {
103
190
  return this.store.data;
104
191
  }
192
+ getInvoiceLayoutConfig() {
193
+ return (0, _utils.normalizeInvoiceLayoutFromTemplateSettings)(this.getInvoiceTemplateSettings());
194
+ }
195
+ getInvoiceTemplateSettings() {
196
+ if (this.shouldSkipInvoiceTemplateDocument()) {
197
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
198
+ }
199
+ if (isRecord(this.store.invoiceTemplateSettings)) {
200
+ const documentId = resolveInvoiceDocumentId(this.store.data?.['documents.invoice_template']);
201
+ if (documentId) {
202
+ const target = this.store.invoiceTemplateTarget;
203
+ if (!target || this.store.invoiceTemplateCacheKey !== this.buildInvoiceTemplateCacheKey(target, documentId)) {
204
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
205
+ }
206
+ }
207
+ return (0, _utils.normalizeRawInvoiceTemplateSettings)(this.store.invoiceTemplateSettings);
208
+ }
209
+ if (isLegacyInvoiceTemplate(this.store.data?.['documents.invoice_template'])) {
210
+ return (0, _utils.normalizeInvoiceTemplateSettings)(this.store.data);
211
+ }
212
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
213
+ }
214
+ async ensureInvoiceTemplateSettings(target) {
215
+ const normalizedTarget = String(target || '').trim();
216
+ const config = this.store.data;
217
+ if (!normalizedTarget || !config) {
218
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
219
+ }
220
+ const fetchRevision = this.fetchRevision;
221
+ const resolved = await this.resolveInvoiceTemplateSettings(config, normalizedTarget);
222
+ if (fetchRevision !== this.fetchRevision || this.store.data !== config) {
223
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
224
+ }
225
+ this.commitInvoiceTemplateSettings(normalizedTarget, resolved);
226
+ return (0, _utils.normalizeRawInvoiceTemplateSettings)(resolved.settings);
227
+ }
228
+ commitInvoiceTemplateSettings(target, resolved) {
229
+ this.store.invoiceTemplateSettings = (0, _utils.normalizeRawInvoiceTemplateSettings)(resolved.settings);
230
+ this.store.invoiceTemplateTarget = target;
231
+ this.store.invoiceTemplateDocumentId = resolved.documentId;
232
+ this.store.invoiceTemplateCacheKey = resolved.cacheKey;
233
+ }
234
+ async resolveInvoiceTemplateSettings(config, target) {
235
+ if (this.shouldSkipInvoiceTemplateDocument()) {
236
+ return {
237
+ settings: (0, _utils.getDefaultInvoiceTemplateSettings)(),
238
+ documentId: null,
239
+ cacheKey: null
240
+ };
241
+ }
242
+ const rawTemplate = config['documents.invoice_template'];
243
+ const documentId = resolveInvoiceDocumentId(rawTemplate);
244
+ if (!documentId) {
245
+ return {
246
+ settings: isLegacyInvoiceTemplate(rawTemplate) ? (0, _utils.normalizeInvoiceTemplateSettings)(config) : (0, _utils.getDefaultInvoiceTemplateSettings)(),
247
+ documentId: null,
248
+ cacheKey: null
249
+ };
250
+ }
251
+ const cacheKey = this.buildInvoiceTemplateCacheKey(target, documentId);
252
+ if (this.store.invoiceTemplateTarget === target && this.store.invoiceTemplateDocumentId === documentId && this.store.invoiceTemplateCacheKey === cacheKey && isRecord(this.store.invoiceTemplateSettings)) {
253
+ return {
254
+ settings: (0, _utils.normalizeRawInvoiceTemplateSettings)(this.store.invoiceTemplateSettings),
255
+ documentId,
256
+ cacheKey
257
+ };
258
+ }
259
+ const cachedSettings = this.invoiceTemplateDocumentCache.get(cacheKey);
260
+ if (cachedSettings) {
261
+ return {
262
+ settings: (0, _utils.normalizeRawInvoiceTemplateSettings)(cachedSettings),
263
+ documentId,
264
+ cacheKey
265
+ };
266
+ }
267
+ let request = this.invoiceTemplateDocumentInFlight.get(cacheKey);
268
+ if (!request) {
269
+ const cacheRevision = this.invoiceTemplateCacheRevision;
270
+ request = this.fetchInvoiceTemplateDocument(documentId).catch(error => {
271
+ this.logInvoiceTemplateDocumentFallback(error, target, documentId);
272
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
273
+ }).then(settings => {
274
+ const normalized = (0, _utils.normalizeRawInvoiceTemplateSettings)(settings);
275
+ if (cacheRevision === this.invoiceTemplateCacheRevision) {
276
+ this.invoiceTemplateDocumentCache.set(cacheKey, normalized);
277
+ }
278
+ return normalized;
279
+ }).finally(() => {
280
+ if (this.invoiceTemplateDocumentInFlight.get(cacheKey) === request) {
281
+ this.invoiceTemplateDocumentInFlight.delete(cacheKey);
282
+ }
283
+ });
284
+ this.invoiceTemplateDocumentInFlight.set(cacheKey, request);
285
+ }
286
+ return {
287
+ settings: await request,
288
+ documentId,
289
+ cacheKey
290
+ };
291
+ }
292
+ buildInvoiceTemplateCacheKey(target, documentId) {
293
+ const getData = this.appPlugin?.getData?.();
294
+ return JSON.stringify([getData?.('tenant_id') ?? null, getData?.('shop_id') ?? null, target, documentId]);
295
+ }
296
+ async fetchInvoiceTemplateDocument(documentId) {
297
+ const response = await this.request.get(`/document:get?filterByTk=${encodeURIComponent(documentId)}`, {}, {
298
+ isNocobase: true,
299
+ prefix: false,
300
+ headers: {
301
+ 'x-data-source': 'pisell2'
302
+ },
303
+ customToast: () => {}
304
+ });
305
+ const document = response?.data;
306
+ if (!document || resolveInvoiceDocumentId(document.id) !== documentId) {
307
+ throw new Error(`Invoice Document ${documentId} 返回的 ID 不匹配`);
308
+ }
309
+ if (document.deleted_at !== null && document.deleted_at !== undefined) {
310
+ throw new Error(`Invoice Document ${documentId} 已被删除`);
311
+ }
312
+ if (!isRecord(document.data) || !isRecord(document.data.template_settings)) {
313
+ throw new Error(`Invoice Document ${documentId} 缺少 template_settings`);
314
+ }
315
+ return (0, _utils.normalizeRawInvoiceTemplateSettings)(document.data.template_settings);
316
+ }
317
+ logInvoiceTemplateDocumentFallback(error, target, documentId) {
318
+ console.warn('[OpenDataModule] Invoice Document 加载失败,使用 DEFAULT', {
319
+ target,
320
+ documentId,
321
+ message: error instanceof Error ? error.message : String(error)
322
+ });
323
+ }
105
324
  getLastFetchedAt() {
106
325
  return this.store.lastFetchedAt ?? null;
107
326
  }
108
327
 
109
328
  /** 清除内存与 sessionStorage 镜像中的 OpenData,供宿主切店时调用。 */
110
329
  clearCache() {
330
+ this.fetchRevision += 1;
331
+ this.invoiceTemplateCacheRevision += 1;
332
+ this.invoiceTemplateDocumentCache.clear();
333
+ this.invoiceTemplateDocumentInFlight.clear();
111
334
  this.store.data = null;
112
335
  this.store.lastFetchedAt = null;
336
+ this.store.invoiceTemplateSettings = null;
337
+ this.store.invoiceTemplateTarget = null;
338
+ this.store.invoiceTemplateDocumentId = null;
339
+ this.store.invoiceTemplateCacheKey = null;
113
340
  }
114
341
  checkAvailability(scheduleModule) {
115
342
  const scheduleList = scheduleModule ? scheduleModule?.getScheduleListByIds(this.store.data?.['availability.operating_hours'] || []) : undefined;
@@ -8,6 +8,49 @@ export interface MultiLangObject {
8
8
  original?: string;
9
9
  [key: string]: string | undefined;
10
10
  }
11
+ export declare const INVOICE_MODULE_KEYS: readonly ["reference", "brand", "custom_1", "order", "handover", "customer", "line_groups", "settlement", "custom_2", "payment", "card", "total_savings", "custom_3", "barcode"];
12
+ export type InvoiceModuleKey = (typeof INVOICE_MODULE_KEYS)[number];
13
+ /**
14
+ * Documents Registry 中的 Invoice 模块配置。
15
+ *
16
+ * 模块 key、显隐值及模块私有字段均由 Registry/Native 约定,OS 不做枚举收窄或改写。
17
+ */
18
+ export interface InvoiceTemplateModuleConfig {
19
+ key: string;
20
+ is_show?: unknown;
21
+ [key: string]: unknown;
22
+ }
23
+ export interface InvoiceModuleConfig extends InvoiceTemplateModuleConfig {
24
+ }
25
+ export interface InvoiceLayoutConfig {
26
+ locale?: string;
27
+ module: InvoiceModuleConfig[];
28
+ }
29
+ export interface InvoiceTemplateSettings {
30
+ template: string;
31
+ language: Record<string, number>;
32
+ modules: InvoiceTemplateModuleConfig[];
33
+ [key: string]: unknown;
34
+ }
35
+ export interface InvoiceDocumentResponse {
36
+ data?: {
37
+ id?: number | string;
38
+ deleted_at?: string | null;
39
+ data?: {
40
+ template_settings?: unknown;
41
+ };
42
+ };
43
+ }
44
+ export type RawInvoiceEditConfig = string | {
45
+ language?: unknown;
46
+ modules?: unknown;
47
+ [key: string]: unknown;
48
+ };
49
+ export type RawInvoiceLayoutConfig = string | {
50
+ locale?: unknown;
51
+ module?: unknown[];
52
+ [key: string]: unknown;
53
+ };
11
54
  export interface OpenDataConfig {
12
55
  'basic.enable'?: boolean;
13
56
  'basic.code'?: string | null;
@@ -45,11 +88,23 @@ export interface OpenDataConfig {
45
88
  label: string;
46
89
  value: number;
47
90
  }>;
91
+ 'documents.invoice_template'?: string | number;
92
+ 'documents.invoice_edit'?: RawInvoiceEditConfig;
93
+ /** @deprecated 仅保留旧调用方的类型兼容,Invoice 读取逻辑不再消费该字段。 */
94
+ 'documents.invoice'?: RawInvoiceLayoutConfig;
95
+ /** @deprecated Invoice 读取逻辑只消费扁平的 documents.invoice_* 字段。 */
96
+ documents?: {
97
+ invoice?: RawInvoiceLayoutConfig;
98
+ };
48
99
  [key: string]: any;
49
100
  }
50
101
  export interface OpenDataState {
51
102
  data: OpenDataConfig | null;
52
103
  lastFetchedAt: number | null;
104
+ invoiceTemplateSettings?: InvoiceTemplateSettings | null;
105
+ invoiceTemplateTarget?: string | null;
106
+ invoiceTemplateDocumentId?: string | null;
107
+ invoiceTemplateCacheKey?: string | null;
53
108
  }
54
109
  export interface OpenDataFetchParams {
55
110
  scope: string;
@@ -2,4 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ exports.INVOICE_MODULE_KEYS = void 0;
7
+ const INVOICE_MODULE_KEYS = exports.INVOICE_MODULE_KEYS = ['reference', 'brand', 'custom_1', 'order', 'handover', 'customer', 'line_groups', 'settlement', 'custom_2', 'payment', 'card', 'total_savings', 'custom_3', 'barcode'];
8
+
9
+ /**
10
+ * Documents Registry 中的 Invoice 模块配置。
11
+ *
12
+ * 模块 key、显隐值及模块私有字段均由 Registry/Native 约定,OS 不做枚举收窄或改写。
13
+ */
@@ -1,2 +1,22 @@
1
- import type { OpenDataAvailabilityResult, ComputeAvailabilityParams } from './types';
1
+ import type { OpenDataConfig, OpenDataAvailabilityResult, ComputeAvailabilityParams, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
2
+ export declare function getDefaultInvoiceLayoutConfig(): InvoiceLayoutConfig;
3
+ export declare function getDefaultInvoiceTemplateSettings(): InvoiceTemplateSettings;
4
+ /**
5
+ * 将非 DEFAULT Invoice 模板启用的语言转换为 small_ticket_data locale。
6
+ * cn_en 是中英组合打印模式,因此展开为 en 与 zh_CN 两份数据。
7
+ */
8
+ export declare function resolveInvoiceReceiptLocales(settings?: InvoiceTemplateSettings | null): string[];
9
+ /**
10
+ * 规范化已经提取出的公开 template_settings 值,供打印入口复用。
11
+ */
12
+ export declare function normalizeRawInvoiceTemplateSettings(value: unknown): InvoiceTemplateSettings;
13
+ /**
14
+ * 从 OpenData Documents section 的两个扁平字段中构造 Native Invoice 配置。
15
+ */
16
+ export declare function normalizeInvoiceTemplateSettings(config: OpenDataConfig | null | undefined): InvoiceTemplateSettings;
17
+ export declare function normalizeInvoiceLayoutFromTemplateSettings(settings: InvoiceTemplateSettings | null | undefined): InvoiceLayoutConfig;
18
+ /**
19
+ * 将 invoice_edit.modules 原样投影为 Web Invoice 使用的 module 字段。
20
+ */
21
+ export declare function normalizeInvoiceLayoutConfig(config: OpenDataConfig | null | undefined): InvoiceLayoutConfig;
2
22
  export declare function computeAvailability(params: ComputeAvailabilityParams): OpenDataAvailabilityResult;