@open-tender/utils 0.1.141 → 0.1.143
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.
|
@@ -9,6 +9,11 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
9
9
|
err: RequestError;
|
|
10
10
|
};
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
|
+
interface RecordInterface {
|
|
13
|
+
[name: string]: string | RecordInterface;
|
|
14
|
+
}
|
|
15
|
+
export declare const handleFormErrorsNested: (params: Record<string, string | null>) => RecordInterface;
|
|
16
|
+
export declare const makeFormErrorsNested: (error: RequestError) => RecordInterface;
|
|
12
17
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
18
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
19
|
export declare const handleCheckoutError: (error: CheckoutError) => CheckoutErrorMessages;
|
|
@@ -47,3 +52,4 @@ export declare const errMessages: {
|
|
|
47
52
|
distanceSurcharge: string;
|
|
48
53
|
missingAddressDeliveryZone: string;
|
|
49
54
|
};
|
|
55
|
+
export {};
|
package/dist/cjs/utils/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errMessages = exports.makeCheckError = exports.handleCheckoutError = exports.makeFormErrors = exports.handleFormErrors = exports.processError = exports.handleRespError = void 0;
|
|
3
|
+
exports.errMessages = exports.makeCheckError = exports.handleCheckoutError = exports.makeFormErrors = exports.handleFormErrors = exports.makeFormErrorsNested = exports.handleFormErrorsNested = exports.processError = exports.handleRespError = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const handleRespError = (err) => {
|
|
6
6
|
const error = typeof err === 'string' ? { detail: err } : err;
|
|
@@ -55,6 +55,32 @@ const processError = (msg) => {
|
|
|
55
55
|
return msg;
|
|
56
56
|
};
|
|
57
57
|
exports.processError = processError;
|
|
58
|
+
const makeErrObj = (keys, msg) => {
|
|
59
|
+
const obj = keys.reduceRight((msg, key) => ({ [key]: msg }), msg);
|
|
60
|
+
return typeof obj === 'string' ? null : obj;
|
|
61
|
+
};
|
|
62
|
+
const handleFormErrorsNested = (params) => {
|
|
63
|
+
return Object.entries(params).reduce((obj, error) => {
|
|
64
|
+
const [field, msg] = error;
|
|
65
|
+
const message = (0, exports.processError)(msg);
|
|
66
|
+
const keys = field.replace('$.', '').split('.');
|
|
67
|
+
const errObj = makeErrObj(keys, message);
|
|
68
|
+
return errObj ? Object.assign(Object.assign({}, obj), errObj) : obj;
|
|
69
|
+
}, {});
|
|
70
|
+
};
|
|
71
|
+
exports.handleFormErrorsNested = handleFormErrorsNested;
|
|
72
|
+
const makeFormErrorsNested = (error) => {
|
|
73
|
+
let errors = {};
|
|
74
|
+
if (error === null || error === void 0 ? void 0 : error.params) {
|
|
75
|
+
errors = (0, exports.handleFormErrorsNested)(error.params);
|
|
76
|
+
errors.form = error.detail;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
errors.form = (error === null || error === void 0 ? void 0 : error.detail) || (error === null || error === void 0 ? void 0 : error.message) || '';
|
|
80
|
+
}
|
|
81
|
+
return errors;
|
|
82
|
+
};
|
|
83
|
+
exports.makeFormErrorsNested = makeFormErrorsNested;
|
|
58
84
|
const handleFormErrors = (params) => {
|
|
59
85
|
return Object.entries(params).reduce((obj, error) => {
|
|
60
86
|
const [field, msg] = error;
|
|
@@ -9,6 +9,11 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
9
9
|
err: RequestError;
|
|
10
10
|
};
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
|
+
interface RecordInterface {
|
|
13
|
+
[name: string]: string | RecordInterface;
|
|
14
|
+
}
|
|
15
|
+
export declare const handleFormErrorsNested: (params: Record<string, string | null>) => RecordInterface;
|
|
16
|
+
export declare const makeFormErrorsNested: (error: RequestError) => RecordInterface;
|
|
12
17
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
18
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
19
|
export declare const handleCheckoutError: (error: CheckoutError) => CheckoutErrorMessages;
|
|
@@ -47,3 +52,4 @@ export declare const errMessages: {
|
|
|
47
52
|
distanceSurcharge: string;
|
|
48
53
|
missingAddressDeliveryZone: string;
|
|
49
54
|
};
|
|
55
|
+
export {};
|
package/dist/esm/utils/errors.js
CHANGED
|
@@ -50,6 +50,30 @@ export const processError = (msg) => {
|
|
|
50
50
|
}
|
|
51
51
|
return msg;
|
|
52
52
|
};
|
|
53
|
+
const makeErrObj = (keys, msg) => {
|
|
54
|
+
const obj = keys.reduceRight((msg, key) => ({ [key]: msg }), msg);
|
|
55
|
+
return typeof obj === 'string' ? null : obj;
|
|
56
|
+
};
|
|
57
|
+
export const handleFormErrorsNested = (params) => {
|
|
58
|
+
return Object.entries(params).reduce((obj, error) => {
|
|
59
|
+
const [field, msg] = error;
|
|
60
|
+
const message = processError(msg);
|
|
61
|
+
const keys = field.replace('$.', '').split('.');
|
|
62
|
+
const errObj = makeErrObj(keys, message);
|
|
63
|
+
return errObj ? Object.assign(Object.assign({}, obj), errObj) : obj;
|
|
64
|
+
}, {});
|
|
65
|
+
};
|
|
66
|
+
export const makeFormErrorsNested = (error) => {
|
|
67
|
+
let errors = {};
|
|
68
|
+
if (error === null || error === void 0 ? void 0 : error.params) {
|
|
69
|
+
errors = handleFormErrorsNested(error.params);
|
|
70
|
+
errors.form = error.detail;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
errors.form = (error === null || error === void 0 ? void 0 : error.detail) || (error === null || error === void 0 ? void 0 : error.message) || '';
|
|
74
|
+
}
|
|
75
|
+
return errors;
|
|
76
|
+
};
|
|
53
77
|
export const handleFormErrors = (params) => {
|
|
54
78
|
return Object.entries(params).reduce((obj, error) => {
|
|
55
79
|
const [field, msg] = error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.143",
|
|
4
4
|
"description": "A library of utils for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"typescript": "^4.8.2"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@open-tender/types": "^0.2.
|
|
57
|
+
"@open-tender/types": "^0.2.78",
|
|
58
58
|
"@reduxjs/toolkit": "^1.8.5",
|
|
59
59
|
"react": "^18.2.0"
|
|
60
60
|
},
|