tornapi-typescript 4.2.1 → 4.2.3

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
@@ -25,7 +25,7 @@ export type FactionStatEnum = "medicalitemsused" | "criminaloffences" | "organis
25
25
  export type FactionBranchStateEnum = "war" | "peace";
26
26
  export type RacingRaceTypeEnum = "official" | "custom";
27
27
  export type MarketSpecializedBazaarCategoryEnum = "Alcohol" | "Artifact" | "Booster" | "Candy" | "Car" | "Clothing" | "Collectible" | "Defensive" | "Drug" | "Energy Drink" | "Enhancer" | "Flower" | "Jewelry" | "Material" | "Medical" | "Melee" | "Other" | "Plushie" | "Primary" | "Secondary" | "Special" | "Supply Pack" | "Temporary" | "Tool";
28
- export type FactionPositionAbilityEnum = "Medical Item Usage" | "Booster Item Usage" | "Drug Item Usage" | "Energy Refill Usage" | "Nerve Refill Usage" | "Temporary Item Loaning" | "Weapon & Armor Loaning" | "Item Retrieving" | "Organised Crimes" | "Faction API Access" | "Item Giving" | "Money Giving" | "Points Giving" | "Forum Management" | "Application Management" | "Kick Members" | "Balance Adjustment" | "War Management" | "Upgrade Management" | "Newsletter Sending" | "Announcement Changes" | "Description Changes";
28
+ export type FactionPositionAbilityEnum = "Medical Item Usage" | "Booster Item Usage" | "Drug Item Usage" | "Energy Refill Usage" | "Nerve Refill Usage" | "Temporary Item Loaning" | "Weapon & Armor Loaning" | "Item Retrieving" | "Organised Crimes" | "Faction API Access" | "Item Giving" | "Money Giving" | "Points Giving" | "Forum Management" | "Application Management" | "Kick Members" | "Balance Adjustment" | "War Management" | "Upgrade Management" | "Newsletter Sending" | "Announcement Changes" | "Description Changes" | "Utility Item Loaning" | "Consumable Item Usage";
29
29
  export type FactionOrganizedCrimePayoutType = "balance" | "wallet" | "inventory";
30
30
  export type TornRacketType = "Item" | "Points" | "Money";
31
31
  export type FactionNewsCategory = "main" | "attack" | "armoryDeposit" | "armoryAction" | "territoryWar" | "rankedWar" | "territoryGain" | "chain" | "crime" | "membership" | "depositFunds" | "giveFunds";
@@ -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
@@ -4403,7 +4403,9 @@ export type FactionPositionAbilityEnum =
4403
4403
  | "Upgrade Management"
4404
4404
  | "Newsletter Sending"
4405
4405
  | "Announcement Changes"
4406
- | "Description Changes";
4406
+ | "Description Changes"
4407
+ | "Utility Item Loaning"
4408
+ | "Consumable Item Usage";
4407
4409
 
4408
4410
  export type FactionOrganizedCrimePayoutType =
4409
4411
  | "balance"
@@ -6370,6 +6372,7 @@ export interface PersonalStatsCrimesV2 {
6370
6372
  cracking: number;
6371
6373
  forgery: number;
6372
6374
  scamming: number;
6375
+ arson: number;
6373
6376
  };
6374
6377
  version: string;
6375
6378
  }
@@ -7040,7 +7043,8 @@ export type PersonalStatsStatName =
7040
7043
  | "disposalskill"
7041
7044
  | "crackingskill"
7042
7045
  | "forgeryskill"
7043
- | "scammingskill";
7046
+ | "scammingskill"
7047
+ | "arsonskill";
7044
7048
 
7045
7049
  export interface FactionRaidReport {
7046
7050
  id: RaidWarId;
@@ -7689,7 +7693,7 @@ export interface FactionCrimeSlot {
7689
7693
  position_number: number;
7690
7694
  item_requirement: {
7691
7695
  id: ItemId;
7692
- /** Shows if the item is reusable or consumed during the crime. */
7696
+ /** 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
7697
  is_reusable: boolean;
7694
7698
  /** Shows if user has the required item. */
7695
7699
  is_available: boolean;
@@ -8007,7 +8011,7 @@ export interface MarketRentalDetails {
8007
8011
  }
8008
8012
 
8009
8013
  export interface MarketRentalsResponse {
8010
- properties: MarketRentalDetails;
8014
+ rentals: MarketRentalDetails;
8011
8015
  _metadata: RequestMetadataWithLinks;
8012
8016
  }
8013
8017
 
@@ -12750,6 +12754,18 @@ export type ParamsV2<
12750
12754
  ? SectionsV2Map[Sec]["selections"][Sel]["params"]
12751
12755
  : never;
12752
12756
 
12757
+ export type CommonArgument = {
12758
+ id?: string | number;
12759
+ key: string;
12760
+ comment?: string;
12761
+ };
12762
+ export type CommonArgumentV1<
12763
+ Sec extends SectionV1,
12764
+ Sel extends keyof SectionsV1Map[Sec]["selections"],
12765
+ > = {
12766
+ section: Sec;
12767
+ selections?: Sel[];
12768
+ } & CommonArgument;
12753
12769
  export type GetArgumentV1<
12754
12770
  Sec extends SectionV1,
12755
12771
  Sel extends keyof SectionsV1Map[Sec]["selections"],
@@ -12771,27 +12787,29 @@ export type GetArgumentV1<
12771
12787
  key: string;
12772
12788
  comment?: string;
12773
12789
  };
12790
+ export type CommonArgumentV2<
12791
+ Sec extends SectionV2,
12792
+ Sel extends keyof SectionsV2Map[Sec]["selections"],
12793
+ > = {
12794
+ section: Sec;
12795
+ selections?: Sel[];
12796
+ } & CommonArgument;
12774
12797
  export type GetArgumentV2<
12775
12798
  Sec extends SectionV2,
12776
12799
  Sel extends keyof SectionsV2Map[Sec]["selections"],
12777
12800
  > =
12778
12801
  ParamsV2<Sec, Sel> extends never
12779
12802
  ? {
12780
- section: Sec;
12781
- selections?: Sel[];
12782
- id?: string | number;
12783
12803
  params?: never;
12784
- key: string;
12785
- comment?: string;
12786
- }
12804
+ } & CommonArgumentV2<Sec, Sel>
12787
12805
  : {
12788
- section: Sec;
12789
- selections?: Sel[];
12790
- id?: string | number;
12791
12806
  params?: Partial<Record<ParamsV2<Sec, Sel>, string>>;
12792
- key: string;
12793
- comment?: string;
12794
- };
12807
+ } & CommonArgumentV2<Sec, Sel>;
12808
+ export type AdditionalArguments<CacheType> = {
12809
+ cache?: CacheType;
12810
+ expiry?: number;
12811
+ timeout?: number;
12812
+ };
12795
12813
 
12796
12814
  export type GetResponseSuccessV1<
12797
12815
  Sec extends SectionV1,
@@ -12860,13 +12878,41 @@ type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
12860
12878
  ? I
12861
12879
  : never;
12862
12880
 
12863
- export interface HTTPClient {
12864
- getJson(url: URL): Promise<any>;
12881
+ export type HTTPClientCapabilities = "abort";
12882
+
12883
+ export abstract class HTTPClient {
12884
+ abstract getJson(url: URL): Promise<any>;
12885
+
12886
+ canAbort(): this is AbortableHTTPClient {
12887
+ return false;
12888
+ }
12865
12889
  }
12866
12890
 
12867
- export class FetchHTTPClient implements HTTPClient {
12868
- async getJson(url: URL): Promise<any> {
12869
- const response = await fetch(url);
12891
+ export abstract class AbortableHTTPClient extends HTTPClient {
12892
+ abstract getJson(url: URL): Promise<any>;
12893
+ abstract getJson(url: URL, timeout: number): Promise<any>;
12894
+ abstract getJson(url: URL, timeout: number | undefined): Promise<any>;
12895
+
12896
+ canAbort(): this is AbortableHTTPClient {
12897
+ return true;
12898
+ }
12899
+ }
12900
+
12901
+ export class FetchHTTPClient extends AbortableHTTPClient {
12902
+ async getJson(
12903
+ url: URL,
12904
+ timeout: number | undefined = undefined,
12905
+ ): Promise<any> {
12906
+ let response: Response;
12907
+ if (timeout !== undefined) {
12908
+ const controller = new AbortController();
12909
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
12910
+
12911
+ response = await fetch(url, { signal: controller.signal });
12912
+ clearTimeout(timeoutId);
12913
+ } else {
12914
+ response = await fetch(url);
12915
+ }
12870
12916
 
12871
12917
  return await response.json();
12872
12918
  }
@@ -12875,15 +12921,18 @@ export class FetchHTTPClient implements HTTPClient {
12875
12921
  interface ClientOptions {
12876
12922
  httpClient?: HTTPClient;
12877
12923
  defaultComment?: string;
12924
+ defaultTimeout?: number;
12878
12925
  }
12879
12926
 
12880
12927
  export class TornApiClient {
12881
12928
  private readonly httpClient: HTTPClient;
12882
12929
  private readonly defaultComment?: string;
12930
+ private readonly defaultTimeout?: number;
12883
12931
 
12884
12932
  constructor(options: ClientOptions = {}) {
12885
12933
  this.httpClient = options.httpClient ?? new FetchHTTPClient();
12886
12934
  this.defaultComment = options.defaultComment;
12935
+ this.defaultTimeout = options.defaultTimeout;
12887
12936
  }
12888
12937
 
12889
12938
  async getV1<Sec extends SectionV1, Sel extends SelectionV1<Sec>>({
@@ -12895,10 +12944,11 @@ export class TornApiClient {
12895
12944
  comment,
12896
12945
  cache,
12897
12946
  expiry,
12898
- }: GetArgumentV1<Sec, Sel> & {
12899
- cache?: CacheV1<Sec, Sel>;
12900
- expiry?: number;
12901
- }): Promise<GetResponseV1<Sec, Sel>> {
12947
+ timeout,
12948
+ }: GetArgumentV1<Sec, Sel> &
12949
+ AdditionalArguments<CacheV1<Sec, Sel>>): Promise<
12950
+ GetResponseV1<Sec, Sel>
12951
+ > {
12902
12952
  const cached = await cache?.get({
12903
12953
  section,
12904
12954
  selections,
@@ -12917,10 +12967,17 @@ export class TornApiClient {
12917
12967
  params ?? {},
12918
12968
  );
12919
12969
 
12920
- return this.httpClient
12921
- .getJson(url)
12922
- .then(addToCache)
12923
- .catch(this.handleError);
12970
+ if (this.httpClient.canAbort() && typeof timeout === "number") {
12971
+ return (this.httpClient as AbortableHTTPClient)
12972
+ .getJson(url, timeout)
12973
+ .then(addToCache)
12974
+ .catch(this.handleError);
12975
+ } else {
12976
+ return this.httpClient
12977
+ .getJson(url)
12978
+ .then(addToCache)
12979
+ .catch(this.handleError);
12980
+ }
12924
12981
 
12925
12982
  function addToCache(
12926
12983
  response: GetResponseV1<Sec, Sel>,
@@ -12950,10 +13007,11 @@ export class TornApiClient {
12950
13007
  comment,
12951
13008
  cache,
12952
13009
  expiry,
12953
- }: GetArgumentV2<Sec, Sel> & {
12954
- cache?: CacheV2<Sec, Sel>;
12955
- expiry?: number;
12956
- }): Promise<GetResponseV2<Sec, Sel>> {
13010
+ timeout,
13011
+ }: GetArgumentV2<Sec, Sel> &
13012
+ AdditionalArguments<CacheV2<Sec, Sel>>): Promise<
13013
+ GetResponseV2<Sec, Sel>
13014
+ > {
12957
13015
  const cached = await cache?.get({
12958
13016
  section,
12959
13017
  selections,
@@ -12972,10 +13030,17 @@ export class TornApiClient {
12972
13030
  params ?? {},
12973
13031
  );
12974
13032
 
12975
- return this.httpClient
12976
- .getJson(url)
12977
- .then(addToCache)
12978
- .catch(this.handleError);
13033
+ if (this.httpClient.canAbort() && typeof timeout === "number") {
13034
+ return (this.httpClient as AbortableHTTPClient)
13035
+ .getJson(url, timeout)
13036
+ .then(addToCache)
13037
+ .catch(this.handleError);
13038
+ } else {
13039
+ return this.httpClient
13040
+ .getJson(url)
13041
+ .then(addToCache)
13042
+ .catch(this.handleError);
13043
+ }
12979
13044
 
12980
13045
  function addToCache(
12981
13046
  response: GetResponseV2<Sec, Sel>,
@@ -13035,37 +13100,3 @@ export class TornApiClient {
13035
13100
  .forEach(([key, value]) => url.searchParams.set(key, value));
13036
13101
  }
13037
13102
  }
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.3"
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": {
@@ -13478,7 +13478,10 @@
13478
13478
  "Upgrade Management",
13479
13479
  "Newsletter Sending",
13480
13480
  "Announcement Changes",
13481
- "Description Changes"
13481
+ "Description Changes",
13482
+ "Organised Crimes",
13483
+ "Utility Item Loaning",
13484
+ "Consumable Item Usage"
13482
13485
  ]
13483
13486
  },
13484
13487
  "FactionOrganizedCrimePayoutType": {
@@ -19922,7 +19925,8 @@
19922
19925
  "disposal",
19923
19926
  "cracking",
19924
19927
  "forgery",
19925
- "scamming"
19928
+ "scamming",
19929
+ "arson"
19926
19930
  ],
19927
19931
  "properties": {
19928
19932
  "search_for_cash": {
@@ -19972,6 +19976,10 @@
19972
19976
  "scamming": {
19973
19977
  "type": "integer",
19974
19978
  "format": "int32"
19979
+ },
19980
+ "arson": {
19981
+ "type": "integer",
19982
+ "format": "int32"
19975
19983
  }
19976
19984
  },
19977
19985
  "type": "object"
@@ -21942,7 +21950,8 @@
21942
21950
  "disposalskill",
21943
21951
  "crackingskill",
21944
21952
  "forgeryskill",
21945
- "scammingskill"
21953
+ "scammingskill",
21954
+ "arsonskill"
21946
21955
  ]
21947
21956
  },
21948
21957
  "FactionRaidReport": {
@@ -24503,7 +24512,7 @@
24503
24512
  "$ref": "#/components/schemas/ItemId"
24504
24513
  },
24505
24514
  "is_reusable": {
24506
- "description": "Shows if the item is reusable or consumed during the crime.",
24515
+ "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
24516
  "type": "boolean"
24508
24517
  },
24509
24518
  "is_available": {
@@ -25920,11 +25929,11 @@
25920
25929
  },
25921
25930
  "MarketRentalsResponse": {
25922
25931
  "required": [
25923
- "properties",
25932
+ "rentals",
25924
25933
  "_metadata"
25925
25934
  ],
25926
25935
  "properties": {
25927
- "properties": {
25936
+ "rentals": {
25928
25937
  "$ref": "#/components/schemas/MarketRentalDetails"
25929
25938
  },
25930
25939
  "_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.3",
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.5.0",
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",