@lgriffin/esi.ts 7.4.0 → 9.0.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 (348) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +100 -24
  3. package/dist/EsiClient.d.ts +3 -0
  4. package/dist/EsiClient.d.ts.map +1 -1
  5. package/dist/EsiClientBuilder.d.ts +1 -0
  6. package/dist/EsiClientBuilder.d.ts.map +1 -1
  7. package/dist/clients/AllianceClient.d.ts +3 -0
  8. package/dist/clients/AllianceClient.d.ts.map +1 -1
  9. package/dist/clients/BaseEsiClient.d.ts +1 -1
  10. package/dist/clients/BaseEsiClient.d.ts.map +1 -1
  11. package/dist/clients/CalendarClient.d.ts +3 -0
  12. package/dist/clients/CalendarClient.d.ts.map +1 -1
  13. package/dist/clients/CharacterClient.d.ts +10 -2
  14. package/dist/clients/CharacterClient.d.ts.map +1 -1
  15. package/dist/clients/ClonesClient.d.ts +2 -0
  16. package/dist/clients/ClonesClient.d.ts.map +1 -1
  17. package/dist/clients/ContactsClient.d.ts +7 -0
  18. package/dist/clients/ContactsClient.d.ts.map +1 -1
  19. package/dist/clients/CorporationsClient.d.ts +18 -0
  20. package/dist/clients/CorporationsClient.d.ts.map +1 -1
  21. package/dist/clients/FittingsClient.d.ts +2 -0
  22. package/dist/clients/FittingsClient.d.ts.map +1 -1
  23. package/dist/clients/FleetClient.d.ts +3 -0
  24. package/dist/clients/FleetClient.d.ts.map +1 -1
  25. package/dist/clients/IndustryClient.d.ts +9 -0
  26. package/dist/clients/IndustryClient.d.ts.map +1 -1
  27. package/dist/clients/LoyaltyClient.d.ts +3 -0
  28. package/dist/clients/LoyaltyClient.d.ts.map +1 -1
  29. package/dist/clients/MailClient.d.ts +6 -0
  30. package/dist/clients/MailClient.d.ts.map +1 -1
  31. package/dist/clients/MarketClient.d.ts +13 -22
  32. package/dist/clients/MarketClient.d.ts.map +1 -1
  33. package/dist/clients/PiClient.d.ts +3 -0
  34. package/dist/clients/PiClient.d.ts.map +1 -1
  35. package/dist/clients/SkillsClient.d.ts +2 -0
  36. package/dist/clients/SkillsClient.d.ts.map +1 -1
  37. package/dist/clients/WalletClient.d.ts +1 -0
  38. package/dist/clients/WalletClient.d.ts.map +1 -1
  39. package/dist/clients/WarsClient.d.ts +3 -0
  40. package/dist/clients/WarsClient.d.ts.map +1 -1
  41. package/dist/config/jest/globalSetup.d.ts.map +1 -1
  42. package/dist/config/jest/globalTeardown.d.ts.map +1 -1
  43. package/dist/core/ApiClient.d.ts +14 -6
  44. package/dist/core/ApiClient.d.ts.map +1 -1
  45. package/dist/core/ApiRequestHandler.d.ts +3 -11
  46. package/dist/core/ApiRequestHandler.d.ts.map +1 -1
  47. package/dist/core/IDeduplicator.d.ts +6 -0
  48. package/dist/core/IDeduplicator.d.ts.map +1 -0
  49. package/dist/core/IRetryStrategy.d.ts +5 -0
  50. package/dist/core/IRetryStrategy.d.ts.map +1 -0
  51. package/dist/core/RequestDeduplicator.d.ts +2 -1
  52. package/dist/core/RequestDeduplicator.d.ts.map +1 -1
  53. package/dist/core/RetryStrategy.d.ts +19 -0
  54. package/dist/core/RetryStrategy.d.ts.map +1 -0
  55. package/dist/core/circuitBreaker/CircuitBreaker.d.ts +11 -1
  56. package/dist/core/circuitBreaker/CircuitBreaker.d.ts.map +1 -1
  57. package/dist/core/circuitBreaker/ICircuitBreaker.d.ts +23 -0
  58. package/dist/core/circuitBreaker/ICircuitBreaker.d.ts.map +1 -0
  59. package/dist/core/configureApiClient.d.ts +18 -0
  60. package/dist/core/configureApiClient.d.ts.map +1 -0
  61. package/dist/core/endpoints/EndpointDefinition.d.ts +2 -0
  62. package/dist/core/endpoints/EndpointDefinition.d.ts.map +1 -1
  63. package/dist/core/endpoints/calendarEndpoints.d.ts +1 -1
  64. package/dist/core/endpoints/characterEndpoints.d.ts +3 -3
  65. package/dist/core/endpoints/contactEndpoints.d.ts +7 -3
  66. package/dist/core/endpoints/contactEndpoints.d.ts.map +1 -1
  67. package/dist/core/endpoints/corporationEndpoints.d.ts +4 -1
  68. package/dist/core/endpoints/corporationEndpoints.d.ts.map +1 -1
  69. package/dist/core/endpoints/createClient.d.ts +18 -1
  70. package/dist/core/endpoints/createClient.d.ts.map +1 -1
  71. package/dist/core/endpoints/dogmaEndpoints.d.ts +17 -0
  72. package/dist/core/endpoints/dogmaEndpoints.d.ts.map +1 -1
  73. package/dist/core/endpoints/esi-scopes.generated.d.ts +1 -1
  74. package/dist/core/endpoints/esi-scopes.generated.d.ts.map +1 -1
  75. package/dist/core/endpoints/fleetEndpoints.d.ts +5 -0
  76. package/dist/core/endpoints/fleetEndpoints.d.ts.map +1 -1
  77. package/dist/core/endpoints/mailEndpoints.d.ts +13 -0
  78. package/dist/core/endpoints/mailEndpoints.d.ts.map +1 -1
  79. package/dist/core/endpoints/marketEndpoints.d.ts +29 -48
  80. package/dist/core/endpoints/marketEndpoints.d.ts.map +1 -1
  81. package/dist/core/endpoints/piEndpoints.d.ts +3 -0
  82. package/dist/core/endpoints/piEndpoints.d.ts.map +1 -1
  83. package/dist/core/endpoints/universeEndpoints.d.ts +13 -2
  84. package/dist/core/endpoints/universeEndpoints.d.ts.map +1 -1
  85. package/dist/core/endpoints/walletEndpoints.d.ts +4 -0
  86. package/dist/core/endpoints/walletEndpoints.d.ts.map +1 -1
  87. package/dist/core/logger/logger.d.ts +2 -1
  88. package/dist/core/logger/logger.d.ts.map +1 -1
  89. package/dist/core/pagination/AsyncPaginationIterator.d.ts +4 -1
  90. package/dist/core/pagination/AsyncPaginationIterator.d.ts.map +1 -1
  91. package/dist/core/pagination/CursorPaginationHandler.d.ts +15 -6
  92. package/dist/core/pagination/CursorPaginationHandler.d.ts.map +1 -1
  93. package/dist/core/pagination/PaginationHandler.d.ts +7 -6
  94. package/dist/core/pagination/PaginationHandler.d.ts.map +1 -1
  95. package/dist/core/rateLimiter/RateLimiter.d.ts +8 -2
  96. package/dist/core/rateLimiter/RateLimiter.d.ts.map +1 -1
  97. package/dist/core/requestPipeline/cachePolicy.d.ts +31 -0
  98. package/dist/core/requestPipeline/cachePolicy.d.ts.map +1 -0
  99. package/dist/core/requestPipeline/dependencies.d.ts +10 -0
  100. package/dist/core/requestPipeline/dependencies.d.ts.map +1 -0
  101. package/dist/core/requestPipeline/fetchExecution.d.ts +28 -0
  102. package/dist/core/requestPipeline/fetchExecution.d.ts.map +1 -0
  103. package/dist/core/requestPipeline/headers.d.ts +11 -0
  104. package/dist/core/requestPipeline/headers.d.ts.map +1 -0
  105. package/dist/core/requestPipeline/index.d.ts +10 -0
  106. package/dist/core/requestPipeline/index.d.ts.map +1 -0
  107. package/dist/core/requestPipeline/middlewareBridge.d.ts +15 -0
  108. package/dist/core/requestPipeline/middlewareBridge.d.ts.map +1 -0
  109. package/dist/core/requestPipeline/paginationOrchestration.d.ts +15 -0
  110. package/dist/core/requestPipeline/paginationOrchestration.d.ts.map +1 -0
  111. package/dist/core/requestPipeline/statusHandling.d.ts +18 -0
  112. package/dist/core/requestPipeline/statusHandling.d.ts.map +1 -0
  113. package/dist/core/util/error.d.ts +6 -1
  114. package/dist/core/util/error.d.ts.map +1 -1
  115. package/dist/errors.d.ts +4 -0
  116. package/dist/errors.d.ts.map +1 -0
  117. package/dist/errors.js +196 -0
  118. package/dist/errors.js.map +1 -0
  119. package/dist/errors.mjs +146 -0
  120. package/dist/errors.mjs.map +1 -0
  121. package/dist/index.d.ts +9 -2
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +9937 -176
  124. package/dist/index.js.map +1 -0
  125. package/dist/index.mjs +9834 -0
  126. package/dist/index.mjs.map +1 -0
  127. package/dist/schemas/calendar.d.ts +1 -1
  128. package/dist/schemas/character.d.ts +1 -10
  129. package/dist/schemas/character.d.ts.map +1 -1
  130. package/dist/schemas/common.d.ts +9 -0
  131. package/dist/schemas/common.d.ts.map +1 -1
  132. package/dist/schemas/contacts.d.ts +2 -1
  133. package/dist/schemas/contacts.d.ts.map +1 -1
  134. package/dist/schemas/corporation.d.ts +4 -9
  135. package/dist/schemas/corporation.d.ts.map +1 -1
  136. package/dist/schemas/dogma.d.ts +17 -0
  137. package/dist/schemas/dogma.d.ts.map +1 -1
  138. package/dist/schemas/fleet.d.ts +1 -0
  139. package/dist/schemas/fleet.d.ts.map +1 -1
  140. package/dist/schemas/index.js +2085 -46
  141. package/dist/schemas/index.js.map +1 -0
  142. package/dist/schemas/index.mjs +1914 -0
  143. package/dist/schemas/index.mjs.map +1 -0
  144. package/dist/schemas/market.d.ts +91 -4
  145. package/dist/schemas/market.d.ts.map +1 -1
  146. package/dist/schemas/pi.d.ts +3 -0
  147. package/dist/schemas/pi.d.ts.map +1 -1
  148. package/dist/schemas/sovereignty.d.ts +2 -0
  149. package/dist/schemas/sovereignty.d.ts.map +1 -1
  150. package/dist/schemas/universe.d.ts +11 -2
  151. package/dist/schemas/universe.d.ts.map +1 -1
  152. package/dist/schemas/wallet.d.ts +2 -0
  153. package/dist/schemas/wallet.d.ts.map +1 -1
  154. package/dist/testing/TestDataFactory.d.ts.map +1 -1
  155. package/dist/testing/index.d.ts +2 -0
  156. package/dist/testing/index.d.ts.map +1 -0
  157. package/dist/testing/index.js +935 -0
  158. package/dist/testing/index.js.map +1 -0
  159. package/dist/testing/index.mjs +898 -0
  160. package/dist/testing/index.mjs.map +1 -0
  161. package/dist/types/character.d.ts +2 -1
  162. package/dist/types/character.d.ts.map +1 -1
  163. package/dist/types/generated/esi-spec.generated.d.ts +3 -3
  164. package/dist/types/generated/esi-spec.generated.d.ts.map +1 -1
  165. package/dist/types/generated/spec-alignment.check.d.ts +9 -0
  166. package/dist/types/generated/spec-alignment.check.d.ts.map +1 -1
  167. package/dist/types/market.d.ts +7 -1
  168. package/dist/types/market.d.ts.map +1 -1
  169. package/package.json +33 -6
  170. package/dist/EsiClient.js +0 -251
  171. package/dist/EsiClientBuilder.js +0 -217
  172. package/dist/clients/AccessListsClient.js +0 -20
  173. package/dist/clients/AllianceClient.js +0 -72
  174. package/dist/clients/AssetsClient.js +0 -81
  175. package/dist/clients/BaseEsiClient.js +0 -40
  176. package/dist/clients/CalendarClient.js +0 -54
  177. package/dist/clients/CharacterClient.js +0 -149
  178. package/dist/clients/ClonesClient.js +0 -31
  179. package/dist/clients/ContactsClient.js +0 -104
  180. package/dist/clients/ContractsClient.js +0 -111
  181. package/dist/clients/CorporationsClient.js +0 -227
  182. package/dist/clients/DogmaClient.js +0 -55
  183. package/dist/clients/FactionClient.js +0 -79
  184. package/dist/clients/FittingsClient.js +0 -42
  185. package/dist/clients/FleetClient.js +0 -162
  186. package/dist/clients/FreelanceJobsClient.js +0 -76
  187. package/dist/clients/IncursionsClient.js +0 -19
  188. package/dist/clients/IndustryClient.js +0 -88
  189. package/dist/clients/InsuranceClient.js +0 -19
  190. package/dist/clients/KillmailsClient.js +0 -47
  191. package/dist/clients/LocationClient.js +0 -41
  192. package/dist/clients/LoyaltyClient.js +0 -30
  193. package/dist/clients/MailClient.js +0 -108
  194. package/dist/clients/MarketClient.js +0 -131
  195. package/dist/clients/MercenaryClient.js +0 -27
  196. package/dist/clients/MetaClient.js +0 -56
  197. package/dist/clients/PiClient.js +0 -51
  198. package/dist/clients/RouteClient.js +0 -24
  199. package/dist/clients/SearchClient.js +0 -22
  200. package/dist/clients/SkillsClient.js +0 -41
  201. package/dist/clients/SkyhooksClient.js +0 -35
  202. package/dist/clients/SovereigntyClient.js +0 -27
  203. package/dist/clients/StatusClient.js +0 -19
  204. package/dist/clients/UiClient.js +0 -58
  205. package/dist/clients/UniverseClient.js +0 -277
  206. package/dist/clients/WalletClient.js +0 -82
  207. package/dist/clients/WarsClient.js +0 -37
  208. package/dist/config/configManager.js +0 -47
  209. package/dist/config/jest/globalSetup.js +0 -7
  210. package/dist/config/jest/globalTeardown.js +0 -7
  211. package/dist/config/jest/jest.setup.js +0 -29
  212. package/dist/core/ApiClient.js +0 -123
  213. package/dist/core/ApiClientBuilder.js +0 -54
  214. package/dist/core/ApiRequestHandler.js +0 -444
  215. package/dist/core/BatchRequestHandler.js +0 -66
  216. package/dist/core/ClientRegistry.js +0 -116
  217. package/dist/core/EsiDiagnostics.js +0 -47
  218. package/dist/core/RequestDeduplicator.js +0 -26
  219. package/dist/core/cache/ETagCacheManager.js +0 -184
  220. package/dist/core/cache/ICache.js +0 -2
  221. package/dist/core/circuitBreaker/CircuitBreaker.js +0 -156
  222. package/dist/core/constants.js +0 -7
  223. package/dist/core/endpoints/EndpointDefinition.js +0 -2
  224. package/dist/core/endpoints/accessListEndpoints.js +0 -13
  225. package/dist/core/endpoints/allianceEndpoints.js +0 -34
  226. package/dist/core/endpoints/assetEndpoints.js +0 -51
  227. package/dist/core/endpoints/buildEndpointPath.js +0 -44
  228. package/dist/core/endpoints/calendarEndpoints.js +0 -35
  229. package/dist/core/endpoints/characterEndpoints.js +0 -104
  230. package/dist/core/endpoints/cloneEndpoints.js +0 -21
  231. package/dist/core/endpoints/contactEndpoints.js +0 -72
  232. package/dist/core/endpoints/contractEndpoints.js +0 -70
  233. package/dist/core/endpoints/corporationEndpoints.js +0 -161
  234. package/dist/core/endpoints/createClient.js +0 -175
  235. package/dist/core/endpoints/dogmaEndpoints.js +0 -40
  236. package/dist/core/endpoints/esi-cache-ttls.generated.js +0 -133
  237. package/dist/core/endpoints/esi-rate-limit-groups.generated.js +0 -153
  238. package/dist/core/endpoints/esi-scopes.generated.js +0 -135
  239. package/dist/core/endpoints/factionEndpoints.js +0 -57
  240. package/dist/core/endpoints/fittingEndpoints.js +0 -27
  241. package/dist/core/endpoints/fleetEndpoints.js +0 -101
  242. package/dist/core/endpoints/freelanceJobsEndpoints.js +0 -51
  243. package/dist/core/endpoints/incursionEndpoints.js +0 -13
  244. package/dist/core/endpoints/industryEndpoints.js +0 -61
  245. package/dist/core/endpoints/insuranceEndpoints.js +0 -13
  246. package/dist/core/endpoints/killmailEndpoints.js +0 -28
  247. package/dist/core/endpoints/locationEndpoints.js +0 -27
  248. package/dist/core/endpoints/loyaltyEndpoints.js +0 -21
  249. package/dist/core/endpoints/mailEndpoints.js +0 -68
  250. package/dist/core/endpoints/marketEndpoints.js +0 -84
  251. package/dist/core/endpoints/mercenaryEndpoints.js +0 -19
  252. package/dist/core/endpoints/metaEndpoints.js +0 -12
  253. package/dist/core/endpoints/piEndpoints.js +0 -36
  254. package/dist/core/endpoints/routeEndpoints.js +0 -14
  255. package/dist/core/endpoints/searchEndpoints.js +0 -14
  256. package/dist/core/endpoints/skillEndpoints.js +0 -29
  257. package/dist/core/endpoints/skyhookEndpoints.js +0 -25
  258. package/dist/core/endpoints/sovereigntyEndpoints.js +0 -19
  259. package/dist/core/endpoints/statusEndpoints.js +0 -12
  260. package/dist/core/endpoints/uiEndpoints.js +0 -39
  261. package/dist/core/endpoints/universeEndpoints.js +0 -210
  262. package/dist/core/endpoints/walletEndpoints.js +0 -50
  263. package/dist/core/endpoints/warEndpoints.js +0 -28
  264. package/dist/core/logger/ILogger.js +0 -2
  265. package/dist/core/logger/logger.js +0 -16
  266. package/dist/core/logger/loggerUtil.js +0 -30
  267. package/dist/core/middleware/Middleware.js +0 -42
  268. package/dist/core/pagination/AsyncPaginationIterator.js +0 -27
  269. package/dist/core/pagination/CursorPaginationHandler.js +0 -148
  270. package/dist/core/pagination/PaginationHandler.js +0 -115
  271. package/dist/core/rateLimiter/IRateLimiter.js +0 -2
  272. package/dist/core/rateLimiter/RateLimiter.js +0 -307
  273. package/dist/core/util/error.js +0 -122
  274. package/dist/core/util/headersUtil.js +0 -37
  275. package/dist/core/util/retry.js +0 -9
  276. package/dist/core/util/sleep.js +0 -6
  277. package/dist/core/util/stringUtil.js +0 -6
  278. package/dist/core/util/testHelpers.js +0 -9
  279. package/dist/core/util/validation.js +0 -52
  280. package/dist/schemas/access-lists.js +0 -14
  281. package/dist/schemas/alliance.js +0 -28
  282. package/dist/schemas/assets.js +0 -26
  283. package/dist/schemas/calendar.js +0 -43
  284. package/dist/schemas/character.js +0 -122
  285. package/dist/schemas/clones.js +0 -21
  286. package/dist/schemas/common.js +0 -34
  287. package/dist/schemas/contacts.js +0 -15
  288. package/dist/schemas/contracts.js +0 -58
  289. package/dist/schemas/corporation.js +0 -192
  290. package/dist/schemas/dogma.js +0 -42
  291. package/dist/schemas/faction-warfare.js +0 -92
  292. package/dist/schemas/fittings.js +0 -15
  293. package/dist/schemas/fleet.js +0 -48
  294. package/dist/schemas/freelance-jobs.js +0 -99
  295. package/dist/schemas/incursions.js +0 -14
  296. package/dist/schemas/industry.js +0 -75
  297. package/dist/schemas/insurance.js +0 -12
  298. package/dist/schemas/killmails.js +0 -42
  299. package/dist/schemas/location.js +0 -20
  300. package/dist/schemas/loyalty.js +0 -20
  301. package/dist/schemas/mail.js +0 -38
  302. package/dist/schemas/market.js +0 -39
  303. package/dist/schemas/mercenary.js +0 -22
  304. package/dist/schemas/pi.js +0 -85
  305. package/dist/schemas/skills.js +0 -30
  306. package/dist/schemas/skyhooks.js +0 -30
  307. package/dist/schemas/sovereignty.js +0 -70
  308. package/dist/schemas/status.js +0 -10
  309. package/dist/schemas/universe.js +0 -245
  310. package/dist/schemas/wallet.js +0 -29
  311. package/dist/schemas/wars.js +0 -31
  312. package/dist/testing/TestDataFactory.js +0 -823
  313. package/dist/types/access-lists.js +0 -2
  314. package/dist/types/alliance.js +0 -2
  315. package/dist/types/api-responses.js +0 -73
  316. package/dist/types/assets.js +0 -2
  317. package/dist/types/branded.js +0 -6
  318. package/dist/types/calendar.js +0 -2
  319. package/dist/types/character.js +0 -2
  320. package/dist/types/clones.js +0 -2
  321. package/dist/types/common.js +0 -2
  322. package/dist/types/contacts.js +0 -2
  323. package/dist/types/contracts.js +0 -2
  324. package/dist/types/corporation.js +0 -2
  325. package/dist/types/dogma.js +0 -2
  326. package/dist/types/faction-warfare.js +0 -2
  327. package/dist/types/fittings.js +0 -2
  328. package/dist/types/fleet.js +0 -2
  329. package/dist/types/freelance-jobs.js +0 -2
  330. package/dist/types/generated/esi-spec.generated.js +0 -6
  331. package/dist/types/generated/spec-alignment.check.js +0 -14
  332. package/dist/types/incursions.js +0 -2
  333. package/dist/types/industry.js +0 -2
  334. package/dist/types/insurance.js +0 -2
  335. package/dist/types/killmails.js +0 -2
  336. package/dist/types/location.js +0 -2
  337. package/dist/types/loyalty.js +0 -2
  338. package/dist/types/mail.js +0 -2
  339. package/dist/types/market.js +0 -2
  340. package/dist/types/mercenary.js +0 -2
  341. package/dist/types/pi.js +0 -2
  342. package/dist/types/skills.js +0 -2
  343. package/dist/types/skyhooks.js +0 -2
  344. package/dist/types/sovereignty.js +0 -2
  345. package/dist/types/status.js +0 -2
  346. package/dist/types/universe.js +0 -2
  347. package/dist/types/wallet.js +0 -2
  348. package/dist/types/wars.js +0 -2
@@ -1,123 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiClient = void 0;
4
- const Middleware_1 = require("./middleware/Middleware");
5
- class ApiClient {
6
- clientId;
7
- link;
8
- accessToken;
9
- datasource;
10
- tokenProvider;
11
- refreshInFlight;
12
- middleware = new Middleware_1.MiddlewareManager();
13
- cache = null;
14
- rateLimiter = null;
15
- circuitBreaker = null;
16
- timeout = 30_000;
17
- deduplicator = null;
18
- retryConfig = null;
19
- validateResponse = true;
20
- language;
21
- constructor(clientId, link, accessToken) {
22
- this.clientId = clientId;
23
- this.link = link;
24
- this.accessToken = accessToken;
25
- this.link = this.link.replace(/\/$/, '');
26
- }
27
- getTimeout() {
28
- return this.timeout;
29
- }
30
- setTimeout(timeout) {
31
- this.timeout = timeout;
32
- }
33
- getCache() {
34
- return this.cache;
35
- }
36
- setCache(cache) {
37
- this.cache = cache;
38
- }
39
- getRateLimiter() {
40
- return this.rateLimiter;
41
- }
42
- setRateLimiter(limiter) {
43
- this.rateLimiter = limiter;
44
- }
45
- getCircuitBreaker() {
46
- return this.circuitBreaker;
47
- }
48
- setCircuitBreaker(cb) {
49
- this.circuitBreaker = cb;
50
- }
51
- getDeduplicator() {
52
- return this.deduplicator;
53
- }
54
- setDeduplicator(dedup) {
55
- this.deduplicator = dedup;
56
- }
57
- getRetryConfig() {
58
- return this.retryConfig;
59
- }
60
- setRetryConfig(config) {
61
- this.retryConfig = config;
62
- }
63
- getValidateResponse() {
64
- return this.validateResponse;
65
- }
66
- setValidateResponse(validate) {
67
- this.validateResponse = validate;
68
- }
69
- getMiddleware() {
70
- return this.middleware;
71
- }
72
- addRequestInterceptor(fn) {
73
- return this.middleware.addRequestInterceptor(fn);
74
- }
75
- addResponseInterceptor(fn) {
76
- return this.middleware.addResponseInterceptor(fn);
77
- }
78
- getAuthorizationHeader() {
79
- return this.accessToken ? `Bearer ${this.accessToken}` : undefined;
80
- }
81
- getLink() {
82
- return this.link;
83
- }
84
- getDatasource() {
85
- return this.datasource;
86
- }
87
- setDatasource(datasource) {
88
- this.datasource = datasource;
89
- }
90
- getLanguage() {
91
- return this.language;
92
- }
93
- setLanguage(language) {
94
- this.language = language;
95
- }
96
- setAccessToken(token) {
97
- this.accessToken = token;
98
- }
99
- setTokenProvider(provider) {
100
- this.tokenProvider = provider;
101
- }
102
- hasTokenProvider() {
103
- return this.tokenProvider !== undefined;
104
- }
105
- async refreshToken() {
106
- if (!this.tokenProvider) {
107
- throw new Error('No token provider configured');
108
- }
109
- if (this.refreshInFlight) {
110
- return this.refreshInFlight;
111
- }
112
- this.refreshInFlight = this.tokenProvider().then((token) => {
113
- this.accessToken = token;
114
- this.refreshInFlight = undefined;
115
- return token;
116
- }, (err) => {
117
- this.refreshInFlight = undefined;
118
- throw err;
119
- });
120
- return this.refreshInFlight;
121
- }
122
- }
123
- exports.ApiClient = ApiClient;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiClientBuilder = void 0;
4
- const ApiClient_1 = require("./ApiClient");
5
- const RateLimiter_1 = require("./rateLimiter/RateLimiter");
6
- class ApiClientBuilder {
7
- clientId;
8
- link;
9
- accessToken;
10
- rateLimiter;
11
- cache;
12
- circuitBreaker;
13
- _timeout;
14
- setClientId(clientId) {
15
- this.clientId = clientId;
16
- return this;
17
- }
18
- setLink(link) {
19
- this.link = link;
20
- return this;
21
- }
22
- setAccessToken(accessToken) {
23
- this.accessToken = accessToken;
24
- return this;
25
- }
26
- setRateLimiter(limiter) {
27
- this.rateLimiter = limiter;
28
- return this;
29
- }
30
- setCache(cache) {
31
- this.cache = cache;
32
- return this;
33
- }
34
- setCircuitBreaker(cb) {
35
- this.circuitBreaker = cb;
36
- return this;
37
- }
38
- setTimeout(timeout) {
39
- this._timeout = timeout;
40
- return this;
41
- }
42
- build() {
43
- const client = new ApiClient_1.ApiClient(this.clientId, this.link, this.accessToken);
44
- client.setRateLimiter(this.rateLimiter ?? new RateLimiter_1.RateLimiter());
45
- if (this.cache)
46
- client.setCache(this.cache);
47
- if (this.circuitBreaker)
48
- client.setCircuitBreaker(this.circuitBreaker);
49
- if (this._timeout !== undefined)
50
- client.setTimeout(this._timeout);
51
- return client;
52
- }
53
- }
54
- exports.ApiClientBuilder = ApiClientBuilder;
@@ -1,444 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleRequest = exports.handleSinglePageRequest = void 0;
4
- const error_1 = require("../core/util/error");
5
- const loggerUtil_1 = require("../core/logger/loggerUtil");
6
- const headersUtil_1 = require("../core/util/headersUtil");
7
- const PaginationHandler_1 = require("./pagination/PaginationHandler");
8
- const constants_1 = require("./constants");
9
- const esi_cache_ttls_generated_1 = require("./endpoints/esi-cache-ttls.generated");
10
- const retry_1 = require("./util/retry");
11
- const sleep_1 = require("./util/sleep");
12
- const CircuitBreaker_1 = require("./circuitBreaker/CircuitBreaker");
13
- const STATUS_MESSAGES = {
14
- 201: 'Created',
15
- 204: 'No Content',
16
- 304: 'Not Modified',
17
- 400: 'Bad Request',
18
- 401: 'Unauthorized',
19
- 403: 'Forbidden',
20
- 404: 'Resource not found',
21
- 420: 'Error Limited',
22
- 422: 'Unprocessable Entity',
23
- 429: 'Too many requests',
24
- 500: 'Internal server error',
25
- 503: 'Service Unavailable',
26
- 504: 'Gateway Timeout',
27
- 520: 'Internal server error, did the request terminate too soon?',
28
- };
29
- // --- Dependency resolution ---
30
- function resolveCache(client) {
31
- return client.getCache();
32
- }
33
- function resolveRateLimiter(client) {
34
- const limiter = client.getRateLimiter();
35
- if (!limiter) {
36
- throw (0, error_1.buildError)('No rate limiter configured on ApiClient. ' +
37
- 'Set one via apiClient.setRateLimiter(new RateLimiter()).', 'CONFIGURATION_ERROR');
38
- }
39
- return limiter;
40
- }
41
- function resolveCircuitBreaker(client) {
42
- return client.getCircuitBreaker();
43
- }
44
- // --- Pure helpers ---
45
- const stringUtil_1 = require("./util/stringUtil");
46
- function lookupSpecTtl(method, templatePath) {
47
- const normalized = templatePath
48
- .replace(/\/$/, '')
49
- .replace(/\{(\w+)\}/g, (_, name) => `{${(0, stringUtil_1.camelToSnake)(name)}}`);
50
- const key = `${method}:${normalized}`;
51
- const seconds = esi_cache_ttls_generated_1.esiCacheTtls[key];
52
- return typeof seconds === 'number' ? seconds * 1000 : undefined;
53
- }
54
- function trySpecAwareCacheHit(client, url, method, templatePath) {
55
- if (method !== 'GET' || !templatePath)
56
- return null;
57
- const specTtlMs = lookupSpecTtl(method, templatePath);
58
- if (!specTtlMs)
59
- return null;
60
- const cache = resolveCache(client);
61
- if (!cache)
62
- return null;
63
- const entry = cache.get(url);
64
- if (!entry)
65
- return null;
66
- const age = Date.now() - entry.timestamp;
67
- if (age < specTtlMs) {
68
- (0, loggerUtil_1.logDebug)(`Spec-aware cache hit for ${url} (age=${Math.round(age / 1000)}s, ttl=${Math.round(specTtlMs / 1000)}s)`);
69
- return {
70
- headers: entry.headers,
71
- body: entry.data,
72
- fromCache: true,
73
- cacheHitType: 'spec-ttl',
74
- };
75
- }
76
- return null;
77
- }
78
- const parseCacheControlTtl = (headers) => {
79
- const cacheControl = headers['cache-control'] ?? headers['Cache-Control'];
80
- if (!cacheControl)
81
- return undefined;
82
- const match = /max-age=(\d+)/.exec(cacheControl);
83
- return match ? parseInt(match[1], 10) * 1000 : undefined;
84
- };
85
- function buildRequestHeaders(client, url, method, requiresAuth, useETag, body) {
86
- const headers = {
87
- accept: 'gzip, deflate, br',
88
- 'User-Agent': constants_1.USER_AGENT,
89
- 'X-Compatibility-Date': constants_1.COMPATIBILITY_DATE,
90
- };
91
- const language = client.getLanguage();
92
- if (language) {
93
- headers['Accept-Language'] = language;
94
- }
95
- if (requiresAuth) {
96
- const authHeader = client.getAuthorizationHeader();
97
- if (!authHeader) {
98
- throw (0, error_1.buildError)('Authorization header is required but not provided', 'NO_AUTH_TOKEN');
99
- }
100
- headers['Authorization'] = authHeader;
101
- }
102
- const cache = resolveCache(client);
103
- if (useETag && method === 'GET' && cache) {
104
- const cachedETag = cache.getETag(url);
105
- if (cachedETag) {
106
- headers['If-None-Match'] = cachedETag;
107
- (0, loggerUtil_1.logDebug)(`Adding If-None-Match header: ${cachedETag}`);
108
- }
109
- }
110
- if (body) {
111
- headers['Content-Type'] = 'application/json';
112
- }
113
- return headers;
114
- }
115
- function handleEarlyStatus(client, status, url, parsed, useETag) {
116
- if (status === 201) {
117
- return { headers: parsed.raw, body: undefined };
118
- }
119
- if (status === 204) {
120
- (0, loggerUtil_1.logInfo)(`No Content for endpoint: ${url}`);
121
- return { headers: parsed.raw, body: undefined };
122
- }
123
- if (status === 304) {
124
- const cache = resolveCache(client);
125
- if (useETag && cache) {
126
- const cachedEntry = cache.get(url);
127
- if (cachedEntry) {
128
- (0, loggerUtil_1.logInfo)(`Cache hit (304) for endpoint: ${url}`);
129
- return {
130
- headers: { ...cachedEntry.headers, ...parsed.raw },
131
- body: cachedEntry.data,
132
- fromCache: true,
133
- cacheHitType: 'etag-304',
134
- };
135
- }
136
- }
137
- throw new error_1.EsiError(304, 'Not Modified — no cached data available', url, parsed.requestId ?? undefined);
138
- }
139
- return null;
140
- }
141
- function tryStaleCacheResponse(client, url, parsed) {
142
- const cache = resolveCache(client);
143
- if (!cache)
144
- return null;
145
- const cachedEntry = cache.get(url);
146
- if (!cachedEntry)
147
- return null;
148
- return {
149
- headers: { ...cachedEntry.headers, ...parsed.raw },
150
- body: cachedEntry.data,
151
- fromCache: true,
152
- stale: true,
153
- cacheHitType: 'stale-on-error',
154
- };
155
- }
156
- function cacheResponse(client, url, method, endpoint, parsed, data, useETag) {
157
- const cache = resolveCache(client);
158
- if (useETag && method === 'GET' && cache && parsed.etag) {
159
- const ttl = parseCacheControlTtl(parsed.raw);
160
- cache.set(url, parsed.etag, data, parsed.raw, ttl);
161
- const ttlInfo = ttl ? ` (ttl=${ttl}ms)` : '';
162
- (0, loggerUtil_1.logDebug)(`Cached response for ${url} with ETag ${parsed.etag}${ttlInfo}`);
163
- }
164
- if (method !== 'GET' && cache) {
165
- cache.deleteByPath(endpoint.split('?')[0]);
166
- }
167
- }
168
- async function parseJsonBody(response, _url) {
169
- try {
170
- return (await response.json());
171
- }
172
- catch (jsonError) {
173
- const msg = jsonError instanceof Error ? jsonError.message : String(jsonError);
174
- (0, loggerUtil_1.logError)(`Failed to parse JSON response: ${msg}`);
175
- throw (0, error_1.buildError)(`Invalid JSON response: ${msg}`, 'JSON_PARSE_ERROR');
176
- }
177
- }
178
- function handleCursorPagination(parsed, data) {
179
- if (!parsed.hasCursorPagination)
180
- return null;
181
- const cursors = {
182
- before: parsed.cursorBefore,
183
- after: parsed.cursorAfter,
184
- };
185
- return { headers: parsed.raw, body: data, cursors };
186
- }
187
- async function handleOffsetPagination(client, endpoint, method, requiresAuth, parsed, data, body, url, useETag, pageFetch, templatePath) {
188
- const totalPages = parsed.xPages;
189
- if (totalPages <= 1) {
190
- return { headers: parsed.raw, body: data };
191
- }
192
- (0, loggerUtil_1.logInfo)(`Found ${totalPages} pages, fetching additional pages with rate limiting...`);
193
- try {
194
- const firstPageData = Array.isArray(data) ? data : [data];
195
- const allData = await PaginationHandler_1.PaginationHandler.fetchRemainingPages(client, endpoint, method, requiresAuth, firstPageData, totalPages, body, {
196
- maxPages: Math.min(totalPages, 1000),
197
- stopOnEmptyPage: true,
198
- maxRetries: 3,
199
- }, pageFetch, templatePath);
200
- cacheResponse(client, url, method, endpoint, parsed, allData, useETag);
201
- return { headers: parsed.raw, body: allData };
202
- }
203
- catch (paginationError) {
204
- const msg = paginationError instanceof Error
205
- ? paginationError.message
206
- : String(paginationError);
207
- (0, loggerUtil_1.logWarn)(`Pagination failed, returning first page only: ${msg}`);
208
- return { headers: parsed.raw, body: data };
209
- }
210
- }
211
- // --- Response interceptor wrapper ---
212
- async function applyResponseInterceptors(client, result, url, endpoint, method, startTime) {
213
- const middleware = client.getMiddleware();
214
- if (!middleware.hasInterceptors())
215
- return result;
216
- const responseCtx = {
217
- url,
218
- endpoint,
219
- method,
220
- status: 200,
221
- headers: result.headers,
222
- body: result.body,
223
- durationMs: Date.now() - startTime,
224
- fromCache: result.fromCache ?? false,
225
- };
226
- const modified = await middleware.applyResponseInterceptors(responseCtx);
227
- return {
228
- ...result,
229
- headers: modified.headers,
230
- body: modified.body,
231
- };
232
- }
233
- // --- Main request functions ---
234
- async function applyRequestMiddleware(client, url, endpoint, method, headers, body) {
235
- const middleware = client.getMiddleware();
236
- if (!middleware.hasInterceptors()) {
237
- return { url, headers, body };
238
- }
239
- const reqCtx = {
240
- url,
241
- endpoint,
242
- method,
243
- headers: { ...headers },
244
- body,
245
- };
246
- const modified = await middleware.applyRequestInterceptors(reqCtx);
247
- return {
248
- url: modified.url,
249
- headers: modified.headers,
250
- body: modified.body,
251
- };
252
- }
253
- function handleErrorResponse(client, response, url, parsed, useETag) {
254
- const errorMessage = STATUS_MESSAGES[response.status] || response.statusText;
255
- if (response.status >= 500 && useETag) {
256
- const staleResult = tryStaleCacheResponse(client, url, parsed);
257
- if (staleResult) {
258
- (0, loggerUtil_1.logWarn)(`${errorMessage} for ${url} — serving stale cache`);
259
- return staleResult;
260
- }
261
- }
262
- if (response.status === 420 || response.status === 429) {
263
- (0, loggerUtil_1.logWarn)(`Rate limited (${response.status}) on ${url}`);
264
- }
265
- throw new error_1.EsiError(response.status, errorMessage, url, parsed.requestId ?? undefined);
266
- }
267
- function wrapError(error) {
268
- if (error instanceof error_1.EsiError || error instanceof CircuitBreaker_1.CircuitOpenError) {
269
- throw error;
270
- }
271
- if (error instanceof Error) {
272
- (0, loggerUtil_1.logError)(`Unexpected error: ${error.message}`);
273
- throw (0, error_1.buildError)(error.message, 'ESIJS_ERROR');
274
- }
275
- (0, loggerUtil_1.logError)(`Unexpected error: ${String(error)}`);
276
- throw (0, error_1.buildError)(String(error), 'ESIJS_ERROR');
277
- }
278
- async function executeSingleFetch(client, endpoint, method, body, requiresAuth, useETag, requestTimeout, templatePath) {
279
- const rawUrl = `${client.getLink()}/${endpoint}`;
280
- const builtHeaders = buildRequestHeaders(client, rawUrl, method, requiresAuth, useETag, body);
281
- const req = await applyRequestMiddleware(client, rawUrl, endpoint, method, builtHeaders, body);
282
- const options = {
283
- method,
284
- headers: req.headers,
285
- body: req.body ? JSON.stringify(req.body) : undefined,
286
- };
287
- const url = req.url;
288
- (0, loggerUtil_1.logInfo)(`Hitting endpoint: ${url}`);
289
- const cb = resolveCircuitBreaker(client);
290
- if (cb)
291
- cb.checkCircuit(endpoint);
292
- const rateLimiter = resolveRateLimiter(client);
293
- await rateLimiter.checkRateLimit(templatePath, method, req.headers);
294
- const timeoutMs = requestTimeout ?? client.getTimeout();
295
- const controller = new AbortController();
296
- const timer = globalThis.setTimeout(() => controller.abort(), timeoutMs);
297
- options.signal = controller.signal;
298
- let response;
299
- try {
300
- response = await fetch(url, options);
301
- }
302
- catch (err) {
303
- clearTimeout(timer);
304
- if (err instanceof Error && err.name === 'AbortError') {
305
- throw new error_1.TimeoutError(timeoutMs, url);
306
- }
307
- throw err;
308
- }
309
- clearTimeout(timer);
310
- const parsed = (0, headersUtil_1.parseHeaders)(response.headers);
311
- rateLimiter.updateFromResponse(parsed.raw, response.status, templatePath, method, req.headers);
312
- if (cb) {
313
- if (response.status >= 500 ||
314
- response.status === 420 ||
315
- response.status === 429) {
316
- cb.recordFailure(endpoint, response.status);
317
- }
318
- else {
319
- cb.recordSuccess(endpoint);
320
- }
321
- }
322
- if (parsed.warning) {
323
- (0, loggerUtil_1.logWarn)(`ESI Warning ${parsed.warning.code} for ${url}: ${parsed.warning.message}`);
324
- }
325
- return { response, parsed, url };
326
- }
327
- async function fetchOnePage(client, endpoint, method, body, requiresAuth = false, useETag = false, requestTimeout, templatePath) {
328
- const { response, parsed, url } = await executeSingleFetch(client, endpoint, method, body, requiresAuth, useETag, requestTimeout, templatePath);
329
- if (!response.ok) {
330
- throw new error_1.EsiError(response.status, STATUS_MESSAGES[response.status] || response.statusText, url, parsed.requestId ?? undefined);
331
- }
332
- const data = await parseJsonBody(response, url);
333
- return { data, parsed, url };
334
- }
335
- const executeRequest = async (client, endpoint, method, body, requiresAuth = false, useETag = true, requestTimeout, templatePath) => {
336
- const startTime = Date.now();
337
- const finish = (r) => {
338
- r.responseTimeMs = Date.now() - startTime;
339
- const rawUrl = `${client.getLink()}/${endpoint}`;
340
- return applyResponseInterceptors(client, r, rawUrl, endpoint, method, startTime);
341
- };
342
- try {
343
- const { response, parsed, url } = await executeSingleFetch(client, endpoint, method, body, requiresAuth, useETag, requestTimeout, templatePath);
344
- if (response.status === 201) {
345
- let data;
346
- try {
347
- data = (await response.json());
348
- }
349
- catch {
350
- data = undefined;
351
- }
352
- return finish({ headers: parsed.raw, body: data });
353
- }
354
- const earlyResult = handleEarlyStatus(client, response.status, url, parsed, useETag);
355
- if (earlyResult)
356
- return finish(earlyResult);
357
- if (!response.ok) {
358
- const staleOrThrow = handleErrorResponse(client, response, url, parsed, useETag);
359
- return finish(staleOrThrow);
360
- }
361
- const data = await parseJsonBody(response, url);
362
- cacheResponse(client, url, method, endpoint, parsed, data, useETag);
363
- const cursorResult = handleCursorPagination(parsed, data);
364
- if (cursorResult)
365
- return finish(cursorResult);
366
- const pageFetch = async (paginatedEndpoint) => {
367
- const result = await fetchOnePage(client, paginatedEndpoint, method, body, requiresAuth, false, requestTimeout, templatePath);
368
- return Array.isArray(result.data)
369
- ? result.data
370
- : [result.data];
371
- };
372
- const paginatedResult = await handleOffsetPagination(client, endpoint, method, requiresAuth, parsed, data, body, url, useETag, pageFetch, templatePath);
373
- return finish(paginatedResult);
374
- }
375
- catch (error) {
376
- wrapError(error);
377
- }
378
- };
379
- const handleSinglePageRequest = async (client, endpoint, method, body, requiresAuth = false) => {
380
- const { data, parsed } = await fetchOnePage(client, endpoint, method, body, requiresAuth);
381
- return { headers: parsed.raw, body: data };
382
- };
383
- exports.handleSinglePageRequest = handleSinglePageRequest;
384
- const handleRequest = async (client, endpoint, method, body, requiresAuth = false, useETag = true, templatePath, requestTimeout) => {
385
- const rawUrl = `${client.getLink()}/${endpoint}`;
386
- const specHit = trySpecAwareCacheHit(client, rawUrl, method, templatePath);
387
- if (specHit)
388
- return specHit;
389
- const doExecute = () => executeRequest(client, endpoint, method, body, requiresAuth, useETag, requestTimeout, templatePath);
390
- const dedup = client.getDeduplicator();
391
- const canDedup = dedup && method === 'GET' && !body;
392
- const retryConfig = client.getRetryConfig();
393
- const maxRetries = retryConfig?.maxRetries ?? 0;
394
- const canRetryMethod = method === 'GET' || retryConfig?.retryMutations === true;
395
- const baseDelayMs = retryConfig?.baseDelayMs ?? 1000;
396
- const maxDelayMs = retryConfig?.maxDelayMs ?? 30000;
397
- let lastError;
398
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
399
- try {
400
- return canDedup
401
- ? await dedup.dedupe(endpoint, doExecute)
402
- : await doExecute();
403
- }
404
- catch (error) {
405
- if (error instanceof CircuitBreaker_1.CircuitOpenError) {
406
- throw error;
407
- }
408
- if (error instanceof error_1.EsiError &&
409
- error.statusCode === 401 &&
410
- requiresAuth &&
411
- client.hasTokenProvider()) {
412
- (0, loggerUtil_1.logInfo)('Received 401, attempting token refresh...');
413
- try {
414
- await client.refreshToken();
415
- (0, loggerUtil_1.logInfo)('Token refreshed, retrying request');
416
- return await executeRequest(client, endpoint, method, body, requiresAuth, useETag, requestTimeout);
417
- }
418
- catch (refreshError) {
419
- if (refreshError instanceof error_1.EsiError) {
420
- throw refreshError;
421
- }
422
- const msg = refreshError instanceof Error
423
- ? refreshError.message
424
- : String(refreshError);
425
- (0, loggerUtil_1.logError)(`Token refresh failed: ${msg}`);
426
- throw (0, error_1.buildError)(`Token refresh failed: ${msg}`, 'TOKEN_REFRESH_FAILED');
427
- }
428
- }
429
- if (error instanceof error_1.EsiError &&
430
- error.retryable &&
431
- canRetryMethod &&
432
- attempt < maxRetries) {
433
- const delay = (0, retry_1.retryDelay)(attempt, baseDelayMs, maxDelayMs);
434
- (0, loggerUtil_1.logWarn)(`Request to ${endpoint} failed (${error.statusCode}), retrying in ${Math.round(delay)}ms (attempt ${attempt + 1}/${maxRetries})`);
435
- await (0, sleep_1.sleep)(delay);
436
- lastError = error;
437
- continue;
438
- }
439
- throw error;
440
- }
441
- }
442
- throw lastError;
443
- };
444
- exports.handleRequest = handleRequest;
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.batchFetch = batchFetch;
4
- exports.batchPost = batchPost;
5
- const error_1 = require("./util/error");
6
- const loggerUtil_1 = require("./logger/loggerUtil");
7
- async function batchFetch(keys, fetcher, options = {}) {
8
- const concurrency = options.concurrency ?? 20;
9
- const results = new Map();
10
- const errors = new Map();
11
- let completed = 0;
12
- let running = 0;
13
- let index = 0;
14
- (0, loggerUtil_1.logInfo)(`Batch fetch: ${keys.length} items, concurrency=${concurrency}`);
15
- return new Promise((resolve) => {
16
- function next() {
17
- while (running < concurrency && index < keys.length) {
18
- const currentIndex = index++;
19
- const key = keys[currentIndex];
20
- running++;
21
- fetcher(key)
22
- .then((result) => {
23
- results.set(key, result);
24
- })
25
- .catch((err) => {
26
- const error = err instanceof error_1.EsiError || err instanceof Error
27
- ? err
28
- : new Error(String(err));
29
- errors.set(key, error);
30
- })
31
- .finally(() => {
32
- running--;
33
- completed++;
34
- if (options.onProgress) {
35
- options.onProgress(completed, keys.length);
36
- }
37
- if (completed === keys.length) {
38
- (0, loggerUtil_1.logDebug)(`Batch complete: ${results.size} succeeded, ${errors.size} failed`);
39
- resolve({ results, errors });
40
- }
41
- else {
42
- next();
43
- }
44
- });
45
- }
46
- }
47
- if (keys.length === 0) {
48
- resolve({ results, errors });
49
- return;
50
- }
51
- next();
52
- });
53
- }
54
- async function batchPost(ids, poster, chunkSize = 1000) {
55
- const chunks = [];
56
- for (let i = 0; i < ids.length; i += chunkSize) {
57
- chunks.push(ids.slice(i, i + chunkSize));
58
- }
59
- (0, loggerUtil_1.logInfo)(`Batch POST: ${ids.length} IDs in ${chunks.length} chunks of ${chunkSize}`);
60
- const results = [];
61
- for (const chunk of chunks) {
62
- const chunkResult = await poster(chunk);
63
- results.push(...chunkResult);
64
- }
65
- return results;
66
- }