guildwars2-ts 1.1.1 → 1.1.4

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.mjs CHANGED
@@ -63,13 +63,10 @@ var ApiTimeoutError = class _ApiTimeoutError extends Error {
63
63
  }
64
64
  };
65
65
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
66
- LogLevel2[LogLevel2["silly"] = 0] = "silly";
67
- LogLevel2[LogLevel2["trace"] = 1] = "trace";
68
- LogLevel2[LogLevel2["debug"] = 2] = "debug";
69
- LogLevel2[LogLevel2["info"] = 3] = "info";
70
- LogLevel2[LogLevel2["warn"] = 4] = "warn";
71
66
  LogLevel2[LogLevel2["error"] = 5] = "error";
72
- LogLevel2[LogLevel2["fatal"] = 6] = "fatal";
67
+ LogLevel2[LogLevel2["warn"] = 4] = "warn";
68
+ LogLevel2[LogLevel2["info"] = 3] = "info";
69
+ LogLevel2[LogLevel2["debug"] = 2] = "debug";
73
70
  return LogLevel2;
74
71
  })(LogLevel || {});
75
72
  var logger = new Logger({
@@ -102,8 +99,7 @@ var ApiBase = class {
102
99
  constructor(apiParams) {
103
100
  this._apiToken = apiParams?.token;
104
101
  this._language = apiParams?.language ?? "en" /* English */;
105
- this._rateLimitRetry = apiParams?.rateLimit?.retry ?? true;
106
- this._rateLimitRetryAttempts = apiParams?.rateLimit?.retry ? apiParams.rateLimit.attempts : 0;
102
+ this._rateLimitRetry = apiParams?.rateLimitRetry ?? true;
107
103
  }
108
104
  /**
109
105
  * Parameters for the api response, at top level
@@ -112,10 +108,7 @@ var ApiBase = class {
112
108
  return {
113
109
  token: this._apiToken,
114
110
  language: this._language,
115
- rateLimit: {
116
- retry: this._rateLimitRetry,
117
- attempts: this._rateLimitRetryAttempts
118
- }
111
+ rateLimitRetry: this._rateLimitRetry
119
112
  };
120
113
  }
121
114
  /**
@@ -124,8 +117,9 @@ var ApiBase = class {
124
117
  * @param endpoint - API Endpoint
125
118
  * @param apiParams - Query string
126
119
  * @param responseType - Type of the response
120
+ * @param attempts - Previously failed retry count
127
121
  */
128
- async buildRequest(endpoint, apiParams, responseType) {
122
+ async buildRequest(endpoint, apiParams, responseType, attempts) {
129
123
  const { tokenRequired } = endpoint;
130
124
  const url = this._getApiUrl(endpoint, apiParams);
131
125
  const headers = new AxiosHeaders();
@@ -147,14 +141,14 @@ var ApiBase = class {
147
141
  const parse = responseType.safeParse(data);
148
142
  if (!parse.success) {
149
143
  logger.warn(
150
- "The requested data failed to parse, when using the known schema. Data is still returned, but may be incorrectly typed"
144
+ "The requested data failed to parse, when using the known schema. Data is still returned, but may be incorrectly typed. Please submit the following log to the developers:"
151
145
  );
152
- logger.warn("Please submit the following log to the developers:");
153
146
  logger.warn(parse.error.errors);
154
147
  }
148
+ logger.info(`[200] Successful request to ${endpoint.path}`);
155
149
  return data;
156
150
  } catch (error) {
157
- return await this.retryRequest(endpoint, options, responseType, apiParams, 0, error);
151
+ return await this.retryRequest(endpoint, options, responseType, apiParams, attempts ?? 0, error);
158
152
  }
159
153
  }
160
154
  /**
@@ -167,48 +161,49 @@ var ApiBase = class {
167
161
  * @param rateLimitAttempt - Current rate-limit retry counter
168
162
  * @param prevError - Error that caused a retry
169
163
  */
170
- async retryRequest(endpoint, prevOptions, responseType, apiParams, rateLimitAttempt = 0, prevError) {
164
+ async retryRequest(endpoint, prevOptions, responseType, apiParams, rateLimitAttempt, prevError) {
171
165
  if (prevError instanceof AxiosError && prevError.response) {
172
166
  const { status } = prevError.response;
173
167
  switch (true) {
174
168
  case status === 401: {
175
- logger.warn(`Request to ${prevOptions.url} failed.`);
169
+ logger.warn(
170
+ // biome-ignore lint/style/noNonNullAssertion: <This will always be present>
171
+ `[401] Failed request to ${prevOptions.url}. Failed to authorize with the provided token.`
172
+ );
176
173
  throw new ApiTokenError();
177
174
  }
178
175
  case status === 403: {
179
176
  const requiredScope = prevError.response.data.text.slice(0, 1).toUpperCase() + prevError.response.data.text.slice(1);
180
- logger.warn(`Request to ${prevOptions.url} failed. ${requiredScope}.`);
177
+ logger.warn(`[403] Failed request to ${prevOptions.url}. ${requiredScope}.`);
181
178
  throw new ApiPermissionsError(requiredScope);
182
179
  }
183
180
  case status === 404: {
184
- logger.warn(`Request to ${prevOptions.url} returned no data.`);
181
+ logger.warn(`[404] Failed request to ${prevOptions.url}. No data was returned.`);
185
182
  throw new ApiNotFoundError();
186
183
  }
187
- case (status === 429 && this._rateLimitRetry): {
188
- logger.warn("Rate-limit has been reached. Request will be repeated soon.");
189
- if (rateLimitAttempt < 3) {
190
- setTimeout(async () => {
191
- return await this.retryRequest(
192
- endpoint,
193
- prevOptions,
194
- responseType,
195
- apiParams,
196
- rateLimitAttempt++,
197
- prevError
198
- );
199
- }, 1e3);
200
- break;
201
- } else {
202
- logger.error(`Rate-limit retries failed. Aborting request to ${prevOptions.url}`);
184
+ case status === 429: {
185
+ if (!this._rateLimitRetry) {
186
+ logger.warn("[429] Rate-limit has been reached, but retries were turned off. Stopping here.");
203
187
  throw new ApiRetryFailedError();
204
188
  }
189
+ if (rateLimitAttempt < 3) {
190
+ logger.warn(
191
+ // biome-ignore lint/style/noNonNullAssertion: <This will always be present>
192
+ `[429] Rate-limit has been reached. Request to ${prevOptions.url} will be repeated in 30 seconds.`
193
+ );
194
+ await new Promise((resolve) => setTimeout(() => resolve(), 3e4));
195
+ return await this.buildRequest(endpoint, apiParams, responseType, ++rateLimitAttempt);
196
+ }
197
+ logger.error(`[429] Rate-limit retries failed. Aborting request to ${prevOptions.url}`);
198
+ throw new ApiRetryFailedError();
205
199
  }
206
200
  case status === 504: {
207
- logger.warn(`Request to ${prevOptions.url} timed out.`);
201
+ logger.warn(`[504] Request to ${prevOptions.url} timed out.`);
208
202
  throw new ApiTimeoutError();
209
203
  }
210
204
  default:
211
- logger.warn(`Request to ${prevOptions.url} failed. ${prevError.message}`);
205
+ logger.warn(`[???] Request to ${prevOptions.url} failed. ${prevError.message}`);
206
+ throw new ApiGenericError();
212
207
  }
213
208
  }
214
209
  throw new ApiGenericError();
@@ -585,6 +580,107 @@ var AccountWalletDTO = z.array(
585
580
  value: z.number()
586
581
  })
587
582
  );
583
+ var AccountWizardsVaultDailyDTO = z.object({
584
+ /** The current progress to the meta achievement for the daily. */
585
+ meta_progress_current: z.number(),
586
+ /** The threshold for the meta progress to be 'complete', and the meta reward claimable. */
587
+ meta_progress_complete: z.number(),
588
+ /** The ID of the item you receive for claiming the meta reward */
589
+ meta_reward_item_id: z.number(),
590
+ /** The amount of Astral Acclaim you receive for claiming the meta reward */
591
+ meta_reward_astral: z.number(),
592
+ /** Whether the account has claimed the meta reward. */
593
+ meta_reward_claimed: z.boolean(),
594
+ /** An array of objects detailing each daily objective */
595
+ objectives: z.array(
596
+ z.object({
597
+ /** The ID of the objective. */
598
+ id: z.number(),
599
+ /** The title of the objective. */
600
+ title: z.string(),
601
+ /** The reward track containing the objective. */
602
+ track: z.string(),
603
+ /** The astral acclaim awarded for the objective. */
604
+ acclaim: z.number(),
605
+ /** The current progress of the objective. */
606
+ progress_current: z.number(),
607
+ /** The progress status of the objective. */
608
+ progress_complete: z.number(),
609
+ /** The claim status of the objective. */
610
+ claimed: z.boolean()
611
+ })
612
+ )
613
+ });
614
+ var AccountWizardsVaultListingsDTO = z.array(
615
+ z.object({
616
+ /** The listing id. */
617
+ id: z.number(),
618
+ /** The id of the item */
619
+ item_id: z.number(),
620
+ /** The quantity of the item the user receives */
621
+ item_count: z.number(),
622
+ /** Appears to be the position in the wizards vault UI. */
623
+ type: z.enum(["Featured", "Normal", "Legacy"]),
624
+ /** The quantity of Astral Acclaim to purchase . */
625
+ cost: z.number(),
626
+ /** Amount of the item already purchased. Not included if the reward is unlimited. */
627
+ purchased: z.number().optional(),
628
+ /** Maximum amount that can be purchased. Not included if the reward is unlimited. */
629
+ purchase_limit: z.number().optional()
630
+ })
631
+ );
632
+ var AccountWizardsVaultSpecialDTO = z.object({
633
+ /** An array of objects detailing each weekly objective */
634
+ objectives: z.array(
635
+ z.object({
636
+ /** The ID of the objective. */
637
+ id: z.number(),
638
+ /** The title of the objective. */
639
+ title: z.string(),
640
+ /** The reward track containing the objective. */
641
+ track: z.string(),
642
+ /** The astral acclaim awarded for the objective. */
643
+ acclaim: z.number(),
644
+ /** The current progress of the objective. */
645
+ progress_current: z.number(),
646
+ /** The progress status of the objective. */
647
+ progress_complete: z.number(),
648
+ /** The claim status of the objective. */
649
+ claimed: z.boolean()
650
+ })
651
+ )
652
+ });
653
+ var AccountWizardsVaultWeeklyDTO = z.object({
654
+ /** The current progress to the meta achievement for the weekly. */
655
+ meta_progress_current: z.number(),
656
+ /** The threshold for the meta progress to be 'complete', and the meta reward claimable. */
657
+ meta_progress_complete: z.number(),
658
+ /** The ID of the item you receive for claiming the meta reward */
659
+ meta_reward_item_id: z.number(),
660
+ /** The amount of Astral Acclaim you receive for claiming the meta reward */
661
+ meta_reward_astral: z.number(),
662
+ /** Whether the account has claimed the meta reward. */
663
+ meta_reward_claimed: z.boolean(),
664
+ /** An array of objects detailing each weekly objective */
665
+ objectives: z.array(
666
+ z.object({
667
+ /** The ID of the objective. */
668
+ id: z.number(),
669
+ /** The title of the objective. */
670
+ title: z.string(),
671
+ /** The reward track containing the objective. */
672
+ track: z.string(),
673
+ /** The astral acclaim awarded for the objective. */
674
+ acclaim: z.number(),
675
+ /** The current progress of the objective. */
676
+ progress_current: z.number(),
677
+ /** The progress status of the objective. */
678
+ progress_complete: z.number(),
679
+ /** The claim status of the objective. */
680
+ claimed: z.boolean()
681
+ })
682
+ )
683
+ });
588
684
  var AccountWorldBossesDTO = z.array(
589
685
  /** Name of the world boss. */
590
686
  z.string()
@@ -1776,7 +1872,7 @@ var ColorsDTO = z.array(
1776
1872
  /** ID of the dye item. */
1777
1873
  item: z.number().optional(),
1778
1874
  /** Color categories. */
1779
- categories: z.tuple([Hue, Material, Rarity]).optional()
1875
+ categories: z.tuple([Hue, Material, Rarity]).or(z.array(z.undefined()).length(0))
1780
1876
  })
1781
1877
  );
1782
1878
  var EmblemDTO = z.array(
@@ -3636,6 +3732,44 @@ var StoriesSeasonsDTO = z.array(
3636
3732
  stories: z.array(z.number())
3637
3733
  })
3638
3734
  );
3735
+ var WizardsVaultDTO = z.object({
3736
+ /** The name of the current season. */
3737
+ title: z.string(),
3738
+ /** The date that the current season begins. */
3739
+ start: z.string(),
3740
+ /** The date that the current season ends. */
3741
+ end: z.string(),
3742
+ /** The wizard's vault listing ids available (use the sub endpoint to view item details). */
3743
+ listings: z.array(z.number()),
3744
+ /** The wizard's vault objective ids available (use the sub endpoint to view item details). */
3745
+ objectives: z.array(z.number())
3746
+ });
3747
+ var WizardsVaultListingsDTO = z.array(
3748
+ z.object({
3749
+ /** The listing id. */
3750
+ id: z.number(),
3751
+ /** The id of the item */
3752
+ item_id: z.number(),
3753
+ /** The quantity of the item the user receives */
3754
+ item_count: z.number(),
3755
+ /** Appears to be the position in the wizards vault UI. */
3756
+ type: z.enum(["Featured", "Normal", "Legacy"]),
3757
+ /** The quantity of Astral Acclaim to purchase . */
3758
+ cost: z.number()
3759
+ })
3760
+ );
3761
+ var WizardsVaultObjectivesDTO = z.array(
3762
+ z.object({
3763
+ /** The ID of the objective. */
3764
+ id: z.number(),
3765
+ /** The title of the objective. */
3766
+ title: z.string(),
3767
+ /** The reward track containing the objective. */
3768
+ track: z.enum(["PvP", "WvW", "PvE"]),
3769
+ /** The amount of astral acclaim awarded. */
3770
+ acclaim: z.number()
3771
+ })
3772
+ );
3639
3773
  var WvWAbilitiesDTO = z.array(
3640
3774
  z.object({
3641
3775
  /** The id of the abilities.*/
@@ -4025,6 +4159,22 @@ var endpoints = {
4025
4159
  path: "v2/account/wallet",
4026
4160
  tokenRequired: true
4027
4161
  },
4162
+ wizardsVaultDaily: {
4163
+ path: "v2/account/wizardsvault/daily",
4164
+ tokenRequired: true
4165
+ },
4166
+ wizardsVaultListings: {
4167
+ path: "v2/account/wizardsvault/listings",
4168
+ tokenRequired: true
4169
+ },
4170
+ wizardsVaultSpecial: {
4171
+ path: "v2/account/wizardsvault/special",
4172
+ tokenRequired: true
4173
+ },
4174
+ wizardsVaultWeekly: {
4175
+ path: "v2/account/wizardsvault/weekly",
4176
+ tokenRequired: true
4177
+ },
4028
4178
  worldBosses: {
4029
4179
  path: "v2/account/worldbosses",
4030
4180
  tokenRequired: true
@@ -4693,6 +4843,28 @@ var endpoints = {
4693
4843
  tokenRequired: false
4694
4844
  }
4695
4845
  },
4846
+ wizardsVault: {
4847
+ root: {
4848
+ path: "v2/wizardsvault",
4849
+ tokenRequired: false
4850
+ },
4851
+ listingsAll: {
4852
+ path: "v2/wizardsvault/listings",
4853
+ tokenRequired: false
4854
+ },
4855
+ listingsById: {
4856
+ path: "v2/wizardsvault/listings?ids=$(ids)",
4857
+ tokenRequired: false
4858
+ },
4859
+ objectivesAll: {
4860
+ path: "v2/wizardsvault/objectives",
4861
+ tokenRequired: false
4862
+ },
4863
+ objectivesById: {
4864
+ path: "v2/wizardsvault/objectives?ids=$(ids)",
4865
+ tokenRequired: false
4866
+ }
4867
+ },
4696
4868
  worldBosses: {
4697
4869
  path: "v2/worldbosses",
4698
4870
  tokenRequired: false
@@ -5033,6 +5205,46 @@ var AccountApi = class extends ApiBase {
5033
5205
  async getWallet() {
5034
5206
  return await this.buildRequest(endpoints.account.wallet, {}, AccountWalletDTO);
5035
5207
  }
5208
+ /**
5209
+ * Returns the current set of daily Wizard's Vault achievements for the account.
5210
+ */
5211
+ async getWizardsVaultDaily() {
5212
+ return await this.buildRequest(
5213
+ endpoints.account.wizardsVaultDaily,
5214
+ {},
5215
+ AccountWizardsVaultDailyDTO
5216
+ );
5217
+ }
5218
+ /**
5219
+ * Returns the current set of Wizard's Vault rewards, along with details about which have already been purchased by the account, and in what quantity.
5220
+ */
5221
+ async getWizardsVaultListings() {
5222
+ return await this.buildRequest(
5223
+ endpoints.account.wizardsVaultListings,
5224
+ {},
5225
+ AccountWizardsVaultListingsDTO
5226
+ );
5227
+ }
5228
+ /**
5229
+ * Returns the current set of special Wizard's Vault achievements for the account.
5230
+ */
5231
+ async getWizardsVaultSpecial() {
5232
+ return await this.buildRequest(
5233
+ endpoints.account.wizardsVaultSpecial,
5234
+ {},
5235
+ AccountWizardsVaultSpecialDTO
5236
+ );
5237
+ }
5238
+ /**
5239
+ * Returns the current set of weekly Wizard's Vault achievements for the account.
5240
+ */
5241
+ async getWizardsVaultWeekly() {
5242
+ return await this.buildRequest(
5243
+ endpoints.account.wizardsVaultWeekly,
5244
+ {},
5245
+ AccountWizardsVaultWeeklyDTO
5246
+ );
5247
+ }
5036
5248
  /**
5037
5249
  * Returns information about which world bosses have been killed by the account since daily-reset.
5038
5250
  */
@@ -6098,6 +6310,38 @@ var PvPApi = class extends ApiBase {
6098
6310
  }
6099
6311
  };
6100
6312
 
6313
+ // src/apis/wizardsvault/wizardsvault.ts
6314
+ var WizardsVaultApi = class extends ApiBase {
6315
+ /**
6316
+ * Returns information about the current Wizard's Vault season.
6317
+ */
6318
+ async get() {
6319
+ return await this.buildRequest(endpoints.wizardsVault.root, {}, WizardsVaultDTO);
6320
+ }
6321
+ async getListings(ids) {
6322
+ if (ids)
6323
+ return await this.buildRequest(
6324
+ endpoints.wizardsVault.listingsById,
6325
+ { ids },
6326
+ WizardsVaultListingsDTO
6327
+ );
6328
+ return await this.buildRequest(endpoints.wizardsVault.listingsAll, {}, numberArrayType);
6329
+ }
6330
+ async getObjectives(ids) {
6331
+ if (ids)
6332
+ return await this.buildRequest(
6333
+ endpoints.wizardsVault.objectivesById,
6334
+ { ids },
6335
+ WizardsVaultObjectivesDTO
6336
+ );
6337
+ return await this.buildRequest(
6338
+ endpoints.wizardsVault.objectivesAll,
6339
+ {},
6340
+ numberArrayType
6341
+ );
6342
+ }
6343
+ };
6344
+
6101
6345
  // src/apis/wvw/wvw.ts
6102
6346
  var WorldVsWorldApi = class extends ApiBase {
6103
6347
  async getAbilities(ids) {
@@ -6273,6 +6517,8 @@ var GW2Api = class extends ApiBase {
6273
6517
  tokenInfo = new TokenInfoApi(this.getParams());
6274
6518
  /** /v2/traits Api */
6275
6519
  traits = new TraitsApi(this.getParams());
6520
+ /** /v2/wizardsvault Api */
6521
+ wizardsVault = new WizardsVaultApi(this.getParams());
6276
6522
  /** /v2/worldbosses Api */
6277
6523
  worldBosses = new WorldBossesApi(this.getParams());
6278
6524
  /** /v2/worlds Api */
@@ -6282,5 +6528,3 @@ var GW2Api = class extends ApiBase {
6282
6528
  };
6283
6529
 
6284
6530
  export { ApiLanguage, GW2Api, LogLevel, setLogLevel, setPathLogging };
6285
- //# sourceMappingURL=out.js.map
6286
- //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guildwars2-ts",
3
- "version": "1.1.1",
3
+ "version": "1.1.4",
4
4
  "description": "GuildWars 2 API Wrapper in Typescript",
5
5
  "homepage": "https://gitlab.com/dinckelman/guildwars2-ts",
6
6
  "main": "dist/index.js",
@@ -22,26 +22,26 @@
22
22
  "gw2"
23
23
  ],
24
24
  "dependencies": {
25
- "axios": "^1.6.1",
26
- "promise-queue": "^2.2.5",
27
- "tslog": "^4.9.2",
28
- "zod": "^3.22.4"
25
+ "axios": "1.6.7",
26
+ "promise-queue": "2.2.5",
27
+ "tslog": "4.9.2",
28
+ "zod": "3.22.4"
29
29
  },
30
30
  "devDependencies": {
31
- "@biomejs/biome": "1.3.3",
31
+ "@biomejs/biome": "^1.5.3",
32
32
  "@jest/globals": "^29.7.0",
33
- "@types/node": "^20.9.0",
33
+ "@types/node": "^20.11.24",
34
34
  "@types/promise-queue": "^2.2.3",
35
35
  "jest": "^29.7.0",
36
- "ts-jest": "^29.1.1",
37
- "ts-node": "^10.9.1",
38
- "tsup": "^7.2.0",
39
- "typescript": "^5.2.2"
36
+ "ts-jest": "^29.1.2",
37
+ "ts-node": "^10.9.2",
38
+ "tsup": "^8.0.2",
39
+ "typescript": "^5.3.3"
40
40
  },
41
41
  "scripts": {
42
42
  "lint:dry": "biome check .",
43
43
  "lint": "biome check . --apply",
44
- "build": "tsup",
44
+ "build": "tsup --env.NODE_ENV production",
45
45
  "test": "jest",
46
46
  "test:coverage": "jest --coverage"
47
47
  }