Skip to content

Commit 93557c7

Browse files
Add type annotations
1 parent 9338f9d commit 93557c7

13 files changed

Lines changed: 57 additions & 56 deletions

src/Client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ export class Client {
737737
return this.keyUtils.load_keypair(Buffer.from(value).toString().trim());
738738
}
739739

740-
private getEcKeyByConfig(envConfig: object) {
740+
private getEcKeyByConfig(envConfig: Record<string, any>) {
741741
const privateKeyPath = envConfig['PrivateKeyPath'].toString().replace('"', '');
742742
const keyHex = envConfig['PrivateKey'].toString().replace('"', '');
743743

src/Client/BillClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { BitPayClient } from './BitPayClient';
2-
import { TokenContainer } from '../TokenContainer';
3-
import { BillInterface } from '../Model';
4-
import { Facade } from '../Facade';
51
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
2+
import { Facade } from '../Facade';
3+
import { BillInterface } from '../Model';
4+
import { TokenContainer } from '../TokenContainer';
5+
import { BitPayClient } from './BitPayClient';
66

77
export class BillClient {
88
private bitPayClient: BitPayClient;
@@ -66,7 +66,7 @@ export class BillClient {
6666
* @throws BitPayApiException BitPayApiException
6767
*/
6868
public async getBills(status: string | null): Promise<BillInterface[]> {
69-
const params = { token: this.tokenContainer.getToken(Facade.Merchant) };
69+
const params: { token: string; status?: string } = { token: this.tokenContainer.getToken(Facade.Merchant) };
7070
if (status) {
7171
params['status'] = status;
7272
}

src/Client/InvoiceClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class InvoiceClient {
9595
* @throws BitPayApiException BitPayApiException class
9696
* @throws BitPayGenericException BitPayGenericException class
9797
*/
98-
public async getInvoices(params: object): Promise<InvoiceInterface[]> {
98+
public async getInvoices(params: { [key: string]: any }): Promise<InvoiceInterface[]> {
9999
params['token'] = this.tokenContainer.getToken(Facade.Merchant);
100100

101101
const result = await this.bitPayClient.get('invoices', params, true);
@@ -114,8 +114,9 @@ export class InvoiceClient {
114114
* @returns
115115
*/
116116
public async getInvoiceEventToken(invoiceId: string): Promise<InvoiceEventTokenInterface> {
117-
const params = {};
118-
params['token'] = this.tokenContainer.getToken(Facade.Merchant);
117+
const params = {
118+
token: this.tokenContainer.getToken(Facade.Merchant)
119+
};
119120

120121
const result = await this.bitPayClient.get('invoices/' + invoiceId + '/events', params, true);
121122

@@ -136,7 +137,7 @@ export class InvoiceClient {
136137
* @throws BitPayApiException BitPayApiException class
137138
* @throws BitPayGenericException BitPayGenericException class
138139
*/
139-
public async update(invoiceId: string, params: object): Promise<InvoiceInterface> {
140+
public async update(invoiceId: string, params: { [key: string]: any }): Promise<InvoiceInterface> {
140141
params['token'] = this.tokenContainer.getToken(Facade.Merchant);
141142

142143
const result = await this.bitPayClient.put('invoices/' + invoiceId, params);

src/Client/LedgerClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { BitPayClient } from './BitPayClient';
2-
import { TokenContainer } from '../TokenContainer';
3-
import { LedgerEntryInterface, LedgerInterface } from '../Model';
4-
import { Facade } from '../Facade';
51
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
2+
import { Facade } from '../Facade';
3+
import { LedgerEntryInterface, LedgerInterface } from '../Model';
4+
import { TokenContainer } from '../TokenContainer';
5+
import { BitPayClient } from './BitPayClient';
66

77
export class LedgerClient {
88
private bitPayClient: BitPayClient;
@@ -41,7 +41,7 @@ export class LedgerClient {
4141
* @throws BitPayApiException BitPayApiException class
4242
* @throws BitPayGenericException BitPayGenericException class
4343
*/
44-
public async getEntries(currency: string, params: object): Promise<LedgerEntryInterface[]> {
44+
public async getEntries(currency: string, params: { [key: string]: any }): Promise<LedgerEntryInterface[]> {
4545
params['token'] = this.tokenContainer.getToken(Facade.Merchant);
4646

4747
const result = await this.bitPayClient.get('ledgers/' + currency, params, true);

src/Client/PayoutClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { BitPayClient } from './BitPayClient';
2-
import { TokenContainer } from '../TokenContainer';
3-
import { GuidGenerator } from '../util/GuidGenerator';
1+
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
42
import { Facade } from '../Facade';
53
import { PayoutInterface } from '../Model';
4+
import { TokenContainer } from '../TokenContainer';
65
import { BitPayResponseParser } from '../util/BitPayResponseParser';
7-
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
6+
import { GuidGenerator } from '../util/GuidGenerator';
7+
import { BitPayClient } from './BitPayClient';
88

99
export class PayoutClient {
1010
private bitPayClient: BitPayClient;
@@ -63,7 +63,7 @@ export class PayoutClient {
6363
* @returns Payout[]
6464
* @throws PayoutQueryException
6565
*/
66-
public async getPayouts(params: object): Promise<PayoutInterface[]> {
66+
public async getPayouts(params: { [key: string]: any }): Promise<PayoutInterface[]> {
6767
params['token'] = this.tokenContainer.getToken(Facade.Payout);
6868
const result = await this.bitPayClient.get('payouts', params, true);
6969

src/Client/PayoutRecipientClient.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { BitPayClient } from './BitPayClient';
2-
import { TokenContainer } from '../TokenContainer';
3-
import { GuidGenerator } from '../util/GuidGenerator';
4-
import { PayoutRecipientInterface, PayoutRecipients } from '../Model';
5-
import { BitPayResponseParser } from '../util/BitPayResponseParser';
61
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
72
import { Facade } from '../index';
3+
import { PayoutRecipientInterface, PayoutRecipients } from '../Model';
4+
import { TokenContainer } from '../TokenContainer';
5+
import { BitPayResponseParser } from '../util/BitPayResponseParser';
6+
import { GuidGenerator } from '../util/GuidGenerator';
7+
import { BitPayClient } from './BitPayClient';
88

99
export class PayoutRecipientClient {
1010
private bitPayClient: BitPayClient;
@@ -90,7 +90,7 @@ export class PayoutRecipientClient {
9090
* @throws BitPayApiException BitPayApiException class
9191
* @throws BitPayGenericException BitPayGenericException class
9292
*/
93-
public async getByFilters(params: object): Promise<PayoutRecipientInterface[]> {
93+
public async getByFilters(params: { [key: string]: any }): Promise<PayoutRecipientInterface[]> {
9494
params['token'] = this.tokenContainer.getToken(Facade.Payout);
9595

9696
const result = await this.bitPayClient.get('recipients', params, true);

src/Client/RefundClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export class RefundClient {
3333
currency: refund.currency,
3434
preview: refund.preview,
3535
immediate: refund.immediate,
36-
buyerPaysRefundFee: refund.buyerPaysRefundFee
36+
buyerPaysRefundFee: refund.buyerPaysRefundFee,
37+
guid: refund.guid ? refund.guid : this.guidGenerator.execute()
3738
};
38-
params['guid'] = refund.guid ? refund.guid : this.guidGenerator.execute();
3939

4040
ParamsRemover.removeNullValuesFromObject(params);
4141

src/Client/SettlementClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { BitPayClient } from './BitPayClient';
2-
import { TokenContainer } from '../TokenContainer';
1+
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
32
import { SettlementInterface } from '../Model/Settlement/Settlement';
3+
import { TokenContainer } from '../TokenContainer';
44
import { Facade } from '../index';
5-
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
5+
import { BitPayClient } from './BitPayClient';
66

77
export class SettlementClient {
88
private bitPayClient: BitPayClient;
@@ -41,7 +41,7 @@ export class SettlementClient {
4141
* @throws BitPayApiException BitPayApiException class
4242
* @throws BitPayGenericException BitPayGenericException class
4343
*/
44-
public async getSettlements(params: object): Promise<SettlementInterface[]> {
44+
public async getSettlements(params: { [key: string]: any }): Promise<SettlementInterface[]> {
4545
params['token'] = this.tokenContainer.getToken(Facade.Merchant);
4646

4747
const result = await this.bitPayClient.get('settlements', params, true);

src/Currency.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class Currency {
179179
static ZMW = 'ZMW';
180180
static ZWL = 'ZWL';
181181

182-
static isValid(value) {
182+
static isValid(value: string) {
183183
try {
184184
return this.hasOwnProperty.call(this, value);
185185
} catch (ex) {

src/setup/BitPaySetup.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import { ec } from 'elliptic';
12
import * as fs from 'fs';
2-
import * as BitPaySDK from '../index';
33
import * as readline from 'readline';
4+
import * as BitPaySDK from '../index';
45

56
const keyUtils = new BitPaySDK.KeyUtils();
67
let configFilePath = process.cwd();
7-
let keyPair;
8-
let ecKey;
9-
let environment;
8+
let keyPair: ec.KeyPair;
9+
let ecKey: ec.KeyPair;
10+
let environment: string;
1011
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1112
let storeFile = true;
12-
let apiUrl;
13-
let merchantToken;
14-
let merchantPairCode;
15-
let payoutToken;
16-
let payoutPairCode;
13+
let apiUrl: string;
14+
let merchantToken: string;
15+
let merchantPairCode: string;
16+
let payoutToken: string;
17+
let payoutPairCode: string;
1718
let keyPath = '';
1819
let keyPlain = '';
1920

@@ -48,7 +49,7 @@ const selectEnv = async () => {
4849
console.log(e);
4950
}
5051
};
51-
const setEnv = async (env) => {
52+
const setEnv = async (env: string) => {
5253
if (env == 'Test') {
5354
apiUrl = 'https://test.bitpay.com';
5455
return;
@@ -84,7 +85,7 @@ const createNewKey = async () => {
8485
console.log(e);
8586
}
8687
};
87-
const loadKey = async (privateKey) => {
88+
const loadKey = async (privateKey: string) => {
8889
try {
8990
if (fs.existsSync(privateKey)) {
9091
console.log('Loading private key... \n');
@@ -205,11 +206,11 @@ const selectTokens = async () => {
205206
console.log(e);
206207
}
207208
};
208-
const requestTokens = async (option) => {
209+
const requestTokens = async (option: string) => {
209210
async function requestMerchantToken(options: {
210211
headers: { 'Content-type': string; 'x-accept-version': string };
211212
method: string;
212-
body: { id: string };
213+
body: { id: string; facade?: string };
213214
url: string;
214215
}) {
215216
console.log('Requesting Merchant token... \n');
@@ -237,7 +238,7 @@ const requestTokens = async (option) => {
237238
async function requestPayoutToken(options: {
238239
headers: { 'Content-type': string; 'x-accept-version': string };
239240
method: string;
240-
body: { id: string };
241+
body: { id: string; facade?: string };
241242
url: string;
242243
}) {
243244
console.log('Requesting Payout token... \n');
@@ -345,7 +346,7 @@ const updateConfigFile = async () => {
345346
process.exit();
346347
};
347348

348-
function sleep(ms) {
349+
function sleep(ms: number) {
349350
return new Promise((resolve) => {
350351
setTimeout(resolve, ms);
351352
});

0 commit comments

Comments
 (0)