@yaelouuu/fortnite-api 1.0.1 → 1.2.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/client.d.ts CHANGED
@@ -3,6 +3,8 @@ import { TournamentsResource } from "./resources/tournaments";
3
3
  import { ProfilesResource } from "./resources/profiles";
4
4
  import { CalendarResource } from "./resources/calendar";
5
5
  import { BundlesResource } from "./resources/bundles";
6
+ import { OauthResource } from "./resources/oauth";
7
+ import { ParsingResource } from "./resources/parsing";
6
8
  export interface ClientOptions {
7
9
  apiKey: string;
8
10
  baseUrl?: string;
@@ -15,9 +17,15 @@ export declare class FortniteAPI {
15
17
  profiles: ProfilesResource;
16
18
  calendar: CalendarResource;
17
19
  bundles: BundlesResource;
20
+ oauth: OauthResource;
21
+ parsing: ParsingResource;
18
22
  constructor(options: ClientOptions);
19
23
  /**
20
24
  * Internal method to make HTTP requests
21
25
  */
22
26
  request<T>(endpoint: string, options?: RequestInit): Promise<T>;
27
+ /**
28
+ * Internal method for multipart/form-data requests (file uploads)
29
+ */
30
+ requestMultipart<T>(endpoint: string, formData: FormData): Promise<T>;
23
31
  }
package/dist/client.js CHANGED
@@ -7,6 +7,8 @@ const profiles_1 = require("./resources/profiles");
7
7
  const calendar_1 = require("./resources/calendar");
8
8
  const errors_1 = require("./errors");
9
9
  const bundles_1 = require("./resources/bundles");
10
+ const oauth_1 = require("./resources/oauth");
11
+ const parsing_1 = require("./resources/parsing");
10
12
  class FortniteAPI {
11
13
  constructor(options) {
12
14
  this.apiKey = options.apiKey;
@@ -18,6 +20,8 @@ class FortniteAPI {
18
20
  this.profiles = new profiles_1.ProfilesResource(this);
19
21
  this.calendar = new calendar_1.CalendarResource(this);
20
22
  this.bundles = new bundles_1.BundlesResource(this);
23
+ this.oauth = new oauth_1.OauthResource(this);
24
+ this.parsing = new parsing_1.ParsingResource(this);
21
25
  }
22
26
  /**
23
27
  * Internal method to make HTTP requests
@@ -45,5 +49,31 @@ class FortniteAPI {
45
49
  const data = await response.json();
46
50
  return data;
47
51
  }
52
+ /**
53
+ * Internal method for multipart/form-data requests (file uploads)
54
+ */
55
+ async requestMultipart(endpoint, formData) {
56
+ const url = `${this.baseUrl}${endpoint}`;
57
+ const response = await fetch(url, {
58
+ method: "POST",
59
+ headers: {
60
+ "x-api-key": this.apiKey,
61
+ // Don't set Content-Type - browser/node will set it with boundary
62
+ },
63
+ body: formData,
64
+ });
65
+ if (!response.ok) {
66
+ let errorData;
67
+ try {
68
+ errorData = await response.json();
69
+ }
70
+ catch {
71
+ errorData = { error: "Request failed" };
72
+ }
73
+ throw new errors_1.FortniteAPIError(errorData.error || `Request failed with status ${response.status}`, response.status, errorData);
74
+ }
75
+ const data = await response.json();
76
+ return data;
77
+ }
48
78
  }
49
79
  exports.FortniteAPI = FortniteAPI;
@@ -0,0 +1,30 @@
1
+ import { FortniteAPI } from "../client";
2
+ import { OAuthCompleteResponse, OAuthDeviceRefreshResponse, OAuthFlowResponse, OAuthRefreshResponse } from "../types";
3
+ export declare class OauthResource {
4
+ private client;
5
+ constructor(client: FortniteAPI);
6
+ /**
7
+ * Initiate OAuth flow - GET /oauth/get-token
8
+ * Returns a verification URL for the user to authenticate
9
+ */
10
+ getToken(): Promise<OAuthFlowResponse>;
11
+ /**
12
+ * Complete OAuth flow - POST /oauth/complete
13
+ * Call this after user has visited the verification URL
14
+ */
15
+ completeOauth(flowId: string): Promise<OAuthCompleteResponse>;
16
+ /**
17
+ * Refresh access token - POST /oauth/refresh-token
18
+ * Use when access token expires (~2 hours)
19
+ */
20
+ refreshToken(refreshToken: string): Promise<OAuthRefreshResponse>;
21
+ /**
22
+ * Refresh with device auth - POST /oauth/refresh-device
23
+ * Use device auth credentials to get fresh tokens (never expires)
24
+ */
25
+ refreshDevice(params: {
26
+ accountId: string;
27
+ deviceId: string;
28
+ secret: string;
29
+ }): Promise<OAuthDeviceRefreshResponse>;
30
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OauthResource = void 0;
4
+ class OauthResource {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ /**
9
+ * Initiate OAuth flow - GET /oauth/get-token
10
+ * Returns a verification URL for the user to authenticate
11
+ */
12
+ async getToken() {
13
+ return this.client.request("/oauth/get-token");
14
+ }
15
+ /**
16
+ * Complete OAuth flow - POST /oauth/complete
17
+ * Call this after user has visited the verification URL
18
+ */
19
+ async completeOauth(flowId) {
20
+ return this.client.request("/oauth/complete", {
21
+ method: "POST",
22
+ body: JSON.stringify({ flowId }),
23
+ });
24
+ }
25
+ /**
26
+ * Refresh access token - POST /oauth/refresh-token
27
+ * Use when access token expires (~2 hours)
28
+ */
29
+ async refreshToken(refreshToken) {
30
+ return this.client.request("/oauth/refresh-token", {
31
+ method: "POST",
32
+ body: JSON.stringify({ refreshToken }),
33
+ });
34
+ }
35
+ /**
36
+ * Refresh with device auth - POST /oauth/refresh-device
37
+ * Use device auth credentials to get fresh tokens (never expires)
38
+ */
39
+ async refreshDevice(params) {
40
+ return this.client.request("/oauth/refresh-device", {
41
+ method: "POST",
42
+ body: JSON.stringify(params),
43
+ });
44
+ }
45
+ }
46
+ exports.OauthResource = OauthResource;
@@ -0,0 +1,18 @@
1
+ import { FortniteAPI } from "../client";
2
+ import { ParsedReplayData } from "../types";
3
+ export declare class ParsingResource {
4
+ private client;
5
+ constructor(client: FortniteAPI);
6
+ /**
7
+ * Parse a single Fortnite replay file
8
+ * @param file - File object (Browser) or Blob/Buffer (Node.js)
9
+ * @param filename - Optional filename (required in Node.js)
10
+ */
11
+ parseReplay(file: File | Blob, filename?: string): Promise<ParsedReplayData>;
12
+ /**
13
+ * Parse multiple Fortnite replay files in batch
14
+ * @param files - Array of File objects or Blobs
15
+ * @param filenames - Optional array of filenames (required in Node.js)
16
+ */
17
+ parseMultipleReplays(files: (File | Blob)[], filenames?: string[]): Promise<ParsedReplayData[]>;
18
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParsingResource = void 0;
4
+ class ParsingResource {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ /**
9
+ * Parse a single Fortnite replay file
10
+ * @param file - File object (Browser) or Blob/Buffer (Node.js)
11
+ * @param filename - Optional filename (required in Node.js)
12
+ */
13
+ async parseReplay(file, filename) {
14
+ const formData = new FormData();
15
+ // In browser: File object has name
16
+ // In Node.js: Need to pass filename
17
+ if (file instanceof File) {
18
+ formData.append("File", file);
19
+ }
20
+ else {
21
+ formData.append("File", file, filename || "replay.replay");
22
+ }
23
+ const response = await this.client.requestMultipart("/parsing", formData);
24
+ if (!response.success || !response.data) {
25
+ throw new Error(response.error || "Failed to parse replay");
26
+ }
27
+ return response.data;
28
+ }
29
+ /**
30
+ * Parse multiple Fortnite replay files in batch
31
+ * @param files - Array of File objects or Blobs
32
+ * @param filenames - Optional array of filenames (required in Node.js)
33
+ */
34
+ async parseMultipleReplays(files, filenames) {
35
+ const formData = new FormData();
36
+ files.forEach((file, index) => {
37
+ if (file instanceof File) {
38
+ formData.append("Files", file);
39
+ }
40
+ else {
41
+ const name = filenames?.[index] || `replay-${index}.replay`;
42
+ formData.append("Files", file, name);
43
+ }
44
+ });
45
+ const response = await this.client.requestMultipart("/parsing/multiple", formData);
46
+ if (!response.success || !response.results) {
47
+ throw new Error(response.error || "Failed to parse replays");
48
+ }
49
+ return response.results;
50
+ }
51
+ }
52
+ exports.ParsingResource = ParsingResource;
@@ -58,3 +58,51 @@ export interface SeasonInfo {
58
58
  seasonNumber: number;
59
59
  exTime: number;
60
60
  }
61
+ export interface OAuthFlowResponse {
62
+ success: boolean;
63
+ flowId: string;
64
+ verificationUri: string;
65
+ expiresIn: number;
66
+ }
67
+ export interface OAuthCompleteResponse {
68
+ success: boolean;
69
+ accessToken: string;
70
+ refreshToken: string;
71
+ expiresIn: number;
72
+ accountId: string;
73
+ displayName: string;
74
+ deviceAuth: {
75
+ accountId: string;
76
+ deviceId: string;
77
+ secret: string;
78
+ };
79
+ }
80
+ export interface OAuthRefreshResponse {
81
+ success: boolean;
82
+ accessToken: string;
83
+ refreshToken: string;
84
+ expiresIn: number;
85
+ accountId: string;
86
+ tokenChanged: boolean;
87
+ }
88
+ export interface OAuthDeviceRefreshResponse {
89
+ success: boolean;
90
+ accessToken: string;
91
+ refreshToken: string;
92
+ expiresIn: number;
93
+ accountId: string;
94
+ displayName: string;
95
+ }
96
+ export interface ParsedReplayData {
97
+ [key: string]: any;
98
+ }
99
+ export interface ParsingResponse {
100
+ success: boolean;
101
+ data?: ParsedReplayData;
102
+ error?: string;
103
+ }
104
+ export interface BatchParsingResponse {
105
+ success: boolean;
106
+ results?: ParsedReplayData[];
107
+ error?: string;
108
+ }
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Oauth types
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@yaelouuu/fortnite-api",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "SDK for Fortnite Tournaments API by Royal Arena - Author : yaelouuu",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "prepublishOnly": "npm run build"
9
+ "prepublishOnly": "npm run build",
10
+ "postpublish": "node scripts/notify-discord.js"
10
11
  },
11
12
  "keywords": [
12
13
  "fortnite",