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.d.cts CHANGED
@@ -5077,6 +5077,8 @@ declare class EpicAuthSession {
5077
5077
  rankedProgressAll(accountId?: string, options?: HabaneroProgressOptions): Promise<HabaneroProgress[]>;
5078
5078
  rankedProgressBulk(trackguid: string, accountIds: string[], options?: HabaneroBaseOptions): Promise<HabaneroProgress[]>;
5079
5079
  rankedProgressBulkByType(rankingType: RankingType | (string & {}), accountIds: string[], options?: HabaneroRankingTypeOptions): Promise<HabaneroProgress[]>;
5080
+ private readCapableToken;
5081
+ private withDeviceAuthRead;
5080
5082
  listDeviceAuths(options?: {
5081
5083
  signal?: AbortSignal;
5082
5084
  }): Promise<DeviceAuth[]>;
@@ -5524,8 +5526,8 @@ declare const Routes: {
5524
5526
  readonly statsByAccountId: (accountId: string) => string;
5525
5527
  };
5526
5528
 
5527
- declare const VERSION = "2.0.0-beta.0";
5528
- declare const USER_AGENT = "fnapi-js/2.0.0-beta.0 (+https://github.com/AjaxFNC-YT/fnapi-js)";
5529
+ declare const VERSION = "2.0.1-beta.0";
5530
+ declare const USER_AGENT = "fnapi-js/2.0.1-beta.0 (+https://github.com/AjaxFNC-YT/fnapi-js)";
5529
5531
 
5530
5532
  interface LockerCosmeticSource {
5531
5533
  all(): Promise<AllCosmetics>;
package/dist/index.d.ts CHANGED
@@ -5077,6 +5077,8 @@ declare class EpicAuthSession {
5077
5077
  rankedProgressAll(accountId?: string, options?: HabaneroProgressOptions): Promise<HabaneroProgress[]>;
5078
5078
  rankedProgressBulk(trackguid: string, accountIds: string[], options?: HabaneroBaseOptions): Promise<HabaneroProgress[]>;
5079
5079
  rankedProgressBulkByType(rankingType: RankingType | (string & {}), accountIds: string[], options?: HabaneroRankingTypeOptions): Promise<HabaneroProgress[]>;
5080
+ private readCapableToken;
5081
+ private withDeviceAuthRead;
5080
5082
  listDeviceAuths(options?: {
5081
5083
  signal?: AbortSignal;
5082
5084
  }): Promise<DeviceAuth[]>;
@@ -5524,8 +5526,8 @@ declare const Routes: {
5524
5526
  readonly statsByAccountId: (accountId: string) => string;
5525
5527
  };
5526
5528
 
5527
- declare const VERSION = "2.0.0-beta.0";
5528
- declare const USER_AGENT = "fnapi-js/2.0.0-beta.0 (+https://github.com/AjaxFNC-YT/fnapi-js)";
5529
+ declare const VERSION = "2.0.1-beta.0";
5530
+ declare const USER_AGENT = "fnapi-js/2.0.1-beta.0 (+https://github.com/AjaxFNC-YT/fnapi-js)";
5529
5531
 
5530
5532
  interface LockerCosmeticSource {
5531
5533
  all(): Promise<AllCosmetics>;
package/dist/index.js CHANGED
@@ -1094,7 +1094,7 @@ var StatsEndpoint = class extends BaseEndpoint {
1094
1094
  };
1095
1095
 
1096
1096
  // src/core/version.ts
1097
- var VERSION = "2.0.0-beta.0";
1097
+ var VERSION = "2.0.1-beta.0";
1098
1098
  var USER_AGENT = `fnapi-js/${VERSION} (+https://github.com/AjaxFNC-YT/fnapi-js)`;
1099
1099
 
1100
1100
  // src/core/response.ts
@@ -8713,14 +8713,44 @@ var EpicAuthSession = class _EpicAuthSession {
8713
8713
  options
8714
8714
  );
8715
8715
  }
8716
+ async readCapableToken(options) {
8717
+ const target = resolveAuthClient("fortnitePC");
8718
+ const exchange = await this.auth.createExchangeCode(this.accessToken, {
8719
+ consumingClientId: target.clientId,
8720
+ ...options?.signal ? { signal: options.signal } : {}
8721
+ });
8722
+ const token = await this.auth.exchangeCode(
8723
+ target,
8724
+ exchange.code,
8725
+ options?.signal ? { signal: options.signal } : void 0
8726
+ );
8727
+ return token.access_token;
8728
+ }
8729
+ async withDeviceAuthRead(run, options) {
8730
+ const accountId = this.requireAccountId();
8731
+ const token = await this.ensureValid(options);
8732
+ try {
8733
+ return await run(token, accountId);
8734
+ } catch (error) {
8735
+ if (!(error instanceof EpicPermissionError)) throw error;
8736
+ const readToken = await this.readCapableToken(options);
8737
+ return run(readToken, accountId);
8738
+ }
8739
+ }
8716
8740
  listDeviceAuths(options) {
8717
- return this.deviceAuths.list(this.accessToken, this.requireAccountId(), options);
8741
+ return this.withDeviceAuthRead(
8742
+ (token, accountId) => this.deviceAuths.list(token, accountId, options),
8743
+ options
8744
+ );
8718
8745
  }
8719
8746
  createDeviceAuth(options) {
8720
8747
  return this.deviceAuths.create(this.accessToken, this.requireAccountId(), options);
8721
8748
  }
8722
8749
  getDeviceAuth(deviceId, options) {
8723
- return this.deviceAuths.get(this.accessToken, this.requireAccountId(), deviceId, options);
8750
+ return this.withDeviceAuthRead(
8751
+ (token, accountId) => this.deviceAuths.get(token, accountId, deviceId, options),
8752
+ options
8753
+ );
8724
8754
  }
8725
8755
  deleteDeviceAuth(deviceId, options) {
8726
8756
  return this.deviceAuths.delete(this.accessToken, this.requireAccountId(), deviceId, options);