@open-tender/utils 0.1.87 → 0.1.89
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.
|
@@ -11,7 +11,7 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
12
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
13
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const handleCheckoutError: (error: CheckoutError) => Record<string, string | Record<string, string | Record<string, string>>>;
|
|
15
15
|
export declare const makeCheckError: (params: CheckoutErrorParams) => CheckoutError;
|
|
16
16
|
export declare const errMessages: {
|
|
17
17
|
unknown: string;
|
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.
|
|
3
|
+
exports.errMessages = exports.makeCheckError = exports.handleCheckoutError = exports.makeFormErrors = exports.handleFormErrors = 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;
|
|
@@ -75,43 +75,44 @@ const makeFormErrors = (error) => {
|
|
|
75
75
|
return errors;
|
|
76
76
|
};
|
|
77
77
|
exports.makeFormErrors = makeFormErrors;
|
|
78
|
-
const
|
|
79
|
-
const { detail, params, message } =
|
|
78
|
+
const handleCheckoutError = (error) => {
|
|
79
|
+
const { detail, params, message } = error || {};
|
|
80
80
|
if (!params || (0, helpers_1.isEmpty)(params))
|
|
81
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
form: detail || message || 'Unknown error. Please contact support.'
|
|
83
|
+
};
|
|
82
84
|
const errObj = Object.entries(params).reduce((obj, error) => {
|
|
83
85
|
const [key, value] = error;
|
|
84
|
-
const
|
|
86
|
+
const errMsg = value.message;
|
|
85
87
|
const [, entity, index, field] = key.split('.');
|
|
86
|
-
const existingEntity = obj[entity]
|
|
88
|
+
const existingEntity = Object.hasOwn(obj, entity) ? obj[entity] : null;
|
|
87
89
|
if (!index) {
|
|
88
|
-
return Object.assign(Object.assign({}, obj), { [entity]:
|
|
90
|
+
return Object.assign(Object.assign({}, obj), { [entity]: errMsg });
|
|
89
91
|
}
|
|
90
92
|
else if (!field) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
if (existingEntity && typeof existingEntity !== 'string') {
|
|
94
|
+
return Object.assign(Object.assign({}, obj), { [entity]: Object.assign(Object.assign({}, existingEntity), { [index]: errMsg }) });
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: errMsg } });
|
|
98
|
+
}
|
|
93
99
|
}
|
|
94
100
|
else {
|
|
95
|
-
if (existingEntity) {
|
|
96
|
-
const existingIndex = existingEntity[index] ||
|
|
97
|
-
const newIndex =
|
|
101
|
+
if (existingEntity && typeof existingEntity !== 'string') {
|
|
102
|
+
const existingIndex = existingEntity[index] || null;
|
|
103
|
+
const newIndex = existingIndex && typeof existingIndex !== 'string'
|
|
104
|
+
? Object.assign(Object.assign({}, existingIndex), { [field]: errMsg }) : { [field]: errMsg };
|
|
98
105
|
const newEntity = Object.assign(Object.assign({}, existingEntity), { [index]: newIndex });
|
|
99
106
|
return Object.assign(Object.assign({}, obj), { [entity]: newEntity });
|
|
100
107
|
}
|
|
101
108
|
else {
|
|
102
|
-
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]:
|
|
109
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]: errMsg } } });
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
|
-
// const newEntity = obj[entity]
|
|
106
|
-
// ? { ...obj[entity], [index]: err }
|
|
107
|
-
// : index
|
|
108
|
-
// ? { [index]: err }
|
|
109
|
-
// : err
|
|
110
|
-
// return { ...obj, [entity]: newEntity }
|
|
111
112
|
}, { form: 'There are one or more errors below' });
|
|
112
113
|
return errObj;
|
|
113
114
|
};
|
|
114
|
-
exports.
|
|
115
|
+
exports.handleCheckoutError = handleCheckoutError;
|
|
115
116
|
const makeCheckError = (params) => {
|
|
116
117
|
if (!params || (0, helpers_1.isEmpty)(params))
|
|
117
118
|
return null;
|
|
@@ -4,6 +4,7 @@ export declare const remsToPixels: (rems?: string, responsive?: boolean) => stri
|
|
|
4
4
|
export declare const remsToNumber: (rems: string) => number;
|
|
5
5
|
export declare const objRemsToPixels: <T extends Partial<ThemeLayout & {
|
|
6
6
|
big: string;
|
|
7
|
+
small: string;
|
|
7
8
|
giga: string;
|
|
8
9
|
h1: string;
|
|
9
10
|
h2: string;
|
|
@@ -13,7 +14,6 @@ export declare const objRemsToPixels: <T extends Partial<ThemeLayout & {
|
|
|
13
14
|
h6: string;
|
|
14
15
|
main: string;
|
|
15
16
|
mega: string;
|
|
16
|
-
small: string;
|
|
17
17
|
tera: string;
|
|
18
18
|
xBig: string;
|
|
19
19
|
xSmall: string;
|
|
@@ -11,7 +11,7 @@ export declare const handleRespError: (err: RequestError) => {
|
|
|
11
11
|
export declare const processError: (msg: string | null) => string;
|
|
12
12
|
export declare const handleFormErrors: (params: Record<string, string | null>) => Record<string, string>;
|
|
13
13
|
export declare const makeFormErrors: (error: RequestError) => Record<string, string>;
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const handleCheckoutError: (error: CheckoutError) => Record<string, string | Record<string, string | Record<string, string>>>;
|
|
15
15
|
export declare const makeCheckError: (params: CheckoutErrorParams) => CheckoutError;
|
|
16
16
|
export declare const errMessages: {
|
|
17
17
|
unknown: string;
|
package/dist/esm/utils/errors.js
CHANGED
|
@@ -68,39 +68,40 @@ export const makeFormErrors = (error) => {
|
|
|
68
68
|
}
|
|
69
69
|
return errors;
|
|
70
70
|
};
|
|
71
|
-
export const
|
|
72
|
-
const { detail, params, message } =
|
|
71
|
+
export const handleCheckoutError = (error) => {
|
|
72
|
+
const { detail, params, message } = error || {};
|
|
73
73
|
if (!params || isEmpty(params))
|
|
74
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
form: detail || message || 'Unknown error. Please contact support.'
|
|
76
|
+
};
|
|
75
77
|
const errObj = Object.entries(params).reduce((obj, error) => {
|
|
76
78
|
const [key, value] = error;
|
|
77
|
-
const
|
|
79
|
+
const errMsg = value.message;
|
|
78
80
|
const [, entity, index, field] = key.split('.');
|
|
79
|
-
const existingEntity = obj[entity]
|
|
81
|
+
const existingEntity = Object.hasOwn(obj, entity) ? obj[entity] : null;
|
|
80
82
|
if (!index) {
|
|
81
|
-
return Object.assign(Object.assign({}, obj), { [entity]:
|
|
83
|
+
return Object.assign(Object.assign({}, obj), { [entity]: errMsg });
|
|
82
84
|
}
|
|
83
85
|
else if (!field) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
if (existingEntity && typeof existingEntity !== 'string') {
|
|
87
|
+
return Object.assign(Object.assign({}, obj), { [entity]: Object.assign(Object.assign({}, existingEntity), { [index]: errMsg }) });
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: errMsg } });
|
|
91
|
+
}
|
|
86
92
|
}
|
|
87
93
|
else {
|
|
88
|
-
if (existingEntity) {
|
|
89
|
-
const existingIndex = existingEntity[index] ||
|
|
90
|
-
const newIndex =
|
|
94
|
+
if (existingEntity && typeof existingEntity !== 'string') {
|
|
95
|
+
const existingIndex = existingEntity[index] || null;
|
|
96
|
+
const newIndex = existingIndex && typeof existingIndex !== 'string'
|
|
97
|
+
? Object.assign(Object.assign({}, existingIndex), { [field]: errMsg }) : { [field]: errMsg };
|
|
91
98
|
const newEntity = Object.assign(Object.assign({}, existingEntity), { [index]: newIndex });
|
|
92
99
|
return Object.assign(Object.assign({}, obj), { [entity]: newEntity });
|
|
93
100
|
}
|
|
94
101
|
else {
|
|
95
|
-
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]:
|
|
102
|
+
return Object.assign(Object.assign({}, obj), { [entity]: { [index]: { [field]: errMsg } } });
|
|
96
103
|
}
|
|
97
104
|
}
|
|
98
|
-
// const newEntity = obj[entity]
|
|
99
|
-
// ? { ...obj[entity], [index]: err }
|
|
100
|
-
// : index
|
|
101
|
-
// ? { [index]: err }
|
|
102
|
-
// : err
|
|
103
|
-
// return { ...obj, [entity]: newEntity }
|
|
104
105
|
}, { form: 'There are one or more errors below' });
|
|
105
106
|
return errObj;
|
|
106
107
|
};
|
|
@@ -4,6 +4,7 @@ export declare const remsToPixels: (rems?: string, responsive?: boolean) => stri
|
|
|
4
4
|
export declare const remsToNumber: (rems: string) => number;
|
|
5
5
|
export declare const objRemsToPixels: <T extends Partial<ThemeLayout & {
|
|
6
6
|
big: string;
|
|
7
|
+
small: string;
|
|
7
8
|
giga: string;
|
|
8
9
|
h1: string;
|
|
9
10
|
h2: string;
|
|
@@ -13,7 +14,6 @@ export declare const objRemsToPixels: <T extends Partial<ThemeLayout & {
|
|
|
13
14
|
h6: string;
|
|
14
15
|
main: string;
|
|
15
16
|
mega: string;
|
|
16
|
-
small: string;
|
|
17
17
|
tera: string;
|
|
18
18
|
xBig: string;
|
|
19
19
|
xSmall: string;
|
package/package.json
CHANGED