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.
Files changed (204) hide show
  1. package/README.md +38 -2
  2. package/esi-request.d.mts +58 -0
  3. package/esi-request.mjs +284 -0
  4. package/package.json +12 -3
  5. package/src/get_alliances_alliance_id_contacts_labels_ok.d.ts +9 -12
  6. package/src/get_alliances_alliance_id_contacts_ok.d.ts +15 -23
  7. package/src/get_alliances_alliance_id_corporations_ok.d.ts +2 -7
  8. package/src/get_alliances_alliance_id_icons_ok.d.ts +9 -12
  9. package/src/get_alliances_alliance_id_ok.d.ts +29 -37
  10. package/src/get_alliances_ok.d.ts +2 -7
  11. package/src/get_characters_character_id_agents_research_ok.d.ts +18 -27
  12. package/src/get_characters_character_id_assets_ok.d.ts +22 -32
  13. package/src/get_characters_character_id_attributes_ok.d.ts +33 -42
  14. package/src/get_characters_character_id_blueprints_ok.d.ts +26 -37
  15. package/src/get_characters_character_id_bookmarks_folders_ok.d.ts +9 -12
  16. package/src/get_characters_character_id_bookmarks_ok.d.ts +46 -62
  17. package/src/get_characters_character_id_calendar_event_id_attendees_ok.d.ts +5 -7
  18. package/src/get_characters_character_id_calendar_event_id_ok.d.ts +37 -47
  19. package/src/get_characters_character_id_calendar_ok.d.ts +17 -22
  20. package/src/get_characters_character_id_clones_ok.d.ts +31 -43
  21. package/src/get_characters_character_id_contacts_labels_ok.d.ts +9 -12
  22. package/src/get_characters_character_id_contacts_ok.d.ts +23 -33
  23. package/src/get_characters_character_id_contracts_contract_id_bids_ok.d.ts +17 -22
  24. package/src/get_characters_character_id_contracts_contract_id_items_ok.d.ts +22 -32
  25. package/src/get_characters_character_id_contracts_ok.d.ts +77 -97
  26. package/src/get_characters_character_id_corporationhistory_ok.d.ts +17 -22
  27. package/src/get_characters_character_id_fatigue_ok.d.ts +13 -17
  28. package/src/get_characters_character_id_fittings_ok.d.ts +19 -32
  29. package/src/get_characters_character_id_fleet_ok.d.ts +13 -17
  30. package/src/get_characters_character_id_fw_stats_ok.d.ts +41 -52
  31. package/src/get_characters_character_id_implants_ok.d.ts +2 -7
  32. package/src/get_characters_character_id_industry_jobs_ok.d.ts +79 -107
  33. package/src/get_characters_character_id_killmails_recent_ok.d.ts +9 -12
  34. package/src/get_characters_character_id_location_ok.d.ts +13 -17
  35. package/src/get_characters_character_id_loyalty_points_ok.d.ts +9 -12
  36. package/src/get_characters_character_id_mail_labels_ok.d.ts +17 -22
  37. package/src/get_characters_character_id_mail_lists_ok.d.ts +9 -12
  38. package/src/get_characters_character_id_mail_mail_id_ok.d.ts +31 -43
  39. package/src/get_characters_character_id_mail_ok.d.ts +31 -43
  40. package/src/get_characters_character_id_medals_ok.d.ts +45 -57
  41. package/src/get_characters_character_id_mining_ok.d.ts +14 -22
  42. package/src/get_characters_character_id_notifications_contacts_ok.d.ts +21 -27
  43. package/src/get_characters_character_id_notifications_ok.d.ts +21 -27
  44. package/src/get_characters_character_id_ok.d.ts +41 -52
  45. package/src/get_characters_character_id_online_ok.d.ts +17 -22
  46. package/src/get_characters_character_id_opportunities_ok.d.ts +9 -12
  47. package/src/get_characters_character_id_orders_history_ok.d.ts +50 -67
  48. package/src/get_characters_character_id_orders_ok.d.ts +50 -67
  49. package/src/get_characters_character_id_planets_ok.d.ts +25 -32
  50. package/src/get_characters_character_id_planets_planet_id_ok.d.ts +110 -150
  51. package/src/get_characters_character_id_portrait_ok.d.ts +17 -22
  52. package/src/get_characters_character_id_roles_ok.d.ts +1 -2
  53. package/src/get_characters_character_id_search_ok.d.ts +62 -123
  54. package/src/get_characters_character_id_ship_ok.d.ts +10 -17
  55. package/src/get_characters_character_id_skillqueue_ok.d.ts +33 -42
  56. package/src/get_characters_character_id_skills_ok.d.ts +25 -32
  57. package/src/get_characters_character_id_standings_ok.d.ts +9 -12
  58. package/src/get_characters_character_id_titles_ok.d.ts +9 -12
  59. package/src/get_characters_character_id_wallet_journal_ok.d.ts +45 -57
  60. package/src/get_characters_character_id_wallet_ok.d.ts +1 -2
  61. package/src/get_characters_character_id_wallet_transactions_ok.d.ts +38 -52
  62. package/src/get_contracts_public_bids_contract_id_ok.d.ts +13 -17
  63. package/src/get_contracts_public_items_contract_id_ok.d.ts +34 -47
  64. package/src/get_contracts_public_region_id_ok.d.ts +61 -77
  65. package/src/get_corporation_corporation_id_mining_extractions_ok.d.ts +24 -30
  66. package/src/get_corporation_corporation_id_mining_observers_observer_id_ok.d.ts +20 -29
  67. package/src/get_corporation_corporation_id_mining_observers_ok.d.ts +10 -13
  68. package/src/get_corporations_corporation_id_alliancehistory_ok.d.ts +17 -22
  69. package/src/get_corporations_corporation_id_assets_ok.d.ts +22 -32
  70. package/src/get_corporations_corporation_id_blueprints_ok.d.ts +26 -37
  71. package/src/get_corporations_corporation_id_bookmarks_folders_ok.d.ts +13 -17
  72. package/src/get_corporations_corporation_id_bookmarks_ok.d.ts +46 -62
  73. package/src/get_corporations_corporation_id_contacts_labels_ok.d.ts +9 -12
  74. package/src/get_corporations_corporation_id_contacts_ok.d.ts +19 -28
  75. package/src/get_corporations_corporation_id_containers_logs_ok.d.ts +31 -47
  76. package/src/get_corporations_corporation_id_contracts_contract_id_bids_ok.d.ts +17 -22
  77. package/src/get_corporations_corporation_id_contracts_contract_id_items_ok.d.ts +22 -32
  78. package/src/get_corporations_corporation_id_contracts_ok.d.ts +77 -97
  79. package/src/get_corporations_corporation_id_customs_offices_ok.d.ts +53 -67
  80. package/src/get_corporations_corporation_id_divisions_ok.d.ts +17 -22
  81. package/src/get_corporations_corporation_id_facilities_ok.d.ts +10 -17
  82. package/src/get_corporations_corporation_id_fw_stats_ok.d.ts +37 -47
  83. package/src/get_corporations_corporation_id_icons_ok.d.ts +13 -17
  84. package/src/get_corporations_corporation_id_industry_jobs_ok.d.ts +79 -107
  85. package/src/get_corporations_corporation_id_killmails_recent_ok.d.ts +9 -12
  86. package/src/get_corporations_corporation_id_medals_issued_ok.d.ts +21 -27
  87. package/src/get_corporations_corporation_id_medals_ok.d.ts +21 -27
  88. package/src/get_corporations_corporation_id_members_limit_ok.d.ts +1 -2
  89. package/src/get_corporations_corporation_id_members_ok.d.ts +2 -7
  90. package/src/get_corporations_corporation_id_members_titles_ok.d.ts +143 -146
  91. package/src/get_corporations_corporation_id_membertracking_ok.d.ts +26 -37
  92. package/src/get_corporations_corporation_id_ok.d.ts +57 -72
  93. package/src/get_corporations_corporation_id_orders_history_ok.d.ts +54 -72
  94. package/src/get_corporations_corporation_id_orders_ok.d.ts +54 -72
  95. package/src/get_corporations_corporation_id_roles_history_ok.d.ts +13 -17
  96. package/src/get_corporations_corporation_id_roles_ok.d.ts +5 -7
  97. package/src/get_corporations_corporation_id_shareholders_ok.d.ts +9 -12
  98. package/src/get_corporations_corporation_id_standings_ok.d.ts +9 -12
  99. package/src/get_corporations_corporation_id_starbases_ok.d.ts +26 -37
  100. package/src/get_corporations_corporation_id_starbases_starbase_id_ok.d.ts +34 -47
  101. package/src/get_corporations_corporation_id_structures_ok.d.ts +54 -72
  102. package/src/get_corporations_corporation_id_titles_ok.d.ts +9 -12
  103. package/src/get_corporations_corporation_id_wallets_division_journal_ok.d.ts +45 -57
  104. package/src/get_corporations_corporation_id_wallets_division_transactions_ok.d.ts +34 -47
  105. package/src/get_corporations_corporation_id_wallets_ok.d.ts +9 -12
  106. package/src/get_corporations_npccorps_ok.d.ts +2 -7
  107. package/src/get_dogma_attributes_attribute_id_ok.d.ts +41 -52
  108. package/src/get_dogma_attributes_ok.d.ts +2 -7
  109. package/src/get_dogma_dynamic_items_type_id_item_id_ok.d.ts +23 -37
  110. package/src/get_dogma_effects_effect_id_ok.d.ts +105 -132
  111. package/src/get_dogma_effects_ok.d.ts +2 -7
  112. package/src/get_fleets_fleet_id_members_ok.d.ts +34 -47
  113. package/src/get_fleets_fleet_id_ok.d.ts +17 -22
  114. package/src/get_fleets_fleet_id_wings_ok.d.ts +17 -22
  115. package/src/get_fw_leaderboards_characters_ok.d.ts +49 -62
  116. package/src/get_fw_leaderboards_corporations_ok.d.ts +49 -62
  117. package/src/get_fw_leaderboards_ok.d.ts +49 -62
  118. package/src/get_fw_stats_ok.d.ts +37 -47
  119. package/src/get_fw_systems_ok.d.ts +21 -27
  120. package/src/get_fw_wars_ok.d.ts +9 -12
  121. package/src/get_incursions_ok.d.ts +28 -43
  122. package/src/get_industry_facilities_ok.d.ts +22 -32
  123. package/src/get_industry_systems_ok.d.ts +9 -12
  124. package/src/get_insurance_prices_ok.d.ts +14 -22
  125. package/src/get_killmails_killmail_id_killmail_hash_ok.d.ts +127 -179
  126. package/src/get_loyalty_stores_corporation_id_offers_ok.d.ts +27 -42
  127. package/src/get_markets_groups_market_group_id_ok.d.ts +18 -33
  128. package/src/get_markets_groups_ok.d.ts +2 -7
  129. package/src/get_markets_prices_ok.d.ts +10 -17
  130. package/src/get_markets_region_id_history_ok.d.ts +25 -32
  131. package/src/get_markets_region_id_orders_ok.d.ts +42 -57
  132. package/src/get_markets_region_id_types_ok.d.ts +2 -7
  133. package/src/get_markets_structures_structure_id_ok.d.ts +38 -52
  134. package/src/get_opportunities_groups_group_id_ok.d.ts +29 -44
  135. package/src/get_opportunities_groups_ok.d.ts +2 -7
  136. package/src/get_opportunities_tasks_ok.d.ts +2 -7
  137. package/src/get_opportunities_tasks_task_id_ok.d.ts +17 -22
  138. package/src/get_route_origin_destination_ok.d.ts +2 -7
  139. package/src/get_sovereignty_campaigns_ok.d.ts +48 -59
  140. package/src/get_sovereignty_map_ok.d.ts +17 -22
  141. package/src/get_sovereignty_structures_ok.d.ts +31 -43
  142. package/src/get_status_ok.d.ts +17 -22
  143. package/src/get_universe_ancestries_ok.d.ts +25 -32
  144. package/src/get_universe_asteroid_belts_asteroid_belt_id_ok.d.ts +21 -27
  145. package/src/get_universe_bloodlines_ok.d.ts +42 -57
  146. package/src/get_universe_categories_category_id_ok.d.ts +19 -28
  147. package/src/get_universe_categories_ok.d.ts +2 -7
  148. package/src/get_universe_constellations_constellation_id_ok.d.ts +31 -43
  149. package/src/get_universe_constellations_ok.d.ts +2 -7
  150. package/src/get_universe_factions_ok.d.ts +41 -52
  151. package/src/get_universe_graphics_graphic_id_ok.d.ts +33 -42
  152. package/src/get_universe_graphics_ok.d.ts +2 -7
  153. package/src/get_universe_groups_group_id_ok.d.ts +18 -33
  154. package/src/get_universe_groups_ok.d.ts +2 -7
  155. package/src/get_universe_moons_moon_id_ok.d.ts +25 -32
  156. package/src/get_universe_planets_planet_id_ok.d.ts +26 -37
  157. package/src/get_universe_races_ok.d.ts +17 -22
  158. package/src/get_universe_regions_ok.d.ts +2 -7
  159. package/src/get_universe_regions_region_id_ok.d.ts +19 -28
  160. package/src/get_universe_schematics_schematic_id_ok.d.ts +9 -12
  161. package/src/get_universe_stargates_stargate_id_ok.d.ts +34 -47
  162. package/src/get_universe_stars_star_id_ok.d.ts +26 -37
  163. package/src/get_universe_stations_station_id_ok.d.ts +50 -67
  164. package/src/get_universe_structures_ok.d.ts +2 -7
  165. package/src/get_universe_structures_structure_id_ok.d.ts +26 -37
  166. package/src/get_universe_system_jumps_ok.d.ts +9 -12
  167. package/src/get_universe_system_kills_ok.d.ts +17 -22
  168. package/src/get_universe_systems_ok.d.ts +2 -7
  169. package/src/get_universe_systems_system_id_ok.d.ts +65 -96
  170. package/src/get_universe_types_ok.d.ts +2 -7
  171. package/src/get_universe_types_type_id_ok.d.ts +70 -92
  172. package/src/get_wars_ok.d.ts +2 -7
  173. package/src/get_wars_war_id_killmails_ok.d.ts +9 -12
  174. package/src/get_wars_war_id_ok.d.ts +69 -87
  175. package/src/index.d.ts +33 -8
  176. package/src/post_characters_affiliation_ok.d.ts +17 -22
  177. package/src/post_characters_character_id_assets_locations_ok.d.ts +17 -22
  178. package/src/post_characters_character_id_assets_names_ok.d.ts +9 -12
  179. package/src/post_characters_character_id_contacts_created.d.ts +2 -7
  180. package/src/post_characters_character_id_cspa_created.d.ts +1 -2
  181. package/src/post_characters_character_id_fittings_created.d.ts +5 -7
  182. package/src/post_characters_character_id_mail_created.d.ts +1 -2
  183. package/src/post_characters_character_id_mail_labels_created.d.ts +1 -2
  184. package/src/post_corporations_corporation_id_assets_locations_ok.d.ts +17 -22
  185. package/src/post_corporations_corporation_id_assets_names_ok.d.ts +9 -12
  186. package/src/post_fleets_fleet_id_members_invitation.d.ts +13 -17
  187. package/src/post_fleets_fleet_id_wings_created.d.ts +5 -7
  188. package/src/post_fleets_fleet_id_wings_wing_id_squads_created.d.ts +5 -7
  189. package/src/post_ui_openwindow_newmail_new_mail.d.ts +22 -28
  190. package/src/post_universe_ids_ok.d.ts +82 -237
  191. package/src/post_universe_names_ok.d.ts +9 -12
  192. package/src/put_characters_character_id_calendar_event_id_response.d.ts +1 -2
  193. package/src/put_characters_character_id_contacts_contact_ids.d.ts +6 -8
  194. package/src/put_characters_character_id_mail_mail_id_contents.d.ts +11 -18
  195. package/src/put_fleets_fleet_id_members_member_id_movement.d.ts +9 -12
  196. package/src/put_fleets_fleet_id_new_settings.d.ts +9 -12
  197. package/src/put_fleets_fleet_id_squads_squad_id_naming.d.ts +5 -7
  198. package/src/put_fleets_fleet_id_wings_wing_id_naming.d.ts +5 -7
  199. package/tsconfig.json +23 -0
  200. package/src/post_characters_character_id_contacts_contact_ids.d.ts +0 -18
  201. package/src/post_characters_character_id_cspa_characters.d.ts +0 -18
  202. package/src/post_characters_character_id_fittings_fitting.d.ts +0 -101
  203. package/src/post_characters_character_id_mail_labels_label.d.ts +0 -39
  204. 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
- Extracted the main type of ESI. use for ESI request response types
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>;
@@ -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.0.0",
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": "echo ok?"
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
- label_id: GetAlliancesAllianceIdContactsLabelsLabelId;
25
- label_name: GetAlliancesAllianceIdContactsLabelsLabelName;
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
- contact_id: GetAlliancesAllianceIdContactsContactId;
19
+ /**
20
+ * contact_id integer
21
+ */
22
+ contact_id: number;
39
23
  contact_type: GetAlliancesAllianceIdContactsContactType;
40
- label_ids?: GetAlliancesAllianceIdContactsLabelIds;
41
- standing: GetAlliancesAllianceIdContactsStanding;
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 = GetAlliancesAllianceIdCorporations_200Ok[];
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
- px128x128?: GetAlliancesAllianceIdIconsPx128X128;
19
- px64x64?: GetAlliancesAllianceIdIconsPx64X64;
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
- creator_corporation_id: GetAlliancesAllianceIdCreatorCorporationId;
39
- creator_id: GetAlliancesAllianceIdCreatorId;
40
- date_founded: GetAlliancesAllianceIdDateFounded;
41
- executor_corporation_id?: GetAlliancesAllianceIdExecutorCorporationId;
42
- faction_id?: GetAlliancesAllianceIdFactionId;
43
- name: GetAlliancesAllianceIdName;
44
- ticker: GetAlliancesAllianceIdTicker;
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
  }
@@ -1,14 +1,9 @@
1
- /**
1
+ /*!
2
2
  * ESI endpoint: /alliances/
3
3
  */
4
-
5
- /**
6
- * 200 ok integer
7
- */
8
- type GetAlliances_200Ok = number;
9
4
  /**
10
5
  * 200 ok array
11
6
  *
12
7
  * @maxItems 5000
13
8
  */
14
- type GetAlliancesOk = GetAlliances_200Ok[];
9
+ type GetAlliancesOk = number[];