Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions components/trunkrs/actions/cancel-shipment/cancel-shipment.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import trunkrs from "../../trunkrs.app.mjs";

export default {
key: "trunkrs-cancel-shipment",
name: "Cancel Shipment",
description: "Cancel a shipment. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/29cfeecfd2273-cancel-shipment)",
version: "0.0.1",
type: "action",
props: {
trunkrs,
trunkrsNr: {
propDefinition: [
trunkrs,
"trunkrsNr",
],
},
},
async run({ $ }) {
const { data } = await this.trunkrs.cancelShipment({
$,
trunkrsNr: this.trunkrsNr,
});
$.export("$summary", `Successfully cancelled shipment ${this.trunkrsNr}.`);
return data;
},
};
148 changes: 148 additions & 0 deletions components/trunkrs/actions/create-shipment/create-shipment.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import trunkrs from "../../trunkrs.app.mjs";

export default {
key: "trunkrs-create-shipment",
name: "Create Shipment",
description: "Create a new shipment. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/85ba39933b755-create-shipment)",
version: "0.0.1",
type: "action",
props: {
trunkrs,
orderReference: {
type: "string",
label: "Order Reference",
description: "Internal order reference provided by customer, this must be unique",
},
senderName: {
type: "string",
label: "Sender Name",
description: "The name of the sender",
},
senderEmailAddress: {
type: "string",
label: "Sender Email Address",
description: "The email address of the sender",
},
senderStreetAddress: {
type: "string",
label: "Sender Street Address",
description: "The street address of the sender",
},
senderPostalCode: {
type: "string",
label: "Sender Postal Code",
description: "The postal code of the sender",
},
senderCity: {
type: "string",
label: "Sender City",
description: "The city of the sender",
},
senderCountry: {
propDefinition: [
trunkrs,
"country",
],
description: "The country of the sender",
},
recipientName: {
type: "string",
label: "Recipient Name",
description: "The name of the recipient",
},
recipientEmailAddress: {
type: "string",
label: "Recipient Email Address",
description: "The email address of the recipient",
},
recipientStreetAddress: {
type: "string",
label: "Recipient Street Address",
description: "The street address of the recipient",
},
recipientPostalCode: {
type: "string",
label: "Recipient Postal Code",
description: "The postal code of the recipient",
},
recipientCity: {
type: "string",
label: "Recipient City",
description: "The city of the recipient",
},
recipientCountry: {
propDefinition: [
trunkrs,
"country",
],
},
parcelWeightUnit: {
type: "string",
label: "Parcel Weight Unit",
description: "The unit of weight for the parcels",
options: [
"g",
"kg",
],
},
parcelWeights: {
type: "string[]",
label: "Parcel Weights",
description: "An array of weights for the parcels in the unit provided by the parcelWeightUnit prop",
},
timeSlotId: {
propDefinition: [
trunkrs,
"timeSlotId",
(c) => ({
country: c.recipientCountry,
postalCode: c.recipientPostalCode,
}),
],
},
service: {
type: "string",
label: "Service",
description: "Specifies the service level of this parcel. To use the freezer service, set the value to SAME_DAY_FROZEN_FOOD.",
options: [
"SAME_DAY",
"SAME_DAY_FROZEN_FOOD",
],
optional: true,
},
},
async run({ $ }) {
const { data } = await this.trunkrs.createShipment({
$,
data: {
orderReference: this.orderReference,
sender: {
name: this.senderName,
emailAddress: this.senderEmailAddress,
address: this.senderStreetAddress,
postalCode: this.senderPostalCode,
city: this.senderCity,
country: this.senderCountry,
},
recipient: {
name: this.recipientName,
emailAddress: this.recipientEmailAddress,
address: this.recipientStreetAddress,
postalCode: this.recipientPostalCode,
city: this.recipientCity,
country: this.recipientCountry,
},
parcel: this.parcelWeights.map((weight) => ({
weight: {
unit: this.parcelWeightUnit,
value: +weight,
},
})),
timeSlotId: this.timeSlotId,
service: this.service,
},
});
$.export("$summary", "Successfully created shipment.");
return data;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import trunkrs from "../../trunkrs.app.mjs";

export default {
key: "trunkrs-get-shipment-state",
name: "Get Shipment State",
description: "Get the state of a shipment. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/47b5b585da6c9-get-status-for-specific-shipment)",
version: "0.0.1",
type: "action",
props: {
trunkrs,
trunkrsNr: {
propDefinition: [
trunkrs,
"trunkrsNr",
],
},
},
async run({ $ }) {
const { data } = await this.trunkrs.getShipmentState({
$,
trunkrsNr: this.trunkrsNr,
});
$.export("$summary", `Successfully fetched shipment state for ${this.trunkrsNr}.`);
return data;
},
};
26 changes: 26 additions & 0 deletions components/trunkrs/actions/get-shipment/get-shipment.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import trunkrs from "../../trunkrs.app.mjs";

export default {
key: "trunkrs-get-shipment",
name: "Get Shipment",
description: "Get a shipment by its Trunkrs number. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/34c6f57bded33-get-a-specific-shipment)",
version: "0.0.1",
type: "action",
props: {
trunkrs,
trunkrsNr: {
propDefinition: [
trunkrs,
"trunkrsNr",
],
},
},
async run({ $ }) {
const { data } = await this.trunkrs.getShipment({
$,
trunkrsNr: this.trunkrsNr,
});
$.export("$summary", `Successfully fetched shipment ${this.trunkrsNr}.`);
return data;
},
};
52 changes: 52 additions & 0 deletions components/trunkrs/actions/list-shipments/list-shipments.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import trunkrs from "../../trunkrs.app.mjs";
import constants from "../../common/constants.mjs";

export default {
key: "trunkrs-list-shipments",
name: "List Shipments",
description: "List all shipments. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/b425314ab6c67-list-shipments)",
version: "0.0.1",
type: "action",
props: {
trunkrs,
sort: {
type: "string",
label: "Sort",
description: "The field to sort by. Fields prepended with a dash (-) are sorted in descending order.",
options: constants.SHIPMENT_SORT_FIELDS,
},
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of shipments to return. Default: 100",
default: 100,
optional: true,
},
offset: {
type: "integer",
label: "Offset",
description: "The offset to start from. Default: 0",
optional: true,
},
},
async run({ $ }) {
const results = this.trunkrs.paginate({
fn: this.trunkrs.listShipments,
args: {
$,
params: {
sort: this.sort,
offset: this.offset,
},
},
max: this.maxResults,
});

const shipments = [];
for await (const shipment of results) {
shipments.push(shipment);
}
$.export("$summary", `Successfully fetched ${shipments.length} shipments.`);
return shipments;
},
};
35 changes: 35 additions & 0 deletions components/trunkrs/actions/list-time-slots/list-time-slots.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import trunkrs from "../../trunkrs.app.mjs";

export default {
key: "trunkrs-list-time-slots",
name: "List Time Slots",
description: "List time slots. [See the documentation](https://docs.trunkrs.nl/docs/v2-api-documentation/5f27080ea3314-list-time-slots)",
version: "0.0.1",
type: "action",
props: {
trunkrs,
country: {
propDefinition: [
trunkrs,
"country",
],
},
postalCode: {
type: "string",
label: "Postal Code",
description: "The postal code of the recipient",
optional: true,
},
},
async run({ $ }) {
const { data } = await this.trunkrs.listTimeSlots({
$,
params: {
country: this.country,
postalCode: this.postalCode,
},
});
$.export("$summary", `Successfully fetched ${data.length} time slots.`);
return data;
},
};
48 changes: 48 additions & 0 deletions components/trunkrs/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const COUNTRIES = [
{
value: "NL",
label: "Netherlands",
},
{
value: "BE",
label: "Belgium",
},
];

const WEBHOOK_EVENTS = [
"onStateUpdate",
"onCreation",
"onCancellation",
"onReview",
];

const SHIPMENT_SORT_FIELDS = [
"trunkrsNr",
"-trunkrsNr",
"recipient.name",
"-recipient.name",
"orderReference",
"-orderReference",
"sender.companyName",
"-sender.companyName",
"sender.name",
"-sender.name",
"timeSlot.id",
"-timeSlot.id",
"timeSlot.cutOffTime",
"-timeSlot.cutOffTime",
"state.code",
"-state.code",
"state.reasonCode",
"-state.reasonCode",
"state.timeStamp",
"-state.timeStamp",
"service",
"-service",
];

export default {
COUNTRIES,
WEBHOOK_EVENTS,
SHIPMENT_SORT_FIELDS,
};
7 changes: 5 additions & 2 deletions components/trunkrs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/trunkrs",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Trunkrs Components",
"main": "trunkrs.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
Loading
Loading