@zauru-sdk/common 6.2.5 → 6.3.1
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 +22 -0
- package/dist/common.d.ts +11 -1
- package/dist/esm/common.js +38 -2
- package/package.json +3 -3
- package/src/common.ts +54 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
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.1](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.3.0...@zauru-sdk/common@6.3.1) (2026-09-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* read rejection percentage from memo objects ([3e1292a](https://github.com/intuitiva/zauru-typescript-sdk/commit/3e1292a2d77f1347a8ceef526019298618fe2ca0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [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)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* store purchase order rejection percentage in memo ([65d77c1](https://github.com/intuitiva/zauru-typescript-sdk/commit/65d77c156ebd17cf599767ccc6cc9653170165f9))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [6.2.5](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.2.4...@zauru-sdk/common@6.2.5) (2026-08-31)
|
|
7
29
|
|
|
8
30
|
**Note:** Version bump only for package @zauru-sdk/common
|
package/dist/common.d.ts
CHANGED
|
@@ -1,7 +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
|
+
export declare const stringifyJsonMemo: (memo: 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
|
+
*/
|
|
11
|
+
export declare const getRejectionPercentage: (source: string | {
|
|
12
|
+
memo?: string | object;
|
|
13
|
+
} | JsonMemoType | undefined) => number;
|
|
14
|
+
export declare const setRejectionPercentage: (memo: string | object | undefined, percentage: number) => string;
|
|
5
15
|
/**
|
|
6
16
|
* Obtener el objeto de canastas en base al memo
|
|
7
17
|
* @param memo
|
package/dist/esm/common.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parsedObject = exports.sortByProperty = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.ZAURU_REGEX = exports.priceToText = exports.arrayToObject = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.obtenerFechaActualConZonaHoraria = exports.getDatePickerCurrentDate = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.getBasketsSchema = exports.parseJsonMemo = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
|
|
6
|
+
exports.parsedObject = exports.sortByProperty = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.ZAURU_REGEX = exports.priceToText = exports.arrayToObject = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.obtenerFechaActualConZonaHoraria = exports.getDatePickerCurrentDate = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.getBasketsSchema = exports.setRejectionPercentage = exports.getRejectionPercentage = exports.mergeJsonMemo = exports.stringifyJsonMemo = exports.parseJsonMemo = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
|
|
7
7
|
exports.generateClientUUID = generateClientUUID;
|
|
8
8
|
exports.extractValueBetweenTags = extractValueBetweenTags;
|
|
9
9
|
exports.isJsonArray = isJsonArray;
|
|
@@ -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 (
|
|
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
|
}
|
|
@@ -44,6 +47,39 @@ const parseJsonMemo = (memo) => {
|
|
|
44
47
|
}
|
|
45
48
|
};
|
|
46
49
|
exports.parseJsonMemo = parseJsonMemo;
|
|
50
|
+
const stringifyJsonMemo = (memo) => JSON.stringify(memo);
|
|
51
|
+
exports.stringifyJsonMemo = stringifyJsonMemo;
|
|
52
|
+
const mergeJsonMemo = (memo, patch) => (0, exports.stringifyJsonMemo)({ ...(0, exports.parseJsonMemo)(memo), ...patch });
|
|
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
|
+
*/
|
|
64
|
+
const getRejectionPercentage = (source) => {
|
|
65
|
+
if (source == null || source === "")
|
|
66
|
+
return 0;
|
|
67
|
+
if (typeof source === "string") {
|
|
68
|
+
return toFiniteNumber((0, exports.parseJsonMemo)(source).rejectionPercentage) ?? 0;
|
|
69
|
+
}
|
|
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;
|
|
77
|
+
}
|
|
78
|
+
return toFiniteNumber(record.rejectionPercentage) ?? 0;
|
|
79
|
+
};
|
|
80
|
+
exports.getRejectionPercentage = getRejectionPercentage;
|
|
81
|
+
const setRejectionPercentage = (memo, percentage) => (0, exports.mergeJsonMemo)(memo, { rejectionPercentage: percentage });
|
|
82
|
+
exports.setRejectionPercentage = setRejectionPercentage;
|
|
47
83
|
/**
|
|
48
84
|
* Obtener el objeto de canastas en base al memo
|
|
49
85
|
* @param memo
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.1",
|
|
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.
|
|
24
|
+
"@zauru-sdk/types": "^6.9.0",
|
|
25
25
|
"moment": "^2.30.1",
|
|
26
26
|
"moment-timezone": "^0.5.45"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "ba084b80941814720297e6e216cf9834b27233b1"
|
|
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 (
|
|
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) {
|
|
@@ -30,6 +33,55 @@ export const parseJsonMemo = (memo?: string): JsonMemoType => {
|
|
|
30
33
|
}
|
|
31
34
|
};
|
|
32
35
|
|
|
36
|
+
export const stringifyJsonMemo = (memo: JsonMemoType): string =>
|
|
37
|
+
JSON.stringify(memo);
|
|
38
|
+
|
|
39
|
+
export const mergeJsonMemo = (
|
|
40
|
+
memo: string | object | undefined,
|
|
41
|
+
patch: Partial<JsonMemoType>,
|
|
42
|
+
): string => stringifyJsonMemo({ ...parseJsonMemo(memo), ...patch });
|
|
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
|
+
*/
|
|
54
|
+
export const getRejectionPercentage = (
|
|
55
|
+
source: string | { memo?: string | object } | JsonMemoType | undefined,
|
|
56
|
+
): number => {
|
|
57
|
+
if (source == null || source === "") return 0;
|
|
58
|
+
|
|
59
|
+
if (typeof source === "string") {
|
|
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;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return toFiniteNumber(record.rejectionPercentage) ?? 0;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const setRejectionPercentage = (
|
|
81
|
+
memo: string | object | undefined,
|
|
82
|
+
percentage: number,
|
|
83
|
+
): string => mergeJsonMemo(memo, { rejectionPercentage: percentage });
|
|
84
|
+
|
|
33
85
|
/**
|
|
34
86
|
* Obtener el objeto de canastas en base al memo
|
|
35
87
|
* @param memo
|