forked from activepieces/activepieces
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request activepieces#6307 from volubileai/outlook
feat(microsoft-outlook-calendar): create/delete/list events
- Loading branch information
Showing
12 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/pieces/community/microsoft-outlook-calendar/.eslintrc.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"extends": [ | ||
"../../../../.eslintrc.base.json" | ||
], | ||
"ignorePatterns": [ | ||
"!**/*" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx", | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
} | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/pieces/community/microsoft-outlook-calendar/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# pieces-microsoft-outlook-calendar | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build pieces-microsoft-outlook-calendar` to build the library. |
4 changes: 4 additions & 0 deletions
4
packages/pieces/community/microsoft-outlook-calendar/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-microsoft-outlook-calendar", | ||
"version": "0.0.1" | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/pieces/community/microsoft-outlook-calendar/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "pieces-microsoft-outlook-calendar", | ||
"$schema": "../../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/pieces/community/microsoft-outlook-calendar/src", | ||
"projectType": "library", | ||
"release": { | ||
"version": { | ||
"generatorOptions": { | ||
"packageRoot": "dist/{projectRoot}", | ||
"currentVersionResolver": "git-tag" | ||
} | ||
} | ||
}, | ||
"tags": [], | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": [ | ||
"{options.outputPath}" | ||
], | ||
"options": { | ||
"outputPath": "dist/packages/pieces/community/microsoft-outlook-calendar", | ||
"tsConfig": "packages/pieces/community/microsoft-outlook-calendar/tsconfig.lib.json", | ||
"packageJson": "packages/pieces/community/microsoft-outlook-calendar/package.json", | ||
"main": "packages/pieces/community/microsoft-outlook-calendar/src/index.ts", | ||
"assets": [ | ||
"packages/pieces/community/microsoft-outlook-calendar/*.md" | ||
], | ||
"buildableProjectDepsInPackageJsonType": "dependencies", | ||
"updateBuildableProjectDepsInPackageJson": true | ||
} | ||
}, | ||
"nx-release-publish": { | ||
"options": { | ||
"packageRoot": "dist/{projectRoot}" | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
] | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/pieces/community/microsoft-outlook-calendar/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
createPiece, | ||
OAuth2PropertyValue, | ||
PieceAuth, | ||
} from '@activepieces/pieces-framework'; | ||
import { createEventAction } from './lib/actions/create-event'; | ||
import { listEventsAction } from './lib/actions/list-events'; | ||
import { createCustomApiCallAction } from '@activepieces/pieces-common'; | ||
import { outlookCalendarCommon } from './lib/common/common'; | ||
import { deleteEventAction } from './lib/actions/delete-event'; | ||
import { PieceCategory } from '@activepieces/shared'; | ||
|
||
export const outlookCalendarAuth = PieceAuth.OAuth2({ | ||
description: 'Authentication for Microsoft Outlook', | ||
authUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize', | ||
tokenUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/token', | ||
required: true, | ||
scope: ['User.Read', 'Calendars.ReadWrite'], | ||
}); | ||
|
||
export const microsoftOutlookCalendar = createPiece({ | ||
displayName: "Microsoft Outlook Calendar", | ||
description: 'Calendar software by Microsoft', | ||
auth: outlookCalendarAuth, | ||
minimumSupportedRelease: '0.30.0', | ||
logoUrl: "https://cdn.activepieces.com/pieces/microsoft-outlook.png", | ||
categories: [PieceCategory.PRODUCTIVITY], | ||
authors: ['antonyvigouret'], | ||
actions: [ | ||
createEventAction, | ||
deleteEventAction, | ||
listEventsAction, | ||
createCustomApiCallAction({ | ||
auth: outlookCalendarAuth, | ||
baseUrl() { | ||
return outlookCalendarCommon.baseUrl; | ||
}, | ||
authMapping: async (auth) => { | ||
return { | ||
Authorization: `Bearer ${(auth as OAuth2PropertyValue).access_token}`, | ||
}; | ||
}, | ||
}), | ||
], | ||
triggers: [], | ||
}); |
73 changes: 73 additions & 0 deletions
73
packages/pieces/community/microsoft-outlook-calendar/src/lib/actions/create-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { | ||
AuthenticationType, | ||
httpClient, | ||
HttpMethod, | ||
HttpRequest, | ||
} from '@activepieces/pieces-common'; | ||
import { outlookCalendarAuth } from '../..'; | ||
import { outlookCalendarCommon } from '../common/common'; | ||
import dayjs from 'dayjs'; | ||
|
||
export const createEventAction = createAction({ | ||
auth: outlookCalendarAuth, | ||
name: 'create_event', | ||
description: 'Create a new event in a calendar', | ||
displayName: 'Create a new event in a calendar', | ||
props: { | ||
calendarId: outlookCalendarCommon.calendarDropdown, | ||
title: Property.ShortText({ | ||
displayName: 'Title of the event', | ||
required: true, | ||
}), | ||
start: Property.DateTime({ | ||
displayName: 'Start date time of the event', | ||
required: true, | ||
}), | ||
end: Property.DateTime({ | ||
displayName: 'End date time of the event', | ||
description: "By default it'll be 30 min post start time", | ||
required: false, | ||
}), | ||
timezone: outlookCalendarCommon.timezoneDropdown, | ||
location: Property.ShortText({ | ||
displayName: 'Location', | ||
required: false, | ||
}), | ||
}, | ||
async run({ propsValue, auth }) { | ||
const startDateTime = dayjs(propsValue.start).format('YYYY-MM-DDTHH:mm:ss'); | ||
const endTime = propsValue.end | ||
? propsValue.end | ||
: dayjs(startDateTime).add(30, 'm'); | ||
const endDateTime = dayjs(endTime).format('YYYY-MM-DDTHH:mm:ss'); | ||
|
||
const request: HttpRequest = { | ||
method: HttpMethod.POST, | ||
url: `${outlookCalendarCommon.baseUrl}/calendars/${propsValue.calendarId}/events`, | ||
body: { | ||
subject: propsValue.title, | ||
body: {}, | ||
start: { | ||
dateTime: startDateTime, | ||
timeZone: propsValue.timezone, | ||
}, | ||
end: { | ||
dateTime: endDateTime, | ||
timeZone: propsValue.timezone, | ||
}, | ||
location: { | ||
displayName: propsValue.location, | ||
}, | ||
}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: auth['access_token'], | ||
}, | ||
}; | ||
|
||
const response = await httpClient.sendRequest(request); | ||
|
||
return response.body; | ||
}, | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/pieces/community/microsoft-outlook-calendar/src/lib/actions/delete-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { | ||
AuthenticationType, | ||
httpClient, | ||
HttpMethod, | ||
HttpRequest, | ||
} from '@activepieces/pieces-common'; | ||
import { outlookCalendarAuth } from '../..'; | ||
import { outlookCalendarCommon } from '../common/common'; | ||
|
||
export const deleteEventAction = createAction({ | ||
auth: outlookCalendarAuth, | ||
name: 'delete_event', | ||
description: 'Delete an event in a calendar', | ||
displayName: 'Delete an event in a calendar', | ||
props: { | ||
calendarId: outlookCalendarCommon.calendarDropdown, | ||
eventId: Property.ShortText({ | ||
displayName: 'Event ID', | ||
required: true, | ||
}), | ||
}, | ||
async run({ propsValue, auth }) { | ||
const request: HttpRequest = { | ||
method: HttpMethod.DELETE, | ||
url: `${outlookCalendarCommon.baseUrl}/calendars/${propsValue.calendarId}/events/${propsValue.eventId}`, | ||
body: {}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: auth['access_token'], | ||
}, | ||
}; | ||
|
||
const response = await httpClient.sendRequest(request); | ||
|
||
return response.body; | ||
}, | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/pieces/community/microsoft-outlook-calendar/src/lib/actions/list-events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { | ||
AuthenticationType, | ||
httpClient, | ||
HttpMethod, | ||
HttpRequest, | ||
} from '@activepieces/pieces-common'; | ||
import { outlookCalendarAuth } from '../..'; | ||
import { outlookCalendarCommon } from '../common/common'; | ||
|
||
export const listEventsAction = createAction({ | ||
auth: outlookCalendarAuth, | ||
name: 'list_events', | ||
description: 'List events in a calendar', | ||
displayName: 'List events in a calendar', | ||
props: { | ||
calendarId: outlookCalendarCommon.calendarDropdown, | ||
filter: Property.LongText({ | ||
displayName: 'Filter', | ||
required: false, | ||
description: | ||
'Search query filter, see: https://learn.microsoft.com/en-us/graph/filter-query-parameter', | ||
}), | ||
}, | ||
async run({ propsValue, auth }) { | ||
const queryParams: Record<string, string> = {}; | ||
|
||
if (propsValue.filter) queryParams['$filter'] = propsValue.filter; | ||
|
||
const request: HttpRequest = { | ||
method: HttpMethod.GET, | ||
url: `${outlookCalendarCommon.baseUrl}/calendars/${propsValue.calendarId}/events`, | ||
queryParams, | ||
body: {}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: auth['access_token'], | ||
}, | ||
}; | ||
|
||
const response = await httpClient.sendRequest(request); | ||
|
||
return response.body; | ||
}, | ||
}); |
84 changes: 84 additions & 0 deletions
84
packages/pieces/community/microsoft-outlook-calendar/src/lib/common/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { OAuth2PropertyValue, Property } from '@activepieces/pieces-framework'; | ||
import { | ||
AuthenticationType, | ||
httpClient, | ||
HttpMethod, | ||
} from '@activepieces/pieces-common'; | ||
|
||
export const outlookCalendarCommon = { | ||
baseUrl: 'https://graph.microsoft.com/v1.0/me', | ||
calendarDropdown: Property.Dropdown({ | ||
displayName: 'Calendar', | ||
required: true, | ||
options: async ({ auth }) => { | ||
if (!auth) { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder: 'Please authenticate first', | ||
}; | ||
} | ||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue; | ||
const calendars: { id: string; name: string }[] = ( | ||
await httpClient.sendRequest<{ value: { id: string; name: string }[] }>( | ||
{ | ||
method: HttpMethod.GET, | ||
url: `${outlookCalendarCommon.baseUrl}/calendars`, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: authProp['access_token'], | ||
}, | ||
} | ||
) | ||
).body.value; | ||
return { | ||
disabled: false, | ||
options: calendars.map((calendar: { id: string; name: string }) => { | ||
return { | ||
label: calendar.name, | ||
value: calendar.id, | ||
}; | ||
}), | ||
}; | ||
}, | ||
refreshers: [], | ||
}), | ||
timezoneDropdown: Property.Dropdown({ | ||
displayName: 'Timezone', | ||
required: true, | ||
options: async ({ auth }) => { | ||
if (!auth) { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder: 'Please authenticate first', | ||
}; | ||
} | ||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue; | ||
const timezones: { displayName: string; alias: string }[] = ( | ||
await httpClient.sendRequest<{ | ||
value: { displayName: string; alias: string }[]; | ||
}>({ | ||
method: HttpMethod.GET, | ||
url: `${outlookCalendarCommon.baseUrl}/outlook/supportedTimeZones`, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: authProp['access_token'], | ||
}, | ||
}) | ||
).body.value; | ||
return { | ||
disabled: false, | ||
options: timezones.map( | ||
(timezone: { displayName: string; alias: string }) => { | ||
return { | ||
label: timezone.displayName, | ||
value: timezone.alias, | ||
}; | ||
} | ||
), | ||
}; | ||
}, | ||
refreshers: [], | ||
}), | ||
}; |
Oops, something went wrong.