xero-node
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -90,2 +90,8 @@ export interface Attachment { | ||
} | ||
export interface BrandingTheme { | ||
BrandingThemeID: string; | ||
Name: string; | ||
SortOrder: number; | ||
CreatedDateUTC: string; | ||
} | ||
export interface PaymentService { | ||
@@ -98,8 +104,2 @@ PaymentServiceID?: string; | ||
} | ||
export interface BrandingTheme { | ||
BrandingThemeID: string; | ||
Name: string; | ||
SortOrder: number; | ||
CreatedDateUTC: string; | ||
} | ||
export interface Overpayment { | ||
@@ -330,3 +330,2 @@ OverpaymentID?: string; | ||
LineItemID?: string; | ||
ItemCode?: string; | ||
} | ||
@@ -333,0 +332,0 @@ export interface ManualJournal { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=AccountingAPI-models.js.map |
@@ -0,0 +0,0 @@ import { ExpenseClaim, User, CreditNote, BrandingTheme, Journal, Item, OnlineInvoice, Organisation, OrgCISSetting, Overpayment, Payment, Prepayment, TaxRate, TrackingCategory, BankTransfer, LinkedTransaction, Employee, Currency, HistoryRecord, Contact, ContactGroup, InvoiceReminder, Invoice, Allocation, BankTransaction, Attachment, Receipt, RepeatingInvoice, ManualJournal, PurchaseOrder, PaymentService } from './AccountingAPI-models'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=AccountingAPI-responses.js.map |
@@ -407,5 +407,7 @@ /// <reference types="node" /> | ||
allocations: { | ||
create: (body: Allocation[], args: { | ||
create: (allocations: Allocation | { | ||
Allocations: Allocation[]; | ||
}, args: { | ||
OverpaymentID: string; | ||
}) => Promise<OverpaymentsResponse>; | ||
}) => Promise<AllocationsResponse>; | ||
}; | ||
@@ -464,3 +466,3 @@ history: { | ||
PrepaymentID: string; | ||
}) => Promise<PrepaymentsResponse>; | ||
}) => Promise<AllocationsResponse>; | ||
}; | ||
@@ -467,0 +469,0 @@ attachments: AttachmentsEndpoint; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -23,215 +10,168 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
}; | ||
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 fs = require("fs"); | ||
var BaseAPIClient_1 = require("./internals/BaseAPIClient"); | ||
var utils_1 = require("./internals/utils"); | ||
var AccountingAPIClient = /** @class */ (function (_super) { | ||
__extends(AccountingAPIClient, _super); | ||
function AccountingAPIClient(options, authState, _oAuth1HttpClient) { | ||
var _this = _super.call(this, options, authState, { apiBasePath: '/api.xro/2.0/' }, _oAuth1HttpClient) || this; | ||
_this.accounts = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'accounts'; | ||
if (args && args.AccountID) { | ||
endpoint = endpoint + '/' + args.AccountID; | ||
delete args.AccountID; // remove from query string | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
create: function (account) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'accounts'; | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, account)]; | ||
}); | ||
}); }, | ||
update: function (account, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'accounts'; | ||
if (args && args.AccountID) { | ||
endpoint = endpoint + '/' + args.AccountID; | ||
delete args.AccountID; // remove from query string | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, account)]; | ||
}); | ||
}); }, | ||
delete: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'accounts/' + args.AccountID; | ||
return [2 /*return*/, this.oauth1Client.delete(endpoint)]; | ||
}); | ||
}); }, | ||
attachments: _this.generateAttachmentsEndpoint('accounts') | ||
const fs = require("fs"); | ||
const BaseAPIClient_1 = require("./internals/BaseAPIClient"); | ||
const utils_1 = require("./internals/utils"); | ||
class AccountingAPIClient extends BaseAPIClient_1.BaseAPIClient { | ||
constructor(options, authState, _oAuth1HttpClient) { | ||
super(options, authState, { apiBasePath: '/api.xro/2.0/' }, _oAuth1HttpClient); | ||
this.accounts = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'accounts'; | ||
if (args && args.AccountID) { | ||
endpoint = endpoint + '/' + args.AccountID; | ||
delete args.AccountID; // remove from query string | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
create: (account) => __awaiter(this, void 0, void 0, function* () { | ||
// from docs: You can only add accounts one at a time (i.e. you'll need to do multiple API calls to add many accounts) | ||
const endpoint = 'accounts'; | ||
return this.oauth1Client.put(endpoint, account); | ||
}), | ||
update: (account, args) => __awaiter(this, void 0, void 0, function* () { | ||
// from docs: You can only update accounts one at a time (i.e. you’ll need to do multiple API calls to update many accounts) | ||
let endpoint = 'accounts'; | ||
if (args && args.AccountID) { | ||
endpoint = endpoint + '/' + args.AccountID; | ||
delete args.AccountID; // remove from query string | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.post(endpoint, account); | ||
}), | ||
delete: (args) => __awaiter(this, void 0, void 0, function* () { | ||
// from docs: If an account is not able to be deleted (e.g. ssystem accounts and accounts used on transactions) you can update the status to ARCHIVED. | ||
const endpoint = 'accounts/' + args.AccountID; | ||
return this.oauth1Client.delete(endpoint); | ||
}), | ||
attachments: this.generateAttachmentsEndpoint('accounts') | ||
}; | ||
_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, 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.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'), | ||
history: _this.generateHistoryEndpoint('banktransactions', 'BankTransactionID') | ||
this.bankTransactions = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'banktransactions'; | ||
if (args && args.BankTransactionID) { | ||
endpoint = endpoint + '/' + args.BankTransactionID; | ||
delete args.BankTransactionID; // remove from query string | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
create: (bankTransaction, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'banktransactions' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, bankTransaction); | ||
}), | ||
update: (bankTransaction, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'banktransactions' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, bankTransaction); | ||
}), | ||
attachments: this.generateAttachmentsEndpoint('banktransactions'), | ||
history: this.generateHistoryEndpoint('banktransactions', 'BankTransactionID') | ||
}; | ||
_this.bankTransfers = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'banktransfers'; | ||
if (args && args.BankTransferID) { | ||
endpoint = endpoint + '/' + args.BankTransferID; | ||
delete args.BankTransferID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, this.generateHeader(args))]; | ||
}); | ||
}); }, | ||
create: function (bankTransfers, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'banktransfers'; | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, bankTransfers)]; | ||
}); | ||
}); }, | ||
attachments: _this.generateAttachmentsEndpoint('banktransfers'), | ||
history: _this.generateHistoryEndpoint('banktransfers', 'BankTransferID') | ||
this.bankTransfers = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'banktransfers'; | ||
if (args && args.BankTransferID) { | ||
endpoint = endpoint + '/' + args.BankTransferID; | ||
delete args.BankTransferID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, this.generateHeader(args)); | ||
}), | ||
create: (bankTransfers, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'banktransfers'; | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, bankTransfers); | ||
}), | ||
attachments: this.generateAttachmentsEndpoint('banktransfers'), | ||
history: this.generateHistoryEndpoint('banktransfers', 'BankTransferID') | ||
}; | ||
_this.brandingThemes = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'brandingthemes'; | ||
if (args && args.BrandingThemeID) { | ||
endpoint = endpoint + '/' + args.BrandingThemeID; | ||
delete args.BrandingThemeID; | ||
} | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); } | ||
this.brandingThemes = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'brandingthemes'; | ||
if (args && args.BrandingThemeID) { | ||
endpoint = endpoint + '/' + args.BrandingThemeID; | ||
delete args.BrandingThemeID; | ||
} | ||
return this.oauth1Client.get(endpoint); | ||
}) | ||
}; | ||
_this.contactGroups = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contactgroups'; | ||
this.contactGroups = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'contactgroups'; | ||
if (args && args.ContactGroupID) { | ||
endpoint = endpoint + '/' + args.ContactGroupID; | ||
delete args.ContactGroupID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
create: (contactGroups, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'contactgroups' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, contactGroups); | ||
}), | ||
update: (contactGroups, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'contactgroups'; | ||
if (args && args.ContactGroupID) { | ||
endpoint = endpoint + '/' + args.ContactGroupID; | ||
delete args.ContactGroupID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, contactGroups); | ||
}), | ||
contacts: { | ||
delete: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'contactgroups'; | ||
if (args && args.ContactGroupID) { | ||
endpoint = endpoint + '/' + args.ContactGroupID; | ||
endpoint = endpoint + '/' + args.ContactGroupID + '/contacts'; | ||
delete args.ContactGroupID; | ||
if (args.ContactID) { | ||
endpoint = endpoint + '/' + args.ContactID; | ||
delete args.ContactID; | ||
} | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
create: function (contactGroups, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contactgroups' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, contactGroups)]; | ||
}); | ||
}); }, | ||
update: function (contactGroups, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contactgroups'; | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.delete(endpoint); | ||
}), | ||
create: (contact, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'contactgroups'; | ||
if (args && args.ContactGroupID) { | ||
endpoint = endpoint + '/' + args.ContactGroupID; | ||
endpoint = endpoint + '/' + args.ContactGroupID + '/contacts'; | ||
delete args.ContactGroupID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, contactGroups)]; | ||
}); | ||
}); }, | ||
contacts: { | ||
delete: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contactgroups'; | ||
if (args && args.ContactGroupID) { | ||
endpoint = endpoint + '/' + args.ContactGroupID + '/contacts'; | ||
delete args.ContactGroupID; | ||
if (args.ContactID) { | ||
endpoint = endpoint + '/' + args.ContactID; | ||
delete args.ContactID; | ||
} | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.delete(endpoint)]; | ||
}); | ||
}); }, | ||
create: function (contact, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contactgroups'; | ||
if (args && args.ContactGroupID) { | ||
endpoint = endpoint + '/' + args.ContactGroupID + '/contacts'; | ||
delete args.ContactGroupID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, contact)]; | ||
}); | ||
}); } | ||
return this.oauth1Client.put(endpoint, contact); | ||
}) | ||
} | ||
}; | ||
_this.contacts = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contacts'; | ||
this.contacts = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'contacts'; | ||
if (args && args.ContactID) { | ||
endpoint = endpoint + '/' + args.ContactID; | ||
delete args.ContactID; | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
create: (body, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'contacts'; | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, body); | ||
}), | ||
update: (body, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'contacts'; | ||
if (args && args.ContactID) { | ||
endpoint = endpoint + '/' + args.ContactID; | ||
delete args.ContactID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, body); | ||
}), | ||
CISsettings: { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'contacts'; | ||
if (args && args.ContactID) { | ||
@@ -241,49 +181,45 @@ endpoint = endpoint + '/' + args.ContactID; | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
create: function (body, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'contacts'; | ||
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)]; | ||
}); | ||
}); } | ||
endpoint += '/cissettings'; | ||
return this.oauth1Client.get(endpoint); | ||
}) | ||
}, | ||
attachments: _this.generateAttachmentsEndpoint('contacts'), | ||
history: _this.generateHistoryEndpoint('contacts', 'ContactID') | ||
attachments: this.generateAttachmentsEndpoint('contacts'), | ||
history: this.generateHistoryEndpoint('contacts', 'ContactID') | ||
}; | ||
_this.creditNotes = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'creditnotes'; | ||
this.creditNotes = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'creditnotes'; | ||
if (args && args.CreditNoteID) { | ||
endpoint = endpoint + '/' + args.CreditNoteID; | ||
delete args.CreditNoteID; // remove from query string | ||
} | ||
else if (args && args.CreditNoteNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.CreditNoteNumber); | ||
delete args.CreditNoteNumber; | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
savePDF: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'creditnotes'; | ||
if (args && args.CreditNoteID) { | ||
endpoint = endpoint + '/' + args.CreditNoteID; | ||
delete args.CreditNoteID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
const writeStream = fs.createWriteStream(args.savePath); | ||
return this.oauth1Client.writeUTF8ResponseToStream(endpoint, 'application/pdf', writeStream); | ||
}), | ||
create: (creditNote, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'creditnotes' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, creditNote); | ||
}), | ||
update: (creditNote, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'creditnotes' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, creditNote); | ||
}), | ||
allocations: { | ||
create: (allocation, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'creditnotes'; | ||
if (args && args.CreditNoteID) { | ||
@@ -293,149 +229,120 @@ endpoint = endpoint + '/' + args.CreditNoteID; | ||
} | ||
else if (args && args.CreditNoteNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.CreditNoteNumber); | ||
delete args.CreditNoteNumber; | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += '/allocations'; | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
savePDF: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, writeStream; | ||
return __generator(this, function (_a) { | ||
endpoint = 'creditnotes'; | ||
if (args && args.CreditNoteID) { | ||
endpoint = endpoint + '/' + args.CreditNoteID; | ||
delete args.CreditNoteID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
writeStream = fs.createWriteStream(args.savePath); | ||
return [2 /*return*/, this.oauth1Client.writeUTF8ResponseToStream(endpoint, 'application/pdf', writeStream)]; | ||
}); | ||
}); }, | ||
create: function (creditNote, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'creditnotes' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, creditNote)]; | ||
}); | ||
}); }, | ||
update: function (creditNote, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'creditnotes' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, creditNote)]; | ||
}); | ||
}); }, | ||
allocations: { | ||
create: function (allocation, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'creditnotes'; | ||
if (args && args.CreditNoteID) { | ||
endpoint = endpoint + '/' + args.CreditNoteID; | ||
delete args.CreditNoteID; // remove from query string | ||
} | ||
endpoint += '/allocations'; | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, allocation)]; | ||
}); | ||
}); }, | ||
return this.oauth1Client.put(endpoint, allocation); | ||
}), | ||
}, | ||
attachments: _this.generateAttachmentsEndpoint('creditnotes'), | ||
history: _this.generateHistoryEndpoint('creditnotes', 'CreditNoteID') | ||
attachments: this.generateAttachmentsEndpoint('creditnotes'), | ||
history: this.generateHistoryEndpoint('creditnotes', 'CreditNoteID') | ||
}; | ||
_this.currencies = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'currencies' + utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
create: function (currency) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'currencies'; | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, currency)]; | ||
}); | ||
}); } | ||
this.currencies = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'currencies' + utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
create: (currency) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'currencies'; | ||
return this.oauth1Client.put(endpoint, currency); | ||
}) | ||
}; | ||
_this.employees = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'employees'; | ||
if (args && args.EmployeeID) { | ||
endpoint = endpoint + '/' + args.EmployeeID; | ||
delete args.EmployeeID; | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
create: function (employees) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'employees'; | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, employees)]; | ||
}); | ||
}); }, | ||
update: function (employees) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'employees'; | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, employees)]; | ||
}); | ||
}); } | ||
this.employees = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'employees'; | ||
if (args && args.EmployeeID) { | ||
endpoint = endpoint + '/' + args.EmployeeID; | ||
delete args.EmployeeID; | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
create: (employees) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'employees'; | ||
return this.oauth1Client.put(endpoint, employees); | ||
}), | ||
update: (employees) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'employees'; | ||
return this.oauth1Client.post(endpoint, employees); | ||
}) | ||
}; | ||
_this.expenseClaims = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'expenseclaims'; | ||
if (args && args.ExpenseClaimID) { | ||
endpoint = endpoint + '/' + args.ExpenseClaimID; | ||
delete args.ExpenseClaimID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
create: function (expenseClaims, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'expenseclaims' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, expenseClaims)]; | ||
}); | ||
}); }, | ||
update: function (expenseClaims, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'expenseclaims'; | ||
if (args && args.ExpenseClaimID) { | ||
endpoint = endpoint + '/' + args.ExpenseClaimID; | ||
delete args.ExpenseClaimID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, expenseClaims)]; | ||
}); | ||
}); }, | ||
history: _this.generateHistoryEndpoint('expenseclaims', 'ExpenseClaimID') | ||
this.expenseClaims = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'expenseclaims'; | ||
if (args && args.ExpenseClaimID) { | ||
endpoint = endpoint + '/' + args.ExpenseClaimID; | ||
delete args.ExpenseClaimID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
create: (expenseClaims, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'expenseclaims' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, expenseClaims); | ||
}), | ||
update: (expenseClaims, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'expenseclaims'; | ||
if (args && args.ExpenseClaimID) { | ||
endpoint = endpoint + '/' + args.ExpenseClaimID; | ||
delete args.ExpenseClaimID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, expenseClaims); | ||
}), | ||
history: this.generateHistoryEndpoint('expenseclaims', 'ExpenseClaimID') | ||
}; | ||
_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.invoiceReminders = { | ||
get: () => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'invoicereminders/settings'; | ||
return this.oauth1Client.get(endpoint); | ||
}) | ||
}; | ||
_this.invoices = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'invoices'; | ||
this.invoices = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'invoices'; | ||
if (args && args.InvoiceID) { | ||
endpoint = endpoint + '/' + args.InvoiceID; | ||
delete args.InvoiceID; | ||
} | ||
else if (args && args.InvoiceNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.InvoiceNumber); | ||
delete args.InvoiceNumber; | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
savePDF: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'invoices'; | ||
if (args && args.InvoiceID) { | ||
endpoint = endpoint + '/' + args.InvoiceID; | ||
delete args.InvoiceID; | ||
} | ||
else if (args && args.InvoiceNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.InvoiceNumber); | ||
delete args.InvoiceNumber; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
const writeStream = fs.createWriteStream(args.savePath); | ||
return this.oauth1Client.writeUTF8ResponseToStream(endpoint, 'application/pdf', writeStream); | ||
}), | ||
create: (invoice, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'invoices' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, invoice); | ||
}), | ||
update: (invoices, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'invoices'; | ||
if (args && args.InvoiceID) { | ||
endpoint = endpoint + '/' + args.InvoiceID; | ||
delete args.InvoiceID; | ||
} | ||
else if (args && args.InvoiceNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.InvoiceNumber); | ||
delete args.InvoiceNumber; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, invoices); | ||
}), | ||
onlineInvoice: { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'invoices'; | ||
if (args && args.InvoiceID) { | ||
@@ -445,15 +352,11 @@ endpoint = endpoint + '/' + args.InvoiceID; | ||
} | ||
else if (args && args.InvoiceNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.InvoiceNumber); | ||
delete args.InvoiceNumber; | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
savePDF: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, writeStream; | ||
return __generator(this, function (_a) { | ||
endpoint = 'invoices'; | ||
endpoint += '/onlineinvoice'; | ||
return this.oauth1Client.get(endpoint); | ||
}) | ||
}, | ||
attachments: this.generateAttachmentsEndpoint('invoices'), | ||
history: this.generateHistoryEndpoint('invoices', 'InvoiceID'), | ||
email: { | ||
create: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'invoices'; | ||
if (args && args.InvoiceID) { | ||
@@ -463,644 +366,432 @@ endpoint = endpoint + '/' + args.InvoiceID; | ||
} | ||
else if (args && args.InvoiceNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.InvoiceNumber); | ||
delete args.InvoiceNumber; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
writeStream = fs.createWriteStream(args.savePath); | ||
return [2 /*return*/, this.oauth1Client.writeUTF8ResponseToStream(endpoint, 'application/pdf', writeStream)]; | ||
}); | ||
}); }, | ||
create: function (invoice, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'invoices' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, invoice)]; | ||
}); | ||
}); }, | ||
update: function (invoices, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'invoices'; | ||
if (args && args.InvoiceID) { | ||
endpoint = endpoint + '/' + args.InvoiceID; | ||
delete args.InvoiceID; | ||
} | ||
else if (args && args.InvoiceNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.InvoiceNumber); | ||
delete args.InvoiceNumber; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, invoices)]; | ||
}); | ||
}); }, | ||
onlineInvoice: { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'invoices'; | ||
if (args && args.InvoiceID) { | ||
endpoint = endpoint + '/' + args.InvoiceID; | ||
delete args.InvoiceID; | ||
} | ||
endpoint += '/onlineinvoice'; | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); } | ||
}, | ||
attachments: _this.generateAttachmentsEndpoint('invoices'), | ||
history: _this.generateHistoryEndpoint('invoices', 'InvoiceID'), | ||
email: { | ||
create: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'invoices'; | ||
if (args && args.InvoiceID) { | ||
endpoint = endpoint + '/' + args.InvoiceID; | ||
delete args.InvoiceID; | ||
} | ||
endpoint += '/email'; | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, {})]; | ||
}); | ||
}); } | ||
endpoint += '/email'; | ||
return this.oauth1Client.post(endpoint, {}); | ||
}) | ||
} | ||
}; | ||
_this.repeatingInvoices = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, headers; | ||
return __generator(this, function (_a) { | ||
endpoint = 'repeatinginvoices'; | ||
if (args && args.RepeatingInvoiceID) { | ||
endpoint = endpoint + '/' + args.RepeatingInvoiceID; | ||
delete args.RepeatingInvoiceID; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); }, | ||
attachments: _this.generateAttachmentsEndpoint('repeatinginvoices'), | ||
history: _this.generateHistoryEndpoint('repeatinginvoices', 'RepeatingInvoiceID') | ||
this.repeatingInvoices = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'repeatinginvoices'; | ||
if (args && args.RepeatingInvoiceID) { | ||
endpoint = endpoint + '/' + args.RepeatingInvoiceID; | ||
delete args.RepeatingInvoiceID; | ||
} | ||
const headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, headers); | ||
}), | ||
attachments: this.generateAttachmentsEndpoint('repeatinginvoices'), | ||
history: this.generateHistoryEndpoint('repeatinginvoices', 'RepeatingInvoiceID') | ||
}; | ||
_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 + '/' + encodeURIComponent(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)]; | ||
}); | ||
}); }, | ||
history: _this.generateHistoryEndpoint('items', 'ItemID') | ||
this.items = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'items'; | ||
if (args && args.ItemID) { | ||
endpoint = endpoint + '/' + args.ItemID; | ||
delete args.ItemID; | ||
} | ||
else if (args && args.Code) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.Code); | ||
delete args.Code; | ||
} | ||
const headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, headers); | ||
}), | ||
create: (items, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'items' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, items); | ||
}), | ||
update: (items, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'items'; | ||
if (args && args.ItemID) { | ||
endpoint = endpoint + '/' + args.ItemID; | ||
delete args.ItemID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, items); | ||
}), | ||
delete: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'items' + '/' + args.ItemID; | ||
return this.oauth1Client.delete(endpoint); | ||
}), | ||
history: this.generateHistoryEndpoint('items', 'ItemID') | ||
}; | ||
_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 + '/' + encodeURIComponent(args.Recordfilter); | ||
delete args.Recordfilter; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); } | ||
this.journals = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'journals'; | ||
if (args && args.Recordfilter) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.Recordfilter); | ||
delete args.Recordfilter; | ||
} | ||
const headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, headers); | ||
}) | ||
}; | ||
_this.linkedTransactions = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'linkedtransactions'; | ||
if (args && args.LinkedTransactionID) { | ||
endpoint = endpoint + '/' + args.LinkedTransactionID; | ||
delete args.LinkedTransactionID; // remove from query string | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
create: function (linkedTransaction, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'linkedtransactions' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, linkedTransaction)]; | ||
}); | ||
}); }, | ||
update: function (linkedTransaction, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'linkedtransactions'; | ||
if (args && args.LinkedTransactionID) { | ||
endpoint = endpoint + '/' + args.LinkedTransactionID; | ||
delete args.LinkedTransactionID; // remove from query string | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, linkedTransaction)]; | ||
}); | ||
}); }, | ||
delete: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'linkedtransactions'; | ||
if (args && args.LinkedTransactionID) { | ||
endpoint = endpoint + '/' + args.LinkedTransactionID; | ||
delete args.LinkedTransactionID; // remove from query string | ||
} | ||
endpoint += utils_1.generateQueryString(args, false); | ||
return [2 /*return*/, this.oauth1Client.delete(endpoint)]; | ||
}); | ||
}); }, | ||
this.linkedTransactions = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'linkedtransactions'; | ||
if (args && args.LinkedTransactionID) { | ||
endpoint = endpoint + '/' + args.LinkedTransactionID; | ||
delete args.LinkedTransactionID; // remove from query string | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
create: (linkedTransaction, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'linkedtransactions' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, linkedTransaction); | ||
}), | ||
update: (linkedTransaction, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'linkedtransactions'; | ||
if (args && args.LinkedTransactionID) { | ||
endpoint = endpoint + '/' + args.LinkedTransactionID; | ||
delete args.LinkedTransactionID; // remove from query string | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, linkedTransaction); | ||
}), | ||
delete: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'linkedtransactions'; | ||
if (args && args.LinkedTransactionID) { | ||
endpoint = endpoint + '/' + args.LinkedTransactionID; | ||
delete args.LinkedTransactionID; // remove from query string | ||
} | ||
endpoint += utils_1.generateQueryString(args, false); | ||
return this.oauth1Client.delete(endpoint); | ||
}), | ||
}; | ||
_this.manualJournals = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'manualjournals'; | ||
if (args && args.ManualJournalID) { | ||
endpoint += '/' + args.ManualJournalID; | ||
delete args.ManualJournalID; | ||
this.manualJournals = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'manualjournals'; | ||
if (args && args.ManualJournalID) { | ||
endpoint += '/' + args.ManualJournalID; | ||
delete args.ManualJournalID; | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
create: (manualJournals, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'manualjournals' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, manualJournals); | ||
}), | ||
update: (manualJournals, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'manualjournals'; | ||
if (args && args.ManualJournalID) { | ||
endpoint += '/' + args.ManualJournalID; | ||
delete args.ManualJournalID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, manualJournals); | ||
}), | ||
attachments: this.generateAttachmentsEndpoint('manualjournals') | ||
}; | ||
this.organisations = { | ||
get: () => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'organisations'; | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
CISSettings: { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'organisations'; | ||
if (args && args.OrganisationID) { | ||
endpoint = endpoint + '/' + args.OrganisationID + '/CISSettings'; | ||
delete args.OrganisationID; | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
create: function (manualJournals, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'manualjournals' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, manualJournals)]; | ||
}); | ||
}); }, | ||
update: function (manualJournals, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'manualjournals'; | ||
if (args && args.ManualJournalID) { | ||
endpoint += '/' + args.ManualJournalID; | ||
delete args.ManualJournalID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, manualJournals)]; | ||
}); | ||
}); }, | ||
attachments: _this.generateAttachmentsEndpoint('manualjournals') | ||
}; | ||
_this.organisations = { | ||
get: function () { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'organisations'; | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
CISSettings: { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'organisations'; | ||
if (args && args.OrganisationID) { | ||
endpoint = endpoint + '/' + args.OrganisationID + '/CISSettings'; | ||
delete args.OrganisationID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); } | ||
return this.oauth1Client.get(endpoint); | ||
}) | ||
} | ||
}; | ||
_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)]; | ||
}); | ||
}); }, | ||
this.overpayments = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'overpayments'; | ||
if (args && args.OverpaymentID) { | ||
endpoint += '/' + args.OverpaymentID; | ||
delete args.OverpaymentID; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
allocations: { | ||
create: 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.put(endpoint, body)]; | ||
}); | ||
}); } | ||
create: (allocations, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = `overpayments/${args.OverpaymentID}/allocations`; | ||
return this.oauth1Client.put(endpoint, allocations); | ||
}) | ||
}, | ||
history: _this.generateHistoryEndpoint('overpayments', 'OverpaymentID') | ||
history: this.generateHistoryEndpoint('overpayments', 'OverpaymentID') | ||
}; | ||
_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)]; | ||
}); | ||
}); }, | ||
history: _this.generateHistoryEndpoint('payments', 'PaymentID') | ||
this.payments = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'payments'; | ||
if (args && args.PaymentID) { | ||
endpoint = endpoint + '/' + args.PaymentID; | ||
delete args.PaymentID; | ||
} | ||
const headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, headers); | ||
}), | ||
create: (payments, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'payments' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, payments); | ||
}), | ||
update: (payments, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'payments'; | ||
if (args && args.PaymentID) { | ||
endpoint = endpoint + '/' + args.PaymentID; | ||
delete args.PaymentID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, payments); | ||
}), | ||
history: this.generateHistoryEndpoint('payments', 'PaymentID') | ||
}; | ||
_this.paymentServices = { | ||
get: function () { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, this.oauth1Client.get('paymentservices')]; | ||
}); | ||
}); }, | ||
create: function (paymentService, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'paymentservices' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, paymentService)]; | ||
}); | ||
}); } | ||
this.paymentServices = { | ||
get: () => __awaiter(this, void 0, void 0, function* () { | ||
return this.oauth1Client.get('paymentservices'); | ||
}), | ||
create: (paymentService, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'paymentservices' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, paymentService); | ||
}) | ||
}; | ||
_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)]; | ||
}); | ||
}); }, | ||
this.prepayments = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'prepayments'; | ||
if (args && args.PrepaymentID) { | ||
endpoint = endpoint + '/' + args.PrepaymentID; | ||
delete args.PrepaymentID; | ||
} | ||
const headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
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)]; | ||
}); | ||
}); } | ||
create: (allocations, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = `prepayments/${args.PrepaymentID}/allocations`; | ||
delete args.PrepaymentID; | ||
return this.oauth1Client.put(endpoint, allocations); | ||
}) | ||
}, | ||
attachments: _this.generateAttachmentsEndpoint('prepayments'), | ||
history: _this.generateHistoryEndpoint('prepayments', 'PrepaymentID') | ||
attachments: this.generateAttachmentsEndpoint('prepayments'), | ||
history: this.generateHistoryEndpoint('prepayments', 'PrepaymentID') | ||
}; | ||
_this.purchaseOrders = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, headers; | ||
return __generator(this, function (_a) { | ||
endpoint = 'purchaseorders'; | ||
if (args && args.PurchaseOrderID) { | ||
endpoint = endpoint + '/' + args.PurchaseOrderID; | ||
delete args.PurchaseOrderID; | ||
} | ||
else if (args && args.PurchaseOrderNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.PurchaseOrderNumber); | ||
delete args.PurchaseOrderNumber; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); }, | ||
savePDF: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, writeStream; | ||
return __generator(this, function (_a) { | ||
endpoint = 'purchaseorders'; | ||
if (args && args.PurchaseOrderID) { | ||
endpoint = endpoint + '/' + args.PurchaseOrderID; | ||
delete args.PurchaseOrderID; | ||
} | ||
else if (args && args.PurchaseOrderNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.PurchaseOrderNumber); | ||
delete args.PurchaseOrderNumber; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
writeStream = fs.createWriteStream(args.savePath); | ||
return [2 /*return*/, this.oauth1Client.writeUTF8ResponseToStream(endpoint, 'application/pdf', writeStream)]; | ||
}); | ||
}); }, | ||
create: function (purchaseOrders, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'purchaseorders'; | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, purchaseOrders)]; | ||
}); | ||
}); }, | ||
update: function (purchaseOrders, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'purchaseorders'; | ||
if (args && args.PurchaseOrderID) { | ||
endpoint = endpoint + '/' + args.PurchaseOrderID; | ||
delete args.PurchaseOrderID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, purchaseOrders)]; | ||
}); | ||
}); }, | ||
history: _this.generateHistoryEndpoint('purchaseorders', 'PurchaseOrderID') | ||
this.purchaseOrders = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'purchaseorders'; | ||
if (args && args.PurchaseOrderID) { | ||
endpoint = endpoint + '/' + args.PurchaseOrderID; | ||
delete args.PurchaseOrderID; | ||
} | ||
else if (args && args.PurchaseOrderNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.PurchaseOrderNumber); | ||
delete args.PurchaseOrderNumber; | ||
} | ||
const headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, headers); | ||
}), | ||
savePDF: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'purchaseorders'; | ||
if (args && args.PurchaseOrderID) { | ||
endpoint = endpoint + '/' + args.PurchaseOrderID; | ||
delete args.PurchaseOrderID; | ||
} | ||
else if (args && args.PurchaseOrderNumber) { | ||
endpoint = endpoint + '/' + encodeURIComponent(args.PurchaseOrderNumber); | ||
delete args.PurchaseOrderNumber; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
const writeStream = fs.createWriteStream(args.savePath); | ||
return this.oauth1Client.writeUTF8ResponseToStream(endpoint, 'application/pdf', writeStream); | ||
}), | ||
create: (purchaseOrders, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'purchaseorders'; | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, purchaseOrders); | ||
}), | ||
update: (purchaseOrders, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'purchaseorders'; | ||
if (args && args.PurchaseOrderID) { | ||
endpoint = endpoint + '/' + args.PurchaseOrderID; | ||
delete args.PurchaseOrderID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, purchaseOrders); | ||
}), | ||
history: this.generateHistoryEndpoint('purchaseorders', 'PurchaseOrderID') | ||
}; | ||
_this.receipts = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, header; | ||
return __generator(this, function (_a) { | ||
endpoint = 'receipts'; | ||
if (args && args.ReceiptID) { | ||
endpoint += '/' + args.ReceiptID; | ||
delete args.ReceiptID; | ||
} | ||
header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, header)]; | ||
}); | ||
}); }, | ||
create: function (receipts, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'receipts' + utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, receipts)]; | ||
}); | ||
}); }, | ||
update: function (receipts, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'receipts'; | ||
if (args && args.ReceiptID) { | ||
endpoint += '/' + args.ReceiptID; | ||
delete args.ReceiptID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, receipts)]; | ||
}); | ||
}); }, | ||
attachments: _this.generateAttachmentsEndpoint('receipts'), | ||
history: _this.generateHistoryEndpoint('receipts', 'ReceiptID') | ||
this.receipts = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'receipts'; | ||
if (args && args.ReceiptID) { | ||
endpoint += '/' + args.ReceiptID; | ||
delete args.ReceiptID; | ||
} | ||
const header = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, header); | ||
}), | ||
create: (receipts, args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'receipts' + utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.put(endpoint, receipts); | ||
}), | ||
update: (receipts, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'receipts'; | ||
if (args && args.ReceiptID) { | ||
endpoint += '/' + args.ReceiptID; | ||
delete args.ReceiptID; | ||
} | ||
endpoint += utils_1.generateQueryString(args, true); | ||
return this.oauth1Client.post(endpoint, receipts); | ||
}), | ||
attachments: this.generateAttachmentsEndpoint('receipts'), | ||
history: this.generateHistoryEndpoint('receipts', 'ReceiptID') | ||
}; | ||
_this.reports = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, reportId; | ||
return __generator(this, function (_a) { | ||
endpoint = 'reports'; | ||
if (args) { | ||
reportId = args.ReportID; | ||
delete args.ReportID; // remove from querystring | ||
endpoint = endpoint + '/' + reportId + utils_1.generateQueryString(args); | ||
} | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); } | ||
this.reports = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'reports'; | ||
if (args) { | ||
const reportId = args.ReportID; | ||
delete args.ReportID; // remove from querystring | ||
endpoint = endpoint + '/' + reportId + utils_1.generateQueryString(args); | ||
} | ||
return this.oauth1Client.get(endpoint); | ||
}) | ||
}; | ||
_this.taxRates = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'taxrates'; | ||
if (args && args.TaxType) { | ||
endpoint += '/' + args.TaxType; | ||
delete args.TaxType; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
create: function (body) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'taxrates'; | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, body)]; | ||
}); | ||
}); }, | ||
update: function (body) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'taxrates'; | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, body)]; | ||
}); | ||
}); } | ||
this.taxRates = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'taxrates'; | ||
if (args && args.TaxType) { | ||
endpoint += '/' + args.TaxType; | ||
delete args.TaxType; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
create: (body) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'taxrates'; | ||
return this.oauth1Client.put(endpoint, body); | ||
}), | ||
update: (body) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'taxrates'; | ||
return this.oauth1Client.post(endpoint, body); | ||
}) | ||
}; | ||
_this.trackingCategories = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, headers; | ||
return __generator(this, function (_a) { | ||
endpoint = 'trackingcategories'; | ||
this.trackingCategories = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
// TODO: Support for where arg | ||
let endpoint = 'trackingcategories'; | ||
if (args && args.TrackingCategoryID) { | ||
endpoint = endpoint + '/' + args.TrackingCategoryID; | ||
} | ||
const headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, headers); | ||
}), | ||
create: (trackingCategory) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'trackingcategories'; | ||
return this.oauth1Client.put(endpoint, trackingCategory); | ||
}), | ||
update: (trackingCategory, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'trackingcategories'; | ||
if (args && args.TrackingCategoryID) { | ||
endpoint = endpoint + '/' + args.TrackingCategoryID; | ||
delete args.TrackingCategoryID; | ||
} | ||
return this.oauth1Client.post(endpoint, trackingCategory); | ||
}), | ||
delete: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'trackingcategories/' + args.TrackingCategoryID; | ||
return this.oauth1Client.delete(endpoint); | ||
}), | ||
trackingOptions: { | ||
create: (trackingOption, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'trackingcategories'; | ||
if (args && args.TrackingCategoryID) { | ||
endpoint = endpoint + '/' + args.TrackingCategoryID; | ||
endpoint = endpoint + '/' + args.TrackingCategoryID + '/Options'; | ||
delete args.TrackingCategoryID; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); }, | ||
create: function (trackingCategory) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'trackingcategories'; | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, trackingCategory)]; | ||
}); | ||
}); }, | ||
update: function (trackingCategory, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'trackingcategories'; | ||
if (args && args.TrackingCategoryID) { | ||
endpoint = endpoint + '/' + args.TrackingCategoryID; | ||
return this.oauth1Client.put(endpoint, trackingOption); | ||
}), | ||
update: (trackingOption, args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'trackingcategories'; | ||
if (args && args.TrackingCategoryID && args.TrackingOptionID) { | ||
endpoint = endpoint + '/' + args.TrackingCategoryID + '/Options/' + args.TrackingOptionID; | ||
delete args.TrackingCategoryID; | ||
delete args.TrackingOptionID; | ||
} | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, trackingCategory)]; | ||
}); | ||
}); }, | ||
delete: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'trackingcategories/' + args.TrackingCategoryID; | ||
return [2 /*return*/, this.oauth1Client.delete(endpoint)]; | ||
}); | ||
}); }, | ||
trackingOptions: { | ||
create: function (trackingOption, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'trackingcategories'; | ||
if (args && args.TrackingCategoryID) { | ||
endpoint = endpoint + '/' + args.TrackingCategoryID + '/Options'; | ||
delete args.TrackingCategoryID; | ||
} | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, trackingOption)]; | ||
}); | ||
}); }, | ||
update: function (trackingOption, args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'trackingcategories'; | ||
if (args && args.TrackingCategoryID && args.TrackingOptionID) { | ||
endpoint = endpoint + '/' + args.TrackingCategoryID + '/Options/' + args.TrackingOptionID; | ||
delete args.TrackingCategoryID; | ||
delete args.TrackingOptionID; | ||
} | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, trackingOption)]; | ||
}); | ||
}); }, | ||
delete: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'trackingcategories/' + args.TrackingCategoryID + '/Options/' + args.TrackingOptionID; | ||
return [2 /*return*/, this.oauth1Client.delete(endpoint)]; | ||
}); | ||
}); }, | ||
return this.oauth1Client.post(endpoint, trackingOption); | ||
}), | ||
delete: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'trackingcategories/' + args.TrackingCategoryID + '/Options/' + args.TrackingOptionID; | ||
return this.oauth1Client.delete(endpoint); | ||
}), | ||
} | ||
}; | ||
_this.users = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, headers; | ||
return __generator(this, function (_a) { | ||
endpoint = 'users'; | ||
if (args && args.UserID) { | ||
endpoint = endpoint + '/' + args.UserID; | ||
delete args.UserID; | ||
} | ||
headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint, headers)]; | ||
}); | ||
}); } | ||
this.users = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'users'; | ||
if (args && args.UserID) { | ||
endpoint = endpoint + '/' + args.UserID; | ||
delete args.UserID; | ||
} | ||
const headers = this.generateHeader(args); | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint, headers); | ||
}) | ||
}; | ||
return _this; | ||
} | ||
AccountingAPIClient.prototype.generateAttachmentsEndpoint = function (path) { | ||
var _this = this; | ||
generateAttachmentsEndpoint(path) { | ||
return { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = path + "/" + args.entityId + "/attachments"; | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
downloadAttachment: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, writeStream; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
endpoint = path + "/" + args.entityId + "/attachments/" + utils_1.escapeString(args.fileName); | ||
writeStream = fs.createWriteStream(args.pathToSave); | ||
return [4 /*yield*/, this.oauth1Client.writeBinaryResponseToStream(endpoint, args.mimeType, writeStream)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }, | ||
uploadAttachment: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint, readStream, fileSize; | ||
return __generator(this, function (_a) { | ||
endpoint = path + "/" + args.entityId + "/attachments/" + utils_1.escapeString(args.fileName) + utils_1.generateQueryString({ IncludeOnline: args.includeOnline }); | ||
readStream = fs.createReadStream(args.pathToUpload); | ||
fileSize = fs.statSync(args.pathToUpload).size; | ||
return [2 /*return*/, this.oauth1Client.readStreamToRequest(endpoint, args.mimeType, fileSize, readStream)]; | ||
}); | ||
}); }, | ||
uploadAttachmentFromStream: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = path + "/" + args.entityId + "/attachments/" + utils_1.escapeString(args.fileName) + utils_1.generateQueryString({ IncludeOnline: args.includeOnline }); | ||
return [2 /*return*/, this.oauth1Client.readStreamToRequest(endpoint, args.mimeType, args.fileSize, args.readStream)]; | ||
}); | ||
}); }, | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = `${path}/${args.entityId}/attachments`; | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
downloadAttachment: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = `${path}/${args.entityId}/attachments/${utils_1.escapeString(args.fileName)}`; | ||
const writeStream = fs.createWriteStream(args.pathToSave); | ||
yield this.oauth1Client.writeBinaryResponseToStream(endpoint, args.mimeType, writeStream); | ||
}), | ||
uploadAttachment: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = `${path}/${args.entityId}/attachments/${utils_1.escapeString(args.fileName)}` + utils_1.generateQueryString({ IncludeOnline: args.includeOnline }); | ||
const readStream = fs.createReadStream(args.pathToUpload); | ||
const fileSize = fs.statSync(args.pathToUpload).size; | ||
return this.oauth1Client.readStreamToRequest(endpoint, args.mimeType, fileSize, readStream); | ||
}), | ||
uploadAttachmentFromStream: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = `${path}/${args.entityId}/attachments/${utils_1.escapeString(args.fileName)}` + utils_1.generateQueryString({ IncludeOnline: args.includeOnline }); | ||
return this.oauth1Client.readStreamToRequest(endpoint, args.mimeType, args.fileSize, args.readStream); | ||
}), | ||
}; | ||
}; | ||
AccountingAPIClient.prototype.generateHistoryEndpoint = function (endpointName, argName) { | ||
var _this = this; | ||
} | ||
generateHistoryEndpoint(endpointName, argName) { | ||
return { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = endpointName; | ||
if (args && args[argName]) { | ||
endpoint = endpoint + '/' + args[argName]; | ||
delete args[argName]; | ||
} | ||
endpoint += '/history'; | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
create: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = endpointName; | ||
if (args && args[argName]) { | ||
endpoint = endpoint + '/' + args[argName]; | ||
delete args[argName]; | ||
} | ||
endpoint += '/history'; | ||
return [2 /*return*/, this.oauth1Client.put(endpoint, args.HistoryNote)]; | ||
}); | ||
}); } | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = endpointName; | ||
if (args && args[argName]) { | ||
endpoint = endpoint + '/' + args[argName]; | ||
delete args[argName]; | ||
} | ||
endpoint += '/history'; | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
create: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = endpointName; | ||
if (args && args[argName]) { | ||
endpoint = endpoint + '/' + args[argName]; | ||
delete args[argName]; | ||
} | ||
endpoint += '/history'; | ||
return this.oauth1Client.put(endpoint, args.HistoryNote); | ||
}) | ||
}; | ||
}; | ||
AccountingAPIClient.prototype.generateHeader = function (args) { | ||
} | ||
generateHeader(args) { | ||
if (args && args['If-Modified-Since']) { | ||
var toReturn = { | ||
const toReturn = { | ||
'If-Modified-Since': args['If-Modified-Since'] | ||
@@ -1111,5 +802,5 @@ }; | ||
} | ||
}; | ||
return AccountingAPIClient; | ||
}(BaseAPIClient_1.BaseAPIClient)); | ||
} | ||
} | ||
exports.AccountingAPIClient = AccountingAPIClient; | ||
//# sourceMappingURL=AccountingAPIClient.js.map |
export { AccountingAPIClient } from './AccountingAPIClient'; | ||
export { ProjectsAPIClient } from './ProjectsAPIClient'; | ||
export * from './XeroError'; |
@@ -11,1 +11,2 @@ "use strict"; | ||
__export(require("./XeroError")); | ||
//# sourceMappingURL=index.js.map |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var OAuth1HttpClient_1 = require("./OAuth1HttpClient"); | ||
var config_helper_1 = require("./config-helper"); | ||
const OAuth1HttpClient_1 = require("./OAuth1HttpClient"); | ||
const config_helper_1 = require("./config-helper"); | ||
/** @private */ | ||
var BaseAPIClient = /** @class */ (function () { | ||
function BaseAPIClient(xeroConfig, authState, apiConfig, oauth1Client) { | ||
if (authState === void 0) { authState = null; } | ||
if (apiConfig === void 0) { apiConfig = {}; } | ||
if (oauth1Client === void 0) { oauth1Client = null; } | ||
class BaseAPIClient { | ||
constructor(xeroConfig, authState = null, apiConfig = {}, oauth1Client = null) { | ||
this.oauth1Client = oauth1Client; | ||
@@ -16,3 +13,3 @@ if (!xeroConfig) { | ||
if (!this.oauth1Client) { | ||
var oauthConfig = config_helper_1.mapConfig(xeroConfig, apiConfig); | ||
const oauthConfig = config_helper_1.mapConfig(xeroConfig, apiConfig); | ||
if (!authState) { | ||
@@ -24,4 +21,4 @@ authState = config_helper_1.mapState(xeroConfig); | ||
} | ||
return BaseAPIClient; | ||
}()); | ||
} | ||
exports.BaseAPIClient = BaseAPIClient; | ||
//# sourceMappingURL=BaseAPIClient.js.map |
@@ -0,0 +0,0 @@ /** @internalapi */ |
@@ -5,7 +5,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utils_1 = require("./utils"); | ||
var version = require('../../package.json').version; | ||
const utils_1 = require("./utils"); | ||
const version = require('../../package.json').version; | ||
/** @private */ | ||
function mapState(xeroConfig) { | ||
var cert = xeroConfig.privateKeyPath ? utils_1.getStringFromFile(xeroConfig.privateKeyPath) : null; // TODO don't read twice | ||
let cert = xeroConfig.privateKeyPath ? utils_1.getStringFromFile(xeroConfig.privateKeyPath) : null; // TODO don't read twice | ||
if (xeroConfig.privateKeyString) { | ||
@@ -27,3 +27,3 @@ cert = xeroConfig.privateKeyString; | ||
else { | ||
throw new Error("Unrecognised app type: " + xeroConfig.appType + " (expected private|public|partner)"); | ||
throw new Error(`Unrecognised app type: ${xeroConfig.appType} (expected private|public|partner)`); | ||
} | ||
@@ -35,7 +35,7 @@ } | ||
// the logic for API_BASE can be used for testing against a mock server | ||
var API_BASE = process.env.XERO_API_BASE ? process.env.XERO_API_BASE : 'https://api.xero.com'; | ||
var OAUTH_REQUEST_TOKEN_PATH = '/oauth/RequestToken'; | ||
var OAUTH_ACCESS_TOKEN_PATH = '/oauth/AccessToken'; | ||
var cert = xeroConfig.privateKeyPath ? utils_1.getStringFromFile(xeroConfig.privateKeyPath) : null; | ||
var userAgentString = 'NodeJS-XeroAPIClient'; | ||
const API_BASE = process.env.XERO_API_BASE ? process.env.XERO_API_BASE : 'https://api.xero.com'; | ||
const OAUTH_REQUEST_TOKEN_PATH = '/oauth/RequestToken'; | ||
const OAUTH_ACCESS_TOKEN_PATH = '/oauth/AccessToken'; | ||
let cert = xeroConfig.privateKeyPath ? utils_1.getStringFromFile(xeroConfig.privateKeyPath) : null; | ||
let userAgentString = 'NodeJS-XeroAPIClient'; | ||
if (xeroConfig.userAgent) { | ||
@@ -48,3 +48,3 @@ userAgentString = userAgentString + '.' + xeroConfig.userAgent; | ||
} | ||
var oauthConfig = { | ||
const oauthConfig = { | ||
apiBaseUrl: API_BASE, | ||
@@ -74,3 +74,3 @@ apiBasePath: apiConfig.apiBasePath || '', | ||
else { | ||
throw new Error("Unrecognised app type: " + xeroConfig.appType + " (expected private|public|partner)"); | ||
throw new Error(`Unrecognised app type: ${xeroConfig.appType} (expected private|public|partner)`); | ||
} | ||
@@ -80,1 +80,2 @@ return oauthConfig; | ||
exports.mapConfig = mapConfig; | ||
//# sourceMappingURL=config-helper.js.map |
@@ -0,0 +0,0 @@ /// <reference types="node" /> |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -21,40 +10,12 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
}; | ||
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 http = require("http"); | ||
var https = require("https"); | ||
var oauth_1 = require("oauth"); | ||
var querystring = require("querystring"); | ||
var URL = require("url"); | ||
var XeroError_1 = require("../XeroError"); | ||
const http = require("http"); | ||
const https = require("https"); | ||
const oauth_1 = require("oauth"); | ||
const querystring = require("querystring"); | ||
const URL = require("url"); | ||
const XeroError_1 = require("../XeroError"); | ||
/** @private */ | ||
var OAuth1HttpClient = /** @class */ (function () { | ||
function OAuth1HttpClient(config, authState, oAuthLibFactory) { | ||
var _this = this; | ||
class OAuth1HttpClient { | ||
constructor(config, authState, oAuthLibFactory) { | ||
this.config = config; | ||
@@ -68,81 +29,72 @@ this.oAuthLibFactory = oAuthLibFactory; | ||
}; | ||
this.getRequestToken = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.resetToDefaultHeaders(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.oauthLib.getOAuthRequestToken(function (err, oauth_token, oauth_token_secret, result) { | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, null) : err); | ||
} | ||
else { | ||
resolve({ | ||
oauth_token: oauth_token, | ||
oauth_token_secret: oauth_token_secret | ||
}); | ||
} | ||
this.getRequestToken = () => __awaiter(this, void 0, void 0, function* () { | ||
this.resetToDefaultHeaders(); | ||
return new Promise((resolve, reject) => { | ||
this.oauthLib.getOAuthRequestToken((err, oauth_token, oauth_token_secret, result) => { | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, null) : err); | ||
} | ||
else { | ||
resolve({ | ||
oauth_token, | ||
oauth_token_secret | ||
}); | ||
})]; | ||
} | ||
}); | ||
}); | ||
}); }; | ||
this.buildAuthoriseUrl = function (requestToken) { | ||
return _this.config.apiBaseUrl + "/oauth/Authorize?oauth_token=" + requestToken.oauth_token; | ||
}); | ||
this.buildAuthoriseUrl = (requestToken) => { | ||
return `${this.config.apiBaseUrl}/oauth/Authorize?oauth_token=${requestToken.oauth_token}`; | ||
}; | ||
this.swapRequestTokenforAccessToken = function (requestToken, oauth_verifier) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.resetToDefaultHeaders(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_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, null) : err); | ||
} | ||
else { | ||
var currentMilliseconds = new Date().getTime(); | ||
var expDate = new Date(currentMilliseconds + (results.oauth_expires_in * 1000)); | ||
var oauthState = { | ||
oauth_token: oauth_token, | ||
oauth_token_secret: oauth_token_secret, | ||
oauth_session_handle: results.oauth_session_handle, | ||
oauth_expires_at: expDate | ||
}; | ||
_this.setState(oauthState); | ||
resolve(oauthState); | ||
} | ||
}); | ||
})]; | ||
this.swapRequestTokenforAccessToken = (requestToken, oauth_verifier) => __awaiter(this, void 0, void 0, function* () { | ||
this.resetToDefaultHeaders(); | ||
return new Promise((resolve, reject) => { | ||
this.oauthLib.getOAuthAccessToken(requestToken.oauth_token, requestToken.oauth_token_secret, oauth_verifier, (err, oauth_token, oauth_token_secret, results) => { | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, null) : err); | ||
} | ||
else { | ||
const currentMilliseconds = new Date().getTime(); | ||
const expDate = new Date(currentMilliseconds + (results.oauth_expires_in * 1000)); | ||
const oauthState = { | ||
oauth_token: oauth_token, | ||
oauth_token_secret: oauth_token_secret, | ||
oauth_session_handle: results.oauth_session_handle, | ||
oauth_expires_at: expDate | ||
}; | ||
this.setState(oauthState); | ||
resolve(oauthState); | ||
} | ||
}); | ||
}); | ||
}); }; | ||
this.refreshAccessToken = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
// We're accessing this "private" method as the lib does not allow refresh with oauth_session_handle. | ||
_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, response ? response.headers : null) : err); | ||
} | ||
else { | ||
var results = querystring.parse(data); | ||
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_session_handle: results.oauth_session_handle, | ||
oauth_expires_at: expDate | ||
}; | ||
_this.setState(oauthState); | ||
resolve(oauthState); | ||
} | ||
}); | ||
})]; | ||
}); | ||
this.refreshAccessToken = () => __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
// We're accessing this "private" method as the lib does not allow refresh with oauth_session_handle. | ||
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, (err, data, response) => { | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, response ? response.headers : null) : err); | ||
} | ||
else { | ||
const results = querystring.parse(data); | ||
const currentMilliseconds = new Date().getTime(); | ||
const expDate = new Date(currentMilliseconds + (results.oauth_expires_in * 1000)); | ||
const oauthState = { | ||
oauth_token: results.oauth_token, | ||
oauth_token_secret: results.oauth_token_secret, | ||
oauth_session_handle: results.oauth_session_handle, | ||
oauth_expires_at: expDate | ||
}; | ||
this.setState(oauthState); | ||
resolve(oauthState); | ||
} | ||
}); | ||
}); | ||
}); }; | ||
this.writeUTF8ResponseToStream = function (endpoint, mimeType, writeStream) { | ||
_this.resetToDefaultHeaders(); | ||
return new Promise(function (resolve, reject) { | ||
_this.assertAccessTokenIsSet(); | ||
var oauthForPdf = _this.oAuthLibFactory(__assign({}, _this.config, { accept: mimeType })); | ||
var request = oauthForPdf.get(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, _this._state.oauth_token, _this._state.oauth_token_secret); | ||
}); | ||
this.writeUTF8ResponseToStream = (endpoint, mimeType, writeStream) => { | ||
this.resetToDefaultHeaders(); | ||
return new Promise((resolve, reject) => { | ||
this.assertAccessTokenIsSet(); | ||
const oauthForPdf = this.oAuthLibFactory(Object.assign({}, this.config, { accept: mimeType })); | ||
const request = oauthForPdf.get(this.config.apiBaseUrl + this.config.apiBasePath + endpoint, this._state.oauth_token, this._state.oauth_token_secret); | ||
request.addListener('response', function (response) { | ||
@@ -164,8 +116,8 @@ response.on('data', function (chunk) { | ||
}; | ||
this.writeBinaryResponseToStream = function (endpoint, mimeType, writeStream) { | ||
_this.resetToDefaultHeaders(); | ||
return new Promise(function (resolve, reject) { | ||
_this.assertAccessTokenIsSet(); | ||
var forPDF = _this.oAuthLibFactory(__assign({}, _this.config, { accept: mimeType })); | ||
_this._OURperformSecureRequest(_this._state.oauth_token, _this._state.oauth_token_secret, 'GET', _this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, function (err, data, httpResponse) { | ||
this.writeBinaryResponseToStream = (endpoint, mimeType, writeStream) => { | ||
this.resetToDefaultHeaders(); | ||
return new Promise((resolve, reject) => { | ||
this.assertAccessTokenIsSet(); | ||
const forPDF = this.oAuthLibFactory(Object.assign({}, this.config, { accept: mimeType })); | ||
this._OURperformSecureRequest(this._state.oauth_token, this._state.oauth_token_secret, 'GET', this.config.apiBaseUrl + this.config.apiBasePath + endpoint, (err, data, httpResponse) => { | ||
// data is the body of the response | ||
@@ -176,4 +128,4 @@ if (err) { | ||
else { | ||
var buffer = Buffer.from(data, 'binary'); | ||
writeStream.write(buffer, function () { | ||
const buffer = Buffer.from(data, 'binary'); | ||
writeStream.write(buffer, () => { | ||
writeStream.close(); | ||
@@ -188,4 +140,4 @@ return resolve(); | ||
// This code was copied out from the lib as it does not support binary downloads. | ||
var orderedParameters = oauthForBinary._prepareParameters(oauth_token, oauth_token_secret, method, url, null); | ||
var parsedUrl = URL.parse(url, false); | ||
const orderedParameters = oauthForBinary._prepareParameters(oauth_token, oauth_token_secret, method, url, null); | ||
const parsedUrl = URL.parse(url, false); | ||
if (parsedUrl.protocol == 'http:' && !parsedUrl.port) { | ||
@@ -197,7 +149,7 @@ parsedUrl.port = '80'; | ||
} | ||
var headers = {}; | ||
var authorization = oauthForBinary._buildAuthorizationHeaders(orderedParameters); | ||
const headers = {}; | ||
const authorization = oauthForBinary._buildAuthorizationHeaders(orderedParameters); | ||
headers['Authorization'] = authorization; | ||
headers['Host'] = parsedUrl.host; | ||
for (var key in this._headers) { | ||
for (const key in this._headers) { | ||
if (this._headers.hasOwnProperty(key)) { | ||
@@ -208,3 +160,3 @@ headers[key] = this._headers[key]; | ||
headers['Content-length'] = 0; | ||
var path; | ||
let path; | ||
if (!parsedUrl.pathname || parsedUrl.pathname == '') { | ||
@@ -220,3 +172,3 @@ parsedUrl.pathname = '/'; | ||
} | ||
var request; | ||
let request; | ||
// tslint:disable-next-line:prefer-conditional-expression | ||
@@ -229,3 +181,3 @@ if (parsedUrl.protocol == 'https:') { | ||
} | ||
var data = ''; | ||
let data = ''; | ||
function passBackControl(response) { | ||
@@ -256,16 +208,16 @@ if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
}; | ||
this.readStreamToRequest = function (endpoint, mimeType, size, readStream) { | ||
_this.resetToDefaultHeaders(); | ||
return new Promise(function (resolve, reject) { | ||
_this.assertAccessTokenIsSet(); | ||
_this.resetToDefaultHeaders(); | ||
var bufs = []; | ||
this.readStreamToRequest = (endpoint, mimeType, size, readStream) => { | ||
this.resetToDefaultHeaders(); | ||
return new Promise((resolve, reject) => { | ||
this.assertAccessTokenIsSet(); | ||
this.resetToDefaultHeaders(); | ||
const bufs = []; | ||
readStream | ||
.on('data', function (chunk) { | ||
.on('data', (chunk) => { | ||
bufs.push(chunk); | ||
}) | ||
.on('end', function () { | ||
_this.oauthLib._headers = __assign({}, _this._defaultHeaders, { 'Content-Type': mimeType, 'Content-Length': size }); | ||
_this.oauthLib.post(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_this._state.oauth_token, _this._state.oauth_token_secret, Buffer.concat(bufs), mimeType, function (err, data, httpResponse) { | ||
.on('end', () => { | ||
this.oauthLib._headers = Object.assign({}, this._defaultHeaders, { 'Content-Type': mimeType, 'Content-Length': size }); | ||
this.oauthLib.post(this.config.apiBaseUrl + this.config.apiBasePath + endpoint, // url | ||
this._state.oauth_token, this._state.oauth_token_secret, Buffer.concat(bufs), mimeType, (err, data, httpResponse) => { | ||
if (err) { | ||
@@ -275,3 +227,3 @@ reject(new XeroError_1.XeroError(httpResponse.statusCode, data, httpResponse ? httpResponse.headers : null)); | ||
else { | ||
var toReturn = JSON.parse(data); | ||
const toReturn = JSON.parse(data); | ||
return resolve(toReturn); | ||
@@ -283,116 +235,101 @@ } | ||
}; | ||
this.get = function (endpoint, customHeaders) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = __assign({}, this._defaultHeaders, customHeaders); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.assertAccessTokenIsSet(); | ||
_this.oauthLib.get(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_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, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
var toReturn = JSON.parse(data); | ||
return resolve(toReturn); | ||
} | ||
}); | ||
})]; | ||
}); | ||
}); }; | ||
this.put = function (endpoint, body, customHeaders) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = __assign({}, this._defaultHeaders, customHeaders); | ||
this.get = (endpoint, customHeaders) => __awaiter(this, void 0, void 0, function* () { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = Object.assign({}, this._defaultHeaders, customHeaders); | ||
return new Promise((resolve, reject) => { | ||
this.assertAccessTokenIsSet(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.oauthLib.put(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_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, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
var toReturn = JSON.parse(data); | ||
return resolve(toReturn); | ||
} | ||
}); | ||
})]; | ||
this.oauthLib.get(this.config.apiBaseUrl + this.config.apiBasePath + endpoint, // url | ||
this._state.oauth_token, this._state.oauth_token_secret, (err, data, httpResponse) => { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
const toReturn = JSON.parse(data); | ||
return resolve(toReturn); | ||
} | ||
}); | ||
}); | ||
}); }; | ||
this.post = function (endpoint, body, customHeaders) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = __assign({}, this._defaultHeaders, customHeaders); | ||
this.assertAccessTokenIsSet(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.oauthLib.post(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_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, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
var toReturn = null; | ||
if (data) { | ||
toReturn = JSON.parse(data); | ||
} | ||
return resolve(toReturn); | ||
} | ||
}); | ||
})]; | ||
}); | ||
this.put = (endpoint, body, customHeaders) => __awaiter(this, void 0, void 0, function* () { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = Object.assign({}, this._defaultHeaders, customHeaders); | ||
this.assertAccessTokenIsSet(); | ||
return new Promise((resolve, reject) => { | ||
this.oauthLib.put(this.config.apiBaseUrl + this.config.apiBasePath + endpoint, // url | ||
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', (err, data, httpResponse) => { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
const toReturn = JSON.parse(data); | ||
return resolve(toReturn); | ||
} | ||
}); | ||
}); | ||
}); }; | ||
this.patch = function (endpoint, body, customHeaders) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = __assign({}, this._defaultHeaders, customHeaders); | ||
this.assertAccessTokenIsSet(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.oauthLib.patch(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_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, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
var toReturn = JSON.parse(data); | ||
return resolve(toReturn); | ||
} | ||
}); | ||
})]; | ||
}); | ||
this.post = (endpoint, body, customHeaders) => __awaiter(this, void 0, void 0, function* () { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = Object.assign({}, this._defaultHeaders, customHeaders); | ||
this.assertAccessTokenIsSet(); | ||
return new Promise((resolve, reject) => { | ||
this.oauthLib.post(this.config.apiBaseUrl + this.config.apiBasePath + endpoint, // url | ||
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', (err, data, httpResponse) => { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
let toReturn = null; | ||
if (data) { | ||
toReturn = JSON.parse(data); | ||
} | ||
return resolve(toReturn); | ||
} | ||
}); | ||
}); | ||
}); }; | ||
this.delete = function (endpoint, customHeaders) { return __awaiter(_this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = __assign({}, this._defaultHeaders, customHeaders); | ||
this.assertAccessTokenIsSet(); | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
_this.oauthLib.delete(_this.config.apiBaseUrl + _this.config.apiBasePath + endpoint, // url | ||
_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, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
var toReturn = null; | ||
if (data) { | ||
toReturn = JSON.parse(data); | ||
} | ||
return resolve(toReturn); | ||
} | ||
}); | ||
})]; | ||
}); | ||
this.patch = (endpoint, body, customHeaders) => __awaiter(this, void 0, void 0, function* () { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = Object.assign({}, this._defaultHeaders, customHeaders); | ||
this.assertAccessTokenIsSet(); | ||
return new Promise((resolve, reject) => { | ||
this.oauthLib.patch(this.config.apiBaseUrl + this.config.apiBasePath + endpoint, // url | ||
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', (err, data, httpResponse) => { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
const toReturn = JSON.parse(data); | ||
return resolve(toReturn); | ||
} | ||
}); | ||
}); | ||
}); }; | ||
}); | ||
this.delete = (endpoint, customHeaders) => __awaiter(this, void 0, void 0, function* () { | ||
this.resetToDefaultHeaders(); | ||
this.oauthLib._headers = Object.assign({}, this._defaultHeaders, customHeaders); | ||
this.assertAccessTokenIsSet(); | ||
return new Promise((resolve, reject) => { | ||
this.oauthLib.delete(this.config.apiBaseUrl + this.config.apiBasePath + endpoint, // url | ||
this._state.oauth_token, this._state.oauth_token_secret, (err, data, httpResponse) => { | ||
// data is the body of the response | ||
if (err) { | ||
reject(err.statusCode ? new XeroError_1.XeroError(err.statusCode, err.data, httpResponse ? httpResponse.headers : null) : err); | ||
} | ||
else { | ||
let toReturn = null; | ||
if (data) { | ||
toReturn = JSON.parse(data); | ||
} | ||
return resolve(toReturn); | ||
} | ||
}); | ||
}); | ||
}); | ||
if (authState) { | ||
@@ -403,5 +340,5 @@ this._state = authState; | ||
this.oAuthLibFactory = function (passedInConfig) { | ||
var requestTokenPath = passedInConfig.oauthRequestTokenPath; | ||
let requestTokenPath = passedInConfig.oauthRequestTokenPath; | ||
if (passedInConfig.tenantType) { | ||
requestTokenPath += "?tenantType=" + passedInConfig.tenantType; | ||
requestTokenPath += `?tenantType=${passedInConfig.tenantType}`; | ||
} | ||
@@ -425,16 +362,16 @@ return new oauth_1.OAuth(passedInConfig.apiBaseUrl + requestTokenPath, // requestTokenUrl | ||
} | ||
OAuth1HttpClient.prototype.resetToDefaultHeaders = function () { | ||
resetToDefaultHeaders() { | ||
this.oauthLib._headers = this._defaultHeaders; | ||
}; | ||
OAuth1HttpClient.prototype.setState = function (newState) { | ||
this._state = __assign({}, this._state, newState); | ||
}; | ||
OAuth1HttpClient.prototype.assertAccessTokenIsSet = function () { | ||
} | ||
setState(newState) { | ||
this._state = Object.assign({}, this._state, newState); | ||
} | ||
assertAccessTokenIsSet() { | ||
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.'); | ||
} | ||
}; | ||
} | ||
// Monkey-patched OAuthLib _createClient function to add proxy support | ||
OAuth1HttpClient.prototype._createHttpClientWithProxySupport = function (port, hostname, method, path, headers, sslEnabled) { | ||
var options = { | ||
_createHttpClientWithProxySupport(port, hostname, method, path, headers, sslEnabled) { | ||
const options = { | ||
host: hostname, | ||
@@ -446,3 +383,3 @@ port: port, | ||
}; | ||
var httpModel = sslEnabled ? https : http; | ||
const httpModel = sslEnabled ? https : http; | ||
if (this.agent) { | ||
@@ -452,5 +389,5 @@ options.agent = this.agent; | ||
return httpModel.request(options); | ||
}; | ||
return OAuth1HttpClient; | ||
}()); | ||
} | ||
} | ||
exports.OAuth1HttpClient = OAuth1HttpClient; | ||
//# sourceMappingURL=OAuth1HttpClient.js.map |
@@ -0,0 +0,0 @@ /** @internalapi */ |
"use strict"; | ||
/** @internalapi */ | ||
/** This second comment is required for typedoc to recognise the WHOLE FILE as @internalapi */ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var path = require("path"); | ||
var fs = require("fs"); | ||
var querystring = require("querystring"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const querystring = require("querystring"); | ||
/** @private */ | ||
function getStringFromFile(location) { | ||
var privateKeyFile = path.resolve(location); | ||
var privateKey = fs.readFileSync(privateKeyFile, 'utf8'); | ||
const privateKeyFile = path.resolve(location); | ||
const privateKey = fs.readFileSync(privateKeyFile, 'utf8'); | ||
return privateKey; | ||
@@ -32,10 +21,8 @@ } | ||
/** @private */ | ||
function generateQueryString(args, addSummarizeErrorsParam) { | ||
if (addSummarizeErrorsParam === void 0) { addSummarizeErrorsParam = false; } | ||
var argsToUse = __assign({}, args); | ||
function generateQueryString(args, addSummarizeErrorsParam = false) { | ||
const argsToUse = Object.assign({}, args); | ||
if (addSummarizeErrorsParam && argsToUse.summarizeErrors == undefined) { | ||
argsToUse.summarizeErrors = false; | ||
} | ||
for (var _i = 0, _a = Object.keys(argsToUse); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
for (const key of Object.keys(argsToUse)) { | ||
if (argsToUse[key] == undefined) { | ||
@@ -53,1 +40,2 @@ delete argsToUse[key]; | ||
exports.generateQueryString = generateQueryString; | ||
//# sourceMappingURL=utils.js.map |
@@ -0,0 +0,0 @@ import { XeroClientConfiguration, BaseAPIClient } from './internals/BaseAPIClient'; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var BaseAPIClient_1 = require("./internals/BaseAPIClient"); | ||
const BaseAPIClient_1 = require("./internals/BaseAPIClient"); | ||
/** @private */ | ||
var PracticeAPIClient = /** @class */ (function (_super) { | ||
__extends(PracticeAPIClient, _super); | ||
function PracticeAPIClient(options, authState, _oAuth1HttpClient) { | ||
return _super.call(this, options, authState, { | ||
class PracticeAPIClient extends BaseAPIClient_1.BaseAPIClient { | ||
constructor(options, authState, _oAuth1HttpClient) { | ||
super(options, authState, { | ||
tenantType: 'PRACTICE' | ||
}, _oAuth1HttpClient) || this; | ||
}, _oAuth1HttpClient); | ||
} | ||
return PracticeAPIClient; | ||
}(BaseAPIClient_1.BaseAPIClient)); | ||
} | ||
exports.PracticeAPIClient = PracticeAPIClient; | ||
//# sourceMappingURL=PracticeAPIClient.js.map |
@@ -0,0 +0,0 @@ interface CurrencyAmount { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ProjectsAPI-models.js.map |
@@ -0,0 +0,0 @@ import { Project } from './ProjectsAPI-models'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ProjectsAPI-responses.js.map |
@@ -0,0 +0,0 @@ import { BaseAPIClient, XeroClientConfiguration } from './internals/BaseAPIClient'; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -23,69 +10,31 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
}; | ||
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 BaseAPIClient_1 = require("./internals/BaseAPIClient"); | ||
var utils_1 = require("./internals/utils"); | ||
var ProjectsAPIClient = /** @class */ (function (_super) { | ||
__extends(ProjectsAPIClient, _super); | ||
function ProjectsAPIClient(options, authState, _oAuth1HttpClient) { | ||
var _this = _super.call(this, options, authState, { apiBasePath: '/projects.xro/1.0/' }, _oAuth1HttpClient) || this; | ||
_this.projects = { | ||
get: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'projects'; | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
getSingle: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'projects'; | ||
if (args && args.projectId) { | ||
endpoint = endpoint + '/' + args.projectId; | ||
delete args.projectId; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return [2 /*return*/, this.oauth1Client.get(endpoint)]; | ||
}); | ||
}); }, | ||
create: function (args) { return __awaiter(_this, void 0, void 0, function () { | ||
var endpoint; | ||
return __generator(this, function (_a) { | ||
endpoint = 'projects'; | ||
return [2 /*return*/, this.oauth1Client.post(endpoint, args)]; | ||
}); | ||
}); }, | ||
const BaseAPIClient_1 = require("./internals/BaseAPIClient"); | ||
const utils_1 = require("./internals/utils"); | ||
class ProjectsAPIClient extends BaseAPIClient_1.BaseAPIClient { | ||
constructor(options, authState, _oAuth1HttpClient) { | ||
super(options, authState, { apiBasePath: '/projects.xro/1.0/' }, _oAuth1HttpClient); | ||
this.projects = { | ||
get: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'projects'; | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
getSingle: (args) => __awaiter(this, void 0, void 0, function* () { | ||
let endpoint = 'projects'; | ||
if (args && args.projectId) { | ||
endpoint = endpoint + '/' + args.projectId; | ||
delete args.projectId; | ||
} | ||
endpoint += utils_1.generateQueryString(args); | ||
return this.oauth1Client.get(endpoint); | ||
}), | ||
create: (args) => __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'projects'; | ||
return this.oauth1Client.post(endpoint, args); | ||
}), | ||
}; | ||
return _this; | ||
} | ||
return ProjectsAPIClient; | ||
}(BaseAPIClient_1.BaseAPIClient)); | ||
} | ||
exports.ProjectsAPIClient = ProjectsAPIClient; | ||
//# sourceMappingURL=ProjectsAPIClient.js.map |
@@ -0,0 +0,0 @@ export declare class XeroError extends Error { |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var querystring = require("querystring"); | ||
var XeroError = /** @class */ (function (_super) { | ||
__extends(XeroError, _super); | ||
function XeroError(statusCode, data, headers) { | ||
var _newTarget = this.constructor; | ||
var _this = this; | ||
var message = 'XeroError:'; | ||
var queryobj = querystring.parse(data); | ||
const querystring = require("querystring"); | ||
class XeroError extends Error { | ||
constructor(statusCode, data, headers) { | ||
let message = 'XeroError:'; | ||
const queryobj = querystring.parse(data); | ||
if (queryobj.oauth_problem && queryobj.oauth_problem_advice) { | ||
@@ -28,17 +12,16 @@ if (statusCode == 503 && headers) { | ||
} | ||
message += " " + queryobj.oauth_problem + " (" + queryobj.oauth_problem_advice + ")"; | ||
message += ` ${queryobj.oauth_problem} (${queryobj.oauth_problem_advice})`; | ||
} | ||
else { | ||
message += " statusCode=" + statusCode + " data=" + data; | ||
message += ` statusCode=${statusCode} data=${data}`; | ||
} | ||
_this = _super.call(this, message) || this; | ||
super(message); | ||
// https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200 | ||
_this.__proto__ = _newTarget.prototype; | ||
_this.statusCode = statusCode; | ||
_this.data = data; | ||
_this.headers = headers; | ||
return _this; | ||
this.__proto__ = new.target.prototype; | ||
this.statusCode = statusCode; | ||
this.data = data; | ||
this.headers = headers; | ||
} | ||
return XeroError; | ||
}(Error)); | ||
} | ||
exports.XeroError = XeroError; | ||
//# sourceMappingURL=XeroError.js.map |
@@ -0,0 +0,0 @@ Copyright (c) 2017 Xero Limited |
{ | ||
"name": "xero-node", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "NodeJS Client for the Xero API, supporting Public, Private and Partner Apps", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "npm run lint && tsc", | ||
"build": "npm run lint -- --quiet && tsc", | ||
"build-watch": "tsc --watch", | ||
"build-docs": "typedoc --options ./typedoc.config.js ./src", | ||
"lint": "tslint ./src/**/*.ts", | ||
"build-docs": "typedoc", | ||
"lint": "eslint --ext=.ts ./src", | ||
"prepublishOnly": "npm run build", | ||
"test-watch": "tsc --noEmit && jest --config ./jestconfig.js --watch", | ||
"test": "tsc --noEmit && jest --config ./jestconfig.js", | ||
"test-ci": "tsc --noEmit && jest --runInBand --config ./jestconfig.js --ci --testResultsProcessor=jest-junit", | ||
"test-watch": "tsc --noEmit && jest --watch", | ||
"test": "tsc --noEmit && jest", | ||
"test-auth": "tsc --noEmit && jest ./src/__integration_tests__/partner-example.tests.ts", | ||
"test-ci": "tsc --noEmit && jest --runInBand --ci --reporters=default --reporters=jest-junit", | ||
"scratch": "ts-node ./src/scratch.ts", | ||
@@ -27,11 +28,15 @@ "create-key": "node ./.circleci/create_private_key.js" | ||
"devDependencies": { | ||
"@types/es6-promise": "3.3.0", | ||
"@types/jest": "^24.0.0", | ||
"@types/jest": "24.0.17", | ||
"@types/node": "9.4.0", | ||
"@types/puppeteer": "^1.19.1", | ||
"jest": "^24.9.0", | ||
"jest-junit": "3.6.0", | ||
"@types/puppeteer": "1.1.0", | ||
"@typescript-eslint/eslint-plugin": "2.0.0", | ||
"@typescript-eslint/parser": "2.0.0", | ||
"eslint": "6.1.0", | ||
"eslint-config-prettier": "6.0.0", | ||
"eslint-plugin-prettier": "3.1.0", | ||
"jest": "24.9.0", | ||
"jest-junit": "7.0.0", | ||
"nodemon": "^1.18.7", | ||
"opn": "5.2.0", | ||
"prettier": "^1.18.2", | ||
"prettier": "1.18.2", | ||
"prompt": "1.0.0", | ||
@@ -41,5 +46,5 @@ "puppeteer": "^1.19.0", | ||
"ts-node": "4.1.0", | ||
"tslint": "5.16.0", | ||
"typedoc": "0.15.0", | ||
"typescript": "3.5.3" | ||
} | ||
} |
@@ -0,5 +1,24 @@ | ||
# xero-node | ||
## Looking for OAuth 2.0 support? | ||
[![npm version](https://badge.fury.io/js/xero-node.svg)](https://badge.fury.io/js/xero-node) | ||
xero-node with OAuth 2.0 support is available on npm with beta tag removed. | ||
Examples and code is located in the [oauth2 branch](https://github.com/XeroAPI/xero-node/tree/oauth2) (will be promoted to master soon). Please submit pull requests to the `oauth2` branch for review and submit issues for us to review. | ||
> Version 4 is a complete rewrite of xero-node and not a continuation of version 3. | ||
> All OAuth 2.0 SDKs built by Xero will be generated from our [OpenAPI 3.0](https://github.com/XeroAPI/Xero-OpenAPI) specifications. | ||
> We still welcome your feedbacks and PRs - please see [guidelines around contributing](https://github.com/XeroAPI/xero-node/blob/oauth2/CONTRIBUTING.md). | ||
> A [kitchen sync app](https://github.com/XeroAPI/xero-node-oauth2-app) is available that demonstrates interacting with each endpoint. | ||
## Looking for OAuth 1.0a support? | ||
[![npm package](https://img.shields.io/badge/npm%20package-3.1.1-blue.svg)](https://www.npmjs.com/package/xero-node/v/3.1.1) | ||
[![CircleCI](https://circleci.com/gh/XeroAPI/xero-node/tree/master.svg?style=svg)](https://circleci.com/gh/XeroAPI/xero-node/tree/master) | ||
# xero-node | ||
xero-node 3.xx with OAuth 1.0a support is available on npm. | ||
@@ -63,2 +82,51 @@ NodeJS Client for the [Xero API](http://developer.xero.com). Works with ES5, ES6+ and TypeScript. | ||
Express.JS WebHook event listener - exmaple uses contacts | ||
```javascript | ||
// Xero webhook for contact creation | ||
app.post("/contactadded", itrBodyParser, (req, res) => { | ||
// do Xero auth check | ||
let hmac = crypto.createHmac("sha256", xeroWebhookKey).update(req.body.toString()).digest("base64"); | ||
// parse to json here - doing it in express messes with the hmac | ||
const body = JSON.parse(req.body); | ||
// check if you have events/contacts | ||
if (Object.keys(body.events).length > 0) { | ||
// iterate through each new event/contact - can get multiple at a time | ||
Object.entries(body.events).forEach(async (contact) => { | ||
// grab the resource ID of the current contact | ||
const resourceID = contact[1].resourceId; | ||
// initialise xeroclient library (xero-node) | ||
let xero = new XeroClient(xeroApplicationConfig); | ||
// get contact speficied by the ContactID: resourceID | ||
const result = await xero.contacts.get({ ContactID: resourceID }); | ||
/* | ||
* Do stuff with your new contact data eg: | ||
* Send welcome email to new client | ||
* Push contact information onto your CRM | ||
*/ | ||
}); | ||
} | ||
// send hmac response to Xero | ||
if (req.headers['x-xero-signature'] == hmac) { | ||
console.log("Success HMAC TEST"); | ||
res.status(200); | ||
} else { | ||
console.log("Failed HMAC TEST"); | ||
res.status(401); | ||
} | ||
res.send(); | ||
}) | ||
``` | ||
# Usage Example for Public and Partner Apps | ||
@@ -65,0 +133,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
430904
319
19
32
2951
6