Skip to content

Commit

Permalink
v2.1.0 minor release (#52)
Browse files Browse the repository at this point in the history
* Handle large Http responses with fetch
* Remove AbstractApPayment class, not needed
* Fix minor defects and update unit tests
* Dependency updates
  • Loading branch information
intacctcoleenho authored Dec 23, 2020
1 parent b76ddae commit 4287671
Show file tree
Hide file tree
Showing 22 changed files with 169 additions and 211 deletions.
194 changes: 103 additions & 91 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@intacct/intacct-sdk",
"version": "2.0.0",
"version": "2.1.0",
"description": "Sage Intacct SDK for JavaScript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -40,7 +40,7 @@
"doc": "rimraf doc && typedoc src/",
"pretest": "npm run build",
"test": "npm run tslint && npm run test-mocha",
"test-mocha": "mocha -require ts-node/register test/**/*.ts",
"test-mocha": "mocha -require ts-node/register \"test/**/*.ts\"",
"coverage": "nyc npm run test",
"preversion": "npm test",
"version": "npm run build",
Expand All @@ -55,7 +55,6 @@
"@types/mock-fs": "^4.13.0",
"@types/node": "^14.14.14",
"@types/uuid": "^8.3.0",
"@types/winston": "^2.4.4",
"@types/xml2js": "^0.4.7",
"@types/xmlbuilder": "^0.0.32",
"chai": "~4.2.0",
Expand All @@ -72,7 +71,7 @@
},
"dependencies": {
"content-type": "^1.0.4",
"dateformat": "^4.3.1",
"dateformat": "^4.4.1",
"ini": "^1.3.8",
"node-fetch": "^2.6.1",
"striptags": "^3.1.1",
Expand Down
25 changes: 0 additions & 25 deletions src/Functions/AccountsPayable/AbstractApPayment.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/Functions/AccountsPayable/ApPaymentConfirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class ApPaymentConfirm extends AbstractApPaymentFunction {
super(recordNo, controlId);
}

protected getFunction(): string {
protected getFunction(): string {
return AbstractApPaymentFunction.CONFIRM;
}
}
1 change: 1 addition & 0 deletions src/Functions/AccountsPayable/ApPaymentCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class ApPaymentCreate extends AbstractFunction {
super(controlId);
this.apPaymentInfo = apPaymentInfo;
}

public writeXml(xml: IaXmlWriter): void {
xml.writeStartElement("function");
xml.writeAttribute("controlid", this.controlId, true);
Expand Down
3 changes: 0 additions & 3 deletions src/Functions/AccountsPayable/ApPaymentDetailBill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export default class ApPaymentDetailBill implements IApPaymentDetail {
}

public writeXml(xml: IaXmlWriter): void {
{

xml.writeStartElement("APPYMTDETAIL");

xml.writeElement("RECORDKEY", this.info.recordNo, true);
Expand All @@ -53,4 +51,3 @@ export default class ApPaymentDetailBill implements IApPaymentDetail {
xml.writeEndElement(); // APPYMTDETAIL
}
}
}
1 change: 0 additions & 1 deletion src/Functions/AccountsPayable/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export { default as AbstractApAdjustment } from "./AbstractApAdjustment";
export { default as AbstractApAdjustmentLine } from "./AbstractApAdjustmentLine";
export { default as AbstractApAdjustmentSummary } from "./AbstractApAdjustmentSummary";
export { default as AbstractApPayment } from "./AbstractApPayment";
export { default as AbstractApPaymentDetailCredit } from "./AbstractApPaymentDetailCredit";
export { default as AbstractApPaymentFunction } from "./AbstractApPaymentFunction";
export { default as AbstractBill } from "./AbstractBill";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class InArrayInteger extends AbstractArrayInteger {
let notClause = "";

if (this.negate === true) {
notClause = "NOT ";
notClause = " NOT";
}

clause = this.field + notClause + " IN (" + this.valuesList.join(",") + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class InArrayString extends AbstractArrayString {
let notClause = "";

if (this.negate === true) {
notClause = "NOT ";
notClause = " NOT";
}

const pieces = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Functions/Purchasing/PurchasingTransactionApprove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default class PurchasingTransactionApprove extends AbstractPurchasingTran

xml.writeStartElement("PODOCUMENT");

xml.writeElement("DOCID", External);
xml.writeElement("DOCID", this.externalId);

xml.writeElement("COMMENT", Comment);
xml.writeElement("COMMENT", this.comment);

xml.writeEndElement(); // PODOCUMENT

Expand Down
4 changes: 2 additions & 2 deletions src/Functions/Purchasing/PurchasingTransactionDecline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default class PurchasingTransactionDecline extends AbstractPurchasingTran

xml.writeStartElement("PODOCUMENT");

xml.writeElement("DOCID", External);
xml.writeElement("DOCID", this.externalId);

xml.writeElement("COMMENT", Comment);
xml.writeElement("COMMENT", this.comment);

xml.writeEndElement(); // PODOCUMENT

Expand Down
11 changes: 9 additions & 2 deletions src/Xml/HttpClientHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ export default class HttpClientHandler {
this.options = options;
}

public async postAsync(): Promise<Response> {
return await fetch(this.options.url, this.options);
public async postAsync(): Promise<[Response, string]> {
try {
const response = await fetch(this.options.url, this.options);
const body = await response.text();

return Promise.all([response, body]);
} catch (error) {
throw new Error(error);
}
}
}
4 changes: 2 additions & 2 deletions src/Xml/IaXmlWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ export default class IaXmlWriter {
} else {
if (value == null) {
if (writeNull === true) {
this._writer.element(localName, value).up();
this._writer.element(localName, "").up();
}
} else {
this._writer.element(localName, value).up();
this._writer.element(localName, "").up();
}
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/Xml/LoggingHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@ export default class LoggingHandler extends HttpClientHandler {
this.logLevel = logLevel;
}

public async postAsync(): Promise<Response> {
let response;
public async postAsync(): Promise<[Response, string]> {

try {
this.logger.log(this.logLevel, this.logMessageFormatter.formatRequest(this.options));

response = await super.postAsync();

this.logger.log(this.logLevel,
this.logMessageFormatter.formatResponse(response,
await response.clone().text()));

return await super.postAsync().then(([response, body]) => {
this.logger.log(this.logLevel,
this.logMessageFormatter.formatResponse(response, body));
return Promise.all([response, body]);
});
} catch (error) {
this.logger.log(this.logLevel, error);
throw error;
}
return response;
}
}
27 changes: 15 additions & 12 deletions src/Xml/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ export default class RequestHandler {
}

const request = new RequestBlock(this.clientConfig, this.requestConfig, content);
const response = await this.execute(request.writeXml());

return new OnlineResponse(await response.clone().text());
return await this.execute(request.writeXml()).then((body) => {
return new OnlineResponse(body);
});
}

public async executeOffline(content: IFunction[]): Promise<OfflineResponse> {
Expand All @@ -83,9 +84,9 @@ export default class RequestHandler {
}

const request = new RequestBlock(this.clientConfig, this.requestConfig, content);
const response = await this.execute(request.writeXml());

return new OfflineResponse(await response.clone().text());
return await this.execute(request.writeXml()).then((body) => {
return new OfflineResponse(body);
});
}

private getHttpClient(options: object): HttpClientHandler {
Expand All @@ -101,7 +102,7 @@ export default class RequestHandler {
}
}

private async execute(xml: string): Promise<Response> {
private async execute(xml: string): Promise<string> {
const httpClient = this.getHttpClient({
url: this.endpointUrl,
method: "POST",
Expand All @@ -115,6 +116,7 @@ export default class RequestHandler {
"Accept-Encoding": "gzip",
"User-Agent": "intacct-sdk-js-client/" + this.version,
},
size: 0,
});

for (let attempt = 0; attempt <= this.requestConfig.maxRetries; attempt++) {
Expand All @@ -123,28 +125,29 @@ export default class RequestHandler {
await this.exponentialDelay(attempt);
}

const response = await httpClient.postAsync();
const result = await httpClient.postAsync();
const response = result[0];
const body = result[1];

let ok = true;
if (response.status >= 400 && response.status < 600) {
ok = false;
}
if (ok === true) {
return response;
return body;
} else if (this.requestConfig.noRetryServerErrorCodes.indexOf(response.status) !== -1) {
// Do not retry this explicitly set 500 level server error
throw new FetchError(response.status, response.text(), httpClient.options, response);
throw new FetchError(response.status, body, httpClient.options, response);
} else if (response.status >= 500 && response.status <= 599) {
// Retry 500 level server errors
continue;
} else {
const contentTypeObj = contentType.parse(response.headers.get("content-type"));
const mimeType = contentTypeObj.type;
if (mimeType === "text/xml" || mimeType === "application/xml") {
return response;
return body;
}

throw new FetchError(response.status, response.text(), httpClient.options, response);
throw new FetchError(response.status, body, httpClient.options, response);
}
}
throw new Error("Request retry count exceeded max retry count: " + this.requestConfig.maxRetries.toString());
Expand Down
32 changes: 0 additions & 32 deletions test/Functions/AccountsReceivable/ArPaymentCreateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,38 +110,6 @@ describe("ArPaymentCreate", () => {
applyToRecordB,
];

XmlObjectTestHelper.CompareXml(expected, record);
});
it("should generate XML to Create Payment against invoice header", () => {
const expected = `<?xml version="1.0" encoding="utf-8" ?>
<test>
<function controlid="unittest">
<create>
<ARPYMT>
<FINANCIALENTITY>BOA</FINANCIALENTITY>
<PAYMENTMETHOD>Cash</PAYMENTMETHOD>
<CUSTOMERID>JHC</CUSTOMERID>
<DOCNUMBER>INV-007</DOCNUMBER>
<RECEIPTDATE>05/15/2019</RECEIPTDATE>
<PAYMENTDATE>05/16/2019</PAYMENTDATE>
<ARPYMTDETAILS>
<ARPYMTDETAIL>
<RECORDKEY>101</RECORDKEY>
<TRX_PAYMENTAMOUNT>125</TRX_PAYMENTAMOUNT>
</ARPYMTDETAIL>
</ARPYMTDETAILS>
</ARPYMT>
</create>
</function>
</test>`;

const record = new ArPaymentCreate();
record.controlId = "unittest";
record.customerId = "C0020";
record.transactionPaymentAmount = 1922.12;
record.receivedDate = new Date("6/30/2016");
record.paymentMethod = "Printed Check";

XmlObjectTestHelper.CompareXml(expected, record);
});
});
8 changes: 4 additions & 4 deletions test/Functions/Common/NewQuery/QueryFilter/AndOperatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("AndOperator", () => {
() => {
const xml = new IaXmlWriter(xmlbuilder.create("request", {
"version": "1.0",
"encoding": this.encoding,
"encoding": "utf-8",
"standalone": null,
}));
const filter = (new AndOperator(
Expand All @@ -98,7 +98,7 @@ describe("AndOperator", () => {
() => {
const xml = new IaXmlWriter(xmlbuilder.create("request", {
"version": "1.0",
"encoding": this.encoding,
"encoding": "utf-8",
"standalone": null,
}));
const filter = new AndOperator([]);
Expand All @@ -114,7 +114,7 @@ describe("AndOperator", () => {
() => {
const xml = new IaXmlWriter(xmlbuilder.create("request", {
"version": "1.0",
"encoding": this.encoding,
"encoding": "utf-8",
"standalone": null,
}));
const filter = new AndOperator(null);
Expand Down Expand Up @@ -165,7 +165,7 @@ describe("AndOperator", () => {
() => {
const xml = new IaXmlWriter(xmlbuilder.create("request", {
"version": "1.0",
"encoding": this.encoding,
"encoding": "utf-8",
"standalone": null,
}));
const filter = new AndOperator();
Expand Down
Loading

0 comments on commit 4287671

Please sign in to comment.