@pisell/private-materials 6.12.367 → 6.12.368

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.
@@ -288,8 +288,9 @@ function bookingHeadersAreVisible(config) {
288
288
  return require_invoiceVisibility.isInvoiceFieldVisible(config, "booking");
289
289
  }
290
290
  const renderBrand = ({ config, receipt }) => {
291
- var _receipt$secondary2, _receipt$secondary3;
291
+ var _receipt$secondary2, _receipt$secondary3, _receipt$secondary4;
292
292
  const base = receipt.baseData;
293
+ const isJapaneseEnglish = receipt.locale.toLowerCase().startsWith("ja") && ((_receipt$secondary2 = receipt.secondary) === null || _receipt$secondary2 === void 0 ? void 0 : _receipt$secondary2.locale.toLowerCase().startsWith("en"));
293
294
  const show = (field) => require_invoiceVisibility.isInvoiceFieldVisible(config, field);
294
295
  const logo = show("logo") && receipt.brandLogo;
295
296
  const name = show("store_name") && base.shop_name;
@@ -301,7 +302,7 @@ const renderBrand = ({ config, receipt }) => {
301
302
  return /* @__PURE__ */ react.default.createElement("section", { className: `${PREFIX}__receipt-brand` }, logo ? /* @__PURE__ */ react.default.createElement("img", {
302
303
  alt: "",
303
304
  src: receipt.brandLogo
304
- }) : null, name ? /* @__PURE__ */ react.default.createElement("h2", null, require_receiptTranslations.bilingualText(base.shop_name, (_receipt$secondary2 = receipt.secondary) === null || _receipt$secondary2 === void 0 ? void 0 : _receipt$secondary2.baseData.shop_name)) : null, taxNumber ? /* @__PURE__ */ react.default.createElement("div", null, receipt.taxNumberLabel ? `${receipt.taxNumberLabel}: ` : "", base.shop_tax_number) : null, address ? /* @__PURE__ */ react.default.createElement("div", null, require_receiptTranslations.bilingualText(base.shop_address, (_receipt$secondary3 = receipt.secondary) === null || _receipt$secondary3 === void 0 ? void 0 : _receipt$secondary3.baseData.shop_address)) : null, phone ? /* @__PURE__ */ react.default.createElement("div", null, base.shop_phone) : null, title ? /* @__PURE__ */ react.default.createElement("strong", { className: `${PREFIX}__receipt-bill-title` }, require_receiptTranslations.receiptLabel(receipt, receipt.billTitle)) : null);
305
+ }) : null, name ? /* @__PURE__ */ react.default.createElement("h2", null, require_receiptTranslations.bilingualText(base.shop_name, (_receipt$secondary3 = receipt.secondary) === null || _receipt$secondary3 === void 0 ? void 0 : _receipt$secondary3.baseData.shop_name)) : null, taxNumber ? /* @__PURE__ */ react.default.createElement("div", null, receipt.taxNumberLabel ? `${receipt.taxNumberLabel}: ` : "", base.shop_tax_number) : null, address ? /* @__PURE__ */ react.default.createElement("div", null, require_receiptTranslations.bilingualText(base.shop_address, (_receipt$secondary4 = receipt.secondary) === null || _receipt$secondary4 === void 0 ? void 0 : _receipt$secondary4.baseData.shop_address)) : null, phone ? /* @__PURE__ */ react.default.createElement("div", null, base.shop_phone) : null, title ? /* @__PURE__ */ react.default.createElement("strong", { className: `${PREFIX}__receipt-bill-title` }, isJapaneseEnglish ? label(receipt.billTitle, "en") : require_receiptTranslations.receiptLabel(receipt, receipt.billTitle)) : null);
305
306
  };
306
307
  /** Stable row keys survive translation; localized labels are never selectors. */
307
308
  function visibleSemanticRows(rows, config, fields) {
@@ -329,8 +330,8 @@ const renderOrder = ({ config, receipt }) => {
329
330
  }) : null);
330
331
  };
331
332
  const renderCustom = ({ config, receipt }) => {
332
- var _receipt$secondary4;
333
- return renderCustomModule(config, receipt.locale, (_receipt$secondary4 = receipt.secondary) === null || _receipt$secondary4 === void 0 ? void 0 : _receipt$secondary4.locale);
333
+ var _receipt$secondary5;
334
+ return renderCustomModule(config, receipt.locale, (_receipt$secondary5 = receipt.secondary) === null || _receipt$secondary5 === void 0 ? void 0 : _receipt$secondary5.locale);
334
335
  };
335
336
  const MODULE_RENDERERS = {
336
337
  reference: ({ receipt }) => receipt.reference ? /* @__PURE__ */ react.default.createElement("section", { className: `${PREFIX}__receipt-reference` }, /* @__PURE__ */ react.default.createElement("span", null, require_receiptTranslations.receiptLabel(receipt, "Reference")), /* @__PURE__ */ react.default.createElement("strong", null, receipt.reference)) : null,
@@ -349,8 +350,8 @@ const MODULE_RENDERERS = {
349
350
  line_groups: ({ config, receipt }) => {
350
351
  const showBookingHeaders = bookingHeadersAreVisible(config);
351
352
  const lineGroups = showBookingHeaders ? receipt.lineGroups.filter((group) => {
352
- var _receipt$secondary5;
353
- return group.products.length || lineGroupMetaRows(group, receipt.locale, (_receipt$secondary5 = receipt.secondary) === null || _receipt$secondary5 === void 0 ? void 0 : _receipt$secondary5.locale).length;
353
+ var _receipt$secondary6;
354
+ return group.products.length || lineGroupMetaRows(group, receipt.locale, (_receipt$secondary6 = receipt.secondary) === null || _receipt$secondary6 === void 0 ? void 0 : _receipt$secondary6.locale).length;
354
355
  }) : receipt.products.length ? [{
355
356
  key: "all-items",
356
357
  products: receipt.products,
@@ -361,12 +362,12 @@ const MODULE_RENDERERS = {
361
362
  locale: receipt.locale,
362
363
  rows: tableRows
363
364
  }), lineGroups.map((group) => {
364
- var _receipt$secondary6;
365
+ var _receipt$secondary7;
365
366
  return /* @__PURE__ */ react.default.createElement(LineGroup, {
366
367
  group,
367
368
  key: group.key,
368
369
  locale: receipt.locale,
369
- secondaryLocale: (_receipt$secondary6 = receipt.secondary) === null || _receipt$secondary6 === void 0 ? void 0 : _receipt$secondary6.locale,
370
+ secondaryLocale: (_receipt$secondary7 = receipt.secondary) === null || _receipt$secondary7 === void 0 ? void 0 : _receipt$secondary7.locale,
370
371
  config
371
372
  });
372
373
  })) : null;
@@ -402,8 +403,8 @@ const MODULE_RENDERERS = {
402
403
  locale: receipt.locale
403
404
  })) : null,
404
405
  total_savings: ({ config, receipt }) => {
405
- var _receipt$secondary7;
406
- return receipt.totalSavings ? /* @__PURE__ */ react.default.createElement("section", null, /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX}__receipt-savings` }, /* @__PURE__ */ react.default.createElement("strong", null, require_receiptTranslations.receiptLabel(receipt, "Total Savings")), /* @__PURE__ */ react.default.createElement("strong", null, receipt.totalSavings)), require_invoiceVisibility.isInvoiceFieldVisible(config, "description") && receipt.totalSavingsDescription ? /* @__PURE__ */ react.default.createElement("p", { className: `${PREFIX}__receipt-savings-description` }, require_receiptTranslations.bilingualText(receipt.totalSavingsDescription, (_receipt$secondary7 = receipt.secondary) === null || _receipt$secondary7 === void 0 ? void 0 : _receipt$secondary7.totalSavingsDescription)) : null) : null;
406
+ var _receipt$secondary8;
407
+ return receipt.totalSavings ? /* @__PURE__ */ react.default.createElement("section", null, /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX}__receipt-savings` }, /* @__PURE__ */ react.default.createElement("strong", null, require_receiptTranslations.receiptLabel(receipt, "Total Savings")), /* @__PURE__ */ react.default.createElement("strong", null, receipt.totalSavings)), require_invoiceVisibility.isInvoiceFieldVisible(config, "description") && receipt.totalSavingsDescription ? /* @__PURE__ */ react.default.createElement("p", { className: `${PREFIX}__receipt-savings-description` }, require_receiptTranslations.bilingualText(receipt.totalSavingsDescription, (_receipt$secondary8 = receipt.secondary) === null || _receipt$secondary8 === void 0 ? void 0 : _receipt$secondary8.totalSavingsDescription)) : null) : null;
407
408
  },
408
409
  custom_3: renderCustom,
409
410
  barcode: ({ receipt }) => receipt.barcodeValue ? /* @__PURE__ */ react.default.createElement("section", { className: `${PREFIX}__receipt-barcode` }, /* @__PURE__ */ react.default.createElement(_pisell_materials.QRCode, {
@@ -566,11 +566,17 @@ const SalesSdkProvider = ({ osKey, enableMultiCurrencySettlement = false, soluti
566
566
  snapshotPreserved: false
567
567
  };
568
568
  });
569
+ const isOrderBootstrapPending = lifecycleOwner === "provider" && (autoRestoreOnInit || Boolean(autoBootstrap && orderId)) && settledBootstrapKey !== bootstrapKey;
570
+ const syncBusinessCode = businessCode || moduleOtherParams.businessCode || (otherParams === null || otherParams === void 0 ? void 0 : otherParams.business_code);
569
571
  const { publishTempOrder } = require_useSalesSdkTempOrderSync.useSalesSdkTempOrderSync({
570
572
  enabled: enableTempOrderSync,
571
- ready: !(lifecycleOwner === "provider" && (autoRestoreOnInit || Boolean(autoBootstrap && orderId)) && settledBootstrapKey !== bootstrapKey),
573
+ ready: !isOrderBootstrapPending,
572
574
  isActive,
573
575
  osKey: (osKey === null || osKey === void 0 || (_osKey$replace = osKey.replace) === null || _osKey$replace === void 0 ? void 0 : _osKey$replace.call(osKey, "bookingTicket-", "")) || osKey,
576
+ salesContext: typeof syncBusinessCode === "string" && syncBusinessCode.trim() ? {
577
+ businessCode: syncBusinessCode,
578
+ channel: productLoadChannel
579
+ } : void 0,
574
580
  bookingTicket,
575
581
  refreshRootSnapshot
576
582
  });
@@ -18,6 +18,13 @@ function getPayloadRevision(payload) {
18
18
  function getPayloadSourceKey(payload) {
19
19
  return `${payload.osKey}:${payload.sourceId}`;
20
20
  }
21
+ function getSalesContextKey(salesContext) {
22
+ return JSON.stringify([salesContext === null || salesContext === void 0 ? void 0 : salesContext.businessCode, salesContext === null || salesContext === void 0 ? void 0 : salesContext.channel]);
23
+ }
24
+ function isSalesContextAlignedWithOrder(tempOrder, salesContext) {
25
+ const orderBusinessCode = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.business_code;
26
+ return !salesContext || typeof orderBusinessCode !== "string" || !orderBusinessCode.trim() || orderBusinessCode === salesContext.businessCode;
27
+ }
21
28
  function resolvePayloadDiscountState(payload) {
22
29
  var _payload$tempOrder;
23
30
  if (payload.discountState) return (0, lodash.cloneDeep)(payload.discountState);
@@ -51,7 +58,7 @@ function isWalletSnapshotAlignedWithCurrentOrder(bookingTicket, snapshot) {
51
58
  * 两端都可发布本地变更、接收同 osKey 快照;页面激活时向更早激活的对端补拉。
52
59
  * 远端快照应用期间禁止再次发布,避免 replaceTempOrder 触发 refresh 后形成回环。
53
60
  */
54
- function useSalesSdkTempOrderSync({ enabled, ready = true, isActive = true, osKey, bookingTicket, refreshRootSnapshot }) {
61
+ function useSalesSdkTempOrderSync({ enabled, ready = true, isActive = true, osKey, salesContext, bookingTicket, refreshRootSnapshot }) {
55
62
  var _context$appHelper, _context$appHelper$ge, _app$getPlugin, _unifiedCommunication;
56
63
  const context = require_useEngineContext.default();
57
64
  const app = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 || (_context$appHelper$ge = _context$appHelper.getApp) === null || _context$appHelper$ge === void 0 ? void 0 : _context$appHelper$ge.call(_context$appHelper);
@@ -80,13 +87,19 @@ function useSalesSdkTempOrderSync({ enabled, ready = true, isActive = true, osKe
80
87
  const latestOfferedRevisionBySourceRef = (0, react.useRef)(/* @__PURE__ */ new Map());
81
88
  const applyQueueRef = (0, react.useRef)(Promise.resolve());
82
89
  const lastAppliedRemoteOriginRef = (0, react.useRef)(null);
90
+ const salesContextKey = getSalesContextKey(salesContext);
91
+ const previousSalesContextKeyRef = (0, react.useRef)(salesContextKey);
83
92
  isActiveRef.current = isActive;
84
93
  readyRef.current = ready;
85
94
  const getPeerTarget = (0, ahooks.useMemoizedFn)((role) => require_tempOrderSync.resolveTempOrderSyncPeerTarget(role, endpoints));
86
- /** 在触发发布时一次性深拷贝订单与折扣上下文,避免防抖期间 OS 原地修改造成版本错配。 */
95
+ /** 发布时一起拷贝订单、业务与折扣上下文,避免防抖期间 OS 原地修改造成版本错配。 */
87
96
  const captureRuntimeSnapshot = (0, ahooks.useMemoizedFn)((tempOrder, causalOrigin) => {
88
97
  const snapshot = {
89
98
  tempOrder,
99
+ salesContext: require_tempOrderSync.resolveTempOrderSyncSalesContext({
100
+ tempOrder,
101
+ salesContext
102
+ }),
90
103
  causalOrigin
91
104
  };
92
105
  if (!bookingTicket) return require_tempOrderSync.cloneTempOrderSyncSnapshot(snapshot);
@@ -113,6 +126,12 @@ function useSalesSdkTempOrderSync({ enabled, ready = true, isActive = true, osKe
113
126
  var _ref = require_asyncToGenerator._asyncToGenerator(function* (snapshot, options = {}) {
114
127
  if (!enabled || !ready || !screenRole || !isActiveRef.current) return;
115
128
  if (remoteApplyingRef.current && !options.responseToRequestId) return;
129
+ if (!isSalesContextAlignedWithOrder(snapshot.tempOrder, snapshot.salesContext)) return;
130
+ const currentSalesContext = require_tempOrderSync.resolveTempOrderSyncSalesContext({
131
+ tempOrder: snapshot.tempOrder,
132
+ salesContext
133
+ });
134
+ if (getSalesContextKey(snapshot.salesContext) !== getSalesContextKey(currentSalesContext)) return;
116
135
  if (options.incrementRevision !== false) revisionRef.current += 1;
117
136
  try {
118
137
  var _snapshot$causalOrigi, _unifiedCommunication2, _unifiedCommunication3;
@@ -135,6 +154,7 @@ function useSalesSdkTempOrderSync({ enabled, ready = true, isActive = true, osKe
135
154
  timestamp: Date.now(),
136
155
  isActive: true,
137
156
  tempOrder: snapshot.tempOrder,
157
+ salesContext: snapshot.salesContext,
138
158
  discountState: snapshot.discountState,
139
159
  walletAssetsSnapshot: snapshot.walletAssetsSnapshot
140
160
  },
@@ -162,7 +182,7 @@ function useSalesSdkTempOrderSync({ enabled, ready = true, isActive = true, osKe
162
182
  });
163
183
  const publishTempOrder = (0, ahooks.useMemoizedFn)((tempOrder, options = {}) => {
164
184
  var _lastAppliedRemoteOri;
165
- if (!enabled || !ready || !screenRole || !isActiveRef.current || remoteApplyingRef.current) return;
185
+ if (!enabled || !ready || !screenRole || !isActiveRef.current || remoteApplyingRef.current || !isSalesContextAlignedWithOrder(tempOrder, salesContext)) return;
166
186
  const causalOrigin = options.preserveRemoteOrigin ? (_lastAppliedRemoteOri = lastAppliedRemoteOriginRef.current) !== null && _lastAppliedRemoteOri !== void 0 ? _lastAppliedRemoteOri : void 0 : void 0;
167
187
  if (!options.preserveRemoteOrigin) {
168
188
  lastAppliedRemoteOriginRef.current = null;
@@ -477,6 +497,26 @@ function useSalesSdkTempOrderSync({ enabled, ready = true, isActive = true, osKe
477
497
  applyPayload,
478
498
  cancelDebouncedPublish
479
499
  ]);
500
+ (0, react.useEffect)(() => {
501
+ var _bookingTicket$getTem5, _bookingTicket$getTem6;
502
+ if (previousSalesContextKeyRef.current === salesContextKey) return;
503
+ cancelDebouncedPublish();
504
+ if (!enabled || !ready || !isActive || screenRole !== "main" || !salesContext || !bookingTicket || remoteApplyingRef.current) return;
505
+ const tempOrder = (_bookingTicket$getTem5 = (_bookingTicket$getTem6 = bookingTicket.getTempOrder) === null || _bookingTicket$getTem6 === void 0 ? void 0 : _bookingTicket$getTem6.call(bookingTicket)) !== null && _bookingTicket$getTem5 !== void 0 ? _bookingTicket$getTem5 : null;
506
+ if (!isSalesContextAlignedWithOrder(tempOrder, salesContext)) return;
507
+ previousSalesContextKeyRef.current = salesContextKey;
508
+ publishTempOrder(tempOrder);
509
+ }, [
510
+ salesContextKey,
511
+ bookingTicket,
512
+ enabled,
513
+ ready,
514
+ isActive,
515
+ osKey,
516
+ screenRole,
517
+ publishTempOrder,
518
+ cancelDebouncedPublish
519
+ ]);
480
520
  (0, react.useEffect)(() => () => {
481
521
  activationEpochRef.current += 1;
482
522
  activationKeyRef.current = null;
@@ -0,0 +1 @@
1
+ export { };
@@ -21,6 +21,16 @@ function getMessageData(event) {
21
21
  function isRecord(value) {
22
22
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
23
23
  }
24
+ function isSalesContext(value) {
25
+ return isRecord(value) && typeof value.businessCode === "string" && value.businessCode.trim().length > 0 && (value.channel === void 0 || typeof value.channel === "string" && value.channel.trim().length > 0);
26
+ }
27
+ /** 旧发送端只有订单字段;它无法证明销售渠道,因此不推测 channel。 */
28
+ function resolveTempOrderSyncSalesContext(payload) {
29
+ var _payload$tempOrder;
30
+ if (payload.salesContext) return payload.salesContext;
31
+ const businessCode = (_payload$tempOrder = payload.tempOrder) === null || _payload$tempOrder === void 0 ? void 0 : _payload$tempOrder.business_code;
32
+ return typeof businessCode === "string" && businessCode.trim() ? { businessCode } : void 0;
33
+ }
24
34
  function isWalletAssetsSnapshot(value) {
25
35
  if (!isRecord(value) || !isRecord(value.state)) return false;
26
36
  const state = value.state;
@@ -42,6 +52,7 @@ function getTempOrderSyncPayload(event) {
42
52
  if (payload.activeSince !== void 0 && !Number.isFinite(payload.activeSince)) return null;
43
53
  if (!Object.prototype.hasOwnProperty.call(payload, "tempOrder")) return null;
44
54
  if (payload.tempOrder !== null && (typeof payload.tempOrder !== "object" || Array.isArray(payload.tempOrder))) return null;
55
+ if (payload.salesContext !== void 0 && !isSalesContext(payload.salesContext)) return null;
45
56
  if (payload.discountState !== void 0) {
46
57
  if (!payload.discountState || typeof payload.discountState !== "object" || Array.isArray(payload.discountState) || !Array.isArray(payload.discountState.discountList) || !Array.isArray(payload.discountState.originalDiscountList)) return null;
47
58
  }
@@ -93,6 +104,7 @@ exports.cloneTempOrderSyncSnapshot = cloneTempOrderSyncSnapshot;
93
104
  exports.getTempOrderSyncPayload = getTempOrderSyncPayload;
94
105
  exports.getTempOrderSyncRequestPayload = getTempOrderSyncRequestPayload;
95
106
  exports.resolveTempOrderSyncPeerTarget = resolveTempOrderSyncPeerTarget;
107
+ exports.resolveTempOrderSyncSalesContext = resolveTempOrderSyncSalesContext;
96
108
  exports.resolveTempOrderSyncScreenRole = resolveTempOrderSyncScreenRole;
97
109
  exports.shouldApplySharedTempOrderPayload = shouldApplySharedTempOrderPayload;
98
110
  exports.shouldRespondToTempOrderSyncRequest = shouldRespondToTempOrderSyncRequest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.12.367",
3
+ "version": "6.12.368",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -74,10 +74,10 @@
74
74
  "styled-components": "^6.0.0-rc.3",
75
75
  "use-sync-external-store": "^1.6.0",
76
76
  "@pisell/pi-payment-sdk": "0.0.4",
77
+ "@pisell/date-picker": "3.0.12",
77
78
  "@pisell/utils": "3.0.7",
78
79
  "@pisell/materials": "6.12.87",
79
- "@pisell/icon": "0.0.11",
80
- "@pisell/date-picker": "3.0.12"
80
+ "@pisell/icon": "0.0.11"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "react": "^18.0.0",