xero-node
Version:
Xero NodeJS OAuth 2.0 client for xero-node
523 lines • 30.3 kB
JavaScript
;
/**
* Xero Assets API
* The Assets API exposes fixed asset related functions of the Xero Accounting application and can be used for a variety of purposes such as creating assets, retrieving asset valuations etc.
*
* The version of the OpenAPI document: 12.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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssetApi = exports.AssetApiApiKeys = void 0;
const models_1 = require("../model/assets/models");
const ApiError_1 = require("../../model/ApiError");
const axios_1 = __importDefault(require("axios"));
const models_2 = require("../model/assets/models");
let defaultBasePath = 'https://api.xero.com/assets.xro/1.0';
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
var AssetApiApiKeys;
(function (AssetApiApiKeys) {
})(AssetApiApiKeys || (exports.AssetApiApiKeys = AssetApiApiKeys = {}));
class AssetApi {
constructor(basePathOrUsername, password, basePath) {
this._basePath = defaultBasePath;
this.defaultHeaders = { 'user-agent': 'xero-node-15.0.0' };
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;
}
}
}
set useQuerystring(value) {
this._useQuerystring = value;
}
set basePath(basePath) {
this._basePath = basePath;
}
get basePath() {
return this._basePath;
}
setDefaultAuthentication(auth) {
this.authentications.default = auth;
}
setApiKey(key, value) {
this.authentications[AssetApiApiKeys[key]].apiKey = value;
}
set accessToken(token) {
this.authentications.OAuth2.accessToken = token;
}
/**
* Adds an asset to the system
* @summary adds a fixed asset
* @param xeroTenantId Xero identifier for Tenant
* @param asset Fixed asset you are creating
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
*/
createAsset(xeroTenantId_1, asset_1, idempotencyKey_1) {
return __awaiter(this, arguments, void 0, function* (xeroTenantId, asset, idempotencyKey, options = { headers: {} }) {
const localVarPath = this.basePath + '/Assets';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this.defaultHeaders);
let localVarFormParams = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf") || acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// 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 createAsset.');
}
// verify required parameter 'asset' is not null or undefined
if (asset === null || asset === undefined) {
throw new Error('Required parameter asset was null or undefined when calling createAsset.');
}
localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = models_1.ObjectSerializer.serialize(idempotencyKey, "string");
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'POST',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: models_1.ObjectSerializer.serialize(asset, "Asset"),
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'Content-Type': 'multipart/form-data' });
}
else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'content-type': 'application/x-www-form-urlencoded' });
}
}
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
let body = null;
try {
const response = yield (0, axios_1.default)(localVarRequestOptions);
body = models_1.ObjectSerializer.deserialize(response.data, "Asset");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
}
else {
reject({ response: response, body: body });
}
}
catch (error) {
const errorResponse = new ApiError_1.ApiError(error);
reject(JSON.stringify(errorResponse.generateError()));
}
}));
});
});
}
/**
* Adds an fixed asset type to the system
* @summary adds a fixed asset type
* @param xeroTenantId Xero identifier for Tenant
* @param assetType Asset type to add
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate processing. 128 character max.
*/
createAssetType(xeroTenantId_1, assetType_1, idempotencyKey_1) {
return __awaiter(this, arguments, void 0, function* (xeroTenantId, assetType, idempotencyKey, options = { headers: {} }) {
const localVarPath = this.basePath + '/AssetTypes';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this.defaultHeaders);
let localVarFormParams = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf") || acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// 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 createAssetType.');
}
// verify required parameter 'assetType' is not null or undefined
if (assetType === null || assetType === undefined) {
throw new Error('Required parameter assetType was null or undefined when calling createAssetType.');
}
localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Idempotency-Key'] = models_1.ObjectSerializer.serialize(idempotencyKey, "string");
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'POST',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: models_1.ObjectSerializer.serialize(assetType, "AssetType"),
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'Content-Type': 'multipart/form-data' });
}
else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'content-type': 'application/x-www-form-urlencoded' });
}
}
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
let body = null;
try {
const response = yield (0, axios_1.default)(localVarRequestOptions);
body = models_1.ObjectSerializer.deserialize(response.data, "AssetType");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
}
else {
reject({ response: response, body: body });
}
}
catch (error) {
const errorResponse = new ApiError_1.ApiError(error);
reject(JSON.stringify(errorResponse.generateError()));
}
}));
});
});
}
/**
* By passing in the appropriate asset id, you can search for a specific fixed asset in the system
* @summary Retrieves fixed asset by id
* @param xeroTenantId Xero identifier for Tenant
* @param id fixed asset id for single object
*/
getAssetById(xeroTenantId_1, id_1) {
return __awaiter(this, arguments, void 0, function* (xeroTenantId, id, options = { headers: {} }) {
const localVarPath = this.basePath + '/Assets/{id}'
.replace('{' + 'id' + '}', encodeURIComponent(String(id)));
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this.defaultHeaders);
let localVarFormParams = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf") || acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// 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 getAssetById.');
}
// verify required parameter 'id' is not null or undefined
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getAssetById.');
}
localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: {},
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'Content-Type': 'multipart/form-data' });
}
else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'content-type': 'application/x-www-form-urlencoded' });
}
}
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
let body = null;
try {
const response = yield (0, axios_1.default)(localVarRequestOptions);
body = models_1.ObjectSerializer.deserialize(response.data, "Asset");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
}
else {
reject({ response: response, body: body });
}
}
catch (error) {
const errorResponse = new ApiError_1.ApiError(error);
reject(JSON.stringify(errorResponse.generateError()));
}
}));
});
});
}
/**
* By passing in the appropriate options, you can search for available fixed asset types in the system
* @summary searches fixed asset settings
* @param xeroTenantId Xero identifier for Tenant
*/
getAssetSettings(xeroTenantId_1) {
return __awaiter(this, arguments, void 0, function* (xeroTenantId, options = { headers: {} }) {
const localVarPath = this.basePath + '/Settings';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this.defaultHeaders);
let localVarFormParams = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf") || acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// 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 getAssetSettings.');
}
localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: {},
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'Content-Type': 'multipart/form-data' });
}
else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'content-type': 'application/x-www-form-urlencoded' });
}
}
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
let body = null;
try {
const response = yield (0, axios_1.default)(localVarRequestOptions);
body = models_1.ObjectSerializer.deserialize(response.data, "Setting");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
}
else {
reject({ response: response, body: body });
}
}
catch (error) {
const errorResponse = new ApiError_1.ApiError(error);
reject(JSON.stringify(errorResponse.generateError()));
}
}));
});
});
}
/**
* By passing in the appropriate options, you can search for available fixed asset types in the system
* @summary searches fixed asset types
* @param xeroTenantId Xero identifier for Tenant
*/
getAssetTypes(xeroTenantId_1) {
return __awaiter(this, arguments, void 0, function* (xeroTenantId, options = { headers: {} }) {
const localVarPath = this.basePath + '/AssetTypes';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this.defaultHeaders);
let localVarFormParams = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf") || acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// 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 getAssetTypes.');
}
localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: {},
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'Content-Type': 'multipart/form-data' });
}
else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'content-type': 'application/x-www-form-urlencoded' });
}
}
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
let body = null;
try {
const response = yield (0, axios_1.default)(localVarRequestOptions);
body = models_1.ObjectSerializer.deserialize(response.data, "Array<AssetType>");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
}
else {
reject({ response: response, body: body });
}
}
catch (error) {
const errorResponse = new ApiError_1.ApiError(error);
reject(JSON.stringify(errorResponse.generateError()));
}
}));
});
});
}
/**
* By passing in the appropriate options, you can search for available fixed asset in the system
* @summary searches fixed asset
* @param xeroTenantId Xero identifier for Tenant
* @param status Required when retrieving a collection of assets. See Asset Status Codes
* @param page Results are paged. This specifies which page of the results to return. The default page is 1.
* @param pageSize The number of records returned per page. By default the number of records returned is 10.
* @param orderBy Requests can be ordered by AssetType, AssetName, AssetNumber, PurchaseDate and PurchasePrice. If the asset status is DISPOSED it also allows DisposalDate and DisposalPrice.
* @param sortDirection ASC or DESC
* @param filterBy A string that can be used to filter the list to only return assets containing the text. Checks it against the AssetName, AssetNumber, Description and AssetTypeName fields.
*/
getAssets(xeroTenantId_1, status_1, page_1, pageSize_1, orderBy_1, sortDirection_1, filterBy_1) {
return __awaiter(this, arguments, void 0, function* (xeroTenantId, status, page, pageSize, orderBy, sortDirection, filterBy, options = { headers: {} }) {
const localVarPath = this.basePath + '/Assets';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this.defaultHeaders);
let localVarFormParams = {};
let acceptHeadersFromSpec = [
"application/json"
];
const isBufferType = acceptHeadersFromSpec.includes("application/pdf") || acceptHeadersFromSpec.includes("application/octet-stream") || acceptHeadersFromSpec.includes("application/jpg");
const responseTypeOption = isBufferType ? "arraybuffer" : "json";
// 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 getAssets.');
}
// verify required parameter 'status' is not null or undefined
if (status === null || status === undefined) {
throw new Error('Required parameter status was null or undefined when calling getAssets.');
}
if (status !== undefined) {
localVarQueryParameters['status'] = models_1.ObjectSerializer.serialize(status, "AssetStatusQueryParam");
}
if (page !== undefined) {
localVarQueryParameters['page'] = models_1.ObjectSerializer.serialize(page, "number");
}
if (pageSize !== undefined) {
localVarQueryParameters['pageSize'] = models_1.ObjectSerializer.serialize(pageSize, "number");
}
if (orderBy !== undefined) {
localVarQueryParameters['orderBy'] = models_1.ObjectSerializer.serialize(orderBy, "'AssetType' | 'AssetName' | 'AssetNumber' | 'PurchaseDate' | 'PurchasePrice' | 'DisposalDate' | 'DisposalPrice'");
}
if (sortDirection !== undefined) {
localVarQueryParameters['sortDirection'] = models_1.ObjectSerializer.serialize(sortDirection, "'asc' | 'desc'");
}
if (filterBy !== undefined) {
localVarQueryParameters['filterBy'] = models_1.ObjectSerializer.serialize(filterBy, "string");
}
localVarHeaderParams['xero-tenant-id'] = models_1.ObjectSerializer.serialize(xeroTenantId, "string");
localVarHeaderParams['Accept'] = acceptHeadersFromSpec.join();
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let localVarRequestOptions = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
responseType: responseTypeOption,
data: {},
};
let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.OAuth2.applyToRequest(localVarRequestOptions));
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
return authenticationPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'Content-Type': 'multipart/form-data' });
}
else {
localVarRequestOptions.data = localVarFormParams;
localVarRequestOptions.headers = Object.assign(Object.assign({}, localVarRequestOptions.headers), { 'content-type': 'application/x-www-form-urlencoded' });
}
}
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
let body = null;
try {
const response = yield (0, axios_1.default)(localVarRequestOptions);
body = models_1.ObjectSerializer.deserialize(response.data, "Assets");
if (response.status && response.status >= 200 && response.status <= 299) {
resolve({ response: response, body: body });
}
else {
reject({ response: response, body: body });
}
}
catch (error) {
const errorResponse = new ApiError_1.ApiError(error);
reject(JSON.stringify(errorResponse.generateError()));
}
}));
});
});
}
}
exports.AssetApi = AssetApi;
//# sourceMappingURL=assetApi.js.map