Skip to content

Commit bfaac7e

Browse files
authored
Trunkrs - new components (#18156)
* new components * pnpm-lock.yaml
1 parent af4fc64 commit bfaac7e

File tree

19 files changed

+690
-8
lines changed

19 files changed

+690
-8
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import trunkrs from "../../trunkrs.app.mjs";
2+
3+
export default {
4+
key: "trunkrs-cancel-shipment",
5+
name: "Cancel Shipment",
6+
description: "Cancel a shipment. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/29cfeecfd2273-cancel-shipment)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
trunkrs,
11+
trunkrsNr: {
12+
propDefinition: [
13+
trunkrs,
14+
"trunkrsNr",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const { data } = await this.trunkrs.cancelShipment({
20+
$,
21+
trunkrsNr: this.trunkrsNr,
22+
});
23+
$.export("$summary", `Successfully cancelled shipment ${this.trunkrsNr}.`);
24+
return data;
25+
},
26+
};
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import trunkrs from "../../trunkrs.app.mjs";
2+
3+
export default {
4+
key: "trunkrs-create-shipment",
5+
name: "Create Shipment",
6+
description: "Create a new shipment. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/85ba39933b755-create-shipment)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
trunkrs,
11+
orderReference: {
12+
type: "string",
13+
label: "Order Reference",
14+
description: "Internal order reference provided by customer, this must be unique",
15+
},
16+
senderName: {
17+
type: "string",
18+
label: "Sender Name",
19+
description: "The name of the sender",
20+
},
21+
senderEmailAddress: {
22+
type: "string",
23+
label: "Sender Email Address",
24+
description: "The email address of the sender",
25+
},
26+
senderStreetAddress: {
27+
type: "string",
28+
label: "Sender Street Address",
29+
description: "The street address of the sender",
30+
},
31+
senderPostalCode: {
32+
type: "string",
33+
label: "Sender Postal Code",
34+
description: "The postal code of the sender",
35+
},
36+
senderCity: {
37+
type: "string",
38+
label: "Sender City",
39+
description: "The city of the sender",
40+
},
41+
senderCountry: {
42+
propDefinition: [
43+
trunkrs,
44+
"country",
45+
],
46+
description: "The country of the sender",
47+
},
48+
recipientName: {
49+
type: "string",
50+
label: "Recipient Name",
51+
description: "The name of the recipient",
52+
},
53+
recipientEmailAddress: {
54+
type: "string",
55+
label: "Recipient Email Address",
56+
description: "The email address of the recipient",
57+
},
58+
recipientStreetAddress: {
59+
type: "string",
60+
label: "Recipient Street Address",
61+
description: "The street address of the recipient",
62+
},
63+
recipientPostalCode: {
64+
type: "string",
65+
label: "Recipient Postal Code",
66+
description: "The postal code of the recipient",
67+
},
68+
recipientCity: {
69+
type: "string",
70+
label: "Recipient City",
71+
description: "The city of the recipient",
72+
},
73+
recipientCountry: {
74+
propDefinition: [
75+
trunkrs,
76+
"country",
77+
],
78+
},
79+
parcelWeightUnit: {
80+
type: "string",
81+
label: "Parcel Weight Unit",
82+
description: "The unit of weight for the parcels",
83+
options: [
84+
"g",
85+
"kg",
86+
],
87+
},
88+
parcelWeights: {
89+
type: "string[]",
90+
label: "Parcel Weights",
91+
description: "An array of weights for the parcels in the unit provided by the parcelWeightUnit prop",
92+
},
93+
timeSlotId: {
94+
propDefinition: [
95+
trunkrs,
96+
"timeSlotId",
97+
(c) => ({
98+
country: c.recipientCountry,
99+
postalCode: c.recipientPostalCode,
100+
}),
101+
],
102+
},
103+
service: {
104+
type: "string",
105+
label: "Service",
106+
description: "Specifies the service level of this parcel. To use the freezer service, set the value to SAME_DAY_FROZEN_FOOD.",
107+
options: [
108+
"SAME_DAY",
109+
"SAME_DAY_FROZEN_FOOD",
110+
],
111+
optional: true,
112+
},
113+
},
114+
async run({ $ }) {
115+
const { data } = await this.trunkrs.createShipment({
116+
$,
117+
data: {
118+
orderReference: this.orderReference,
119+
sender: {
120+
name: this.senderName,
121+
emailAddress: this.senderEmailAddress,
122+
address: this.senderStreetAddress,
123+
postalCode: this.senderPostalCode,
124+
city: this.senderCity,
125+
country: this.senderCountry,
126+
},
127+
recipient: {
128+
name: this.recipientName,
129+
emailAddress: this.recipientEmailAddress,
130+
address: this.recipientStreetAddress,
131+
postalCode: this.recipientPostalCode,
132+
city: this.recipientCity,
133+
country: this.recipientCountry,
134+
},
135+
parcel: this.parcelWeights.map((weight) => ({
136+
weight: {
137+
unit: this.parcelWeightUnit,
138+
value: +weight,
139+
},
140+
})),
141+
timeSlotId: this.timeSlotId,
142+
service: this.service,
143+
},
144+
});
145+
$.export("$summary", "Successfully created shipment.");
146+
return data;
147+
},
148+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import trunkrs from "../../trunkrs.app.mjs";
2+
3+
export default {
4+
key: "trunkrs-get-shipment-state",
5+
name: "Get Shipment State",
6+
description: "Get the state of a shipment. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/47b5b585da6c9-get-status-for-specific-shipment)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
trunkrs,
11+
trunkrsNr: {
12+
propDefinition: [
13+
trunkrs,
14+
"trunkrsNr",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const { data } = await this.trunkrs.getShipmentState({
20+
$,
21+
trunkrsNr: this.trunkrsNr,
22+
});
23+
$.export("$summary", `Successfully fetched shipment state for ${this.trunkrsNr}.`);
24+
return data;
25+
},
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import trunkrs from "../../trunkrs.app.mjs";
2+
3+
export default {
4+
key: "trunkrs-get-shipment",
5+
name: "Get Shipment",
6+
description: "Get a shipment by its Trunkrs number. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/34c6f57bded33-get-a-specific-shipment)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
trunkrs,
11+
trunkrsNr: {
12+
propDefinition: [
13+
trunkrs,
14+
"trunkrsNr",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const { data } = await this.trunkrs.getShipment({
20+
$,
21+
trunkrsNr: this.trunkrsNr,
22+
});
23+
$.export("$summary", `Successfully fetched shipment ${this.trunkrsNr}.`);
24+
return data;
25+
},
26+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import trunkrs from "../../trunkrs.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "trunkrs-list-shipments",
6+
name: "List Shipments",
7+
description: "List all shipments. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/b425314ab6c67-list-shipments)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
trunkrs,
12+
sort: {
13+
type: "string",
14+
label: "Sort",
15+
description: "The field to sort by. Fields prepended with a dash (-) are sorted in descending order.",
16+
options: constants.SHIPMENT_SORT_FIELDS,
17+
},
18+
maxResults: {
19+
type: "integer",
20+
label: "Max Results",
21+
description: "The maximum number of shipments to return. Default: 100",
22+
default: 100,
23+
optional: true,
24+
},
25+
offset: {
26+
type: "integer",
27+
label: "Offset",
28+
description: "The offset to start from. Default: 0",
29+
optional: true,
30+
},
31+
},
32+
async run({ $ }) {
33+
const results = this.trunkrs.paginate({
34+
fn: this.trunkrs.listShipments,
35+
args: {
36+
$,
37+
params: {
38+
sort: this.sort,
39+
offset: this.offset,
40+
},
41+
},
42+
max: this.maxResults,
43+
});
44+
45+
const shipments = [];
46+
for await (const shipment of results) {
47+
shipments.push(shipment);
48+
}
49+
$.export("$summary", `Successfully fetched ${shipments.length} shipments.`);
50+
return shipments;
51+
},
52+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import trunkrs from "../../trunkrs.app.mjs";
2+
3+
export default {
4+
key: "trunkrs-list-time-slots",
5+
name: "List Time Slots",
6+
description: "List time slots. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/5f27080ea3314-list-time-slots)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
trunkrs,
11+
country: {
12+
propDefinition: [
13+
trunkrs,
14+
"country",
15+
],
16+
},
17+
postalCode: {
18+
type: "string",
19+
label: "Postal Code",
20+
description: "The postal code of the recipient",
21+
optional: true,
22+
},
23+
},
24+
async run({ $ }) {
25+
const { data } = await this.trunkrs.listTimeSlots({
26+
$,
27+
params: {
28+
country: this.country,
29+
postalCode: this.postalCode,
30+
},
31+
});
32+
$.export("$summary", `Successfully fetched ${data.length} time slots.`);
33+
return data;
34+
},
35+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const COUNTRIES = [
2+
{
3+
value: "NL",
4+
label: "Netherlands",
5+
},
6+
{
7+
value: "BE",
8+
label: "Belgium",
9+
},
10+
];
11+
12+
const WEBHOOK_EVENTS = [
13+
"onStateUpdate",
14+
"onCreation",
15+
"onCancellation",
16+
"onReview",
17+
];
18+
19+
const SHIPMENT_SORT_FIELDS = [
20+
"trunkrsNr",
21+
"-trunkrsNr",
22+
"recipient.name",
23+
"-recipient.name",
24+
"orderReference",
25+
"-orderReference",
26+
"sender.companyName",
27+
"-sender.companyName",
28+
"sender.name",
29+
"-sender.name",
30+
"timeSlot.id",
31+
"-timeSlot.id",
32+
"timeSlot.cutOffTime",
33+
"-timeSlot.cutOffTime",
34+
"state.code",
35+
"-state.code",
36+
"state.reasonCode",
37+
"-state.reasonCode",
38+
"state.timeStamp",
39+
"-state.timeStamp",
40+
"service",
41+
"-service",
42+
];
43+
44+
export default {
45+
COUNTRIES,
46+
WEBHOOK_EVENTS,
47+
SHIPMENT_SORT_FIELDS,
48+
};

components/trunkrs/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/trunkrs",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Trunkrs Components",
55
"main": "trunkrs.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)