@vulog/aima-client 1.2.29 → 1.2.31
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 +281 -0
- package/dist/index.d.cts +43 -0
- package/dist/index.d.mts +31 -29
- package/dist/index.mjs +249 -285
- package/package.json +18 -5
- package/{tsup.config.ts → tsdown.config.ts} +1 -1
- package/vitest.config.ts +3 -3
- package/dist/index.d.ts +0 -41
- package/dist/index.js +0 -330
- /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,293 +1,257 @@
|
|
|
1
|
-
// src/getClient.ts
|
|
2
1
|
import axios, { AxiosError } from "axios";
|
|
3
2
|
import { isEqual, trimEnd } from "es-toolkit";
|
|
4
3
|
import { LRUCache } from "lru-cache";
|
|
5
|
-
|
|
6
|
-
// src/CurlHelper.ts
|
|
4
|
+
//#region src/CurlHelper.ts
|
|
7
5
|
var CurlHelper = class {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (this.getQueryString() !== "") {
|
|
70
|
-
url += this.getQueryString();
|
|
71
|
-
}
|
|
72
|
-
return url.trim();
|
|
73
|
-
}
|
|
74
|
-
generateCommand() {
|
|
75
|
-
return `curl ${this.getMethod()} "${this.getBuiltURL()}" ${this.getHeaders()} ${this.getBody()}`.trim().replace(/\s{2,}/g, " ");
|
|
76
|
-
}
|
|
6
|
+
request;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.request = config;
|
|
9
|
+
}
|
|
10
|
+
getHeaders() {
|
|
11
|
+
let { headers } = this.request;
|
|
12
|
+
let curlHeaders = "";
|
|
13
|
+
if (headers.hasOwnProperty("common")) headers = this.request.headers[this.request.method];
|
|
14
|
+
for (const property in this.request.headers) if (![
|
|
15
|
+
"common",
|
|
16
|
+
"delete",
|
|
17
|
+
"get",
|
|
18
|
+
"head",
|
|
19
|
+
"patch",
|
|
20
|
+
"post",
|
|
21
|
+
"put"
|
|
22
|
+
].includes(property)) headers[property] = this.request.headers[property];
|
|
23
|
+
for (const property in headers) if ({}.hasOwnProperty.call(headers, property)) {
|
|
24
|
+
const header = `${property}:${headers[property]}`;
|
|
25
|
+
curlHeaders = `${curlHeaders} -H '${header}'`;
|
|
26
|
+
}
|
|
27
|
+
return curlHeaders.trim();
|
|
28
|
+
}
|
|
29
|
+
getMethod() {
|
|
30
|
+
return `-X ${this.request.method.toUpperCase()}`;
|
|
31
|
+
}
|
|
32
|
+
getBody() {
|
|
33
|
+
if (typeof this.request.data !== "undefined" && this.request.data !== "" && this.request.data !== null && this.request.method.toUpperCase() !== "GET") return `--data '${typeof this.request.data === "object" || Object.prototype.toString.call(this.request.data) === "[object Array]" ? JSON.stringify(this.request.data) : this.request.data}'`.trim();
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
getUrl() {
|
|
37
|
+
if (this.request.baseURL) {
|
|
38
|
+
const baseUrl = this.request.baseURL;
|
|
39
|
+
const { url } = this.request;
|
|
40
|
+
return (url.startsWith("http") ? url : `${baseUrl}/${url}`).replace(/\/{2,}/g, "/").replace("http:/", "http://").replace("https:/", "https://");
|
|
41
|
+
}
|
|
42
|
+
return this.request.url;
|
|
43
|
+
}
|
|
44
|
+
getQueryString() {
|
|
45
|
+
if (this.request.paramsSerializer) {
|
|
46
|
+
const params = this.request.paramsSerializer(this.request.params);
|
|
47
|
+
if (!params || params.length === 0) return "";
|
|
48
|
+
if (params.startsWith("?")) return params;
|
|
49
|
+
return `?${params}`;
|
|
50
|
+
}
|
|
51
|
+
let params = "";
|
|
52
|
+
let i = 0;
|
|
53
|
+
for (const param in this.request.params) if ({}.hasOwnProperty.call(this.request.params, param)) {
|
|
54
|
+
params += i !== 0 ? `&${param}=${this.request.params[param]}` : `?${param}=${this.request.params[param]}`;
|
|
55
|
+
i += 1;
|
|
56
|
+
}
|
|
57
|
+
return params;
|
|
58
|
+
}
|
|
59
|
+
getBuiltURL() {
|
|
60
|
+
let url = this.getUrl();
|
|
61
|
+
if (this.getQueryString() !== "") url += this.getQueryString();
|
|
62
|
+
return url.trim();
|
|
63
|
+
}
|
|
64
|
+
generateCommand() {
|
|
65
|
+
return `curl ${this.getMethod()} "${this.getBuiltURL()}" ${this.getHeaders()} ${this.getBody()}`.trim().replace(/\s{2,}/g, " ");
|
|
66
|
+
}
|
|
77
67
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
tokenCache.set(options.name ?? options.fleetId, token);
|
|
96
|
-
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/getClient.ts
|
|
70
|
+
const clientCache = new LRUCache({ max: 100 });
|
|
71
|
+
const tokenCache = new LRUCache({ max: 100 });
|
|
72
|
+
const getMemoryStore = (options) => ({
|
|
73
|
+
getToken: async () => {
|
|
74
|
+
const log = options.onLog ?? console.log;
|
|
75
|
+
log("getMemoryStore.getToken", options.name ?? options.fleetId);
|
|
76
|
+
if (tokenCache.has(options.name ?? options.fleetId)) {
|
|
77
|
+
log("getMemoryStore.getToken", tokenCache.get(options.name ?? options.fleetId));
|
|
78
|
+
return tokenCache.get(options.name ?? options.fleetId);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
setToken: async (token) => {
|
|
82
|
+
(options.onLog ?? console.log)("getMemoryStore.setToken", options.name ?? options.fleetId, token);
|
|
83
|
+
tokenCache.set(options.name ?? options.fleetId, token);
|
|
84
|
+
}
|
|
97
85
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
originalError: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
112
|
-
};
|
|
86
|
+
const formatError = (error) => {
|
|
87
|
+
if (error instanceof AxiosError) return {
|
|
88
|
+
originalError: error.toJSON(),
|
|
89
|
+
formattedError: {
|
|
90
|
+
status: error.response?.status ?? error.status,
|
|
91
|
+
data: error.response?.data,
|
|
92
|
+
message: error.message
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
formattedError: {},
|
|
97
|
+
originalError: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
98
|
+
};
|
|
113
99
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
authentification = refreshTokenAuthentification;
|
|
270
|
-
} else {
|
|
271
|
-
authentification = clientCredentialsAuthentification;
|
|
272
|
-
}
|
|
273
|
-
authentification().then((accessToken) => {
|
|
274
|
-
refreshSubscribers.forEach((cb) => cb(accessToken));
|
|
275
|
-
}).catch((errorAuth) => {
|
|
276
|
-
refreshSubscribers.forEach((cb) => cb(void 0, errorAuth));
|
|
277
|
-
}).finally(() => {
|
|
278
|
-
isRefreshing = false;
|
|
279
|
-
refreshSubscribers = [];
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
return executorRefresh(originalRequest);
|
|
283
|
-
}
|
|
284
|
-
return Promise.reject(formatError(error));
|
|
285
|
-
}
|
|
286
|
-
);
|
|
287
|
-
clientCache.set(options.name ?? options.fleetId, { options, client });
|
|
288
|
-
return client;
|
|
289
|
-
};
|
|
290
|
-
var getClient_default = getClient;
|
|
291
|
-
export {
|
|
292
|
-
getClient_default as getClient
|
|
100
|
+
const getClient = (options) => {
|
|
101
|
+
if (clientCache.has(options.name ?? options.fleetId)) {
|
|
102
|
+
const { options: cachedOptions, client } = clientCache.get(options.fleetId);
|
|
103
|
+
if (isEqual(cachedOptions, options)) return client;
|
|
104
|
+
}
|
|
105
|
+
const client = axios.create({
|
|
106
|
+
baseURL: trimEnd(options.baseUrl, "/"),
|
|
107
|
+
timeout: 3e4,
|
|
108
|
+
headers: {
|
|
109
|
+
"Cache-Control": "no-cache",
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
"X-Api-Key": options.apiKey,
|
|
112
|
+
"User-Agent": options.userAgent ?? `aima-node/1.2.31 ${options.fleetId}`
|
|
113
|
+
},
|
|
114
|
+
withCredentials: false
|
|
115
|
+
});
|
|
116
|
+
client.clientOptions = options;
|
|
117
|
+
const clientCredentialsAuthentification = async () => {
|
|
118
|
+
const params = new URLSearchParams();
|
|
119
|
+
params.append("client_id", options.clientId);
|
|
120
|
+
params.append("client_secret", options.clientSecret);
|
|
121
|
+
params.append("securityOptions", "SSL_OP_NO_SSLv3");
|
|
122
|
+
params.append("grant_type", "client_credentials");
|
|
123
|
+
const { data: token } = await axios.post(`${trimEnd(options.baseUrl, "/")}/auth/realms/${options.fleetMaster ?? options.fleetId}/protocol/openid-connect/token`, params, {
|
|
124
|
+
timeout: 3e4,
|
|
125
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
126
|
+
withCredentials: false
|
|
127
|
+
});
|
|
128
|
+
await (options.store ?? getMemoryStore(options)).setToken({
|
|
129
|
+
accessToken: token.access_token,
|
|
130
|
+
refreshToken: token.refresh_token
|
|
131
|
+
});
|
|
132
|
+
return token.access_token;
|
|
133
|
+
};
|
|
134
|
+
const refreshTokenAuthentification = async () => {
|
|
135
|
+
const store = options.store ?? getMemoryStore(options);
|
|
136
|
+
const oldToken = await store.getToken();
|
|
137
|
+
if (!oldToken?.refreshToken) throw new Error("No refresh token available");
|
|
138
|
+
const params = new URLSearchParams();
|
|
139
|
+
params.append("client_id", options.clientId);
|
|
140
|
+
params.append("client_secret", options.clientSecret);
|
|
141
|
+
params.append("securityOptions", "SSL_OP_NO_SSLv3");
|
|
142
|
+
params.append("grant_type", "refresh_token");
|
|
143
|
+
params.append("refresh_token", oldToken.refreshToken);
|
|
144
|
+
const { data: token } = await axios.post(`${trimEnd(options.baseUrl, "/")}/auth/realms/${options.fleetMaster ?? options.fleetId}/protocol/openid-connect/token`, params, {
|
|
145
|
+
timeout: 3e4,
|
|
146
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
147
|
+
withCredentials: false
|
|
148
|
+
});
|
|
149
|
+
await store.setToken({
|
|
150
|
+
accessToken: token.access_token,
|
|
151
|
+
refreshToken: token.refresh_token
|
|
152
|
+
});
|
|
153
|
+
return token.access_token;
|
|
154
|
+
};
|
|
155
|
+
client.signInWithPassword = async (username, password) => {
|
|
156
|
+
if (!options.secure) throw new Error("Not secure");
|
|
157
|
+
const params = new URLSearchParams();
|
|
158
|
+
params.append("client_id", options.clientId);
|
|
159
|
+
params.append("client_secret", options.clientSecret);
|
|
160
|
+
params.append("securityOptions", "SSL_OP_NO_SSLv3");
|
|
161
|
+
params.append("grant_type", "password");
|
|
162
|
+
params.append("username", username);
|
|
163
|
+
params.append("password", password);
|
|
164
|
+
const { data: token } = await axios.post(`${trimEnd(options.baseUrl, "/")}/auth/realms/${options.fleetMaster ?? options.fleetId}/protocol/openid-connect/token`, params, {
|
|
165
|
+
timeout: 3e4,
|
|
166
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
167
|
+
withCredentials: false
|
|
168
|
+
});
|
|
169
|
+
const newToken = {
|
|
170
|
+
accessToken: token.access_token,
|
|
171
|
+
refreshToken: token.refresh_token
|
|
172
|
+
};
|
|
173
|
+
await (options.store ?? getMemoryStore(options)).setToken(newToken);
|
|
174
|
+
return newToken;
|
|
175
|
+
};
|
|
176
|
+
client.interceptors.request.use(async (request) => {
|
|
177
|
+
const newRequest = request;
|
|
178
|
+
const token = await (options.store ?? getMemoryStore(options)).getToken();
|
|
179
|
+
if (token?.accessToken) newRequest.headers.Authorization = `Bearer ${token.accessToken}`;
|
|
180
|
+
if (options.logCurl) {
|
|
181
|
+
const curl = new CurlHelper(newRequest).generateCommand();
|
|
182
|
+
if (options.onLog) options.onLog({
|
|
183
|
+
curl,
|
|
184
|
+
message: "getClient > Curl command"
|
|
185
|
+
});
|
|
186
|
+
else console.log({
|
|
187
|
+
curl,
|
|
188
|
+
message: "getClient > Curl command"
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return newRequest;
|
|
192
|
+
});
|
|
193
|
+
let isRefreshing = false;
|
|
194
|
+
let refreshSubscribers = [];
|
|
195
|
+
const executorRefresh = (config) => {
|
|
196
|
+
return new Promise((resolve, reject) => {
|
|
197
|
+
refreshSubscribers.push((token, error) => {
|
|
198
|
+
if (error) {
|
|
199
|
+
reject(formatError(error));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
resolve(client.request(config));
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
client.interceptors.response.use((response) => {
|
|
207
|
+
if (options.logResponse) {
|
|
208
|
+
const finalUrl = new CurlHelper(response.config).getBuiltURL();
|
|
209
|
+
const { data, headers } = response;
|
|
210
|
+
const dataLog = response.config.responseType !== "arraybuffer" && response.config.responseType !== "blob" ? data : "ArrayBuffer or blob";
|
|
211
|
+
if (options.onLog) options.onLog({
|
|
212
|
+
finalUrl,
|
|
213
|
+
data: dataLog,
|
|
214
|
+
headers,
|
|
215
|
+
message: "getClient > Response"
|
|
216
|
+
});
|
|
217
|
+
else console.log({
|
|
218
|
+
finalUrl,
|
|
219
|
+
data: dataLog,
|
|
220
|
+
headers,
|
|
221
|
+
message: "getClient > Response"
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return response;
|
|
225
|
+
}, (error) => {
|
|
226
|
+
const { config, response: { status } = { status: 500 } } = error;
|
|
227
|
+
const originalRequest = config;
|
|
228
|
+
if (originalRequest.attemptCount === void 0) originalRequest.attemptCount = 0;
|
|
229
|
+
if (originalRequest.attemptCount === 5) return Promise.reject(formatError(error));
|
|
230
|
+
if (status === 401) {
|
|
231
|
+
originalRequest.attemptCount += 1;
|
|
232
|
+
if (!isRefreshing) {
|
|
233
|
+
isRefreshing = true;
|
|
234
|
+
let authentification;
|
|
235
|
+
if (options.secure) authentification = refreshTokenAuthentification;
|
|
236
|
+
else authentification = clientCredentialsAuthentification;
|
|
237
|
+
authentification().then((accessToken) => {
|
|
238
|
+
refreshSubscribers.forEach((cb) => cb(accessToken));
|
|
239
|
+
}).catch((errorAuth) => {
|
|
240
|
+
refreshSubscribers.forEach((cb) => cb(void 0, errorAuth));
|
|
241
|
+
}).finally(() => {
|
|
242
|
+
isRefreshing = false;
|
|
243
|
+
refreshSubscribers = [];
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
return executorRefresh(originalRequest);
|
|
247
|
+
}
|
|
248
|
+
return Promise.reject(formatError(error));
|
|
249
|
+
});
|
|
250
|
+
clientCache.set(options.name ?? options.fleetId, {
|
|
251
|
+
options,
|
|
252
|
+
client
|
|
253
|
+
});
|
|
254
|
+
return client;
|
|
293
255
|
};
|
|
256
|
+
//#endregion
|
|
257
|
+
export { getClient };
|
package/package.json
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-client",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.2.31",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
5
6
|
"module": "dist/index.mjs",
|
|
6
|
-
"types": "dist/index.d.
|
|
7
|
+
"types": "dist/index.d.cts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.cts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
7
20
|
"scripts": {
|
|
8
|
-
"build": "
|
|
9
|
-
"dev": "
|
|
21
|
+
"build": "tsdown",
|
|
22
|
+
"dev": "tsdown --watch",
|
|
10
23
|
"test": "vitest run",
|
|
11
24
|
"test:watch": "vitest",
|
|
12
25
|
"lint": "eslint src/**/* --ext .ts"
|
package/vitest.config.ts
CHANGED
package/dist/index.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
|
|
3
|
-
type Token = {
|
|
4
|
-
accessToken: string;
|
|
5
|
-
refreshToken: string;
|
|
6
|
-
};
|
|
7
|
-
type Store = {
|
|
8
|
-
getToken: () => Promise<Token | undefined>;
|
|
9
|
-
setToken: (token: Token) => Promise<void>;
|
|
10
|
-
};
|
|
11
|
-
type ClientOptions = {
|
|
12
|
-
fleetId: string;
|
|
13
|
-
name?: string;
|
|
14
|
-
fleetMaster?: string;
|
|
15
|
-
baseUrl: string;
|
|
16
|
-
clientId: string;
|
|
17
|
-
clientSecret: string;
|
|
18
|
-
apiKey: string;
|
|
19
|
-
secure?: boolean;
|
|
20
|
-
logCurl?: boolean;
|
|
21
|
-
logResponse?: boolean;
|
|
22
|
-
store?: Store;
|
|
23
|
-
onLog?: (...args: any[]) => void;
|
|
24
|
-
userAgent?: string;
|
|
25
|
-
};
|
|
26
|
-
type ClientError = {
|
|
27
|
-
formattedError: {
|
|
28
|
-
status?: number;
|
|
29
|
-
data?: any;
|
|
30
|
-
message?: string;
|
|
31
|
-
};
|
|
32
|
-
originalError: any;
|
|
33
|
-
};
|
|
34
|
-
type Client = AxiosInstance & {
|
|
35
|
-
signInWithPassword: (username: string, password: string) => Promise<Token>;
|
|
36
|
-
clientOptions: ClientOptions;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
declare const getClient: (options: ClientOptions) => Client;
|
|
40
|
-
|
|
41
|
-
export { type Client, type ClientError, type ClientOptions, type Store, type Token, getClient };
|