@pipedream/google_calendar 0.3.8 → 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.8",
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"
@@ -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
+ };