@dotdev/harmony-sdk 1.27.1 → 1.28.1

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.
@@ -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);
@@ -144,7 +144,7 @@ export class HarmonyAPI {
144
144
  return this.giftVoucherModule.giftVoucherVerificationKey(params, sessionId);
145
145
  }
146
146
  async giftVoucherReservation(params, sessionId) {
147
- return this.giftVoucherModule.giftVoucherVerificationKey(params, sessionId);
147
+ return this.giftVoucherModule.giftVoucherReservation(params, sessionId);
148
148
  }
149
149
  async giftVoucherUsed(params, sessionId) {
150
150
  return this.giftVoucherModule.giftVoucherUsed(params, sessionId);
@@ -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
- const logs = logger.child({
24
- request: requestBody,
25
- response: response?.data,
26
- size: +(response?.headers?.["Content-Length"] || 0),
27
- status: response?.status,
28
- });
29
- logs.debug(`Received Harmony response: `);
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?.["Content-Type"] !== "text/xml" &&
32
- response?.headers?.["Content-Type"] !== "application/xml") {
33
- throw new Error(`Returned response not in XML format. This is likely a gateway error - [${response?.status} - ${response?.statusText}]: ${JSON.stringify(response)}`);
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
- logger.error(`Unexpected error occurred during API request`);
131
- throw JSON.stringify(error);
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
@@ -1,3 +1 @@
1
- import * as pino from "pino";
2
- declare const logger: pino.Logger<never, boolean>;
3
- export default logger;
1
+ export declare const logger: import("pino").Logger<never, boolean>;
@@ -1,4 +1,10 @@
1
1
  import { createGcpLoggingPinoConfig } from "@google-cloud/pino-logging-gcp-config";
2
- import * as pino from "pino";
3
- const logger = pino.pino(createGcpLoggingPinoConfig());
4
- export default logger;
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
+ }));
@@ -75,6 +75,7 @@ export declare abstract class Utils {
75
75
  * @returns
76
76
  */
77
77
  static isValidXml(xmlString: string): boolean;
78
+ static removeTabsAndNewLines(str?: string): string;
78
79
  }
79
80
  export declare const TEST_HEADERS: {
80
81
  headers: {
@@ -158,6 +158,11 @@ export class Utils {
158
158
  }
159
159
  return stack.length === 0;
160
160
  }
161
+ static removeTabsAndNewLines(str) {
162
+ if (!str)
163
+ return "";
164
+ return str.replace(/ |\r\n|\n|\r/gm, "");
165
+ }
161
166
  }
162
167
  export const TEST_HEADERS = {
163
168
  headers: {
@@ -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.27.1",
3
+ "version": "1.28.1",
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
  }