guildwars2-ts 1.1.0 → 1.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/dist/index.d.mts CHANGED
@@ -50,8 +50,6 @@ declare class ApiBase {
50
50
  constructor(apiParams?: ApiParams);
51
51
  /**
52
52
  * Parameters for the api response, at top level
53
- *
54
- * @returns Api parameters
55
53
  */
56
54
  protected getParams(): ApiParams;
57
55
  /**
@@ -64,22 +62,20 @@ declare class ApiBase {
64
62
  protected buildRequest<T extends z.ZodType>(endpoint: Endpoint, apiParams: UrlParams, responseType: T): Promise<z.infer<T>>;
65
63
  /**
66
64
  * Retries failed requests
67
- * TODO: Fix logic. Rate-limits are almost impossible hit, but other generic requests will fail and loop forever
68
65
  *
69
66
  * @param endpoint - Endpoint to which a request was originally made
70
67
  * @param prevOptions - Axios request options
71
68
  * @param responseType - Originally requested schema
72
69
  * @param apiParams - Query string
70
+ * @param rateLimitAttempt - Current rate-limit retry counter
73
71
  * @param prevError - Error that caused a retry
74
- * @returns Successful request, or error
75
72
  */
76
- protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, prevError?: unknown): Promise<T>;
73
+ protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, rateLimitAttempt?: number, prevError?: unknown): Promise<T>;
77
74
  /**
78
75
  * Builds final Api url from the endpoint and provided parameters
79
76
  *
80
77
  * @param endpoint - Api endpoint
81
78
  * @param urlParams - Parameters
82
- * @returns Finalized endpoint Url
83
79
  */
84
80
  private _getApiUrl;
85
81
  }
@@ -11098,12 +11094,6 @@ declare class GuildApi extends ApiBase {
11098
11094
  name: string;
11099
11095
  role: "Member" | "Captain";
11100
11096
  }[];
11101
- seasons: {
11102
- id: string;
11103
- rating: number;
11104
- wins: number;
11105
- losses: number;
11106
- }[];
11107
11097
  id: number;
11108
11098
  name: string;
11109
11099
  aggregate: {
@@ -11114,20 +11104,20 @@ declare class GuildApi extends ApiBase {
11114
11104
  forfeits: number;
11115
11105
  };
11116
11106
  ladders: {
11117
- ranked: {
11107
+ ranked?: {
11118
11108
  wins: number;
11119
11109
  losses: number;
11120
11110
  desertions: number;
11121
11111
  byes: number;
11122
11112
  forfeits: number;
11123
- };
11124
- unranked: {
11113
+ } | undefined;
11114
+ unranked?: {
11125
11115
  wins: number;
11126
11116
  losses: number;
11127
11117
  desertions: number;
11128
11118
  byes: number;
11129
11119
  forfeits: number;
11130
- };
11120
+ } | undefined;
11131
11121
  };
11132
11122
  games: {
11133
11123
  id: string;
@@ -11143,6 +11133,12 @@ declare class GuildApi extends ApiBase {
11143
11133
  rating_change: number;
11144
11134
  season?: string | undefined;
11145
11135
  }[];
11136
+ seasons?: {
11137
+ id: string;
11138
+ rating: number;
11139
+ wins: number;
11140
+ losses: number;
11141
+ }[] | undefined;
11146
11142
  }[]>;
11147
11143
  /**
11148
11144
  * Returns information about the items in a guild's treasury.
package/dist/index.d.ts CHANGED
@@ -50,8 +50,6 @@ declare class ApiBase {
50
50
  constructor(apiParams?: ApiParams);
51
51
  /**
52
52
  * Parameters for the api response, at top level
53
- *
54
- * @returns Api parameters
55
53
  */
56
54
  protected getParams(): ApiParams;
57
55
  /**
@@ -64,22 +62,20 @@ declare class ApiBase {
64
62
  protected buildRequest<T extends z.ZodType>(endpoint: Endpoint, apiParams: UrlParams, responseType: T): Promise<z.infer<T>>;
65
63
  /**
66
64
  * Retries failed requests
67
- * TODO: Fix logic. Rate-limits are almost impossible hit, but other generic requests will fail and loop forever
68
65
  *
69
66
  * @param endpoint - Endpoint to which a request was originally made
70
67
  * @param prevOptions - Axios request options
71
68
  * @param responseType - Originally requested schema
72
69
  * @param apiParams - Query string
70
+ * @param rateLimitAttempt - Current rate-limit retry counter
73
71
  * @param prevError - Error that caused a retry
74
- * @returns Successful request, or error
75
72
  */
76
- protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, prevError?: unknown): Promise<T>;
73
+ protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, rateLimitAttempt?: number, prevError?: unknown): Promise<T>;
77
74
  /**
78
75
  * Builds final Api url from the endpoint and provided parameters
79
76
  *
80
77
  * @param endpoint - Api endpoint
81
78
  * @param urlParams - Parameters
82
- * @returns Finalized endpoint Url
83
79
  */
84
80
  private _getApiUrl;
85
81
  }
@@ -11098,12 +11094,6 @@ declare class GuildApi extends ApiBase {
11098
11094
  name: string;
11099
11095
  role: "Member" | "Captain";
11100
11096
  }[];
11101
- seasons: {
11102
- id: string;
11103
- rating: number;
11104
- wins: number;
11105
- losses: number;
11106
- }[];
11107
11097
  id: number;
11108
11098
  name: string;
11109
11099
  aggregate: {
@@ -11114,20 +11104,20 @@ declare class GuildApi extends ApiBase {
11114
11104
  forfeits: number;
11115
11105
  };
11116
11106
  ladders: {
11117
- ranked: {
11107
+ ranked?: {
11118
11108
  wins: number;
11119
11109
  losses: number;
11120
11110
  desertions: number;
11121
11111
  byes: number;
11122
11112
  forfeits: number;
11123
- };
11124
- unranked: {
11113
+ } | undefined;
11114
+ unranked?: {
11125
11115
  wins: number;
11126
11116
  losses: number;
11127
11117
  desertions: number;
11128
11118
  byes: number;
11129
11119
  forfeits: number;
11130
- };
11120
+ } | undefined;
11131
11121
  };
11132
11122
  games: {
11133
11123
  id: string;
@@ -11143,6 +11133,12 @@ declare class GuildApi extends ApiBase {
11143
11133
  rating_change: number;
11144
11134
  season?: string | undefined;
11145
11135
  }[];
11136
+ seasons?: {
11137
+ id: string;
11138
+ rating: number;
11139
+ wins: number;
11140
+ losses: number;
11141
+ }[] | undefined;
11146
11142
  }[]>;
11147
11143
  /**
11148
11144
  * Returns information about the items in a guild's treasury.
package/dist/index.js CHANGED
@@ -114,8 +114,6 @@ var ApiBase = class {
114
114
  }
115
115
  /**
116
116
  * Parameters for the api response, at top level
117
- *
118
- * @returns Api parameters
119
117
  */
120
118
  getParams() {
121
119
  return {
@@ -163,46 +161,62 @@ var ApiBase = class {
163
161
  }
164
162
  return data;
165
163
  } catch (error) {
166
- return await this.retryRequest(endpoint, options, responseType, apiParams, error);
164
+ return await this.retryRequest(endpoint, options, responseType, apiParams, 0, error);
167
165
  }
168
166
  }
169
167
  /**
170
168
  * Retries failed requests
171
- * TODO: Fix logic. Rate-limits are almost impossible hit, but other generic requests will fail and loop forever
172
169
  *
173
170
  * @param endpoint - Endpoint to which a request was originally made
174
171
  * @param prevOptions - Axios request options
175
172
  * @param responseType - Originally requested schema
176
173
  * @param apiParams - Query string
174
+ * @param rateLimitAttempt - Current rate-limit retry counter
177
175
  * @param prevError - Error that caused a retry
178
- * @returns Successful request, or error
179
176
  */
180
- async retryRequest(endpoint, prevOptions, responseType, apiParams, prevError) {
181
- if (prevError instanceof axios.AxiosError) {
182
- if (prevError.response) {
183
- const { status } = prevError.response;
184
- if (status === 401) {
177
+ async retryRequest(endpoint, prevOptions, responseType, apiParams, rateLimitAttempt = 0, prevError) {
178
+ if (prevError instanceof axios.AxiosError && prevError.response) {
179
+ const { status } = prevError.response;
180
+ switch (true) {
181
+ case status === 401: {
185
182
  logger.warn(`Request to ${prevOptions.url} failed.`);
186
183
  throw new ApiTokenError();
187
184
  }
188
- if (status === 403) {
185
+ case status === 403: {
189
186
  const requiredScope = prevError.response.data.text.slice(0, 1).toUpperCase() + prevError.response.data.text.slice(1);
190
187
  logger.warn(`Request to ${prevOptions.url} failed. ${requiredScope}.`);
191
188
  throw new ApiPermissionsError(requiredScope);
192
189
  }
193
- if (status === 404) {
190
+ case status === 404: {
194
191
  logger.warn(`Request to ${prevOptions.url} returned no data.`);
195
192
  throw new ApiNotFoundError();
196
193
  }
197
- if (status === 504) {
194
+ case (status === 429 && this._rateLimitRetry): {
195
+ logger.warn("Rate-limit has been reached. Request will be repeated soon.");
196
+ if (rateLimitAttempt < 3) {
197
+ setTimeout(async () => {
198
+ return await this.retryRequest(
199
+ endpoint,
200
+ prevOptions,
201
+ responseType,
202
+ apiParams,
203
+ rateLimitAttempt++,
204
+ prevError
205
+ );
206
+ }, 1e3);
207
+ break;
208
+ } else {
209
+ logger.error(`Rate-limit retries failed. Aborting request to ${prevOptions.url}`);
210
+ throw new ApiRetryFailedError();
211
+ }
212
+ }
213
+ case status === 504: {
198
214
  logger.warn(`Request to ${prevOptions.url} timed out.`);
199
215
  throw new ApiTimeoutError();
200
216
  }
217
+ default:
218
+ logger.warn(`Request to ${prevOptions.url} failed. ${prevError.message}`);
201
219
  }
202
- logger.warn(`Request to ${prevOptions.url} failed. ${prevError.message}`);
203
- } else if (this._rateLimitRetry) {
204
- logger.info(`Rate-limit retries failed. Aborting request to ${prevOptions.url}`);
205
- throw new ApiRetryFailedError();
206
220
  }
207
221
  throw new ApiGenericError();
208
222
  }
@@ -211,7 +225,6 @@ var ApiBase = class {
211
225
  *
212
226
  * @param endpoint - Api endpoint
213
227
  * @param urlParams - Parameters
214
- * @returns Finalized endpoint Url
215
228
  */
216
229
  _getApiUrl(endpoint, urlParams) {
217
230
  const { path } = endpoint;
@@ -1550,9 +1563,9 @@ var GuildTeamsDTO = zod.z.array(
1550
1563
  /** Team ladder statistics aggregates. */
1551
1564
  ladders: zod.z.object({
1552
1565
  /** Ranked arena stats. */
1553
- ranked: PvPAggregate,
1566
+ ranked: PvPAggregate.optional(),
1554
1567
  /** Unranked arena stats. */
1555
- unranked: PvPAggregate
1568
+ unranked: PvPAggregate.optional()
1556
1569
  }),
1557
1570
  /** Team games. */
1558
1571
  games: zod.z.array(PvPGame),
@@ -1568,7 +1581,7 @@ var GuildTeamsDTO = zod.z.array(
1568
1581
  /** Seasonal rating. */
1569
1582
  rating: zod.z.number()
1570
1583
  })
1571
- )
1584
+ ).optional()
1572
1585
  })
1573
1586
  );
1574
1587
  var GuildTreasuryDTO = zod.z.array(