27 Commits
dev2 ... nswag

Author SHA1 Message Date
1a8ffe89bc Update api.nswag 2025-05-26 18:06:19 -03:00
6b7525c7b0 Patch v1.0.2 2025-05-17 11:44:41 -03:00
aff56dfad6 Update api.js 2025-05-17 11:42:15 -03:00
bf2f448dc9 Patch v1.0.1 2025-05-17 11:20:29 -03:00
6b3873dae1 Rename files 2025-05-17 11:12:09 -03:00
70cb6c6bc9 Update .editorconfig 2025-05-16 20:40:42 -03:00
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
14 changed files with 2242 additions and 1238 deletions

View File

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

View File

@ -7,8 +7,8 @@ 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.getUserInfo());
} }
main(); main();

View File

@ -1,6 +1,6 @@
{ {
"name": "tribufu", "name": "tribufu",
"version": "0.1.20", "version": "1.0.2",
"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

@ -1 +0,0 @@
import { TribufuApiBase } from "./api.base";

View File

@ -4,7 +4,7 @@
"documentGenerator": { "documentGenerator": {
"fromDocument": { "fromDocument": {
"json": "", "json": "",
"url": "http://localhost:5000/v1/openapi.json", "url": "http://localhost:5000/openapi.json",
"output": null, "output": null,
"newLineBehavior": "Auto" "newLineBehavior": "Auto"
} }
@ -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,14 +41,14 @@
"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",
"useLeafType": false, "useLeafType": false,
"classTypes": [], "classTypes": [],
"extendedClasses": [], "extendedClasses": [],
"extensionCode": "api.include.ts", "extensionCode": "include.ts",
"generateDefaultValues": true, "generateDefaultValues": true,
"excludedTypeNames": [], "excludedTypeNames": [],
"excludedParameterNames": [], "excludedParameterNames": [],
@ -67,7 +67,7 @@
"templateDirectory": null, "templateDirectory": null,
"serviceHost": null, "serviceHost": null,
"serviceSchemes": null, "serviceSchemes": null,
"output": "api.generated.ts", "output": "generated.ts",
"newLineBehavior": "LF" "newLineBehavior": "LF"
} }
} }

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;
} }
@ -92,12 +92,10 @@ export abstract class TribufuApiBase {
* @returns * @returns
*/ */
protected transformOptions(options: RequestInit) { protected transformOptions(options: RequestInit) {
if (this.apiKey) { options.headers = {
options.headers = { ...options.headers,
...options.headers, ...this.getHeaders(),
...this.getHeaders(), };
};
}
return Promise.resolve(options); return Promise.resolve(options);
} }

File diff suppressed because it is too large Load Diff

1
src/api/include.ts Normal file
View File

@ -0,0 +1 @@
import { TribufuApiBase } from "./base";

View File

@ -2,8 +2,8 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
import { TRIBUFU_API_URL } from ".."; import { TRIBUFU_API_URL } from "..";
import { TribufuApiBase } from "./api.base"; import { TribufuApiBase } from "./base";
import { TribufuApiGenerated } from "./api.generated"; import { TribufuApiGenerated } from "./generated";
import { TribufuApiOptions } from "../options"; import { TribufuApiOptions } from "../options";
/** /**
@ -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,13 +93,11 @@ 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;
} }
const baseUrl = process.env[`TRIBUFU_API_URL`] || null; const baseUrl = process.env[`TRIBUFU_API_URL`] || null;
return TribufuApiBase.debugEnabled() && baseUrl return TribufuApiBase.debugEnabled() && baseUrl ? baseUrl : TRIBUFU_API_URL;
? baseUrl
: 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/base";
export * from "./api/generated";
export * from "./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",