fc-landmark 2.1.3 → 3.0.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/README.md +12 -12
- package/azure-pipelines.yml +45 -45
- package/dist/axios.js +29 -29
- package/dist/core.js +18 -18
- package/dist/globals.js +4 -4
- package/dist/index.js +6 -6
- package/dist/landmark.js +78 -78
- package/dist/shipment.js +212 -201
- package/dist/shipment.js.map +1 -1
- package/dist/tracking.js +92 -92
- package/dist/types.js +2 -2
- package/package.json +42 -31
- package/src/axios.ts +28 -28
- package/src/core.ts +12 -12
- package/src/globals.ts +4 -4
- package/src/index.ts +2 -2
- package/src/landmark.ts +67 -67
- package/src/shipment.spec.ts +179 -0
- package/src/shipment.ts +213 -193
- package/src/tracking.ts +82 -82
- package/src/types.ts +109 -102
- package/tests/shipment.js +456 -456
- package/tests/tracking.js +32 -32
- package/tsconfig.json +14 -12
package/dist/tracking.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const globals_1 = require("./globals");
|
|
13
|
-
const xml_js_1 = require("xml-js");
|
|
14
|
-
class Tracking {
|
|
15
|
-
constructor() {
|
|
16
|
-
}
|
|
17
|
-
buildTrackingRequest(args, username, password, test, clientId) {
|
|
18
|
-
try {
|
|
19
|
-
let trackRequest = {
|
|
20
|
-
"Login": {
|
|
21
|
-
"Username": username,
|
|
22
|
-
"Password": password
|
|
23
|
-
},
|
|
24
|
-
"Test": test,
|
|
25
|
-
"ClientID": clientId,
|
|
26
|
-
"TrackingNumber": args.tracking_number,
|
|
27
|
-
"RetrievalType": "Historical"
|
|
28
|
-
};
|
|
29
|
-
let request = {
|
|
30
|
-
"TrackRequest": trackRequest
|
|
31
|
-
};
|
|
32
|
-
const xmlData = (0, xml_js_1.js2xml)(request, { compact: true, ignoreComment: true, spaces: 4 });
|
|
33
|
-
return xmlData;
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
throw globals_1.MyGlobal.FlclError.create({ className: 'Tracking', methodName: '_buildRequest', message: 'Exception while building the LandMark Tracking request', cause: e, appendChildMsg: true });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
trackInfo(ShipmentRequest) {
|
|
40
|
-
var _a, _b, _c;
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
try {
|
|
43
|
-
let configs = {
|
|
44
|
-
headers: {
|
|
45
|
-
'Content-Type': 'application/xml'
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
let resp = yield globals_1.MyGlobal.axios.post(globals_1.MyGlobal.track_url, ShipmentRequest, configs);
|
|
49
|
-
(_a = globals_1.MyGlobal.logger) === null || _a === void 0 ? void 0 : _a.info({ npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'landmark-RAW-RESPOSNE', propertyValue: resp.data });
|
|
50
|
-
let responsejson = (0, xml_js_1.xml2json)(resp.data, { compact: true, spaces: 4 });
|
|
51
|
-
return JSON.parse(responsejson);
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
(_b = globals_1.MyGlobal.logger) === null || _b === void 0 ? void 0 : _b.info({ npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'landmar-RAW-RESPOSNE', data: { error: e } });
|
|
55
|
-
(_c = globals_1.MyGlobal.logger) === null || _c === void 0 ? void 0 : _c.error(globals_1.MyGlobal.flclError.create({ npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'CREDITS_ERROR', cause: e }));
|
|
56
|
-
throw e;
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
buildResponse(resp, args) {
|
|
61
|
-
let response = {
|
|
62
|
-
reference: args.reference,
|
|
63
|
-
tracking_number: args.tracking_number,
|
|
64
|
-
tracking_history: []
|
|
65
|
-
};
|
|
66
|
-
if (!Array.isArray(resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'])) {
|
|
67
|
-
resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'] = [resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event']];
|
|
68
|
-
}
|
|
69
|
-
for (let i = 0; i < resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'].length; i++) {
|
|
70
|
-
let history = {};
|
|
71
|
-
let code = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['EventCode']['_text'];
|
|
72
|
-
if (code == '50' || code == '60') {
|
|
73
|
-
history.status = "In Progress";
|
|
74
|
-
}
|
|
75
|
-
else if (code == '500') {
|
|
76
|
-
history.status = "Delivered";
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
history.status = "In Transit";
|
|
80
|
-
}
|
|
81
|
-
history.status_date = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['DateTime']['_text'];
|
|
82
|
-
let dateofevent = new Date(history.status_date);
|
|
83
|
-
history.event_date = dateofevent.getTime();
|
|
84
|
-
history.status_detail = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['Status']['_text'] || "";
|
|
85
|
-
history.location = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['Location']['_text'] || '';
|
|
86
|
-
history.country = '';
|
|
87
|
-
response.tracking_history.push(history);
|
|
88
|
-
}
|
|
89
|
-
return response;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.default = Tracking;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const globals_1 = require("./globals");
|
|
13
|
+
const xml_js_1 = require("xml-js");
|
|
14
|
+
class Tracking {
|
|
15
|
+
constructor() {
|
|
16
|
+
}
|
|
17
|
+
buildTrackingRequest(args, username, password, test, clientId) {
|
|
18
|
+
try {
|
|
19
|
+
let trackRequest = {
|
|
20
|
+
"Login": {
|
|
21
|
+
"Username": username,
|
|
22
|
+
"Password": password
|
|
23
|
+
},
|
|
24
|
+
"Test": test,
|
|
25
|
+
"ClientID": clientId,
|
|
26
|
+
"TrackingNumber": args.tracking_number,
|
|
27
|
+
"RetrievalType": "Historical"
|
|
28
|
+
};
|
|
29
|
+
let request = {
|
|
30
|
+
"TrackRequest": trackRequest
|
|
31
|
+
};
|
|
32
|
+
const xmlData = (0, xml_js_1.js2xml)(request, { compact: true, ignoreComment: true, spaces: 4 });
|
|
33
|
+
return xmlData;
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw globals_1.MyGlobal.FlclError.create({ className: 'Tracking', methodName: '_buildRequest', message: 'Exception while building the LandMark Tracking request', cause: e, appendChildMsg: true });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
trackInfo(ShipmentRequest) {
|
|
40
|
+
var _a, _b, _c;
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
try {
|
|
43
|
+
let configs = {
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/xml'
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
let resp = yield globals_1.MyGlobal.axios.post(globals_1.MyGlobal.track_url, ShipmentRequest, configs);
|
|
49
|
+
(_a = globals_1.MyGlobal.logger) === null || _a === void 0 ? void 0 : _a.info({ npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'landmark-RAW-RESPOSNE', propertyValue: resp.data });
|
|
50
|
+
let responsejson = (0, xml_js_1.xml2json)(resp.data, { compact: true, spaces: 4 });
|
|
51
|
+
return JSON.parse(responsejson);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
(_b = globals_1.MyGlobal.logger) === null || _b === void 0 ? void 0 : _b.info({ npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'landmar-RAW-RESPOSNE', data: { error: e } });
|
|
55
|
+
(_c = globals_1.MyGlobal.logger) === null || _c === void 0 ? void 0 : _c.error(globals_1.MyGlobal.flclError.create({ npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'CREDITS_ERROR', cause: e }));
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
buildResponse(resp, args) {
|
|
61
|
+
let response = {
|
|
62
|
+
reference: args.reference,
|
|
63
|
+
tracking_number: args.tracking_number,
|
|
64
|
+
tracking_history: []
|
|
65
|
+
};
|
|
66
|
+
if (!Array.isArray(resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'])) {
|
|
67
|
+
resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'] = [resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event']];
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'].length; i++) {
|
|
70
|
+
let history = {};
|
|
71
|
+
let code = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['EventCode']['_text'];
|
|
72
|
+
if (code == '50' || code == '60') {
|
|
73
|
+
history.status = "In Progress";
|
|
74
|
+
}
|
|
75
|
+
else if (code == '500') {
|
|
76
|
+
history.status = "Delivered";
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
history.status = "In Transit";
|
|
80
|
+
}
|
|
81
|
+
history.status_date = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['DateTime']['_text'];
|
|
82
|
+
let dateofevent = new Date(history.status_date);
|
|
83
|
+
history.event_date = dateofevent.getTime();
|
|
84
|
+
history.status_detail = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['Status']['_text'] || "";
|
|
85
|
+
history.location = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['Location']['_text'] || '';
|
|
86
|
+
history.country = '';
|
|
87
|
+
response.tracking_history.push(history);
|
|
88
|
+
}
|
|
89
|
+
return response;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.default = Tracking;
|
|
93
93
|
//# sourceMappingURL=tracking.js.map
|
package/dist/types.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,31 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "fc-landmark",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "landmark Shipment and Tracking API.",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "rm -rf ./dist && tsc",
|
|
8
|
-
"test": "
|
|
9
|
-
},
|
|
10
|
-
"author": "Midhun",
|
|
11
|
-
"license": "ISC",
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"@types/xml2js": "0.4.11",
|
|
14
|
-
"@types/redis": "^2.8.25",
|
|
15
|
-
"@types/redlock": "^4.0.1",
|
|
16
|
-
"@types/uuid": "^8.3.0",
|
|
17
|
-
"app-root-path": "^3.0.0",
|
|
18
|
-
"axios": "^0.19.0",
|
|
19
|
-
"fc-logger": "^4.2.0",
|
|
20
|
-
"fs": "0.0.1-security",
|
|
21
|
-
"redis": "^3.0.2",
|
|
22
|
-
"redlock": "^4.1.0",
|
|
23
|
-
"request": "^2.88.2",
|
|
24
|
-
"uuid": "^8.3.0",
|
|
25
|
-
"xml-js": "1.6.11"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@types/
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "fc-landmark",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "landmark Shipment and Tracking API.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rm -rf ./dist && tsc",
|
|
8
|
+
"test": "jest"
|
|
9
|
+
},
|
|
10
|
+
"author": "Midhun",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@types/xml2js": "0.4.11",
|
|
14
|
+
"@types/redis": "^2.8.25",
|
|
15
|
+
"@types/redlock": "^4.0.1",
|
|
16
|
+
"@types/uuid": "^8.3.0",
|
|
17
|
+
"app-root-path": "^3.0.0",
|
|
18
|
+
"axios": "^0.19.0",
|
|
19
|
+
"fc-logger": "^4.2.0",
|
|
20
|
+
"fs": "0.0.1-security",
|
|
21
|
+
"redis": "^3.0.2",
|
|
22
|
+
"redlock": "^4.1.0",
|
|
23
|
+
"request": "^2.88.2",
|
|
24
|
+
"uuid": "^8.3.0",
|
|
25
|
+
"xml-js": "1.6.11"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/jest": "^29.5.14",
|
|
29
|
+
"@types/node": "^20.19.43",
|
|
30
|
+
"@types/request": "^2.48.7",
|
|
31
|
+
"jest": "^29.7.0",
|
|
32
|
+
"ts-jest": "^29.4.14",
|
|
33
|
+
"typescript": "^4.9.5"
|
|
34
|
+
},
|
|
35
|
+
"jest": {
|
|
36
|
+
"preset": "ts-jest",
|
|
37
|
+
"testEnvironment": "node",
|
|
38
|
+
"roots": [
|
|
39
|
+
"<rootDir>/src"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/axios.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { FlclAxiosMiddleware, ValidObject } from './types';
|
|
3
|
-
import { MyGlobal as app } from './globals';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const injectRequestId = (data?: ValidObject) => {
|
|
7
|
-
if(data) {
|
|
8
|
-
data.requestId = app.requestId;
|
|
9
|
-
data.rootRequestId = app.rootRequestId;
|
|
10
|
-
}
|
|
11
|
-
return data;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let axiosMiddleware: FlclAxiosMiddleware = {
|
|
15
|
-
get: (urlPath: string, configs?: ValidObject) => {
|
|
16
|
-
return axios.get(urlPath, configs);
|
|
17
|
-
},
|
|
18
|
-
put: (urlPath: string, data?: ValidObject, configs?: ValidObject) => {
|
|
19
|
-
return axios.put(urlPath, data, configs);
|
|
20
|
-
},
|
|
21
|
-
post: (urlPath: string, data?: ValidObject, configs?: ValidObject) => {
|
|
22
|
-
return axios.post(urlPath, data, configs);
|
|
23
|
-
},
|
|
24
|
-
delete: (urlPath: string, configs?: ValidObject) => {
|
|
25
|
-
return axios.delete(urlPath, configs);
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { FlclAxiosMiddleware, ValidObject } from './types';
|
|
3
|
+
import { MyGlobal as app } from './globals';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const injectRequestId = (data?: ValidObject) => {
|
|
7
|
+
if(data) {
|
|
8
|
+
data.requestId = app.requestId;
|
|
9
|
+
data.rootRequestId = app.rootRequestId;
|
|
10
|
+
}
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let axiosMiddleware: FlclAxiosMiddleware = {
|
|
15
|
+
get: (urlPath: string, configs?: ValidObject) => {
|
|
16
|
+
return axios.get(urlPath, configs);
|
|
17
|
+
},
|
|
18
|
+
put: (urlPath: string, data?: ValidObject, configs?: ValidObject) => {
|
|
19
|
+
return axios.put(urlPath, data, configs);
|
|
20
|
+
},
|
|
21
|
+
post: (urlPath: string, data?: ValidObject, configs?: ValidObject) => {
|
|
22
|
+
return axios.post(urlPath, data, configs);
|
|
23
|
+
},
|
|
24
|
+
delete: (urlPath: string, configs?: ValidObject) => {
|
|
25
|
+
return axios.delete(urlPath, configs);
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
|
|
29
29
|
export default axiosMiddleware;
|
package/src/core.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { MyGlobal as app } from './globals';
|
|
2
|
-
import { FlclLogger, FlclError } from "fc-logger";
|
|
3
|
-
import axiosMiddleware from './axios';
|
|
4
|
-
export const setRequredGlobals = (logger?: FlclLogger, flclerror?: FlclError, rootRequestId?: string, requestId?: string) => {
|
|
5
|
-
app.logger = logger || undefined;
|
|
6
|
-
app.flclError = flclerror || undefined;
|
|
7
|
-
app.rootRequestId = rootRequestId || '';
|
|
8
|
-
app.requestId = requestId || '';
|
|
9
|
-
app.axios = axiosMiddleware;
|
|
10
|
-
app.ship_url = "https://api.landmarkglobal.com/v2/Import.php",
|
|
11
|
-
app.track_url = "https://api.landmarkglobal.com/v2/Track.php"
|
|
12
|
-
}
|
|
1
|
+
import { MyGlobal as app } from './globals';
|
|
2
|
+
import { FlclLogger, FlclError } from "fc-logger";
|
|
3
|
+
import axiosMiddleware from './axios';
|
|
4
|
+
export const setRequredGlobals = (logger?: FlclLogger, flclerror?: FlclError, rootRequestId?: string, requestId?: string) => {
|
|
5
|
+
app.logger = logger || undefined;
|
|
6
|
+
app.flclError = flclerror || undefined;
|
|
7
|
+
app.rootRequestId = rootRequestId || '';
|
|
8
|
+
app.requestId = requestId || '';
|
|
9
|
+
app.axios = axiosMiddleware;
|
|
10
|
+
app.ship_url = "https://api.landmarkglobal.com/v2/Import.php",
|
|
11
|
+
app.track_url = "https://api.landmarkglobal.com/v2/Track.php"
|
|
12
|
+
}
|
package/src/globals.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AppObj } from './types';
|
|
2
|
-
|
|
3
|
-
export var MyGlobal: Partial<AppObj> = {
|
|
4
|
-
|
|
1
|
+
import { AppObj } from './types';
|
|
2
|
+
|
|
3
|
+
export var MyGlobal: Partial<AppObj> = {
|
|
4
|
+
|
|
5
5
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { LandMark } from './landmark';
|
|
2
|
-
|
|
1
|
+
export { LandMark } from './landmark';
|
|
2
|
+
|
|
3
3
|
//export default ECMS;
|
package/src/landmark.ts
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import Shipment from './shipment';
|
|
2
|
-
import Tracking from './tracking';
|
|
3
|
-
import { setRequredGlobals } from './core';
|
|
4
|
-
import { MyGlobal as app } from './globals';
|
|
5
|
-
import {FlavorcloudShipmentResponse, FlavorcloudTrackingResponse} from './types';
|
|
6
|
-
import { FlclLogger, FlclError } from "fc-logger";
|
|
7
|
-
export class LandMark {
|
|
8
|
-
private username : string;
|
|
9
|
-
private password : string;
|
|
10
|
-
private test : boolean;
|
|
11
|
-
private clientId : number;
|
|
12
|
-
private vendorEORINumber : string;
|
|
13
|
-
private vendorIOSSNumber : string;
|
|
14
|
-
constructor(username:string,password:string,clientId:number,test:boolean,vendorEORINumber:string,vendorIOSSNumber:string, logger?: FlclLogger, flclerror?: FlclError, rootRequestId?: string, requestId?: string) {
|
|
15
|
-
this.username = username;
|
|
16
|
-
this.password = password;
|
|
17
|
-
this.test = test;
|
|
18
|
-
this.clientId = clientId;
|
|
19
|
-
this.vendorEORINumber = vendorEORINumber;
|
|
20
|
-
this.vendorIOSSNumber = vendorIOSSNumber;
|
|
21
|
-
setRequredGlobals(logger, flclerror, rootRequestId, requestId);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async createShipmet(args: any, dangerousGoodsDeatils: any = "", regionValue: string = "") {
|
|
25
|
-
try {
|
|
26
|
-
|
|
27
|
-
let shipObj = new Shipment();
|
|
28
|
-
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'createShipmet', propertyName: 'landMarkShipmentInput', propertyValue: args});
|
|
29
|
-
let landmarkShipmentRequest: string = shipObj.buildShipmentRequest(args, dangerousGoodsDeatils, this.username,this.password,this.test,this.clientId,this.vendorEORINumber,this.vendorIOSSNumber, regionValue);
|
|
30
|
-
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'createShipmet', propertyName: 'landMarkShipmentRequest', propertyValue: landmarkShipmentRequest});
|
|
31
|
-
let landmarkShipmentRes: any = await shipObj.createShipment(landmarkShipmentRequest);
|
|
32
|
-
if(landmarkShipmentRes.hasOwnProperty("ImportResponse") && landmarkShipmentRes['ImportResponse']['Errors']){
|
|
33
|
-
const rawErrors = landmarkShipmentRes['ImportResponse']['Errors']['Error'];
|
|
34
|
-
const errorArray = Array.isArray(rawErrors) ? rawErrors : [rawErrors];
|
|
35
|
-
const messages = errorArray.map((e: any) => e?.['ErrorMessage']?.['_text'] ?? 'Unknown Landmark error').join('; ');
|
|
36
|
-
throw new Error(messages);
|
|
37
|
-
}
|
|
38
|
-
let response: FlavorcloudShipmentResponse = shipObj.buildResponse(landmarkShipmentRes, args);
|
|
39
|
-
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'createShipmet', propertyName: 'response', propertyValue: response});
|
|
40
|
-
return response;
|
|
41
|
-
} catch(e) {
|
|
42
|
-
app.logger?.error(app.flclError?.create({npm: 'fc-landmark', className: 'Landmark', methodName: 'createShipmet', propertyName: 'landMark_ERROR', cause: e, message: 'Exception while creating shipment in Landmark'}));
|
|
43
|
-
throw e;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async getTrackingInfo(args: any) {
|
|
48
|
-
try {
|
|
49
|
-
|
|
50
|
-
let trackObj = new Tracking();
|
|
51
|
-
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'getTrackingInfo', propertyName: 'LandmarkInput', propertyValue: args});
|
|
52
|
-
let landmarkTrackRequest: string = trackObj.buildTrackingRequest(args,this.username,this.password,this.test,this.clientId);
|
|
53
|
-
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'getTrackingInfo', propertyName: 'LandmarkTrackRequest', propertyValue: landmarkTrackRequest});
|
|
54
|
-
let landMarkTrackingRes: any = await trackObj.trackInfo(landmarkTrackRequest);
|
|
55
|
-
if(landMarkTrackingRes.hasOwnProperty("TrackResponse") && landMarkTrackingRes['TrackResponse']['Errors']){
|
|
56
|
-
throw new Error(landMarkTrackingRes['TrackResponse']['Errors']['Error']['ErrorMessage']['_text']) ;
|
|
57
|
-
}
|
|
58
|
-
let response: FlavorcloudTrackingResponse = trackObj.buildResponse(landMarkTrackingRes, args);
|
|
59
|
-
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'getTrackingInfo', propertyName: 'response', propertyValue: response});
|
|
60
|
-
return response;
|
|
61
|
-
} catch(e) {
|
|
62
|
-
app.logger?.error(app.flclError?.create({npm: 'fc-landmark', className: 'Landmark', methodName: 'getTrackingInfo', propertyName: 'landMark_ERROR', cause: e, message: 'Exception while get trackinfo in Landmark'}));
|
|
63
|
-
throw e;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
1
|
+
import Shipment from './shipment';
|
|
2
|
+
import Tracking from './tracking';
|
|
3
|
+
import { setRequredGlobals } from './core';
|
|
4
|
+
import { MyGlobal as app } from './globals';
|
|
5
|
+
import {FlavorcloudShipmentResponse, FlavorcloudTrackingResponse} from './types';
|
|
6
|
+
import { FlclLogger, FlclError } from "fc-logger";
|
|
7
|
+
export class LandMark {
|
|
8
|
+
private username : string;
|
|
9
|
+
private password : string;
|
|
10
|
+
private test : boolean;
|
|
11
|
+
private clientId : number;
|
|
12
|
+
private vendorEORINumber : string;
|
|
13
|
+
private vendorIOSSNumber : string;
|
|
14
|
+
constructor(username:string,password:string,clientId:number,test:boolean,vendorEORINumber:string,vendorIOSSNumber:string, logger?: FlclLogger, flclerror?: FlclError, rootRequestId?: string, requestId?: string) {
|
|
15
|
+
this.username = username;
|
|
16
|
+
this.password = password;
|
|
17
|
+
this.test = test;
|
|
18
|
+
this.clientId = clientId;
|
|
19
|
+
this.vendorEORINumber = vendorEORINumber;
|
|
20
|
+
this.vendorIOSSNumber = vendorIOSSNumber;
|
|
21
|
+
setRequredGlobals(logger, flclerror, rootRequestId, requestId);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async createShipmet(args: any, dangerousGoodsDeatils: any = "", regionValue: string = "") {
|
|
25
|
+
try {
|
|
26
|
+
|
|
27
|
+
let shipObj = new Shipment();
|
|
28
|
+
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'createShipmet', propertyName: 'landMarkShipmentInput', propertyValue: args});
|
|
29
|
+
let landmarkShipmentRequest: string = shipObj.buildShipmentRequest(args, dangerousGoodsDeatils, this.username,this.password,this.test,this.clientId,this.vendorEORINumber,this.vendorIOSSNumber, regionValue);
|
|
30
|
+
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'createShipmet', propertyName: 'landMarkShipmentRequest', propertyValue: landmarkShipmentRequest});
|
|
31
|
+
let landmarkShipmentRes: any = await shipObj.createShipment(landmarkShipmentRequest);
|
|
32
|
+
if(landmarkShipmentRes.hasOwnProperty("ImportResponse") && landmarkShipmentRes['ImportResponse']['Errors']){
|
|
33
|
+
const rawErrors = landmarkShipmentRes['ImportResponse']['Errors']['Error'];
|
|
34
|
+
const errorArray = Array.isArray(rawErrors) ? rawErrors : [rawErrors];
|
|
35
|
+
const messages = errorArray.map((e: any) => e?.['ErrorMessage']?.['_text'] ?? 'Unknown Landmark error').join('; ');
|
|
36
|
+
throw new Error(messages);
|
|
37
|
+
}
|
|
38
|
+
let response: FlavorcloudShipmentResponse = shipObj.buildResponse(landmarkShipmentRes, args);
|
|
39
|
+
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'createShipmet', propertyName: 'response', propertyValue: response});
|
|
40
|
+
return response;
|
|
41
|
+
} catch(e) {
|
|
42
|
+
app.logger?.error(app.flclError?.create({npm: 'fc-landmark', className: 'Landmark', methodName: 'createShipmet', propertyName: 'landMark_ERROR', cause: e, message: 'Exception while creating shipment in Landmark'}));
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getTrackingInfo(args: any) {
|
|
48
|
+
try {
|
|
49
|
+
|
|
50
|
+
let trackObj = new Tracking();
|
|
51
|
+
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'getTrackingInfo', propertyName: 'LandmarkInput', propertyValue: args});
|
|
52
|
+
let landmarkTrackRequest: string = trackObj.buildTrackingRequest(args,this.username,this.password,this.test,this.clientId);
|
|
53
|
+
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'getTrackingInfo', propertyName: 'LandmarkTrackRequest', propertyValue: landmarkTrackRequest});
|
|
54
|
+
let landMarkTrackingRes: any = await trackObj.trackInfo(landmarkTrackRequest);
|
|
55
|
+
if(landMarkTrackingRes.hasOwnProperty("TrackResponse") && landMarkTrackingRes['TrackResponse']['Errors']){
|
|
56
|
+
throw new Error(landMarkTrackingRes['TrackResponse']['Errors']['Error']['ErrorMessage']['_text']) ;
|
|
57
|
+
}
|
|
58
|
+
let response: FlavorcloudTrackingResponse = trackObj.buildResponse(landMarkTrackingRes, args);
|
|
59
|
+
app.logger?.info({npm: 'fc-landmark', className: 'Landmark', methodName: 'getTrackingInfo', propertyName: 'response', propertyValue: response});
|
|
60
|
+
return response;
|
|
61
|
+
} catch(e) {
|
|
62
|
+
app.logger?.error(app.flclError?.create({npm: 'fc-landmark', className: 'Landmark', methodName: 'getTrackingInfo', propertyName: 'landMark_ERROR', cause: e, message: 'Exception while get trackinfo in Landmark'}));
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|