@pisell/pisellos 0.10.96 → 0.10.98

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.
@@ -6,13 +6,6 @@ export * from './types';
6
6
  export * from './contactInfo';
7
7
  export * from './salesSettings';
8
8
  export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, resolveInvoiceReceiptLocales, } from './utils';
9
- interface InvoiceShopScope {
10
- shopId: string;
11
- tenantId: string;
12
- }
13
- interface CloudInvoiceScope extends InvoiceShopScope {
14
- assertCurrent(): void;
15
- }
16
9
  export declare class OpenDataModule extends BaseModule implements Module {
17
10
  protected defaultName: string;
18
11
  protected defaultVersion: string;
@@ -26,7 +19,6 @@ export declare class OpenDataModule extends BaseModule implements Module {
26
19
  private otherParams;
27
20
  private fetchRevision;
28
21
  private invoiceTemplateCacheRevision;
29
- private cloudInvoiceTemplates;
30
22
  private invoiceTemplateDocumentCache;
31
23
  private invoiceTemplateDocumentInFlight;
32
24
  constructor(name?: string, version?: string);
@@ -41,10 +33,8 @@ export declare class OpenDataModule extends BaseModule implements Module {
41
33
  private shouldSkipInvoiceTemplateDocument;
42
34
  fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
43
35
  private requestOpenData;
44
- /** Bind every stage of a cloud print to the same authenticated shop and cache generation. */
45
- captureCloudInvoiceScope(expectedShopId: string | number): CloudInvoiceScope;
46
- loadCloudInvoiceTemplate(target: string, scope: CloudInvoiceScope): Promise<InvoiceTemplateSettings>;
47
- private fetchCloudInvoiceTemplate;
36
+ /** Cloud orders must resolve their own channel's template before printing. */
37
+ loadCloudInvoiceTemplate(target: string): Promise<InvoiceTemplateSettings>;
48
38
  getOpenData(): OpenDataConfig | null;
49
39
  getInvoiceLayoutConfig(): InvoiceLayoutConfig;
50
40
  getInvoiceTemplateSettings(): InvoiceTemplateSettings;
@@ -42,14 +42,6 @@ function isLegacyInvoiceTemplate(value) {
42
42
  var numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
43
43
  return !numericLike.test(normalized);
44
44
  }
45
- function readInvoiceShopScope(app) {
46
- var _app$getData, _getData, _getData2;
47
- var getData = app === null || app === void 0 || (_app$getData = app.getData) === null || _app$getData === void 0 ? void 0 : _app$getData.call(app);
48
- return {
49
- shopId: String((_getData = getData === null || getData === void 0 ? void 0 : getData('shop_id')) !== null && _getData !== void 0 ? _getData : '').trim(),
50
- tenantId: String((_getData2 = getData === null || getData === void 0 ? void 0 : getData('tenant_id')) !== null && _getData2 !== void 0 ? _getData2 : '').trim()
51
- };
52
- }
53
45
  export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
54
46
  _inherits(OpenDataModule, _BaseModule);
55
47
  var _super = _createSuper(OpenDataModule);
@@ -69,9 +61,6 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
69
61
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
70
62
  _defineProperty(_assertThisInitialized(_this), "fetchRevision", 0);
71
63
  _defineProperty(_assertThisInitialized(_this), "invoiceTemplateCacheRevision", 0);
72
- // Cloud printing only caches successful resolutions. Regular sales screens
73
- // deliberately retain DEFAULT after a failed Document lookup.
74
- _defineProperty(_assertThisInitialized(_this), "cloudInvoiceTemplates", new Map());
75
64
  _defineProperty(_assertThisInitialized(_this), "invoiceTemplateDocumentCache", new Map());
76
65
  _defineProperty(_assertThisInitialized(_this), "invoiceTemplateDocumentInFlight", new Map());
77
66
  return _this;
@@ -160,7 +149,7 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
160
149
  case 0:
161
150
  fetchRevision = ++this.fetchRevision;
162
151
  _context2.next = 3;
163
- return this.requestOpenData(params, readInvoiceShopScope(this.appPlugin));
152
+ return this.requestOpenData(params);
164
153
  case 3:
165
154
  response = _context2.sent;
166
155
  if (!((response === null || response === void 0 ? void 0 : response.status) === false)) {
@@ -194,10 +183,14 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
194
183
  }()
195
184
  }, {
196
185
  key: "requestOpenData",
197
- value: function requestOpenData(params, scope) {
198
- var background = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
199
- if (!scope.shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
200
- return this.request.post("/open/my-pisell/".concat(encodeURIComponent(scope.shopId), "/setting"), {
186
+ value: function requestOpenData(params) {
187
+ var _this$appPlugin, _this$appPlugin$getDa;
188
+ var background = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
189
+ var getData = (_this$appPlugin = this.appPlugin) === null || _this$appPlugin === void 0 || (_this$appPlugin$getDa = _this$appPlugin.getData) === null || _this$appPlugin$getDa === void 0 ? void 0 : _this$appPlugin$getDa.call(_this$appPlugin);
190
+ var shopId = getData === null || getData === void 0 ? void 0 : getData('shop_id');
191
+ var tenantId = getData === null || getData === void 0 ? void 0 : getData('tenant_id');
192
+ if (!shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
193
+ return this.request.post("/open/my-pisell/".concat(encodeURIComponent(String(shopId)), "/setting"), {
201
194
  scope: params.scope,
202
195
  target: params.target,
203
196
  section_code: params.section_code
@@ -205,8 +198,8 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
205
198
  pisell2: true,
206
199
  isPisell2: true,
207
200
  prefix: false,
208
- headers: scope.tenantId ? {
209
- 'Tenant-Id': scope.tenantId
201
+ headers: tenantId ? {
202
+ 'Tenant-Id': String(tenantId)
210
203
  } : {}
211
204
  }, background ? {
212
205
  customToast: function customToast() {},
@@ -215,127 +208,61 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
215
208
  } : {}));
216
209
  }
217
210
 
218
- /** Bind every stage of a cloud print to the same authenticated shop and cache generation. */
219
- }, {
220
- key: "captureCloudInvoiceScope",
221
- value: function captureCloudInvoiceScope(expectedShopId) {
222
- var _this2 = this;
223
- var scope = readInvoiceShopScope(this.appPlugin);
224
- if (!scope.shopId || scope.shopId !== String(expectedShopId).trim()) {
225
- throw new Error('Cloud Invoice shop does not match the active shop');
226
- }
227
- var revision = this.invoiceTemplateCacheRevision;
228
- return _objectSpread(_objectSpread({}, scope), {}, {
229
- assertCurrent: function assertCurrent() {
230
- var current = readInvoiceShopScope(_this2.appPlugin);
231
- if (revision !== _this2.invoiceTemplateCacheRevision || current.shopId !== scope.shopId || current.tenantId !== scope.tenantId) {
232
- throw new Error('Cloud Invoice shop context changed');
233
- }
234
- }
235
- });
236
- }
211
+ /** Cloud orders must resolve their own channel's template before printing. */
237
212
  }, {
238
213
  key: "loadCloudInvoiceTemplate",
239
- value: function () {
240
- var _loadCloudInvoiceTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target, scope) {
241
- var key, existing, request, entry, settings;
214
+ value: (function () {
215
+ var _loadCloudInvoiceTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target) {
216
+ var response, raw, documentId;
242
217
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
243
218
  while (1) switch (_context3.prev = _context3.next) {
244
219
  case 0:
245
- scope.assertCurrent();
246
- key = JSON.stringify([scope.tenantId, scope.shopId, target]);
247
- existing = this.cloudInvoiceTemplates.get(key);
248
- if (!(existing && existing.expiresAt > Date.now())) {
249
- _context3.next = 5;
250
- break;
251
- }
252
- return _context3.abrupt("return", existing.request);
253
- case 5:
254
- request = this.fetchCloudInvoiceTemplate(target, scope);
255
- entry = {
256
- request: request,
257
- expiresAt: Infinity
258
- };
259
- this.cloudInvoiceTemplates.set(key, entry);
260
- _context3.prev = 8;
261
- _context3.next = 11;
262
- return request;
263
- case 11:
264
- settings = _context3.sent;
265
- scope.assertCurrent();
266
- entry.expiresAt = Date.now() + 5 * 60 * 1000;
267
- return _context3.abrupt("return", settings);
268
- case 17:
269
- _context3.prev = 17;
270
- _context3.t0 = _context3["catch"](8);
271
- if (this.cloudInvoiceTemplates.get(key) === entry) this.cloudInvoiceTemplates.delete(key);
272
- throw _context3.t0;
273
- case 21:
274
- case "end":
275
- return _context3.stop();
276
- }
277
- }, _callee3, this, [[8, 17]]);
278
- }));
279
- function loadCloudInvoiceTemplate(_x4, _x5) {
280
- return _loadCloudInvoiceTemplate.apply(this, arguments);
281
- }
282
- return loadCloudInvoiceTemplate;
283
- }()
284
- }, {
285
- key: "fetchCloudInvoiceTemplate",
286
- value: function () {
287
- var _fetchCloudInvoiceTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(target, scope) {
288
- var response, raw, documentId;
289
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
290
- while (1) switch (_context4.prev = _context4.next) {
291
- case 0:
292
- _context4.next = 2;
220
+ _context3.next = 2;
293
221
  return this.requestOpenData({
294
222
  scope: 'board',
295
223
  target: target,
296
224
  section_code: ['documents']
297
- }, scope, true);
225
+ }, true);
298
226
  case 2:
299
- response = _context4.sent;
300
- scope.assertCurrent();
227
+ response = _context3.sent;
301
228
  if (!((response === null || response === void 0 ? void 0 : response.status) !== true || response.code !== 200 || !isRecord(response.data))) {
302
- _context4.next = 6;
229
+ _context3.next = 5;
303
230
  break;
304
231
  }
305
232
  throw new Error((response === null || response === void 0 ? void 0 : response.message) || 'Cloud Invoice settings unavailable');
306
- case 6:
233
+ case 5:
307
234
  raw = response.data['documents.invoice_template'];
308
235
  documentId = resolveInvoiceDocumentId(raw);
309
236
  if (!documentId) {
310
- _context4.next = 10;
237
+ _context3.next = 9;
311
238
  break;
312
239
  }
313
- return _context4.abrupt("return", this.fetchInvoiceTemplateDocument(documentId, true));
314
- case 10:
240
+ return _context3.abrupt("return", this.fetchInvoiceTemplateDocument(documentId, true));
241
+ case 9:
315
242
  if (!(raw == null || typeof raw === 'string' && !raw.trim())) {
316
- _context4.next = 12;
243
+ _context3.next = 11;
317
244
  break;
318
245
  }
319
- return _context4.abrupt("return", getDefaultInvoiceTemplateSettings());
320
- case 12:
246
+ return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
247
+ case 11:
321
248
  if (!isLegacyInvoiceTemplate(raw)) {
322
- _context4.next = 14;
249
+ _context3.next = 13;
323
250
  break;
324
251
  }
325
- return _context4.abrupt("return", normalizeInvoiceTemplateSettings(response.data));
326
- case 14:
252
+ return _context3.abrupt("return", normalizeInvoiceTemplateSettings(response.data));
253
+ case 13:
327
254
  throw new Error('Cloud Invoice template identifier is invalid');
328
- case 15:
255
+ case 14:
329
256
  case "end":
330
- return _context4.stop();
257
+ return _context3.stop();
331
258
  }
332
- }, _callee4, this);
259
+ }, _callee3, this);
333
260
  }));
334
- function fetchCloudInvoiceTemplate(_x6, _x7) {
335
- return _fetchCloudInvoiceTemplate.apply(this, arguments);
261
+ function loadCloudInvoiceTemplate(_x4) {
262
+ return _loadCloudInvoiceTemplate.apply(this, arguments);
336
263
  }
337
- return fetchCloudInvoiceTemplate;
338
- }()
264
+ return loadCloudInvoiceTemplate;
265
+ }())
339
266
  }, {
340
267
  key: "getOpenData",
341
268
  value: function getOpenData() {
@@ -372,10 +299,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
372
299
  }, {
373
300
  key: "ensureInvoiceTemplateSettings",
374
301
  value: function () {
375
- var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(target, openDataConfig) {
302
+ var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(target, openDataConfig) {
376
303
  var normalizedTarget, config, fetchRevision, resolved;
377
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
378
- while (1) switch (_context5.prev = _context5.next) {
304
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
305
+ while (1) switch (_context4.prev = _context4.next) {
379
306
  case 0:
380
307
  normalizedTarget = String(target || '').trim();
381
308
  if (openDataConfig && openDataConfig !== this.store.data) {
@@ -388,31 +315,31 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
388
315
  }
389
316
  config = this.store.data;
390
317
  if (!(!normalizedTarget || !config)) {
391
- _context5.next = 5;
318
+ _context4.next = 5;
392
319
  break;
393
320
  }
394
- return _context5.abrupt("return", getDefaultInvoiceTemplateSettings());
321
+ return _context4.abrupt("return", getDefaultInvoiceTemplateSettings());
395
322
  case 5:
396
323
  fetchRevision = this.fetchRevision;
397
- _context5.next = 8;
324
+ _context4.next = 8;
398
325
  return this.resolveInvoiceTemplateSettings(config, normalizedTarget);
399
326
  case 8:
400
- resolved = _context5.sent;
327
+ resolved = _context4.sent;
401
328
  if (!(fetchRevision !== this.fetchRevision || this.store.data !== config)) {
402
- _context5.next = 11;
329
+ _context4.next = 11;
403
330
  break;
404
331
  }
405
- return _context5.abrupt("return", getDefaultInvoiceTemplateSettings());
332
+ return _context4.abrupt("return", getDefaultInvoiceTemplateSettings());
406
333
  case 11:
407
334
  this.commitInvoiceTemplateSettings(normalizedTarget, resolved);
408
- return _context5.abrupt("return", normalizeRawInvoiceTemplateSettings(resolved.settings));
335
+ return _context4.abrupt("return", normalizeRawInvoiceTemplateSettings(resolved.settings));
409
336
  case 13:
410
337
  case "end":
411
- return _context5.stop();
338
+ return _context4.stop();
412
339
  }
413
- }, _callee5, this);
340
+ }, _callee4, this);
414
341
  }));
415
- function ensureInvoiceTemplateSettings(_x8, _x9) {
342
+ function ensureInvoiceTemplateSettings(_x5, _x6) {
416
343
  return _ensureInvoiceTemplateSettings.apply(this, arguments);
417
344
  }
418
345
  return ensureInvoiceTemplateSettings;
@@ -428,17 +355,17 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
428
355
  }, {
429
356
  key: "resolveInvoiceTemplateSettings",
430
357
  value: function () {
431
- var _resolveInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(config, target) {
432
- var _this3 = this;
358
+ var _resolveInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(config, target) {
359
+ var _this2 = this;
433
360
  var rawTemplate, documentId, cacheKey, cachedSettings, request, cacheRevision;
434
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
435
- while (1) switch (_context6.prev = _context6.next) {
361
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
362
+ while (1) switch (_context5.prev = _context5.next) {
436
363
  case 0:
437
364
  if (!this.shouldSkipInvoiceTemplateDocument()) {
438
- _context6.next = 2;
365
+ _context5.next = 2;
439
366
  break;
440
367
  }
441
- return _context6.abrupt("return", {
368
+ return _context5.abrupt("return", {
442
369
  settings: getDefaultInvoiceTemplateSettings(),
443
370
  documentId: null,
444
371
  cacheKey: null
@@ -447,10 +374,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
447
374
  rawTemplate = config['documents.invoice_template'];
448
375
  documentId = resolveInvoiceDocumentId(rawTemplate);
449
376
  if (documentId) {
450
- _context6.next = 6;
377
+ _context5.next = 6;
451
378
  break;
452
379
  }
453
- return _context6.abrupt("return", {
380
+ return _context5.abrupt("return", {
454
381
  settings: isLegacyInvoiceTemplate(rawTemplate) ? normalizeInvoiceTemplateSettings(config) : getDefaultInvoiceTemplateSettings(),
455
382
  documentId: null,
456
383
  cacheKey: null
@@ -458,10 +385,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
458
385
  case 6:
459
386
  cacheKey = this.buildInvoiceTemplateCacheKey(target, documentId);
460
387
  if (!(this.store.invoiceTemplateTarget === target && this.store.invoiceTemplateDocumentId === documentId && this.store.invoiceTemplateCacheKey === cacheKey && isRecord(this.store.invoiceTemplateSettings))) {
461
- _context6.next = 9;
388
+ _context5.next = 9;
462
389
  break;
463
390
  }
464
- return _context6.abrupt("return", {
391
+ return _context5.abrupt("return", {
465
392
  settings: normalizeRawInvoiceTemplateSettings(this.store.invoiceTemplateSettings),
466
393
  documentId: documentId,
467
394
  cacheKey: cacheKey
@@ -469,10 +396,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
469
396
  case 9:
470
397
  cachedSettings = this.invoiceTemplateDocumentCache.get(cacheKey);
471
398
  if (!cachedSettings) {
472
- _context6.next = 12;
399
+ _context5.next = 12;
473
400
  break;
474
401
  }
475
- return _context6.abrupt("return", {
402
+ return _context5.abrupt("return", {
476
403
  settings: normalizeRawInvoiceTemplateSettings(cachedSettings),
477
404
  documentId: documentId,
478
405
  cacheKey: cacheKey
@@ -482,39 +409,39 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
482
409
  if (!request) {
483
410
  cacheRevision = this.invoiceTemplateCacheRevision;
484
411
  request = this.fetchInvoiceTemplateDocument(documentId).catch(function (error) {
485
- _this3.logInvoiceTemplateDocumentFallback(error, target, documentId);
412
+ _this2.logInvoiceTemplateDocumentFallback(error, target, documentId);
486
413
  return getDefaultInvoiceTemplateSettings();
487
414
  }).then(function (settings) {
488
415
  var normalized = normalizeRawInvoiceTemplateSettings(settings);
489
- if (cacheRevision === _this3.invoiceTemplateCacheRevision) {
490
- _this3.invoiceTemplateDocumentCache.set(cacheKey, normalized);
416
+ if (cacheRevision === _this2.invoiceTemplateCacheRevision) {
417
+ _this2.invoiceTemplateDocumentCache.set(cacheKey, normalized);
491
418
  }
492
419
  return normalized;
493
420
  }).finally(function () {
494
- if (_this3.invoiceTemplateDocumentInFlight.get(cacheKey) === request) {
495
- _this3.invoiceTemplateDocumentInFlight.delete(cacheKey);
421
+ if (_this2.invoiceTemplateDocumentInFlight.get(cacheKey) === request) {
422
+ _this2.invoiceTemplateDocumentInFlight.delete(cacheKey);
496
423
  }
497
424
  });
498
425
  this.invoiceTemplateDocumentInFlight.set(cacheKey, request);
499
426
  }
500
- _context6.next = 16;
427
+ _context5.next = 16;
501
428
  return request;
502
429
  case 16:
503
- _context6.t0 = _context6.sent;
504
- _context6.t1 = documentId;
505
- _context6.t2 = cacheKey;
506
- return _context6.abrupt("return", {
507
- settings: _context6.t0,
508
- documentId: _context6.t1,
509
- cacheKey: _context6.t2
430
+ _context5.t0 = _context5.sent;
431
+ _context5.t1 = documentId;
432
+ _context5.t2 = cacheKey;
433
+ return _context5.abrupt("return", {
434
+ settings: _context5.t0,
435
+ documentId: _context5.t1,
436
+ cacheKey: _context5.t2
510
437
  });
511
438
  case 20:
512
439
  case "end":
513
- return _context6.stop();
440
+ return _context5.stop();
514
441
  }
515
- }, _callee6, this);
442
+ }, _callee5, this);
516
443
  }));
517
- function resolveInvoiceTemplateSettings(_x10, _x11) {
444
+ function resolveInvoiceTemplateSettings(_x7, _x8) {
518
445
  return _resolveInvoiceTemplateSettings.apply(this, arguments);
519
446
  }
520
447
  return resolveInvoiceTemplateSettings;
@@ -522,23 +449,23 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
522
449
  }, {
523
450
  key: "buildInvoiceTemplateCacheKey",
524
451
  value: function buildInvoiceTemplateCacheKey(target, documentId) {
525
- var _this$appPlugin, _this$appPlugin$getDa, _getData3, _getData4;
526
- var getData = (_this$appPlugin = this.appPlugin) === null || _this$appPlugin === void 0 || (_this$appPlugin$getDa = _this$appPlugin.getData) === null || _this$appPlugin$getDa === void 0 ? void 0 : _this$appPlugin$getDa.call(_this$appPlugin);
527
- return JSON.stringify([(_getData3 = getData === null || getData === void 0 ? void 0 : getData('tenant_id')) !== null && _getData3 !== void 0 ? _getData3 : null, (_getData4 = getData === null || getData === void 0 ? void 0 : getData('shop_id')) !== null && _getData4 !== void 0 ? _getData4 : null, target, documentId]);
452
+ var _this$appPlugin2, _this$appPlugin2$getD, _getData, _getData2;
453
+ var getData = (_this$appPlugin2 = this.appPlugin) === null || _this$appPlugin2 === void 0 || (_this$appPlugin2$getD = _this$appPlugin2.getData) === null || _this$appPlugin2$getD === void 0 ? void 0 : _this$appPlugin2$getD.call(_this$appPlugin2);
454
+ return JSON.stringify([(_getData = getData === null || getData === void 0 ? void 0 : getData('tenant_id')) !== null && _getData !== void 0 ? _getData : null, (_getData2 = getData === null || getData === void 0 ? void 0 : getData('shop_id')) !== null && _getData2 !== void 0 ? _getData2 : null, target, documentId]);
528
455
  }
529
456
  }, {
530
457
  key: "fetchInvoiceTemplateDocument",
531
458
  value: function () {
532
- var _fetchInvoiceTemplateDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(documentId) {
459
+ var _fetchInvoiceTemplateDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(documentId) {
533
460
  var strict,
534
461
  response,
535
462
  document,
536
- _args7 = arguments;
537
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
538
- while (1) switch (_context7.prev = _context7.next) {
463
+ _args6 = arguments;
464
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
465
+ while (1) switch (_context6.prev = _context6.next) {
539
466
  case 0:
540
- strict = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : false;
541
- _context7.next = 3;
467
+ strict = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : false;
468
+ _context6.next = 3;
542
469
  return this.request.get("/document:get?filterByTk=".concat(encodeURIComponent(documentId)), {}, _objectSpread({
543
470
  isNocobase: true,
544
471
  prefix: false,
@@ -551,40 +478,40 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
551
478
  skipErrorHandler: true
552
479
  } : {}));
553
480
  case 3:
554
- response = _context7.sent;
481
+ response = _context6.sent;
555
482
  document = response === null || response === void 0 ? void 0 : response.data;
556
483
  if (!(!document || resolveInvoiceDocumentId(document.id) !== documentId)) {
557
- _context7.next = 7;
484
+ _context6.next = 7;
558
485
  break;
559
486
  }
560
487
  throw new Error("Invoice Document ".concat(documentId, " \u8FD4\u56DE\u7684 ID \u4E0D\u5339\u914D"));
561
488
  case 7:
562
489
  if (!(document.deleted_at !== null && document.deleted_at !== undefined)) {
563
- _context7.next = 9;
490
+ _context6.next = 9;
564
491
  break;
565
492
  }
566
493
  throw new Error("Invoice Document ".concat(documentId, " \u5DF2\u88AB\u5220\u9664"));
567
494
  case 9:
568
495
  if (!(!isRecord(document.data) || !isRecord(document.data.template_settings))) {
569
- _context7.next = 11;
496
+ _context6.next = 11;
570
497
  break;
571
498
  }
572
499
  throw new Error("Invoice Document ".concat(documentId, " \u7F3A\u5C11 template_settings"));
573
500
  case 11:
574
501
  if (!(strict && (typeof document.data.template_settings.template !== 'string' || !document.data.template_settings.template.trim()))) {
575
- _context7.next = 13;
502
+ _context6.next = 13;
576
503
  break;
577
504
  }
578
505
  throw new Error("Invoice Document ".concat(documentId, " \u7F3A\u5C11 template"));
579
506
  case 13:
580
- return _context7.abrupt("return", normalizeRawInvoiceTemplateSettings(document.data.template_settings));
507
+ return _context6.abrupt("return", normalizeRawInvoiceTemplateSettings(document.data.template_settings));
581
508
  case 14:
582
509
  case "end":
583
- return _context7.stop();
510
+ return _context6.stop();
584
511
  }
585
- }, _callee7, this);
512
+ }, _callee6, this);
586
513
  }));
587
- function fetchInvoiceTemplateDocument(_x12) {
514
+ function fetchInvoiceTemplateDocument(_x9) {
588
515
  return _fetchInvoiceTemplateDocument.apply(this, arguments);
589
516
  }
590
517
  return fetchInvoiceTemplateDocument;
@@ -611,7 +538,6 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
611
538
  value: function clearCache() {
612
539
  this.fetchRevision += 1;
613
540
  this.invoiceTemplateCacheRevision += 1;
614
- this.cloudInvoiceTemplates.clear();
615
541
  this.invoiceTemplateDocumentCache.clear();
616
542
  this.invoiceTemplateDocumentInFlight.clear();
617
543
  this.store.data = null;
@@ -21,6 +21,23 @@ var DEFAULT_BUSINESS_HOURS = {
21
21
  startTime: '00:00',
22
22
  endTime: '00:00'
23
23
  };
24
+ // Only factory-owned snapshots are immutable. A caller may provide a mutable
25
+ // projection, or freeze its outer object without freezing its products/cells.
26
+ var immutableProjections = new WeakSet();
27
+ var projectionStaticIndices = new WeakMap();
28
+ function getProjectionStaticIndex(projection, key, build) {
29
+ if (!immutableProjections.has(projection)) return build(projection);
30
+ var indices = projectionStaticIndices.get(projection);
31
+ if (!indices) {
32
+ indices = {};
33
+ projectionStaticIndices.set(projection, indices);
34
+ }
35
+ var existing = indices[key];
36
+ if (existing) return existing;
37
+ var index = build(projection);
38
+ indices[key] = index;
39
+ return index;
40
+ }
24
41
  function availabilityError(code, message, details) {
25
42
  return new AvailabilityError(code, message, details);
26
43
  }
@@ -882,9 +899,11 @@ export function createAvailabilityProjection(input) {
882
899
  resources: resources,
883
900
  resourceOccupancies: resourceOccupancies
884
901
  };
885
- return deepFreeze(_objectSpread(_objectSpread({}, projectionBase), {}, {
902
+ var projection = deepFreeze(_objectSpread(_objectSpread({}, projectionBase), {}, {
886
903
  cells: buildCells(projectionBase)
887
904
  }));
905
+ immutableProjections.add(projection);
906
+ return projection;
888
907
  }
889
908
  function uniqByOccupancy(occupancies) {
890
909
  var map = new Map();
@@ -2255,8 +2274,8 @@ export function queryAvailabilityProjection(projection, request) {
2255
2274
  assertRangesWithinProjection(projection, request.selectedRanges);
2256
2275
  }
2257
2276
  var productIdSet = (_request$productIds2 = request.productIds) !== null && _request$productIds2 !== void 0 && _request$productIds2.length ? new Set(request.productIds.map(String)) : null;
2258
- var productIndex = buildProductIndex(projection);
2259
- var cellIndex = buildAvailabilityCellIndex(projection);
2277
+ var productIndex = getProjectionStaticIndex(projection, 'productIndex', buildProductIndex);
2278
+ var cellIndex = getProjectionStaticIndex(projection, 'cellIndex', buildAvailabilityCellIndex);
2260
2279
  var groupResourceIndex = buildGroupResourceIndex({
2261
2280
  projection: projection,
2262
2281
  resourceIds: request.resourceIds,
@@ -2577,14 +2596,14 @@ export function validateAvailabilitySelection(projection, params) {
2577
2596
  var normalizedPartySize = normalizePartySize(params.partySize);
2578
2597
  var normalizedBookingCount = normalizeBookingCount(params.bookingCount);
2579
2598
  assertRangesWithinProjection(projection, [params.candidate]);
2580
- var productIndex = buildProductIndex(projection);
2599
+ var productIndex = getProjectionStaticIndex(projection, 'productIndex', buildProductIndex);
2581
2600
  var evaluatedAt = formatDateTime(localDateToScalar(new Date()), projection.meta.timezone, (_extractFixedOffsetMi7 = extractFixedOffsetMinutes(projection.meta.now)) !== null && _extractFixedOffsetMi7 !== void 0 ? _extractFixedOffsetMi7 : captureRuntimeOffsetMinutes());
2582
2601
  var evaluated = evaluateCandidate(projection, params.candidate, {
2583
2602
  partySize: normalizedPartySize,
2584
2603
  evaluatedAt: evaluatedAt,
2585
2604
  requirementSelections: params.requirementSelections,
2586
2605
  allowImplicitSelection: false,
2587
- cellIndex: buildAvailabilityCellIndex(projection),
2606
+ cellIndex: getProjectionStaticIndex(projection, 'cellIndex', buildAvailabilityCellIndex),
2588
2607
  productIndex: productIndex,
2589
2608
  groupResourceIndex: buildGroupResourceIndex({
2590
2609
  projection: projection,
@@ -66,7 +66,6 @@ declare class Server {
66
66
  private localPaymentUpdateQueues;
67
67
  private paymentIdentityRefreshes;
68
68
  private receiptFulfillmentConfigInFlight;
69
- private cloudInvoiceSubmissions;
70
69
  private floorPlanQuerySubscribers;
71
70
  private moduleRegistry;
72
71
  constructor(core: PisellCore);
@@ -548,10 +547,7 @@ declare class Server {
548
547
  private shouldLookupLocalPrintOrder;
549
548
  private getLocalPrintOrderLookup;
550
549
  private mergeLocalPrintOrderInput;
551
- private getCloudInvoiceDevice;
552
- private assertCloudInvoiceContext;
553
550
  private loadCloudInvoiceOrder;
554
- private resolveCloudOrderInvoice;
555
551
  private handleCloudOrderInvoice;
556
552
  private handleLocalPrintOrder;
557
553
  private normalizeRequestedReceiptLocales;