eve-esi-types 1.0.0 → 2.0.0-beta

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 (206) hide show
  1. package/README.md +11 -1
  2. package/esi-request.mjs +247 -0
  3. package/esi-request.mts +309 -0
  4. package/package.json +1 -1
  5. package/tsconfig.json +22 -0
  6. package/v2/get_alliances_alliance_id_contacts_labels_ok.d.ts +27 -0
  7. package/v2/get_alliances_alliance_id_contacts_ok.d.ts +43 -0
  8. package/v2/get_alliances_alliance_id_corporations_ok.d.ts +14 -0
  9. package/v2/get_alliances_alliance_id_icons_ok.d.ts +21 -0
  10. package/v2/get_alliances_alliance_id_ok.d.ts +46 -0
  11. package/v2/get_alliances_ok.d.ts +14 -0
  12. package/v2/get_characters_character_id_agents_research_ok.d.ts +42 -0
  13. package/v2/get_characters_character_id_assets_ok.d.ts +144 -0
  14. package/v2/get_characters_character_id_attributes_ok.d.ts +51 -0
  15. package/v2/get_characters_character_id_blueprints_ok.d.ts +133 -0
  16. package/v2/get_characters_character_id_bookmarks_folders_ok.d.ts +27 -0
  17. package/v2/get_characters_character_id_bookmarks_ok.d.ts +91 -0
  18. package/v2/get_characters_character_id_calendar_event_id_attendees_ok.d.ts +32 -0
  19. package/v2/get_characters_character_id_calendar_event_id_ok.d.ts +66 -0
  20. package/v2/get_characters_character_id_calendar_ok.d.ts +42 -0
  21. package/v2/get_characters_character_id_clones_ok.d.ts +82 -0
  22. package/v2/get_characters_character_id_contacts_labels_ok.d.ts +27 -0
  23. package/v2/get_characters_character_id_contacts_ok.d.ts +53 -0
  24. package/v2/get_characters_character_id_contracts_contract_id_bids_ok.d.ts +37 -0
  25. package/v2/get_characters_character_id_contracts_contract_id_items_ok.d.ts +48 -0
  26. package/v2/get_characters_character_id_contracts_ok.d.ts +137 -0
  27. package/v2/get_characters_character_id_corporationhistory_ok.d.ts +37 -0
  28. package/v2/get_characters_character_id_fatigue_ok.d.ts +26 -0
  29. package/v2/get_characters_character_id_fittings_ok.d.ts +108 -0
  30. package/v2/get_characters_character_id_fleet_ok.d.ts +35 -0
  31. package/v2/get_characters_character_id_fw_stats_ok.d.ts +75 -0
  32. package/v2/get_characters_character_id_implants_ok.d.ts +14 -0
  33. package/v2/get_characters_character_id_industry_jobs_ok.d.ts +133 -0
  34. package/v2/get_characters_character_id_killmails_recent_ok.d.ts +27 -0
  35. package/v2/get_characters_character_id_location_ok.d.ts +26 -0
  36. package/v2/get_characters_character_id_loyalty_points_ok.d.ts +27 -0
  37. package/v2/get_characters_character_id_mail_labels_ok.d.ts +67 -0
  38. package/v2/get_characters_character_id_mail_lists_ok.d.ts +27 -0
  39. package/v2/get_characters_character_id_mail_mail_id_ok.d.ts +71 -0
  40. package/v2/get_characters_character_id_mail_ok.d.ts +77 -0
  41. package/v2/get_characters_character_id_medals_ok.d.ts +147 -0
  42. package/v2/get_characters_character_id_mining_ok.d.ts +37 -0
  43. package/v2/get_characters_character_id_notifications_contacts_ok.d.ts +42 -0
  44. package/v2/get_characters_character_id_notifications_ok.d.ts +297 -0
  45. package/v2/get_characters_character_id_ok.d.ts +66 -0
  46. package/v2/get_characters_character_id_online_ok.d.ts +31 -0
  47. package/v2/get_characters_character_id_opportunities_ok.d.ts +27 -0
  48. package/v2/get_characters_character_id_orders_history_ok.d.ts +104 -0
  49. package/v2/get_characters_character_id_orders_ok.d.ts +99 -0
  50. package/v2/get_characters_character_id_planets_ok.d.ts +131 -0
  51. package/v2/get_characters_character_id_planets_planet_id_ok.d.ts +323 -0
  52. package/v2/get_characters_character_id_portrait_ok.d.ts +31 -0
  53. package/v2/get_characters_character_id_roles_ok.d.ts +271 -0
  54. package/v2/get_characters_character_id_search_ok.d.ts +132 -0
  55. package/v2/get_characters_character_id_ship_ok.d.ts +26 -0
  56. package/v2/get_characters_character_id_skillqueue_ok.d.ts +57 -0
  57. package/v2/get_characters_character_id_skills_ok.d.ts +54 -0
  58. package/v2/get_characters_character_id_standings_ok.d.ts +32 -0
  59. package/v2/get_characters_character_id_titles_ok.d.ts +187 -0
  60. package/v2/get_characters_character_id_wallet_journal_ok.d.ts +240 -0
  61. package/v2/get_characters_character_id_wallet_ok.d.ts +8 -0
  62. package/v2/get_characters_character_id_wallet_transactions_ok.d.ts +67 -0
  63. package/v2/get_contracts_public_bids_contract_id_ok.d.ts +32 -0
  64. package/v2/get_contracts_public_items_contract_id_ok.d.ts +62 -0
  65. package/v2/get_contracts_public_region_id_ok.d.ts +97 -0
  66. package/v2/get_corporation_corporation_id_mining_extractions_ok.d.ts +45 -0
  67. package/v2/get_corporation_corporation_id_mining_observers_observer_id_ok.d.ts +45 -0
  68. package/v2/get_corporation_corporation_id_mining_observers_ok.d.ts +33 -0
  69. package/v2/get_corporations_corporation_id_alliancehistory_ok.d.ts +37 -0
  70. package/v2/get_corporations_corporation_id_assets_ok.d.ts +180 -0
  71. package/v2/get_corporations_corporation_id_blueprints_ok.d.ts +174 -0
  72. package/v2/get_corporations_corporation_id_bookmarks_folders_ok.d.ts +32 -0
  73. package/v2/get_corporations_corporation_id_bookmarks_ok.d.ts +91 -0
  74. package/v2/get_corporations_corporation_id_contacts_labels_ok.d.ts +27 -0
  75. package/v2/get_corporations_corporation_id_contacts_ok.d.ts +48 -0
  76. package/v2/get_corporations_corporation_id_containers_logs_ok.d.ts +204 -0
  77. package/v2/get_corporations_corporation_id_contracts_contract_id_bids_ok.d.ts +38 -0
  78. package/v2/get_corporations_corporation_id_contracts_contract_id_items_ok.d.ts +48 -0
  79. package/v2/get_corporations_corporation_id_contracts_ok.d.ts +137 -0
  80. package/v2/get_corporations_corporation_id_customs_offices_ok.d.ts +92 -0
  81. package/v2/get_corporations_corporation_id_divisions_ok.d.ts +133 -0
  82. package/v2/get_corporations_corporation_id_facilities_ok.d.ts +32 -0
  83. package/v2/get_corporations_corporation_id_fw_stats_ok.d.ts +70 -0
  84. package/v2/get_corporations_corporation_id_icons_ok.d.ts +26 -0
  85. package/v2/get_corporations_corporation_id_industry_jobs_ok.d.ts +133 -0
  86. package/v2/get_corporations_corporation_id_killmails_recent_ok.d.ts +27 -0
  87. package/v2/get_corporations_corporation_id_medals_issued_ok.d.ts +47 -0
  88. package/v2/get_corporations_corporation_id_medals_ok.d.ts +42 -0
  89. package/v2/get_corporations_corporation_id_members_limit_ok.d.ts +8 -0
  90. package/v2/get_corporations_corporation_id_members_ok.d.ts +14 -0
  91. package/v2/get_corporations_corporation_id_members_titles_ok.d.ts +197 -0
  92. package/v2/get_corporations_corporation_id_membertracking_ok.d.ts +52 -0
  93. package/v2/get_corporations_corporation_id_ok.d.ts +81 -0
  94. package/v2/get_corporations_corporation_id_orders_history_ok.d.ts +109 -0
  95. package/v2/get_corporations_corporation_id_orders_ok.d.ts +104 -0
  96. package/v2/get_corporations_corporation_id_roles_history_ok.d.ts +175 -0
  97. package/v2/get_corporations_corporation_id_roles_ok.d.ts +545 -0
  98. package/v2/get_corporations_corporation_id_shareholders_ok.d.ts +32 -0
  99. package/v2/get_corporations_corporation_id_standings_ok.d.ts +32 -0
  100. package/v2/get_corporations_corporation_id_starbases_ok.d.ts +62 -0
  101. package/v2/get_corporations_corporation_id_starbases_starbase_id_ok.d.ts +369 -0
  102. package/v2/get_corporations_corporation_id_structures_ok.d.ts +194 -0
  103. package/v2/get_corporations_corporation_id_titles_ok.d.ts +715 -0
  104. package/v2/get_corporations_corporation_id_wallets_division_journal_ok.d.ts +241 -0
  105. package/v2/get_corporations_corporation_id_wallets_division_transactions_ok.d.ts +63 -0
  106. package/v2/get_corporations_corporation_id_wallets_ok.d.ts +65 -0
  107. package/v2/get_corporations_npccorps_ok.d.ts +14 -0
  108. package/v2/get_dogma_attributes_attribute_id_ok.d.ts +61 -0
  109. package/v2/get_dogma_attributes_ok.d.ts +14 -0
  110. package/v2/get_dogma_dynamic_items_type_id_item_id_ok.d.ts +72 -0
  111. package/v2/get_dogma_effects_effect_id_ok.d.ts +154 -0
  112. package/v2/get_dogma_effects_ok.d.ts +14 -0
  113. package/v2/get_fleets_fleet_id_members_ok.d.ts +67 -0
  114. package/v2/get_fleets_fleet_id_ok.d.ts +31 -0
  115. package/v2/get_fleets_fleet_id_wings_ok.d.ts +50 -0
  116. package/v2/get_fw_leaderboards_characters_ok.d.ts +163 -0
  117. package/v2/get_fw_leaderboards_corporations_ok.d.ts +589 -0
  118. package/v2/get_fw_leaderboards_ok.d.ts +235 -0
  119. package/v2/get_fw_stats_ok.d.ts +76 -0
  120. package/v2/get_fw_systems_ok.d.ts +47 -0
  121. package/v2/get_fw_wars_ok.d.ts +27 -0
  122. package/v2/get_incursions_ok.d.ts +63 -0
  123. package/v2/get_industry_facilities_ok.d.ts +47 -0
  124. package/v2/get_industry_systems_ok.d.ts +122 -0
  125. package/v2/get_insurance_prices_ok.d.ts +70 -0
  126. package/v2/get_killmails_killmail_id_killmail_hash_ok.d.ts +242 -0
  127. package/v2/get_loyalty_stores_corporation_id_offers_ok.d.ts +70 -0
  128. package/v2/get_markets_groups_market_group_id_ok.d.ts +42 -0
  129. package/v2/get_markets_groups_ok.d.ts +14 -0
  130. package/v2/get_markets_prices_ok.d.ts +32 -0
  131. package/v2/get_markets_region_id_history_ok.d.ts +47 -0
  132. package/v2/get_markets_region_id_orders_ok.d.ts +89 -0
  133. package/v2/get_markets_region_id_types_ok.d.ts +14 -0
  134. package/v2/get_markets_structures_structure_id_ok.d.ts +84 -0
  135. package/v2/get_opportunities_groups_group_id_ok.d.ts +53 -0
  136. package/v2/get_opportunities_groups_ok.d.ts +14 -0
  137. package/v2/get_opportunities_tasks_ok.d.ts +14 -0
  138. package/v2/get_opportunities_tasks_task_id_ok.d.ts +31 -0
  139. package/v2/get_route_origin_destination_ok.d.ts +14 -0
  140. package/v2/get_sovereignty_campaigns_ok.d.ts +94 -0
  141. package/v2/get_sovereignty_map_ok.d.ts +37 -0
  142. package/v2/get_sovereignty_structures_ok.d.ts +58 -0
  143. package/v2/get_status_ok.d.ts +31 -0
  144. package/v2/get_universe_ancestries_ok.d.ts +47 -0
  145. package/v2/get_universe_asteroid_belts_asteroid_belt_id_ok.d.ts +43 -0
  146. package/v2/get_universe_bloodlines_ok.d.ts +72 -0
  147. package/v2/get_universe_categories_category_id_ok.d.ts +37 -0
  148. package/v2/get_universe_categories_ok.d.ts +14 -0
  149. package/v2/get_universe_constellations_constellation_id_ok.d.ts +59 -0
  150. package/v2/get_universe_constellations_ok.d.ts +14 -0
  151. package/v2/get_universe_factions_ok.d.ts +67 -0
  152. package/v2/get_universe_graphics_graphic_id_ok.d.ts +51 -0
  153. package/v2/get_universe_graphics_ok.d.ts +14 -0
  154. package/v2/get_universe_groups_group_id_ok.d.ts +42 -0
  155. package/v2/get_universe_groups_ok.d.ts +14 -0
  156. package/v2/get_universe_moons_moon_id_ok.d.ts +48 -0
  157. package/v2/get_universe_planets_planet_id_ok.d.ts +53 -0
  158. package/v2/get_universe_races_ok.d.ts +57 -0
  159. package/v2/get_universe_regions_ok.d.ts +14 -0
  160. package/v2/get_universe_regions_region_id_ok.d.ts +37 -0
  161. package/v2/get_universe_schematics_schematic_id_ok.d.ts +21 -0
  162. package/v2/get_universe_stargates_stargate_id_ok.d.ts +70 -0
  163. package/v2/get_universe_stars_star_id_ok.d.ts +140 -0
  164. package/v2/get_universe_stations_station_id_ok.d.ts +121 -0
  165. package/v2/get_universe_structures_ok.d.ts +14 -0
  166. package/v2/get_universe_structures_structure_id_ok.d.ts +54 -0
  167. package/v2/get_universe_system_jumps_ok.d.ts +27 -0
  168. package/v2/get_universe_system_kills_ok.d.ts +37 -0
  169. package/v2/get_universe_systems_ok.d.ts +14 -0
  170. package/v2/get_universe_systems_system_id_ok.d.ts +125 -0
  171. package/v2/get_universe_types_ok.d.ts +14 -0
  172. package/v2/get_universe_types_type_id_ok.d.ts +127 -0
  173. package/v2/get_wars_ok.d.ts +14 -0
  174. package/v2/get_wars_war_id_killmails_ok.d.ts +27 -0
  175. package/v2/get_wars_war_id_ok.d.ts +123 -0
  176. package/v2/index.d.ts +1043 -0
  177. package/v2/post_characters_affiliation_ok.d.ts +37 -0
  178. package/v2/post_characters_character_id_assets_locations_ok.d.ts +44 -0
  179. package/v2/post_characters_character_id_assets_names_ok.d.ts +27 -0
  180. package/v2/post_characters_character_id_contacts_contact_ids.d.ts +18 -0
  181. package/v2/post_characters_character_id_contacts_created.d.ts +14 -0
  182. package/v2/post_characters_character_id_cspa_characters.d.ts +18 -0
  183. package/v2/post_characters_character_id_cspa_created.d.ts +8 -0
  184. package/v2/post_characters_character_id_fittings_created.d.ts +16 -0
  185. package/v2/post_characters_character_id_fittings_fitting.d.ts +101 -0
  186. package/v2/post_characters_character_id_mail_created.d.ts +8 -0
  187. package/v2/post_characters_character_id_mail_labels_created.d.ts +8 -0
  188. package/v2/post_characters_character_id_mail_labels_label.d.ts +39 -0
  189. package/v2/post_characters_character_id_mail_mail.d.ts +53 -0
  190. package/v2/post_corporations_corporation_id_assets_locations_ok.d.ts +44 -0
  191. package/v2/post_corporations_corporation_id_assets_names_ok.d.ts +27 -0
  192. package/v2/post_fleets_fleet_id_members_invitation.d.ts +31 -0
  193. package/v2/post_fleets_fleet_id_wings_created.d.ts +16 -0
  194. package/v2/post_fleets_fleet_id_wings_wing_id_squads_created.d.ts +16 -0
  195. package/v2/post_ui_openwindow_newmail_new_mail.d.ts +46 -0
  196. package/v2/post_universe_ids_ok.d.ts +241 -0
  197. package/v2/post_universe_names_ok.d.ts +41 -0
  198. package/v2/put_characters_character_id_calendar_event_id_response.d.ts +16 -0
  199. package/v2/put_characters_character_id_contacts_contact_ids.d.ts +18 -0
  200. package/v2/put_characters_character_id_mail_mail_id_contents.d.ts +27 -0
  201. package/v2/put_fleets_fleet_id_members_member_id_movement.d.ts +30 -0
  202. package/v2/put_fleets_fleet_id_new_settings.d.ts +21 -0
  203. package/v2/put_fleets_fleet_id_squads_squad_id_naming.d.ts +16 -0
  204. package/v2/put_fleets_fleet_id_wings_wing_id_naming.d.ts +16 -0
  205. package/v2.mjs +253 -0
  206. package/v2.mts +316 -0
package/v2.mts ADDED
@@ -0,0 +1,316 @@
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
+ // - - - - - - - - - - - - - - - - - - - -
9
+ // imports
10
+ // - - - - - - - - - - - - - - - - - - - -
11
+ import type { TESIResponseOKMap } from "./v2";
12
+ // import type { TESIResponseOKMap } from "eve-esi-types";
13
+
14
+
15
+ // - - - - - - - - - - - - - - - - - - - -
16
+ // constants, types
17
+ // - - - - - - - - - - - - - - - - - - - -
18
+ // shorthands
19
+ const log = console.log;
20
+ const isArray = Array.isArray;
21
+ /**
22
+ * enable/disable console.log
23
+ */
24
+ let LOG = false;
25
+ /**
26
+ * this always `https://esi.evetech.net`
27
+ */
28
+ const BASE = "https://esi.evetech.net";
29
+
30
+
31
+ type ESIRequestOptions = {
32
+ /**
33
+ * query params for ESI request.
34
+ */
35
+ queries?: Record<string, any>;
36
+ /**
37
+ * will need it for `POST` request etc.
38
+ */
39
+ body?: any;
40
+ /**
41
+ * if want response data with ignore error then can be set to `true`.
42
+ */
43
+ ignoreError?: boolean;
44
+ /**
45
+ * cancel request immediately
46
+ */
47
+ cancelable?: AbortController;
48
+
49
+ /**
50
+ * Can be an empty object if no authentication is required.description
51
+ */
52
+ token?: string;
53
+
54
+ auth?: true;
55
+ };
56
+ /**
57
+ * @typedef {import("./v2").TESIResponseOKMap} TESIResponseOKMap
58
+ */
59
+ /**
60
+ * @typedef ESIRequestOptions
61
+ * @prop {Record<string, any>} [queries] query params for ESI request.
62
+ * @prop {any} [body] will need it for `POST` request etc.
63
+ * @prop {boolean} [ignoreError] if want response data with ignore error then can be set to `true`.
64
+ * @prop {AbortController} [cancelable] cancel request immediately
65
+ * @prop {string} [token] Can be an empty object if no authentication is required.description
66
+ * @prop {true=} [auth] Can be an empty object if no authentication is required.description
67
+ */
68
+
69
+
70
+ // - - - - - - - - - - - - - - - - - - - -
71
+ // module vars, functions
72
+ // - - - - - - - - - - - - - - - - - - - -
73
+ /**
74
+ * Get the number of currently executing ESI requests
75
+ */
76
+ let ax: number = 0;
77
+ /**
78
+ * simple named error class.
79
+ */
80
+ class ESIRequesError extends Error {}
81
+ /**
82
+ * throws when x-esi-error-limit-remain header value is "0". (http status: 420)
83
+ */
84
+ class ESIErrorLimitReachedError extends Error {
85
+ constructor() {
86
+ super("Cannot continue ESI request because 'x-esi-error-limit-remain' is zero!");
87
+ }
88
+ valueOf(): number {
89
+ return 420;
90
+ }
91
+ }
92
+ /**
93
+ * fetch the extra pages
94
+ *
95
+ * + if the `x-pages` header property ware more than 1
96
+ *
97
+ * @param {string} endpointUrl
98
+ * @param {RequestInit} rqopt request options
99
+ * @param {Record<string, any>} qs queries
100
+ * @param {number} pc pageCount
101
+ */
102
+ const fetchP = async <T extends any>(endpointUrl: string, rqopt: RequestInit, qs: Record<string, any>, pc: number) => {
103
+ const rqs: Promise<T>[] = [];
104
+ const rqp = new URLSearchParams(qs);
105
+ for (let i = 2; i <= pc; ) {
106
+ rqp.set("page", (i++) + "");
107
+ ax++;
108
+ rqs.push(
109
+ fetch(`${endpointUrl}?${rqp + ""}`, rqopt).then(
110
+ res => res.json()
111
+ ).catch(reason => {
112
+ console.warn(reason);
113
+ return [] as T;
114
+ }).finally(() => {
115
+ ax--;
116
+ })
117
+ );
118
+ }
119
+ return Promise.all(rqs).then(jsons => {
120
+ // DEVNOTE: let check the page 2, type is array?
121
+ if (isArray(jsons[0])) {
122
+ let combined: any[] = [];
123
+ for (let i = 0, end = jsons.length; i < end;) {
124
+ combined = combined.concat(jsons[i++]);
125
+ }
126
+ return combined as T;
127
+ }
128
+
129
+ LOG && log("> > > pages result are object < < < --", jsons);
130
+ return null;
131
+ });
132
+ };
133
+
134
+ /** ### replace (C)urly (B)races (T)oken
135
+ *
136
+ * @example
137
+ * "/characters/{character_id}/skills"
138
+ * // ->
139
+ * "/characters/<char.character_id>/skills"
140
+ *
141
+ * @param {string} endpoint e.g - "/characters/{character_id}/"
142
+ * @param {number[]} ids
143
+ * @returns fragment of qualified endpoint uri or null.
144
+ */
145
+ const replaceCbt = (endpoint: string, ids: number[]) => {
146
+ const re = /{([\w]+)}/g;
147
+ /** @type {RegExpExecArray?} */
148
+ let m: RegExpExecArray | null;
149
+ let idx = 0
150
+ while (m = re.exec(endpoint)) {
151
+ endpoint = endpoint.replace(m[0], ids[idx++] + "");
152
+ }
153
+ return endpoint;
154
+ };
155
+ /**
156
+ *
157
+ * @param {string} endp this means endpoint url fragment like `/characters/{character_id}/` or `/characters/{character_id}/agents_research/`
158
+ * + The version parameter can be omitted by using `<version>/<endpoint>`
159
+ */
160
+ const curl = (endp: string) => {
161
+ endp = endp.replace(/^\/+|\/+$/g, "");
162
+ return `${BASE}/latest/${endp}/`;
163
+ };
164
+
165
+
166
+ // - - - - - - - - - - - - - - - - - - - -
167
+ // main functions
168
+ // - - - - - - - - - - - - - - - - - - - -
169
+ // It should complete correctly.
170
+ async function getEVEStatus() {
171
+ try {
172
+ const ok = await fire("get", "/characters/{character_id}/ship/", 994562, { auth: true, token: "<accessToken of 994562>" });
173
+ } catch (error) {
174
+ console.error("Failed to get character ship -", error);
175
+ }
176
+ return fire("get", "/status/");
177
+ }
178
+ /**
179
+ * fire ESI request
180
+ * @template {TESIEntryMethod} M
181
+ * @template {keyof TESIResponseOKMap[M]} EP
182
+ * @template {IdentifyParameters<TESIResponseOKMap[M][EP] & { result: any }, ESIRequestOptions>} Opt
183
+ * @template {TESIResponseOKMap[M][EP] extends { result: infer U } ? U : never} R
184
+ *
185
+ * @param {M} mthd
186
+ * @param {EP} endp - The endpoint to request.
187
+ * @param {number | number[] | Opt} [pathParams] - Optional path parameters.
188
+ * @param {Opt} [opt] - default is empty object {}. `body` is json string
189
+ * @returns {Promise<R>} - The response from the endpoint.
190
+ * @throws
191
+ * @async
192
+ */
193
+ export async function fire<
194
+ M extends TESIEntryMethod,
195
+ EP extends keyof TESIResponseOKMap[M],
196
+ Opt extends IdentifyParameters<TESIResponseOKMap[M][EP] & { result: any }, ESIRequestOptions>,
197
+ R extends TESIResponseOKMap[M][EP] extends { result: infer U } ? U : never
198
+ >(
199
+ mthd: M, endp: EP, pathParams?: number | number[] | Opt,
200
+ opt?: Opt
201
+ ): Promise<R> {
202
+
203
+ if (typeof pathParams === "number") {
204
+ pathParams = /** @type {number[]} */([pathParams]);
205
+ }
206
+ if (isArray(pathParams)) {
207
+ // @ts-ignore actualy endp is string
208
+ endp = replaceCbt(endp, pathParams) as EP;
209
+ }
210
+ if (!opt) {
211
+ // When only options are provided
212
+ opt = /** @type {Opt} */(pathParams) as Opt || opt || {};
213
+ }
214
+
215
+ /** @type {RequestInit} */
216
+ const rqopt: RequestInit = {
217
+ method: mthd,
218
+ mode: "cors",
219
+ cache: "no-cache",
220
+ signal: opt.cancelable?.signal,
221
+ headers: {}
222
+ };
223
+ const qss: Record<string, string> = {
224
+ // language: "en",
225
+ };
226
+
227
+ if (opt.queries) {
228
+ // Object.assign(queries, options.queries); Object.assign is too slow
229
+ const oqs = opt.queries;
230
+ for (const k of Object.keys(oqs)) {
231
+ qss[k] = oqs[k] as string;
232
+ }
233
+ }
234
+ // DEVNOTE: when datasource is not empty string. (e.g - "singularity"
235
+ // in this case must specify datasource.
236
+ // disabled since `REMOVING DATASOURCE SINGULARITY`
237
+ // if (opt.datasource === "singularity") {
238
+ // opt.datasource = "tranquility";
239
+ // }
240
+ if (opt.auth) {
241
+ // @ts-ignore The header is indeed an object
242
+ (rqopt.headers as any).authorization = `Bearer ${opt.token}`;
243
+ }
244
+ if (opt.body) { // means "POST" method etc
245
+ // @ts-ignore The header is indeed an object
246
+ (rqopt.headers as any)["content-type"] = "application/json";
247
+ rqopt.body = JSON.stringify(opt.body);
248
+ }
249
+
250
+ // @ts-ignore actualy endp is string
251
+ const endpointUrl = curl(endp);
252
+ ax++;
253
+ try {
254
+ // @ts-ignore A silly type error will appear, but ignore it.
255
+ const res = await fetch(
256
+ `${endpointUrl}?${new URLSearchParams(qss) + ""}`, rqopt
257
+ ).finally(() => {
258
+ ax--;
259
+ });
260
+
261
+ const stat = res.status;
262
+ if (!res.ok && !opt.ignoreError) {
263
+ if (stat === 420) {
264
+ opt.cancelable && opt.cancelable.abort();
265
+ throw new ESIErrorLimitReachedError();
266
+ } else {
267
+ // console.log(res);
268
+ throw new ESIRequesError(`${res.statusText} (status=${stat})`);
269
+ }
270
+ } else {
271
+ // DEVNOTE: - 204 No Content
272
+ if (stat === 204) {
273
+ // this result is empty, decided to return status code.
274
+ return /** @type {R} */({ status: stat }) as unknown as R;
275
+ }
276
+
277
+ /** @type {R} */
278
+ const data: R = await res.json();
279
+ if (opt.ignoreError) {
280
+ // meaning `forceJson`?
281
+ return data;
282
+ }
283
+ // - - - - x-pages response.
284
+ // +undefined is NaN
285
+ // @ts-ignore becouse +null is 0
286
+ const pc = +res.headers.get("x-pages")!;
287
+ // has remaining pages? NaN > 1 === false !isNaN(pageCount)
288
+ if (pc > 1) {
289
+ LOG && log('found "x-pages" header, pages: %d', pc);
290
+ const remData = await fetchP<R>(endpointUrl, rqopt, qss, pc);
291
+ // finally, decide product data.
292
+ if (isArray(data) && isArray(remData)) {
293
+ // DEVNOTE: 2019/7/23 15:01:48 - types
294
+ return /** @type {R} */(data.concat(remData)) as unknown as R;
295
+ } else {
296
+ // @ts-ignore TODO: fix type
297
+ remData && Object.assign(data, remData);
298
+ }
299
+ }
300
+
301
+ return data;
302
+ }
303
+
304
+ } catch (e) {
305
+ // @ts-ignore actualy endp is string
306
+ throw new ESIRequesError(`message: ${(e as Error).message}, endpoint=${endp}`);
307
+ }
308
+ }
309
+
310
+ // node v2.mjs
311
+ getEVEStatus().then(eveStatus => console.log(eveStatus));
312
+ // {
313
+ // "players": 16503,
314
+ // "server_version": "2794925",
315
+ // "start_time": "2025-01-21T11:02:34Z"
316
+ // }