diff --git a/components/google_calendar/package.json b/components/google_calendar/package.json index f1bd4a36c36ad..c63b99a82c8be 100644 --- a/components/google_calendar/package.json +++ b/components/google_calendar/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/google_calendar", - "version": "0.5.6", + "version": "0.5.7", "description": "Pipedream Google_calendar Components", "main": "google_calendar.app.mjs", "keywords": [ diff --git a/components/google_calendar/sources/new-or-updated-event-instant/new-or-updated-event-instant.mjs b/components/google_calendar/sources/new-or-updated-event-instant/new-or-updated-event-instant.mjs index b4d4db70e7757..1ca4ecb79b0bd 100644 --- a/components/google_calendar/sources/new-or-updated-event-instant/new-or-updated-event-instant.mjs +++ b/components/google_calendar/sources/new-or-updated-event-instant/new-or-updated-event-instant.mjs @@ -8,7 +8,7 @@ export default { type: "source", name: "New Created or Updated Event (Instant)", description: "Emit new event when a Google Calendar events is created or updated (does not emit cancelled events)", - version: "0.1.13", + version: "0.1.14", dedupe: "unique", props: { googleCalendar, @@ -199,16 +199,18 @@ export default { } return new Date(min); }, - getChannelIds() { - const channelIds = []; + getCalendarIdForChannelId(incomingChannelId) { for (const calendarId of this.calendarIds) { - const channelId = this.db.get(`${calendarId}.channelId`); - channelIds.push(channelId); + if (this.db.get(`${calendarId}.channelId`) === incomingChannelId) { + return calendarId; + } } - return channelIds; + return null; }, }, async run(event) { + let calendarId = null; // calendar ID matching incoming channel ID + // refresh watch if (event.interval_seconds) { // get time @@ -224,9 +226,9 @@ export default { } } else { // Verify channel ID - const channelIds = this.getChannelIds(); const incomingChannelId = event?.headers?.["x-goog-channel-id"]; - if (!channelIds.includes(incomingChannelId)) { + calendarId = this.getCalendarIdForChannelId(incomingChannelId); + if (!calendarId) { console.log( `Unexpected channel ID ${incomingChannelId}. This likely means there are multiple, older subscriptions active.`, ); @@ -252,41 +254,49 @@ export default { } // Fetch and emit events - for (const calendarId of this.calendarIds) { + const checkCalendarIds = calendarId + ? [ + calendarId, + ] + : this.calendarIds; + for (const calendarId of checkCalendarIds) { const syncToken = this.getNextSyncToken(calendarId); let nextSyncToken = null; let nextPageToken = null; while (!nextSyncToken) { - const { - data: syncData = {}, - status: syncStatus, - } = await this.googleCalendar.listEvents({ - returnOnlyData: false, - calendarId, - syncToken, - pageToken: nextPageToken, - maxResults: 2500, - }); - if (syncStatus === 410) { - console.log("Sync token invalid, resyncing"); - nextSyncToken = await this.googleCalendar.fullSync(this.calendarId); - break; - } - nextPageToken = syncData.nextPageToken; - nextSyncToken = syncData.nextSyncToken; - - const { items: events = [] } = syncData; - events - .filter(this.isEventRelevant, this) - .forEach((event) => { - const { status } = event; - if (status === "cancelled") { - console.log("Event cancelled. Exiting."); - return; - } - const meta = this.generateMeta(event); - this.$emit(event, meta); + try { + const { data: syncData = {} } = await this.googleCalendar.listEvents({ + returnOnlyData: false, + calendarId, + syncToken, + pageToken: nextPageToken, + maxResults: 2500, }); + + nextPageToken = syncData.nextPageToken; + nextSyncToken = syncData.nextSyncToken; + + const { items: events = [] } = syncData; + events + .filter(this.isEventRelevant, this) + .forEach((event) => { + const { status } = event; + if (status === "cancelled") { + console.log("Event cancelled. Exiting."); + return; + } + const meta = this.generateMeta(event); + this.$emit(event, meta); + }); + } catch (error) { + if (error === "Sync token is no longer valid, a full sync is required.") { + console.log("Sync token invalid, resyncing"); + nextSyncToken = await this.googleCalendar.fullSync(calendarId); + break; + } else { + throw error; + } + } } this.setNextSyncToken(calendarId, nextSyncToken); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 954737ed2f60b..c831dcc75e3d7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24487,22 +24487,22 @@ 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 v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . 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 v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . 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 v7.0.2+ of superagent. We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing. See the releases tab for more information at . superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - 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 downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731) supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==}