@pipedream/google_calendar 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_calendar",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "Pipedream Google_calendar Components",
5
5
  "main": "google_calendar.app.mjs",
6
6
  "keywords": [
@@ -8,7 +8,7 @@ export default {
8
8
  type: "source",
9
9
  name: "New Created or Updated Event (Instant)",
10
10
  description: "Emit new event when a Google Calendar events is created or updated (does not emit cancelled events)",
11
- version: "0.1.13",
11
+ version: "0.1.14",
12
12
  dedupe: "unique",
13
13
  props: {
14
14
  googleCalendar,
@@ -199,16 +199,18 @@ export default {
199
199
  }
200
200
  return new Date(min);
201
201
  },
202
- getChannelIds() {
203
- const channelIds = [];
202
+ getCalendarIdForChannelId(incomingChannelId) {
204
203
  for (const calendarId of this.calendarIds) {
205
- const channelId = this.db.get(`${calendarId}.channelId`);
206
- channelIds.push(channelId);
204
+ if (this.db.get(`${calendarId}.channelId`) === incomingChannelId) {
205
+ return calendarId;
206
+ }
207
207
  }
208
- return channelIds;
208
+ return null;
209
209
  },
210
210
  },
211
211
  async run(event) {
212
+ let calendarId = null; // calendar ID matching incoming channel ID
213
+
212
214
  // refresh watch
213
215
  if (event.interval_seconds) {
214
216
  // get time
@@ -224,9 +226,9 @@ export default {
224
226
  }
225
227
  } else {
226
228
  // Verify channel ID
227
- const channelIds = this.getChannelIds();
228
229
  const incomingChannelId = event?.headers?.["x-goog-channel-id"];
229
- if (!channelIds.includes(incomingChannelId)) {
230
+ calendarId = this.getCalendarIdForChannelId(incomingChannelId);
231
+ if (!calendarId) {
230
232
  console.log(
231
233
  `Unexpected channel ID ${incomingChannelId}. This likely means there are multiple, older subscriptions active.`,
232
234
  );
@@ -252,41 +254,49 @@ export default {
252
254
  }
253
255
 
254
256
  // Fetch and emit events
255
- for (const calendarId of this.calendarIds) {
257
+ const checkCalendarIds = calendarId
258
+ ? [
259
+ calendarId,
260
+ ]
261
+ : this.calendarIds;
262
+ for (const calendarId of checkCalendarIds) {
256
263
  const syncToken = this.getNextSyncToken(calendarId);
257
264
  let nextSyncToken = null;
258
265
  let nextPageToken = null;
259
266
  while (!nextSyncToken) {
260
- const {
261
- data: syncData = {},
262
- status: syncStatus,
263
- } = await this.googleCalendar.listEvents({
264
- returnOnlyData: false,
265
- calendarId,
266
- syncToken,
267
- pageToken: nextPageToken,
268
- maxResults: 2500,
269
- });
270
- if (syncStatus === 410) {
271
- console.log("Sync token invalid, resyncing");
272
- nextSyncToken = await this.googleCalendar.fullSync(this.calendarId);
273
- break;
274
- }
275
- nextPageToken = syncData.nextPageToken;
276
- nextSyncToken = syncData.nextSyncToken;
277
-
278
- const { items: events = [] } = syncData;
279
- events
280
- .filter(this.isEventRelevant, this)
281
- .forEach((event) => {
282
- const { status } = event;
283
- if (status === "cancelled") {
284
- console.log("Event cancelled. Exiting.");
285
- return;
286
- }
287
- const meta = this.generateMeta(event);
288
- this.$emit(event, meta);
267
+ try {
268
+ const { data: syncData = {} } = await this.googleCalendar.listEvents({
269
+ returnOnlyData: false,
270
+ calendarId,
271
+ syncToken,
272
+ pageToken: nextPageToken,
273
+ maxResults: 2500,
289
274
  });
275
+
276
+ nextPageToken = syncData.nextPageToken;
277
+ nextSyncToken = syncData.nextSyncToken;
278
+
279
+ const { items: events = [] } = syncData;
280
+ events
281
+ .filter(this.isEventRelevant, this)
282
+ .forEach((event) => {
283
+ const { status } = event;
284
+ if (status === "cancelled") {
285
+ console.log("Event cancelled. Exiting.");
286
+ return;
287
+ }
288
+ const meta = this.generateMeta(event);
289
+ this.$emit(event, meta);
290
+ });
291
+ } catch (error) {
292
+ if (error === "Sync token is no longer valid, a full sync is required.") {
293
+ console.log("Sync token invalid, resyncing");
294
+ nextSyncToken = await this.googleCalendar.fullSync(calendarId);
295
+ break;
296
+ } else {
297
+ throw error;
298
+ }
299
+ }
290
300
  }
291
301
 
292
302
  this.setNextSyncToken(calendarId, nextSyncToken);