@vulog/aima-client 1.0.9 → 1.0.11

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/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @vulog/aima-client
2
2
 
3
+ ```bash
4
+ npm i @vulog/aima-client
5
+ ```
6
+
3
7
  ```javascript
4
8
  import { getClient } from '@vulog/aima-client';
5
9
 
package/dist/index.d.mts CHANGED
@@ -16,14 +16,16 @@ type ClientOptions = {
16
16
  };
17
17
  type ClientError = {
18
18
  formattedError: {
19
- status: number;
20
- data: any;
19
+ status?: number;
20
+ data?: any;
21
+ message?: string;
21
22
  };
22
23
  originalError: any;
23
24
  };
24
25
  type Client = AxiosInstance & {
25
26
  refreshToken?: string;
26
27
  signInWithPassword: (username: string, password: string) => Promise<void>;
28
+ clientOptions: ClientOptions;
27
29
  };
28
30
 
29
31
  declare const getClient: (options: ClientOptions) => Client;
package/dist/index.d.ts CHANGED
@@ -16,14 +16,16 @@ type ClientOptions = {
16
16
  };
17
17
  type ClientError = {
18
18
  formattedError: {
19
- status: number;
20
- data: any;
19
+ status?: number;
20
+ data?: any;
21
+ message?: string;
21
22
  };
22
23
  originalError: any;
23
24
  };
24
25
  type Client = AxiosInstance & {
25
26
  refreshToken?: string;
26
27
  signInWithPassword: (username: string, password: string) => Promise<void>;
28
+ clientOptions: ClientOptions;
27
29
  };
28
30
 
29
31
  declare const getClient: (options: ClientOptions) => Client;
package/dist/index.js CHANGED
@@ -115,13 +115,19 @@ var CurlHelper = class {
115
115
  // src/getClient.ts
116
116
  var clientCache = new import_lru_cache.LRUCache({ max: 100 });
117
117
  var formatError = (error) => {
118
- const { response: { status, data } = { status: 500 } } = error ?? {};
118
+ if (error instanceof import_axios.AxiosError) {
119
+ return {
120
+ originalError: error.toJSON(),
121
+ formattedError: {
122
+ status: error.response?.status ?? error.status,
123
+ data: error.response?.data,
124
+ message: error.message
125
+ }
126
+ };
127
+ }
119
128
  return {
120
- formattedError: {
121
- status,
122
- data
123
- },
124
- originalError: error.toJSON ? error.toJSON() : error
129
+ formattedError: {},
130
+ originalError: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
125
131
  };
126
132
  };
127
133
  var getClient = (options) => {
@@ -141,6 +147,7 @@ var getClient = (options) => {
141
147
  },
142
148
  withCredentials: false
143
149
  });
150
+ client.clientOptions = options;
144
151
  const clientCredentialsAuthentification = async () => {
145
152
  const params = new URLSearchParams();
146
153
  params.append("client_id", options.clientId);
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/getClient.ts
2
- import axios from "axios";
2
+ import axios, { AxiosError } from "axios";
3
3
  import _ from "lodash";
4
4
  import { LRUCache } from "lru-cache";
5
5
 
@@ -79,13 +79,19 @@ var CurlHelper = class {
79
79
  // src/getClient.ts
80
80
  var clientCache = new LRUCache({ max: 100 });
81
81
  var formatError = (error) => {
82
- const { response: { status, data } = { status: 500 } } = error ?? {};
82
+ if (error instanceof AxiosError) {
83
+ return {
84
+ originalError: error.toJSON(),
85
+ formattedError: {
86
+ status: error.response?.status ?? error.status,
87
+ data: error.response?.data,
88
+ message: error.message
89
+ }
90
+ };
91
+ }
83
92
  return {
84
- formattedError: {
85
- status,
86
- data
87
- },
88
- originalError: error.toJSON ? error.toJSON() : error
93
+ formattedError: {},
94
+ originalError: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
89
95
  };
90
96
  };
91
97
  var getClient = (options) => {
@@ -105,6 +111,7 @@ var getClient = (options) => {
105
111
  },
106
112
  withCredentials: false
107
113
  });
114
+ client.clientOptions = options;
108
115
  const clientCredentialsAuthentification = async () => {
109
116
  const params = new URLSearchParams();
110
117
  params.append("client_id", options.clientId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-client",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "typescript": "^5.6.3",
34
34
  "vitest": "^2.1.3"
35
35
  },
36
- "dependencies": {
36
+ "peerDependencies": {
37
37
  "axios": "^1.7.7",
38
38
  "lodash": "^4.17.21",
39
39
  "lru-cache": "^11.0.1"
package/src/getClient.ts CHANGED
@@ -1,4 +1,4 @@
1
- import axios from 'axios';
1
+ import axios, { AxiosError } from 'axios';
2
2
  import _ from 'lodash';
3
3
  import { LRUCache } from 'lru-cache';
4
4
 
@@ -14,14 +14,20 @@ const clientCache = new LRUCache<
14
14
  >({ max: 100 });
15
15
 
16
16
  const formatError = (error: any): ClientError => {
17
- const { response: { status, data } = { status: 500 } } = error ?? {};
17
+ if (error instanceof AxiosError) {
18
+ return {
19
+ originalError: error.toJSON(),
20
+ formattedError: {
21
+ status: error.response?.status ?? error.status,
22
+ data: error.response?.data,
23
+ message: error.message,
24
+ },
25
+ };
26
+ }
18
27
 
19
28
  return {
20
- formattedError: {
21
- status,
22
- data,
23
- },
24
- originalError: error.toJSON ? error.toJSON() : error,
29
+ formattedError: {},
30
+ originalError: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))),
25
31
  };
26
32
  };
27
33
 
@@ -43,6 +49,7 @@ const getClient = (options: ClientOptions): Client => {
43
49
  },
44
50
  withCredentials: false,
45
51
  }) as Client;
52
+ client.clientOptions = options;
46
53
 
47
54
  const clientCredentialsAuthentification = async (): Promise<string> => {
48
55
  const params = new URLSearchParams();
package/src/types.ts CHANGED
@@ -17,8 +17,9 @@ export type ClientOptions = {
17
17
 
18
18
  export type ClientError = {
19
19
  formattedError: {
20
- status: number;
21
- data: any;
20
+ status?: number;
21
+ data?: any;
22
+ message?: string;
22
23
  };
23
24
  originalError: any;
24
25
  };
@@ -26,4 +27,5 @@ export type ClientError = {
26
27
  export type Client = AxiosInstance & {
27
28
  refreshToken?: string;
28
29
  signInWithPassword: (username: string, password: string) => Promise<void>;
30
+ clientOptions: ClientOptions;
29
31
  };