mirror of
https://github.com/tribufu/sdk-js
synced 2025-06-16 18:44:18 +00:00
Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
bf2f448dc9 | |||
6b3873dae1 | |||
70cb6c6bc9 | |||
ea9d87f5ab | |||
f8d2153123 | |||
76cd15fc4c | |||
9c54143d2e | |||
10a0619f80 | |||
5081c11ad5 | |||
3bc568dcb4 | |||
864b46c4a2 | |||
1ab428cfd7 | |||
f02a66c09c | |||
1cf38a35de | |||
be08efe49f | |||
009dfc04ab | |||
962a3de36a | |||
55b4e64594 | |||
b0788d5f72 | |||
14572419cf | |||
db828be54a | |||
b48ee646e1 | |||
80ec992b89 | |||
a2fc56a98f | |||
10cd001665 | |||
93d89995b5 | |||
b5d1e086f3 | |||
332c0b2fa6 | |||
e04da0a06c | |||
a3dfa0d4f4 | |||
6a8fe8d988 | |||
744c6771b3 | |||
c441ff7ff5 | |||
2a3c9854e6 | |||
6d631ffea8 | |||
4186350f7e | |||
485d19b9f2 | |||
51addfcd53 | |||
725b5f1a4c | |||
a1021ecd86 | |||
52dca6a519 | |||
23dac26596 | |||
db6a2cd5da | |||
804a116b7b | |||
ab304a8b08 | |||
23c6f5b30a | |||
c6136b6e21 | |||
b4d074420a | |||
a83926229a | |||
7fa3386cba | |||
7c22788be4 | |||
86abc9877e |
@ -1,15 +1,17 @@
|
|||||||
root = true
|
root = true
|
||||||
|
|
||||||
[*]
|
[*]
|
||||||
end_of_line = lf
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
trim_trailing_whitespace = true
|
end_of_line = lf
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
max_line_length = 120
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
|
indent_size = 1
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
[*.env*]
|
[.env*]
|
||||||
insert_final_newline = false
|
insert_final_newline = false
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
NODE_ENV=development
|
||||||
TRIBUFU_API_KEY=
|
TRIBUFU_API_KEY=
|
||||||
TRIBUFU_API_URL=
|
TRIBUFU_API_URL=
|
||||||
TRIBUFU_BOT_TOKEN=
|
TRIBUFU_BOT_TOKEN=
|
||||||
|
1
.prettierignore
Normal file
1
.prettierignore
Normal file
@ -0,0 +1 @@
|
|||||||
|
src/api.generated.ts
|
@ -1,15 +1,16 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
// Copyright (c) Tribufu. All Rights Reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT AND Apache-2.0
|
||||||
|
|
||||||
import dotenv from 'dotenv';
|
import dotenv from "dotenv";
|
||||||
import { TribufuApi } from '../build/index.mjs';
|
import { TribufuApi } from "../build/index.mjs";
|
||||||
|
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const api = TribufuApi.fromEnv("TRIBUFU");
|
const tribufu = TribufuApi.fromEnv();
|
||||||
const games = await api.getGames();
|
console.log(
|
||||||
console.log(games[0]);
|
await tribufu.getServerByAddressAndQueryPort("mine.tribufu.com", 25565),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import dotenv from 'dotenv';
|
|
||||||
import { TribufuBot } from '../build/index.mjs';
|
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
const bot = TribufuBot.fromEnv("TRIBUFU");
|
|
||||||
const botId = bot.getBotId();
|
|
@ -1,18 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import dotenv from 'dotenv';
|
|
||||||
import { TribufuClient } from '../build/index.mjs';
|
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const client = TribufuClient.fromEnv("TRIBUFU");
|
|
||||||
|
|
||||||
if (await client.passwordLogin("", "")) {
|
|
||||||
const userInfo = await client.getUserInfo();
|
|
||||||
console.log(userInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main();
|
|
@ -1,11 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import dotenv from 'dotenv';
|
|
||||||
import { TribufuServer } from '../build/index.mjs';
|
|
||||||
|
|
||||||
dotenv.config();
|
|
||||||
|
|
||||||
const server = TribufuServer.fromEnv("TRIBUFU");
|
|
||||||
const serverId = server.getServerId();
|
|
||||||
const clientId = server.getClientId();
|
|
19
package.json
19
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tribufu",
|
"name": "tribufu",
|
||||||
"version": "0.1.13",
|
"version": "1.0.1",
|
||||||
"description": "Tribufu JS SDK",
|
"description": "Tribufu JS SDK",
|
||||||
"repository": "https://github.com/Tribufu/TribufuJs",
|
"repository": "https://github.com/Tribufu/TribufuJs",
|
||||||
"author": "Tribufu <contact@Tribufu.com>",
|
"author": "Tribufu <contact@Tribufu.com>",
|
||||||
@ -9,21 +9,28 @@
|
|||||||
"types": "./build/index.d.ts",
|
"types": "./build/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
"import": "./build/index.mjs",
|
"import": "./build/index.mjs",
|
||||||
"require": "./build/index.cjs"
|
"require": "./build/index.cjs",
|
||||||
|
"types": "./build/index.d.ts"
|
||||||
|
},
|
||||||
|
"typesVersions": {
|
||||||
|
"*": {
|
||||||
|
"*": [
|
||||||
|
"./build/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf build",
|
"clean": "rimraf build",
|
||||||
"build": "npm run clean && tsc && node scripts/esbuild.js"
|
"build": "npm run clean && tsc && node scripts/esbuild.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {},
|
||||||
"@tribufu/mintaka": "0.1.7"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.10.6",
|
"@types/node": "^20.10.6",
|
||||||
"cross-env": "^7.0.3",
|
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"esbuild": "^0.19.10",
|
"esbuild": "^0.19.10",
|
||||||
"esbuild-node-externals": "^1.12.0",
|
"esbuild-node-externals": "^1.12.0",
|
||||||
|
"eslint": "9.11.1",
|
||||||
|
"prettier": "3.3.3",
|
||||||
"rimraf": "^5.0.5",
|
"rimraf": "^5.0.5",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^5.3.3"
|
||||||
}
|
}
|
||||||
|
1454
pnpm-lock.yaml
generated
1454
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -22,12 +22,26 @@ const moduleConfig = {
|
|||||||
format: "esm",
|
format: "esm",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const moduleMinConfig = {
|
||||||
|
...moduleConfig,
|
||||||
|
outfile: "build/index.min.mjs",
|
||||||
|
minify: true,
|
||||||
|
sourcemap: true,
|
||||||
|
};
|
||||||
|
|
||||||
const legacyConfig = {
|
const legacyConfig = {
|
||||||
...baseConfig,
|
...baseConfig,
|
||||||
outfile: "build/index.cjs",
|
outfile: "build/index.cjs",
|
||||||
format: "cjs",
|
format: "cjs",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const legacyMinConfig = {
|
||||||
|
...legacyConfig,
|
||||||
|
outfile: "build/index.min.cjs",
|
||||||
|
minify: true,
|
||||||
|
sourcemap: true,
|
||||||
|
};
|
||||||
|
|
||||||
async function addCopyrightHeader(filename) {
|
async function addCopyrightHeader(filename) {
|
||||||
const header = `// Copyright (c) Tribufu. All Rights Reserved.\n// SPDX-License-Identifier: MIT\n\n`;
|
const header = `// Copyright (c) Tribufu. All Rights Reserved.\n// SPDX-License-Identifier: MIT\n\n`;
|
||||||
const content = await fs.readFile(filename, 'utf-8');
|
const content = await fs.readFile(filename, 'utf-8');
|
||||||
@ -44,5 +58,8 @@ async function buildAndAddHeader(config) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
await buildAndAddHeader(moduleConfig);
|
|
||||||
await buildAndAddHeader(legacyConfig);
|
await buildAndAddHeader(legacyConfig);
|
||||||
|
await buildAndAddHeader(moduleConfig);
|
||||||
|
|
||||||
|
//await buildAndAddHeader(legacyMinConfig);
|
||||||
|
//await buildAndAddHeader(moduleMinConfig);
|
||||||
|
3
scripts/nswag.ps1
Normal file
3
scripts/nswag.ps1
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
nswag run ./src/api/api.nswag
|
427
src/api.ts
427
src/api.ts
@ -1,427 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import { HttpHeaders, HttpClient } from "@tribufu/mintaka";
|
|
||||||
import { JavaScriptRuntime } from "./node";
|
|
||||||
import { JsonCasing, JwtDecoder } from "@tribufu/mintaka";
|
|
||||||
import { TokenPayload } from "./token";
|
|
||||||
import { TRIBUFU_API_URL, TRIBUFU_VERSION } from ".";
|
|
||||||
import { TribufuApiOptions } from "./options";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* **Tribufu API**
|
|
||||||
*
|
|
||||||
* Use this class to interact with the Tribufu API.
|
|
||||||
*
|
|
||||||
* *There are three ways to use the Tribufu API:*
|
|
||||||
* - A api key give you public read only access to the Tribufu API.
|
|
||||||
* - A bot give you read and write access to the Tribufu API as a bot account.
|
|
||||||
* - A client give you read and write access to the Tribufu API as a client application.
|
|
||||||
*/
|
|
||||||
export class TribufuApi {
|
|
||||||
protected readonly http: HttpClient;
|
|
||||||
protected readonly options: TribufuApiOptions;
|
|
||||||
|
|
||||||
constructor(options?: TribufuApiOptions | null) {
|
|
||||||
this.options = options || {};
|
|
||||||
|
|
||||||
this.http = new HttpClient({
|
|
||||||
baseUrl: TribufuApi.getBaseUrl(),
|
|
||||||
headers: TribufuApi.defaultHeaders(),
|
|
||||||
enableLog: TribufuApi.debugEnabled(),
|
|
||||||
jsonRequestCasing: JsonCasing.SnakeCase,
|
|
||||||
jsonResponseCasing: JsonCasing.CamelCase,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a TribufuApi with the default options.
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
public static default(): TribufuApi {
|
|
||||||
return new TribufuApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a TribufuApi with the given api key.
|
|
||||||
*
|
|
||||||
* - A api key give you public read only access to the Tribufu API.
|
|
||||||
*
|
|
||||||
* @param apiKey
|
|
||||||
* @returns TribufuApi
|
|
||||||
*/
|
|
||||||
public static withApiKey(apiKey: string): TribufuApi {
|
|
||||||
return new TribufuApi({ apiKey });
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to create a TribufuApi from environment variables.
|
|
||||||
*
|
|
||||||
* - This will only work if the environment variables are set.
|
|
||||||
*
|
|
||||||
* @param prefix A prefix for the environment variables.
|
|
||||||
* @returns TribufuApi | null
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* // process.env.TRIBUFU_API_KEY
|
|
||||||
* const api = TribufuApi.fromEnv("TRIBUFU");
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
public static fromEnv(prefix?: string | null): TribufuApi | null {
|
|
||||||
const envPrefix = prefix ? `${prefix}_` : "";
|
|
||||||
const apiKey = process.env[`${envPrefix}API_KEY`];
|
|
||||||
|
|
||||||
if (apiKey) {
|
|
||||||
return TribufuApi.withApiKey(apiKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a TribufuApi from environment variables or the default api.
|
|
||||||
*
|
|
||||||
* - This will fallback to the default api if the environment variables are not set.
|
|
||||||
*
|
|
||||||
* @param prefix A prefix for the environment variables.
|
|
||||||
* @returns TribufuApi | null
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* // process.env.TRIBUFU_API_KEY = null
|
|
||||||
* const api = TribufuApi.fromEnvOrDefault("TRIBUFU_");
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
public static fromEnvOrDefault(prefix: string = ""): TribufuApi {
|
|
||||||
return TribufuApi.fromEnv(prefix) || TribufuApi.default();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if debug mode is enabled.
|
|
||||||
*
|
|
||||||
* - Debug mode is enabled if the environment variable `NODE_ENV` is set to `development`.
|
|
||||||
* - Debug mode is disabled by default.
|
|
||||||
* - Debug mode is disabled in the browser.
|
|
||||||
*
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
private static debugEnabled(): boolean {
|
|
||||||
return process.env.NODE_ENV ? process.env.NODE_ENV === "development" : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the base url for the Tribufu API.
|
|
||||||
*
|
|
||||||
* - The base url can be set using the environment variable `TRIBUFU_API_URL`.
|
|
||||||
* - The custom base url is only used if debug mode is enabled.
|
|
||||||
* - The default base url is `https://api.tribufu.com`.
|
|
||||||
*
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
private static getBaseUrl(): string {
|
|
||||||
const baseUrl = process.env[`TRIBUFU_API_URL`] || null;
|
|
||||||
return TribufuApi.debugEnabled() && baseUrl ? baseUrl : TRIBUFU_API_URL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the default headers for the Tribufu API.
|
|
||||||
* @returns HeaderMap
|
|
||||||
*/
|
|
||||||
private static defaultHeaders(): HttpHeaders {
|
|
||||||
const headers = new HttpHeaders();
|
|
||||||
headers.set("X-Tribufu-Language", "javascript");
|
|
||||||
headers.set("X-Tribufu-Version", TRIBUFU_VERSION);
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detect the current JavaScript runtime.
|
|
||||||
*
|
|
||||||
* - This is used to determine if the code is running in a browser or in Node.js.
|
|
||||||
*
|
|
||||||
* @returns JavaScriptRuntime
|
|
||||||
*/
|
|
||||||
private static detectRuntime(): JavaScriptRuntime {
|
|
||||||
if (typeof window !== "undefined") {
|
|
||||||
return JavaScriptRuntime.Browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof process !== "undefined" && process?.versions?.node) {
|
|
||||||
return JavaScriptRuntime.Node;
|
|
||||||
}
|
|
||||||
|
|
||||||
return JavaScriptRuntime.Other;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the current JavaScript runtime is a browser.
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public static isBrowser(): boolean {
|
|
||||||
return TribufuApi.detectRuntime() === JavaScriptRuntime.Browser;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the current JavaScript runtime is Node.js.
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public static isNode(): boolean {
|
|
||||||
return TribufuApi.detectRuntime() === JavaScriptRuntime.Node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the payload from a Tribufu token.
|
|
||||||
* @param token
|
|
||||||
* @returns TokenPayload | null
|
|
||||||
*/
|
|
||||||
protected static parseToken(token: string): TokenPayload | null {
|
|
||||||
try {
|
|
||||||
const payload = JwtDecoder.decode(token);
|
|
||||||
|
|
||||||
if (!payload) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return payload as TokenPayload;
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get current headers with the api key or access token.
|
|
||||||
* @returns HeaderMap
|
|
||||||
*/
|
|
||||||
protected getHeaders(): HttpHeaders {
|
|
||||||
let headers = TribufuApi.defaultHeaders();
|
|
||||||
|
|
||||||
if (this.options.apiKey) {
|
|
||||||
headers.set("Authorization", `ApiKey ${this.options.apiKey}`);
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.accessToken) {
|
|
||||||
headers.set("Authorization", `Bearer ${this.options.accessToken}`);
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get games from the Tribufu API.
|
|
||||||
* @param page
|
|
||||||
* @returns Game[]
|
|
||||||
*/
|
|
||||||
public async getGames(page: number = 1): Promise<any[]> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get<any[]>(`/v1/packages?page=${page}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a game from the Tribufu API.
|
|
||||||
* @param id
|
|
||||||
* @returns Game | null
|
|
||||||
*/
|
|
||||||
public async getGameById(id: string): Promise<any | null> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get<any>(`/v1/packages/${id}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get servers from the Tribufu API.
|
|
||||||
* @param page
|
|
||||||
* @returns Server[]
|
|
||||||
*/
|
|
||||||
public async getServers(page: number = 1): Promise<any[]> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get<any[]>(`/v1/servers?page=${page}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a server by id or address from the Tribufu API.
|
|
||||||
* @param idOrAddress
|
|
||||||
* @returns Server | null
|
|
||||||
*/
|
|
||||||
public async getServer(idOrAddress: string): Promise<any> {
|
|
||||||
if (/[.:]/.test(idOrAddress)) {
|
|
||||||
return await this.getServerByAddress(idOrAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await this.getServerById(idOrAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a server by id from the Tribufu API.
|
|
||||||
* @param id
|
|
||||||
* @returns Server | null
|
|
||||||
*/
|
|
||||||
public async getServerById(id: string): Promise<any> {
|
|
||||||
const headers = this.getHeaders()
|
|
||||||
const responseBody = await this.http.get<any>(`/v1/servers/${id}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a server by address from the Tribufu API.
|
|
||||||
* @param address
|
|
||||||
* @returns Server | null
|
|
||||||
*/
|
|
||||||
public async getServerByAddress(address: string): Promise<any> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get(`/v1/servers/address/${address}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a user by id from the Tribufu API.
|
|
||||||
* @param id
|
|
||||||
* @returns User | null
|
|
||||||
*/
|
|
||||||
public async getUserById(id: string): Promise<any> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get(`/v1/users/${id}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a user by uuid from the Tribufu API.
|
|
||||||
* @param uuid
|
|
||||||
* @returns User[]
|
|
||||||
*/
|
|
||||||
public async getUserByUuid(uuid: string): Promise<any[]> {
|
|
||||||
return await this.getUserByKey("uuid", uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a user by name from the Tribufu API.
|
|
||||||
* @param uuid
|
|
||||||
* @returns User[]
|
|
||||||
*/
|
|
||||||
public async getUserByName(name: string): Promise<any[]> {
|
|
||||||
return await this.getUserByKey("name", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a user by email from the Tribufu API.
|
|
||||||
* @param uuid
|
|
||||||
* @returns User[]
|
|
||||||
*/
|
|
||||||
public async getUserByEmail(email: string): Promise<any[]> {
|
|
||||||
return await this.getUserByKey("email", email);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a user by custom key from the Tribufu API.
|
|
||||||
* @param key
|
|
||||||
* @param value
|
|
||||||
* @returns User[]
|
|
||||||
*/
|
|
||||||
private async getUserByKey(key: string, value: string): Promise<any[]> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get<any[]>(`/v1/users?${key}=${value}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all servers for a user from the Tribufu API.
|
|
||||||
* @param userId
|
|
||||||
* @returns Server[]
|
|
||||||
*/
|
|
||||||
public async getUserServers(userId: string): Promise<any[]> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get<any[]>(`/v1/users/${userId}/servers`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a oauth2 client by id from the Tribufu API.
|
|
||||||
* @param id
|
|
||||||
* @returns Client | null
|
|
||||||
*/
|
|
||||||
protected async getClientById(id: string): Promise<any> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get(`/v1/oauth2/clients/${id}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get files from the Tribufu API.
|
|
||||||
* @param page
|
|
||||||
* @returns File[]
|
|
||||||
*/
|
|
||||||
public async getFiles(page: number = 1): Promise<any[]> {
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get<any[]>(`/v1/files?page=${page}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a file by id from the Tribufu API.
|
|
||||||
* @param id
|
|
||||||
* @returns File | null
|
|
||||||
*/
|
|
||||||
public async getFileById(id: string): Promise<any> {
|
|
||||||
const headers = this.getHeaders()
|
|
||||||
const responseBody = await this.http.get<any>(`/v1/files/${id}`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
}
|
|
74
src/api/api.nswag
Normal file
74
src/api/api.nswag
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
{
|
||||||
|
"runtime": "Default",
|
||||||
|
"defaultVariables": null,
|
||||||
|
"documentGenerator": {
|
||||||
|
"fromDocument": {
|
||||||
|
"json": "",
|
||||||
|
"url": "https://api.tribufu.com/v1/openapi.json",
|
||||||
|
"output": null,
|
||||||
|
"newLineBehavior": "Auto"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"codeGenerators": {
|
||||||
|
"openApiToTypeScriptClient": {
|
||||||
|
"className": "TribufuApiGenerated",
|
||||||
|
"moduleName": "",
|
||||||
|
"namespace": "",
|
||||||
|
"typeScriptVersion": 4.3,
|
||||||
|
"template": "Fetch",
|
||||||
|
"promiseType": "Promise",
|
||||||
|
"httpClass": "HttpClient",
|
||||||
|
"withCredentials": false,
|
||||||
|
"useSingletonProvider": false,
|
||||||
|
"injectionTokenType": "OpaqueToken",
|
||||||
|
"rxJsVersion": 6,
|
||||||
|
"dateTimeType": "String",
|
||||||
|
"nullValue": "Null",
|
||||||
|
"generateClientClasses": true,
|
||||||
|
"generateClientInterfaces": false,
|
||||||
|
"generateOptionalParameters": true,
|
||||||
|
"exportTypes": true,
|
||||||
|
"wrapDtoExceptions": false,
|
||||||
|
"exceptionClass": "TribufuApiError",
|
||||||
|
"clientBaseClass": "TribufuApiBase",
|
||||||
|
"wrapResponses": false,
|
||||||
|
"wrapResponseMethods": [],
|
||||||
|
"generateResponseClasses": true,
|
||||||
|
"responseClass": "SwaggerResponse",
|
||||||
|
"protectedMethods": [],
|
||||||
|
"configurationClass": null,
|
||||||
|
"useTransformOptionsMethod": true,
|
||||||
|
"useTransformResultMethod": false,
|
||||||
|
"generateDtoTypes": true,
|
||||||
|
"operationGenerationMode": "SingleClientFromOperationId",
|
||||||
|
"markOptionalProperties": false,
|
||||||
|
"generateCloneMethod": false,
|
||||||
|
"typeStyle": "Interface",
|
||||||
|
"enumStyle": "Enum",
|
||||||
|
"useLeafType": false,
|
||||||
|
"classTypes": [],
|
||||||
|
"extendedClasses": [],
|
||||||
|
"extensionCode": "include.ts",
|
||||||
|
"generateDefaultValues": true,
|
||||||
|
"excludedTypeNames": [],
|
||||||
|
"excludedParameterNames": [],
|
||||||
|
"handleReferences": false,
|
||||||
|
"generateTypeCheckFunctions": false,
|
||||||
|
"generateConstructorInterface": true,
|
||||||
|
"convertConstructorInterfaceData": false,
|
||||||
|
"importRequiredTypes": true,
|
||||||
|
"useGetBaseUrlMethod": false,
|
||||||
|
"baseUrlTokenName": "API_BASE_URL",
|
||||||
|
"queryNullValue": "",
|
||||||
|
"useAbortSignal": false,
|
||||||
|
"inlineNamedDictionaries": false,
|
||||||
|
"inlineNamedAny": false,
|
||||||
|
"includeHttpContext": false,
|
||||||
|
"templateDirectory": null,
|
||||||
|
"serviceHost": null,
|
||||||
|
"serviceSchemes": null,
|
||||||
|
"output": "generated.ts",
|
||||||
|
"newLineBehavior": "LF"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
102
src/api/base.ts
Normal file
102
src/api/base.ts
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// Copyright (c) Tribufu. All Rights Reserved.
|
||||||
|
// SPDX-License-Identifier: UNLICENSED
|
||||||
|
|
||||||
|
import { HttpHeaders } from "../http/headers";
|
||||||
|
import { JavaScriptRuntime } from "../node";
|
||||||
|
import { TRIBUFU_VERSION } from "..";
|
||||||
|
|
||||||
|
export abstract class TribufuApiBase {
|
||||||
|
protected apiKey: string | null = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if debug mode is enabled.
|
||||||
|
*
|
||||||
|
* - Debug mode is enabled if the environment variable `NODE_ENV` is set to `development`.
|
||||||
|
* - Debug mode is disabled by default.
|
||||||
|
* - Debug mode is disabled in the browser.
|
||||||
|
*
|
||||||
|
* @returns boolean
|
||||||
|
*/
|
||||||
|
public static debugEnabled(): boolean {
|
||||||
|
if (typeof process !== "undefined") {
|
||||||
|
return process.env.NODE_ENV === "development";
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect the current JavaScript runtime.
|
||||||
|
*
|
||||||
|
* - This is used to determine if the code is running in a browser or in Node.js.
|
||||||
|
*
|
||||||
|
* @returns JavaScriptRuntime
|
||||||
|
*/
|
||||||
|
public static detectRuntime(): JavaScriptRuntime {
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
return JavaScriptRuntime.Browser;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof process !== "undefined" && process?.versions?.node) {
|
||||||
|
return JavaScriptRuntime.Node;
|
||||||
|
}
|
||||||
|
|
||||||
|
return JavaScriptRuntime.Other;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current JavaScript runtime is a browser.
|
||||||
|
* @returns boolean
|
||||||
|
*/
|
||||||
|
public static isBrowser(): boolean {
|
||||||
|
return TribufuApiBase.detectRuntime() === JavaScriptRuntime.Browser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current JavaScript runtime is Node.js.
|
||||||
|
* @returns boolean
|
||||||
|
*/
|
||||||
|
public static isNode(): boolean {
|
||||||
|
return TribufuApiBase.detectRuntime() === JavaScriptRuntime.Node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default headers for the Tribufu API.
|
||||||
|
* @returns HeaderMap
|
||||||
|
*/
|
||||||
|
protected static defaultHeaders(): HttpHeaders {
|
||||||
|
const headers = {};
|
||||||
|
headers["X-Tribufu-Library"] = "javascript";
|
||||||
|
headers["X-Tribufu-Version"] = TRIBUFU_VERSION;
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current headers with the api key or access token.
|
||||||
|
* @returns HeaderMap
|
||||||
|
*/
|
||||||
|
protected getHeaders(): HttpHeaders {
|
||||||
|
let headers = TribufuApiBase.defaultHeaders();
|
||||||
|
|
||||||
|
if (this.apiKey) {
|
||||||
|
headers["Authorization"] = `ApiKey ${this.apiKey}`;
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transform the options before sending the request.
|
||||||
|
* @param options
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
protected transformOptions(options: RequestInit) {
|
||||||
|
options.headers = {
|
||||||
|
...options.headers,
|
||||||
|
...this.getHeaders(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return Promise.resolve(options);
|
||||||
|
}
|
||||||
|
}
|
3075
src/api/generated.ts
Normal file
3075
src/api/generated.ts
Normal file
File diff suppressed because it is too large
Load Diff
1
src/api/include.ts
Normal file
1
src/api/include.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
import { TribufuApiBase } from "./base";
|
103
src/api/index.ts
Normal file
103
src/api/index.ts
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
// Copyright (c) Tribufu. All Rights Reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import { TRIBUFU_API_URL } from "..";
|
||||||
|
import { TribufuApiBase } from "./base";
|
||||||
|
import { TribufuApiGenerated } from "./generated";
|
||||||
|
import { TribufuApiOptions } from "../options";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* **Tribufu API**
|
||||||
|
*
|
||||||
|
* Use this class to interact with the Tribufu API.
|
||||||
|
*/
|
||||||
|
export class TribufuApi extends TribufuApiGenerated {
|
||||||
|
constructor(options?: TribufuApiOptions | null) {
|
||||||
|
const baseUrl = options?.baseUrl || TribufuApi.getBaseUrl();
|
||||||
|
const http = options?.fetch ? { fetch: options.fetch } : { fetch };
|
||||||
|
super(baseUrl, http);
|
||||||
|
this.apiKey = options?.apiKey || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a TribufuApi with the default options.
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public static default(): TribufuApi {
|
||||||
|
return new TribufuApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a TribufuApi with the given api key.
|
||||||
|
*
|
||||||
|
* - A api key give you public read only access to the Tribufu API.
|
||||||
|
*
|
||||||
|
* @param apiKey
|
||||||
|
* @returns TribufuApi
|
||||||
|
*/
|
||||||
|
public static withApiKey(apiKey: string): TribufuApi {
|
||||||
|
return new TribufuApi({ apiKey });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to create a TribufuApi from environment variables.
|
||||||
|
*
|
||||||
|
* - This will only work if the environment variables are set.
|
||||||
|
*
|
||||||
|
* @param prefix A prefix for the environment variables. Default is `TRIBUFU`.
|
||||||
|
* @returns TribufuApi | null
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* // process.env.TRIBUFU_API_KEY
|
||||||
|
* const api = TribufuApi.fromEnv();
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public static fromEnv(prefix?: string | null): TribufuApi | null {
|
||||||
|
if (typeof process === "undefined") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiKey = process.env[`${prefix || "TRIBUFU"}_API_KEY`];
|
||||||
|
|
||||||
|
if (apiKey) {
|
||||||
|
return TribufuApi.withApiKey(apiKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a TribufuApi from environment variables or the default api.
|
||||||
|
*
|
||||||
|
* - This will fallback to the default api if the environment variables are not set.
|
||||||
|
*
|
||||||
|
* @param prefix A prefix for the environment variables. Default is `TRIBUFU`.
|
||||||
|
* @returns TribufuApi | null
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* // process.env.TRIBUFU_API_KEY = null
|
||||||
|
* const api = TribufuApi.fromEnvOrDefault();
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public static fromEnvOrDefault(prefix: string = ""): TribufuApi {
|
||||||
|
return TribufuApi.fromEnv(prefix) || TribufuApi.default();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the base url for the Tribufu API.
|
||||||
|
*
|
||||||
|
* - The base url can be set using the environment variable `TRIBUFU_API_URL`.
|
||||||
|
* - The custom base url is only used if debug mode is enabled.
|
||||||
|
* - The default base url is `https://api.tribufu.com`.
|
||||||
|
*
|
||||||
|
* @returns string
|
||||||
|
*/
|
||||||
|
protected static getBaseUrl(): string {
|
||||||
|
if (typeof process === "undefined") {
|
||||||
|
return TRIBUFU_API_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseUrl = process.env[`TRIBUFU_API_URL`] || null;
|
||||||
|
return TribufuApiBase.debugEnabled() && baseUrl ? baseUrl : TRIBUFU_API_URL;
|
||||||
|
}
|
||||||
|
}
|
23
src/api/singletion.ts
Normal file
23
src/api/singletion.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (c) Tribufu. All Rights Reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import { TribufuApi } from "./index";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* **Tribufu API**
|
||||||
|
*
|
||||||
|
* Helper class to get a singleton instance of the Tribufu API.
|
||||||
|
*/
|
||||||
|
export class TribufuApiSingleton {
|
||||||
|
private static INSTANCE: TribufuApi | null = null;
|
||||||
|
|
||||||
|
private constructor() {}
|
||||||
|
|
||||||
|
public static getInstance(): TribufuApi {
|
||||||
|
if (!TribufuApiSingleton.INSTANCE) {
|
||||||
|
TribufuApiSingleton.INSTANCE = TribufuApi.fromEnvOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
return TribufuApiSingleton.INSTANCE;
|
||||||
|
}
|
||||||
|
}
|
68
src/bot.ts
68
src/bot.ts
@ -1,68 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import { TribufuApi } from "./api";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* **Tribufu Bot**
|
|
||||||
*
|
|
||||||
* To authenticate a bot you need to use the bot token obtained from the Tribufu Developer Portal.
|
|
||||||
*
|
|
||||||
* - A bot is a special type of user account.
|
|
||||||
* - A bot give you read and write access to the Tribufu API.
|
|
||||||
*/
|
|
||||||
export class TribufuBot extends TribufuApi {
|
|
||||||
private readonly botId: string;
|
|
||||||
|
|
||||||
constructor(token: string) {
|
|
||||||
const payload = TribufuApi.parseToken(token);
|
|
||||||
|
|
||||||
if (!payload) {
|
|
||||||
throw new Error("Invalid token");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.type !== "bot") {
|
|
||||||
throw new Error("Invalid token type");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!payload.bot_id) {
|
|
||||||
throw new Error("Invalid token payload");
|
|
||||||
}
|
|
||||||
|
|
||||||
super({ accessToken: token });
|
|
||||||
|
|
||||||
this.botId = payload.bot_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to create a TribufuBot from environment variables.
|
|
||||||
*
|
|
||||||
* - This will only work if the environment variables are set.
|
|
||||||
*
|
|
||||||
* @param prefix A prefix for the environment variables.
|
|
||||||
* @returns TribufuBot | null
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* // process.env.TRIBUFU_BOT_TOKEN
|
|
||||||
* const bot = TribufuBot.fromEnv("TRIBUFU");
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
public static override fromEnv(prefix?: string | null): TribufuBot | null {
|
|
||||||
const envPrefix = prefix ? `${prefix}_` : "";
|
|
||||||
const token = process.env[`${envPrefix}BOT_TOKEN`];
|
|
||||||
|
|
||||||
if (token) {
|
|
||||||
return new TribufuBot(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the bot id.
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
public getBotId(): string {
|
|
||||||
return this.botId;
|
|
||||||
}
|
|
||||||
}
|
|
362
src/client.ts
362
src/client.ts
@ -1,362 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import { HttpCookieMap, HttpHeaders } from "@tribufu/mintaka";
|
|
||||||
import { OAuth2GrantType, OAuth2IntrospectionRequest, OAuth2IntrospectionResponse, OAuth2TokenRequest, OAuth2TokenResponse } from "@tribufu/mintaka";
|
|
||||||
import { TribufuApi } from "./api";
|
|
||||||
import { User } from "./models/user";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* **Tribufu Client**
|
|
||||||
*
|
|
||||||
* To authenticate a client you need to use the client id and client secret obtained from the Tribufu Developer Portal
|
|
||||||
*
|
|
||||||
* - A client is how external applications interact with the Tribufu API.
|
|
||||||
* - A client give you read and write access to the Tribufu API.
|
|
||||||
* - A client can be used to login users.
|
|
||||||
*/
|
|
||||||
export class TribufuClient extends TribufuApi {
|
|
||||||
private readonly clientId: string;
|
|
||||||
private readonly clientSecret: string;
|
|
||||||
|
|
||||||
constructor(clientId: string, clientSecret: string) {
|
|
||||||
super();
|
|
||||||
this.clientId = clientId;
|
|
||||||
this.clientSecret = clientSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to create a TribufuClient from environment variables.
|
|
||||||
*
|
|
||||||
* - This will only work if the environment variables are set.
|
|
||||||
*
|
|
||||||
* @param prefix A prefix for the environment variables.
|
|
||||||
* @returns TribufuClient | null
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* // process.env.TRIBUFU_CLIENT_ID
|
|
||||||
* // process.env.TRIBUFU_CLIENT_SECRET
|
|
||||||
* const client = TribufuClient.fromEnv("TRIBUFU");
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
public static override fromEnv(prefix?: string | null): TribufuClient | null {
|
|
||||||
const envPrefix = prefix ? `${prefix}_` : "";
|
|
||||||
const clientId = process.env[`${envPrefix}CLIENT_ID`];
|
|
||||||
const clientSecret = process.env[`${envPrefix}CLIENT_SECRET`];
|
|
||||||
|
|
||||||
if (clientId && clientSecret) {
|
|
||||||
return new TribufuClient(clientId, clientSecret);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to create a TribufuClient from environment variables and cookies.
|
|
||||||
*
|
|
||||||
* - This will only work if the environment variables are set.
|
|
||||||
* - The cookies are used to get the access token and refresh token.
|
|
||||||
*
|
|
||||||
* @param cookies Cookies from the request.
|
|
||||||
* @param prefix A prefix for the environment variables.
|
|
||||||
* @returns TribufuClient | null
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* // process.env.TRIBUFU_CLIENT_ID
|
|
||||||
* // process.env.TRIBUFU_CLIENT_SECRET
|
|
||||||
* const cookies = { "access_token": "...", "refresh_token": "..." };
|
|
||||||
* const client = TribufuClient.fromCookies(cookies, "TRIBUFU_");
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
public static fromCookies(cookies: HttpCookieMap, prefix: string = ""): TribufuClient | null {
|
|
||||||
const client = TribufuClient.fromEnv(prefix);
|
|
||||||
const accessToken = cookies["access_token"] || null;
|
|
||||||
const refreshToken = cookies["refresh_token"] || null;
|
|
||||||
|
|
||||||
if (client) {
|
|
||||||
client.setTokens(accessToken, refreshToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tokens.
|
|
||||||
* @param accessToken
|
|
||||||
* @param refreshToken
|
|
||||||
* @param expiresIn
|
|
||||||
*/
|
|
||||||
protected setTokens(accessToken: string | null, refreshToken?: string | null, expiresIn?: number | null): void {
|
|
||||||
this.options.accessToken = accessToken;
|
|
||||||
this.options.refreshToken = refreshToken || null;
|
|
||||||
this.options.expiresIn = expiresIn || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the tokens.
|
|
||||||
*/
|
|
||||||
protected clearTokens(): void {
|
|
||||||
this.setTokens(null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tokens from a oauth2 response.
|
|
||||||
* @param tokens
|
|
||||||
*/
|
|
||||||
private setTokensFromResponse(tokens: OAuth2TokenResponse): void {
|
|
||||||
this.setTokens(tokens.access_token, tokens.refresh_token || null, tokens.expires_in || null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the headers for a oauth2 request.
|
|
||||||
* @returns HttpHeaders
|
|
||||||
*/
|
|
||||||
private getOAuthHeaders(): HttpHeaders {
|
|
||||||
let headers = this.getHeaders();
|
|
||||||
headers["Authorization"] = `Basic ${Buffer.from(`${this.clientId}:${this.clientSecret}`, "binary").toString("base64")}`;
|
|
||||||
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the client id.
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
public getClientId(): string {
|
|
||||||
return this.clientId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Login using an authorization code.
|
|
||||||
* @param authorizationCode
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async authorizationLogin(authorizationCode: string): Promise<boolean> {
|
|
||||||
const response = await this.getToken("authorization_code", authorizationCode, null, null);
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setTokensFromResponse(response);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Login using a device code.
|
|
||||||
* @param deviceCode
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async deviceLogin(deviceCode: string): Promise<boolean> {
|
|
||||||
const response = await this.getToken("device_code", deviceCode, null, null);
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setTokensFromResponse(response);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Login using a username and password.
|
|
||||||
* @param username
|
|
||||||
* @param password
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async passwordLogin(username: string, password: string): Promise<boolean> {
|
|
||||||
const response = await this.getToken("password", password, null, username);
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setTokensFromResponse(response);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Login using a passkey.
|
|
||||||
* @param username
|
|
||||||
* @param passkey
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async passkeyLogin(username: string, passkey: string): Promise<boolean> {
|
|
||||||
const response = await this.getToken("passkey", passkey, null, username);
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setTokensFromResponse(response);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a token for a client application.
|
|
||||||
* @param subjectKey
|
|
||||||
* @param subjectValue
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async clientLogin(subjectKey: string | null, subjectValue: string | null): Promise<boolean> {
|
|
||||||
const response = await this.getToken("client_credentials", null, subjectKey, subjectValue);
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setTokensFromResponse(response);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a new access token using a refresh token.
|
|
||||||
* @param refreshToken
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async refreshToken(): Promise<boolean> {
|
|
||||||
if (!this.options.refreshToken) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await this.getToken("refresh_token", this.options.refreshToken, null, null);
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setTokensFromResponse(response);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get information about a access token.
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async instrospectToken(): Promise<OAuth2IntrospectionResponse | null> {
|
|
||||||
if (!this.options.accessToken) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestBody: OAuth2IntrospectionRequest = {
|
|
||||||
token: this.options.accessToken,
|
|
||||||
token_type_hint: "access_token",
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = `/v1/oauth2/introspect`;
|
|
||||||
const headers = this.getOAuthHeaders();
|
|
||||||
const responseBody = await this.http.post<OAuth2IntrospectionRequest, OAuth2IntrospectionResponse>(url, requestBody, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Revoke a refresh token.
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async revokeToken(): Promise<boolean> {
|
|
||||||
if (!this.options.refreshToken) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestBody: OAuth2IntrospectionRequest = {
|
|
||||||
token: this.options.refreshToken,
|
|
||||||
token_type_hint: "refresh_token",
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = `/v1/oauth2/revoke`;
|
|
||||||
const headers = this.getOAuthHeaders();
|
|
||||||
const responseBody = await this.http.post<OAuth2IntrospectionRequest, OAuth2IntrospectionResponse>(url, requestBody, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.clearTokens();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the current access token is valid.
|
|
||||||
* @returns boolean
|
|
||||||
*/
|
|
||||||
public async isTokenValid(): Promise<boolean> {
|
|
||||||
const response = await this.instrospectToken();
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.active;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a oauth2 token with the given grant type.
|
|
||||||
* @param grantType
|
|
||||||
* @param grantValue
|
|
||||||
* @param subjectKey
|
|
||||||
* @param subjectValue
|
|
||||||
* @returns OAuth2TokenResponse | null
|
|
||||||
*/
|
|
||||||
protected async getToken(grantType: OAuth2GrantType, grantValue: string | null, subjectKey: string | null, subjectValue: string | null): Promise<OAuth2TokenResponse | null> {
|
|
||||||
const requestBody: OAuth2TokenRequest = {
|
|
||||||
grant_type: grantType,
|
|
||||||
code: grantType === "authorization_code" ? grantValue : null,
|
|
||||||
refresh_token: grantType === "refresh_token" ? grantValue : null,
|
|
||||||
username: grantType === "password" || grantType === "passkey" ? subjectValue : null,
|
|
||||||
password: grantType === "password" ? grantValue : null,
|
|
||||||
passkey: grantType === "passkey" ? grantValue : null,
|
|
||||||
client_id: this.clientId,
|
|
||||||
client_secret: this.clientSecret,
|
|
||||||
}
|
|
||||||
|
|
||||||
const params = subjectKey && subjectValue ? `?${subjectKey}=${subjectValue}` : "";
|
|
||||||
const url = `/v1/oauth2/token${params}`;
|
|
||||||
const headers = this.getOAuthHeaders();
|
|
||||||
const responseBody = await this.http.post<OAuth2TokenRequest, OAuth2TokenResponse>(url, requestBody, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get information about the current client.
|
|
||||||
* @returns Client | null
|
|
||||||
*/
|
|
||||||
public async getClientInfo(): Promise<User | null> {
|
|
||||||
return this.getClientById(this.clientId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get information about the current user.
|
|
||||||
* @returns User | null
|
|
||||||
*/
|
|
||||||
public async getUserInfo(): Promise<User | null> {
|
|
||||||
if (!this.options.accessToken) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const headers = this.getHeaders();
|
|
||||||
const responseBody = await this.http.get<User>(`/v1/oauth2/userinfo`, headers);
|
|
||||||
|
|
||||||
if (!responseBody) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return responseBody;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +1,29 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
// Copyright (c) Tribufu. All Rights Reserved.
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
/**
|
import packageJson from "../package.json";
|
||||||
* The version of the Tribufu SDK.
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
export const TRIBUFU_VERSION = "0.1.13";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default Tribufu API URL.
|
* The version of the Tribufu SDK.
|
||||||
* @type {string}
|
|
||||||
*/
|
*/
|
||||||
export const TRIBUFU_API_URL = "https://api.tribufu.com";
|
export const TRIBUFU_VERSION: string = packageJson.version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default Tribufu WEB URL.
|
* The default Tribufu WEB URL.
|
||||||
* @type {string}
|
|
||||||
*/
|
*/
|
||||||
export const TRIBUFU_WEB_URL = "https://www.tribufu.com";
|
export const TRIBUFU_WEB_URL: string = "https://www.tribufu.com";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default Tribufu API URL.
|
||||||
|
*/
|
||||||
|
export const TRIBUFU_API_URL: string = "https://api.tribufu.com";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default Tribufu CDN URL.
|
* The default Tribufu CDN URL.
|
||||||
* @type {string}
|
|
||||||
*/
|
*/
|
||||||
export const TRIBUFU_CDN_URL = "https://cdn.tribufu.com";
|
export const TRIBUFU_CDN_URL: string = "https://cdn.tribufu.com";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tribufu copyright notice.
|
||||||
|
*/
|
||||||
|
export const TRIBUFU_COPYRIGHT = `© ${new Date().getFullYear()} Tribufu.`;
|
||||||
|
11
src/http/headers.ts
Normal file
11
src/http/headers.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (c) Tribufu. All Rights Reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Http Headers
|
||||||
|
*
|
||||||
|
* Helper type to represent HTTP headers.
|
||||||
|
*/
|
||||||
|
export type HttpHeaders = {
|
||||||
|
[key: string]: string;
|
||||||
|
};
|
25
src/index.ts
25
src/index.ts
@ -8,23 +8,24 @@ import {
|
|||||||
TRIBUFU_WEB_URL,
|
TRIBUFU_WEB_URL,
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
|
|
||||||
|
import { TribufuApi } from "./api";
|
||||||
|
import { TribufuApiOptions } from "./options";
|
||||||
|
import { TribufuApiSingleton } from "./api/singletion";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
TRIBUFU_API_URL,
|
TRIBUFU_API_URL,
|
||||||
TRIBUFU_CDN_URL,
|
TRIBUFU_CDN_URL,
|
||||||
TRIBUFU_VERSION,
|
TRIBUFU_VERSION,
|
||||||
TRIBUFU_WEB_URL,
|
TRIBUFU_WEB_URL,
|
||||||
};
|
|
||||||
|
|
||||||
import { TribufuApi } from "./api";
|
|
||||||
import { TribufuApiOptions } from "./options";
|
|
||||||
import { TribufuBot } from "./bot";
|
|
||||||
import { TribufuClient } from "./client";
|
|
||||||
import { TribufuServer } from "./server";
|
|
||||||
|
|
||||||
export {
|
|
||||||
TribufuApi,
|
TribufuApi,
|
||||||
TribufuApiOptions,
|
TribufuApiOptions,
|
||||||
TribufuBot,
|
TribufuApiSingleton,
|
||||||
TribufuClient,
|
|
||||||
TribufuServer,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export * from "./api/base";
|
||||||
|
export * from "./api/generated";
|
||||||
|
export * from "./api/include";
|
||||||
|
export * from "./api/index";
|
||||||
|
export * from "./api/singletion";
|
||||||
|
export * from "./http/headers";
|
||||||
|
export * from "./node";
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
export type AccountType = "user" | "bot" | "org";
|
|
||||||
|
|
||||||
export interface User {
|
|
||||||
id: number,
|
|
||||||
uuid: string,
|
|
||||||
name: string,
|
|
||||||
displayName: string,
|
|
||||||
kind: AccountType,
|
|
||||||
publicFlags: number,
|
|
||||||
verified: boolean,
|
|
||||||
level: number,
|
|
||||||
experience: number,
|
|
||||||
publicBirthday: boolean,
|
|
||||||
birthday?: string | null,
|
|
||||||
points: number,
|
|
||||||
location?: string | null,
|
|
||||||
photoUrl?: string | null,
|
|
||||||
bannerUrl?: string | null,
|
|
||||||
lastOnline?: string | null,
|
|
||||||
biography?: string | null,
|
|
||||||
viewCount: number,
|
|
||||||
created: string,
|
|
||||||
updated?: string | null,
|
|
||||||
}
|
|
@ -2,8 +2,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
export interface TribufuApiOptions {
|
export interface TribufuApiOptions {
|
||||||
apiKey?: string | null;
|
baseUrl?: string;
|
||||||
accessToken?: string | null;
|
apiKey?: string;
|
||||||
refreshToken?: string | null;
|
fetch?: (url: RequestInfo, init?: RequestInit) => Promise<Response>;
|
||||||
expiresIn?: number | null;
|
|
||||||
}
|
}
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import { TribufuClient } from "./client";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* **Tribufu Server**
|
|
||||||
*
|
|
||||||
* To authenticate a server you need to use the server id, client id and client secret obtained from your server subscription.
|
|
||||||
*
|
|
||||||
* - A server is a special type of client application.
|
|
||||||
* - A server is how game servers interact with the Tribufu API.
|
|
||||||
* - A server give you read and write access to the Tribufu API.
|
|
||||||
*/
|
|
||||||
export class TribufuServer extends TribufuClient {
|
|
||||||
private readonly serverId: string;
|
|
||||||
|
|
||||||
constructor(serverId: string, clientId: string, clientSecret: string) {
|
|
||||||
super(clientId, clientSecret);
|
|
||||||
this.serverId = serverId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Try to create a TribufuServer from environment variables.
|
|
||||||
*
|
|
||||||
* - This will only work if the environment variables are set.
|
|
||||||
*
|
|
||||||
* @param prefix A prefix for the environment variables.
|
|
||||||
* @returns TribufuServer | null
|
|
||||||
* @example
|
|
||||||
* ```ts
|
|
||||||
* // process.env.TRIBUFU_SERVER_ID
|
|
||||||
* // process.env.TRIBUFU_CLIENT_ID
|
|
||||||
* // process.env.TRIBUFU_CLIENT_SECRET
|
|
||||||
* const server = TribufuServer.fromEnv("TRIBUFU");
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
public static override fromEnv(prefix?: string | null): TribufuServer | null {
|
|
||||||
const envPrefix = prefix ? `${prefix}_` : "";
|
|
||||||
const serverId = process.env[`${envPrefix}SERVER_ID`];
|
|
||||||
const clientId = process.env[`${envPrefix}CLIENT_ID`];
|
|
||||||
const clientSecret = process.env[`${envPrefix}CLIENT_SECRET`];
|
|
||||||
|
|
||||||
if (serverId && clientId && clientSecret) {
|
|
||||||
return new TribufuServer(serverId, clientId, clientSecret);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the server id.
|
|
||||||
* @returns string
|
|
||||||
*/
|
|
||||||
public getServerId(): string {
|
|
||||||
return this.serverId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get information about the current server.
|
|
||||||
* @returns Server | null
|
|
||||||
*/
|
|
||||||
public async getServerInfo(): Promise<any | null> {
|
|
||||||
return this.getServerById(this.serverId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of connected users.
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
public async getConnectedUsers(): Promise<any[]> {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tribufu Socket
|
|
||||||
*
|
|
||||||
* Helper class to connect to the Tribufu Socket API.
|
|
||||||
*/
|
|
||||||
export class TribufuSocket {
|
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
}
|
|
20
src/token.ts
20
src/token.ts
@ -1,20 +0,0 @@
|
|||||||
// Copyright (c) Tribufu. All Rights Reserved.
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
export type TokenType = "user" | "bot" | "client" | "server";
|
|
||||||
|
|
||||||
export interface TokenPayload {
|
|
||||||
jti: string;
|
|
||||||
type: TokenType;
|
|
||||||
iss: string;
|
|
||||||
aud: string;
|
|
||||||
client_id: string;
|
|
||||||
scope: string;
|
|
||||||
user_id?: string;
|
|
||||||
bot_id?: string;
|
|
||||||
private_flags?: string;
|
|
||||||
public_flags?: string;
|
|
||||||
server_id?: string;
|
|
||||||
iat: number;
|
|
||||||
exp: number;
|
|
||||||
}
|
|
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"target": "ESNext",
|
"target": "esnext",
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"emitDeclarationOnly": true,
|
"emitDeclarationOnly": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
"allowImportingTsExtensions": true,
|
"allowImportingTsExtensions": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
|
Reference in New Issue
Block a user