@bagelink/sdk 1.2.15 → 1.2.18

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 CHANGED
@@ -421,11 +421,11 @@ function formatAPIErrorMessage(err) {
421
421
  return "Network error occurred. Please check your connection.";
422
422
  }
423
423
  const { status, data } = error.response;
424
- if (data?.detail && Array.isArray(data.detail)) {
424
+ if (data.detail && Array.isArray(data.detail)) {
425
425
  return data.detail.map((err2) => {
426
426
  const fieldPath = err2.loc.slice(1).join(".");
427
427
  const field = fieldPath.split(".").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
428
- 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");
428
+ const 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");
429
429
  return `${field} ${message.toLowerCase()}`;
430
430
  }).join("\n");
431
431
  }
@@ -441,10 +441,10 @@ function formatAPIErrorMessage(err) {
441
441
  case 500:
442
442
  return "An internal server error occurred. Please try again later.";
443
443
  }
444
- if (data?.detail && typeof data.detail === "string") {
444
+ if (data.detail && typeof data.detail === "string") {
445
445
  return data.detail;
446
446
  }
447
- if (data?.message) {
447
+ if (data.message) {
448
448
  return data.message;
449
449
  }
450
450
  return `An error occurred (Status ${status}): ${error.message || "Unknown error"}`;
package/dist/index.mjs CHANGED
@@ -415,11 +415,11 @@ function formatAPIErrorMessage(err) {
415
415
  return "Network error occurred. Please check your connection.";
416
416
  }
417
417
  const { status, data } = error.response;
418
- if (data?.detail && Array.isArray(data.detail)) {
418
+ if (data.detail && Array.isArray(data.detail)) {
419
419
  return data.detail.map((err2) => {
420
420
  const fieldPath = err2.loc.slice(1).join(".");
421
421
  const field = fieldPath.split(".").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
422
- 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");
422
+ const 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");
423
423
  return `${field} ${message.toLowerCase()}`;
424
424
  }).join("\n");
425
425
  }
@@ -435,10 +435,10 @@ function formatAPIErrorMessage(err) {
435
435
  case 500:
436
436
  return "An internal server error occurred. Please try again later.";
437
437
  }
438
- if (data?.detail && typeof data.detail === "string") {
438
+ if (data.detail && typeof data.detail === "string") {
439
439
  return data.detail;
440
440
  }
441
- if (data?.message) {
441
+ if (data.message) {
442
442
  return data.message;
443
443
  }
444
444
  return `An error occurred (Status ${status}): ${error.message || "Unknown error"}`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "1.2.15",
4
+ "version": "1.2.18",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AxiosError } from "axios"
1
+ import type { AxiosError } from 'axios'
2
2
 
3
3
  export interface ValidationError {
4
4
  loc: (string | number)[]
@@ -10,9 +10,8 @@ export interface HTTPValidationError {
10
10
  detail: ValidationError[]
11
11
  }
12
12
 
13
-
14
13
  export function formatAPIErrorMessage(err: unknown): string {
15
- const error = err as AxiosError<HTTPValidationError & {[key:string]: any}> | undefined
14
+ const error = err as AxiosError<HTTPValidationError & { [key: string]: any }> | undefined
16
15
 
17
16
  // Handle case where error or response is undefined
18
17
  if (!error || !error.response) {
@@ -22,17 +21,17 @@ export function formatAPIErrorMessage(err: unknown): string {
22
21
  const { status, data } = error.response
23
22
 
24
23
  // Handle validation errors (422)
25
- if (data?.detail && Array.isArray(data.detail)) {
24
+ if (data.detail && Array.isArray(data.detail)) {
26
25
  return data.detail
27
26
  .map((err) => {
28
27
  // Handle nested field paths properly
29
28
  const fieldPath = err.loc.slice(1).join('.')
30
29
  const field = fieldPath
31
30
  .split('.')
32
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
31
+ .map(part => part.charAt(0).toUpperCase() + part.slice(1))
33
32
  .join(' ')
34
33
 
35
- let message = err.msg
34
+ const message = err.msg
36
35
  // Common validation messages
37
36
  .replace(/^(?:field|value|string|none) required$/i, 'is required')
38
37
  .replace(/^value is not a valid/i, 'must be a valid')
@@ -66,12 +65,12 @@ export function formatAPIErrorMessage(err: unknown): string {
66
65
  }
67
66
 
68
67
  // Handle other errors with detail
69
- if (data?.detail && typeof data.detail === 'string') {
68
+ if (data.detail && typeof data.detail === 'string') {
70
69
  return data.detail
71
70
  }
72
71
 
73
72
  // Handle errors with a message field
74
- if (data?.message) {
73
+ if (data.message) {
75
74
  return data.message
76
75
  }
77
76