UNPKG

xero-node

Version:

Xero NodeJS OAuth 2.0 client for xero-node

841 lines (840 loc) 934 kB
"use strict"; /** * Accounting API * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 2.0.0 * Contact: api@xero.com * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var localVarRequest = require("request"); var models_1 = require("../model/accounting/models"); var models_2 = require("../model/accounting/models"); var defaultBasePath = 'https://api.xero.com/api.xro/2.0'; // =============================================== // This file is autogenerated - Please do not edit // =============================================== var AccountingApiApiKeys; (function (AccountingApiApiKeys) { })(AccountingApiApiKeys = exports.AccountingApiApiKeys || (exports.AccountingApiApiKeys = {})); var AccountingApi = /** @class */ (function () { function AccountingApi(basePathOrUsername, password, basePath) { this._basePath = defaultBasePath; this.defaultHeaders = {}; this._useQuerystring = false; this.binaryHeaders = {}; this.authentications = { 'default': new models_1.VoidAuth(), 'OAuth2': new models_2.OAuth(), }; if (password) { if (basePath) { this.basePath = basePath; } } else { if (basePathOrUsername) { this.basePath = basePathOrUsername; } } } Object.defineProperty(AccountingApi.prototype, "useQuerystring", { set: function (value) { this._useQuerystring = value; }, enumerable: true, configurable: true }); Object.defineProperty(AccountingApi.prototype, "basePath", { get: function () { return this._basePath; }, set: function (basePath) { this._basePath = basePath; }, enumerable: true, configurable: true }); AccountingApi.prototype.setDefaultAuthentication = function (auth) { this.authentications.default = auth; }; AccountingApi.prototype.setApiKey = function (key, value) { this.authentications[AccountingApiApiKeys[key]].apiKey = value; }; Object.defineProperty(AccountingApi.prototype, "accessToken", { set: function (token) { this.authentications.OAuth2.accessToken = token; }, enumerable: true, configurable: true }); /** * * @summary Allows you to create a new chart of accounts * @param xeroTenantId Xero identifier for Tenant * @param account Request of type Account */ AccountingApi.prototype.createAccount = function (xeroTenantId, account, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/Accounts'; localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createAccount.'); } // verify required parameter 'account' is not null or undefined if (account === null || account === undefined) { throw new Error('Required parameter account was null or undefined when calling createAccount.'); } localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'PUT', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(account, "Account") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "Accounts"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @summary Allows you to create Attachment on Account * @param xeroTenantId Xero identifier for Tenant * @param accountID Unique identifier for Account object * @param fileName Name of the attachment * @param body Byte array of file in body of request */ AccountingApi.prototype.createAccountAttachmentByFileName = function (xeroTenantId, accountID, fileName, body, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/Accounts/{AccountID}/Attachments/{FileName}' .replace('{' + 'AccountID' + '}', encodeURIComponent(String(accountID))) .replace('{' + 'FileName' + '}', encodeURIComponent(String(fileName))); localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createAccountAttachmentByFileName.'); } // verify required parameter 'accountID' is not null or undefined if (accountID === null || accountID === undefined) { throw new Error('Required parameter accountID was null or undefined when calling createAccountAttachmentByFileName.'); } // verify required parameter 'fileName' is not null or undefined if (fileName === null || fileName === undefined) { throw new Error('Required parameter fileName was null or undefined when calling createAccountAttachmentByFileName.'); } // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createAccountAttachmentByFileName.'); } this.binaryHeaders = { 'Accept': 'application/json' }; Object.assign(localVarHeaderParams, this.binaryHeaders); localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'PUT', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(body, "string") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } }).then(function () { // Reads file stream as chunks so we can put it in the request body. // This collects the whole file into memory, which is why we do it _after_ authentication. return new Promise(function (resolve, reject) { var fileContents = []; body.on('data', function (chunk) { fileContents.push(chunk); }); body.on('end', function () { resolve(fileContents); }); body.on('error', function (err) { reject(err); }); }); }).then(function (fileContents) { localVarRequestOptions.body = fileContents; return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "Attachments"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @summary Allows you to create a spend or receive money transaction * @param xeroTenantId Xero identifier for Tenant * @param bankTransaction */ AccountingApi.prototype.createBankTransaction = function (xeroTenantId, bankTransaction, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/BankTransactions'; localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createBankTransaction.'); } // verify required parameter 'bankTransaction' is not null or undefined if (bankTransaction === null || bankTransaction === undefined) { throw new Error('Required parameter bankTransaction was null or undefined when calling createBankTransaction.'); } localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'PUT', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(bankTransaction, "BankTransaction") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "BankTransactions"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @summary Allows you to createa an Attachment on BankTransaction by Filename * @param xeroTenantId Xero identifier for Tenant * @param bankTransactionID Xero generated unique identifier for a bank transaction * @param fileName The name of the file being attached * @param body Byte array of file in body of request */ AccountingApi.prototype.createBankTransactionAttachmentByFileName = function (xeroTenantId, bankTransactionID, fileName, body, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/BankTransactions/{BankTransactionID}/Attachments/{FileName}' .replace('{' + 'BankTransactionID' + '}', encodeURIComponent(String(bankTransactionID))) .replace('{' + 'FileName' + '}', encodeURIComponent(String(fileName))); localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createBankTransactionAttachmentByFileName.'); } // verify required parameter 'bankTransactionID' is not null or undefined if (bankTransactionID === null || bankTransactionID === undefined) { throw new Error('Required parameter bankTransactionID was null or undefined when calling createBankTransactionAttachmentByFileName.'); } // verify required parameter 'fileName' is not null or undefined if (fileName === null || fileName === undefined) { throw new Error('Required parameter fileName was null or undefined when calling createBankTransactionAttachmentByFileName.'); } // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createBankTransactionAttachmentByFileName.'); } this.binaryHeaders = { 'Accept': 'application/json' }; Object.assign(localVarHeaderParams, this.binaryHeaders); localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'PUT', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(body, "string") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } }).then(function () { // Reads file stream as chunks so we can put it in the request body. // This collects the whole file into memory, which is why we do it _after_ authentication. return new Promise(function (resolve, reject) { var fileContents = []; body.on('data', function (chunk) { fileContents.push(chunk); }); body.on('end', function () { resolve(fileContents); }); body.on('error', function (err) { reject(err); }); }); }).then(function (fileContents) { localVarRequestOptions.body = fileContents; return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "Attachments"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @summary Allows you to create history record for a bank transactions * @param xeroTenantId Xero identifier for Tenant * @param bankTransactionID Xero generated unique identifier for a bank transaction * @param historyRecords */ AccountingApi.prototype.createBankTransactionHistoryRecord = function (xeroTenantId, bankTransactionID, historyRecords, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/BankTransactions/{BankTransactionID}/History' .replace('{' + 'BankTransactionID' + '}', encodeURIComponent(String(bankTransactionID))); localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createBankTransactionHistoryRecord.'); } // verify required parameter 'bankTransactionID' is not null or undefined if (bankTransactionID === null || bankTransactionID === undefined) { throw new Error('Required parameter bankTransactionID was null or undefined when calling createBankTransactionHistoryRecord.'); } // verify required parameter 'historyRecords' is not null or undefined if (historyRecords === null || historyRecords === undefined) { throw new Error('Required parameter historyRecords was null or undefined when calling createBankTransactionHistoryRecord.'); } localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'PUT', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(historyRecords, "HistoryRecords") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "HistoryRecords"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @summary Allows you to create a spend or receive money transaction * @param xeroTenantId Xero identifier for Tenant * @param bankTransactions * @param summarizeErrors response format that shows validation errors for each bank transaction */ AccountingApi.prototype.createBankTransactions = function (xeroTenantId, bankTransactions, summarizeErrors, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/BankTransactions'; localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createBankTransactions.'); } // verify required parameter 'bankTransactions' is not null or undefined if (bankTransactions === null || bankTransactions === undefined) { throw new Error('Required parameter bankTransactions was null or undefined when calling createBankTransactions.'); } if (summarizeErrors !== undefined) { localVarQueryParameters['SummarizeErrors'] = models_1.ObjectSerializer.serialize(summarizeErrors, "boolean"); } localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'POST', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(bankTransactions, "BankTransactions") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "BankTransactions"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @summary Allows you to create a bank transfers * @param xeroTenantId Xero identifier for Tenant * @param bankTransfers */ AccountingApi.prototype.createBankTransfer = function (xeroTenantId, bankTransfers, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/BankTransfers'; localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createBankTransfer.'); } // verify required parameter 'bankTransfers' is not null or undefined if (bankTransfers === null || bankTransfers === undefined) { throw new Error('Required parameter bankTransfers was null or undefined when calling createBankTransfer.'); } localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'PUT', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(bankTransfers, "BankTransfers") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "BankTransfers"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @param xeroTenantId Xero identifier for Tenant * @param bankTransferID Xero generated unique identifier for a bank transfer * @param fileName The name of the file being attached to a Bank Transfer * @param body Byte array of file in body of request */ AccountingApi.prototype.createBankTransferAttachmentByFileName = function (xeroTenantId, bankTransferID, fileName, body, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/BankTransfers/{BankTransferID}/Attachments/{FileName}' .replace('{' + 'BankTransferID' + '}', encodeURIComponent(String(bankTransferID))) .replace('{' + 'FileName' + '}', encodeURIComponent(String(fileName))); localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createBankTransferAttachmentByFileName.'); } // verify required parameter 'bankTransferID' is not null or undefined if (bankTransferID === null || bankTransferID === undefined) { throw new Error('Required parameter bankTransferID was null or undefined when calling createBankTransferAttachmentByFileName.'); } // verify required parameter 'fileName' is not null or undefined if (fileName === null || fileName === undefined) { throw new Error('Required parameter fileName was null or undefined when calling createBankTransferAttachmentByFileName.'); } // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createBankTransferAttachmentByFileName.'); } this.binaryHeaders = { 'Accept': 'application/json' }; Object.assign(localVarHeaderParams, this.binaryHeaders); localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'PUT', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(body, "string") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } }).then(function () { // Reads file stream as chunks so we can put it in the request body. // This collects the whole file into memory, which is why we do it _after_ authentication. return new Promise(function (resolve, reject) { var fileContents = []; body.on('data', function (chunk) { fileContents.push(chunk); }); body.on('end', function () { resolve(fileContents); }); body.on('error', function (err) { reject(err); }); }); }).then(function (fileContents) { localVarRequestOptions.body = fileContents; return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "Attachments"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @param xeroTenantId Xero identifier for Tenant * @param bankTransferID Xero generated unique identifier for a bank transfer * @param historyRecords */ AccountingApi.prototype.createBankTransferHistoryRecord = function (xeroTenantId, bankTransferID, historyRecords, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this; return __generator(this, function (_a) { localVarPath = this.basePath + '/BankTransfers/{BankTransferID}/History' .replace('{' + 'BankTransferID' + '}', encodeURIComponent(String(bankTransferID))); localVarQueryParameters = {}; localVarHeaderParams = Object.assign({}, this.defaultHeaders); localVarFormParams = {}; // verify required parameter 'xeroTenantId' is not null or undefined if (xeroTenantId === null || xeroTenantId === undefined) { throw new Error('Required parameter xeroTenantId was null or undefined when calling createBankTransferHistoryRecord.'); } // verify required parameter 'bankTransferID' is not null or undefined if (bankTransferID === null || bankTransferID === undefined) { throw new Error('Required parameter bankTransferID was null or undefined when calling createBankTransferHistoryRecord.'); } // verify required parameter 'historyRecords' is not null or undefined if (historyRecords === null || historyRecords === undefined) { throw new Error('Required parameter historyRecords was null or undefined when calling createBankTransferHistoryRecord.'); } localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string"); Object.assign(localVarHeaderParams, options.headers); localVarUseFormData = false; localVarRequestOptions = { method: 'PUT', qs: localVarQueryParameters, headers: localVarHeaderParams, uri: localVarPath, useQuerystring: this._useQuerystring, json: true, body: models_1.ObjectSerializer.serialize(historyRecords, "HistoryRecords") }; authenticationPromise = Promise.resolve(); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.OAuth2.applyToRequest(localVarRequestOptions); }); authenticationPromise = authenticationPromise.then(function () { return _this.authentications.default.applyToRequest(localVarRequestOptions); }); return [2 /*return*/, authenticationPromise.then(function () { if (Object.keys(localVarFormParams).length) { if (localVarUseFormData) { localVarRequestOptions.formData = localVarFormParams; } else { localVarRequestOptions.form = localVarFormParams; } } return new Promise(function (resolve, reject) { localVarRequest(localVarRequestOptions, function (error, response, body) { if (error) { reject(error); } else { body = models_1.ObjectSerializer.deserialize(body, "HistoryRecords"); if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) { resolve({ response: response, body: body }); } else { reject({ response: response, body: body }); } } }); }); })]; }); }); }; /** * * @summary Create one or many BatchPayments for invoices * @param xeroTenantId Xero identifier for Tenant * @param batchPayments Request of type BatchPayments containing a Payments array with one or more Payment objects */ AccountingApi.prototype.createBatchPayment = function (xeroTenantId, batchPayments, options) { if (options === void 0) { options = { headers: {} }; } return __awaiter(this, void 0, void 0, function () { var localVarPath, localVarQueryParameters, localVarHeaderParams, localVarFormParams, localVarUseFormData, localVarRequestOptions, authenticationPromise; var _this = this;