eve-esi-types 3.2.4 → 3.2.7
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/CHANGELOG.md +39 -0
- package/README.md +87 -63
- package/{v2 → dist/v2}/esi-tagged-types.d.ts +77 -44
- package/{v2 → dist/v2}/experimental-esi-types.d.ts +139 -29
- package/dist/v2/index.d.ts +621 -0
- package/{v2 → dist/v2}/response-map.d.ts +1 -1
- package/{v2 → dist/v2}/types-index.d.ts +1 -1
- package/dist/v2/types-util.d.ts +281 -0
- package/dist/v2/util.d.ts +149 -0
- package/lib/console-util.mjs +1 -1
- package/lib/request-api.d.mts +4 -4
- package/lib/request-api.mjs +15 -16
- package/lib/rq-util.d.mts +76 -15
- package/lib/rq-util.mjs +122 -48
- package/lib/tagged-request-api.d.mts +2 -2
- package/lib/tagged-request-api.mjs +2 -2
- package/minimal-rq.mjs +5 -5
- package/package.json +5 -5
- package/request-v3.d.mts +1 -8
- package/request-v3.mjs +16 -19
- package/tagged-rq.mjs +17 -6
- package/{jsconfig.json → tsconfig.json} +5 -5
- package/v2/index.d.ts +0 -515
- package/v2/types-util.d.ts +0 -171
- package/v2/util.d.ts +0 -72
- /package/{v2 → dist/v2}/globals/alliance.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/assets.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/calendar.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/character.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/clones.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/contacts.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/contracts.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/corporation.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/dogma.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/extra-types.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/factionwarfare.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/fittings.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/fleets.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/incursions.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/industry.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/insurance.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/killmails.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/location.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/loyalty.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/mail.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/market.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/planetaryinteraction.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/routes.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/search.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/skills.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/sovereignty.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/status.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/universe.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/wallet.d.ts +0 -0
- /package/{v2 → dist/v2}/globals/wars.d.ts +0 -0
package/lib/rq-util.d.mts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// https://opensource.org/licenses/mit-license.php
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="../v2"/>
|
|
8
|
+
/// <reference types="../dist/v2"/>
|
|
9
9
|
// - - - - - - - - - - - - - - - - - - - -
|
|
10
10
|
// imports
|
|
11
11
|
// - - - - - - - - - - - - - - - - - - - -
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// https://opensource.org/licenses/mit-license.php
|
|
17
17
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
18
18
|
*/
|
|
19
|
-
import type { TESIRequestFunctionMethods2 } from "../v2";
|
|
19
|
+
import type { TESIRequestFunctionMethods2 } from "../dist/v2";
|
|
20
20
|
import type { TESIErrorStats } from "./esi-error-types";
|
|
21
21
|
export { isNode } from "./constants.mjs";
|
|
22
22
|
/**
|
|
@@ -27,7 +27,7 @@ export type Truthy = string | number | boolean;
|
|
|
27
27
|
/**
|
|
28
28
|
* __{Header}.{Payload}.{Signature}__
|
|
29
29
|
*/
|
|
30
|
-
export type
|
|
30
|
+
export type TAccessToken = `${string}.${string}.${string}`;
|
|
31
31
|
export type ESIRequestOptions = {
|
|
32
32
|
/**
|
|
33
33
|
* query params for ESI request.
|
|
@@ -53,14 +53,45 @@ export type ESIRequestOptions = {
|
|
|
53
53
|
/**
|
|
54
54
|
* Can be an empty object if no authentication is required.description
|
|
55
55
|
*/
|
|
56
|
-
token?:
|
|
56
|
+
token?: TAccessToken;
|
|
57
57
|
/**
|
|
58
58
|
* cancel request immediately
|
|
59
59
|
*/
|
|
60
60
|
cancelable?: AbortController;
|
|
61
61
|
};
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* type of the JWT token `payload` section
|
|
64
|
+
*/
|
|
65
|
+
export declare type TJWTPayload = {
|
|
66
|
+
/** scopes. */
|
|
67
|
+
scp: string[];
|
|
68
|
+
/** uuid of the token */
|
|
69
|
+
jti: string;
|
|
70
|
+
/** jwt type */
|
|
71
|
+
kid: string;
|
|
72
|
+
/** contains EVE character ID.
|
|
73
|
+
* ```
|
|
74
|
+
* "CHARACTER:EVE:<character_id>"
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
sub: `CHARACTER:EVE:${number}`;
|
|
78
|
+
/** Application client ID. */
|
|
79
|
+
azp: string;
|
|
80
|
+
/** EVE character name. */
|
|
81
|
+
name: string;
|
|
82
|
+
/** owner hash. */
|
|
83
|
+
owner: string;
|
|
84
|
+
/** expire date as 1/1000. (UNIX timestamp) */
|
|
85
|
+
exp: number;
|
|
86
|
+
/** issuer host name. */
|
|
87
|
+
iss: string;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* @import * as ESIUtil from "./rq-util.mjs";
|
|
91
|
+
* @typedef {ESIUtil.Truthy} Truthy
|
|
92
|
+
* @typedef {ESIUtil.TAccessToken} TAccessToken
|
|
93
|
+
* @typedef {ESIUtil.TJWTPayload} TJWTPayload
|
|
94
|
+
* @typedef {ESIUtil.ESIRequestOptions} ESIRequestOptions
|
|
64
95
|
*/
|
|
65
96
|
/**
|
|
66
97
|
* simple named error class.
|
|
@@ -75,8 +106,12 @@ export declare class ESIErrorLimitReachedError extends ESIRequestError {
|
|
|
75
106
|
valueOf(): number;
|
|
76
107
|
}
|
|
77
108
|
/**
|
|
78
|
-
* @
|
|
109
|
+
* @template T
|
|
110
|
+
* @template {Record<string, unknown>} O
|
|
111
|
+
* @param {[T] | [(T | undefined)?]} opt
|
|
112
|
+
* @returns {NonNullable<T> & O}
|
|
79
113
|
*/
|
|
114
|
+
export declare const normalizeOptions: <T extends unknown, O extends Record<string, unknown> = ESIRequestOptions>(opt: [T] | [(T | undefined)?]) => (NonNullable<T> & O);
|
|
80
115
|
/**
|
|
81
116
|
* #### status: 200 | 201 | 204
|
|
82
117
|
*
|
|
@@ -86,10 +121,11 @@ export declare class ESIErrorLimitReachedError extends ESIRequestError {
|
|
|
86
121
|
* @param {string} endpointUrl
|
|
87
122
|
* @param {RequestInit} requestOpt
|
|
88
123
|
* @param {URLSearchParams} urlParams
|
|
89
|
-
* @param {(minus?: Truthy) => void=}
|
|
124
|
+
* @param {(minus?: Truthy) => void=} progress
|
|
125
|
+
* @param {true=} allowFetchPages 2025/4/26
|
|
90
126
|
* @returns {Promise<any>}
|
|
91
127
|
*/
|
|
92
|
-
export declare const handleSuccessResponse: (response: Response, endpointUrl: string, requestOpt: RequestInit, urlParams: URLSearchParams,
|
|
128
|
+
export declare const handleSuccessResponse: (response: Response, endpointUrl: string, requestOpt: RequestInit, urlParams: URLSearchParams, progress?: (minus?: Truthy) => void, allowFetchPages?: true) => Promise<any>;
|
|
93
129
|
/**
|
|
94
130
|
* @import {
|
|
95
131
|
* TESIErrorStats,
|
|
@@ -146,11 +182,13 @@ export declare const initOptions: (method: string, opt: ESIRequestOptions) => {
|
|
|
146
182
|
* @param {RequestInit} rqopt request options
|
|
147
183
|
* @param {URLSearchParams} usp queries
|
|
148
184
|
* @param {number} pc pageCount
|
|
149
|
-
* @param {(minus?: number) => void=}
|
|
185
|
+
* @param {(minus?: number) => void=} progress
|
|
150
186
|
* @returns {Promise<T | null>}
|
|
151
187
|
*/
|
|
152
|
-
export declare const fetchP: <T extends unknown>(endpointUrl: string, rqopt: RequestInit, usp: URLSearchParams, pc: number,
|
|
188
|
+
export declare const fetchP: <T extends unknown>(endpointUrl: string, rqopt: RequestInit, usp: URLSearchParams, pc: number, progress?: (minus?: Truthy) => void) => Promise<T | null>;
|
|
153
189
|
/** ### replace (C)urly (B)races (T)oken
|
|
190
|
+
*
|
|
191
|
+
* + Replace each `{…}` placeholder in the endpoint string with the corresponding ID.
|
|
154
192
|
*
|
|
155
193
|
* @example
|
|
156
194
|
* "/characters/{character_id}/skills"
|
|
@@ -158,18 +196,39 @@ export declare const fetchP: <T extends unknown>(endpointUrl: string, rqopt: Req
|
|
|
158
196
|
* "/characters/<char.character_id>/skills"
|
|
159
197
|
*
|
|
160
198
|
* @template {unknown} T
|
|
161
|
-
* @param {T} endpoint e.g
|
|
162
|
-
* @param {number[]} ids
|
|
163
|
-
* @returns {T}
|
|
199
|
+
* @param {T} endpoint An endpoint template, e.g. "/characters/{character_id}/skills"
|
|
200
|
+
* @param {number[]} ids An array of numbers to fill into each placeholder, in order of appearance
|
|
201
|
+
* @returns {T} A fully-qualified endpoint string with all `{…}` tokens replaced by their IDs
|
|
164
202
|
*/
|
|
165
203
|
export declare const replaceCbt: <T extends unknown>(endpoint: T, ids: number[]) => T;
|
|
166
204
|
/**
|
|
167
205
|
* @template {unknown} T
|
|
168
|
-
* @param {T}
|
|
206
|
+
* @param {T} endpoint this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
|
|
169
207
|
* + The version parameter is forced to apply `latest`
|
|
170
208
|
* @returns {string}
|
|
171
209
|
*/
|
|
172
|
-
export declare const curl: <T extends unknown>(
|
|
210
|
+
export declare const curl: <T extends unknown>(endpoint: T) => string;
|
|
211
|
+
/**
|
|
212
|
+
* Type guard that checks whether the given object has a `pathParams` property
|
|
213
|
+
* of type `number` or `number[]`.
|
|
214
|
+
*
|
|
215
|
+
* @template {Record<string, unknown>} T - The type of the object being checked.
|
|
216
|
+
* @param {T} opt - The object to inspect.
|
|
217
|
+
* @returns {opt is (T & { pathParams: number | number[] })}
|
|
218
|
+
* `true` if `opt` contains a `pathParams` property whose value is either
|
|
219
|
+
* a single number or an array of numbers, otherwise `false`.
|
|
220
|
+
*
|
|
221
|
+
* @date 2025/4/28
|
|
222
|
+
*/
|
|
223
|
+
export declare function hasPathParams<T extends Record<string, unknown>>(opt: T): opt is (T & {
|
|
224
|
+
pathParams: number | number[];
|
|
225
|
+
});
|
|
226
|
+
/**
|
|
227
|
+
*
|
|
228
|
+
* @param {string} accessToken OAuth 2.0 access token
|
|
229
|
+
* @returns {TJWTPayload}
|
|
230
|
+
*/
|
|
231
|
+
export declare const getJWTPayload: (accessToken: string) => TJWTPayload;
|
|
173
232
|
/**
|
|
174
233
|
* @date 2020/03/31
|
|
175
234
|
* @version 2.1
|
|
@@ -188,6 +247,8 @@ type TPrependParams = TESIRequestFunctionSignature2<ESIRequestOptions> | TESIReq
|
|
|
188
247
|
/**
|
|
189
248
|
* #### Fire a request that does not require authentication.
|
|
190
249
|
*
|
|
250
|
+
* + __CAVEAT:__ This function should only be used for testing.
|
|
251
|
+
*
|
|
191
252
|
* @param {TPrependParams} fn
|
|
192
253
|
* @returns {Promise<void>}
|
|
193
254
|
*/
|
package/lib/rq-util.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// https://opensource.org/licenses/mit-license.php
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="../v2"/>
|
|
8
|
+
/// <reference types="../dist/v2"/>
|
|
9
9
|
// - - - - - - - - - - - - - - - - - - - -
|
|
10
10
|
// imports
|
|
11
11
|
// - - - - - - - - - - - - - - - - - - - -
|
|
@@ -27,7 +27,11 @@ let LOG = false;
|
|
|
27
27
|
*/
|
|
28
28
|
export const BASE = "https://esi.evetech.net";
|
|
29
29
|
/**
|
|
30
|
-
* @
|
|
30
|
+
* @import * as ESIUtil from "./rq-util.mjs";
|
|
31
|
+
* @typedef {ESIUtil.Truthy} Truthy
|
|
32
|
+
* @typedef {ESIUtil.TAccessToken} TAccessToken
|
|
33
|
+
* @typedef {ESIUtil.TJWTPayload} TJWTPayload
|
|
34
|
+
* @typedef {ESIUtil.ESIRequestOptions} ESIRequestOptions
|
|
31
35
|
*/
|
|
32
36
|
/**
|
|
33
37
|
* simple named error class.
|
|
@@ -45,12 +49,24 @@ export class ESIErrorLimitReachedError extends ESIRequestError {
|
|
|
45
49
|
return 420;
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
|
-
/**
|
|
49
|
-
* @typedef {import("./rq-util.mjs").ESIRequestOptions} ESIRequestOptions
|
|
50
|
-
*/
|
|
51
52
|
// - - - - - - - - - - - - - - - - - - - -
|
|
52
53
|
// utility functions
|
|
53
54
|
// - - - - - - - - - - - - - - - - - - - -
|
|
55
|
+
/**
|
|
56
|
+
* @template T
|
|
57
|
+
* @template {Record<string, unknown>} O
|
|
58
|
+
* @param {[T] | [(T | undefined)?]} opt
|
|
59
|
+
* @returns {NonNullable<T> & O}
|
|
60
|
+
*/
|
|
61
|
+
export const normalizeOptions = (opt) => {
|
|
62
|
+
//* ctt
|
|
63
|
+
return /** @type {NonNullable<T> & O} */ (opt.length ? (opt[0] ?? {}) : {});
|
|
64
|
+
/*/
|
|
65
|
+
const r = /** @type {NonNullable<T>} * /(opt.length ? (opt[0] ?? {}): {}) as NonNullable<T>;
|
|
66
|
+
log(`normalizeOptions::[${JSON.stringify(r)}]`);
|
|
67
|
+
return r;
|
|
68
|
+
//*/
|
|
69
|
+
};
|
|
54
70
|
/**
|
|
55
71
|
* #### status: 200 | 201 | 204
|
|
56
72
|
*
|
|
@@ -60,30 +76,33 @@ export class ESIErrorLimitReachedError extends ESIRequestError {
|
|
|
60
76
|
* @param {string} endpointUrl
|
|
61
77
|
* @param {RequestInit} requestOpt
|
|
62
78
|
* @param {URLSearchParams} urlParams
|
|
63
|
-
* @param {(minus?: Truthy) => void=}
|
|
79
|
+
* @param {(minus?: Truthy) => void=} progress
|
|
80
|
+
* @param {true=} allowFetchPages 2025/4/26
|
|
64
81
|
* @returns {Promise<any>}
|
|
65
82
|
*/
|
|
66
|
-
export const handleSuccessResponse = async (response, endpointUrl, requestOpt, urlParams,
|
|
83
|
+
export const handleSuccessResponse = async (response, endpointUrl, requestOpt, urlParams, progress = () => { }, allowFetchPages) => {
|
|
67
84
|
// NoContentResponse
|
|
68
85
|
if (response.status === 204)
|
|
69
86
|
return {};
|
|
70
87
|
/** @type {any} */
|
|
71
88
|
const data = await response.json();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
if (allowFetchPages) {
|
|
90
|
+
// - - - - x-pages response.
|
|
91
|
+
// +undefined is NaN
|
|
92
|
+
// @ts-expect-error becouse +null is 0
|
|
93
|
+
const pc = +response.headers.get("x-pages");
|
|
94
|
+
// has remaining pages? NaN > 1 === false !isNaN(pageCount)
|
|
95
|
+
if (pc > 1) {
|
|
96
|
+
LOG && log('found "x-pages" header, pages: %d', pc);
|
|
97
|
+
const remData = await fetchP(endpointUrl, requestOpt, urlParams, pc, progress);
|
|
98
|
+
// finally, decide product data.
|
|
99
|
+
if (isArray(data) && isArray(remData)) {
|
|
100
|
+
// DEVNOTE: 2019/7/23 15:01:48 - types
|
|
101
|
+
return data.concat(remData);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
remData && Object.assign(data, remData);
|
|
105
|
+
}
|
|
87
106
|
}
|
|
88
107
|
}
|
|
89
108
|
return data;
|
|
@@ -214,6 +233,9 @@ export const initOptions = (method, opt) => {
|
|
|
214
233
|
qss[key] = oqs[key];
|
|
215
234
|
}
|
|
216
235
|
if (opt.auth) {
|
|
236
|
+
if (!opt.token) {
|
|
237
|
+
throw new Error("Authentication required: missing `token`");
|
|
238
|
+
}
|
|
217
239
|
// @ts-ignore The header is indeed an object
|
|
218
240
|
rqopt.headers.authorization = `Bearer ${opt.token}`;
|
|
219
241
|
}
|
|
@@ -233,19 +255,19 @@ export const initOptions = (method, opt) => {
|
|
|
233
255
|
* @param {RequestInit} rqopt request options
|
|
234
256
|
* @param {URLSearchParams} usp queries
|
|
235
257
|
* @param {number} pc pageCount
|
|
236
|
-
* @param {(minus?: number) => void=}
|
|
258
|
+
* @param {(minus?: number) => void=} progress
|
|
237
259
|
* @returns {Promise<T | null>}
|
|
238
260
|
*/
|
|
239
|
-
export const fetchP = async (endpointUrl, rqopt, usp, pc,
|
|
261
|
+
export const fetchP = async (endpointUrl, rqopt, usp, pc, progress = () => { }) => {
|
|
240
262
|
const rqs = [];
|
|
241
263
|
for (let i = 2; i <= pc;) {
|
|
242
264
|
usp.set("page", (i++) + "");
|
|
243
|
-
|
|
265
|
+
progress();
|
|
244
266
|
rqs.push(fetch(`${endpointUrl}?${usp + ""}`, rqopt).then(res => res.json()).catch(reason => {
|
|
245
267
|
console.warn(reason);
|
|
246
268
|
return [];
|
|
247
269
|
}).finally(() => {
|
|
248
|
-
|
|
270
|
+
progress(1);
|
|
249
271
|
}));
|
|
250
272
|
}
|
|
251
273
|
return Promise.all(rqs).then(jsons => {
|
|
@@ -262,7 +284,10 @@ export const fetchP = async (endpointUrl, rqopt, usp, pc, increment = () => { })
|
|
|
262
284
|
return null;
|
|
263
285
|
});
|
|
264
286
|
};
|
|
287
|
+
const CBT_RE = /{\w+}/g;
|
|
265
288
|
/** ### replace (C)urly (B)races (T)oken
|
|
289
|
+
*
|
|
290
|
+
* + Replace each `{…}` placeholder in the endpoint string with the corresponding ID.
|
|
266
291
|
*
|
|
267
292
|
* @example
|
|
268
293
|
* "/characters/{character_id}/skills"
|
|
@@ -270,24 +295,51 @@ export const fetchP = async (endpointUrl, rqopt, usp, pc, increment = () => { })
|
|
|
270
295
|
* "/characters/<char.character_id>/skills"
|
|
271
296
|
*
|
|
272
297
|
* @template {unknown} T
|
|
273
|
-
* @param {T} endpoint e.g
|
|
274
|
-
* @param {number[]} ids
|
|
275
|
-
* @returns {T}
|
|
298
|
+
* @param {T} endpoint An endpoint template, e.g. "/characters/{character_id}/skills"
|
|
299
|
+
* @param {number[]} ids An array of numbers to fill into each placeholder, in order of appearance
|
|
300
|
+
* @returns {T} A fully-qualified endpoint string with all `{…}` tokens replaced by their IDs
|
|
276
301
|
*/
|
|
277
302
|
export const replaceCbt = (endpoint, ids) => {
|
|
278
303
|
let idx = 0;
|
|
279
|
-
|
|
280
|
-
return endpoint.replace(/{([\w]+)}/g, () => ids[idx++] + "");
|
|
304
|
+
return /** @type {T} */ (/** @type {string} */ (endpoint).replace(CBT_RE, () => String(ids[idx++])));
|
|
281
305
|
};
|
|
282
306
|
/**
|
|
283
307
|
* @template {unknown} T
|
|
284
|
-
* @param {T}
|
|
308
|
+
* @param {T} endpoint this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
|
|
285
309
|
* + The version parameter is forced to apply `latest`
|
|
286
310
|
* @returns {string}
|
|
287
311
|
*/
|
|
288
|
-
export const curl = (
|
|
289
|
-
|
|
290
|
-
|
|
312
|
+
export const curl = (endpoint) => {
|
|
313
|
+
return `${BASE}/latest/${/** @type {string} */ (endpoint).replace(/^\/+|\/+$/g, "")}/`;
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* Type guard that checks whether the given object has a `pathParams` property
|
|
317
|
+
* of type `number` or `number[]`.
|
|
318
|
+
*
|
|
319
|
+
* @template {Record<string, unknown>} T - The type of the object being checked.
|
|
320
|
+
* @param {T} opt - The object to inspect.
|
|
321
|
+
* @returns {opt is (T & { pathParams: number | number[] })}
|
|
322
|
+
* `true` if `opt` contains a `pathParams` property whose value is either
|
|
323
|
+
* a single number or an array of numbers, otherwise `false`.
|
|
324
|
+
*
|
|
325
|
+
* @date 2025/4/28
|
|
326
|
+
*/
|
|
327
|
+
export function hasPathParams(opt) {
|
|
328
|
+
if (typeof opt !== "object" || opt === null)
|
|
329
|
+
return false;
|
|
330
|
+
return "pathParams" in opt && (typeof opt.pathParams === "number" || Array.isArray(opt.pathParams));
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
*
|
|
334
|
+
* @param {string} accessToken OAuth 2.0 access token
|
|
335
|
+
* @returns {TJWTPayload}
|
|
336
|
+
*/
|
|
337
|
+
export const getJWTPayload = (accessToken) => {
|
|
338
|
+
// const [header, payload, sig] = accessToken.split(".");
|
|
339
|
+
// const headerJson = a2b(header); maybe always {"alg":"RS256","kid":"JWT-Signature-Key","typ":"JWT"}
|
|
340
|
+
// const sigJson = a2b(sig);
|
|
341
|
+
const json = atob(accessToken.split(".")[1]);
|
|
342
|
+
return JSON.parse(json); // as NsEVEOAuth.TJWTPayload;
|
|
291
343
|
};
|
|
292
344
|
/**
|
|
293
345
|
* @date 2020/03/31
|
|
@@ -326,7 +378,7 @@ export function getLogger() {
|
|
|
326
378
|
}
|
|
327
379
|
/**
|
|
328
380
|
* Need typescript v5.5 later
|
|
329
|
-
* @import * as ESI from "../v2";
|
|
381
|
+
* @import * as ESI from "../dist/v2";
|
|
330
382
|
* @typedef {ESI.TESIRequestFunctionMethods2<ESIRequestOptions>} TESIRequestFunctionMethods2
|
|
331
383
|
*/
|
|
332
384
|
/**
|
|
@@ -337,24 +389,43 @@ export function getLogger() {
|
|
|
337
389
|
*
|
|
338
390
|
* @type {TESIEnhancedRequestFunctionSignature<TPrependParams, ESIRequestOptions>}
|
|
339
391
|
*/
|
|
392
|
+
// @ts-ignore ts(2322) ignore on ts file, bad js file is OK?
|
|
340
393
|
const fireWithoutAuth = (fn, method, endpoint, ...opt) => {
|
|
394
|
+
const arg = opt.length ? opt[0] : void 0;
|
|
341
395
|
if (typeof fn === "function") {
|
|
342
|
-
|
|
343
|
-
return fn(method, endpoint,
|
|
396
|
+
// @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
|
|
397
|
+
return fn(method, endpoint, arg);
|
|
344
398
|
}
|
|
345
399
|
// @ts-expect-error TODO: ts(2345) The argument type does not match the type of the specified parameter
|
|
346
|
-
return fn[method](endpoint,
|
|
400
|
+
return fn[method](endpoint, arg);
|
|
347
401
|
};
|
|
348
|
-
|
|
402
|
+
// /**
|
|
403
|
+
// * ```
|
|
404
|
+
// * process.env.CID // Specify EVE Character id
|
|
405
|
+
// * process.env.OAUTH_TOKEN // Spedify valid OAuth token
|
|
406
|
+
// * ```
|
|
407
|
+
// * @param envName
|
|
408
|
+
// */
|
|
409
|
+
// const getEnvValue = (envName: string) => process.env[envName] ?? null;
|
|
410
|
+
/** @type {TAccessToken} */
|
|
411
|
+
const token = /** @type {TAccessToken} */ (process.env.OAUTH_TOKEN ?? "token.token.token");
|
|
412
|
+
const ID_SomeEVECharacter = (() => {
|
|
413
|
+
if (token !== "token.token.token") {
|
|
414
|
+
const payload = getJWTPayload(token);
|
|
415
|
+
return +payload.sub.split(":")[2];
|
|
416
|
+
}
|
|
417
|
+
return 9000;
|
|
418
|
+
})();
|
|
349
419
|
/**
|
|
350
420
|
* #### Fire a request that does not require authentication.
|
|
351
421
|
*
|
|
422
|
+
* + __CAVEAT:__ This function should only be used for testing.
|
|
423
|
+
*
|
|
352
424
|
* @param {TPrependParams} fn
|
|
353
425
|
* @returns {Promise<void>}
|
|
354
426
|
*/
|
|
355
427
|
export async function fireRequestsDoesNotRequireAuth(fn) {
|
|
356
428
|
const { clog, rlog } = getLogger();
|
|
357
|
-
const ID_SomeEVECharacter = 90000;
|
|
358
429
|
const ID_CCP_Zoetrope = 2112625428;
|
|
359
430
|
try {
|
|
360
431
|
// - - - - - - - - - - - -
|
|
@@ -377,17 +448,21 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
|
|
|
377
448
|
rlog("get:/incursions/".green);
|
|
378
449
|
await fireWithoutAuth(fn, "get", "/incursions/").then(log);
|
|
379
450
|
if (is("withError")) {
|
|
451
|
+
log(`Try character ${ID_SomeEVECharacter} assets request`);
|
|
380
452
|
await fireWithoutAuth(fn, "get", "/characters/{character_id}/assets/", {
|
|
381
|
-
auth: true,
|
|
453
|
+
auth: true, token,
|
|
382
454
|
pathParams: ID_SomeEVECharacter,
|
|
383
|
-
token
|
|
384
455
|
}).then(assets => {
|
|
385
456
|
log(assets.slice(0, 5));
|
|
386
457
|
});
|
|
387
|
-
|
|
458
|
+
log(`Try character ${ID_SomeEVECharacter} fittings request`);
|
|
459
|
+
await fireWithoutAuth(fn, "get", `/characters/${ID_SomeEVECharacter}/fittings/`, {
|
|
388
460
|
auth: true,
|
|
389
|
-
// pathParams: [
|
|
390
|
-
|
|
461
|
+
// pathParams: [ID_SomeEVECharacter, 56789], // ✅ At this point, the expected semantic error is successfully triggered as intended.
|
|
462
|
+
token
|
|
463
|
+
}).then(fittings => {
|
|
464
|
+
log(fittings.slice(0, 5));
|
|
465
|
+
});
|
|
391
466
|
}
|
|
392
467
|
}
|
|
393
468
|
// - - - - - - - - - - - -
|
|
@@ -420,8 +495,7 @@ export async function fireRequestsDoesNotRequireAuth(fn) {
|
|
|
420
495
|
// Authentication is required, so an error will occur.
|
|
421
496
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
422
497
|
let willFailed = await fireWithoutAuth(fn, "get", `/characters/${ID_SomeEVECharacter}/ship/`, {
|
|
423
|
-
auth: true,
|
|
424
|
-
token //: "token.token.token"
|
|
498
|
+
auth: true, token
|
|
425
499
|
});
|
|
426
500
|
log(`get:/characters/${ID_SomeEVECharacter}/ship/, returns:`, willFailed);
|
|
427
501
|
// in this case, "categories" and "search" is required
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// https://opensource.org/licenses/mit-license.php
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="../v2/esi-tagged-types"/>
|
|
8
|
+
/// <reference types="../dist/v2/esi-tagged-types"/>
|
|
9
9
|
import type { ESIRequestOptions } from "./rq-util.mjs";
|
|
10
10
|
/**
|
|
11
11
|
* Decorates the ESI request body into a tagged ESI request map.
|
|
@@ -30,4 +30,4 @@ export declare function decoreateESIRequestBody<Opt extends Record<string, unkno
|
|
|
30
30
|
* @since 2.x
|
|
31
31
|
* @type {XESI.TaggedESIRequestMap2<ESIRequestOptions>}
|
|
32
32
|
*/
|
|
33
|
-
export declare const esi: import("../v2/esi-tagged-types").TaggedESIRequestMap2<ESIRequestOptions>;
|
|
33
|
+
export declare const esi: import("../dist/v2/esi-tagged-types").TaggedESIRequestMap2<ESIRequestOptions>;
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
// https://opensource.org/licenses/mit-license.php
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="../v2/esi-tagged-types"/>
|
|
8
|
+
/// <reference types="../dist/v2/esi-tagged-types"/>
|
|
9
9
|
/**
|
|
10
10
|
* @file eve-esi-types/lib/tagged-request-api.mts
|
|
11
11
|
*/
|
|
12
12
|
import { request2 } from "./request-api.mjs";
|
|
13
13
|
/**
|
|
14
|
-
* @import { TESIRequestFunctionMethods2 } from "../v2"
|
|
14
|
+
* @import { TESIRequestFunctionMethods2 } from "../dist/v2"
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
17
17
|
* @typedef {`${string}${"" | `,${string}`}`} TMethodList
|
package/minimal-rq.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// https://opensource.org/licenses/mit-license.php
|
|
6
6
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
|
-
/// <reference types="./v2"/>
|
|
8
|
+
/// <reference types="./dist/v2"/>
|
|
9
9
|
// - - - - - - - - - - - - - - - - - - - -
|
|
10
10
|
// imports
|
|
11
11
|
// - - - - - - - - - - - - - - - - - - - -
|
|
@@ -17,8 +17,8 @@ import { request2 } from "./lib/request-api.mjs";
|
|
|
17
17
|
// shorthands
|
|
18
18
|
const log = util.getUniversalLogger("[request-mini]: ");
|
|
19
19
|
/**
|
|
20
|
-
* @typedef {import("./v2").IESIRequestFunction2<util.ESIRequestOptions>} IESIRequestFunction2
|
|
21
|
-
* @typedef {import("./v2").TESIRequestFunctionMethods2<util.ESIRequestOptions>} TESIRequestFunctionMethods2
|
|
20
|
+
* @typedef {import("./dist/v2").IESIRequestFunction2<util.ESIRequestOptions>} IESIRequestFunction2
|
|
21
|
+
* @typedef {import("./dist/v2").TESIRequestFunctionMethods2<util.ESIRequestOptions>} TESIRequestFunctionMethods2
|
|
22
22
|
*/
|
|
23
23
|
// - - - - - - - - - - - - - - - - - - - -
|
|
24
24
|
// main functions
|
|
@@ -29,8 +29,8 @@ const log = util.getUniversalLogger("[request-mini]: ");
|
|
|
29
29
|
const esiMethods = /** @type {TESIRequestFunctionMethods2} */ ({});
|
|
30
30
|
/** @satisfies {TESIEntryMethod[]} */ (["get", "post", "put", "delete"]).forEach((method) => {
|
|
31
31
|
esiMethods[method] = /** @type {TESIRequestFunctionEachMethod2<typeof method, util.ESIRequestOptions>} */ ((endpoint, opt) => {
|
|
32
|
-
// @ts-expect
|
|
33
|
-
return request2(method, endpoint,
|
|
32
|
+
// @ts-expect-error ts(2345)
|
|
33
|
+
return request2(method, endpoint, opt);
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
// It should complete correctly.
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eve-esi-types",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.7",
|
|
4
4
|
"description": "Extracted the main type of ESI. use for ESI request response types (version 2 only)",
|
|
5
|
-
"main": "v2/index.d.ts",
|
|
5
|
+
"main": "dist/v2/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"start": "tsc
|
|
7
|
+
"start": "tsc",
|
|
8
8
|
"test": "node request-v3.mjs -debug",
|
|
9
9
|
"test:mini": "node minimal-rq.mjs -debug"
|
|
10
10
|
},
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"url": "git+ssh://git@github.com/jeffy-g/eve-esi-types.git"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
16
|
+
"dist",
|
|
17
17
|
"lib",
|
|
18
18
|
"web",
|
|
19
19
|
"*.d.mts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"LICENSE",
|
|
22
22
|
"*.md",
|
|
23
23
|
"package.json",
|
|
24
|
-
"
|
|
24
|
+
"tsconfig.json"
|
|
25
25
|
],
|
|
26
26
|
"keywords": [
|
|
27
27
|
"api",
|
package/request-v3.d.mts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
3
|
-
Copyright (C) 2025 jeffy-g <hirotom1107@gmail.com>
|
|
4
|
-
Released under the MIT license
|
|
5
|
-
https://opensource.org/licenses/mit-license.php
|
|
6
|
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
|
-
*/
|
|
8
|
-
import { type ESIRequestOptions } from "./lib/rq-util.mjs";
|
|
1
|
+
import type { ESIRequestOptions } from "./lib/rq-util.mjs";
|
|
9
2
|
/**
|
|
10
3
|
* @returns Get The Current ESI request pending count.
|
|
11
4
|
*/
|
package/request-v3.mjs
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
https://opensource.org/licenses/mit-license.php
|
|
6
6
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @file request-v3.mts
|
|
10
|
+
* @command node request-v3.mjs
|
|
11
|
+
*/
|
|
12
|
+
/// <reference types="./dist/v2"/>
|
|
9
13
|
// - - - - - - - - - - - - - - - - - - - -
|
|
10
14
|
// imports
|
|
11
15
|
// - - - - - - - - - - - - - - - - - - - -
|
|
12
|
-
|
|
13
|
-
// import type { TESIResponseOKMap } from "eve-esi-types";
|
|
14
|
-
import { is, curl, replaceCbt, getSDEVersion, initOptions, isDebug, fireRequestsDoesNotRequireAuth, isSuccess, handleESIError, handleSuccessResponse } from "./lib/rq-util.mjs";
|
|
16
|
+
import { is, curl, replaceCbt, hasPathParams, getSDEVersion, normalizeOptions, initOptions, isDebug, fireRequestsDoesNotRequireAuth, isSuccess, handleESIError, handleSuccessResponse, } from "./lib/rq-util.mjs";
|
|
15
17
|
// - - - - - - - - - - - - - - - - - - - -
|
|
16
18
|
// constants, types
|
|
17
19
|
// - - - - - - - - - - - - - - - - - - - -
|
|
@@ -21,9 +23,8 @@ const isArray = Array.isArray;
|
|
|
21
23
|
/**
|
|
22
24
|
* enable/disable console.log
|
|
23
25
|
*/
|
|
24
|
-
|
|
26
|
+
const LOG = isDebug();
|
|
25
27
|
/**
|
|
26
|
-
* @typedef {import("./v2").TESIResponseOKMap} TESIResponseOKMap
|
|
27
28
|
* @typedef {import("./lib/rq-util.mjs").ESIRequestOptions} ESIRequestOptions
|
|
28
29
|
* @typedef {import("./lib/rq-util.mjs").ESIRequestError} ESIRequestError
|
|
29
30
|
* @typedef {import("./lib/rq-util.mjs").Truthy} Truthy
|
|
@@ -36,7 +37,7 @@ let LOG = isDebug();
|
|
|
36
37
|
*/
|
|
37
38
|
let ax = 0;
|
|
38
39
|
/** @type {function(Truthy=): number} */
|
|
39
|
-
const
|
|
40
|
+
const progress = (minus) => minus ? ax-- : ax++;
|
|
40
41
|
/**
|
|
41
42
|
* @returns Get The Current ESI request pending count.
|
|
42
43
|
*/
|
|
@@ -50,18 +51,14 @@ export const getRequestPending = () => ax;
|
|
|
50
51
|
* @throws {ESIRequestError}
|
|
51
52
|
* @async
|
|
52
53
|
*/
|
|
53
|
-
export const fire = /** @type {TESIRequestFunctionSignature2<ESIRequestOptions>} */ (async (mthd, endp, opt) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
pathParams =
|
|
58
|
-
}
|
|
59
|
-
if (isArray(pathParams)) {
|
|
54
|
+
export const fire = /** @type {TESIRequestFunctionSignature2<ESIRequestOptions>} */ (async (mthd, endp, ...opt) => {
|
|
55
|
+
// When only options are provided
|
|
56
|
+
const nOpt = normalizeOptions(opt);
|
|
57
|
+
if (hasPathParams(nOpt)) {
|
|
58
|
+
const pathParams = Array.isArray(nOpt.pathParams) ? nOpt.pathParams : [nOpt.pathParams];
|
|
60
59
|
endp = replaceCbt(endp, pathParams);
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
const actualOpt = opt || /** @type {NonNullable<typeof opt>} */ ({});
|
|
64
|
-
const { rqopt, qss } = initOptions(mthd, actualOpt);
|
|
61
|
+
const { rqopt, qss } = initOptions(mthd, nOpt);
|
|
65
62
|
const endpointUrl = curl(endp);
|
|
66
63
|
const up = new URLSearchParams(qss);
|
|
67
64
|
const url = `${endpointUrl}${up.size ? `?${up}` : ""}`;
|
|
@@ -71,11 +68,11 @@ export const fire = /** @type {TESIRequestFunctionSignature2<ESIRequestOptions>}
|
|
|
71
68
|
const res = await fetch(url, rqopt).finally(() => ax--);
|
|
72
69
|
// The parameters are different for successful and error responses.
|
|
73
70
|
if (isSuccess(res.status)) {
|
|
74
|
-
return handleSuccessResponse(res, endpointUrl, rqopt, up,
|
|
71
|
+
return handleSuccessResponse(res, endpointUrl, rqopt, up, progress);
|
|
75
72
|
}
|
|
76
73
|
// else if (isError(status)) {}
|
|
77
74
|
// Actually, throw Error
|
|
78
|
-
throw await handleESIError(res, endpointUrl,
|
|
75
|
+
throw await handleESIError(res, endpointUrl, nOpt.cancelable);
|
|
79
76
|
}
|
|
80
77
|
catch (e) {
|
|
81
78
|
throw e;
|