diff --git a/components/postnl/actions/get-status-by-barcode/get-status-by-barcode.mjs b/components/postnl/actions/get-status-by-barcode/get-status-by-barcode.mjs new file mode 100644 index 0000000000000..55246b59bdf51 --- /dev/null +++ b/components/postnl/actions/get-status-by-barcode/get-status-by-barcode.mjs @@ -0,0 +1,58 @@ +import app from "../../postnl.app.mjs"; + +export default { + key: "postnl-get-status-by-barcode", + name: "Get Status By Barcode", + 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)", + type: "action", + version: "0.0.1", + props: { + app, + barcode: { + propDefinition: [ + app, + "barcode", + ], + }, + detail: { + propDefinition: [ + app, + "detail", + ], + }, + language: { + propDefinition: [ + app, + "language", + ], + }, + maxDays: { + propDefinition: [ + app, + "maxDays", + ], + }, + }, + async run({ $ }) { + const { + app, + barcode, + detail, + language, + maxDays, + } = this; + + const response = await app.getStatusByBarcode({ + $, + barcode, + params: { + detail, + language, + maxDays, + }, + }); + + $.export("$summary", "Successfully retrieved status by barcode"); + return response; + }, +}; diff --git a/components/postnl/actions/get-status-by-reference/get-status-by-reference.mjs b/components/postnl/actions/get-status-by-reference/get-status-by-reference.mjs new file mode 100644 index 0000000000000..2e328c5a6befa --- /dev/null +++ b/components/postnl/actions/get-status-by-reference/get-status-by-reference.mjs @@ -0,0 +1,74 @@ +import app from "../../postnl.app.mjs"; + +export default { + key: "postnl-get-status-by-reference", + name: "Get Status By Reference", + 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)", + type: "action", + version: "0.0.1", + props: { + app, + customerCode: { + propDefinition: [ + app, + "customerCode", + ], + }, + customerNumber: { + propDefinition: [ + app, + "customerNumber", + ], + }, + reference: { + propDefinition: [ + app, + "referenceId", + ], + }, + detail: { + propDefinition: [ + app, + "detail", + ], + }, + language: { + propDefinition: [ + app, + "language", + ], + }, + maxDays: { + propDefinition: [ + app, + "maxDays", + ], + }, + }, + async run({ $ }) { + const { + app, + customerCode, + customerNumber, + reference, + detail, + language, + maxDays, + } = this; + + const response = await app.getStatusByReference({ + $, + params: { + customerCode, + customerNumber, + reference, + detail, + language, + maxDays, + }, + }); + + $.export("$summary", "Successfully retrieved status by reference"); + return response; + }, +}; diff --git a/components/postnl/package.json b/components/postnl/package.json index 3452c58fef198..e3843fb935ddc 100644 --- a/components/postnl/package.json +++ b/components/postnl/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/postnl", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream PostNL Components", "main": "postnl.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/postnl/postnl.app.mjs b/components/postnl/postnl.app.mjs index efc95ec9e218a..9ea80fc522701 100644 --- a/components/postnl/postnl.app.mjs +++ b/components/postnl/postnl.app.mjs @@ -1,11 +1,94 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "postnl", - propDefinitions: {}, + propDefinitions: { + barcode: { + type: "string", + label: "Barcode", + description: "The barcode of the shipment to track. Eg. `3SABCD123456789`", + }, + customerCode: { + type: "string", + label: "Customer Code", + description: "The customer code for reference tracking", + async options() { + return [ + this.$auth.customer_code, + ]; + }, + }, + customerNumber: { + type: "string", + label: "Customer Number", + description: "The customer number for reference tracking", + }, + referenceId: { + type: "string", + label: "Reference ID", + description: "The reference number to track", + }, + detail: { + type: "boolean", + label: "Detail", + description: "Option to include old statuses in the response", + optional: true, + }, + language: { + type: "string", + label: "Language", + description: "Language of the returned shipment and status descriptions (default is Dutch)", + options: [ + "NL", + "EN", + "CN", + "DE", + "FR", + ], + optional: true, + }, + maxDays: { + type: "integer", + label: "Max Days", + description: "Limit the number of days that will be searched (decrease this amount for better performance).", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + const { api_url: baseUrl } = this.$auth; + return `${baseUrl}${path}`; + }, + getHeaders(headers) { + return { + "Content-Type": "application/json", + "apikey": this.$auth.api_key, + ...headers, + }; + }, + makeRequest({ + $ = this, path, headers, ...config + }) { + return axios($, { + url: this.getUrl(path), + headers: this.getHeaders(headers), + ...config, + }); + }, + getStatusByBarcode({ + barcode, ...args + } = {}) { + return this.makeRequest({ + path: `/shipment/v2/status/barcode/${barcode}`, + ...args, + }); + }, + getStatusByReference(args = {}) { + return this.makeRequest({ + path: "/shipment/v2/status/reference", + ...args, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 48fcea4d2c2ca..97e1a572ef9f8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11021,7 +11021,11 @@ importers: components/postmaster: {} - components/postnl: {} + components/postnl: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/power_automate: {}