import type { IntegrationAccountRequirement, TriggerDefinition } from "../types" const OUTLOOK_ACCOUNT = { connectionOptions: [ { requiredScopes: [ { requirements: ["Mail.ReadWrite", "Mail.Read"], type: "or", }, ], }, ], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement const TEAMS_CHANNEL_MESSAGE_ACCOUNT = { connectionOptions: [ { requiredScopes: [ { requirements: [ "ChannelMessage.Read.All", "Team.ReadBasic.All", "Channel.ReadBasic.All", ], type: "and", }, ], }, ], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement const TEAMS_TEAM_ACCOUNT = { connectionOptions: [{ requiredScopes: ["Team.ReadBasic.All"] }], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement const TEAMS_CHANNEL_ACCOUNT = { connectionOptions: [ { requiredScopes: [ { requirements: ["Team.ReadBasic.All", "Channel.ReadBasic.All"], type: "and", }, ], }, ], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement const TEAMS_CHANNEL_MEMBER_ACCOUNT = { connectionOptions: [ { requiredScopes: [ { requirements: [ "Team.ReadBasic.All", "Channel.ReadBasic.All", "ChannelMember.Read.All", ], type: "and", }, ], }, ], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement const TEAMS_TEAM_MEMBER_ACCOUNT = { connectionOptions: [ { requiredScopes: [ { requirements: ["Team.ReadBasic.All", "TeamMember.Read.All"], type: "and", }, ], }, ], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement const TEAMS_CHAT_MESSAGE_ACCOUNT = { connectionOptions: [ { requiredScopes: [ { requirements: ["Chat.ReadWrite", "Chat.Read"], type: "or", }, ], }, ], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement const TEAMS_CHAT_ACCOUNT = { connectionOptions: [{ requiredScopes: ["Chat.ReadBasic"] }], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement const TEAMS_CHAT_MEMBER_ACCOUNT = { connectionOptions: [ { requiredScopes: [ { requirements: ["ChatMember.ReadWrite", "ChatMember.Read"], type: "or", }, ], }, ], serviceId: "microsoft", } as const satisfies IntegrationAccountRequirement export const microsoftTriggerDefinitions = { outlookMessageEvent: { account: OUTLOOK_ACCOUNT, type: "outlook.message.changed", }, outlookMessageCreated: { account: OUTLOOK_ACCOUNT, type: "outlook.message.created", }, outlookMessageDeleted: { account: OUTLOOK_ACCOUNT, type: "outlook.message.deleted", }, outlookMessageUpdated: { account: OUTLOOK_ACCOUNT, type: "outlook.message.updated", }, outlookEmailReceived: { account: OUTLOOK_ACCOUNT, type: "outlook.email.received", }, teamsChannelMessagePosted: { account: TEAMS_CHANNEL_MESSAGE_ACCOUNT, name: "Microsoft Teams channel message posted", type: "teams.channel.message.posted", }, teamsChannelEvent: microsoftChangeTrigger( "teams.channel.changed", TEAMS_CHANNEL_ACCOUNT, ), teamsChannelCreated: microsoftChangeTrigger( "teams.channel.created", TEAMS_CHANNEL_ACCOUNT, ), teamsChannelDeleted: microsoftChangeTrigger( "teams.channel.deleted", TEAMS_CHANNEL_ACCOUNT, ), teamsChannelUpdated: microsoftChangeTrigger( "teams.channel.updated", TEAMS_CHANNEL_ACCOUNT, ), teamsTeamEvent: microsoftChangeTrigger( "teams.team.changed", TEAMS_TEAM_ACCOUNT, ), teamsTeamDeleted: microsoftChangeTrigger( "teams.team.deleted", TEAMS_TEAM_ACCOUNT, ), teamsTeamUpdated: microsoftChangeTrigger( "teams.team.updated", TEAMS_TEAM_ACCOUNT, ), teamsTeamMemberAdded: microsoftChangeTrigger( "teams.team.member.added", TEAMS_TEAM_MEMBER_ACCOUNT, ), teamsTeamMemberEvent: microsoftChangeTrigger( "teams.team.member.changed", TEAMS_TEAM_MEMBER_ACCOUNT, ), teamsTeamMemberRemoved: microsoftChangeTrigger( "teams.team.member.removed", TEAMS_TEAM_MEMBER_ACCOUNT, ), teamsTeamMemberUpdated: microsoftChangeTrigger( "teams.team.member.updated", TEAMS_TEAM_MEMBER_ACCOUNT, ), teamsChannelMemberAdded: microsoftChangeTrigger( "teams.channel.member.added", TEAMS_CHANNEL_MEMBER_ACCOUNT, ), teamsChannelMemberEvent: microsoftChangeTrigger( "teams.channel.member.changed", TEAMS_CHANNEL_MEMBER_ACCOUNT, ), teamsChannelMemberRemoved: microsoftChangeTrigger( "teams.channel.member.removed", TEAMS_CHANNEL_MEMBER_ACCOUNT, ), teamsChannelMemberUpdated: microsoftChangeTrigger( "teams.channel.member.updated", TEAMS_CHANNEL_MEMBER_ACCOUNT, ), teamsChannelMessageEvent: microsoftChangeTrigger( "teams.channel.message.changed", TEAMS_CHANNEL_MESSAGE_ACCOUNT, ), teamsChannelMessageDeleted: microsoftChangeTrigger( "teams.channel.message.deleted", TEAMS_CHANNEL_MESSAGE_ACCOUNT, ), teamsChannelMessageUpdated: microsoftChangeTrigger( "teams.channel.message.updated", TEAMS_CHANNEL_MESSAGE_ACCOUNT, ), teamsChatEvent: microsoftChangeTrigger( "teams.chat.changed", TEAMS_CHAT_ACCOUNT, ), teamsChatMemberAdded: microsoftChangeTrigger( "teams.chat.member.added", TEAMS_CHAT_MEMBER_ACCOUNT, ), teamsChatMemberEvent: microsoftChangeTrigger( "teams.chat.member.changed", TEAMS_CHAT_MEMBER_ACCOUNT, ), teamsChatMemberRemoved: microsoftChangeTrigger( "teams.chat.member.removed", TEAMS_CHAT_MEMBER_ACCOUNT, ), teamsChatMessageEvent: microsoftChangeTrigger( "teams.chat.message.changed", TEAMS_CHAT_MESSAGE_ACCOUNT, ), teamsChatMessageDeleted: microsoftChangeTrigger( "teams.chat.message.deleted", TEAMS_CHAT_MESSAGE_ACCOUNT, ), teamsChatMessageUpdated: microsoftChangeTrigger( "teams.chat.message.updated", TEAMS_CHAT_MESSAGE_ACCOUNT, ), teamsChatUpdated: microsoftChangeTrigger( "teams.chat.updated", TEAMS_CHAT_ACCOUNT, ), teamsChatMessagePosted: { account: TEAMS_CHAT_MESSAGE_ACCOUNT, name: "Microsoft Teams chat message posted", type: "teams.chat.message.posted", }, } as const satisfies Record /** * Builds one Microsoft change-trigger definition without widening its type. * * @param type - Stable integration event type. * @param account - Microsoft account and scope requirement. */ function microsoftChangeTrigger( type: TType, account: IntegrationAccountRequirement, ) { return { account, type } }