import * as url from 'url'; export interface $FetchOptions { body?: string; headers?: $HttpHeaders; method?: $HttpMethod; } export type $FetchFunction = (url: string, options?: $FetchOptions) => Promise; export interface $HttpHeaders { [key: string]: string; } export type $HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'CONNECT' | 'OPTIONS' | 'TRACE'; export interface $HttpQuery { [key: string]: string | number | boolean | string[] | number[] | boolean[] | undefined | null; } export interface $HttpRequest { body?: any; url: string; headers: $HttpHeaders; method: $HttpMethod; } export interface $HttpRequestOptions { body?: any; endpoint: string; headers?: $HttpHeaders; method: $HttpMethod; query?: $HttpQuery; } export interface $HttpResponse { body: B; headers: $HttpHeaders; ok: O; request: $HttpRequest; status: S; statusText: string; } export type $HttpContinue = $HttpResponse; export type $HttpSwitchingProtocol = $HttpResponse; export type $HttpProcessing = $HttpResponse; export type $HttpOk = $HttpResponse; export type $HttpCreated = $HttpResponse; export type $HttpAccepted = $HttpResponse; export type $HttpNonAuthoritativeInformation = $HttpResponse; export type $HttpNoContent = $HttpResponse; export type $HttpResetContent = $HttpResponse; export type $HttpPartialContent = $HttpResponse; export type $HttpMultiStatus = $HttpResponse; export type $HttpAlreadyReported = $HttpResponse; export type $HttpImUsed = $HttpResponse; export type $HttpMultipleChoices = $HttpResponse; export type $HttpMovedPermanently = $HttpResponse; export type $HttpFound = $HttpResponse; export type $HttpSeeOther = $HttpResponse; export type $HttpNotModified = $HttpResponse; export type $HttpUseProxy = $HttpResponse; export type $HttpTemporaryRedirect = $HttpResponse; export type $HttpPermanentRedirect = $HttpResponse; export type $HttpBadRequest = $HttpResponse; export type $HttpUnauthorized = $HttpResponse; export type $HttpPaymentRequired = $HttpResponse; export type $HttpForbidden = $HttpResponse; export type $HttpNotFound = $HttpResponse; export type $HttpMethodNotAllowed = $HttpResponse; export type $HttpNotAcceptable = $HttpResponse; export type $HttpProxyAuthenticationRequired = $HttpResponse; export type $HttpRequestTimeout = $HttpResponse; export type $HttpConflict = $HttpResponse; export type $HttpGone = $HttpResponse; export type $HttpLengthRequired = $HttpResponse; export type $HttpPreconditionFailed = $HttpResponse; export type $HttpRequestEntityTooLarge = $HttpResponse; export type $HttpRequestUriTooLong = $HttpResponse; export type $HttpUnsupportedMediaType = $HttpResponse; export type $HttpRequestedRangeNotSatisfiable = $HttpResponse; export type $HttpExpectationFailed = $HttpResponse; export type $HttpMisdirectedRequest = $HttpResponse; export type $HttpUnprocessableEntity = $HttpResponse; export type $HttpLocked = $HttpResponse; export type $HttpFailedDependency = $HttpResponse; export type $HttpUpgradeRequired = $HttpResponse; export type $HttpPreconditionRequired = $HttpResponse; export type $HttpTooManyRequests = $HttpResponse; export type $HttpRequestHeaderFieldsTooLarge = $HttpResponse; export type $HttpNoResponse = $HttpResponse; export type $HttpRetryWith = $HttpResponse; export type $HttpBlockedByWindowsParentalControls = $HttpResponse; export type $HttpUnavailableForLegalReasons = $HttpResponse; export type $HttpClientClosedRequest = $HttpResponse; export type $HttpInternalServerError = $HttpResponse; export type $HttpNotImplemented = $HttpResponse; export type $HttpBadGateway = $HttpResponse; export type $HttpServiceUnavailable = $HttpResponse; export type $HttpGatewayTimeout = $HttpResponse; export type $HttpHttpVersionNotSupported = $HttpResponse; export type $HttpInsufficientStorage = $HttpResponse; export type $HttpLoopDetected = $HttpResponse; export type $HttpBandwidthLimitExceeded = $HttpResponse; export type $HttpNotExtended = $HttpResponse; export type $HttpNetworkAuthenticationRequired = $HttpResponse; export type $HttpNetworkReadTimeoutError = $HttpResponse; export type $HttpNetworkConnectTimeoutError = $HttpResponse; export interface $HttpClientOptions { fetch: $FetchFunction; } export function isResponseEmpty(response: Response): boolean { const contentLength = response.headers.get('Content-Length'); return response.status === 204 || contentLength != null && Number.parseInt(contentLength, 10) === 0; } export function isResponseJson(response: Response): boolean { const contentType = response.headers.get('Content-Type'); return contentType != null && contentType.indexOf('json') >= 0; } export function parseJson(response: Response): Promise { return !isResponseEmpty(response) && isResponseJson(response) ? response.json() : Promise.resolve(); } export function parseHeaders(response: Response): Record { const headers: Record = {}; response.headers.forEach((value, key) => { headers[key.toLowerCase()] = value; }); return headers; } export function stripQuery(query: $HttpQuery = {}): $HttpQuery { const initialValue: $HttpQuery = {}; return Object.keys(query).reduce((previousValue, key) => { const value = query[key]; if (value != null) previousValue[key] = value; return previousValue; }, initialValue); } export class $HttpClient { private options: $HttpClientOptions; constructor(options: $HttpClientOptions) { this.options = options; } public request(options: $HttpRequestOptions): Promise<$HttpResponse> { const finalUrl: string = url.format({ hostname: 'api.apibuilder.io', pathname: options.endpoint, protocol: 'https:', query: stripQuery(options.query), }); const finalHeaders: $HttpHeaders = { accept: 'application/json', 'content-type': 'application/json', ...options.headers, }; const request: $HttpRequest = { body: options.body, headers: finalHeaders, method: options.method, url: finalUrl, }; return this.options.fetch(request.url, { body: JSON.stringify(request.body), headers: request.headers, method: request.method, }).then((response) => { return parseJson(response).then((json) => { return { body: json, headers: parseHeaders(response), ok: response.ok, request, status: response.status, statusText: response.statusText, }; }); }); } } export class $Resource { protected client: $HttpClient; constructor(options: $HttpClientOptions) { this.client = new $HttpClient(options); } } export interface AccountsPostCreateParameters { headers?: $HttpHeaders; accountid: number; ownerid: string; total_amount: number; sold: number; debit: number; currency: string; } export interface AccountsPutUpdateByAccountidParameters { headers?: $HttpHeaders; accountid: number; ownerid: string; total_amount: number; currency: string; sold: number; debit: number; } export interface AccountsDeleteDeleteByAccountidParameters { headers?: $HttpHeaders; accountid: number; } export interface AccountsGetByAccountidParameters { headers?: $HttpHeaders; accountid: number; ownerid: string; total_amount: number; sold: number; debit: number; currency: string; } export interface AccountsGetListParameters { headers?: $HttpHeaders; accountid: number; ownerid: string; total_amount: number; currency: string; sold: number; debit: number; } export interface DepositsDeleteDeleteByDepidParameters { headers?: $HttpHeaders; depid: number; } export interface DepositsGetByDepidParameters { headers?: $HttpHeaders; depid: number; payment_method: string; actorid: string; ref_accountid: number; operatorid: string; amount: number; phone: number; pin: number; currency: string; payment_context: string; } export interface DepositsGetListParameters { headers?: $HttpHeaders; payid: number; payment_method: string; actorid: string; ref_accountid: number; operatorid: string; amount: number; phone: number; pin: number; currency: string; payment_context: string; } export interface PaymentsPostCreateParameters { headers?: $HttpHeaders; payid: number; payment_method: string; actorid: string; ref_accountid: number; operatorid: string; amount: number; currency: string; phone: number; pin: number; payment_context: string; } export interface PaymentsPutUpdateByPayidParameters { headers?: $HttpHeaders; payid: number; payment_method: string; actorid: string; ref_accountid: number; operatorid: string; amount: number; phone: number; pin: number; currency: string; payment_context: string; } export interface PaymentsDeleteDeleteByPayidParameters { headers?: $HttpHeaders; payid: number; } export interface PaymentsGetByPayidParameters { headers?: $HttpHeaders; payid: number; payment_method: string; actorid: string; ref_accountid: number; operatorid: string; amount: number; phone: number; pin: number; currency: string; payment_context: string; } export interface PaymentsGetByRefAccountidParameters { headers?: $HttpHeaders; ref_accountid: number; payid: number; payment_method: string; actorid: string; operatorid: string; amount: number; phone: number; pin: number; currency: string; payment_context: string; } export interface PaymentsGetListParameters { headers?: $HttpHeaders; payid: number; payment_method: string; actorid: string; ref_accountid: number; operatorid: string; amount: number; phone: number; pin: number; currency: string; payment_context: string; } export interface TransfersPostCreateParameters { headers?: $HttpHeaders; transferid: number; senderid: string; amount: number; currency: string; ref_accountid_receiver: number; ref_accountid_sender: number; } export interface TransfersPutUpdateByTransferidParameters { headers?: $HttpHeaders; transferid: number; senderid: string; amount: number; currency: string; ref_accountid_receiver: number; ref_accountid_sender: number; } export interface TransfersDeleteDeleteByTransferidParameters { headers?: $HttpHeaders; transferid: number; } export interface TransfersGetByTransferidParameters { headers?: $HttpHeaders; transferid: number; senderid: string; amount: number; currency: string; ref_accountid_receiver: number; ref_accountid_sender: number; } export interface TransfersGetListParameters { headers?: $HttpHeaders; transferid: number; senderid: string; amount: number; currency: string; ref_accountid_receiver: number; ref_accountid_sender: number; } export interface ValidationsPostParameters { body: string; headers?: $HttpHeaders; } export interface WithdrawsDeleteDeleteByWdwidParameters { headers?: $HttpHeaders; wdwid: number; } export interface WithdrawsGetByWdwidParameters { headers?: $HttpHeaders; wdwid: number; depid: number; payment_method: string; actorid: string; ref_accountid: number; operatorid: string; amount: number; phone: number; pin: number; currency: string; payment_context: string; } export interface WithdrawsGetListParameters { headers?: $HttpHeaders; payid: number; payment_method: string; actorid: string; ref_accountid: number; operatorid: string; amount: number; phone: number; pin: number; currency: string; payment_context: string; } export type AccountsPostCreateResponse = $HttpOk | $HttpConflict; export type AccountsPutUpdateByAccountidResponse = $HttpOk | $HttpConflict; export type AccountsDeleteDeleteByAccountidResponse = $HttpNoContent | $HttpUnauthorized | $HttpNotFound; export type AccountsGetByAccountidResponse = $HttpOk | $HttpNotFound; export type AccountsGetListResponse = $HttpOk | $HttpNotFound; export type DepositsDeleteDeleteByDepidResponse = $HttpNoContent | $HttpUnauthorized | $HttpNotFound; export type DepositsGetByDepidResponse = $HttpOk | $HttpNotFound; export type DepositsGetListResponse = $HttpOk | $HttpNotFound; export type PaymentsPostCreateResponse = $HttpOk | $HttpConflict; export type PaymentsPutUpdateByPayidResponse = $HttpOk | $HttpConflict; export type PaymentsDeleteDeleteByPayidResponse = $HttpNoContent | $HttpUnauthorized | $HttpNotFound; export type PaymentsGetByPayidResponse = $HttpOk | $HttpNotFound; export type PaymentsGetByRefAccountidResponse = $HttpOk | $HttpNotFound; export type PaymentsGetListResponse = $HttpOk | $HttpNotFound; export type TransfersPostCreateResponse = $HttpOk | $HttpConflict; export type TransfersPutUpdateByTransferidResponse = $HttpOk | $HttpConflict; export type TransfersDeleteDeleteByTransferidResponse = $HttpNoContent | $HttpUnauthorized | $HttpNotFound; export type TransfersGetByTransferidResponse = $HttpOk | $HttpNotFound; export type TransfersGetListResponse = $HttpOk | $HttpNotFound; export type ValidationsPostResponse = $HttpOk; export type WithdrawsDeleteDeleteByWdwidResponse = $HttpNoContent | $HttpUnauthorized | $HttpNotFound; export type WithdrawsGetByWdwidResponse = $HttpOk | $HttpNotFound; export type WithdrawsGetListResponse = $HttpOk | $HttpNotFound; export class AccountsResource extends $Resource { /*Used to create an account.*/ public postCreate(params: AccountsPostCreateParameters): Promise { return this.client.request({ endpoint: '/accounts/create', headers: params.headers, method: 'POST', }); } /*Used to update an account.*/ public putUpdateByAccountid(params: AccountsPutUpdateByAccountidParameters): Promise { return this.client.request({ endpoint: `/accounts/update/${encodeURIComponent(params.accountid)}`, headers: params.headers, method: 'PUT', }); } /*Delete some account.*/ public deleteDeleteByAccountid(params: AccountsDeleteDeleteByAccountidParameters): Promise { return this.client.request({ endpoint: `/accounts/delete/${encodeURIComponent(params.accountid)}`, headers: params.headers, method: 'DELETE', }); } /*Find account by its id*/ public getByAccountid(params: AccountsGetByAccountidParameters): Promise { return this.client.request({ endpoint: `/accounts/${encodeURIComponent(params.accountid)}`, headers: params.headers, method: 'GET', query: { currency: params.currency, debit: params.debit, ownerid: params.ownerid, sold: params.sold, total_amount: params.total_amount, }, }); } /*Find all the accounts.*/ public getList(params: AccountsGetListParameters): Promise { return this.client.request({ endpoint: '/accounts/list', headers: params.headers, method: 'GET', query: { accountid: params.accountid, currency: params.currency, debit: params.debit, ownerid: params.ownerid, sold: params.sold, total_amount: params.total_amount, }, }); } } export class DepositsResource extends $Resource { /*Delete some deposit.*/ public deleteDeleteByDepid(params: DepositsDeleteDeleteByDepidParameters): Promise { return this.client.request({ endpoint: `/deposits/delete/${encodeURIComponent(params.depid)}`, headers: params.headers, method: 'DELETE', }); } /*Find deposit by its id.*/ public getByDepid(params: DepositsGetByDepidParameters): Promise { return this.client.request({ endpoint: `/deposits/${encodeURIComponent(params.depid)}`, headers: params.headers, method: 'GET', query: { actorid: params.actorid, amount: params.amount, currency: params.currency, operatorid: params.operatorid, payment_context: params.payment_context, payment_method: params.payment_method, phone: params.phone, pin: params.pin, ref_accountid: params.ref_accountid, }, }); } /*List all the deposits*/ public getList(params: DepositsGetListParameters): Promise { return this.client.request({ endpoint: '/deposits/list', headers: params.headers, method: 'GET', query: { actorid: params.actorid, amount: params.amount, currency: params.currency, operatorid: params.operatorid, payid: params.payid, payment_context: params.payment_context, payment_method: params.payment_method, phone: params.phone, pin: params.pin, ref_accountid: params.ref_accountid, }, }); } } export class PaymentsResource extends $Resource { /*Used to create a payment.*/ public postCreate(params: PaymentsPostCreateParameters): Promise { return this.client.request({ endpoint: '/payments/create', headers: params.headers, method: 'POST', }); } /*Used to update a payment.*/ public putUpdateByPayid(params: PaymentsPutUpdateByPayidParameters): Promise { return this.client.request({ endpoint: `/payments/update/${encodeURIComponent(params.payid)}`, headers: params.headers, method: 'PUT', }); } /*Delete some payment.*/ public deleteDeleteByPayid(params: PaymentsDeleteDeleteByPayidParameters): Promise { return this.client.request({ endpoint: `/payments/delete/${encodeURIComponent(params.payid)}`, headers: params.headers, method: 'DELETE', }); } /*Find payment by its id.*/ public getByPayid(params: PaymentsGetByPayidParameters): Promise { return this.client.request({ endpoint: `/payments/${encodeURIComponent(params.payid)}`, headers: params.headers, method: 'GET', query: { actorid: params.actorid, amount: params.amount, currency: params.currency, operatorid: params.operatorid, payment_context: params.payment_context, payment_method: params.payment_method, phone: params.phone, pin: params.pin, ref_accountid: params.ref_accountid, }, }); } /*Find payment by id accountid*/ public getByRefAccountid(params: PaymentsGetByRefAccountidParameters): Promise { return this.client.request({ endpoint: `/payments/${encodeURIComponent(params.ref_accountid)}`, headers: params.headers, method: 'GET', query: { actorid: params.actorid, amount: params.amount, currency: params.currency, operatorid: params.operatorid, payid: params.payid, payment_context: params.payment_context, payment_method: params.payment_method, phone: params.phone, pin: params.pin, }, }); } /*List all the payments*/ public getList(params: PaymentsGetListParameters): Promise { return this.client.request({ endpoint: '/payments/list', headers: params.headers, method: 'GET', query: { actorid: params.actorid, amount: params.amount, currency: params.currency, operatorid: params.operatorid, payid: params.payid, payment_context: params.payment_context, payment_method: params.payment_method, phone: params.phone, pin: params.pin, ref_accountid: params.ref_accountid, }, }); } } export class TransfersResource extends $Resource { /*Used to create a transfer resource.*/ public postCreate(params: TransfersPostCreateParameters): Promise { return this.client.request({ endpoint: '/transfers/create', headers: params.headers, method: 'POST', }); } /*Used to update a transfer resource.*/ public putUpdateByTransferid(params: TransfersPutUpdateByTransferidParameters): Promise { return this.client.request({ endpoint: `/transfers/update/${encodeURIComponent(params.transferid)}`, headers: params.headers, method: 'PUT', }); } /*Delete some transfer.*/ public deleteDeleteByTransferid(params: TransfersDeleteDeleteByTransferidParameters): Promise { return this.client.request({ endpoint: `/transfers/delete/${encodeURIComponent(params.transferid)}`, headers: params.headers, method: 'DELETE', }); } /*Find transfer by its id*/ public getByTransferid(params: TransfersGetByTransferidParameters): Promise { return this.client.request({ endpoint: `/transfers/${encodeURIComponent(params.transferid)}`, headers: params.headers, method: 'GET', query: { amount: params.amount, currency: params.currency, ref_accountid_receiver: params.ref_accountid_receiver, ref_accountid_sender: params.ref_accountid_sender, senderid: params.senderid, }, }); } /*Find all the transfers.*/ public getList(params: TransfersGetListParameters): Promise { return this.client.request({ endpoint: '/transfers/list', headers: params.headers, method: 'GET', query: { amount: params.amount, currency: params.currency, ref_accountid_receiver: params.ref_accountid_receiver, ref_accountid_sender: params.ref_accountid_sender, senderid: params.senderid, transferid: params.transferid, }, }); } } export class ValidationsResource extends $Resource { public post(params: ValidationsPostParameters): Promise { return this.client.request({ body: params.body, endpoint: '/validations', headers: params.headers, method: 'POST', }); } } export class WithdrawsResource extends $Resource { /*Delete some withdraw.*/ public deleteDeleteByWdwid(params: WithdrawsDeleteDeleteByWdwidParameters): Promise { return this.client.request({ endpoint: `/withdraws/delete/${encodeURIComponent(params.wdwid)}`, headers: params.headers, method: 'DELETE', }); } /*Find withdraw by its id.*/ public getByWdwid(params: WithdrawsGetByWdwidParameters): Promise { return this.client.request({ endpoint: `/withdraws/${encodeURIComponent(params.wdwid)}`, headers: params.headers, method: 'GET', query: { actorid: params.actorid, amount: params.amount, currency: params.currency, depid: params.depid, operatorid: params.operatorid, payment_context: params.payment_context, payment_method: params.payment_method, phone: params.phone, pin: params.pin, ref_accountid: params.ref_accountid, }, }); } /*List all the withdraws*/ public getList(params: WithdrawsGetListParameters): Promise { return this.client.request({ endpoint: '/withdraws/list', headers: params.headers, method: 'GET', query: { actorid: params.actorid, amount: params.amount, currency: params.currency, operatorid: params.operatorid, payid: params.payid, payment_context: params.payment_context, payment_method: params.payment_method, phone: params.phone, pin: params.pin, ref_accountid: params.ref_accountid, }, }); } } export interface ClientInstance { accounts: AccountsResource; deposits: DepositsResource; payments: PaymentsResource; transfers: TransfersResource; validations: ValidationsResource; withdraws: WithdrawsResource; } export function createClient(options: $HttpClientOptions): ClientInstance { return { accounts: new AccountsResource(options), deposits: new DepositsResource(options), payments: new PaymentsResource(options), transfers: new TransfersResource(options), validations: new ValidationsResource(options), withdraws: new WithdrawsResource(options), }; }