serialstation 1.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.
- package/LICENSE +21 -0
- package/README.md +272 -0
- package/dist/api/companies/index.d.mts +16 -0
- package/dist/api/companies/index.d.ts +16 -0
- package/dist/api/companies/index.js +41 -0
- package/dist/api/companies/index.js.map +1 -0
- package/dist/api/companies/index.mjs +16 -0
- package/dist/api/companies/index.mjs.map +1 -0
- package/dist/api/content-ids/index.d.mts +20 -0
- package/dist/api/content-ids/index.d.ts +20 -0
- package/dist/api/content-ids/index.js +47 -0
- package/dist/api/content-ids/index.js.map +1 -0
- package/dist/api/content-ids/index.mjs +22 -0
- package/dist/api/content-ids/index.mjs.map +1 -0
- package/dist/api/franchises/index.d.mts +16 -0
- package/dist/api/franchises/index.d.ts +16 -0
- package/dist/api/franchises/index.js +41 -0
- package/dist/api/franchises/index.js.map +1 -0
- package/dist/api/franchises/index.mjs +16 -0
- package/dist/api/franchises/index.mjs.map +1 -0
- package/dist/api/games/index.d.mts +20 -0
- package/dist/api/games/index.d.ts +20 -0
- package/dist/api/games/index.js +47 -0
- package/dist/api/games/index.js.map +1 -0
- package/dist/api/games/index.mjs +22 -0
- package/dist/api/games/index.mjs.map +1 -0
- package/dist/api/title-ids/index.d.mts +32 -0
- package/dist/api/title-ids/index.d.ts +32 -0
- package/dist/api/title-ids/index.js +58 -0
- package/dist/api/title-ids/index.js.map +1 -0
- package/dist/api/title-ids/index.mjs +33 -0
- package/dist/api/title-ids/index.mjs.map +1 -0
- package/dist/client/BaseClient.d.mts +76 -0
- package/dist/client/BaseClient.d.ts +76 -0
- package/dist/client/BaseClient.js +136 -0
- package/dist/client/BaseClient.js.map +1 -0
- package/dist/client/BaseClient.mjs +101 -0
- package/dist/client/BaseClient.mjs.map +1 -0
- package/dist/index.d.mts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +263 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +220 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types/index.d.mts +23 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types-BjzcHkoc.d.mts +25 -0
- package/dist/types-BjzcHkoc.d.ts +25 -0
- package/dist/types-BnaHEIcd.d.mts +41 -0
- package/dist/types-BnaHEIcd.d.ts +41 -0
- package/dist/types-Dv-1DNPu.d.mts +60 -0
- package/dist/types-Dv-1DNPu.d.ts +60 -0
- package/dist/types-KwGU8D6g.d.mts +66 -0
- package/dist/types-KwGU8D6g.d.ts +66 -0
- package/dist/types-axGWx6HR.d.mts +25 -0
- package/dist/types-axGWx6HR.d.ts +25 -0
- package/package.json +103 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/api/games/index.ts
|
|
21
|
+
var games_exports = {};
|
|
22
|
+
__export(games_exports, {
|
|
23
|
+
GamesAPI: () => GamesAPI
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(games_exports);
|
|
26
|
+
var GamesAPI = class {
|
|
27
|
+
constructor(client) {
|
|
28
|
+
this.client = client;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Lists games with optional filtering and pagination.
|
|
32
|
+
*/
|
|
33
|
+
async listGames(params) {
|
|
34
|
+
return this.client.get("/games/", params);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves game information by its UUID.
|
|
38
|
+
*/
|
|
39
|
+
async getGame(gameId) {
|
|
40
|
+
return this.client.get(`/games/${gameId}`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
GamesAPI
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/games/index.ts"],"sourcesContent":["import { SerialStationClient } from '../../client/BaseClient';\r\nimport { GameSchema, PagedGameSchema, GameFilterParams } from './types';\r\n\r\n/**\r\n * API client for managing game information.\r\n */\r\nexport class GamesAPI {\r\n constructor(private client: SerialStationClient) {}\r\n\r\n /**\r\n * Lists games with optional filtering and pagination.\r\n */\r\n async listGames(params?: GameFilterParams): Promise<PagedGameSchema> {\r\n return this.client.get<PagedGameSchema>('/games/', params);\r\n }\r\n\r\n /**\r\n * Retrieves game information by its UUID.\r\n */\r\n async getGame(gameId: string): Promise<GameSchema> {\r\n return this.client.get<GameSchema>(`/games/${gameId}`);\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,WAAN,MAAe;AAAA,EACpB,YAAoB,QAA6B;AAA7B;AAAA,EAA8B;AAAA;AAAA;AAAA;AAAA,EAKlD,MAAM,UAAU,QAAqD;AACnE,WAAO,KAAK,OAAO,IAAqB,WAAW,MAAM;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,QAAqC;AACjD,WAAO,KAAK,OAAO,IAAgB,UAAU,MAAM,EAAE;AAAA,EACvD;AACF;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/api/games/index.ts
|
|
2
|
+
var GamesAPI = class {
|
|
3
|
+
constructor(client) {
|
|
4
|
+
this.client = client;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Lists games with optional filtering and pagination.
|
|
8
|
+
*/
|
|
9
|
+
async listGames(params) {
|
|
10
|
+
return this.client.get("/games/", params);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves game information by its UUID.
|
|
14
|
+
*/
|
|
15
|
+
async getGame(gameId) {
|
|
16
|
+
return this.client.get(`/games/${gameId}`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
GamesAPI
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/games/index.ts"],"sourcesContent":["import { SerialStationClient } from '../../client/BaseClient';\r\nimport { GameSchema, PagedGameSchema, GameFilterParams } from './types';\r\n\r\n/**\r\n * API client for managing game information.\r\n */\r\nexport class GamesAPI {\r\n constructor(private client: SerialStationClient) {}\r\n\r\n /**\r\n * Lists games with optional filtering and pagination.\r\n */\r\n async listGames(params?: GameFilterParams): Promise<PagedGameSchema> {\r\n return this.client.get<PagedGameSchema>('/games/', params);\r\n }\r\n\r\n /**\r\n * Retrieves game information by its UUID.\r\n */\r\n async getGame(gameId: string): Promise<GameSchema> {\r\n return this.client.get<GameSchema>(`/games/${gameId}`);\r\n }\r\n}\r\n"],"mappings":";AAMO,IAAM,WAAN,MAAe;AAAA,EACpB,YAAoB,QAA6B;AAA7B;AAAA,EAA8B;AAAA;AAAA;AAAA;AAAA,EAKlD,MAAM,UAAU,QAAqD;AACnE,WAAO,KAAK,OAAO,IAAqB,WAAW,MAAM;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,QAAqC;AACjD,WAAO,KAAK,OAAO,IAAgB,UAAU,MAAM,EAAE;AAAA,EACvD;AACF;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SerialStationClient } from '../../client/BaseClient.mjs';
|
|
2
|
+
import { T as TitleIDFilterParams, P as PagedTitleIDSchema, c as TitleIDSchema } from '../../types-KwGU8D6g.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* API client for managing title ID information.
|
|
6
|
+
* Provides methods to query and retrieve PlayStation title ID data.
|
|
7
|
+
*/
|
|
8
|
+
declare class TitleIDsAPI {
|
|
9
|
+
private client;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new TitleIDsAPI instance.
|
|
12
|
+
*
|
|
13
|
+
* @param client - The SerialStation client instance to use for requests
|
|
14
|
+
*/
|
|
15
|
+
constructor(client: SerialStationClient);
|
|
16
|
+
/**
|
|
17
|
+
* Lists title IDs with optional filtering and pagination.
|
|
18
|
+
*
|
|
19
|
+
* @param params - Optional parameters for filtering and pagination
|
|
20
|
+
* @returns Promise resolving to a paginated list of title IDs
|
|
21
|
+
*/
|
|
22
|
+
listTitleIDs(params?: TitleIDFilterParams): Promise<PagedTitleIDSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves title ID information by its unique identifier.
|
|
25
|
+
*
|
|
26
|
+
* @param titleId - The unique title ID (hexadecimal string)
|
|
27
|
+
* @returns Promise resolving to the title ID schema
|
|
28
|
+
*/
|
|
29
|
+
getTitleID(titleId: string): Promise<TitleIDSchema>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { TitleIDsAPI };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SerialStationClient } from '../../client/BaseClient.js';
|
|
2
|
+
import { T as TitleIDFilterParams, P as PagedTitleIDSchema, c as TitleIDSchema } from '../../types-KwGU8D6g.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* API client for managing title ID information.
|
|
6
|
+
* Provides methods to query and retrieve PlayStation title ID data.
|
|
7
|
+
*/
|
|
8
|
+
declare class TitleIDsAPI {
|
|
9
|
+
private client;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new TitleIDsAPI instance.
|
|
12
|
+
*
|
|
13
|
+
* @param client - The SerialStation client instance to use for requests
|
|
14
|
+
*/
|
|
15
|
+
constructor(client: SerialStationClient);
|
|
16
|
+
/**
|
|
17
|
+
* Lists title IDs with optional filtering and pagination.
|
|
18
|
+
*
|
|
19
|
+
* @param params - Optional parameters for filtering and pagination
|
|
20
|
+
* @returns Promise resolving to a paginated list of title IDs
|
|
21
|
+
*/
|
|
22
|
+
listTitleIDs(params?: TitleIDFilterParams): Promise<PagedTitleIDSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves title ID information by its unique identifier.
|
|
25
|
+
*
|
|
26
|
+
* @param titleId - The unique title ID (hexadecimal string)
|
|
27
|
+
* @returns Promise resolving to the title ID schema
|
|
28
|
+
*/
|
|
29
|
+
getTitleID(titleId: string): Promise<TitleIDSchema>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { TitleIDsAPI };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/api/title-ids/index.ts
|
|
21
|
+
var title_ids_exports = {};
|
|
22
|
+
__export(title_ids_exports, {
|
|
23
|
+
TitleIDsAPI: () => TitleIDsAPI
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(title_ids_exports);
|
|
26
|
+
var TitleIDsAPI = class {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new TitleIDsAPI instance.
|
|
29
|
+
*
|
|
30
|
+
* @param client - The SerialStation client instance to use for requests
|
|
31
|
+
*/
|
|
32
|
+
constructor(client) {
|
|
33
|
+
this.client = client;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Lists title IDs with optional filtering and pagination.
|
|
37
|
+
*
|
|
38
|
+
* @param params - Optional parameters for filtering and pagination
|
|
39
|
+
* @returns Promise resolving to a paginated list of title IDs
|
|
40
|
+
*/
|
|
41
|
+
async listTitleIDs(params) {
|
|
42
|
+
return this.client.get("/title-ids/", params);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves title ID information by its unique identifier.
|
|
46
|
+
*
|
|
47
|
+
* @param titleId - The unique title ID (hexadecimal string)
|
|
48
|
+
* @returns Promise resolving to the title ID schema
|
|
49
|
+
*/
|
|
50
|
+
async getTitleID(titleId) {
|
|
51
|
+
return this.client.get(`/title-ids/${titleId}`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
TitleIDsAPI
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/title-ids/index.ts"],"sourcesContent":["import { SerialStationClient } from '../../client/BaseClient';\r\nimport { TitleIDSchema, PagedTitleIDSchema, TitleIDFilterParams } from './types';\r\n\r\n/**\r\n * API client for managing title ID information.\r\n * Provides methods to query and retrieve PlayStation title ID data.\r\n */\r\nexport class TitleIDsAPI {\r\n /**\r\n * Creates a new TitleIDsAPI instance.\r\n * \r\n * @param client - The SerialStation client instance to use for requests\r\n */\r\n constructor(private client: SerialStationClient) {}\r\n \r\n /**\r\n * Lists title IDs with optional filtering and pagination.\r\n * \r\n * @param params - Optional parameters for filtering and pagination\r\n * @returns Promise resolving to a paginated list of title IDs\r\n */\r\n async listTitleIDs(params?: TitleIDFilterParams): Promise<PagedTitleIDSchema> {\r\n return this.client.get<PagedTitleIDSchema>('/title-ids/', params);\r\n }\r\n \r\n /**\r\n * Retrieves title ID information by its unique identifier.\r\n * \r\n * @param titleId - The unique title ID (hexadecimal string)\r\n * @returns Promise resolving to the title ID schema\r\n */\r\n async getTitleID(titleId: string): Promise<TitleIDSchema> {\r\n return this.client.get<TitleIDSchema>(`/title-ids/${titleId}`);\r\n }\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,IAAM,cAAN,MAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,YAAoB,QAA6B;AAA7B;AAAA,EAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlD,MAAM,aAAa,QAA2D;AAC5E,WAAO,KAAK,OAAO,IAAwB,eAAe,MAAM;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,SAAyC;AACxD,WAAO,KAAK,OAAO,IAAmB,cAAc,OAAO,EAAE;AAAA,EAC/D;AACF;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/api/title-ids/index.ts
|
|
2
|
+
var TitleIDsAPI = class {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new TitleIDsAPI instance.
|
|
5
|
+
*
|
|
6
|
+
* @param client - The SerialStation client instance to use for requests
|
|
7
|
+
*/
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Lists title IDs with optional filtering and pagination.
|
|
13
|
+
*
|
|
14
|
+
* @param params - Optional parameters for filtering and pagination
|
|
15
|
+
* @returns Promise resolving to a paginated list of title IDs
|
|
16
|
+
*/
|
|
17
|
+
async listTitleIDs(params) {
|
|
18
|
+
return this.client.get("/title-ids/", params);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves title ID information by its unique identifier.
|
|
22
|
+
*
|
|
23
|
+
* @param titleId - The unique title ID (hexadecimal string)
|
|
24
|
+
* @returns Promise resolving to the title ID schema
|
|
25
|
+
*/
|
|
26
|
+
async getTitleID(titleId) {
|
|
27
|
+
return this.client.get(`/title-ids/${titleId}`);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
TitleIDsAPI
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/title-ids/index.ts"],"sourcesContent":["import { SerialStationClient } from '../../client/BaseClient';\r\nimport { TitleIDSchema, PagedTitleIDSchema, TitleIDFilterParams } from './types';\r\n\r\n/**\r\n * API client for managing title ID information.\r\n * Provides methods to query and retrieve PlayStation title ID data.\r\n */\r\nexport class TitleIDsAPI {\r\n /**\r\n * Creates a new TitleIDsAPI instance.\r\n * \r\n * @param client - The SerialStation client instance to use for requests\r\n */\r\n constructor(private client: SerialStationClient) {}\r\n \r\n /**\r\n * Lists title IDs with optional filtering and pagination.\r\n * \r\n * @param params - Optional parameters for filtering and pagination\r\n * @returns Promise resolving to a paginated list of title IDs\r\n */\r\n async listTitleIDs(params?: TitleIDFilterParams): Promise<PagedTitleIDSchema> {\r\n return this.client.get<PagedTitleIDSchema>('/title-ids/', params);\r\n }\r\n \r\n /**\r\n * Retrieves title ID information by its unique identifier.\r\n * \r\n * @param titleId - The unique title ID (hexadecimal string)\r\n * @returns Promise resolving to the title ID schema\r\n */\r\n async getTitleID(titleId: string): Promise<TitleIDSchema> {\r\n return this.client.get<TitleIDSchema>(`/title-ids/${titleId}`);\r\n }\r\n}"],"mappings":";AAOO,IAAM,cAAN,MAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,YAAoB,QAA6B;AAA7B;AAAA,EAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQlD,MAAM,aAAa,QAA2D;AAC5E,WAAO,KAAK,OAAO,IAAwB,eAAe,MAAM;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,SAAyC;AACxD,WAAO,KAAK,OAAO,IAAmB,cAAc,OAAO,EAAE;AAAA,EAC/D;AACF;","names":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the SerialStation API client.
|
|
3
|
+
*/
|
|
4
|
+
interface SerialStationClientConfig {
|
|
5
|
+
/** Base URL for API requests. Defaults to 'https://api.serialstation.com/v1' */
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
/** Request timeout in milliseconds. Defaults to 10000 */
|
|
8
|
+
timeout?: number;
|
|
9
|
+
/** Additional HTTP headers to include with requests */
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
/** Number of retry attempts for failed requests. Defaults to 3 */
|
|
12
|
+
retries?: number;
|
|
13
|
+
/** Delay between retries in milliseconds. Defaults to 1000 */
|
|
14
|
+
retryDelay?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Base HTTP client for making requests to the SerialStation API.
|
|
18
|
+
* Handles retries, error handling, and request configuration.
|
|
19
|
+
*/
|
|
20
|
+
declare class SerialStationClient {
|
|
21
|
+
private client;
|
|
22
|
+
private retries;
|
|
23
|
+
private retryDelay;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new SerialStationClient instance.
|
|
26
|
+
*
|
|
27
|
+
* @param config - Configuration options for the client
|
|
28
|
+
*/
|
|
29
|
+
constructor(config?: SerialStationClientConfig);
|
|
30
|
+
/**
|
|
31
|
+
* Retries a failed request with exponential backoff.
|
|
32
|
+
*
|
|
33
|
+
* @param config - The Axios request configuration to retry
|
|
34
|
+
* @param retryCount - Current retry attempt number
|
|
35
|
+
* @returns Promise resolving to the Axios response
|
|
36
|
+
* @throws Error if max retries exceeded
|
|
37
|
+
*/
|
|
38
|
+
private retryRequest;
|
|
39
|
+
/**
|
|
40
|
+
* Performs a GET request to the specified endpoint.
|
|
41
|
+
*
|
|
42
|
+
* @param endpoint - The API endpoint path
|
|
43
|
+
* @param params - Query parameters to include in the request
|
|
44
|
+
* @returns Promise resolving to the response data
|
|
45
|
+
*/
|
|
46
|
+
get<T>(endpoint: string, params?: any): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Performs a POST request to the specified endpoint.
|
|
49
|
+
*
|
|
50
|
+
* @param endpoint - The API endpoint path
|
|
51
|
+
* @param data - Request body data
|
|
52
|
+
* @returns Promise resolving to the response data
|
|
53
|
+
*/
|
|
54
|
+
post<T>(endpoint: string, data?: any): Promise<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Updates the base URL for all subsequent requests.
|
|
57
|
+
*
|
|
58
|
+
* @param baseURL - The new base URL
|
|
59
|
+
*/
|
|
60
|
+
setBaseURL(baseURL: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Sets a header value for all subsequent requests.
|
|
63
|
+
*
|
|
64
|
+
* @param key - Header name
|
|
65
|
+
* @param value - Header value
|
|
66
|
+
*/
|
|
67
|
+
setHeader(key: string, value: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Removes a header from all subsequent requests.
|
|
70
|
+
*
|
|
71
|
+
* @param key - Header name to remove
|
|
72
|
+
*/
|
|
73
|
+
removeHeader(key: string): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { SerialStationClient, type SerialStationClientConfig };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the SerialStation API client.
|
|
3
|
+
*/
|
|
4
|
+
interface SerialStationClientConfig {
|
|
5
|
+
/** Base URL for API requests. Defaults to 'https://api.serialstation.com/v1' */
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
/** Request timeout in milliseconds. Defaults to 10000 */
|
|
8
|
+
timeout?: number;
|
|
9
|
+
/** Additional HTTP headers to include with requests */
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
/** Number of retry attempts for failed requests. Defaults to 3 */
|
|
12
|
+
retries?: number;
|
|
13
|
+
/** Delay between retries in milliseconds. Defaults to 1000 */
|
|
14
|
+
retryDelay?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Base HTTP client for making requests to the SerialStation API.
|
|
18
|
+
* Handles retries, error handling, and request configuration.
|
|
19
|
+
*/
|
|
20
|
+
declare class SerialStationClient {
|
|
21
|
+
private client;
|
|
22
|
+
private retries;
|
|
23
|
+
private retryDelay;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new SerialStationClient instance.
|
|
26
|
+
*
|
|
27
|
+
* @param config - Configuration options for the client
|
|
28
|
+
*/
|
|
29
|
+
constructor(config?: SerialStationClientConfig);
|
|
30
|
+
/**
|
|
31
|
+
* Retries a failed request with exponential backoff.
|
|
32
|
+
*
|
|
33
|
+
* @param config - The Axios request configuration to retry
|
|
34
|
+
* @param retryCount - Current retry attempt number
|
|
35
|
+
* @returns Promise resolving to the Axios response
|
|
36
|
+
* @throws Error if max retries exceeded
|
|
37
|
+
*/
|
|
38
|
+
private retryRequest;
|
|
39
|
+
/**
|
|
40
|
+
* Performs a GET request to the specified endpoint.
|
|
41
|
+
*
|
|
42
|
+
* @param endpoint - The API endpoint path
|
|
43
|
+
* @param params - Query parameters to include in the request
|
|
44
|
+
* @returns Promise resolving to the response data
|
|
45
|
+
*/
|
|
46
|
+
get<T>(endpoint: string, params?: any): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Performs a POST request to the specified endpoint.
|
|
49
|
+
*
|
|
50
|
+
* @param endpoint - The API endpoint path
|
|
51
|
+
* @param data - Request body data
|
|
52
|
+
* @returns Promise resolving to the response data
|
|
53
|
+
*/
|
|
54
|
+
post<T>(endpoint: string, data?: any): Promise<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Updates the base URL for all subsequent requests.
|
|
57
|
+
*
|
|
58
|
+
* @param baseURL - The new base URL
|
|
59
|
+
*/
|
|
60
|
+
setBaseURL(baseURL: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Sets a header value for all subsequent requests.
|
|
63
|
+
*
|
|
64
|
+
* @param key - Header name
|
|
65
|
+
* @param value - Header value
|
|
66
|
+
*/
|
|
67
|
+
setHeader(key: string, value: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Removes a header from all subsequent requests.
|
|
70
|
+
*
|
|
71
|
+
* @param key - Header name to remove
|
|
72
|
+
*/
|
|
73
|
+
removeHeader(key: string): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { SerialStationClient, type SerialStationClientConfig };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/client/BaseClient.ts
|
|
31
|
+
var BaseClient_exports = {};
|
|
32
|
+
__export(BaseClient_exports, {
|
|
33
|
+
SerialStationClient: () => SerialStationClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(BaseClient_exports);
|
|
36
|
+
var import_axios = __toESM(require("axios"));
|
|
37
|
+
var SerialStationClient = class {
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new SerialStationClient instance.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Configuration options for the client
|
|
42
|
+
*/
|
|
43
|
+
constructor(config = {}) {
|
|
44
|
+
this.client = import_axios.default.create({
|
|
45
|
+
baseURL: config.baseURL || "https://api.serialstation.com/v1",
|
|
46
|
+
timeout: config.timeout || 1e4,
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
"Accept": "application/json",
|
|
50
|
+
...config.headers
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.retries = config.retries || 3;
|
|
54
|
+
this.retryDelay = config.retryDelay || 1e3;
|
|
55
|
+
this.client.interceptors.response.use(
|
|
56
|
+
(response) => response,
|
|
57
|
+
async (error) => {
|
|
58
|
+
if (error.response?.status && (error.response?.status === 429 || error.response?.status >= 500)) {
|
|
59
|
+
return this.retryRequest(error.config);
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Retries a failed request with exponential backoff.
|
|
67
|
+
*
|
|
68
|
+
* @param config - The Axios request configuration to retry
|
|
69
|
+
* @param retryCount - Current retry attempt number
|
|
70
|
+
* @returns Promise resolving to the Axios response
|
|
71
|
+
* @throws Error if max retries exceeded
|
|
72
|
+
*/
|
|
73
|
+
async retryRequest(config, retryCount = 0) {
|
|
74
|
+
if (retryCount >= this.retries) {
|
|
75
|
+
throw new Error(`Max retries (${this.retries}) exceeded`);
|
|
76
|
+
}
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, this.retryDelay * (retryCount + 1)));
|
|
78
|
+
try {
|
|
79
|
+
return await this.client.request(config);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return this.retryRequest(config, retryCount + 1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Performs a GET request to the specified endpoint.
|
|
86
|
+
*
|
|
87
|
+
* @param endpoint - The API endpoint path
|
|
88
|
+
* @param params - Query parameters to include in the request
|
|
89
|
+
* @returns Promise resolving to the response data
|
|
90
|
+
*/
|
|
91
|
+
async get(endpoint, params) {
|
|
92
|
+
const response = await this.client.get(endpoint, { params });
|
|
93
|
+
return response.data;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Performs a POST request to the specified endpoint.
|
|
97
|
+
*
|
|
98
|
+
* @param endpoint - The API endpoint path
|
|
99
|
+
* @param data - Request body data
|
|
100
|
+
* @returns Promise resolving to the response data
|
|
101
|
+
*/
|
|
102
|
+
async post(endpoint, data) {
|
|
103
|
+
const response = await this.client.post(endpoint, data);
|
|
104
|
+
return response.data;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Updates the base URL for all subsequent requests.
|
|
108
|
+
*
|
|
109
|
+
* @param baseURL - The new base URL
|
|
110
|
+
*/
|
|
111
|
+
setBaseURL(baseURL) {
|
|
112
|
+
this.client.defaults.baseURL = baseURL;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Sets a header value for all subsequent requests.
|
|
116
|
+
*
|
|
117
|
+
* @param key - Header name
|
|
118
|
+
* @param value - Header value
|
|
119
|
+
*/
|
|
120
|
+
setHeader(key, value) {
|
|
121
|
+
this.client.defaults.headers.common[key] = value;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Removes a header from all subsequent requests.
|
|
125
|
+
*
|
|
126
|
+
* @param key - Header name to remove
|
|
127
|
+
*/
|
|
128
|
+
removeHeader(key) {
|
|
129
|
+
delete this.client.defaults.headers.common[key];
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
SerialStationClient
|
|
135
|
+
});
|
|
136
|
+
//# sourceMappingURL=BaseClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/BaseClient.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';\r\n\r\n/**\r\n * Configuration options for the SerialStation API client.\r\n */\r\nexport interface SerialStationClientConfig {\r\n /** Base URL for API requests. Defaults to 'https://api.serialstation.com/v1' */\r\n baseURL?: string;\r\n /** Request timeout in milliseconds. Defaults to 10000 */\r\n timeout?: number;\r\n /** Additional HTTP headers to include with requests */\r\n headers?: Record<string, string>;\r\n /** Number of retry attempts for failed requests. Defaults to 3 */\r\n retries?: number;\r\n /** Delay between retries in milliseconds. Defaults to 1000 */\r\n retryDelay?: number;\r\n}\r\n\r\n/**\r\n * Base HTTP client for making requests to the SerialStation API.\r\n * Handles retries, error handling, and request configuration.\r\n */\r\nexport class SerialStationClient {\r\n private client: AxiosInstance;\r\n private retries: number;\r\n private retryDelay: number;\r\n\r\n /**\r\n * Creates a new SerialStationClient instance.\r\n * \r\n * @param config - Configuration options for the client\r\n */\r\n constructor(config: SerialStationClientConfig = {}) {\r\n this.client = axios.create({\r\n baseURL: config.baseURL || 'https://api.serialstation.com/v1',\r\n timeout: config.timeout || 10000,\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n 'Accept': 'application/json',\r\n ...config.headers\r\n }\r\n });\r\n\r\n this.retries = config.retries || 3;\r\n this.retryDelay = config.retryDelay || 1000;\r\n\r\n this.client.interceptors.response.use(\r\n (response) => response,\r\n async (error: AxiosError) => {\r\n if (error.response?.status && (error.response?.status === 429 || error.response?.status >= 500)) {\r\n return this.retryRequest(error.config!);\r\n }\r\n throw error;\r\n }\r\n );\r\n }\r\n\r\n /**\r\n * Retries a failed request with exponential backoff.\r\n * \r\n * @param config - The Axios request configuration to retry\r\n * @param retryCount - Current retry attempt number\r\n * @returns Promise resolving to the Axios response\r\n * @throws Error if max retries exceeded\r\n */\r\n private async retryRequest(config: AxiosRequestConfig, retryCount = 0): Promise<AxiosResponse> {\r\n if (retryCount >= this.retries) {\r\n throw new Error(`Max retries (${this.retries}) exceeded`);\r\n }\r\n\r\n await new Promise(resolve => setTimeout(resolve, this.retryDelay * (retryCount + 1)));\r\n\r\n try {\r\n return await this.client.request(config);\r\n } catch (error) {\r\n return this.retryRequest(config, retryCount + 1);\r\n }\r\n }\r\n\r\n /**\r\n * Performs a GET request to the specified endpoint.\r\n * \r\n * @param endpoint - The API endpoint path\r\n * @param params - Query parameters to include in the request\r\n * @returns Promise resolving to the response data\r\n */\r\n async get<T>(endpoint: string, params?: any): Promise<T> {\r\n const response: AxiosResponse<T> = await this.client.get(endpoint, { params });\r\n return response.data;\r\n }\r\n\r\n /**\r\n * Performs a POST request to the specified endpoint.\r\n * \r\n * @param endpoint - The API endpoint path\r\n * @param data - Request body data\r\n * @returns Promise resolving to the response data\r\n */\r\n async post<T>(endpoint: string, data?: any): Promise<T> {\r\n const response: AxiosResponse<T> = await this.client.post(endpoint, data);\r\n return response.data;\r\n }\r\n\r\n /**\r\n * Updates the base URL for all subsequent requests.\r\n * \r\n * @param baseURL - The new base URL\r\n */\r\n setBaseURL(baseURL: string): void {\r\n this.client.defaults.baseURL = baseURL;\r\n }\r\n\r\n /**\r\n * Sets a header value for all subsequent requests.\r\n * \r\n * @param key - Header name\r\n * @param value - Header value\r\n */\r\n setHeader(key: string, value: string): void {\r\n this.client.defaults.headers.common[key] = value;\r\n }\r\n\r\n /**\r\n * Removes a header from all subsequent requests.\r\n * \r\n * @param key - Header name to remove\r\n */\r\n removeHeader(key: string): void {\r\n delete this.client.defaults.headers.common[key];\r\n }\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoF;AAsB7E,IAAM,sBAAN,MAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU7B,YAAY,SAAoC,CAAC,GAAG;AAChD,SAAK,SAAS,aAAAA,QAAM,OAAO;AAAA,MACvB,SAAS,OAAO,WAAW;AAAA,MAC3B,SAAS,OAAO,WAAW;AAAA,MAC3B,SAAS;AAAA,QACL,gBAAgB;AAAA,QAChB,UAAU;AAAA,QACV,GAAG,OAAO;AAAA,MACd;AAAA,IACJ,CAAC;AAED,SAAK,UAAU,OAAO,WAAW;AACjC,SAAK,aAAa,OAAO,cAAc;AAEvC,SAAK,OAAO,aAAa,SAAS;AAAA,MAC9B,CAAC,aAAa;AAAA,MACd,OAAO,UAAsB;AACzB,YAAI,MAAM,UAAU,WAAW,MAAM,UAAU,WAAW,OAAO,MAAM,UAAU,UAAU,MAAM;AAC7F,iBAAO,KAAK,aAAa,MAAM,MAAO;AAAA,QAC1C;AACA,cAAM;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAc,aAAa,QAA4B,aAAa,GAA2B;AAC3F,QAAI,cAAc,KAAK,SAAS;AAC5B,YAAM,IAAI,MAAM,gBAAgB,KAAK,OAAO,YAAY;AAAA,IAC5D;AAEA,UAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,KAAK,cAAc,aAAa,EAAE,CAAC;AAEpF,QAAI;AACA,aAAO,MAAM,KAAK,OAAO,QAAQ,MAAM;AAAA,IAC3C,SAAS,OAAO;AACZ,aAAO,KAAK,aAAa,QAAQ,aAAa,CAAC;AAAA,IACnD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,IAAO,UAAkB,QAA0B;AACrD,UAAM,WAA6B,MAAM,KAAK,OAAO,IAAI,UAAU,EAAE,OAAO,CAAC;AAC7E,WAAO,SAAS;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,KAAQ,UAAkB,MAAwB;AACpD,UAAM,WAA6B,MAAM,KAAK,OAAO,KAAK,UAAU,IAAI;AACxE,WAAO,SAAS;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,SAAuB;AAC9B,SAAK,OAAO,SAAS,UAAU;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAU,KAAa,OAAqB;AACxC,SAAK,OAAO,SAAS,QAAQ,OAAO,GAAG,IAAI;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,KAAmB;AAC5B,WAAO,KAAK,OAAO,SAAS,QAAQ,OAAO,GAAG;AAAA,EAClD;AACJ;","names":["axios"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// src/client/BaseClient.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
var SerialStationClient = class {
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new SerialStationClient instance.
|
|
6
|
+
*
|
|
7
|
+
* @param config - Configuration options for the client
|
|
8
|
+
*/
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
this.client = axios.create({
|
|
11
|
+
baseURL: config.baseURL || "https://api.serialstation.com/v1",
|
|
12
|
+
timeout: config.timeout || 1e4,
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
"Accept": "application/json",
|
|
16
|
+
...config.headers
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
this.retries = config.retries || 3;
|
|
20
|
+
this.retryDelay = config.retryDelay || 1e3;
|
|
21
|
+
this.client.interceptors.response.use(
|
|
22
|
+
(response) => response,
|
|
23
|
+
async (error) => {
|
|
24
|
+
if (error.response?.status && (error.response?.status === 429 || error.response?.status >= 500)) {
|
|
25
|
+
return this.retryRequest(error.config);
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retries a failed request with exponential backoff.
|
|
33
|
+
*
|
|
34
|
+
* @param config - The Axios request configuration to retry
|
|
35
|
+
* @param retryCount - Current retry attempt number
|
|
36
|
+
* @returns Promise resolving to the Axios response
|
|
37
|
+
* @throws Error if max retries exceeded
|
|
38
|
+
*/
|
|
39
|
+
async retryRequest(config, retryCount = 0) {
|
|
40
|
+
if (retryCount >= this.retries) {
|
|
41
|
+
throw new Error(`Max retries (${this.retries}) exceeded`);
|
|
42
|
+
}
|
|
43
|
+
await new Promise((resolve) => setTimeout(resolve, this.retryDelay * (retryCount + 1)));
|
|
44
|
+
try {
|
|
45
|
+
return await this.client.request(config);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return this.retryRequest(config, retryCount + 1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Performs a GET request to the specified endpoint.
|
|
52
|
+
*
|
|
53
|
+
* @param endpoint - The API endpoint path
|
|
54
|
+
* @param params - Query parameters to include in the request
|
|
55
|
+
* @returns Promise resolving to the response data
|
|
56
|
+
*/
|
|
57
|
+
async get(endpoint, params) {
|
|
58
|
+
const response = await this.client.get(endpoint, { params });
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Performs a POST request to the specified endpoint.
|
|
63
|
+
*
|
|
64
|
+
* @param endpoint - The API endpoint path
|
|
65
|
+
* @param data - Request body data
|
|
66
|
+
* @returns Promise resolving to the response data
|
|
67
|
+
*/
|
|
68
|
+
async post(endpoint, data) {
|
|
69
|
+
const response = await this.client.post(endpoint, data);
|
|
70
|
+
return response.data;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Updates the base URL for all subsequent requests.
|
|
74
|
+
*
|
|
75
|
+
* @param baseURL - The new base URL
|
|
76
|
+
*/
|
|
77
|
+
setBaseURL(baseURL) {
|
|
78
|
+
this.client.defaults.baseURL = baseURL;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Sets a header value for all subsequent requests.
|
|
82
|
+
*
|
|
83
|
+
* @param key - Header name
|
|
84
|
+
* @param value - Header value
|
|
85
|
+
*/
|
|
86
|
+
setHeader(key, value) {
|
|
87
|
+
this.client.defaults.headers.common[key] = value;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Removes a header from all subsequent requests.
|
|
91
|
+
*
|
|
92
|
+
* @param key - Header name to remove
|
|
93
|
+
*/
|
|
94
|
+
removeHeader(key) {
|
|
95
|
+
delete this.client.defaults.headers.common[key];
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
SerialStationClient
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=BaseClient.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/BaseClient.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';\r\n\r\n/**\r\n * Configuration options for the SerialStation API client.\r\n */\r\nexport interface SerialStationClientConfig {\r\n /** Base URL for API requests. Defaults to 'https://api.serialstation.com/v1' */\r\n baseURL?: string;\r\n /** Request timeout in milliseconds. Defaults to 10000 */\r\n timeout?: number;\r\n /** Additional HTTP headers to include with requests */\r\n headers?: Record<string, string>;\r\n /** Number of retry attempts for failed requests. Defaults to 3 */\r\n retries?: number;\r\n /** Delay between retries in milliseconds. Defaults to 1000 */\r\n retryDelay?: number;\r\n}\r\n\r\n/**\r\n * Base HTTP client for making requests to the SerialStation API.\r\n * Handles retries, error handling, and request configuration.\r\n */\r\nexport class SerialStationClient {\r\n private client: AxiosInstance;\r\n private retries: number;\r\n private retryDelay: number;\r\n\r\n /**\r\n * Creates a new SerialStationClient instance.\r\n * \r\n * @param config - Configuration options for the client\r\n */\r\n constructor(config: SerialStationClientConfig = {}) {\r\n this.client = axios.create({\r\n baseURL: config.baseURL || 'https://api.serialstation.com/v1',\r\n timeout: config.timeout || 10000,\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n 'Accept': 'application/json',\r\n ...config.headers\r\n }\r\n });\r\n\r\n this.retries = config.retries || 3;\r\n this.retryDelay = config.retryDelay || 1000;\r\n\r\n this.client.interceptors.response.use(\r\n (response) => response,\r\n async (error: AxiosError) => {\r\n if (error.response?.status && (error.response?.status === 429 || error.response?.status >= 500)) {\r\n return this.retryRequest(error.config!);\r\n }\r\n throw error;\r\n }\r\n );\r\n }\r\n\r\n /**\r\n * Retries a failed request with exponential backoff.\r\n * \r\n * @param config - The Axios request configuration to retry\r\n * @param retryCount - Current retry attempt number\r\n * @returns Promise resolving to the Axios response\r\n * @throws Error if max retries exceeded\r\n */\r\n private async retryRequest(config: AxiosRequestConfig, retryCount = 0): Promise<AxiosResponse> {\r\n if (retryCount >= this.retries) {\r\n throw new Error(`Max retries (${this.retries}) exceeded`);\r\n }\r\n\r\n await new Promise(resolve => setTimeout(resolve, this.retryDelay * (retryCount + 1)));\r\n\r\n try {\r\n return await this.client.request(config);\r\n } catch (error) {\r\n return this.retryRequest(config, retryCount + 1);\r\n }\r\n }\r\n\r\n /**\r\n * Performs a GET request to the specified endpoint.\r\n * \r\n * @param endpoint - The API endpoint path\r\n * @param params - Query parameters to include in the request\r\n * @returns Promise resolving to the response data\r\n */\r\n async get<T>(endpoint: string, params?: any): Promise<T> {\r\n const response: AxiosResponse<T> = await this.client.get(endpoint, { params });\r\n return response.data;\r\n }\r\n\r\n /**\r\n * Performs a POST request to the specified endpoint.\r\n * \r\n * @param endpoint - The API endpoint path\r\n * @param data - Request body data\r\n * @returns Promise resolving to the response data\r\n */\r\n async post<T>(endpoint: string, data?: any): Promise<T> {\r\n const response: AxiosResponse<T> = await this.client.post(endpoint, data);\r\n return response.data;\r\n }\r\n\r\n /**\r\n * Updates the base URL for all subsequent requests.\r\n * \r\n * @param baseURL - The new base URL\r\n */\r\n setBaseURL(baseURL: string): void {\r\n this.client.defaults.baseURL = baseURL;\r\n }\r\n\r\n /**\r\n * Sets a header value for all subsequent requests.\r\n * \r\n * @param key - Header name\r\n * @param value - Header value\r\n */\r\n setHeader(key: string, value: string): void {\r\n this.client.defaults.headers.common[key] = value;\r\n }\r\n\r\n /**\r\n * Removes a header from all subsequent requests.\r\n * \r\n * @param key - Header name to remove\r\n */\r\n removeHeader(key: string): void {\r\n delete this.client.defaults.headers.common[key];\r\n }\r\n}"],"mappings":";AAAA,OAAO,WAA6E;AAsB7E,IAAM,sBAAN,MAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU7B,YAAY,SAAoC,CAAC,GAAG;AAChD,SAAK,SAAS,MAAM,OAAO;AAAA,MACvB,SAAS,OAAO,WAAW;AAAA,MAC3B,SAAS,OAAO,WAAW;AAAA,MAC3B,SAAS;AAAA,QACL,gBAAgB;AAAA,QAChB,UAAU;AAAA,QACV,GAAG,OAAO;AAAA,MACd;AAAA,IACJ,CAAC;AAED,SAAK,UAAU,OAAO,WAAW;AACjC,SAAK,aAAa,OAAO,cAAc;AAEvC,SAAK,OAAO,aAAa,SAAS;AAAA,MAC9B,CAAC,aAAa;AAAA,MACd,OAAO,UAAsB;AACzB,YAAI,MAAM,UAAU,WAAW,MAAM,UAAU,WAAW,OAAO,MAAM,UAAU,UAAU,MAAM;AAC7F,iBAAO,KAAK,aAAa,MAAM,MAAO;AAAA,QAC1C;AACA,cAAM;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAc,aAAa,QAA4B,aAAa,GAA2B;AAC3F,QAAI,cAAc,KAAK,SAAS;AAC5B,YAAM,IAAI,MAAM,gBAAgB,KAAK,OAAO,YAAY;AAAA,IAC5D;AAEA,UAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,KAAK,cAAc,aAAa,EAAE,CAAC;AAEpF,QAAI;AACA,aAAO,MAAM,KAAK,OAAO,QAAQ,MAAM;AAAA,IAC3C,SAAS,OAAO;AACZ,aAAO,KAAK,aAAa,QAAQ,aAAa,CAAC;AAAA,IACnD;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,IAAO,UAAkB,QAA0B;AACrD,UAAM,WAA6B,MAAM,KAAK,OAAO,IAAI,UAAU,EAAE,OAAO,CAAC;AAC7E,WAAO,SAAS;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,KAAQ,UAAkB,MAAwB;AACpD,UAAM,WAA6B,MAAM,KAAK,OAAO,KAAK,UAAU,IAAI;AACxE,WAAO,SAAS;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,WAAW,SAAuB;AAC9B,SAAK,OAAO,SAAS,UAAU;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAU,KAAa,OAAqB;AACxC,SAAK,OAAO,SAAS,QAAQ,OAAO,GAAG,IAAI;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,aAAa,KAAmB;AAC5B,WAAO,KAAK,OAAO,SAAS,QAAQ,OAAO,GAAG;AAAA,EAClD;AACJ;","names":[]}
|