@dotdev/harmony-sdk 1.27.0 → 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);
|
|
@@ -13,43 +13,33 @@ export class ApiHelper {
|
|
|
13
13
|
let response;
|
|
14
14
|
switch (type) {
|
|
15
15
|
case "GET":
|
|
16
|
-
response = await axiosInstance.get(url)
|
|
17
|
-
logger.error(error, `Error while sending request to ${endpoint} endpoint`);
|
|
18
|
-
throw error;
|
|
19
|
-
});
|
|
16
|
+
response = await axiosInstance.get(url);
|
|
20
17
|
break;
|
|
21
18
|
case "POST":
|
|
22
19
|
default:
|
|
23
|
-
response = await axiosInstance
|
|
24
|
-
.post(url, requestBody)
|
|
25
|
-
.catch((error) => {
|
|
26
|
-
logger.error(error, `Error while sending request to ${endpoint} endpoint`);
|
|
27
|
-
throw error;
|
|
28
|
-
});
|
|
20
|
+
response = await axiosInstance.post(url, requestBody);
|
|
29
21
|
break;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
|
-
request: requestBody,
|
|
33
|
-
response:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 🔽`);
|
|
38
32
|
// Throw an error if the response is not in XML format
|
|
39
|
-
if (response?.headers
|
|
40
|
-
response?.headers
|
|
41
|
-
|
|
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}`));
|
|
42
37
|
}
|
|
43
38
|
// Parse the XML response
|
|
44
39
|
const result = (await parseXml(response?.data)); // fix type
|
|
45
40
|
return result["S:Envelope"]["S:Body"][0];
|
|
46
41
|
}
|
|
47
42
|
catch (error) {
|
|
48
|
-
const logs = logger.child({
|
|
49
|
-
request: requestBody,
|
|
50
|
-
error: error,
|
|
51
|
-
});
|
|
52
|
-
logs.error(`Error while when sending request to Harmony`);
|
|
53
43
|
throw await ApiHelper.parseError(error);
|
|
54
44
|
}
|
|
55
45
|
}
|
|
@@ -135,9 +125,10 @@ export class ApiHelper {
|
|
|
135
125
|
}
|
|
136
126
|
}
|
|
137
127
|
else {
|
|
138
|
-
|
|
139
|
-
|
|
128
|
+
console.log(JSON.stringify(error));
|
|
129
|
+
logger.error(`=============== Unexpected error occurred during API request ===============`);
|
|
140
130
|
}
|
|
131
|
+
return new RequestError(`Unexpected error occurred during API request`);
|
|
141
132
|
}
|
|
142
133
|
/**
|
|
143
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
|
}
|