@pisell/private-materials 6.12.364 → 6.12.365

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.
@@ -2,6 +2,7 @@ import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/
2
2
  import { _objectWithoutProperties } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
3
3
  import { generateProductTabs, sortProductsByTabOrder } from "../../ticketBooking/components/ProductDisplayAdapter/utils.js";
4
4
  import { ProductDisplayPresets } from "../../ticketBooking/components/ProductDisplayAdapter/types.js";
5
+ import "../../ticketBooking/components/ProductDisplayAdapter/index.js";
5
6
  import { mergeBigSaleProductListPreferences } from "../utils/productListPreferences.js";
6
7
  import { useMemo, useRef } from "react";
7
8
  import isEqual from "lodash/isEqual";
@@ -0,0 +1,79 @@
1
+ const assert = require('node:assert/strict');
2
+ const { readFileSync } = require('node:fs');
3
+ const { join } = require('node:path');
4
+ const test = require('node:test');
5
+ const ts = require('typescript');
6
+
7
+ // Run with node --test; load the pure adapter in memory without a materials build.
8
+ const source = readFileSync(join(__dirname, 'toShoppingCartProducts.ts'), 'utf8');
9
+ const output = ts.transpileModule(source, {
10
+ compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
11
+ });
12
+ const adapter = { exports: {} };
13
+ new Function('exports', output.outputText)(adapter.exports);
14
+ const { toShoppingCartProducts } = adapter.exports;
15
+
16
+ const product = {
17
+ product_id: 477300,
18
+ product_variant_id: 493720,
19
+ product_title: 'Latte',
20
+ selling_price: '5.70',
21
+ num: 1,
22
+ product_sku: {
23
+ option: [{ product_option_item_id: 101, name: 'Almond Milk', add_price: 0.7, num: 1 }],
24
+ },
25
+ };
26
+ const toCart = (...products) => toShoppingCartProducts({ orderProducts: products });
27
+
28
+ test('current OS rows retain their metadata identity for cart delete and edit callbacks', () => {
29
+ const uid = '0dd325cf-545e-4665-bda0-d1a26046f78e';
30
+ const input = { ...product, metadata: { unique_identification_number: uid } };
31
+ const [row] = toCart(input);
32
+ assert.equal(row.identity_key, uid);
33
+ assert.equal(row.rowKey, uid);
34
+ assert.equal(row._id, uid);
35
+ assert.equal(row.price, 5.7);
36
+ assert.equal(row.options[0].name, 'Almond Milk');
37
+ assert.equal(input.identity_key, undefined);
38
+ });
39
+
40
+ test('same-SKU option rows remain independently addressable when cart order changes', () => {
41
+ const almond = { ...product, metadata: { unique_identification_number: 'almond-row' } };
42
+ const regular = {
43
+ ...product,
44
+ product_sku: { option: [] },
45
+ metadata: { unique_identification_number: 'regular-row' },
46
+ };
47
+ const original = toCart(almond, regular);
48
+ const reordered = toCart(regular, almond);
49
+ assert.notEqual(original[0].identity_key, original[1].identity_key);
50
+ assert.equal(original[0].identity_key, reordered[1].identity_key);
51
+ assert.equal(original[1].identity_key, reordered[0].identity_key);
52
+ });
53
+
54
+ test('metadata identity takes precedence over stale top-level compatibility fields', () => {
55
+ const [row] = toCart({
56
+ ...product,
57
+ metadata: { unique_identification_number: 'canonical-row' },
58
+ unique_identification_number: 'old-top-level-row',
59
+ identity_key: 'old-alias-row',
60
+ });
61
+ assert.equal(row.identity_key, 'canonical-row');
62
+ });
63
+
64
+ test('accepts top-level and legacy OS identities when metadata has no valid identity', () => {
65
+ for (const metadata of [undefined, {}, { unique_identification_number: '' }, { unique_identification_number: 123 }]) {
66
+ const [current, legacy] = toCart(
67
+ { ...product, metadata, unique_identification_number: 'top-level-row' },
68
+ { ...product, metadata, identity_key: 'legacy-row' },
69
+ );
70
+ assert.equal(current.identity_key, 'top-level-row');
71
+ assert.equal(legacy.identity_key, 'legacy-row');
72
+ }
73
+ });
74
+
75
+ test('a display-only row key never becomes a deletion identity', () => {
76
+ const [row] = toCart(product);
77
+ assert.equal(row.rowKey, '477300_493720_0');
78
+ assert.equal(row.identity_key, undefined);
79
+ });
@@ -174,11 +174,15 @@ function toShoppingCartProducts(params) {
174
174
  const { orderProducts, amountSymbol = "$" } = params;
175
175
  if (!Array.isArray(orderProducts)) return [];
176
176
  return orderProducts.map((productItem, index) => {
177
- var _productItem$_origin, _productItem$product_, _productItem$metadata;
177
+ var _productItem$_origin, _productItem$metadata, _productItem$product_, _productItem$metadata2;
178
178
  const productNum = toSafeNum(productItem === null || productItem === void 0 ? void 0 : productItem.num);
179
179
  const unitPrice = getUnitPrice(productItem);
180
180
  const callbackData = (productItem === null || productItem === void 0 || (_productItem$_origin = productItem._origin) === null || _productItem$_origin === void 0 ? void 0 : _productItem$_origin.callbackData) || {};
181
- const identityKey = typeof (productItem === null || productItem === void 0 ? void 0 : productItem.identity_key) === "string" && productItem.identity_key.length > 0 ? productItem.identity_key : void 0;
181
+ const identityKey = [
182
+ productItem === null || productItem === void 0 || (_productItem$metadata = productItem.metadata) === null || _productItem$metadata === void 0 ? void 0 : _productItem$metadata.unique_identification_number,
183
+ productItem === null || productItem === void 0 ? void 0 : productItem.unique_identification_number,
184
+ productItem === null || productItem === void 0 ? void 0 : productItem.identity_key
185
+ ].find((value) => typeof value === "string" && value.length > 0);
182
186
  const rowKey = identityKey !== null && identityKey !== void 0 ? identityKey : `${(_productItem$product_ = productItem.product_id) !== null && _productItem$product_ !== void 0 ? _productItem$product_ : "p"}_${productItem.product_variant_id}_${index}`;
183
187
  const productOptionString = (typeof (callbackData === null || callbackData === void 0 ? void 0 : callbackData.product_option_string) === "string" ? callbackData.product_option_string.trim() : "") || getVariantProductOptionString(productItem) || void 0;
184
188
  const base = _objectSpread2({
@@ -204,7 +208,7 @@ function toShoppingCartProducts(params) {
204
208
  if (productItem.product_sku) base.product_sku = productItem.product_sku;
205
209
  else if (Array.isArray(productItem.product_option_item) && productItem.product_option_item.length) base.product_option_item = productItem.product_option_item;
206
210
  if (Array.isArray(productItem.product_bundle) && productItem.product_bundle.length) base.product_bundle = productItem.product_bundle;
207
- if (productItem === null || productItem === void 0 || (_productItem$metadata = productItem.metadata) === null || _productItem$metadata === void 0 ? void 0 : _productItem$metadata.venue_booking) {
211
+ if (productItem === null || productItem === void 0 || (_productItem$metadata2 = productItem.metadata) === null || _productItem$metadata2 === void 0 ? void 0 : _productItem$metadata2.venue_booking) {
208
212
  var _origin$resources2;
209
213
  const origin = productItem._origin || {};
210
214
  const meta = productItem.metadata || {};
@@ -0,0 +1,3 @@
1
+ import "./ProductDisplayAdapter.js";
2
+ import "./types.js";
3
+ export {};
@@ -19,6 +19,7 @@ import { useProducts } from "../../hooks/pisellos/useProducts.js";
19
19
  import { useService } from "../../../booking/info/service/serviceManager/index.js";
20
20
  import ProductDisplayAdapter_default from "../ProductDisplayAdapter/ProductDisplayAdapter.js";
21
21
  import { resolveProductDisplayConfig } from "../ProductDisplayAdapter/types.js";
22
+ import "../ProductDisplayAdapter/index.js";
22
23
  import notAvailable_default from "../notAvailable/index.js";
23
24
  import MultiDayTimeSelectModal from "./MultiDayTimeSelectModal.js";
24
25
  import dayjs from "dayjs";
@@ -1,10 +1,10 @@
1
1
  import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
2
  import dayjs from "dayjs";
3
- import timezonePlugin from "dayjs/plugin/timezone";
4
- import utcPlugin from "dayjs/plugin/utc";
3
+ import timezone from "dayjs/plugin/timezone";
4
+ import utc from "dayjs/plugin/utc";
5
5
  //#region src/plus/saasDevice/devicePasscodes/model.ts
6
- dayjs.extend(utcPlugin);
7
- dayjs.extend(timezonePlugin);
6
+ dayjs.extend(utc);
7
+ dayjs.extend(timezone);
8
8
  const INITIAL_DEVICE_PASSCODE_STATE = {
9
9
  deviceIds: [],
10
10
  devicesById: {}
@@ -6,12 +6,12 @@ import React, { useCallback, useEffect, useMemo, useRef } from "react";
6
6
  import { locales } from "@pisell/utils";
7
7
  import { Button, PisellEmpty, PisellModal, PisellStatisticList, Skeleton, Timeline, usePisellConfig } from "@pisell/materials";
8
8
  import { useRequest } from "ahooks";
9
- import timezonePlugin from "dayjs/plugin/timezone";
10
- import utcPlugin from "dayjs/plugin/utc";
9
+ import timezone from "dayjs/plugin/timezone";
10
+ import utc from "dayjs/plugin/utc";
11
11
  import "./index.less";
12
12
  //#region src/plus/walletPassGallery/components/timelineSection/index.tsx
13
- dayjs.extend(timezonePlugin);
14
- dayjs.extend(utcPlugin);
13
+ dayjs.extend(timezone);
14
+ dayjs.extend(utc);
15
15
  const stateTimeUnix = 1723255863;
16
16
  const POLL_INTERVAL = 2e3;
17
17
  const POLL_MAX_TIMES = 5;
@@ -0,0 +1,79 @@
1
+ const assert = require('node:assert/strict');
2
+ const { readFileSync } = require('node:fs');
3
+ const { join } = require('node:path');
4
+ const test = require('node:test');
5
+ const ts = require('typescript');
6
+
7
+ // Run with node --test; load the pure adapter in memory without a materials build.
8
+ const source = readFileSync(join(__dirname, 'toShoppingCartProducts.ts'), 'utf8');
9
+ const output = ts.transpileModule(source, {
10
+ compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
11
+ });
12
+ const adapter = { exports: {} };
13
+ new Function('exports', output.outputText)(adapter.exports);
14
+ const { toShoppingCartProducts } = adapter.exports;
15
+
16
+ const product = {
17
+ product_id: 477300,
18
+ product_variant_id: 493720,
19
+ product_title: 'Latte',
20
+ selling_price: '5.70',
21
+ num: 1,
22
+ product_sku: {
23
+ option: [{ product_option_item_id: 101, name: 'Almond Milk', add_price: 0.7, num: 1 }],
24
+ },
25
+ };
26
+ const toCart = (...products) => toShoppingCartProducts({ orderProducts: products });
27
+
28
+ test('current OS rows retain their metadata identity for cart delete and edit callbacks', () => {
29
+ const uid = '0dd325cf-545e-4665-bda0-d1a26046f78e';
30
+ const input = { ...product, metadata: { unique_identification_number: uid } };
31
+ const [row] = toCart(input);
32
+ assert.equal(row.identity_key, uid);
33
+ assert.equal(row.rowKey, uid);
34
+ assert.equal(row._id, uid);
35
+ assert.equal(row.price, 5.7);
36
+ assert.equal(row.options[0].name, 'Almond Milk');
37
+ assert.equal(input.identity_key, undefined);
38
+ });
39
+
40
+ test('same-SKU option rows remain independently addressable when cart order changes', () => {
41
+ const almond = { ...product, metadata: { unique_identification_number: 'almond-row' } };
42
+ const regular = {
43
+ ...product,
44
+ product_sku: { option: [] },
45
+ metadata: { unique_identification_number: 'regular-row' },
46
+ };
47
+ const original = toCart(almond, regular);
48
+ const reordered = toCart(regular, almond);
49
+ assert.notEqual(original[0].identity_key, original[1].identity_key);
50
+ assert.equal(original[0].identity_key, reordered[1].identity_key);
51
+ assert.equal(original[1].identity_key, reordered[0].identity_key);
52
+ });
53
+
54
+ test('metadata identity takes precedence over stale top-level compatibility fields', () => {
55
+ const [row] = toCart({
56
+ ...product,
57
+ metadata: { unique_identification_number: 'canonical-row' },
58
+ unique_identification_number: 'old-top-level-row',
59
+ identity_key: 'old-alias-row',
60
+ });
61
+ assert.equal(row.identity_key, 'canonical-row');
62
+ });
63
+
64
+ test('accepts top-level and legacy OS identities when metadata has no valid identity', () => {
65
+ for (const metadata of [undefined, {}, { unique_identification_number: '' }, { unique_identification_number: 123 }]) {
66
+ const [current, legacy] = toCart(
67
+ { ...product, metadata, unique_identification_number: 'top-level-row' },
68
+ { ...product, metadata, identity_key: 'legacy-row' },
69
+ );
70
+ assert.equal(current.identity_key, 'top-level-row');
71
+ assert.equal(legacy.identity_key, 'legacy-row');
72
+ }
73
+ });
74
+
75
+ test('a display-only row key never becomes a deletion identity', () => {
76
+ const [row] = toCart(product);
77
+ assert.equal(row.rowKey, '477300_493720_0');
78
+ assert.equal(row.identity_key, undefined);
79
+ });
@@ -174,11 +174,15 @@ function toShoppingCartProducts(params) {
174
174
  const { orderProducts, amountSymbol = "$" } = params;
175
175
  if (!Array.isArray(orderProducts)) return [];
176
176
  return orderProducts.map((productItem, index) => {
177
- var _productItem$_origin, _productItem$product_, _productItem$metadata;
177
+ var _productItem$_origin, _productItem$metadata, _productItem$product_, _productItem$metadata2;
178
178
  const productNum = toSafeNum(productItem === null || productItem === void 0 ? void 0 : productItem.num);
179
179
  const unitPrice = getUnitPrice(productItem);
180
180
  const callbackData = (productItem === null || productItem === void 0 || (_productItem$_origin = productItem._origin) === null || _productItem$_origin === void 0 ? void 0 : _productItem$_origin.callbackData) || {};
181
- const identityKey = typeof (productItem === null || productItem === void 0 ? void 0 : productItem.identity_key) === "string" && productItem.identity_key.length > 0 ? productItem.identity_key : void 0;
181
+ const identityKey = [
182
+ productItem === null || productItem === void 0 || (_productItem$metadata = productItem.metadata) === null || _productItem$metadata === void 0 ? void 0 : _productItem$metadata.unique_identification_number,
183
+ productItem === null || productItem === void 0 ? void 0 : productItem.unique_identification_number,
184
+ productItem === null || productItem === void 0 ? void 0 : productItem.identity_key
185
+ ].find((value) => typeof value === "string" && value.length > 0);
182
186
  const rowKey = identityKey !== null && identityKey !== void 0 ? identityKey : `${(_productItem$product_ = productItem.product_id) !== null && _productItem$product_ !== void 0 ? _productItem$product_ : "p"}_${productItem.product_variant_id}_${index}`;
183
187
  const productOptionString = (typeof (callbackData === null || callbackData === void 0 ? void 0 : callbackData.product_option_string) === "string" ? callbackData.product_option_string.trim() : "") || getVariantProductOptionString(productItem) || void 0;
184
188
  const base = require_objectSpread2._objectSpread2({
@@ -204,7 +208,7 @@ function toShoppingCartProducts(params) {
204
208
  if (productItem.product_sku) base.product_sku = productItem.product_sku;
205
209
  else if (Array.isArray(productItem.product_option_item) && productItem.product_option_item.length) base.product_option_item = productItem.product_option_item;
206
210
  if (Array.isArray(productItem.product_bundle) && productItem.product_bundle.length) base.product_bundle = productItem.product_bundle;
207
- if (productItem === null || productItem === void 0 || (_productItem$metadata = productItem.metadata) === null || _productItem$metadata === void 0 ? void 0 : _productItem$metadata.venue_booking) {
211
+ if (productItem === null || productItem === void 0 || (_productItem$metadata2 = productItem.metadata) === null || _productItem$metadata2 === void 0 ? void 0 : _productItem$metadata2.venue_booking) {
208
212
  var _origin$resources2;
209
213
  const origin = productItem._origin || {};
210
214
  const meta = productItem.metadata || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/private-materials",
3
- "version": "6.12.364",
3
+ "version": "6.12.365",
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/utils": "3.0.7",
78
77
  "@pisell/materials": "6.12.87",
79
78
  "@pisell/date-picker": "3.0.12",
80
- "@pisell/icon": "0.0.11"
79
+ "@pisell/icon": "0.0.11",
80
+ "@pisell/utils": "3.0.7"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "react": "^18.0.0",