@vulog/aima-client 1.2.3 → 1.2.4
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/index.mjs +2 -1
- package/package.json +1 -1
- package/src/getClient.test.ts +26 -0
- package/src/getClient.ts +4 -0
- package/src/types.ts +1 -0
- package/tsup.config.ts +6 -0
- package/vitest.config.ts +3 -0
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -160,7 +160,8 @@ var getClient = (options) => {
|
|
|
160
160
|
headers: {
|
|
161
161
|
"Cache-Control": "no-cache",
|
|
162
162
|
"Content-Type": "application/json",
|
|
163
|
-
"X-Api-Key": options.apiKey
|
|
163
|
+
"X-Api-Key": options.apiKey,
|
|
164
|
+
"User-Agent": options.userAgent ?? `aima-node/${"1.2.4"} ${options.fleetId}`
|
|
164
165
|
},
|
|
165
166
|
withCredentials: false
|
|
166
167
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -124,7 +124,8 @@ var getClient = (options) => {
|
|
|
124
124
|
headers: {
|
|
125
125
|
"Cache-Control": "no-cache",
|
|
126
126
|
"Content-Type": "application/json",
|
|
127
|
-
"X-Api-Key": options.apiKey
|
|
127
|
+
"X-Api-Key": options.apiKey,
|
|
128
|
+
"User-Agent": options.userAgent ?? `aima-node/${"1.2.4"} ${options.fleetId}`
|
|
128
129
|
},
|
|
129
130
|
withCredentials: false
|
|
130
131
|
});
|
package/package.json
CHANGED
package/src/getClient.test.ts
CHANGED
|
@@ -18,4 +18,30 @@ describe('getClient', () => {
|
|
|
18
18
|
const client = getClient(options);
|
|
19
19
|
expect(client.defaults.baseURL).toEqual(options.baseUrl);
|
|
20
20
|
});
|
|
21
|
+
|
|
22
|
+
test('User-Agent should contain package version', () => {
|
|
23
|
+
const options: ClientOptions = {
|
|
24
|
+
fleetId: 'fleetId',
|
|
25
|
+
baseUrl: 'baseUrl',
|
|
26
|
+
clientId: 'clientId',
|
|
27
|
+
clientSecret: 'clientSecret',
|
|
28
|
+
apiKey: 'apiKey',
|
|
29
|
+
};
|
|
30
|
+
const client = getClient(options);
|
|
31
|
+
expect(client.defaults.headers['User-Agent']).toEqual(`aima-node/1.1.98 ${options.fleetId}`);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('User-Agent should use custom value when provided', () => {
|
|
35
|
+
const customUserAgent = 'custom-user-agent/1.0';
|
|
36
|
+
const options: ClientOptions = {
|
|
37
|
+
fleetId: 'fleetId',
|
|
38
|
+
baseUrl: 'baseUrl',
|
|
39
|
+
clientId: 'clientId',
|
|
40
|
+
clientSecret: 'clientSecret',
|
|
41
|
+
apiKey: 'apiKey',
|
|
42
|
+
userAgent: customUserAgent,
|
|
43
|
+
};
|
|
44
|
+
const client = getClient(options);
|
|
45
|
+
expect(client.defaults.headers['User-Agent']).toEqual(customUserAgent);
|
|
46
|
+
});
|
|
21
47
|
});
|
package/src/getClient.ts
CHANGED
|
@@ -5,6 +5,9 @@ import { LRUCache } from 'lru-cache';
|
|
|
5
5
|
import { CurlHelper } from './CurlHelper';
|
|
6
6
|
import { Client, ClientError, ClientOptions, Store, Token } from './types';
|
|
7
7
|
|
|
8
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
9
|
+
declare const __VERSION__: string;
|
|
10
|
+
|
|
8
11
|
type RefreshSubscriber = (token?: string, error?: any) => void;
|
|
9
12
|
|
|
10
13
|
const clientCache = new LRUCache<
|
|
@@ -70,6 +73,7 @@ const getClient = (options: ClientOptions): Client => {
|
|
|
70
73
|
'Cache-Control': 'no-cache',
|
|
71
74
|
'Content-Type': 'application/json',
|
|
72
75
|
'X-Api-Key': options.apiKey,
|
|
76
|
+
'User-Agent': options.userAgent ?? `aima-node/${__VERSION__} ${options.fleetId}`,
|
|
73
77
|
},
|
|
74
78
|
withCredentials: false,
|
|
75
79
|
}) as Client;
|
package/src/types.ts
CHANGED
package/tsup.config.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { defineConfig } from 'tsup';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
|
|
4
|
+
const packageJson = JSON.parse(readFileSync('./package.json', 'utf-8'));
|
|
2
5
|
|
|
3
6
|
export default defineConfig({
|
|
4
7
|
entry: ['src/index.ts'],
|
|
5
8
|
clean: true,
|
|
6
9
|
format: ['cjs', 'esm'],
|
|
7
10
|
dts: true,
|
|
11
|
+
define: {
|
|
12
|
+
__VERSION__: JSON.stringify(packageJson.version),
|
|
13
|
+
},
|
|
8
14
|
});
|