@pisell/pisellos 2.1.178 → 2.1.179

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.
@@ -1463,7 +1463,7 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1463
1463
  return 1;
1464
1464
  };
1465
1465
  return function (payload, _ref3) {
1466
- var _ref4, _tempOrder$resource_i, _tempOrder$metadata, _ref5, _pickOriginal, _resourceState$table_2, _resourceState$relati, _pickFirstCustomCapac;
1466
+ var _ref4, _tempOrder$resource_i, _tempOrder$metadata, _resourceState$table_2, _this5$core, _coreState$core, _ref5, _ref6, _ref7, _ref8, _pickFromCandidates, _resourceState$table_3, _resourceState$relati, _pickFirstCustomCapac;
1467
1467
  var bookingUuid = _ref3.bookingUuid,
1468
1468
  tempOrder = _ref3.tempOrder;
1469
1469
  var resourceId = String((_ref4 = (_tempOrder$resource_i = tempOrder.resource_id) !== null && _tempOrder$resource_i !== void 0 ? _tempOrder$resource_i : resourceState === null || resourceState === void 0 ? void 0 : resourceState.relationId) !== null && _ref4 !== void 0 ? _ref4 : '').trim();
@@ -1477,14 +1477,46 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1477
1477
  var rawCollectPax = (_tempOrder$metadata = tempOrder.metadata) === null || _tempOrder$metadata === void 0 ? void 0 : _tempOrder$metadata.collect_pax;
1478
1478
  var hasExplicitCollectPax = rawCollectPax !== null && rawCollectPax !== undefined && rawCollectPax !== '';
1479
1479
  var bookingCapacityValue = resolveBookingCapacityValue();
1480
- var pickOriginal = function pickOriginal(value) {
1481
- if (value && _typeof(value) === 'object' && !Array.isArray(value)) {
1482
- var original = value.original;
1483
- return typeof original === 'string' && original.length > 0 ? original : undefined;
1480
+ var resourceNameCandidates = [tempOrder.table_number, resourceState === null || resourceState === void 0 || (_resourceState$table_2 = resourceState.table_form_record) === null || _resourceState$table_2 === void 0 ? void 0 : _resourceState$table_2.name];
1481
+ var toNonEmptyString = function toNonEmptyString(value) {
1482
+ return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
1483
+ };
1484
+ var toNameMap = function toNameMap(value) {
1485
+ return value && _typeof(value) === 'object' && !Array.isArray(value) ? value : undefined;
1486
+ };
1487
+ var pickFromCandidates = function pickFromCandidates(picker) {
1488
+ for (var _i4 = 0, _resourceNameCandidat = resourceNameCandidates; _i4 < _resourceNameCandidat.length; _i4++) {
1489
+ var candidate = _resourceNameCandidat[_i4];
1490
+ var resolved = picker(candidate);
1491
+ if (resolved !== undefined) return resolved;
1492
+ }
1493
+ return undefined;
1494
+ };
1495
+ var pickDirectOrOriginal = function pickDirectOrOriginal(value) {
1496
+ var _toNonEmptyString, _toNameMap;
1497
+ return (_toNonEmptyString = toNonEmptyString(value)) !== null && _toNonEmptyString !== void 0 ? _toNonEmptyString : toNonEmptyString((_toNameMap = toNameMap(value)) === null || _toNameMap === void 0 ? void 0 : _toNameMap.original);
1498
+ };
1499
+ var pickLocalized = function pickLocalized(value, locale) {
1500
+ var _toNameMap2;
1501
+ return toNonEmptyString((_toNameMap2 = toNameMap(value)) === null || _toNameMap2 === void 0 ? void 0 : _toNameMap2[locale]);
1502
+ };
1503
+ var pickFirstNonEmpty = function pickFirstNonEmpty(value) {
1504
+ var nameMap = toNameMap(value);
1505
+ if (!nameMap) return undefined;
1506
+ for (var _i5 = 0, _Object$values = Object.values(nameMap); _i5 < _Object$values.length; _i5++) {
1507
+ var candidate = _Object$values[_i5];
1508
+ var resolved = toNonEmptyString(candidate);
1509
+ if (resolved !== undefined) return resolved;
1484
1510
  }
1485
1511
  return undefined;
1486
1512
  };
1487
- var mainField = (_ref5 = (_pickOriginal = pickOriginal(tempOrder.table_number)) !== null && _pickOriginal !== void 0 ? _pickOriginal : pickOriginal(resourceState === null || resourceState === void 0 || (_resourceState$table_2 = resourceState.table_form_record) === null || _resourceState$table_2 === void 0 ? void 0 : _resourceState$table_2.name)) !== null && _ref5 !== void 0 ? _ref5 : '';
1513
+ var coreState = (_this5$core = _this5.core) === null || _this5$core === void 0 || (_this5$core = _this5$core.getPlugin('shopStore')) === null || _this5$core === void 0 ? void 0 : _this5$core.get('core');
1514
+ var activeLocale = String((coreState === null || coreState === void 0 ? void 0 : coreState.translateLocale) || (coreState === null || coreState === void 0 || (_coreState$core = coreState.core) === null || _coreState$core === void 0 || (_coreState$core = _coreState$core.shop) === null || _coreState$core === void 0 ? void 0 : _coreState$core.primary_locale) || 'en');
1515
+ var mainField = (_ref5 = (_ref6 = (_ref7 = (_ref8 = (_pickFromCandidates = pickFromCandidates(pickDirectOrOriginal)) !== null && _pickFromCandidates !== void 0 ? _pickFromCandidates : toNonEmptyString(resourceState === null || resourceState === void 0 || (_resourceState$table_3 = resourceState.table_form_record) === null || _resourceState$table_3 === void 0 ? void 0 : _resourceState$table_3.main_field)) !== null && _ref8 !== void 0 ? _ref8 : pickFromCandidates(function (value) {
1516
+ return pickLocalized(value, activeLocale);
1517
+ })) !== null && _ref7 !== void 0 ? _ref7 : pickFromCandidates(function (value) {
1518
+ return pickLocalized(value, 'en');
1519
+ })) !== null && _ref6 !== void 0 ? _ref6 : pickFromCandidates(pickFirstNonEmpty)) !== null && _ref5 !== void 0 ? _ref5 : '';
1488
1520
  var resourceEntry = resourceState && resourceId ? {
1489
1521
  relation_type: 'form',
1490
1522
  like_status: 'common',
@@ -1528,9 +1560,9 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
1528
1560
  var nextProducts = _toConsumableArray(payload.products || []);
1529
1561
  // 加餐(已有 order_id)走 scanOrderMore,原单已含 booking 规则行,勿再追加虚拟规则商品
1530
1562
  if (ruleProduct && ruleProductUid && !tempOrder.order_id) {
1531
- var _ruleProduct$price, _ref6, _ruleProduct$original, _ruleProduct$is_gst;
1563
+ var _ruleProduct$price, _ref9, _ruleProduct$original, _ruleProduct$is_gst;
1532
1564
  var sellingPrice = String((_ruleProduct$price = ruleProduct.price) !== null && _ruleProduct$price !== void 0 ? _ruleProduct$price : '0.00');
1533
- var originalPrice = String((_ref6 = (_ruleProduct$original = ruleProduct.original_price) !== null && _ruleProduct$original !== void 0 ? _ruleProduct$original : ruleProduct.price) !== null && _ref6 !== void 0 ? _ref6 : '0.00');
1565
+ var originalPrice = String((_ref9 = (_ruleProduct$original = ruleProduct.original_price) !== null && _ruleProduct$original !== void 0 ? _ruleProduct$original : ruleProduct.price) !== null && _ref9 !== void 0 ? _ref9 : '0.00');
1534
1566
  nextProducts.push({
1535
1567
  product_id: ruleProduct.id,
1536
1568
  product_variant_id: 0,
@@ -2003,16 +2035,16 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2003
2035
  var rawProductId = (_node$product_id = node.product_id) !== null && _node$product_id !== void 0 ? _node$product_id : node.id;
2004
2036
  var productId = Number(rawProductId);
2005
2037
  if (Number.isFinite(productId) && productId > 0) {
2006
- var _ref7, _node$product_variant;
2007
- var productVariantId = Number((_ref7 = (_node$product_variant = node.product_variant_id) !== null && _node$product_variant !== void 0 ? _node$product_variant : node.variant_id) !== null && _ref7 !== void 0 ? _ref7 : 0);
2038
+ var _ref10, _node$product_variant;
2039
+ var productVariantId = Number((_ref10 = (_node$product_variant = node.product_variant_id) !== null && _node$product_variant !== void 0 ? _node$product_variant : node.variant_id) !== null && _ref10 !== void 0 ? _ref10 : 0);
2008
2040
  var normalizedVariantId = Number.isNaN(productVariantId) ? 0 : productVariantId;
2009
2041
  var key = buildProductKey(productId, normalizedVariantId);
2010
2042
  if (!sourceMap.has(key)) {
2011
2043
  sourceMap.set(key, node);
2012
2044
  }
2013
2045
  }
2014
- for (var _i4 = 0, _Object$values = Object.values(node); _i4 < _Object$values.length; _i4++) {
2015
- var childValue = _Object$values[_i4];
2046
+ for (var _i6 = 0, _Object$values2 = Object.values(node); _i6 < _Object$values2.length; _i6++) {
2047
+ var childValue = _Object$values2[_i6];
2016
2048
  if (childValue && _typeof(childValue) === 'object') {
2017
2049
  collectFromValue(childValue);
2018
2050
  }
@@ -2528,18 +2560,18 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2528
2560
  }, {
2529
2561
  key: "checkResourceSchedule",
2530
2562
  value: function checkResourceSchedule(formRecord) {
2531
- var _this$core$getPlugin, _this$store$schedule, _coreState$core, _coreState$core2;
2563
+ var _this$core$getPlugin, _this$store$schedule, _coreState$core2, _coreState$core3;
2532
2564
  var ids = formRecord === null || formRecord === void 0 ? void 0 : formRecord.schedule;
2533
2565
  if (!Array.isArray(ids) || !ids.length) return null;
2534
2566
  var coreState = (_this$core$getPlugin = this.core.getPlugin('shopStore')) === null || _this$core$getPlugin === void 0 ? void 0 : _this$core$getPlugin.get('core');
2535
2567
  var schedules = ((_this$store$schedule = this.store.schedule) === null || _this$store$schedule === void 0 ? void 0 : _this$store$schedule.getScheduleListByIds(ids.map(Number))) || [];
2536
2568
  var result = evaluateResourceSchedules({
2537
2569
  schedules: schedules,
2538
- timeZone: coreState === null || coreState === void 0 || (_coreState$core = coreState.core) === null || _coreState$core === void 0 || (_coreState$core = _coreState$core.shop) === null || _coreState$core === void 0 ? void 0 : _coreState$core.timezone,
2570
+ timeZone: coreState === null || coreState === void 0 || (_coreState$core2 = coreState.core) === null || _coreState$core2 === void 0 || (_coreState$core2 = _coreState$core2.shop) === null || _coreState$core2 === void 0 ? void 0 : _coreState$core2.timezone,
2539
2571
  now: new Date()
2540
2572
  });
2541
2573
  if (result.available) return null;
2542
- var locale = String((coreState === null || coreState === void 0 ? void 0 : coreState.translateLocale) || (coreState === null || coreState === void 0 || (_coreState$core2 = coreState.core) === null || _coreState$core2 === void 0 || (_coreState$core2 = _coreState$core2.shop) === null || _coreState$core2 === void 0 ? void 0 : _coreState$core2.primary_locale) || 'en').toLowerCase();
2574
+ var locale = String((coreState === null || coreState === void 0 ? void 0 : coreState.translateLocale) || (coreState === null || coreState === void 0 || (_coreState$core3 = coreState.core) === null || _coreState$core3 === void 0 || (_coreState$core3 = _coreState$core3.shop) === null || _coreState$core3 === void 0 ? void 0 : _coreState$core3.primary_locale) || 'en').toLowerCase();
2543
2575
  var errorTips = locale === 'zh-hk' || locale === 'zh-tw' ? '目前桌檯不在可用時段,請聯絡工作人員。' : locale.startsWith('zh') ? '当前桌台不在可用时段,请联系工作人员。' : 'This table is outside its available hours. Please contact staff.';
2544
2576
  return {
2545
2577
  mode: 'resource_block',
@@ -3252,14 +3284,14 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
3252
3284
  key: "setOtherParams",
3253
3285
  value: function () {
3254
3286
  var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
3255
- var _ref9,
3256
- _ref9$cover,
3287
+ var _ref12,
3288
+ _ref12$cover,
3257
3289
  cover,
3258
3290
  _args41 = arguments;
3259
3291
  return _regeneratorRuntime().wrap(function _callee41$(_context41) {
3260
3292
  while (1) switch (_context41.prev = _context41.next) {
3261
3293
  case 0:
3262
- _ref9 = _args41.length > 1 && _args41[1] !== undefined ? _args41[1] : {}, _ref9$cover = _ref9.cover, cover = _ref9$cover === void 0 ? false : _ref9$cover;
3294
+ _ref12 = _args41.length > 1 && _args41[1] !== undefined ? _args41[1] : {}, _ref12$cover = _ref12.cover, cover = _ref12$cover === void 0 ? false : _ref12$cover;
3263
3295
  if (cover) {
3264
3296
  this.otherParams = params;
3265
3297
  } else {
@@ -3410,13 +3442,13 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
3410
3442
  key: "syncAdditionalOrderFromResource",
3411
3443
  value: function () {
3412
3444
  var _syncAdditionalOrderFromResource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(resourceId) {
3413
- var _ref10, _ref11, _ref12, _this$store$resource3, _this$store$resource4, _occupyDetails$2, _this$store$resource5, _this$otherParams18, _this$store$order9;
3445
+ var _ref13, _ref14, _ref15, _this$store$resource3, _this$store$resource4, _occupyDetails$2, _this$store$resource5, _this$otherParams18, _this$store$order9;
3414
3446
  var tempOrder, normalizedResourceId, _result, occupyDetails, occupyDetail, resourceSelectType, allowAddItems, result;
3415
3447
  return _regeneratorRuntime().wrap(function _callee43$(_context43) {
3416
3448
  while (1) switch (_context43.prev = _context43.next) {
3417
3449
  case 0:
3418
3450
  tempOrder = this.ensureTempOrder();
3419
- normalizedResourceId = String((_ref10 = (_ref11 = (_ref12 = resourceId !== null && resourceId !== void 0 ? resourceId : tempOrder.resource_id) !== null && _ref12 !== void 0 ? _ref12 : (_this$store$resource3 = this.store.resource) === null || _this$store$resource3 === void 0 ? void 0 : _this$store$resource3.relationId) !== null && _ref11 !== void 0 ? _ref11 : (_this$store$resource4 = this.store.resource) === null || _this$store$resource4 === void 0 ? void 0 : _this$store$resource4.relation_id) !== null && _ref10 !== void 0 ? _ref10 : '').trim();
3451
+ normalizedResourceId = String((_ref13 = (_ref14 = (_ref15 = resourceId !== null && resourceId !== void 0 ? resourceId : tempOrder.resource_id) !== null && _ref15 !== void 0 ? _ref15 : (_this$store$resource3 = this.store.resource) === null || _this$store$resource3 === void 0 ? void 0 : _this$store$resource3.relationId) !== null && _ref14 !== void 0 ? _ref14 : (_this$store$resource4 = this.store.resource) === null || _this$store$resource4 === void 0 ? void 0 : _this$store$resource4.relation_id) !== null && _ref13 !== void 0 ? _ref13 : '').trim();
3420
3452
  this.logMethodStart('syncAdditionalOrderFromResource', {
3421
3453
  resourceId: normalizedResourceId
3422
3454
  });
@@ -1,49 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/model/strategy/adapter/promotion/index.ts
30
- var promotion_exports = {};
31
- __export(promotion_exports, {
32
- BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
- PromotionAdapter: () => import_adapter.PromotionAdapter,
34
- PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
- X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
- default: () => import_adapter2.default
37
- });
38
- module.exports = __toCommonJS(promotion_exports);
39
- var import_evaluator = require("./evaluator");
40
- var import_adapter = require("./adapter");
41
- var import_adapter2 = __toESM(require("./adapter"));
42
- var import_examples = require("./examples");
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- BUY_X_GET_Y_FREE_STRATEGY,
46
- PromotionAdapter,
47
- PromotionEvaluator,
48
- X_ITEMS_FOR_Y_PRICE_STRATEGY
49
- });
@@ -913,7 +913,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
913
913
  return 1;
914
914
  };
915
915
  return (payload, { bookingUuid, tempOrder }) => {
916
- var _a, _b;
916
+ var _a, _b, _c, _d, _e, _f, _g;
917
917
  const resourceId = String(tempOrder.resource_id ?? (resourceState == null ? void 0 : resourceState.relationId) ?? "").trim();
918
918
  const hasReservationBookingContext = Boolean(
919
919
  ruleProduct && resourceState && resourceId && (tempOrder.relation_id || resourceState.relationId) && (tempOrder.table_form_id || resourceState.tableFormId)
@@ -928,14 +928,44 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
928
928
  const rawCollectPax = (_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax;
929
929
  const hasExplicitCollectPax = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
930
930
  const bookingCapacityValue = resolveBookingCapacityValue();
931
- const pickOriginal = (value) => {
932
- if (value && typeof value === "object" && !Array.isArray(value)) {
933
- const original = value.original;
934
- return typeof original === "string" && original.length > 0 ? original : void 0;
931
+ const resourceNameCandidates = [
932
+ tempOrder.table_number,
933
+ (_b = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _b.name
934
+ ];
935
+ const toNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
936
+ const toNameMap = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
937
+ const pickFromCandidates = (picker) => {
938
+ for (const candidate of resourceNameCandidates) {
939
+ const resolved = picker(candidate);
940
+ if (resolved !== void 0)
941
+ return resolved;
935
942
  }
936
943
  return void 0;
937
944
  };
938
- const mainField = pickOriginal(tempOrder.table_number) ?? pickOriginal((_b = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _b.name) ?? "";
945
+ const pickDirectOrOriginal = (value) => {
946
+ var _a2;
947
+ return toNonEmptyString(value) ?? toNonEmptyString((_a2 = toNameMap(value)) == null ? void 0 : _a2.original);
948
+ };
949
+ const pickLocalized = (value, locale) => {
950
+ var _a2;
951
+ return toNonEmptyString((_a2 = toNameMap(value)) == null ? void 0 : _a2[locale]);
952
+ };
953
+ const pickFirstNonEmpty = (value) => {
954
+ const nameMap = toNameMap(value);
955
+ if (!nameMap)
956
+ return void 0;
957
+ for (const candidate of Object.values(nameMap)) {
958
+ const resolved = toNonEmptyString(candidate);
959
+ if (resolved !== void 0)
960
+ return resolved;
961
+ }
962
+ return void 0;
963
+ };
964
+ const coreState = (_d = (_c = this.core) == null ? void 0 : _c.getPlugin("shopStore")) == null ? void 0 : _d.get("core");
965
+ const activeLocale = String(
966
+ (coreState == null ? void 0 : coreState.translateLocale) || ((_f = (_e = coreState == null ? void 0 : coreState.core) == null ? void 0 : _e.shop) == null ? void 0 : _f.primary_locale) || "en"
967
+ );
968
+ const mainField = pickFromCandidates(pickDirectOrOriginal) ?? toNonEmptyString((_g = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _g.main_field) ?? pickFromCandidates((value) => pickLocalized(value, activeLocale)) ?? pickFromCandidates((value) => pickLocalized(value, "en")) ?? pickFromCandidates(pickFirstNonEmpty) ?? "";
939
969
  const resourceEntry = resourceState && resourceId ? {
940
970
  relation_type: "form",
941
971
  like_status: "common",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.178",
4
+ "version": "2.1.179",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",