@pipedream/google_calendar 0.5.11 → 0.5.13

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.
@@ -5,7 +5,12 @@ export default {
5
5
  key: "google_calendar-add-attendees-to-event",
6
6
  name: "Add Attendees To Event",
7
7
  description: "Add attendees to an existing event. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#update)",
8
- version: "0.0.3",
8
+ version: "0.0.4",
9
+ annotations: {
10
+ destructiveHint: true,
11
+ openWorldHint: true,
12
+ readOnlyHint: false,
13
+ },
9
14
  type: "action",
10
15
  props: {
11
16
  googleCalendar,
@@ -7,7 +7,12 @@ export default {
7
7
  key: "google_calendar-create-event",
8
8
  name: "Create Event",
9
9
  description: "Create an event in a Google Calendar. [See the documentation](https://developers.google.com/calendar/api/v3/reference/events/insert)",
10
- version: "0.2.6",
10
+ version: "0.2.7",
11
+ annotations: {
12
+ destructiveHint: false,
13
+ openWorldHint: true,
14
+ readOnlyHint: false,
15
+ },
11
16
  type: "action",
12
17
  props: {
13
18
  googleCalendar,
@@ -4,7 +4,12 @@ export default {
4
4
  key: "google_calendar-delete-event",
5
5
  name: "Delete an Event",
6
6
  description: "Delete an event from a Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#delete)",
7
- version: "0.1.7",
7
+ version: "0.1.8",
8
+ annotations: {
9
+ destructiveHint: true,
10
+ openWorldHint: true,
11
+ readOnlyHint: false,
12
+ },
8
13
  type: "action",
9
14
  props: {
10
15
  googleCalendar,
@@ -4,7 +4,12 @@ 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.8",
7
+ version: "0.1.9",
8
+ annotations: {
9
+ destructiveHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: true,
12
+ },
8
13
  type: "action",
9
14
  props: {
10
15
  googleCalendar,
@@ -0,0 +1,58 @@
1
+ import googleCalendar from "../../google_calendar.app.mjs";
2
+ import constants from "../../common/constants.mjs";
3
+
4
+ const DEFAULT_CALENDAR_SAMPLE_LIMIT = 25;
5
+
6
+ export default {
7
+ key: "google_calendar-get-current-user",
8
+ name: "Get Current User",
9
+ description: "Retrieve information about the authenticated Google Calendar account, including the primary calendar (summary, timezone, ACL flags), a list of accessible calendars, user-level settings (timezone, locale, week start), and the color palette that controls events and calendars. Ideal for confirming which calendar account is in use, customizing downstream scheduling, or equipping LLMs with the user’s context (timezones, available calendars) prior to creating or updating events. [See the documentation](https://developers.google.com/calendar/api/v3/reference/calendars/get).",
10
+ version: "0.0.1",
11
+ type: "action",
12
+ annotations: {
13
+ destructiveHint: false,
14
+ openWorldHint: true,
15
+ readOnlyHint: true,
16
+ },
17
+ props: {
18
+ googleCalendar,
19
+ },
20
+ async run({ $ }) {
21
+ const [
22
+ primaryCalendar,
23
+ calendarList,
24
+ settings,
25
+ colors,
26
+ ] = await Promise.all([
27
+ this.googleCalendar.getCalendar({
28
+ calendarId: "primary",
29
+ }),
30
+ this.googleCalendar.listCalendars({
31
+ maxResults: DEFAULT_CALENDAR_SAMPLE_LIMIT,
32
+ }),
33
+ this.googleCalendar.requestHandler({
34
+ api: constants.API.SETTINGS.NAME,
35
+ method: constants.API.SETTINGS.METHOD.LIST,
36
+ }),
37
+ this.googleCalendar.requestHandler({
38
+ api: constants.API.COLORS.NAME,
39
+ method: constants.API.COLORS.METHOD.GET,
40
+ }),
41
+ ]);
42
+
43
+ const timezoneSetting = settings?.items?.find?.((setting) => setting.id === "timezone")?.value;
44
+ const localeSetting = settings?.items?.find?.((setting) => setting.id === "locale")?.value;
45
+
46
+ const summaryName = primaryCalendar?.summary || primaryCalendar?.id;
47
+ $.export("$summary", `Retrieved Google Calendar user ${summaryName}`);
48
+
49
+ return {
50
+ primaryCalendar,
51
+ calendars: calendarList?.items ?? [],
52
+ settings: settings?.items ?? [],
53
+ timezone: timezoneSetting || primaryCalendar?.timeZone,
54
+ locale: localeSetting,
55
+ colors,
56
+ };
57
+ },
58
+ };
@@ -4,7 +4,12 @@ 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.8",
7
+ version: "0.1.9",
8
+ annotations: {
9
+ destructiveHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: true,
12
+ },
8
13
  type: "action",
9
14
  props: {
10
15
  googleCalendar,
@@ -4,7 +4,12 @@ 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.8",
7
+ version: "0.1.9",
8
+ annotations: {
9
+ destructiveHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: true,
12
+ },
8
13
  type: "action",
9
14
  props: {
10
15
  googleCalendar,
@@ -6,7 +6,12 @@ export default {
6
6
  key: "google_calendar-list-events",
7
7
  name: "List Events",
8
8
  description: "Retrieve a list of event from the Google Calendar. [See the documentation](https://developers.google.com/calendar/api/v3/reference/events/list)",
9
- version: "0.0.8",
9
+ version: "0.0.9",
10
+ annotations: {
11
+ destructiveHint: false,
12
+ openWorldHint: true,
13
+ readOnlyHint: true,
14
+ },
10
15
  type: "action",
11
16
  props: {
12
17
  googleCalendar,
@@ -4,7 +4,12 @@ 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.8",
7
+ version: "0.1.9",
8
+ annotations: {
9
+ destructiveHint: false,
10
+ openWorldHint: true,
11
+ readOnlyHint: true,
12
+ },
8
13
  type: "action",
9
14
  props: {
10
15
  googleCalendar,
@@ -6,7 +6,12 @@ export default {
6
6
  key: "google_calendar-quick-add-event",
7
7
  name: "Add Quick Event",
8
8
  description: "Create a quick event to the Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#quickAdd)",
9
- version: "0.1.8",
9
+ version: "0.1.9",
10
+ annotations: {
11
+ destructiveHint: false,
12
+ openWorldHint: true,
13
+ readOnlyHint: false,
14
+ },
10
15
  type: "action",
11
16
  props: {
12
17
  googleCalendar,
@@ -6,7 +6,12 @@ export default {
6
6
  key: "google_calendar-update-event",
7
7
  name: "Update Event",
8
8
  description: "Update an event from Google Calendar. [See the documentation](https://googleapis.dev/nodejs/googleapis/latest/calendar/classes/Resource$Events.html#update)",
9
- version: "0.0.10",
9
+ version: "0.0.11",
10
+ annotations: {
11
+ destructiveHint: true,
12
+ openWorldHint: true,
13
+ readOnlyHint: false,
14
+ },
10
15
  type: "action",
11
16
  props: {
12
17
  googleCalendar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/google_calendar",
3
- "version": "0.5.11",
3
+ "version": "0.5.13",
4
4
  "description": "Pipedream Google_calendar Components",
5
5
  "main": "google_calendar.app.mjs",
6
6
  "keywords": [
@@ -11,7 +11,7 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "dependencies": {
13
13
  "@googleapis/calendar": "^1.0.2",
14
- "@pipedream/platform": "^3.0.0",
14
+ "@pipedream/platform": "^3.1.0",
15
15
  "color-2-name": "^1.4.4",
16
16
  "lodash.get": "^4.4.2",
17
17
  "moment-timezone": "^0.5.33",
@@ -0,0 +1,147 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import { v4 as uuid } from "uuid";
3
+
4
+ export default {
5
+ methods: {
6
+ async _makeAPIRequest({
7
+ $ = this, apiKey, ...opts
8
+ }) {
9
+ if (!opts.headers) opts.headers = {};
10
+ opts.headers["Authorization"] = `Bearer ${apiKey}`;
11
+ opts.headers["Content-Type"] = "application/json";
12
+ opts.headers["user-agent"] = "@PipedreamHQ/pipedream v0.1";
13
+ const { path } = opts;
14
+ delete opts.path;
15
+ opts.url = `https://api.pipedream.com/v1${path[0] === "/"
16
+ ? ""
17
+ : "/"
18
+ }${path}`;
19
+ return axios($, opts);
20
+ },
21
+ selfChannel() {
22
+ return "self";
23
+ },
24
+ queuedEventsChannel() {
25
+ return "$in";
26
+ },
27
+ async subscribe(emitter_id, listener_id, event_name = null, apiKey) {
28
+ let params = {
29
+ emitter_id,
30
+ listener_id,
31
+ };
32
+ if (event_name) {
33
+ params.event_name = event_name;
34
+ }
35
+ return await this._makeAPIRequest({
36
+ method: "POST",
37
+ path: "/subscriptions",
38
+ params,
39
+ apiKey,
40
+ });
41
+ },
42
+ async selfSubscribe(apiKey) {
43
+ const isSubscribedToSelf = this.db.get("isSubscribedToSelf");
44
+ if (!isSubscribedToSelf) {
45
+ const componentId = process.env.PD_COMPONENT;
46
+ const selfChannel = this.selfChannel();
47
+ console.log(`Subscribing to ${selfChannel} channel for event source`);
48
+ console.log(
49
+ await this.subscribe(componentId, componentId, selfChannel, apiKey),
50
+ );
51
+ this.db.set("isSubscribedToSelf", true);
52
+ }
53
+ },
54
+ emitScheduleEvent(event, timestamp) {
55
+ const selfChannel = this.selfChannel();
56
+ const epoch = Date.parse(timestamp);
57
+ const $id = uuid();
58
+
59
+ console.log(`Scheduled event to emit on: ${new Date(epoch)}`);
60
+
61
+ this.$emit(
62
+ {
63
+ ...event,
64
+ $channel: selfChannel,
65
+ $id,
66
+ },
67
+ {
68
+ name: selfChannel,
69
+ id: $id,
70
+ delivery_ts: epoch,
71
+ },
72
+ );
73
+
74
+ return $id;
75
+ },
76
+ async deleteScheduledEvent(event, apiKey) {
77
+ const componentId = process.env.PD_COMPONENT;
78
+ const inChannel = this.queuedEventsChannel();
79
+
80
+ // The user must pass a scheduled event UUID they'd like to cancel
81
+ // We lookup the event by ID and delete it
82
+ const { id } = event.body;
83
+
84
+ // List events in the $in channel - the queue of scheduled events, to be emitted in the future
85
+ const events = await this.listEvents(
86
+ componentId,
87
+ inChannel,
88
+ apiKey,
89
+ );
90
+ console.log("Events: ", events);
91
+
92
+ // Find the event in the list by id
93
+ const eventToCancel = events.data.find((e) => {
94
+ const { metadata } = e;
95
+ return metadata.id === id;
96
+ });
97
+
98
+ console.log("Event to cancel: ", eventToCancel);
99
+
100
+ if (!eventToCancel) {
101
+ console.log(`No event with ${id} found`);
102
+ return false;
103
+ }
104
+
105
+ // Delete the event
106
+ await this.deleteEvent(
107
+ componentId,
108
+ eventToCancel.id,
109
+ inChannel,
110
+ apiKey,
111
+ );
112
+ return true;
113
+ },
114
+ async listEvents(dcID, event_name, apiKey) {
115
+ return await this._makeAPIRequest({
116
+ path: `/sources/${dcID}/event_summaries`,
117
+ params: {
118
+ event_name,
119
+ },
120
+ apiKey,
121
+ });
122
+ },
123
+ async deleteEvent(dcID, eventID, event_name, apiKey) {
124
+ return await this._makeAPIRequest({
125
+ method: "DELETE",
126
+ path: `/sources/${dcID}/events`,
127
+ params: {
128
+ start_id: eventID,
129
+ end_id: eventID,
130
+ event_name,
131
+ },
132
+ apiKey,
133
+ });
134
+ },
135
+ emitEvent(event, summary) {
136
+ const id = event.$id;
137
+ delete event.$channel;
138
+ delete event.$id;
139
+
140
+ this.$emit(event, {
141
+ summary: summary ?? JSON.stringify(event),
142
+ id,
143
+ ts: +new Date(),
144
+ });
145
+ },
146
+ },
147
+ };
@@ -1,20 +1,23 @@
1
- import taskScheduler from "../../../pipedream/sources/new-scheduled-tasks/new-scheduled-tasks.mjs";
2
1
  import googleCalendar from "../../google_calendar.app.mjs";
2
+ import taskScheduler from "../common/taskScheduler.mjs";
3
3
  import sampleEmit from "./test-event.mjs";
4
4
 
5
5
  export default {
6
6
  key: "google_calendar-upcoming-event-alert",
7
7
  name: "New Upcoming Event Alert",
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
- [See the documentation](https://pipedream.com/docs/examples/waiting-to-execute-next-step-of-workflow/#step-1-create-a-task-scheduler-event-source)
10
- for more information and instructions for connecting your Pipedream account.`,
11
- version: "0.0.10",
8
+ description: "Emit new event based on a time interval before an upcoming event in the calendar.",
9
+ version: "0.1.0",
12
10
  type: "source",
13
11
  props: {
14
- pipedream: taskScheduler.props.pipedream,
15
12
  googleCalendar,
16
13
  db: "$.service.db",
17
14
  http: "$.interface.http",
15
+ pipedreamApiKey: {
16
+ type: "string",
17
+ label: "Pipedream API Key",
18
+ description: "[Click here to find your Pipedream API key](https://pipedream.com/settings/user)",
19
+ secret: true,
20
+ },
18
21
  calendarId: {
19
22
  propDefinition: [
20
23
  googleCalendar,
@@ -55,11 +58,11 @@ export default {
55
58
  return;
56
59
  }
57
60
  for (const id of ids) {
58
- if (await this.deleteEvent({
61
+ if (await this.deleteScheduledEvent({
59
62
  body: {
60
63
  id,
61
64
  },
62
- })) {
65
+ }, this.pipedreamApiKey)) {
63
66
  console.log("Cancelled scheduled event");
64
67
  }
65
68
  }
@@ -112,7 +115,7 @@ export default {
112
115
  async run(event) {
113
116
  // self subscribe only on the first time
114
117
  if (!this._hasDeployed()) {
115
- await this.selfSubscribe();
118
+ await this.selfSubscribe(this.pipedreamApiKey);
116
119
  }
117
120
 
118
121
  const scheduledEventIds = this._getScheduledEventIds() || [];
@@ -121,7 +124,9 @@ export default {
121
124
  if (event.$channel === this.selfChannel()) {
122
125
  const remainingScheduledEventIds = scheduledEventIds.filter((id) => id !== event["$id"]);
123
126
  this._setScheduledEventIds(remainingScheduledEventIds);
124
- this.emitEvent(event, `Upcoming ${event.summary} event`);
127
+ this.emitEvent(event, `Upcoming ${event.summary
128
+ ? event.summary + " "
129
+ : ""}event`);
125
130
  return;
126
131
  }
127
132