diff --git a/package-lock.json b/package-lock.json index eb20901..ae9b5d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "whmcs-node", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b80fd1e..f41f4ef 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "name": "Niek van Gogh", "email": "niek@shockbyte.com", "url": "https://github.com/niekvangogh" - } + } ], "license": "ISC", "bugs": { diff --git a/src/index.ts b/src/index.ts index f4fe9dc..056bf85 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,26 +18,22 @@ import { WhmcsUsersService } from "./module/users"; export default class WhmcsApi { - public static options: WhmcsSetupOptions; + constructor(private readonly options: WhmcsSetupOptions) { } - 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 addons: WhmcsAddonsService = new WhmcsAddonsService(options); + public affiliates: WhmcsAffiliatesService = new WhmcsAffiliatesService(options); + public authentication: WhmcsAuthenticationService = new WhmcsAuthenticationService(options); + public billing: WhmcsBillingService = new WhmcsBillingService(options); + public client: WhmcsClientService = new WhmcsClientService(options); + public domains: WhmcsDomainsService = new WhmcsDomainsService(options); + public module: WhmcsModuleService = new WhmcsModuleService(options); + public orders: WhmcsOrdersService = new WhmcsOrdersService(options); + public products: WhmcsProductsService = new WhmcsProductsService(options); + public projectmanagement: WhmcsProjectManagementService = new WhmcsProjectManagementService(options); + public servers: WhmcsServersService = new WhmcsServersService(options); + public service: WhmcsServiceService = new WhmcsServiceService(options); + public support: WhmcsSupportService = new WhmcsSupportService(options); + public system: WhmcsSystemService = new WhmcsSystemService(options); + public tickets: WhmcsTicketsService = new WhmcsTicketsService(options); + public users: WhmcsUsersService = new WhmcsUsersService(options); } \ No newline at end of file diff --git a/src/module/base.ts b/src/module/base.ts index cc9cf2f..a7af732 100644 --- a/src/module/base.ts +++ b/src/module/base.ts @@ -1,16 +1,19 @@ import got from 'got'; import WhmcsApi from '..'; +import { WhmcsSetupOptions } from '../interface/whmcs.setup.options'; export abstract class BaseModule { - async request(methodName: string, options?: any): Promise { - options.identifier = WhmcsApi.options.identifier; - options.secret = WhmcsApi.options.secret; + constructor(private readonly options: WhmcsSetupOptions) { } + + protected async request(methodName: string, options?: any): Promise { + options.identifier = this.options.identifier; + options.secret = this.options.secret; options.action = methodName; options.responsetype = 'json'; return new Promise(async (resolve, reject) => { - const res = await got(WhmcsApi.options.apiUrl, { + const res = await got(this.options.apiUrl, { method: 'post', form: options }); diff --git a/src/module/billing.ts b/src/module/billing.ts index 2280948..c91bef3 100644 --- a/src/module/billing.ts +++ b/src/module/billing.ts @@ -26,7 +26,7 @@ import { UpdateTransactionRequest, UpdateTransactionResponse } from "../interfac export class WhmcsBillingService extends BaseModule { - public async acceptQuote(options: AcceptQuoteRequest): Promise { + public async acceptQuote(options: AcceptQuoteRequest): Promise { return this.request('AcceptQuote', options); } @@ -101,7 +101,7 @@ export class WhmcsBillingService extends BaseModule { public async getTransactions(options: GetTransactionsRequest): Promise { return this.request('GetTransactions', options); } - + public async sendQuote(options: SendQuoteRequest): Promise { return this.request('SendQuote', options); }