21 Commits
dev2 ... 1.0.0

Author SHA1 Message Date
ea9d87f5ab Release v1.0.0 2025-05-01 18:56:18 -03:00
f8d2153123 Update package.json 2025-04-20 18:28:48 -03:00
76cd15fc4c Update api.generated.ts 2025-04-20 18:28:47 -03:00
9c54143d2e Fix nodejs process check 2024-11-28 15:30:20 -03:00
10a0619f80 Disable markOptionalProperties 2024-10-18 14:05:19 -03:00
5081c11ad5 Update package.json 2024-10-18 13:18:49 -03:00
3bc568dcb4 Export types 2024-10-18 13:18:48 -03:00
864b46c4a2 Update package.json 2024-10-18 13:16:07 -03:00
1ab428cfd7 Update index.ts 2024-10-18 13:16:05 -03:00
f02a66c09c Update package.json 2024-10-18 13:05:59 -03:00
1cf38a35de Test add typesVersions 2024-10-18 13:05:55 -03:00
be08efe49f Update package.json 2024-10-18 13:04:45 -03:00
009dfc04ab Add more methods and singleton 2024-10-18 12:50:44 -03:00
962a3de36a Update package.json 2024-10-04 19:17:44 -03:00
55b4e64594 Update optional parameters 2024-10-04 19:16:05 -03:00
b0788d5f72 Update package.json 2024-10-04 19:06:01 -03:00
14572419cf Update index.ts 2024-10-04 18:58:32 -03:00
db828be54a Update operation ids 2024-10-04 18:58:30 -03:00
b48ee646e1 Update package.json 2024-10-04 18:49:46 -03:00
80ec992b89 Update esbuild.js 2024-10-04 18:49:44 -03:00
a2fc56a98f Update tsconfig.json 2024-10-04 18:49:21 -03:00
11 changed files with 2197 additions and 1224 deletions

View File

@ -7,8 +7,10 @@ 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();
console.log(await api.authGetUserInfo()); console.log(
await tribufu.getServerByAddressAndQueryPort("mine.tribufu.com", 25565),
);
} }
main(); main();

View File

@ -1,6 +1,6 @@
{ {
"name": "tribufu", "name": "tribufu",
"version": "0.1.20", "version": "1.0.0",
"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,7 +9,15 @@
"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",
@ -19,8 +27,8 @@
"devDependencies": { "devDependencies": {
"@types/node": "^20.10.6", "@types/node": "^20.10.6",
"dotenv": "^16.3.1", "dotenv": "^16.3.1",
"esbuild-node-externals": "^1.12.0",
"esbuild": "^0.19.10", "esbuild": "^0.19.10",
"esbuild-node-externals": "^1.12.0",
"eslint": "9.11.1", "eslint": "9.11.1",
"prettier": "3.3.3", "prettier": "3.3.3",
"rimraf": "^5.0.5", "rimraf": "^5.0.5",

1382
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -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);

View File

@ -18,11 +18,11 @@ export abstract class TribufuApiBase {
* @returns boolean * @returns boolean
*/ */
public static debugEnabled(): boolean { public static debugEnabled(): boolean {
if (!process) { if (typeof process !== "undefined") {
return false; return process.env.NODE_ENV === "development";
} }
return process.env.NODE_ENV === "development"; return false;
} }
/** /**
@ -66,7 +66,7 @@ export abstract class TribufuApiBase {
*/ */
protected static defaultHeaders(): HttpHeaders { protected static defaultHeaders(): HttpHeaders {
const headers = {}; const headers = {};
headers["X-Tribufu-Language"] = "javascript"; headers["X-Tribufu-Library"] = "javascript";
headers["X-Tribufu-Version"] = TRIBUFU_VERSION; headers["X-Tribufu-Version"] = TRIBUFU_VERSION;
return headers; return headers;
} }

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@
"nullValue": "Null", "nullValue": "Null",
"generateClientClasses": true, "generateClientClasses": true,
"generateClientInterfaces": false, "generateClientInterfaces": false,
"generateOptionalParameters": false, "generateOptionalParameters": true,
"exportTypes": true, "exportTypes": true,
"wrapDtoExceptions": false, "wrapDtoExceptions": false,
"exceptionClass": "TribufuApiError", "exceptionClass": "TribufuApiError",
@ -41,7 +41,7 @@
"useTransformResultMethod": false, "useTransformResultMethod": false,
"generateDtoTypes": true, "generateDtoTypes": true,
"operationGenerationMode": "SingleClientFromOperationId", "operationGenerationMode": "SingleClientFromOperationId",
"markOptionalProperties": true, "markOptionalProperties": false,
"generateCloneMethod": false, "generateCloneMethod": false,
"typeStyle": "Interface", "typeStyle": "Interface",
"enumStyle": "Enum", "enumStyle": "Enum",

View File

@ -44,22 +44,20 @@ export class TribufuApi extends TribufuApiGenerated {
* *
* - This will only work if the environment variables are set. * - This will only work if the environment variables are set.
* *
* @param prefix A prefix for the environment variables. * @param prefix A prefix for the environment variables. Default is `TRIBUFU`.
* @returns TribufuApi | null * @returns TribufuApi | null
* @example * @example
* ```ts * ```ts
* // process.env.TRIBUFU_API_KEY * // process.env.TRIBUFU_API_KEY
* const api = TribufuApi.fromEnv("TRIBUFU"); * const api = TribufuApi.fromEnv();
* ``` * ```
*/ */
public static fromEnv(prefix?: string | null): TribufuApi | null { public static fromEnv(prefix?: string | null): TribufuApi | null {
const envPrefix = prefix ? `${prefix}_` : ""; if (typeof process === "undefined") {
if (!process) {
return null; return null;
} }
const apiKey = process.env[`${envPrefix}API_KEY`]; const apiKey = process.env[`${prefix || "TRIBUFU"}_API_KEY`];
if (apiKey) { if (apiKey) {
return TribufuApi.withApiKey(apiKey); return TribufuApi.withApiKey(apiKey);
@ -73,12 +71,12 @@ export class TribufuApi extends TribufuApiGenerated {
* *
* - This will fallback to the default api if the environment variables are not set. * - This will fallback to the default api if the environment variables are not set.
* *
* @param prefix A prefix for the environment variables. * @param prefix A prefix for the environment variables. Default is `TRIBUFU`.
* @returns TribufuApi | null * @returns TribufuApi | null
* @example * @example
* ```ts * ```ts
* // process.env.TRIBUFU_API_KEY = null * // process.env.TRIBUFU_API_KEY = null
* const api = TribufuApi.fromEnvOrDefault("TRIBUFU_"); * const api = TribufuApi.fromEnvOrDefault();
* ``` * ```
*/ */
public static fromEnvOrDefault(prefix: string = ""): TribufuApi { public static fromEnvOrDefault(prefix: string = ""): TribufuApi {
@ -95,7 +93,7 @@ export class TribufuApi extends TribufuApiGenerated {
* @returns string * @returns string
*/ */
protected static getBaseUrl(): string { protected static getBaseUrl(): string {
if (!process) { if (typeof process === "undefined") {
return TRIBUFU_API_URL; return TRIBUFU_API_URL;
} }

23
src/api/singletion.ts Normal file
View 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;
}
}

View File

@ -8,9 +8,24 @@ import {
TRIBUFU_WEB_URL, TRIBUFU_WEB_URL,
} from "./constants"; } from "./constants";
export { TRIBUFU_API_URL, TRIBUFU_CDN_URL, TRIBUFU_VERSION, TRIBUFU_WEB_URL };
import { TribufuApi } from "./api"; import { TribufuApi } from "./api";
import { TribufuApiOptions } from "./options"; import { TribufuApiOptions } from "./options";
import { TribufuApiSingleton } from "./api/singletion";
export { TribufuApi, TribufuApiOptions }; export {
TRIBUFU_API_URL,
TRIBUFU_CDN_URL,
TRIBUFU_VERSION,
TRIBUFU_WEB_URL,
TribufuApi,
TribufuApiOptions,
TribufuApiSingleton,
};
export * from "./api/api.base";
export * from "./api/api.generated";
export * from "./api/api.include";
export * from "./api/index";
export * from "./api/singletion";
export * from "./http/headers";
export * from "./node";

View File

@ -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",