diff --git a/components/wics/actions/delete-order-line/delete-order-line.mjs b/components/wics/actions/delete-order-line/delete-order-line.mjs new file mode 100644 index 0000000000000..269bf9da0ef0c --- /dev/null +++ b/components/wics/actions/delete-order-line/delete-order-line.mjs @@ -0,0 +1,41 @@ +import wics from "../../wics.app.mjs"; + +export default { + key: "wics-delete-order-line", + name: "Delete Order Line", + description: "Delete a line from an order. [See the documentation](https://docs.wics.nl/test-environment.html#orders-delete-order-line)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: true, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + wics, + orderReference: { + propDefinition: [ + wics, + "orderReference", + ], + }, + lineNumber: { + propDefinition: [ + wics, + "lineNumber", + (c) => ({ + orderReference: c.orderReference, + }), + ], + }, + }, + async run({ $ }) { + const { data } = await this.wics.deleteOrderLine({ + $, + orderReference: this.orderReference, + lineNumber: this.lineNumber, + }); + $.export("$summary", `Successfully deleted line ${this.lineNumber} from order ${this.orderReference}`); + return data; + }, +}; diff --git a/components/wics/actions/get-order-by-additional-reference/get-order-by-additional-reference.mjs b/components/wics/actions/get-order-by-additional-reference/get-order-by-additional-reference.mjs new file mode 100644 index 0000000000000..f60d176ddfc9f --- /dev/null +++ b/components/wics/actions/get-order-by-additional-reference/get-order-by-additional-reference.mjs @@ -0,0 +1,37 @@ +import wics from "../../wics.app.mjs"; + +export default { + key: "wics-get-order-by-additional-reference", + name: "Get Order by Additional Reference", + description: "Get an order by its additional reference. [See the documentation](https://docs.wics.nl/test-environment.html#orders-list-orders)", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + type: "action", + props: { + wics, + additionalReference: { + propDefinition: [ + wics, + "additionalReference", + ], + }, + }, + async run({ $ }) { + const { data } = await this.wics.listOrders({ + $, + params: { + additionalReference: this.additionalReference, + }, + }); + if (!data?.length) { + $.export("$summary", "No order found"); + return; + } + $.export("$summary", `Successfully retrieved order with additional reference: ${this.additionalReference}`); + return data[0]; + }, +}; diff --git a/components/wics/actions/update-order/update-order.mjs b/components/wics/actions/update-order/update-order.mjs new file mode 100644 index 0000000000000..cab9f3f4671ea --- /dev/null +++ b/components/wics/actions/update-order/update-order.mjs @@ -0,0 +1,240 @@ +import wics from "../../wics.app.mjs"; +import { parseObject } from "../../common/utils.mjs"; + +export default { + key: "wics-update-order", + name: "Update Order", + description: "Update an order. [See the documentation](https://docs.wics.nl/test-environment.html#orders-update-order)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: true, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + wics, + orderReference: { + propDefinition: [ + wics, + "orderReference", + ], + }, + deliveryDate: { + type: "string", + label: "Delivery Date", + description: "The date that the order should be delivered. Format: YYYY-MM-DD", + optional: true, + }, + webshopId: { + type: "integer", + label: "Webshop ID", + description: "The identifier that corresponds to the webshop account of Transmart or Paazl", + optional: true, + }, + warehouseCode: { + type: "string", + label: "Warehouse Code", + description: "The warehouse used for this order", + optional: true, + }, + note: { + type: "string", + label: "Note", + description: "A note that will shown alongside the order", + optional: true, + }, + tag: { + type: "string", + label: "Tag", + description: "A shippingTag or tag that is linked with a shipment option in WICS.", + optional: true, + }, + pickupPoint: { + type: "string", + label: "Pickup Point", + description: "A place for picking up the order", + optional: true, + }, + termsOfDelivery: { + type: "string", + label: "Terms of Delivery", + description: "The delivery condition", + optional: true, + }, + type: { + type: "string", + label: "Type", + description: "The order type of the order", + optional: true, + }, + invoiceAddressName: { + type: "string", + label: "Invoice Address Name", + description: "The name of the invoice address", + optional: true, + }, + invoiceAddressStreetNumber: { + type: "string", + label: "Invoice Address Street Number", + description: "The street number of the invoice address", + optional: true, + }, + invoiceAddressStreet: { + type: "string", + label: "Invoice Address Street Name", + description: "The street name of the invoice address", + optional: true, + }, + invoiceAddressCity: { + type: "string", + label: "Invoice Address City", + description: "The city of the invoice address", + optional: true, + }, + invoiceAddressState: { + type: "string", + label: "Invoice Address State", + description: "The state of the invoice address", + optional: true, + }, + invoiceAddressZipcode: { + type: "string", + label: "Invoice Address Zipcode", + description: "The zipcode of the invoice address", + optional: true, + }, + invoiceAddressCountry: { + type: "string", + label: "Invoice Address Country", + description: "The country of the invoice address", + optional: true, + }, + invoiceEmail: { + type: "string", + label: "Invoice Email", + description: "The email of the invoice address", + optional: true, + }, + deliveryAddressName: { + type: "string", + label: "Delivery Address Name", + description: "The name of the delivery address", + optional: true, + }, + deliveryAddressStreetNumber: { + type: "string", + label: "Delivery Address Street Number", + description: "The street number of the delivery address", + optional: true, + }, + deliveryAddressStreet: { + type: "string", + label: "Delivery Address Street Name", + description: "The street name of the delivery address", + optional: true, + }, + deliveryAddressCity: { + type: "string", + label: "Delivery Address City", + description: "The city of the delivery address", + optional: true, + }, + deliveryAddressState: { + type: "string", + label: "Delivery Address State", + description: "The state of the delivery address", + optional: true, + }, + deliveryAddressZipcode: { + type: "string", + label: "Delivery Address Zipcode", + description: "The zipcode of the delivery address", + optional: true, + }, + deliveryAddressCountry: { + type: "string", + label: "Delivery Address Country", + description: "The country of the delivery address", + optional: true, + }, + deliveryEmail: { + type: "string", + label: "Delivery Email", + description: "The email of the delivery address", + optional: true, + }, + lines: { + type: "string[]", + label: "Lines", + description: "The lines of the order as an array of objects including the key `lineNumber`. Example: `[{ \"lineNumber\": 20002, \"itemCode\": \"16084\", \"itemDescription\": \"Speaker kabel\", \"quantity\": 5 }]` [See the documentation](https://docs.wics.nl/test-environment.html#orders-update-order) for additional information", + optional: true, + }, + }, + async run({ $ }) { + const { data: order } = await this.wics.getOrder({ + $, + orderReference: this.orderReference, + }); + + // add in updated lines + const lines = []; + const newLines = parseObject(this.lines); + for (const line of order.lines) { + const newLine = newLines.find((l) => l.lineNumber === line.lineNumber); + if (newLine) { + lines.push(newLine); + } else { + lines.push(line); + } + } + + // add in new lines + for (const line of newLines) { + if (!lines.find((l) => l.lineNumber === line.lineNumber)) { + lines.push(line); + } + } + + const { data } = await this.wics.updateOrder({ + $, + orderReference: this.orderReference, + data: { + ...order, + deliveryDate: this.deliveryDate, + webshopId: this.webshopId, + warehouseCode: this.warehouseCode, + note: this.note, + tag: this.tag, + pickupPoint: this.pickupPoint, + termsOfDelivery: this.termsOfDelivery, + type: this.type, + invoiceAddress: { + ...order.invoiceAddress, + name: this.invoiceAddressName, + streetNumber: this.invoiceAddressStreetNumber, + street: this.invoiceAddressStreet, + city: this.invoiceAddressCity, + state: this.invoiceAddressState, + zipcode: this.invoiceAddressZipcode, + country: this.invoiceAddressCountry, + email: this.invoiceEmail, + }, + deliveryAddress: { + ...order.deliveryAddress, + name: this.deliveryAddressName, + streetNumber: this.deliveryAddressStreetNumber, + street: this.deliveryAddressStreet, + city: this.deliveryAddressCity, + state: this.deliveryAddressState, + zipcode: this.deliveryAddressZipcode, + country: this.deliveryAddressCountry, + email: this.deliveryEmail, + }, + lines, + }, + }); + $.export("$summary", `Successfully updated order ${this.orderReference}`); + return data; + }, +}; diff --git a/components/wics/common/utils.mjs b/components/wics/common/utils.mjs new file mode 100644 index 0000000000000..b5d4492b07055 --- /dev/null +++ b/components/wics/common/utils.mjs @@ -0,0 +1,32 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + return parseObject(item); + } + return item; + }); + } + + if (typeof obj === "object") { + return Object.fromEntries(Object.entries(obj).map(([ + key, + value, + ]) => [ + key, + parseObject(value), + ])); + } + + return obj; +}; diff --git a/components/wics/package.json b/components/wics/package.json index 00d64b05d56fe..863577aca30c4 100644 --- a/components/wics/package.json +++ b/components/wics/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/wics", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream WICS Components", "main": "wics.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.1" } -} \ No newline at end of file +} diff --git a/components/wics/wics.app.mjs b/components/wics/wics.app.mjs index 5b5b15cd03c3a..d48edd1ab9caa 100644 --- a/components/wics/wics.app.mjs +++ b/components/wics/wics.app.mjs @@ -1,11 +1,103 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "wics", - propDefinitions: {}, + propDefinitions: { + orderReference: { + type: "string", + label: "Order Reference", + description: "Reference identifier for the order", + async options({ page }) { + const { data } = await this.listOrders({ + params: { + page: page + 1, + }, + }); + return data?.filter((order) => order.reference)?.map((order) => ({ + label: `Order #${order.number}`, + value: order.reference, + })) || []; + }, + }, + additionalReference: { + type: "string", + label: "Additional Reference", + description: "Additional reference for the order", + async options({ page }) { + const { data } = await this.listOrders({ + params: { + page: page + 1, + }, + }); + return data?.filter((order) => order.additionalReference)?.map((order) => ({ + label: `Order #${order.number}`, + value: order.additionalReference, + })) || []; + }, + }, + lineNumber: { + type: "string", + label: "Line Number", + description: "Line number of an order", + async options({ orderReference }) { + const { data } = await this.getOrder({ + orderReference, + }); + return data?.lines?.map((line) => ({ + label: `Line #${line.lineNumber}`, + value: line.lineNumber, + })) || []; + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `${this.$auth.environment}servicelayer.wics.nl/api`; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + auth: { + username: `${this.$auth.api_key}`, + password: `${this.$auth.api_secret}`, + }, + ...opts, + }); + }, + getOrder({ + orderReference, ...opts + }) { + return this._makeRequest({ + path: `/order/${orderReference}`, + ...opts, + }); + }, + listOrders(opts = {}) { + return this._makeRequest({ + path: "/order", + ...opts, + }); + }, + updateOrder({ + orderReference, ...opts + }) { + return this._makeRequest({ + path: `/order/${orderReference}`, + method: "PUT", + ...opts, + }); + }, + deleteOrderLine({ + orderReference, lineNumber, ...opts + }) { + return this._makeRequest({ + path: `/order/${orderReference}/line/${lineNumber}`, + method: "DELETE", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f4b073c41f50d..61b0242f8b55a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11156,8 +11156,7 @@ importers: components/pingrabbit: {} - components/pinpoint: - specifiers: {} + components/pinpoint: {} components/pinterest: dependencies: @@ -16460,7 +16459,11 @@ importers: components/wicked_reports: {} - components/wics: {} + components/wics: + dependencies: + '@pipedream/platform': + specifier: ^3.1.1 + version: 3.1.1 components/widgetform: dependencies: @@ -31715,17 +31718,17 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net supports-color@10.2.2: resolution: {integrity: sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==}