torn-client 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Torn API Client
2
2
 
3
3
 
4
- [![API Compatibility](https://img.shields.io/badge/Torn%20API-3.0.0-62a03f)](https://www.torn.com/api.html)
4
+ [![API Compatibility](https://img.shields.io/badge/dynamic/regex?url=https%3A%2F%2Fraw.githubusercontent.com%2Fneon0404%2Ftorn-client%2Fmain%2F.torn-api-version&search=.*&label=Torn%20API&color=62a03f)](https://www.torn.com/api.html)
5
5
  [![NPM Version](https://img.shields.io/npm/v/torn-client.svg)](https://www.npmjs.com/package/torn-client)
6
6
  [![License](https://img.shields.io/npm/l/torn-client?color=62a03f)](https://github.com/neon0404/torn-client/blob/main/LICENSE)
7
7
  [![PRs](https://img.shields.io/badge/PRs-welcome-blue)](https://github.com/neon0404/torn-client/pulls)
@@ -10,18 +10,19 @@ A TypeScript-first, auto-generated client for the [Torn City v2 API](https://www
10
10
 
11
11
  This client provides full type safety, built-in rate limiting and automatic multi-key balancing to simplify interactions with the Torn API
12
12
 
13
- > **⚠️ Warning**
13
+ > **⚠️ Warning**
14
+ >
14
15
  > The Torn v2 API is under active development and changes frequently
15
- > This client is also a work in progress and may contain bugs
16
+ > This client is also a work in progress, use with caution
16
17
  >
17
18
  > Some multi-selection endpoints like `/user` - are not yet fully tested and may behave unexpectedly
18
19
 
19
20
 
20
21
  ## Features
21
22
 
22
- - **Fully Typed**: Provides strong type safety and autocompletion for all API methods and responses
23
+ - **Fully Typed**: Provides strong type safety and autocompletion for API methods and responses
23
24
  - **Cross-Environment**: Works seamlessly in both Node.js and browser environments
24
- - **Zero Dependencies**: No external dependencies, ensuring a lightweight footprint and easy integration
25
+ - **Zero Runtime Dependencies**: No external dependencies, ensuring a lightweight footprint and easy integration
25
26
  - **Multi-Key Management**: Automatically balances requests across multiple API keys using round-robin or random strategies
26
27
  - **Built-in Rate Limiting**: Avoids hitting the API limit by auto-delaying requests
27
28
  - **Robust Pagination**: Simple `.next()` and `.prev()` methods are always available on paginated API responses
@@ -44,7 +45,7 @@ You can also use `torn-client` directly in a browser without any build tools by
44
45
 
45
46
  ```html
46
47
  <script type="module">
47
- import { TornAPI, TornApiError } from 'https://unpkg.com/torn-client/dist/index.mjs';
48
+ import { TornAPI } from 'https://unpkg.com/torn-client/dist/index.mjs';
48
49
 
49
50
  const client = new TornAPI({ apiKeys: ['YOUR_API_KEY'] });
50
51
  </script>
@@ -102,7 +103,7 @@ For information about Torn API endpoints and parameters, see the [official Torn
102
103
  ## Contributing
103
104
 
104
105
  Contributions, issues, and feature requests are welcome!
105
- Please feel free to open an issue or submit a pull request on GitHub
106
+ Feel free to open an issue or submit a pull request on GitHub
106
107
  Please read [contributing guide](https://github.com/neon0404/torn-client/blob/main/CONTRIBUTING.md) first
107
108
 
108
109
  ## Contact
package/dist/index.d.mts CHANGED
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * Defines the rate limit handling strategy for API requests
3
+ *
4
+ * @category Core
3
5
  */
4
6
  type RateLimitMode = "autoDelay" | "throwOnLimit" | "ignore";
5
7
  /**
6
8
  * Defines the algorithm for distributing requests across multiple API keys
9
+ *
10
+ * @category Core
7
11
  */
8
12
  type ApiKeyBalancing = "roundRobin" | "random";
9
13
  /**
@@ -14,6 +18,8 @@ type ApiKeyBalancing = "roundRobin" | "random";
14
18
  * @param path The API endpoint path (e.g., "/user/profile")
15
19
  * @param params The query parameters for the request
16
20
  * @returns A Promise that resolves to the response data of type T
21
+ *
22
+ * @category Core
17
23
  */
18
24
  type Requester = <T = unknown>(path: string, params: Record<string, unknown>) => Promise<T>;
19
25
 
@@ -23,6 +29,8 @@ type Requester = <T = unknown>(path: string, params: Record<string, unknown>) =>
23
29
  * The properties of the current page's data are directly accessible on instances of this class
24
30
  *
25
31
  * @template T The type of the data within the paginated response
32
+ *
33
+ * @category Core
26
34
  */
27
35
  declare class PaginatedResponse<T> {
28
36
  private readonly nextUrl;
@@ -3953,7 +3961,7 @@ declare class FactionEndpoint {
3953
3961
  withTerritoryWarId(territoryWarId: string | number): FactionTerritoryWarIdContext;
3954
3962
  }
3955
3963
  /**
3956
- * Context class for Faction API endpoints that require a 'id'
3964
+ * Context class for Faction API endpoints that require a "id"
3957
3965
  * @category Endpoints
3958
3966
  */
3959
3967
  declare class FactionIdContext {
@@ -4039,7 +4047,7 @@ declare class FactionIdContext {
4039
4047
  get(): Promise<Faction>;
4040
4048
  }
4041
4049
  /**
4042
- * Context class for Faction API endpoints that require a 'chainId'
4050
+ * Context class for Faction API endpoints that require a "chainId"
4043
4051
  * @category Endpoints
4044
4052
  */
4045
4053
  declare class FactionChainIdContext {
@@ -4055,7 +4063,7 @@ declare class FactionChainIdContext {
4055
4063
  }): Promise<FactionChainReportResponse>;
4056
4064
  }
4057
4065
  /**
4058
- * Context class for Faction API endpoints that require a 'crimeId'
4066
+ * Context class for Faction API endpoints that require a "crimeId"
4059
4067
  * @category Endpoints
4060
4068
  */
4061
4069
  declare class FactionCrimeIdContext {
@@ -4071,7 +4079,7 @@ declare class FactionCrimeIdContext {
4071
4079
  }): Promise<FactionCrimeResponse>;
4072
4080
  }
4073
4081
  /**
4074
- * Context class for Faction API endpoints that require a 'raidWarId'
4082
+ * Context class for Faction API endpoints that require a "raidWarId"
4075
4083
  * @category Endpoints
4076
4084
  */
4077
4085
  declare class FactionRaidWarIdContext {
@@ -4087,7 +4095,7 @@ declare class FactionRaidWarIdContext {
4087
4095
  }): Promise<FactionRaidWarReportResponse>;
4088
4096
  }
4089
4097
  /**
4090
- * Context class for Faction API endpoints that require a 'rankedWarId'
4098
+ * Context class for Faction API endpoints that require a "rankedWarId"
4091
4099
  * @category Endpoints
4092
4100
  */
4093
4101
  declare class FactionRankedWarIdContext {
@@ -4103,7 +4111,7 @@ declare class FactionRankedWarIdContext {
4103
4111
  }): Promise<FactionRankedWarReportResponse>;
4104
4112
  }
4105
4113
  /**
4106
- * Context class for Faction API endpoints that require a 'territoryWarId'
4114
+ * Context class for Faction API endpoints that require a "territoryWarId"
4107
4115
  * @category Endpoints
4108
4116
  */
4109
4117
  declare class FactionTerritoryWarIdContext {
@@ -4179,7 +4187,7 @@ declare class ForumEndpoint {
4179
4187
  withCategoryIds(categoryIds: string | number): ForumCategoryIdsContext;
4180
4188
  }
4181
4189
  /**
4182
- * Context class for Forum API endpoints that require a 'threadId'
4190
+ * Context class for Forum API endpoints that require a "threadId"
4183
4191
  * @category Endpoints
4184
4192
  */
4185
4193
  declare class ForumThreadIdContext {
@@ -4204,7 +4212,7 @@ declare class ForumThreadIdContext {
4204
4212
  }): Promise<ForumThreadResponse>;
4205
4213
  }
4206
4214
  /**
4207
- * Context class for Forum API endpoints that require a 'categoryIds'
4215
+ * Context class for Forum API endpoints that require a "categoryIds"
4208
4216
  * @category Endpoints
4209
4217
  */
4210
4218
  declare class ForumCategoryIdsContext {
@@ -4308,7 +4316,7 @@ declare class MarketEndpoint {
4308
4316
  withPropertyTypeId(propertyTypeId: string | number): MarketPropertyTypeIdContext;
4309
4317
  }
4310
4318
  /**
4311
- * Context class for Market API endpoints that require a 'id'
4319
+ * Context class for Market API endpoints that require a "id"
4312
4320
  * @category Endpoints
4313
4321
  */
4314
4322
  declare class MarketIdContext {
@@ -4333,7 +4341,7 @@ declare class MarketIdContext {
4333
4341
  }): Promise<PaginatedResponse<MarketItemMarketResponse> & MarketItemMarketResponse>;
4334
4342
  }
4335
4343
  /**
4336
- * Context class for Market API endpoints that require a 'propertyTypeId'
4344
+ * Context class for Market API endpoints that require a "propertyTypeId"
4337
4345
  * @category Endpoints
4338
4346
  */
4339
4347
  declare class MarketPropertyTypeIdContext {
@@ -4396,7 +4404,7 @@ declare class PropertyEndpoint {
4396
4404
  }): Promise<PropertyResponse>;
4397
4405
  }
4398
4406
  /**
4399
- * Context class for Property API endpoints that require a 'id'
4407
+ * Context class for Property API endpoints that require a "id"
4400
4408
  * @category Endpoints
4401
4409
  */
4402
4410
  declare class PropertyIdContext {
@@ -4487,7 +4495,7 @@ declare class RacingEndpoint {
4487
4495
  withTrackId(trackId: string | number): RacingTrackIdContext;
4488
4496
  }
4489
4497
  /**
4490
- * Context class for Racing API endpoints that require a 'raceId'
4498
+ * Context class for Racing API endpoints that require a "raceId"
4491
4499
  * @category Endpoints
4492
4500
  */
4493
4501
  declare class RacingRaceIdContext {
@@ -4503,7 +4511,7 @@ declare class RacingRaceIdContext {
4503
4511
  }): Promise<RacingRaceDetailsResponse>;
4504
4512
  }
4505
4513
  /**
4506
- * Context class for Racing API endpoints that require a 'trackId'
4514
+ * Context class for Racing API endpoints that require a "trackId"
4507
4515
  * @category Endpoints
4508
4516
  */
4509
4517
  declare class RacingTrackIdContext {
@@ -4694,7 +4702,7 @@ declare class TornEndpoint {
4694
4702
  withCrimeId(crimeId: string | number): TornCrimeIdContext;
4695
4703
  }
4696
4704
  /**
4697
- * Context class for Torn API endpoints that require a 'ids'
4705
+ * Context class for Torn API endpoints that require a "ids"
4698
4706
  * @category Endpoints
4699
4707
  */
4700
4708
  declare class TornIdsContext {
@@ -4711,7 +4719,7 @@ declare class TornIdsContext {
4711
4719
  }): Promise<TornItemsResponse>;
4712
4720
  }
4713
4721
  /**
4714
- * Context class for Torn API endpoints that require a 'logCategoryId'
4722
+ * Context class for Torn API endpoints that require a "logCategoryId"
4715
4723
  * @category Endpoints
4716
4724
  */
4717
4725
  declare class TornLogCategoryIdContext {
@@ -4727,7 +4735,7 @@ declare class TornLogCategoryIdContext {
4727
4735
  }): Promise<TornLogTypesResponse>;
4728
4736
  }
4729
4737
  /**
4730
- * Context class for Torn API endpoints that require a 'crimeId'
4738
+ * Context class for Torn API endpoints that require a "crimeId"
4731
4739
  * @category Endpoints
4732
4740
  */
4733
4741
  declare class TornCrimeIdContext {
@@ -5007,7 +5015,7 @@ declare class UserEndpoint {
5007
5015
  withCrimeId(crimeId: string | number): UserCrimeIdContext;
5008
5016
  }
5009
5017
  /**
5010
- * Context class for User API endpoints that require a 'id'
5018
+ * Context class for User API endpoints that require a "id"
5011
5019
  * @category Endpoints
5012
5020
  */
5013
5021
  declare class UserIdContext {
@@ -5080,7 +5088,7 @@ declare class UserIdContext {
5080
5088
  get(): Promise<User>;
5081
5089
  }
5082
5090
  /**
5083
- * Context class for User API endpoints that require a 'crimeId'
5091
+ * Context class for User API endpoints that require a "crimeId"
5084
5092
  * @category Endpoints
5085
5093
  */
5086
5094
  declare class UserCrimeIdContext {
@@ -5135,9 +5143,9 @@ interface TornAPIOptions extends Omit<RequestHandlerOptions, "apiKeys"> {
5135
5143
  * ## Example
5136
5144
  * ```
5137
5145
  * const client = new TornAPI({
5138
- * apiKeys: ['YOUR_API_KEY1', 'YOUR_API_KEY2'],
5139
- * comment: 'my-app',
5140
- * rateLimitMode: 'autoDelay',
5146
+ * apiKeys: ["YOUR_API_KEY1", "YOUR_API_KEY2"],
5147
+ * comment: "my-app",
5148
+ * rateLimitMode: "autoDelay",
5141
5149
  * verbose: true,
5142
5150
  * });
5143
5151
  *
package/dist/index.d.ts CHANGED
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * Defines the rate limit handling strategy for API requests
3
+ *
4
+ * @category Core
3
5
  */
4
6
  type RateLimitMode = "autoDelay" | "throwOnLimit" | "ignore";
5
7
  /**
6
8
  * Defines the algorithm for distributing requests across multiple API keys
9
+ *
10
+ * @category Core
7
11
  */
8
12
  type ApiKeyBalancing = "roundRobin" | "random";
9
13
  /**
@@ -14,6 +18,8 @@ type ApiKeyBalancing = "roundRobin" | "random";
14
18
  * @param path The API endpoint path (e.g., "/user/profile")
15
19
  * @param params The query parameters for the request
16
20
  * @returns A Promise that resolves to the response data of type T
21
+ *
22
+ * @category Core
17
23
  */
18
24
  type Requester = <T = unknown>(path: string, params: Record<string, unknown>) => Promise<T>;
19
25
 
@@ -23,6 +29,8 @@ type Requester = <T = unknown>(path: string, params: Record<string, unknown>) =>
23
29
  * The properties of the current page's data are directly accessible on instances of this class
24
30
  *
25
31
  * @template T The type of the data within the paginated response
32
+ *
33
+ * @category Core
26
34
  */
27
35
  declare class PaginatedResponse<T> {
28
36
  private readonly nextUrl;
@@ -3953,7 +3961,7 @@ declare class FactionEndpoint {
3953
3961
  withTerritoryWarId(territoryWarId: string | number): FactionTerritoryWarIdContext;
3954
3962
  }
3955
3963
  /**
3956
- * Context class for Faction API endpoints that require a 'id'
3964
+ * Context class for Faction API endpoints that require a "id"
3957
3965
  * @category Endpoints
3958
3966
  */
3959
3967
  declare class FactionIdContext {
@@ -4039,7 +4047,7 @@ declare class FactionIdContext {
4039
4047
  get(): Promise<Faction>;
4040
4048
  }
4041
4049
  /**
4042
- * Context class for Faction API endpoints that require a 'chainId'
4050
+ * Context class for Faction API endpoints that require a "chainId"
4043
4051
  * @category Endpoints
4044
4052
  */
4045
4053
  declare class FactionChainIdContext {
@@ -4055,7 +4063,7 @@ declare class FactionChainIdContext {
4055
4063
  }): Promise<FactionChainReportResponse>;
4056
4064
  }
4057
4065
  /**
4058
- * Context class for Faction API endpoints that require a 'crimeId'
4066
+ * Context class for Faction API endpoints that require a "crimeId"
4059
4067
  * @category Endpoints
4060
4068
  */
4061
4069
  declare class FactionCrimeIdContext {
@@ -4071,7 +4079,7 @@ declare class FactionCrimeIdContext {
4071
4079
  }): Promise<FactionCrimeResponse>;
4072
4080
  }
4073
4081
  /**
4074
- * Context class for Faction API endpoints that require a 'raidWarId'
4082
+ * Context class for Faction API endpoints that require a "raidWarId"
4075
4083
  * @category Endpoints
4076
4084
  */
4077
4085
  declare class FactionRaidWarIdContext {
@@ -4087,7 +4095,7 @@ declare class FactionRaidWarIdContext {
4087
4095
  }): Promise<FactionRaidWarReportResponse>;
4088
4096
  }
4089
4097
  /**
4090
- * Context class for Faction API endpoints that require a 'rankedWarId'
4098
+ * Context class for Faction API endpoints that require a "rankedWarId"
4091
4099
  * @category Endpoints
4092
4100
  */
4093
4101
  declare class FactionRankedWarIdContext {
@@ -4103,7 +4111,7 @@ declare class FactionRankedWarIdContext {
4103
4111
  }): Promise<FactionRankedWarReportResponse>;
4104
4112
  }
4105
4113
  /**
4106
- * Context class for Faction API endpoints that require a 'territoryWarId'
4114
+ * Context class for Faction API endpoints that require a "territoryWarId"
4107
4115
  * @category Endpoints
4108
4116
  */
4109
4117
  declare class FactionTerritoryWarIdContext {
@@ -4179,7 +4187,7 @@ declare class ForumEndpoint {
4179
4187
  withCategoryIds(categoryIds: string | number): ForumCategoryIdsContext;
4180
4188
  }
4181
4189
  /**
4182
- * Context class for Forum API endpoints that require a 'threadId'
4190
+ * Context class for Forum API endpoints that require a "threadId"
4183
4191
  * @category Endpoints
4184
4192
  */
4185
4193
  declare class ForumThreadIdContext {
@@ -4204,7 +4212,7 @@ declare class ForumThreadIdContext {
4204
4212
  }): Promise<ForumThreadResponse>;
4205
4213
  }
4206
4214
  /**
4207
- * Context class for Forum API endpoints that require a 'categoryIds'
4215
+ * Context class for Forum API endpoints that require a "categoryIds"
4208
4216
  * @category Endpoints
4209
4217
  */
4210
4218
  declare class ForumCategoryIdsContext {
@@ -4308,7 +4316,7 @@ declare class MarketEndpoint {
4308
4316
  withPropertyTypeId(propertyTypeId: string | number): MarketPropertyTypeIdContext;
4309
4317
  }
4310
4318
  /**
4311
- * Context class for Market API endpoints that require a 'id'
4319
+ * Context class for Market API endpoints that require a "id"
4312
4320
  * @category Endpoints
4313
4321
  */
4314
4322
  declare class MarketIdContext {
@@ -4333,7 +4341,7 @@ declare class MarketIdContext {
4333
4341
  }): Promise<PaginatedResponse<MarketItemMarketResponse> & MarketItemMarketResponse>;
4334
4342
  }
4335
4343
  /**
4336
- * Context class for Market API endpoints that require a 'propertyTypeId'
4344
+ * Context class for Market API endpoints that require a "propertyTypeId"
4337
4345
  * @category Endpoints
4338
4346
  */
4339
4347
  declare class MarketPropertyTypeIdContext {
@@ -4396,7 +4404,7 @@ declare class PropertyEndpoint {
4396
4404
  }): Promise<PropertyResponse>;
4397
4405
  }
4398
4406
  /**
4399
- * Context class for Property API endpoints that require a 'id'
4407
+ * Context class for Property API endpoints that require a "id"
4400
4408
  * @category Endpoints
4401
4409
  */
4402
4410
  declare class PropertyIdContext {
@@ -4487,7 +4495,7 @@ declare class RacingEndpoint {
4487
4495
  withTrackId(trackId: string | number): RacingTrackIdContext;
4488
4496
  }
4489
4497
  /**
4490
- * Context class for Racing API endpoints that require a 'raceId'
4498
+ * Context class for Racing API endpoints that require a "raceId"
4491
4499
  * @category Endpoints
4492
4500
  */
4493
4501
  declare class RacingRaceIdContext {
@@ -4503,7 +4511,7 @@ declare class RacingRaceIdContext {
4503
4511
  }): Promise<RacingRaceDetailsResponse>;
4504
4512
  }
4505
4513
  /**
4506
- * Context class for Racing API endpoints that require a 'trackId'
4514
+ * Context class for Racing API endpoints that require a "trackId"
4507
4515
  * @category Endpoints
4508
4516
  */
4509
4517
  declare class RacingTrackIdContext {
@@ -4694,7 +4702,7 @@ declare class TornEndpoint {
4694
4702
  withCrimeId(crimeId: string | number): TornCrimeIdContext;
4695
4703
  }
4696
4704
  /**
4697
- * Context class for Torn API endpoints that require a 'ids'
4705
+ * Context class for Torn API endpoints that require a "ids"
4698
4706
  * @category Endpoints
4699
4707
  */
4700
4708
  declare class TornIdsContext {
@@ -4711,7 +4719,7 @@ declare class TornIdsContext {
4711
4719
  }): Promise<TornItemsResponse>;
4712
4720
  }
4713
4721
  /**
4714
- * Context class for Torn API endpoints that require a 'logCategoryId'
4722
+ * Context class for Torn API endpoints that require a "logCategoryId"
4715
4723
  * @category Endpoints
4716
4724
  */
4717
4725
  declare class TornLogCategoryIdContext {
@@ -4727,7 +4735,7 @@ declare class TornLogCategoryIdContext {
4727
4735
  }): Promise<TornLogTypesResponse>;
4728
4736
  }
4729
4737
  /**
4730
- * Context class for Torn API endpoints that require a 'crimeId'
4738
+ * Context class for Torn API endpoints that require a "crimeId"
4731
4739
  * @category Endpoints
4732
4740
  */
4733
4741
  declare class TornCrimeIdContext {
@@ -5007,7 +5015,7 @@ declare class UserEndpoint {
5007
5015
  withCrimeId(crimeId: string | number): UserCrimeIdContext;
5008
5016
  }
5009
5017
  /**
5010
- * Context class for User API endpoints that require a 'id'
5018
+ * Context class for User API endpoints that require a "id"
5011
5019
  * @category Endpoints
5012
5020
  */
5013
5021
  declare class UserIdContext {
@@ -5080,7 +5088,7 @@ declare class UserIdContext {
5080
5088
  get(): Promise<User>;
5081
5089
  }
5082
5090
  /**
5083
- * Context class for User API endpoints that require a 'crimeId'
5091
+ * Context class for User API endpoints that require a "crimeId"
5084
5092
  * @category Endpoints
5085
5093
  */
5086
5094
  declare class UserCrimeIdContext {
@@ -5135,9 +5143,9 @@ interface TornAPIOptions extends Omit<RequestHandlerOptions, "apiKeys"> {
5135
5143
  * ## Example
5136
5144
  * ```
5137
5145
  * const client = new TornAPI({
5138
- * apiKeys: ['YOUR_API_KEY1', 'YOUR_API_KEY2'],
5139
- * comment: 'my-app',
5140
- * rateLimitMode: 'autoDelay',
5146
+ * apiKeys: ["YOUR_API_KEY1", "YOUR_API_KEY2"],
5147
+ * comment: "my-app",
5148
+ * rateLimitMode: "autoDelay",
5141
5149
  * verbose: true,
5142
5150
  * });
5143
5151
  *