@pisell/pisellos 0.10.96 → 0.10.97
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.
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/OpenData/index.d.ts +2 -12
- package/dist/modules/OpenData/index.js +95 -169
- package/dist/server/index.d.ts +0 -4
- package/dist/server/index.js +580 -759
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Sales/index.d.ts +2 -2
- package/dist/solution/Sales/index.js +36 -68
- package/dist/solution/Sales/types.d.ts +2 -8
- package/dist/solution/Sales/types.js +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/OpenData/index.d.ts +2 -12
- package/lib/modules/OpenData/index.js +12 -58
- package/lib/server/index.d.ts +0 -4
- package/lib/server/index.js +51 -136
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Sales/index.d.ts +2 -2
- package/lib/solution/Sales/index.js +13 -39
- package/lib/solution/Sales/types.d.ts +2 -8
- package/lib/solution/Sales/types.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 导出评估器
|
|
2
|
+
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
+
|
|
4
|
+
// 导出适配器
|
|
5
|
+
export { PromotionAdapter } from "./adapter";
|
|
6
|
+
export { default } from "./adapter";
|
|
7
|
+
|
|
8
|
+
// 导出策略配置示例常量
|
|
9
|
+
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
|
|
@@ -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
|
-
/**
|
|
45
|
-
|
|
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
|
|
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
|
|
198
|
-
var
|
|
199
|
-
|
|
200
|
-
|
|
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:
|
|
209
|
-
'Tenant-Id':
|
|
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
|
-
/**
|
|
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
|
|
241
|
-
var
|
|
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
|
-
|
|
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
|
-
},
|
|
225
|
+
}, true);
|
|
298
226
|
case 2:
|
|
299
|
-
response =
|
|
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
|
-
|
|
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
|
|
233
|
+
case 5:
|
|
307
234
|
raw = response.data['documents.invoice_template'];
|
|
308
235
|
documentId = resolveInvoiceDocumentId(raw);
|
|
309
236
|
if (!documentId) {
|
|
310
|
-
|
|
237
|
+
_context3.next = 9;
|
|
311
238
|
break;
|
|
312
239
|
}
|
|
313
|
-
return
|
|
314
|
-
case
|
|
240
|
+
return _context3.abrupt("return", this.fetchInvoiceTemplateDocument(documentId, true));
|
|
241
|
+
case 9:
|
|
315
242
|
if (!(raw == null || typeof raw === 'string' && !raw.trim())) {
|
|
316
|
-
|
|
243
|
+
_context3.next = 11;
|
|
317
244
|
break;
|
|
318
245
|
}
|
|
319
|
-
return
|
|
320
|
-
case
|
|
246
|
+
return _context3.abrupt("return", getDefaultInvoiceTemplateSettings());
|
|
247
|
+
case 11:
|
|
321
248
|
if (!isLegacyInvoiceTemplate(raw)) {
|
|
322
|
-
|
|
249
|
+
_context3.next = 13;
|
|
323
250
|
break;
|
|
324
251
|
}
|
|
325
|
-
return
|
|
326
|
-
case
|
|
252
|
+
return _context3.abrupt("return", normalizeInvoiceTemplateSettings(response.data));
|
|
253
|
+
case 13:
|
|
327
254
|
throw new Error('Cloud Invoice template identifier is invalid');
|
|
328
|
-
case
|
|
255
|
+
case 14:
|
|
329
256
|
case "end":
|
|
330
|
-
return
|
|
257
|
+
return _context3.stop();
|
|
331
258
|
}
|
|
332
|
-
},
|
|
259
|
+
}, _callee3, this);
|
|
333
260
|
}));
|
|
334
|
-
function
|
|
335
|
-
return
|
|
261
|
+
function loadCloudInvoiceTemplate(_x4) {
|
|
262
|
+
return _loadCloudInvoiceTemplate.apply(this, arguments);
|
|
336
263
|
}
|
|
337
|
-
return
|
|
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
|
|
302
|
+
var _ensureInvoiceTemplateSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(target, openDataConfig) {
|
|
376
303
|
var normalizedTarget, config, fetchRevision, resolved;
|
|
377
|
-
return _regeneratorRuntime().wrap(function
|
|
378
|
-
while (1) switch (
|
|
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
|
-
|
|
318
|
+
_context4.next = 5;
|
|
392
319
|
break;
|
|
393
320
|
}
|
|
394
|
-
return
|
|
321
|
+
return _context4.abrupt("return", getDefaultInvoiceTemplateSettings());
|
|
395
322
|
case 5:
|
|
396
323
|
fetchRevision = this.fetchRevision;
|
|
397
|
-
|
|
324
|
+
_context4.next = 8;
|
|
398
325
|
return this.resolveInvoiceTemplateSettings(config, normalizedTarget);
|
|
399
326
|
case 8:
|
|
400
|
-
resolved =
|
|
327
|
+
resolved = _context4.sent;
|
|
401
328
|
if (!(fetchRevision !== this.fetchRevision || this.store.data !== config)) {
|
|
402
|
-
|
|
329
|
+
_context4.next = 11;
|
|
403
330
|
break;
|
|
404
331
|
}
|
|
405
|
-
return
|
|
332
|
+
return _context4.abrupt("return", getDefaultInvoiceTemplateSettings());
|
|
406
333
|
case 11:
|
|
407
334
|
this.commitInvoiceTemplateSettings(normalizedTarget, resolved);
|
|
408
|
-
return
|
|
335
|
+
return _context4.abrupt("return", normalizeRawInvoiceTemplateSettings(resolved.settings));
|
|
409
336
|
case 13:
|
|
410
337
|
case "end":
|
|
411
|
-
return
|
|
338
|
+
return _context4.stop();
|
|
412
339
|
}
|
|
413
|
-
},
|
|
340
|
+
}, _callee4, this);
|
|
414
341
|
}));
|
|
415
|
-
function ensureInvoiceTemplateSettings(
|
|
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
|
|
432
|
-
var
|
|
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
|
|
435
|
-
while (1) switch (
|
|
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
|
-
|
|
365
|
+
_context5.next = 2;
|
|
439
366
|
break;
|
|
440
367
|
}
|
|
441
|
-
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
|
-
|
|
377
|
+
_context5.next = 6;
|
|
451
378
|
break;
|
|
452
379
|
}
|
|
453
|
-
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
|
-
|
|
388
|
+
_context5.next = 9;
|
|
462
389
|
break;
|
|
463
390
|
}
|
|
464
|
-
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
|
-
|
|
399
|
+
_context5.next = 12;
|
|
473
400
|
break;
|
|
474
401
|
}
|
|
475
|
-
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
|
-
|
|
412
|
+
_this2.logInvoiceTemplateDocumentFallback(error, target, documentId);
|
|
486
413
|
return getDefaultInvoiceTemplateSettings();
|
|
487
414
|
}).then(function (settings) {
|
|
488
415
|
var normalized = normalizeRawInvoiceTemplateSettings(settings);
|
|
489
|
-
if (cacheRevision ===
|
|
490
|
-
|
|
416
|
+
if (cacheRevision === _this2.invoiceTemplateCacheRevision) {
|
|
417
|
+
_this2.invoiceTemplateDocumentCache.set(cacheKey, normalized);
|
|
491
418
|
}
|
|
492
419
|
return normalized;
|
|
493
420
|
}).finally(function () {
|
|
494
|
-
if (
|
|
495
|
-
|
|
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
|
-
|
|
427
|
+
_context5.next = 16;
|
|
501
428
|
return request;
|
|
502
429
|
case 16:
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
return
|
|
507
|
-
settings:
|
|
508
|
-
documentId:
|
|
509
|
-
cacheKey:
|
|
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
|
|
440
|
+
return _context5.stop();
|
|
514
441
|
}
|
|
515
|
-
},
|
|
442
|
+
}, _callee5, this);
|
|
516
443
|
}));
|
|
517
|
-
function resolveInvoiceTemplateSettings(
|
|
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$
|
|
526
|
-
var getData = (_this$
|
|
527
|
-
return JSON.stringify([(
|
|
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
|
|
459
|
+
var _fetchInvoiceTemplateDocument = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(documentId) {
|
|
533
460
|
var strict,
|
|
534
461
|
response,
|
|
535
462
|
document,
|
|
536
|
-
|
|
537
|
-
return _regeneratorRuntime().wrap(function
|
|
538
|
-
while (1) switch (
|
|
463
|
+
_args6 = arguments;
|
|
464
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
465
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
539
466
|
case 0:
|
|
540
|
-
strict =
|
|
541
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
507
|
+
return _context6.abrupt("return", normalizeRawInvoiceTemplateSettings(document.data.template_settings));
|
|
581
508
|
case 14:
|
|
582
509
|
case "end":
|
|
583
|
-
return
|
|
510
|
+
return _context6.stop();
|
|
584
511
|
}
|
|
585
|
-
},
|
|
512
|
+
}, _callee6, this);
|
|
586
513
|
}));
|
|
587
|
-
function fetchInvoiceTemplateDocument(
|
|
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;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -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;
|