@dotdev/harmony-sdk 1.29.1 → 1.30.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.
@@ -28,7 +28,7 @@ export class ApiHelper {
28
28
  size: +(response?.headers?.["content-length"] || 0),
29
29
  status: response?.status,
30
30
  },
31
- }, `Received Harmony response 🔽`);
31
+ }, `Received Harmony response for ${endpoint} endpoint 🔽`);
32
32
  // Throw an error if the response is not in XML format
33
33
  if (response?.headers["content-type"] !== "text/xml" &&
34
34
  response?.headers["content-type"] !== "text/xml;charset=utf-8" &&
@@ -93,7 +93,7 @@ export class ApiHelper {
93
93
  const child = logger.child({
94
94
  request: requestBody,
95
95
  });
96
- child.debug(`Sending API request`);
96
+ child.debug(`Sending API request to ${serviceName} endpoint`);
97
97
  const response = await ApiHelper.sendSoapRequest(serviceName, axios, requestBody);
98
98
  return response[responseMethodName][0];
99
99
  }
@@ -1,6 +1,7 @@
1
1
  import { promisify } from "util";
2
2
  import xml2js, { parseString } from "xml2js";
3
3
  const parseXml = promisify(parseString);
4
+ import { XMLValidator } from "fast-xml-parser";
4
5
  export class Utils {
5
6
  /**
6
7
  * Check if an object is an empty array or not an array
@@ -143,20 +144,8 @@ export class Utils {
143
144
  * @returns
144
145
  */
145
146
  static isValidXml(xmlString) {
146
- let stack = [];
147
- const regex = /<([^>]+)>/g;
148
- let match;
149
- while ((match = regex.exec(xmlString)) !== null) {
150
- if (match[1].charAt(0) === "/") {
151
- if (stack.length === 0 || stack.pop() !== match[1].slice(1)) {
152
- return false;
153
- }
154
- }
155
- else {
156
- stack.push(match[1]);
157
- }
158
- }
159
- return stack.length === 0;
147
+ const validationResult = XMLValidator.validate(xmlString);
148
+ return validationResult === true;
160
149
  }
161
150
  static removeTabsAndNewLines(str) {
162
151
  if (!str)
@@ -112,10 +112,12 @@ describe("Misc", () => {
112
112
  // Check if Accept-Encoding is set to gzip, deflate, br for compression support (currently enabled for S2)
113
113
  expect(harmonyApi.axiosInstance.defaults.headers["Accept-Encoding"]).toEqual("gzip, deflate, br");
114
114
  });
115
- test("validateXml() should validate XML correctly", () => {
116
- expect(Utils.isValidXml("<root><child></child></root>")).toBe(true);
117
- expect(Utils.isValidXml("<root><child></root>")).toBe(false);
118
- expect(Utils.isValidXml("<root><child></child>")).toBe(false);
119
- expect(Utils.isValidXml("<root><child></child></root><root>")).toBe(false);
115
+ test("validateXml() should validate XML correctly", async () => {
116
+ expect(await Utils.isValidXml("<root><child></child></root>")).toBe(true);
117
+ expect(await Utils.isValidXml("<root><child></root>")).toBe(false);
118
+ expect(await Utils.isValidXml("<root><child></child>")).toBe(false);
119
+ expect(await Utils.isValidXml("<root><child></child></root><root>")).toBe(false);
120
+ const harmonyExampleResponse = `<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>S:Server</faultcode><faultstring>Failed GiftVoucherReservation</faultstring><detail><ns2:ServiceFault xmlns:ns2="http://gv.ws.fbsaust.com.au"><errorDetails>[205-106-2508050909-0000727429] (Reservation Amount exceeds Unused Amount.)</errorDetails></ns2:ServiceFault></detail></S:Fault></S:Body></S:Envelope>`;
121
+ expect(await Utils.isValidXml(harmonyExampleResponse)).toBe(true);
120
122
  });
121
123
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotdev/harmony-sdk",
3
- "version": "1.29.1",
3
+ "version": "1.30.1",
4
4
  "description": "Harmony API SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,6 +20,7 @@
20
20
  "@google-cloud/pino-logging-gcp-config": "^1.0.4",
21
21
  "axios": "^1.7.2",
22
22
  "axios-retry": "^4.5.0",
23
+ "fast-xml-parser": "^5.2.5",
23
24
  "pino": "^9.7.0",
24
25
  "xml2js": "0.6.2"
25
26
  },