@pisell/pisellos 0.10.95 → 0.10.96

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,6 +6,13 @@ 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
+ }
9
16
  export declare class OpenDataModule extends BaseModule implements Module {
10
17
  protected defaultName: string;
11
18
  protected defaultVersion: string;
@@ -19,6 +26,7 @@ export declare class OpenDataModule extends BaseModule implements Module {
19
26
  private otherParams;
20
27
  private fetchRevision;
21
28
  private invoiceTemplateCacheRevision;
29
+ private cloudInvoiceTemplates;
22
30
  private invoiceTemplateDocumentCache;
23
31
  private invoiceTemplateDocumentInFlight;
24
32
  constructor(name?: string, version?: string);
@@ -32,6 +40,11 @@ export declare class OpenDataModule extends BaseModule implements Module {
32
40
  updateOtherParams(params: Record<string, any>): void;
33
41
  private shouldSkipInvoiceTemplateDocument;
34
42
  fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
43
+ 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;
35
48
  getOpenData(): OpenDataConfig | null;
36
49
  getInvoiceLayoutConfig(): InvoiceLayoutConfig;
37
50
  getInvoiceTemplateSettings(): InvoiceTemplateSettings;
@@ -1,3 +1,5 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
3
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
2
4
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
3
5
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -40,6 +42,14 @@ function isLegacyInvoiceTemplate(value) {
40
42
  var numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
41
43
  return !numericLike.test(normalized);
42
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
+ }
43
53
  export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
44
54
  _inherits(OpenDataModule, _BaseModule);
45
55
  var _super = _createSuper(OpenDataModule);
@@ -59,6 +69,9 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
59
69
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
60
70
  _defineProperty(_assertThisInitialized(_this), "fetchRevision", 0);
61
71
  _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());
62
75
  _defineProperty(_assertThisInitialized(_this), "invoiceTemplateDocumentCache", new Map());
63
76
  _defineProperty(_assertThisInitialized(_this), "invoiceTemplateDocumentInFlight", new Map());
64
77
  return _this;
@@ -141,46 +154,25 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
141
154
  key: "fetchOpenData",
142
155
  value: function () {
143
156
  var _fetchOpenData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
144
- var _this$appPlugin, _this$appPlugin$getDa;
145
- var fetchRevision, getData, shopId, tenantId, headers, response, data, resolvedInvoiceTemplate;
157
+ var fetchRevision, response, data, resolvedInvoiceTemplate;
146
158
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
147
159
  while (1) switch (_context2.prev = _context2.next) {
148
160
  case 0:
149
161
  fetchRevision = ++this.fetchRevision;
150
- 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);
151
- shopId = getData === null || getData === void 0 ? void 0 : getData('shop_id');
152
- if (shopId) {
153
- _context2.next = 5;
154
- break;
155
- }
156
- throw new Error('[OpenDataModule] 无法获取 shop_id');
157
- case 5:
158
- tenantId = getData === null || getData === void 0 ? void 0 : getData('tenant_id');
159
- headers = {};
160
- if (tenantId) headers['Tenant-Id'] = String(tenantId);
161
- _context2.next = 10;
162
- return this.request.post("/open/my-pisell/".concat(shopId, "/setting"), {
163
- scope: params.scope,
164
- target: params.target,
165
- section_code: params.section_code
166
- }, {
167
- pisell2: true,
168
- isPisell2: true,
169
- prefix: false,
170
- headers: headers
171
- });
172
- case 10:
162
+ _context2.next = 3;
163
+ return this.requestOpenData(params, readInvoiceShopScope(this.appPlugin));
164
+ case 3:
173
165
  response = _context2.sent;
174
166
  if (!((response === null || response === void 0 ? void 0 : response.status) === false)) {
175
- _context2.next = 13;
167
+ _context2.next = 6;
176
168
  break;
177
169
  }
178
170
  throw new Error((response === null || response === void 0 ? void 0 : response.message) || '获取 OpenData 配置失败');
179
- case 13:
171
+ case 6:
180
172
  data = (response === null || response === void 0 ? void 0 : response.data) || {};
181
- _context2.next = 16;
173
+ _context2.next = 9;
182
174
  return this.resolveInvoiceTemplateSettings(data, params.target);
183
- case 16:
175
+ case 9:
184
176
  resolvedInvoiceTemplate = _context2.sent;
185
177
  // clearCache() 或后续请求发生后,旧响应不得复活已失效的 target 配置。
186
178
  if (fetchRevision === this.fetchRevision) {
@@ -189,7 +181,7 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
189
181
  this.commitInvoiceTemplateSettings(params.target, resolvedInvoiceTemplate);
190
182
  }
191
183
  return _context2.abrupt("return", data);
192
- case 19:
184
+ case 12:
193
185
  case "end":
194
186
  return _context2.stop();
195
187
  }
@@ -200,6 +192,150 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
200
192
  }
201
193
  return fetchOpenData;
202
194
  }()
195
+ }, {
196
+ 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"), {
201
+ scope: params.scope,
202
+ target: params.target,
203
+ section_code: params.section_code
204
+ }, _objectSpread({
205
+ pisell2: true,
206
+ isPisell2: true,
207
+ prefix: false,
208
+ headers: scope.tenantId ? {
209
+ 'Tenant-Id': scope.tenantId
210
+ } : {}
211
+ }, background ? {
212
+ customToast: function customToast() {},
213
+ manualErrorHandling: true,
214
+ skipErrorHandler: true
215
+ } : {}));
216
+ }
217
+
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
+ }
237
+ }, {
238
+ key: "loadCloudInvoiceTemplate",
239
+ value: function () {
240
+ var _loadCloudInvoiceTemplate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target, scope) {
241
+ var key, existing, request, entry, settings;
242
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
243
+ while (1) switch (_context3.prev = _context3.next) {
244
+ 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;
293
+ return this.requestOpenData({
294
+ scope: 'board',
295
+ target: target,
296
+ section_code: ['documents']
297
+ }, scope, true);
298
+ case 2:
299
+ response = _context4.sent;
300
+ scope.assertCurrent();
301
+ if (!((response === null || response === void 0 ? void 0 : response.status) !== true || response.code !== 200 || !isRecord(response.data))) {
302
+ _context4.next = 6;
303
+ break;
304
+ }
305
+ throw new Error((response === null || response === void 0 ? void 0 : response.message) || 'Cloud Invoice settings unavailable');
306
+ case 6:
307
+ raw = response.data['documents.invoice_template'];
308
+ documentId = resolveInvoiceDocumentId(raw);
309
+ if (!documentId) {
310
+ _context4.next = 10;
311
+ break;
312
+ }
313
+ return _context4.abrupt("return", this.fetchInvoiceTemplateDocument(documentId, true));
314
+ case 10:
315
+ if (!(raw == null || typeof raw === 'string' && !raw.trim())) {
316
+ _context4.next = 12;
317
+ break;
318
+ }
319
+ return _context4.abrupt("return", getDefaultInvoiceTemplateSettings());
320
+ case 12:
321
+ if (!isLegacyInvoiceTemplate(raw)) {
322
+ _context4.next = 14;
323
+ break;
324
+ }
325
+ return _context4.abrupt("return", normalizeInvoiceTemplateSettings(response.data));
326
+ case 14:
327
+ throw new Error('Cloud Invoice template identifier is invalid');
328
+ case 15:
329
+ case "end":
330
+ return _context4.stop();
331
+ }
332
+ }, _callee4, this);
333
+ }));
334
+ function fetchCloudInvoiceTemplate(_x6, _x7) {
335
+ return _fetchCloudInvoiceTemplate.apply(this, arguments);
336
+ }
337
+ return fetchCloudInvoiceTemplate;
338
+ }()
203
339
  }, {
204
340
  key: "getOpenData",
205
341
  value: function getOpenData() {
@@ -236,10 +372,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
236
372
  }, {
237
373
  key: "ensureInvoiceTemplateSettings",
238
374
  value: function () {
239
- var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(target, openDataConfig) {
375
+ var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(target, openDataConfig) {
240
376
  var normalizedTarget, config, fetchRevision, resolved;
241
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
242
- while (1) switch (_context3.prev = _context3.next) {
377
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
378
+ while (1) switch (_context5.prev = _context5.next) {
243
379
  case 0:
244
380
  normalizedTarget = String(target || '').trim();
245
381
  if (openDataConfig && openDataConfig !== this.store.data) {
@@ -252,31 +388,31 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
252
388
  }
253
389
  config = this.store.data;
254
390
  if (!(!normalizedTarget || !config)) {
255
- _context3.next = 5;
391
+ _context5.next = 5;
256
392
  break;
257
393
  }
258
- return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
394
+ return _context5.abrupt("return", getDefaultInvoiceTemplateSettings());
259
395
  case 5:
260
396
  fetchRevision = this.fetchRevision;
261
- _context3.next = 8;
397
+ _context5.next = 8;
262
398
  return this.resolveInvoiceTemplateSettings(config, normalizedTarget);
263
399
  case 8:
264
- resolved = _context3.sent;
400
+ resolved = _context5.sent;
265
401
  if (!(fetchRevision !== this.fetchRevision || this.store.data !== config)) {
266
- _context3.next = 11;
402
+ _context5.next = 11;
267
403
  break;
268
404
  }
269
- return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
405
+ return _context5.abrupt("return", getDefaultInvoiceTemplateSettings());
270
406
  case 11:
271
407
  this.commitInvoiceTemplateSettings(normalizedTarget, resolved);
272
- return _context3.abrupt("return", normalizeRawInvoiceTemplateSettings(resolved.settings));
408
+ return _context5.abrupt("return", normalizeRawInvoiceTemplateSettings(resolved.settings));
273
409
  case 13:
274
410
  case "end":
275
- return _context3.stop();
411
+ return _context5.stop();
276
412
  }
277
- }, _callee3, this);
413
+ }, _callee5, this);
278
414
  }));
279
- function ensureInvoiceTemplateSettings(_x4, _x5) {
415
+ function ensureInvoiceTemplateSettings(_x8, _x9) {
280
416
  return _ensureInvoiceTemplateSettings.apply(this, arguments);
281
417
  }
282
418
  return ensureInvoiceTemplateSettings;
@@ -292,17 +428,17 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
292
428
  }, {
293
429
  key: "resolveInvoiceTemplateSettings",
294
430
  value: function () {
295
- var _resolveInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config, target) {
296
- var _this2 = this;
431
+ var _resolveInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(config, target) {
432
+ var _this3 = this;
297
433
  var rawTemplate, documentId, cacheKey, cachedSettings, request, cacheRevision;
298
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
299
- while (1) switch (_context4.prev = _context4.next) {
434
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
435
+ while (1) switch (_context6.prev = _context6.next) {
300
436
  case 0:
301
437
  if (!this.shouldSkipInvoiceTemplateDocument()) {
302
- _context4.next = 2;
438
+ _context6.next = 2;
303
439
  break;
304
440
  }
305
- return _context4.abrupt("return", {
441
+ return _context6.abrupt("return", {
306
442
  settings: getDefaultInvoiceTemplateSettings(),
307
443
  documentId: null,
308
444
  cacheKey: null
@@ -311,10 +447,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
311
447
  rawTemplate = config['documents.invoice_template'];
312
448
  documentId = resolveInvoiceDocumentId(rawTemplate);
313
449
  if (documentId) {
314
- _context4.next = 6;
450
+ _context6.next = 6;
315
451
  break;
316
452
  }
317
- return _context4.abrupt("return", {
453
+ return _context6.abrupt("return", {
318
454
  settings: isLegacyInvoiceTemplate(rawTemplate) ? normalizeInvoiceTemplateSettings(config) : getDefaultInvoiceTemplateSettings(),
319
455
  documentId: null,
320
456
  cacheKey: null
@@ -322,10 +458,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
322
458
  case 6:
323
459
  cacheKey = this.buildInvoiceTemplateCacheKey(target, documentId);
324
460
  if (!(this.store.invoiceTemplateTarget === target && this.store.invoiceTemplateDocumentId === documentId && this.store.invoiceTemplateCacheKey === cacheKey && isRecord(this.store.invoiceTemplateSettings))) {
325
- _context4.next = 9;
461
+ _context6.next = 9;
326
462
  break;
327
463
  }
328
- return _context4.abrupt("return", {
464
+ return _context6.abrupt("return", {
329
465
  settings: normalizeRawInvoiceTemplateSettings(this.store.invoiceTemplateSettings),
330
466
  documentId: documentId,
331
467
  cacheKey: cacheKey
@@ -333,10 +469,10 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
333
469
  case 9:
334
470
  cachedSettings = this.invoiceTemplateDocumentCache.get(cacheKey);
335
471
  if (!cachedSettings) {
336
- _context4.next = 12;
472
+ _context6.next = 12;
337
473
  break;
338
474
  }
339
- return _context4.abrupt("return", {
475
+ return _context6.abrupt("return", {
340
476
  settings: normalizeRawInvoiceTemplateSettings(cachedSettings),
341
477
  documentId: documentId,
342
478
  cacheKey: cacheKey
@@ -346,39 +482,39 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
346
482
  if (!request) {
347
483
  cacheRevision = this.invoiceTemplateCacheRevision;
348
484
  request = this.fetchInvoiceTemplateDocument(documentId).catch(function (error) {
349
- _this2.logInvoiceTemplateDocumentFallback(error, target, documentId);
485
+ _this3.logInvoiceTemplateDocumentFallback(error, target, documentId);
350
486
  return getDefaultInvoiceTemplateSettings();
351
487
  }).then(function (settings) {
352
488
  var normalized = normalizeRawInvoiceTemplateSettings(settings);
353
- if (cacheRevision === _this2.invoiceTemplateCacheRevision) {
354
- _this2.invoiceTemplateDocumentCache.set(cacheKey, normalized);
489
+ if (cacheRevision === _this3.invoiceTemplateCacheRevision) {
490
+ _this3.invoiceTemplateDocumentCache.set(cacheKey, normalized);
355
491
  }
356
492
  return normalized;
357
493
  }).finally(function () {
358
- if (_this2.invoiceTemplateDocumentInFlight.get(cacheKey) === request) {
359
- _this2.invoiceTemplateDocumentInFlight.delete(cacheKey);
494
+ if (_this3.invoiceTemplateDocumentInFlight.get(cacheKey) === request) {
495
+ _this3.invoiceTemplateDocumentInFlight.delete(cacheKey);
360
496
  }
361
497
  });
362
498
  this.invoiceTemplateDocumentInFlight.set(cacheKey, request);
363
499
  }
364
- _context4.next = 16;
500
+ _context6.next = 16;
365
501
  return request;
366
502
  case 16:
367
- _context4.t0 = _context4.sent;
368
- _context4.t1 = documentId;
369
- _context4.t2 = cacheKey;
370
- return _context4.abrupt("return", {
371
- settings: _context4.t0,
372
- documentId: _context4.t1,
373
- cacheKey: _context4.t2
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
374
510
  });
375
511
  case 20:
376
512
  case "end":
377
- return _context4.stop();
513
+ return _context6.stop();
378
514
  }
379
- }, _callee4, this);
515
+ }, _callee6, this);
380
516
  }));
381
- function resolveInvoiceTemplateSettings(_x6, _x7) {
517
+ function resolveInvoiceTemplateSettings(_x10, _x11) {
382
518
  return _resolveInvoiceTemplateSettings.apply(this, arguments);
383
519
  }
384
520
  return resolveInvoiceTemplateSettings;
@@ -386,56 +522,69 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
386
522
  }, {
387
523
  key: "buildInvoiceTemplateCacheKey",
388
524
  value: function buildInvoiceTemplateCacheKey(target, documentId) {
389
- var _this$appPlugin2, _this$appPlugin2$getD, _getData, _getData2;
390
- 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);
391
- 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]);
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]);
392
528
  }
393
529
  }, {
394
530
  key: "fetchInvoiceTemplateDocument",
395
531
  value: function () {
396
- var _fetchInvoiceTemplateDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(documentId) {
397
- var response, document;
398
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
399
- while (1) switch (_context5.prev = _context5.next) {
532
+ var _fetchInvoiceTemplateDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(documentId) {
533
+ var strict,
534
+ response,
535
+ document,
536
+ _args7 = arguments;
537
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
538
+ while (1) switch (_context7.prev = _context7.next) {
400
539
  case 0:
401
- _context5.next = 2;
402
- return this.request.get("/document:get?filterByTk=".concat(encodeURIComponent(documentId)), {}, {
540
+ strict = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : false;
541
+ _context7.next = 3;
542
+ return this.request.get("/document:get?filterByTk=".concat(encodeURIComponent(documentId)), {}, _objectSpread({
403
543
  isNocobase: true,
404
544
  prefix: false,
405
545
  headers: {
406
546
  'x-data-source': 'pisell2'
407
547
  },
408
548
  customToast: function customToast() {}
409
- });
410
- case 2:
411
- response = _context5.sent;
549
+ }, strict ? {
550
+ manualErrorHandling: true,
551
+ skipErrorHandler: true
552
+ } : {}));
553
+ case 3:
554
+ response = _context7.sent;
412
555
  document = response === null || response === void 0 ? void 0 : response.data;
413
556
  if (!(!document || resolveInvoiceDocumentId(document.id) !== documentId)) {
414
- _context5.next = 6;
557
+ _context7.next = 7;
415
558
  break;
416
559
  }
417
560
  throw new Error("Invoice Document ".concat(documentId, " \u8FD4\u56DE\u7684 ID \u4E0D\u5339\u914D"));
418
- case 6:
561
+ case 7:
419
562
  if (!(document.deleted_at !== null && document.deleted_at !== undefined)) {
420
- _context5.next = 8;
563
+ _context7.next = 9;
421
564
  break;
422
565
  }
423
566
  throw new Error("Invoice Document ".concat(documentId, " \u5DF2\u88AB\u5220\u9664"));
424
- case 8:
567
+ case 9:
425
568
  if (!(!isRecord(document.data) || !isRecord(document.data.template_settings))) {
426
- _context5.next = 10;
569
+ _context7.next = 11;
427
570
  break;
428
571
  }
429
572
  throw new Error("Invoice Document ".concat(documentId, " \u7F3A\u5C11 template_settings"));
430
- case 10:
431
- return _context5.abrupt("return", normalizeRawInvoiceTemplateSettings(document.data.template_settings));
432
573
  case 11:
574
+ if (!(strict && (typeof document.data.template_settings.template !== 'string' || !document.data.template_settings.template.trim()))) {
575
+ _context7.next = 13;
576
+ break;
577
+ }
578
+ throw new Error("Invoice Document ".concat(documentId, " \u7F3A\u5C11 template"));
579
+ case 13:
580
+ return _context7.abrupt("return", normalizeRawInvoiceTemplateSettings(document.data.template_settings));
581
+ case 14:
433
582
  case "end":
434
- return _context5.stop();
583
+ return _context7.stop();
435
584
  }
436
- }, _callee5, this);
585
+ }, _callee7, this);
437
586
  }));
438
- function fetchInvoiceTemplateDocument(_x8) {
587
+ function fetchInvoiceTemplateDocument(_x12) {
439
588
  return _fetchInvoiceTemplateDocument.apply(this, arguments);
440
589
  }
441
590
  return fetchInvoiceTemplateDocument;
@@ -462,6 +611,7 @@ export var OpenDataModule = /*#__PURE__*/function (_BaseModule) {
462
611
  value: function clearCache() {
463
612
  this.fetchRevision += 1;
464
613
  this.invoiceTemplateCacheRevision += 1;
614
+ this.cloudInvoiceTemplates.clear();
465
615
  this.invoiceTemplateDocumentCache.clear();
466
616
  this.invoiceTemplateDocumentInFlight.clear();
467
617
  this.store.data = null;
@@ -640,7 +640,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
640
640
  generateIdempotencyToken(): string;
641
641
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
642
642
  createOrder(params: CommitOrderParams['query']): {
643
- type: "virtual" | "appointment_booking";
643
+ type: "appointment_booking" | "virtual";
644
644
  platform: string;
645
645
  sales_channel: string;
646
646
  order_sales_channel: string;
@@ -66,6 +66,7 @@ declare class Server {
66
66
  private localPaymentUpdateQueues;
67
67
  private paymentIdentityRefreshes;
68
68
  private receiptFulfillmentConfigInFlight;
69
+ private cloudInvoiceSubmissions;
69
70
  private floorPlanQuerySubscribers;
70
71
  private moduleRegistry;
71
72
  constructor(core: PisellCore);
@@ -547,8 +548,14 @@ declare class Server {
547
548
  private shouldLookupLocalPrintOrder;
548
549
  private getLocalPrintOrderLookup;
549
550
  private mergeLocalPrintOrderInput;
551
+ private getCloudInvoiceDevice;
552
+ private assertCloudInvoiceContext;
553
+ private loadCloudInvoiceOrder;
554
+ private resolveCloudOrderInvoice;
555
+ private handleCloudOrderInvoice;
550
556
  private handleLocalPrintOrder;
551
557
  private normalizeRequestedReceiptLocales;
558
+ private rebuildOrderReceipt;
552
559
  private handleLocalOrderReceiptSnapshot;
553
560
  private handleMachinecodeBatchMeta;
554
561
  private resolveMachinecodeBatchMetadataLookup;