@pisell/pisellos 2.2.282 → 2.2.284

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.
Files changed (285) hide show
  1. package/dist/core/index.js +6 -9
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/model/strategy/adapter/walletPass/example.js +3 -26
  4. package/dist/model/strategy/strategy-example.js +5 -19
  5. package/dist/modules/Cart/index.js +0 -3
  6. package/dist/modules/Cart/utils/cartProduct.js +0 -1
  7. package/dist/modules/Date/index.js +1 -5
  8. package/dist/modules/Discount/index.js +2 -4
  9. package/dist/modules/OpenData/index.js +0 -2
  10. package/dist/modules/Order/index.d.ts +2 -2
  11. package/dist/modules/Order/index.js +75 -91
  12. package/dist/modules/Order/types.d.ts +3 -1
  13. package/dist/modules/Payment/index.js +97 -162
  14. package/dist/modules/Rules/index.js +1 -4
  15. package/dist/modules/Schedule/index.js +0 -1
  16. package/dist/modules/Schedule/utils.js +0 -1
  17. package/dist/modules/Step/index.js +0 -1
  18. package/dist/modules/Summary/utils.d.ts +1 -1
  19. package/dist/plugins/request.js +1 -4
  20. package/dist/plugins/window.js +2 -6
  21. package/dist/server/index.js +97 -129
  22. package/dist/server/modules/menu/index.js +32 -41
  23. package/dist/server/modules/order/index.js +2 -4
  24. package/dist/server/modules/products/index.js +24 -42
  25. package/dist/server/modules/quotation/index.js +29 -38
  26. package/dist/server/modules/resource/index.js +3 -4
  27. package/dist/server/modules/schedule/index.js +27 -35
  28. package/dist/server/utils/product.js +0 -1
  29. package/dist/solution/BaseSales/index.js +100 -72
  30. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  31. package/dist/solution/BaseSales/utils/cartPromotion.js +15 -6
  32. package/dist/solution/BookingByStep/index.d.ts +1 -1
  33. package/dist/solution/BookingByStep/index.js +7 -59
  34. package/dist/solution/BookingByStep/utils/capacity.js +1 -11
  35. package/dist/solution/BookingByStep/utils/resources.js +1 -3
  36. package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
  37. package/dist/solution/BookingTicket/index.js +8 -4
  38. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
  39. package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
  40. package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
  41. package/dist/solution/BuyTickets/index.js +9 -12
  42. package/dist/solution/Checkout/index.js +177 -252
  43. package/dist/solution/Checkout/utils/index.js +4 -16
  44. package/dist/solution/RegisterAndLogin/index.js +30 -76
  45. package/dist/solution/ScanOrder/index.js +50 -60
  46. package/dist/solution/ShopDiscount/index.js +2 -7
  47. package/dist/solution/VenueBooking/index.js +45 -55
  48. package/dist/utils/task.js +15 -18
  49. package/dist/utils/watch.js +0 -1
  50. package/lib/apis/picoding.js +2 -0
  51. package/lib/core/index.js +131 -131
  52. package/lib/effects/index.js +46 -57
  53. package/lib/index.js +82 -49
  54. package/lib/model/index.js +14 -21
  55. package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
  56. package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
  57. package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
  58. package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
  59. package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
  60. package/lib/model/strategy/adapter/index.js +100 -64
  61. package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
  62. package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
  63. package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
  64. package/lib/model/strategy/adapter/itemRule/index.js +83 -57
  65. package/lib/model/strategy/adapter/itemRule/type.js +97 -36
  66. package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
  67. package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
  68. package/lib/model/strategy/adapter/promotion/examples.js +222 -234
  69. package/lib/model/strategy/adapter/promotion/index.js +1 -51
  70. package/lib/model/strategy/adapter/promotion/type.js +243 -36
  71. package/lib/model/strategy/adapter/type.js +4 -16
  72. package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
  73. package/lib/model/strategy/adapter/walletPass/example.js +217 -190
  74. package/lib/model/strategy/adapter/walletPass/index.js +75 -51
  75. package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
  76. package/lib/model/strategy/adapter/walletPass/type.js +4 -16
  77. package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
  78. package/lib/model/strategy/engine.js +270 -168
  79. package/lib/model/strategy/index.js +49 -34
  80. package/lib/model/strategy/strategy-example.js +243 -239
  81. package/lib/model/strategy/type.js +100 -40
  82. package/lib/modules/Account/index.js +39 -53
  83. package/lib/modules/Account/types.js +20 -33
  84. package/lib/modules/AccountList/index.js +116 -154
  85. package/lib/modules/AccountList/types.js +30 -31
  86. package/lib/modules/AccountList/utils.js +18 -30
  87. package/lib/modules/BaseModule.js +23 -42
  88. package/lib/modules/BookingContext/index.js +158 -136
  89. package/lib/modules/BookingContext/types.js +46 -32
  90. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
  91. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
  92. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
  93. package/lib/modules/BookingContext/utils/flexible.js +38 -55
  94. package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
  95. package/lib/modules/BookingContext/utils/index.js +124 -41
  96. package/lib/modules/BookingContext/utils/noResource.js +58 -70
  97. package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
  98. package/lib/modules/BookingContext/utils/productExtend.js +202 -155
  99. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  100. package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
  101. package/lib/modules/BookingContext/utils/resources.js +209 -167
  102. package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
  103. package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
  104. package/lib/modules/Cart/index.js +170 -124
  105. package/lib/modules/Cart/types.js +46 -51
  106. package/lib/modules/Cart/utils/cartAccount.js +40 -39
  107. package/lib/modules/Cart/utils/cartDate.js +56 -61
  108. package/lib/modules/Cart/utils/cartDiscount.js +28 -33
  109. package/lib/modules/Cart/utils/cartNote.js +27 -32
  110. package/lib/modules/Cart/utils/cartProduct.js +321 -251
  111. package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
  112. package/lib/modules/Cart/utils/cartResource.js +70 -78
  113. package/lib/modules/Cart/utils/changePrice.js +22 -50
  114. package/lib/modules/Cart/utils/index.js +106 -48
  115. package/lib/modules/Customer/constants.js +13 -34
  116. package/lib/modules/Customer/index.js +235 -172
  117. package/lib/modules/Customer/types.js +38 -35
  118. package/lib/modules/Date/index.js +116 -115
  119. package/lib/modules/Date/types.js +16 -28
  120. package/lib/modules/Date/utils.js +174 -123
  121. package/lib/modules/Discount/index.js +122 -127
  122. package/lib/modules/Discount/types.js +9 -31
  123. package/lib/modules/Guests/index.js +30 -56
  124. package/lib/modules/Guests/types.js +23 -33
  125. package/lib/modules/Holder/index.js +209 -189
  126. package/lib/modules/Holder/types.js +4 -16
  127. package/lib/modules/Holder/utils.js +20 -49
  128. package/lib/modules/OpenData/index.js +70 -76
  129. package/lib/modules/OpenData/types.js +4 -16
  130. package/lib/modules/OpenData/utils.js +44 -78
  131. package/lib/modules/Order/index.d.ts +2 -2
  132. package/lib/modules/Order/index.js +1733 -2121
  133. package/lib/modules/Order/payment-utils.js +77 -120
  134. package/lib/modules/Order/types.d.ts +3 -1
  135. package/lib/modules/Order/types.js +87 -35
  136. package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
  137. package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
  138. package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
  139. package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
  140. package/lib/modules/Order/utils.js +814 -647
  141. package/lib/modules/Payment/cash.js +20 -33
  142. package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
  143. package/lib/modules/Payment/eftpos.js +16 -30
  144. package/lib/modules/Payment/index.js +532 -399
  145. package/lib/modules/Payment/mx51.js +1 -0
  146. package/lib/modules/Payment/types.js +230 -108
  147. package/lib/modules/Payment/utils.js +52 -51
  148. package/lib/modules/Payment/walletpass.js +485 -660
  149. package/lib/modules/Product/index.js +51 -46
  150. package/lib/modules/Product/types.js +4 -16
  151. package/lib/modules/Product/utils.js +32 -33
  152. package/lib/modules/ProductList/index.js +113 -123
  153. package/lib/modules/ProductList/types.js +9 -31
  154. package/lib/modules/Quotation/index.js +66 -100
  155. package/lib/modules/Quotation/types.js +4 -16
  156. package/lib/modules/Resource/index.js +27 -59
  157. package/lib/modules/Resource/types.js +22 -32
  158. package/lib/modules/Resource/utils.js +30 -38
  159. package/lib/modules/ResourcePlanner/index.js +60 -61
  160. package/lib/modules/ResourcePlanner/planner.js +346 -384
  161. package/lib/modules/ResourcePlanner/types.js +4 -16
  162. package/lib/modules/Rules/index.js +1218 -959
  163. package/lib/modules/Rules/types.js +17 -40
  164. package/lib/modules/SalesSummary/index.js +85 -90
  165. package/lib/modules/SalesSummary/types.js +4 -16
  166. package/lib/modules/SalesSummary/utils.js +355 -430
  167. package/lib/modules/ScanOrderLogger/index.js +59 -79
  168. package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
  169. package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
  170. package/lib/modules/ScanOrderLogger/types.js +4 -16
  171. package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
  172. package/lib/modules/Schedule/index.js +100 -114
  173. package/lib/modules/Schedule/type.js +4 -16
  174. package/lib/modules/Schedule/types.js +4 -16
  175. package/lib/modules/Schedule/utils.js +433 -291
  176. package/lib/modules/Step/index.js +40 -52
  177. package/lib/modules/Step/tyeps.js +4 -16
  178. package/lib/modules/Summary/index.js +66 -71
  179. package/lib/modules/Summary/types.js +4 -16
  180. package/lib/modules/Summary/utils.d.ts +1 -1
  181. package/lib/modules/Summary/utils.js +773 -418
  182. package/lib/modules/SurchargeList/index.js +46 -60
  183. package/lib/modules/SurchargeList/types.js +4 -16
  184. package/lib/modules/index.js +245 -63
  185. package/lib/plugins/app.js +4 -16
  186. package/lib/plugins/index.js +36 -25
  187. package/lib/plugins/request.js +137 -126
  188. package/lib/plugins/shopStore.js +4 -16
  189. package/lib/plugins/user.js +4 -16
  190. package/lib/plugins/window.js +171 -179
  191. package/lib/server/index.js +3027 -2655
  192. package/lib/server/modules/floor-plan/index.js +102 -123
  193. package/lib/server/modules/floor-plan/types.js +15 -30
  194. package/lib/server/modules/index.js +106 -68
  195. package/lib/server/modules/menu/index.js +146 -122
  196. package/lib/server/modules/menu/types.js +18 -31
  197. package/lib/server/modules/order/index.js +758 -956
  198. package/lib/server/modules/order/types.js +122 -33
  199. package/lib/server/modules/order/utils/filterBookings.js +219 -194
  200. package/lib/server/modules/order/utils/filterOrders.js +118 -92
  201. package/lib/server/modules/payment/index.js +59 -83
  202. package/lib/server/modules/payment/types.js +4 -16
  203. package/lib/server/modules/products/index.js +575 -459
  204. package/lib/server/modules/products/types.js +44 -34
  205. package/lib/server/modules/quotation/index.js +137 -172
  206. package/lib/server/modules/quotation/types.js +21 -31
  207. package/lib/server/modules/resource/index.js +213 -184
  208. package/lib/server/modules/resource/types.js +42 -33
  209. package/lib/server/modules/schedule/index.js +135 -123
  210. package/lib/server/modules/schedule/types.js +14 -21
  211. package/lib/server/modules/schedule/utils.js +334 -163
  212. package/lib/server/types.js +4 -16
  213. package/lib/server/utils/index.js +25 -23
  214. package/lib/server/utils/product.js +196 -139
  215. package/lib/server/utils/schedule.js +34 -41
  216. package/lib/server/utils/small-ticket.js +479 -456
  217. package/lib/server/utils/time.js +40 -49
  218. package/lib/solution/BaseSales/index.js +1209 -1412
  219. package/lib/solution/BaseSales/types.js +42 -38
  220. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  221. package/lib/solution/BaseSales/utils/cartPromotion.js +652 -498
  222. package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
  223. package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
  224. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
  225. package/lib/solution/BaseSales/utils.js +158 -143
  226. package/lib/solution/BookingByStep/index.d.ts +1 -1
  227. package/lib/solution/BookingByStep/index.js +1527 -1340
  228. package/lib/solution/BookingByStep/types.js +40 -99
  229. package/lib/solution/BookingByStep/utils/capacity.js +192 -160
  230. package/lib/solution/BookingByStep/utils/products.js +42 -52
  231. package/lib/solution/BookingByStep/utils/resources.js +527 -330
  232. package/lib/solution/BookingByStep/utils/stock.js +65 -44
  233. package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
  234. package/lib/solution/BookingTicket/index.js +598 -514
  235. package/lib/solution/BookingTicket/types.js +99 -77
  236. package/lib/solution/BookingTicket/utils/addProductDecision.js +225 -187
  237. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
  238. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
  239. package/lib/solution/BookingTicket/utils/cartView.js +114 -99
  240. package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
  241. package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
  242. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
  243. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
  244. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
  245. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
  246. package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
  247. package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
  248. package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
  249. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
  250. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
  251. package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
  252. package/lib/solution/BuyTickets/index.js +67 -70
  253. package/lib/solution/BuyTickets/types.js +22 -38
  254. package/lib/solution/Checkout/index.js +1451 -1158
  255. package/lib/solution/Checkout/types.js +91 -61
  256. package/lib/solution/Checkout/utils/index.js +228 -156
  257. package/lib/solution/PlaceOrder/index.js +55 -0
  258. package/lib/solution/RegisterAndLogin/config.js +493 -460
  259. package/lib/solution/RegisterAndLogin/index.js +633 -630
  260. package/lib/solution/RegisterAndLogin/types.js +189 -76
  261. package/lib/solution/RegisterAndLogin/utils.js +183 -125
  262. package/lib/solution/Sales/index.js +328 -324
  263. package/lib/solution/Sales/types.js +27 -33
  264. package/lib/solution/ScanOrder/index.js +832 -864
  265. package/lib/solution/ScanOrder/types.js +33 -34
  266. package/lib/solution/ScanOrder/utils.js +409 -374
  267. package/lib/solution/ShopDiscount/index.js +226 -232
  268. package/lib/solution/ShopDiscount/types.js +15 -37
  269. package/lib/solution/ShopDiscount/utils.js +300 -172
  270. package/lib/solution/UnifiedBookingSales/index.js +437 -487
  271. package/lib/solution/UnifiedBookingSales/types.js +12 -31
  272. package/lib/solution/VenueBooking/index.js +811 -879
  273. package/lib/solution/VenueBooking/types.js +19 -39
  274. package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
  275. package/lib/solution/VenueBooking/utils/resource.js +31 -54
  276. package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
  277. package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
  278. package/lib/solution/VenueBooking/utils.js +130 -67
  279. package/lib/solution/index.js +124 -41
  280. package/lib/store/createStore.js +32 -29
  281. package/lib/types/index.js +4 -16
  282. package/lib/utils/payment-number.js +26 -46
  283. package/lib/utils/task.js +36 -36
  284. package/lib/utils/watch.js +81 -47
  285. package/package.json +2 -1
@@ -1,89 +1,65 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";
18
2
 
19
- // src/modules/Order/utils/orderCollectionIdentity.ts
20
- var orderCollectionIdentity_exports = {};
21
- __export(orderCollectionIdentity_exports, {
22
- applyOrderCollectionUidRemaps: () => applyOrderCollectionUidRemaps,
23
- buildOrderCollectionFallbackUid: () => buildOrderCollectionFallbackUid,
24
- createUuidV4: () => createUuidV4,
25
- getOrderCollectionPersistentId: () => getOrderCollectionPersistentId,
26
- getOrderCollectionReferenceUid: () => getOrderCollectionReferenceUid,
27
- getOrderCollectionUid: () => getOrderCollectionUid,
28
- isBlankOrderCollectionIdentity: () => isBlankOrderCollectionIdentity,
29
- isSameOrderCollectionItem: () => isSameOrderCollectionItem,
30
- mergeOrderCollectionItems: () => mergeOrderCollectionItems,
31
- normalizeOrderCollection: () => normalizeOrderCollection,
32
- normalizeOrderCollections: () => normalizeOrderCollections,
33
- repairDuplicateProductLineIdentities: () => repairDuplicateProductLineIdentities,
34
- setOrderCollectionUid: () => setOrderCollectionUid
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
35
5
  });
36
- module.exports = __toCommonJS(orderCollectionIdentity_exports);
37
- var import_lodash_es = require("lodash-es");
38
- var IDENTITY_CONFIG = {
6
+ exports.applyOrderCollectionUidRemaps = applyOrderCollectionUidRemaps;
7
+ exports.buildOrderCollectionFallbackUid = buildOrderCollectionFallbackUid;
8
+ exports.createUuidV4 = createUuidV4;
9
+ exports.getOrderCollectionPersistentId = getOrderCollectionPersistentId;
10
+ exports.getOrderCollectionReferenceUid = getOrderCollectionReferenceUid;
11
+ exports.getOrderCollectionUid = getOrderCollectionUid;
12
+ exports.isBlankOrderCollectionIdentity = isBlankOrderCollectionIdentity;
13
+ exports.isSameOrderCollectionItem = isSameOrderCollectionItem;
14
+ exports.mergeOrderCollectionItems = mergeOrderCollectionItems;
15
+ exports.normalizeOrderCollection = normalizeOrderCollection;
16
+ exports.normalizeOrderCollections = normalizeOrderCollections;
17
+ exports.repairDuplicateProductLineIdentities = repairDuplicateProductLineIdentities;
18
+ exports.setOrderCollectionUid = setOrderCollectionUid;
19
+ var _lodashEs = require("lodash-es");
20
+ const IDENTITY_CONFIG = {
39
21
  product: {
40
- persistentIdField: "order_detail_id",
41
- uidField: "unique_identification_number",
42
- fallbackPrefix: "os-fallback:product:order-detail"
22
+ persistentIdField: 'order_detail_id',
23
+ uidField: 'unique_identification_number',
24
+ fallbackPrefix: 'os-fallback:product:order-detail'
43
25
  },
44
26
  booking: {
45
- persistentIdField: "schedule_event_id",
46
- uidField: "unique_identification_number",
47
- fallbackPrefix: "os-fallback:booking:schedule-event"
27
+ persistentIdField: 'schedule_event_id',
28
+ uidField: 'unique_identification_number',
29
+ fallbackPrefix: 'os-fallback:booking:schedule-event'
48
30
  },
49
31
  payment: {
50
- persistentIdField: "order_payment_id",
51
- uidField: "unique_payment_number",
52
- fallbackPrefix: "os-fallback:payment:order-payment"
32
+ persistentIdField: 'order_payment_id',
33
+ uidField: 'unique_payment_number',
34
+ fallbackPrefix: 'os-fallback:payment:order-payment'
53
35
  }
54
36
  };
55
37
  function createUuidV4() {
56
- const template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
57
- return template.replace(/[xy]/g, (char) => {
38
+ const template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
39
+ return template.replace(/[xy]/g, char => {
58
40
  const randomValue = Math.floor(Math.random() * 16);
59
- const value = char === "x" ? randomValue : randomValue & 3 | 8;
41
+ const value = char === 'x' ? randomValue : randomValue & 0x3 | 0x8;
60
42
  return value.toString(16);
61
43
  });
62
44
  }
63
45
  function isBlankOrderCollectionIdentity(value) {
64
- return value === void 0 || value === null || value === "";
46
+ return value === undefined || value === null || value === '';
65
47
  }
66
48
  function getOrderCollectionPersistentId(kind, item) {
67
49
  const record = item;
68
- if (!record)
69
- return null;
50
+ if (!record) return null;
70
51
  const value = record[IDENTITY_CONFIG[kind].persistentIdField];
71
- if (isBlankOrderCollectionIdentity(value))
72
- return null;
52
+ if (isBlankOrderCollectionIdentity(value)) return null;
73
53
  return String(value);
74
54
  }
75
55
  function getOrderCollectionUid(kind, item) {
76
- var _a;
77
56
  const record = item;
78
- if (!record)
79
- return null;
57
+ if (!record) return null;
80
58
  const uidField = IDENTITY_CONFIG[kind].uidField;
81
- const metadataValue = (_a = record.metadata) == null ? void 0 : _a[uidField];
82
- if (!isBlankOrderCollectionIdentity(metadataValue))
83
- return String(metadataValue);
59
+ const metadataValue = record.metadata?.[uidField];
60
+ if (!isBlankOrderCollectionIdentity(metadataValue)) return String(metadataValue);
84
61
  const topLevelValue = record[uidField];
85
- if (isBlankOrderCollectionIdentity(topLevelValue))
86
- return null;
62
+ if (isBlankOrderCollectionIdentity(topLevelValue)) return null;
87
63
  return String(topLevelValue);
88
64
  }
89
65
  function buildOrderCollectionFallbackUid(kind, persistentId) {
@@ -91,31 +67,27 @@ function buildOrderCollectionFallbackUid(kind, persistentId) {
91
67
  }
92
68
  function getOrderCollectionReferenceUid(kind, item) {
93
69
  const uid = getOrderCollectionUid(kind, item);
94
- if (uid)
95
- return uid;
70
+ if (uid) return uid;
96
71
  const persistentId = getOrderCollectionPersistentId(kind, item);
97
72
  return persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : null;
98
73
  }
99
74
  function setOrderCollectionUid(kind, item, uid) {
100
- const record = (0, import_lodash_es.cloneDeep)(item || {});
75
+ const record = (0, _lodashEs.cloneDeep)(item || {});
101
76
  const uidField = IDENTITY_CONFIG[kind].uidField;
102
77
  record.metadata = {
103
- ...record.metadata && typeof record.metadata === "object" ? record.metadata : {},
78
+ ...(record.metadata && typeof record.metadata === 'object' ? record.metadata : {}),
104
79
  [uidField]: uid
105
80
  };
106
81
  delete record[uidField];
107
82
  return record;
108
83
  }
109
84
  function getGoodPassResourceId(product) {
110
- var _a;
111
- const goodPass = (product.discount_list || []).find((item) => {
112
- var _a2, _b;
113
- const type = (item == null ? void 0 : item.type) || (item == null ? void 0 : item.tag) || ((_a2 = item == null ? void 0 : item.discount) == null ? void 0 : _a2.type) || ((_b = item == null ? void 0 : item.discount) == null ? void 0 : _b.tag);
114
- return type === "good_pass";
85
+ const goodPass = (product.discount_list || []).find(item => {
86
+ const type = item?.type || item?.tag || item?.discount?.type || item?.discount?.tag;
87
+ return type === 'good_pass';
115
88
  });
116
- if (!goodPass)
117
- return null;
118
- const resourceId = ((_a = goodPass.discount) == null ? void 0 : _a.resource_id) ?? goodPass.resource_id ?? goodPass.discount_id ?? goodPass.id;
89
+ if (!goodPass) return null;
90
+ const resourceId = goodPass.discount?.resource_id ?? goodPass.resource_id ?? goodPass.discount_id ?? goodPass.id;
119
91
  return isBlankOrderCollectionIdentity(resourceId) ? null : String(resourceId);
120
92
  }
121
93
  function buildSplitProductUid(originalUid, product, duplicateOrdinal) {
@@ -126,54 +98,63 @@ function buildSplitProductUid(originalUid, product, duplicateOrdinal) {
126
98
  }
127
99
  return `os-split:product:${encodedOriginalUid}:duplicate:${duplicateOrdinal}`;
128
100
  }
101
+
102
+ /**
103
+ * Rules 会把同一商品按商品券拆成多条真实订单行。拆行结果会继承原商品 UID,
104
+ * 因此必须在通用 collection normalization 之前为后续行派生稳定身份,避免被折叠。
105
+ */
129
106
  function repairDuplicateProductLineIdentities(products, productsByUid) {
130
- const repairedProducts = (0, import_lodash_es.cloneDeep)(products || []);
131
- const repairedProductsByUid = productsByUid ? (0, import_lodash_es.cloneDeep)(productsByUid) : void 0;
132
- const occupiedUids = new Set(
133
- repairedProducts.map((product) => getOrderCollectionUid("product", product)).filter((uid) => Boolean(uid))
134
- );
135
- Object.keys(repairedProductsByUid || {}).forEach((uid) => occupiedUids.add(uid));
136
- const occurrences = /* @__PURE__ */ new Map();
107
+ const repairedProducts = (0, _lodashEs.cloneDeep)(products || []);
108
+ const repairedProductsByUid = productsByUid ? (0, _lodashEs.cloneDeep)(productsByUid) : undefined;
109
+ const occupiedUids = new Set(repairedProducts.map(product => getOrderCollectionUid('product', product)).filter(uid => Boolean(uid)));
110
+ Object.keys(repairedProductsByUid || {}).forEach(uid => occupiedUids.add(uid));
111
+ const occurrences = new Map();
137
112
  const repairs = [];
138
113
  repairedProducts.forEach((product, index) => {
139
- const originalUid = getOrderCollectionUid("product", product);
140
- if (!originalUid)
141
- return;
114
+ const originalUid = getOrderCollectionUid('product', product);
115
+ if (!originalUid) return;
142
116
  const occurrence = (occurrences.get(originalUid) || 0) + 1;
143
117
  occurrences.set(originalUid, occurrence);
144
- if (occurrence === 1)
145
- return;
118
+ if (occurrence === 1) return;
146
119
  const duplicateOrdinal = occurrence - 1;
147
- const baseCandidate = buildSplitProductUid(
148
- originalUid,
149
- product,
150
- duplicateOrdinal
151
- );
120
+ const baseCandidate = buildSplitProductUid(originalUid, product, duplicateOrdinal);
152
121
  let nextUid = baseCandidate;
153
122
  let conflictOrdinal = 1;
154
123
  while (occupiedUids.has(nextUid)) {
155
124
  nextUid = `${baseCandidate}:conflict:${conflictOrdinal}`;
156
125
  conflictOrdinal += 1;
157
126
  }
158
- const repairedProduct = setOrderCollectionUid("product", product, nextUid);
127
+ const repairedProduct = setOrderCollectionUid('product', product, nextUid);
159
128
  repairedProduct.identity_key = nextUid;
160
129
  repairedProducts[index] = repairedProduct;
161
130
  occupiedUids.add(nextUid);
162
- repairs.push({ index, from: originalUid, to: nextUid });
163
- const runtimeSource = repairedProductsByUid == null ? void 0 : repairedProductsByUid[originalUid];
131
+ repairs.push({
132
+ index,
133
+ from: originalUid,
134
+ to: nextUid
135
+ });
136
+ const runtimeSource = repairedProductsByUid?.[originalUid];
164
137
  if (runtimeSource && repairedProductsByUid) {
165
138
  repairedProductsByUid[nextUid] = {
166
- ...(0, import_lodash_es.cloneDeep)(runtimeSource),
167
- ...runtimeSource.rowKey !== void 0 ? { rowKey: nextUid } : {}
139
+ ...(0, _lodashEs.cloneDeep)(runtimeSource),
140
+ ...(runtimeSource.rowKey !== undefined ? {
141
+ rowKey: nextUid
142
+ } : {})
168
143
  };
169
144
  }
170
145
  });
171
146
  return {
172
147
  products: repairedProducts,
173
- ...repairedProductsByUid ? { productsByUid: repairedProductsByUid } : {},
148
+ ...(repairedProductsByUid ? {
149
+ productsByUid: repairedProductsByUid
150
+ } : {}),
174
151
  repairs
175
152
  };
176
153
  }
154
+
155
+ /**
156
+ * 持久化行 ID 是服务端事实主键;只有至少一侧尚未持久化时,才允许用 runtime UID 对齐。
157
+ */
177
158
  function isSameOrderCollectionItem(kind, left, right) {
178
159
  const leftPersistentId = getOrderCollectionPersistentId(kind, left);
179
160
  const rightPersistentId = getOrderCollectionPersistentId(kind, right);
@@ -185,9 +166,8 @@ function isSameOrderCollectionItem(kind, left, right) {
185
166
  return Boolean(leftUid && rightUid && leftUid === rightUid);
186
167
  }
187
168
  function mergeOrderCollectionItems(kind, currentItem, incomingItem, options) {
188
- var _a;
189
- const current = (0, import_lodash_es.cloneDeep)(currentItem || {});
190
- const incoming = (0, import_lodash_es.cloneDeep)(incomingItem || {});
169
+ const current = (0, _lodashEs.cloneDeep)(currentItem || {});
170
+ const incoming = (0, _lodashEs.cloneDeep)(incomingItem || {});
191
171
  const persistentIdField = IDENTITY_CONFIG[kind].persistentIdField;
192
172
  const currentPersistentIdValue = current[persistentIdField];
193
173
  const incomingPersistentIdValue = incoming[persistentIdField];
@@ -198,19 +178,19 @@ function mergeOrderCollectionItems(kind, currentItem, incomingItem, options) {
198
178
  ...current,
199
179
  ...incoming,
200
180
  metadata: {
201
- ...current.metadata && typeof current.metadata === "object" ? current.metadata : {},
202
- ...incoming.metadata && typeof incoming.metadata === "object" ? incoming.metadata : {}
181
+ ...(current.metadata && typeof current.metadata === 'object' ? current.metadata : {}),
182
+ ...(incoming.metadata && typeof incoming.metadata === 'object' ? incoming.metadata : {})
203
183
  }
204
184
  };
185
+
186
+ // UID 对齐允许一侧尚未持久化,但稀疏 incoming 的 null/空值不能擦掉已存在行 ID。
205
187
  if (!isBlankOrderCollectionIdentity(incomingPersistentIdValue)) {
206
188
  merged[persistentIdField] = incomingPersistentIdValue;
207
189
  } else if (!isBlankOrderCollectionIdentity(currentPersistentIdValue)) {
208
190
  merged[persistentIdField] = currentPersistentIdValue;
209
191
  }
210
- const incomingUidIsDerived = Boolean(
211
- incomingUid && persistentId && (incomingUid === buildOrderCollectionFallbackUid(kind, persistentId) || incomingUid.startsWith(`${buildOrderCollectionFallbackUid(kind, persistentId)}:conflict:`))
212
- );
213
- const uid = (incomingUid && !incomingUidIsDerived ? incomingUid : null) || currentUid || incomingUid || ((options == null ? void 0 : options.ensureUid) === false ? null : persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : ((_a = options == null ? void 0 : options.createAnonymousUid) == null ? void 0 : _a.call(options)) || createUuidV4());
192
+ const incomingUidIsDerived = Boolean(incomingUid && persistentId && (incomingUid === buildOrderCollectionFallbackUid(kind, persistentId) || incomingUid.startsWith(`${buildOrderCollectionFallbackUid(kind, persistentId)}:conflict:`)));
193
+ const uid = (incomingUid && !incomingUidIsDerived ? incomingUid : null) || currentUid || incomingUid || (options?.ensureUid === false ? null : persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : options?.createAnonymousUid?.() || createUuidV4());
214
194
  return uid ? setOrderCollectionUid(kind, merged, uid) : merged;
215
195
  }
216
196
  function createEmptyIdentityStats() {
@@ -223,14 +203,15 @@ function createEmptyIdentityStats() {
223
203
  }
224
204
  function allocateAnonymousUid(occupiedUids, createAnonymousUid) {
225
205
  let uid = createAnonymousUid();
226
- while (occupiedUids.has(uid))
227
- uid = createAnonymousUid();
206
+ while (occupiedUids.has(uid)) uid = createAnonymousUid();
228
207
  return uid;
229
208
  }
230
209
  function allocatePersistentConflictUid(kind, persistentId, occupiedUids) {
231
210
  const fallbackUid = buildOrderCollectionFallbackUid(kind, persistentId);
232
- if (!occupiedUids.has(fallbackUid))
233
- return fallbackUid;
211
+ if (!occupiedUids.has(fallbackUid)) return fallbackUid;
212
+
213
+ // 极端情况下其它行可能把本行 fallback 当作显式 UID 使用;继续派生稳定后缀,
214
+ // 避免修复冲突后仍留下重复 UID。规范化结果一旦持久化,后续读取保持幂等。
234
215
  let suffix = 1;
235
216
  let candidate = `${fallbackUid}:conflict:${suffix}`;
236
217
  while (occupiedUids.has(candidate)) {
@@ -239,38 +220,32 @@ function allocatePersistentConflictUid(kind, persistentId, occupiedUids) {
239
220
  }
240
221
  return candidate;
241
222
  }
223
+
224
+ /**
225
+ * 规范化单一数组:强身份重复时保留首次位置、用最后一条业务字段覆盖,并统一补 UID。
226
+ */
242
227
  function normalizeOrderCollection(kind, items, options) {
243
- var _a, _b;
244
228
  const stats = createEmptyIdentityStats();
245
229
  const uidRemaps = [];
246
230
  const result = [];
247
- const ensureUid = (options == null ? void 0 : options.ensureUid) !== false;
248
- const createAnonymousUid = (options == null ? void 0 : options.createAnonymousUid) || createUuidV4;
231
+ const ensureUid = options?.ensureUid !== false;
232
+ const createAnonymousUid = options?.createAnonymousUid || createUuidV4;
249
233
  for (const rawItem of items || []) {
250
- const item = (0, import_lodash_es.cloneDeep)(rawItem);
251
- const existingIndex = result.findIndex(
252
- (existing) => isSameOrderCollectionItem(kind, existing, item)
253
- );
234
+ const item = (0, _lodashEs.cloneDeep)(rawItem);
235
+ const existingIndex = result.findIndex(existing => isSameOrderCollectionItem(kind, existing, item));
254
236
  if (existingIndex === -1) {
255
237
  result.push(item);
256
238
  continue;
257
239
  }
258
- const previousReferenceUid = getOrderCollectionReferenceUid(
259
- kind,
260
- result[existingIndex]
261
- );
240
+ const previousReferenceUid = getOrderCollectionReferenceUid(kind, result[existingIndex]);
262
241
  const incomingReferenceUid = getOrderCollectionReferenceUid(kind, item);
263
- result[existingIndex] = mergeOrderCollectionItems(
264
- kind,
265
- result[existingIndex],
266
- item,
267
- { ensureUid: false }
268
- );
242
+ result[existingIndex] = mergeOrderCollectionItems(kind, result[existingIndex], item, {
243
+ ensureUid: false
244
+ });
269
245
  const nextUid = getOrderCollectionUid(kind, result[existingIndex]);
270
246
  if (nextUid) {
271
- for (const from of /* @__PURE__ */ new Set([previousReferenceUid, incomingReferenceUid])) {
272
- if (!from || from === nextUid)
273
- continue;
247
+ for (const from of new Set([previousReferenceUid, incomingReferenceUid])) {
248
+ if (!from || from === nextUid) continue;
274
249
  uidRemaps.push({
275
250
  kind,
276
251
  from,
@@ -281,23 +256,26 @@ function normalizeOrderCollection(kind, items, options) {
281
256
  }
282
257
  stats.collapsedDuplicateCount += 1;
283
258
  }
284
- if (!ensureUid)
285
- return { items: result, stats, uidRemaps };
286
- const occupiedUids = /* @__PURE__ */ new Set();
259
+ if (!ensureUid) return {
260
+ items: result,
261
+ stats,
262
+ uidRemaps
263
+ };
264
+ const occupiedUids = new Set();
287
265
  for (let index = 0; index < result.length; index += 1) {
288
266
  let item = result[index];
289
267
  const persistentId = getOrderCollectionPersistentId(kind, item);
290
268
  let uid = getOrderCollectionUid(kind, item);
291
269
  if (!uid) {
292
- if (kind === "payment" && !isBlankOrderCollectionIdentity(item == null ? void 0 : item.payment_number)) {
270
+ if (kind === 'payment' && !isBlankOrderCollectionIdentity(item?.payment_number)) {
271
+ // payment_number 已提供稳定身份,不占用真实交易流水字段作为内部 UID。
293
272
  continue;
294
273
  }
295
274
  uid = persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
296
275
  item = setOrderCollectionUid(kind, item, uid);
297
276
  result[index] = item;
298
277
  stats.backfilledUidCount += 1;
299
- if (!persistentId)
300
- stats.anonymousRowCount += 1;
278
+ if (!persistentId) stats.anonymousRowCount += 1;
301
279
  }
302
280
  if (occupiedUids.has(uid)) {
303
281
  const replacementUid = persistentId ? allocatePersistentConflictUid(kind, persistentId, occupiedUids) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
@@ -307,123 +285,120 @@ function normalizeOrderCollection(kind, items, options) {
307
285
  from: uid,
308
286
  to: replacementUid,
309
287
  persistentId,
310
- scope: "linked-owner",
311
- referenceOwnerUid: kind === "product" ? String(
312
- (item == null ? void 0 : item.booking_uid) || ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.booking_uid) || ""
313
- ) || null : kind === "booking" ? String(
314
- (item == null ? void 0 : item.product_uid) || ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.product_uid) || ""
315
- ) || null : null
288
+ scope: 'linked-owner',
289
+ referenceOwnerUid: kind === 'product' ? String(item?.booking_uid || item?.metadata?.booking_uid || '') || null : kind === 'booking' ? String(item?.product_uid || item?.metadata?.product_uid || '') || null : null
316
290
  });
317
291
  uid = replacementUid;
318
292
  stats.uidConflictCount += 1;
319
293
  }
320
294
  occupiedUids.add(uid);
321
295
  }
322
- return { items: result, stats, uidRemaps };
296
+ return {
297
+ items: result,
298
+ stats,
299
+ uidRemaps
300
+ };
323
301
  }
324
302
  function applyOrderCollectionUidRemaps(sourceOrder, uidRemaps) {
325
- var _a, _b, _c, _d, _e;
326
- if (!uidRemaps.length)
327
- return sourceOrder;
328
- const order = (0, import_lodash_es.cloneDeep)(sourceOrder);
329
- const hasAmbiguousLinkedOwner = (remap) => {
330
- if (remap.scope !== "linked-owner" || !remap.referenceOwnerUid)
331
- return false;
332
- const ownerKind = remap.kind === "product" ? "booking" : remap.kind === "booking" ? "product" : null;
333
- if (!ownerKind)
334
- return false;
335
- return uidRemaps.some(
336
- (candidate) => candidate.scope === "linked-owner" && candidate.kind === ownerKind && candidate.from === remap.referenceOwnerUid
337
- );
303
+ if (!uidRemaps.length) return sourceOrder;
304
+ const order = (0, _lodashEs.cloneDeep)(sourceOrder);
305
+ const hasAmbiguousLinkedOwner = remap => {
306
+ if (remap.scope !== 'linked-owner' || !remap.referenceOwnerUid) return false;
307
+ const ownerKind = remap.kind === 'product' ? 'booking' : remap.kind === 'booking' ? 'product' : null;
308
+ if (!ownerKind) return false;
309
+ return uidRemaps.some(candidate => candidate.scope === 'linked-owner' && candidate.kind === ownerKind && candidate.from === remap.referenceOwnerUid);
338
310
  };
339
311
  for (const remap of uidRemaps) {
340
- if (remap.from === remap.to)
341
- continue;
312
+ if (remap.from === remap.to) continue;
342
313
  const linkedOwnerIsAmbiguous = hasAmbiguousLinkedOwner(remap);
343
- if (remap.kind === "product") {
314
+ if (remap.kind === 'product') {
344
315
  for (const booking of order.bookings || []) {
345
- if (remap.scope === "linked-owner" && (linkedOwnerIsAmbiguous || getOrderCollectionUid("booking", booking) !== remap.referenceOwnerUid)) {
316
+ if (remap.scope === 'linked-owner' && (linkedOwnerIsAmbiguous || getOrderCollectionUid('booking', booking) !== remap.referenceOwnerUid)) {
346
317
  continue;
347
318
  }
348
- if (String((booking == null ? void 0 : booking.product_uid) || "") === remap.from) {
319
+ if (String(booking?.product_uid || '') === remap.from) {
349
320
  booking.product_uid = remap.to;
350
321
  }
351
- if (String(((_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.product_uid) || "") === remap.from) {
352
- booking.metadata = { ...booking.metadata || {}, product_uid: remap.to };
322
+ if (String(booking?.metadata?.product_uid || '') === remap.from) {
323
+ booking.metadata = {
324
+ ...(booking.metadata || {}),
325
+ product_uid: remap.to
326
+ };
353
327
  }
354
328
  }
355
- if (remap.scope !== "linked-owner") {
329
+ // 冲突 UID 仍由第一条持有;赠品父引用缺少可用的持久化行定位时不能全局改写。
330
+ if (remap.scope !== 'linked-owner') {
356
331
  for (const product of order.products || []) {
357
- if (String(((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.parent_unique_identification_number) || "") === remap.from) {
332
+ if (String(product?.metadata?.parent_unique_identification_number || '') === remap.from) {
358
333
  product.metadata = {
359
- ...product.metadata || {},
334
+ ...(product.metadata || {}),
360
335
  parent_unique_identification_number: remap.to
361
336
  };
362
337
  }
363
- const giftInfo = (_c = product == null ? void 0 : product.metadata) == null ? void 0 : _c._giftInfo;
364
- if (giftInfo && typeof giftInfo === "object") {
365
- const sourceProductIds = Array.isArray(giftInfo.sourceProductIds) ? giftInfo.sourceProductIds.map(
366
- (uid) => String(uid) === remap.from ? remap.to : uid
367
- ) : giftInfo.sourceProductIds;
368
- const sourceProductId = String(giftInfo.sourceProductId || "") === remap.from ? remap.to : giftInfo.sourceProductId;
338
+ const giftInfo = product?.metadata?._giftInfo;
339
+ if (giftInfo && typeof giftInfo === 'object') {
340
+ const sourceProductIds = Array.isArray(giftInfo.sourceProductIds) ? giftInfo.sourceProductIds.map(uid => String(uid) === remap.from ? remap.to : uid) : giftInfo.sourceProductIds;
341
+ const sourceProductId = String(giftInfo.sourceProductId || '') === remap.from ? remap.to : giftInfo.sourceProductId;
369
342
  product.metadata = {
370
- ...product.metadata || {},
343
+ ...(product.metadata || {}),
371
344
  _giftInfo: {
372
345
  ...giftInfo,
373
- ...sourceProductIds !== void 0 ? { sourceProductIds } : {},
374
- ...sourceProductId !== void 0 ? { sourceProductId } : {}
346
+ ...(sourceProductIds !== undefined ? {
347
+ sourceProductIds
348
+ } : {}),
349
+ ...(sourceProductId !== undefined ? {
350
+ sourceProductId
351
+ } : {})
375
352
  }
376
353
  };
377
354
  }
378
355
  }
379
356
  }
380
- const productsByUid = (_d = order._extend) == null ? void 0 : _d.productsByUid;
381
- const cachedProduct = productsByUid == null ? void 0 : productsByUid[remap.from];
382
- const cachedPersistentId = getOrderCollectionPersistentId(
383
- "product",
384
- (cachedProduct == null ? void 0 : cachedProduct.origin) || cachedProduct
385
- );
386
- if (productsByUid && remap.scope === "linked-owner") {
387
- const retainedProduct = (order.products || []).find(
388
- (product) => getOrderCollectionUid("product", product) === remap.from
389
- );
390
- const remappedProduct = (order.products || []).find(
391
- (product) => getOrderCollectionUid("product", product) === remap.to
392
- );
357
+ const productsByUid = order._extend?.productsByUid;
358
+ const cachedProduct = productsByUid?.[remap.from];
359
+ const cachedPersistentId = getOrderCollectionPersistentId('product', cachedProduct?.origin || cachedProduct);
360
+ if (productsByUid && remap.scope === 'linked-owner') {
361
+ const retainedProduct = (order.products || []).find(product => getOrderCollectionUid('product', product) === remap.from);
362
+ const remappedProduct = (order.products || []).find(product => getOrderCollectionUid('product', product) === remap.to);
393
363
  if (cachedProduct && remap.persistentId && cachedPersistentId === remap.persistentId) {
394
364
  productsByUid[remap.to] = {
395
- ...cachedProduct || {},
396
- ...productsByUid[remap.to] || {}
365
+ ...(cachedProduct || {}),
366
+ ...(productsByUid[remap.to] || {})
397
367
  };
398
368
  if (retainedProduct) {
399
369
  productsByUid[remap.from] = {
400
- ...cachedProduct || {},
401
- origin: (0, import_lodash_es.cloneDeep)(retainedProduct)
370
+ ...(cachedProduct || {}),
371
+ origin: (0, _lodashEs.cloneDeep)(retainedProduct)
402
372
  };
403
373
  }
404
374
  } else if (remappedProduct && !productsByUid[remap.to]) {
405
- productsByUid[remap.to] = { origin: (0, import_lodash_es.cloneDeep)(remappedProduct) };
375
+ productsByUid[remap.to] = {
376
+ origin: (0, _lodashEs.cloneDeep)(remappedProduct)
377
+ };
406
378
  }
407
379
  continue;
408
380
  }
409
- if (cachedProduct && remap.scope !== "linked-owner") {
381
+ if (cachedProduct && remap.scope !== 'linked-owner') {
410
382
  productsByUid[remap.to] = {
411
- ...cachedProduct || {},
412
- ...productsByUid[remap.to] || {}
383
+ ...(cachedProduct || {}),
384
+ ...(productsByUid[remap.to] || {})
413
385
  };
414
386
  delete productsByUid[remap.from];
415
387
  }
416
388
  }
417
- if (remap.kind === "booking") {
389
+ if (remap.kind === 'booking') {
418
390
  for (const product of order.products || []) {
419
- if (remap.scope === "linked-owner" && (linkedOwnerIsAmbiguous || getOrderCollectionUid("product", product) !== remap.referenceOwnerUid)) {
391
+ if (remap.scope === 'linked-owner' && (linkedOwnerIsAmbiguous || getOrderCollectionUid('product', product) !== remap.referenceOwnerUid)) {
420
392
  continue;
421
393
  }
422
- if (String((product == null ? void 0 : product.booking_uid) || "") === remap.from) {
394
+ if (String(product?.booking_uid || '') === remap.from) {
423
395
  product.booking_uid = remap.to;
424
396
  }
425
- if (String(((_e = product == null ? void 0 : product.metadata) == null ? void 0 : _e.booking_uid) || "") === remap.from) {
426
- product.metadata = { ...product.metadata || {}, booking_uid: remap.to };
397
+ if (String(product?.metadata?.booking_uid || '') === remap.from) {
398
+ product.metadata = {
399
+ ...(product.metadata || {}),
400
+ booking_uid: remap.to
401
+ };
427
402
  }
428
403
  }
429
404
  }
@@ -431,34 +406,15 @@ function applyOrderCollectionUidRemaps(sourceOrder, uidRemaps) {
431
406
  return order;
432
407
  }
433
408
  function normalizeOrderCollections(sourceOrder, options) {
434
- let order = (0, import_lodash_es.cloneDeep)(sourceOrder || {});
409
+ let order = (0, _lodashEs.cloneDeep)(sourceOrder || {});
435
410
  const orderRecord = order;
436
- const productResult = normalizeOrderCollection(
437
- "product",
438
- Array.isArray(orderRecord.products) ? orderRecord.products : [],
439
- options
440
- );
441
- const bookingResult = normalizeOrderCollection(
442
- "booking",
443
- Array.isArray(orderRecord.bookings) ? orderRecord.bookings : [],
444
- options
445
- );
446
- const paymentResult = normalizeOrderCollection(
447
- "payment",
448
- Array.isArray(orderRecord.payments) ? orderRecord.payments : [],
449
- options
450
- );
451
- if (Array.isArray(orderRecord.products))
452
- orderRecord.products = productResult.items;
453
- if (Array.isArray(orderRecord.bookings))
454
- orderRecord.bookings = bookingResult.items;
455
- if (Array.isArray(orderRecord.payments))
456
- orderRecord.payments = paymentResult.items;
457
- const uidRemaps = [
458
- ...productResult.uidRemaps,
459
- ...bookingResult.uidRemaps,
460
- ...paymentResult.uidRemaps
461
- ];
411
+ const productResult = normalizeOrderCollection('product', Array.isArray(orderRecord.products) ? orderRecord.products : [], options);
412
+ const bookingResult = normalizeOrderCollection('booking', Array.isArray(orderRecord.bookings) ? orderRecord.bookings : [], options);
413
+ const paymentResult = normalizeOrderCollection('payment', Array.isArray(orderRecord.payments) ? orderRecord.payments : [], options);
414
+ if (Array.isArray(orderRecord.products)) orderRecord.products = productResult.items;
415
+ if (Array.isArray(orderRecord.bookings)) orderRecord.bookings = bookingResult.items;
416
+ if (Array.isArray(orderRecord.payments)) orderRecord.payments = paymentResult.items;
417
+ const uidRemaps = [...productResult.uidRemaps, ...bookingResult.uidRemaps, ...paymentResult.uidRemaps];
462
418
  order = applyOrderCollectionUidRemaps(order, uidRemaps);
463
419
  return {
464
420
  order,
@@ -469,20 +425,4 @@ function normalizeOrderCollections(sourceOrder, options) {
469
425
  },
470
426
  uidRemaps
471
427
  };
472
- }
473
- // Annotate the CommonJS export names for ESM import in node:
474
- 0 && (module.exports = {
475
- applyOrderCollectionUidRemaps,
476
- buildOrderCollectionFallbackUid,
477
- createUuidV4,
478
- getOrderCollectionPersistentId,
479
- getOrderCollectionReferenceUid,
480
- getOrderCollectionUid,
481
- isBlankOrderCollectionIdentity,
482
- isSameOrderCollectionItem,
483
- mergeOrderCollectionItems,
484
- normalizeOrderCollection,
485
- normalizeOrderCollections,
486
- repairDuplicateProductLineIdentities,
487
- setOrderCollectionUid
488
- });
428
+ }