@takaro/apiclient 0.0.0-dev.bf507a2 → 0.0.0-dev.bfbcbc4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/api.d.ts +1305 -50
- package/dist/generated/api.d.ts.map +1 -1
- package/dist/generated/api.js +774 -8
- package/dist/generated/api.js.map +1 -1
- package/dist/lib/baseClient.d.ts +14 -0
- package/dist/lib/baseClient.d.ts.map +1 -1
- package/dist/lib/baseClient.js +13 -0
- package/dist/lib/baseClient.js.map +1 -1
- package/dist/lib/client.d.ts +2 -1
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/client.js +6 -1
- package/dist/lib/client.js.map +1 -1
- package/package.json +2 -2
- package/src/generated/api.ts +2073 -189
- package/src/lib/__tests__/baseClient.unit.test.ts +17 -0
- package/src/lib/baseClient.ts +16 -0
- package/src/lib/client.ts +11 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import { expect } from '@takaro/test/unit';
|
|
3
|
+
import { BaseApiClient, DEFAULT_REQUEST_TIMEOUT_MS } from '../baseClient.js';
|
|
4
|
+
|
|
5
|
+
describe('BaseApiClient timeouts', () => {
|
|
6
|
+
it('sets a default request timeout so a stalled request cannot hang forever', () => {
|
|
7
|
+
const client = new BaseApiClient({ url: 'http://localhost:3000', log: false });
|
|
8
|
+
|
|
9
|
+
expect(client.axiosInstance.defaults.timeout).to.equal(DEFAULT_REQUEST_TIMEOUT_MS);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('lets a caller override the timeout', () => {
|
|
13
|
+
const client = new BaseApiClient({ url: 'http://localhost:3000', log: false, timeoutMs: 5000 });
|
|
14
|
+
|
|
15
|
+
expect(client.axiosInstance.defaults.timeout).to.equal(5000);
|
|
16
|
+
});
|
|
17
|
+
});
|
package/src/lib/baseClient.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { MetaApi } from '../generated/api.js';
|
|
2
2
|
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Axios defaults to NO timeout, so a request whose TCP connection stalls blocks its
|
|
6
|
+
* await forever. During incident run-29688761260 a single POST hung for ~80 minutes
|
|
7
|
+
* (Tempo trace 15f5708701c38676355a0e42cb9f7ffe: a client span with no server span),
|
|
8
|
+
* freezing 3 of 4 CI shards until the 53-minute job timeout.
|
|
9
|
+
*
|
|
10
|
+
* 120s is deliberately generous — the goal is "not infinite", not "tight". The slowest
|
|
11
|
+
* legitimate single call is a domain create under full 4-shard CI load at roughly 30s.
|
|
12
|
+
* Individual long-running calls should pass a per-request `{ timeout }` override rather
|
|
13
|
+
* than raising this.
|
|
14
|
+
*/
|
|
15
|
+
export const DEFAULT_REQUEST_TIMEOUT_MS = 120_000;
|
|
16
|
+
|
|
4
17
|
export interface IBaseApiClientConfig {
|
|
5
18
|
url: string;
|
|
6
19
|
log?: Logger | false;
|
|
20
|
+
/** Per-request timeout in ms. Defaults to DEFAULT_REQUEST_TIMEOUT_MS. */
|
|
21
|
+
timeoutMs?: number;
|
|
7
22
|
}
|
|
8
23
|
|
|
9
24
|
interface Logger {
|
|
@@ -36,6 +51,7 @@ export class BaseApiClient<T extends IBaseApiClientConfig> {
|
|
|
36
51
|
...(!isBrowser && { 'User-Agent': 'Takaro-API-Client' }),
|
|
37
52
|
},
|
|
38
53
|
withCredentials: true,
|
|
54
|
+
timeout: this.config.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
39
55
|
};
|
|
40
56
|
this.axios = this.addLoggers(axios.create(axiosConfig));
|
|
41
57
|
|
package/src/lib/client.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
TrackingApi,
|
|
22
22
|
EntityApi,
|
|
23
23
|
AnalyticsApi,
|
|
24
|
+
InviteLinkApi,
|
|
24
25
|
} from '../generated/api.js';
|
|
25
26
|
import { BaseApiClient, IBaseApiClientConfig } from './baseClient.js';
|
|
26
27
|
|
|
@@ -305,4 +306,14 @@ export class Client extends BaseApiClient<IApiClientConfig> {
|
|
|
305
306
|
this.axios,
|
|
306
307
|
);
|
|
307
308
|
}
|
|
309
|
+
|
|
310
|
+
get inviteLink() {
|
|
311
|
+
return new InviteLinkApi(
|
|
312
|
+
{
|
|
313
|
+
isJsonMime: this.isJsonMime,
|
|
314
|
+
},
|
|
315
|
+
'',
|
|
316
|
+
this.axios,
|
|
317
|
+
);
|
|
318
|
+
}
|
|
308
319
|
}
|