guildwars2-ts 1.1.1 → 1.1.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/LICENSE +16 -16
- package/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +17 -19
- package/dist/index.mjs +17 -19
- package/package.json +1 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Ivan Sosnov
|
|
4
|
-
Copyright (c) 2021 Julio Sansossio (parts of request base code)
|
|
5
|
-
|
|
6
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
8
|
-
copyright notice and this permission notice appear in all copies.
|
|
9
|
-
|
|
10
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Ivan Sosnov
|
|
4
|
+
Copyright (c) 2021 Julio Sansossio (parts of request base code)
|
|
5
|
+
|
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
8
|
+
copyright notice and this permission notice appear in all copies.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/dist/index.d.mts
CHANGED
|
@@ -58,8 +58,9 @@ declare class ApiBase {
|
|
|
58
58
|
* @param endpoint - API Endpoint
|
|
59
59
|
* @param apiParams - Query string
|
|
60
60
|
* @param responseType - Type of the response
|
|
61
|
+
* @param attempts - Previously failed retry count
|
|
61
62
|
*/
|
|
62
|
-
protected buildRequest<T extends z.ZodType>(endpoint: Endpoint, apiParams: UrlParams, responseType: T): Promise<z.infer<T>>;
|
|
63
|
+
protected buildRequest<T extends z.ZodType>(endpoint: Endpoint, apiParams: UrlParams, responseType: T, attempts?: number): Promise<z.infer<T>>;
|
|
63
64
|
/**
|
|
64
65
|
* Retries failed requests
|
|
65
66
|
*
|
|
@@ -70,7 +71,7 @@ declare class ApiBase {
|
|
|
70
71
|
* @param rateLimitAttempt - Current rate-limit retry counter
|
|
71
72
|
* @param prevError - Error that caused a retry
|
|
72
73
|
*/
|
|
73
|
-
protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, rateLimitAttempt
|
|
74
|
+
protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, rateLimitAttempt: number, prevError?: unknown): Promise<T>;
|
|
74
75
|
/**
|
|
75
76
|
* Builds final Api url from the endpoint and provided parameters
|
|
76
77
|
*
|
|
@@ -1799,8 +1800,9 @@ declare const ColorsDTO: z.ZodArray<z.ZodObject<{
|
|
|
1799
1800
|
/** ID of the dye item. */
|
|
1800
1801
|
item: z.ZodOptional<z.ZodNumber>;
|
|
1801
1802
|
/** Color categories. */
|
|
1802
|
-
categories: z.
|
|
1803
|
+
categories: z.ZodUnion<[z.ZodTuple<[z.ZodEnum<["Gray", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Purple"]>, z.ZodEnum<["Vibrant", "Leather", "Metal"]>, z.ZodEnum<["Starter", "Common", "Uncommon", "Rare", "Exclusive"]>], null>, z.ZodArray<z.ZodUndefined, "many">]>;
|
|
1803
1804
|
}, "strip", z.ZodTypeAny, {
|
|
1805
|
+
categories: (undefined[] | ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"]) & (undefined[] | ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"] | undefined);
|
|
1804
1806
|
id: number;
|
|
1805
1807
|
name: string;
|
|
1806
1808
|
base_rgb: number[];
|
|
@@ -1837,8 +1839,8 @@ declare const ColorsDTO: z.ZodArray<z.ZodObject<{
|
|
|
1837
1839
|
rgb: number[];
|
|
1838
1840
|
} | undefined;
|
|
1839
1841
|
item?: number | undefined;
|
|
1840
|
-
categories?: ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"] | undefined;
|
|
1841
1842
|
}, {
|
|
1843
|
+
categories: (undefined[] | ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"]) & (undefined[] | ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"] | undefined);
|
|
1842
1844
|
id: number;
|
|
1843
1845
|
name: string;
|
|
1844
1846
|
base_rgb: number[];
|
|
@@ -1875,7 +1877,6 @@ declare const ColorsDTO: z.ZodArray<z.ZodObject<{
|
|
|
1875
1877
|
rgb: number[];
|
|
1876
1878
|
} | undefined;
|
|
1877
1879
|
item?: number | undefined;
|
|
1878
|
-
categories?: ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"] | undefined;
|
|
1879
1880
|
}>, "many">;
|
|
1880
1881
|
|
|
1881
1882
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -58,8 +58,9 @@ declare class ApiBase {
|
|
|
58
58
|
* @param endpoint - API Endpoint
|
|
59
59
|
* @param apiParams - Query string
|
|
60
60
|
* @param responseType - Type of the response
|
|
61
|
+
* @param attempts - Previously failed retry count
|
|
61
62
|
*/
|
|
62
|
-
protected buildRequest<T extends z.ZodType>(endpoint: Endpoint, apiParams: UrlParams, responseType: T): Promise<z.infer<T>>;
|
|
63
|
+
protected buildRequest<T extends z.ZodType>(endpoint: Endpoint, apiParams: UrlParams, responseType: T, attempts?: number): Promise<z.infer<T>>;
|
|
63
64
|
/**
|
|
64
65
|
* Retries failed requests
|
|
65
66
|
*
|
|
@@ -70,7 +71,7 @@ declare class ApiBase {
|
|
|
70
71
|
* @param rateLimitAttempt - Current rate-limit retry counter
|
|
71
72
|
* @param prevError - Error that caused a retry
|
|
72
73
|
*/
|
|
73
|
-
protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, rateLimitAttempt
|
|
74
|
+
protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, rateLimitAttempt: number, prevError?: unknown): Promise<T>;
|
|
74
75
|
/**
|
|
75
76
|
* Builds final Api url from the endpoint and provided parameters
|
|
76
77
|
*
|
|
@@ -1799,8 +1800,9 @@ declare const ColorsDTO: z.ZodArray<z.ZodObject<{
|
|
|
1799
1800
|
/** ID of the dye item. */
|
|
1800
1801
|
item: z.ZodOptional<z.ZodNumber>;
|
|
1801
1802
|
/** Color categories. */
|
|
1802
|
-
categories: z.
|
|
1803
|
+
categories: z.ZodUnion<[z.ZodTuple<[z.ZodEnum<["Gray", "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Purple"]>, z.ZodEnum<["Vibrant", "Leather", "Metal"]>, z.ZodEnum<["Starter", "Common", "Uncommon", "Rare", "Exclusive"]>], null>, z.ZodArray<z.ZodUndefined, "many">]>;
|
|
1803
1804
|
}, "strip", z.ZodTypeAny, {
|
|
1805
|
+
categories: (undefined[] | ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"]) & (undefined[] | ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"] | undefined);
|
|
1804
1806
|
id: number;
|
|
1805
1807
|
name: string;
|
|
1806
1808
|
base_rgb: number[];
|
|
@@ -1837,8 +1839,8 @@ declare const ColorsDTO: z.ZodArray<z.ZodObject<{
|
|
|
1837
1839
|
rgb: number[];
|
|
1838
1840
|
} | undefined;
|
|
1839
1841
|
item?: number | undefined;
|
|
1840
|
-
categories?: ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"] | undefined;
|
|
1841
1842
|
}, {
|
|
1843
|
+
categories: (undefined[] | ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"]) & (undefined[] | ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"] | undefined);
|
|
1842
1844
|
id: number;
|
|
1843
1845
|
name: string;
|
|
1844
1846
|
base_rgb: number[];
|
|
@@ -1875,7 +1877,6 @@ declare const ColorsDTO: z.ZodArray<z.ZodObject<{
|
|
|
1875
1877
|
rgb: number[];
|
|
1876
1878
|
} | undefined;
|
|
1877
1879
|
item?: number | undefined;
|
|
1878
|
-
categories?: ["Gray" | "Brown" | "Red" | "Orange" | "Yellow" | "Green" | "Blue" | "Purple", "Vibrant" | "Leather" | "Metal", "Starter" | "Common" | "Uncommon" | "Rare" | "Exclusive"] | undefined;
|
|
1879
1880
|
}>, "many">;
|
|
1880
1881
|
|
|
1881
1882
|
/**
|
package/dist/index.js
CHANGED
|
@@ -131,8 +131,9 @@ var ApiBase = class {
|
|
|
131
131
|
* @param endpoint - API Endpoint
|
|
132
132
|
* @param apiParams - Query string
|
|
133
133
|
* @param responseType - Type of the response
|
|
134
|
+
* @param attempts - Previously failed retry count
|
|
134
135
|
*/
|
|
135
|
-
async buildRequest(endpoint, apiParams, responseType) {
|
|
136
|
+
async buildRequest(endpoint, apiParams, responseType, attempts) {
|
|
136
137
|
const { tokenRequired } = endpoint;
|
|
137
138
|
const url = this._getApiUrl(endpoint, apiParams);
|
|
138
139
|
const headers = new axios.AxiosHeaders();
|
|
@@ -161,7 +162,7 @@ var ApiBase = class {
|
|
|
161
162
|
}
|
|
162
163
|
return data;
|
|
163
164
|
} catch (error) {
|
|
164
|
-
return await this.retryRequest(endpoint, options, responseType, apiParams, 0, error);
|
|
165
|
+
return await this.retryRequest(endpoint, options, responseType, apiParams, attempts ?? 0, error);
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
/**
|
|
@@ -174,7 +175,7 @@ var ApiBase = class {
|
|
|
174
175
|
* @param rateLimitAttempt - Current rate-limit retry counter
|
|
175
176
|
* @param prevError - Error that caused a retry
|
|
176
177
|
*/
|
|
177
|
-
async retryRequest(endpoint, prevOptions, responseType, apiParams, rateLimitAttempt
|
|
178
|
+
async retryRequest(endpoint, prevOptions, responseType, apiParams, rateLimitAttempt, prevError) {
|
|
178
179
|
if (prevError instanceof axios.AxiosError && prevError.response) {
|
|
179
180
|
const { status } = prevError.response;
|
|
180
181
|
switch (true) {
|
|
@@ -191,20 +192,18 @@ var ApiBase = class {
|
|
|
191
192
|
logger.warn(`Request to ${prevOptions.url} returned no data.`);
|
|
192
193
|
throw new ApiNotFoundError();
|
|
193
194
|
}
|
|
194
|
-
case
|
|
195
|
-
|
|
195
|
+
case status === 429: {
|
|
196
|
+
if (!this._rateLimitRetry) {
|
|
197
|
+
logger.warn("Rate-limit has been reached, but retries were turned off. Stopping here.");
|
|
198
|
+
throw new ApiRetryFailedError();
|
|
199
|
+
}
|
|
196
200
|
if (rateLimitAttempt < 3) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
rateLimitAttempt++,
|
|
204
|
-
prevError
|
|
205
|
-
);
|
|
206
|
-
}, 1e3);
|
|
207
|
-
break;
|
|
201
|
+
logger.warn(
|
|
202
|
+
// biome-ignore lint/style/noNonNullAssertion: <This will always be present>
|
|
203
|
+
`Rate-limit has been reached. Request to ${prevOptions.url} will be repeated in 30 seconds.`
|
|
204
|
+
);
|
|
205
|
+
await new Promise((resolve) => setTimeout(() => resolve(), 3e4));
|
|
206
|
+
return await this.buildRequest(endpoint, apiParams, responseType, ++rateLimitAttempt);
|
|
208
207
|
} else {
|
|
209
208
|
logger.error(`Rate-limit retries failed. Aborting request to ${prevOptions.url}`);
|
|
210
209
|
throw new ApiRetryFailedError();
|
|
@@ -216,6 +215,7 @@ var ApiBase = class {
|
|
|
216
215
|
}
|
|
217
216
|
default:
|
|
218
217
|
logger.warn(`Request to ${prevOptions.url} failed. ${prevError.message}`);
|
|
218
|
+
throw new ApiGenericError();
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
throw new ApiGenericError();
|
|
@@ -1783,7 +1783,7 @@ var ColorsDTO = zod.z.array(
|
|
|
1783
1783
|
/** ID of the dye item. */
|
|
1784
1784
|
item: zod.z.number().optional(),
|
|
1785
1785
|
/** Color categories. */
|
|
1786
|
-
categories: zod.z.tuple([Hue, Material, Rarity]).
|
|
1786
|
+
categories: zod.z.tuple([Hue, Material, Rarity]).or(zod.z.array(zod.z.undefined()).length(0))
|
|
1787
1787
|
})
|
|
1788
1788
|
);
|
|
1789
1789
|
var EmblemDTO = zod.z.array(
|
|
@@ -6293,5 +6293,3 @@ exports.GW2Api = GW2Api;
|
|
|
6293
6293
|
exports.LogLevel = LogLevel;
|
|
6294
6294
|
exports.setLogLevel = setLogLevel;
|
|
6295
6295
|
exports.setPathLogging = setPathLogging;
|
|
6296
|
-
//# sourceMappingURL=out.js.map
|
|
6297
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -124,8 +124,9 @@ var ApiBase = class {
|
|
|
124
124
|
* @param endpoint - API Endpoint
|
|
125
125
|
* @param apiParams - Query string
|
|
126
126
|
* @param responseType - Type of the response
|
|
127
|
+
* @param attempts - Previously failed retry count
|
|
127
128
|
*/
|
|
128
|
-
async buildRequest(endpoint, apiParams, responseType) {
|
|
129
|
+
async buildRequest(endpoint, apiParams, responseType, attempts) {
|
|
129
130
|
const { tokenRequired } = endpoint;
|
|
130
131
|
const url = this._getApiUrl(endpoint, apiParams);
|
|
131
132
|
const headers = new AxiosHeaders();
|
|
@@ -154,7 +155,7 @@ var ApiBase = class {
|
|
|
154
155
|
}
|
|
155
156
|
return data;
|
|
156
157
|
} catch (error) {
|
|
157
|
-
return await this.retryRequest(endpoint, options, responseType, apiParams, 0, error);
|
|
158
|
+
return await this.retryRequest(endpoint, options, responseType, apiParams, attempts ?? 0, error);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
/**
|
|
@@ -167,7 +168,7 @@ var ApiBase = class {
|
|
|
167
168
|
* @param rateLimitAttempt - Current rate-limit retry counter
|
|
168
169
|
* @param prevError - Error that caused a retry
|
|
169
170
|
*/
|
|
170
|
-
async retryRequest(endpoint, prevOptions, responseType, apiParams, rateLimitAttempt
|
|
171
|
+
async retryRequest(endpoint, prevOptions, responseType, apiParams, rateLimitAttempt, prevError) {
|
|
171
172
|
if (prevError instanceof AxiosError && prevError.response) {
|
|
172
173
|
const { status } = prevError.response;
|
|
173
174
|
switch (true) {
|
|
@@ -184,20 +185,18 @@ var ApiBase = class {
|
|
|
184
185
|
logger.warn(`Request to ${prevOptions.url} returned no data.`);
|
|
185
186
|
throw new ApiNotFoundError();
|
|
186
187
|
}
|
|
187
|
-
case
|
|
188
|
-
|
|
188
|
+
case status === 429: {
|
|
189
|
+
if (!this._rateLimitRetry) {
|
|
190
|
+
logger.warn("Rate-limit has been reached, but retries were turned off. Stopping here.");
|
|
191
|
+
throw new ApiRetryFailedError();
|
|
192
|
+
}
|
|
189
193
|
if (rateLimitAttempt < 3) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
rateLimitAttempt++,
|
|
197
|
-
prevError
|
|
198
|
-
);
|
|
199
|
-
}, 1e3);
|
|
200
|
-
break;
|
|
194
|
+
logger.warn(
|
|
195
|
+
// biome-ignore lint/style/noNonNullAssertion: <This will always be present>
|
|
196
|
+
`Rate-limit has been reached. Request to ${prevOptions.url} will be repeated in 30 seconds.`
|
|
197
|
+
);
|
|
198
|
+
await new Promise((resolve) => setTimeout(() => resolve(), 3e4));
|
|
199
|
+
return await this.buildRequest(endpoint, apiParams, responseType, ++rateLimitAttempt);
|
|
201
200
|
} else {
|
|
202
201
|
logger.error(`Rate-limit retries failed. Aborting request to ${prevOptions.url}`);
|
|
203
202
|
throw new ApiRetryFailedError();
|
|
@@ -209,6 +208,7 @@ var ApiBase = class {
|
|
|
209
208
|
}
|
|
210
209
|
default:
|
|
211
210
|
logger.warn(`Request to ${prevOptions.url} failed. ${prevError.message}`);
|
|
211
|
+
throw new ApiGenericError();
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
throw new ApiGenericError();
|
|
@@ -1776,7 +1776,7 @@ var ColorsDTO = z.array(
|
|
|
1776
1776
|
/** ID of the dye item. */
|
|
1777
1777
|
item: z.number().optional(),
|
|
1778
1778
|
/** Color categories. */
|
|
1779
|
-
categories: z.tuple([Hue, Material, Rarity]).
|
|
1779
|
+
categories: z.tuple([Hue, Material, Rarity]).or(z.array(z.undefined()).length(0))
|
|
1780
1780
|
})
|
|
1781
1781
|
);
|
|
1782
1782
|
var EmblemDTO = z.array(
|
|
@@ -6282,5 +6282,3 @@ var GW2Api = class extends ApiBase {
|
|
|
6282
6282
|
};
|
|
6283
6283
|
|
|
6284
6284
|
export { ApiLanguage, GW2Api, LogLevel, setLogLevel, setPathLogging };
|
|
6285
|
-
//# sourceMappingURL=out.js.map
|
|
6286
|
-
//# sourceMappingURL=index.mjs.map
|