eve-esi-types 1.0.0 → 1.1.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 +38 -2
- package/esi-request.d.mts +58 -0
- package/esi-request.mjs +284 -0
- package/package.json +12 -3
- package/src/get_alliances_alliance_id_contacts_labels_ok.d.ts +9 -12
- package/src/get_alliances_alliance_id_contacts_ok.d.ts +15 -23
- package/src/get_alliances_alliance_id_corporations_ok.d.ts +2 -7
- package/src/get_alliances_alliance_id_icons_ok.d.ts +9 -12
- package/src/get_alliances_alliance_id_ok.d.ts +29 -37
- package/src/get_alliances_ok.d.ts +2 -7
- package/src/get_characters_character_id_agents_research_ok.d.ts +18 -27
- package/src/get_characters_character_id_assets_ok.d.ts +22 -32
- package/src/get_characters_character_id_attributes_ok.d.ts +33 -42
- package/src/get_characters_character_id_blueprints_ok.d.ts +26 -37
- package/src/get_characters_character_id_bookmarks_folders_ok.d.ts +9 -12
- package/src/get_characters_character_id_bookmarks_ok.d.ts +46 -62
- package/src/get_characters_character_id_calendar_event_id_attendees_ok.d.ts +5 -7
- package/src/get_characters_character_id_calendar_event_id_ok.d.ts +37 -47
- package/src/get_characters_character_id_calendar_ok.d.ts +17 -22
- package/src/get_characters_character_id_clones_ok.d.ts +31 -43
- package/src/get_characters_character_id_contacts_labels_ok.d.ts +9 -12
- package/src/get_characters_character_id_contacts_ok.d.ts +23 -33
- package/src/get_characters_character_id_contracts_contract_id_bids_ok.d.ts +17 -22
- package/src/get_characters_character_id_contracts_contract_id_items_ok.d.ts +22 -32
- package/src/get_characters_character_id_contracts_ok.d.ts +77 -97
- package/src/get_characters_character_id_corporationhistory_ok.d.ts +17 -22
- package/src/get_characters_character_id_fatigue_ok.d.ts +13 -17
- package/src/get_characters_character_id_fittings_ok.d.ts +19 -32
- package/src/get_characters_character_id_fleet_ok.d.ts +13 -17
- package/src/get_characters_character_id_fw_stats_ok.d.ts +41 -52
- package/src/get_characters_character_id_implants_ok.d.ts +2 -7
- package/src/get_characters_character_id_industry_jobs_ok.d.ts +79 -107
- package/src/get_characters_character_id_killmails_recent_ok.d.ts +9 -12
- package/src/get_characters_character_id_location_ok.d.ts +13 -17
- package/src/get_characters_character_id_loyalty_points_ok.d.ts +9 -12
- package/src/get_characters_character_id_mail_labels_ok.d.ts +17 -22
- package/src/get_characters_character_id_mail_lists_ok.d.ts +9 -12
- package/src/get_characters_character_id_mail_mail_id_ok.d.ts +31 -43
- package/src/get_characters_character_id_mail_ok.d.ts +31 -43
- package/src/get_characters_character_id_medals_ok.d.ts +45 -57
- package/src/get_characters_character_id_mining_ok.d.ts +14 -22
- package/src/get_characters_character_id_notifications_contacts_ok.d.ts +21 -27
- package/src/get_characters_character_id_notifications_ok.d.ts +21 -27
- package/src/get_characters_character_id_ok.d.ts +41 -52
- package/src/get_characters_character_id_online_ok.d.ts +17 -22
- package/src/get_characters_character_id_opportunities_ok.d.ts +9 -12
- package/src/get_characters_character_id_orders_history_ok.d.ts +50 -67
- package/src/get_characters_character_id_orders_ok.d.ts +50 -67
- package/src/get_characters_character_id_planets_ok.d.ts +25 -32
- package/src/get_characters_character_id_planets_planet_id_ok.d.ts +110 -150
- package/src/get_characters_character_id_portrait_ok.d.ts +17 -22
- package/src/get_characters_character_id_roles_ok.d.ts +1 -2
- package/src/get_characters_character_id_search_ok.d.ts +62 -123
- package/src/get_characters_character_id_ship_ok.d.ts +10 -17
- package/src/get_characters_character_id_skillqueue_ok.d.ts +33 -42
- package/src/get_characters_character_id_skills_ok.d.ts +25 -32
- package/src/get_characters_character_id_standings_ok.d.ts +9 -12
- package/src/get_characters_character_id_titles_ok.d.ts +9 -12
- package/src/get_characters_character_id_wallet_journal_ok.d.ts +45 -57
- package/src/get_characters_character_id_wallet_ok.d.ts +1 -2
- package/src/get_characters_character_id_wallet_transactions_ok.d.ts +38 -52
- package/src/get_contracts_public_bids_contract_id_ok.d.ts +13 -17
- package/src/get_contracts_public_items_contract_id_ok.d.ts +34 -47
- package/src/get_contracts_public_region_id_ok.d.ts +61 -77
- package/src/get_corporation_corporation_id_mining_extractions_ok.d.ts +24 -30
- package/src/get_corporation_corporation_id_mining_observers_observer_id_ok.d.ts +20 -29
- package/src/get_corporation_corporation_id_mining_observers_ok.d.ts +10 -13
- package/src/get_corporations_corporation_id_alliancehistory_ok.d.ts +17 -22
- package/src/get_corporations_corporation_id_assets_ok.d.ts +22 -32
- package/src/get_corporations_corporation_id_blueprints_ok.d.ts +26 -37
- package/src/get_corporations_corporation_id_bookmarks_folders_ok.d.ts +13 -17
- package/src/get_corporations_corporation_id_bookmarks_ok.d.ts +46 -62
- package/src/get_corporations_corporation_id_contacts_labels_ok.d.ts +9 -12
- package/src/get_corporations_corporation_id_contacts_ok.d.ts +19 -28
- package/src/get_corporations_corporation_id_containers_logs_ok.d.ts +31 -47
- package/src/get_corporations_corporation_id_contracts_contract_id_bids_ok.d.ts +17 -22
- package/src/get_corporations_corporation_id_contracts_contract_id_items_ok.d.ts +22 -32
- package/src/get_corporations_corporation_id_contracts_ok.d.ts +77 -97
- package/src/get_corporations_corporation_id_customs_offices_ok.d.ts +53 -67
- package/src/get_corporations_corporation_id_divisions_ok.d.ts +17 -22
- package/src/get_corporations_corporation_id_facilities_ok.d.ts +10 -17
- package/src/get_corporations_corporation_id_fw_stats_ok.d.ts +37 -47
- package/src/get_corporations_corporation_id_icons_ok.d.ts +13 -17
- package/src/get_corporations_corporation_id_industry_jobs_ok.d.ts +79 -107
- package/src/get_corporations_corporation_id_killmails_recent_ok.d.ts +9 -12
- package/src/get_corporations_corporation_id_medals_issued_ok.d.ts +21 -27
- package/src/get_corporations_corporation_id_medals_ok.d.ts +21 -27
- package/src/get_corporations_corporation_id_members_limit_ok.d.ts +1 -2
- package/src/get_corporations_corporation_id_members_ok.d.ts +2 -7
- package/src/get_corporations_corporation_id_members_titles_ok.d.ts +143 -146
- package/src/get_corporations_corporation_id_membertracking_ok.d.ts +26 -37
- package/src/get_corporations_corporation_id_ok.d.ts +57 -72
- package/src/get_corporations_corporation_id_orders_history_ok.d.ts +54 -72
- package/src/get_corporations_corporation_id_orders_ok.d.ts +54 -72
- package/src/get_corporations_corporation_id_roles_history_ok.d.ts +13 -17
- package/src/get_corporations_corporation_id_roles_ok.d.ts +5 -7
- package/src/get_corporations_corporation_id_shareholders_ok.d.ts +9 -12
- package/src/get_corporations_corporation_id_standings_ok.d.ts +9 -12
- package/src/get_corporations_corporation_id_starbases_ok.d.ts +26 -37
- package/src/get_corporations_corporation_id_starbases_starbase_id_ok.d.ts +34 -47
- package/src/get_corporations_corporation_id_structures_ok.d.ts +54 -72
- package/src/get_corporations_corporation_id_titles_ok.d.ts +9 -12
- package/src/get_corporations_corporation_id_wallets_division_journal_ok.d.ts +45 -57
- package/src/get_corporations_corporation_id_wallets_division_transactions_ok.d.ts +34 -47
- package/src/get_corporations_corporation_id_wallets_ok.d.ts +9 -12
- package/src/get_corporations_npccorps_ok.d.ts +2 -7
- package/src/get_dogma_attributes_attribute_id_ok.d.ts +41 -52
- package/src/get_dogma_attributes_ok.d.ts +2 -7
- package/src/get_dogma_dynamic_items_type_id_item_id_ok.d.ts +23 -37
- package/src/get_dogma_effects_effect_id_ok.d.ts +105 -132
- package/src/get_dogma_effects_ok.d.ts +2 -7
- package/src/get_fleets_fleet_id_members_ok.d.ts +34 -47
- package/src/get_fleets_fleet_id_ok.d.ts +17 -22
- package/src/get_fleets_fleet_id_wings_ok.d.ts +17 -22
- package/src/get_fw_leaderboards_characters_ok.d.ts +49 -62
- package/src/get_fw_leaderboards_corporations_ok.d.ts +49 -62
- package/src/get_fw_leaderboards_ok.d.ts +49 -62
- package/src/get_fw_stats_ok.d.ts +37 -47
- package/src/get_fw_systems_ok.d.ts +21 -27
- package/src/get_fw_wars_ok.d.ts +9 -12
- package/src/get_incursions_ok.d.ts +28 -43
- package/src/get_industry_facilities_ok.d.ts +22 -32
- package/src/get_industry_systems_ok.d.ts +9 -12
- package/src/get_insurance_prices_ok.d.ts +14 -22
- package/src/get_killmails_killmail_id_killmail_hash_ok.d.ts +127 -179
- package/src/get_loyalty_stores_corporation_id_offers_ok.d.ts +27 -42
- package/src/get_markets_groups_market_group_id_ok.d.ts +18 -33
- package/src/get_markets_groups_ok.d.ts +2 -7
- package/src/get_markets_prices_ok.d.ts +10 -17
- package/src/get_markets_region_id_history_ok.d.ts +25 -32
- package/src/get_markets_region_id_orders_ok.d.ts +42 -57
- package/src/get_markets_region_id_types_ok.d.ts +2 -7
- package/src/get_markets_structures_structure_id_ok.d.ts +38 -52
- package/src/get_opportunities_groups_group_id_ok.d.ts +29 -44
- package/src/get_opportunities_groups_ok.d.ts +2 -7
- package/src/get_opportunities_tasks_ok.d.ts +2 -7
- package/src/get_opportunities_tasks_task_id_ok.d.ts +17 -22
- package/src/get_route_origin_destination_ok.d.ts +2 -7
- package/src/get_sovereignty_campaigns_ok.d.ts +48 -59
- package/src/get_sovereignty_map_ok.d.ts +17 -22
- package/src/get_sovereignty_structures_ok.d.ts +31 -43
- package/src/get_status_ok.d.ts +17 -22
- package/src/get_universe_ancestries_ok.d.ts +25 -32
- package/src/get_universe_asteroid_belts_asteroid_belt_id_ok.d.ts +21 -27
- package/src/get_universe_bloodlines_ok.d.ts +42 -57
- package/src/get_universe_categories_category_id_ok.d.ts +19 -28
- package/src/get_universe_categories_ok.d.ts +2 -7
- package/src/get_universe_constellations_constellation_id_ok.d.ts +31 -43
- package/src/get_universe_constellations_ok.d.ts +2 -7
- package/src/get_universe_factions_ok.d.ts +41 -52
- package/src/get_universe_graphics_graphic_id_ok.d.ts +33 -42
- package/src/get_universe_graphics_ok.d.ts +2 -7
- package/src/get_universe_groups_group_id_ok.d.ts +18 -33
- package/src/get_universe_groups_ok.d.ts +2 -7
- package/src/get_universe_moons_moon_id_ok.d.ts +25 -32
- package/src/get_universe_planets_planet_id_ok.d.ts +26 -37
- package/src/get_universe_races_ok.d.ts +17 -22
- package/src/get_universe_regions_ok.d.ts +2 -7
- package/src/get_universe_regions_region_id_ok.d.ts +19 -28
- package/src/get_universe_schematics_schematic_id_ok.d.ts +9 -12
- package/src/get_universe_stargates_stargate_id_ok.d.ts +34 -47
- package/src/get_universe_stars_star_id_ok.d.ts +26 -37
- package/src/get_universe_stations_station_id_ok.d.ts +50 -67
- package/src/get_universe_structures_ok.d.ts +2 -7
- package/src/get_universe_structures_structure_id_ok.d.ts +26 -37
- package/src/get_universe_system_jumps_ok.d.ts +9 -12
- package/src/get_universe_system_kills_ok.d.ts +17 -22
- package/src/get_universe_systems_ok.d.ts +2 -7
- package/src/get_universe_systems_system_id_ok.d.ts +65 -96
- package/src/get_universe_types_ok.d.ts +2 -7
- package/src/get_universe_types_type_id_ok.d.ts +70 -92
- package/src/get_wars_ok.d.ts +2 -7
- package/src/get_wars_war_id_killmails_ok.d.ts +9 -12
- package/src/get_wars_war_id_ok.d.ts +69 -87
- package/src/index.d.ts +33 -8
- package/src/post_characters_affiliation_ok.d.ts +17 -22
- package/src/post_characters_character_id_assets_locations_ok.d.ts +17 -22
- package/src/post_characters_character_id_assets_names_ok.d.ts +9 -12
- package/src/post_characters_character_id_contacts_created.d.ts +2 -7
- package/src/post_characters_character_id_cspa_created.d.ts +1 -2
- package/src/post_characters_character_id_fittings_created.d.ts +5 -7
- package/src/post_characters_character_id_mail_created.d.ts +1 -2
- package/src/post_characters_character_id_mail_labels_created.d.ts +1 -2
- package/src/post_corporations_corporation_id_assets_locations_ok.d.ts +17 -22
- package/src/post_corporations_corporation_id_assets_names_ok.d.ts +9 -12
- package/src/post_fleets_fleet_id_members_invitation.d.ts +13 -17
- package/src/post_fleets_fleet_id_wings_created.d.ts +5 -7
- package/src/post_fleets_fleet_id_wings_wing_id_squads_created.d.ts +5 -7
- package/src/post_ui_openwindow_newmail_new_mail.d.ts +22 -28
- package/src/post_universe_ids_ok.d.ts +82 -237
- package/src/post_universe_names_ok.d.ts +9 -12
- package/src/put_characters_character_id_calendar_event_id_response.d.ts +1 -2
- package/src/put_characters_character_id_contacts_contact_ids.d.ts +6 -8
- package/src/put_characters_character_id_mail_mail_id_contents.d.ts +11 -18
- package/src/put_fleets_fleet_id_members_member_id_movement.d.ts +9 -12
- package/src/put_fleets_fleet_id_new_settings.d.ts +9 -12
- package/src/put_fleets_fleet_id_squads_squad_id_naming.d.ts +5 -7
- package/src/put_fleets_fleet_id_wings_wing_id_naming.d.ts +5 -7
- package/tsconfig.json +23 -0
- package/src/post_characters_character_id_contacts_contact_ids.d.ts +0 -18
- package/src/post_characters_character_id_cspa_characters.d.ts +0 -18
- package/src/post_characters_character_id_fittings_fitting.d.ts +0 -101
- package/src/post_characters_character_id_mail_labels_label.d.ts +0 -39
- package/src/post_characters_character_id_mail_mail.d.ts +0 -53
package/README.md
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
# eve-esi-types
|
|
2
|
-
|
|
1
|
+
# eve-esi-types (version 1)
|
|
2
|
+
|
|
3
|
+
Extracted the main type of ESI. Used for ESI request response types.
|
|
4
|
+
|
|
5
|
+
+ Version 1 makes it somewhat easier to handle types,
|
|
6
|
+
|
|
7
|
+
but as a trade-off, it does not support query parameter completion etc.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
> This package is configured to use version 1 only.
|
|
12
|
+
|
|
13
|
+
+ If you need to use version 2, please refer to the following link:
|
|
14
|
+
[eve-esi-types v2](https://github.com/jeffy-g/eve-esi-types)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
> Sample code is provided -> [`esi-request.mjs`](./esi-request.mjs)
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
$ node esi-request.mjs
|
|
21
|
+
```
|
|
22
|
+
## API
|
|
23
|
+
|
|
24
|
+
> The following function signature allows you to benefit from `eve-esi-types`.
|
|
25
|
+
> By specifying the method (`get`, `post`, `put`, `delete`) for each `endpoint`,
|
|
26
|
+
> you can determine the result type of the ESI request.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// function signature
|
|
30
|
+
export async function fire<
|
|
31
|
+
M extends TRequestMethod,
|
|
32
|
+
EP extends keyof TESIResponseOKMap[M],
|
|
33
|
+
Opt extends number | number[] | ESIRequestOptions,
|
|
34
|
+
R extends TESIResponseOKMap[M][EP]
|
|
35
|
+
>(
|
|
36
|
+
mthd: M, endp: EP, pathParams?: Opt, opt?: ESIRequestOptions
|
|
37
|
+
): Promise<R>;
|
|
38
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { TESIResponseOKMap } from "./src";
|
|
9
|
+
type TRequestMethod = "get" | "post" | "put" | "delete";
|
|
10
|
+
/**
|
|
11
|
+
* __{Header}.{Payload}.{Signature}__
|
|
12
|
+
*/
|
|
13
|
+
type TAcccessToken = `${string}.${string}.${string}`;
|
|
14
|
+
type ESIRequestOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* query params for ESI request.
|
|
17
|
+
*/
|
|
18
|
+
query?: Record<string, any>;
|
|
19
|
+
/**
|
|
20
|
+
* will need it for `POST` request etc.
|
|
21
|
+
*/
|
|
22
|
+
body?: any;
|
|
23
|
+
/**
|
|
24
|
+
* if want response data with ignore error then can be set to `true`.
|
|
25
|
+
*/
|
|
26
|
+
ignoreError?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* cancel request immediately
|
|
29
|
+
*/
|
|
30
|
+
cancelable?: AbortController;
|
|
31
|
+
/**
|
|
32
|
+
* Can be an empty object if no authentication is required.description
|
|
33
|
+
*/
|
|
34
|
+
token?: TAcccessToken;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* fire ESI request
|
|
38
|
+
* @template {"get" | "post" | "put" | "delete"} M
|
|
39
|
+
* @template {keyof TESIResponseOKMap[M]} EP
|
|
40
|
+
* @template {number | number[] | ESIRequestOptions} Opt
|
|
41
|
+
* @template {TESIResponseOKMap[M][EP]} R
|
|
42
|
+
*
|
|
43
|
+
* @param {M} mthd
|
|
44
|
+
* @param {EP} endp - The endpoint to request.
|
|
45
|
+
* @param {Opt} [pathParams] - Optional path parameters.
|
|
46
|
+
* @param {ESIRequestOptions} [opt] - default is empty object {}. `body` is json string
|
|
47
|
+
* @returns {Promise<R>} - The response from the endpoint.
|
|
48
|
+
* @throws
|
|
49
|
+
* @async
|
|
50
|
+
*/
|
|
51
|
+
export declare function fire<
|
|
52
|
+
M extends TRequestMethod,
|
|
53
|
+
EP extends keyof TESIResponseOKMap[M],
|
|
54
|
+
Opt extends number | number[] | ESIRequestOptions,
|
|
55
|
+
R extends TESIResponseOKMap[M][EP]
|
|
56
|
+
>(
|
|
57
|
+
mthd: M, endp: EP, pathParams?: Opt, opt?: ESIRequestOptions
|
|
58
|
+
): Promise<R>;
|
package/esi-request.mjs
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// import type { TESIResponseOKMap } from "eve-esi-types";
|
|
2
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
3
|
+
// constants, types
|
|
4
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
5
|
+
// shorthands
|
|
6
|
+
const log = console.log;
|
|
7
|
+
const isArray = Array.isArray;
|
|
8
|
+
/**
|
|
9
|
+
* enable/disable console.log
|
|
10
|
+
*/
|
|
11
|
+
let LOG = false;
|
|
12
|
+
/**
|
|
13
|
+
* this always `https://esi.evetech.net`
|
|
14
|
+
*/
|
|
15
|
+
const BASE = "https://esi.evetech.net";
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {import("./src").TESIResponseOKMap} TESIResponseOKMap
|
|
18
|
+
* @typedef {`${string}.${string}.${string}`} TAcccessToken __{Header}.{Payload}.{Signature}__
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @typedef ESIRequestOptions
|
|
22
|
+
* @prop {Record<string, any>} [query] query params for ESI request.
|
|
23
|
+
* @prop {any} [body] will need it for `POST` request etc.
|
|
24
|
+
* @prop {boolean} [ignoreError] if want response data with ignore error then can be set to `true`.
|
|
25
|
+
* @prop {AbortController} [cancelable] cancel request immediately
|
|
26
|
+
* @prop {TAcccessToken} [token] Can be an empty object if no authentication is required.description
|
|
27
|
+
*/
|
|
28
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
29
|
+
// module vars, functions
|
|
30
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
31
|
+
/**
|
|
32
|
+
* Get the number of currently executing ESI requests
|
|
33
|
+
*/
|
|
34
|
+
let ax = 0;
|
|
35
|
+
/**
|
|
36
|
+
* simple named error class.
|
|
37
|
+
*/
|
|
38
|
+
class ESIRequesError extends Error {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* throws when x-esi-error-limit-remain header value is "0". (http status: 420)
|
|
42
|
+
*/
|
|
43
|
+
class ESIErrorLimitReachedError extends Error {
|
|
44
|
+
constructor() {
|
|
45
|
+
super("Cannot continue ESI request because 'x-esi-error-limit-remain' is zero!");
|
|
46
|
+
}
|
|
47
|
+
valueOf() {
|
|
48
|
+
return 420;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* fetch the extra pages
|
|
53
|
+
*
|
|
54
|
+
* + if the `x-pages` header property ware more than 1
|
|
55
|
+
*
|
|
56
|
+
* @param {string} endpointUrl
|
|
57
|
+
* @param {RequestInit} rqopt request options
|
|
58
|
+
* @param {Record<string, any>} qs queries
|
|
59
|
+
* @param {number} pc pageCount
|
|
60
|
+
*/
|
|
61
|
+
const fetchP = async (endpointUrl, rqopt, qs, pc) => {
|
|
62
|
+
const rqs = [];
|
|
63
|
+
const rqp = new URLSearchParams(qs);
|
|
64
|
+
for (let i = 2; i <= pc;) {
|
|
65
|
+
rqp.set("page", (i++) + "");
|
|
66
|
+
ax++;
|
|
67
|
+
rqs.push(fetch(`${endpointUrl}?${rqp + ""}`, rqopt).then(res => res.json()).catch(reason => {
|
|
68
|
+
console.warn(reason);
|
|
69
|
+
return [];
|
|
70
|
+
}).finally(() => {
|
|
71
|
+
ax--;
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
return Promise.all(rqs).then(jsons => {
|
|
75
|
+
// DEVNOTE: let check the page 2, type is array?
|
|
76
|
+
if (isArray(jsons[0])) {
|
|
77
|
+
let combined = [];
|
|
78
|
+
for (let i = 0, end = jsons.length; i < end;) {
|
|
79
|
+
combined = combined.concat(jsons[i++]);
|
|
80
|
+
}
|
|
81
|
+
return combined;
|
|
82
|
+
}
|
|
83
|
+
LOG && log("> > > pages result are object < < < --", jsons);
|
|
84
|
+
return null;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/** ### replace (C)urly (B)races (T)oken
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* "/characters/{character_id}/skills"
|
|
91
|
+
* // ->
|
|
92
|
+
* "/characters/<char.character_id>/skills"
|
|
93
|
+
*
|
|
94
|
+
* @param {string} endpoint e.g - "/characters/{character_id}/"
|
|
95
|
+
* @param {number[]} ids
|
|
96
|
+
* @returns fragment of qualified endpoint uri or null.
|
|
97
|
+
*/
|
|
98
|
+
const replaceCbt = (endpoint, ids) => {
|
|
99
|
+
const re = /{([\w]+)}/g;
|
|
100
|
+
/** @type {RegExpExecArray?} */
|
|
101
|
+
let m;
|
|
102
|
+
let idx = 0;
|
|
103
|
+
while (m = re.exec(endpoint)) {
|
|
104
|
+
endpoint = endpoint.replace(m[0], ids[idx++] + "");
|
|
105
|
+
}
|
|
106
|
+
return endpoint;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
*
|
|
110
|
+
* @param {string} endp this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
|
|
111
|
+
* + The version parameter can be omitted by using `<version>/<endpoint>`
|
|
112
|
+
*/
|
|
113
|
+
const curl = (endp) => {
|
|
114
|
+
endp = endp.replace(/^\/+|\/+$/g, "");
|
|
115
|
+
return `${BASE}/latest/${endp}/`;
|
|
116
|
+
};
|
|
117
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
118
|
+
// main functions
|
|
119
|
+
// - - - - - - - - - - - - - - - - - - - -
|
|
120
|
+
/**
|
|
121
|
+
* fire ESI request
|
|
122
|
+
* @template {"get" | "post" | "put" | "delete"} M
|
|
123
|
+
* @template {keyof TESIResponseOKMap[M]} EP
|
|
124
|
+
* @template {number | number[] | ESIRequestOptions} Opt
|
|
125
|
+
* @template {TESIResponseOKMap[M][EP]} R
|
|
126
|
+
*
|
|
127
|
+
* @param {M} mthd
|
|
128
|
+
* @param {EP} endp - The endpoint to request.
|
|
129
|
+
* @param {Opt} [pathParams] - Optional path parameters.
|
|
130
|
+
* @param {ESIRequestOptions} [opt] - default is empty object {}. `body` is json string
|
|
131
|
+
* @returns {Promise<R>} - The response from the endpoint.
|
|
132
|
+
* @throws
|
|
133
|
+
* @async
|
|
134
|
+
*/
|
|
135
|
+
export async function fire(mthd, endp, pathParams, opt = {}) {
|
|
136
|
+
if (typeof pathParams === "number") {
|
|
137
|
+
// @ts-expect-error
|
|
138
|
+
pathParams = [pathParams];
|
|
139
|
+
}
|
|
140
|
+
if (isArray(pathParams)) {
|
|
141
|
+
// @ts-ignore actualy endp is string
|
|
142
|
+
endp = replaceCbt(endp, pathParams);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// When only options are provided
|
|
146
|
+
opt = /** @type {ESIRequestOptions} */ (pathParams) || opt;
|
|
147
|
+
}
|
|
148
|
+
/** @type {RequestInit} */
|
|
149
|
+
const rqopt = {
|
|
150
|
+
method: mthd,
|
|
151
|
+
mode: "cors",
|
|
152
|
+
cache: "no-cache",
|
|
153
|
+
signal: opt.cancelable?.signal,
|
|
154
|
+
headers: {}
|
|
155
|
+
};
|
|
156
|
+
const qss = {
|
|
157
|
+
// language: "en",
|
|
158
|
+
};
|
|
159
|
+
if (opt.query) {
|
|
160
|
+
// Object.assign(queries, options.queries); Object.assign is too slow
|
|
161
|
+
const oqs = opt.query;
|
|
162
|
+
for (const k of Object.keys(oqs)) {
|
|
163
|
+
qss[k] = oqs[k];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// DEVNOTE: when datasource is not empty string. (e.g - "singularity"
|
|
167
|
+
// in this case must specify datasource.
|
|
168
|
+
// disabled since `REMOVING DATASOURCE SINGULARITY`
|
|
169
|
+
// if (opt.datasource === "singularity") {
|
|
170
|
+
// opt.datasource = "tranquility";
|
|
171
|
+
// }
|
|
172
|
+
if (opt.token) {
|
|
173
|
+
// @ts-ignore The header is indeed an object
|
|
174
|
+
rqopt.headers.authorization = `Bearer ${opt.token}`;
|
|
175
|
+
}
|
|
176
|
+
if (opt.body) { // means "POST" method etc
|
|
177
|
+
// @ts-ignore The header is indeed an object
|
|
178
|
+
rqopt.headers["content-type"] = "application/json";
|
|
179
|
+
rqopt.body = JSON.stringify(opt.body);
|
|
180
|
+
}
|
|
181
|
+
// @ts-ignore actualy endp is string
|
|
182
|
+
const endpointUrl = curl(endp);
|
|
183
|
+
ax++;
|
|
184
|
+
try {
|
|
185
|
+
// @ts-ignore A silly type error will appear, but ignore it.
|
|
186
|
+
const res = await fetch(`${endpointUrl}?${new URLSearchParams(qss) + ""}`, rqopt).finally(() => {
|
|
187
|
+
ax--;
|
|
188
|
+
});
|
|
189
|
+
const stat = res.status;
|
|
190
|
+
if (!res.ok && !opt.ignoreError) {
|
|
191
|
+
if (stat === 420) {
|
|
192
|
+
opt.cancelable && opt.cancelable.abort();
|
|
193
|
+
throw new ESIErrorLimitReachedError();
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
// @ts-ignore actualy endp is string
|
|
197
|
+
throw new ESIRequesError(`maybe network disconneted or otherwise request data are invalid. (endpoint=${endp}, http status=${stat})`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
// DEVNOTE: - 204 No Content
|
|
202
|
+
if (stat === 204) {
|
|
203
|
+
// this result is empty, decided to return status code.
|
|
204
|
+
return /** @type {R} */ ({ status: stat });
|
|
205
|
+
}
|
|
206
|
+
/** @type {R} */
|
|
207
|
+
const data = await res.json();
|
|
208
|
+
if (opt.ignoreError) {
|
|
209
|
+
// meaning `forceJson`?
|
|
210
|
+
return data;
|
|
211
|
+
}
|
|
212
|
+
// - - - - x-pages response.
|
|
213
|
+
// +undefined is NaN
|
|
214
|
+
// @ts-ignore becouse +null is 0
|
|
215
|
+
const pc = +res.headers.get("x-pages");
|
|
216
|
+
// has remaining pages? NaN > 1 === false !isNaN(pageCount)
|
|
217
|
+
if (pc > 1) {
|
|
218
|
+
LOG && log('found "x-pages" header, pages: %d', pc);
|
|
219
|
+
const remData = await fetchP(endpointUrl, rqopt, qss, pc);
|
|
220
|
+
// finally, decide product data.
|
|
221
|
+
if (isArray(data) && isArray(remData)) {
|
|
222
|
+
// DEVNOTE: 2019/7/23 15:01:48 - types
|
|
223
|
+
return /** @type {R} */ (data.concat(remData));
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
// @ts-ignore TODO: fix type
|
|
227
|
+
remData && Object.assign(data, remData);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return data;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
// @ts-ignore actualy endp is string
|
|
235
|
+
throw new ESIRequesError(`unknown error occurred, message: ${e.message}, endpoint=${endp}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// It should complete correctly.
|
|
239
|
+
async function getEVEStatus() {
|
|
240
|
+
try {
|
|
241
|
+
const ok = await fire("get", "/characters/{character_id}/ship/", 994562, {
|
|
242
|
+
// This token is completely random, but a simple check can be done with type TAcccessToken
|
|
243
|
+
token: "eyJhbGciOiJIjoiSldUIn0.YDbHqu0xPwtK5eTER7aPl8I0oYC.YDbHqu0xPwtK5eTER7aPl8I0oYC"
|
|
244
|
+
});
|
|
245
|
+
// query patameter `filter` is optional
|
|
246
|
+
// Version 1 makes it somewhat easier to handle types,
|
|
247
|
+
// but as a trade-off, it does not support query parameter completion.
|
|
248
|
+
await fire("get", "/universe/structures/", {
|
|
249
|
+
query: {
|
|
250
|
+
filter: "market"
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
// in this case, "categories" and "search" is required
|
|
254
|
+
await fire("get", "/characters/{character_id}/search/", 994562, {
|
|
255
|
+
query: {
|
|
256
|
+
categories: ["agent"],
|
|
257
|
+
search: "ok"
|
|
258
|
+
},
|
|
259
|
+
token: "eyJhbGciOiJIjoiSldUIn0.YDbHqu0xPwtK5eTER7aPl8I0oYC.YDbHqu0xPwtK5eTER7aPl8I0oYC"
|
|
260
|
+
});
|
|
261
|
+
// in this case, "order_type" is required
|
|
262
|
+
await fire("get", "/markets/{region_id}/orders/", 994562, {
|
|
263
|
+
query: {
|
|
264
|
+
order_type: "all"
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
// TODO: want TypeScript semantics to throw an error because there is a required query parameter, but it's not possible
|
|
268
|
+
await fire("get", "/characters/{character_id}/search/");
|
|
269
|
+
console.log(ok);
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
console.error("Failed to get character ship -", error);
|
|
273
|
+
}
|
|
274
|
+
return fire("get", "/status/");
|
|
275
|
+
}
|
|
276
|
+
// type following and run
|
|
277
|
+
// node esi-request.mjs
|
|
278
|
+
// or yarn test
|
|
279
|
+
getEVEStatus().then(eveStatus => console.log(eveStatus));
|
|
280
|
+
// {
|
|
281
|
+
// "players": 16503,
|
|
282
|
+
// "server_version": "2794925",
|
|
283
|
+
// "start_time": "2025-01-21T11:02:34Z"
|
|
284
|
+
// }
|
package/package.json
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eve-esi-types",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Extracted the main type of ESI. use for ESI request response types",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Extracted the main type of ESI. use for ESI request response types (version 1 only)",
|
|
5
5
|
"main": "src/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "
|
|
7
|
+
"test": "node esi-request.mjs"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+ssh://git@github.com/jeffy-g/eve-esi-types.git"
|
|
12
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"esi-request.mjs",
|
|
16
|
+
"esi-request.d.mts",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"*.md",
|
|
19
|
+
"package.json",
|
|
20
|
+
"tsconfig.json"
|
|
21
|
+
],
|
|
13
22
|
"keywords": [
|
|
14
23
|
"eve",
|
|
15
24
|
"esi",
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
2
|
* ESI endpoint: /alliances/{alliance_id}/contacts/labels/
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* label_id integer
|
|
7
|
-
*/
|
|
8
|
-
type GetAlliancesAllianceIdContactsLabelsLabelId = number;
|
|
9
|
-
/**
|
|
10
|
-
* label_name string
|
|
11
|
-
*/
|
|
12
|
-
type GetAlliancesAllianceIdContactsLabelsLabelName = string;
|
|
13
4
|
/**
|
|
14
5
|
* 200 ok array
|
|
15
6
|
*
|
|
@@ -21,7 +12,13 @@ type GetAlliancesAllianceIdContactsLabelsOk = GetAlliancesAllianceIdContactsLabe
|
|
|
21
12
|
* 200 ok object
|
|
22
13
|
*/
|
|
23
14
|
interface GetAlliancesAllianceIdContactsLabels_200Ok {
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
/**
|
|
16
|
+
* label_id integer
|
|
17
|
+
*/
|
|
18
|
+
label_id: number;
|
|
19
|
+
/**
|
|
20
|
+
* label_name string
|
|
21
|
+
*/
|
|
22
|
+
label_name: string;
|
|
26
23
|
[k: string]: unknown | undefined;
|
|
27
24
|
}
|
|
@@ -1,29 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
2
|
* ESI endpoint: /alliances/{alliance_id}/contacts/
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* contact_id integer
|
|
7
|
-
*/
|
|
8
|
-
type GetAlliancesAllianceIdContactsContactId = number;
|
|
9
4
|
/**
|
|
10
5
|
* contact_type string
|
|
11
6
|
*/
|
|
12
7
|
type GetAlliancesAllianceIdContactsContactType = "character" | "corporation" | "alliance" | "faction";
|
|
13
|
-
/**
|
|
14
|
-
* Label IDs applied to the contact
|
|
15
|
-
*/
|
|
16
|
-
type GetAlliancesAllianceIdContactsLabelId = number;
|
|
17
|
-
/**
|
|
18
|
-
* label_ids array
|
|
19
|
-
*
|
|
20
|
-
* @maxItems 63
|
|
21
|
-
*/
|
|
22
|
-
type GetAlliancesAllianceIdContactsLabelIds = GetAlliancesAllianceIdContactsLabelId[];
|
|
23
|
-
/**
|
|
24
|
-
* Standing of the contact
|
|
25
|
-
*/
|
|
26
|
-
type GetAlliancesAllianceIdContactsStanding = number;
|
|
27
8
|
/**
|
|
28
9
|
* 200 ok array
|
|
29
10
|
*
|
|
@@ -35,9 +16,20 @@ type GetAlliancesAllianceIdContactsOk = GetAlliancesAllianceIdContacts_200Ok[];
|
|
|
35
16
|
* 200 ok object
|
|
36
17
|
*/
|
|
37
18
|
interface GetAlliancesAllianceIdContacts_200Ok {
|
|
38
|
-
|
|
19
|
+
/**
|
|
20
|
+
* contact_id integer
|
|
21
|
+
*/
|
|
22
|
+
contact_id: number;
|
|
39
23
|
contact_type: GetAlliancesAllianceIdContactsContactType;
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
/**
|
|
25
|
+
* label_ids array
|
|
26
|
+
*
|
|
27
|
+
* @maxItems 63
|
|
28
|
+
*/
|
|
29
|
+
label_ids?: number[];
|
|
30
|
+
/**
|
|
31
|
+
* Standing of the contact
|
|
32
|
+
*/
|
|
33
|
+
standing: number;
|
|
42
34
|
[k: string]: unknown | undefined;
|
|
43
35
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
2
|
* ESI endpoint: /alliances/{alliance_id}/corporations/
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 200 ok integer
|
|
7
|
-
*/
|
|
8
|
-
type GetAlliancesAllianceIdCorporations_200Ok = number;
|
|
9
4
|
/**
|
|
10
5
|
* 200 ok array
|
|
11
6
|
*
|
|
12
7
|
* @maxItems 1000
|
|
13
8
|
*/
|
|
14
|
-
type GetAlliancesAllianceIdCorporationsOk =
|
|
9
|
+
type GetAlliancesAllianceIdCorporationsOk = number[];
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
2
|
* ESI endpoint: /alliances/{alliance_id}/icons/
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* px128x128 string
|
|
7
|
-
*/
|
|
8
|
-
type GetAlliancesAllianceIdIconsPx128X128 = string;
|
|
9
|
-
/**
|
|
10
|
-
* px64x64 string
|
|
11
|
-
*/
|
|
12
|
-
type GetAlliancesAllianceIdIconsPx64X64 = string;
|
|
13
|
-
|
|
14
5
|
/**
|
|
15
6
|
* 200 ok object
|
|
16
7
|
*/
|
|
17
8
|
interface GetAlliancesAllianceIdIconsOk {
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
/**
|
|
10
|
+
* px128x128 string
|
|
11
|
+
*/
|
|
12
|
+
px128x128?: string;
|
|
13
|
+
/**
|
|
14
|
+
* px64x64 string
|
|
15
|
+
*/
|
|
16
|
+
px64x64?: string;
|
|
20
17
|
[k: string]: unknown | undefined;
|
|
21
18
|
}
|
|
@@ -1,46 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
2
|
* ESI endpoint: /alliances/{alliance_id}/
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* ID of the corporation that created the alliance
|
|
7
|
-
*/
|
|
8
|
-
type GetAlliancesAllianceIdCreatorCorporationId = number;
|
|
9
|
-
/**
|
|
10
|
-
* ID of the character that created the alliance
|
|
11
|
-
*/
|
|
12
|
-
type GetAlliancesAllianceIdCreatorId = number;
|
|
13
|
-
/**
|
|
14
|
-
* date_founded string
|
|
15
|
-
*/
|
|
16
|
-
type GetAlliancesAllianceIdDateFounded = string;
|
|
17
|
-
/**
|
|
18
|
-
* the executor corporation ID, if this alliance is not closed
|
|
19
|
-
*/
|
|
20
|
-
type GetAlliancesAllianceIdExecutorCorporationId = number;
|
|
21
|
-
/**
|
|
22
|
-
* Faction ID this alliance is fighting for, if this alliance is enlisted in factional warfare
|
|
23
|
-
*/
|
|
24
|
-
type GetAlliancesAllianceIdFactionId = number;
|
|
25
|
-
/**
|
|
26
|
-
* the full name of the alliance
|
|
27
|
-
*/
|
|
28
|
-
type GetAlliancesAllianceIdName = string;
|
|
29
|
-
/**
|
|
30
|
-
* the short name of the alliance
|
|
31
|
-
*/
|
|
32
|
-
type GetAlliancesAllianceIdTicker = string;
|
|
33
|
-
|
|
34
5
|
/**
|
|
35
6
|
* 200 ok object
|
|
36
7
|
*/
|
|
37
8
|
interface GetAlliancesAllianceIdOk {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
9
|
+
/**
|
|
10
|
+
* ID of the corporation that created the alliance
|
|
11
|
+
*/
|
|
12
|
+
creator_corporation_id: number;
|
|
13
|
+
/**
|
|
14
|
+
* ID of the character that created the alliance
|
|
15
|
+
*/
|
|
16
|
+
creator_id: number;
|
|
17
|
+
/**
|
|
18
|
+
* date_founded string
|
|
19
|
+
*/
|
|
20
|
+
date_founded: string;
|
|
21
|
+
/**
|
|
22
|
+
* the executor corporation ID, if this alliance is not closed
|
|
23
|
+
*/
|
|
24
|
+
executor_corporation_id?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Faction ID this alliance is fighting for, if this alliance is enlisted in factional warfare
|
|
27
|
+
*/
|
|
28
|
+
faction_id?: number;
|
|
29
|
+
/**
|
|
30
|
+
* the full name of the alliance
|
|
31
|
+
*/
|
|
32
|
+
name: string;
|
|
33
|
+
/**
|
|
34
|
+
* the short name of the alliance
|
|
35
|
+
*/
|
|
36
|
+
ticker: string;
|
|
45
37
|
[k: string]: unknown | undefined;
|
|
46
38
|
}
|