diff --git a/package-lock.json b/package-lock.json index 694e97f..c0e7394 100644 --- a/package-lock.json +++ b/package-lock.json @@ -419,21 +419,63 @@ } }, "node_modules/@bettercorp/service-base": { - "version": "8.5.73", - "resolved": "https://registry.npmjs.org/@bettercorp/service-base/-/service-base-8.5.73.tgz", - "integrity": "sha512-MHd8OE8av7T9sda9Z6ToKYYJumzO8o/sHvGZiRYTNQNRX5BSuohjdrXMHaGXhZmvjeJKRK8a2FQzK0dttW/GUA==", + "version": "8.5.63", + "resolved": "https://registry.npmjs.org/@bettercorp/service-base/-/service-base-8.5.63.tgz", + "integrity": "sha512-QtEfoi2g3BhSnLBE9Ms5S9AX6bpj/b+MA0sYtEB6tQ893+TF9B0Ixe4EQjEePcAv9IIs4COYvDoMQ7sTh6QH8w==", "license": "AGPL-3.0-only", "dependencies": { - "uuid": "^10.0.0", - "yaml": "^2.5.0", - "zod": "^3.23.8" + "@bettercorp/tools": "^3.7.0", + "yaml": "^2.3.4", + "yargs": "^17.7.2", + "zod": "^3.22.4" }, "bin": { "bsb": "lib/cli.js" }, "engines": { - "node": ">=20.0.0", - "npm": ">=10.0.0" + "node": ">=18.0.0", + "npm": ">=9.0.0" + } + }, + "node_modules/@bettercorp/service-base/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@bettercorp/service-base/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "license": "MIT", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@bettercorp/service-base/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "license": "ISC", + "engines": { + "node": ">=12" } }, "node_modules/@bettercorp/tools": { @@ -1199,7 +1241,6 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -1209,7 +1250,6 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, "license": "MIT", "dependencies": { "color-convert": "^2.0.1" @@ -1554,7 +1594,6 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, "license": "MIT", "dependencies": { "color-name": "~1.1.4" @@ -1567,7 +1606,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true, "license": "MIT" }, "node_modules/combined-stream": { @@ -1742,7 +1780,6 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true, "license": "MIT" }, "node_modules/es6-error": { @@ -1756,7 +1793,6 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -2222,7 +2258,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "dev": true, "license": "ISC", "engines": { "node": "6.* || 8.* || >= 10.*" @@ -2493,7 +2528,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -3679,7 +3713,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -3930,7 +3963,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "license": "MIT", "dependencies": { "emoji-regex": "^8.0.0", @@ -3945,7 +3977,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, "license": "MIT", "dependencies": { "ansi-regex": "^5.0.1" @@ -4246,19 +4277,6 @@ "punycode": "^2.1.0" } }, - "node_modules/uuid": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", - "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "license": "MIT", - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", @@ -4310,7 +4328,6 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^4.0.0", @@ -4348,7 +4365,6 @@ "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "dev": true, "license": "ISC", "engines": { "node": ">=10" diff --git a/src/plugins/service-iq-enterprise/client.ts b/src/plugins/service-iq-enterprise/client.ts index 1a93525..60c8bb6 100644 --- a/src/plugins/service-iq-enterprise/client.ts +++ b/src/plugins/service-iq-enterprise/client.ts @@ -244,6 +244,22 @@ export class IQEnterprise< ); } + public async getApplication( + uid: string, + hostname?: string, + username?: string, + password?: string, + ): Promise> { + return await this.events.emitEventAndReturn( + "getApplication", + 30, + uid, + hostname ?? this.customConfig.hostname, + username ?? this.customConfig.username, + password ?? this.customConfig.password, + ); + } + public async getServiceUsageBySubAccount( subAccountId: string, month: number, diff --git a/src/plugins/service-iq-enterprise/plugin.ts b/src/plugins/service-iq-enterprise/plugin.ts index c7702d8..d07f976 100755 --- a/src/plugins/service-iq-enterprise/plugin.ts +++ b/src/plugins/service-iq-enterprise/plugin.ts @@ -102,6 +102,12 @@ export interface Events username?: string, password?: string, ): Promise>>; + getApplication( + uid: string, + hostname?: string, + username?: string, + password?: string, + ): Promise>; updateApplication( applicationId: number, data: NewAPIApplication, @@ -496,14 +502,14 @@ export class Plugin password?: string, ) => { const axios: Axios = await this.getAxios(hostname, username, password); - const resp = await axios.get>>( + const resp = await axios.get & {portalmeta?: string}>>( `/api/portal/application/${encodeURIComponent(email)}`, ); if (resp.status == 200 && resp.data) { - return resp.data.map((d: any) => { + return resp.data.map((d) => { d.meta = Tools.isString(d.portalmeta) - ? JSON.parse(d.portalmeta) - : null; + ? JSON.parse(d.portalmeta) + : null; delete d.portalmeta; return d; }); @@ -513,6 +519,31 @@ export class Plugin ); }, ); + await this.events.onReturnableEvent( + "getApplication", + async ( + uid: string, + hostname?: string, + username?: string, + password?: string, + ) => { + const axios: Axios = await this.getAxios(hostname, username, password); + const resp = await axios.get & {portalmeta?: string}>( + `/api/portal/application/id/${encodeURIComponent(uid)}`, + ); + if (resp.status == 200 && resp.data) { + let d = resp.data; + d.meta = Tools.isString(d.portalmeta) + ? JSON.parse(d.portalmeta) + : null; + delete d.portalmeta; + return d; + } + throw new Error( + `Error ${resp.status}: ${resp.statusText} [${resp.data}]`, + ); + }, + ); await this.events.onReturnableEvent( "getServiceUsageByAccount", async ( @@ -535,8 +566,8 @@ export class Plugin `/api/portal/usage/${encodeURIComponent( id, )}?${Object.keys(query) - .map(x => `${x}=${encodeURIComponent(query[x])}`) - .join("&")}`, + .map(x => `${x}=${encodeURIComponent(query[x])}`) + .join("&")}`, ); if (resp.status == 200) { return resp.data; @@ -560,7 +591,7 @@ export class Plugin if (resp.status == 200 && Tools.isString(resp.data.status)) { const result = resp.data.status.toLowerCase(); if (Object.keys(UpgradeDowngradeStatusTypes) - .indexOf(result) !== -1) { + .indexOf(result) !== -1) { let dateAsEpoc = null; if (Tools.isString(resp.data.eta)) { const timeStr = "00:00:00"; @@ -771,7 +802,7 @@ export class Plugin ): Promise { const now = new Date().getTime(); if (cleanup) { - for (let i = 0 ; i < this._axios.length ; i++) { + for (let i = 0; i < this._axios.length; i++) { if (this._axios[i].hostname !== hostname) { continue; } @@ -781,7 +812,7 @@ export class Plugin this._axios.splice(i, 1); } } - for (let i = 0 ; i < this._axios.length ; i++) { + for (let i = 0; i < this._axios.length; i++) { if (this._axios[i].hostname !== hostname) { continue; } @@ -821,7 +852,7 @@ export class Plugin instance.defaults.headers.common[ "Authorization" ] = `Bearer ${await self.getToken(instance, username, password)}`; - for (let i = 0 ; i < self._axios.length ; i++) { + for (let i = 0; i < self._axios.length; i++) { if (self._axios[i].hostname !== hostname) { continue; } @@ -833,8 +864,7 @@ export class Plugin } return instance(config); - } - catch (e: any) { + } catch (e: any) { self.log.error(e.message ?? e, {}); } // Do something with response error