Skip to content

Commit de206e6

Browse files
committed
[APP] PostNL - new action components
1 parent 0151fa0 commit de206e6

File tree

5 files changed

+229
-7
lines changed

5 files changed

+229
-7
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import app from "../../postnl.app.mjs";
2+
3+
export default {
4+
key: "postnl-get-status-by-barcode",
5+
name: "Get Status By Barcode",
6+
description: "Retrieve the status of a shipment using its barcode. [See the documentation](https://developer.postnl.nl/docs/#/http/api-endpoints/send-track/shippingstatus/get-status-by-barcode)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
app,
11+
barcode: {
12+
propDefinition: [
13+
app,
14+
"barcode",
15+
],
16+
},
17+
detail: {
18+
propDefinition: [
19+
app,
20+
"detail",
21+
],
22+
},
23+
language: {
24+
propDefinition: [
25+
app,
26+
"language",
27+
],
28+
},
29+
maxDays: {
30+
propDefinition: [
31+
app,
32+
"maxDays",
33+
],
34+
},
35+
},
36+
async run({ $ }) {
37+
const {
38+
app,
39+
barcode,
40+
detail,
41+
language,
42+
maxDays,
43+
} = this;
44+
45+
const response = await app.getStatusByBarcode({
46+
$,
47+
barcode,
48+
params: {
49+
detail,
50+
language,
51+
maxDays,
52+
},
53+
});
54+
55+
$.export("$summary", "Successfully retrieved status by barcode");
56+
return response;
57+
},
58+
};
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import app from "../../postnl.app.mjs";
2+
3+
export default {
4+
key: "postnl-get-status-by-reference",
5+
name: "Get Status By Reference",
6+
description: "Retrieve the status of a shipment using a reference number. [See the documentation](https://developer.postnl.nl/docs/#/http/api-endpoints/send-track/shippingstatus/get-status-by-reference)",
7+
type: "action",
8+
version: "0.0.1",
9+
props: {
10+
app,
11+
customerCode: {
12+
propDefinition: [
13+
app,
14+
"customerCode",
15+
],
16+
},
17+
customerNumber: {
18+
propDefinition: [
19+
app,
20+
"customerNumber",
21+
],
22+
},
23+
reference: {
24+
propDefinition: [
25+
app,
26+
"referenceId",
27+
],
28+
},
29+
detail: {
30+
propDefinition: [
31+
app,
32+
"detail",
33+
],
34+
},
35+
language: {
36+
propDefinition: [
37+
app,
38+
"language",
39+
],
40+
},
41+
maxDays: {
42+
propDefinition: [
43+
app,
44+
"maxDays",
45+
],
46+
},
47+
},
48+
async run({ $ }) {
49+
const {
50+
app,
51+
customerCode,
52+
customerNumber,
53+
reference,
54+
detail,
55+
language,
56+
maxDays,
57+
} = this;
58+
59+
const response = await app.getStatusByReference({
60+
$,
61+
params: {
62+
customerCode,
63+
customerNumber,
64+
reference,
65+
detail,
66+
language,
67+
maxDays,
68+
},
69+
});
70+
71+
$.export("$summary", "Successfully retrieved status by reference");
72+
return response;
73+
},
74+
};

components/postnl/package.json

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

components/postnl/postnl.app.mjs

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,94 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "postnl",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
barcode: {
8+
type: "string",
9+
label: "Barcode",
10+
description: "The barcode of the shipment to track. Eg. `3SABCD123456789`",
11+
},
12+
customerCode: {
13+
type: "string",
14+
label: "Customer Code",
15+
description: "The customer code for reference tracking",
16+
async options() {
17+
return [
18+
this.$auth.customer_code,
19+
];
20+
},
21+
},
22+
customerNumber: {
23+
type: "string",
24+
label: "Customer Number",
25+
description: "The customer number for reference tracking",
26+
},
27+
referenceId: {
28+
type: "string",
29+
label: "Reference ID",
30+
description: "The reference number to track",
31+
},
32+
detail: {
33+
type: "boolean",
34+
label: "Detail",
35+
description: "Option to include old statuses in the response",
36+
optional: true,
37+
},
38+
language: {
39+
type: "string",
40+
label: "Language",
41+
description: "Language of the returned shipment and status descriptions (default is Dutch)",
42+
options: [
43+
"NL",
44+
"EN",
45+
"CN",
46+
"DE",
47+
"FR",
48+
],
49+
optional: true,
50+
},
51+
maxDays: {
52+
type: "integer",
53+
label: "Max Days",
54+
description: "Limit the number of days that will be searched (decrease this amount for better performance).",
55+
optional: true,
56+
},
57+
},
558
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
59+
getUrl(path) {
60+
const { api_url: baseUrl } = this.$auth;
61+
return `${baseUrl}${path}`;
62+
},
63+
getHeaders(headers) {
64+
return {
65+
"Content-Type": "application/json",
66+
"apikey": this.$auth.api_key,
67+
...headers,
68+
};
69+
},
70+
makeRequest({
71+
$ = this, path, headers, ...config
72+
}) {
73+
return axios($, {
74+
url: this.getUrl(path),
75+
headers: this.getHeaders(headers),
76+
...config,
77+
});
78+
},
79+
getStatusByBarcode({
80+
barcode, ...args
81+
} = {}) {
82+
return this.makeRequest({
83+
path: `/shipment/v2/status/barcode/${barcode}`,
84+
...args,
85+
});
86+
},
87+
getStatusByReference(args = {}) {
88+
return this.makeRequest({
89+
path: "/shipment/v2/status/reference",
90+
...args,
91+
});
992
},
1093
},
1194
};

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)