@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 CHANGED
@@ -21,6 +21,7 @@ type ClientOptions = {
21
21
  logResponse?: boolean;
22
22
  store?: Store;
23
23
  onLog?: (...args: any[]) => void;
24
+ userAgent?: string;
24
25
  };
25
26
  type ClientError = {
26
27
  formattedError: {
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ type ClientOptions = {
21
21
  logResponse?: boolean;
22
22
  store?: Store;
23
23
  onLog?: (...args: any[]) => void;
24
+ userAgent?: string;
24
25
  };
25
26
  type ClientError = {
26
27
  formattedError: {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-client",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -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
@@ -23,6 +23,7 @@ export type ClientOptions = {
23
23
  logResponse?: boolean;
24
24
  store?: Store;
25
25
  onLog?: (...args: any[]) => void;
26
+ userAgent?: string;
26
27
  };
27
28
 
28
29
  export type ClientError = {
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
  });
package/vitest.config.ts CHANGED
@@ -4,5 +4,8 @@ export default defineConfig({
4
4
  test: {
5
5
  globals: true,
6
6
  environment: 'node',
7
+ env: {
8
+ VERSION: '1.1.98',
9
+ },
7
10
  },
8
11
  });