diff --git a/components/microsoft_outlook/microsoft_outlook.app.mjs b/components/microsoft_outlook/microsoft_outlook.app.mjs index 6d066831558eb..70c43718084d8 100644 --- a/components/microsoft_outlook/microsoft_outlook.app.mjs +++ b/components/microsoft_outlook/microsoft_outlook.app.mjs @@ -216,6 +216,13 @@ export default { ...args, }); }, + async listCalendarEvents({ ...args } = {}) { + return await this._makeRequest({ + method: "GET", + path: "/me/events", + ...args, + }); + }, async sendEmail({ ...args } = {}) { return await this._makeRequest({ method: "POST", @@ -274,6 +281,13 @@ export default { ...args, }); }, + async listMessages({ ...args } = {}) { + return await this._makeRequest({ + method: "GET", + path: "/me/messages", + ...args, + }); + }, async getCalendarEvent({ eventId, ...args diff --git a/components/microsoft_outlook/package.json b/components/microsoft_outlook/package.json index e05cd64ac75f6..f7080cab6f174 100644 --- a/components/microsoft_outlook/package.json +++ b/components/microsoft_outlook/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/microsoft_outlook", - "version": "0.0.2", + "version": "0.0.3", "description": "Pipedream Microsoft Outlook Components", "main": "microsoft_outlook.app.mjs", "keywords": [ diff --git a/components/microsoft_outlook/sources/common.mjs b/components/microsoft_outlook/sources/common.mjs index 83965faf8b811..90cc7f377dd16 100644 --- a/components/microsoft_outlook/sources/common.mjs +++ b/components/microsoft_outlook/sources/common.mjs @@ -24,6 +24,19 @@ export default { }, }, }, + hooks: { + async deploy() { + const { value: events } = await this.getSampleEvents({ + pageSize: 25, + }); + if (!events || events.length == 0) { + return; + } + for (const item of events) { + this.emitEvent(item); + } + }, + }, methods: { getIntervalEnd() { return new Date(Date.now() + getRenewalInterval(true)); diff --git a/components/microsoft_outlook/sources/new-calendar-event/new-calendar-event.mjs b/components/microsoft_outlook/sources/new-calendar-event/new-calendar-event.mjs index 615994d7fb814..eb0817bac377a 100644 --- a/components/microsoft_outlook/sources/new-calendar-event/new-calendar-event.mjs +++ b/components/microsoft_outlook/sources/new-calendar-event/new-calendar-event.mjs @@ -3,11 +3,12 @@ import common from "../common.mjs"; export default { ...common, key: "microsoft_outlook-new-calendar-event", - name: "New Calendar Event", + name: "New Calendar Event (Instant)", description: "Emit new event when a new Calendar event is created", - version: "0.0.1", + version: "0.0.2", type: "source", hooks: { + ...common.hooks, async activate() { await this.activate({ changeType: "created", @@ -18,6 +19,29 @@ export default { await this.deactivate(); }, }, + methods: { + ...common.methods, + async getSampleEvents({ pageSize }) { + return this.microsoftOutlook.listCalendarEvents({ + params: { + $top: pageSize, + $orderby: "createdDateTime desc", + }, + }); + }, + emitEvent(item) { + this.$emit({ + message: item, + }, this.generateMeta(item)); + }, + generateMeta(item) { + return { + id: item.id, + summary: `New calendar event (ID:${item.id})`, + ts: Date.parse(item.createdDateTime), + }; + }, + }, async run(event) { await this.run({ event, @@ -25,16 +49,7 @@ export default { const item = await this.microsoftOutlook.getCalendarEvent({ eventId: resourceId, }); - this.$emit( - { - message: item, - }, - { - id: item.id, - ts: Date.parse(item.createdDateTime), - summary: `New calendar event (ID:${item.id})`, - }, - ); + this.emitEvent(item); }, }); }, diff --git a/components/microsoft_outlook/sources/new-contact/new-contact.mjs b/components/microsoft_outlook/sources/new-contact/new-contact.mjs index 27d206e13de59..b34c556f98f60 100644 --- a/components/microsoft_outlook/sources/new-contact/new-contact.mjs +++ b/components/microsoft_outlook/sources/new-contact/new-contact.mjs @@ -3,11 +3,12 @@ import common from "../common.mjs"; export default { ...common, key: "microsoft_outlook-new-contact", - name: "New Contact Event", + name: "New Contact Event (Instant)", description: "Emit new event when a new Contact is created", - version: "0.0.1", + version: "0.0.2", type: "source", hooks: { + ...common.hooks, async activate() { await this.activate({ changeType: "created", @@ -18,6 +19,29 @@ export default { await this.deactivate(); }, }, + methods: { + ...common.methods, + async getSampleEvents({ pageSize }) { + return this.microsoftOutlook.listContacts({ + params: { + $top: pageSize, + $orderby: "createdDateTime desc", + }, + }); + }, + emitEvent(item) { + this.$emit({ + contact: item, + }, this.generateMeta(item)); + }, + generateMeta(item) { + return { + id: item.id, + summary: `New contact (ID:${item.id})`, + ts: Date.parse(item.createdDateTime), + }; + }, + }, async run(event) { await this.run({ event, @@ -25,16 +49,7 @@ export default { const item = await this.microsoftOutlook.getContact({ contactId: resourceId, }); - this.$emit( - { - contact: item, - }, - { - id: item.id, - ts: Date.parse(item.createdDateTime), - summary: `New contact (ID:${item.id})`, - }, - ); + this.emitEvent(item); }, }); }, diff --git a/components/microsoft_outlook/sources/new-email/new-email.mjs b/components/microsoft_outlook/sources/new-email/new-email.mjs index d59654f328462..e1e9bb109507e 100644 --- a/components/microsoft_outlook/sources/new-email/new-email.mjs +++ b/components/microsoft_outlook/sources/new-email/new-email.mjs @@ -3,11 +3,12 @@ import common from "../common.mjs"; export default { ...common, key: "microsoft_outlook-new-email", - name: "New Email Event", + name: "New Email Event (Instant)", description: "Emit new event when an email received", - version: "0.0.1", + version: "0.0.2", type: "source", hooks: { + ...common.hooks, async activate() { await this.activate({ changeType: "created", @@ -18,6 +19,29 @@ export default { await this.deactivate(); }, }, + methods: { + ...common.methods, + async getSampleEvents({ pageSize }) { + return this.microsoftOutlook.listMessages({ + params: { + $top: pageSize, + $orderby: "createdDateTime desc", + }, + }); + }, + emitEvent(item) { + this.$emit({ + email: item, + }, this.generateMeta(item)); + }, + generateMeta(item) { + return { + id: item.id, + summary: `New email (ID:${item.id})`, + ts: Date.parse(item.createdDateTime), + }; + }, + }, async run(event) { await this.run({ event, @@ -25,16 +49,7 @@ export default { const item = await this.microsoftOutlook.getMessage({ messageId: resourceId, }); - this.$emit( - { - email: item, - }, - { - id: item.id, - ts: Date.parse(item.createdDateTime), - summary: `New email (ID:${item.id})`, - }, - ); + this.emitEvent(item); }, }); }, diff --git a/components/microsoft_outlook/sources/updated-calendar-event/updated-calendar-event.mjs b/components/microsoft_outlook/sources/updated-calendar-event/updated-calendar-event.mjs index 7431772671965..51be9cf077650 100644 --- a/components/microsoft_outlook/sources/updated-calendar-event/updated-calendar-event.mjs +++ b/components/microsoft_outlook/sources/updated-calendar-event/updated-calendar-event.mjs @@ -3,12 +3,12 @@ import common from "../common.mjs"; export default { ...common, key: "microsoft_outlook-updated-calendar-event", - name: "New Calendar Event Update", + name: "New Calendar Event Update (Instant)", description: "Emit new event when a Calendar event is updated", - version: "0.0.1", + version: "0.0.2", type: "source", - dedupe: "unique", hooks: { + ...common.hooks, async activate() { await this.activate({ changeType: "updated", @@ -19,6 +19,29 @@ export default { await this.deactivate(); }, }, + methods: { + ...common.methods, + async getSampleEvents({ pageSize }) { + return this.microsoftOutlook.listCalendarEvents({ + params: { + $top: pageSize, + $orderby: "lastModifiedDateTime desc", + }, + }); + }, + emitEvent(item) { + this.$emit({ + message: item, + }, this.generateMeta(item)); + }, + generateMeta(item) { + return { + id: item.id, + summary: `Calendar event updated (ID:${item.id})`, + ts: Date.parse(item.createdDateTime), + }; + }, + }, async run(event) { await this.run({ event, @@ -26,16 +49,7 @@ export default { const item = await this.microsoftOutlook.getCalendarEvent({ eventId: resourceId, }); - this.$emit( - { - message: item, - }, - { - id: item.id, - ts: Date.parse(item.createdDateTime), - summary: `Calendar event updated (ID:${item.id})`, - }, - ); + this.emitEvent(item); }, }); },