@zauru-sdk/common 6.3.0 → 6.3.2

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [6.3.2](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.3.1...@zauru-sdk/common@6.3.2) (2026-09-09)
7
+
8
+ **Note:** Version bump only for package @zauru-sdk/common
9
+
10
+
11
+
12
+
13
+
14
+ ## [6.3.1](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.3.0...@zauru-sdk/common@6.3.1) (2026-09-09)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * read rejection percentage from memo objects ([3e1292a](https://github.com/intuitiva/zauru-typescript-sdk/commit/3e1292a2d77f1347a8ceef526019298618fe2ca0))
20
+
21
+
22
+
23
+
24
+
6
25
  # [6.3.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.2.5...@zauru-sdk/common@6.3.0) (2026-09-08)
7
26
 
8
27
 
package/dist/common.d.ts CHANGED
@@ -1,13 +1,17 @@
1
1
  import "moment-timezone";
2
2
  import type { PayeeGraphQL, AxiosUtilsResponse, BasketSchema, SelectFieldOption, JsonMemoType } from "@zauru-sdk/types";
3
3
  export declare const DESTINOS_MUESTRA_OPTIONS: SelectFieldOption[];
4
- export declare const parseJsonMemo: (memo?: string) => JsonMemoType;
4
+ export declare const parseJsonMemo: (memo?: string | object) => JsonMemoType;
5
5
  export declare const stringifyJsonMemo: (memo: JsonMemoType) => string;
6
- export declare const mergeJsonMemo: (memo: string | undefined, patch: Partial<JsonMemoType>) => string;
6
+ export declare const mergeJsonMemo: (memo: string | object | undefined, patch: Partial<JsonMemoType>) => string;
7
+ /**
8
+ * Reads rejection % from memo.rejectionPercentage.
9
+ * Does not use purchase_orders.discount (monetary Baculo field).
10
+ */
7
11
  export declare const getRejectionPercentage: (source: string | {
8
- memo?: string;
12
+ memo?: string | object;
9
13
  } | JsonMemoType | undefined) => number;
10
- export declare const setRejectionPercentage: (memo: string | undefined, percentage: number) => string;
14
+ export declare const setRejectionPercentage: (memo: string | object | undefined, percentage: number) => string;
11
15
  /**
12
16
  * Obtener el objeto de canastas en base al memo
13
17
  * @param memo
@@ -31,8 +31,11 @@ exports.DESTINOS_MUESTRA_OPTIONS = [
31
31
  moment_1.default.locale("es");
32
32
  // Helper function to parse JSON memo safely
33
33
  const parseJsonMemo = (memo) => {
34
- if (!memo)
34
+ if (memo == null || memo === "")
35
35
  return {};
36
+ if (typeof memo === "object") {
37
+ return memo;
38
+ }
36
39
  try {
37
40
  return JSON.parse(memo);
38
41
  }
@@ -48,21 +51,31 @@ const stringifyJsonMemo = (memo) => JSON.stringify(memo);
48
51
  exports.stringifyJsonMemo = stringifyJsonMemo;
49
52
  const mergeJsonMemo = (memo, patch) => (0, exports.stringifyJsonMemo)({ ...(0, exports.parseJsonMemo)(memo), ...patch });
50
53
  exports.mergeJsonMemo = mergeJsonMemo;
54
+ const toFiniteNumber = (value) => {
55
+ if (value == null || value === "")
56
+ return undefined;
57
+ const parsed = Number(value);
58
+ return Number.isFinite(parsed) ? parsed : undefined;
59
+ };
60
+ /**
61
+ * Reads rejection % from memo.rejectionPercentage.
62
+ * Does not use purchase_orders.discount (monetary Baculo field).
63
+ */
51
64
  const getRejectionPercentage = (source) => {
52
65
  if (source == null || source === "")
53
66
  return 0;
54
- let parsed;
55
67
  if (typeof source === "string") {
56
- parsed = (0, exports.parseJsonMemo)(source);
68
+ return toFiniteNumber((0, exports.parseJsonMemo)(source).rejectionPercentage) ?? 0;
57
69
  }
58
- else if (typeof source.memo === "string") {
59
- parsed = (0, exports.parseJsonMemo)(source.memo);
60
- }
61
- else {
62
- parsed = source;
70
+ if (typeof source !== "object")
71
+ return 0;
72
+ const record = source;
73
+ if (record.memo != null && record.memo !== "") {
74
+ const fromMemo = toFiniteNumber((0, exports.parseJsonMemo)(record.memo).rejectionPercentage);
75
+ if (fromMemo !== undefined)
76
+ return fromMemo;
63
77
  }
64
- const value = Number(parsed.rejectionPercentage);
65
- return Number.isFinite(value) ? value : 0;
78
+ return toFiniteNumber(record.rejectionPercentage) ?? 0;
66
79
  };
67
80
  exports.getRejectionPercentage = getRejectionPercentage;
68
81
  const setRejectionPercentage = (memo, percentage) => (0, exports.mergeJsonMemo)(memo, { rejectionPercentage: percentage });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/common",
3
- "version": "6.3.0",
3
+ "version": "6.3.2",
4
4
  "description": "Funciones de uso común en el desarrollo de webapps en Zauru",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -21,9 +21,9 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@remix-run/node": "^2.8.1",
24
- "@zauru-sdk/types": "^6.9.0",
24
+ "@zauru-sdk/types": "^6.10.0",
25
25
  "moment": "^2.30.1",
26
26
  "moment-timezone": "^0.5.45"
27
27
  },
28
- "gitHead": "2cc49202c68f74f1ef031322b108b1461b9c9ad7"
28
+ "gitHead": "bde6df12ceda8636075e0adb3b79a563076d51bf"
29
29
  }
package/src/common.ts CHANGED
@@ -18,8 +18,11 @@ export const DESTINOS_MUESTRA_OPTIONS: SelectFieldOption[] = [
18
18
  moment.locale("es");
19
19
 
20
20
  // Helper function to parse JSON memo safely
21
- export const parseJsonMemo = (memo?: string): JsonMemoType => {
22
- if (!memo) return {};
21
+ export const parseJsonMemo = (memo?: string | object): JsonMemoType => {
22
+ if (memo == null || memo === "") return {};
23
+ if (typeof memo === "object") {
24
+ return memo as JsonMemoType;
25
+ }
23
26
  try {
24
27
  return JSON.parse(memo);
25
28
  } catch (error) {
@@ -34,30 +37,48 @@ export const stringifyJsonMemo = (memo: JsonMemoType): string =>
34
37
  JSON.stringify(memo);
35
38
 
36
39
  export const mergeJsonMemo = (
37
- memo: string | undefined,
40
+ memo: string | object | undefined,
38
41
  patch: Partial<JsonMemoType>,
39
42
  ): string => stringifyJsonMemo({ ...parseJsonMemo(memo), ...patch });
40
43
 
44
+ const toFiniteNumber = (value: unknown): number | undefined => {
45
+ if (value == null || value === "") return undefined;
46
+ const parsed = Number(value);
47
+ return Number.isFinite(parsed) ? parsed : undefined;
48
+ };
49
+
50
+ /**
51
+ * Reads rejection % from memo.rejectionPercentage.
52
+ * Does not use purchase_orders.discount (monetary Baculo field).
53
+ */
41
54
  export const getRejectionPercentage = (
42
- source: string | { memo?: string } | JsonMemoType | undefined,
55
+ source: string | { memo?: string | object } | JsonMemoType | undefined,
43
56
  ): number => {
44
57
  if (source == null || source === "") return 0;
45
58
 
46
- let parsed: JsonMemoType;
47
59
  if (typeof source === "string") {
48
- parsed = parseJsonMemo(source);
49
- } else if (typeof (source as { memo?: unknown }).memo === "string") {
50
- parsed = parseJsonMemo((source as { memo: string }).memo);
51
- } else {
52
- parsed = source as JsonMemoType;
60
+ return toFiniteNumber(parseJsonMemo(source).rejectionPercentage) ?? 0;
61
+ }
62
+
63
+ if (typeof source !== "object") return 0;
64
+
65
+ const record = source as {
66
+ memo?: string | object;
67
+ rejectionPercentage?: number | string;
68
+ };
69
+
70
+ if (record.memo != null && record.memo !== "") {
71
+ const fromMemo = toFiniteNumber(
72
+ parseJsonMemo(record.memo).rejectionPercentage,
73
+ );
74
+ if (fromMemo !== undefined) return fromMemo;
53
75
  }
54
76
 
55
- const value = Number(parsed.rejectionPercentage);
56
- return Number.isFinite(value) ? value : 0;
77
+ return toFiniteNumber(record.rejectionPercentage) ?? 0;
57
78
  };
58
79
 
59
80
  export const setRejectionPercentage = (
60
- memo: string | undefined,
81
+ memo: string | object | undefined,
61
82
  percentage: number,
62
83
  ): string => mergeJsonMemo(memo, { rejectionPercentage: percentage });
63
84