diff --git a/components/orderspace/actions/create-customer/create-customer.mjs b/components/orderspace/actions/create-customer/create-customer.mjs new file mode 100644 index 0000000000000..b6560d7e21c75 --- /dev/null +++ b/components/orderspace/actions/create-customer/create-customer.mjs @@ -0,0 +1,148 @@ +import orderspace from "../../orderspace.app.mjs"; + +export default { + key: "orderspace-create-customer", + name: "Create Customer", + description: "Create a new customer. [See the documentation](https://apidocs.orderspace.com/#create-a-customer)", + type: "action", + version: "0.0.1", + props: { + orderspace, + companyName: { + type: "string", + label: "Company Name", + description: "The name of the customer's company", + }, + contactName: { + type: "string", + label: "Contact Name", + description: "The contact name for the customer", + }, + email: { + type: "string", + label: "Email", + description: "The email address of the customer", + }, + addressLine1: { + type: "string", + label: "Address Line 1", + description: "The first line of the customer's address", + }, + addressLine2: { + type: "string", + label: "Address Line 2", + description: "The second line of the customer's address", + optional: true, + }, + city: { + type: "string", + label: "City", + description: "The city of the customer's address", + }, + state: { + type: "string", + label: "State", + description: "The state of the customer's address", + }, + postalCode: { + type: "string", + label: "Postal Code", + description: "The postal code of the customer's address", + }, + country: { + type: "string", + label: "Country", + description: "The 2 letter country code of the customer's address", + }, + phone: { + type: "string", + label: "Phone", + description: "The phone number of the customer", + optional: true, + }, + reference: { + type: "string", + label: "Reference", + description: "Your reference for the customer", + optional: true, + }, + internalNote: { + type: "string", + label: "Internal Note", + description: "An internal note for the customer", + optional: true, + }, + taxNumber: { + type: "string", + label: "Sales Tax Number", + description: "The sales tax number of the customer", + optional: true, + }, + minimumSpend: { + type: "string", + label: "Minimum Spend", + description: "The minimum spend per order for the customer", + optional: true, + }, + paymentTermId: { + propDefinition: [ + orderspace, + "paymentTermId", + ], + }, + customerGroupId: { + propDefinition: [ + orderspace, + "customerGroupId", + ], + }, + priceListId: { + propDefinition: [ + orderspace, + "priceListId", + ], + }, + }, + async run({ $ }) { + const { customer } = await this.orderspace.createCustomer({ + data: { + customer: { + company_name: this.companyName, + reference: this.reference, + internal_note: this.internalNote, + buyers: [ + { + name: this.contactName, + email_address: this.email, + }, + ], + phone: this.phone, + email_addresses: { + orders: this.email, + dispatches: this.email, + invoices: this.email, + }, + tax_number: this.taxNumber, + addresses: [ + { + company_name: this.companyName, + contact_name: this.contactName, + line1: this.addressLine1, + line2: this.addressLine2, + city: this.city, + state: this.state, + postal_code: this.postalCode, + country: this.country, + }, + ], + minimum_spend: this.minimumSpend, + payment_terms_id: this.paymentTermId, + customer_group_id: this.customerGroupId, + price_list_id: this.priceListId, + }, + }, + }); + $.export("$summary", `Successfully created customer with ID: ${customer.id}`); + return customer; + }, +}; diff --git a/components/orderspace/actions/create-dispatch/create-dispatch.mjs b/components/orderspace/actions/create-dispatch/create-dispatch.mjs new file mode 100644 index 0000000000000..cde40be05181c --- /dev/null +++ b/components/orderspace/actions/create-dispatch/create-dispatch.mjs @@ -0,0 +1,44 @@ +import orderspace from "../../orderspace.app.mjs"; +import { parseObject } from "../../common/utils.mjs"; + +export default { + key: "orderspace-create-dispatch", + name: "Create Dispatch", + description: "Create a new dispatch. [See the documentation](https://apidocs.orderspace.com/#create-a-dispatch)", + type: "action", + version: "0.0.1", + props: { + orderspace, + orderId: { + propDefinition: [ + orderspace, + "orderId", + ], + }, + comments: { + type: "string", + label: "Comments", + description: "The comments to add to the dispatch", + optional: true, + }, + dispatchLines: { + type: "string[]", + label: "Dispatch Lines", + description: "The lines of the dispatch. Each line should contain values for `sku` and `quantity`. [See the documentation](https://apidocs.orderspace.com/#create-a-dispatch) for information.", + }, + }, + async run({ $ }) { + const { dispatch } = await this.orderspace.createDispatch({ + $, + data: { + dispatch: { + order_id: this.orderId, + comments: this.comments, + dispatch_lines: parseObject(this.dispatchLines), + }, + }, + }); + $.export("$summary", `Successfully created dispatch ${dispatch.id}`); + return dispatch; + }, +}; diff --git a/components/orderspace/actions/create-order/create-order.mjs b/components/orderspace/actions/create-order/create-order.mjs new file mode 100644 index 0000000000000..18e6bce17b518 --- /dev/null +++ b/components/orderspace/actions/create-order/create-order.mjs @@ -0,0 +1,150 @@ +import orderspace from "../../orderspace.app.mjs"; +import { parseObject } from "../../common/utils.mjs"; + +export default { + key: "orderspace-create-order", + name: "Create Order", + description: "Create a new order. [See the documentation](https://apidocs.orderspace.com/#create-an-order)", + type: "action", + version: "0.0.1", + props: { + orderspace, + customerId: { + propDefinition: [ + orderspace, + "customerId", + ], + }, + shippingAddressLine1: { + type: "string", + label: "Address Line 1", + description: "The first line of the shipping address", + }, + shippingAddressLine2: { + type: "string", + label: "Address Line 2", + description: "The second line of the shipping address", + optional: true, + }, + shippingCity: { + type: "string", + label: "City", + description: "The city of the shipping address", + }, + shippingState: { + type: "string", + label: "State", + description: "The state of the shipping address", + }, + shippingPostalCode: { + type: "string", + label: "Postal Code", + description: "The postal code of the shipping address", + }, + shippingCountry: { + type: "string", + label: "Country", + description: "The 2 letter country code of the shipping address", + }, + billingAddressLine1: { + type: "string", + label: "Address Line 1", + description: "The first line of the billing address", + }, + billingAddressLine2: { + type: "string", + label: "Address Line 2", + description: "The second line of the billing address", + optional: true, + }, + billingCity: { + type: "string", + label: "City", + description: "The city of the billing address", + }, + billingState: { + type: "string", + label: "State", + description: "The state of the billing address", + }, + billingPostalCode: { + type: "string", + label: "Postal Code", + description: "The postal code of the billing address", + }, + billingCountry: { + type: "string", + label: "Country", + description: "The 2 letter country code of the billing address", + }, + orderLines: { + type: "string[]", + label: "Order Lines", + description: "The lines of the order. [See the documentation](https://apidocs.orderspace.com/#create-an-order) for information about line format.", + }, + deliveryDate: { + type: "string", + label: "Delivery Date", + description: "The date the order is due (YYYY-MM-DD)", + optional: true, + }, + reference: { + type: "string", + label: "Reference", + description: "The reference for the order", + optional: true, + }, + internalNote: { + type: "string", + label: "Internal Note", + description: "An internal note for the order", + optional: true, + }, + customerPoNumber: { + type: "string", + label: "Customer PO Number", + description: "The customer's purchase order number for this order", + optional: true, + }, + customerNote: { + type: "string", + label: "Customer Note", + description: "The customer's note on this order", + optional: true, + }, + }, + async run({ $ }) { + const { order } = await this.orderspace.createOrder({ + $, + data: { + order: { + customer_id: this.customerId, + delivery_date: this.deliveryDate, + reference: this.reference, + internal_note: this.internalNote, + customer_po_number: this.customerPoNumber, + customer_note: this.customerNote, + shipping_address: { + line1: this.shippingAddressLine1, + line2: this.shippingAddressLine2, + city: this.shippingCity, + state: this.shippingState, + postal_code: this.shippingPostalCode, + country: this.shippingCountry, + }, + billing_address: { + line1: this.billingAddressLine1, + line2: this.billingAddressLine2, + city: this.billingCity, + state: this.billingState, + postal_code: this.billingPostalCode, + country: this.billingCountry, + }, + order_lines: parseObject(this.orderLines), + }, + }, + }); + $.export("$summary", `Successfully created order ${order.id}`); + return order; + }, +}; diff --git a/components/orderspace/actions/list-customers/list-customers.mjs b/components/orderspace/actions/list-customers/list-customers.mjs new file mode 100644 index 0000000000000..1572f71e37d35 --- /dev/null +++ b/components/orderspace/actions/list-customers/list-customers.mjs @@ -0,0 +1,92 @@ +import orderspace from "../../orderspace.app.mjs"; + +export default { + key: "orderspace-list-customers", + name: "List Customers", + description: "List a list of customers. [See the documentation](https://apidocs.orderspace.com/#list-customers)", + version: "0.0.1", + type: "action", + props: { + orderspace, + createdSince: { + type: "string", + label: "Created Since", + description: "Return records created since the given date and time in ISO 8601 format, e.g. 2019-10-29T21:00", + optional: true, + }, + companyName: { + type: "string", + label: "Company Name", + description: "Return customers with the specified company name", + optional: true, + }, + buyersEmailAddress: { + type: "string", + label: "Buyer's Email Address", + description: "Return customers with the specified buyers email address", + optional: true, + }, + status: { + type: "string", + label: "Status", + description: "Return customers with the specified status", + options: [ + "new", + "active", + "closed", + ], + optional: true, + }, + reference: { + type: "string", + label: "Reference", + description: "Return customers with the specified reference", + optional: true, + }, + paymentTermId: { + propDefinition: [ + orderspace, + "paymentTermId", + ], + description: "Return customers with the specified payment terms", + }, + customerGroupId: { + propDefinition: [ + orderspace, + "customerGroupId", + ], + description: "Return customers in the specified group", + }, + priceListId: { + propDefinition: [ + orderspace, + "priceListId", + ], + description: "Return customers with the specified price list", + }, + maxResults: { + propDefinition: [ + orderspace, + "maxResults", + ], + }, + }, + async run({ $ }) { + const { customers } = await this.orderspace.listCustomers({ + $, + params: { + created_since: this.createdSince, + company_name: this.companyName, + buyers_email_address: this.buyersEmailAddress, + status: this.status, + reference: this.reference, + payment_terms_id: this.paymentTermId, + customer_group_id: this.customerGroupId, + price_list_id: this.priceListId, + limit: this.maxResults, + }, + }); + $.export("$summary", `Successfully listed ${customers.length} customers`); + return customers; + }, +}; diff --git a/components/orderspace/actions/list-orders/list-orders.mjs b/components/orderspace/actions/list-orders/list-orders.mjs new file mode 100644 index 0000000000000..9da7b119b9ff5 --- /dev/null +++ b/components/orderspace/actions/list-orders/list-orders.mjs @@ -0,0 +1,96 @@ +import orderspace from "../../orderspace.app.mjs"; + +export default { + key: "orderspace-list-orders", + name: "List Orders", + description: "List a list of orders. [See the documentation](https://apidocs.orderspace.com/#list-orders)", + version: "0.0.1", + type: "action", + props: { + orderspace, + createdSince: { + type: "string", + label: "Created Since", + description: "Return records created since the given date and time in ISO 8601 format, e.g. 2019-10-29T21:00", + optional: true, + }, + createdBefore: { + type: "string", + label: "Created Before", + description: "Return records created before the given date and time in ISO 8601 format, e.g. 2019-10-29T21:00", + optional: true, + }, + deliveryDateSince: { + type: "string", + label: "Delivery Date Since", + description: "Return records with a delivery date since the given date and time in ISO 8601 format, e.g. 2019-10-29T21:00", + optional: true, + }, + deliveryDateBefore: { + type: "string", + label: "Delivery Date Before", + description: "Return records with a delivery date before the given date and time in ISO 8601 format, e.g. 2019-10-29T21:00", + optional: true, + }, + number: { + type: "string", + label: "Number", + description: "Return records with the specified number", + optional: true, + }, + status: { + type: "string", + label: "Status", + description: "Return records with the specified status", + options: [ + "new", + "invoiced", + "released", + "part_fulfilled", + "preorder", + "fulfilled", + "standing_order", + "cancelled", + ], + optional: true, + }, + reference: { + type: "string", + label: "Reference", + description: "Return records with the specified reference", + optional: true, + }, + customerId: { + propDefinition: [ + orderspace, + "customerId", + ], + description: "Return records with the specified customer", + optional: true, + }, + maxResults: { + propDefinition: [ + orderspace, + "maxResults", + ], + }, + }, + async run({ $ }) { + const { orders } = await this.orderspace.listOrders({ + $, + params: { + created_since: this.createdSince, + created_before: this.createdBefore, + delivery_date_since: this.deliveryDateSince, + delivery_date_before: this.deliveryDateBefore, + number: this.number, + status: this.status, + reference: this.reference, + customer_id: this.customerId, + limit: this.maxResults, + }, + }); + $.export("$summary", `Successfully listed ${orders.length} orders`); + return orders; + }, +}; diff --git a/components/orderspace/actions/list-products/list-products.mjs b/components/orderspace/actions/list-products/list-products.mjs new file mode 100644 index 0000000000000..8cad9777df41c --- /dev/null +++ b/components/orderspace/actions/list-products/list-products.mjs @@ -0,0 +1,71 @@ +import orderspace from "../../orderspace.app.mjs"; + +export default { + key: "orderspace-list-products", + name: "List Products", + description: "List a list of products. [See the documentation](https://apidocs.orderspace.com/#list-products)", + version: "0.0.1", + type: "action", + props: { + orderspace, + createdSince: { + type: "string", + label: "Created Since", + description: "Return records created since the given date and time in ISO 8601 format, e.g. 2019-10-29T21:00", + optional: true, + }, + updatedSince: { + type: "string", + label: "Updated Since", + description: "Return records updated since the given date and time in ISO 8601 format, e.g. 2019-10-29T21:00", + optional: true, + }, + code: { + type: "string", + label: "Code", + description: "Return products with the specified code", + optional: true, + }, + name: { + type: "string", + label: "Name", + description: "Return products with the specified name", + optional: true, + }, + active: { + type: "boolean", + label: "Active", + description: "Return products with the specified active status", + optional: true, + }, + categoryId: { + propDefinition: [ + orderspace, + "categoryId", + ], + description: "Return products in the specified category", + }, + maxResults: { + propDefinition: [ + orderspace, + "maxResults", + ], + }, + }, + async run({ $ }) { + const { products } = await this.orderspace.listProducts({ + $, + params: { + created_since: this.createdSince, + updated_since: this.updatedSince, + code: this.code, + name: this.name, + active: this.active, + category_id: this.categoryId, + limit: this.maxResults, + }, + }); + $.export("$summary", `Successfully listed ${products.length} products`); + return products; + }, +}; diff --git a/components/orderspace/actions/update-inventory-level/update-inventory-level.mjs b/components/orderspace/actions/update-inventory-level/update-inventory-level.mjs new file mode 100644 index 0000000000000..a27c5c669992a --- /dev/null +++ b/components/orderspace/actions/update-inventory-level/update-inventory-level.mjs @@ -0,0 +1,56 @@ +import orderspace from "../../orderspace.app.mjs"; + +export default { + key: "orderspace-update-inventory-level", + name: "Update Inventory Level", + description: "Update an inventory level. [See the documentation](https://apidocs.orderspace.com/#update-inventory-levels)", + type: "action", + version: "0.0.1", + props: { + orderspace, + productId: { + propDefinition: [ + orderspace, + "productId", + ], + }, + productSku: { + propDefinition: [ + orderspace, + "productSku", + (c) => ({ + productId: c.productId, + }), + ], + }, + type: { + type: "string", + label: "Type", + description: "The type of inventory level to update", + options: [ + "on_hand", + "available", + ], + }, + quantity: { + type: "integer", + label: "Quantity", + description: "The quantity of the product to update the inventory level to", + }, + }, + async run({ $ }) { + const response = await this.orderspace.updateInventoryLevel({ + $, + data: { + inventory_levels: [ + { + sku: this.productSku, + [this.type]: this.quantity, + }, + ], + }, + }); + $.export("$summary", `Successfully updated inventory level for ${this.productSku}`); + return response; + }, +}; diff --git a/components/orderspace/common/utils.mjs b/components/orderspace/common/utils.mjs new file mode 100644 index 0000000000000..c2b75bdc360c0 --- /dev/null +++ b/components/orderspace/common/utils.mjs @@ -0,0 +1,25 @@ +export const parseObject = (obj) => { + if (!obj) { + return {}; + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch { + return obj; + } + } + if (Array.isArray(obj)) { + return obj.map(parseObject); + } + if (typeof obj === "object") { + return Object.fromEntries(Object.entries(obj).map(([ + key, + value, + ]) => [ + key, + parseObject(value), + ])); + } + return obj; +}; diff --git a/components/orderspace/orderspace.app.mjs b/components/orderspace/orderspace.app.mjs index 2015e23db53c9..5b41ba2b86e2a 100644 --- a/components/orderspace/orderspace.app.mjs +++ b/components/orderspace/orderspace.app.mjs @@ -1,11 +1,264 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "orderspace", - propDefinitions: {}, + propDefinitions: { + paymentTermId: { + type: "string", + label: "Payment Term ID", + description: "The ID of a payment term", + optional: true, + async options() { + const { payment_terms = [] } = await this.listPaymentTerms(); + return payment_terms.map((term) => ({ + label: term.name, + value: term.id, + })); + }, + }, + customerGroupId: { + type: "string", + label: "Customer Group ID", + description: "The ID of a customer group", + optional: true, + async options() { + const { customer_groups = [] } = await this.listCustomerGroups(); + return customer_groups.map((group) => ({ + label: group.name, + value: group.id, + })); + }, + }, + priceListId: { + type: "string", + label: "Price List ID", + description: "The ID of a price list", + optional: true, + async options() { + const { price_lists = [] } = await this.listPriceLists(); + return price_lists.map((list) => ({ + label: list.name, + value: list.id, + })); + }, + }, + orderId: { + type: "string", + label: "Order ID", + description: "The ID of an order", + async options({ prevContext }) { + const { orders = [] } = await this.listOrders({ + params: { + starting_after: prevContext?.after, + }, + }); + return { + options: orders.map((order) => order.id), + context: { + after: orders.length + ? orders[orders.length - 1].id + : undefined, + }, + }; + }, + }, + customerId: { + type: "string", + label: "Customer ID", + description: "The ID of a customer", + async options({ prevContext }) { + const { customers = [] } = await this.listCustomers({ + params: { + starting_after: prevContext?.after, + }, + }); + return { + options: customers.map((customer) => ({ + label: customer.company_name, + value: customer.id, + })), + context: { + after: customers.length + ? customers[customers.length - 1].id + : undefined, + }, + }; + }, + }, + productId: { + type: "string", + label: "Product ID", + description: "The ID of a product", + async options({ prevContext }) { + const { products = [] } = await this.listProducts({ + params: { + starting_after: prevContext?.after, + }, + }); + return { + options: products.map((product) => ({ + label: product.name, + value: product.id, + })), + context: { + after: products.length + ? products[products.length - 1].id + : undefined, + }, + }; + }, + }, + productSku: { + type: "string", + label: "Product SKU", + description: "The SKU of a product", + async options({ productId }) { + const { product: { product_variants = [] } } = await this.getProduct({ + productId, + }); + return product_variants.map((variant) => variant.sku); + }, + }, + categoryId: { + type: "string", + label: "Category ID", + description: "The ID of a category", + optional: true, + async options({ prevContext }) { + const { categories = [] } = await this.listCategories({ + params: { + starting_after: prevContext?.after, + }, + }); + return { + options: categories.map((category) => ({ + label: category.name, + value: category.id, + })), + context: { + after: categories.length + ? categories[categories.length - 1].id + : undefined, + }, + }; + }, + }, + maxResults: { + type: "integer", + label: "Max Results", + description: "The maximum number of results to return. The default is `50` and the maximum limit is `200`", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.orderspace.com/v1"; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }, + ...opts, + }); + }, + createWebhook(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/webhooks", + ...opts, + }); + }, + deleteWebhook({ + hookId, ...opts + }) { + return this._makeRequest({ + method: "DELETE", + path: `/webhooks/${hookId}`, + ...opts, + }); + }, + getProduct({ + productId, ...opts + }) { + return this._makeRequest({ + path: `/products/${productId}`, + ...opts, + }); + }, + listPaymentTerms(opts = {}) { + return this._makeRequest({ + path: "/payment_terms", + ...opts, + }); + }, + listCustomers(opts = {}) { + return this._makeRequest({ + path: "/customers", + ...opts, + }); + }, + listCustomerGroups(opts = {}) { + return this._makeRequest({ + path: "/customer_groups", + ...opts, + }); + }, + listPriceLists(opts = {}) { + return this._makeRequest({ + path: "/price_lists", + ...opts, + }); + }, + listOrders(opts = {}) { + return this._makeRequest({ + path: "/orders", + ...opts, + }); + }, + listProducts(opts = {}) { + return this._makeRequest({ + path: "/products", + ...opts, + }); + }, + listCategories(opts = {}) { + return this._makeRequest({ + path: "/categories", + ...opts, + }); + }, + createCustomer(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/customers", + ...opts, + }); + }, + createOrder(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/orders", + ...opts, + }); + }, + createDispatch(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/dispatches", + ...opts, + }); + }, + updateInventoryLevel(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/inventory_levels", + ...opts, + }); }, }, }; diff --git a/components/orderspace/package.json b/components/orderspace/package.json index 46ffcf1a678f5..03c6920670a28 100644 --- a/components/orderspace/package.json +++ b/components/orderspace/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/orderspace", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Orderspace Components", "main": "orderspace.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/orderspace/sources/common/base.mjs b/components/orderspace/sources/common/base.mjs new file mode 100644 index 0000000000000..7c5987e86dc6b --- /dev/null +++ b/components/orderspace/sources/common/base.mjs @@ -0,0 +1,51 @@ +import orderspace from "../../orderspace.app.mjs"; +import { ConfigurationError } from "@pipedream/platform"; + +export default { + props: { + orderspace, + db: "$.service.db", + http: "$.interface.http", + }, + hooks: { + async activate() { + const { webhook } = await this.orderspace.createWebhook({ + data: { + webhook: { + endpoint: this.http.endpoint, + events: this.getEvents(), + }, + }, + }); + this._setHookId(webhook.id); + }, + async deactivate() { + const hookId = this._getHookId(); + if (hookId) { + await this.orderspace.deleteWebhook({ + webhookId: hookId, + }); + } + }, + }, + methods: { + _getHookId() { + return this.db.get("hookId"); + }, + _setHookId(hookId) { + this.db.set("hookId", hookId); + }, + generateMeta() { + throw new ConfigurationError("generateMeta is not implemented"); + }, + }, + async run(event) { + const { body } = event; + if (!body || !body?.length) { + return; + } + const { data } = body[0]; + const meta = this.generateMeta(data); + this.$emit(data, meta); + }, +}; diff --git a/components/orderspace/sources/customer-updated/customer-updated.mjs b/components/orderspace/sources/customer-updated/customer-updated.mjs new file mode 100644 index 0000000000000..0654bc37c1fb8 --- /dev/null +++ b/components/orderspace/sources/customer-updated/customer-updated.mjs @@ -0,0 +1,29 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "orderspace-customer-updated", + name: "Customer Updated (Instant)", + description: "Emit new event when a customer is updated", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvents() { + return [ + "customer.updated", + ]; + }, + generateMeta(data) { + const ts = Date.now(); + return { + id: `${data.customer.id}-${ts}`, + summary: `Customer ${data.customer.id} updated`, + ts, + }; + }, + }, + sampleEmit, +}; diff --git a/components/orderspace/sources/customer-updated/test-event.mjs b/components/orderspace/sources/customer-updated/test-event.mjs new file mode 100644 index 0000000000000..bd2fcda58d734 --- /dev/null +++ b/components/orderspace/sources/customer-updated/test-event.mjs @@ -0,0 +1,40 @@ +export default { + "customer": { + "id": "cu_r1o0k8y1", + "company_name": "Acme", + "created": "2025-07-02T21:26:26Z", + "status": "active", + "reference": "1222345", + "internal_note": "", + "buyers": [ + { + "name": "", + "email_address": "" + } + ], + "phone": "", + "email_addresses": { + "orders": "", + "dispatches": "", + "invoices": "" + }, + "tax_number": "", + "tax_rate_id": "", + "addresses": [ + { + "company_name": "", + "contact_name": "", + "line1": "", + "line2": "", + "city": "", + "state": "", + "postal_code": "", + "country": "" + } + ], + "minimum_spend": null, + "payment_terms_id": null, + "customer_group_id": null, + "price_list_id": null + } +} \ No newline at end of file diff --git a/components/orderspace/sources/inventory-level-updated/inventory-level-updated.mjs b/components/orderspace/sources/inventory-level-updated/inventory-level-updated.mjs new file mode 100644 index 0000000000000..89a8794b5a62e --- /dev/null +++ b/components/orderspace/sources/inventory-level-updated/inventory-level-updated.mjs @@ -0,0 +1,29 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "orderspace-inventory-level-updated", + name: "Inventory Level Updated (Instant)", + description: "Emit new event when an inventory level is updated", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvents() { + return [ + "inventory_level.updated", + ]; + }, + generateMeta(data) { + const ts = Date.now(); + return { + id: `${data.inventory_level.sku}-${ts}`, + summary: `Inventory level ${data.inventory_level.sku} updated`, + ts, + }; + }, + }, + sampleEmit, +}; diff --git a/components/orderspace/sources/inventory-level-updated/test-event.mjs b/components/orderspace/sources/inventory-level-updated/test-event.mjs new file mode 100644 index 0000000000000..a5d4249edec06 --- /dev/null +++ b/components/orderspace/sources/inventory-level-updated/test-event.mjs @@ -0,0 +1,9 @@ +export default { + "inventory_level": { + "sku": "123", + "on_hand": 125, + "on_hand_adjustment": 25, + "available": 124, + "available_adjustment": 25 + } +} \ No newline at end of file diff --git a/components/orderspace/sources/new-customer-created/new-customer-created.mjs b/components/orderspace/sources/new-customer-created/new-customer-created.mjs new file mode 100644 index 0000000000000..54622cc760f13 --- /dev/null +++ b/components/orderspace/sources/new-customer-created/new-customer-created.mjs @@ -0,0 +1,28 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "orderspace-new-customer-created", + name: "New Customer Created (Instant)", + description: "Emit new event when a customer is created", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvents() { + return [ + "customer.created", + ]; + }, + generateMeta(data) { + return { + id: data.customer.id, + summary: `Customer ${data.customer.id} created`, + ts: Date.parse(data.customer.created_at), + }; + }, + }, + sampleEmit, +}; diff --git a/components/orderspace/sources/new-customer-created/test-event.mjs b/components/orderspace/sources/new-customer-created/test-event.mjs new file mode 100644 index 0000000000000..70463e5d01dea --- /dev/null +++ b/components/orderspace/sources/new-customer-created/test-event.mjs @@ -0,0 +1,40 @@ +export default { + "customer": { + "id": "cu_81kg9dd3", + "company_name": "New Customer", + "created": "2025-07-03T20:51:50Z", + "status": "active", + "reference": "", + "internal_note": "", + "buyers": [ + { + "name": "New Customer", + "email_address": "customer@example.com" + } + ], + "phone": "", + "email_addresses": { + "orders": "customer@example.com", + "dispatches": "customer@example.com", + "invoices": "customer@example.com" + }, + "tax_number": "", + "tax_rate_id": "", + "addresses": [ + { + "company_name": "New Customer", + "contact_name": "New Customer", + "line1": "123 Main St.", + "line2": "", + "city": "Springfield", + "state": "IL", + "postal_code": "12345", + "country": "US" + } + ], + "minimum_spend": null, + "payment_terms_id": null, + "customer_group_id": null, + "price_list_id": null + } +} \ No newline at end of file diff --git a/components/orderspace/sources/new-dispatch-created/new-dispatch-created.mjs b/components/orderspace/sources/new-dispatch-created/new-dispatch-created.mjs new file mode 100644 index 0000000000000..72546fdf3add8 --- /dev/null +++ b/components/orderspace/sources/new-dispatch-created/new-dispatch-created.mjs @@ -0,0 +1,28 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "orderspace-new-dispatch-created", + name: "New Dispatch Created (Instant)", + description: "Emit new event when a dispatch is created", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvents() { + return [ + "dispatch.created", + ]; + }, + generateMeta(data) { + return { + id: data.dispatch.id, + summary: `Dispatch ${data.dispatch.id} created`, + ts: Date.parse(data.dispatch.created), + }; + }, + }, + sampleEmit, +}; diff --git a/components/orderspace/sources/new-dispatch-created/test-event.mjs b/components/orderspace/sources/new-dispatch-created/test-event.mjs new file mode 100644 index 0000000000000..e47d385840065 --- /dev/null +++ b/components/orderspace/sources/new-dispatch-created/test-event.mjs @@ -0,0 +1,33 @@ +export default { + "dispatch": { + "id": "di_ml6r1nwm", + "order_id": "or_lqq1vzql", + "order_number": 1, + "created": "2025-07-03T20:56:39Z", + "comments": "comments", + "customer_note": "", + "customer_po_number": "", + "shipping_type": "", + "shipping_address": { + "company_name": "Acme Acres", + "contact_name": "", + "line1": "1234 Main St.", + "line2": "", + "city": "Cityville", + "state": "MI", + "postal_code": "49349", + "country": "US" + }, + "email_address": "", + "phone": "+15555555555", + "dispatch_lines": [ + { + "order_line_id": "ol_m3zkozxn", + "sku": "123", + "name": "t-shirt", + "options": "", + "quantity": 1 + } + ] + } +} \ No newline at end of file diff --git a/components/orderspace/sources/new-invoice-created/new-invoice-created.mjs b/components/orderspace/sources/new-invoice-created/new-invoice-created.mjs new file mode 100644 index 0000000000000..0c0e803edbed3 --- /dev/null +++ b/components/orderspace/sources/new-invoice-created/new-invoice-created.mjs @@ -0,0 +1,28 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "orderspace-new-invoice-created", + name: "New Invoice Created (Instant)", + description: "Emit new event when an invoice is created", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvents() { + return [ + "invoice.created", + ]; + }, + generateMeta(data) { + return { + id: data.invoice.id, + summary: `Invoice ${data.invoice.id} created`, + ts: Date.now(), + }; + }, + }, + sampleEmit, +}; diff --git a/components/orderspace/sources/new-invoice-created/test-event.mjs b/components/orderspace/sources/new-invoice-created/test-event.mjs new file mode 100644 index 0000000000000..6444c48530bf4 --- /dev/null +++ b/components/orderspace/sources/new-invoice-created/test-event.mjs @@ -0,0 +1,59 @@ +export default { + "invoice": { + "id": "iv_7xg471xv", + "number": "INV-1288", + "invoice_date": "2021-04-24", + "customer_id": "cu_pg34zo1x", + "company_name": "BP Twelve", + "email_address": "bp12@alliumstudios.com", + "orders": [ + { + "id": "or_e875r5l5", + "number": 1288, + }, + ], + "payment_terms": "15 Days", + "due_date": "2021-05-09", + "paid": true, + "proforma": false, + "deposit": { + "percentage": 25.0, + "due_date": "2021-04-24", + }, + "comments": "", + "address": { + "company_name": "BP Twelve", + "contact_name": "", + "line1": "addr1", + "line2": "", + "city": "", + "state": "", + "postal_code": "NN14", + "country": "GB", + }, + "invoice_lines": [ + { + "sku": "ZAG-D-16", + "name": "Angelica Dress", + "options": "Size: 16", + "quantity": 1, + "unit_price": 22.25, + "sub_total": 22.25, + "tax_rate": 20.0, + "tax_amount": 4.45, + }, + ], + "currency": "GBP", + "net_total": 22.25, + "gross_total": 26.7, + "payments": [ + { + "amount": 26.7, + "payment_date": "2021-04-24", + "source": "card", + "description": "Visa ending 3220", + "reference": "pi_1IjW8KJzxI5C4d4qXkHyOFKZ", + }, + ], + }, +}; diff --git a/components/orderspace/sources/new-order-created/new-order-created.mjs b/components/orderspace/sources/new-order-created/new-order-created.mjs new file mode 100644 index 0000000000000..634b2eed74cf3 --- /dev/null +++ b/components/orderspace/sources/new-order-created/new-order-created.mjs @@ -0,0 +1,28 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "orderspace-new-order-created", + name: "New Order Created (Instant)", + description: "Emit new event when an order is created", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvents() { + return [ + "order.created", + ]; + }, + generateMeta(data) { + return { + id: data.order.id, + summary: `Order ${data.order.id} created`, + ts: Date.parse(data.order.created), + }; + }, + }, + sampleEmit, +}; diff --git a/components/orderspace/sources/new-order-created/test-event.mjs b/components/orderspace/sources/new-order-created/test-event.mjs new file mode 100644 index 0000000000000..802c239c3f312 --- /dev/null +++ b/components/orderspace/sources/new-order-created/test-event.mjs @@ -0,0 +1,67 @@ +export default { + "order": { + "id": "or_lg2gyw64", + "number": 3, + "created": "2025-07-03T20:55:14Z", + "status": "new", + "customer_id": "cu_03dd9ew3", + "company_name": "Acme Acres", + "phone": "+15555555555", + "email_addresses": { + "orders": "", + "dispatches": "", + "invoices": "" + }, + "created_by": null, + "delivery_date": "2025-07-04", + "reference": "123", + "internal_note": "internal note", + "customer_po_number": "123", + "customer_note": "customer note", + "shipping_type": "", + "shipping_address": { + "company_name": "Acme Acres", + "contact_name": "", + "line1": "1234 Main St.", + "line2": "", + "city": "Cityville", + "state": "MI", + "postal_code": "49349", + "country": "US" + }, + "billing_address": { + "company_name": "Acme Acres", + "contact_name": "", + "line1": "456 Main St.", + "line2": "", + "city": "Cityville", + "postal_code": "49349", + "state": "MI", + "country": "US" + }, + "order_lines": [ + { + "id": "ol_rlj9zyly", + "sku": "123", + "name": "t-shirt", + "options": "", + "shipping": false, + "quantity": 1, + "unit_price": 15, + "sub_total": 15, + "tax_rate_id": null, + "tax_name": "", + "tax_rate": 0, + "tax_amount": 0, + "preorder_window_id": null, + "on_hold": false, + "invoiced": 0, + "paid": 0, + "dispatched": 0 + } + ], + "currency": "USD", + "net_total": 15, + "gross_total": 15 + } +} \ No newline at end of file diff --git a/components/orderspace/sources/new-payment-created/new-payment-created.mjs b/components/orderspace/sources/new-payment-created/new-payment-created.mjs new file mode 100644 index 0000000000000..bee829c4a74f3 --- /dev/null +++ b/components/orderspace/sources/new-payment-created/new-payment-created.mjs @@ -0,0 +1,29 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "orderspace-new-payment-created", + name: "New Payment Created (Instant)", + description: "Emit new event when a payment is created", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvents() { + return [ + "payment.created", + ]; + }, + generateMeta(data) { + const ts = Date.now(); + return { + id: `${data.payment.reference}-${ts}`, + summary: `Payment reference ${data.payment.reference} created`, + ts, + }; + }, + }, + sampleEmit, +}; diff --git a/components/orderspace/sources/new-payment-created/test-event.mjs b/components/orderspace/sources/new-payment-created/test-event.mjs new file mode 100644 index 0000000000000..eb3e914f00ff1 --- /dev/null +++ b/components/orderspace/sources/new-payment-created/test-event.mjs @@ -0,0 +1,11 @@ +export default { + "payment": { + "invoice_id": "iv_7xg471xv", + "invoice_number": "INV-1288", + "amount": 26.7, + "payment_date": "2021-04-24", + "source": "card", + "description": "Visa ending 3220", + "reference": "pi_1IjW8KJzxI5C4d4qXkHyOFKZ" + } +} \ No newline at end of file diff --git a/components/orderspace/sources/new-product-created/new-product-created.mjs b/components/orderspace/sources/new-product-created/new-product-created.mjs new file mode 100644 index 0000000000000..6da9841571d85 --- /dev/null +++ b/components/orderspace/sources/new-product-created/new-product-created.mjs @@ -0,0 +1,28 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "orderspace-new-product-created", + name: "New Product Created (Instant)", + description: "Emit new event when a product is created", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getEvents() { + return [ + "product.created", + ]; + }, + generateMeta(data) { + return { + id: data.product.id, + summary: `Product ${data.product.id} created`, + ts: Date.now(), + }; + }, + }, + sampleEmit, +}; diff --git a/components/orderspace/sources/new-product-created/test-event.mjs b/components/orderspace/sources/new-product-created/test-event.mjs new file mode 100644 index 0000000000000..4545210aef04d --- /dev/null +++ b/components/orderspace/sources/new-product-created/test-event.mjs @@ -0,0 +1,67 @@ +export default { + "product":{ + "id": "pr_lj3pwm1n", + "code": "AD01", + "name": "Alexa Dress", + "description": "Summer colours, fully lined", + "active": true, + "tariff_code": "0804.401", + "country_of_origin": "India", + "composition": "100% cotton", + "variant_options": ["Color", "Size"], + "product_variants": [ + { + "id": "pv_v18kxq1e", + "sku": "AD01-10", + "barcode": "123456789", + "options": {"Color": "Red", "Size": "10"}, + "unit_price": 32.0, + "price_list_prices": [ + {"id": "pr_z0j7yjl2", "unit_price": 35.0} + ], + "rrp": 72.0, + "backorder": true, + "minimum": 4, + "multiple": 3, + "weight": 0.0, + }, + { + "id": "pv_xjz5xvjk", + "sku": "AD01-12", + "barcode": "1123456789", + "options": {"Color": "Red", "Size": "12"}, + "unit_price": 32.0, + "price_list_prices": [], + "rrp": 72.0, + "backorder": true, + "minimum": 2, + "multiple": 2, + "weight": 0.0, + }, + { + "id": "pv_q1l2n634", + "sku": "AD01-14", + "barcode": "2123456789", + "options": {"Color": "Red", "Size": "14"}, + "unit_price": 32.0, + "price_list_prices": [], + "rrp": 72.0, + "backorder": true, + "minimum": 4, + "multiple": null, + "weight": 1.0, + } + ], + "categories": [ + { + "id": "ca_x61lk8j7", + "name": "Dresses" + }, + { + "id": "ca_3xwy7mwo", + "name": "Spring / Summer 2022" + } + ], + "grouping_category_id": "ca_x61lk8j7" + } +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0572c97234a8d..39f40ad0ad43f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5971,8 +5971,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/hana: - specifiers: {} + components/hana: {} components/handwrytten: {} @@ -9502,7 +9501,11 @@ importers: components/order_sender: {} - components/orderspace: {} + components/orderspace: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/originality_ai: dependencies: