mirror of
https://github.com/tribufu/sdk-js
synced 2025-06-16 18:44:18 +00:00
Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
ea9d87f5ab | |||
f8d2153123 | |||
76cd15fc4c | |||
9c54143d2e | |||
10a0619f80 | |||
5081c11ad5 | |||
3bc568dcb4 | |||
864b46c4a2 | |||
1ab428cfd7 | |||
f02a66c09c | |||
1cf38a35de | |||
be08efe49f | |||
009dfc04ab | |||
962a3de36a | |||
55b4e64594 | |||
b0788d5f72 | |||
14572419cf | |||
db828be54a | |||
b48ee646e1 | |||
80ec992b89 | |||
a2fc56a98f |
@ -7,8 +7,10 @@ import { TribufuApi } from "../build/index.mjs";
|
||||
dotenv.config();
|
||||
|
||||
async function main() {
|
||||
const api = TribufuApi.fromEnv("TRIBUFU");
|
||||
console.log(await api.authGetUserInfo());
|
||||
const tribufu = TribufuApi.fromEnv();
|
||||
console.log(
|
||||
await tribufu.getServerByAddressAndQueryPort("mine.tribufu.com", 25565),
|
||||
);
|
||||
}
|
||||
|
||||
main();
|
||||
|
19
package.json
19
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "tribufu",
|
||||
"version": "0.1.20",
|
||||
"version": "1.0.0",
|
||||
"description": "Tribufu JS SDK",
|
||||
"repository": "https://github.com/Tribufu/TribufuJs",
|
||||
"author": "Tribufu <contact@Tribufu.com>",
|
||||
@ -9,21 +9,26 @@
|
||||
"types": "./build/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./build/index.mjs",
|
||||
"require": "./build/index.cjs"
|
||||
"require": "./build/index.cjs",
|
||||
"types": "./build/index.d.ts"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"./build/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf build",
|
||||
"build": "npm run clean && tsc && node scripts/esbuild.js"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@tauri-apps/plugin-http": "^2.0.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/plugin-http": "^2.0.0",
|
||||
"@types/node": "^20.10.6",
|
||||
"dotenv": "^16.3.1",
|
||||
"esbuild-node-externals": "^1.12.0",
|
||||
"esbuild": "^0.19.10",
|
||||
"esbuild-node-externals": "^1.12.0",
|
||||
"eslint": "9.11.1",
|
||||
"prettier": "3.3.3",
|
||||
"rimraf": "^5.0.5",
|
||||
|
1348
pnpm-lock.yaml
generated
1348
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -22,12 +22,26 @@ const moduleConfig = {
|
||||
format: "esm",
|
||||
};
|
||||
|
||||
const moduleMinConfig = {
|
||||
...moduleConfig,
|
||||
outfile: "build/index.min.mjs",
|
||||
minify: true,
|
||||
sourcemap: true,
|
||||
};
|
||||
|
||||
const legacyConfig = {
|
||||
...baseConfig,
|
||||
outfile: "build/index.cjs",
|
||||
format: "cjs",
|
||||
};
|
||||
|
||||
const legacyMinConfig = {
|
||||
...legacyConfig,
|
||||
outfile: "build/index.min.cjs",
|
||||
minify: true,
|
||||
sourcemap: true,
|
||||
};
|
||||
|
||||
async function addCopyrightHeader(filename) {
|
||||
const header = `// Copyright (c) Tribufu. All Rights Reserved.\n// SPDX-License-Identifier: MIT\n\n`;
|
||||
const content = await fs.readFile(filename, 'utf-8');
|
||||
@ -44,5 +58,8 @@ async function buildAndAddHeader(config) {
|
||||
}
|
||||
};
|
||||
|
||||
await buildAndAddHeader(moduleConfig);
|
||||
await buildAndAddHeader(legacyConfig);
|
||||
await buildAndAddHeader(moduleConfig);
|
||||
|
||||
//await buildAndAddHeader(legacyMinConfig);
|
||||
//await buildAndAddHeader(moduleMinConfig);
|
||||
|
@ -18,11 +18,11 @@ export abstract class TribufuApiBase {
|
||||
* @returns boolean
|
||||
*/
|
||||
public static debugEnabled(): boolean {
|
||||
if (!process) {
|
||||
return false;
|
||||
if (typeof process !== "undefined") {
|
||||
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 {
|
||||
const headers = {};
|
||||
headers["X-Tribufu-Language"] = "javascript";
|
||||
headers["X-Tribufu-Library"] = "javascript";
|
||||
headers["X-Tribufu-Version"] = TRIBUFU_VERSION;
|
||||
return headers;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,7 +26,7 @@
|
||||
"nullValue": "Null",
|
||||
"generateClientClasses": true,
|
||||
"generateClientInterfaces": false,
|
||||
"generateOptionalParameters": false,
|
||||
"generateOptionalParameters": true,
|
||||
"exportTypes": true,
|
||||
"wrapDtoExceptions": false,
|
||||
"exceptionClass": "TribufuApiError",
|
||||
@ -41,7 +41,7 @@
|
||||
"useTransformResultMethod": false,
|
||||
"generateDtoTypes": true,
|
||||
"operationGenerationMode": "SingleClientFromOperationId",
|
||||
"markOptionalProperties": true,
|
||||
"markOptionalProperties": false,
|
||||
"generateCloneMethod": false,
|
||||
"typeStyle": "Interface",
|
||||
"enumStyle": "Enum",
|
||||
|
@ -44,22 +44,20 @@ export class TribufuApi extends TribufuApiGenerated {
|
||||
*
|
||||
* - 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
|
||||
* @example
|
||||
* ```ts
|
||||
* // process.env.TRIBUFU_API_KEY
|
||||
* const api = TribufuApi.fromEnv("TRIBUFU");
|
||||
* const api = TribufuApi.fromEnv();
|
||||
* ```
|
||||
*/
|
||||
public static fromEnv(prefix?: string | null): TribufuApi | null {
|
||||
const envPrefix = prefix ? `${prefix}_` : "";
|
||||
|
||||
if (!process) {
|
||||
if (typeof process === "undefined") {
|
||||
return null;
|
||||
}
|
||||
|
||||
const apiKey = process.env[`${envPrefix}API_KEY`];
|
||||
const apiKey = process.env[`${prefix || "TRIBUFU"}_API_KEY`];
|
||||
|
||||
if (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.
|
||||
*
|
||||
* @param prefix A prefix for the environment variables.
|
||||
* @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("TRIBUFU_");
|
||||
* const api = TribufuApi.fromEnvOrDefault();
|
||||
* ```
|
||||
*/
|
||||
public static fromEnvOrDefault(prefix: string = ""): TribufuApi {
|
||||
@ -95,7 +93,7 @@ export class TribufuApi extends TribufuApiGenerated {
|
||||
* @returns string
|
||||
*/
|
||||
protected static getBaseUrl(): string {
|
||||
if (!process) {
|
||||
if (typeof process === "undefined") {
|
||||
return 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;
|
||||
}
|
||||
}
|
21
src/index.ts
21
src/index.ts
@ -8,9 +8,24 @@ import {
|
||||
TRIBUFU_WEB_URL,
|
||||
} from "./constants";
|
||||
|
||||
export { TRIBUFU_API_URL, TRIBUFU_CDN_URL, TRIBUFU_VERSION, TRIBUFU_WEB_URL };
|
||||
|
||||
import { TribufuApi } from "./api";
|
||||
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";
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { TribufuApi } from "../api";
|
||||
import { TribufuApiOptions } from "../options";
|
||||
|
||||
let fetchFn: typeof fetch | undefined;
|
||||
|
||||
if (window && (window as any).__TAURI__) {
|
||||
fetchFn = (await import("@tauri-apps/plugin-http")).fetch;
|
||||
}
|
||||
|
||||
export type TribufuTauriApiOptions = Omit<TribufuApiOptions, "fetch">;
|
||||
|
||||
/**
|
||||
* **Tribufu Tauri API**
|
||||
*
|
||||
* Use this class to interact with the Tribufu API in a Tauri application.
|
||||
*/
|
||||
export class TribufuTauriApi extends TribufuApi {
|
||||
constructor(options?: TribufuTauriApiOptions | null) {
|
||||
super({ ...options, fetch: fetchFn });
|
||||
}
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"target": "ESNext",
|
||||
"target": "esnext",
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"noImplicitAny": false,
|
||||
"moduleResolution": "Node",
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"rootDir": "src",
|
||||
|
Reference in New Issue
Block a user