@pisell/pisellos 2.2.314 → 2.2.316

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 (268) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  4. package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
  5. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  6. package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
  7. package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
  8. package/dist/model/strategy/adapter/itemRule/type.js +10 -0
  9. package/dist/model/strategy/adapter/promotion/evaluator.js +89 -104
  10. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
  11. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +28 -4
  12. package/dist/modules/BookingContext/utils/productExtend.d.ts +7 -0
  13. package/dist/modules/BookingContext/utils/productExtend.js +62 -18
  14. package/dist/modules/BookingContext/utils/resources.js +1 -1
  15. package/dist/modules/BusinessAvailability/index.d.ts +30 -0
  16. package/dist/modules/BusinessAvailability/index.js +204 -0
  17. package/dist/modules/Cart/index.js +4 -3
  18. package/dist/modules/Cart/types.d.ts +2 -0
  19. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  20. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  21. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  22. package/dist/modules/FulfillmentTiming/index.js +407 -0
  23. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  24. package/dist/modules/FulfillmentTiming/types.js +1 -0
  25. package/dist/modules/Holder/utils.d.ts +2 -0
  26. package/dist/modules/Holder/utils.js +32 -2
  27. package/dist/modules/OpenData/contactInfo.d.ts +20 -0
  28. package/dist/modules/OpenData/contactInfo.js +70 -0
  29. package/dist/modules/OpenData/index.d.ts +1 -0
  30. package/dist/modules/OpenData/index.js +1 -0
  31. package/dist/modules/OpenData/types.d.ts +23 -0
  32. package/dist/modules/Order/holderRelations.d.ts +14 -0
  33. package/dist/modules/Order/holderRelations.js +154 -0
  34. package/dist/modules/Order/index.d.ts +16 -4
  35. package/dist/modules/Order/index.js +926 -511
  36. package/dist/modules/Order/localEftposState.d.ts +13 -0
  37. package/dist/modules/Order/localEftposState.js +39 -0
  38. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  39. package/dist/modules/Order/pickupTiming.js +53 -0
  40. package/dist/modules/Order/types.d.ts +49 -3
  41. package/dist/modules/Order/types.js +2 -0
  42. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
  43. package/dist/modules/Order/utils/discountProductLineIdentity.js +142 -7
  44. package/dist/modules/Order/utils/orderCollectionIdentity.js +24 -10
  45. package/dist/modules/Order/utils.d.ts +2 -1
  46. package/dist/modules/Order/utils.js +61 -17
  47. package/dist/modules/Payment/index.js +9 -10
  48. package/dist/modules/Product/types.d.ts +11 -0
  49. package/dist/modules/ProductList/index.js +1 -1
  50. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  51. package/dist/modules/ResourcePlanner/planner.js +332 -23
  52. package/dist/modules/ResourcePlanner/types.d.ts +29 -0
  53. package/dist/modules/Rules/index.js +62 -61
  54. package/dist/modules/Schedule/index.d.ts +8 -0
  55. package/dist/modules/Schedule/index.js +141 -39
  56. package/dist/modules/index.d.ts +1 -0
  57. package/dist/modules/index.js +1 -0
  58. package/dist/plugins/request.d.ts +7 -0
  59. package/dist/server/index.d.ts +1 -0
  60. package/dist/server/index.js +1557 -1322
  61. package/dist/server/modules/form/index.d.ts +19 -0
  62. package/dist/server/modules/form/index.js +205 -0
  63. package/dist/server/modules/form/types.d.ts +13 -0
  64. package/dist/server/modules/form/types.js +3 -0
  65. package/dist/server/modules/index.d.ts +3 -0
  66. package/dist/server/modules/index.js +4 -0
  67. package/dist/server/modules/order/index.d.ts +19 -0
  68. package/dist/server/modules/order/index.js +1071 -774
  69. package/dist/server/modules/order/types.d.ts +4 -0
  70. package/dist/server/modules/products/index.d.ts +28 -7
  71. package/dist/server/modules/products/index.js +1297 -770
  72. package/dist/server/modules/products/replication.d.ts +8 -0
  73. package/dist/server/modules/products/replication.js +69 -0
  74. package/dist/server/modules/products/types.d.ts +12 -1
  75. package/dist/server/modules/products/types.js +4 -0
  76. package/dist/server/test.json +1 -1
  77. package/dist/server/utils/small-ticket.d.ts +1 -85
  78. package/dist/server/utils/small-ticket.js +2 -2542
  79. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  80. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  81. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  82. package/dist/shared/receipt/customerInvoiceLanguages.js +60 -0
  83. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +27 -0
  84. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +184 -0
  85. package/dist/shared/receipt/small-ticket.d.ts +96 -0
  86. package/dist/shared/receipt/small-ticket.js +2763 -0
  87. package/dist/shared/receipt/templateVisibility.d.ts +26 -0
  88. package/dist/shared/receipt/templateVisibility.js +68 -0
  89. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  90. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  91. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  92. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  93. package/dist/solution/BaseSales/index.d.ts +43 -16
  94. package/dist/solution/BaseSales/index.js +2028 -1247
  95. package/dist/solution/BaseSales/pickupTiming.d.ts +47 -0
  96. package/dist/solution/BaseSales/pickupTiming.js +616 -0
  97. package/dist/solution/BaseSales/types.d.ts +12 -0
  98. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
  99. package/dist/solution/BaseSales/utils/parseSalesResponse.js +10 -3
  100. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -4
  101. package/dist/solution/BookingByStep/index.d.ts +4 -2
  102. package/dist/solution/BookingByStep/index.js +8 -3
  103. package/dist/solution/BookingTicket/index.d.ts +23 -3
  104. package/dist/solution/BookingTicket/index.js +867 -507
  105. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -1
  106. package/dist/solution/BookingTicket/utils/addProductDecision.js +1 -1
  107. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  108. package/dist/solution/OrderInvoicePreview/index.d.ts +66 -0
  109. package/dist/solution/OrderInvoicePreview/index.js +340 -0
  110. package/dist/solution/RegisterAndLogin/config.js +54 -11
  111. package/dist/solution/RegisterAndLogin/index.d.ts +2 -0
  112. package/dist/solution/RegisterAndLogin/index.js +1 -1
  113. package/dist/solution/RegisterAndLogin/utils.d.ts +12 -4
  114. package/dist/solution/RegisterAndLogin/utils.js +36 -16
  115. package/dist/solution/ScanOrder/index.js +65 -31
  116. package/dist/solution/ScanOrder/types.d.ts +3 -0
  117. package/dist/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  118. package/dist/solution/UnifiedBookingSales/businessAvailability.js +292 -0
  119. package/dist/solution/UnifiedBookingSales/index.d.ts +36 -4
  120. package/dist/solution/UnifiedBookingSales/index.js +1715 -906
  121. package/dist/solution/UnifiedBookingSales/types.d.ts +16 -2
  122. package/dist/solution/VenueBooking/index.d.ts +15 -2
  123. package/dist/solution/VenueBooking/index.js +1062 -785
  124. package/dist/solution/VenueBooking/types.d.ts +2 -1
  125. package/dist/solution/VenueBooking/types.js +1 -0
  126. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  127. package/dist/solution/VenueBooking/utils/dateSummary.js +7 -4
  128. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  129. package/dist/solution/VenueBooking/utils/smartPricing.js +273 -0
  130. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  131. package/dist/solution/VenueBooking/utils/timeSlot.js +6 -3
  132. package/dist/solution/index.d.ts +1 -0
  133. package/dist/solution/index.js +2 -1
  134. package/lib/index.d.ts +2 -0
  135. package/lib/index.js +21 -1
  136. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  137. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  138. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  139. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  140. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  141. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  142. package/lib/model/strategy/adapter/promotion/evaluator.js +9 -14
  143. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  144. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
  145. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +17 -1
  146. package/lib/modules/BookingContext/utils/productExtend.d.ts +7 -0
  147. package/lib/modules/BookingContext/utils/productExtend.js +45 -2
  148. package/lib/modules/BookingContext/utils/resources.js +1 -1
  149. package/lib/modules/BusinessAvailability/index.d.ts +30 -0
  150. package/lib/modules/BusinessAvailability/index.js +146 -0
  151. package/lib/modules/Cart/index.js +4 -2
  152. package/lib/modules/Cart/types.d.ts +2 -0
  153. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  154. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  155. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  156. package/lib/modules/FulfillmentTiming/index.js +359 -0
  157. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  158. package/lib/modules/FulfillmentTiming/types.js +5 -0
  159. package/lib/modules/Holder/utils.d.ts +2 -0
  160. package/lib/modules/Holder/utils.js +27 -1
  161. package/lib/modules/OpenData/contactInfo.d.ts +20 -0
  162. package/lib/modules/OpenData/contactInfo.js +56 -0
  163. package/lib/modules/OpenData/index.d.ts +1 -0
  164. package/lib/modules/OpenData/index.js +12 -0
  165. package/lib/modules/OpenData/types.d.ts +23 -0
  166. package/lib/modules/Order/holderRelations.d.ts +14 -0
  167. package/lib/modules/Order/holderRelations.js +98 -0
  168. package/lib/modules/Order/index.d.ts +16 -4
  169. package/lib/modules/Order/index.js +284 -50
  170. package/lib/modules/Order/localEftposState.d.ts +13 -0
  171. package/lib/modules/Order/localEftposState.js +44 -0
  172. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  173. package/lib/modules/Order/pickupTiming.js +61 -0
  174. package/lib/modules/Order/types.d.ts +49 -3
  175. package/lib/modules/Order/types.js +1 -0
  176. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
  177. package/lib/modules/Order/utils/discountProductLineIdentity.js +51 -2
  178. package/lib/modules/Order/utils/orderCollectionIdentity.js +5 -0
  179. package/lib/modules/Order/utils.d.ts +2 -1
  180. package/lib/modules/Order/utils.js +49 -11
  181. package/lib/modules/Payment/index.js +3 -4
  182. package/lib/modules/Product/types.d.ts +11 -0
  183. package/lib/modules/ProductList/index.js +1 -1
  184. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  185. package/lib/modules/ResourcePlanner/planner.js +252 -8
  186. package/lib/modules/ResourcePlanner/types.d.ts +29 -0
  187. package/lib/modules/Rules/index.js +2 -1
  188. package/lib/modules/Schedule/index.d.ts +8 -0
  189. package/lib/modules/Schedule/index.js +68 -12
  190. package/lib/modules/index.d.ts +1 -0
  191. package/lib/modules/index.js +11 -0
  192. package/lib/plugins/request.d.ts +7 -0
  193. package/lib/server/index.d.ts +1 -0
  194. package/lib/server/index.js +166 -39
  195. package/lib/server/modules/form/index.d.ts +19 -0
  196. package/lib/server/modules/form/index.js +73 -0
  197. package/lib/server/modules/form/types.d.ts +13 -0
  198. package/lib/server/modules/form/types.js +9 -0
  199. package/lib/server/modules/index.d.ts +3 -0
  200. package/lib/server/modules/index.js +15 -1
  201. package/lib/server/modules/order/index.d.ts +19 -0
  202. package/lib/server/modules/order/index.js +160 -7
  203. package/lib/server/modules/order/types.d.ts +4 -0
  204. package/lib/server/modules/products/index.d.ts +28 -7
  205. package/lib/server/modules/products/index.js +226 -63
  206. package/lib/server/modules/products/replication.d.ts +8 -0
  207. package/lib/server/modules/products/replication.js +30 -0
  208. package/lib/server/modules/products/types.d.ts +12 -1
  209. package/lib/server/modules/products/types.js +3 -0
  210. package/lib/server/test.json +1 -1
  211. package/lib/server/utils/small-ticket.d.ts +1 -85
  212. package/lib/server/utils/small-ticket.js +9 -2305
  213. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  214. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  215. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  216. package/lib/shared/receipt/customerInvoiceLanguages.js +58 -0
  217. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +27 -0
  218. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +124 -0
  219. package/lib/shared/receipt/small-ticket.d.ts +96 -0
  220. package/lib/shared/receipt/small-ticket.js +2555 -0
  221. package/lib/shared/receipt/templateVisibility.d.ts +26 -0
  222. package/lib/shared/receipt/templateVisibility.js +67 -0
  223. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  224. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  225. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  226. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  227. package/lib/solution/BaseSales/index.d.ts +43 -16
  228. package/lib/solution/BaseSales/index.js +401 -33
  229. package/lib/solution/BaseSales/pickupTiming.d.ts +47 -0
  230. package/lib/solution/BaseSales/pickupTiming.js +290 -0
  231. package/lib/solution/BaseSales/types.d.ts +12 -0
  232. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
  233. package/lib/solution/BaseSales/utils/parseSalesResponse.js +7 -0
  234. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +16 -8
  235. package/lib/solution/BookingByStep/index.d.ts +4 -2
  236. package/lib/solution/BookingByStep/index.js +7 -3
  237. package/lib/solution/BookingTicket/index.d.ts +23 -3
  238. package/lib/solution/BookingTicket/index.js +197 -9
  239. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -1
  240. package/lib/solution/BookingTicket/utils/addProductDecision.js +1 -1
  241. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  242. package/lib/solution/OrderInvoicePreview/index.d.ts +66 -0
  243. package/lib/solution/OrderInvoicePreview/index.js +246 -0
  244. package/lib/solution/RegisterAndLogin/config.js +57 -11
  245. package/lib/solution/RegisterAndLogin/index.d.ts +2 -0
  246. package/lib/solution/RegisterAndLogin/index.js +9 -1
  247. package/lib/solution/RegisterAndLogin/utils.d.ts +12 -4
  248. package/lib/solution/RegisterAndLogin/utils.js +24 -17
  249. package/lib/solution/ScanOrder/index.js +59 -20
  250. package/lib/solution/ScanOrder/types.d.ts +3 -0
  251. package/lib/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  252. package/lib/solution/UnifiedBookingSales/businessAvailability.js +138 -0
  253. package/lib/solution/UnifiedBookingSales/index.d.ts +36 -4
  254. package/lib/solution/UnifiedBookingSales/index.js +562 -75
  255. package/lib/solution/UnifiedBookingSales/types.d.ts +16 -2
  256. package/lib/solution/VenueBooking/index.d.ts +15 -2
  257. package/lib/solution/VenueBooking/index.js +243 -96
  258. package/lib/solution/VenueBooking/types.d.ts +2 -1
  259. package/lib/solution/VenueBooking/types.js +1 -0
  260. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  261. package/lib/solution/VenueBooking/utils/dateSummary.js +7 -4
  262. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  263. package/lib/solution/VenueBooking/utils/smartPricing.js +224 -0
  264. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  265. package/lib/solution/VenueBooking/utils/timeSlot.js +5 -2
  266. package/lib/solution/index.d.ts +1 -0
  267. package/lib/solution/index.js +11 -0
  268. package/package.json +1 -1
@@ -0,0 +1,9 @@
1
+ import type { RequestPlugin } from '../../plugins/request';
2
+ import type { PaymentMethod } from '../../modules/Payment/types';
3
+ /** Shared read-only transport; customer hosts route the remote path under /h5. */
4
+ export declare function loadPaymentMethods(request: RequestPlugin, options: {
5
+ transport: 'remote' | 'os-server';
6
+ filterPaymentMethods: boolean;
7
+ }): Promise<PaymentMethod[]>;
8
+ /** Enrich a copy: never overwrite historical names or change payment amounts. */
9
+ export declare function withPaymentMethodNames(order: Record<string, any>, methods: PaymentMethod[]): Record<string, any>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadPaymentMethods = loadPaymentMethods;
7
+ exports.withPaymentMethodNames = withPaymentMethodNames;
8
+ /** Shared read-only transport; customer hosts route the remote path under /h5. */
9
+ async function loadPaymentMethods(request, options) {
10
+ const response = await request.get('/pay/custom-payment/all', {
11
+ filterPaymentMethods: options.filterPaymentMethods
12
+ }, options.transport === 'os-server' ? {
13
+ osServer: true
14
+ } : {
15
+ manualErrorHandling: true,
16
+ skipErrorHandler: true
17
+ });
18
+ const methods = response?.data ?? response;
19
+ if (!Array.isArray(methods)) throw new Error('Payment methods are unavailable');
20
+ return methods;
21
+ }
22
+
23
+ /** Enrich a copy: never overwrite historical names or change payment amounts. */
24
+ function withPaymentMethodNames(order, methods) {
25
+ if (!Array.isArray(order.payments)) return order;
26
+ return {
27
+ ...order,
28
+ payments: order.payments.map(payment => {
29
+ if (payment.name || payment.title || payment.payment_method_name || payment.method_name) return payment;
30
+ const id = payment.custom_payment_id;
31
+ const hasId = id !== undefined && id !== null && String(id).trim() !== '';
32
+ const code = payment.code || payment.type || payment.payment_method || payment.method;
33
+ const method = methods.find(candidate => hasId ? String(candidate.id) === String(id) : !!code && candidate.code === code);
34
+ return method?.name ? {
35
+ ...payment,
36
+ payment_method_name: method.name
37
+ } : payment;
38
+ })
39
+ };
40
+ }
@@ -0,0 +1,8 @@
1
+ export type CustomerInvoiceLanguageCode = 'en' | 'zh_CN' | 'zh_HK' | 'ja' | 'pt' | 'cn_en';
2
+ export interface CustomerInvoiceLanguageOption {
3
+ code: CustomerInvoiceLanguageCode;
4
+ locales: string[];
5
+ }
6
+ export declare function normalizeCustomerInvoiceLanguage(value: string): CustomerInvoiceLanguageCode | undefined;
7
+ /** Preserve configured insertion order; a print count never repeats an option. */
8
+ export declare function resolveCustomerInvoiceLanguages(language: Record<string, unknown>, pageLocale: string): CustomerInvoiceLanguageOption[];
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeCustomerInvoiceLanguage = normalizeCustomerInvoiceLanguage;
7
+ exports.resolveCustomerInvoiceLanguages = resolveCustomerInvoiceLanguages;
8
+ const aliases = {
9
+ en: 'en',
10
+ en_us: 'en',
11
+ en_gb: 'en',
12
+ en_au: 'en',
13
+ cn: 'zh_CN',
14
+ zh: 'zh_CN',
15
+ zh_cn: 'zh_CN',
16
+ zh_hans: 'zh_CN',
17
+ zh_sg: 'zh_CN',
18
+ hk: 'zh_HK',
19
+ zh_hk: 'zh_HK',
20
+ zh_tw: 'zh_HK',
21
+ zh_hant: 'zh_HK',
22
+ ja: 'ja',
23
+ ja_jp: 'ja',
24
+ jp: 'ja',
25
+ pt: 'pt',
26
+ pt_br: 'pt',
27
+ pt_pt: 'pt',
28
+ cn_en: 'cn_en',
29
+ en_cn: 'cn_en'
30
+ };
31
+ function normalizeCustomerInvoiceLanguage(value) {
32
+ return aliases[value.trim().toLowerCase().replace(/-/g, '_')];
33
+ }
34
+ function option(code) {
35
+ return {
36
+ code,
37
+ locales: code === 'cn_en' ? ['en', 'zh_CN'] : [code]
38
+ };
39
+ }
40
+
41
+ /** Preserve configured insertion order; a print count never repeats an option. */
42
+ function resolveCustomerInvoiceLanguages(language, pageLocale) {
43
+ const options = [];
44
+ const seen = new Set();
45
+ Object.entries(language).forEach(([key, count]) => {
46
+ if (typeof count !== 'number' || !Number.isFinite(count) || count <= 0) return;
47
+ const code = normalizeCustomerInvoiceLanguage(key);
48
+ if (!code || seen.has(code)) return;
49
+ seen.add(code);
50
+ options.push(option(code));
51
+ });
52
+ if (options.length) return options;
53
+ const normalized = normalizeCustomerInvoiceLanguage(pageLocale);
54
+ // A page locale is a single language, never a bilingual printer mode.
55
+ const requested = pageLocale.toLowerCase().replace(/_/g, '-');
56
+ const fallback = normalized && normalized !== 'cn_en' ? normalized : requested.startsWith('zh-tw') || requested.startsWith('zh-hk') ? 'zh_HK' : requested.startsWith('zh') ? 'zh_CN' : requested.startsWith('ja') ? 'ja' : requested.startsWith('pt') ? 'pt' : 'en';
57
+ return [option(fallback)];
58
+ }
@@ -0,0 +1,27 @@
1
+ import type { RequestPlugin } from '../../plugins/request';
2
+ import { type InvoiceLayoutConfig } from '../../modules/OpenData';
3
+ export interface PublicInvoiceDocumentResponse {
4
+ status: boolean;
5
+ code: number;
6
+ message?: string;
7
+ data: {
8
+ id: number;
9
+ data?: {
10
+ template_settings?: unknown;
11
+ } | null;
12
+ } | null;
13
+ }
14
+ export interface CustomerInvoiceTemplate {
15
+ layout: InvoiceLayoutConfig;
16
+ language: Record<string, unknown>;
17
+ }
18
+ interface TemplateScope {
19
+ tenantId: string | number;
20
+ shopId: string | number;
21
+ identity: string;
22
+ businessCode: string;
23
+ channel: string;
24
+ }
25
+ export declare function loadCustomerInvoiceTemplate(request: RequestPlugin, scope: TemplateScope): Promise<CustomerInvoiceTemplate>;
26
+ export declare function loadCustomerInvoiceLayout(request: RequestPlugin, scope: TemplateScope): Promise<InvoiceLayoutConfig>;
27
+ export {};
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadCustomerInvoiceLayout = loadCustomerInvoiceLayout;
7
+ exports.loadCustomerInvoiceTemplate = loadCustomerInvoiceTemplate;
8
+ var _OpenData = require("../../modules/OpenData");
9
+ // Page-runtime caches: also retain DEFAULT on failure, without automatic retries.
10
+ const caches = new WeakMap();
11
+ const isRecord = value => !!value && typeof value === 'object' && !Array.isArray(value);
12
+ function documentId(value) {
13
+ if (typeof value !== 'string' && typeof value !== 'number') return null;
14
+ const text = String(value).trim();
15
+ if (!/^\d+$/.test(text)) return null;
16
+ const id = Number(text);
17
+ return Number.isSafeInteger(id) && id > 0 ? String(id) : null;
18
+ }
19
+ function loadCustomerInvoiceTemplate(request, scope) {
20
+ let cache = caches.get(request);
21
+ if (!cache) {
22
+ cache = {
23
+ scopes: new Map(),
24
+ documents: new Map()
25
+ };
26
+ caches.set(request, cache);
27
+ }
28
+ const target = `${scope.businessCode}+${scope.channel}`;
29
+ const key = JSON.stringify([scope.tenantId, scope.shopId, scope.identity, scope.businessCode, scope.channel]);
30
+ const cached = cache.scopes.get(key);
31
+ if (cached) return cached;
32
+ let id = null;
33
+ const task = (async () => {
34
+ const response = await request.post(`/open/my-pisell/${encodeURIComponent(String(scope.shopId))}/setting`, {
35
+ scope: 'board',
36
+ target,
37
+ section_code: ['documents']
38
+ }, {
39
+ pisell2: true,
40
+ prefix: false,
41
+ headers: scope.tenantId ? {
42
+ 'Tenant-Id': String(scope.tenantId)
43
+ } : {},
44
+ manualErrorHandling: true,
45
+ skipErrorHandler: true,
46
+ timeout: 15000
47
+ });
48
+ if (response?.status !== true || response.code !== 200 || !isRecord(response.data)) throw new Error(response?.message || 'Invoice OpenData is unavailable');
49
+ const config = response.data;
50
+ const raw = config['documents.invoice_template'];
51
+ id = documentId(raw);
52
+ if (!id) {
53
+ // Preserve the existing non-numeric legacy template / invoice_edit contract.
54
+ const numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
55
+ return typeof raw === 'string' && raw.trim() && !numericLike.test(raw.trim()) ? {
56
+ layout: (0, _OpenData.normalizeInvoiceLayoutFromTemplateSettings)((0, _OpenData.normalizeInvoiceTemplateSettings)(config)),
57
+ language: readLanguage(config['documents.invoice_edit'])
58
+ } : defaultTemplate();
59
+ }
60
+ const docKey = JSON.stringify([key, id]);
61
+ let pending = cache.documents.get(docKey);
62
+ if (!pending) {
63
+ const expectedId = id;
64
+ pending = (async () => {
65
+ const result = await request.get(`/open/document/${expectedId}`, {}, {
66
+ publicInvoiceDocument: true
67
+ });
68
+ if (result?.status !== true || result.code !== 200) throw new Error(result?.message || 'Invoice Document request failed');
69
+ const doc = result.data;
70
+ if (!doc || documentId(doc.id) !== expectedId) throw new Error('Invoice Document is unavailable or its ID does not match');
71
+ if (!isRecord(doc.data) || !isRecord(doc.data.template_settings)) throw new Error('Invoice Document has no template_settings');
72
+ const settings = (0, _OpenData.normalizeRawInvoiceTemplateSettings)(doc.data.template_settings);
73
+ if (settings.modules.length === 0) throw new Error('Invoice Document has no usable template modules');
74
+ return {
75
+ layout: (0, _OpenData.normalizeInvoiceLayoutFromTemplateSettings)(settings),
76
+ language: readLanguage(doc.data.template_settings)
77
+ };
78
+ })().catch(error => fallback(error, target, expectedId));
79
+ cache.documents.set(docKey, pending);
80
+ }
81
+ return pending;
82
+ })().catch(error => fallback(error, target, id));
83
+ cache.scopes.set(key, task);
84
+ return task;
85
+ }
86
+ function fallback(error, target, id) {
87
+ console.warn('[OrderInvoicePreview] Template unavailable; using DEFAULT', {
88
+ target,
89
+ documentId: id,
90
+ message: error instanceof Error ? error.message : 'Template request failed'
91
+ });
92
+ return defaultTemplate();
93
+ }
94
+
95
+ // Keep the existing layout-only API and its in-flight promise identity intact.
96
+ const layoutPromises = new WeakMap();
97
+ function loadCustomerInvoiceLayout(request, scope) {
98
+ const template = loadCustomerInvoiceTemplate(request, scope);
99
+ let layout = layoutPromises.get(template);
100
+ if (!layout) {
101
+ layout = template.then(value => value.layout);
102
+ layoutPromises.set(template, layout);
103
+ }
104
+ return layout;
105
+ }
106
+ function defaultTemplate() {
107
+ return {
108
+ layout: (0, _OpenData.getDefaultInvoiceLayoutConfig)(),
109
+ language: {}
110
+ };
111
+ }
112
+ function readLanguage(value) {
113
+ let settings = value;
114
+ if (typeof settings === 'string') {
115
+ try {
116
+ settings = JSON.parse(settings);
117
+ } catch {
118
+ return {};
119
+ }
120
+ }
121
+ return isRecord(settings) && isRecord(settings.language) ? {
122
+ ...settings.language
123
+ } : {};
124
+ }
@@ -0,0 +1,96 @@
1
+ export interface SmallTicketShopInfo {
2
+ name?: string;
3
+ phone?: string;
4
+ address?: string;
5
+ address_street?: string;
6
+ address_detail?: string;
7
+ city?: string;
8
+ province?: string;
9
+ country?: string;
10
+ zip?: string;
11
+ tax_number?: string;
12
+ tax_title?: string;
13
+ is_price_include_tax?: 0 | 1 | boolean;
14
+ currency_symbol?: string;
15
+ currency_code?: string;
16
+ primary_locale?: string;
17
+ timezone?: string;
18
+ [key: string]: any;
19
+ }
20
+ export interface BuildSmallTicketDataParams {
21
+ order: Record<string, any>;
22
+ shopInfo?: SmallTicketShopInfo | null;
23
+ locales?: string[];
24
+ productMap?: Record<string | number, Record<string, any>>;
25
+ /** Resolved template settings or layout; omitted settings preserve native compatibility. */
26
+ templateSettings?: unknown;
27
+ /** Customer preview only: stable source identities for bilingual rows. */
28
+ includeReceiptKeys?: boolean;
29
+ }
30
+ export interface SmallTicketItem {
31
+ receipt_key?: string;
32
+ receipt_value_kind?: 'shared' | 'text';
33
+ receipt_item_kind?: 'shared';
34
+ item: string;
35
+ value: string;
36
+ size?: number;
37
+ align?: string;
38
+ product_uid?: string | number;
39
+ booking_uid?: string | number;
40
+ }
41
+ export interface SmallTicketProduct {
42
+ receipt_key?: string;
43
+ receipt_source_index?: number;
44
+ product_title: string;
45
+ product_quantity: number;
46
+ selling_price: string;
47
+ total_selling_price: string;
48
+ original_price: string;
49
+ base_price?: string;
50
+ total_original_price: string;
51
+ options_total_price?: string;
52
+ package_items_total_price?: string;
53
+ extension_list: any[];
54
+ product_uid?: string | number;
55
+ booking_uid?: string | number;
56
+ product_note?: string;
57
+ allergy?: string;
58
+ options?: Array<{
59
+ receipt_key?: string;
60
+ receipt_source_index?: number;
61
+ name: string;
62
+ num?: number;
63
+ price?: string;
64
+ total_price: string;
65
+ value?: string;
66
+ }>;
67
+ variant?: string;
68
+ combinations?: any[];
69
+ }
70
+ export type SmallTicketAppointment = SmallTicketItem[];
71
+ export interface SmallTicketLocaleData {
72
+ base_data: Record<string, any>;
73
+ products: SmallTicketProduct[];
74
+ fees: {
75
+ fees: SmallTicketItem[];
76
+ countFee: Record<string, any>;
77
+ };
78
+ customer: SmallTicketItem[];
79
+ appointment: SmallTicketAppointment;
80
+ delivery?: SmallTicketItem[];
81
+ resources: Array<{
82
+ id: string | number;
83
+ code: string;
84
+ title: string;
85
+ form_title: string;
86
+ }>;
87
+ payment_data: SmallTicketItem[][];
88
+ wallets: SmallTicketItem[][];
89
+ tickets: any[];
90
+ source_shop: any[];
91
+ refund_data: SmallTicketItem[][];
92
+ expend_data: any[];
93
+ }
94
+ export type SmallTicketData = Record<string, SmallTicketLocaleData>;
95
+ export declare function buildSmallTicketData(params: BuildSmallTicketDataParams): SmallTicketData;
96
+ export declare function hasSmallTicketData(value: any): boolean;