@pipedream/google_calendar 0.3.7 → 0.3.9

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.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "Pipedream Google_calendar Components",
5
5
  "main": "google_calendar.app.mjs",
6
6
  "keywords": [
@@ -12,6 +12,7 @@
12
12
  "license": "MIT",
13
13
  "dependencies": {
14
14
  "@googleapis/calendar": "^1.0.2",
15
+ "@pipedream/platform": "^1.2.0",
15
16
  "lodash.get": "^4.4.2",
16
17
  "moment-timezone": "^0.5.33",
17
18
  "uuid": "^8.3.2"
@@ -1,4 +1,5 @@
1
1
  import googleCalendar from "../google_calendar.app.mjs";
2
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
3
 
3
4
  export default {
4
5
  props: {
@@ -12,7 +13,7 @@ export default {
12
13
  timer: {
13
14
  type: "$.interface.timer",
14
15
  default: {
15
- intervalSeconds: 15 * 60,
16
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
16
17
  },
17
18
  },
18
19
  },
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-event-cancelled",
6
6
  name: "Event Cancelled",
7
7
  description: "Emits when an event is cancelled or deleted",
8
- version: "0.1.1",
8
+ version: "0.1.2",
9
9
  type: "source",
10
10
  dedupe: "unique", // Dedupe events based on the Google Calendar event ID
11
11
  methods: {
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-event-ended",
6
6
  name: "Event Ended",
7
7
  description: "Emits when an event ends",
8
- version: "0.1.1",
8
+ version: "0.1.2",
9
9
  type: "source",
10
10
  dedupe: "unique", // Dedupe events based on the Google Calendar event ID
11
11
  methods: {
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-event-start",
6
6
  name: "Event Start",
7
7
  description: "Emits a specified time before an event starts",
8
- version: "0.1.1",
8
+ version: "0.1.2",
9
9
  type: "source",
10
10
  dedupe: "unique", // Dedupe events based on the Google Calendar event ID
11
11
  methods: {
@@ -1,10 +1,11 @@
1
1
  import googleCalendar from "../../google_calendar.app.mjs";
2
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2
3
 
3
4
  export default {
4
5
  key: "google_calendar-new-calendar",
5
6
  name: "New Calendar",
6
7
  description: "Emit an event when a calendar is created.",
7
- version: "0.1.1",
8
+ version: "0.1.2",
8
9
  type: "source",
9
10
  props: {
10
11
  db: "$.service.db",
@@ -12,7 +13,7 @@ export default {
12
13
  timer: {
13
14
  type: "$.interface.timer",
14
15
  default: {
15
- intervalSeconds: 15 * 60,
16
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
16
17
  },
17
18
  },
18
19
  },
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-new-event",
6
6
  name: "New Event",
7
7
  description: "Emits when an event is created",
8
- version: "0.1.1",
8
+ version: "0.1.2",
9
9
  type: "source",
10
10
  dedupe: "unique", // Dedupe events based on the Google Calendar event ID
11
11
  methods: {
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-new-event-search",
6
6
  name: "Event Search",
7
7
  description: "Emit when an event is created that matches a search",
8
- version: "0.1.1",
8
+ version: "0.1.2",
9
9
  type: "source",
10
10
  dedupe: "unique", // Dedupe events based on the Google Calendar event ID
11
11
  props: {
@@ -5,7 +5,7 @@ export default {
5
5
  key: "google_calendar-new-or-updated-event",
6
6
  name: "New or Updated Event",
7
7
  description: "Emits when an event is created or updated (except when it's cancelled)",
8
- version: "0.1.1",
8
+ version: "0.1.2",
9
9
  type: "source",
10
10
  dedupe: "unique", // Dedupe events based on the Google Calendar event ID
11
11
  methods: {
@@ -1,12 +1,13 @@
1
1
  import { v4 as uuid } from "uuid";
2
2
  import googleCalendar from "../../google_calendar.app.mjs";
3
+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3
4
 
4
5
  export default {
5
6
  key: "google_calendar-new-or-updated-event-instant",
6
7
  type: "source",
7
8
  name: "New or Updated Event (Instant)",
8
9
  description: "Emit new calendar events when an event is created or updated (does not emit cancelled events)",
9
- version: "0.1.4",
10
+ version: "0.1.5",
10
11
  dedupe: "unique",
11
12
  props: {
12
13
  googleCalendar,
@@ -33,7 +34,7 @@ export default {
33
34
  description: "The Google Calendar API requires occasional renewal of push notification subscriptions. **This runs in the background, so you should not need to modify this schedule**.",
34
35
  type: "$.interface.timer",
35
36
  static: {
36
- intervalSeconds: 60 * 60 * 23,
37
+ intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
37
38
  },
38
39
  },
39
40
  },
@@ -0,0 +1,109 @@
1
+ import taskScheduler from "../../../pipedream/sources/new-scheduled-tasks/new-scheduled-tasks.mjs";
2
+ import googleCalendar from "../../google_calendar.app.mjs";
3
+ import { axios } from "@pipedream/platform";
4
+
5
+ const docLink = "https://pipedream.com/docs/examples/waiting-to-execute-next-step-of-workflow/#step-1-create-a-task-scheduler-event-source";
6
+
7
+ export default {
8
+ key: "google_calendar-upcoming-event-alert",
9
+ name: "Upcoming Event Alert",
10
+ description: `Triggers based on a time interval before an upcoming event in the calendar. This source uses Pipedream's Task Scheduler.
11
+ [See here](${docLink}) for more information and instructions for connecting your Pipedream account.`,
12
+ version: "0.0.1",
13
+ type: "source",
14
+ props: {
15
+ pipedream: taskScheduler.props.pipedream,
16
+ googleCalendar,
17
+ db: "$.service.db",
18
+ http: "$.interface.http",
19
+ calendarId: {
20
+ propDefinition: [
21
+ googleCalendar,
22
+ "calendarId",
23
+ ],
24
+ },
25
+ eventId: {
26
+ propDefinition: [
27
+ googleCalendar,
28
+ "eventId",
29
+ (c) => ({
30
+ calendarId: c.calendarId,
31
+ }),
32
+ ],
33
+ },
34
+ time: {
35
+ type: "integer",
36
+ label: "Minutes Before",
37
+ description: "Number of minutes to trigger before the start of the calendar event.",
38
+ min: 0,
39
+ },
40
+ },
41
+ hooks: {
42
+ async activate() {
43
+ // workaround - self call run() because selfSubscribe() can't be run on activate or deploy
44
+ // see selfSubscribe() method in pipedream/sources/new-scheduled-tasks/new-scheduled-tasks.mjs
45
+ await axios(this, {
46
+ url: this.http.endpoint,
47
+ method: "POST",
48
+ data: {
49
+ schedule: true,
50
+ },
51
+ });
52
+ },
53
+ async deactivate() {
54
+ const id = this._getScheduledEventId();
55
+ if (id && await this.deleteEvent({
56
+ body: {
57
+ id,
58
+ },
59
+ })) {
60
+ console.log("Cancelled scheduled event");
61
+ this._setScheduledEventId();
62
+ }
63
+ },
64
+ },
65
+ methods: {
66
+ ...taskScheduler.methods,
67
+ _getScheduledEventId() {
68
+ return this.db.get("scheduledEventId");
69
+ },
70
+ _setScheduledEventId(id) {
71
+ this.db.set("scheduledEventId", id);
72
+ },
73
+ _hasDeployed() {
74
+ const result = this.db.get("hasDeployed");
75
+ this.db.set("hasDeployed", true);
76
+ return result;
77
+ },
78
+ subtractMinutes(date, minutes) {
79
+ return date.getTime() - minutes * 60000;
80
+ },
81
+ },
82
+ async run(event) {
83
+ // self subscribe only on the first time
84
+ if (!this._hasDeployed()) {
85
+ await this.selfSubscribe();
86
+ }
87
+
88
+ // incoming scheduled event
89
+ if (event.$channel === this.selfChannel()) {
90
+ this.emitEvent(event, `Upcoming ${event.summary} event`);
91
+ this._setScheduledEventId();
92
+ return;
93
+ }
94
+
95
+ // received schedule command
96
+ if (event.body?.schedule) {
97
+ const calendarEvent = await this.googleCalendar.getEvent({
98
+ calendarId: this.calendarId,
99
+ eventId: this.eventId,
100
+ });
101
+
102
+ const startTime = new Date(calendarEvent.start.dateTime || calendarEvent.start.date);
103
+ const later = new Date(this.subtractMinutes(startTime, this.time));
104
+
105
+ const scheduledEventId = this.emitScheduleEvent(calendarEvent, later);
106
+ this._setScheduledEventId(scheduledEventId);
107
+ }
108
+ },
109
+ };