@localisprimary/esi 1.1.0 → 1.3.0
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 +14 -3
- package/dist/client.d.ts +4 -0
- package/dist/client.js +20 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ A slightly opinionated TypeScript client for the [EVE Online API](https://develo
|
|
|
12
12
|
import { EsiClient } from '@localisprimary/esi'
|
|
13
13
|
|
|
14
14
|
// Create client (optionally with auth token)
|
|
15
|
-
const esi = new EsiClient({ token: 'bearer-token' })
|
|
15
|
+
const esi = new EsiClient({ userAgent: 'foo@example.com', token: 'bearer-token' })
|
|
16
16
|
|
|
17
17
|
// Get all alliances
|
|
18
18
|
const alliances = await esi.getAlliances()
|
|
@@ -23,9 +23,20 @@ const alliance = await esi.getAlliance({ alliance_id: 123 })
|
|
|
23
23
|
console.log(alliance.data)
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
The `EsiClient` constructor accepts an options object with the following properties:
|
|
29
|
+
| Parameter | Description | Type | Default | Required |
|
|
30
|
+
|-----------|-------------|------|---------|----------|
|
|
31
|
+
| `token` | Optional auth token for authenticated requests | `string` | `undefined` | No |
|
|
32
|
+
| `userAgent` | User agent string for requests. Resolves to `"localisprimary/esi <userAgent>"` | `string` | `undefined` | No* |
|
|
33
|
+
| `useRequestHeaders` | When false, fall back to query parameters for user agent and token | `boolean` | `true` | No |
|
|
34
|
+
|
|
35
|
+
<small>* Will be required in a future version.</small>
|
|
36
|
+
|
|
26
37
|
## Methods
|
|
27
38
|
|
|
28
|
-
This client provides methods for all EVE ESI endpoints. Methods return a Promise that resolves to an `EsiResponse<T>`
|
|
39
|
+
This client provides methods for all EVE ESI endpoints. Methods return a `Promise` that resolves to an `EsiResponse<T>` or throws an `EsiError`.
|
|
29
40
|
|
|
30
41
|
```typescript
|
|
31
42
|
interface EsiResponse<TData, THeaders = Record<string, string>> {
|
|
@@ -44,7 +55,7 @@ All methods are fully typed: `getAlliance` will take `GetAllianceParams` and ret
|
|
|
44
55
|
|
|
45
56
|
`Params` types make no distinction between path, query, or body parameters, it's all the same object:
|
|
46
57
|
```typescript
|
|
47
|
-
const esi = new EsiClient({ token: 'bearer-token' })
|
|
58
|
+
const esi = new EsiClient({ userAgent: 'foo@example.com', token: 'bearer-token' })
|
|
48
59
|
|
|
49
60
|
// POST https://esi.evetech.net/characters/{character_id}/mail
|
|
50
61
|
esi.postCharacterMail({
|
package/dist/client.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import * as Types from './types';
|
|
2
2
|
export declare class EsiClient {
|
|
3
3
|
private readonly baseUrl;
|
|
4
|
+
private readonly userAgent;
|
|
4
5
|
private readonly token?;
|
|
6
|
+
private readonly useRequestHeaders;
|
|
5
7
|
constructor(options?: {
|
|
6
8
|
token?: string;
|
|
9
|
+
userAgent?: string;
|
|
10
|
+
useRequestHeaders?: boolean;
|
|
7
11
|
});
|
|
8
12
|
private request;
|
|
9
13
|
/**
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
const COMPATIBILITY_DATE = '2025-07-29';
|
|
1
2
|
export class EsiClient {
|
|
2
3
|
constructor(options = {}) {
|
|
3
4
|
this.baseUrl = 'https://esi.evetech.net';
|
|
5
|
+
this.userAgent = 'localisprimary/esi';
|
|
6
|
+
this.useRequestHeaders = true;
|
|
4
7
|
this.token = options.token;
|
|
8
|
+
this.useRequestHeaders = options.useRequestHeaders ?? true;
|
|
9
|
+
if (options.userAgent?.length) {
|
|
10
|
+
this.userAgent += ` ${options.userAgent}`;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
console.warn('@localisprimary/esi: No user agent provided in constructor. This will be required in a future release.');
|
|
14
|
+
}
|
|
5
15
|
}
|
|
6
16
|
async request(method, path, params, body) {
|
|
7
17
|
const url = new URL(path, this.baseUrl);
|
|
@@ -12,15 +22,24 @@ export class EsiClient {
|
|
|
12
22
|
}
|
|
13
23
|
});
|
|
14
24
|
}
|
|
25
|
+
if (!this.useRequestHeaders) {
|
|
26
|
+
url.searchParams.append('user_agent', this.userAgent);
|
|
27
|
+
url.searchParams.append('compatibility_date', COMPATIBILITY_DATE);
|
|
28
|
+
if (this.token) {
|
|
29
|
+
url.searchParams.append('token', this.token);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
15
32
|
const headers = {
|
|
16
33
|
'Content-Type': 'application/json',
|
|
34
|
+
'X-Compatibility-Date': COMPATIBILITY_DATE,
|
|
35
|
+
'X-User-Agent': this.userAgent,
|
|
17
36
|
};
|
|
18
37
|
if (this.token) {
|
|
19
38
|
headers['Authorization'] = `Bearer ${this.token}`;
|
|
20
39
|
}
|
|
21
40
|
const response = await fetch(url.toString(), {
|
|
22
41
|
method,
|
|
23
|
-
headers,
|
|
42
|
+
headers: this.useRequestHeaders ? headers : undefined,
|
|
24
43
|
body: body ? JSON.stringify(body) : undefined,
|
|
25
44
|
});
|
|
26
45
|
const data = await response.json();
|