diff --git a/src/XeroClient.ts b/src/XeroClient.ts index 100e1817..a90f5c4c 100644 --- a/src/XeroClient.ts +++ b/src/XeroClient.ts @@ -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; @@ -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 @@ -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; + }); } } diff --git a/src/gen/api/apis.ts b/src/gen/api/apis.ts index 459e0f40..6704aeb8 100644 --- a/src/gen/api/apis.ts +++ b/src/gen/api/apis.ts @@ -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'; @@ -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]; \ No newline at end of file +export const APIS = [AccountingApi, AssetApi, FilesApi, ProjectApi, PayrollAuApi, PayrollAuV2Api, BankFeedsApi, PayrollUkApi, PayrollNzApi, AppStoreApi, FinanceApi]; diff --git a/src/test/xeroClient.spec.ts b/src/test/xeroClient.spec.ts index 89a8cb4a..6ef25239 100644 --- a/src/test/xeroClient.spec.ts +++ b/src/test/xeroClient.spec.ts @@ -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)