xero-node
Advanced tools
Comparing version 3.0.0-alpha.5 to 3.0.0-alpha.6
@@ -129,3 +129,3 @@ "use strict"; | ||
updateRequestBody = invoiceIdsToArchive.map(function (invoiceId) { return ({ InvoiceID: invoiceId, Status: 'DELETED' }); }); | ||
return [4 /*yield*/, xero.invoices.update(updateRequestBody)]; | ||
return [4 /*yield*/, xero.invoices.update({ Invoices: updateRequestBody })]; | ||
case 1: | ||
@@ -132,0 +132,0 @@ _a.sent(); |
@@ -43,3 +43,3 @@ "use strict"; | ||
var xero; | ||
var response; | ||
var existingId; | ||
beforeAll(function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -49,3 +49,3 @@ var config; | ||
integration_helpers_1.setJestTimeout(); | ||
config = integration_helpers_1.getPrivateConfig(); | ||
config = integration_helpers_1.getPrivateConfig('1'); | ||
xero = new AccountingAPIClient_1.AccountingAPIClient(config); | ||
@@ -56,10 +56,10 @@ return [2 /*return*/]; | ||
it('can get all', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
expect.assertions(1); | ||
return [4 /*yield*/, xero.brandingThemes.get()]; | ||
case 0: return [4 /*yield*/, xero.brandingThemes.get()]; | ||
case 1: | ||
response = _a.sent(); | ||
expect(response.BrandingThemes[0].Name).toBeDefined(); | ||
existingId = response.BrandingThemes[0].BrandingThemeID; | ||
return [2 /*return*/]; | ||
@@ -73,5 +73,3 @@ } | ||
switch (_a.label) { | ||
case 0: | ||
expect.assertions(1); | ||
return [4 /*yield*/, xero.brandingThemes.get({ BrandingThemeID: response.BrandingThemes[0].BrandingThemeID })]; | ||
case 0: return [4 /*yield*/, xero.brandingThemes.get({ BrandingThemeID: existingId })]; | ||
case 1: | ||
@@ -78,0 +76,0 @@ newResponse = _a.sent(); |
@@ -125,8 +125,13 @@ "use strict"; | ||
afterAll(function () { return __awaiter(_this, void 0, void 0, function () { | ||
var employeeToUpdate; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, xero.employees.update(employeeIdsToArchive.map(function (employeeId) { return ({ | ||
case 0: | ||
employeeToUpdate = employeeIdsToArchive.map(function (employeeId) { return ({ | ||
EmployeeID: employeeId, | ||
Status: 'ARCHIVED' | ||
}); }))]; | ||
}); }); | ||
return [4 /*yield*/, xero.employees.update({ | ||
Employees: employeeToUpdate | ||
})]; | ||
case 1: | ||
@@ -133,0 +138,0 @@ _a.sent(); |
@@ -123,8 +123,13 @@ "use strict"; | ||
afterAll(function () { return __awaiter(_this, void 0, void 0, function () { | ||
var expenseClaimsToUpdate; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, xero.expenseclaims.update(idsToArchive.map(function (id) { return ({ | ||
case 0: | ||
expenseClaimsToUpdate = idsToArchive.map(function (id) { return ({ | ||
ExpenseClaimID: id, | ||
Status: 'VOIDED' | ||
}); }))]; | ||
}); }); | ||
return [4 /*yield*/, xero.expenseclaims.update({ | ||
ExpenseClaims: expenseClaimsToUpdate | ||
})]; | ||
case 1: | ||
@@ -131,0 +136,0 @@ _a.sent(); |
import { AccountingAPIClient } from '../../AccountingAPIClient'; | ||
export declare function getOrCreateInvoiceId(xero: AccountingAPIClient): Promise<string>; | ||
export declare function getOrCreateAccountId(xero: AccountingAPIClient, args?: any): Promise<string>; | ||
@@ -10,1 +9,4 @@ export declare function getOrCreateBankTransferId(xero: AccountingAPIClient): Promise<string>; | ||
export declare function getOrCreateExpenseClaimId(xero: AccountingAPIClient): Promise<string>; | ||
export declare function getOrCreateInvoiceId(xero: AccountingAPIClient): Promise<string>; | ||
export declare function getOrCreateItemId(xero: AccountingAPIClient): Promise<string>; | ||
export declare function getOrCreatePaymentId(xero: AccountingAPIClient): Promise<string>; |
@@ -40,26 +40,2 @@ "use strict"; | ||
var inMemoryCache = {}; | ||
function getOrCreateInvoiceId(xero) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!!inMemoryCache.invoiceId) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, xero.invoices.get()]; | ||
case 1: | ||
response = _a.sent(); | ||
if (!(response.Invoices.length <= 0)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, xero.invoices.create(invoice_request_examples_1.createSingleInvoiceRequest)]; | ||
case 2: | ||
response = _a.sent(); | ||
_a.label = 3; | ||
case 3: | ||
inMemoryCache.invoiceId = response.Invoices[0].InvoiceID; | ||
_a.label = 4; | ||
case 4: return [2 /*return*/, inMemoryCache.invoiceId]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.getOrCreateInvoiceId = getOrCreateInvoiceId; | ||
function getOrCreateAccountId(xero, args) { | ||
@@ -254,1 +230,83 @@ return __awaiter(this, void 0, void 0, function () { | ||
exports.getOrCreateExpenseClaimId = getOrCreateExpenseClaimId; | ||
function getOrCreateInvoiceId(xero) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!!inMemoryCache.invoiceId) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, xero.invoices.get()]; | ||
case 1: | ||
response = _a.sent(); | ||
if (!(response.Invoices.length <= 0)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, xero.invoices.create(invoice_request_examples_1.createSingleInvoiceRequest)]; | ||
case 2: | ||
response = _a.sent(); | ||
_a.label = 3; | ||
case 3: | ||
inMemoryCache.invoiceId = response.Invoices[0].InvoiceID; | ||
_a.label = 4; | ||
case 4: return [2 /*return*/, inMemoryCache.invoiceId]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.getOrCreateInvoiceId = getOrCreateInvoiceId; | ||
function getOrCreateItemId(xero) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!!inMemoryCache.itemId) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, xero.items.get()]; | ||
case 1: | ||
response = _a.sent(); | ||
if (!(response.Items.length <= 0)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, xero.items.create({ Code: 'Item-1' })]; | ||
case 2: | ||
response = _a.sent(); | ||
_a.label = 3; | ||
case 3: | ||
inMemoryCache.itemId = response.Items[0].ItemID; | ||
_a.label = 4; | ||
case 4: return [2 /*return*/, inMemoryCache.itemId]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.getOrCreateItemId = getOrCreateItemId; | ||
function getOrCreatePaymentId(xero) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, _a, _b, _c, _d, _e; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
case 0: | ||
if (!!inMemoryCache.paymentId) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, xero.payments.get()]; | ||
case 1: | ||
response = _f.sent(); | ||
if (!(response.Payments.length <= 0)) return [3 /*break*/, 5]; | ||
_b = (_a = xero.payments).create; | ||
_c = {}; | ||
_d = {}; | ||
return [4 /*yield*/, getOrCreateInvoiceId(xero)]; | ||
case 2: | ||
_c.Invoice = (_d.InvoiceID = _f.sent(), _d); | ||
_e = {}; | ||
return [4 /*yield*/, getOrCreateAccountId(xero)]; | ||
case 3: return [4 /*yield*/, _b.apply(_a, [(_c.Account = (_e.AccountID = _f.sent(), _e), | ||
_c.Amount = 123, | ||
_c)])]; | ||
case 4: | ||
response = _f.sent(); | ||
_f.label = 5; | ||
case 5: | ||
inMemoryCache.paymentId = response.Payments[0].PaymentID; | ||
_f.label = 6; | ||
case 6: return [2 /*return*/, inMemoryCache.paymentId]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.getOrCreatePaymentId = getOrCreatePaymentId; |
@@ -0,5 +1,6 @@ | ||
import { IXeroClientConfiguration } from '../../internals/BaseAPIClient'; | ||
export declare function readLine(stringPrompt: string): Promise<string>; | ||
export declare function getPrivateConfig(): any; | ||
export declare function getPrivateConfig(testPartition?: string): IXeroClientConfiguration; | ||
export declare function getLoginConfig(): any; | ||
export declare function getPartnerAppConfig(): any; | ||
export declare function setJestTimeout(): void; |
@@ -53,5 +53,5 @@ "use strict"; | ||
exports.readLine = readLine; | ||
function getPrivateConfig() { | ||
function getPrivateConfig(testPartition) { | ||
if (!process.env.CI) { | ||
var config = require('../private-config.json'); | ||
var config = require("../" + (testPartition || '') + "private-config.json"); | ||
return config; | ||
@@ -62,4 +62,4 @@ } | ||
appType: 'private', | ||
consumerKey: process.env.ConsumerKey, | ||
consumerSecret: process.env.ConsumerSecret, | ||
consumerKey: process.env['PrivateConsumerKey' + (testPartition || '')], | ||
consumerSecret: process.env['PrivateConsumerKey' + (testPartition || '')], | ||
callbackUrl: null, | ||
@@ -66,0 +66,0 @@ privateKeyPath: path.resolve(__dirname, '.', 'privatekey.pem') |
@@ -61,3 +61,3 @@ "use strict"; | ||
integration_helpers_1.setJestTimeout(); | ||
config = integration_helpers_1.getPrivateConfig(); | ||
config = integration_helpers_1.getPrivateConfig('1'); | ||
xero = new AccountingAPIClient_1.AccountingAPIClient(config); | ||
@@ -174,3 +174,3 @@ return [2 /*return*/]; | ||
updateRequestBody = invoiceIdsToArchive.map(function (invoiceId) { return ({ InvoiceID: invoiceId, Status: 'DELETED' }); }); | ||
return [4 /*yield*/, xero.invoices.update(updateRequestBody)]; | ||
return [4 /*yield*/, xero.invoices.update({ Invoices: updateRequestBody })]; | ||
case 1: | ||
@@ -177,0 +177,0 @@ _a.sent(); |
@@ -55,2 +55,4 @@ "use strict"; | ||
var authUrl; | ||
var requestToken; | ||
var authState; | ||
var page; | ||
@@ -62,6 +64,6 @@ var oauth_verifier; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.getUnauthorisedRequestToken()]; | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.getRequestToken()]; | ||
case 1: | ||
_a.sent(); | ||
authUrl = accounting1.oauth1Client.buildAuthoriseUrl(); | ||
requestToken = _a.sent(); | ||
authUrl = accounting1.oauth1Client.buildAuthoriseUrl(requestToken); | ||
return [4 /*yield*/, puppeteer.launch({ | ||
@@ -134,5 +136,5 @@ headless: true, | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.swapRequestTokenforAccessToken(oauth_verifier)]; | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.swapRequestTokenforAccessToken(requestToken, oauth_verifier)]; | ||
case 1: | ||
_a.sent(); | ||
authState = _a.sent(); | ||
return [4 /*yield*/, accounting1.organisation.get()]; | ||
@@ -162,18 +164,12 @@ case 2: | ||
describe('OAuth State', function () { | ||
var state; | ||
var accounting2_callback; | ||
it('it allows you to keep copy of the state in your own dadtastore', function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.getState()]; | ||
case 1: | ||
// Saves your state to your datastore | ||
state = _a.sent(); | ||
expect(state.accessToken).not.toBeNull(); | ||
expect(state.oauth_session_handle).not.toBeNull(); | ||
expect(state.requestToken).not.toBeNull(); | ||
// This is how you can check when you have to refresh your Access Token | ||
expect(typeof state.oauth_expires_at.getDate).toBe('function'); | ||
return [2 /*return*/]; | ||
} | ||
// Saves your state to your datastore | ||
expect(authState).not.toBeNull(); | ||
expect(authState.oauth_session_handle).not.toBeNull(); | ||
expect(requestToken).not.toBeNull(); | ||
// This is how you can check when you have to refresh your Access Token | ||
expect(typeof authState.oauth_expires_at.getDate).toBe('function'); | ||
return [2 /*return*/]; | ||
}); | ||
@@ -183,6 +179,3 @@ }); }); | ||
return __generator(this, function (_a) { | ||
accounting2_callback = new AccountingAPIClient_1.AccountingAPIClient(config); | ||
// Get state from your data store | ||
accounting2_callback.oauth1Client.setState(state); | ||
expect(accounting2_callback.oauth1Client.getState()).toMatchObject(state); | ||
accounting2_callback = new AccountingAPIClient_1.AccountingAPIClient(config, authState); | ||
return [2 /*return*/]; | ||
@@ -189,0 +182,0 @@ }); |
@@ -53,2 +53,4 @@ "use strict"; | ||
var authUrl; | ||
var requestToken; | ||
var authState; | ||
var page; | ||
@@ -60,6 +62,6 @@ var oauth_verifier; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.getUnauthorisedRequestToken()]; | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.getRequestToken()]; | ||
case 1: | ||
_a.sent(); | ||
authUrl = accounting1.oauth1Client.buildAuthoriseUrl(); | ||
requestToken = _a.sent(); | ||
authUrl = accounting1.oauth1Client.buildAuthoriseUrl(requestToken); | ||
return [4 /*yield*/, puppeteer.launch({ | ||
@@ -135,5 +137,5 @@ headless: true, | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.swapRequestTokenforAccessToken(oauth_verifier)]; | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.swapRequestTokenforAccessToken(requestToken, oauth_verifier)]; | ||
case 1: | ||
_a.sent(); | ||
authState = _a.sent(); | ||
return [4 /*yield*/, accounting1.organisation.get()]; | ||
@@ -153,3 +155,3 @@ case 2: | ||
case 1: | ||
_a.sent(); | ||
authState = _a.sent(); | ||
return [4 /*yield*/, accounting1.organisation.get()]; | ||
@@ -164,18 +166,12 @@ case 2: | ||
describe('OAuth State', function () { | ||
var state; | ||
var accounting2; | ||
it('it allows you to keep copy of the state in your own dadtastore', function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, accounting1.oauth1Client.getState()]; | ||
case 1: | ||
// Saves your state to your datastore | ||
state = _a.sent(); | ||
expect(state.accessToken).not.toBeNull(); | ||
expect(state.oauth_session_handle).not.toBeNull(); | ||
expect(state.requestToken).not.toBeNull(); | ||
// This is how you can check when you have to refresh your Access Token | ||
expect(typeof state.oauth_expires_at.getDate).toBe('function'); | ||
return [2 /*return*/]; | ||
} | ||
// Saves your state to your datastore | ||
expect(authState).not.toBeNull(); | ||
expect(authState.oauth_session_handle).not.toBeNull(); | ||
expect(requestToken).not.toBeNull(); | ||
// This is how you can check when you have to refresh your Access Token | ||
expect(typeof authState.oauth_expires_at.getDate).toBe('function'); | ||
return [2 /*return*/]; | ||
}); | ||
@@ -185,6 +181,3 @@ }); }); | ||
return __generator(this, function (_a) { | ||
accounting2 = new AccountingAPIClient_1.AccountingAPIClient(config); | ||
// Get state from your data store | ||
accounting2.oauth1Client.setState(state); | ||
expect(accounting2.oauth1Client.getState()).toMatchObject(state); | ||
accounting2 = new AccountingAPIClient_1.AccountingAPIClient(config, authState); | ||
return [2 /*return*/]; | ||
@@ -191,0 +184,0 @@ }); |
@@ -46,11 +46,10 @@ "use strict"; | ||
it('I can get a Practice Auth Token', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var state; | ||
var requestToken; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, client.oauth1Client.getUnauthorisedRequestToken()]; | ||
case 0: return [4 /*yield*/, client.oauth1Client.getRequestToken()]; | ||
case 1: | ||
_a.sent(); | ||
state = client.oauth1Client.getState(); | ||
expect(state.requestToken).toBeDefined(); | ||
expect(typeof state.requestToken.oauth_token).toEqual('string'); | ||
requestToken = _a.sent(); | ||
expect(requestToken).toBeDefined(); | ||
expect(typeof requestToken.oauth_token).toEqual('string'); | ||
return [2 /*return*/]; | ||
@@ -57,0 +56,0 @@ } |
@@ -54,2 +54,4 @@ "use strict"; | ||
res = _a.sent(); | ||
xero.contacts.get(); | ||
xero.contacts.CISsettings.get({ ContactID: '9a9b2ffd-99c6-40c8-8a83-3d172dabf331' }); | ||
console.log('Res: ', res); | ||
@@ -56,0 +58,0 @@ return [3 /*break*/, 4]; |
@@ -52,3 +52,3 @@ "use strict"; | ||
}); }); | ||
it('create', function () { return __awaiter(_this, void 0, void 0, function () { | ||
it('update', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var rate, response, err_1; | ||
@@ -55,0 +55,0 @@ return __generator(this, function (_a) { |
@@ -43,3 +43,2 @@ "use strict"; | ||
var xero; | ||
var createResponse; | ||
beforeAll(function () { | ||
@@ -50,31 +49,25 @@ integration_helpers_1.setJestTimeout(); | ||
}); | ||
it('create single', function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, xero.trackingCategories.create({ | ||
Name: 'Phil Test Category 1' | ||
})]; | ||
case 1: | ||
createResponse = _a.sent(); | ||
expect(createResponse.TrackingCategories.length).toBe(1); | ||
expect(createResponse.TrackingCategories[0].Name).toEqual('Phil Test Category 1'); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
it('get single', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, xero.trackingCategories.get({ TrackingCategoryID: createResponse.TrackingCategories[0].TrackingCategoryID })]; | ||
case 1: | ||
response = _a.sent(); | ||
expect(response).toBeDefined(); | ||
expect(response.Id).toBeTruthy(); | ||
expect(response.TrackingCategories.length).toBe(1); | ||
expect(response.TrackingCategories[0].TrackingCategoryID).toBeTruthy(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
// commented out some of the tests for now. | ||
// it('create single', async () => { | ||
// try { | ||
// createResponse = await xero.trackingCategories.create({ | ||
// Name: 'Phil Test Category 1' | ||
// }); | ||
// } catch (error) { | ||
// const response = await xero.trackingCategories.get(); | ||
// await xero.trackingCategories.delete({TrackingCategoryID: response.TrackingCategories[0].TrackingCategoryID}); | ||
// createResponse = await xero.trackingCategories.create({ | ||
// Name: 'Phil Test Category 1' | ||
// }); | ||
// } | ||
// expect(createResponse.TrackingCategories.length).toBe(1); | ||
// expect(createResponse.TrackingCategories[0].Name).toEqual('Phil Test Category 1'); | ||
// }); | ||
// it('get single', async () => { | ||
// const response = await xero.trackingCategories.get({ TrackingCategoryID: createResponse.TrackingCategories[0].TrackingCategoryID}); | ||
// expect(response).toBeDefined(); | ||
// expect(response.Id).toBeTruthy(); | ||
// expect(response.TrackingCategories.length).toBe(1); | ||
// expect(response.TrackingCategories[0].TrackingCategoryID).toBeTruthy(); | ||
// }); | ||
it('get all', function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -95,17 +88,9 @@ var response; | ||
}); }); | ||
it('delete single', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, xero.trackingCategories.delete({ TrackingCategoryID: createResponse.TrackingCategories[0].TrackingCategoryID })]; | ||
case 1: | ||
response = _a.sent(); | ||
expect(response).toBeDefined(); | ||
expect(response.Id).toBeTruthy(); | ||
expect(response.TrackingCategories.length).toBe(1); | ||
expect(response.TrackingCategories[0].TrackingCategoryID).toBeTruthy(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
// it('delete single' , async () => { | ||
// const response = await xero.trackingCategories.delete({ TrackingCategoryID: createResponse.TrackingCategories[0].TrackingCategoryID}); | ||
// expect(response).toBeDefined(); | ||
// expect(response.Id).toBeTruthy(); | ||
// expect(response.TrackingCategories.length).toBe(1); | ||
// expect(response.TrackingCategories[0].TrackingCategoryID).toBeTruthy(); | ||
// }); | ||
}); |
@@ -43,9 +43,10 @@ "use strict"; | ||
var xero; | ||
var response; | ||
var existingId; | ||
beforeAll(function () { | ||
integration_helpers_1.setJestTimeout(); | ||
var config = integration_helpers_1.getPrivateConfig(); | ||
var config = integration_helpers_1.getPrivateConfig('1'); | ||
xero = new AccountingAPIClient_1.AccountingAPIClient(config); | ||
}); | ||
it('get all', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
@@ -60,2 +61,3 @@ switch (_a.label) { | ||
expect(response.Users[0].UserID).toBeTruthy(); | ||
existingId = response.Users[0].UserID; | ||
return [2 /*return*/]; | ||
@@ -66,12 +68,12 @@ } | ||
it('get single', function () { return __awaiter(_this, void 0, void 0, function () { | ||
var singleResponse; | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, xero.users.get({ UserID: response.Users[0].UserID })]; | ||
case 0: return [4 /*yield*/, xero.users.get({ UserID: existingId })]; | ||
case 1: | ||
singleResponse = _a.sent(); | ||
expect(singleResponse).toBeDefined(); | ||
expect(singleResponse.Id).toBeTruthy(); | ||
expect(singleResponse.Users.length).toBeGreaterThan(0); | ||
expect(singleResponse.Users[0].UserID).toBeTruthy(); | ||
response = _a.sent(); | ||
expect(response).toBeDefined(); | ||
expect(response.Id).toBeTruthy(); | ||
expect(response.Users.length).toBe(1); | ||
expect(response.Users[0].UserID).toBeTruthy(); | ||
return [2 /*return*/]; | ||
@@ -78,0 +80,0 @@ } |
@@ -61,5 +61,3 @@ "use strict"; | ||
readStreamToRequest: readStreamToRequestSpy, | ||
setState: undefined, | ||
getState: undefined, | ||
getUnauthorisedRequestToken: undefined, | ||
getRequestToken: undefined, | ||
buildAuthoriseUrl: undefined, | ||
@@ -71,14 +69,26 @@ swapRequestTokenforAccessToken: undefined, | ||
var localAttachmentLocation = path.resolve(__dirname, 'helpers', 'bean.jpg'); | ||
// Invoices [x] | ||
// Receipts [ ] | ||
// Credit Notes [ ] | ||
// Repeating Invoices [ ] | ||
// Bank Transactions [ ] | ||
// Bank Transfers [ ] | ||
// Contacts [x] | ||
// Accounts [ ] | ||
// Manual Journals [ ] | ||
var fixtures = { | ||
invoices: [ | ||
{ expectedPath: "invoices/" + guid1 + "/attachments/bean.jpg", args: { mimeType: 'image/jpg', pathToSave: tempAttachmentLocation, entityID: guid1, fileName: 'bean.jpg' } } | ||
], | ||
bankTransactions: [ | ||
{ expectedPath: "banktransactions/" + guid1 + "/attachments/bean.jpg", args: { mimeType: 'image/jpg', pathToSave: tempAttachmentLocation, entityID: guid1, fileName: 'bean.jpg' } } | ||
], | ||
creditNotes: [ | ||
{ expectedPath: "creditnotes/" + guid1 + "/attachments/bean.jpg", args: { mimeType: 'image/jpg', pathToSave: tempAttachmentLocation, entityID: guid1, fileName: 'bean.jpg' } } | ||
], | ||
repeatingInvoices: [ | ||
{ expectedPath: "repeatinginvoices/" + guid1 + "/attachments/bean.jpg", args: { mimeType: 'image/jpg', pathToSave: tempAttachmentLocation, entityID: guid1, fileName: 'bean.jpg' } } | ||
], | ||
bankTransfers: [ | ||
{ expectedPath: "banktransfers/" + guid1 + "/attachments/bean.jpg", args: { mimeType: 'image/jpg', pathToSave: tempAttachmentLocation, entityID: guid1, fileName: 'bean.jpg' } } | ||
], | ||
contacts: [ | ||
{ expectedPath: "contacts/" + guid1 + "/attachments/bean.jpg", args: { mimeType: 'image/jpg', pathToSave: tempAttachmentLocation, entityID: guid1, fileName: 'bean.jpg' } } | ||
], | ||
accounts: [ | ||
{ expectedPath: "accounts/" + guid1 + "/attachments/bean.jpg", args: { mimeType: 'image/jpg', pathToSave: tempAttachmentLocation, entityID: guid1, fileName: 'bean.jpg' } } | ||
], | ||
manualJournals: [ | ||
{ expectedPath: "manualjournals/" + guid1 + "/attachments/bean.jpg", args: { mimeType: 'image/jpg', pathToSave: tempAttachmentLocation, entityID: guid1, fileName: 'bean.jpg' } } | ||
] | ||
@@ -105,3 +115,3 @@ }; | ||
}); | ||
xeroClient = new AccountingAPIClient_1.AccountingAPIClient(xeroConfig, oAuth1HttpClient); | ||
xeroClient = new AccountingAPIClient_1.AccountingAPIClient(xeroConfig, null, oAuth1HttpClient); | ||
return [4 /*yield*/, xeroClient[endpoint]['attachments'].downloadAttachment(fixture.args)]; | ||
@@ -157,3 +167,3 @@ case 1: | ||
}); | ||
xeroClient = new AccountingAPIClient_1.AccountingAPIClient(xeroConfig, oAuth1HttpClient); | ||
xeroClient = new AccountingAPIClient_1.AccountingAPIClient(xeroConfig, null, oAuth1HttpClient); | ||
return [4 /*yield*/, xeroClient[endpoint]['attachments'].uploadAttachment({ | ||
@@ -160,0 +170,0 @@ entityID: fixture.args.entityID, |
@@ -56,5 +56,4 @@ "use strict"; | ||
var accountingBaseUrl = oauthConfig.apiBaseUrl + oauthConfig.apiBasePath; | ||
var oauthHttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, inMemoryOAuthLibFF.newFactory()); | ||
oauthHttpClient.setState(config_helper_1.mapState(xeroConfig)); | ||
var xeroClient = new AccountingAPIClient_1.AccountingAPIClient(xeroConfig, oauthHttpClient); | ||
var oauthHttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, config_helper_1.mapState(xeroConfig), inMemoryOAuthLibFF.newFactory()); | ||
var xeroClient = new AccountingAPIClient_1.AccountingAPIClient(xeroConfig, null, oauthHttpClient); | ||
var actionToVerbMap = { | ||
@@ -75,2 +74,12 @@ create: 'put', | ||
], | ||
bankTransactions: [ | ||
{ action: 'get', expectedPath: 'banktransactions' }, | ||
{ action: 'get', expectedPath: "banktransactions?page=3", args: { page: 3 } }, | ||
{ action: 'get', expectedPath: "banktransactions?order=something", args: { order: 'something' } }, | ||
{ action: 'get', expectedPath: "banktransactions?where=Type%3D%3D%22ACCPAY%22&createdByMyApp=true", args: { where: "Type==\"ACCPAY\"", createdByMyApp: true } }, | ||
{ action: 'get', expectedPath: "banktransactions?page=3", args: { 'page': 3, 'If-Modified-Since': 'headerValue' } }, | ||
{ action: 'create', expectedPath: 'banktransactions' }, | ||
{ action: 'update', expectedPath: 'banktransactions?summarizeErrors=false' }, | ||
{ action: 'update', expectedPath: 'banktransactions?summarizeErrors=true', args: { summarizeErrors: true } }, | ||
], | ||
invoices: [ | ||
@@ -97,2 +106,5 @@ { action: 'get', expectedPath: 'invoices' }, | ||
], | ||
invoiceReminders: [ | ||
{ action: 'get', expectedPath: 'invoicereminders/settings' }, | ||
], | ||
organisation: [ | ||
@@ -104,2 +116,3 @@ { action: 'get', expectedPath: 'organisation' }, | ||
{ action: 'get', expectedPath: 'contacts' }, | ||
{ action: 'get', expectedPath: "contacts/" + guid1, args: { ContactID: guid1 } }, | ||
{ action: 'get', expectedPath: "contacts?IDs=" + guid1 + "%2C" + guid2, args: { IDs: guid1 + "," + guid2 } }, | ||
@@ -109,2 +122,11 @@ { action: 'get', expectedPath: "contacts?where=Type%3D%3D%22BANK%22", args: { where: 'Type=="BANK"' } }, | ||
{ action: 'get', expectedPath: "contacts?includeArchived=true", args: { includeArchived: true } }, | ||
{ action: 'get', expectedPath: "contacts", args: { 'If-Modified-Since': 'headerValue' } }, | ||
{ action: 'get', expectedPath: "contacts?where=Type%3D%3D%22BANK%22", args: { where: 'Type=="BANK"' } }, | ||
{ action: 'get', expectedPath: "contacts?order=EmailAddress%20DESC", args: { order: 'EmailAddress DESC' } }, | ||
{ action: 'get', expectedPath: "contacts?page=2", args: { page: 2 } }, | ||
{ subResource: 'CISsettings', action: 'get', expectedPath: "contacts/" + guid1 + "/cissettings", args: { ContactID: guid1 } }, | ||
{ action: 'update', expectedPath: "contacts/" + guid1 + "?summarizeErrors=false", args: { ContactID: guid1 } }, | ||
{ action: 'update', expectedPath: "contacts/" + guid1 + "?summarizeErrors=true", args: { summarizeErrors: true, ContactID: guid1 } }, | ||
{ action: 'create', expectedPath: "contacts?summarizeErrors=false" }, | ||
{ action: 'create', expectedPath: "contacts?summarizeErrors=true", args: { summarizeErrors: true } }, | ||
], | ||
@@ -146,2 +168,33 @@ contactgroups: [ | ||
], | ||
items: [ | ||
{ action: 'get', expectedPath: 'items' }, | ||
{ action: 'get', expectedPath: "items/" + guid1, args: { ItemID: guid1 } }, | ||
{ action: 'get', expectedPath: "items/" + guid1 + "?order=UpdatedDateUTC", args: { ItemID: guid1, order: 'UpdatedDateUTC' } }, | ||
{ action: 'create', expectedPath: "items?summarizeErrors=false" }, | ||
{ action: 'update', expectedPath: "items?summarizeErrors=false" }, | ||
{ action: 'update', expectedPath: "items/" + guid1 + "?summarizeErrors=true", args: { ItemID: guid1, summarizeErrors: true } }, | ||
], | ||
overpayments: [ | ||
{ action: 'get', expectedPath: 'overpayments' }, | ||
{ action: 'get', expectedPath: "overpayments/" + guid1 + "?order=Date", args: { OverpaymentID: guid1, order: 'Date' } }, | ||
{ action: 'get', expectedPath: "overpayments?page=5", args: { page: 5 } }, | ||
{ action: 'update', expectedPath: "overpayments/" + guid1 + "/allocations", args: { OverpaymentID: guid1 } } | ||
], | ||
payments: [ | ||
{ action: 'get', expectedPath: 'payments' }, | ||
{ action: 'get', expectedPath: "payments/" + guid1, args: { PaymentID: guid1 } }, | ||
{ action: 'get', expectedPath: "payments/" + guid1 + "?order=UpdatedDateUTC", args: { PaymentID: guid1, order: 'UpdatedDateUTC' } }, | ||
{ action: 'get', expectedPath: "payments", args: { 'If-Modified-Since': 'headerValue' } }, | ||
{ action: 'create', expectedPath: "payments?summarizeErrors=false" }, | ||
{ action: 'update', expectedPath: "payments?summarizeErrors=false" }, | ||
{ action: 'update', expectedPath: "payments/" + guid1 + "?summarizeErrors=true", args: { PaymentID: guid1, summarizeErrors: true } }, | ||
], | ||
prepayments: [ | ||
{ action: 'get', expectedPath: 'prepayments' }, | ||
{ action: 'get', expectedPath: "prepayments/" + guid1, args: { PrepaymentID: guid1 } }, | ||
{ action: 'get', expectedPath: "prepayments/" + guid1 + "?order=UpdatedDateUTC", args: { PrepaymentID: guid1, order: 'UpdatedDateUTC' } }, | ||
{ action: 'get', expectedPath: "prepayments?page=5", args: { 'page': 5, 'If-Modified-Since': 'headerValue' } }, | ||
{ subResource: 'allocations', action: 'create', expectedPath: "prepayments/" + guid1 + "/allocations", args: { PrepaymentID: guid1 } }, | ||
{ subResource: 'attachments', action: 'get', expectedPath: "prepayments/" + guid1 + "/attachments", args: { EntityID: guid1 } }, | ||
], | ||
users: [ | ||
@@ -154,2 +207,9 @@ { action: 'get', expectedPath: 'users' }, | ||
], | ||
journals: [ | ||
{ action: 'get', expectedPath: 'journals' }, | ||
{ action: 'get', expectedPath: "journals/" + guid1, args: { Recordfilter: guid1 } }, | ||
{ action: 'get', expectedPath: "journals?offset=2", args: { offset: '2' } }, | ||
{ action: 'get', expectedPath: "journals?paymentsOnly=true", args: { paymentsOnly: true } }, | ||
{ action: 'get', expectedPath: "journals", args: { 'If-Modified-Since': 'headerValue' } }, | ||
], | ||
reports: [ | ||
@@ -156,0 +216,0 @@ { action: 'get', expectedPath: 'reports' }, |
@@ -19,3 +19,9 @@ "use strict"; | ||
{ | ||
expectedMessage: 'XeroError: rate limit exceeded (please wait before retrying the xero api)', | ||
expectedMessage: 'XeroError: statusCode=404 data=It went bad!', | ||
statusCode: 404, | ||
data: 'It went bad!', | ||
headers: null | ||
}, | ||
{ | ||
expectedMessage: 'XeroError: Minute rate limit exceeded (please wait before retrying the xero api)', | ||
statusCode: 503, | ||
@@ -22,0 +28,0 @@ data: 'oauth_problem=rate%20limit%20exceeded&oauth_problem_advice=please%20wait%20before%20retrying%20the%20xero%20api', |
@@ -17,5 +17,11 @@ export interface AccountingResponse { | ||
} | ||
export interface BankTransactionsResponse extends AccountingResponse { | ||
BankTransactions: BankTransaction[]; | ||
} | ||
export interface InvoicesResponse extends AccountingResponse { | ||
Invoices: Invoice[]; | ||
} | ||
export interface InvoiceRemindersResponse extends AccountingResponse { | ||
InvoiceReminders: InvoiceReminder[]; | ||
} | ||
export interface ContactGroupsResponse extends AccountingResponse { | ||
@@ -45,2 +51,14 @@ ContactGroups: ContactGroup[]; | ||
} | ||
export interface BrandingThemesResponse extends AccountingResponse { | ||
BrandingThemes: BrandingTheme[]; | ||
} | ||
export interface JournalsResponse extends AccountingResponse { | ||
Journals: Journal[]; | ||
} | ||
export interface ItemsResponse extends AccountingResponse { | ||
Items: Item[]; | ||
} | ||
export interface ItemsResponse extends AccountingResponse { | ||
Items: Item[]; | ||
} | ||
export interface OnlineInvoicesResponse extends AccountingResponse { | ||
@@ -52,8 +70,14 @@ OnlineInvoices: OnlineInvoice[]; | ||
} | ||
export interface OrganisationCISSettingResponse { | ||
export interface OrganisationCISSettingResponse extends AccountingResponse { | ||
CISSettings: OrgCISSetting[]; | ||
} | ||
export interface BrandingThemesResponse { | ||
BrandingThemes: BrandingTheme[]; | ||
export interface OverpaymentsResponse extends AccountingResponse { | ||
Overpayments: Overpayment[]; | ||
} | ||
export interface PaymentsResponse extends AccountingResponse { | ||
Payments: Payment[]; | ||
} | ||
export interface PrepaymentsResponse extends AccountingResponse { | ||
Prepayments: Prepayment[]; | ||
} | ||
export interface TaxRatesResponse extends AccountingResponse { | ||
@@ -71,2 +95,25 @@ TaxRates?: TaxRate[]; | ||
} | ||
export interface BankTransaction { | ||
Contact?: Contact; | ||
DateString?: string; | ||
Date?: string; | ||
Status?: string; | ||
LineAmountTypes?: string; | ||
LineItems?: LineItem[]; | ||
SubTotal?: number; | ||
TotalTax?: number; | ||
Total?: number; | ||
UpdatedDateUTC?: string; | ||
CurrencyCode?: string; | ||
BankTransactionID?: string; | ||
BankAccount?: BankAccount; | ||
Type?: string; | ||
Reference?: string; | ||
IsReconciled?: boolean; | ||
} | ||
export interface BankAccount { | ||
AccountID?: string; | ||
Code?: string; | ||
Name?: string; | ||
} | ||
export interface BankTransfer { | ||
@@ -94,6 +141,17 @@ BankTransferID?: string; | ||
Amount?: number; | ||
BankAmount?: number; | ||
Reference?: string; | ||
CurrencyRate?: number; | ||
IsReconciled?: boolean; | ||
Status?: string; | ||
PaymentType?: string; | ||
HasAccount?: boolean; | ||
Account?: any; | ||
Invoice?: Invoice; | ||
CreditNote?: CreditNote; | ||
Prepayment?: Prepayment; | ||
Overpayment?: Overpayment; | ||
UpdatedDateUTC?: string; | ||
HasValidationErrors?: boolean; | ||
ValidationErrors?: ValidationError[]; | ||
} | ||
@@ -106,19 +164,43 @@ export interface BrandingTheme { | ||
} | ||
export interface Overpayment { | ||
OverpaymentID?: string; | ||
Type?: string; | ||
Contact?: Contact; | ||
Date?: string; | ||
Status?: string; | ||
LineAmountTypes?: string; | ||
LineItems?: LineItem[]; | ||
SubTotal?: number; | ||
TotalTax?: number; | ||
Total?: number; | ||
UpdatedDateUTC?: string; | ||
CurrencyCode?: string; | ||
CurrencyRate?: number; | ||
RemainingCredit?: number; | ||
Allocations?: Allocation[]; | ||
Payments?: Payment[]; | ||
HasAttachments?: boolean; | ||
HasValidationErrors?: boolean; | ||
ValidationErrors?: ValidationError[]; | ||
} | ||
export interface Prepayment { | ||
Contact: Contact; | ||
Date: string; | ||
Status: string; | ||
LineAmountTypes: string; | ||
SubTotal: string; | ||
TotalTax: string; | ||
Total: string; | ||
UpdatedDateUTC: string; | ||
CurrencyCode: string; | ||
FullyPaidOnDate: string; | ||
Type: string; | ||
PrepaymentID: string; | ||
CurrencyRate: string; | ||
RemainingCredit: string; | ||
Allocations: Allocation[]; | ||
HasAttachments: string; | ||
PrepaymentID?: string; | ||
Type?: string; | ||
Contact?: Contact; | ||
Date?: string; | ||
Status?: string; | ||
LineAmountTypes?: string; | ||
LineItems?: LineItem[]; | ||
SubTotal?: number; | ||
TotalTax?: number; | ||
Total?: number; | ||
UpdatedDateUTC?: string; | ||
CurrencyCode?: string; | ||
CurrencyRate?: number; | ||
RemainingCredit?: number; | ||
Allocations?: Allocation[]; | ||
Reference?: string; | ||
HasAttachments?: boolean; | ||
HasValidationErrors?: boolean; | ||
ValidationErrors?: ValidationError[]; | ||
} | ||
@@ -159,3 +241,3 @@ export interface Allocation { | ||
CreditNotes?: CreditNote[]; | ||
Overpayments?: any[]; | ||
Overpayments?: Overpayment[]; | ||
CISDeduction?: number; | ||
@@ -186,2 +268,5 @@ AmountDue?: number; | ||
} | ||
export interface InvoiceReminder { | ||
Enabled?: boolean; | ||
} | ||
export interface ValidationError { | ||
@@ -203,7 +288,7 @@ Message: string; | ||
Balances?: any; | ||
ContactGroups?: any[]; | ||
ContactGroups?: ContactGroup[]; | ||
IsSupplier?: boolean; | ||
IsCustomer?: boolean; | ||
SalesTrackingCategories?: any[]; | ||
PurchasesTrackingCategories?: any[]; | ||
SalesTrackingCategories?: Tracking[]; | ||
PurchasesTrackingCategories?: Tracking[]; | ||
ContactPersons?: any[]; | ||
@@ -241,2 +326,21 @@ HasAttachments?: boolean; | ||
} | ||
export interface Journal { | ||
JournalID?: string; | ||
JournalDate?: string; | ||
JournalNumber?: string; | ||
CreatedDateUTC?: string; | ||
SourceID?: string; | ||
SourceType?: string; | ||
JournalLines?: JournalLine[]; | ||
} | ||
export interface JournalLine { | ||
JournalLineID?: string; | ||
AccountID?: string; | ||
AccountCode?: string; | ||
AccountType?: string; | ||
AccountName?: string; | ||
NetAmount?: string; | ||
GrossAmount?: string; | ||
TaxAmount?: string; | ||
} | ||
export interface Phone { | ||
@@ -287,2 +391,24 @@ PhoneType?: string; | ||
} | ||
export interface Item { | ||
ItemID?: string; | ||
Code?: string; | ||
Name?: string; | ||
QuantityOnHand?: number; | ||
TotalCostPool?: number; | ||
IsSold?: boolean; | ||
Description?: string; | ||
SalesDetails?: PurchaseAndSalesDetails; | ||
IsPurchased?: boolean; | ||
PurchaseDescription?: string; | ||
PurchaseDetails?: PurchaseAndSalesDetails; | ||
IsTrackedAsInventory?: boolean; | ||
InventoryAssetAccountCode?: string; | ||
UpdatedDateUTC?: string; | ||
} | ||
export interface PurchaseAndSalesDetails { | ||
UnitPrice: number; | ||
AccountCode: string; | ||
COGSAccountCode?: string; | ||
TaxType?: string; | ||
} | ||
export interface Tracking { | ||
@@ -289,0 +415,0 @@ Name?: string; |
@@ -1,4 +0,4 @@ | ||
import { AccountsResponse, InvoicesResponse, Invoice, ContactGroupsResponse, ContactGroup, CurrenciesResponse, EmployeesResponse, Currency, Employee, ContactsResponse, ReportsResponse, AttachmentsResponse, OrganisationResponse, Contact, UsersResponse, BrandingThemesResponse, BankTransfersResponse, BankTransfer, TrackingCategoriesResponse, TrackingCategory, TrackingOption, TaxRatesResponse, ExpenseClaimsResponse, ExpenseClaim, TaxRate } from './AccountingAPI-types'; | ||
import { IXeroClientConfiguration, BaseAPIClient } from './internals/BaseAPIClient'; | ||
import { IOAuth1HttpClient } from './internals/OAuth1HttpClient'; | ||
import { IOAuth1HttpClient, IOAuth1State } from './internals/OAuth1HttpClient'; | ||
import { AccountsResponse, BankTransaction, BankTransactionsResponse, InvoicesResponse, Invoice, ContactGroupsResponse, ContactGroup, CurrenciesResponse, Currency, EmployeesResponse, Employee, ContactsResponse, Contact, ReportsResponse, AttachmentsResponse, OrganisationResponse, UsersResponse, BrandingThemesResponse, BankTransfersResponse, BankTransfer, TrackingCategoriesResponse, TrackingCategory, TrackingOption, TaxRatesResponse, TaxRate, ExpenseClaimsResponse, ExpenseClaim, ItemsResponse, Item, InvoiceRemindersResponse, JournalsResponse, PaymentsResponse, Payment, PrepaymentsResponse, Allocation, OverpaymentsResponse } from './AccountingAPI-types'; | ||
export interface QueryArgs { | ||
@@ -8,2 +8,5 @@ where?: string; | ||
} | ||
export interface PagingArgs { | ||
page?: number; | ||
} | ||
export interface HeaderArgs { | ||
@@ -13,3 +16,3 @@ 'If-Modified-Since'?: string; | ||
export declare class AccountingAPIClient extends BaseAPIClient { | ||
constructor(options: IXeroClientConfiguration, _oAuth1HttpClient?: IOAuth1HttpClient); | ||
constructor(options: IXeroClientConfiguration, authState?: IOAuth1State, _oAuth1HttpClient?: IOAuth1HttpClient); | ||
private generateHeader(args); | ||
@@ -45,2 +48,32 @@ accounts: { | ||
}; | ||
bankTransactions: { | ||
get: (args?: { | ||
BankTransactionID?: string; | ||
} & QueryArgs & HeaderArgs) => Promise<BankTransactionsResponse>; | ||
create: (bankTransaction: BankTransaction | { | ||
BankTransactions: BankTransaction[]; | ||
}) => Promise<BankTransactionsResponse>; | ||
update: (bankTransaction: BankTransaction | { | ||
BankTransactions: BankTransaction[]; | ||
}, args?: { | ||
summarizeErrors?: boolean; | ||
}) => Promise<BankTransactionsResponse>; | ||
attachments: { | ||
get: (args?: { | ||
EntityID: string; | ||
}) => Promise<AttachmentsResponse>; | ||
downloadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToSave: string; | ||
}) => Promise<void>; | ||
uploadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToUpload: string; | ||
}) => Promise<AttachmentsResponse>; | ||
}; | ||
}; | ||
invoices: { | ||
@@ -63,3 +96,5 @@ get: (args?: { | ||
}) => Promise<InvoicesResponse>; | ||
update: (invoices: Invoice | Invoice[], args?: { | ||
update: (invoices: Invoice | { | ||
Invoices: Invoice[]; | ||
}, args?: { | ||
InvoiceID?: string; | ||
@@ -93,3 +128,26 @@ InvoiceNumber?: string; | ||
}; | ||
invoiceReminders: { | ||
get: () => Promise<InvoiceRemindersResponse>; | ||
}; | ||
private generateAttachmentsEndpoint(path); | ||
banktransactions: { | ||
create: (bankTransactions: any) => Promise<any>; | ||
attachments: { | ||
get: (args?: { | ||
EntityID: string; | ||
}) => Promise<AttachmentsResponse>; | ||
downloadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToSave: string; | ||
}) => Promise<void>; | ||
uploadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToUpload: string; | ||
}) => Promise<AttachmentsResponse>; | ||
}; | ||
}; | ||
contactgroups: { | ||
@@ -99,6 +157,10 @@ get: (args?: { | ||
} & QueryArgs) => Promise<ContactGroupsResponse>; | ||
create: (contactGroups: ContactGroup | ContactGroup[], args?: { | ||
create: (contactGroups: ContactGroup | { | ||
ContactGroups: ContactGroup[]; | ||
}, args?: { | ||
summarizeErrors?: boolean; | ||
}) => Promise<ContactGroupsResponse>; | ||
update: (contactGroups: ContactGroup | ContactGroup[], args?: { | ||
update: (contactGroups: ContactGroup | { | ||
ContactGroups: ContactGroup[]; | ||
}, args?: { | ||
ContactGroupID: string; | ||
@@ -119,8 +181,22 @@ summarizeErrors?: boolean; | ||
get: (args?: { | ||
ContactID?: string; | ||
includeArchived?: boolean; | ||
IDs?: string; | ||
} & HeaderArgs & QueryArgs) => Promise<ContactsResponse>; | ||
create: (body: Contact | { | ||
Contacts: Contact[]; | ||
}, args?: { | ||
summarizeErrors: boolean; | ||
}) => Promise<ContactsResponse>; | ||
create: (body?: object, args?: { | ||
update: (body?: Contact | { | ||
Contacts: Contact[]; | ||
}, args?: { | ||
ContactID: string; | ||
summarizeErrors: boolean; | ||
}) => Promise<ContactsResponse>; | ||
CISsettings: { | ||
get: (args?: { | ||
ContactID: string; | ||
}) => Promise<string>; | ||
}; | ||
attachments: { | ||
@@ -144,2 +220,21 @@ get: (args?: { | ||
}; | ||
creditNotes: { | ||
attachments: { | ||
get: (args?: { | ||
EntityID: string; | ||
}) => Promise<AttachmentsResponse>; | ||
downloadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToSave: string; | ||
}) => Promise<void>; | ||
uploadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToUpload: string; | ||
}) => Promise<AttachmentsResponse>; | ||
}; | ||
}; | ||
currencies: { | ||
@@ -153,4 +248,8 @@ get: (args?: QueryArgs) => Promise<CurrenciesResponse>; | ||
} & QueryArgs & HeaderArgs) => Promise<EmployeesResponse>; | ||
create: (employees: Employee | Employee[]) => Promise<EmployeesResponse>; | ||
update: (employees: Employee | Employee[]) => Promise<EmployeesResponse>; | ||
create: (employees: Employee | { | ||
Employees: Employee[]; | ||
}) => Promise<EmployeesResponse>; | ||
update: (employees: Employee | { | ||
Employees: Employee[]; | ||
}) => Promise<EmployeesResponse>; | ||
}; | ||
@@ -161,6 +260,10 @@ expenseclaims: { | ||
} & QueryArgs & HeaderArgs) => Promise<ExpenseClaimsResponse>; | ||
create: (expenseClaims: ExpenseClaim | ExpenseClaim[], args?: { | ||
create: (expenseClaims: ExpenseClaim | { | ||
ExpenseClaims: ExpenseClaim[]; | ||
}, args?: { | ||
summarizeErrors?: boolean; | ||
}) => Promise<ExpenseClaimsResponse>; | ||
update: (expenseClaims: ExpenseClaim | ExpenseClaim[], args?: { | ||
update: (expenseClaims: ExpenseClaim | { | ||
ExpenseClaims: ExpenseClaim[]; | ||
}, args?: { | ||
ExpenseClaimID?: string; | ||
@@ -170,2 +273,22 @@ summarizeErrors?: boolean; | ||
}; | ||
items: { | ||
get: (args?: { | ||
ItemID?: string; | ||
Code?: string; | ||
} & QueryArgs & HeaderArgs) => Promise<ItemsResponse>; | ||
create: (items: Item | { | ||
Items: Item[]; | ||
}, args?: { | ||
summarizeErrors?: boolean; | ||
}) => Promise<ItemsResponse>; | ||
update: (items: Item | { | ||
Items: Item[]; | ||
}, args?: { | ||
ItemID?: string; | ||
summarizeErrors?: boolean; | ||
}) => Promise<ItemsResponse>; | ||
delete: (args: { | ||
ItemID: string; | ||
}) => Promise<ItemsResponse>; | ||
}; | ||
trackingCategories: { | ||
@@ -177,6 +300,6 @@ get: (args?: { | ||
create: (trackingCategory: TrackingCategory | { | ||
TrackingCategories: TrackingCategory[]; | ||
TrackingCategorys: TrackingCategory[]; | ||
}) => Promise<TrackingCategoriesResponse>; | ||
update: (trackingCategory: TrackingCategory | { | ||
TrackingCategories: TrackingCategory[]; | ||
TrackingCategorys: TrackingCategory[]; | ||
}, args?: { | ||
@@ -190,3 +313,3 @@ TrackingCategoryID: string; | ||
create: (trackingOption: TrackingOption | { | ||
Options: TrackingOption[]; | ||
TrackingOptions: TrackingOption[]; | ||
}, args?: { | ||
@@ -196,3 +319,3 @@ TrackingCategoryID: string; | ||
update: (trackingOption: TrackingOption | { | ||
Options: TrackingOption[]; | ||
TrackingOptions: TrackingOption[]; | ||
}, args?: { | ||
@@ -213,2 +336,9 @@ TrackingCategoryID: string; | ||
}; | ||
journals: { | ||
get: (args?: { | ||
Recordfilter?: string; | ||
offset?: string; | ||
paymentsOnly?: boolean; | ||
} & HeaderArgs) => Promise<JournalsResponse>; | ||
}; | ||
brandingThemes: { | ||
@@ -223,3 +353,5 @@ get: (args?: { | ||
} & HeaderArgs & QueryArgs) => Promise<BankTransfersResponse>; | ||
create: (bankTransfers: BankTransfer | BankTransfer[], args?: { | ||
create: (bankTransfers: BankTransfer | { | ||
BankTransfers: BankTransfer[]; | ||
}, args?: { | ||
summarizeErrors: boolean; | ||
@@ -245,2 +377,21 @@ }) => Promise<BankTransfersResponse>; | ||
}; | ||
manualJournals: { | ||
attachments: { | ||
get: (args?: { | ||
EntityID: string; | ||
}) => Promise<AttachmentsResponse>; | ||
downloadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToSave: string; | ||
}) => Promise<void>; | ||
uploadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToUpload: string; | ||
}) => Promise<AttachmentsResponse>; | ||
}; | ||
}; | ||
organisation: { | ||
@@ -255,2 +406,55 @@ get: () => Promise<OrganisationResponse>; | ||
}; | ||
payments: { | ||
get: (args?: { | ||
PaymentID: string; | ||
} & QueryArgs & HeaderArgs) => Promise<PaymentsResponse>; | ||
create: (payments: Payment | { | ||
Payments: Payment[]; | ||
}, args?: { | ||
summarizeErrors?: boolean; | ||
}) => Promise<PaymentsResponse>; | ||
update: (payments: Payment | { | ||
Payments: Payment[]; | ||
}, args?: { | ||
PaymentID: string; | ||
summarizeErrors?: boolean; | ||
}) => Promise<PaymentsResponse>; | ||
}; | ||
prepayments: { | ||
get: (args?: { | ||
PrepaymentID: string; | ||
} & QueryArgs & PagingArgs & HeaderArgs) => Promise<PrepaymentsResponse>; | ||
allocations: { | ||
create: (allocations: Allocation | { | ||
Allocations: Allocation[]; | ||
}, args: { | ||
PrepaymentID: string; | ||
}) => Promise<PrepaymentsResponse>; | ||
}; | ||
attachments: { | ||
get: (args?: { | ||
EntityID: string; | ||
}) => Promise<AttachmentsResponse>; | ||
downloadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToSave: string; | ||
}) => Promise<void>; | ||
uploadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToUpload: string; | ||
}) => Promise<AttachmentsResponse>; | ||
}; | ||
}; | ||
overpayments: { | ||
get: (args?: { | ||
OverpaymentID?: string; | ||
} & QueryArgs & PagingArgs & HeaderArgs) => Promise<OverpaymentsResponse>; | ||
update: (body: Allocation[], args: { | ||
OverpaymentID: string; | ||
}) => Promise<OverpaymentsResponse>; | ||
}; | ||
reports: { | ||
@@ -261,2 +465,21 @@ get: (args?: { | ||
}; | ||
repeatingInvoices: { | ||
attachments: { | ||
get: (args?: { | ||
EntityID: string; | ||
}) => Promise<AttachmentsResponse>; | ||
downloadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToSave: string; | ||
}) => Promise<void>; | ||
uploadAttachment: (args?: { | ||
entityID: string; | ||
mimeType: string; | ||
fileName: string; | ||
pathToUpload: string; | ||
}) => Promise<AttachmentsResponse>; | ||
}; | ||
}; | ||
taxRates: { | ||
@@ -263,0 +486,0 @@ get: (args?: { |
@@ -53,4 +53,4 @@ "use strict"; | ||
__extends(AccountingAPIClient, _super); | ||
function AccountingAPIClient(options, _oAuth1HttpClient) { | ||
var _this = _super.call(this, options, {}, _oAuth1HttpClient) || this; | ||
function AccountingAPIClient(options, authState, _oAuth1HttpClient) { | ||
var _this = _super.call(this, options, authState, {}, _oAuth1HttpClient) || this; | ||
_this.accounts = { | ||
@@ -98,2 +98,32 @@ get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
}; | ||
_this.bankTransactions = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'banktransactions'; | ||
if (args && args.BankTransactionID) { | ||
endpoint = endpoint + '/' + args.BankTransactionID; | ||
delete args.BankTransactionID; // remove from query string | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
create: function (bankTransaction) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'banktransactions'; | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, bankTransaction)]; | ||
}); | ||
}); }, | ||
update: function (bankTransaction, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'banktransactions' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, bankTransaction)]; | ||
}); | ||
}); }, | ||
attachments: _this.generateAttachmentsEndpoint('banktransactions') | ||
}; | ||
_this.invoices = { | ||
@@ -173,2 +203,19 @@ get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
}; | ||
_this.invoiceReminders = { | ||
get: function () { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'invoicereminders/settings'; | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); } | ||
}; | ||
_this.banktransactions = { | ||
create: function (bankTransactions) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, null]; // TODO | ||
}); | ||
}); }, | ||
attachments: _this.generateAttachmentsEndpoint('banktransactions') | ||
}; | ||
_this.contactgroups = { | ||
@@ -239,7 +286,12 @@ get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contacts'; | ||
endpoint += utils_1.generateQueryString(args, false); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
if (args && args.ContactID) { | ||
endpoint = endpoint + '/' + args.ContactID; | ||
delete args.ContactID; | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
@@ -252,7 +304,36 @@ }); }, | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, body)]; | ||
}); | ||
}); }, | ||
update: function (body, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contacts'; | ||
if (args && args.ContactID) { | ||
endpoint = endpoint + '/' + args.ContactID; | ||
delete args.ContactID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, body)]; | ||
}); | ||
}); }, | ||
CISsettings: { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contacts'; | ||
if (args && args.ContactID) { | ||
endpoint = endpoint + '/' + args.ContactID; | ||
delete args.ContactID; | ||
} | ||
endpoint += '/cissettings'; | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); } | ||
}, | ||
attachments: _this.generateAttachmentsEndpoint('contacts') | ||
}; | ||
_this.creditNotes = { | ||
attachments: _this.generateAttachmentsEndpoint('creditnotes') | ||
}; | ||
_this.currencies = { | ||
@@ -336,2 +417,47 @@ get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
}; | ||
_this.items = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, headers; | ||
return __generator(this, function (_a) { | ||
endpoint = 'items'; | ||
if (args && args.ItemID) { | ||
endpoint = endpoint + '/' + args.ItemID; | ||
delete args.ItemID; | ||
} | ||
else if (args && args.Code) { | ||
endpoint = endpoint + '/' + args.Code; | ||
delete args.Code; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); }, | ||
create: function (items, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'items' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, items)]; | ||
}); | ||
}); }, | ||
update: function (items, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'items'; | ||
if (args && args.ItemID) { | ||
endpoint = endpoint + '/' + args.ItemID; | ||
delete args.ItemID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, items)]; | ||
}); | ||
}); }, | ||
delete: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'items' + '/' + args.ItemID; | ||
return [2 /*return*/, this.oauth1Client.delete(endpoint)]; | ||
}); | ||
}); } | ||
}; | ||
_this.trackingCategories = { | ||
@@ -423,2 +549,17 @@ get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
}; | ||
_this.journals = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, headers; | ||
return __generator(this, function (_a) { | ||
endpoint = 'journals'; | ||
if (args && args.Recordfilter) { | ||
endpoint = endpoint + '/' + args.Recordfilter; | ||
delete args.Recordfilter; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); } | ||
}; | ||
_this.brandingThemes = { | ||
@@ -460,2 +601,5 @@ get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
}; | ||
_this.manualJournals = { | ||
attachments: _this.generateAttachmentsEndpoint('manualjournals') | ||
}; | ||
_this.organisation = { | ||
@@ -484,2 +628,83 @@ get: function () { return __awaiter(_this, void 0, void 0, function () { | ||
}; | ||
_this.payments = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, headers; | ||
return __generator(this, function (_a) { | ||
endpoint = 'payments'; | ||
if (args && args.PaymentID) { | ||
endpoint = endpoint + '/' + args.PaymentID; | ||
delete args.PaymentID; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); }, | ||
create: function (payments, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'payments' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, payments)]; | ||
}); | ||
}); }, | ||
update: function (payments, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'payments'; | ||
if (args && args.PaymentID) { | ||
endpoint = endpoint + '/' + args.PaymentID; | ||
delete args.PaymentID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, payments)]; | ||
}); | ||
}); } | ||
}; | ||
_this.prepayments = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, headers; | ||
return __generator(this, function (_a) { | ||
endpoint = 'prepayments'; | ||
if (args && args.PrepaymentID) { | ||
endpoint = endpoint + '/' + args.PrepaymentID; | ||
delete args.PrepaymentID; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); }, | ||
allocations: { | ||
create: function (allocations, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = "prepayments/" + args.PrepaymentID + "/allocations"; | ||
delete args.PrepaymentID; | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, allocations)]; | ||
}); | ||
}); } | ||
}, | ||
attachments: _this.generateAttachmentsEndpoint('prepayments') | ||
}; | ||
_this.overpayments = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'overpayments'; | ||
if (args && args.OverpaymentID) { | ||
endpoint += '/' + args.OverpaymentID; | ||
delete args.OverpaymentID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
update: function (body, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = "overpayments/" + args.OverpaymentID + "/allocations"; | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, body)]; | ||
}); | ||
}); } | ||
}; | ||
_this.reports = { | ||
@@ -499,2 +724,5 @@ get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
}; | ||
_this.repeatingInvoices = { | ||
attachments: _this.generateAttachmentsEndpoint('repeatinginvoices') | ||
}; | ||
_this.taxRates = { | ||
@@ -501,0 +729,0 @@ get: function (args) { return __awaiter(_this, void 0, void 0, function () { |
@@ -33,6 +33,4 @@ "use strict"; | ||
expect(retrievedState).toEqual({ | ||
accessToken: { | ||
oauth_token: 'RDGDV41TRLQZDFSDX96TKQ2KRJIW4C', | ||
oauth_token_secret: privateKey_helpers_1.testCertString() | ||
} | ||
oauth_token: 'RDGDV41TRLQZDFSDX96TKQ2KRJIW4C', | ||
oauth_token_secret: privateKey_helpers_1.testCertString() | ||
}); | ||
@@ -67,6 +65,4 @@ }); | ||
expect(retrievedState).toEqual({ | ||
accessToken: { | ||
oauth_token: 'RDGDV41TRLQZDFSDX96TKQ2KRJIW4C', | ||
oauth_token_secret: privateKey_helpers_1.testCertString() | ||
} | ||
oauth_token: 'RDGDV41TRLQZDFSDX96TKQ2KRJIW4C', | ||
oauth_token_secret: privateKey_helpers_1.testCertString() | ||
}); | ||
@@ -101,3 +97,3 @@ }); | ||
var retrievedState = config_helper_1.mapState(xeroConfig); | ||
expect(retrievedState).toEqual({}); | ||
expect(retrievedState).toEqual(null); | ||
}); | ||
@@ -131,3 +127,3 @@ }); | ||
var retrievedState = config_helper_1.mapState(xeroConfig); | ||
expect(retrievedState).toEqual({}); | ||
expect(retrievedState).toEqual(null); | ||
}); | ||
@@ -160,3 +156,3 @@ }); | ||
var retrievedState = config_helper_1.mapState(xeroConfig); | ||
expect(retrievedState).toEqual({}); | ||
expect(retrievedState).toEqual(null); | ||
}); | ||
@@ -163,0 +159,0 @@ }); |
@@ -45,41 +45,38 @@ "use strict"; | ||
describe('HTTP errors', function () { | ||
var testError = new XeroError_1.XeroError(101, 'the sky is blue'); | ||
var testError = new XeroError_1.XeroError(101, 'the sky is blue', null); | ||
var inMemoryOAuthFF = new InMemoryOAuthLib_1.InMemoryOAuthLibFactoryFactory(); | ||
var xeroClient; | ||
var oauthConfig = { | ||
consumerKey: 'ck', | ||
consumerSecret: 'cs', | ||
tenantType: null, | ||
apiBaseUrl: 'abu', | ||
apiBasePath: 'abp', | ||
oauthRequestTokenPath: 'ortp', | ||
oauthAccessTokenPath: 'oatp', | ||
signatureMethod: 'sigm', | ||
callbackUrl: 'http://sdf.sdf', | ||
accept: 'acceps', | ||
userAgent: 'ua' | ||
}; | ||
var requestToken = { | ||
oauth_token: 'reqtoken', | ||
oauth_token_secret: 'reqsecret', | ||
}; | ||
var oauthState = { | ||
oauth_token: 'atoken', | ||
oauth_token_secret: 'asecret', | ||
oauth_session_handle: 'sessionHandle' | ||
}; | ||
var xeroConfig = { | ||
appType: 'private', | ||
consumerKey: 'RDGDV41TRLQZDFSDX96TKQ2KRJIW4C', | ||
consumerSecret: 'DJ3CMGDB0DIIA9DNEEJMRLZG0BWE7Y', | ||
privateKeyPath: privateKey_helpers_1.validTestCertPath() | ||
}; | ||
beforeAll(function () { return __awaiter(_this, void 0, void 0, function () { | ||
var oauthConfig, oauthState, xeroConfig, oAuth1HttpClient; | ||
var oAuth1HttpClient; | ||
return __generator(this, function (_a) { | ||
oauthConfig = { | ||
consumerKey: 'ck', | ||
consumerSecret: 'cs', | ||
tenantType: null, | ||
apiBaseUrl: 'abu', | ||
apiBasePath: 'abp', | ||
oauthRequestTokenPath: 'ortp', | ||
oauthAccessTokenPath: 'oatp', | ||
signatureMethod: 'sigm', | ||
callbackUrl: 'http://sdf.sdf', | ||
accept: 'acceps', | ||
userAgent: 'ua' | ||
}; | ||
oauthState = { | ||
requestToken: { | ||
oauth_token: 'reqtoken', | ||
oauth_token_secret: 'reqsecret', | ||
}, | ||
accessToken: { | ||
oauth_token: 'atoken', | ||
oauth_token_secret: 'asecret', | ||
}, | ||
oauth_session_handle: 'sessionHandle' | ||
}; | ||
xeroConfig = { | ||
appType: 'private', | ||
consumerKey: 'RDGDV41TRLQZDFSDX96TKQ2KRJIW4C', | ||
consumerSecret: 'DJ3CMGDB0DIIA9DNEEJMRLZG0BWE7Y', | ||
privateKeyPath: privateKey_helpers_1.validTestCertPath() | ||
}; | ||
oAuth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, inMemoryOAuthFF.newFactory()); | ||
oAuth1HttpClient.setState(oauthState); | ||
xeroClient = new TestAPIClient_1.TestAPIClient(xeroConfig, oAuth1HttpClient); | ||
oAuth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, oauthState, inMemoryOAuthFF.newFactory()); | ||
xeroClient = new TestAPIClient_1.TestAPIClient(xeroConfig, null, oAuth1HttpClient); | ||
return [2 /*return*/]; | ||
@@ -94,4 +91,4 @@ }); | ||
// TODO { verb: 'writeUTF8ResponseToStream', underlyingMethod: 'get', methodUnderTest: () => xeroClient.oauth1Client.writeUTF8ResponseToStream('/any-endpoint', 'mime/type', null) }, | ||
{ verb: 'getUnauthorisedRequestToken', underlyingMethod: 'getOAuthRequestToken', methodUnderTest: function () { return xeroClient.oauth1Client.getUnauthorisedRequestToken(); } }, | ||
{ verb: 'swapRequestTokenforAccessToken', underlyingMethod: 'getOAuthAccessToken', methodUnderTest: function () { return xeroClient.oauth1Client.swapRequestTokenforAccessToken('any-token'); } }, | ||
{ verb: 'getUnauthorisedRequestToken', underlyingMethod: 'getOAuthRequestToken', methodUnderTest: function () { return xeroClient.oauth1Client.getRequestToken(); } }, | ||
{ verb: 'swapRequestTokenforAccessToken', underlyingMethod: 'getOAuthAccessToken', methodUnderTest: function () { return xeroClient.oauth1Client.swapRequestTokenforAccessToken(requestToken, 'any-token'); } }, | ||
{ verb: 'refreshAccessToken', underlyingMethod: '_performSecureRequest', methodUnderTest: function () { return xeroClient.oauth1Client.refreshAccessToken(); } } | ||
@@ -98,0 +95,0 @@ ]; |
@@ -21,3 +21,3 @@ import { IOAuth1Configuration } from '../../OAuth1HttpClient'; | ||
private lastRequestedBody; | ||
private returnOauth_expires_in; | ||
private oauth_expires_in; | ||
_headers: any; | ||
@@ -39,5 +39,5 @@ constructor(config?: IOAuth1Configuration); | ||
getOAuthRequestToken(callback: (err: any, oauth_token: string, oauth_token_secret: string, result: any) => any): Promise<void>; | ||
set__performSecureRequest(oauth_token: string, oauth_secret: string, sessionHandle?: string): void; | ||
set__performSecureRequest(oauth_token: string, oauth_secret: string, sessionHandle?: string, sessionExpires?: string): void; | ||
_performSecureRequest(oauth_token: string, oauth_token_secret: string, verb: string, oauthAccessTokenPath: string, extraParams: any, something: any, something2: any, callback: (err: any, response: any) => any): Promise<void>; | ||
getOAuthAccessToken(authedToken: string, authedSecret: string, oauthVerifier: any, callback: (err: any, oauth_token: string, oauth_token_secret: string, result: any) => any): Promise<void>; | ||
} |
@@ -74,3 +74,3 @@ "use strict"; | ||
this.lastRequestedBody = null; | ||
this.returnOauth_expires_in = null; | ||
this.oauth_expires_in = null; | ||
} | ||
@@ -105,3 +105,3 @@ InMemoryOAuthLib.prototype.setConfig = function (config) { | ||
this.returnSessionHandle = sessionHandle; | ||
this.returnOauth_expires_in = oauth_expires_in; | ||
this.oauth_expires_in = oauth_expires_in; | ||
}; | ||
@@ -185,6 +185,7 @@ InMemoryOAuthLib.prototype.lastRequestedHadBody = function (expectedBody) { | ||
}; | ||
InMemoryOAuthLib.prototype.set__performSecureRequest = function (oauth_token, oauth_secret, sessionHandle) { | ||
InMemoryOAuthLib.prototype.set__performSecureRequest = function (oauth_token, oauth_secret, sessionHandle, sessionExpires) { | ||
this.returnAuthorisedToken = oauth_token; | ||
this.returnAuthorisedSecret = oauth_secret; | ||
this.returnSessionHandle = sessionHandle; | ||
this.oauth_expires_in = sessionExpires; | ||
}; | ||
@@ -195,3 +196,3 @@ InMemoryOAuthLib.prototype._performSecureRequest = function (oauth_token, oauth_token_secret, verb, oauthAccessTokenPath, extraParams, something, something2, callback) { | ||
this.lastCalledMethod = '_performSecureRequest'; | ||
callback(this.err, "oauth_session_handle=" + this.returnSessionHandle + "&oauth_token_secret=" + this.returnAuthorisedSecret + "&oauth_token=" + this.returnAuthorisedToken); | ||
callback(this.err, "oauth_session_handle=" + this.returnSessionHandle + "&oauth_token_secret=" + this.returnAuthorisedSecret + "&oauth_token=" + this.returnAuthorisedToken + "&oauth_expires_in=" + this.oauth_expires_in); | ||
return [2 /*return*/]; | ||
@@ -205,3 +206,3 @@ }); | ||
this.lastCalledMethod = 'getOAuthAccessToken'; | ||
callback(this.err, this.returnAuthorisedToken, this.returnAuthorisedSecret, { oauth_session_handle: this.returnSessionHandle, oauth_expires_in: this.returnOauth_expires_in }); | ||
callback(this.err, this.returnAuthorisedToken, this.returnAuthorisedSecret, { oauth_session_handle: this.returnSessionHandle, oauth_expires_in: this.oauth_expires_in }); | ||
return [2 /*return*/]; | ||
@@ -208,0 +209,0 @@ }); |
import { BaseAPIClient, IXeroClientConfiguration } from '../../BaseAPIClient'; | ||
import { IOAuth1HttpClient } from '../../OAuth1HttpClient'; | ||
import { IOAuth1HttpClient, IOAuth1State } from '../../OAuth1HttpClient'; | ||
export declare class TestAPIClient extends BaseAPIClient { | ||
constructor(xeroConfig: IXeroClientConfiguration, _oauthClient?: IOAuth1HttpClient); | ||
constructor(xeroConfig: IXeroClientConfiguration, authState?: IOAuth1State, _oauthClient?: IOAuth1HttpClient); | ||
} |
@@ -16,4 +16,4 @@ "use strict"; | ||
__extends(TestAPIClient, _super); | ||
function TestAPIClient(xeroConfig, _oauthClient) { | ||
return _super.call(this, xeroConfig, {}, _oauthClient) || this; | ||
function TestAPIClient(xeroConfig, authState, _oauthClient) { | ||
return _super.call(this, xeroConfig, authState, {}, _oauthClient) || this; | ||
} | ||
@@ -20,0 +20,0 @@ return TestAPIClient; |
@@ -49,11 +49,9 @@ "use strict"; | ||
var OAuth1HttpClient_1 = require("../OAuth1HttpClient"); | ||
var requestToken = { | ||
oauth_token: 'test3', | ||
oauth_token_secret: 'test4' | ||
}; | ||
var defaultState = { | ||
requestToken: { | ||
oauth_token: 'test3', | ||
oauth_token_secret: 'test4' | ||
}, | ||
accessToken: { | ||
oauth_token: 'test7', | ||
oauth_token_secret: 'test8' | ||
}, | ||
oauth_token: 'test7', | ||
oauth_token_secret: 'test8', | ||
oauth_session_handle: 'test9' | ||
@@ -79,56 +77,30 @@ }; | ||
beforeEach(function () { | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig); | ||
oauth1HttpClient.setState(defaultState); | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, defaultState); | ||
}); | ||
it('matches what it was set to', function () { | ||
expect(oauth1HttpClient.getState()).toEqual(defaultState); | ||
expect(oauth1HttpClient._state).toEqual(defaultState); | ||
}); | ||
it('only overrides the accessToken keys', function () { | ||
oauth1HttpClient.setState({ | ||
accessToken: { oauth_token: 'something new', oauth_token_secret: 'something borrowed' } | ||
var client = oauth1HttpClient; | ||
client.setState({ | ||
oauth_token: 'something new', oauth_token_secret: 'something borrowed' | ||
}); | ||
expect(oauth1HttpClient.getState()).not.toEqual(defaultState); | ||
expect(oauth1HttpClient.getState()).toEqual({ | ||
requestToken: { | ||
oauth_token: 'test3', | ||
oauth_token_secret: 'test4' | ||
}, | ||
accessToken: { | ||
oauth_token: 'something new', | ||
oauth_token_secret: 'something borrowed' | ||
}, | ||
expect(client._state).not.toEqual(defaultState); | ||
expect(client._state).toEqual({ | ||
oauth_token: 'something new', | ||
oauth_token_secret: 'something borrowed', | ||
oauth_session_handle: 'test9' | ||
}); | ||
}); | ||
it('only overrides the requestToken keys', function () { | ||
oauth1HttpClient.setState({ oauth_session_handle: 'yoyo' }); | ||
expect(oauth1HttpClient.getState()).not.toEqual(defaultState); | ||
expect(oauth1HttpClient.getState()).toEqual({ | ||
requestToken: { | ||
oauth_token: 'test3', | ||
oauth_token_secret: 'test4' | ||
}, | ||
accessToken: { | ||
oauth_token: 'test7', | ||
oauth_token_secret: 'test8' | ||
}, | ||
it('only overrides the oauth_session_handle keys', function () { | ||
var client = oauth1HttpClient; | ||
client.setState({ | ||
oauth_session_handle: 'yoyo' | ||
}); | ||
}); | ||
it('only overrides the oauth_session_handle keys', function () { | ||
oauth1HttpClient.setState({ | ||
requestToken: { oauth_token: 'something new', oauth_token_secret: 'something borrowed' } | ||
expect(client._state).not.toEqual(defaultState); | ||
expect(client._state).toEqual({ | ||
oauth_token: 'test7', | ||
oauth_token_secret: 'test8', | ||
oauth_session_handle: 'yoyo' | ||
}); | ||
expect(oauth1HttpClient.getState()).not.toEqual(defaultState); | ||
expect(oauth1HttpClient.getState()).toEqual({ | ||
requestToken: { | ||
oauth_token: 'something new', | ||
oauth_token_secret: 'something borrowed' | ||
}, | ||
accessToken: { | ||
oauth_token: 'test7', | ||
oauth_token_secret: 'test8' | ||
}, | ||
oauth_session_handle: 'test9' | ||
}); | ||
}); | ||
@@ -139,4 +111,3 @@ }); | ||
return __generator(this, function (_a) { | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, inMemoryOAuthLib.newFactory()); | ||
oauth1HttpClient.setState(defaultState); | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, defaultState, inMemoryOAuthLib.newFactory()); | ||
return [2 /*return*/]; | ||
@@ -146,6 +117,7 @@ }); | ||
it('it builds the authorise url', function () { | ||
expect(oauth1HttpClient.buildAuthoriseUrl()).toEqual("abu/oauth/Authorize?oauth_token=test3"); | ||
expect(oauth1HttpClient.buildAuthoriseUrl(requestToken)).toEqual("abu/oauth/Authorize?oauth_token=test3"); | ||
}); | ||
}); | ||
describe('and getting unauthorisedRequestTokens', function () { | ||
describe('and getting RequestTokens', function () { | ||
var token; | ||
beforeEach(function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -155,7 +127,7 @@ return __generator(this, function (_a) { | ||
case 0: | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, inMemoryOAuthLib.newFactory()); | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, defaultState, inMemoryOAuthLib.newFactory()); | ||
inMemoryOAuthLib.inMemoryOAuthLib.set_getOAuthRequestToken('aaa', 'bbb'); | ||
return [4 /*yield*/, oauth1HttpClient.getUnauthorisedRequestToken()]; | ||
return [4 /*yield*/, oauth1HttpClient.getRequestToken()]; | ||
case 1: | ||
_a.sent(); | ||
token = _a.sent(); | ||
return [2 /*return*/]; | ||
@@ -165,9 +137,9 @@ } | ||
}); }); | ||
it('sets expected state', function () { | ||
var state = oauth1HttpClient.getState(); | ||
expect(state.requestToken.oauth_token).toBe('aaa'); | ||
expect(state.requestToken.oauth_token_secret).toBe('bbb'); | ||
it('token is returned', function () { | ||
expect(token.oauth_token).toBe('aaa'); | ||
expect(token.oauth_token_secret).toBe('bbb'); | ||
}); | ||
}); | ||
describe('and swapping request for access token', function () { | ||
var authState; | ||
beforeAll(function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -178,8 +150,7 @@ return __generator(this, function (_a) { | ||
inMemoryOAuthLib.inMemoryOAuthLib.reset(); | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, inMemoryOAuthLib.newFactory()); | ||
oauth1HttpClient.setState(defaultState); | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, defaultState, inMemoryOAuthLib.newFactory()); | ||
inMemoryOAuthLib.inMemoryOAuthLib.set_SwapRequestTokenforAccessToken("access+token", "access+secret", '1800'); | ||
return [4 /*yield*/, oauth1HttpClient.swapRequestTokenforAccessToken('1234')]; | ||
return [4 /*yield*/, oauth1HttpClient.swapRequestTokenforAccessToken(requestToken, '1234')]; | ||
case 1: | ||
_a.sent(); | ||
authState = _a.sent(); | ||
return [2 /*return*/]; | ||
@@ -189,12 +160,15 @@ } | ||
}); }); | ||
it('sets expected state', function () { | ||
expect(oauth1HttpClient.getState().accessToken) | ||
.toMatchObject({ oauth_token: 'access+token', oauth_token_secret: 'access+secret' }); | ||
it('returns and sets expected state', function () { | ||
var expectedState = { oauth_token: 'access+token', oauth_token_secret: 'access+secret' }; | ||
var client = oauth1HttpClient; | ||
expect(authState).toMatchObject(expectedState); | ||
expect(client._state).toMatchObject(expectedState); | ||
var timeObject = new Date(); | ||
var expDate = new Date(timeObject.getTime() + (1800 * 1000)); | ||
// Removes seconds from dates... | ||
expect(oauth1HttpClient.getState().oauth_expires_at.setSeconds(0, 0)).toEqual(expDate.setSeconds(0, 0)); | ||
expect(client._state.oauth_expires_at.setSeconds(0, 0)).toEqual(expDate.setSeconds(0, 0)); | ||
}); | ||
}); | ||
describe('and refreshing authorized request token', function () { | ||
var authState; | ||
beforeAll(function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -204,8 +178,7 @@ return __generator(this, function (_a) { | ||
case 0: | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, inMemoryOAuthLib.newFactory()); | ||
oauth1HttpClient.setState(defaultState); | ||
inMemoryOAuthLib.inMemoryOAuthLib.set__performSecureRequest("access#token", "access#secret", 'session#handle'); | ||
oauth1HttpClient = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, defaultState, inMemoryOAuthLib.newFactory()); | ||
inMemoryOAuthLib.inMemoryOAuthLib.set__performSecureRequest("access#token", "access#secret", 'session#handle', '1800'); | ||
return [4 /*yield*/, oauth1HttpClient.refreshAccessToken()]; | ||
case 1: | ||
_a.sent(); | ||
authState = _a.sent(); | ||
return [2 /*return*/]; | ||
@@ -215,8 +188,14 @@ } | ||
}); }); | ||
it('sets expected state', function () { | ||
expect(oauth1HttpClient.getState().oauth_session_handle).toBe('session#handle'); | ||
expect(oauth1HttpClient.getState().accessToken).toMatchObject({ | ||
it('returns sets expected state', function () { | ||
var currentMilliseconds = new Date().getTime(); | ||
var expDate = new Date(currentMilliseconds + (1800 * 1000)); | ||
var expectedState = { | ||
oauth_token: "access#token", | ||
oauth_token_secret: "access#secret" | ||
}); | ||
oauth_token_secret: "access#secret", | ||
oauth_session_handle: 'session#handle', | ||
}; | ||
expect(authState).toMatchObject(expectedState); | ||
expect(oauth1HttpClient._state).toMatchObject(expectedState); | ||
// Removes seconds from dates... | ||
expect(authState.oauth_expires_at.setSeconds(0, 0)).toEqual(expDate.setSeconds(0, 0)); | ||
}); | ||
@@ -223,0 +202,0 @@ }); |
/// <reference types="node" /> | ||
/** @internalapi */ | ||
/** This second comment is required for typedoc to recognise the WHOLE FILE as @internalapi */ | ||
import { IOAuth1HttpClient } from './OAuth1HttpClient'; | ||
import { IOAuth1HttpClient, IOAuth1State } from './OAuth1HttpClient'; | ||
import * as fs from 'fs'; | ||
@@ -45,3 +45,3 @@ import { AttachmentsResponse } from '../AccountingAPI-types'; | ||
readonly oauth1Client: IOAuth1HttpClient; | ||
constructor(xeroConfig: IXeroClientConfiguration, apiConfig?: IApiConfiguration, oauth1Client?: IOAuth1HttpClient); | ||
constructor(xeroConfig: IXeroClientConfiguration, authState?: IOAuth1State, apiConfig?: IApiConfiguration, oauth1Client?: IOAuth1HttpClient); | ||
} |
@@ -8,3 +8,4 @@ "use strict"; | ||
var BaseAPIClient = /** @class */ (function () { | ||
function BaseAPIClient(xeroConfig, apiConfig, oauth1Client) { | ||
function BaseAPIClient(xeroConfig, authState, apiConfig, oauth1Client) { | ||
if (authState === void 0) { authState = null; } | ||
if (apiConfig === void 0) { apiConfig = {}; } | ||
@@ -18,4 +19,6 @@ if (oauth1Client === void 0) { oauth1Client = null; } | ||
var oauthConfig = config_helper_1.mapConfig(xeroConfig, apiConfig); | ||
this.oauth1Client = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig); | ||
this.oauth1Client.setState(config_helper_1.mapState(xeroConfig)); // only affects private and partner apps | ||
if (!authState) { | ||
authState = config_helper_1.mapState(xeroConfig); | ||
} | ||
this.oauth1Client = new OAuth1HttpClient_1.OAuth1HttpClient(oauthConfig, authState); | ||
} | ||
@@ -22,0 +25,0 @@ } |
@@ -5,3 +5,3 @@ /** @internalapi */ | ||
import { IOAuth1Configuration, IOAuth1State } from './OAuth1HttpClient'; | ||
export declare function mapState(xeroConfig: IXeroClientConfiguration): Partial<IOAuth1State>; | ||
export declare function mapState(xeroConfig: IXeroClientConfiguration): IOAuth1State; | ||
export declare function mapConfig(xeroConfig: IXeroClientConfiguration, apiConfig: IApiConfiguration): IOAuth1Configuration; |
@@ -13,13 +13,11 @@ "use strict"; | ||
return { | ||
accessToken: { | ||
oauth_token: xeroConfig.consumerKey, | ||
oauth_token_secret: cert, | ||
} | ||
oauth_token: xeroConfig.consumerKey, | ||
oauth_token_secret: cert | ||
}; | ||
} | ||
else if (xeroConfig.appType == 'public') { | ||
return {}; | ||
return null; | ||
} | ||
else if (xeroConfig.appType == 'partner') { | ||
return {}; | ||
return null; | ||
} | ||
@@ -26,0 +24,0 @@ else { |
@@ -13,6 +13,4 @@ /// <reference types="node" /> | ||
} | ||
export interface IOAuth1State { | ||
requestToken: IToken; | ||
accessToken: IToken; | ||
oauth_session_handle: string; | ||
export interface IOAuth1State extends IToken { | ||
oauth_session_handle?: string; | ||
oauth_expires_at?: Date; | ||
@@ -35,8 +33,6 @@ } | ||
agent?: http.Agent; | ||
getState(): IOAuth1State; | ||
setState(state: Partial<IOAuth1State>): void; | ||
getUnauthorisedRequestToken(): Promise<void>; | ||
buildAuthoriseUrl(): string; | ||
swapRequestTokenforAccessToken(oauth_verifier: string): Promise<void>; | ||
refreshAccessToken(): Promise<void>; | ||
getRequestToken(): Promise<IToken>; | ||
buildAuthoriseUrl(requestToken: IToken): string; | ||
swapRequestTokenforAccessToken(requestToken: IToken, oauth_verifier: string): Promise<IOAuth1State>; | ||
refreshAccessToken(): Promise<IOAuth1State>; | ||
} | ||
@@ -53,7 +49,7 @@ export interface IOAuth1HttpClient extends IHttpClient, IOAuth1Client { | ||
private resetToDefaultHeaders(); | ||
constructor(config: IOAuth1Configuration, oAuthLibFactory?: (config: IOAuth1Configuration) => typeof OAuth); | ||
getUnauthorisedRequestToken: () => Promise<void>; | ||
buildAuthoriseUrl: () => string; | ||
swapRequestTokenforAccessToken: (oauth_verifier: string) => Promise<void>; | ||
refreshAccessToken: () => Promise<void>; | ||
constructor(config: IOAuth1Configuration, authState?: IOAuth1State, oAuthLibFactory?: (config: IOAuth1Configuration) => typeof OAuth); | ||
getRequestToken: () => Promise<IToken>; | ||
buildAuthoriseUrl: (requestToken: IToken) => string; | ||
swapRequestTokenforAccessToken: (requestToken: IToken, oauth_verifier: string) => Promise<IOAuth1State>; | ||
refreshAccessToken: () => Promise<IOAuth1State>; | ||
writeUTF8ResponseToStream: (endpoint: string, mimeType: string, writeStream: fs.WriteStream) => Promise<void>; | ||
@@ -75,6 +71,5 @@ writeBinaryResponseToStream: (endpoint: string, mimeType: string, writeStream: fs.WriteStream) => Promise<void>; | ||
}) => Promise<T>; | ||
getState(): IOAuth1State; | ||
setState(newState: Partial<IOAuth1State>): void; | ||
private setState(newState); | ||
private assertAccessTokenIsSet(); | ||
private _createHttpClientWithProxySupport(port, hostname, method, path, headers, sslEnabled?); | ||
} |
@@ -55,11 +55,7 @@ "use strict"; | ||
var OAuth1HttpClient = /** @class */ (function () { | ||
function OAuth1HttpClient(config, oAuthLibFactory) { | ||
function OAuth1HttpClient(config, authState, oAuthLibFactory) { | ||
var _this = this; | ||
this.config = config; | ||
this.oAuthLibFactory = oAuthLibFactory; | ||
this._state = { | ||
requestToken: null, | ||
accessToken: null, | ||
oauth_session_handle: null | ||
}; | ||
this._state = null; | ||
this.agent = null; | ||
@@ -70,3 +66,3 @@ this._defaultHeaders = { | ||
}; | ||
this.getUnauthorisedRequestToken = function () { return __awaiter(_this, void 0, void 0, function () { | ||
this.getRequestToken = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
@@ -78,12 +74,9 @@ return __generator(this, function (_a) { | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data) : err); | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, null) : err); | ||
} | ||
else { | ||
_this.setState({ | ||
requestToken: { | ||
oauth_token: oauth_token, | ||
oauth_token_secret: oauth_token_secret | ||
} | ||
resolve({ | ||
oauth_token: oauth_token, | ||
oauth_token_secret: oauth_token_secret | ||
}); | ||
resolve(); | ||
} | ||
@@ -94,6 +87,6 @@ }); | ||
}); }; | ||
this.buildAuthoriseUrl = function () { | ||
return _this.config.apiBaseUrl + "/oauth/Authorize?oauth_token=" + _this._state.requestToken.oauth_token; | ||
this.buildAuthoriseUrl = function (requestToken) { | ||
return _this.config.apiBaseUrl + "/oauth/Authorize?oauth_token=" + requestToken.oauth_token; | ||
}; | ||
this.swapRequestTokenforAccessToken = function (oauth_verifier) { return __awaiter(_this, void 0, void 0, function () { | ||
this.swapRequestTokenforAccessToken = function (requestToken, oauth_verifier) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
@@ -103,5 +96,5 @@ return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.oauthLib.getOAuthAccessToken(_this._state.requestToken.oauth_token, _this._state.requestToken.oauth_token_secret, oauth_verifier, function (err, oauth_token, oauth_token_secret, results) { | ||
_this.oauthLib.getOAuthAccessToken(requestToken.oauth_token, requestToken.oauth_token_secret, oauth_verifier, function (err, oauth_token, oauth_token_secret, results) { | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data) : err); | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, null) : err); | ||
} | ||
@@ -111,11 +104,10 @@ else { | ||
var expDate = new Date(currentMilliseconds + (results.oauth_expires_in * 1000)); | ||
_this.setState({ | ||
accessToken: { | ||
oauth_token: oauth_token, | ||
oauth_token_secret: oauth_token_secret | ||
}, | ||
var oauthState = { | ||
oauth_token: oauth_token, | ||
oauth_token_secret: oauth_token_secret, | ||
oauth_session_handle: results.oauth_session_handle, | ||
oauth_expires_at: expDate | ||
}); | ||
resolve(); | ||
}; | ||
_this.setState(oauthState); | ||
resolve(oauthState); | ||
} | ||
@@ -131,14 +123,18 @@ }); | ||
// We're accessing this "private" method as the lib does not allow refresh with oauth_session_handle. | ||
_this.oauthLib._performSecureRequest(_this._state.accessToken.oauth_token, _this._state.accessToken.oauth_token_secret, 'POST', _this.config.apiBaseUrl + _this.config.oauthAccessTokenPath, { oauth_session_handle: _this._state.oauth_session_handle }, null, null, function (err, data) { | ||
_this.oauthLib._performSecureRequest(_this._state.oauth_token, _this._state.oauth_token_secret, 'POST', _this.config.apiBaseUrl + _this.config.oauthAccessTokenPath, { oauth_session_handle: _this._state.oauth_session_handle }, null, null, function (err, data, response) { | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data) : err); | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, response ? response.headers : null) : err); | ||
} | ||
else { | ||
var results = querystring.parse(data); | ||
var newAccessToken = { | ||
var currentMilliseconds = new Date().getTime(); | ||
var expDate = new Date(currentMilliseconds + (results.oauth_expires_in * 1000)); | ||
var oauthState = { | ||
oauth_token: results.oauth_token, | ||
oauth_token_secret: results.oauth_token_secret | ||
oauth_token_secret: results.oauth_token_secret, | ||
oauth_session_handle: results.oauth_session_handle, | ||
oauth_expires_at: expDate | ||
}; | ||
_this.setState({ accessToken: newAccessToken, oauth_session_handle: results.oauth_session_handle }); | ||
resolve(); | ||
_this.setState(oauthState); | ||
resolve(oauthState); | ||
} | ||
@@ -154,3 +150,3 @@ }); | ||
var oauthForPdf = _this.oAuthLibFactory(__assign({}, _this.config, { accept: mimeType })); | ||
var request = oauthForPdf.get(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, _this._state.accessToken.oauth_token, _this._state.accessToken.oauth_token_secret); | ||
var request = oauthForPdf.get(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, _this._state.oauth_token, _this._state.oauth_token_secret); | ||
request.addListener('response', function (response) { | ||
@@ -174,6 +170,6 @@ response.addListener('data', function (chunk) { | ||
var forPDF = _this.oAuthLibFactory(__assign({}, _this.config, { accept: mimeType })); | ||
_this._OURperformSecureRequest(_this._state.accessToken.oauth_token, _this._state.accessToken.oauth_token_secret, 'GET', _this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, function (err, data, httpResponse) { | ||
_this._OURperformSecureRequest(_this._state.oauth_token, _this._state.oauth_token_secret, 'GET', _this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, function (err, data, httpResponse) { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data) : err); | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse.headers) : err); | ||
} | ||
@@ -234,2 +230,5 @@ else { | ||
} | ||
else { | ||
callback({ statusCode: response.statusCode, data: data }, data, response); | ||
} | ||
} | ||
@@ -266,5 +265,5 @@ request.on('response', function (response) { | ||
_this.oauthLib.post(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_this._state.accessToken.oauth_token, _this._state.accessToken.oauth_token_secret, Buffer.concat(bufs), mimeType, function (err, data, httpResponse) { | ||
_this._state.oauth_token, _this._state.oauth_token_secret, Buffer.concat(bufs), mimeType, function (err, data, httpResponse) { | ||
if (err) { | ||
reject(new XeroError_1.XeroError(httpResponse.statusCode, data)); | ||
reject(new XeroError_1.XeroError(httpResponse.statusCode, data, httpResponse ? httpResponse.headers : null)); | ||
} | ||
@@ -287,6 +286,6 @@ else { | ||
_this.oauthLib.get(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_this._state.accessToken.oauth_token, _this._state.accessToken.oauth_token_secret, function (err, data, httpResponse) { | ||
_this._state.oauth_token, _this._state.oauth_token_secret, function (err, data, httpResponse) { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data) : err); | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
@@ -309,7 +308,7 @@ else { | ||
_this.oauthLib.put(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_this._state.accessToken.oauth_token, _this._state.accessToken.oauth_token_secret, JSON.stringify(body), // Had to do this not sure if there is another way | ||
_this._state.oauth_token, _this._state.oauth_token_secret, JSON.stringify(body), // Had to do this not sure if there is another way | ||
'application/json', function (err, data, httpResponse) { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data) : err); | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
@@ -332,7 +331,7 @@ else { | ||
_this.oauthLib.post(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_this._state.accessToken.oauth_token, _this._state.accessToken.oauth_token_secret, JSON.stringify(body), // Had to do this not sure if there is another way | ||
_this._state.oauth_token, _this._state.oauth_token_secret, JSON.stringify(body), // Had to do this not sure if there is another way | ||
'application/json', function (err, data, httpResponse) { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data) : err); | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
@@ -355,6 +354,6 @@ else { | ||
_this.oauthLib.delete(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_this._state.accessToken.oauth_token, _this._state.accessToken.oauth_token_secret, function (err, data, httpResponse) { | ||
_this._state.oauth_token, _this._state.oauth_token_secret, function (err, data, httpResponse) { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data) : err); | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
@@ -372,7 +371,5 @@ else { | ||
}); }; | ||
this._state = { | ||
requestToken: null, | ||
accessToken: null, | ||
oauth_session_handle: null | ||
}; | ||
if (authState) { | ||
this._state = authState; | ||
} | ||
if (!this.oAuthLibFactory) { | ||
@@ -404,5 +401,2 @@ this.oAuthLibFactory = function (passedInConfig) { | ||
}; | ||
OAuth1HttpClient.prototype.getState = function () { | ||
return this._state; | ||
}; | ||
OAuth1HttpClient.prototype.setState = function (newState) { | ||
@@ -412,3 +406,3 @@ this._state = __assign({}, this._state, newState); | ||
OAuth1HttpClient.prototype.assertAccessTokenIsSet = function () { | ||
if (!this._state.accessToken) { | ||
if (!this._state.oauth_token) { | ||
throw new Error('Missing access token. Acquire a new access token by following the oauth flow or call setState() to use an existing token.'); | ||
@@ -415,0 +409,0 @@ } |
import { IXeroClientConfiguration, BaseAPIClient } from './internals/BaseAPIClient'; | ||
import { IOAuth1HttpClient } from './internals/OAuth1HttpClient'; | ||
import { IOAuth1HttpClient, IOAuth1State } from './internals/OAuth1HttpClient'; | ||
export declare class PracticeAPIClient extends BaseAPIClient { | ||
constructor(options: IXeroClientConfiguration, _oAuth1HttpClient?: IOAuth1HttpClient); | ||
constructor(options: IXeroClientConfiguration, authState?: IOAuth1State, _oAuth1HttpClient?: IOAuth1HttpClient); | ||
} |
@@ -16,4 +16,4 @@ "use strict"; | ||
__extends(PracticeAPIClient, _super); | ||
function PracticeAPIClient(options, _oAuth1HttpClient) { | ||
return _super.call(this, options, { | ||
function PracticeAPIClient(options, authState, _oAuth1HttpClient) { | ||
return _super.call(this, options, authState, { | ||
tenantType: 'PRACTICE' | ||
@@ -20,0 +20,0 @@ }, _oAuth1HttpClient) || this; |
@@ -5,3 +5,3 @@ export declare class XeroError extends Error { | ||
readonly headers: any; | ||
constructor(statusCode: number, data: string, headers?: any); | ||
constructor(statusCode: number, data: string, headers: any); | ||
} |
@@ -19,9 +19,14 @@ "use strict"; | ||
var _this = this; | ||
var message = 'XeroError:'; | ||
var queryobj = querystring.parse(data); | ||
if (queryobj.oauth_problem && queryobj.oauth_problem_advice) { | ||
_this = _super.call(this, "XeroError: " + queryobj.oauth_problem + " (" + queryobj.oauth_problem_advice + ")") || this; | ||
if (statusCode == 503 && headers) { | ||
message += ' ' + (headers['x-rate-limit-problem'] || headers['X-Rate-Limit-Problem'] || ''); | ||
} | ||
message += " " + queryobj.oauth_problem + " (" + queryobj.oauth_problem_advice + ")"; | ||
} | ||
else { | ||
_this = _super.call(this, "XeroError: statusCode=" + statusCode + " data=" + data) || this; | ||
message += " statusCode=" + statusCode + " data=" + data; | ||
} | ||
_this = _super.call(this, message) || this; | ||
// https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 | ||
@@ -28,0 +33,0 @@ _this.__proto__ = _newTarget.prototype; |
{ | ||
"name": "xero-node", | ||
"version": "3.0.0-alpha.5", | ||
"version": "3.0.0-alpha.6", | ||
"description": "NodeJS Client for the Xero API, supporting Public, Private and Partner Apps", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
1625664
177
9963
20