tornapi-typescript 4.2.1 → 4.2.2

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/index.d.ts CHANGED
@@ -1278,6 +1278,7 @@ export interface PersonalStatsCrimesV2 {
1278
1278
  cracking: number;
1279
1279
  forgery: number;
1280
1280
  scamming: number;
1281
+ arson: number;
1281
1282
  };
1282
1283
  version: string;
1283
1284
  }
@@ -1623,7 +1624,7 @@ export interface UserPersonalStatsFullPublic {
1623
1624
  }
1624
1625
  export type UserPersonalStatsResponse = UserPersonalStatsFull | UserPersonalStatsFullPublic | UserPersonalStatsPopular | UserPersonalStatsCategory | UserPersonalStatsHistoric;
1625
1626
  export type PersonalStatsCategoryEnum = "all" | "popular" | "attacking" | "battle_stats" | "jobs" | "trading" | "jail" | "hospital" | "finishing_hits" | "communication" | "crimes" | "bounties" | "investments" | "items" | "travel" | "drugs" | "missions" | "racing" | "networth" | "other" | "itemmarketcustomers" | "itemmarketsales" | "itemmarketrevenue" | "itemmarketfees";
1626
- export type PersonalStatsStatName = "attackswon" | "attackslost" | "attacksdraw" | "attacksassisted" | "defendswon" | "defendslost" | "defendsstalemated" | "elo" | "yourunaway" | "theyrunaway" | "unarmoredwon" | "bestkillstreak" | "attackhits" | "attackmisses" | "attackdamage" | "bestdamage" | "onehitkills" | "attackcriticalhits" | "roundsfired" | "specialammoused" | "hollowammoused" | "tracerammoused" | "piercingammoused" | "incendiaryammoused" | "attacksstealthed" | "retals" | "moneymugged" | "largestmug" | "itemslooted" | "highestbeaten" | "respectforfaction" | "rankedwarhits" | "raidhits" | "territoryjoins" | "territoryclears" | "territorytime" | "jobpointsused" | "trainsreceived" | "marketitemsbought" | "auctionswon" | "auctionsells" | "itemssent" | "trades" | "cityitemsbought" | "pointsbought" | "pointssold" | "bazaarcustomers" | "bazaarsales" | "bazaarprofit" | "jailed" | "peoplebusted" | "failedbusts" | "peoplebought" | "peopleboughtspent" | "hospital" | "medicalitemsused" | "bloodwithdrawn" | "reviveskill" | "revives" | "revivesreceived" | "heavyhits" | "machinehits" | "riflehits" | "smghits" | "shotgunhits" | "pistolhits" | "temphits" | "piercinghits" | "slashinghits" | "clubbinghits" | "mechanicalhits" | "h2hhits" | "mailssent" | "friendmailssent" | "factionmailssent" | "companymailssent" | "spousemailssent" | "classifiedadsplaced" | "personalsplaced" | "criminaloffensesold" | "sellillegalgoods" | "theftold" | "autotheftcrime" | "drugdealscrime" | "computercrime" | "fraudold" | "murdercrime" | "othercrime" | "organizedcrimes" | "bountiesplaced" | "totalbountyspent" | "bountiescollected" | "totalbountyreward" | "bountiesreceived" | "receivedbountyvalue" | "cityfinds" | "dumpfinds" | "itemsdumped" | "booksread" | "boostersused" | "consumablesused" | "candyused" | "alcoholused" | "energydrinkused" | "statenhancersused" | "eastereggsfound" | "eastereggsused" | "virusescoded" | "traveltimes" | "timespenttraveling" | "itemsboughtabroad" | "attackswonabroad" | "defendslostabroad" | "argtravel" | "mextravel" | "uaetravel" | "hawtravel" | "japtravel" | "uktravel" | "satravel" | "switravel" | "chitravel" | "cantravel" | "caytravel" | "drugsused" | "overdosed" | "rehabs" | "rehabcost" | "cantaken" | "exttaken" | "kettaken" | "lsdtaken" | "opitaken" | "pcptaken" | "shrtaken" | "spetaken" | "victaken" | "xantaken" | "missionscompleted" | "contractscompleted" | "dukecontractscompleted" | "missioncreditsearned" | "racingskill" | "racingpointsearned" | "racesentered" | "raceswon" | "networth" | "timeplayed" | "activestreak" | "bestactivestreak" | "awards" | "refills" | "nerverefills" | "tokenrefills" | "meritsbought" | "daysbeendonator" | "criminaloffenses" | "vandalism" | "theft" | "counterfeiting" | "fraud" | "illicitservices" | "cybercrime" | "extortion" | "illegalproduction" | "currentkillstreak" | "strength" | "defense" | "speed" | "dexterity" | "totalstats" | "manuallabor" | "intelligence" | "endurance" | "totalworkingstats" | "moneyinvested" | "investedprofit" | "investamount" | "banktimeleft" | "stockprofits" | "stocklosses" | "stockfees" | "stocknetprofits" | "stockpayouts" | "networthwallet" | "networthvault" | "networthbank" | "networthcayman" | "networthpoints" | "networthitems" | "networthdisplaycase" | "networthbazaar" | "networthitemmarket" | "networthproperties" | "networthstockmarket" | "networthauctionhouse" | "networthbookie" | "networthcompany" | "networthenlistedcars" | "networthpiggybank" | "networthpending" | "networthloan" | "networthunpaidfees" | "huntingskill" | "searchforcashskill" | "bootleggingskill" | "graffitiskill" | "shopliftingskill" | "pickpocketingskill" | "cardskimmingskill" | "burglaryskill" | "hustlingskill" | "disposalskill" | "crackingskill" | "forgeryskill" | "scammingskill";
1627
+ export type PersonalStatsStatName = "attackswon" | "attackslost" | "attacksdraw" | "attacksassisted" | "defendswon" | "defendslost" | "defendsstalemated" | "elo" | "yourunaway" | "theyrunaway" | "unarmoredwon" | "bestkillstreak" | "attackhits" | "attackmisses" | "attackdamage" | "bestdamage" | "onehitkills" | "attackcriticalhits" | "roundsfired" | "specialammoused" | "hollowammoused" | "tracerammoused" | "piercingammoused" | "incendiaryammoused" | "attacksstealthed" | "retals" | "moneymugged" | "largestmug" | "itemslooted" | "highestbeaten" | "respectforfaction" | "rankedwarhits" | "raidhits" | "territoryjoins" | "territoryclears" | "territorytime" | "jobpointsused" | "trainsreceived" | "marketitemsbought" | "auctionswon" | "auctionsells" | "itemssent" | "trades" | "cityitemsbought" | "pointsbought" | "pointssold" | "bazaarcustomers" | "bazaarsales" | "bazaarprofit" | "jailed" | "peoplebusted" | "failedbusts" | "peoplebought" | "peopleboughtspent" | "hospital" | "medicalitemsused" | "bloodwithdrawn" | "reviveskill" | "revives" | "revivesreceived" | "heavyhits" | "machinehits" | "riflehits" | "smghits" | "shotgunhits" | "pistolhits" | "temphits" | "piercinghits" | "slashinghits" | "clubbinghits" | "mechanicalhits" | "h2hhits" | "mailssent" | "friendmailssent" | "factionmailssent" | "companymailssent" | "spousemailssent" | "classifiedadsplaced" | "personalsplaced" | "criminaloffensesold" | "sellillegalgoods" | "theftold" | "autotheftcrime" | "drugdealscrime" | "computercrime" | "fraudold" | "murdercrime" | "othercrime" | "organizedcrimes" | "bountiesplaced" | "totalbountyspent" | "bountiescollected" | "totalbountyreward" | "bountiesreceived" | "receivedbountyvalue" | "cityfinds" | "dumpfinds" | "itemsdumped" | "booksread" | "boostersused" | "consumablesused" | "candyused" | "alcoholused" | "energydrinkused" | "statenhancersused" | "eastereggsfound" | "eastereggsused" | "virusescoded" | "traveltimes" | "timespenttraveling" | "itemsboughtabroad" | "attackswonabroad" | "defendslostabroad" | "argtravel" | "mextravel" | "uaetravel" | "hawtravel" | "japtravel" | "uktravel" | "satravel" | "switravel" | "chitravel" | "cantravel" | "caytravel" | "drugsused" | "overdosed" | "rehabs" | "rehabcost" | "cantaken" | "exttaken" | "kettaken" | "lsdtaken" | "opitaken" | "pcptaken" | "shrtaken" | "spetaken" | "victaken" | "xantaken" | "missionscompleted" | "contractscompleted" | "dukecontractscompleted" | "missioncreditsearned" | "racingskill" | "racingpointsearned" | "racesentered" | "raceswon" | "networth" | "timeplayed" | "activestreak" | "bestactivestreak" | "awards" | "refills" | "nerverefills" | "tokenrefills" | "meritsbought" | "daysbeendonator" | "criminaloffenses" | "vandalism" | "theft" | "counterfeiting" | "fraud" | "illicitservices" | "cybercrime" | "extortion" | "illegalproduction" | "currentkillstreak" | "strength" | "defense" | "speed" | "dexterity" | "totalstats" | "manuallabor" | "intelligence" | "endurance" | "totalworkingstats" | "moneyinvested" | "investedprofit" | "investamount" | "banktimeleft" | "stockprofits" | "stocklosses" | "stockfees" | "stocknetprofits" | "stockpayouts" | "networthwallet" | "networthvault" | "networthbank" | "networthcayman" | "networthpoints" | "networthitems" | "networthdisplaycase" | "networthbazaar" | "networthitemmarket" | "networthproperties" | "networthstockmarket" | "networthauctionhouse" | "networthbookie" | "networthcompany" | "networthenlistedcars" | "networthpiggybank" | "networthpending" | "networthloan" | "networthunpaidfees" | "huntingskill" | "searchforcashskill" | "bootleggingskill" | "graffitiskill" | "shopliftingskill" | "pickpocketingskill" | "cardskimmingskill" | "burglaryskill" | "hustlingskill" | "disposalskill" | "crackingskill" | "forgeryskill" | "scammingskill" | "arsonskill";
1627
1628
  export interface FactionRaidReport {
1628
1629
  id: RaidWarId;
1629
1630
  start: number;
@@ -2187,7 +2188,7 @@ export interface FactionCrimeSlot {
2187
2188
  position_number: number;
2188
2189
  item_requirement: {
2189
2190
  id: ItemId;
2190
- /** Shows if the item is reusable or consumed during the crime. */
2191
+ /** Shows if the item is reusable or consumed during the crime.<br><b>Important note: There may be alternative paths which won't consume the item, even if the item is non-reusable.</b> */
2191
2192
  is_reusable: boolean;
2192
2193
  /** Shows if user has the required item. */
2193
2194
  is_available: boolean;
@@ -2466,7 +2467,7 @@ export interface MarketRentalDetails {
2466
2467
  property: BasicProperty;
2467
2468
  }
2468
2469
  export interface MarketRentalsResponse {
2469
- properties: MarketRentalDetails;
2470
+ rentals: MarketRentalDetails;
2470
2471
  _metadata: RequestMetadataWithLinks;
2471
2472
  }
2472
2473
  export interface MarketPropertyDetails {
@@ -6952,6 +6953,15 @@ export type ParamsV1<Sec extends SectionV1, Sel extends SelectionV1<Sec>> = Sect
6952
6953
  export type ParamsV2<Sec extends SectionV2, Sel extends SelectionV2<Sec>> = SectionsV2Map[Sec]["selections"][Sel] extends {
6953
6954
  params: any;
6954
6955
  } ? SectionsV2Map[Sec]["selections"][Sel]["params"] : never;
6956
+ export type CommonArgument = {
6957
+ id?: string | number;
6958
+ key: string;
6959
+ comment?: string;
6960
+ };
6961
+ export type CommonArgumentV1<Sec extends SectionV1, Sel extends keyof SectionsV1Map[Sec]["selections"]> = {
6962
+ section: Sec;
6963
+ selections?: Sel[];
6964
+ } & CommonArgument;
6955
6965
  export type GetArgumentV1<Sec extends SectionV1, Sel extends keyof SectionsV1Map[Sec]["selections"]> = ParamsV1<Sec, Sel> extends never ? {
6956
6966
  section: Sec;
6957
6967
  selections?: Sel[];
@@ -6967,20 +6977,19 @@ export type GetArgumentV1<Sec extends SectionV1, Sel extends keyof SectionsV1Map
6967
6977
  key: string;
6968
6978
  comment?: string;
6969
6979
  };
6970
- export type GetArgumentV2<Sec extends SectionV2, Sel extends keyof SectionsV2Map[Sec]["selections"]> = ParamsV2<Sec, Sel> extends never ? {
6980
+ export type CommonArgumentV2<Sec extends SectionV2, Sel extends keyof SectionsV2Map[Sec]["selections"]> = {
6971
6981
  section: Sec;
6972
6982
  selections?: Sel[];
6973
- id?: string | number;
6983
+ } & CommonArgument;
6984
+ export type GetArgumentV2<Sec extends SectionV2, Sel extends keyof SectionsV2Map[Sec]["selections"]> = ParamsV2<Sec, Sel> extends never ? {
6974
6985
  params?: never;
6975
- key: string;
6976
- comment?: string;
6977
- } : {
6978
- section: Sec;
6979
- selections?: Sel[];
6980
- id?: string | number;
6986
+ } & CommonArgumentV2<Sec, Sel> : {
6981
6987
  params?: Partial<Record<ParamsV2<Sec, Sel>, string>>;
6982
- key: string;
6983
- comment?: string;
6988
+ } & CommonArgumentV2<Sec, Sel>;
6989
+ export type AdditionalArguments<CacheType> = {
6990
+ cache?: CacheType;
6991
+ expiry?: number;
6992
+ timeout?: number;
6984
6993
  };
6985
6994
  export type GetResponseSuccessV1<Sec extends SectionV1, Sel extends keyof SectionsV1Map[Sec]["selections"]> = SectionsV1Map[Sec]["selections"][Sel] extends {
6986
6995
  response: any;
@@ -7007,45 +7016,33 @@ export type CacheV2<Sec extends SectionV2, Sel extends keyof SectionsV2Map[Sec][
7007
7016
  set: (key: GetArgumentV2<Sec, Sel>, value: GetResponseV2<Sec, Sel>, expiry: number) => void | Promise<void>;
7008
7017
  };
7009
7018
  type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
7010
- export interface HTTPClient {
7011
- getJson(url: URL): Promise<any>;
7019
+ export type HTTPClientCapabilities = "abort";
7020
+ export declare abstract class HTTPClient {
7021
+ abstract getJson(url: URL): Promise<any>;
7022
+ canAbort(): this is AbortableHTTPClient;
7023
+ }
7024
+ export declare abstract class AbortableHTTPClient extends HTTPClient {
7025
+ abstract getJson(url: URL): Promise<any>;
7026
+ abstract getJson(url: URL, timeout: number): Promise<any>;
7027
+ abstract getJson(url: URL, timeout: number | undefined): Promise<any>;
7028
+ canAbort(): this is AbortableHTTPClient;
7012
7029
  }
7013
- export declare class FetchHTTPClient implements HTTPClient {
7014
- getJson(url: URL): Promise<any>;
7030
+ export declare class FetchHTTPClient extends AbortableHTTPClient {
7031
+ getJson(url: URL, timeout?: number | undefined): Promise<any>;
7015
7032
  }
7016
7033
  interface ClientOptions {
7017
7034
  httpClient?: HTTPClient;
7018
7035
  defaultComment?: string;
7036
+ defaultTimeout?: number;
7019
7037
  }
7020
7038
  export declare class TornApiClient {
7021
7039
  private readonly httpClient;
7022
7040
  private readonly defaultComment?;
7041
+ private readonly defaultTimeout?;
7023
7042
  constructor(options?: ClientOptions);
7024
- getV1<Sec extends SectionV1, Sel extends SelectionV1<Sec>>({ section, selections, id, params, key, comment, cache, expiry, }: GetArgumentV1<Sec, Sel> & {
7025
- cache?: CacheV1<Sec, Sel>;
7026
- expiry?: number;
7027
- }): Promise<GetResponseV1<Sec, Sel>>;
7028
- getV2<Sec extends SectionV2, Sel extends SelectionV2<Sec>>({ section, selections, id, params, key, comment, cache, expiry, }: GetArgumentV2<Sec, Sel> & {
7029
- cache?: CacheV2<Sec, Sel>;
7030
- expiry?: number;
7031
- }): Promise<GetResponseV2<Sec, Sel>>;
7043
+ getV1<Sec extends SectionV1, Sel extends SelectionV1<Sec>>({ section, selections, id, params, key, comment, cache, expiry, timeout, }: GetArgumentV1<Sec, Sel> & AdditionalArguments<CacheV1<Sec, Sel>>): Promise<GetResponseV1<Sec, Sel>>;
7044
+ getV2<Sec extends SectionV2, Sel extends SelectionV2<Sec>>({ section, selections, id, params, key, comment, cache, expiry, timeout, }: GetArgumentV2<Sec, Sel> & AdditionalArguments<CacheV2<Sec, Sel>>): Promise<GetResponseV2<Sec, Sel>>;
7032
7045
  private handleError;
7033
7046
  private populateUrl;
7034
7047
  }
7035
- /**
7036
- * @deprecated Move to TornApiClient instead of using this. Will be removed in an upcoming version.
7037
- * @see TornApiClient
7038
- */
7039
- export declare function tornApiGetV1<Sec extends SectionV1, Sel extends SelectionV1<Sec>>(options: GetArgumentV1<Sec, Sel> & {
7040
- cache?: CacheV1<Sec, Sel>;
7041
- expiry?: number;
7042
- }): Promise<GetResponseV1<Sec, Sel>>;
7043
- /**
7044
- * @deprecated Move to TornApiClient instead of using this. Will be removed in an upcoming version.
7045
- * @see TornApiClient
7046
- */
7047
- export declare function tornApiGetV2<Sec extends SectionV2, Sel extends SelectionV2<Sec>>(options: GetArgumentV2<Sec, Sel> & {
7048
- cache?: CacheV2<Sec, Sel>;
7049
- expiry?: number;
7050
- }): Promise<GetResponseV2<Sec, Sel>>;
7051
7048
  export {};
package/dist/index.js CHANGED
@@ -34,20 +34,41 @@ export var TornApiError;
34
34
  TornApiError[TornApiError["SELECTION_ONLY_AVAILABLE_API_V2"] = 23] = "SELECTION_ONLY_AVAILABLE_API_V2";
35
35
  TornApiError[TornApiError["CLOSED_TEMPORARILY"] = 24] = "CLOSED_TEMPORARILY";
36
36
  })(TornApiError || (TornApiError = {}));
37
- export class FetchHTTPClient {
38
- async getJson(url) {
39
- const response = await fetch(url);
37
+ export class HTTPClient {
38
+ canAbort() {
39
+ return false;
40
+ }
41
+ }
42
+ export class AbortableHTTPClient extends HTTPClient {
43
+ canAbort() {
44
+ return true;
45
+ }
46
+ }
47
+ export class FetchHTTPClient extends AbortableHTTPClient {
48
+ async getJson(url, timeout = undefined) {
49
+ let response;
50
+ if (timeout !== undefined) {
51
+ const controller = new AbortController();
52
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
53
+ response = await fetch(url, { signal: controller.signal });
54
+ clearTimeout(timeoutId);
55
+ }
56
+ else {
57
+ response = await fetch(url);
58
+ }
40
59
  return await response.json();
41
60
  }
42
61
  }
43
62
  export class TornApiClient {
44
63
  httpClient;
45
64
  defaultComment;
65
+ defaultTimeout;
46
66
  constructor(options = {}) {
47
67
  this.httpClient = options.httpClient ?? new FetchHTTPClient();
48
68
  this.defaultComment = options.defaultComment;
69
+ this.defaultTimeout = options.defaultTimeout;
49
70
  }
50
- async getV1({ section, selections, id, params = {}, key, comment, cache, expiry, }) {
71
+ async getV1({ section, selections, id, params = {}, key, comment, cache, expiry, timeout, }) {
51
72
  const cached = await cache?.get({
52
73
  section,
53
74
  selections,
@@ -59,10 +80,18 @@ export class TornApiClient {
59
80
  return cached;
60
81
  const url = new URL(`https://api.torn.com/${section}/${id ?? ""}`);
61
82
  this.populateUrl(url, key, (selections ?? []), comment, params ?? {});
62
- return this.httpClient
63
- .getJson(url)
64
- .then(addToCache)
65
- .catch(this.handleError);
83
+ if (this.httpClient.canAbort() && typeof timeout === "number") {
84
+ return this.httpClient
85
+ .getJson(url, timeout)
86
+ .then(addToCache)
87
+ .catch(this.handleError);
88
+ }
89
+ else {
90
+ return this.httpClient
91
+ .getJson(url)
92
+ .then(addToCache)
93
+ .catch(this.handleError);
94
+ }
66
95
  function addToCache(response) {
67
96
  if ("error" in response)
68
97
  return response;
@@ -76,7 +105,7 @@ export class TornApiClient {
76
105
  return response;
77
106
  }
78
107
  }
79
- async getV2({ section, selections, id, params = {}, key, comment, cache, expiry, }) {
108
+ async getV2({ section, selections, id, params = {}, key, comment, cache, expiry, timeout, }) {
80
109
  const cached = await cache?.get({
81
110
  section,
82
111
  selections,
@@ -88,10 +117,18 @@ export class TornApiClient {
88
117
  return cached;
89
118
  const url = new URL(`https://api.torn.com/v2/${section}/${id ?? ""}`);
90
119
  this.populateUrl(url, key, (selections ?? []), comment, params ?? {});
91
- return this.httpClient
92
- .getJson(url)
93
- .then(addToCache)
94
- .catch(this.handleError);
120
+ if (this.httpClient.canAbort() && typeof timeout === "number") {
121
+ return this.httpClient
122
+ .getJson(url, timeout)
123
+ .then(addToCache)
124
+ .catch(this.handleError);
125
+ }
126
+ else {
127
+ return this.httpClient
128
+ .getJson(url)
129
+ .then(addToCache)
130
+ .catch(this.handleError);
131
+ }
95
132
  function addToCache(response) {
96
133
  if ("error" in response)
97
134
  return response;
@@ -134,18 +171,3 @@ export class TornApiClient {
134
171
  .forEach(([key, value]) => url.searchParams.set(key, value));
135
172
  }
136
173
  }
137
- const DEFAULT_CLIENT = new TornApiClient();
138
- /**
139
- * @deprecated Move to TornApiClient instead of using this. Will be removed in an upcoming version.
140
- * @see TornApiClient
141
- */
142
- export async function tornApiGetV1(options) {
143
- return DEFAULT_CLIENT.getV1(options);
144
- }
145
- /**
146
- * @deprecated Move to TornApiClient instead of using this. Will be removed in an upcoming version.
147
- * @see TornApiClient
148
- */
149
- export async function tornApiGetV2(options) {
150
- return DEFAULT_CLIENT.getV2(options);
151
- }
package/dist/index.ts CHANGED
@@ -6370,6 +6370,7 @@ export interface PersonalStatsCrimesV2 {
6370
6370
  cracking: number;
6371
6371
  forgery: number;
6372
6372
  scamming: number;
6373
+ arson: number;
6373
6374
  };
6374
6375
  version: string;
6375
6376
  }
@@ -7040,7 +7041,8 @@ export type PersonalStatsStatName =
7040
7041
  | "disposalskill"
7041
7042
  | "crackingskill"
7042
7043
  | "forgeryskill"
7043
- | "scammingskill";
7044
+ | "scammingskill"
7045
+ | "arsonskill";
7044
7046
 
7045
7047
  export interface FactionRaidReport {
7046
7048
  id: RaidWarId;
@@ -7689,7 +7691,7 @@ export interface FactionCrimeSlot {
7689
7691
  position_number: number;
7690
7692
  item_requirement: {
7691
7693
  id: ItemId;
7692
- /** Shows if the item is reusable or consumed during the crime. */
7694
+ /** Shows if the item is reusable or consumed during the crime.<br><b>Important note: There may be alternative paths which won't consume the item, even if the item is non-reusable.</b> */
7693
7695
  is_reusable: boolean;
7694
7696
  /** Shows if user has the required item. */
7695
7697
  is_available: boolean;
@@ -8007,7 +8009,7 @@ export interface MarketRentalDetails {
8007
8009
  }
8008
8010
 
8009
8011
  export interface MarketRentalsResponse {
8010
- properties: MarketRentalDetails;
8012
+ rentals: MarketRentalDetails;
8011
8013
  _metadata: RequestMetadataWithLinks;
8012
8014
  }
8013
8015
 
@@ -12750,6 +12752,18 @@ export type ParamsV2<
12750
12752
  ? SectionsV2Map[Sec]["selections"][Sel]["params"]
12751
12753
  : never;
12752
12754
 
12755
+ export type CommonArgument = {
12756
+ id?: string | number;
12757
+ key: string;
12758
+ comment?: string;
12759
+ };
12760
+ export type CommonArgumentV1<
12761
+ Sec extends SectionV1,
12762
+ Sel extends keyof SectionsV1Map[Sec]["selections"],
12763
+ > = {
12764
+ section: Sec;
12765
+ selections?: Sel[];
12766
+ } & CommonArgument;
12753
12767
  export type GetArgumentV1<
12754
12768
  Sec extends SectionV1,
12755
12769
  Sel extends keyof SectionsV1Map[Sec]["selections"],
@@ -12771,27 +12785,29 @@ export type GetArgumentV1<
12771
12785
  key: string;
12772
12786
  comment?: string;
12773
12787
  };
12788
+ export type CommonArgumentV2<
12789
+ Sec extends SectionV2,
12790
+ Sel extends keyof SectionsV2Map[Sec]["selections"],
12791
+ > = {
12792
+ section: Sec;
12793
+ selections?: Sel[];
12794
+ } & CommonArgument;
12774
12795
  export type GetArgumentV2<
12775
12796
  Sec extends SectionV2,
12776
12797
  Sel extends keyof SectionsV2Map[Sec]["selections"],
12777
12798
  > =
12778
12799
  ParamsV2<Sec, Sel> extends never
12779
12800
  ? {
12780
- section: Sec;
12781
- selections?: Sel[];
12782
- id?: string | number;
12783
12801
  params?: never;
12784
- key: string;
12785
- comment?: string;
12786
- }
12802
+ } & CommonArgumentV2<Sec, Sel>
12787
12803
  : {
12788
- section: Sec;
12789
- selections?: Sel[];
12790
- id?: string | number;
12791
12804
  params?: Partial<Record<ParamsV2<Sec, Sel>, string>>;
12792
- key: string;
12793
- comment?: string;
12794
- };
12805
+ } & CommonArgumentV2<Sec, Sel>;
12806
+ export type AdditionalArguments<CacheType> = {
12807
+ cache?: CacheType;
12808
+ expiry?: number;
12809
+ timeout?: number;
12810
+ };
12795
12811
 
12796
12812
  export type GetResponseSuccessV1<
12797
12813
  Sec extends SectionV1,
@@ -12860,13 +12876,41 @@ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
12860
12876
  ? I
12861
12877
  : never;
12862
12878
 
12863
- export interface HTTPClient {
12864
- getJson(url: URL): Promise<any>;
12879
+ export type HTTPClientCapabilities = "abort";
12880
+
12881
+ export abstract class HTTPClient {
12882
+ abstract getJson(url: URL): Promise<any>;
12883
+
12884
+ canAbort(): this is AbortableHTTPClient {
12885
+ return false;
12886
+ }
12865
12887
  }
12866
12888
 
12867
- export class FetchHTTPClient implements HTTPClient {
12868
- async getJson(url: URL): Promise<any> {
12869
- const response = await fetch(url);
12889
+ export abstract class AbortableHTTPClient extends HTTPClient {
12890
+ abstract getJson(url: URL): Promise<any>;
12891
+ abstract getJson(url: URL, timeout: number): Promise<any>;
12892
+ abstract getJson(url: URL, timeout: number | undefined): Promise<any>;
12893
+
12894
+ canAbort(): this is AbortableHTTPClient {
12895
+ return true;
12896
+ }
12897
+ }
12898
+
12899
+ export class FetchHTTPClient extends AbortableHTTPClient {
12900
+ async getJson(
12901
+ url: URL,
12902
+ timeout: number | undefined = undefined,
12903
+ ): Promise<any> {
12904
+ let response: Response;
12905
+ if (timeout !== undefined) {
12906
+ const controller = new AbortController();
12907
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
12908
+
12909
+ response = await fetch(url, { signal: controller.signal });
12910
+ clearTimeout(timeoutId);
12911
+ } else {
12912
+ response = await fetch(url);
12913
+ }
12870
12914
 
12871
12915
  return await response.json();
12872
12916
  }
@@ -12875,15 +12919,18 @@ export class FetchHTTPClient implements HTTPClient {
12875
12919
  interface ClientOptions {
12876
12920
  httpClient?: HTTPClient;
12877
12921
  defaultComment?: string;
12922
+ defaultTimeout?: number;
12878
12923
  }
12879
12924
 
12880
12925
  export class TornApiClient {
12881
12926
  private readonly httpClient: HTTPClient;
12882
12927
  private readonly defaultComment?: string;
12928
+ private readonly defaultTimeout?: number;
12883
12929
 
12884
12930
  constructor(options: ClientOptions = {}) {
12885
12931
  this.httpClient = options.httpClient ?? new FetchHTTPClient();
12886
12932
  this.defaultComment = options.defaultComment;
12933
+ this.defaultTimeout = options.defaultTimeout;
12887
12934
  }
12888
12935
 
12889
12936
  async getV1<Sec extends SectionV1, Sel extends SelectionV1<Sec>>({
@@ -12895,10 +12942,11 @@ export class TornApiClient {
12895
12942
  comment,
12896
12943
  cache,
12897
12944
  expiry,
12898
- }: GetArgumentV1<Sec, Sel> & {
12899
- cache?: CacheV1<Sec, Sel>;
12900
- expiry?: number;
12901
- }): Promise<GetResponseV1<Sec, Sel>> {
12945
+ timeout,
12946
+ }: GetArgumentV1<Sec, Sel> &
12947
+ AdditionalArguments<CacheV1<Sec, Sel>>): Promise<
12948
+ GetResponseV1<Sec, Sel>
12949
+ > {
12902
12950
  const cached = await cache?.get({
12903
12951
  section,
12904
12952
  selections,
@@ -12917,10 +12965,17 @@ export class TornApiClient {
12917
12965
  params ?? {},
12918
12966
  );
12919
12967
 
12920
- return this.httpClient
12921
- .getJson(url)
12922
- .then(addToCache)
12923
- .catch(this.handleError);
12968
+ if (this.httpClient.canAbort() && typeof timeout === "number") {
12969
+ return (this.httpClient as AbortableHTTPClient)
12970
+ .getJson(url, timeout)
12971
+ .then(addToCache)
12972
+ .catch(this.handleError);
12973
+ } else {
12974
+ return this.httpClient
12975
+ .getJson(url)
12976
+ .then(addToCache)
12977
+ .catch(this.handleError);
12978
+ }
12924
12979
 
12925
12980
  function addToCache(
12926
12981
  response: GetResponseV1<Sec, Sel>,
@@ -12950,10 +13005,11 @@ export class TornApiClient {
12950
13005
  comment,
12951
13006
  cache,
12952
13007
  expiry,
12953
- }: GetArgumentV2<Sec, Sel> & {
12954
- cache?: CacheV2<Sec, Sel>;
12955
- expiry?: number;
12956
- }): Promise<GetResponseV2<Sec, Sel>> {
13008
+ timeout,
13009
+ }: GetArgumentV2<Sec, Sel> &
13010
+ AdditionalArguments<CacheV2<Sec, Sel>>): Promise<
13011
+ GetResponseV2<Sec, Sel>
13012
+ > {
12957
13013
  const cached = await cache?.get({
12958
13014
  section,
12959
13015
  selections,
@@ -12972,10 +13028,17 @@ export class TornApiClient {
12972
13028
  params ?? {},
12973
13029
  );
12974
13030
 
12975
- return this.httpClient
12976
- .getJson(url)
12977
- .then(addToCache)
12978
- .catch(this.handleError);
13031
+ if (this.httpClient.canAbort() && typeof timeout === "number") {
13032
+ return (this.httpClient as AbortableHTTPClient)
13033
+ .getJson(url, timeout)
13034
+ .then(addToCache)
13035
+ .catch(this.handleError);
13036
+ } else {
13037
+ return this.httpClient
13038
+ .getJson(url)
13039
+ .then(addToCache)
13040
+ .catch(this.handleError);
13041
+ }
12979
13042
 
12980
13043
  function addToCache(
12981
13044
  response: GetResponseV2<Sec, Sel>,
@@ -13035,37 +13098,3 @@ export class TornApiClient {
13035
13098
  .forEach(([key, value]) => url.searchParams.set(key, value));
13036
13099
  }
13037
13100
  }
13038
-
13039
- const DEFAULT_CLIENT = new TornApiClient();
13040
-
13041
- /**
13042
- * @deprecated Move to TornApiClient instead of using this. Will be removed in an upcoming version.
13043
- * @see TornApiClient
13044
- */
13045
- export async function tornApiGetV1<
13046
- Sec extends SectionV1,
13047
- Sel extends SelectionV1<Sec>,
13048
- >(
13049
- options: GetArgumentV1<Sec, Sel> & {
13050
- cache?: CacheV1<Sec, Sel>;
13051
- expiry?: number;
13052
- },
13053
- ): Promise<GetResponseV1<Sec, Sel>> {
13054
- return DEFAULT_CLIENT.getV1(options);
13055
- }
13056
-
13057
- /**
13058
- * @deprecated Move to TornApiClient instead of using this. Will be removed in an upcoming version.
13059
- * @see TornApiClient
13060
- */
13061
- export async function tornApiGetV2<
13062
- Sec extends SectionV2,
13063
- Sel extends SelectionV2<Sec>,
13064
- >(
13065
- options: GetArgumentV2<Sec, Sel> & {
13066
- cache?: CacheV2<Sec, Sel>;
13067
- expiry?: number;
13068
- },
13069
- ): Promise<GetResponseV2<Sec, Sel>> {
13070
- return DEFAULT_CLIENT.getV2(options);
13071
- }
package/dist/openapi.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "info": {
4
4
  "title": "Torn API",
5
5
  "description": "\n * The development of Torn's API v2 is still ongoing.\n * If selections remain unaltered, they will default to the API v1 version.\n * Unlike API v1, API v2 accepts both selections and IDs as path and query parameters.\n * If any discrepancies or errors are found, please submit a [bug report](https://www.torn.com/forums.php#/p=forums&f=19&b=0&a=0) on the Torn Forums.\n * In case you're using bots to check for changes on openapi.json file, make sure to specificy a custom user-agent header - CloudFlare sometimes prevents requests from default user-agents.",
6
- "version": "4.2.1"
6
+ "version": "4.2.2"
7
7
  },
8
8
  "servers": [
9
9
  {
@@ -156,7 +156,7 @@
156
156
  "api_key": []
157
157
  }
158
158
  ],
159
- "x-stability": "Unstable"
159
+ "x-stability": "Stable"
160
160
  }
161
161
  },
162
162
  "/user/basic": {
@@ -453,7 +453,7 @@
453
453
  "api_key": []
454
454
  }
455
455
  ],
456
- "x-stability": "Unstable"
456
+ "x-stability": "Stable"
457
457
  }
458
458
  },
459
459
  "/user/{id}/competition": {
@@ -501,7 +501,7 @@
501
501
  "api_key": []
502
502
  }
503
503
  ],
504
- "x-stability": "Unstable"
504
+ "x-stability": "Stable"
505
505
  }
506
506
  },
507
507
  "/user/cooldowns": {
@@ -540,7 +540,7 @@
540
540
  "api_key": []
541
541
  }
542
542
  ],
543
- "x-stability": "Unstable"
543
+ "x-stability": "Stable"
544
544
  }
545
545
  },
546
546
  "/user/{crimeId}/crimes": {
@@ -717,7 +717,7 @@
717
717
  "api_key": []
718
718
  }
719
719
  ],
720
- "x-stability": "Unstable"
720
+ "x-stability": "Stable"
721
721
  }
722
722
  },
723
723
  "/user/faction": {
@@ -756,7 +756,7 @@
756
756
  "api_key": []
757
757
  }
758
758
  ],
759
- "x-stability": "Unstable"
759
+ "x-stability": "Stable"
760
760
  }
761
761
  },
762
762
  "/user/{id}/faction": {
@@ -804,7 +804,7 @@
804
804
  "api_key": []
805
805
  }
806
806
  ],
807
- "x-stability": "Unstable"
807
+ "x-stability": "Stable"
808
808
  }
809
809
  },
810
810
  "/user/factionbalance": {
@@ -1354,7 +1354,7 @@
1354
1354
  "api_key": []
1355
1355
  }
1356
1356
  ],
1357
- "x-stability": "Unstable"
1357
+ "x-stability": "Stable"
1358
1358
  }
1359
1359
  },
1360
1360
  "/user/{id}/icons": {
@@ -1402,7 +1402,7 @@
1402
1402
  "api_key": []
1403
1403
  }
1404
1404
  ],
1405
- "x-stability": "Unstable"
1405
+ "x-stability": "Stable"
1406
1406
  }
1407
1407
  },
1408
1408
  "/user/itemmarket": {
@@ -1483,7 +1483,7 @@
1483
1483
  "api_key": []
1484
1484
  }
1485
1485
  ],
1486
- "x-stability": "Unstable"
1486
+ "x-stability": "Stable"
1487
1487
  }
1488
1488
  },
1489
1489
  "/user/{id}/job": {
@@ -1531,7 +1531,7 @@
1531
1531
  "api_key": []
1532
1532
  }
1533
1533
  ],
1534
- "x-stability": "Unstable"
1534
+ "x-stability": "Stable"
1535
1535
  }
1536
1536
  },
1537
1537
  "/user/jobpoints": {
@@ -1869,7 +1869,7 @@
1869
1869
  "api_key": []
1870
1870
  }
1871
1871
  ],
1872
- "x-stability": "Unstable"
1872
+ "x-stability": "Stable"
1873
1873
  }
1874
1874
  },
1875
1875
  "/user/money": {
@@ -1950,7 +1950,7 @@
1950
1950
  "api_key": []
1951
1951
  }
1952
1952
  ],
1953
- "x-stability": "Unstable"
1953
+ "x-stability": "Stable"
1954
1954
  }
1955
1955
  },
1956
1956
  "/user/newmessages": {
@@ -1989,7 +1989,7 @@
1989
1989
  "api_key": []
1990
1990
  }
1991
1991
  ],
1992
- "x-stability": "Unstable"
1992
+ "x-stability": "Stable"
1993
1993
  }
1994
1994
  },
1995
1995
  "/user/notifications": {
@@ -2028,7 +2028,7 @@
2028
2028
  "api_key": []
2029
2029
  }
2030
2030
  ],
2031
- "x-stability": "Unstable"
2031
+ "x-stability": "Stable"
2032
2032
  }
2033
2033
  },
2034
2034
  "/user/organizedcrime": {
@@ -2256,7 +2256,7 @@
2256
2256
  "api_key": []
2257
2257
  }
2258
2258
  ],
2259
- "x-stability": "Unstable"
2259
+ "x-stability": "Stable"
2260
2260
  }
2261
2261
  },
2262
2262
  "/user/{id}/profile": {
@@ -2307,7 +2307,7 @@
2307
2307
  "api_key": []
2308
2308
  }
2309
2309
  ],
2310
- "x-stability": "Unstable"
2310
+ "x-stability": "Stable"
2311
2311
  }
2312
2312
  },
2313
2313
  "/user/properties": {
@@ -2637,7 +2637,7 @@
2637
2637
  "api_key": []
2638
2638
  }
2639
2639
  ],
2640
- "x-stability": "Unstable"
2640
+ "x-stability": "Stable"
2641
2641
  }
2642
2642
  },
2643
2643
  "/user/reports": {
@@ -2892,7 +2892,7 @@
2892
2892
  "api_key": []
2893
2893
  }
2894
2894
  ],
2895
- "x-stability": "Unstable"
2895
+ "x-stability": "Stable"
2896
2896
  }
2897
2897
  },
2898
2898
  "/user/virus": {
@@ -2931,7 +2931,7 @@
2931
2931
  "api_key": []
2932
2932
  }
2933
2933
  ],
2934
- "x-stability": "Unstable"
2934
+ "x-stability": "Stable"
2935
2935
  }
2936
2936
  },
2937
2937
  "/user/workstats": {
@@ -19922,7 +19922,8 @@
19922
19922
  "disposal",
19923
19923
  "cracking",
19924
19924
  "forgery",
19925
- "scamming"
19925
+ "scamming",
19926
+ "arson"
19926
19927
  ],
19927
19928
  "properties": {
19928
19929
  "search_for_cash": {
@@ -19972,6 +19973,10 @@
19972
19973
  "scamming": {
19973
19974
  "type": "integer",
19974
19975
  "format": "int32"
19976
+ },
19977
+ "arson": {
19978
+ "type": "integer",
19979
+ "format": "int32"
19975
19980
  }
19976
19981
  },
19977
19982
  "type": "object"
@@ -21942,7 +21947,8 @@
21942
21947
  "disposalskill",
21943
21948
  "crackingskill",
21944
21949
  "forgeryskill",
21945
- "scammingskill"
21950
+ "scammingskill",
21951
+ "arsonskill"
21946
21952
  ]
21947
21953
  },
21948
21954
  "FactionRaidReport": {
@@ -24503,7 +24509,7 @@
24503
24509
  "$ref": "#/components/schemas/ItemId"
24504
24510
  },
24505
24511
  "is_reusable": {
24506
- "description": "Shows if the item is reusable or consumed during the crime.",
24512
+ "description": "Shows if the item is reusable or consumed during the crime.<br><b>Important note: There may be alternative paths which won't consume the item, even if the item is non-reusable.</b>",
24507
24513
  "type": "boolean"
24508
24514
  },
24509
24515
  "is_available": {
@@ -25920,11 +25926,11 @@
25920
25926
  },
25921
25927
  "MarketRentalsResponse": {
25922
25928
  "required": [
25923
- "properties",
25929
+ "rentals",
25924
25930
  "_metadata"
25925
25931
  ],
25926
25932
  "properties": {
25927
- "properties": {
25933
+ "rentals": {
25928
25934
  "$ref": "#/components/schemas/MarketRentalDetails"
25929
25935
  },
25930
25936
  "_metadata": {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "tornapi-typescript",
3
3
  "type": "module",
4
- "version": "4.2.1",
4
+ "version": "4.2.2",
5
5
  "scripts": {
6
6
  "generate-types": "tsc && node build/index.js"
7
7
  },
8
8
  "devDependencies": {
9
- "@scalar/openapi-types": "^0.3.7",
10
- "@types/node": "^22.18.6",
9
+ "@scalar/openapi-types": "^0.4.1",
10
+ "@types/node": "^22.18.10",
11
11
  "prettier": "^3.6.2",
12
12
  "typeconv": "^2.3.1",
13
- "typescript": "^5.9.2"
13
+ "typescript": "^5.9.3"
14
14
  },
15
15
  "main": "./dist/index.js",
16
16
  "types": "./dist/index.d.ts",