@bagelink/sdk 1.0.41 → 1.0.47
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/dist/index.cjs +5 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +5 -4
- package/package.json +2 -2
- package/src/utils.ts +18 -3
package/dist/index.cjs
CHANGED
|
@@ -403,16 +403,17 @@ const index = async (openApiUrl, baseUrl) => {
|
|
|
403
403
|
}
|
|
404
404
|
};
|
|
405
405
|
|
|
406
|
-
function formatAPIErrorMessage(
|
|
406
|
+
function formatAPIErrorMessage(err) {
|
|
407
|
+
const error = err;
|
|
407
408
|
if (!error || !error.response) {
|
|
408
409
|
return "Network error occurred. Please check your connection.";
|
|
409
410
|
}
|
|
410
411
|
const { status, data } = error.response;
|
|
411
412
|
if (data?.detail && Array.isArray(data.detail)) {
|
|
412
|
-
return data.detail.map((
|
|
413
|
-
const fieldPath =
|
|
413
|
+
return data.detail.map((err2) => {
|
|
414
|
+
const fieldPath = err2.loc.slice(1).join(".");
|
|
414
415
|
const field = fieldPath.split(".").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
415
|
-
let message =
|
|
416
|
+
let message = err2.msg.replace(/^(?:field|value|string|none) required$/i, "is required").replace(/^value is not a valid/i, "must be a valid").replace(/^ensure this value/i, "this value must").replace(/^str type expected$/i, "must be text").replace(/^value could not be parsed to/i, "must be a").replace(/^ensure this value has at least/i, "must have at least").replace(/^ensure this value has at most/i, "must have at most").replace(/^invalid datetime format/i, "must be a valid date/time").replace(/^value is not a valid email address/i, "must be a valid email address").replace(/^value is not a valid integer/i, "must be a whole number").replace(/^value is not a valid float/i, "must be a valid number");
|
|
416
417
|
return `${field} ${message.toLowerCase()}`;
|
|
417
418
|
}).join("\n");
|
|
418
419
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ interface OpenAPIResponse {
|
|
|
4
4
|
}
|
|
5
5
|
declare const _default: (openApiUrl: string, baseUrl: string) => Promise<OpenAPIResponse>;
|
|
6
6
|
|
|
7
|
-
declare function formatAPIErrorMessage(
|
|
7
|
+
declare function formatAPIErrorMessage(err: unknown): string;
|
|
8
8
|
|
|
9
9
|
type Tables = '';
|
|
10
10
|
type TableToTypeMapping = Record<Tables, any>;
|
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ interface OpenAPIResponse {
|
|
|
4
4
|
}
|
|
5
5
|
declare const _default: (openApiUrl: string, baseUrl: string) => Promise<OpenAPIResponse>;
|
|
6
6
|
|
|
7
|
-
declare function formatAPIErrorMessage(
|
|
7
|
+
declare function formatAPIErrorMessage(err: unknown): string;
|
|
8
8
|
|
|
9
9
|
type Tables = '';
|
|
10
10
|
type TableToTypeMapping = Record<Tables, any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ interface OpenAPIResponse {
|
|
|
4
4
|
}
|
|
5
5
|
declare const _default: (openApiUrl: string, baseUrl: string) => Promise<OpenAPIResponse>;
|
|
6
6
|
|
|
7
|
-
declare function formatAPIErrorMessage(
|
|
7
|
+
declare function formatAPIErrorMessage(err: unknown): string;
|
|
8
8
|
|
|
9
9
|
type Tables = '';
|
|
10
10
|
type TableToTypeMapping = Record<Tables, any>;
|
package/dist/index.mjs
CHANGED
|
@@ -397,16 +397,17 @@ const index = async (openApiUrl, baseUrl) => {
|
|
|
397
397
|
}
|
|
398
398
|
};
|
|
399
399
|
|
|
400
|
-
function formatAPIErrorMessage(
|
|
400
|
+
function formatAPIErrorMessage(err) {
|
|
401
|
+
const error = err;
|
|
401
402
|
if (!error || !error.response) {
|
|
402
403
|
return "Network error occurred. Please check your connection.";
|
|
403
404
|
}
|
|
404
405
|
const { status, data } = error.response;
|
|
405
406
|
if (data?.detail && Array.isArray(data.detail)) {
|
|
406
|
-
return data.detail.map((
|
|
407
|
-
const fieldPath =
|
|
407
|
+
return data.detail.map((err2) => {
|
|
408
|
+
const fieldPath = err2.loc.slice(1).join(".");
|
|
408
409
|
const field = fieldPath.split(".").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
409
|
-
let message =
|
|
410
|
+
let message = err2.msg.replace(/^(?:field|value|string|none) required$/i, "is required").replace(/^value is not a valid/i, "must be a valid").replace(/^ensure this value/i, "this value must").replace(/^str type expected$/i, "must be text").replace(/^value could not be parsed to/i, "must be a").replace(/^ensure this value has at least/i, "must have at least").replace(/^ensure this value has at most/i, "must have at most").replace(/^invalid datetime format/i, "must be a valid date/time").replace(/^value is not a valid email address/i, "must be a valid email address").replace(/^value is not a valid integer/i, "must be a whole number").replace(/^value is not a valid float/i, "must be a valid number");
|
|
410
411
|
return `${field} ${message.toLowerCase()}`;
|
|
411
412
|
}).join("\n");
|
|
412
413
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagelink/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.47",
|
|
5
5
|
"description": "Bagel core sdk packages",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Neveh Allon",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"axios": "^1.
|
|
53
|
+
"axios": "^1.8.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@apidevtools/swagger-parser": "^10.1.1",
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AxiosError } from "axios"
|
|
2
|
+
|
|
3
|
+
export interface ValidationError {
|
|
4
|
+
loc: (string | number)[]
|
|
5
|
+
msg: string
|
|
6
|
+
type: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface HTTPValidationError {
|
|
10
|
+
detail: ValidationError[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export function formatAPIErrorMessage(err: unknown): string {
|
|
15
|
+
const error = err as AxiosError<HTTPValidationError & {[key:string]: any}> | undefined
|
|
16
|
+
|
|
2
17
|
// Handle case where error or response is undefined
|
|
3
18
|
if (!error || !error.response) {
|
|
4
19
|
return 'Network error occurred. Please check your connection.'
|
|
@@ -9,12 +24,12 @@ export function formatAPIErrorMessage(error: any) {
|
|
|
9
24
|
// Handle validation errors (422)
|
|
10
25
|
if (data?.detail && Array.isArray(data.detail)) {
|
|
11
26
|
return data.detail
|
|
12
|
-
.map((err
|
|
27
|
+
.map((err) => {
|
|
13
28
|
// Handle nested field paths properly
|
|
14
29
|
const fieldPath = err.loc.slice(1).join('.')
|
|
15
30
|
const field = fieldPath
|
|
16
31
|
.split('.')
|
|
17
|
-
.map((part
|
|
32
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
18
33
|
.join(' ')
|
|
19
34
|
|
|
20
35
|
let message = err.msg
|