@dotdev/harmony-sdk 1.18.1 → 1.20.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.d.ts +7 -4
- package/dist/HarmonyAPI.js +6 -1
- package/dist/helpers/index.js +15 -20
- package/dist/helpers/logger.d.ts +2 -0
- package/dist/helpers/logger.js +3 -0
- package/dist/helpers/utils.spec.js +14 -0
- package/dist/modules/point-of-sale/mappings/process-returns.mapper.d.ts +15 -0
- package/dist/modules/point-of-sale/mappings/process-returns.mapper.js +128 -0
- package/dist/modules/point-of-sale/point-of-sale.module.d.ts +4 -3
- package/dist/modules/point-of-sale/point-of-sale.module.js +42 -3
- package/dist/modules/point-of-sale/types/process-returns.interface.d.ts +3 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +0 -1
- package/package.json +2 -1
package/dist/HarmonyAPI.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
1
2
|
import { IAxiosRetryConfig } from "axios-retry";
|
|
2
|
-
import { AuthenticationToken, Carrier, CarrierShipment, CreateDiaryQueryParams, Diary, DispatchData, GetCarrierShipmentByTimeQueryParams, GetDiaryQueryParams, GetDispatchDataByTimeQueryParams, ProcessInvoiceQueryParams, ProcessSaleOrderQueryParams, ProcessSaleOrderWithoutPaymentQueryParams, SizeGrid, Stock, StockBarcode, StockCategory, StockClassification, StockClassificationType, StockColor, StockLevel, StockLevelLookupQueryParams, StockLookupRequestParams, Warehouse } from "./modules";
|
|
3
|
+
import { AuthenticationToken, Carrier, CarrierShipment, CreateDiaryQueryParams, Diary, DispatchData, GetCarrierShipmentByTimeQueryParams, GetDiaryQueryParams, GetDispatchDataByTimeQueryParams, ProcessInvoiceQueryParams, ProcessReturnsQueryParams, ProcessSaleOrderQueryParams, ProcessSaleOrderWithoutPaymentQueryParams, SizeGrid, Stock, StockBarcode, StockCategory, StockClassification, StockClassificationType, StockColor, StockLevel, StockLevelLookupQueryParams, StockLookupRequestParams, Warehouse } from "./modules";
|
|
3
4
|
import { GiftVoucher, GiftVoucherLookupQueryParams, GiftVoucherReservationQueryParams, GiftVoucherUsedQueryParams, GiftVoucherVerificationKeyQueryParams } from "./modules/gift-voucher/types";
|
|
5
|
+
import { RequestConfig } from "./types";
|
|
4
6
|
export declare class HarmonyAPI {
|
|
5
7
|
private baseUrl;
|
|
6
|
-
|
|
8
|
+
axiosInstance: AxiosInstance;
|
|
7
9
|
private authModule;
|
|
8
10
|
private stockLookupModule;
|
|
9
11
|
private stockLevelLookupModule;
|
|
@@ -11,7 +13,7 @@ export declare class HarmonyAPI {
|
|
|
11
13
|
private carrierModule;
|
|
12
14
|
private diaryModule;
|
|
13
15
|
private giftVoucherModule;
|
|
14
|
-
constructor(url: string, axiosRetryConfig?: IAxiosRetryConfig);
|
|
16
|
+
constructor(url: string, axiosRetryConfig?: IAxiosRetryConfig, config?: RequestConfig);
|
|
15
17
|
authenticate(authToken: AuthenticationToken): Promise<string>;
|
|
16
18
|
stockLookup(params: StockLookupRequestParams, sessionId: string): Promise<Stock[]>;
|
|
17
19
|
stockCategoryLookup(sessionId: string): Promise<StockCategory[]>;
|
|
@@ -25,8 +27,9 @@ export declare class HarmonyAPI {
|
|
|
25
27
|
processSalesOrder(params: ProcessSaleOrderQueryParams, sessionId: string): Promise<boolean>;
|
|
26
28
|
processSalesOrderWithoutPayment(params: ProcessSaleOrderWithoutPaymentQueryParams, sessionId: string): Promise<boolean>;
|
|
27
29
|
mapOrderPayloadToXml(params: Partial<ProcessSaleOrderQueryParams>, sessionId: string, method?: "ProcessSalesOrder" | "ProcessSalesOrderWithoutPayment" | "ProcessInvoice"): Promise<string>;
|
|
30
|
+
mapReturnPayloadToXml(params: ProcessReturnsQueryParams, sessionId: string): Promise<string>;
|
|
28
31
|
processInvoice(params: ProcessInvoiceQueryParams, sessionId: string): Promise<boolean>;
|
|
29
|
-
processReturns(params:
|
|
32
|
+
processReturns(params: ProcessReturnsQueryParams, sessionId: string): Promise<boolean>;
|
|
30
33
|
modifyExistingSalesOrder(params: ProcessSaleOrderQueryParams, sessionId: string): Promise<boolean>;
|
|
31
34
|
cancelExistingSalesOrder(params: ProcessSaleOrderQueryParams, sessionId: string): Promise<boolean>;
|
|
32
35
|
getCarrier(sessionId: string): Promise<Carrier[]>;
|
package/dist/HarmonyAPI.js
CHANGED
|
@@ -16,12 +16,14 @@ export class HarmonyAPI {
|
|
|
16
16
|
carrierModule;
|
|
17
17
|
diaryModule;
|
|
18
18
|
giftVoucherModule;
|
|
19
|
-
constructor(url, axiosRetryConfig) {
|
|
19
|
+
constructor(url, axiosRetryConfig, config) {
|
|
20
20
|
this.baseUrl = url;
|
|
21
21
|
this.axiosInstance = axios.create({
|
|
22
22
|
baseURL: this.baseUrl,
|
|
23
23
|
headers: {
|
|
24
|
+
...config?.headers,
|
|
24
25
|
"Content-Type": "text/xml;charset=UTF-8",
|
|
26
|
+
"Accept-Encoding": "gzip, deflate, br", // Override default Accept-Encoding
|
|
25
27
|
},
|
|
26
28
|
httpsAgent: new https.Agent({
|
|
27
29
|
rejectUnauthorized: false,
|
|
@@ -91,6 +93,9 @@ export class HarmonyAPI {
|
|
|
91
93
|
async mapOrderPayloadToXml(params, sessionId, method) {
|
|
92
94
|
return await this.pointOfSaleModule.mapOrderPayloadToXml(params, sessionId, method);
|
|
93
95
|
}
|
|
96
|
+
async mapReturnPayloadToXml(params, sessionId) {
|
|
97
|
+
return await this.pointOfSaleModule.mapReturnPayloadToXml(params, sessionId);
|
|
98
|
+
}
|
|
94
99
|
// Post fulfilled orders
|
|
95
100
|
async processInvoice(params, sessionId) {
|
|
96
101
|
return await this.pointOfSaleModule.processInvoice(params, sessionId);
|
package/dist/helpers/index.js
CHANGED
|
@@ -2,6 +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
6
|
import { Utils } from "./utils";
|
|
6
7
|
export * from "./utils";
|
|
7
8
|
const parseXml = promisify(parseString);
|
|
@@ -9,36 +10,29 @@ export class ApiHelper {
|
|
|
9
10
|
static async sendSoapRequest(endpoint, axiosInstance, requestBody, type = "POST") {
|
|
10
11
|
const url = `${endpoint}?wsdl`;
|
|
11
12
|
let response;
|
|
12
|
-
let defaultConfig = {
|
|
13
|
-
headers: {
|
|
14
|
-
'Accept-Encoding': 'gzip, deflate, br' //Override default Accept-Encoding
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
13
|
try {
|
|
18
14
|
let response;
|
|
19
15
|
switch (type) {
|
|
20
16
|
case "GET":
|
|
21
|
-
response = await axiosInstance.get(url
|
|
22
|
-
...defaultConfig,
|
|
23
|
-
params: {},
|
|
24
|
-
});
|
|
17
|
+
response = await axiosInstance.get(url);
|
|
25
18
|
break;
|
|
26
19
|
case "POST":
|
|
27
20
|
default:
|
|
28
|
-
response = await axiosInstance.post(url, requestBody
|
|
29
|
-
...defaultConfig
|
|
30
|
-
// headers: {
|
|
31
|
-
// 'SOAPAction': request.action
|
|
32
|
-
// }
|
|
33
|
-
});
|
|
21
|
+
response = await axiosInstance.post(url, requestBody);
|
|
34
22
|
break;
|
|
35
23
|
}
|
|
36
|
-
|
|
24
|
+
const child = logger.child({
|
|
25
|
+
request: requestBody,
|
|
26
|
+
response: response?.data,
|
|
27
|
+
size: +response?.headers?.["content-length"],
|
|
28
|
+
status: response?.status,
|
|
29
|
+
});
|
|
30
|
+
child.debug(`Harmony response (success) - size [${+response?.headers?.["content-length"]}]: `, { response: response?.data });
|
|
37
31
|
const result = (await parseXml(response?.data)); // fix type
|
|
38
32
|
return result["S:Envelope"]["S:Body"][0];
|
|
39
33
|
}
|
|
40
34
|
catch (error) {
|
|
41
|
-
|
|
35
|
+
logger.error(`Harmony reponse (fail): `, { response });
|
|
42
36
|
throw await ApiHelper.parseError(error);
|
|
43
37
|
}
|
|
44
38
|
}
|
|
@@ -89,7 +83,10 @@ export class ApiHelper {
|
|
|
89
83
|
? `ns2:${methodName[0]}Response`
|
|
90
84
|
: `ns2:${methodName}Response`;
|
|
91
85
|
const requestBody = ApiHelper.createServiceRequestBody(methodName, sessionId, serviceAlias, body);
|
|
92
|
-
|
|
86
|
+
const child = logger.child({
|
|
87
|
+
request: requestBody,
|
|
88
|
+
});
|
|
89
|
+
child.debug(`Sending API request`);
|
|
93
90
|
const response = await ApiHelper.sendSoapRequest(serviceName, axios, requestBody);
|
|
94
91
|
return response[responseMethodName][0];
|
|
95
92
|
}
|
|
@@ -100,8 +97,6 @@ export class ApiHelper {
|
|
|
100
97
|
return new RequestError(`API request failed with status ${error.response.status}: {code: ${parsedError?.code}, name: ${parsedError?.name}, message: ${parsedError?.message}}`);
|
|
101
98
|
}
|
|
102
99
|
else if (error?.request) {
|
|
103
|
-
console.log(`The following request was sent to server`);
|
|
104
|
-
console.log(error?.toJSON());
|
|
105
100
|
return new RequestError("No response received from the server during API call");
|
|
106
101
|
}
|
|
107
102
|
else {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { HarmonyAPI } from "../HarmonyAPI";
|
|
1
2
|
import { Utils } from "./utils";
|
|
3
|
+
jest.unmock("axios");
|
|
2
4
|
describe("Utils", () => {
|
|
3
5
|
test("isEmptyArray", () => {
|
|
4
6
|
expect.assertions(7);
|
|
@@ -94,3 +96,15 @@ describe("Utils", () => {
|
|
|
94
96
|
});
|
|
95
97
|
});
|
|
96
98
|
});
|
|
99
|
+
describe("Misc", () => {
|
|
100
|
+
test("Axios should pass through request headers correctly", () => {
|
|
101
|
+
const harmonyApi = new HarmonyAPI("test", undefined, {
|
|
102
|
+
headers: { "test-header": "test-value" },
|
|
103
|
+
});
|
|
104
|
+
expect(harmonyApi.axiosInstance.defaults.headers["test-header"]).toEqual("test-value");
|
|
105
|
+
// Default header for Content-Type should be set to text/xml;charset=UTF-8
|
|
106
|
+
expect(harmonyApi.axiosInstance.defaults.headers["Content-Type"]).toEqual("text/xml;charset=UTF-8");
|
|
107
|
+
// Check if Accept-Encoding is set to gzip, deflate, br for compression support (currently enabled for S2)
|
|
108
|
+
expect(harmonyApi.axiosInstance.defaults.headers["Accept-Encoding"]).toEqual("gzip, deflate, br");
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ProcessReturnsQueryDebtor, ProcessReturnsQueryExtra, ProcessReturnsQueryHeader, ProcessReturnsQueryParams, ProcessReturnsQueryStock } from "../types";
|
|
2
|
+
export declare function mapProcessReturnsQueryParams(params: ProcessReturnsQueryParams): string;
|
|
3
|
+
export declare function mapProcessReturnsBaseQueryParams(params: ProcessReturnsQueryParams): {
|
|
4
|
+
mode: import("../types").PosQueryMode | undefined;
|
|
5
|
+
audit_no: string;
|
|
6
|
+
export_no: string | undefined;
|
|
7
|
+
header: string;
|
|
8
|
+
extra: string;
|
|
9
|
+
stock: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function mapProcessReturnsQueryHeaders(params: ProcessReturnsQueryHeader): string;
|
|
12
|
+
export declare function mapProcessReturnsQueryExtra(params: ProcessReturnsQueryExtra): string;
|
|
13
|
+
export declare function mapReturnsInvoiceQuery(params: ProcessReturnsQueryParams): string;
|
|
14
|
+
export declare function mapProcessReturnsQueryStock(params: ProcessReturnsQueryStock): string;
|
|
15
|
+
export declare function mapProcessReturnsQueryDebtor(params: ProcessReturnsQueryDebtor): string;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Utils } from "../../../helpers";
|
|
2
|
+
export function mapProcessReturnsQueryParams(params) {
|
|
3
|
+
const body = {
|
|
4
|
+
...mapProcessReturnsBaseQueryParams(params),
|
|
5
|
+
invoice: mapReturnsInvoiceQuery(params),
|
|
6
|
+
debtor: (params?.debtor ?? []).map(mapProcessReturnsQueryDebtor),
|
|
7
|
+
};
|
|
8
|
+
return Utils.toXml(Utils.deleteEmptyProps(body));
|
|
9
|
+
}
|
|
10
|
+
export function mapProcessReturnsBaseQueryParams(params) {
|
|
11
|
+
return {
|
|
12
|
+
mode: params?.mode,
|
|
13
|
+
audit_no: params?.auditNo,
|
|
14
|
+
export_no: params?.exportNo,
|
|
15
|
+
header: mapProcessReturnsQueryHeaders(params?.header),
|
|
16
|
+
extra: params?.extra ? mapProcessReturnsQueryExtra(params.extra) : "",
|
|
17
|
+
stock: params?.stock.map(mapProcessReturnsQueryStock),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function mapProcessReturnsQueryHeaders(params) {
|
|
21
|
+
// XML body in JSON format, to be converted to XML string
|
|
22
|
+
const body = {
|
|
23
|
+
credit_no: params?.creditNo,
|
|
24
|
+
customer_order_no: params?.customerOrderNo,
|
|
25
|
+
transaction_date: params?.transactionDate,
|
|
26
|
+
transaction_time_hour: params?.transactionTimeHour,
|
|
27
|
+
transaction_time_min: params?.transactionTimeMin,
|
|
28
|
+
transaction_time_sec: params?.transactionTimeSec,
|
|
29
|
+
shop_debtor: params?.shopDebtor,
|
|
30
|
+
diary: params?.diary,
|
|
31
|
+
diary_name_1: params?.diaryName1,
|
|
32
|
+
diary_name_2: params?.diaryName2,
|
|
33
|
+
warehouse: params?.warehouse,
|
|
34
|
+
originated_warehouse: params?.originatedWarehouse,
|
|
35
|
+
agent_zone_1: params?.agentZone1,
|
|
36
|
+
agent_zone_2: params?.agentZone2 ?? "",
|
|
37
|
+
agent_zone_3: params?.agentZone3 ?? "",
|
|
38
|
+
terminal_id: params?.terminalId,
|
|
39
|
+
order_class: params?.orderClass,
|
|
40
|
+
user: params?.user,
|
|
41
|
+
comment_1: params?.comment1,
|
|
42
|
+
comment_2: params?.comment2,
|
|
43
|
+
comment_3: params?.comment3,
|
|
44
|
+
comment_4: params?.comment4,
|
|
45
|
+
comment_5: params?.comment5,
|
|
46
|
+
comment_6: params?.comment6,
|
|
47
|
+
comment_7: params?.comment7,
|
|
48
|
+
comment_8: params?.comment8,
|
|
49
|
+
comment_9: params?.comment9,
|
|
50
|
+
comment_10: params?.comment10,
|
|
51
|
+
order_tax_exemption: params?.orderTaxExemption,
|
|
52
|
+
originator_software: params?.originatorSoftware,
|
|
53
|
+
account_sale_flag: params?.accountSaleFlag,
|
|
54
|
+
};
|
|
55
|
+
return Utils.deleteEmptyProps(body);
|
|
56
|
+
}
|
|
57
|
+
export function mapProcessReturnsQueryExtra(params) {
|
|
58
|
+
// XML body in JSON format, to be converted to XML string
|
|
59
|
+
const body = {
|
|
60
|
+
email: params?.email,
|
|
61
|
+
telephone_home: params?.telephoneHome,
|
|
62
|
+
telephone_mobile: params?.telephoneMobile,
|
|
63
|
+
telephone_work: params?.telephoneWork,
|
|
64
|
+
billing_surname: params?.billingSurname,
|
|
65
|
+
billing_first_name: params?.billingFirstname,
|
|
66
|
+
billing_address_1: params?.billingAddress1,
|
|
67
|
+
billing_address_2: params?.billingAddress2,
|
|
68
|
+
billing_address_3: params?.billingAddress3,
|
|
69
|
+
billing_address_4: params?.billingAddress4,
|
|
70
|
+
billing_postcode: params?.billingPostcode,
|
|
71
|
+
billing_telephone_home: params?.billingTelephoneHome,
|
|
72
|
+
billing_telephone_mobile: params?.billingTelephoneMobile,
|
|
73
|
+
billing_telephone_work: params?.billingTelephoneWork,
|
|
74
|
+
customised_info: params?.customisedInfo,
|
|
75
|
+
};
|
|
76
|
+
return Utils.deleteEmptyProps(body);
|
|
77
|
+
}
|
|
78
|
+
export function mapReturnsInvoiceQuery(params) {
|
|
79
|
+
const body = {
|
|
80
|
+
invoice_price_inc: params?.invoice?.invoicePriceInc,
|
|
81
|
+
rounding: params?.invoice?.rounding,
|
|
82
|
+
total_tax: params?.invoice?.totalTax,
|
|
83
|
+
cash_drawer_id: params?.invoice?.cashDrawerId,
|
|
84
|
+
};
|
|
85
|
+
return Utils.deleteEmptyProps(body);
|
|
86
|
+
}
|
|
87
|
+
export function mapProcessReturnsQueryStock(params) {
|
|
88
|
+
// XML body in JSON format, to be converted to XML string
|
|
89
|
+
const body = {
|
|
90
|
+
stock: params?.stock,
|
|
91
|
+
stock_description: params?.stockDescription,
|
|
92
|
+
size: params?.size,
|
|
93
|
+
qdp: params?.qdp,
|
|
94
|
+
pdp: params?.pdp,
|
|
95
|
+
return_qty: params?.returnQty,
|
|
96
|
+
discount_price: params?.discountPrice,
|
|
97
|
+
line_tax: params?.lineTax,
|
|
98
|
+
discount_rate: params?.discountRate,
|
|
99
|
+
discount_reason: params?.discountReason,
|
|
100
|
+
credit_note_reason: params?.creditNoteReason,
|
|
101
|
+
serial_no: params?.serialNo,
|
|
102
|
+
comment: params?.comment,
|
|
103
|
+
credit_note_reference: params?.creditNoteReference,
|
|
104
|
+
current_rrp_inc: params?.currentRrpInc,
|
|
105
|
+
per: params?.per,
|
|
106
|
+
singles_per_pack: params?.singlesPerPack,
|
|
107
|
+
packs_per_carton: params?.packsPerCarton,
|
|
108
|
+
size_pack_name: params?.sizePackName,
|
|
109
|
+
};
|
|
110
|
+
return Utils.deleteEmptyProps(body);
|
|
111
|
+
}
|
|
112
|
+
export function mapProcessReturnsQueryDebtor(params) {
|
|
113
|
+
// XML body in JSON format, to be converted to XML string
|
|
114
|
+
const body = {
|
|
115
|
+
payment_type: params?.paymentType,
|
|
116
|
+
payment_amount: params?.paymentAmount,
|
|
117
|
+
card_name: params?.cardName,
|
|
118
|
+
card_no: params?.cardNo,
|
|
119
|
+
card_holder: params?.cardHolder,
|
|
120
|
+
card_expiry_month: params?.cardExpiryMonth,
|
|
121
|
+
card_expiry_year: params?.cardExpiryYear,
|
|
122
|
+
comment: params?.comment,
|
|
123
|
+
cash_drawer_id: params?.cashDrawerId,
|
|
124
|
+
gift_voucher_stock: params?.giftVoucherStock,
|
|
125
|
+
gift_voucher_serial_no: params?.giftVoucherSerialNo,
|
|
126
|
+
};
|
|
127
|
+
return Utils.deleteEmptyProps(body);
|
|
128
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
|
-
import { ProcessInvoiceQueryParams, ProcessSaleOrderQueryParams, ProcessSaleOrderWithoutPaymentQueryParams } from "./types";
|
|
2
|
+
import { ProcessInvoiceQueryParams, ProcessReturnsQueryParams, ProcessSaleOrderQueryParams, ProcessSaleOrderWithoutPaymentQueryParams } from "./types";
|
|
3
3
|
export declare class PointOfSaleModule {
|
|
4
4
|
private axiosInstance;
|
|
5
5
|
private readonly SERVICE_URL;
|
|
@@ -22,6 +22,7 @@ export declare class PointOfSaleModule {
|
|
|
22
22
|
* @param {string} sessionId
|
|
23
23
|
*/
|
|
24
24
|
mapOrderPayloadToXml(params: Partial<ProcessSaleOrderQueryParams>, sessionId: string, method?: "ProcessSalesOrder" | "ProcessSalesOrderWithoutPayment" | "ProcessInvoice"): Promise<string>;
|
|
25
|
+
mapReturnPayloadToXml(params: ProcessReturnsQueryParams, sessionId: string): Promise<string>;
|
|
25
26
|
/**
|
|
26
27
|
* Function to call the ProcessSalesOrderWithoutPayment endpoint in Harmony Point Of Sale service
|
|
27
28
|
*
|
|
@@ -42,11 +43,11 @@ export declare class PointOfSaleModule {
|
|
|
42
43
|
* Function to call the ProcessReturns endpoint in Harmony Point Of Sale service
|
|
43
44
|
*
|
|
44
45
|
* @async
|
|
45
|
-
* @param {
|
|
46
|
+
* @param {ProcessReturnsQueryParams} params
|
|
46
47
|
* @param {string} sessionId
|
|
47
48
|
* @returns {Promise<boolean>}
|
|
48
49
|
*/
|
|
49
|
-
processReturns(params:
|
|
50
|
+
processReturns(params: ProcessReturnsQueryParams, sessionId: string): Promise<boolean>;
|
|
50
51
|
/**
|
|
51
52
|
* Function to call the ModifyExistingSalesOrder endpoint in Harmony Point Of Sale service
|
|
52
53
|
*
|
|
@@ -3,6 +3,7 @@ import { ServiceAlias } from "../shared";
|
|
|
3
3
|
import { mapPosInvoiceQuery, mapProcessInvoiceQueryParams, mapProcessSaleOrderQueryDebtor, mapProcessSaleOrderQueryExtra, mapProcessSaleOrderQueryHeaders, mapProcessSaleOrderQueryParams, mapProcessSaleOrderQueryStock, mapProcessSaleOrderWithoutPaymentQueryParams, } from "./mappings/process-sale-order.mapper";
|
|
4
4
|
import { promisify } from "util";
|
|
5
5
|
import { parseString } from "xml2js";
|
|
6
|
+
import { mapProcessReturnsQueryExtra, mapProcessReturnsQueryHeaders, mapProcessReturnsQueryParams, mapProcessReturnsQueryStock, mapReturnsInvoiceQuery } from "./mappings/process-returns.mapper";
|
|
6
7
|
const parseXml = promisify(parseString);
|
|
7
8
|
export class PointOfSaleModule {
|
|
8
9
|
axiosInstance;
|
|
@@ -81,6 +82,38 @@ export class PointOfSaleModule {
|
|
|
81
82
|
const parsedJson = await parseXml(fullXml);
|
|
82
83
|
return Utils.objectToXml(parsedJson);
|
|
83
84
|
}
|
|
85
|
+
async mapReturnPayloadToXml(params, sessionId) {
|
|
86
|
+
const soapNamespace = "S";
|
|
87
|
+
// Extract method name and construct corresponding properties for the body of the SOAP request and the response from the API
|
|
88
|
+
const bodyMethodName = "ProcessReturnsRequest";
|
|
89
|
+
let body = {
|
|
90
|
+
mode: params?.mode,
|
|
91
|
+
audit_no: params?.auditNo,
|
|
92
|
+
export_no: params?.exportNo,
|
|
93
|
+
header: mapProcessReturnsQueryHeaders(params?.header),
|
|
94
|
+
extra: params?.extra ? mapProcessReturnsQueryExtra(params.extra) : "",
|
|
95
|
+
stock: params?.stock?.map(mapProcessReturnsQueryStock),
|
|
96
|
+
invoice: mapReturnsInvoiceQuery(params),
|
|
97
|
+
debtor: (params?.debtor ?? []).map(mapProcessSaleOrderQueryDebtor)
|
|
98
|
+
};
|
|
99
|
+
const soapBodyJson = {};
|
|
100
|
+
soapBodyJson[`${ServiceAlias.POINT_OF_SALE}:${bodyMethodName}`] =
|
|
101
|
+
body;
|
|
102
|
+
const soapBody = Utils.objectToXml(soapBodyJson);
|
|
103
|
+
const soapHeader = `
|
|
104
|
+
<${ServiceAlias.POINT_OF_SALE}:SessionId>${sessionId}</${ServiceAlias.POINT_OF_SALE}:SessionId>
|
|
105
|
+
`;
|
|
106
|
+
const fullXml = `
|
|
107
|
+
<${soapNamespace}:Envelope xmlns:${soapNamespace}="http://schemas.xmlsoap.org/soap/envelope/" xmlns:${ServiceAlias.POINT_OF_SALE}="http://${ServiceAlias.POINT_OF_SALE}.ws.fbsaust.com.au">
|
|
108
|
+
<${soapNamespace}:Header>${soapHeader}</${soapNamespace}:Header>
|
|
109
|
+
<${soapNamespace}:Body>
|
|
110
|
+
${soapBody}
|
|
111
|
+
</${soapNamespace}:Body>
|
|
112
|
+
</${soapNamespace}:Envelope>
|
|
113
|
+
`;
|
|
114
|
+
const parsedJson = await parseXml(fullXml);
|
|
115
|
+
return Utils.objectToXml(parsedJson);
|
|
116
|
+
}
|
|
84
117
|
/**
|
|
85
118
|
* Function to call the ProcessSalesOrderWithoutPayment endpoint in Harmony Point Of Sale service
|
|
86
119
|
*
|
|
@@ -119,13 +152,19 @@ export class PointOfSaleModule {
|
|
|
119
152
|
* Function to call the ProcessReturns endpoint in Harmony Point Of Sale service
|
|
120
153
|
*
|
|
121
154
|
* @async
|
|
122
|
-
* @param {
|
|
155
|
+
* @param {ProcessReturnsQueryParams} params
|
|
123
156
|
* @param {string} sessionId
|
|
124
157
|
* @returns {Promise<boolean>}
|
|
125
158
|
*/
|
|
126
159
|
async processReturns(params, sessionId) {
|
|
127
|
-
|
|
128
|
-
|
|
160
|
+
try {
|
|
161
|
+
const requestBody = mapProcessReturnsQueryParams(params);
|
|
162
|
+
const response = await ApiHelper.sendServiceRequest(this.SERVICE_URL, ["ProcessReturns", "Request"], sessionId, ServiceAlias.POINT_OF_SALE, this.axiosInstance, requestBody);
|
|
163
|
+
return Boolean(response?.result[0] ?? "false");
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
throw await ApiHelper.parseError(error);
|
|
167
|
+
}
|
|
129
168
|
}
|
|
130
169
|
/**
|
|
131
170
|
* Function to call the ModifyExistingSalesOrder endpoint in Harmony Point Of Sale service
|
|
@@ -14,4 +14,6 @@ export interface ProcessReturnsQueryStock extends PosQueryStock {
|
|
|
14
14
|
}
|
|
15
15
|
export type ProcessReturnsQueryExtra = PosQueryExtra;
|
|
16
16
|
export type ProcessReturnsQueryInvoice = PosQueryInvoice;
|
|
17
|
-
export type ProcessReturnsQueryDebtor = PosQueryDebtor
|
|
17
|
+
export type ProcessReturnsQueryDebtor = Omit<PosQueryDebtor, "creditReference" | "reservationHistoryNo"> & {
|
|
18
|
+
cashDrawerId: string;
|
|
19
|
+
};
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotdev/harmony-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "Harmony API SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"axios": "^1.7.2",
|
|
21
21
|
"axios-retry": "^4.5.0",
|
|
22
|
+
"pino": "^9.7.0",
|
|
22
23
|
"xml2js": "0.6.2"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|