Skip to content

Commit bb8cb7b

Browse files
committed
Add even more methods and change naming
1 parent 3818238 commit bb8cb7b

27 files changed

+5052
-6176
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules
22
dist
33
docs
4-
test.ts
5-
yarn.lock
4+
test.ts

package-lock.json

-5,920
This file was deleted.

package.json

+59-57
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,61 @@
11
{
2-
"name": "@linux123123/jspteroapi",
3-
"version": "2.4.3",
4-
"description": "A pterodactyl v1 api using node-fetch",
5-
"main": "dist/index.js",
6-
"types": "dist/index.d.ts",
7-
"scripts": {
8-
"test": "tsc-watch --onCompilationComplete \"node dist/test.js\"",
9-
"build": "rimraf dist/* && tsc",
10-
"build:publish": "npm run build && rimraf src/",
11-
"lint": "eslint \"src/**\"",
12-
"docs:build": "typedoc --categorizeByGroup --defaultCategory Types --excludeInternal --name JSPteroAPI",
13-
"semantic-release": "semantic-release"
14-
},
15-
"repository": {
16-
"type": "git",
17-
"url": "https://github.com/Linux123123/JSPteroAPI.git"
18-
},
19-
"keywords": [
20-
"Pterodactyl",
21-
"API",
22-
"node-fetch",
23-
"node-js",
24-
"js",
25-
"ptero-api",
26-
"ptero",
27-
"pterodactyl-api",
28-
"API client"
29-
],
30-
"author": "Linux123123",
31-
"license": "MIT",
32-
"bugs": {
33-
"url": "https://github.com/Linux123123/JSPteroAPI/issues"
34-
},
35-
"homepage": "https://github.com/Linux123123/JSPteroAPI#readme",
36-
"dependencies": {
37-
"node-fetch": "^3.0.0",
38-
"sockette": "^2.0.6",
39-
"ws": "^8.2.1"
40-
},
41-
"devDependencies": {
42-
"@amanda-mitchell/semantic-release-npm-multiple": "^2.14.0",
43-
"@microsoft/tsdoc-config": "^0.15.0",
44-
"@types/node": "^16.7.10",
45-
"@types/node-fetch": "^2.5.12",
46-
"@typescript-eslint/eslint-plugin": "^4.30.0",
47-
"@typescript-eslint/parser": "^4.30.0",
48-
"eslint": "^7.32.0",
49-
"eslint-config-prettier": "^8.0.0",
50-
"eslint-plugin-prettier": "^3.4.1",
51-
"eslint-plugin-tsdoc": "^0.2.11",
52-
"prettier": "^2.2.1",
53-
"rimraf": "^3.0.2",
54-
"semantic-release": "^17.4.7",
55-
"tsc-watch": "^4.5.0",
56-
"typedoc": "^0.21.9",
57-
"typescript": "^4.4.2"
58-
}
2+
"name": "@linux123123/jspteroapi",
3+
"version": "2.4.3",
4+
"description": "A pterodactyl v1 api using node-fetch",
5+
"main": "dist/index.js",
6+
"exports": "./dist/index.js",
7+
"types": "dist/index.d.ts",
8+
"scripts": {
9+
"test": "tsc-watch --onCompilationComplete \"node dist/test.js\"",
10+
"build": "rimraf dist/* && tsc",
11+
"build:publish": "yarn build && rimraf src/",
12+
"lint": "eslint \"src/**\"",
13+
"docs:build": "typedoc --categorizeByGroup --defaultCategory Types --excludeInternal --name JSPteroAPI",
14+
"semantic-release": "semantic-release"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/Linux123123/JSPteroAPI.git"
19+
},
20+
"keywords": [
21+
"Pterodactyl",
22+
"API",
23+
"node-fetch",
24+
"node-js",
25+
"js",
26+
"ptero-api",
27+
"ptero",
28+
"pterodactyl-api",
29+
"API client"
30+
],
31+
"author": "Linux123123",
32+
"license": "MIT",
33+
"bugs": {
34+
"url": "https://github.com/Linux123123/JSPteroAPI/issues"
35+
},
36+
"homepage": "https://github.com/Linux123123/JSPteroAPI#readme",
37+
"dependencies": {
38+
"node-fetch": "v2",
39+
"sockette": "^2.0.6",
40+
"ws": "^8.2.2"
41+
},
42+
"devDependencies": {
43+
"@amanda-mitchell/semantic-release-npm-multiple": "^2.14.0",
44+
"@microsoft/tsdoc-config": "^0.15.0",
45+
"@types/node": "^16.9.1",
46+
"@types/node-fetch": "v2",
47+
"@typescript-eslint/eslint-plugin": "^4.31.0",
48+
"@typescript-eslint/parser": "^4.31.0",
49+
"babel-loader": "^8.2.2",
50+
"eslint": "^7.32.0",
51+
"eslint-config-prettier": "^8.0.0",
52+
"eslint-plugin-prettier": "^3.4.1",
53+
"eslint-plugin-tsdoc": "^0.2.11",
54+
"prettier": "^2.4.0",
55+
"rimraf": "^3.0.2",
56+
"semantic-release": "^17.4.7",
57+
"tsc-watch": "^4.5.0",
58+
"typedoc": "^0.21.9",
59+
"typescript": "^4.4.2"
60+
}
5961
}

src/application/ApplicationRequest.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export class Request {
4242
),
4343
);
4444
if (rawData.status == 204) return dataObj;
45-
const res = (await rawData.json()) as Record<string, unknown>;
46-
return res[dataObj] || res;
45+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
46+
let res = (await rawData.json()) as any;
47+
const objArr = dataObj.split('.');
48+
objArr.forEach((obj) => {
49+
res = res[obj];
50+
});
51+
return res;
4752
}
4853
}

src/application/index.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import fetch, { RequestInit } from 'node-fetch'; // import node-fetch
2-
import { allocationMethods } from './methods/allocationMethods';
3-
import { databaseMethods } from './methods/databaseMethods';
4-
import { nestMethods } from './methods/nestMethods';
5-
import { nodeMethods } from './methods/nodeMethods';
6-
import { serverMethods } from './methods/serverMethods';
7-
import { userMethods } from './methods/userMethods';
8-
import { locationMethods } from './methods/locationMethods';
2+
import { allocationMethods } from './methods/allocation';
3+
import { databaseMethods } from './methods/database';
4+
import { nestMethods } from './methods/nest';
5+
import { nodeMethods } from './methods/node';
6+
import { serverMethods } from './methods/server';
7+
import { userMethods } from './methods/user';
8+
import { locationMethods } from './methods/location';
99
import { Request } from './ApplicationRequest';
1010
import { JSPteroAPIError } from '../modules/Error';
1111
class Application {
@@ -26,6 +26,11 @@ class Application {
2626
if (host.endsWith('/')) host = host.slice(0, -1);
2727
this.host = host;
2828
if (!fast) this.testAPI();
29+
this.request = new Request(
30+
this.host,
31+
this.key,
32+
this.errorHandler,
33+
).request;
2934
const servermethods = new serverMethods(this);
3035
this.getAllServers = servermethods.getAllServers;
3136
this.getServerInfo = servermethods.getServerInfo;
@@ -99,8 +104,7 @@ class Application {
99104
/**
100105
@internal
101106
*/
102-
public request = new Request(this.host, this.host, this.errorHandler)
103-
.request;
107+
public request;
104108

105109
// GET
106110
public getAllServers;

src/application/methods/allocationMethods.ts src/application/methods/allocation.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
AllocationIncludeInput,
55
Allocations,
66
} from '../interfaces/Allocation';
7-
import { Application } from '..';
7+
import { Application } from '../index';
88

99
export class allocationMethods {
1010
constructor(private readonly application: Application) {}
@@ -50,24 +50,24 @@ export class allocationMethods {
5050
};
5151
/**
5252
* @param nodeId - The node id of which you want to create allocations
53-
* @param ip - IP for the allocation
5453
* @param ports - Ports array to add
5554
* @param alias - The alias for this allocation
55+
* @param ip - IP for the allocation
5656
* @returns If successful returns Successfully created!
5757
* @example
5858
* ```ts
59-
* const res = await app.createAllocation(1, undefined, ['25565']) // res = Successfully created!
59+
* const res = await app.createAllocation(1, ['25565']) // res = Successfully created!
6060
* ```
6161
* @example
6262
* ```ts
63-
* app.createAllocation(1, undefined, ['25565'], 'minecraft').then((res) => console.log(res)) // res = Successfully created!
63+
* app.createAllocation(1, ['25565'], 'minecraft').then((res) => console.log(res)) // res = Successfully created!
6464
* ```
6565
*/
6666
public createAllocation = async (
6767
nodeId: number,
68-
ip = '0.0.0.0',
6968
ports: string[],
7069
alias = '',
70+
ip = '0.0.0.0',
7171
): Promise<string> => {
7272
return this.application.request(
7373
'POST',

src/application/methods/databaseMethods.ts src/application/methods/database.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
DatabaseAttributes,
55
DatabaseIncludeInput,
66
} from '../interfaces/Database';
7-
import { Application } from '..';
7+
import { Application } from '../index';
88

99
export class databaseMethods {
1010
constructor(private readonly application: Application) {}

src/application/methods/locationMethods.ts src/application/methods/location.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
LocationIncludeInput,
88
Locations,
99
} from '../interfaces/Location';
10-
import { Application } from '..';
10+
import { Application } from '../index';
1111

1212
export class locationMethods {
1313
constructor(private readonly application: Application) {}

src/application/methods/nestMethods.ts src/application/methods/nest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
NestIncludeInput,
88
Nests,
99
} from '../interfaces/Nest';
10-
import { Application } from '..';
10+
import { Application } from '../index';
1111

1212
export class nestMethods {
1313
constructor(private readonly application: Application) {}

src/application/methods/nodeMethods.ts src/application/methods/node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
NodeIncludeInput,
99
Nodes,
1010
} from '../interfaces/Node';
11-
import { Application } from '..';
11+
import { Application } from '../index';
1212

1313
export class nodeMethods {
1414
constructor(private readonly application: Application) {}

src/application/methods/serverMethods.ts src/application/methods/server.ts

+24-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
ServerIncludesInput,
1111
Servers,
1212
} from '../interfaces/Server';
13-
import { Application } from '..';
13+
import { Application } from '../index';
1414

1515
export class serverMethods {
1616
constructor(private readonly application: Application) {}
@@ -127,7 +127,7 @@ export class serverMethods {
127127
description: options.description ?? server.description,
128128
},
129129
'attributes',
130-
`/api/application/servers/${serverId}/details$${makeOptions({
130+
`/api/application/servers/${serverId}/details${makeOptions({
131131
includes: { ...options.options },
132132
})}`,
133133
);
@@ -310,20 +310,28 @@ export class serverMethods {
310310
const envVars: Record<string, unknown> = {};
311311
let givenEnvVars: string[] = [];
312312
if (environment) givenEnvVars = Object.keys(environment);
313-
egg.relationships?.variables?.data.forEach((envVar) => {
314-
const envVariable = envVar.attributes.env_variable;
315-
if (givenEnvVars.includes(envVariable)) {
316-
envVars[envVariable] = environment?.[envVariable];
317-
} else if (envVar.attributes.rules.includes('nullable')) {
318-
envVars[envVariable] = '';
319-
} else if (envVar.attributes.default_value) {
320-
envVars[envVariable] = envVar.attributes.default_value;
321-
} else {
322-
throw new Error(
323-
`Environment variable ${envVariable} was not defined!`,
324-
);
325-
}
326-
});
313+
egg.relationships?.variables?.data.forEach(
314+
(envVar: {
315+
attributes: {
316+
env_variable: string;
317+
rules: string;
318+
default_value: string;
319+
};
320+
}) => {
321+
const envVariable = envVar.attributes.env_variable;
322+
if (givenEnvVars.includes(envVariable)) {
323+
envVars[envVariable] = environment?.[envVariable];
324+
} else if (envVar.attributes.rules.includes('nullable')) {
325+
envVars[envVariable] = '';
326+
} else if (envVar.attributes.default_value) {
327+
envVars[envVariable] = envVar.attributes.default_value;
328+
} else {
329+
throw new Error(
330+
`Environment variable ${envVariable} was not defined!`,
331+
);
332+
}
333+
},
334+
);
327335
return this.application.request(
328336
'POST',
329337
{

src/application/methods/userMethods.ts src/application/methods/user.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Application } from '..';
1+
import { Application } from '../index';
22
import { makeOptions, MakeOpts, paginate } from '../../modules/Functions';
33
import {
44
EditUserOptions,

src/client/ClientRequest.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ export class Request {
4545
);
4646
if (rawData.status == 204) return dataObj;
4747
if (text) return await rawData.text();
48-
const res = (await rawData.json()) as Record<string, unknown>;
49-
return !dataObj.includes(' ')
50-
? res[dataObj] || res
51-
: (res[dataObj.split(' ')[0]] as Record<string, unknown>)[
52-
dataObj.split(' ')[1]
53-
];
48+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
49+
let res = (await rawData.json()) as any;
50+
const objArr = dataObj.split('.');
51+
objArr.forEach((obj) => {
52+
res = res[obj];
53+
});
54+
return res;
5455
}
5556
}

0 commit comments

Comments
 (0)