diff --git a/.gitignore b/.gitignore index 76add87..5deb29a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -dist \ No newline at end of file +dist +.idea/ \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index ae11814..65cd296 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,25 +15,31 @@ import { WhmcsSupportService } from "./module/support"; import { WhmcsSystemService } from "./module/system"; import { WhmcsTicketsService } from "./module/tickets"; import { WhmcsUsersService } from "./module/users"; +import { WhmcsClientCustom } from "./module/custom"; export default class WhmcsApi { constructor(private readonly options: WhmcsSetupOptions) { } - public addons: WhmcsAddonsService = new WhmcsAddonsService(this.options); - public affiliates: WhmcsAffiliatesService = new WhmcsAffiliatesService(this.options); - public authentication: WhmcsAuthenticationService = new WhmcsAuthenticationService(this.options); - public billing: WhmcsBillingService = new WhmcsBillingService(this.options); - public client: WhmcsClientService = new WhmcsClientService(this.options); - public domains: WhmcsDomainsService = new WhmcsDomainsService(this.options); - public module: WhmcsModuleService = new WhmcsModuleService(this.options); - public orders: WhmcsOrdersService = new WhmcsOrdersService(this.options); - public products: WhmcsProductsService = new WhmcsProductsService(this.options); - public projectmanagement: WhmcsProjectManagementService = new WhmcsProjectManagementService(this.options); - public servers: WhmcsServersService = new WhmcsServersService(this.options); - public service: WhmcsServiceService = new WhmcsServiceService(this.options); - public support: WhmcsSupportService = new WhmcsSupportService(this.options); - public system: WhmcsSystemService = new WhmcsSystemService(this.options); - public tickets: WhmcsTicketsService = new WhmcsTicketsService(this.options); - public users: WhmcsUsersService = new WhmcsUsersService(this.options); + constructor(options: WhmcsSetupOptions) { + WhmcsApi.options = options + } + + public addons: WhmcsAddonsService = new WhmcsAddonsService; + public affiliates: WhmcsAffiliatesService = new WhmcsAffiliatesService; + public authentication: WhmcsAuthenticationService = new WhmcsAuthenticationService; + public billing: WhmcsBillingService = new WhmcsBillingService; + public client: WhmcsClientService = new WhmcsClientService; + public domains: WhmcsDomainsService = new WhmcsDomainsService; + public module: WhmcsModuleService = new WhmcsModuleService; + public orders: WhmcsOrdersService = new WhmcsOrdersService; + public products: WhmcsProductsService = new WhmcsProductsService; + public projectmanagement: WhmcsProjectManagementService = new WhmcsProjectManagementService; + public servers: WhmcsServersService = new WhmcsServersService; + public service: WhmcsServiceService = new WhmcsServiceService; + public support: WhmcsSupportService = new WhmcsSupportService; + public system: WhmcsSystemService = new WhmcsSystemService; + public tickets: WhmcsTicketsService = new WhmcsTicketsService; + public users: WhmcsUsersService = new WhmcsUsersService; + public custom: WhmcsClientCustom = new WhmcsClientCustom; } \ No newline at end of file diff --git a/src/module/base.ts b/src/module/base.ts index 1371ee1..b45317f 100644 --- a/src/module/base.ts +++ b/src/module/base.ts @@ -1,25 +1,22 @@ -import got from 'got'; -import { WhmcsSetupOptions } from '../interface/whmcs.setup.options'; +import got from "got"; +import WhmcsApi from ".."; export abstract class BaseModule { - - constructor(private readonly options: WhmcsSetupOptions) { } - - protected async request(methodName: string, options?: any): Promise { - options.identifier = this.options.identifier; - options.secret = this.options.secret; + async request(methodName: string, options?: any): Promise { + options.identifier = WhmcsApi.options.identifier; + options.secret = WhmcsApi.options.secret; options.action = methodName; - options.responsetype = 'json'; + options.responsetype = "json"; return new Promise(async (resolve, reject) => { try { - const res = await got(this.options.apiUrl, { - method: 'post', - form: options + const res = await got(WhmcsApi.options.apiUrl, { + method: "post", + form: options, }); - + const data = JSON.parse(res.body); - + if (data.result != "success") return reject(data); resolve(data); } catch (error) { @@ -27,4 +24,4 @@ export abstract class BaseModule { } }); } -} \ No newline at end of file +} diff --git a/src/module/custom.ts b/src/module/custom.ts new file mode 100644 index 0000000..ca97114 --- /dev/null +++ b/src/module/custom.ts @@ -0,0 +1,7 @@ +import {BaseModule} from "./base"; + +export class WhmcsClientCustom extends BaseModule { + public async call(method: string, options: Record): Promise { + return this.request(method, options); + } +} \ No newline at end of file