@dotdev/harmony-sdk 1.27.1 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/HarmonyAPI.js
CHANGED
|
@@ -3,7 +3,7 @@ import axiosRetry from "axios-retry";
|
|
|
3
3
|
import * as https from "https";
|
|
4
4
|
import { promisify } from "util";
|
|
5
5
|
import { parseString } from "xml2js";
|
|
6
|
-
import logger from "./helpers/logger";
|
|
6
|
+
import { logger } from "./helpers/logger";
|
|
7
7
|
import { AuthModule, CarrierModule, DiaryModule, GiftVoucherModule, PointOfSaleModule, StockClassificationType, StockLevelLookupModule, StockLookupModule, } from "./modules";
|
|
8
8
|
require("tls").DEFAULT_MIN_VERSION = "TLSv1";
|
|
9
9
|
const parseXml = promisify(parseString);
|
package/dist/helpers/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import axios from "axios";
|
|
|
2
2
|
import { promisify } from "util";
|
|
3
3
|
import { parseString } from "xml2js";
|
|
4
4
|
import { RequestError } from "../errors";
|
|
5
|
-
import logger from "./logger";
|
|
5
|
+
import { logger } from "./logger";
|
|
6
6
|
import { Utils } from "./utils";
|
|
7
7
|
export * from "./utils";
|
|
8
8
|
const parseXml = promisify(parseString);
|
|
@@ -20,28 +20,26 @@ export class ApiHelper {
|
|
|
20
20
|
response = await axiosInstance.post(url, requestBody);
|
|
21
21
|
break;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
request: requestBody,
|
|
25
|
-
response:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
logger.debug({
|
|
24
|
+
request: Utils.removeTabsAndNewLines(requestBody),
|
|
25
|
+
response: {
|
|
26
|
+
data: response?.data,
|
|
27
|
+
headers: response?.headers,
|
|
28
|
+
size: +(response?.headers?.["content-length"] || 0),
|
|
29
|
+
status: response?.status,
|
|
30
|
+
},
|
|
31
|
+
}, `Received Harmony response 🔽`);
|
|
30
32
|
// Throw an error if the response is not in XML format
|
|
31
|
-
if (response?.headers
|
|
32
|
-
response?.headers
|
|
33
|
-
|
|
33
|
+
if (response?.headers["content-type"] !== "text/xml" &&
|
|
34
|
+
response?.headers["content-type"] !== "text/xml;charset=utf-8" &&
|
|
35
|
+
response?.headers["content-type"] !== "application/xml") {
|
|
36
|
+
logger.error(new Error(`Returned response not in XML format. This is likely a gateway error - [${response?.status} - ${response?.statusText}]: ${response.data}`));
|
|
34
37
|
}
|
|
35
38
|
// Parse the XML response
|
|
36
39
|
const result = (await parseXml(response?.data)); // fix type
|
|
37
40
|
return result["S:Envelope"]["S:Body"][0];
|
|
38
41
|
}
|
|
39
42
|
catch (error) {
|
|
40
|
-
const logs = logger.child({
|
|
41
|
-
request: requestBody,
|
|
42
|
-
error: error,
|
|
43
|
-
});
|
|
44
|
-
logs.error(`Error while when sending request to Harmony`);
|
|
45
43
|
throw await ApiHelper.parseError(error);
|
|
46
44
|
}
|
|
47
45
|
}
|
|
@@ -127,9 +125,10 @@ export class ApiHelper {
|
|
|
127
125
|
}
|
|
128
126
|
}
|
|
129
127
|
else {
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
console.log(JSON.stringify(error));
|
|
129
|
+
logger.error(`=============== Unexpected error occurred during API request ===============`);
|
|
132
130
|
}
|
|
131
|
+
return new RequestError(`Unexpected error occurred during API request`);
|
|
133
132
|
}
|
|
134
133
|
/**
|
|
135
134
|
* Extract error response from Harmony in XML format and convert it to JSON format for ease of debugging
|
package/dist/helpers/logger.d.ts
CHANGED
package/dist/helpers/logger.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { createGcpLoggingPinoConfig } from "@google-cloud/pino-logging-gcp-config";
|
|
2
|
-
import
|
|
3
|
-
const logger = pino
|
|
4
|
-
|
|
2
|
+
import pino from "pino";
|
|
3
|
+
export const logger = pino(createGcpLoggingPinoConfig({
|
|
4
|
+
serviceContext: {
|
|
5
|
+
service: "harmony-sdk",
|
|
6
|
+
},
|
|
7
|
+
}, {
|
|
8
|
+
// set Pino log level to 'debug'
|
|
9
|
+
level: "debug",
|
|
10
|
+
}));
|
package/dist/helpers/utils.d.ts
CHANGED
package/dist/helpers/utils.js
CHANGED
|
@@ -6,6 +6,7 @@ export class AuthModule {
|
|
|
6
6
|
this.axiosInstance = axiosInstance;
|
|
7
7
|
}
|
|
8
8
|
async authenticate(authToken) {
|
|
9
|
+
console.log(`===========================================================================`);
|
|
9
10
|
// @todo: TBC whether using `xmlbuilder` or template string
|
|
10
11
|
const authHeader = `
|
|
11
12
|
<ns2:AuthenticationToken xmlns:ns2="http://auth.ws.fbsaust.com.au" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
|
@@ -15,6 +16,7 @@ export class AuthModule {
|
|
|
15
16
|
<timeout>${authToken.timeout}${authToken.timeoutUnit}</timeout>
|
|
16
17
|
</ns2:AuthenticationToken>
|
|
17
18
|
`;
|
|
19
|
+
console.log(`authHeader`, authHeader);
|
|
18
20
|
const loginBody = '<ns2:Login xmlns:ns2="http://auth.ws.fbsaust.com.au"/>';
|
|
19
21
|
const soapEnvelope = `
|
|
20
22
|
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
|
@@ -22,6 +24,7 @@ export class AuthModule {
|
|
|
22
24
|
<S:Body>${loginBody}</S:Body>
|
|
23
25
|
</S:Envelope>
|
|
24
26
|
`;
|
|
27
|
+
console.log(`soapEnvelope`, soapEnvelope);
|
|
25
28
|
try {
|
|
26
29
|
const response = await ApiHelper.sendSoapRequest("/AuthenticationService/AuthenticationService", this.axiosInstance, soapEnvelope);
|
|
27
30
|
const token = response["ns2:LoginResponse"][0]["token"][0];
|
|
@@ -35,6 +38,8 @@ export class AuthModule {
|
|
|
35
38
|
throw error;
|
|
36
39
|
}
|
|
37
40
|
else {
|
|
41
|
+
console.error(`Auth error`);
|
|
42
|
+
console.error(error);
|
|
38
43
|
throw new AuthenticationError(`An unexpected error occurred: ${error.message}`);
|
|
39
44
|
}
|
|
40
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotdev/harmony-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"description": "Harmony API SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"watch": "tsc -w",
|
|
46
46
|
"test": "jest",
|
|
47
47
|
"release": "./release.sh",
|
|
48
|
-
"prettier": "prettier --write ."
|
|
48
|
+
"prettier": "prettier --write .",
|
|
49
|
+
"refreshLocal": "pnpm run build && yalc push --sig"
|
|
49
50
|
}
|
|
50
51
|
}
|