fnapi-js 2.0.0-beta.0 → 2.0.1-beta.0

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.cjs CHANGED
@@ -1096,7 +1096,7 @@ var StatsEndpoint = class extends BaseEndpoint {
1096
1096
  };
1097
1097
 
1098
1098
  // src/core/version.ts
1099
- var VERSION = "2.0.0-beta.0";
1099
+ var VERSION = "2.0.1-beta.0";
1100
1100
  var USER_AGENT = `fnapi-js/${VERSION} (+https://github.com/AjaxFNC-YT/fnapi-js)`;
1101
1101
 
1102
1102
  // src/core/response.ts
@@ -8715,14 +8715,44 @@ var EpicAuthSession = class _EpicAuthSession {
8715
8715
  options
8716
8716
  );
8717
8717
  }
8718
+ async readCapableToken(options) {
8719
+ const target = resolveAuthClient("fortnitePC");
8720
+ const exchange = await this.auth.createExchangeCode(this.accessToken, {
8721
+ consumingClientId: target.clientId,
8722
+ ...options?.signal ? { signal: options.signal } : {}
8723
+ });
8724
+ const token = await this.auth.exchangeCode(
8725
+ target,
8726
+ exchange.code,
8727
+ options?.signal ? { signal: options.signal } : void 0
8728
+ );
8729
+ return token.access_token;
8730
+ }
8731
+ async withDeviceAuthRead(run, options) {
8732
+ const accountId = this.requireAccountId();
8733
+ const token = await this.ensureValid(options);
8734
+ try {
8735
+ return await run(token, accountId);
8736
+ } catch (error) {
8737
+ if (!(error instanceof EpicPermissionError)) throw error;
8738
+ const readToken = await this.readCapableToken(options);
8739
+ return run(readToken, accountId);
8740
+ }
8741
+ }
8718
8742
  listDeviceAuths(options) {
8719
- return this.deviceAuths.list(this.accessToken, this.requireAccountId(), options);
8743
+ return this.withDeviceAuthRead(
8744
+ (token, accountId) => this.deviceAuths.list(token, accountId, options),
8745
+ options
8746
+ );
8720
8747
  }
8721
8748
  createDeviceAuth(options) {
8722
8749
  return this.deviceAuths.create(this.accessToken, this.requireAccountId(), options);
8723
8750
  }
8724
8751
  getDeviceAuth(deviceId, options) {
8725
- return this.deviceAuths.get(this.accessToken, this.requireAccountId(), deviceId, options);
8752
+ return this.withDeviceAuthRead(
8753
+ (token, accountId) => this.deviceAuths.get(token, accountId, deviceId, options),
8754
+ options
8755
+ );
8726
8756
  }
8727
8757
  deleteDeviceAuth(deviceId, options) {
8728
8758
  return this.deviceAuths.delete(this.accessToken, this.requireAccountId(), deviceId, options);