Skip to content

Commit 50ea485

Browse files
committed
new components
1 parent 4fb872c commit 50ea485

File tree

9 files changed

+487
-7
lines changed

9 files changed

+487
-7
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import dhl from "../../dhl.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "dhl-create-subscription",
6+
name: "Create Subscription",
7+
description: "Create a new subscription. [See the documentation](https://developer.dhl.com/api-reference/dgf-push-api#operations-Timestamp_Push_API_v2-timestampNotificationSubscriptionv2_POST)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
dhl,
12+
status: {
13+
propDefinition: [
14+
dhl,
15+
"status",
16+
],
17+
},
18+
onlyNotifyAPIBookings: {
19+
type: "string",
20+
label: "Only Notify API Bookings",
21+
description: "Enable to receive timestamp or tracking notifications exclusively for shipments booked through the API",
22+
options: [
23+
"true",
24+
"false",
25+
],
26+
optional: true,
27+
},
28+
subscriptionType: {
29+
type: "string",
30+
label: "Subscription Type",
31+
description: "Specify the type of subscription",
32+
options: constants.SUBSCRIPTION_TYPES,
33+
optional: true,
34+
},
35+
numberOfFilters: {
36+
type: "integer",
37+
label: "Number of Filters",
38+
description: "Specify the number of filters to apply to the subscription",
39+
min: 1,
40+
reloadProps: true,
41+
},
42+
callbackUrl: {
43+
propDefinition: [
44+
dhl,
45+
"callbackUrl",
46+
],
47+
},
48+
},
49+
additionalProps() {
50+
const props = {};
51+
if (!(this.numberOfFilters > 0)) {
52+
return props;
53+
}
54+
for (let i = 1; i <= this.numberOfFilters; i++) {
55+
props[`modeOfTransport${i}`] = {
56+
type: "string",
57+
label: `Mode of Transport ${i}`,
58+
description: "Specify the mode of transport for the filter",
59+
options: constants.MODE_OF_TRANSPORT,
60+
};
61+
props[`origin${i}`] = {
62+
type: "string",
63+
label: `Origin ${i}`,
64+
description: "Origin country code (2 character) or UNLOCODE (5 character)",
65+
};
66+
props[`destination${i}`] = {
67+
type: "string",
68+
label: `Destination ${i}`,
69+
description: "Destination country code (2 character) or UNLOCODE (5 character)",
70+
};
71+
props[`events${i}`] = {
72+
type: "string[]",
73+
label: `Events ${i}`,
74+
description: "Event codes. Please refer to [GET Started Page](https://developer.dhl.com/api-reference/dgf-push-api#get-started-section/timestamp-push-api-v2-_28in-testing_29) for the event codes. Example:`A30`",
75+
optional: true,
76+
};
77+
}
78+
return props;
79+
},
80+
async run({ $ }) {
81+
const filters = [];
82+
for (let i = 1; i <= this.numberOfFilters; i++) {
83+
filters.push({
84+
modeOfTransport: this[`modeOfTransport${i}`],
85+
origin: this[`origin${i}`],
86+
destination: this[`destination${i}`],
87+
Events: this[`events${i}`],
88+
});
89+
}
90+
91+
const response = await this.dhl.createSubscription({
92+
$,
93+
data: {
94+
"status": this.status,
95+
"onlyNotifyAPIBookings": this.onlyNotifyAPIBookings,
96+
"subscription-type": this.subscriptionType,
97+
filters,
98+
"callback-details": {
99+
"callback-url": this.callbackUrl,
100+
},
101+
},
102+
});
103+
104+
$.export("$summary", `Successfully created subscription ${response.subscriptionID}`);
105+
return response;
106+
},
107+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import dhl from "../../dhl.app.mjs";
2+
3+
export default {
4+
key: "dhl-get-subscription-details",
5+
name: "Get Subscription Details",
6+
description: "Get details about a subscription. [See the documentation](https://developer.dhl.com/api-reference/dgf-push-api#operations-Timestamp_Push_API_v2-timestampNotificationSubscriptionv2_GET)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
dhl,
11+
subscriptionId: {
12+
propDefinition: [
13+
dhl,
14+
"subscriptionId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.dhl.getSubscriptionDetails({
20+
$,
21+
subscriberId: this.subscriptionId,
22+
});
23+
$.export("$summary", `Successfully fetched subscription details for ${this.subscriptionId}`);
24+
return response;
25+
},
26+
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import dhl from "../../dhl.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "dhl-get-tracking",
6+
name: "Get Tracking Information",
7+
description: "Get tracking information for shipments. [See the documentation](https://developer.dhl.com/api-reference/shipment-tracking#operations-default-getTrackingShipment)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
dhl,
12+
trackingNumber: {
13+
type: "string",
14+
label: "Tracking Number",
15+
description: "The tracking number of the shipment to get tracking information for",
16+
},
17+
service: {
18+
type: "string",
19+
label: "Service",
20+
description: "The service of the shipment to get tracking information for",
21+
options: constants.SHIPPIMG_SERVICES,
22+
optional: true,
23+
},
24+
requesterCountryCode: {
25+
type: "string",
26+
label: "Requester Country Code",
27+
description: "Optional ISO 3166-1 alpha-2 country code represents country of the consumer of the API response.",
28+
optional: true,
29+
},
30+
originCountryCode: {
31+
type: "string",
32+
label: "Origin Country Code",
33+
description: "Optional ISO 3166-1 alpha-2 country code of the shipment origin to further qualify the shipment tracking number (trackingNumber) parameter of the request.",
34+
optional: true,
35+
},
36+
recipientPostalCode: {
37+
type: "string",
38+
label: "Requester Postal Code",
39+
description: "Postal code of the destination address",
40+
optional: true,
41+
},
42+
language: {
43+
type: "string",
44+
label: "Language",
45+
description: "ISO 639-1 2-character language code for the response. This parameter serves as an indication of the client preferences ONLY. Language availability depends on the service used.",
46+
optional: true,
47+
},
48+
limit: {
49+
type: "integer",
50+
label: "Limit",
51+
description: "Maximum number of events to be returned in the response. Default: 5",
52+
optional: true,
53+
},
54+
offset: {
55+
type: "integer",
56+
label: "Offset",
57+
description: "Offset of the first event to be returned in the response. Default: 0",
58+
optional: true,
59+
},
60+
},
61+
async run({ $ }) {
62+
const response = await this.dhl.getTracking({
63+
$,
64+
params: {
65+
trackingNumber: this.trackingNumber,
66+
service: this.service,
67+
requesterCountryCode: this.requesterCountryCode,
68+
originCountryCode: this.originCountryCode,
69+
recipientPostalCode: this.recipientPostalCode,
70+
language: this.language,
71+
limit: this.limit,
72+
offset: this.offset,
73+
},
74+
});
75+
$.export("$summary", `Successfully fetched tracking information for ${this.trackingNumber}`);
76+
return response;
77+
},
78+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import dhl from "../../dhl.app.mjs";
2+
3+
export default {
4+
key: "dhl-list-subscriptions",
5+
name: "List Subscriptions",
6+
description: "List all subscriptions. [See the documentation](https://developer.dhl.com/api-reference/dgf-push-api#operations-Timestamp_Push_API_v2-timestampNotificationSubscriptionv2_GET)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
dhl,
11+
},
12+
async run({ $ }) {
13+
const response = await this.dhl.listSubscriptions({
14+
$,
15+
});
16+
$.export("$summary", `Successfully listed ${response.subscriptions?.length || 0} subscriptions`);
17+
return response;
18+
},
19+
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import dhl from "../../dhl.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "dhl-update-subscription-filters",
6+
name: "Update Subscription Filters",
7+
description: "Update the filters of a subscription. [See the documentation](https://developer.dhl.com/api-reference/dgf-push-api#operations-Timestamp_Push_API_v2-timestampNotificationSubscriptionv2_PUT)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
dhl,
12+
subscriptionId: {
13+
propDefinition: [
14+
dhl,
15+
"subscriptionId",
16+
],
17+
},
18+
numberOfFilters: {
19+
type: "integer",
20+
label: "Number of Filters",
21+
description: "Specify the number of filters to apply to the subscription",
22+
min: 1,
23+
reloadProps: true,
24+
},
25+
callbackUrl: {
26+
propDefinition: [
27+
dhl,
28+
"callbackUrl",
29+
],
30+
},
31+
},
32+
additionalProps() {
33+
const props = {};
34+
if (!(this.numberOfFilters > 0)) {
35+
return props;
36+
}
37+
for (let i = 1; i <= this.numberOfFilters; i++) {
38+
props[`modeOfTransport${i}`] = {
39+
type: "string",
40+
label: `Mode of Transport ${i}`,
41+
description: "Specify the mode of transport for the filter",
42+
options: constants.MODE_OF_TRANSPORT,
43+
};
44+
props[`origin${i}`] = {
45+
type: "string",
46+
label: `Origin ${i}`,
47+
description: "Origin country code (2 character) or UNLOCODE (5 character)",
48+
};
49+
props[`destination${i}`] = {
50+
type: "string",
51+
label: `Destination ${i}`,
52+
description: "Destination country code (2 character) or UNLOCODE (5 character)",
53+
};
54+
props[`events${i}`] = {
55+
type: "string[]",
56+
label: `Events ${i}`,
57+
description: "Event codes. Please refer to [GET Started Page](https://developer.dhl.com/api-reference/dgf-push-api#get-started-section/timestamp-push-api-v2-_28in-testing_29) for the event codes. Example:`A30`",
58+
optional: true,
59+
};
60+
}
61+
return props;
62+
},
63+
async run({ $ }) {
64+
const filters = [];
65+
for (let i = 1; i <= this.numberOfFilters; i++) {
66+
filters.push({
67+
modeOfTransport: this[`modeOfTransport${i}`],
68+
origin: this[`origin${i}`],
69+
destination: this[`destination${i}`],
70+
Events: this[`events${i}`],
71+
});
72+
}
73+
74+
const response = await this.dhl.updateSubscriptionFilters({
75+
$,
76+
subscriberId: this.subscriptionId,
77+
data: {
78+
filters,
79+
"callback-details": {
80+
"callback-url": this.callbackUrl,
81+
},
82+
},
83+
});
84+
85+
$.export("$summary", `Successfully updated subscription ${this.subscriptionId} filters`);
86+
return response;
87+
},
88+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import dhl from "../../dhl.app.mjs";
2+
3+
export default {
4+
key: "dhl-update-subscription-status",
5+
name: "Update Subscription Status",
6+
description: "Update the status of a subscription. [See the documentation](https://developer.dhl.com/api-reference/dgf-push-api#operations-Timestamp_Push_API_v2-timestampNotificationSubscriptionv2_PATCH)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
dhl,
11+
subscriptionId: {
12+
propDefinition: [
13+
dhl,
14+
"subscriptionId",
15+
],
16+
},
17+
status: {
18+
propDefinition: [
19+
dhl,
20+
"status",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.dhl.updateSubscriptionStatus({
26+
$,
27+
subscriberId: this.subscriptionId,
28+
data: {
29+
"status": this.status,
30+
},
31+
});
32+
$.export("$summary", `Successfully updated subscription ${this.subscriptionId} status to ${this.status}`);
33+
return response;
34+
},
35+
};

0 commit comments

Comments
 (0)