@takaro/apiclient 0.0.0-dev.fc39ea2 → 0.0.0-dev.fc4b15f
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 +12352 -5731
- package/dist/generated/api.d.ts.map +1 -1
- package/dist/generated/api.js +11593 -6680
- package/dist/generated/api.js.map +1 -1
- package/dist/generated/base.d.ts +1 -1
- package/dist/generated/base.js +1 -1
- package/dist/generated/common.d.ts +1 -1
- package/dist/generated/common.js +1 -1
- package/dist/generated/configuration.d.ts +1 -1
- package/dist/generated/configuration.js +2 -2
- package/dist/generated/configuration.js.map +1 -1
- package/dist/generated/index.d.ts +1 -1
- package/dist/generated/index.js +1 -1
- package/dist/lib/adminClient.d.ts +1 -1
- package/dist/lib/adminClient.d.ts.map +1 -1
- package/dist/lib/adminClient.js +2 -1
- package/dist/lib/adminClient.js.map +1 -1
- package/dist/lib/baseClient.d.ts +15 -1
- package/dist/lib/baseClient.d.ts.map +1 -1
- package/dist/lib/baseClient.js +21 -2
- package/dist/lib/baseClient.js.map +1 -1
- package/dist/lib/client.d.ts +4 -3
- package/dist/lib/client.d.ts.map +1 -1
- package/dist/lib/client.js +15 -9
- package/dist/lib/client.js.map +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/generated.manifest.json +27 -0
- package/openapi.json +27938 -0
- package/package.json +2 -2
- package/src/generated/api.ts +20400 -9494
- package/src/generated/base.ts +1 -1
- package/src/generated/common.ts +1 -1
- package/src/generated/configuration.ts +2 -2
- package/src/generated/index.ts +1 -1
- package/src/lib/__tests__/baseClient.unit.test.ts +17 -0
- package/src/lib/adminClient.ts +5 -3
- package/src/lib/baseClient.ts +27 -3
- package/src/lib/client.ts +23 -11
- package/src/main.ts +1 -1
package/src/generated/base.ts
CHANGED
package/src/generated/common.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
|
-
* Takaro
|
|
4
|
+
* Takaro API
|
|
5
5
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
6
6
|
*
|
|
7
7
|
* The version of the OpenAPI document: 0.0.0
|
|
@@ -117,7 +117,7 @@ export class Configuration {
|
|
|
117
117
|
* @return True if the given MIME is JSON, false otherwise.
|
|
118
118
|
*/
|
|
119
119
|
public isJsonMime(mime: string): boolean {
|
|
120
|
-
const jsonMime: RegExp = new RegExp('^(application
|
|
120
|
+
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
|
121
121
|
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
|
|
122
122
|
}
|
|
123
123
|
}
|
package/src/generated/index.ts
CHANGED
|
@@ -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/adminClient.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DomainApi } from '../generated/index.js';
|
|
2
|
-
import { BaseApiClient, IBaseApiClientConfig } from './baseClient.js';
|
|
3
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { BaseApiClient, type IBaseApiClientConfig } from './baseClient.js';
|
|
3
|
+
import { type AxiosInstance } from 'axios';
|
|
4
4
|
|
|
5
5
|
export interface IAdminApiClientConfig extends IBaseApiClientConfig {
|
|
6
6
|
auth: {
|
|
@@ -16,7 +16,9 @@ export class AdminClient extends BaseApiClient<IAdminApiClientConfig> {
|
|
|
16
16
|
|
|
17
17
|
private addAuthInterceptor(token: string, axios: AxiosInstance): AxiosInstance {
|
|
18
18
|
axios.interceptors.request.use(async (request) => {
|
|
19
|
-
if (request.url?.includes('health'))
|
|
19
|
+
if (request.url?.includes('health')) {
|
|
20
|
+
return request;
|
|
21
|
+
}
|
|
20
22
|
|
|
21
23
|
request.headers['X-Takaro-Admin-Token'] = token;
|
|
22
24
|
return request;
|
package/src/lib/baseClient.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { MetaApi } from '../generated/api.js';
|
|
2
|
-
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import axios, { type AxiosError, type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|
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;
|
|
3
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 {
|
|
@@ -23,17 +38,26 @@ export class BaseApiClient<T extends IBaseApiClientConfig> {
|
|
|
23
38
|
};
|
|
24
39
|
|
|
25
40
|
constructor(protected readonly config: T) {
|
|
41
|
+
// Browsers refuse to let JS set the User-Agent header (it's a "forbidden header").
|
|
42
|
+
// Only include it when running outside a browser context (Node.js / server-side).
|
|
43
|
+
// Use globalThis so this compiles under both DOM and non-DOM TypeScript lib targets.
|
|
44
|
+
const isBrowser =
|
|
45
|
+
(globalThis as Record<string, unknown>).window !== undefined &&
|
|
46
|
+
(globalThis as Record<string, unknown>).document !== undefined;
|
|
26
47
|
const axiosConfig: AxiosRequestConfig = {
|
|
27
48
|
baseURL: this.config.url,
|
|
28
49
|
headers: {
|
|
29
50
|
'Content-Type': 'application/json',
|
|
30
|
-
'User-Agent': 'Takaro-API-Client',
|
|
51
|
+
...(!isBrowser && { 'User-Agent': 'Takaro-API-Client' }),
|
|
31
52
|
},
|
|
32
53
|
withCredentials: true,
|
|
54
|
+
timeout: this.config.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS,
|
|
33
55
|
};
|
|
34
56
|
this.axios = this.addLoggers(axios.create(axiosConfig));
|
|
35
57
|
|
|
36
|
-
if (this.config.log)
|
|
58
|
+
if (this.config.log) {
|
|
59
|
+
this.log = this.config.log;
|
|
60
|
+
}
|
|
37
61
|
}
|
|
38
62
|
|
|
39
63
|
setHeader(key: string, value: string) {
|
package/src/lib/client.ts
CHANGED
|
@@ -14,15 +14,16 @@ import {
|
|
|
14
14
|
EventApi,
|
|
15
15
|
PlayerOnGameServerApi,
|
|
16
16
|
ItemApi,
|
|
17
|
-
StatsApi,
|
|
18
17
|
ShopOrderApi,
|
|
19
18
|
ShopListingApi,
|
|
20
19
|
ShopCategoryApi,
|
|
20
|
+
ShopActionApi,
|
|
21
21
|
TrackingApi,
|
|
22
22
|
EntityApi,
|
|
23
23
|
AnalyticsApi,
|
|
24
|
+
InviteLinkApi,
|
|
24
25
|
} from '../generated/api.js';
|
|
25
|
-
import { BaseApiClient, IBaseApiClientConfig } from './baseClient.js';
|
|
26
|
+
import { BaseApiClient, type IBaseApiClientConfig } from './baseClient.js';
|
|
26
27
|
|
|
27
28
|
export interface IApiClientConfig extends IBaseApiClientConfig {
|
|
28
29
|
auth: {
|
|
@@ -63,13 +64,13 @@ export class Client extends BaseApiClient<IApiClientConfig> {
|
|
|
63
64
|
this.config.auth.token = loginRes.data.data.token;
|
|
64
65
|
this.token = loginRes.data.data.token;
|
|
65
66
|
|
|
66
|
-
this.axios.defaults.headers.common
|
|
67
|
+
this.axios.defaults.headers.common.Authorization = `Bearer ${loginRes.data.data.token}`;
|
|
67
68
|
|
|
68
69
|
return loginRes.data.data.token;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
public logout() {
|
|
72
|
-
delete this.axios.defaults.headers.common
|
|
73
|
+
delete this.axios.defaults.headers.common.Authorization;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
public async permissionCodesToInputs(permissions: string[]) {
|
|
@@ -80,8 +81,9 @@ export class Client extends BaseApiClient<IApiClientConfig> {
|
|
|
80
81
|
permissionId: p.id,
|
|
81
82
|
}));
|
|
82
83
|
|
|
83
|
-
if (records.length !== permissions.length)
|
|
84
|
+
if (records.length !== permissions.length) {
|
|
84
85
|
throw new Error(`Not all permissions were found: ${permissions.join(', ')}`);
|
|
86
|
+
}
|
|
85
87
|
|
|
86
88
|
return records;
|
|
87
89
|
}
|
|
@@ -236,8 +238,8 @@ export class Client extends BaseApiClient<IApiClientConfig> {
|
|
|
236
238
|
);
|
|
237
239
|
}
|
|
238
240
|
|
|
239
|
-
get
|
|
240
|
-
return new
|
|
241
|
+
get shopListing() {
|
|
242
|
+
return new ShopListingApi(
|
|
241
243
|
{
|
|
242
244
|
isJsonMime: this.isJsonMime,
|
|
243
245
|
},
|
|
@@ -246,8 +248,8 @@ export class Client extends BaseApiClient<IApiClientConfig> {
|
|
|
246
248
|
);
|
|
247
249
|
}
|
|
248
250
|
|
|
249
|
-
get
|
|
250
|
-
return new
|
|
251
|
+
get shopCategory() {
|
|
252
|
+
return new ShopCategoryApi(
|
|
251
253
|
{
|
|
252
254
|
isJsonMime: this.isJsonMime,
|
|
253
255
|
},
|
|
@@ -256,8 +258,8 @@ export class Client extends BaseApiClient<IApiClientConfig> {
|
|
|
256
258
|
);
|
|
257
259
|
}
|
|
258
260
|
|
|
259
|
-
get
|
|
260
|
-
return new
|
|
261
|
+
get shopAction() {
|
|
262
|
+
return new ShopActionApi(
|
|
261
263
|
{
|
|
262
264
|
isJsonMime: this.isJsonMime,
|
|
263
265
|
},
|
|
@@ -305,4 +307,14 @@ export class Client extends BaseApiClient<IApiClientConfig> {
|
|
|
305
307
|
this.axios,
|
|
306
308
|
);
|
|
307
309
|
}
|
|
310
|
+
|
|
311
|
+
get inviteLink() {
|
|
312
|
+
return new InviteLinkApi(
|
|
313
|
+
{
|
|
314
|
+
isJsonMime: this.isJsonMime,
|
|
315
|
+
},
|
|
316
|
+
'',
|
|
317
|
+
this.axios,
|
|
318
|
+
);
|
|
319
|
+
}
|
|
308
320
|
}
|
package/src/main.ts
CHANGED