From 2ff8179b9511959ce434635202105a3642a6ac5c Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Fri, 8 Aug 2025 17:06:13 -0500 Subject: [PATCH] [Components] Mews --- .../cancel-reservation/cancel-reservation.mjs | 35 +++ .../create-reservation/create-reservation.mjs | 161 ++++++++++ .../fetch-customers/fetch-customers.mjs | 37 +++ .../fetch-order-items/fetch-order-items.mjs | 37 +++ .../actions/fetch-products/fetch-products.mjs | 37 +++ .../fetch-reservations/fetch-reservations.mjs | 38 +++ .../update-reservation/update-reservation.mjs | 158 ++++++++++ components/mews/common/utils.mjs | 44 +++ components/mews/mews.app.mjs | 295 +++++++++++++++++- components/mews/package.json | 4 +- components/mews/sources/common/polling.mjs | 129 ++++++++ .../order-item-created/order-item-created.mjs | 32 ++ .../order-item-updated/order-item-updated.mjs | 32 ++ .../product-service-order-created.mjs | 32 ++ .../reservation-cancelled.mjs | 39 +++ .../reservation-created.mjs | 31 ++ .../reservation-updated.mjs | 32 ++ pnpm-lock.yaml | 18 +- 18 files changed, 1173 insertions(+), 18 deletions(-) create mode 100644 components/mews/actions/cancel-reservation/cancel-reservation.mjs create mode 100644 components/mews/actions/create-reservation/create-reservation.mjs create mode 100644 components/mews/actions/fetch-customers/fetch-customers.mjs create mode 100644 components/mews/actions/fetch-order-items/fetch-order-items.mjs create mode 100644 components/mews/actions/fetch-products/fetch-products.mjs create mode 100644 components/mews/actions/fetch-reservations/fetch-reservations.mjs create mode 100644 components/mews/actions/update-reservation/update-reservation.mjs create mode 100644 components/mews/common/utils.mjs create mode 100644 components/mews/sources/common/polling.mjs create mode 100644 components/mews/sources/order-item-created/order-item-created.mjs create mode 100644 components/mews/sources/order-item-updated/order-item-updated.mjs create mode 100644 components/mews/sources/product-service-order-created/product-service-order-created.mjs create mode 100644 components/mews/sources/reservation-cancelled/reservation-cancelled.mjs create mode 100644 components/mews/sources/reservation-created/reservation-created.mjs create mode 100644 components/mews/sources/reservation-updated/reservation-updated.mjs diff --git a/components/mews/actions/cancel-reservation/cancel-reservation.mjs b/components/mews/actions/cancel-reservation/cancel-reservation.mjs new file mode 100644 index 0000000000000..c7f221edafcad --- /dev/null +++ b/components/mews/actions/cancel-reservation/cancel-reservation.mjs @@ -0,0 +1,35 @@ +import app from "../../mews.app.mjs"; + +export default { + name: "Cancel Reservation", + description: "Cancel a reservation in Mews.", + key: "mews-cancel-reservation", + version: "0.0.1", + type: "action", + props: { + app, + reservationId: { + propDefinition: [ + app, + "reservationId", + ], + }, + }, + async run({ $ }) { + const { + app, + reservationId, + } = this; + const response = await app.reservationsCancel({ + $, + data: { + ReservationIds: [ + reservationId, + ], + }, + }); + $.export("summary", "Successfully cancelled reservation"); + return response; + }, +}; + diff --git a/components/mews/actions/create-reservation/create-reservation.mjs b/components/mews/actions/create-reservation/create-reservation.mjs new file mode 100644 index 0000000000000..afde3ed094d5f --- /dev/null +++ b/components/mews/actions/create-reservation/create-reservation.mjs @@ -0,0 +1,161 @@ +import app from "../../mews.app.mjs"; +import utils from "../../common/utils.mjs"; + +export default { + name: "Create Reservation", + description: "Create a reservation in Mews. See reservation parameters in the docs. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/reservations#add-reservations)", + key: "mews-create-reservation", + version: "0.0.1", + type: "action", + props: { + app, + serviceId: { + propDefinition: [ + app, + "serviceId", + ], + }, + customerId: { + propDefinition: [ + app, + "customerId", + ], + }, + startUtc: { + propDefinition: [ + app, + "startUtc", + ], + }, + endUtc: { + propDefinition: [ + app, + "endUtc", + ], + }, + state: { + propDefinition: [ + app, + "state", + ], + optional: true, + }, + resourceId: { + propDefinition: [ + app, + "resourceId", + ], + optional: true, + }, + number: { + propDefinition: [ + app, + "number", + ], + optional: true, + }, + notes: { + propDefinition: [ + app, + "notes", + ], + optional: true, + }, + rateId: { + propDefinition: [ + app, + "rateId", + ], + optional: true, + }, + companyId: { + propDefinition: [ + app, + "companyId", + ], + optional: true, + }, + travelAgencyId: { + propDefinition: [ + app, + "travelAgencyId", + ], + optional: true, + }, + businessSegmentId: { + propDefinition: [ + app, + "businessSegmentId", + ], + optional: true, + }, + additionalFields: { + propDefinition: [ + app, + "additionalFields", + ], + optional: true, + }, + }, + async run({ $ }) { + const { + app, + serviceId, + customerId, + startUtc, + endUtc, + state, + resourceId, + number, + notes, + rateId, + companyId, + travelAgencyId, + businessSegmentId, + additionalFields, + } = this; + + const response = await app.reservationsCreate({ + data: { + Reservations: [ + { + ServiceId: serviceId, + CustomerId: customerId, + StartUtc: startUtc, + EndUtc: endUtc, + ...(state && { + State: state, + }), + ...(resourceId && { + ResourceId: resourceId, + }), + ...(number && { + Number: number, + }), + ...(notes && { + Notes: notes, + }), + ...(rateId && { + RateId: rateId, + }), + ...(companyId && { + CompanyId: companyId, + }), + ...(travelAgencyId && { + TravelAgencyId: travelAgencyId, + }), + ...(businessSegmentId && { + BusinessSegmentId: businessSegmentId, + }), + ...(additionalFields && { + ...utils.parseJson(additionalFields), + }), + }, + ], + }, + $, + }); + $.export("summary", "Successfully created reservation"); + return response; + }, +}; diff --git a/components/mews/actions/fetch-customers/fetch-customers.mjs b/components/mews/actions/fetch-customers/fetch-customers.mjs new file mode 100644 index 0000000000000..26b8eb846b1d0 --- /dev/null +++ b/components/mews/actions/fetch-customers/fetch-customers.mjs @@ -0,0 +1,37 @@ +import app from "../../mews.app.mjs"; +import utils from "../../common/utils.mjs"; + +export default { + name: "Fetch Customers", + description: "Retrieve customers using Mews Connector API. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/customers#get-all-customers)", + key: "mews-fetch-customers", + version: "0.0.1", + type: "action", + props: { + app, + additionalFields: { + propDefinition: [ + app, + "additionalFields", + ], + }, + }, + async run({ $ }) { + const { + app, + additionalFields, + } = this; + + const items = await app.paginate({ + requester: app.customersGetAll, + requesterArgs: { + $, + data: utils.parseJson(additionalFields), + }, + resultKey: "Customers", + }); + $.export("summary", `Successfully fetched ${items.length} customers`); + return items; + }, +}; + diff --git a/components/mews/actions/fetch-order-items/fetch-order-items.mjs b/components/mews/actions/fetch-order-items/fetch-order-items.mjs new file mode 100644 index 0000000000000..f1a9ac7d62831 --- /dev/null +++ b/components/mews/actions/fetch-order-items/fetch-order-items.mjs @@ -0,0 +1,37 @@ +import app from "../../mews.app.mjs"; +import utils from "../../common/utils.mjs"; + +export default { + name: "Fetch Order Items", + description: "Retrieve order items using Mews Connector API. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/orderitems#get-all-order-items)", + key: "mews-fetch-order-items", + version: "0.0.1", + type: "action", + props: { + app, + additionalFields: { + propDefinition: [ + app, + "additionalFields", + ], + }, + }, + async run({ $ }) { + const { + app, + additionalFields, + } = this; + + const items = await app.paginate({ + requester: app.orderItemsGetAll, + requesterArgs: { + $, + data: utils.parseJson(additionalFields), + }, + resultKey: "OrderItems", + }); + $.export("summary", `Successfully fetched ${items.length} order items`); + return items; + }, +}; + diff --git a/components/mews/actions/fetch-products/fetch-products.mjs b/components/mews/actions/fetch-products/fetch-products.mjs new file mode 100644 index 0000000000000..3d238dae18202 --- /dev/null +++ b/components/mews/actions/fetch-products/fetch-products.mjs @@ -0,0 +1,37 @@ +import app from "../../mews.app.mjs"; +import utils from "../../common/utils.mjs"; + +export default { + name: "Fetch Products", + description: "Retrieve products using Mews Connector API. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/products#get-all-products)", + key: "mews-fetch-products", + version: "0.0.1", + type: "action", + props: { + app, + additionalFields: { + propDefinition: [ + app, + "additionalFields", + ], + }, + }, + async run({ $ }) { + const { + app, + additionalFields, + } = this; + + const items = await app.paginate({ + requester: app.productsGetAll, + requesterArgs: { + $, + data: utils.parseJson(additionalFields), + }, + resultKey: "Products", + }); + $.export("summary", `Successfully fetched ${items.length} products`); + return items; + }, +}; + diff --git a/components/mews/actions/fetch-reservations/fetch-reservations.mjs b/components/mews/actions/fetch-reservations/fetch-reservations.mjs new file mode 100644 index 0000000000000..9a411c4b506d9 --- /dev/null +++ b/components/mews/actions/fetch-reservations/fetch-reservations.mjs @@ -0,0 +1,38 @@ +import app from "../../mews.app.mjs"; +import utils from "../../common/utils.mjs"; + +export default { + name: "Fetch Reservations", + description: "Retrieve reservations using Mews Connector API. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/reservations#get-all-reservations-ver-2023-06-06)", + key: "mews-fetch-reservations", + version: "0.0.1", + type: "action", + props: { + app, + additionalFields: { + propDefinition: [ + app, + "additionalFields", + ], + }, + }, + async run({ $ }) { + const { + app, + additionalFields, + } = this; + + const items = await app.paginate({ + requester: app.reservationsGetAll, + requesterArgs: { + $, + data: utils.parseJson(additionalFields), + }, + resultKey: "Reservations", + }); + + $.export("summary", `Successfully fetched ${items.length} reservations`); + return items; + }, +}; + diff --git a/components/mews/actions/update-reservation/update-reservation.mjs b/components/mews/actions/update-reservation/update-reservation.mjs new file mode 100644 index 0000000000000..b3fd020e84f2f --- /dev/null +++ b/components/mews/actions/update-reservation/update-reservation.mjs @@ -0,0 +1,158 @@ +import app from "../../mews.app.mjs"; +import utils from "../../common/utils.mjs"; + +export default { + name: "Update Reservation", + description: "Update an existing reservation in Mews.", + key: "mews-update-reservation", + version: "0.0.1", + type: "action", + props: { + app, + reservationId: { + propDefinition: [ + app, + "reservationId", + ], + }, + startUtc: { + propDefinition: [ + app, + "startUtc", + ], + optional: true, + }, + endUtc: { + propDefinition: [ + app, + "endUtc", + ], + optional: true, + }, + state: { + propDefinition: [ + app, + "state", + ], + optional: true, + }, + resourceId: { + propDefinition: [ + app, + "resourceId", + ], + optional: true, + }, + number: { + propDefinition: [ + app, + "number", + ], + optional: true, + }, + notes: { + propDefinition: [ + app, + "notes", + ], + optional: true, + }, + rateId: { + propDefinition: [ + app, + "rateId", + ], + optional: true, + }, + companyId: { + propDefinition: [ + app, + "companyId", + ], + optional: true, + }, + travelAgencyId: { + propDefinition: [ + app, + "travelAgencyId", + ], + optional: true, + }, + businessSegmentId: { + propDefinition: [ + app, + "businessSegmentId", + ], + optional: true, + }, + additionalFields: { + propDefinition: [ + app, + "additionalFields", + ], + optional: true, + }, + }, + async run({ $ }) { + const { + app, + reservationId, + startUtc, + endUtc, + state, + resourceId, + number, + notes, + rateId, + companyId, + travelAgencyId, + businessSegmentId, + additionalFields, + } = this; + + const response = await app.reservationsUpdate({ + $, + data: { + Reservations: [ + { + Id: reservationId, + ...(startUtc && { + StartUtc: startUtc, + }), + ...(endUtc && { + EndUtc: endUtc, + }), + ...(state && { + State: state, + }), + ...(resourceId && { + ResourceId: resourceId, + }), + ...(number && { + Number: number, + }), + ...(notes && { + Notes: notes, + }), + ...(rateId && { + RateId: rateId, + }), + ...(companyId && { + CompanyId: companyId, + }), + ...(travelAgencyId && { + TravelAgencyId: travelAgencyId, + }), + ...(businessSegmentId && { + BusinessSegmentId: businessSegmentId, + }), + ...utils.parseJson(additionalFields), + }, + ], + }, + }); + $.export("summary", "Successfully updated reservation"); + return response; + }, +}; + diff --git a/components/mews/common/utils.mjs b/components/mews/common/utils.mjs new file mode 100644 index 0000000000000..2adf04343104f --- /dev/null +++ b/components/mews/common/utils.mjs @@ -0,0 +1,44 @@ +const parseJson = (input, maxDepth = 100) => { + const seen = new WeakSet(); + const parse = (value) => { + if (maxDepth <= 0) { + return value; + } + if (typeof(value) === "string") { + // Only parse if the string looks like a JSON object or array + const trimmed = value.trim(); + if ( + (trimmed.startsWith("{") && trimmed.endsWith("}")) || + (trimmed.startsWith("[") && trimmed.endsWith("]")) + ) { + try { + return parseJson(JSON.parse(value), maxDepth - 1); + } catch (e) { + return value; + } + } + return value; + } else if (typeof(value) === "object" && value !== null && !Array.isArray(value)) { + if (seen.has(value)) { + return value; + } + seen.add(value); + return Object.entries(value) + .reduce((acc, [ + key, + val, + ]) => Object.assign(acc, { + [key]: parse(val), + }), {}); + } else if (Array.isArray(value)) { + return value.map((item) => parse(item)); + } + return value; + }; + + return parse(input); +}; + +export default { + parseJson, +}; diff --git a/components/mews/mews.app.mjs b/components/mews/mews.app.mjs index bd82aacdc9e33..3fbebce6e68ce 100644 --- a/components/mews/mews.app.mjs +++ b/components/mews/mews.app.mjs @@ -1,11 +1,298 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "mews", - propDefinitions: {}, + propDefinitions: { + additionalFields: { + type: "object", + label: "Additional Fields", + description: "Raw payload fields to include in the request (e.g. filters).", + optional: true, + }, + reservationId: { + type: "string", + label: "Reservation ID", + description: "The ID of the reservation to fetch.", + async options() { + const reservations = await this.reservationsGetAll(); + return reservations.map((reservation) => ({ + label: reservation.Id, + value: reservation.Id, + })); + }, + }, + serviceId: { + type: "string", + label: "Service ID", + description: "Identifier of the Service (bookable service). [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/services#get-services)", + async options() { + const services = await this.servicesGetAll(); + return services.map((service) => ({ + label: service.Id, + value: service.Id, + })); + }, + }, + customerId: { + type: "string", + label: "Customer ID", + description: "Identifier of the Customer who owns the reservation. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/customers#get-customers)", + async options() { + const customers = await this.customersGetAll(); + return customers.map((customer) => ({ + label: customer.Id, + value: customer.Id, + })); + }, + }, + startUtc: { + type: "string", + label: "Start (UTC)", + description: "Start of the reservation in ISO 8601 (UTC).", + }, + endUtc: { + type: "string", + label: "End (UTC)", + description: "End of the reservation in ISO 8601 (UTC).", + }, + state: { + type: "string", + label: "State", + description: "State of the reservation.", + options: [ + "Optional", + "Enquired", + "Confirmed", + ], + }, + resourceId: { + type: "string", + label: "Resource ID", + description: "Identifier of the Resource (bookable resource). [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/resources#get-resources)", + optional: true, + async options() { + const resources = await this.resourcesGetAll(); + return resources.map((resource) => ({ + label: resource.Id, + value: resource.Id, + })); + }, + }, + number: { + type: "string", + label: "Reservation Number", + description: "Number of the reservation.", + optional: true, + }, + notes: { + type: "string", + label: "Notes", + description: "Notes of the reservation.", + optional: true, + }, + rateId: { + type: "string", + label: "Rate ID", + description: "Identifier of the Rate. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/rates#get-rates)", + optional: true, + async options() { + const rates = await this.ratesGetAll(); + return rates.map((rate) => ({ + label: rate.Id, + value: rate.Id, + })); + }, + }, + companyId: { + type: "string", + label: "Company ID", + description: "Identifier of the Company. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/companies#get-companies)", + optional: true, + async options() { + const companies = await this.companiesGetAll(); + return companies.map((company) => ({ + label: company.Id, + value: company.Id, + })); + }, + }, + travelAgencyId: { + type: "string", + label: "Travel Agency ID", + description: "Identifier of the Travel Agency. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/travel-agencies#get-travel-agencies)", + optional: true, + async options() { + const travelAgencies = await this.travelAgenciesGetAll(); + return travelAgencies.map((travelAgency) => ({ + label: travelAgency.Id, + value: travelAgency.Id, + })); + }, + }, + businessSegmentId: { + type: "string", + label: "Business Segment ID", + description: "Identifier of the Business Segment. [See the documentation](https://mews-systems.gitbook.io/connector-api/operations/business-segments#get-business-segments)", + optional: true, + async options() { + const businessSegments = await this.businessSegmentsGetAll(); + return businessSegments.map((businessSegment) => ({ + label: businessSegment.Id, + value: businessSegment.Id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `https://api.mews.com/api/connector/v1${path}`; + }, + getAuthData(data) { + const { + ClientToken: clientToken, + AccessToken: accessToken, + Client: client, + } = this.$auth; + return { + ...data, + ClientToken: clientToken, + AccessToken: accessToken, + Client: client, + }; + }, + _makeRequest({ + $ = this, path, data, ...args + } = {}) { + return axios($, { + method: "POST", + url: this.getUrl(path), + data: this.getAuthData(data), + ...args, + }); + }, + reservationsGetAll(args = {}) { + return this._makeRequest({ + path: "/reservations/getAll/2023-06-06", + ...args, + }); + }, + reservationsCreate(args = {}) { + return this._makeRequest({ + path: "/reservations/create", + ...args, + }); + }, + reservationsUpdate(args = {}) { + return this._makeRequest({ + path: "/reservations/update", + ...args, + }); + }, + reservationsCancel(args = {}) { + return this._makeRequest({ + path: "/reservations/cancel", + ...args, + }); + }, + orderItemsGetAll(args = {}) { + return this._makeRequest({ + path: "/orderItems/getAll", + ...args, + }); + }, + productsGetAll(args = {}) { + return this._makeRequest({ + path: "/products/getAll", + ...args, + }); + }, + customersGetAll(args = {}) { + return this._makeRequest({ + path: "/customers/getAll", + ...args, + }); + }, + productServiceOrdersGetAll(args = {}) { + return this._makeRequest({ + path: "/productServiceOrders/getAll", + ...args, + }); + }, + servicesGetAll(args = {}) { + return this._makeRequest({ + path: "/services/getAll", + ...args, + }); + }, + resourcesGetAll(args = {}) { + return this._makeRequest({ + path: "/resources/getAll", + ...args, + }); + }, + ratesGetAll(args = {}) { + return this._makeRequest({ + path: "/rates/getAll", + ...args, + }); + }, + companiesGetAll(args = {}) { + return this._makeRequest({ + path: "/companies/getAll", + ...args, + }); + }, + travelAgenciesGetAll(args = {}) { + return this._makeRequest({ + path: "/travelAgencies/getAll", + ...args, + }); + }, + businessSegmentsGetAll(args = {}) { + return this._makeRequest({ + path: "/businessSegments/getAll", + ...args, + }); + }, + async paginate({ + requester, + requesterArgs = {}, + resultKey, + count = 100, + maxRequests = 3, + } = {}) { + const items = []; + let next; + let requestCount = 0; + + while (true) { + if (requestCount >= maxRequests) { + break; + } + + const response = await requester({ + ...requesterArgs, + data: { + ...requesterArgs?.data, + Limitation: { + Cursor: next, + Count: count, + }, + }, + }); + + items.push(...(response?.[resultKey] || [])); + + next = response?.Limitation?.Cursor ?? null; + requestCount += 1; + + if (!next) { + break; + } + } + + return items; }, }, }; diff --git a/components/mews/package.json b/components/mews/package.json index 017f397007a40..ae51907eeddb9 100644 --- a/components/mews/package.json +++ b/components/mews/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/mews", - "version": "0.6.0", + "version": "0.7.0", "description": "Pipedream mews Components", "main": "mews.app.mjs", "keywords": [ @@ -13,6 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^3.0.0" + "@pipedream/platform": "^3.1.0" } } diff --git a/components/mews/sources/common/polling.mjs b/components/mews/sources/common/polling.mjs new file mode 100644 index 0000000000000..bc77a43d4d169 --- /dev/null +++ b/components/mews/sources/common/polling.mjs @@ -0,0 +1,129 @@ +import { + ConfigurationError, + DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, +} from "@pipedream/platform"; +import app from "../../mews.app.mjs"; + +export default { + props: { + app, + db: "$.service.db", + timer: { + type: "$.interface.timer", + label: "Polling Schedule", + description: "How often to poll the API", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + hooks: { + deploy() { + const { + getLastDateAt, + setLastDateAt, + getInitialLookbackMs, + } = this; + if (!getLastDateAt()) { + const initial = new Date(Date.now() - getInitialLookbackMs()).toISOString(); + setLastDateAt(initial); + } + }, + }, + methods: { + // Override these in concrete sources + getRequester() { + throw new ConfigurationError("getRequester is not implemented"); + }, + getResultKey() { + throw new ConfigurationError("getResultKey is not implemented"); + }, + getResourceName() { + return "Resource"; + }, + getId(resource) { + return resource?.Id || resource?.id; + }, + getDateField() { + throw new ConfigurationError("getDateField is not implemented"); + }, + getDateFilterField() { + // e.g. "CreatedUtc" | "UpdatedUtc" | "CanceledUtc" + throw new ConfigurationError("getDateFilterField is not implemented"); + }, + getStaticFilters() { + // e.g. { States: ["Cancelled"] } + return {}; + }, + getInitialLookbackMs() { + return 60 * 60 * 1000; // 1 hour + }, + getMaxRequests() { + return 3; + }, + setLastDateAt(value) { + this.db.set("lastDateAt", value); + }, + getLastDateAt() { + return this.db.get("lastDateAt"); + }, + generateMeta(resource) { + const id = this.getId(resource); + const dateField = this.getDateField(); + const tsStr = resource?.[dateField] || new Date().toISOString(); + return { + id, + summary: `${this.getResourceName()} ${id}`, + ts: Date.parse(tsStr), + }; + }, + }, + async run() { + const { + app, + getRequester, + getResultKey, + getDateField, + getDateFilterField, + getStaticFilters, + getLastDateAt, + setLastDateAt, + generateMeta, + getMaxRequests, + } = this; + + const lastDateAt = getLastDateAt() || new Date(0).toISOString(); + + const items = await app.paginate({ + requester: getRequester(), + requesterArgs: { + data: { + ...getStaticFilters(), + [getDateFilterField()]: { + StartUtc: lastDateAt, + }, + }, + }, + resultKey: getResultKey(), + maxRequests: getMaxRequests(), + }); + + if (!items?.length) { + return; + } + + let maxTs = lastDateAt; + items.forEach((resource) => { + const meta = generateMeta(resource); + const tsStr = resource?.[getDateField()] || new Date().toISOString(); + + if (tsStr > maxTs) { + maxTs = tsStr; + } + + this.$emit(resource, meta); + }); + + setLastDateAt(maxTs); + }, +}; diff --git a/components/mews/sources/order-item-created/order-item-created.mjs b/components/mews/sources/order-item-created/order-item-created.mjs new file mode 100644 index 0000000000000..7c8822d1253d2 --- /dev/null +++ b/components/mews/sources/order-item-created/order-item-created.mjs @@ -0,0 +1,32 @@ +import base from "../common/polling.mjs"; + +export default { + ...base, + name: "Order Item Created", + description: "Emit new order items as they are created (polling)", + key: "mews-order-item-created", + version: "0.0.1", + type: "source", + methods: { + ...base.methods, + getRequester() { + return this.app.orderItemsGetAll; + }, + getResultKey() { + return "OrderItems"; + }, + getResourceName() { + return "Order Item"; + }, + getId(resource) { + return resource?.Id || resource?.id; + }, + getDateField() { + return "CreatedUtc"; + }, + getDateFilterField() { + return "CreatedUtc"; + }, + }, +}; + diff --git a/components/mews/sources/order-item-updated/order-item-updated.mjs b/components/mews/sources/order-item-updated/order-item-updated.mjs new file mode 100644 index 0000000000000..c37d9f27442d2 --- /dev/null +++ b/components/mews/sources/order-item-updated/order-item-updated.mjs @@ -0,0 +1,32 @@ +import base from "../common/polling.mjs"; + +export default { + ...base, + name: "Order Item Updated", + description: "Emit new order items as they are updated (polling)", + key: "mews-order-item-updated", + version: "0.0.1", + type: "source", + methods: { + ...base.methods, + getRequester() { + return this.app.orderItemsGetAll; + }, + getResultKey() { + return "OrderItems"; + }, + getResourceName() { + return "Order Item"; + }, + getId(resource) { + return resource?.Id || resource?.id; + }, + getDateField() { + return "UpdatedUtc"; + }, + getDateFilterField() { + return "UpdatedUtc"; + }, + }, +}; + diff --git a/components/mews/sources/product-service-order-created/product-service-order-created.mjs b/components/mews/sources/product-service-order-created/product-service-order-created.mjs new file mode 100644 index 0000000000000..732a9724fc12c --- /dev/null +++ b/components/mews/sources/product-service-order-created/product-service-order-created.mjs @@ -0,0 +1,32 @@ +import base from "../common/polling.mjs"; + +export default { + ...base, + name: "Product Service Order Created", + description: "Emit new product service orders as they are created (polling)", + key: "mews-product-service-order-created", + version: "0.0.1", + type: "source", + methods: { + ...base.methods, + getRequester() { + return this.app.productServiceOrdersGetAll; + }, + getResultKey() { + return "ProductServiceOrders"; + }, + getResourceName() { + return "Product Service Order"; + }, + getId(resource) { + return resource?.Id || resource?.id; + }, + getDateField() { + return "CreatedUtc"; + }, + getDateFilterField() { + return "CreatedUtc"; + }, + }, +}; + diff --git a/components/mews/sources/reservation-cancelled/reservation-cancelled.mjs b/components/mews/sources/reservation-cancelled/reservation-cancelled.mjs new file mode 100644 index 0000000000000..133f0450a7729 --- /dev/null +++ b/components/mews/sources/reservation-cancelled/reservation-cancelled.mjs @@ -0,0 +1,39 @@ +import base from "../common/polling.mjs"; + +export default { + ...base, + name: "Reservation Cancelled", + description: "Emit new reservations as they are cancelled (polling)", + key: "mews-reservation-cancelled", + version: "0.0.1", + type: "source", + methods: { + ...base.methods, + getRequester() { + return this.app.reservationsGetAll; + }, + getResultKey() { + return "Reservations"; + }, + getResourceName() { + return "Reservation"; + }, + getId(resource) { + return resource?.Id || resource?.id; + }, + getDateField() { + return "CanceledUtc"; + }, + getDateFilterField() { + return "CanceledUtc"; + }, + getStaticFilters() { + return { + States: [ + "Canceled", + ], + }; + }, + }, +}; + diff --git a/components/mews/sources/reservation-created/reservation-created.mjs b/components/mews/sources/reservation-created/reservation-created.mjs new file mode 100644 index 0000000000000..bea7cd60312e2 --- /dev/null +++ b/components/mews/sources/reservation-created/reservation-created.mjs @@ -0,0 +1,31 @@ +import base from "../common/polling.mjs"; + +export default { + ...base, + name: "New Reservation Created", + description: "Emit new reservations as they are created (polling)", + key: "mews-reservation-created", + version: "0.0.1", + type: "source", + methods: { + ...base.methods, + getRequester() { + return this.app.reservationsGetAll; + }, + getResultKey() { + return "Reservations"; + }, + getResourceName() { + return "Reservation"; + }, + getId(resource) { + return resource?.Id || resource?.id; + }, + getDateField() { + return "CreatedUtc"; + }, + getDateFilterField() { + return "CreatedUtc"; + }, + }, +}; diff --git a/components/mews/sources/reservation-updated/reservation-updated.mjs b/components/mews/sources/reservation-updated/reservation-updated.mjs new file mode 100644 index 0000000000000..f641e7575500b --- /dev/null +++ b/components/mews/sources/reservation-updated/reservation-updated.mjs @@ -0,0 +1,32 @@ +import base from "../common/polling.mjs"; + +export default { + ...base, + name: "Reservation Updated", + description: "Emit new reservations as they are updated (polling)", + key: "mews-reservation-updated", + version: "0.0.1", + type: "source", + methods: { + ...base.methods, + getRequester() { + return this.app.reservationsGetAll; + }, + getResultKey() { + return "Reservations"; + }, + getResourceName() { + return "Reservation"; + }, + getId(resource) { + return resource?.Id || resource?.id; + }, + getDateField() { + return "UpdatedUtc"; + }, + getDateFilterField() { + return "UpdatedUtc"; + }, + }, +}; + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cd2cd3afdf21d..4bfc8f5f889be 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8585,8 +8585,8 @@ importers: components/mews: dependencies: '@pipedream/platform': - specifier: ^3.0.0 - version: 3.0.3 + specifier: ^3.1.0 + version: 3.1.0 components/mezmo: {} @@ -8774,8 +8774,7 @@ importers: components/minerstat: {} - components/minform: - specifiers: {} + components/minform: {} components/minio: {} @@ -9936,8 +9935,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/orufy_bookings: - specifiers: {} + components/orufy_bookings: {} components/ory: {} @@ -9963,8 +9961,7 @@ importers: specifier: ^1.2.0 version: 1.6.6 - components/outlign: - specifiers: {} + components/outlign: {} components/outline: {} @@ -12183,8 +12180,7 @@ importers: components/sap_s_4hana_cloud: {} - components/sap_s_4hana_cloud_sandbox: - specifiers: {} + components/sap_s_4hana_cloud_sandbox: {} components/sapling: {} @@ -40206,8 +40202,6 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) - transitivePeerDependencies: - - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: