From b5d1e086f3bdc09b4f338e0e337ce5effd5ec800 Mon Sep 17 00:00:00 2001 From: Guilherme Werner Date: Wed, 2 Oct 2024 21:03:18 -0300 Subject: [PATCH] Use nswag generator --- .prettierignore | 1 + examples/api.js | 9 +- examples/bot.js | 10 - examples/client.js | 15 - examples/server.js | 11 - package.json | 11 +- pnpm-lock.yaml | 748 +++++++++---- scripts/nswag.ps1 | 3 + src/api.ts | 544 ---------- src/api/api.base.ts | 104 ++ src/api/api.generated.ts | 2233 ++++++++++++++++++++++++++++++++++++++ src/api/api.include.ts | 1 + src/api/api.nswag | 74 ++ src/api/index.ts | 107 ++ src/bot.ts | 68 -- src/client.ts | 386 ------- src/constants.ts | 14 +- src/http/headers.ts | 11 + src/index.ts | 18 +- src/models/cluster.ts | 22 - src/models/profile.ts | 16 - src/options.ts | 7 +- src/server.ts | 74 -- src/socket/index.ts | 12 - src/token.ts | 20 - 25 files changed, 3063 insertions(+), 1456 deletions(-) create mode 100644 .prettierignore delete mode 100644 examples/bot.js delete mode 100644 examples/client.js delete mode 100644 examples/server.js create mode 100644 scripts/nswag.ps1 delete mode 100644 src/api.ts create mode 100644 src/api/api.base.ts create mode 100644 src/api/api.generated.ts create mode 100644 src/api/api.include.ts create mode 100644 src/api/api.nswag create mode 100644 src/api/index.ts delete mode 100644 src/bot.ts delete mode 100644 src/client.ts create mode 100644 src/http/headers.ts delete mode 100644 src/models/cluster.ts delete mode 100644 src/models/profile.ts delete mode 100644 src/server.ts delete mode 100644 src/socket/index.ts delete mode 100644 src/token.ts diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..b9daa3c --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +src/api.generated.ts diff --git a/examples/api.js b/examples/api.js index 34d9d16..dcff1c8 100644 --- a/examples/api.js +++ b/examples/api.js @@ -1,15 +1,14 @@ // Copyright (c) Tribufu. All Rights Reserved. -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: MIT AND Apache-2.0 -import dotenv from 'dotenv'; -import { TribufuApi } from '../build/index.mjs'; +import dotenv from "dotenv"; +import { TribufuApi } from "../build/index.mjs"; dotenv.config(); async function main() { const api = TribufuApi.fromEnv("TRIBUFU"); - const games = await api.getGames(); - console.log(games[0]); + console.log(await api.authGetUserInfo()); } main(); diff --git a/examples/bot.js b/examples/bot.js deleted file mode 100644 index 347605f..0000000 --- a/examples/bot.js +++ /dev/null @@ -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(); diff --git a/examples/client.js b/examples/client.js deleted file mode 100644 index 026d208..0000000 --- a/examples/client.js +++ /dev/null @@ -1,15 +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"); - const games = await client.getServers(); - console.log(games); -} - -main(); diff --git a/examples/server.js b/examples/server.js deleted file mode 100644 index 78e41e1..0000000 --- a/examples/server.js +++ /dev/null @@ -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(); diff --git a/package.json b/package.json index 9124388..0a1ad01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tribufu", - "version": "0.1.19", + "version": "0.1.20", "description": "Tribufu JS SDK", "repository": "https://github.com/Tribufu/TribufuJs", "author": "Tribufu ", @@ -15,15 +15,14 @@ "clean": "rimraf build", "build": "npm run clean && tsc && node scripts/esbuild.js" }, - "dependencies": { - "@tribufu/mintaka": "0.1.8" - }, + "dependencies": {}, "devDependencies": { "@types/node": "^20.10.6", - "cross-env": "^7.0.3", "dotenv": "^16.3.1", - "esbuild": "^0.19.10", "esbuild-node-externals": "^1.12.0", + "esbuild": "^0.19.10", + "eslint": "9.11.1", + "prettier": "3.3.3", "rimraf": "^5.0.5", "typescript": "^5.3.3" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 953fa75..231a029 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,14 +5,23 @@ settings: excludeLinksFromLockfile: false dependencies: - '@tribufu/mintaka': - specifier: 0.1.8 - version: 0.1.8 + json-bigint: + specifier: ^1.0.0 + version: 1.0.0 devDependencies: + '@types/json-bigint': + specifier: ^1.0.4 + version: 1.0.4 + '@types/jsonwebtoken': + specifier: ^9.0.5 + version: 9.0.7 '@types/node': specifier: ^20.10.6 version: 20.10.6 + '@types/uuid': + specifier: ^9.0.7 + version: 9.0.8 cross-env: specifier: ^7.0.3 version: 7.0.3 @@ -25,6 +34,12 @@ devDependencies: esbuild-node-externals: specifier: ^1.12.0 version: 1.12.0(esbuild@0.19.11) + eslint: + specifier: 9.11.1 + version: 9.11.1 + prettier: + specifier: 3.3.3 + version: 3.3.3 rimraf: specifier: ^5.0.5 version: 5.0.5 @@ -241,6 +256,81 @@ packages: dev: true optional: true + /@eslint-community/eslint-utils@4.4.0(eslint@9.11.1): + resolution: {integrity: sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || >=8.0.0 + dependencies: + eslint: 9.11.1 + eslint-visitor-keys: 3.4.3 + dev: true + + /@eslint-community/regexpp@4.11.1: + resolution: {integrity: sha512-m4DVN9ZqskZoLU5GlWZadwDnYo3vAEydiUayB9widCl9ffWx2IvPnp6n3on5rJmziJSw9Bv+Z3ChDVdMwXCY8Q==} + engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} + dev: true + + /@eslint/config-array@0.18.0: + resolution: {integrity: sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dependencies: + '@eslint/object-schema': 2.1.4 + debug: 4.3.7 + minimatch: 3.1.2 + transitivePeerDependencies: + - supports-color + dev: true + + /@eslint/core@0.6.0: + resolution: {integrity: sha512-8I2Q8ykA4J0x0o7cg67FPVnehcqWTBehu/lmY+bolPFHGjh49YzGBMXTvpqVgEbBdvNCSxj6iFgiIyHzf03lzg==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dev: true + + /@eslint/eslintrc@3.1.0: + resolution: {integrity: sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dependencies: + ajv: 6.12.6 + debug: 4.3.7 + espree: 10.2.0 + globals: 14.0.0 + ignore: 5.3.2 + import-fresh: 3.3.0 + js-yaml: 4.1.0 + minimatch: 3.1.2 + strip-json-comments: 3.1.1 + transitivePeerDependencies: + - supports-color + dev: true + + /@eslint/js@9.11.1: + resolution: {integrity: sha512-/qu+TWz8WwPWc7/HcIJKi+c+MOm46GdVaSlTTQcaqaL53+GsoA6MxWp5PtTx48qbSP7ylM1Kn7nhvkugfJvRSA==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dev: true + + /@eslint/object-schema@2.1.4: + resolution: {integrity: sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dev: true + + /@eslint/plugin-kit@0.2.0: + resolution: {integrity: sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dependencies: + levn: 0.4.1 + dev: true + + /@humanwhocodes/module-importer@1.0.1: + resolution: {integrity: sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==} + engines: {node: '>=12.22'} + dev: true + + /@humanwhocodes/retry@0.3.0: + resolution: {integrity: sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==} + engines: {node: '>=18.18'} + dev: true + /@isaacs/cliui@8.0.2: resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -253,6 +343,27 @@ packages: wrap-ansi-cjs: /wrap-ansi@7.0.0 dev: true + /@nodelib/fs.scandir@2.1.5: + resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} + engines: {node: '>= 8'} + dependencies: + '@nodelib/fs.stat': 2.0.5 + run-parallel: 1.2.0 + dev: true + + /@nodelib/fs.stat@2.0.5: + resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} + engines: {node: '>= 8'} + dev: true + + /@nodelib/fs.walk@1.2.8: + resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} + engines: {node: '>= 8'} + dependencies: + '@nodelib/fs.scandir': 2.1.5 + fastq: 1.17.1 + dev: true + /@pkgjs/parseargs@0.11.0: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} @@ -260,21 +371,23 @@ packages: dev: true optional: true - /@tribufu/mintaka@0.1.8: - resolution: {integrity: sha512-qUvReWlz8irSIbKCTfjFnUnUq7MIgLjnTBPeWv2ayyiwGkf8L3q7qi1Zxuqt3OduOugSOtxYQwXOaClldIMUTQ==} + /@types/estree@1.0.6: + resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==} + dev: true + + /@types/json-bigint@1.0.4: + resolution: {integrity: sha512-ydHooXLbOmxBbubnA7Eh+RpBzuaIiQjh8WGJYQB50JFGFrdxW7JzVlyEV7fAXw0T2sqJ1ysTneJbiyNLqZRAag==} + dev: true + + /@types/json-schema@7.0.15: + resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} + dev: true + + /@types/jsonwebtoken@9.0.7: + resolution: {integrity: sha512-ugo316mmTYBl2g81zDFnZ7cfxlut3o+/EQdaP7J8QN2kY6lJ22hmQYCK5EHcJHbrW+dkCGSCPgbG8JtYj6qSrg==} dependencies: - axios: 1.6.4 - camelcase-keys: 9.1.2 - fp-ts: 2.16.2 - json-bigint: 1.0.0 - jsonwebtoken: 9.0.2 - snakecase-keys: 5.5.0 - toml: 3.0.0 - uuid: 9.0.1 - uuidv7: 0.6.3 - transitivePeerDependencies: - - debug - dev: false + '@types/node': 20.10.6 + dev: true /@types/node@20.10.6: resolution: {integrity: sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==} @@ -282,6 +395,33 @@ packages: undici-types: 5.26.5 dev: true + /@types/uuid@9.0.8: + resolution: {integrity: sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==} + dev: true + + /acorn-jsx@5.3.2(acorn@8.12.1): + resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} + peerDependencies: + acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 + dependencies: + acorn: 8.12.1 + dev: true + + /acorn@8.12.1: + resolution: {integrity: sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==} + engines: {node: '>=0.4.0'} + hasBin: true + dev: true + + /ajv@6.12.6: + resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==} + dependencies: + fast-deep-equal: 3.1.3 + fast-json-stable-stringify: 2.1.0 + json-schema-traverse: 0.4.1 + uri-js: 4.4.1 + dev: true + /ansi-regex@5.0.1: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} engines: {node: '>=8'} @@ -304,19 +444,9 @@ packages: engines: {node: '>=12'} dev: true - /asynckit@0.4.0: - resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} - dev: false - - /axios@1.6.4: - resolution: {integrity: sha512-heJnIs6N4aa1eSthhN9M5ioILu8Wi8vmQW9iHQ9NUvfkJb0lEEDUiIdQNAuBtfUt3FxReaKdpQA5DbmMOqzF/A==} - dependencies: - follow-redirects: 1.15.4 - form-data: 4.0.0 - proxy-from-env: 1.1.0 - transitivePeerDependencies: - - debug - dev: false + /argparse@2.0.1: + resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} + dev: true /balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} @@ -326,30 +456,31 @@ packages: resolution: {integrity: sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==} dev: false + /brace-expansion@1.1.11: + resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + dependencies: + balanced-match: 1.0.2 + concat-map: 0.0.1 + dev: true + /brace-expansion@2.0.1: resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} dependencies: balanced-match: 1.0.2 dev: true - /buffer-equal-constant-time@1.0.1: - resolution: {integrity: sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==} - dev: false + /callsites@3.1.0: + resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} + engines: {node: '>=6'} + dev: true - /camelcase-keys@9.1.2: - resolution: {integrity: sha512-nFhquwz7p3nWSHeVYoIkefNPdR2Rt4EuKs9/gaqx3DhJL6HkNHIEcsH+D6N4NvW/MHxc4TT+rp0rc4K7E7x9hw==} - engines: {node: '>=16'} + /chalk@4.1.2: + resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} + engines: {node: '>=10'} dependencies: - camelcase: 8.0.0 - map-obj: 5.0.0 - quick-lru: 6.1.2 - type-fest: 4.9.0 - dev: false - - /camelcase@8.0.0: - resolution: {integrity: sha512-8WB3Jcas3swSvjIeA2yvCJ+Miyz5l1ZmB6HFb9R1317dt9LCQoswg/BGrmAmkWVEszSrrg4RwmO46qIm2OEnSA==} - engines: {node: '>=16'} - dev: false + ansi-styles: 4.3.0 + supports-color: 7.2.0 + dev: true /color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} @@ -362,12 +493,9 @@ packages: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} dev: true - /combined-stream@1.0.8: - resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} - engines: {node: '>= 0.8'} - dependencies: - delayed-stream: 1.0.0 - dev: false + /concat-map@0.0.1: + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} + dev: true /cross-env@7.0.3: resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==} @@ -386,17 +514,21 @@ packages: which: 2.0.2 dev: true - /delayed-stream@1.0.0: - resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} - engines: {node: '>=0.4.0'} - dev: false - - /dot-case@3.0.4: - resolution: {integrity: sha512-Kv5nKlh6yRrdrGvxeJ2e5y2eRUpkUosIW4A2AS38zwSz27zu7ufDwQPi5Jhs3XAlGNetl3bmnGhQsMtkKJnj3w==} + /debug@4.3.7: + resolution: {integrity: sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==} + engines: {node: '>=6.0'} + peerDependencies: + supports-color: '*' + peerDependenciesMeta: + supports-color: + optional: true dependencies: - no-case: 3.0.4 - tslib: 2.6.2 - dev: false + ms: 2.1.3 + dev: true + + /deep-is@0.1.4: + resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} + dev: true /dotenv@16.3.1: resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} @@ -407,12 +539,6 @@ packages: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true - /ecdsa-sig-formatter@1.0.11: - resolution: {integrity: sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==} - dependencies: - safe-buffer: 5.2.1 - dev: false - /emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} dev: true @@ -463,6 +589,138 @@ packages: '@esbuild/win32-x64': 0.19.11 dev: true + /escape-string-regexp@4.0.0: + resolution: {integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==} + engines: {node: '>=10'} + dev: true + + /eslint-scope@8.1.0: + resolution: {integrity: sha512-14dSvlhaVhKKsa9Fx1l8A17s7ah7Ef7wCakJ10LYk6+GYmP9yDti2oq2SEwcyndt6knfcZyhyxwY3i9yL78EQw==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dependencies: + esrecurse: 4.3.0 + estraverse: 5.3.0 + dev: true + + /eslint-visitor-keys@3.4.3: + resolution: {integrity: sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dev: true + + /eslint-visitor-keys@4.1.0: + resolution: {integrity: sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dev: true + + /eslint@9.11.1: + resolution: {integrity: sha512-MobhYKIoAO1s1e4VUrgx1l1Sk2JBR/Gqjjgw8+mfgoLE2xwsHur4gdfTxyTgShrhvdVFTaJSgMiQBl1jv/AWxg==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + hasBin: true + peerDependencies: + jiti: '*' + peerDependenciesMeta: + jiti: + optional: true + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@9.11.1) + '@eslint-community/regexpp': 4.11.1 + '@eslint/config-array': 0.18.0 + '@eslint/core': 0.6.0 + '@eslint/eslintrc': 3.1.0 + '@eslint/js': 9.11.1 + '@eslint/plugin-kit': 0.2.0 + '@humanwhocodes/module-importer': 1.0.1 + '@humanwhocodes/retry': 0.3.0 + '@nodelib/fs.walk': 1.2.8 + '@types/estree': 1.0.6 + '@types/json-schema': 7.0.15 + ajv: 6.12.6 + chalk: 4.1.2 + cross-spawn: 7.0.3 + debug: 4.3.7 + escape-string-regexp: 4.0.0 + eslint-scope: 8.1.0 + eslint-visitor-keys: 4.1.0 + espree: 10.2.0 + esquery: 1.6.0 + esutils: 2.0.3 + fast-deep-equal: 3.1.3 + file-entry-cache: 8.0.0 + find-up: 5.0.0 + glob-parent: 6.0.2 + ignore: 5.3.2 + imurmurhash: 0.1.4 + is-glob: 4.0.3 + is-path-inside: 3.0.3 + json-stable-stringify-without-jsonify: 1.0.1 + lodash.merge: 4.6.2 + minimatch: 3.1.2 + natural-compare: 1.4.0 + optionator: 0.9.4 + strip-ansi: 6.0.1 + text-table: 0.2.0 + transitivePeerDependencies: + - supports-color + dev: true + + /espree@10.2.0: + resolution: {integrity: sha512-upbkBJbckcCNBDBDXEbuhjbP68n+scUd3k/U2EkyM9nw+I/jPiL4cLF/Al06CF96wRltFda16sxDFrxsI1v0/g==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + dependencies: + acorn: 8.12.1 + acorn-jsx: 5.3.2(acorn@8.12.1) + eslint-visitor-keys: 4.1.0 + dev: true + + /esquery@1.6.0: + resolution: {integrity: sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==} + engines: {node: '>=0.10'} + dependencies: + estraverse: 5.3.0 + dev: true + + /esrecurse@4.3.0: + resolution: {integrity: sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==} + engines: {node: '>=4.0'} + dependencies: + estraverse: 5.3.0 + dev: true + + /estraverse@5.3.0: + resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} + engines: {node: '>=4.0'} + dev: true + + /esutils@2.0.3: + resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} + engines: {node: '>=0.10.0'} + dev: true + + /fast-deep-equal@3.1.3: + resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} + dev: true + + /fast-json-stable-stringify@2.1.0: + resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} + dev: true + + /fast-levenshtein@2.0.6: + resolution: {integrity: sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==} + dev: true + + /fastq@1.17.1: + resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==} + dependencies: + reusify: 1.0.4 + dev: true + + /file-entry-cache@8.0.0: + resolution: {integrity: sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==} + engines: {node: '>=16.0.0'} + dependencies: + flat-cache: 4.0.1 + dev: true + /find-up@5.0.0: resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==} engines: {node: '>=10'} @@ -471,15 +729,17 @@ packages: path-exists: 4.0.0 dev: true - /follow-redirects@1.15.4: - resolution: {integrity: sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==} - engines: {node: '>=4.0'} - peerDependencies: - debug: '*' - peerDependenciesMeta: - debug: - optional: true - dev: false + /flat-cache@4.0.1: + resolution: {integrity: sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==} + engines: {node: '>=16'} + dependencies: + flatted: 3.3.1 + keyv: 4.5.4 + dev: true + + /flatted@3.3.1: + resolution: {integrity: sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==} + dev: true /foreground-child@3.1.1: resolution: {integrity: sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==} @@ -489,18 +749,12 @@ packages: signal-exit: 4.1.0 dev: true - /form-data@4.0.0: - resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} - engines: {node: '>= 6'} + /glob-parent@6.0.2: + resolution: {integrity: sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==} + engines: {node: '>=10.13.0'} dependencies: - asynckit: 0.4.0 - combined-stream: 1.0.8 - mime-types: 2.1.35 - dev: false - - /fp-ts@2.16.2: - resolution: {integrity: sha512-CkqAjnIKFqvo3sCyoBTqgJvF+bHrSik584S9nhTjtBESLx26cbtVMR/T9a6ApChOcSDAaM3JydDmWDUn4EEXng==} - dev: false + is-glob: 4.0.3 + dev: true /glob@10.3.10: resolution: {integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==} @@ -514,11 +768,56 @@ packages: path-scurry: 1.10.1 dev: true + /globals@14.0.0: + resolution: {integrity: sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==} + engines: {node: '>=18'} + dev: true + + /has-flag@4.0.0: + resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} + engines: {node: '>=8'} + dev: true + + /ignore@5.3.2: + resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==} + engines: {node: '>= 4'} + dev: true + + /import-fresh@3.3.0: + resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==} + engines: {node: '>=6'} + dependencies: + parent-module: 1.0.1 + resolve-from: 4.0.0 + dev: true + + /imurmurhash@0.1.4: + resolution: {integrity: sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==} + engines: {node: '>=0.8.19'} + dev: true + + /is-extglob@2.1.1: + resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==} + engines: {node: '>=0.10.0'} + dev: true + /is-fullwidth-code-point@3.0.0: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} engines: {node: '>=8'} dev: true + /is-glob@4.0.3: + resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==} + engines: {node: '>=0.10.0'} + dependencies: + is-extglob: 2.1.1 + dev: true + + /is-path-inside@3.0.3: + resolution: {integrity: sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==} + engines: {node: '>=8'} + dev: true + /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} dev: true @@ -532,42 +831,44 @@ packages: '@pkgjs/parseargs': 0.11.0 dev: true + /js-yaml@4.1.0: + resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==} + hasBin: true + dependencies: + argparse: 2.0.1 + dev: true + /json-bigint@1.0.0: resolution: {integrity: sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==} dependencies: bignumber.js: 9.1.2 dev: false - /jsonwebtoken@9.0.2: - resolution: {integrity: sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==} - engines: {node: '>=12', npm: '>=6'} - dependencies: - jws: 3.2.2 - lodash.includes: 4.3.0 - lodash.isboolean: 3.0.3 - lodash.isinteger: 4.0.4 - lodash.isnumber: 3.0.3 - lodash.isplainobject: 4.0.6 - lodash.isstring: 4.0.1 - lodash.once: 4.1.1 - ms: 2.1.3 - semver: 7.5.4 - dev: false + /json-buffer@3.0.1: + resolution: {integrity: sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==} + dev: true - /jwa@1.4.1: - resolution: {integrity: sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==} - dependencies: - buffer-equal-constant-time: 1.0.1 - ecdsa-sig-formatter: 1.0.11 - safe-buffer: 5.2.1 - dev: false + /json-schema-traverse@0.4.1: + resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==} + dev: true - /jws@3.2.2: - resolution: {integrity: sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==} + /json-stable-stringify-without-jsonify@1.0.1: + resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==} + dev: true + + /keyv@4.5.4: + resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} dependencies: - jwa: 1.4.1 - safe-buffer: 5.2.1 - dev: false + json-buffer: 3.0.1 + dev: true + + /levn@0.4.1: + resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} + engines: {node: '>= 0.8.0'} + dependencies: + prelude-ls: 1.2.1 + type-check: 0.4.0 + dev: true /locate-path@6.0.0: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} @@ -576,73 +877,20 @@ packages: p-locate: 5.0.0 dev: true - /lodash.includes@4.3.0: - resolution: {integrity: sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==} - dev: false - - /lodash.isboolean@3.0.3: - resolution: {integrity: sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==} - dev: false - - /lodash.isinteger@4.0.4: - resolution: {integrity: sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==} - dev: false - - /lodash.isnumber@3.0.3: - resolution: {integrity: sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==} - dev: false - - /lodash.isplainobject@4.0.6: - resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==} - dev: false - - /lodash.isstring@4.0.1: - resolution: {integrity: sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==} - dev: false - - /lodash.once@4.1.1: - resolution: {integrity: sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==} - dev: false - - /lower-case@2.0.2: - resolution: {integrity: sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==} - dependencies: - tslib: 2.6.2 - dev: false + /lodash.merge@4.6.2: + resolution: {integrity: sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==} + dev: true /lru-cache@10.1.0: resolution: {integrity: sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==} engines: {node: 14 || >=16.14} dev: true - /lru-cache@6.0.0: - resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} - engines: {node: '>=10'} + /minimatch@3.1.2: + resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} dependencies: - yallist: 4.0.0 - dev: false - - /map-obj@4.3.0: - resolution: {integrity: sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ==} - engines: {node: '>=8'} - dev: false - - /map-obj@5.0.0: - resolution: {integrity: sha512-2L3MIgJynYrZ3TYMriLDLWocz15okFakV6J12HXvMXDHui2x/zgChzg1u9mFFGbbGWE+GsLpQByt4POb9Or+uA==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: false - - /mime-db@1.52.0: - resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} - engines: {node: '>= 0.6'} - dev: false - - /mime-types@2.1.35: - resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} - engines: {node: '>= 0.6'} - dependencies: - mime-db: 1.52.0 - dev: false + brace-expansion: 1.1.11 + dev: true /minimatch@9.0.3: resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==} @@ -658,14 +906,23 @@ packages: /ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} - dev: false + dev: true - /no-case@3.0.4: - resolution: {integrity: sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==} + /natural-compare@1.4.0: + resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} + dev: true + + /optionator@0.9.4: + resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==} + engines: {node: '>= 0.8.0'} dependencies: - lower-case: 2.0.2 - tslib: 2.6.2 - dev: false + deep-is: 0.1.4 + fast-levenshtein: 2.0.6 + levn: 0.4.1 + prelude-ls: 1.2.1 + type-check: 0.4.0 + word-wrap: 1.2.5 + dev: true /p-limit@3.1.0: resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==} @@ -681,6 +938,13 @@ packages: p-limit: 3.1.0 dev: true + /parent-module@1.0.1: + resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==} + engines: {node: '>=6'} + dependencies: + callsites: 3.1.0 + dev: true + /path-exists@4.0.0: resolution: {integrity: sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==} engines: {node: '>=8'} @@ -699,14 +963,35 @@ packages: minipass: 7.0.4 dev: true - /proxy-from-env@1.1.0: - resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} - dev: false + /prelude-ls@1.2.1: + resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} + engines: {node: '>= 0.8.0'} + dev: true - /quick-lru@6.1.2: - resolution: {integrity: sha512-AAFUA5O1d83pIHEhJwWCq/RQcRukCkn/NSm2QsTEMle5f2hP0ChI2+3Xb051PZCkLryI/Ir1MVKviT2FIloaTQ==} - engines: {node: '>=12'} - dev: false + /prettier@3.3.3: + resolution: {integrity: sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==} + engines: {node: '>=14'} + hasBin: true + dev: true + + /punycode@2.3.1: + resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} + engines: {node: '>=6'} + dev: true + + /queue-microtask@1.2.3: + resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} + dev: true + + /resolve-from@4.0.0: + resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==} + engines: {node: '>=4'} + dev: true + + /reusify@1.0.4: + resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} + engines: {iojs: '>=1.0.0', node: '>=0.10.0'} + dev: true /rimraf@5.0.5: resolution: {integrity: sha512-CqDakW+hMe/Bz202FPEymy68P+G50RfMQK+Qo5YUqc9SPipvbGjCGKd0RSKEelbsfQuw3g5NZDSrlZZAJurH1A==} @@ -716,17 +1001,11 @@ packages: glob: 10.3.10 dev: true - /safe-buffer@5.2.1: - resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} - dev: false - - /semver@7.5.4: - resolution: {integrity: sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==} - engines: {node: '>=10'} - hasBin: true + /run-parallel@1.2.0: + resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: - lru-cache: 6.0.0 - dev: false + queue-microtask: 1.2.3 + dev: true /shebang-command@2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} @@ -745,22 +1024,6 @@ packages: engines: {node: '>=14'} dev: true - /snake-case@3.0.4: - resolution: {integrity: sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg==} - dependencies: - dot-case: 3.0.4 - tslib: 2.6.2 - dev: false - - /snakecase-keys@5.5.0: - resolution: {integrity: sha512-r3kRtnoPu3FxGJ3fny6PKNnU3pteb29o6qAa0ugzhSseKNWRkw1dw8nIjXMyyKaU9vQxxVIE62Mb3bKbdrgpiw==} - engines: {node: '>=12'} - dependencies: - map-obj: 4.3.0 - snake-case: 3.0.4 - type-fest: 3.13.1 - dev: false - /string-width@4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} @@ -793,22 +1056,32 @@ packages: ansi-regex: 6.0.1 dev: true - /toml@3.0.0: - resolution: {integrity: sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==} - dev: false + /strip-json-comments@3.1.1: + resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==} + engines: {node: '>=8'} + dev: true + + /supports-color@7.2.0: + resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} + engines: {node: '>=8'} + dependencies: + has-flag: 4.0.0 + dev: true + + /text-table@0.2.0: + resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} + dev: true /tslib@2.6.2: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} + dev: true - /type-fest@3.13.1: - resolution: {integrity: sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==} - engines: {node: '>=14.16'} - dev: false - - /type-fest@4.9.0: - resolution: {integrity: sha512-KS/6lh/ynPGiHD/LnAobrEFq3Ad4pBzOlJ1wAnJx9N4EYoqFhMfLIBjUT2UEx4wg5ZE+cC1ob6DCSpppVo+rtg==} - engines: {node: '>=16'} - dev: false + /type-check@0.4.0: + resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} + engines: {node: '>= 0.8.0'} + dependencies: + prelude-ls: 1.2.1 + dev: true /typescript@5.3.3: resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} @@ -820,15 +1093,11 @@ packages: resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} dev: true - /uuid@9.0.1: - resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==} - hasBin: true - dev: false - - /uuidv7@0.6.3: - resolution: {integrity: sha512-zV3eW2NlXTsun/aJ7AixxZjH/byQcH/r3J99MI0dDEkU2cJIBJxhEWUHDTpOaLPRNhebPZoeHuykYREkI9HafA==} - hasBin: true - dev: false + /uri-js@4.4.1: + resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} + dependencies: + punycode: 2.3.1 + dev: true /which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} @@ -838,6 +1107,11 @@ packages: isexe: 2.0.0 dev: true + /word-wrap@1.2.5: + resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} + engines: {node: '>=0.10.0'} + dev: true + /wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} @@ -856,10 +1130,6 @@ packages: strip-ansi: 7.1.0 dev: true - /yallist@4.0.0: - resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - dev: false - /yocto-queue@0.1.0: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} diff --git a/scripts/nswag.ps1 b/scripts/nswag.ps1 new file mode 100644 index 0000000..ad9ee6b --- /dev/null +++ b/scripts/nswag.ps1 @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +nswag run ./src/api/api.nswag diff --git a/src/api.ts b/src/api.ts deleted file mode 100644 index 6061d02..0000000 --- a/src/api.ts +++ /dev/null @@ -1,544 +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(), - logEnabled: 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(); - } - - /** - * Set the tokens. - * @param accessToken - * @param refreshToken - * @param expiresIn - */ - protected setApiKey(apiKey: string | null): void { - this.options.apiKey = apiKey; - } - - /** - * 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 - */ - protected 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 { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/games?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 { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/games/${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 { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/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 { - 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 { - const headers = this.getHeaders() - const responseBody = await this.http.get(`/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 { - const parts = address.split(":"); - const hostOrAddress = parts[0]; - const queryPort = parts[1]; - - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/servers?address=${hostOrAddress}&query_port=${queryPort}`, headers); - - if (!responseBody) { - return null; - } - - return responseBody[0]; - } - - /** - * Get a user by id from the Tribufu API. - * @param id - * @returns User | null - */ - public async getUserById(id: string): Promise { - 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 { - 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 { - return await this.getUserByKey("name", name); - } - - /** - * Get a user by custom key from the Tribufu API. - * @param key - * @param value - * @returns User[] - */ - private async getUserByKey(key: string, value: string): Promise { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/users?${key}=${value}`, headers); - - if (!responseBody) { - return []; - } - - return responseBody; - } - - /** - * Get all groups for a user from the Tribufu API. - * @param userId - * @returns Group[] - */ - public async getUserGroups(userId: string): Promise { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/users/${userId}/groups`, headers); - - if (!responseBody) { - return []; - } - - return responseBody; - } - - /** - * Get all games for a user from the Tribufu API. - * @param userId - * @returns Game[] - */ - public async getUserGames(userId: string): Promise { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/users/${userId}/games`, headers); - - if (!responseBody) { - return []; - } - - return responseBody; - } - - /** - * Get all punishments for a user from the Tribufu API. - * @param userId - * @returns Punishment[] - */ - public async getUserPunishments(userId: string): Promise { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/users/${userId}/punishments`, 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 { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/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 { - 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 { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/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 { - const headers = this.getHeaders() - const responseBody = await this.http.get(`/v1/files/${id}`, headers); - - if (!responseBody) { - return null; - } - - return responseBody; - } - - /** - * Get clusters from the Tribufu API. - * @param page - * @returns Cluster[] - */ - public async getClusters(page: number = 1): Promise { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/clusters?page=${page}`, headers); - - if (!responseBody) { - return []; - } - - return responseBody; - } - - /** - * Get a cluster by id from the Tribufu API. - * @param id - * @returns Cluster | null - */ - public async getClusterById(id: string): Promise { - const headers = this.getHeaders() - const responseBody = await this.http.get(`/v1/clusters/${id}`, headers); - - if (!responseBody) { - return null; - } - - return responseBody; - } - - /** - * Get subscriptions from the Tribufu API. - * @param page - * @returns Subscription[] - */ - public async getSubscriptions(page: number = 1): Promise { - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/subscriptions?page=${page}`, headers); - - if (!responseBody) { - return []; - } - - return responseBody; - } - - /** - * Get a subscription by id from the Tribufu API. - * @param id - * @returns Subscription | null - */ - public async getSubscriptionById(id: string): Promise { - const headers = this.getHeaders() - const responseBody = await this.http.get(`/v1/subscriptions/${id}`, headers); - - if (!responseBody) { - return null; - } - - return responseBody; - } -} diff --git a/src/api/api.base.ts b/src/api/api.base.ts new file mode 100644 index 0000000..d9f7d94 --- /dev/null +++ b/src/api/api.base.ts @@ -0,0 +1,104 @@ +// 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 (!process) { + return false; + } + + return process.env.NODE_ENV === "development"; + } + + /** + * 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-Language"] = "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) { + if (this.apiKey) { + options.headers = { + ...options.headers, + ...this.getHeaders(), + }; + } + + return Promise.resolve(options); + } +} diff --git a/src/api/api.generated.ts b/src/api/api.generated.ts new file mode 100644 index 0000000..0d4be34 --- /dev/null +++ b/src/api/api.generated.ts @@ -0,0 +1,2233 @@ +//---------------------- +// +// Generated using the NSwag toolchain v14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org) +// +//---------------------- + +/* tslint:disable */ +/* eslint-disable */ +// ReSharper disable InconsistentNaming + +import { TribufuApiBase } from "./api.base"; + +export class TribufuApiGenerated extends TribufuApiBase { + private http: { fetch(url: RequestInfo, init?: RequestInit): Promise }; + private baseUrl: string; + protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined; + + constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise }) { + super(); + this.http = http ? http : window as any; + this.baseUrl = baseUrl ?? ""; + } + + /** + * @return OK + */ + authGetUserInfo(): Promise { + let url_ = this.baseUrl + "/v1/me"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processAuthGetUserInfo(_response); + }); + } + + protected processAuthGetUserInfo(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as UserInfo; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + authLogin(body: LoginRequest | undefined): Promise { + let url_ = this.baseUrl + "/v1/login"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processAuthLogin(_response); + }); + } + + protected processAuthLogin(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as LoginResponse; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + authRegister(body: RegisterRequest | undefined): Promise { + let url_ = this.baseUrl + "/v1/register"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processAuthRegister(_response); + }); + } + + protected processAuthRegister(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as LoginResponse; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + authRefresh(body: RefreshRequest | undefined): Promise { + let url_ = this.baseUrl + "/v1/refresh"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processAuthRefresh(_response); + }); + } + + protected processAuthRefresh(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as LoginResponse; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + authLogout(): Promise { + let url_ = this.baseUrl + "/v1/logout"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "POST", + headers: { + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processAuthLogout(_response); + }); + } + + protected processAuthLogout(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + return; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param page (optional) + * @return OK + */ + clustersGetPage(page: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/clusters?"; + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processClustersGetPage(_response); + }); + } + + protected processClustersGetPage(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GameServerCluster[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + clustersGetById(id: string): Promise { + let url_ = this.baseUrl + "/v1/clusters/{id}"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processClustersGetById(_response); + }); + } + + protected processClustersGetById(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GameServerCluster; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param page (optional) + * @return OK + */ + filesGetPage(page: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/files?"; + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processFilesGetPage(_response); + }); + } + + protected processFilesGetPage(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as File[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + filesGetById(id: string): Promise { + let url_ = this.baseUrl + "/v1/files/{id}"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processFilesGetById(_response); + }); + } + + protected processFilesGetById(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as File; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + gamesGetAll(): Promise { + let url_ = this.baseUrl + "/v1/games"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processGamesGetAll(_response); + }); + } + + protected processGamesGetAll(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Game[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + gamesGetById(id: string): Promise { + let url_ = this.baseUrl + "/v1/games/{id}"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processGamesGetById(_response); + }); + } + + protected processGamesGetById(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Game; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param page (optional) + * @return OK + */ + gamesGetServers(id: string, page: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/games/{id}/servers?"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processGamesGetServers(_response); + }); + } + + protected processGamesGetServers(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GameServer[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param page (optional) + * @return OK + */ + gamesGetClusters(id: string, page: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/games/{id}/clusters?"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processGamesGetClusters(_response); + }); + } + + protected processGamesGetClusters(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GameServerCluster[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param uuid (optional) + * @param tag (optional) + * @param name (optional) + * @param email (optional) + * @param page (optional) + * @param limit (optional) + * @return OK + */ + groupsGetPage(uuid: string | undefined, tag: string | undefined, name: string | undefined, email: string | undefined, page: number | undefined, limit: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/groups?"; + if (uuid === null) + throw new Error("The parameter 'uuid' cannot be null."); + else if (uuid !== undefined) + url_ += "uuid=" + encodeURIComponent("" + uuid) + "&"; + if (tag === null) + throw new Error("The parameter 'tag' cannot be null."); + else if (tag !== undefined) + url_ += "tag=" + encodeURIComponent("" + tag) + "&"; + if (name === null) + throw new Error("The parameter 'name' cannot be null."); + else if (name !== undefined) + url_ += "name=" + encodeURIComponent("" + name) + "&"; + if (email === null) + throw new Error("The parameter 'email' cannot be null."); + else if (email !== undefined) + url_ += "email=" + encodeURIComponent("" + email) + "&"; + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + if (limit === null) + throw new Error("The parameter 'limit' cannot be null."); + else if (limit !== undefined) + url_ += "limit=" + encodeURIComponent("" + limit) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processGroupsGetPage(_response); + }); + } + + protected processGroupsGetPage(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Group[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + groupsGetById(id: string): Promise { + let url_ = this.baseUrl + "/v1/groups/{id}"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processGroupsGetById(_response); + }); + } + + protected processGroupsGetById(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Group; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + groupsGetMembers(id: string): Promise { + let url_ = this.baseUrl + "/v1/groups/{id}/members"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processGroupsGetMembers(_response); + }); + } + + protected processGroupsGetMembers(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GroupMember[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + groupsGetGames(id: string): Promise { + let url_ = this.baseUrl + "/v1/groups/{id}/games"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processGroupsGetGames(_response); + }); + } + + protected processGroupsGetGames(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GroupGame[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param order (optional) + * @return OK + */ + leaderboardGetTop20(order: LeaderboardOrder | undefined): Promise { + let url_ = this.baseUrl + "/v1/leaderboard?"; + if (order === null) + throw new Error("The parameter 'order' cannot be null."); + else if (order !== undefined) + url_ += "Order=" + encodeURIComponent("" + order) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processLeaderboardGetTop20(_response); + }); + } + + protected processLeaderboardGetTop20(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as LeaderboardItem[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + searchSearch(body: SearchRequest | undefined): Promise { + let url_ = this.baseUrl + "/v1/search"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processSearchSearch(_response); + }); + } + + protected processSearchSearch(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as any[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param address (optional) + * @param query_port (optional) + * @param country (optional) + * @param page (optional) + * @param limit (optional) + * @return OK + */ + serversGetPage(address: string | undefined, query_port: number | undefined, country: string | undefined, page: number | undefined, limit: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/servers?"; + if (address === null) + throw new Error("The parameter 'address' cannot be null."); + else if (address !== undefined) + url_ += "address=" + encodeURIComponent("" + address) + "&"; + if (query_port === null) + throw new Error("The parameter 'query_port' cannot be null."); + else if (query_port !== undefined) + url_ += "query_port=" + encodeURIComponent("" + query_port) + "&"; + if (country === null) + throw new Error("The parameter 'country' cannot be null."); + else if (country !== undefined) + url_ += "country=" + encodeURIComponent("" + country) + "&"; + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + if (limit === null) + throw new Error("The parameter 'limit' cannot be null."); + else if (limit !== undefined) + url_ += "limit=" + encodeURIComponent("" + limit) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processServersGetPage(_response); + }); + } + + protected processServersGetPage(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GameServer[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + serversGetById(id: string): Promise { + let url_ = this.baseUrl + "/v1/servers/{id}"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processServersGetById(_response); + }); + } + + protected processServersGetById(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GameServer; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + serversGetMetrics(): Promise { + let url_ = this.baseUrl + "/v1/servers/metrics"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processServersGetMetrics(_response); + }); + } + + protected processServersGetMetrics(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as ServerMetrics; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + serversGetCountries(): Promise<{ [key: string]: number; }> { + let url_ = this.baseUrl + "/v1/servers/countries"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processServersGetCountries(_response); + }); + } + + protected processServersGetCountries(response: Response): Promise<{ [key: string]: number; }> { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as { [key: string]: number; }; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve<{ [key: string]: number; }>(null as any); + } + + /** + * @param page (optional) + * @return OK + */ + subscriptionsGetPage(page: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/subscriptions?"; + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processSubscriptionsGetPage(_response); + }); + } + + protected processSubscriptionsGetPage(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Subscription[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + subscriptionsGetById(id: string): Promise { + let url_ = this.baseUrl + "/v1/subscriptions/{id}"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processSubscriptionsGetById(_response); + }); + } + + protected processSubscriptionsGetById(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Subscription; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param uuid (optional) + * @param name (optional) + * @param email (optional) + * @param page (optional) + * @param limit (optional) + * @return OK + */ + usersGetPage(uuid: string | undefined, name: string | undefined, email: string | undefined, page: number | undefined, limit: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/users?"; + if (uuid === null) + throw new Error("The parameter 'uuid' cannot be null."); + else if (uuid !== undefined) + url_ += "uuid=" + encodeURIComponent("" + uuid) + "&"; + if (name === null) + throw new Error("The parameter 'name' cannot be null."); + else if (name !== undefined) + url_ += "name=" + encodeURIComponent("" + name) + "&"; + if (email === null) + throw new Error("The parameter 'email' cannot be null."); + else if (email !== undefined) + url_ += "email=" + encodeURIComponent("" + email) + "&"; + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + if (limit === null) + throw new Error("The parameter 'limit' cannot be null."); + else if (limit !== undefined) + url_ += "limit=" + encodeURIComponent("" + limit) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersGetPage(_response); + }); + } + + protected processUsersGetPage(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Profile[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + usersGetById(id: string): Promise { + let url_ = this.baseUrl + "/v1/users/{id}"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersGetById(_response); + }); + } + + protected processUsersGetById(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Profile; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + usersGetGroups(id: string): Promise { + let url_ = this.baseUrl + "/v1/users/{id}/groups"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersGetGroups(_response); + }); + } + + protected processUsersGetGroups(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as ProfileGroup[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + usersGetGames(id: string): Promise { + let url_ = this.baseUrl + "/v1/users/{id}/games"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersGetGames(_response); + }); + } + + protected processUsersGetGames(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as ProfileGame[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + usersGetFriends(id: string): Promise { + let url_ = this.baseUrl + "/v1/users/{id}/friends"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersGetFriends(_response); + }); + } + + protected processUsersGetFriends(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as any[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param page (optional) + * @param limit (optional) + * @return OK + */ + usersGetServers(id: string, page: number | undefined, limit: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/users/{id}/servers?"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + if (page === null) + throw new Error("The parameter 'page' cannot be null."); + else if (page !== undefined) + url_ += "page=" + encodeURIComponent("" + page) + "&"; + if (limit === null) + throw new Error("The parameter 'limit' cannot be null."); + else if (limit !== undefined) + url_ += "limit=" + encodeURIComponent("" + limit) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersGetServers(_response); + }); + } + + protected processUsersGetServers(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as GameServer[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + usersGetAccounts(id: string): Promise { + let url_ = this.baseUrl + "/v1/users/{id}/accounts"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersGetAccounts(_response); + }); + } + + protected processUsersGetAccounts(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Account[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @return OK + */ + usersGetPunishments(id: string): Promise { + let url_ = this.baseUrl + "/v1/users/{id}/punishments"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersGetPunishments(_response); + }); + } + + protected processUsersGetPunishments(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as any[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + usersUpdateProfile(id: string, body: UpdateProfile | undefined): Promise { + let url_ = this.baseUrl + "/v1/users/{id}/profile"; + if (id === undefined || id === null) + throw new Error("The parameter 'id' must be defined."); + url_ = url_.replace("{id}", encodeURIComponent("" + id)); + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "PUT", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUsersUpdateProfile(_response); + }); + } + + protected processUsersUpdateProfile(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as Profile; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param length (optional) + * @param symbols (optional) + * @return OK + */ + utilsPassword(length: number | undefined, symbols: boolean | undefined): Promise { + let url_ = this.baseUrl + "/v1/utils/password?"; + if (length === null) + throw new Error("The parameter 'length' cannot be null."); + else if (length !== undefined) + url_ += "length=" + encodeURIComponent("" + length) + "&"; + if (symbols === null) + throw new Error("The parameter 'symbols' cannot be null."); + else if (symbols !== undefined) + url_ += "symbols=" + encodeURIComponent("" + symbols) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUtilsPassword(_response); + }); + } + + protected processUtilsPassword(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as HashViewModel; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param amount (optional) + * @return OK + */ + utilsNewFlake(amount: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/utils/flake?"; + if (amount === null) + throw new Error("The parameter 'amount' cannot be null."); + else if (amount !== undefined) + url_ += "amount=" + encodeURIComponent("" + amount) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUtilsNewFlake(_response); + }); + } + + protected processUtilsNewFlake(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as string[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param version (optional) + * @param amount (optional) + * @return OK + */ + utilsNewUuid(version: number | undefined, amount: number | undefined): Promise { + let url_ = this.baseUrl + "/v1/utils/uuid?"; + if (version === null) + throw new Error("The parameter 'version' cannot be null."); + else if (version !== undefined) + url_ += "version=" + encodeURIComponent("" + version) + "&"; + if (amount === null) + throw new Error("The parameter 'amount' cannot be null."); + else if (amount !== undefined) + url_ += "amount=" + encodeURIComponent("" + amount) + "&"; + url_ = url_.replace(/[?&]$/, ""); + + let options_: RequestInit = { + method: "GET", + headers: { + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUtilsNewUuid(_response); + }); + } + + protected processUtilsNewUuid(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as string[]; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + utilsBase64(body: CryptoViewModel | undefined): Promise { + let url_ = this.baseUrl + "/v1/utils/base64"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUtilsBase64(_response); + }); + } + + protected processUtilsBase64(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as CryptoViewModel; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + utilsMd5Hash(body: HashViewModel | undefined): Promise { + let url_ = this.baseUrl + "/v1/utils/md5"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUtilsMd5Hash(_response); + }); + } + + protected processUtilsMd5Hash(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as HashViewModel; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + utilsSha256Hash(body: HashViewModel | undefined): Promise { + let url_ = this.baseUrl + "/v1/utils/sha256"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUtilsSha256Hash(_response); + }); + } + + protected processUtilsSha256Hash(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as HashViewModel; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + utilsBcryptHash(body: HashViewModel | undefined): Promise { + let url_ = this.baseUrl + "/v1/utils/bcrypt"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUtilsBcryptHash(_response); + }); + } + + protected processUtilsBcryptHash(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as HashViewModel; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } + + /** + * @param body (optional) + * @return OK + */ + utilsArgon2Hash(body: HashViewModel | undefined): Promise { + let url_ = this.baseUrl + "/v1/utils/argon2"; + url_ = url_.replace(/[?&]$/, ""); + + const content_ = JSON.stringify(body); + + let options_: RequestInit = { + body: content_, + method: "POST", + headers: { + "Content-Type": "application/json-patch+json", + "Accept": "text/plain" + } + }; + + return this.transformOptions(options_).then(transformedOptions_ => { + return this.http.fetch(url_, transformedOptions_); + }).then((_response: Response) => { + return this.processUtilsArgon2Hash(_response); + }); + } + + protected processUtilsArgon2Hash(response: Response): Promise { + const status = response.status; + let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); }; + if (status === 200) { + return response.text().then((_responseText) => { + let result200: any = null; + result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as HashViewModel; + return result200; + }); + } else if (status !== 200 && status !== 204) { + return response.text().then((_responseText) => { + return throwException("An unexpected server error occurred.", status, _responseText, _headers); + }); + } + return Promise.resolve(null as any); + } +} + +export interface Account { + id?: string | null; + name?: string | null; + provider?: LoginProvider; + user_id?: string; + authorized?: boolean; + fields?: any | null; + created?: string; + updated?: string | null; +} + +export interface CryptoViewModel { + encoded?: string | null; + decoded?: string | null; +} + +export interface File { + id?: string; + name?: string | null; + description?: string | null; + image_url?: string | null; + author_id?: string; + version?: string | null; + file_url?: string | null; + raw_size?: number; + download_count?: number; + last_download?: string | null; + created?: string; + updated?: string | null; +} + +export interface Game { + id?: string; + name?: string | null; + description?: string | null; + type?: number; + organization_id?: string; + icon_url?: string | null; + banner_url?: string | null; + capsule_image_url?: string | null; + library_image_url?: string | null; + parent_id?: string | null; + slug?: string | null; + visibility?: number; + password?: string | null; + primary?: number; + game_port?: number | null; + query_port?: number | null; + rcon_port?: number | null; + user_count?: number; + server_count?: number; + achievement_count?: number; + badge_count?: number; + download_count?: number; + steam_app_id?: number | null; + steam_server_app_id?: number | null; + enable_servers?: boolean; + rust_gamedig_id?: string | null; + node_gamedig_id?: string | null; + server_connect_url?: string | null; + server_tags?: string | null; + created?: string; + updated?: string | null; +} + +export interface GameServer { + id?: string; + name?: string | null; + description?: string | null; + address?: string | null; + game_port?: number | null; + query_port?: number; + game_id?: string; + game_icon_url?: string | null; + version?: string | null; + featured?: number; + cluster_id?: string | null; + website_url?: string | null; + banner_url?: string | null; + owner_id?: string | null; + uptime?: number; + status?: ServerStatus; + ping?: number | null; + map?: string | null; + used_slots?: number | null; + max_slots?: number | null; + motd?: string | null; + players?: string | null; + last_online?: string | null; + country?: string | null; + steam?: number; + discord_server_id?: string | null; + youtube_video_url?: string | null; + tags?: string | null; + comment_count?: number; + created?: string; + updated?: string | null; +} + +export interface GameServerCluster { + id?: string; + name?: string | null; + description?: string | null; + package_id?: string; + website_url?: string | null; + banner_url?: string | null; + owner_id?: string; + discord_server_id?: string | null; + youtube_video_url?: string | null; + tags?: string | null; + comment_count?: number; + server_count?: number; + created?: string; + updated?: string | null; +} + +export interface Group { + id?: string; + uuid?: string; + name?: string | null; + tag?: string | null; + description?: string | null; + type?: number; + privacy?: number; + owner_id?: string; + verified?: boolean; + photo_url?: string | null; + banner_url?: string | null; + member_count?: number; + follower_count?: number; + view_count?: number; + created?: string; + updated?: string | null; +} + +export interface GroupGame { + group_id?: string; + game_id?: string; + stats?: any | null; + acquired?: string; + last_used?: string | null; + group?: Group; +} + +export interface GroupMember { + id?: string; + uuid?: string; + name?: string | null; + display_name?: string | null; + verified?: boolean; + photo_url?: string | null; + last_online?: string | null; + rank?: GroupRank; + since?: string; +} + +export enum GroupRank { + Member = "member", + Leader = "leader", + Owner = "owner", +} + +export interface HashViewModel { + value?: string | null; +} + +export interface LeaderboardItem { + name?: string | null; + display_name?: string | null; + photo_url?: string | null; + level?: number; + experience?: number; + points?: number; +} + +export enum LeaderboardOrder { + Level = "level", + Points = "points", +} + +export enum LoginProvider { + Steam = "steam", + Epic = "epic", + Discord = "discord", + Microsoft = "microsoft", + Playstation = "playstation", + Google = "google", + Apple = "apple", +} + +export interface LoginRequest { + login?: string | null; + password?: string | null; +} + +export interface LoginResponse { + user?: UserInfo; + access_token?: string | null; + refresh_token?: string | null; + expires_in?: number; +} + +export interface Profile { + id?: string; + uuid?: string; + name?: string | null; + display_name?: string | null; + flags?: string; + verified?: boolean; + level?: number; + experience?: number; + public_birthday?: boolean; + birthday?: string | null; + points?: number; + location?: string | null; + photo_url?: string | null; + banner_url?: string | null; + last_online?: string | null; + biography?: string | null; + view_count?: number; + created?: string; + updated?: string | null; +} + +export interface ProfileGame { + id?: string; + name?: string | null; + capsule_image_url?: string | null; + library_image_url?: string | null; + slug?: string | null; + time_used?: number; + unlocked_achievements?: number; + total_achievements?: number; + stats?: any | null; + acquired?: string; + last_used?: string | null; +} + +export interface ProfileGroup { + id?: string; + uuid?: string; + name?: string | null; + tag?: string | null; + privacy?: number; + verified?: boolean; + photo_url?: string | null; + member_count?: number; + rank?: GroupRank; + since?: string; +} + +export interface RefreshRequest { + refresh_token?: string | null; +} + +export interface RegisterRequest { + uuid?: string | null; + name: string; + email?: string | null; + password: string; +} + +export interface SearchRequest { + type?: SearchType; + query?: string | null; + page?: number | null; + game_id?: string | null; +} + +export enum SearchType { + User = "user", + Group = "group", + Server = "server", + Cluster = "cluster", +} + +export interface ServerMetrics { + server_count?: number; + package_count?: number; + country_count?: number; +} + +export enum ServerStatus { + Unknown = "unknown", + Offline = "offline", + Online = "online", +} + +export interface Subscription { + id?: string; + name?: string | null; + description?: string | null; + image_url?: string | null; + readonly prices?: { [key: string]: number; } | null; + created?: string; + updated?: string | null; +} + +export interface UpdateProfile { + display_name?: string | null; + biography?: string | null; +} + +export interface UserInfo { + id?: string; + uuid?: string; + name?: string | null; + display_name?: string | null; + email?: string | null; + type?: UserType; + flags?: string; + permissions?: string; + verified?: boolean; + level?: number; + experience?: number; + public_birthday?: boolean; + birthday?: string | null; + points?: number; + location?: string | null; + language?: string | null; + timezone?: string | null; + currency?: string | null; + photo_url?: string | null; + banner_url?: string | null; + last_online?: string | null; + biography?: string | null; + view_count?: number; + created?: string; + updated?: string | null; +} + +export enum UserType { + User = "user", + Bot = "bot", + Organization = "organization", +} + +export class TribufuApiError extends Error { + override message: string; + status: number; + response: string; + headers: { [key: string]: any; }; + result: any; + + constructor(message: string, status: number, response: string, headers: { [key: string]: any; }, result: any) { + super(); + + this.message = message; + this.status = status; + this.response = response; + this.headers = headers; + this.result = result; + } + + protected isTribufuApiError = true; + + static isTribufuApiError(obj: any): obj is TribufuApiError { + return obj.isTribufuApiError === true; + } +} + +function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any { + if (result !== null && result !== undefined) + throw result; + else + throw new TribufuApiError(message, status, response, headers, null); +} diff --git a/src/api/api.include.ts b/src/api/api.include.ts new file mode 100644 index 0000000..e6021f9 --- /dev/null +++ b/src/api/api.include.ts @@ -0,0 +1 @@ +import { TribufuApiBase } from "./api.base"; diff --git a/src/api/api.nswag b/src/api/api.nswag new file mode 100644 index 0000000..fa82959 --- /dev/null +++ b/src/api/api.nswag @@ -0,0 +1,74 @@ +{ + "runtime": "Default", + "defaultVariables": null, + "documentGenerator": { + "fromDocument": { + "json": "", + "url": "http://localhost:5000/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": false, + "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": true, + "generateCloneMethod": false, + "typeStyle": "Interface", + "enumStyle": "Enum", + "useLeafType": false, + "classTypes": [], + "extendedClasses": [], + "extensionCode": "api.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": "api.generated.ts", + "newLineBehavior": "LF" + } + } +} diff --git a/src/api/index.ts b/src/api/index.ts new file mode 100644 index 0000000..47e944f --- /dev/null +++ b/src/api/index.ts @@ -0,0 +1,107 @@ +// Copyright (c) Tribufu. All Rights Reserved. +// SPDX-License-Identifier: MIT + +import { TRIBUFU_API_URL } from ".."; +import { TribufuApiBase } from "./api.base"; +import { TribufuApiGenerated } from "./api.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. + * @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}_` : ""; + + if (!process) { + return null; + } + + 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(); + } + + /** + * 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 { + if (!process) { + return TRIBUFU_API_URL; + } + + const baseUrl = process.env[`TRIBUFU_API_URL`] || null; + return TribufuApiBase.debugEnabled() && baseUrl + ? baseUrl + : TRIBUFU_API_URL; + } +} diff --git a/src/bot.ts b/src/bot.ts deleted file mode 100644 index 4b4b63c..0000000 --- a/src/bot.ts +++ /dev/null @@ -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; - } -} diff --git a/src/client.ts b/src/client.ts deleted file mode 100644 index 6725759..0000000 --- a/src/client.ts +++ /dev/null @@ -1,386 +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"; - -/** - * **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 apiKey = process.env[`${envPrefix}API_KEY`]; - const clientId = process.env[`${envPrefix}CLIENT_ID`]; - const clientSecret = process.env[`${envPrefix}CLIENT_SECRET`]; - - if (!clientId || !clientSecret) { - return null; - } - - const client = new TribufuClient(clientId, clientSecret); - - /* - if (apiKey) { - client.setApiKey(apiKey); - } - */ - - return client; - } - - /** - * 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 && accessToken && refreshToken) { - 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 current headers with the api key or access token. - * @returns HeaderMap - */ - protected override getHeaders(): HttpHeaders { - let headers = TribufuClient.defaultHeaders(); - headers.set("Authorization", `Basic ${Buffer.from(`${this.clientId}:${this.clientSecret}`, "binary").toString("base64")}`); - - if (this.options.accessToken) { - headers.set("Authorization", `Bearer ${this.options.accessToken}`); - return headers; - } - - 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 { - 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 { - 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 { - 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 { - 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 { - 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 { - 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 { - 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(url, requestBody, headers); - - if (!responseBody) { - return null; - } - - return responseBody; - } - - /** - * Revoke a refresh token. - * @returns boolean - */ - public async revokeToken(): Promise { - 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(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 { - 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 { - 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(url, requestBody, headers); - - if (!responseBody) { - return null; - } - - return responseBody; - } - - /** - * Get information about the current client. - * @returns Client | null - */ - public async getClientInfo(): Promise { - return this.getClientById(this.clientId); - } - - /** - * Get information about the current user. - * @returns User | null - */ - public async getUserInfo(): Promise { - if (!this.options.accessToken) { - return null; - } - - const headers = this.getHeaders(); - const responseBody = await this.http.get(`/v1/oauth2/userinfo`, headers); - - if (!responseBody) { - return null; - } - - return responseBody; - } -} diff --git a/src/constants.ts b/src/constants.ts index d791f8d..15e9da5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,26 +1,24 @@ // Copyright (c) Tribufu. All Rights Reserved. // SPDX-License-Identifier: MIT +import packageJson from "../package.json"; + /** * The version of the Tribufu SDK. - * @type {string} */ -export const TRIBUFU_VERSION = "0.1.13"; +export const TRIBUFU_VERSION: string = packageJson.version; /** * The default Tribufu API URL. - * @type {string} */ -export const TRIBUFU_API_URL = "https://api.tribufu.com"; +export const TRIBUFU_API_URL: string = "https://api.tribufu.com"; /** * 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 CDN URL. - * @type {string} */ -export const TRIBUFU_CDN_URL = "https://cdn.tribufu.com"; +export const TRIBUFU_CDN_URL: string = "https://cdn.tribufu.com"; diff --git a/src/http/headers.ts b/src/http/headers.ts new file mode 100644 index 0000000..e6a1020 --- /dev/null +++ b/src/http/headers.ts @@ -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; +}; diff --git a/src/index.ts b/src/index.ts index 845cf6d..dcccaaa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,23 +8,9 @@ import { TRIBUFU_WEB_URL, } from "./constants"; -export { - TRIBUFU_API_URL, - TRIBUFU_CDN_URL, - TRIBUFU_VERSION, - TRIBUFU_WEB_URL, -}; +export { TRIBUFU_API_URL, TRIBUFU_CDN_URL, TRIBUFU_VERSION, 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, - TribufuApiOptions, - TribufuBot, - TribufuClient, - TribufuServer, -}; +export { TribufuApi, TribufuApiOptions }; diff --git a/src/models/cluster.ts b/src/models/cluster.ts deleted file mode 100644 index 490bd32..0000000 --- a/src/models/cluster.ts +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Tribufu. All Rights Reserved. -// SPDX-License-Identifier: MIT - -import { MiniProfile } from "./profile"; - -export interface Cluster { - id: string, - name: string, - description: string | null, - packageId: string, - websiteUrl: string | null, - bannerUrl: string | null, - ownerId: string | null, - owner: MiniProfile | null, - discordServerId: string | null, - youtubeVideoUrl: string | null, - tags: string | null, - commentCount: number, - serverCount: number, - created: string, - updated: string | null -} diff --git a/src/models/profile.ts b/src/models/profile.ts deleted file mode 100644 index d07cd28..0000000 --- a/src/models/profile.ts +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Tribufu. All Rights Reserved. -// SPDX-License-Identifier: MIT - -export type ProfileType = "user" | "bot" | "org"; - -export type Profile = any; - -export interface MiniProfile { - id: string, - uuid: string, - name: string, - displayName: string, - type: ProfileType, - verified: boolean, - photoUrl: string | null -} diff --git a/src/options.ts b/src/options.ts index ff95462..a127d66 100644 --- a/src/options.ts +++ b/src/options.ts @@ -2,8 +2,7 @@ // SPDX-License-Identifier: MIT export interface TribufuApiOptions { - apiKey?: string | null; - accessToken?: string | null; - refreshToken?: string | null; - expiresIn?: number | null; + baseUrl?: string; + apiKey?: string; + fetch?: (url: RequestInfo, init?: RequestInit) => Promise; } diff --git a/src/server.ts b/src/server.ts deleted file mode 100644 index 33bda1a..0000000 --- a/src/server.ts +++ /dev/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 { - return this.getServerById(this.serverId); - } - - /** - * Get a list of connected users. - * @returns - */ - public async getConnectedUsers(): Promise { - return []; - } -} diff --git a/src/socket/index.ts b/src/socket/index.ts deleted file mode 100644 index da87559..0000000 --- a/src/socket/index.ts +++ /dev/null @@ -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() { - } -} diff --git a/src/token.ts b/src/token.ts deleted file mode 100644 index b1f38f8..0000000 --- a/src/token.ts +++ /dev/null @@ -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; -}