@dotdev/harmony-sdk 1.3.0 → 1.4.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/helpers/utils.d.ts +1 -0
- package/dist/helpers/utils.js +11 -4
- package/dist/modules/carrier/types/index.d.ts +2 -2
- package/dist/modules/carrier/types/index.js +2 -2
- package/dist/modules/point-of-sale/mappings/process-sale-order.mapper.js +4 -4
- package/dist/modules/point-of-sale/point-of-sale.module.d.ts +9 -0
- package/dist/modules/point-of-sale/point-of-sale.module.js +47 -2
- package/package.json +1 -1
package/dist/helpers/utils.d.ts
CHANGED
package/dist/helpers/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { promisify } from "util";
|
|
2
|
-
import { parseString } from "xml2js";
|
|
2
|
+
import xml2js, { parseString } from "xml2js";
|
|
3
3
|
const parseXml = promisify(parseString);
|
|
4
4
|
export class Utils {
|
|
5
5
|
/**
|
|
@@ -94,23 +94,30 @@ export class Utils {
|
|
|
94
94
|
const open = parent ? `<${parent}>` : "";
|
|
95
95
|
const close = parent ? `</${parent}>` : "";
|
|
96
96
|
if (Array.isArray(obj)) {
|
|
97
|
-
str += obj
|
|
97
|
+
str += obj
|
|
98
|
+
.map((o) => [open, Utils.toXml(o), close].join("\n"))
|
|
99
|
+
.join("\n");
|
|
98
100
|
}
|
|
99
101
|
else if (typeof obj === "object") {
|
|
100
102
|
let valStr = "";
|
|
101
103
|
for (const k in obj) {
|
|
102
104
|
const val = obj[k];
|
|
103
105
|
if (!(val == null)) {
|
|
104
|
-
valStr += `${Utils.toXml(val, k)}`;
|
|
106
|
+
valStr += `${Utils.toXml(val, k)}\n`;
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
|
-
str += open
|
|
109
|
+
str += [open, valStr, close].join("\n");
|
|
108
110
|
}
|
|
109
111
|
else {
|
|
110
112
|
str += open + obj + close;
|
|
111
113
|
}
|
|
112
114
|
return str;
|
|
113
115
|
}
|
|
116
|
+
// Function to convert object to xml using xml2js library
|
|
117
|
+
static objectToXml(obj) {
|
|
118
|
+
const builder = new xml2js.Builder({ headless: true });
|
|
119
|
+
return builder.buildObject(obj);
|
|
120
|
+
}
|
|
114
121
|
static deleteUndefinedProps(obj) {
|
|
115
122
|
Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]);
|
|
116
123
|
return obj;
|
|
@@ -8,8 +8,8 @@ export declare enum CarrierCode {
|
|
|
8
8
|
ARAMEX = "ARAME",
|
|
9
9
|
BORDER_EXPRESS_WHOLESALE = "BORD",
|
|
10
10
|
BORDER_EXPRESS_RETAIL = "BORDR",
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
DIRECT_FREIGHT_EXPRESS = "DFE",
|
|
12
|
+
DIRECT_FREIGHT_EXPRESS_RETAIL = "DFER",
|
|
13
13
|
NONE = "",
|
|
14
14
|
STAR_TRACK = "STAR",
|
|
15
15
|
TNT_ROAD_EXPRESS = "TNT",
|
|
@@ -6,8 +6,8 @@ export var CarrierCode;
|
|
|
6
6
|
CarrierCode["ARAMEX"] = "ARAME";
|
|
7
7
|
CarrierCode["BORDER_EXPRESS_WHOLESALE"] = "BORD";
|
|
8
8
|
CarrierCode["BORDER_EXPRESS_RETAIL"] = "BORDR";
|
|
9
|
-
CarrierCode["
|
|
10
|
-
CarrierCode["
|
|
9
|
+
CarrierCode["DIRECT_FREIGHT_EXPRESS"] = "DFE";
|
|
10
|
+
CarrierCode["DIRECT_FREIGHT_EXPRESS_RETAIL"] = "DFER";
|
|
11
11
|
CarrierCode["NONE"] = "";
|
|
12
12
|
CarrierCode["STAR_TRACK"] = "STAR";
|
|
13
13
|
CarrierCode["TNT_ROAD_EXPRESS"] = "TNT";
|
|
@@ -56,7 +56,7 @@ export function mapProcessSaleOrderQueryHeaders(params) {
|
|
|
56
56
|
account_sale_flag: params?.accountSaleFlag,
|
|
57
57
|
web_order_type: params?.webOrderType,
|
|
58
58
|
};
|
|
59
|
-
return Utils.
|
|
59
|
+
return Utils.deleteEmptyProps(body);
|
|
60
60
|
}
|
|
61
61
|
export function mapProcessSaleOrderQueryExtra(params) {
|
|
62
62
|
// XML body in JSON format, to be converted to XML string
|
|
@@ -85,7 +85,7 @@ export function mapProcessSaleOrderQueryExtra(params) {
|
|
|
85
85
|
billing_telephone_work: params?.billingTelephoneWork,
|
|
86
86
|
customised_info: params?.customisedInfo,
|
|
87
87
|
};
|
|
88
|
-
return Utils.
|
|
88
|
+
return Utils.deleteEmptyProps(body);
|
|
89
89
|
}
|
|
90
90
|
export function mapProcessSaleOrderQueryStock(params) {
|
|
91
91
|
// XML body in JSON format, to be converted to XML string
|
|
@@ -116,7 +116,7 @@ export function mapProcessSaleOrderQueryStock(params) {
|
|
|
116
116
|
packs_per_carton: params?.packsPerCarton,
|
|
117
117
|
size_pack_name: params?.sizePackName,
|
|
118
118
|
};
|
|
119
|
-
return Utils.
|
|
119
|
+
return Utils.deleteEmptyProps(body);
|
|
120
120
|
}
|
|
121
121
|
export function mapProcessSaleOrderQueryDebtor(params) {
|
|
122
122
|
// XML body in JSON format, to be converted to XML string
|
|
@@ -138,5 +138,5 @@ export function mapProcessSaleOrderQueryDebtor(params) {
|
|
|
138
138
|
gift_voucher_serial_no: params?.giftVoucherSerialNo,
|
|
139
139
|
reservation_history_no: params?.reservationHistoryNo,
|
|
140
140
|
};
|
|
141
|
-
return Utils.
|
|
141
|
+
return Utils.deleteEmptyProps(body);
|
|
142
142
|
}
|
|
@@ -13,6 +13,15 @@ export declare class PointOfSaleModule {
|
|
|
13
13
|
* @returns {Promise<boolean>}
|
|
14
14
|
*/
|
|
15
15
|
processSalesOrder(params: ProcessSaleOrderQueryParams, sessionId: string): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Function to map ProcessSaleOrderQueryParams to XML for sending to the Point Of Sale service
|
|
18
|
+
* This is a TEMPORARY workaround to have the XML payload returned to be saved to the database
|
|
19
|
+
* TODO: combine this into the returned value of the `processSalesOrder` function
|
|
20
|
+
*
|
|
21
|
+
* @param {ProcessSaleOrderQueryParams} params
|
|
22
|
+
* @param {string} sessionId
|
|
23
|
+
*/
|
|
24
|
+
mapOrderPayloadToXml(params: ProcessSaleOrderQueryParams, sessionId: string): Promise<string>;
|
|
16
25
|
/**
|
|
17
26
|
* Function to call the ProcessReturns endpoint in Harmony Point Of Sale service
|
|
18
27
|
*
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { ApiHelper } from "../../helpers";
|
|
1
|
+
import { ApiHelper, Utils } from "../../helpers";
|
|
2
2
|
import { ServiceAlias } from "../shared";
|
|
3
|
-
import { mapProcessSaleOrderQueryParams } from "./mappings/process-sale-order.mapper";
|
|
3
|
+
import { mapProcessSaleOrderQueryDebtor, mapProcessSaleOrderQueryExtra, mapProcessSaleOrderQueryHeaders, mapProcessSaleOrderQueryParams, mapProcessSaleOrderQueryStock, } from "./mappings/process-sale-order.mapper";
|
|
4
|
+
import { promisify } from "util";
|
|
5
|
+
import { parseString } from "xml2js";
|
|
6
|
+
const parseXml = promisify(parseString);
|
|
4
7
|
export class PointOfSaleModule {
|
|
5
8
|
axiosInstance;
|
|
6
9
|
SERVICE_URL = "PointOfSaleService/PointOfSaleService";
|
|
@@ -25,6 +28,48 @@ export class PointOfSaleModule {
|
|
|
25
28
|
throw await ApiHelper.parseError(error);
|
|
26
29
|
}
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Function to map ProcessSaleOrderQueryParams to XML for sending to the Point Of Sale service
|
|
33
|
+
* This is a TEMPORARY workaround to have the XML payload returned to be saved to the database
|
|
34
|
+
* TODO: combine this into the returned value of the `processSalesOrder` function
|
|
35
|
+
*
|
|
36
|
+
* @param {ProcessSaleOrderQueryParams} params
|
|
37
|
+
* @param {string} sessionId
|
|
38
|
+
*/
|
|
39
|
+
async mapOrderPayloadToXml(params, sessionId) {
|
|
40
|
+
const methodName = ["ProcessSalesOrder", "Request"];
|
|
41
|
+
const soapNamespace = "S";
|
|
42
|
+
// Extract method name and construct corresponding properties for the body of the SOAP request and the response from the API
|
|
43
|
+
const bodyMethodName = Array.isArray(methodName)
|
|
44
|
+
? methodName.join("")
|
|
45
|
+
: methodName;
|
|
46
|
+
const body = {
|
|
47
|
+
mode: params?.mode,
|
|
48
|
+
audit_no: params?.auditNo,
|
|
49
|
+
export_no: params?.exportNo,
|
|
50
|
+
header: mapProcessSaleOrderQueryHeaders(params?.header),
|
|
51
|
+
extra: mapProcessSaleOrderQueryExtra(params?.extra),
|
|
52
|
+
stock: params?.stock.map(mapProcessSaleOrderQueryStock),
|
|
53
|
+
debtor: mapProcessSaleOrderQueryDebtor((params?.debtor ?? [])[0]),
|
|
54
|
+
};
|
|
55
|
+
const soapBodyJson = {};
|
|
56
|
+
soapBodyJson[`${ServiceAlias.POINT_OF_SALE}:${bodyMethodName}`] =
|
|
57
|
+
body;
|
|
58
|
+
const soapBody = Utils.objectToXml(soapBodyJson);
|
|
59
|
+
const soapHeader = `
|
|
60
|
+
<${ServiceAlias.POINT_OF_SALE}:SessionId>${sessionId}</${ServiceAlias.POINT_OF_SALE}:SessionId>
|
|
61
|
+
`;
|
|
62
|
+
const fullXml = `
|
|
63
|
+
<${soapNamespace}:Envelope xmlns:${soapNamespace}="http://schemas.xmlsoap.org/soap/envelope/" xmlns:${ServiceAlias.POINT_OF_SALE}="http://${ServiceAlias.POINT_OF_SALE}.ws.fbsaust.com.au">
|
|
64
|
+
<${soapNamespace}:Header>${soapHeader}</${soapNamespace}:Header>
|
|
65
|
+
<${soapNamespace}:Body>
|
|
66
|
+
${soapBody}
|
|
67
|
+
</${soapNamespace}:Body>
|
|
68
|
+
</${soapNamespace}:Envelope>
|
|
69
|
+
`;
|
|
70
|
+
const parsedJson = await parseXml(fullXml);
|
|
71
|
+
return Utils.objectToXml(parsedJson);
|
|
72
|
+
}
|
|
28
73
|
/**
|
|
29
74
|
* Function to call the ProcessReturns endpoint in Harmony Point Of Sale service
|
|
30
75
|
*
|