@managed-api/microsoft-core v0.6.0
Managed API for Microsoft Graph
Managed API for Microsoft Graph is an API Client for Microsoft Graph by Adaptavist primarily designed for the use in Stitch It. You can read more about Managed APIs here.
This is a runtime agnostic version of the Managed API (with core suffix) that makes it easy to port it to any runtime you may want to use this Managed API on.
Platform specific ports
Supported API calls
- fetch
- Groups
- Teams
- Messaging
- Team
- Users
Porting to other runtimes
While the primary reason for creating Managed APIs was to use them in Stitch It runtime, then you can easily port them to any runtime of your choosing.
You can do so by extending the *Core Managed API class where you'll be asked to provide implementation for getPlatformImplementation function. In this implementation you have yo specify how to perform buffer encoding/decoding operations and how to perform HTTP calls:
{
buffer: {
encode(input: string): ArrayBuffer;
decode(input: ArrayBuffer): string;
},
performHttpCall(request: Request): Promise<Response>
}Here is an example how to create a Node port of the Managed API:
import { MicrosoftGraphApiCore, Request, Response, Headers } from "@managed-api/microsoft-core";
import { PlatformImplementation } from "@managed-api/commons-core";
import fetch from "node-fetch";
export class MicrosoftGraphApi extends MicrosoftGraphApiCore {
constructor(private baseUrl: string, private authToken: string) {
super();
}
protected getPlatformImplementation(): PlatformImplementation {
return {
buffer: {
encode: (input) => Buffer.from(input, 'utf-8'),
decode: (input) => Buffer.from(input).toString('utf-8')
},
performHttpCall: (request) => this.performHttpCall(request)
};
}
private async performHttpCall(request: Request): Promise<Response> {
const requestUrl = `${this.baseUrl}${request.url}`; // Substitute base URL
request.headers.set('Authorization', `Basic ${this.authToken}`); // Substitute auth token
const response = await fetch(requestUrl, {
method: request.method,
headers: request.headers as any,
body: request.method.toLowerCase() !== 'get' ? Buffer.from((await request.arrayBuffer()) ?? new ArrayBuffer(0)) : undefined
});
const apiHeaders = new Headers();
response.headers.forEach((value, key) => apiHeaders.append(key, value));
const body = await response.arrayBuffer();
return super.buildResponse(response.url, response.status, response.statusText, apiHeaders, body);
}
}Please note that the authentication handling details may not be accurate and serve as an example. If you wish yo use these Managed APIs without having to concern yourself how to deal with and secure authentication details when working with APIs, then feel free to evaluate Stitch It platform.
Contact
At this time Managed APIs are unlicensed and close sourced, but feel free to drop an email to eknoll@adaptavist.com for ideas, suggestions and improvements.
Changelog
0.2.0
Added support for the following Users methods:
- List users that can be used as
Users.getUsersorAll.getUsers. - Create user that can be used as
Users.createUserorAll.createUser. - Get user that can be used as
Users.getUserorAll.getUser. - Get user that can be used as
Users.getMyUserorAll.getMyUser. - Update user that can be used as
Users.updateUserorAll.updateUser. - Delete a user that can be used as
Users.deleteUserorAll.deleteUser.
Added support for the following Teams.Team methods:
- Create team that can be used as
Teams.Team.createTeamorAll.createTeamsTeam. - Get team that can be used as
Teams.Team.getTeamorAll.getTeamsTeam. - Update team that can be used as
Teams.Team.updateTeamorAll.updateTeamsTeam. - Delete group that can be used as
Teams.Team.deleteTeamorAll.deleteTeamsTeam. - List members of team that can be used as
Teams.Team.getMembersorAll.getTeamsTeamMembers. - Add member to team that can be used as
Teams.Team.addMemberorAll.addTeamsTeamMember. - Get member of team that can be used as
Teams.Team.getMemberorAll.getTeamsTeamMember. - Remove member from team that can be used as
Teams.Team.removeMemberorAll.removeTeamsTeamMember. - Update member in team that can be used as
Teams.Team.updateMemberorAll.updateTeamsTeamMember. - List joinedTeams that can be used as
Teams.Team.getMyTeamsorAll.getMyTeams. - List joinedTeams that can be used as
Teams.Team.getUserTeamsorAll.getUserTeams. - List associatedTeamInfo that can be used as
Teams.Team.getUserAssociatedTeamsorAll.getUserAssociatedTeams. - List all teams in Microsoft Teams for an organization that can be used as
Groups.getGroupsorAll.getGroups.
Added support for the following Teams.Messaging.Channel methods:
- List channels that can be used as
Teams.Messaging.Channel.getChannelsorAll.getTeamsChannels. - Create channel that can be used as
Teams.Messaging.Channel.createChannelorAll.createTeamsChannel. - Get channel that can be used as
Teams.Messaging.Channel.getChannelorAll.getTeamsChannel. - Patch channel that can be used as
Teams.Messaging.Channel.updateChannelorAll.updateTeamsChannel. - Delete channel that can be used as
Teams.Messaging.Channel.deleteChannelorAll.deleteTeamsChannel. - List members of a channel that can be used as
Teams.Messaging.Channel.getMembersorAll.getTeamsChannelMembers. - Add member to channel that can be used as
Teams.Messaging.Channel.addMemberorAll.addMemberToTeamsChannel. - Remove member from channel that can be used as
Teams.Messaging.Channel.removeMemberorAll.removeMemberFromTeamsChannel. - List channel messages that can be used as
Teams.Messaging.Channel.getMessagesorAll.getTeamsChannelMessages. - Send chatMessage in channel that can be used as
Teams.Messaging.Channel.sendMessageorAll.sendTeamsChannelMessage. - Get chatMessage in a channel or chat that can be used as
Teams.Messaging.Channel.getMessageorAll.getTeamsChannelMessage. - Update chatMessage that can be used as
Teams.Messaging.Channel.updateMessageorAll.updateTeamsChannelMessage. - List replies that can be used as
Teams.Messaging.Channel.getMessageRepliesorAll.getTeamsChannelMessageReplies. - Send replies to a message in a channel that can be used as
Teams.Messaging.Channel.replyToMessageorAll.replyToTeamsChannelMessage.
Added support for the following Teams.Messaging.Chat methods:
- List chats that can be used as
Teams.Messaging.Chat.getChatsorAll.getTeamsChats. - Create chat that can be used as
Teams.Messaging.Chat.createChatorAll.createTeamsChat. - Get chat that can be used as
Teams.Messaging.Chat.getChatorAll.getTeamsChat. - Update chat that can be used as
Teams.Messaging.Chat.updateChatorAll.updateTeamsChat. - List members of a chat that can be used as
Teams.Messaging.Chat.getMembersorAll.getTeamsChatMembers. - Add member to a chat that can be used as
Teams.Messaging.Chat.addMemberorAll.addMemberToTeamsChat. - Get conversationMember in a chat that can be used as
Teams.Messaging.Chat.getMemberorAll.getTeamsChatMember. - Remove member from chat that can be used as
Teams.Messaging.Chat.removeMemberorAll.removeTeamsChatMember. - List messages in a chat that can be used as
Teams.Messaging.Chat.getMessagesorAll.getTeamsChatMessages. - Send message in a chat that can be used as
Teams.Messaging.Chat.sendMessageorAll.sendTeamsChatMessage. - Get chatMessage in a channel or chat that can be used as
Teams.Messaging.Chat.getMessageorAll.getTeamsChatMessage. - Update chatMessage that can be used as
Teams.Messaging.Chat.updateMessageorAll.updateTeamsChatMessage.
Copyright Adaptavist 2023 (c) All rights reserved