Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/google_calendar/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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.`,
);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading