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/src/tracking.ts
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { FlavorcloudTrackingResponse} from "./types";
|
|
2
|
-
import { MyGlobal as app } from './globals';
|
|
3
|
-
import { js2xml , xml2json} from 'xml-js';
|
|
4
|
-
|
|
5
|
-
export default class Tracking {
|
|
6
|
-
constructor() {
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
buildTrackingRequest(args: any,username: string,password: string, test:boolean,clientId:number): string{
|
|
11
|
-
try {
|
|
12
|
-
let trackRequest :any = {
|
|
13
|
-
"Login": {
|
|
14
|
-
"Username": username,
|
|
15
|
-
"Password": password
|
|
16
|
-
},
|
|
17
|
-
"Test": test,
|
|
18
|
-
"ClientID": clientId ,
|
|
19
|
-
"TrackingNumber": args.tracking_number,
|
|
20
|
-
"RetrievalType":"Historical"
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
let request :any = {
|
|
24
|
-
"TrackRequest": trackRequest
|
|
25
|
-
}
|
|
26
|
-
const xmlData = js2xml(request, { compact: true, ignoreComment: true, spaces: 4 });
|
|
27
|
-
return xmlData;
|
|
28
|
-
} catch(e) {
|
|
29
|
-
throw app.FlclError!.create({className: 'Tracking', methodName: '_buildRequest', message: 'Exception while building the LandMark Tracking request', cause: e, appendChildMsg: true});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
async trackInfo(ShipmentRequest: string): Promise<any> {
|
|
35
|
-
try {
|
|
36
|
-
let configs = {
|
|
37
|
-
headers: {
|
|
38
|
-
'Content-Type' : 'application/xml'
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
let resp = await app.axios!.post(app.track_url, ShipmentRequest, configs);
|
|
42
|
-
app.logger?.info({npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'landmark-RAW-RESPOSNE', propertyValue: resp.data});
|
|
43
|
-
let responsejson= xml2json(resp.data,{compact: true, spaces: 4}) ;
|
|
44
|
-
return JSON.parse(responsejson) ;
|
|
45
|
-
} catch(e) {
|
|
46
|
-
app.logger?.info({npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'landmar-RAW-RESPOSNE', data: {error: e}});
|
|
47
|
-
app.logger?.error(app.flclError!.create({npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'CREDITS_ERROR', cause: e}));
|
|
48
|
-
throw e;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
buildResponse(resp: any, args: any): FlavorcloudTrackingResponse{
|
|
53
|
-
let response: FlavorcloudTrackingResponse = {
|
|
54
|
-
reference: args.reference,
|
|
55
|
-
tracking_number: args.tracking_number,
|
|
56
|
-
tracking_history : []
|
|
57
|
-
};
|
|
58
|
-
if(! Array.isArray(resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'])){
|
|
59
|
-
resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'] = [resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event']]
|
|
60
|
-
}
|
|
61
|
-
for(let i = 0; i < resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'].length; i++){
|
|
62
|
-
let history: any = {};
|
|
63
|
-
let code :any = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['EventCode']['_text'] ;
|
|
64
|
-
if(code == '50' || code == '60' ){
|
|
65
|
-
history.status = "In Progress";
|
|
66
|
-
}
|
|
67
|
-
else if(code == '500'){
|
|
68
|
-
history.status = "Delivered";
|
|
69
|
-
}
|
|
70
|
-
else{
|
|
71
|
-
history.status = "In Transit";
|
|
72
|
-
}
|
|
73
|
-
history.status_date = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['DateTime']['_text'];
|
|
74
|
-
let dateofevent = new Date(history.status_date);
|
|
75
|
-
history.event_date = dateofevent.getTime();
|
|
76
|
-
history.status_detail = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['Status']['_text']|| "";
|
|
77
|
-
history.location = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['Location']['_text'] || '';
|
|
78
|
-
history.country = '';
|
|
79
|
-
response.tracking_history.push(history);
|
|
80
|
-
}
|
|
81
|
-
return response;
|
|
82
|
-
}
|
|
1
|
+
import { FlavorcloudTrackingResponse} from "./types";
|
|
2
|
+
import { MyGlobal as app } from './globals';
|
|
3
|
+
import { js2xml , xml2json} from 'xml-js';
|
|
4
|
+
|
|
5
|
+
export default class Tracking {
|
|
6
|
+
constructor() {
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
buildTrackingRequest(args: any,username: string,password: string, test:boolean,clientId:number): string{
|
|
11
|
+
try {
|
|
12
|
+
let trackRequest :any = {
|
|
13
|
+
"Login": {
|
|
14
|
+
"Username": username,
|
|
15
|
+
"Password": password
|
|
16
|
+
},
|
|
17
|
+
"Test": test,
|
|
18
|
+
"ClientID": clientId ,
|
|
19
|
+
"TrackingNumber": args.tracking_number,
|
|
20
|
+
"RetrievalType":"Historical"
|
|
21
|
+
|
|
22
|
+
};
|
|
23
|
+
let request :any = {
|
|
24
|
+
"TrackRequest": trackRequest
|
|
25
|
+
}
|
|
26
|
+
const xmlData = js2xml(request, { compact: true, ignoreComment: true, spaces: 4 });
|
|
27
|
+
return xmlData;
|
|
28
|
+
} catch(e) {
|
|
29
|
+
throw app.FlclError!.create({className: 'Tracking', methodName: '_buildRequest', message: 'Exception while building the LandMark Tracking request', cause: e, appendChildMsg: true});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
async trackInfo(ShipmentRequest: string): Promise<any> {
|
|
35
|
+
try {
|
|
36
|
+
let configs = {
|
|
37
|
+
headers: {
|
|
38
|
+
'Content-Type' : 'application/xml'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
let resp = await app.axios!.post(app.track_url, ShipmentRequest, configs);
|
|
42
|
+
app.logger?.info({npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'landmark-RAW-RESPOSNE', propertyValue: resp.data});
|
|
43
|
+
let responsejson= xml2json(resp.data,{compact: true, spaces: 4}) ;
|
|
44
|
+
return JSON.parse(responsejson) ;
|
|
45
|
+
} catch(e) {
|
|
46
|
+
app.logger?.info({npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'landmar-RAW-RESPOSNE', data: {error: e}});
|
|
47
|
+
app.logger?.error(app.flclError!.create({npm: 'fc-landmark', className: 'Tracking', methodName: 'trackInfo', propertyName: 'CREDITS_ERROR', cause: e}));
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
buildResponse(resp: any, args: any): FlavorcloudTrackingResponse{
|
|
53
|
+
let response: FlavorcloudTrackingResponse = {
|
|
54
|
+
reference: args.reference,
|
|
55
|
+
tracking_number: args.tracking_number,
|
|
56
|
+
tracking_history : []
|
|
57
|
+
};
|
|
58
|
+
if(! Array.isArray(resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'])){
|
|
59
|
+
resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'] = [resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event']]
|
|
60
|
+
}
|
|
61
|
+
for(let i = 0; i < resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'].length; i++){
|
|
62
|
+
let history: any = {};
|
|
63
|
+
let code :any = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['EventCode']['_text'] ;
|
|
64
|
+
if(code == '50' || code == '60' ){
|
|
65
|
+
history.status = "In Progress";
|
|
66
|
+
}
|
|
67
|
+
else if(code == '500'){
|
|
68
|
+
history.status = "Delivered";
|
|
69
|
+
}
|
|
70
|
+
else{
|
|
71
|
+
history.status = "In Transit";
|
|
72
|
+
}
|
|
73
|
+
history.status_date = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['DateTime']['_text'];
|
|
74
|
+
let dateofevent = new Date(history.status_date);
|
|
75
|
+
history.event_date = dateofevent.getTime();
|
|
76
|
+
history.status_detail = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['Status']['_text']|| "";
|
|
77
|
+
history.location = resp['TrackResponse']['Result']['Packages']['Package']['Events']['Event'][i]['Location']['_text'] || '';
|
|
78
|
+
history.country = '';
|
|
79
|
+
response.tracking_history.push(history);
|
|
80
|
+
}
|
|
81
|
+
return response;
|
|
82
|
+
}
|
|
83
83
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,102 +1,109 @@
|
|
|
1
|
-
import { FlclLogger, FlclError } from "fc-logger";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface AppObj {
|
|
6
|
-
logger?: FlclLogger,
|
|
7
|
-
FlclError?: typeof FlclError,
|
|
8
|
-
[x: string]: any
|
|
9
|
-
}
|
|
10
|
-
export interface credentials {
|
|
11
|
-
token?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface FlclAxiosMiddleware {
|
|
15
|
-
get: Function,
|
|
16
|
-
put: Function,
|
|
17
|
-
post: Function,
|
|
18
|
-
delete: Function,
|
|
19
|
-
}
|
|
20
|
-
export interface ValidObject {
|
|
21
|
-
[x: string]: string | number | boolean | object | [] | any
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export interface WIZMOShipmentRespone {
|
|
33
|
-
shipmentresponse : ShipmentRespone
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface ShipmentRespone{
|
|
37
|
-
tracknbr : string,
|
|
38
|
-
label : string,
|
|
39
|
-
labelformat : string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export interface FlavorcloudShipmentResponse {
|
|
46
|
-
|
|
47
|
-
master_tracking_id?: any;
|
|
48
|
-
|
|
49
|
-
provider_name?: string,
|
|
50
|
-
|
|
51
|
-
shipping_provider: string,
|
|
52
|
-
|
|
53
|
-
carrier? : string,
|
|
54
|
-
|
|
55
|
-
tracking_number: number | string,
|
|
56
|
-
|
|
57
|
-
tracking_number_multi?: Array<string>,
|
|
58
|
-
|
|
59
|
-
provider_tracking_number?: number | string,
|
|
60
|
-
|
|
61
|
-
tracking_url?: string,
|
|
62
|
-
|
|
63
|
-
shipping_label: string,
|
|
64
|
-
|
|
65
|
-
shipping_label_multi?: Array<string>,
|
|
66
|
-
|
|
67
|
-
label_type: string,
|
|
68
|
-
|
|
69
|
-
gross_weight: number,
|
|
70
|
-
|
|
71
|
-
gross_weight_unit: string,
|
|
72
|
-
|
|
73
|
-
easyPostReferenceId?: string,
|
|
74
|
-
|
|
75
|
-
ecourierzReferenceId?: string,
|
|
76
|
-
|
|
77
|
-
submitted_electronically?: boolean,
|
|
78
|
-
|
|
79
|
-
formUrl?: string | null,
|
|
80
|
-
|
|
81
|
-
fims_parcel_id?: number | string,
|
|
82
|
-
|
|
83
|
-
customsInvoiceData?: any,
|
|
84
|
-
|
|
85
|
-
form_id?: any
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface WIZMOTrackingRequest {
|
|
90
|
-
tracking: TrackingRequest
|
|
91
|
-
}
|
|
92
|
-
export interface TrackingRequest {
|
|
93
|
-
tracknbr: string
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface WIZMOTrackingResponse {
|
|
97
|
-
[x: string]: any;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export interface FlavorcloudTrackingResponse{
|
|
101
|
-
[x: string]: any;
|
|
102
|
-
}
|
|
1
|
+
import { FlclLogger, FlclError } from "fc-logger";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export interface AppObj {
|
|
6
|
+
logger?: FlclLogger,
|
|
7
|
+
FlclError?: typeof FlclError,
|
|
8
|
+
[x: string]: any
|
|
9
|
+
}
|
|
10
|
+
export interface credentials {
|
|
11
|
+
token?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FlclAxiosMiddleware {
|
|
15
|
+
get: Function,
|
|
16
|
+
put: Function,
|
|
17
|
+
post: Function,
|
|
18
|
+
delete: Function,
|
|
19
|
+
}
|
|
20
|
+
export interface ValidObject {
|
|
21
|
+
[x: string]: string | number | boolean | object | [] | any
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export interface WIZMOShipmentRespone {
|
|
33
|
+
shipmentresponse : ShipmentRespone
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ShipmentRespone{
|
|
37
|
+
tracknbr : string,
|
|
38
|
+
label : string,
|
|
39
|
+
labelformat : string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export interface FlavorcloudShipmentResponse {
|
|
46
|
+
|
|
47
|
+
master_tracking_id?: any;
|
|
48
|
+
|
|
49
|
+
provider_name?: string,
|
|
50
|
+
|
|
51
|
+
shipping_provider: string,
|
|
52
|
+
|
|
53
|
+
carrier? : string,
|
|
54
|
+
|
|
55
|
+
tracking_number: number | string,
|
|
56
|
+
|
|
57
|
+
tracking_number_multi?: Array<string>,
|
|
58
|
+
|
|
59
|
+
provider_tracking_number?: number | string,
|
|
60
|
+
|
|
61
|
+
tracking_url?: string,
|
|
62
|
+
|
|
63
|
+
shipping_label: string,
|
|
64
|
+
|
|
65
|
+
shipping_label_multi?: Array<string>,
|
|
66
|
+
|
|
67
|
+
label_type: string,
|
|
68
|
+
|
|
69
|
+
gross_weight: number,
|
|
70
|
+
|
|
71
|
+
gross_weight_unit: string,
|
|
72
|
+
|
|
73
|
+
easyPostReferenceId?: string,
|
|
74
|
+
|
|
75
|
+
ecourierzReferenceId?: string,
|
|
76
|
+
|
|
77
|
+
submitted_electronically?: boolean,
|
|
78
|
+
|
|
79
|
+
formUrl?: string | null,
|
|
80
|
+
|
|
81
|
+
fims_parcel_id?: number | string,
|
|
82
|
+
|
|
83
|
+
customsInvoiceData?: any,
|
|
84
|
+
|
|
85
|
+
form_id?: any
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface WIZMOTrackingRequest {
|
|
90
|
+
tracking: TrackingRequest
|
|
91
|
+
}
|
|
92
|
+
export interface TrackingRequest {
|
|
93
|
+
tracknbr: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface WIZMOTrackingResponse {
|
|
97
|
+
[x: string]: any;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface FlavorcloudTrackingResponse{
|
|
101
|
+
[x: string]: any;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface LandmarkProductIdentifiers {
|
|
105
|
+
MerchantProductID?: string;
|
|
106
|
+
ManufacturerProductID?: string;
|
|
107
|
+
HasStandardizedProductID?: 0 | 1;
|
|
108
|
+
StandardizedProductID?: string;
|
|
109
|
+
}
|