@pisell/pisellos 2.3.117 → 2.3.118

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.
@@ -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";
@@ -61,6 +61,7 @@ var LABELS = {
61
61
  remainingAmount: 'Remaining amount',
62
62
  redeemPoints: 'Redeem points',
63
63
  remainingPoints: 'Points balance',
64
+ entitlementRemaining: 'Remaining',
64
65
  table: 'Table',
65
66
  bookingId: 'Booking ID',
66
67
  bookingDateTime: 'Date & time',
@@ -105,6 +106,7 @@ var LABELS = {
105
106
  remainingAmount: '剩余金额',
106
107
  redeemPoints: '本次使用积分',
107
108
  remainingPoints: '积分余额',
109
+ entitlementRemaining: '剩余次数',
108
110
  table: '桌台',
109
111
  bookingId: '预约编号',
110
112
  bookingDateTime: '日期和时间',
@@ -149,6 +151,7 @@ var LABELS = {
149
151
  remainingAmount: '剩餘金額',
150
152
  redeemPoints: '本次使用積分',
151
153
  remainingPoints: '積分餘額',
154
+ entitlementRemaining: '剩餘次數',
152
155
  table: '桌台',
153
156
  bookingId: '預約編號',
154
157
  bookingDateTime: '日期和時間',
@@ -191,6 +194,7 @@ var LABELS = {
191
194
  remainingAmount: '残高',
192
195
  redeemPoints: '利用ポイント',
193
196
  remainingPoints: 'ポイント残高',
197
+ entitlementRemaining: '残り回数',
194
198
  table: 'テーブル',
195
199
  bookingId: '予約ID',
196
200
  bookingDateTime: '日時',
@@ -234,6 +238,7 @@ var LABELS = {
234
238
  remainingAmount: 'Saldo restante',
235
239
  redeemPoints: 'Pontos utilizados',
236
240
  remainingPoints: 'Saldo de pontos',
241
+ entitlementRemaining: 'Utilizações restantes',
237
242
  table: 'Mesa',
238
243
  bookingId: 'ID da reserva',
239
244
  bookingDateTime: 'Data e hora',
@@ -549,7 +554,8 @@ function normalizeProductDiscounts(params) {
549
554
  var title = resolveDiscountTitleWithPercent(discount, locale);
550
555
  var amount = (_ref15 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref15 !== void 0 ? _ref15 : discount.discount_amount;
551
556
  var isMarkup = isManualMarkup(discount);
552
- var totalAmount = new Decimal(toMoneyNumber(amount)).mul(quantity);
557
+ var isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
558
+ var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount ? 1 : quantity);
553
559
  var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
554
560
  return {
555
561
  item: title,
@@ -649,6 +655,9 @@ function buildProductQuantityPriceText(params) {
649
655
  function resolveDiscountTitleWithPercent(discount, locale) {
650
656
  var _discount$discount2, _discount$discount$di, _discount$discount3;
651
657
  var title = resolveDiscountTitle(discount, locale);
658
+ if (getProductWalletDiscountType(discount) === 'entitlement_pass') {
659
+ return title;
660
+ }
652
661
  var percentRaw = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.percent;
653
662
  var cardType = (_discount$discount$di = (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.discount_card_type) !== null && _discount$discount$di !== void 0 ? _discount$discount$di : 'percent';
654
663
  var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
@@ -1540,43 +1549,323 @@ function buildWallets(params) {
1540
1549
  virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
1541
1550
  });
1542
1551
  });
1543
- var displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
1544
- return [].concat(_toConsumableArray(paymentWallets), _toConsumableArray(buildVoucherAssets(params)), _toConsumableArray(buildPointCardSnapshotAssets({
1552
+ var displayedWalletAssetIdentities = collectDisplayedWalletAssetIdentities(displayedWalletPayments);
1553
+ var voucherWallets = buildVoucherAssets(_objectSpread(_objectSpread({}, params), {}, {
1554
+ displayedWalletAssetIdentities: displayedWalletAssetIdentities
1555
+ }));
1556
+ var productDiscountWallets = buildProductDiscountAssets(_objectSpread(_objectSpread({}, params), {}, {
1557
+ displayedWalletAssetIdentities: displayedWalletAssetIdentities
1558
+ }));
1559
+ return [].concat(_toConsumableArray(paymentWallets), voucherWallets, productDiscountWallets, _toConsumableArray(buildPointCardSnapshotAssets({
1545
1560
  order: params.order,
1546
1561
  locale: params.locale,
1547
- displayedWalletPassIds: displayedWalletPassIds
1562
+ displayedWalletAssetIdentities: displayedWalletAssetIdentities
1548
1563
  })), _toConsumableArray(buildVirtualCurrencySnapshotAssets({
1549
1564
  snapshots: virtualCurrencySnapshots.items,
1550
1565
  order: params.order,
1551
1566
  locale: params.locale,
1552
- displayedWalletPassIds: displayedWalletPassIds
1567
+ displayedWalletAssetIdentities: displayedWalletAssetIdentities
1553
1568
  })));
1554
1569
  }
1555
- function collectDisplayedWalletPassIds(payments) {
1556
- var ids = new Set();
1570
+ function collectDisplayedWalletAssetIdentities(payments) {
1571
+ var identities = [];
1557
1572
  payments.forEach(function (payment) {
1558
1573
  var fundRecord = getFundRecord(payment);
1559
- [payment.voucher_id, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id].forEach(function (value) {
1560
- var id = normalizeWalletPassId(value);
1561
- if (id) ids.add(id);
1574
+ var ids = Array.from(new Set([fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id].map(function (value) {
1575
+ return normalizeWalletPassId(value);
1576
+ }).filter(function (value) {
1577
+ return !!value;
1578
+ })));
1579
+ var codes = normalizeWalletAssetCodes(fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.code, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.encoded);
1580
+ if (!ids.length) {
1581
+ registerWalletAssetIdentity(identities, {
1582
+ id: null,
1583
+ codes: codes
1584
+ });
1585
+ return;
1586
+ }
1587
+ ids.forEach(function (id) {
1588
+ registerWalletAssetIdentity(identities, {
1589
+ id: id,
1590
+ codes: codes
1591
+ });
1562
1592
  });
1563
1593
  });
1564
- return ids;
1594
+ return identities;
1595
+ }
1596
+ var PRODUCT_WALLET_DISCOUNT_TYPES = new Set(['good_pass', 'discount_card', 'product_discount_card', 'entitlement_pass']);
1597
+ function buildProductDiscountAssets(params) {
1598
+ var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1599
+ return collectProductWalletDiscountAssets(params.order).flatMap(function (asset) {
1600
+ var _getProductWalletDisc;
1601
+ if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1602
+ id: asset.id,
1603
+ codes: asset.codes
1604
+ })) return [];
1605
+ var name = getProductWalletDiscountName(asset, params.locale);
1606
+ var assetTime = (_getProductWalletDisc = getProductWalletDiscountTime(asset)) !== null && _getProductWalletDisc !== void 0 ? _getProductWalletDisc : fallbackAssetTime;
1607
+ var timeRow = isPresentId(assetTime) ? {
1608
+ item: formatDateTime(assetTime, params.locale),
1609
+ value: ''
1610
+ } : null;
1611
+ if (asset.type === 'entitlement_pass') {
1612
+ var remaining = getProductEntitlementBalance(asset);
1613
+ return [[{
1614
+ item: name,
1615
+ value: ''
1616
+ }].concat(_toConsumableArray(remaining ? [{
1617
+ item: label(params.locale, 'entitlementRemaining'),
1618
+ value: formatEntitlementUses(remaining, params.locale)
1619
+ }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1620
+ }
1621
+ var percent = getProductWalletDiscountPercent(asset);
1622
+ if (percent) {
1623
+ return [[{
1624
+ item: appendPercentToVoucherName(name, percent),
1625
+ value: formatVoucherDiscount(percent, params.locale)
1626
+ }].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
1627
+ }
1628
+ var balance = getProductWalletMoneyBalance(asset);
1629
+ return [[{
1630
+ item: name,
1631
+ value: ''
1632
+ }].concat(_toConsumableArray(balance ? [{
1633
+ item: label(params.locale, 'balance'),
1634
+ value: formatMoney(balance, params.currencySymbol)
1635
+ }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
1636
+ });
1637
+ }
1638
+ function collectProductWalletDiscountAssets(order) {
1639
+ var assets = [];
1640
+ var assetsById = new Map();
1641
+ normalizeArray(order.products).forEach(function (rawProduct) {
1642
+ if (!rawProduct || _typeof(rawProduct) !== 'object') return;
1643
+ visitProductWalletDiscounts(restoreReceiptDiscountHierarchy(rawProduct), assets, assetsById);
1644
+ });
1645
+ return assets;
1646
+ }
1647
+ function visitProductWalletDiscounts(product, assets, assetsById) {
1648
+ normalizeArray(product.discount_list).forEach(function (record) {
1649
+ if (!record || _typeof(record) !== 'object' || Array.isArray(record)) return;
1650
+ var type = getProductWalletDiscountType(record);
1651
+ if (!type) return;
1652
+ var id = getProductWalletDiscountAssetId(record);
1653
+ if (!id) return;
1654
+ var codes = getProductWalletDiscountCodes(record);
1655
+ var existing = assetsById.get(id);
1656
+ if (existing) {
1657
+ existing.records.push(record);
1658
+ existing.codes = Array.from(new Set([].concat(_toConsumableArray(existing.codes), codes)));
1659
+ return;
1660
+ }
1661
+ var asset = {
1662
+ id: id,
1663
+ type: type,
1664
+ codes: codes,
1665
+ records: [record]
1666
+ };
1667
+ assetsById.set(id, asset);
1668
+ assets.push(asset);
1669
+ });
1670
+ for (var _i6 = 0, _arr2 = ['combinations', 'product_bundle', 'bundle']; _i6 < _arr2.length; _i6++) {
1671
+ var childKey = _arr2[_i6];
1672
+ normalizeArray(product[childKey]).forEach(function (child) {
1673
+ if (!child || _typeof(child) !== 'object' || Array.isArray(child)) return;
1674
+ visitProductWalletDiscounts(child, assets, assetsById);
1675
+ });
1676
+ }
1677
+ }
1678
+ function getProductWalletDiscountType(record) {
1679
+ for (var _i7 = 0, _arr3 = [record.tag, record.type, (_record$discount = record.discount) === null || _record$discount === void 0 ? void 0 : _record$discount.tag, (_record$discount2 = record.discount) === null || _record$discount2 === void 0 ? void 0 : _record$discount2.type]; _i7 < _arr3.length; _i7++) {
1680
+ var _record$discount, _record$discount2;
1681
+ var value = _arr3[_i7];
1682
+ var type = stringify(value).trim().toLowerCase();
1683
+ if (PRODUCT_WALLET_DISCOUNT_TYPES.has(type)) return type;
1684
+ }
1685
+ return null;
1686
+ }
1687
+ function getProductWalletDiscountAssetId(record) {
1688
+ for (var _i8 = 0, _arr4 = [(_record$discount3 = record.discount) === null || _record$discount3 === void 0 ? void 0 : _record$discount3.resource_id, record.resource_id, record.id, record.discount_id]; _i8 < _arr4.length; _i8++) {
1689
+ var _record$discount3;
1690
+ var value = _arr4[_i8];
1691
+ var id = normalizeWalletPassId(value);
1692
+ if (id && id !== '0') return id;
1693
+ }
1694
+ return null;
1695
+ }
1696
+ function getProductWalletDiscountCodes(record) {
1697
+ var _record$discount4, _record$discount5;
1698
+ return normalizeWalletAssetCodes(record.code, record.encoded, (_record$discount4 = record.discount) === null || _record$discount4 === void 0 ? void 0 : _record$discount4.code, (_record$discount5 = record.discount) === null || _record$discount5 === void 0 ? void 0 : _record$discount5.encoded);
1699
+ }
1700
+ function getProductWalletDiscountName(asset, locale) {
1701
+ var _iterator4 = _createForOfIteratorHelper(asset.records),
1702
+ _step4;
1703
+ try {
1704
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1705
+ var record = _step4.value;
1706
+ for (var _i9 = 0, _arr5 = [(_record$discount6 = record.discount) === null || _record$discount6 === void 0 ? void 0 : _record$discount6.title, (_record$discount7 = record.discount) === null || _record$discount7 === void 0 ? void 0 : _record$discount7.name, (_record$discount8 = record.discount) === null || _record$discount8 === void 0 ? void 0 : _record$discount8.message, record.product_name, record.format_title, record.title, record.name, record.message]; _i9 < _arr5.length; _i9++) {
1707
+ var _record$discount6, _record$discount7, _record$discount8;
1708
+ var value = _arr5[_i9];
1709
+ var name = getLocalizedValue(value, locale).trim();
1710
+ if (name) return name;
1711
+ }
1712
+ }
1713
+ } catch (err) {
1714
+ _iterator4.e(err);
1715
+ } finally {
1716
+ _iterator4.f();
1717
+ }
1718
+ return asset.codes[0] || label(locale, 'giftCard');
1719
+ }
1720
+ function getProductWalletDiscountTime(asset) {
1721
+ for (var _i10 = 0, _arr6 = ['updated_at', 'created_at', 'collection_time']; _i10 < _arr6.length; _i10++) {
1722
+ var field = _arr6[_i10];
1723
+ var _iterator5 = _createForOfIteratorHelper(asset.records),
1724
+ _step5;
1725
+ try {
1726
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1727
+ var _record$discount9;
1728
+ var record = _step5.value;
1729
+ var value = firstPresentValue(record[field], (_record$discount9 = record.discount) === null || _record$discount9 === void 0 ? void 0 : _record$discount9[field]);
1730
+ if (isPresentId(value)) return value;
1731
+ }
1732
+ } catch (err) {
1733
+ _iterator5.e(err);
1734
+ } finally {
1735
+ _iterator5.f();
1736
+ }
1737
+ }
1738
+ return undefined;
1739
+ }
1740
+ function getProductEntitlementBalance(asset) {
1741
+ var _iterator6 = _createForOfIteratorHelper(asset.records),
1742
+ _step6;
1743
+ try {
1744
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1745
+ var record = _step6.value;
1746
+ var balance = getProductDiscountEntitlementBalance(record);
1747
+ if (balance) return balance;
1748
+ }
1749
+ } catch (err) {
1750
+ _iterator6.e(err);
1751
+ } finally {
1752
+ _iterator6.f();
1753
+ }
1754
+ return null;
1755
+ }
1756
+ function getProductDiscountEntitlementBalance(record) {
1757
+ var _record$metadata, _record$discount10, _record$discount11;
1758
+ return getEntitlementBalance((_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.balance, record.balance, (_record$discount10 = record.discount) === null || _record$discount10 === void 0 || (_record$discount10 = _record$discount10.metadata) === null || _record$discount10 === void 0 ? void 0 : _record$discount10.balance, (_record$discount11 = record.discount) === null || _record$discount11 === void 0 ? void 0 : _record$discount11.balance);
1759
+ }
1760
+ function getEntitlementBalance() {
1761
+ for (var _len3 = arguments.length, values = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
1762
+ values[_key3] = arguments[_key3];
1763
+ }
1764
+ for (var _i11 = 0, _values2 = values; _i11 < _values2.length; _i11++) {
1765
+ var value = _values2[_i11];
1766
+ if (!isNumericAmount(value)) continue;
1767
+ var balance = new Decimal(value);
1768
+ if (balance.isFinite() && balance.isInteger() && balance.gte(0)) {
1769
+ return balance;
1770
+ }
1771
+ }
1772
+ return null;
1773
+ }
1774
+ function formatEntitlementUses(value, locale) {
1775
+ var count = value.toFixed(0);
1776
+ switch (normalizeLocaleKey(locale)) {
1777
+ case 'zh_CN':
1778
+ case 'zh_HK':
1779
+ return "".concat(count, "\u6B21");
1780
+ case 'ja':
1781
+ return "".concat(count, "\u56DE");
1782
+ case 'pt':
1783
+ return "".concat(count, " ").concat(value.eq(1) ? 'utilização' : 'utilizações');
1784
+ default:
1785
+ return "".concat(count, " ").concat(value.eq(1) ? 'use' : 'uses');
1786
+ }
1787
+ }
1788
+ function getProductWalletDiscountPercent(asset) {
1789
+ if (asset.type !== 'discount_card' && asset.type !== 'product_discount_card') return null;
1790
+ var _iterator7 = _createForOfIteratorHelper(asset.records),
1791
+ _step7;
1792
+ try {
1793
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1794
+ var _record$metadata2, _record$discount12, _record$discount13, _record$discount14;
1795
+ var record = _step7.value;
1796
+ var discountType = stringify(firstPresentValue(record.discount_card_type, (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.discount_card_type, (_record$discount12 = record.discount) === null || _record$discount12 === void 0 ? void 0 : _record$discount12.discount_card_type, (_record$discount13 = record.discount) === null || _record$discount13 === void 0 || (_record$discount13 = _record$discount13.metadata) === null || _record$discount13 === void 0 ? void 0 : _record$discount13.discount_card_type)).trim().toLowerCase();
1797
+ if (discountType && discountType !== 'percent' && discountType !== 'percentage') continue;
1798
+ var candidates = [record.percent, (_record$discount14 = record.discount) === null || _record$discount14 === void 0 ? void 0 : _record$discount14.percent];
1799
+ if (discountType === 'percent' || discountType === 'percentage') {
1800
+ var _record$discount15;
1801
+ candidates.push(record.par_value, (_record$discount15 = record.discount) === null || _record$discount15 === void 0 ? void 0 : _record$discount15.par_value);
1802
+ }
1803
+ for (var _i12 = 0, _candidates = candidates; _i12 < _candidates.length; _i12++) {
1804
+ var value = _candidates[_i12];
1805
+ if (!isNumericAmount(value)) continue;
1806
+ var percent = new Decimal(value);
1807
+ if (percent.isFinite() && percent.gt(0) && percent.lte(100)) {
1808
+ return percent;
1809
+ }
1810
+ }
1811
+ }
1812
+ } catch (err) {
1813
+ _iterator7.e(err);
1814
+ } finally {
1815
+ _iterator7.f();
1816
+ }
1817
+ return null;
1818
+ }
1819
+ function getProductWalletMoneyBalance(asset) {
1820
+ var _iterator8 = _createForOfIteratorHelper(asset.records),
1821
+ _step8;
1822
+ try {
1823
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1824
+ var record = _step8.value;
1825
+ for (var _i13 = 0, _arr7 = [(_record$metadata3 = record.metadata) === null || _record$metadata3 === void 0 ? void 0 : _record$metadata3.balance, record.balance, (_record$discount16 = record.discount) === null || _record$discount16 === void 0 || (_record$discount16 = _record$discount16.metadata) === null || _record$discount16 === void 0 ? void 0 : _record$discount16.balance, (_record$discount17 = record.discount) === null || _record$discount17 === void 0 ? void 0 : _record$discount17.balance]; _i13 < _arr7.length; _i13++) {
1826
+ var _record$metadata3, _record$discount16, _record$discount17;
1827
+ var value = _arr7[_i13];
1828
+ if (!isNumericAmount(value)) continue;
1829
+ return Decimal.max(new Decimal(value), 0);
1830
+ }
1831
+ }
1832
+ } catch (err) {
1833
+ _iterator8.e(err);
1834
+ } finally {
1835
+ _iterator8.f();
1836
+ }
1837
+ var _iterator9 = _createForOfIteratorHelper(asset.records),
1838
+ _step9;
1839
+ try {
1840
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1841
+ var _record$discount18, _record$discount19;
1842
+ var _record = _step9.value;
1843
+ var parValue = firstPresentValue(_record.par_value, (_record$discount18 = _record.discount) === null || _record$discount18 === void 0 ? void 0 : _record$discount18.par_value);
1844
+ var usedParValue = firstPresentValue(_record.used_par_value, (_record$discount19 = _record.discount) === null || _record$discount19 === void 0 ? void 0 : _record$discount19.used_par_value);
1845
+ if (!isNumericAmount(parValue) || !isNumericAmount(usedParValue)) continue;
1846
+ return Decimal.max(new Decimal(parValue).minus(new Decimal(usedParValue)), 0);
1847
+ }
1848
+ } catch (err) {
1849
+ _iterator9.e(err);
1850
+ } finally {
1851
+ _iterator9.f();
1852
+ }
1853
+ return null;
1565
1854
  }
1566
1855
  function buildPointCardSnapshotAssets(params) {
1567
1856
  var _params$order$order_m;
1568
1857
  var snapshots = (_params$order$order_m = params.order.order_meta_list) === null || _params$order$order_m === void 0 ? void 0 : _params$order$order_m.point_cards_snapshot;
1569
1858
  if (!Array.isArray(snapshots)) return [];
1570
1859
  var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1571
- var seenSnapshotIds = new Set();
1572
1860
  return snapshots.flatMap(function (snapshot) {
1573
1861
  if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return [];
1574
1862
  var pointCard = snapshot;
1575
1863
  if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
1576
- var id = normalizeWalletPassId(pointCard.id);
1577
- if (!id || seenSnapshotIds.has(id)) return [];
1578
- seenSnapshotIds.add(id);
1579
- if (params.displayedWalletPassIds.has(id)) return [];
1864
+ var assetId = normalizeWalletPassId(pointCard.id);
1865
+ if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1866
+ id: assetId,
1867
+ codes: []
1868
+ })) return [];
1580
1869
  var rows = [{
1581
1870
  item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1582
1871
  value: ''
@@ -1622,8 +1911,8 @@ function collectVirtualCurrencySnapshots(order) {
1622
1911
  }
1623
1912
  function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
1624
1913
  var fundRecord = getFundRecord(payment);
1625
- for (var _i6 = 0, _arr2 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i6 < _arr2.length; _i6++) {
1626
- var value = _arr2[_i6];
1914
+ for (var _i14 = 0, _arr8 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i14 < _arr8.length; _i14++) {
1915
+ var value = _arr8[_i14];
1627
1916
  var id = normalizeWalletPassId(value);
1628
1917
  if (!id) continue;
1629
1918
  var snapshot = snapshotsById.get(id);
@@ -1634,8 +1923,11 @@ function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
1634
1923
  function buildVirtualCurrencySnapshotAssets(params) {
1635
1924
  var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1636
1925
  return params.snapshots.flatMap(function (virtualCurrency) {
1637
- var id = normalizeWalletPassId(virtualCurrency.id);
1638
- if (!id || params.displayedWalletPassIds.has(id)) return [];
1926
+ var assetId = normalizeWalletPassId(virtualCurrency.id);
1927
+ if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1928
+ id: assetId,
1929
+ codes: []
1930
+ })) return [];
1639
1931
  var rows = [{
1640
1932
  item: stringify(virtualCurrency.product_name).trim(),
1641
1933
  value: ''
@@ -1670,8 +1962,8 @@ function getNonEmptyLocalizedValue(value, locale) {
1670
1962
  if (_typeof(value) !== 'object' || Array.isArray(value)) return stringify(value).trim();
1671
1963
  var dashedLocale = locale.replace('_', '-');
1672
1964
  var underscoredLocale = locale.replace('-', '_');
1673
- for (var _i7 = 0, _arr3 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i7 < _arr3.length; _i7++) {
1674
- var candidate = _arr3[_i7];
1965
+ for (var _i15 = 0, _arr9 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i15 < _arr9.length; _i15++) {
1966
+ var candidate = _arr9[_i15];
1675
1967
  var text = stringify(candidate).trim();
1676
1968
  if (text) return text;
1677
1969
  }
@@ -1687,6 +1979,66 @@ function normalizeWalletPassId(value) {
1687
1979
  if (typeof value !== 'string') return null;
1688
1980
  return value.trim() || null;
1689
1981
  }
1982
+ function firstNormalizedWalletAssetId() {
1983
+ for (var _len4 = arguments.length, values = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
1984
+ values[_key4] = arguments[_key4];
1985
+ }
1986
+ for (var _i16 = 0, _values3 = values; _i16 < _values3.length; _i16++) {
1987
+ var value = _values3[_i16];
1988
+ var id = normalizeWalletPassId(value);
1989
+ if (id) return id;
1990
+ }
1991
+ return null;
1992
+ }
1993
+ function normalizeWalletAssetCodes() {
1994
+ for (var _len5 = arguments.length, values = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
1995
+ values[_key5] = arguments[_key5];
1996
+ }
1997
+ return Array.from(new Set(values.map(function (value) {
1998
+ return normalizeWalletPassId(value);
1999
+ }).filter(function (value) {
2000
+ return !!value;
2001
+ })));
2002
+ }
2003
+ function registerWalletAssetIdentity(identities, candidate) {
2004
+ if (!candidate.id && !candidate.codes.length) return;
2005
+ var existing = identities.find(function (identity) {
2006
+ return isSameWalletAssetIdentity(identity, candidate);
2007
+ });
2008
+ if (existing) {
2009
+ mergeWalletAssetIdentity(existing, candidate);
2010
+ return;
2011
+ }
2012
+ identities.push({
2013
+ id: candidate.id,
2014
+ codes: _toConsumableArray(candidate.codes)
2015
+ });
2016
+ }
2017
+ function claimWalletAssetIdentity(identities, candidate) {
2018
+ if (!candidate.id && !candidate.codes.length) return true;
2019
+ var existing = identities.find(function (identity) {
2020
+ return isSameWalletAssetIdentity(identity, candidate);
2021
+ });
2022
+ if (existing) {
2023
+ mergeWalletAssetIdentity(existing, candidate);
2024
+ return false;
2025
+ }
2026
+ identities.push({
2027
+ id: candidate.id,
2028
+ codes: _toConsumableArray(candidate.codes)
2029
+ });
2030
+ return true;
2031
+ }
2032
+ function isSameWalletAssetIdentity(left, right) {
2033
+ if (left.id && right.id) return left.id === right.id;
2034
+ return left.codes.some(function (code) {
2035
+ return right.codes.includes(code);
2036
+ });
2037
+ }
2038
+ function mergeWalletAssetIdentity(target, source) {
2039
+ if (!target.id && source.id) target.id = source.id;
2040
+ target.codes = Array.from(new Set([].concat(_toConsumableArray(target.codes), _toConsumableArray(source.codes))));
2041
+ }
1690
2042
  function getPointCardSnapshotRemainingPoints(snapshot) {
1691
2043
  if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
1692
2044
  return null;
@@ -1694,19 +2046,27 @@ function getPointCardSnapshotRemainingPoints(snapshot) {
1694
2046
  return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
1695
2047
  }
1696
2048
  function buildVoucherAssets(params) {
1697
- var seenVoucherKeys = new Set();
1698
2049
  var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1699
- return normalizeArray(params.order.vouchers).flatMap(function (voucher, index) {
2050
+ return normalizeArray(params.order.vouchers).flatMap(function (voucher) {
1700
2051
  if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
1701
- var voucherKey = getVoucherAssetKey(voucher, index);
1702
- if (seenVoucherKeys.has(voucherKey)) return [];
1703
- seenVoucherKeys.add(voucherKey);
2052
+ if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, getVoucherAssetIdentity(voucher))) return [];
1704
2053
  var name = getVoucherAssetName(voucher, params.locale);
1705
2054
  var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
1706
2055
  var timeRow = isPresentId(assetTime) ? {
1707
2056
  item: formatDateTime(assetTime, params.locale),
1708
2057
  value: ''
1709
2058
  } : null;
2059
+ if (isEntitlementVoucher(voucher)) {
2060
+ var _voucher$metadata;
2061
+ var remaining = getEntitlementBalance((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.balance, voucher.balance);
2062
+ return [[{
2063
+ item: name,
2064
+ value: ''
2065
+ }].concat(_toConsumableArray(remaining ? [{
2066
+ item: label(params.locale, 'entitlementRemaining'),
2067
+ value: formatEntitlementUses(remaining, params.locale)
2068
+ }] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
2069
+ }
1710
2070
  if (isTicketVoucher(voucher)) {
1711
2071
  var validity = getVoucherValidity(voucher, params.locale);
1712
2072
  return [[{
@@ -1735,19 +2095,24 @@ function buildVoucherAssets(params) {
1735
2095
  });
1736
2096
  }
1737
2097
  var TICKET_VOUCHER_TAGS = new Set(['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket']);
2098
+ function isEntitlementVoucher(voucher) {
2099
+ return [voucher.tag, voucher.type].some(function (value) {
2100
+ return stringify(value).trim().toLowerCase() === 'entitlement_pass';
2101
+ });
2102
+ }
1738
2103
  function isTicketVoucher(voucher) {
1739
2104
  return TICKET_VOUCHER_TAGS.has(stringify(voucher.tag).trim().toLowerCase());
1740
2105
  }
1741
2106
  function getVoucherValidity(voucher, locale) {
1742
- var _voucher$metadata, _voucher$metadata2, _voucher$metadata3, _voucher$metadata4, _voucher$metadata5, _voucher$metadata6, _voucher$metadata7, _voucher$metadata8, _voucher$metadata9, _voucher$metadata10, _voucher$start_time, _voucher$metadata11, _voucher$end_time, _voucher$metadata12;
1743
- var availableTime = firstPresentValue(voucher.available_time, voucher.avaliable_time, (_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.available_time, (_voucher$metadata2 = voucher.metadata) === null || _voucher$metadata2 === void 0 ? void 0 : _voucher$metadata2.avaliable_time);
2107
+ var _voucher$metadata2, _voucher$metadata3, _voucher$metadata4, _voucher$metadata5, _voucher$metadata6, _voucher$metadata7, _voucher$metadata8, _voucher$metadata9, _voucher$metadata10, _voucher$metadata11, _voucher$start_time, _voucher$metadata12, _voucher$end_time, _voucher$metadata13;
2108
+ var availableTime = firstPresentValue(voucher.available_time, voucher.avaliable_time, (_voucher$metadata2 = voucher.metadata) === null || _voucher$metadata2 === void 0 ? void 0 : _voucher$metadata2.available_time, (_voucher$metadata3 = voucher.metadata) === null || _voucher$metadata3 === void 0 ? void 0 : _voucher$metadata3.avaliable_time);
1744
2109
  var availableTimeText = formatVoucherAvailableTime(availableTime, locale);
1745
2110
  if (availableTimeText) return availableTimeText;
1746
- var startDate = firstPresentValue(voucher.valid_from, voucher.start_at, voucher.start_date_time, voucher.start_date, (_voucher$metadata3 = voucher.metadata) === null || _voucher$metadata3 === void 0 ? void 0 : _voucher$metadata3.valid_from, (_voucher$metadata4 = voucher.metadata) === null || _voucher$metadata4 === void 0 ? void 0 : _voucher$metadata4.start_at, (_voucher$metadata5 = voucher.metadata) === null || _voucher$metadata5 === void 0 ? void 0 : _voucher$metadata5.start_date);
1747
- var endDate = firstPresentValue(voucher.valid_to, voucher.end_at, voucher.end_date_time, voucher.expire_date, voucher.end_date, voucher.expire_time, (_voucher$metadata6 = voucher.metadata) === null || _voucher$metadata6 === void 0 ? void 0 : _voucher$metadata6.valid_to, (_voucher$metadata7 = voucher.metadata) === null || _voucher$metadata7 === void 0 ? void 0 : _voucher$metadata7.end_at, (_voucher$metadata8 = voucher.metadata) === null || _voucher$metadata8 === void 0 ? void 0 : _voucher$metadata8.expire_date, (_voucher$metadata9 = voucher.metadata) === null || _voucher$metadata9 === void 0 ? void 0 : _voucher$metadata9.end_date, (_voucher$metadata10 = voucher.metadata) === null || _voucher$metadata10 === void 0 ? void 0 : _voucher$metadata10.expire_time);
2111
+ var startDate = firstPresentValue(voucher.valid_from, voucher.start_at, voucher.start_date_time, voucher.start_date, (_voucher$metadata4 = voucher.metadata) === null || _voucher$metadata4 === void 0 ? void 0 : _voucher$metadata4.valid_from, (_voucher$metadata5 = voucher.metadata) === null || _voucher$metadata5 === void 0 ? void 0 : _voucher$metadata5.start_at, (_voucher$metadata6 = voucher.metadata) === null || _voucher$metadata6 === void 0 ? void 0 : _voucher$metadata6.start_date);
2112
+ var endDate = firstPresentValue(voucher.valid_to, voucher.end_at, voucher.end_date_time, voucher.expire_date, voucher.end_date, voucher.expire_time, (_voucher$metadata7 = voucher.metadata) === null || _voucher$metadata7 === void 0 ? void 0 : _voucher$metadata7.valid_to, (_voucher$metadata8 = voucher.metadata) === null || _voucher$metadata8 === void 0 ? void 0 : _voucher$metadata8.end_at, (_voucher$metadata9 = voucher.metadata) === null || _voucher$metadata9 === void 0 ? void 0 : _voucher$metadata9.expire_date, (_voucher$metadata10 = voucher.metadata) === null || _voucher$metadata10 === void 0 ? void 0 : _voucher$metadata10.end_date, (_voucher$metadata11 = voucher.metadata) === null || _voucher$metadata11 === void 0 ? void 0 : _voucher$metadata11.expire_time);
1748
2113
  return formatVoucherValidityRange(startDate, endDate, locale, {
1749
- startTime: (_voucher$start_time = voucher.start_time) !== null && _voucher$start_time !== void 0 ? _voucher$start_time : (_voucher$metadata11 = voucher.metadata) === null || _voucher$metadata11 === void 0 ? void 0 : _voucher$metadata11.start_time,
1750
- endTime: (_voucher$end_time = voucher.end_time) !== null && _voucher$end_time !== void 0 ? _voucher$end_time : (_voucher$metadata12 = voucher.metadata) === null || _voucher$metadata12 === void 0 ? void 0 : _voucher$metadata12.end_time
2114
+ startTime: (_voucher$start_time = voucher.start_time) !== null && _voucher$start_time !== void 0 ? _voucher$start_time : (_voucher$metadata12 = voucher.metadata) === null || _voucher$metadata12 === void 0 ? void 0 : _voucher$metadata12.start_time,
2115
+ endTime: (_voucher$end_time = voucher.end_time) !== null && _voucher$end_time !== void 0 ? _voucher$end_time : (_voucher$metadata13 = voucher.metadata) === null || _voucher$metadata13 === void 0 ? void 0 : _voucher$metadata13.end_time
1751
2116
  });
1752
2117
  }
1753
2118
  function formatVoucherAvailableTime(value, locale) {
@@ -1813,16 +2178,18 @@ function formatVoucherValidityDate(value, locale) {
1813
2178
  text: time ? "".concat(time, " ").concat(date) : date
1814
2179
  };
1815
2180
  }
1816
- function getVoucherAssetKey(voucher, index) {
1817
- var identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
1818
- return identity === undefined ? "voucher-index:".concat(index) : "voucher:".concat(String(identity));
2181
+ function getVoucherAssetIdentity(voucher) {
2182
+ return {
2183
+ id: firstNormalizedWalletAssetId(voucher.voucher_id, voucher.id),
2184
+ codes: normalizeWalletAssetCodes(voucher.code, voucher.encoded)
2185
+ };
1819
2186
  }
1820
2187
  function getVoucherAssetName(voucher, locale) {
1821
2188
  return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
1822
2189
  }
1823
2190
  function getVoucherDiscountPercent(voucher) {
1824
- var _voucher$metadata13;
1825
- var discountType = stringify(((_voucher$metadata13 = voucher.metadata) === null || _voucher$metadata13 === void 0 ? void 0 : _voucher$metadata13.discount_card_type) || voucher.discount_card_type).toLowerCase();
2191
+ var _voucher$metadata14;
2192
+ var discountType = stringify(((_voucher$metadata14 = voucher.metadata) === null || _voucher$metadata14 === void 0 ? void 0 : _voucher$metadata14.discount_card_type) || voucher.discount_card_type).toLowerCase();
1826
2193
  if (discountType !== 'percent' && discountType !== 'percentage') return null;
1827
2194
  var percent = new Decimal(toMoneyNumber(voucher.par_value));
1828
2195
  if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
@@ -1842,6 +2209,12 @@ function formatVoucherDiscount(percent, locale) {
1842
2209
  return normalizedLocale === 'en' ? "Discount ".concat(trimDecimal(percent), "% OFF") : "".concat(trimDecimal(percent), "% OFF");
1843
2210
  }
1844
2211
  function getVoucherBalance(voucher) {
2212
+ for (var _i17 = 0, _arr10 = [(_voucher$metadata15 = voucher.metadata) === null || _voucher$metadata15 === void 0 ? void 0 : _voucher$metadata15.balance, voucher.balance]; _i17 < _arr10.length; _i17++) {
2213
+ var _voucher$metadata15;
2214
+ var value = _arr10[_i17];
2215
+ if (!isNumericAmount(value)) continue;
2216
+ return Decimal.max(new Decimal(value), 0);
2217
+ }
1845
2218
  var parValue = new Decimal(toMoneyNumber(voucher.par_value));
1846
2219
  var usedParValue = new Decimal(toMoneyNumber(voucher.used_par_value));
1847
2220
  return Decimal.max(parValue.minus(usedParValue), 0);
@@ -1 +1,46 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _examples.BUY_X_GET_Y_FREE_STRATEGY;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _examples.ITEM_REWARD_STRATEGY;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "PromotionAdapter", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _adapter.PromotionAdapter;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "PromotionEvaluator", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _evaluator.PromotionEvaluator;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "default", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _adapter.default;
40
+ }
41
+ });
42
+ var _evaluator = require("./evaluator");
43
+ var _adapter = _interopRequireWildcard(require("./adapter"));
44
+ var _examples = require("./examples");
45
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
46
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -49,6 +49,7 @@ const LABELS = {
49
49
  remainingAmount: 'Remaining amount',
50
50
  redeemPoints: 'Redeem points',
51
51
  remainingPoints: 'Points balance',
52
+ entitlementRemaining: 'Remaining',
52
53
  table: 'Table',
53
54
  bookingId: 'Booking ID',
54
55
  bookingDateTime: 'Date & time',
@@ -93,6 +94,7 @@ const LABELS = {
93
94
  remainingAmount: '剩余金额',
94
95
  redeemPoints: '本次使用积分',
95
96
  remainingPoints: '积分余额',
97
+ entitlementRemaining: '剩余次数',
96
98
  table: '桌台',
97
99
  bookingId: '预约编号',
98
100
  bookingDateTime: '日期和时间',
@@ -137,6 +139,7 @@ const LABELS = {
137
139
  remainingAmount: '剩餘金額',
138
140
  redeemPoints: '本次使用積分',
139
141
  remainingPoints: '積分餘額',
142
+ entitlementRemaining: '剩餘次數',
140
143
  table: '桌台',
141
144
  bookingId: '預約編號',
142
145
  bookingDateTime: '日期和時間',
@@ -179,6 +182,7 @@ const LABELS = {
179
182
  remainingAmount: '残高',
180
183
  redeemPoints: '利用ポイント',
181
184
  remainingPoints: 'ポイント残高',
185
+ entitlementRemaining: '残り回数',
182
186
  table: 'テーブル',
183
187
  bookingId: '予約ID',
184
188
  bookingDateTime: '日時',
@@ -222,6 +226,7 @@ const LABELS = {
222
226
  remainingAmount: 'Saldo restante',
223
227
  redeemPoints: 'Pontos utilizados',
224
228
  remainingPoints: 'Saldo de pontos',
229
+ entitlementRemaining: 'Utilizações restantes',
225
230
  table: 'Mesa',
226
231
  bookingId: 'ID da reserva',
227
232
  bookingDateTime: 'Data e hora',
@@ -522,7 +527,8 @@ function normalizeProductDiscounts(params) {
522
527
  const title = resolveDiscountTitleWithPercent(discount, locale);
523
528
  const amount = discount.amount ?? discount.value ?? discount.discount_amount;
524
529
  const isMarkup = isManualMarkup(discount);
525
- const totalAmount = new _decimal.default(toMoneyNumber(amount)).mul(quantity);
530
+ const isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
531
+ const totalAmount = new _decimal.default(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount ? 1 : quantity);
526
532
  const formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
527
533
  return {
528
534
  item: title,
@@ -615,6 +621,9 @@ function buildProductQuantityPriceText(params) {
615
621
  }
616
622
  function resolveDiscountTitleWithPercent(discount, locale) {
617
623
  const title = resolveDiscountTitle(discount, locale);
624
+ if (getProductWalletDiscountType(discount) === 'entitlement_pass') {
625
+ return title;
626
+ }
618
627
  const percentRaw = discount.discount?.percent;
619
628
  const cardType = discount.discount?.discount_card_type ?? 'percent';
620
629
  const percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
@@ -1427,42 +1436,244 @@ function buildWallets(params) {
1427
1436
  virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
1428
1437
  });
1429
1438
  });
1430
- const displayedWalletPassIds = collectDisplayedWalletPassIds(displayedWalletPayments);
1431
- return [...paymentWallets, ...buildVoucherAssets(params), ...buildPointCardSnapshotAssets({
1439
+ const displayedWalletAssetIdentities = collectDisplayedWalletAssetIdentities(displayedWalletPayments);
1440
+ const voucherWallets = buildVoucherAssets({
1441
+ ...params,
1442
+ displayedWalletAssetIdentities
1443
+ });
1444
+ const productDiscountWallets = buildProductDiscountAssets({
1445
+ ...params,
1446
+ displayedWalletAssetIdentities
1447
+ });
1448
+ return [...paymentWallets, ...voucherWallets, ...productDiscountWallets, ...buildPointCardSnapshotAssets({
1432
1449
  order: params.order,
1433
1450
  locale: params.locale,
1434
- displayedWalletPassIds
1451
+ displayedWalletAssetIdentities
1435
1452
  }), ...buildVirtualCurrencySnapshotAssets({
1436
1453
  snapshots: virtualCurrencySnapshots.items,
1437
1454
  order: params.order,
1438
1455
  locale: params.locale,
1439
- displayedWalletPassIds
1456
+ displayedWalletAssetIdentities
1440
1457
  })];
1441
1458
  }
1442
- function collectDisplayedWalletPassIds(payments) {
1443
- const ids = new Set();
1459
+ function collectDisplayedWalletAssetIdentities(payments) {
1460
+ const identities = [];
1444
1461
  payments.forEach(payment => {
1445
1462
  const fundRecord = getFundRecord(payment);
1446
- [payment.voucher_id, fundRecord?.voucher_id].forEach(value => {
1447
- const id = normalizeWalletPassId(value);
1448
- if (id) ids.add(id);
1463
+ const ids = Array.from(new Set([fundRecord?.voucher_id, payment.voucher_id].map(value => normalizeWalletPassId(value)).filter(value => !!value)));
1464
+ const codes = normalizeWalletAssetCodes(fundRecord?.code, fundRecord?.encoded);
1465
+ if (!ids.length) {
1466
+ registerWalletAssetIdentity(identities, {
1467
+ id: null,
1468
+ codes
1469
+ });
1470
+ return;
1471
+ }
1472
+ ids.forEach(id => {
1473
+ registerWalletAssetIdentity(identities, {
1474
+ id,
1475
+ codes
1476
+ });
1449
1477
  });
1450
1478
  });
1451
- return ids;
1479
+ return identities;
1480
+ }
1481
+ const PRODUCT_WALLET_DISCOUNT_TYPES = new Set(['good_pass', 'discount_card', 'product_discount_card', 'entitlement_pass']);
1482
+ function buildProductDiscountAssets(params) {
1483
+ const fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1484
+ return collectProductWalletDiscountAssets(params.order).flatMap(asset => {
1485
+ if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1486
+ id: asset.id,
1487
+ codes: asset.codes
1488
+ })) return [];
1489
+ const name = getProductWalletDiscountName(asset, params.locale);
1490
+ const assetTime = getProductWalletDiscountTime(asset) ?? fallbackAssetTime;
1491
+ const timeRow = isPresentId(assetTime) ? {
1492
+ item: formatDateTime(assetTime, params.locale),
1493
+ value: ''
1494
+ } : null;
1495
+ if (asset.type === 'entitlement_pass') {
1496
+ const remaining = getProductEntitlementBalance(asset);
1497
+ return [[{
1498
+ item: name,
1499
+ value: ''
1500
+ }, ...(remaining ? [{
1501
+ item: label(params.locale, 'entitlementRemaining'),
1502
+ value: formatEntitlementUses(remaining, params.locale)
1503
+ }] : []), ...(timeRow ? [timeRow] : [])]];
1504
+ }
1505
+ const percent = getProductWalletDiscountPercent(asset);
1506
+ if (percent) {
1507
+ return [[{
1508
+ item: appendPercentToVoucherName(name, percent),
1509
+ value: formatVoucherDiscount(percent, params.locale)
1510
+ }, ...(timeRow ? [timeRow] : [])]];
1511
+ }
1512
+ const balance = getProductWalletMoneyBalance(asset);
1513
+ return [[{
1514
+ item: name,
1515
+ value: ''
1516
+ }, ...(balance ? [{
1517
+ item: label(params.locale, 'balance'),
1518
+ value: formatMoney(balance, params.currencySymbol)
1519
+ }] : []), ...(timeRow ? [timeRow] : [])]];
1520
+ });
1521
+ }
1522
+ function collectProductWalletDiscountAssets(order) {
1523
+ const assets = [];
1524
+ const assetsById = new Map();
1525
+ normalizeArray(order.products).forEach(rawProduct => {
1526
+ if (!rawProduct || typeof rawProduct !== 'object') return;
1527
+ visitProductWalletDiscounts(restoreReceiptDiscountHierarchy(rawProduct), assets, assetsById);
1528
+ });
1529
+ return assets;
1530
+ }
1531
+ function visitProductWalletDiscounts(product, assets, assetsById) {
1532
+ normalizeArray(product.discount_list).forEach(record => {
1533
+ if (!record || typeof record !== 'object' || Array.isArray(record)) return;
1534
+ const type = getProductWalletDiscountType(record);
1535
+ if (!type) return;
1536
+ const id = getProductWalletDiscountAssetId(record);
1537
+ if (!id) return;
1538
+ const codes = getProductWalletDiscountCodes(record);
1539
+ const existing = assetsById.get(id);
1540
+ if (existing) {
1541
+ existing.records.push(record);
1542
+ existing.codes = Array.from(new Set([...existing.codes, ...codes]));
1543
+ return;
1544
+ }
1545
+ const asset = {
1546
+ id,
1547
+ type,
1548
+ codes,
1549
+ records: [record]
1550
+ };
1551
+ assetsById.set(id, asset);
1552
+ assets.push(asset);
1553
+ });
1554
+ for (const childKey of ['combinations', 'product_bundle', 'bundle']) {
1555
+ normalizeArray(product[childKey]).forEach(child => {
1556
+ if (!child || typeof child !== 'object' || Array.isArray(child)) return;
1557
+ visitProductWalletDiscounts(child, assets, assetsById);
1558
+ });
1559
+ }
1560
+ }
1561
+ function getProductWalletDiscountType(record) {
1562
+ for (const value of [record.tag, record.type, record.discount?.tag, record.discount?.type]) {
1563
+ const type = stringify(value).trim().toLowerCase();
1564
+ if (PRODUCT_WALLET_DISCOUNT_TYPES.has(type)) return type;
1565
+ }
1566
+ return null;
1567
+ }
1568
+ function getProductWalletDiscountAssetId(record) {
1569
+ for (const value of [record.discount?.resource_id, record.resource_id, record.id, record.discount_id]) {
1570
+ const id = normalizeWalletPassId(value);
1571
+ if (id && id !== '0') return id;
1572
+ }
1573
+ return null;
1574
+ }
1575
+ function getProductWalletDiscountCodes(record) {
1576
+ return normalizeWalletAssetCodes(record.code, record.encoded, record.discount?.code, record.discount?.encoded);
1577
+ }
1578
+ function getProductWalletDiscountName(asset, locale) {
1579
+ for (const record of asset.records) {
1580
+ for (const value of [record.discount?.title, record.discount?.name, record.discount?.message, record.product_name, record.format_title, record.title, record.name, record.message]) {
1581
+ const name = getLocalizedValue(value, locale).trim();
1582
+ if (name) return name;
1583
+ }
1584
+ }
1585
+ return asset.codes[0] || label(locale, 'giftCard');
1586
+ }
1587
+ function getProductWalletDiscountTime(asset) {
1588
+ for (const field of ['updated_at', 'created_at', 'collection_time']) {
1589
+ for (const record of asset.records) {
1590
+ const value = firstPresentValue(record[field], record.discount?.[field]);
1591
+ if (isPresentId(value)) return value;
1592
+ }
1593
+ }
1594
+ return undefined;
1595
+ }
1596
+ function getProductEntitlementBalance(asset) {
1597
+ for (const record of asset.records) {
1598
+ const balance = getProductDiscountEntitlementBalance(record);
1599
+ if (balance) return balance;
1600
+ }
1601
+ return null;
1602
+ }
1603
+ function getProductDiscountEntitlementBalance(record) {
1604
+ return getEntitlementBalance(record.metadata?.balance, record.balance, record.discount?.metadata?.balance, record.discount?.balance);
1605
+ }
1606
+ function getEntitlementBalance(...values) {
1607
+ for (const value of values) {
1608
+ if (!isNumericAmount(value)) continue;
1609
+ const balance = new _decimal.default(value);
1610
+ if (balance.isFinite() && balance.isInteger() && balance.gte(0)) {
1611
+ return balance;
1612
+ }
1613
+ }
1614
+ return null;
1615
+ }
1616
+ function formatEntitlementUses(value, locale) {
1617
+ const count = value.toFixed(0);
1618
+ switch (normalizeLocaleKey(locale)) {
1619
+ case 'zh_CN':
1620
+ case 'zh_HK':
1621
+ return `${count}次`;
1622
+ case 'ja':
1623
+ return `${count}回`;
1624
+ case 'pt':
1625
+ return `${count} ${value.eq(1) ? 'utilização' : 'utilizações'}`;
1626
+ default:
1627
+ return `${count} ${value.eq(1) ? 'use' : 'uses'}`;
1628
+ }
1629
+ }
1630
+ function getProductWalletDiscountPercent(asset) {
1631
+ if (asset.type !== 'discount_card' && asset.type !== 'product_discount_card') return null;
1632
+ for (const record of asset.records) {
1633
+ const discountType = stringify(firstPresentValue(record.discount_card_type, record.metadata?.discount_card_type, record.discount?.discount_card_type, record.discount?.metadata?.discount_card_type)).trim().toLowerCase();
1634
+ if (discountType && discountType !== 'percent' && discountType !== 'percentage') continue;
1635
+ const candidates = [record.percent, record.discount?.percent];
1636
+ if (discountType === 'percent' || discountType === 'percentage') {
1637
+ candidates.push(record.par_value, record.discount?.par_value);
1638
+ }
1639
+ for (const value of candidates) {
1640
+ if (!isNumericAmount(value)) continue;
1641
+ const percent = new _decimal.default(value);
1642
+ if (percent.isFinite() && percent.gt(0) && percent.lte(100)) {
1643
+ return percent;
1644
+ }
1645
+ }
1646
+ }
1647
+ return null;
1648
+ }
1649
+ function getProductWalletMoneyBalance(asset) {
1650
+ for (const record of asset.records) {
1651
+ for (const value of [record.metadata?.balance, record.balance, record.discount?.metadata?.balance, record.discount?.balance]) {
1652
+ if (!isNumericAmount(value)) continue;
1653
+ return _decimal.default.max(new _decimal.default(value), 0);
1654
+ }
1655
+ }
1656
+ for (const record of asset.records) {
1657
+ const parValue = firstPresentValue(record.par_value, record.discount?.par_value);
1658
+ const usedParValue = firstPresentValue(record.used_par_value, record.discount?.used_par_value);
1659
+ if (!isNumericAmount(parValue) || !isNumericAmount(usedParValue)) continue;
1660
+ return _decimal.default.max(new _decimal.default(parValue).minus(new _decimal.default(usedParValue)), 0);
1661
+ }
1662
+ return null;
1452
1663
  }
1453
1664
  function buildPointCardSnapshotAssets(params) {
1454
1665
  const snapshots = params.order.order_meta_list?.point_cards_snapshot;
1455
1666
  if (!Array.isArray(snapshots)) return [];
1456
1667
  const snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1457
- const seenSnapshotIds = new Set();
1458
1668
  return snapshots.flatMap(snapshot => {
1459
1669
  if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) return [];
1460
1670
  const pointCard = snapshot;
1461
1671
  if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
1462
- const id = normalizeWalletPassId(pointCard.id);
1463
- if (!id || seenSnapshotIds.has(id)) return [];
1464
- seenSnapshotIds.add(id);
1465
- if (params.displayedWalletPassIds.has(id)) return [];
1672
+ const assetId = normalizeWalletPassId(pointCard.id);
1673
+ if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1674
+ id: assetId,
1675
+ codes: []
1676
+ })) return [];
1466
1677
  const rows = [{
1467
1678
  item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1468
1679
  value: ''
@@ -1518,8 +1729,11 @@ function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
1518
1729
  function buildVirtualCurrencySnapshotAssets(params) {
1519
1730
  const snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1520
1731
  return params.snapshots.flatMap(virtualCurrency => {
1521
- const id = normalizeWalletPassId(virtualCurrency.id);
1522
- if (!id || params.displayedWalletPassIds.has(id)) return [];
1732
+ const assetId = normalizeWalletPassId(virtualCurrency.id);
1733
+ if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
1734
+ id: assetId,
1735
+ codes: []
1736
+ })) return [];
1523
1737
  const rows = [{
1524
1738
  item: stringify(virtualCurrency.product_name).trim(),
1525
1739
  value: ''
@@ -1570,6 +1784,49 @@ function normalizeWalletPassId(value) {
1570
1784
  if (typeof value !== 'string') return null;
1571
1785
  return value.trim() || null;
1572
1786
  }
1787
+ function firstNormalizedWalletAssetId(...values) {
1788
+ for (const value of values) {
1789
+ const id = normalizeWalletPassId(value);
1790
+ if (id) return id;
1791
+ }
1792
+ return null;
1793
+ }
1794
+ function normalizeWalletAssetCodes(...values) {
1795
+ return Array.from(new Set(values.map(value => normalizeWalletPassId(value)).filter(value => !!value)));
1796
+ }
1797
+ function registerWalletAssetIdentity(identities, candidate) {
1798
+ if (!candidate.id && !candidate.codes.length) return;
1799
+ const existing = identities.find(identity => isSameWalletAssetIdentity(identity, candidate));
1800
+ if (existing) {
1801
+ mergeWalletAssetIdentity(existing, candidate);
1802
+ return;
1803
+ }
1804
+ identities.push({
1805
+ id: candidate.id,
1806
+ codes: [...candidate.codes]
1807
+ });
1808
+ }
1809
+ function claimWalletAssetIdentity(identities, candidate) {
1810
+ if (!candidate.id && !candidate.codes.length) return true;
1811
+ const existing = identities.find(identity => isSameWalletAssetIdentity(identity, candidate));
1812
+ if (existing) {
1813
+ mergeWalletAssetIdentity(existing, candidate);
1814
+ return false;
1815
+ }
1816
+ identities.push({
1817
+ id: candidate.id,
1818
+ codes: [...candidate.codes]
1819
+ });
1820
+ return true;
1821
+ }
1822
+ function isSameWalletAssetIdentity(left, right) {
1823
+ if (left.id && right.id) return left.id === right.id;
1824
+ return left.codes.some(code => right.codes.includes(code));
1825
+ }
1826
+ function mergeWalletAssetIdentity(target, source) {
1827
+ if (!target.id && source.id) target.id = source.id;
1828
+ target.codes = Array.from(new Set([...target.codes, ...source.codes]));
1829
+ }
1573
1830
  function getPointCardSnapshotRemainingPoints(snapshot) {
1574
1831
  if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
1575
1832
  return null;
@@ -1577,19 +1834,26 @@ function getPointCardSnapshotRemainingPoints(snapshot) {
1577
1834
  return _decimal.default.max(new _decimal.default(snapshot.par_value).minus(new _decimal.default(snapshot.used_par_value)), 0);
1578
1835
  }
1579
1836
  function buildVoucherAssets(params) {
1580
- const seenVoucherKeys = new Set();
1581
1837
  const fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
1582
- return normalizeArray(params.order.vouchers).flatMap((voucher, index) => {
1838
+ return normalizeArray(params.order.vouchers).flatMap(voucher => {
1583
1839
  if (!voucher || typeof voucher !== 'object' || Array.isArray(voucher)) return [];
1584
- const voucherKey = getVoucherAssetKey(voucher, index);
1585
- if (seenVoucherKeys.has(voucherKey)) return [];
1586
- seenVoucherKeys.add(voucherKey);
1840
+ if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, getVoucherAssetIdentity(voucher))) return [];
1587
1841
  const name = getVoucherAssetName(voucher, params.locale);
1588
1842
  const assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
1589
1843
  const timeRow = isPresentId(assetTime) ? {
1590
1844
  item: formatDateTime(assetTime, params.locale),
1591
1845
  value: ''
1592
1846
  } : null;
1847
+ if (isEntitlementVoucher(voucher)) {
1848
+ const remaining = getEntitlementBalance(voucher.metadata?.balance, voucher.balance);
1849
+ return [[{
1850
+ item: name,
1851
+ value: ''
1852
+ }, ...(remaining ? [{
1853
+ item: label(params.locale, 'entitlementRemaining'),
1854
+ value: formatEntitlementUses(remaining, params.locale)
1855
+ }] : []), ...(timeRow ? [timeRow] : [])]];
1856
+ }
1593
1857
  if (isTicketVoucher(voucher)) {
1594
1858
  const validity = getVoucherValidity(voucher, params.locale);
1595
1859
  return [[{
@@ -1618,6 +1882,9 @@ function buildVoucherAssets(params) {
1618
1882
  });
1619
1883
  }
1620
1884
  const TICKET_VOUCHER_TAGS = new Set(['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket']);
1885
+ function isEntitlementVoucher(voucher) {
1886
+ return [voucher.tag, voucher.type].some(value => stringify(value).trim().toLowerCase() === 'entitlement_pass');
1887
+ }
1621
1888
  function isTicketVoucher(voucher) {
1622
1889
  return TICKET_VOUCHER_TAGS.has(stringify(voucher.tag).trim().toLowerCase());
1623
1890
  }
@@ -1692,9 +1959,11 @@ function formatVoucherValidityDate(value, locale) {
1692
1959
  text: time ? `${time} ${date}` : date
1693
1960
  };
1694
1961
  }
1695
- function getVoucherAssetKey(voucher, index) {
1696
- const identity = firstPresentValue(voucher.voucher_id, voucher.id, voucher.code, voucher.encoded);
1697
- return identity === undefined ? `voucher-index:${index}` : `voucher:${String(identity)}`;
1962
+ function getVoucherAssetIdentity(voucher) {
1963
+ return {
1964
+ id: firstNormalizedWalletAssetId(voucher.voucher_id, voucher.id),
1965
+ codes: normalizeWalletAssetCodes(voucher.code, voucher.encoded)
1966
+ };
1698
1967
  }
1699
1968
  function getVoucherAssetName(voucher, locale) {
1700
1969
  return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
@@ -1720,6 +1989,10 @@ function formatVoucherDiscount(percent, locale) {
1720
1989
  return normalizedLocale === 'en' ? `Discount ${trimDecimal(percent)}% OFF` : `${trimDecimal(percent)}% OFF`;
1721
1990
  }
1722
1991
  function getVoucherBalance(voucher) {
1992
+ for (const value of [voucher.metadata?.balance, voucher.balance]) {
1993
+ if (!isNumericAmount(value)) continue;
1994
+ return _decimal.default.max(new _decimal.default(value), 0);
1995
+ }
1723
1996
  const parValue = new _decimal.default(toMoneyNumber(voucher.par_value));
1724
1997
  const usedParValue = new _decimal.default(toMoneyNumber(voucher.used_par_value));
1725
1998
  return _decimal.default.max(parValue.minus(usedParValue), 0);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.117",
4
+ "version": "2.3.118",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",