@yaelouuu/fortnite-api 1.1.0 → 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 +6 -0
- package/dist/client.js +28 -0
- package/dist/resources/parsing.d.ts +18 -0
- package/dist/resources/parsing.js +52 -0
- package/dist/types/index.d.ts +13 -0
- package/package.json +3 -2
package/dist/client.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ProfilesResource } from "./resources/profiles";
|
|
|
4
4
|
import { CalendarResource } from "./resources/calendar";
|
|
5
5
|
import { BundlesResource } from "./resources/bundles";
|
|
6
6
|
import { OauthResource } from "./resources/oauth";
|
|
7
|
+
import { ParsingResource } from "./resources/parsing";
|
|
7
8
|
export interface ClientOptions {
|
|
8
9
|
apiKey: string;
|
|
9
10
|
baseUrl?: string;
|
|
@@ -17,9 +18,14 @@ export declare class FortniteAPI {
|
|
|
17
18
|
calendar: CalendarResource;
|
|
18
19
|
bundles: BundlesResource;
|
|
19
20
|
oauth: OauthResource;
|
|
21
|
+
parsing: ParsingResource;
|
|
20
22
|
constructor(options: ClientOptions);
|
|
21
23
|
/**
|
|
22
24
|
* Internal method to make HTTP requests
|
|
23
25
|
*/
|
|
24
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>;
|
|
25
31
|
}
|
package/dist/client.js
CHANGED
|
@@ -8,6 +8,7 @@ const calendar_1 = require("./resources/calendar");
|
|
|
8
8
|
const errors_1 = require("./errors");
|
|
9
9
|
const bundles_1 = require("./resources/bundles");
|
|
10
10
|
const oauth_1 = require("./resources/oauth");
|
|
11
|
+
const parsing_1 = require("./resources/parsing");
|
|
11
12
|
class FortniteAPI {
|
|
12
13
|
constructor(options) {
|
|
13
14
|
this.apiKey = options.apiKey;
|
|
@@ -20,6 +21,7 @@ class FortniteAPI {
|
|
|
20
21
|
this.calendar = new calendar_1.CalendarResource(this);
|
|
21
22
|
this.bundles = new bundles_1.BundlesResource(this);
|
|
22
23
|
this.oauth = new oauth_1.OauthResource(this);
|
|
24
|
+
this.parsing = new parsing_1.ParsingResource(this);
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Internal method to make HTTP requests
|
|
@@ -47,5 +49,31 @@ class FortniteAPI {
|
|
|
47
49
|
const data = await response.json();
|
|
48
50
|
return data;
|
|
49
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
|
+
}
|
|
50
78
|
}
|
|
51
79
|
exports.FortniteAPI = FortniteAPI;
|
|
@@ -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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -93,3 +93,16 @@ export interface OAuthDeviceRefreshResponse {
|
|
|
93
93
|
accountId: string;
|
|
94
94
|
displayName: string;
|
|
95
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaelouuu/fortnite-api",
|
|
3
|
-
"version": "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",
|