@pipedream/google_calendar 0.4.0 → 0.5.0

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.
@@ -6,7 +6,7 @@ export default {
6
6
  key: "google_calendar-create-event",
7
7
  name: "Create Event",
8
8
  description: "Create an event to the Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#insert)",
9
- version: "0.2.0",
9
+ version: "0.2.1",
10
10
  type: "action",
11
11
  props: {
12
12
  googleCalendar,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "google_calendar-delete-event",
5
5
  name: "Delete an Event",
6
6
  description: "Delete an event to the Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#delete)",
7
- version: "0.1.3",
7
+ version: "0.1.4",
8
8
  type: "action",
9
9
  props: {
10
10
  googleCalendar,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "google_calendar-get-calendar",
5
5
  name: "Retrieve Calendar Details",
6
6
  description: "Retrieve calendar details of a Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Calendars.html#get)",
7
- version: "0.1.4",
7
+ version: "0.1.5",
8
8
  type: "action",
9
9
  props: {
10
10
  googleCalendar,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "google_calendar-get-event",
5
5
  name: "Retrieve Event Details",
6
6
  description: "Retrieve event details from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#get)",
7
- version: "0.1.4",
7
+ version: "0.1.5",
8
8
  type: "action",
9
9
  props: {
10
10
  googleCalendar,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "google_calendar-list-calendars",
5
5
  name: "List Calendars",
6
6
  description: "Retrieve a list of calendars from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Calendarlist.html#list)",
7
- version: "0.1.4",
7
+ version: "0.1.5",
8
8
  type: "action",
9
9
  props: {
10
10
  googleCalendar,
@@ -1,10 +1,11 @@
1
1
  import googleCalendar from "../../google_calendar.app.mjs";
2
+ import utils from "../../common/utils.mjs";
2
3
 
3
4
  export default {
4
5
  key: "google_calendar-list-events",
5
6
  name: "List Events",
6
7
  description: "Retrieve a list of event from the Google Calendar. [See the documentation](https://developers.google.com/calendar/api/v3/reference/events/list)",
7
- version: "0.0.4",
8
+ version: "0.0.5",
8
9
  type: "action",
9
10
  props: {
10
11
  googleCalendar,
@@ -111,30 +112,15 @@ export default {
111
112
  "updatedMin",
112
113
  ],
113
114
  },
114
- },
115
- methods: {
116
- filterEmptyValues(obj) {
117
- if (!obj) {
118
- return obj;
119
- }
120
- return Object.entries(obj)
121
- .reduce((reduction,
122
- [
123
- key,
124
- value,
125
- ]) => {
126
- if (value === undefined || value === null) {
127
- return reduction;
128
- }
129
- return {
130
- ...reduction,
131
- [key]: value,
132
- };
133
- }, {});
115
+ eventTypes: {
116
+ propDefinition: [
117
+ googleCalendar,
118
+ "eventTypes",
119
+ ],
134
120
  },
135
121
  },
136
122
  async run({ $ }) {
137
- const args = this.filterEmptyValues({
123
+ const args = utils.filterEmptyValues({
138
124
  calendarId: this.calendarId,
139
125
  iCalUID: this.iCalUID,
140
126
  maxAttendees: this.maxAttendees,
@@ -152,6 +138,7 @@ export default {
152
138
  timeMin: this.timeMin,
153
139
  timeZone: this.timeZone,
154
140
  updatedMin: this.updatedMin,
141
+ eventTypes: this.eventTypes,
155
142
  });
156
143
  const response = await this.googleCalendar.listEvents(args);
157
144
 
@@ -0,0 +1,56 @@
1
+ import googleCalendar from "../../google_calendar.app.mjs";
2
+ import utils from "../../common/utils.mjs";
3
+
4
+ export default {
5
+ key: "google_calendar-list-events-by-type",
6
+ name: "List Calendar Events by Type",
7
+ description: "Retrieve a list of events filtered by type (\"default\", \"focusTime\", \"outOfOffice\", \"workingLocation\") from the Google Calendar. [See the documentation](https://developers.google.com/calendar/api/v3/reference/events/list)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ googleCalendar,
12
+ calendarId: {
13
+ propDefinition: [
14
+ googleCalendar,
15
+ "calendarId",
16
+ ],
17
+ },
18
+ eventTypes: {
19
+ propDefinition: [
20
+ googleCalendar,
21
+ "eventTypes",
22
+ ],
23
+ },
24
+ maxResults: {
25
+ propDefinition: [
26
+ googleCalendar,
27
+ "maxResults",
28
+ ],
29
+ },
30
+ },
31
+ async run({ $ }) {
32
+ const args = utils.filterEmptyValues({
33
+ calendarId: this.calendarId,
34
+ eventTypes: this.eventTypes,
35
+ });
36
+ const events = [];
37
+ let total, done = false, count = 0;
38
+ do {
39
+ const response = await this.googleCalendar.listEvents(args);
40
+ for (const item of response.items) {
41
+ events.push(item);
42
+ count++;
43
+ if (this.maxResults && count >= this.maxResults) {
44
+ done = true;
45
+ break;
46
+ }
47
+ }
48
+ total = response.items?.length;
49
+ args.syncToken = response.nextSyncToken;
50
+ } while (total && !done);
51
+
52
+ $.export("$summary", `Successfully retrieved ${events.length} event(s)`);
53
+
54
+ return events;
55
+ },
56
+ };
@@ -4,7 +4,7 @@ export default {
4
4
  key: "google_calendar-query-free-busy-calendars",
5
5
  name: "Retrieve Free/Busy Calendar Details",
6
6
  description: "Retrieve free/busy calendar details from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Freebusy.html#query)",
7
- version: "0.1.4",
7
+ version: "0.1.5",
8
8
  type: "action",
9
9
  props: {
10
10
  googleCalendar,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "google_calendar-quick-add-event",
5
5
  name: "Add Quick Event",
6
6
  description: "Create a quick event to the Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#quickAdd)",
7
- version: "0.1.3",
7
+ version: "0.1.4",
8
8
  type: "action",
9
9
  props: {
10
10
  googleCalendar,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-update-event",
6
6
  name: "Update Event",
7
7
  description: "Update an event from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#update)",
8
- version: "0.0.5",
8
+ version: "0.0.6",
9
9
  type: "action",
10
10
  props: {
11
11
  googleCalendar,
@@ -4,7 +4,7 @@ export default {
4
4
  key: "google_calendar-update-event-attendees",
5
5
  name: "Update attendees of an event",
6
6
  description: "Update attendees of an existing event. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#update)",
7
- version: "0.1.3",
7
+ version: "0.1.4",
8
8
  type: "action",
9
9
  props: {
10
10
  googleCalendar,
@@ -0,0 +1,21 @@
1
+ export default {
2
+ filterEmptyValues(obj) {
3
+ if (!obj) {
4
+ return obj;
5
+ }
6
+ return Object.entries(obj)
7
+ .reduce((reduction,
8
+ [
9
+ key,
10
+ value,
11
+ ]) => {
12
+ if (value === undefined || value === null) {
13
+ return reduction;
14
+ }
15
+ return {
16
+ ...reduction,
17
+ [key]: value,
18
+ };
19
+ }, {});
20
+ },
21
+ };
@@ -277,6 +277,18 @@ export default {
277
277
  }));
278
278
  },
279
279
  },
280
+ eventTypes: {
281
+ type: "string[]",
282
+ label: "Event Types",
283
+ description: "Filter events by event type",
284
+ optional: true,
285
+ options: [
286
+ "default",
287
+ "focusTime",
288
+ "outOfOffice",
289
+ "workingLocation",
290
+ ],
291
+ },
280
292
  },
281
293
  methods: {
282
294
  _tokens() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_calendar",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Pipedream Google_calendar Components",
5
5
  "main": "google_calendar.app.mjs",
6
6
  "keywords": [
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-event-cancelled",
6
6
  name: "New Cancelled Event",
7
7
  description: "Emit new event when a Google Calendar event is cancelled or deleted",
8
- version: "0.1.6",
8
+ version: "0.1.7",
9
9
  type: "source",
10
10
  dedupe: "unique",
11
11
  props: {
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-event-ended",
6
6
  name: "New Ended Event",
7
7
  description: "Emit new event when a Google Calendar event ends",
8
- version: "0.1.6",
8
+ version: "0.1.7",
9
9
  type: "source",
10
10
  dedupe: "unique",
11
11
  props: {
@@ -6,7 +6,7 @@ export default {
6
6
  key: "google_calendar-event-start",
7
7
  name: "New Event Start",
8
8
  description: "Emit new event when the specified time before the Google Calendar event starts",
9
- version: "0.1.7",
9
+ version: "0.1.8",
10
10
  type: "source",
11
11
  dedupe: "unique",
12
12
  props: {
@@ -4,7 +4,7 @@ export default {
4
4
  key: "google_calendar-new-calendar",
5
5
  name: "New Calendar Created",
6
6
  description: "Emit new event when a calendar is created.",
7
- version: "0.1.6",
7
+ version: "0.1.7",
8
8
  type: "source",
9
9
  props: {
10
10
  ...common.props,
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-new-event",
6
6
  name: "New Event Created",
7
7
  description: "Emit new event when a Google Calendar event is created",
8
- version: "0.1.6",
8
+ version: "0.1.7",
9
9
  type: "source",
10
10
  dedupe: "unique",
11
11
  props: {
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-new-event-search",
6
6
  name: "New Event Matching a Search",
7
7
  description: "Emit new event when a Google Calendar event is created that matches a search",
8
- version: "0.1.6",
8
+ version: "0.1.7",
9
9
  type: "source",
10
10
  dedupe: "unique",
11
11
  props: {
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-new-or-updated-event",
6
6
  name: "New Created or Updated Event",
7
7
  description: "Emit new event when a Google Calendar events is created or updated (does not emit cancelled events)",
8
- version: "0.1.6",
8
+ version: "0.1.7",
9
9
  type: "source",
10
10
  dedupe: "unique",
11
11
  props: {
@@ -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.10",
11
+ version: "0.1.11",
12
12
  dedupe: "unique",
13
13
  props: {
14
14
  googleCalendar,
@@ -8,7 +8,7 @@ export default {
8
8
  description: `Emit new event based on a time interval before an upcoming event in the calendar. This source uses Pipedream's Task Scheduler.
9
9
  [See the documentation](https://pipedream.com/docs/examples/waiting-to-execute-next-step-of-workflow/#step-1-create-a-task-scheduler-event-source)
10
10
  for more information and instructions for connecting your Pipedream account.`,
11
- version: "0.0.4",
11
+ version: "0.0.5",
12
12
  type: "source",
13
13
  props: {
14
14
  pipedream: taskScheduler.props.pipedream,
@@ -0,0 +1,149 @@
1
+ import taskScheduler from "../../../pipedream/sources/new-scheduled-tasks/new-scheduled-tasks.mjs";
2
+ import googleCalendar from "../../google_calendar.app.mjs";
3
+
4
+ export default {
5
+ key: "google_calendar-upcoming-event-type-alert",
6
+ name: "New Upcoming Event Type Alert",
7
+ description: `Emit new event based on a time interval before an upcoming event of the specified type ("default", "focusTime", "outOfOffice", "workingLocation") in the calendar. This source uses Pipedream's Task Scheduler.
8
+ [See the documentation](https://pipedream.com/docs/examples/waiting-to-execute-next-step-of-workflow/#step-1-create-a-task-scheduler-event-source)
9
+ for more information and instructions for connecting your Pipedream account.`,
10
+ version: "0.0.1",
11
+ type: "source",
12
+ props: {
13
+ pipedream: taskScheduler.props.pipedream,
14
+ googleCalendar,
15
+ db: "$.service.db",
16
+ http: "$.interface.http",
17
+ calendarId: {
18
+ propDefinition: [
19
+ googleCalendar,
20
+ "calendarId",
21
+ ],
22
+ },
23
+ eventTypes: {
24
+ propDefinition: [
25
+ googleCalendar,
26
+ "eventTypes",
27
+ ],
28
+ },
29
+ time: {
30
+ type: "integer",
31
+ label: "Minutes Before",
32
+ description: "Number of minutes to trigger before the start of the calendar event.",
33
+ min: 0,
34
+ reloadProps: true,
35
+ },
36
+ },
37
+ async additionalProps() {
38
+ const props = {};
39
+ if (this.time > 0) {
40
+ props.timer = {
41
+ type: "$.interface.timer",
42
+ description: "Poll the API to schedule alerts for any newly created events",
43
+ default: {
44
+ intervalSeconds: 60 * this.time,
45
+ },
46
+ };
47
+ }
48
+ return props;
49
+ },
50
+ hooks: {
51
+ async deactivate() {
52
+ const ids = this._getScheduledEventIds();
53
+ if (!ids?.length) {
54
+ return;
55
+ }
56
+ for (const id of ids) {
57
+ if (await this.deleteEvent({
58
+ body: {
59
+ id,
60
+ },
61
+ })) {
62
+ console.log("Cancelled scheduled event");
63
+ }
64
+ }
65
+ this._setScheduledEventIds();
66
+ },
67
+ },
68
+ methods: {
69
+ ...taskScheduler.methods,
70
+ _getScheduledEventIds() {
71
+ return this.db.get("scheduledEventIds");
72
+ },
73
+ _setScheduledEventIds(ids) {
74
+ this.db.set("scheduledEventIds", ids);
75
+ },
76
+ _getScheduledCalendarEventIds() {
77
+ return this.db.get("scheduledCalendarEventIds");
78
+ },
79
+ _setScheduledCalendarEventIds(ids) {
80
+ this.db.set("scheduledCalendarEventIds", ids);
81
+ },
82
+ _hasDeployed() {
83
+ const result = this.db.get("hasDeployed");
84
+ this.db.set("hasDeployed", true);
85
+ return result;
86
+ },
87
+ subtractMinutes(date, minutes) {
88
+ return date.getTime() - minutes * 60000;
89
+ },
90
+ async getCalendarEvents() {
91
+ const calendarEvents = [];
92
+ const params = {
93
+ calendarId: this.calendarId,
94
+ eventTypes: this.eventTypes,
95
+ };
96
+ do {
97
+ const {
98
+ data: {
99
+ items, nextPageToken,
100
+ },
101
+ } = await this.googleCalendar.getEvents(params);
102
+ if (items?.length) {
103
+ calendarEvents.push(...items);
104
+ }
105
+ params.pageToken = nextPageToken;
106
+ } while (params.pageToken);
107
+ return calendarEvents;
108
+ },
109
+ },
110
+ async run(event) {
111
+ // self subscribe only on the first time
112
+ if (!this._hasDeployed()) {
113
+ await this.selfSubscribe();
114
+ }
115
+
116
+ const scheduledEventIds = this._getScheduledEventIds() || [];
117
+
118
+ // incoming scheduled event
119
+ if (event.$channel === this.selfChannel()) {
120
+ const remainingScheduledEventIds = scheduledEventIds.filter((id) => id !== event["$id"]);
121
+ this._setScheduledEventIds(remainingScheduledEventIds);
122
+ this.emitEvent(event, `Upcoming ${event.summary} event`);
123
+ return;
124
+ }
125
+
126
+ // schedule new events
127
+ const scheduledCalendarEventIds = this._getScheduledCalendarEventIds() || {};
128
+ const calendarEvents = await this.getCalendarEvents();
129
+
130
+ for (const calendarEvent of calendarEvents) {
131
+ const startTime = calendarEvent.start
132
+ ? (new Date(calendarEvent.start.dateTime || calendarEvent.start.date))
133
+ : null;
134
+ if (!startTime
135
+ || startTime.getTime() < Date.now()
136
+ || scheduledCalendarEventIds[calendarEvent.id])
137
+ {
138
+ continue;
139
+ }
140
+ const later = new Date(this.subtractMinutes(startTime, this.time));
141
+
142
+ const scheduledEventId = this.emitScheduleEvent(calendarEvent, later);
143
+ scheduledEventIds.push(scheduledEventId);
144
+ scheduledCalendarEventIds[calendarEvent.id] = true;
145
+ }
146
+ this._setScheduledEventIds(scheduledEventIds);
147
+ this._setScheduledCalendarEventIds(scheduledCalendarEventIds);
148
+ },
149
+ };