Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/XeroClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,25 @@ export class XeroClient {
this.filesApi = new xero.FilesApi();
this.projectApi = new xero.ProjectApi();
this.payrollAUApi = new xero.PayrollAuApi();
this.payrollAUV2Api = new xero.PayrollAuV2Api();
this.bankFeedsApi = new xero.BankFeedsApi();
this.payrollUKApi = new xero.PayrollUkApi();
this.payrollNZApi = new xero.PayrollNzApi();
this.appStoreApi = new xero.AppStoreApi();
this.financeApi = new xero.FinanceApi();
this.apiClients = [
this.accountingApi,
this.assetApi,
this.filesApi,
this.projectApi,
this.payrollAUApi,
this.payrollAUV2Api,
this.bankFeedsApi,
this.payrollUKApi,
this.payrollNZApi,
this.appStoreApi,
this.financeApi,
];
};

private _tokenSet: TokenSet = new TokenSet;
Expand All @@ -74,11 +88,13 @@ export class XeroClient {
readonly filesApi: xero.FilesApi;
readonly projectApi: xero.ProjectApi;
readonly payrollAUApi: xero.PayrollAuApi;
readonly payrollAUV2Api: xero.PayrollAuV2Api;
readonly bankFeedsApi: xero.BankFeedsApi;
readonly payrollUKApi: xero.PayrollUkApi;
readonly payrollNZApi: xero.PayrollNzApi;
readonly appStoreApi: xero.AppStoreApi;
readonly financeApi: xero.FinanceApi;
private readonly apiClients: Array<{ accessToken: string }>;

openIdClient: Client; // from openid-client

Expand Down Expand Up @@ -273,15 +289,8 @@ export class XeroClient {
throw new Error('Access token is undefined!');
}

this.accountingApi.accessToken = accessToken;
this.assetApi.accessToken = accessToken;
this.filesApi.accessToken = accessToken;
this.projectApi.accessToken = accessToken;
this.payrollAUApi.accessToken = accessToken;
this.bankFeedsApi.accessToken = accessToken;
this.payrollUKApi.accessToken = accessToken;
this.payrollNZApi.accessToken = accessToken;
this.appStoreApi.accessToken = accessToken;
this.financeApi.accessToken = accessToken;
this.apiClients.forEach(apiClient => {
apiClient.accessToken = accessToken;
});
}
}
4 changes: 3 additions & 1 deletion src/gen/api/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './assetApi';
export * from './projectApi';
export * from './filesApi';
export * from './payrollAUApi';
export * from './payrollAUV2Api';
export * from './bankfeedsApi';
export * from './payrollUKApi';
export * from './payrollNZApi';
Expand All @@ -13,9 +14,10 @@ import { AssetApi } from './assetApi';
import { FilesApi } from './filesApi';
import { ProjectApi } from './projectApi';
import { PayrollAuApi } from './payrollAUApi';
import { PayrollAuV2Api } from './payrollAUV2Api';
import { BankFeedsApi } from './bankfeedsApi';
import { PayrollUkApi } from './payrollUKApi';
import { PayrollNzApi } from './payrollNZApi';
import { AppStoreApi } from './appStoreApi';
import { FinanceApi } from './financeApi';
export const APIS = [AccountingApi, AssetApi, FilesApi, ProjectApi, PayrollAuApi, BankFeedsApi, PayrollUkApi, PayrollNzApi, AppStoreApi, FinanceApi];
export const APIS = [AccountingApi, AssetApi, FilesApi, ProjectApi, PayrollAuApi, PayrollAuV2Api, BankFeedsApi, PayrollUkApi, PayrollNzApi, AppStoreApi, FinanceApi];
7 changes: 7 additions & 0 deletions src/test/xeroClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@ describe('the XeroClient', () => {
expect(xeroClient).toHaveProperty('bankFeedsApi')
expect(xeroClient).toHaveProperty('projectApi')
expect(xeroClient).toHaveProperty('payrollAUApi')
expect(xeroClient).toHaveProperty('payrollAUV2Api')
expect(xeroClient).toHaveProperty('payrollUKApi')
expect(xeroClient).toHaveProperty('payrollNZApi')
expect(xeroClient).toHaveProperty('appStoreApi')
});

it('propagates access tokens to Payroll AU v2', () => {
xero.setTokenSet(tokenSet)

expect((xero.payrollAUV2Api as any).authentications.OAuth2.accessToken).toEqual(tokenSet.access_token)
});

it('readTokenSet() returns the tokenSet', async () => {
const xeroTokenSet = await xero.readTokenSet()
expect(xeroTokenSet).toEqual(tokenSet)
Expand Down