@pipedream/microsoft_outlook_calendar 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Overview
2
+
3
+ With the Microsoft Outlook API, you can build a wide range of applications and
4
+ services that work with Outlook. The Microsoft Outlook Calendar app helps you
5
+ manage your calendar and schedule appointments.
@@ -0,0 +1,111 @@
1
+ import microsoftOutlook from "../../microsoft_outlook_calendar.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook_calendar-create-calendar-event",
6
+ version: "0.0.6",
7
+ name: "Create Calendar Event",
8
+ description: "Create an event in the user's default calendar. [See the documentation](https://docs.microsoft.com/en-us/graph/api/user-post-events)",
9
+ props: {
10
+ microsoftOutlook,
11
+ subject: {
12
+ label: "Subject",
13
+ description: "Subject of the event",
14
+ type: "string",
15
+ },
16
+ contentType: {
17
+ propDefinition: [
18
+ microsoftOutlook,
19
+ "contentType",
20
+ ],
21
+ },
22
+ content: {
23
+ propDefinition: [
24
+ microsoftOutlook,
25
+ "content",
26
+ ],
27
+ description: "Content",
28
+ },
29
+ timeZone: {
30
+ propDefinition: [
31
+ microsoftOutlook,
32
+ "timeZone",
33
+ ],
34
+ },
35
+ start: {
36
+ propDefinition: [
37
+ microsoftOutlook,
38
+ "start",
39
+ ],
40
+ },
41
+ end: {
42
+ propDefinition: [
43
+ microsoftOutlook,
44
+ "end",
45
+ ],
46
+ },
47
+ attendees: {
48
+ propDefinition: [
49
+ microsoftOutlook,
50
+ "attendees",
51
+ ],
52
+ },
53
+ location: {
54
+ propDefinition: [
55
+ microsoftOutlook,
56
+ "location",
57
+ ],
58
+ },
59
+ isOnlineMeeting: {
60
+ propDefinition: [
61
+ microsoftOutlook,
62
+ "isOnlineMeeting",
63
+ ],
64
+ },
65
+ expand: {
66
+ propDefinition: [
67
+ microsoftOutlook,
68
+ "expand",
69
+ ],
70
+ description: "Additional event details, [See object definition](https://docs.microsoft.com/en-us/graph/api/resources/event)",
71
+ },
72
+ },
73
+ async run({ $ }) {
74
+ //RegExp to check time strings(yyyy-MM-ddThh:mm:ss)
75
+ const re = /^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)$/;
76
+ if (!re.test(this.start) || !re.test(this.start)) {
77
+ throw new Error("Please provide both start and end props in 'yyyy-MM-ddThh:mm:ss'");
78
+ }
79
+ const data = {
80
+ subject: this.subject,
81
+ body: {
82
+ contentType: this.contentType ?? "HTML",
83
+ content: this.content,
84
+ },
85
+ start: {
86
+ dateTime: this.start,
87
+ timeZone: this.timeZone,
88
+ },
89
+ end: {
90
+ dateTime: this.end,
91
+ timeZone: this.timeZone,
92
+ },
93
+ location: {
94
+ displayName: this.location,
95
+ },
96
+ attendees: this.attendees.map((at) => ({
97
+ emailAddress: {
98
+ address: at,
99
+ },
100
+ })),
101
+ isOnlineMeeting: this.isOnlineMeeting,
102
+ ...this.expand,
103
+ };
104
+ const response = await this.microsoftOutlook.createCalendarEvent({
105
+ $,
106
+ data,
107
+ });
108
+ $.export("$summary", "Calendar event has been created.");
109
+ return response;
110
+ },
111
+ };
@@ -0,0 +1,28 @@
1
+ import microsoftOutlook from "../../microsoft_outlook_calendar.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook_calendar-delete-calendar-event",
6
+ version: "0.0.1",
7
+ name: "Delete Calendar Event",
8
+ description: "Delete an event in the user's default calendar. [See the documentation](https://learn.microsoft.com/en-us/graph/api/event-delete?view=graph-rest-1.0&tabs=http)",
9
+ props: {
10
+ microsoftOutlook,
11
+ eventId: {
12
+ propDefinition: [
13
+ microsoftOutlook,
14
+ "eventId",
15
+ ],
16
+ },
17
+ },
18
+ async run({ $ }) {
19
+ const response = await this.microsoftOutlook.deleteCalendarEvent({
20
+ $,
21
+ eventId: this.eventId,
22
+ });
23
+
24
+ $.export("$summary", `Successfully deleted calendar event with ID ${this.eventId}`);
25
+
26
+ return response;
27
+ },
28
+ };
@@ -0,0 +1,142 @@
1
+ import microsoftOutlook from "../../microsoft_outlook_calendar.app.mjs";
2
+
3
+ export default {
4
+ type: "action",
5
+ key: "microsoft_outlook_calendar-update-calendar-event",
6
+ version: "0.0.1",
7
+ name: "Update Calendar Event",
8
+ description: "Update an event in the user's default calendar. [See the documentation](https://learn.microsoft.com/en-us/graph/api/event-update?view=graph-rest-1.0&tabs=http)",
9
+ props: {
10
+ microsoftOutlook,
11
+ eventId: {
12
+ propDefinition: [
13
+ microsoftOutlook,
14
+ "eventId",
15
+ ],
16
+ },
17
+ subject: {
18
+ label: "Subject",
19
+ description: "Subject of the event",
20
+ type: "string",
21
+ optional: true,
22
+
23
+ },
24
+ contentType: {
25
+ propDefinition: [
26
+ microsoftOutlook,
27
+ "contentType",
28
+ ],
29
+ optional: true,
30
+ },
31
+ content: {
32
+ propDefinition: [
33
+ microsoftOutlook,
34
+ "content",
35
+ ],
36
+ description: "Content",
37
+ optional: true,
38
+ },
39
+ timeZone: {
40
+ propDefinition: [
41
+ microsoftOutlook,
42
+ "timeZone",
43
+ ],
44
+ optional: true,
45
+ },
46
+ start: {
47
+ propDefinition: [
48
+ microsoftOutlook,
49
+ "start",
50
+ ],
51
+ optional: true,
52
+ },
53
+ end: {
54
+ propDefinition: [
55
+ microsoftOutlook,
56
+ "end",
57
+ ],
58
+ optional: true,
59
+ },
60
+ attendees: {
61
+ propDefinition: [
62
+ microsoftOutlook,
63
+ "attendees",
64
+ ],
65
+ optional: true,
66
+ },
67
+ location: {
68
+ propDefinition: [
69
+ microsoftOutlook,
70
+ "location",
71
+ ],
72
+ optional: true,
73
+ },
74
+ isOnlineMeeting: {
75
+ propDefinition: [
76
+ microsoftOutlook,
77
+ "isOnlineMeeting",
78
+ ],
79
+ optional: true,
80
+ },
81
+ expand: {
82
+ propDefinition: [
83
+ microsoftOutlook,
84
+ "expand",
85
+ ],
86
+ description: "Additional event details, [See object definition](https://docs.microsoft.com/en-us/graph/api/resources/event)",
87
+ optional: true,
88
+ },
89
+ },
90
+ async run({ $ }) {
91
+ const data = {
92
+ subject: this.subject,
93
+ isOnlineMeeting: this.isOnlineMeeting,
94
+ ...this.expand,
95
+ };
96
+
97
+ if (this.location) {
98
+ data.location = {
99
+ displayName: this.location,
100
+ };
101
+ }
102
+
103
+ if (this.contentType && this.content) {
104
+ data.body = {
105
+ contentType: this.contentType ?? "HTML",
106
+ content: this.content,
107
+ };
108
+ }
109
+
110
+ if (this.start && this.timeZone) {
111
+ data.start = {
112
+ dateTime: this.start,
113
+ timeZone: this.timeZone,
114
+
115
+ };
116
+ }
117
+ if (this.end && this.timeZone) {
118
+ data.end = {
119
+ dateTime: this.end,
120
+ timeZone: this.timeZone,
121
+ };
122
+ }
123
+
124
+ if (this.attendees) {
125
+ data.attendees = this.attendees.map((at) => ({
126
+ emailAddress: {
127
+ address: at,
128
+ },
129
+ }));
130
+ }
131
+
132
+ const response = await this.microsoftOutlook.updateCalendarEvent({
133
+ $,
134
+ eventId: this.eventId,
135
+ data,
136
+ });
137
+
138
+ $.export("$summary", `Successfully updated calendar event with ID ${response.id}`);
139
+
140
+ return response;
141
+ },
142
+ };
@@ -0,0 +1,184 @@
1
+ import { axios } from "@pipedream/platform";
2
+
3
+ export default {
4
+ type: "app",
5
+ app: "microsoft_outlook_calendar",
6
+ propDefinitions: {
7
+ eventId: {
8
+ label: "Event ID",
9
+ description: "The event ID",
10
+ type: "string",
11
+ async options() {
12
+ const { value: events } = await this.listCalendarEvents();
13
+
14
+ return events.map((event) => ({
15
+ label: event.subject,
16
+ value: event.id,
17
+ }));
18
+ },
19
+ },
20
+ contentType: {
21
+ label: "Content Type",
22
+ description: "Content type (default `text`)",
23
+ type: "string",
24
+ optional: true,
25
+ options: [
26
+ "text",
27
+ "html",
28
+ ],
29
+ default: "text",
30
+ },
31
+ content: {
32
+ label: "Content",
33
+ description: "Content of the email in text or html format",
34
+ type: "string",
35
+ optional: true,
36
+ },
37
+ timeZone: {
38
+ label: "Time Zone",
39
+ description: "Time zone of the event in supported time zones, [See the docs](https://docs.microsoft.com/en-us/graph/api/outlookuser-supportedtimezones)",
40
+ type: "string",
41
+ async options() {
42
+ const timeZonesResponse = await this.getSupportedTimeZones();
43
+ return timeZonesResponse.value.map((tz) => ({
44
+ label: tz.displayName,
45
+ value: tz.alias,
46
+ }));
47
+ },
48
+ },
49
+ start: {
50
+ label: "Start",
51
+ description: "Start date-time (yyyy-MM-ddThh:mm:ss) e.g. '2022-04-15T11:20:00'",
52
+ type: "string",
53
+ },
54
+ end: {
55
+ label: "End",
56
+ description: "End date-time (yyyy-MM-ddThh:mm:ss) e.g. '2022-04-15T13:30:00'",
57
+ type: "string",
58
+ },
59
+ attendees: {
60
+ label: "Attendees",
61
+ description: "Array of email addresses",
62
+ type: "string[]",
63
+ },
64
+ location: {
65
+ label: "Location",
66
+ description: "Location of the event",
67
+ type: "string",
68
+ optional: true,
69
+ },
70
+ isOnlineMeeting: {
71
+ label: "Is Online Meeting",
72
+ description: "If it is online meeting or not",
73
+ type: "boolean",
74
+ optional: true,
75
+ },
76
+ expand: {
77
+ label: "Expand",
78
+ description: "Additional properties",
79
+ type: "object",
80
+ optional: true,
81
+ },
82
+ },
83
+ methods: {
84
+ _getUrl(path) {
85
+ return `https://graph.microsoft.com/v1.0${path}`;
86
+ },
87
+ _getHeaders() {
88
+ return {
89
+ "Authorization": `Bearer ${this.$auth.oauth_access_token}`,
90
+ "accept": "application/json",
91
+ "Content-Type": "application/json",
92
+ };
93
+ },
94
+ async _makeRequest({
95
+ $,
96
+ path,
97
+ headers,
98
+ ...otherConfig
99
+ } = {}) {
100
+ const config = {
101
+ url: this._getUrl(path),
102
+ headers: this._getHeaders(headers),
103
+ ...otherConfig,
104
+ };
105
+ return axios($ ?? this, config);
106
+ },
107
+ async createHook(args = {}) {
108
+ const response = await this._makeRequest({
109
+ method: "POST",
110
+ path: "/subscriptions",
111
+ ...args,
112
+ });
113
+ return response;
114
+ },
115
+ async renewHook({
116
+ hookId,
117
+ ...args
118
+ } = {}) {
119
+ return this._makeRequest({
120
+ method: "PATCH",
121
+ path: `/subscriptions/${hookId}`,
122
+ ...args,
123
+ });
124
+ },
125
+ async deleteHook({
126
+ hookId,
127
+ ...args
128
+ } = {}) {
129
+ return this._makeRequest({
130
+ method: "DELETE",
131
+ path: `/subscriptions/${hookId}`,
132
+ ...args,
133
+ });
134
+ },
135
+ async getSupportedTimeZones() {
136
+ return this._makeRequest({
137
+ method: "GET",
138
+ path: "/me/outlook/supportedTimeZones",
139
+ });
140
+ },
141
+ async createCalendarEvent(args = {}) {
142
+ return this._makeRequest({
143
+ method: "POST",
144
+ path: "/me/events",
145
+ ...args,
146
+ });
147
+ },
148
+ async updateCalendarEvent({
149
+ eventId, ...args
150
+ }) {
151
+ return this._makeRequest({
152
+ method: "PATCH",
153
+ path: `/me/events/${eventId}`,
154
+ ...args,
155
+ });
156
+ },
157
+ async deleteCalendarEvent({
158
+ eventId, ...args
159
+ }) {
160
+ return this._makeRequest({
161
+ method: "DELETE",
162
+ path: `/me/events/${eventId}`,
163
+ ...args,
164
+ });
165
+ },
166
+ async listCalendarEvents(args = {}) {
167
+ return this._makeRequest({
168
+ method: "GET",
169
+ path: "/me/events",
170
+ ...args,
171
+ });
172
+ },
173
+ async getCalendarEvent({
174
+ eventId,
175
+ ...args
176
+ } = {}) {
177
+ return this._makeRequest({
178
+ method: "GET",
179
+ path: `/me/events/${eventId}`,
180
+ ...args,
181
+ });
182
+ },
183
+ },
184
+ };
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@pipedream/microsoft_outlook_calendar",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Pipedream Microsoft Outlook Calendar Components",
5
- "main": "dist/app/microsoft_outlook_calendar.app.mjs",
5
+ "main": "microsoft_outlook_calendar.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
- "microsoft_outlook_calendar"
9
- ],
10
- "files": [
11
- "dist"
8
+ "microsoft_outlook_calendar",
9
+ "microsoft",
10
+ "outlook"
12
11
  ],
13
12
  "homepage": "https://pipedream.com/apps/microsoft_outlook_calendar",
14
13
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
14
+ "dependencies": {
15
+ "@pipedream/platform": "^1.5.1"
16
+ },
15
17
  "publishConfig": {
16
18
  "access": "public"
17
19
  }
@@ -0,0 +1,10 @@
1
+ import microsoftOutlook from "../microsoft_outlook_calendar.app.mjs";
2
+ import common from "../../microsoft_outlook/sources/common.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ props: {
7
+ ...common.props,
8
+ microsoftOutlook,
9
+ },
10
+ };
@@ -0,0 +1,56 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "microsoft_outlook_calendar-new-calendar-event",
6
+ name: "New Calendar Event (Instant)",
7
+ description: "Emit new event when a new Calendar event is created",
8
+ version: "0.0.7",
9
+ type: "source",
10
+ hooks: {
11
+ ...common.hooks,
12
+ async activate() {
13
+ await this.activate({
14
+ changeType: "created",
15
+ resource: "/me/events",
16
+ });
17
+ },
18
+ async deactivate() {
19
+ await this.deactivate();
20
+ },
21
+ },
22
+ methods: {
23
+ ...common.methods,
24
+ async getSampleEvents({ pageSize }) {
25
+ return this.microsoftOutlook.listCalendarEvents({
26
+ params: {
27
+ $top: pageSize,
28
+ $orderby: "createdDateTime desc",
29
+ },
30
+ });
31
+ },
32
+ emitEvent(item) {
33
+ this.$emit({
34
+ message: item,
35
+ }, this.generateMeta(item));
36
+ },
37
+ generateMeta(item) {
38
+ return {
39
+ id: item.id,
40
+ summary: `New calendar event (ID:${item.id})`,
41
+ ts: Date.parse(item.createdDateTime),
42
+ };
43
+ },
44
+ },
45
+ async run(event) {
46
+ await this.run({
47
+ event,
48
+ emitFn: async ({ resourceId } = {}) => {
49
+ const item = await this.microsoftOutlook.getCalendarEvent({
50
+ eventId: resourceId,
51
+ });
52
+ this.emitEvent(item);
53
+ },
54
+ });
55
+ },
56
+ };
@@ -0,0 +1,92 @@
1
+ import common from "../common.mjs";
2
+ import taskScheduler from "../../../pipedream/sources/new-scheduled-tasks/new-scheduled-tasks.mjs";
3
+
4
+ export default {
5
+ ...common,
6
+ key: "microsoft_outlook_calendar-new-upcoming-event",
7
+ name: "New Upcoming Calendar Event",
8
+ description: "Emit new event when a Calendar event is upcoming, this source is using `reminderMinutesBeforeStart` property of the event to determine the time it should emit.",
9
+ version: "0.0.3",
10
+ type: "source",
11
+ props: {
12
+ ...common.props,
13
+ pipedream: taskScheduler.props.pipedream,
14
+ },
15
+ hooks: {
16
+ ...common.hooks,
17
+ async activate() {
18
+ await this.activate({
19
+ changeType: "updated",
20
+ resource: "/me/events",
21
+ });
22
+ },
23
+ async deactivate() {
24
+ await this.deactivate();
25
+ },
26
+ },
27
+ methods: {
28
+ ...taskScheduler.methods,
29
+ ...common.methods,
30
+ _hasDeployed() {
31
+ const result = this.db.get("hasDeployed");
32
+ this.db.set("hasDeployed", true);
33
+ return result;
34
+ },
35
+ subtractMinutes(date, minutes) {
36
+ return date.getTime() - minutes * 60000;
37
+ },
38
+ async getSampleEvents({ pageSize }) {
39
+ return this.microsoftOutlook.listCalendarEvents({
40
+ params: {
41
+ $top: pageSize,
42
+ $orderby: "lastModifiedDateTime desc",
43
+ },
44
+ });
45
+ },
46
+ emitEvent(item) {
47
+ this.$emit({
48
+ message: item,
49
+ }, this.generateMeta(item));
50
+ },
51
+ generateMeta(item) {
52
+ return {
53
+ id: item.id,
54
+ summary: `Upcoming event - ${item.subject}`,
55
+ ts: +Date.parse(item.createdDateTime),
56
+ };
57
+ },
58
+ },
59
+ async run(event) {
60
+ if (event.$channel === this.selfChannel()) {
61
+ const item = await this.microsoftOutlook.getCalendarEvent({
62
+ eventId: event.eventId,
63
+ });
64
+ // checking if the event was modified after this scheduling
65
+ if (item.lastModifiedDateTime === event.lastModifiedControl) {
66
+ this.emitEvent(item);
67
+ }
68
+ return;
69
+ }
70
+ await this.run({
71
+ event,
72
+ emitFn: async ({ resourceId } = {}) => {
73
+ if (!this._hasDeployed()) {
74
+ await this.selfSubscribe();
75
+ }
76
+ const item = await this.microsoftOutlook.getCalendarEvent({
77
+ eventId: resourceId,
78
+ });
79
+ if (event.$channel !== this.selfChannel()) {
80
+ const startTime = new Date(item.start.dateTime || item.start.date);
81
+ const reminderMinutesBeforeStart = item.reminderMinutesBeforeStart || 15;
82
+ const later = new Date(this.subtractMinutes(startTime, reminderMinutesBeforeStart));
83
+ const newEvent = {
84
+ lastModifiedControl: item.lastModifiedDateTime,
85
+ eventId: resourceId,
86
+ };
87
+ this.emitScheduleEvent(newEvent, later);
88
+ }
89
+ },
90
+ });
91
+ },
92
+ };
@@ -0,0 +1,56 @@
1
+ import common from "../common.mjs";
2
+
3
+ export default {
4
+ ...common,
5
+ key: "microsoft_outlook_calendar-updated-calendar-event",
6
+ name: "New Calendar Event Update (Instant)",
7
+ description: "Emit new event when a Calendar event is updated",
8
+ version: "0.0.7",
9
+ type: "source",
10
+ hooks: {
11
+ ...common.hooks,
12
+ async activate() {
13
+ await this.activate({
14
+ changeType: "updated",
15
+ resource: "/me/events",
16
+ });
17
+ },
18
+ async deactivate() {
19
+ await this.deactivate();
20
+ },
21
+ },
22
+ methods: {
23
+ ...common.methods,
24
+ async getSampleEvents({ pageSize }) {
25
+ return this.microsoftOutlook.listCalendarEvents({
26
+ params: {
27
+ $top: pageSize,
28
+ $orderby: "lastModifiedDateTime desc",
29
+ },
30
+ });
31
+ },
32
+ emitEvent(item) {
33
+ this.$emit({
34
+ message: item,
35
+ }, this.generateMeta(item));
36
+ },
37
+ generateMeta(item) {
38
+ return {
39
+ id: item.id,
40
+ summary: `Calendar event updated (ID:${item.id})`,
41
+ ts: Date.parse(item.createdDateTime),
42
+ };
43
+ },
44
+ },
45
+ async run(event) {
46
+ await this.run({
47
+ event,
48
+ emitFn: async ({ resourceId } = {}) => {
49
+ const item = await this.microsoftOutlook.getCalendarEvent({
50
+ eventId: resourceId,
51
+ });
52
+ this.emitEvent(item);
53
+ },
54
+ });
55
+ },
56
+ };