diff --git a/.gitignore b/.gitignore index 4372de832..88c2755a8 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,6 @@ samples/**/lib/ samples/**/solution/ samples/**/temp/ samples/**/release/ -samples/**/node_modules \ No newline at end of file +samples/**/node_modules +samples/react-kiota-custom-api-client/TeamifiedApi/appsettings.Development.json +samples/react-kiota-custom-api-client/teamified-client/package-lock.json diff --git a/samples/react-kiota-custom-api-client/README.md b/samples/react-kiota-custom-api-client/README.md new file mode 100644 index 000000000..4dddf0148 --- /dev/null +++ b/samples/react-kiota-custom-api-client/README.md @@ -0,0 +1,116 @@ +# Using Kiota to generate a client to your AzureAd API and use it from a SPFx webpart + +## Summary + +This sample shows how you can generate a client for your custom API using Kiota, and how to use that client in an SPFx webpart. The sample contains a custom API that is secured by Azure AD and interacts with Microsoft Graph API to do some basic operations with the Teams endpoint (it allows to list all the Teams in the tenant, to get detailed info for a given Team, and to Provision a new Team with some preconfigured channels). + +![kiota-spfx-sample](./assets/react-kiota-custom-api-client.png) + +### About Kiota + +Kiota is a tool created by Microsoft, that allows you to generate a client/SDK for any given API that is described using OpenAPI. It supports different languages, and provides some abstractions, so you can customise several things, like Auth providers, JSON serialisation, HTTP Request adapter, etc. + +In this sample, in the folder ```/teamified-client/src/webparts/client``` is included the code generated by Kiota. We executed the following command: + +``` +kiota generate --openapi "my-api-swagger.yaml" --language typescript --namespace-name TeamifiedApiClient --class-name TeamifiedApiClient --output generated --log-level debug +``` + +## Used SharePoint Framework Version + +![version](https://img.shields.io/badge/version-1.15-green.svg) + +## Applies to + +- [SharePoint Framework](https://aka.ms/spfx) +- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant) + +> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram) + +## Prerequisites + +The API must be registered in your Azure Active Directory tenant. You can find more information on how to do it in these articles: + - https://learn.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient-enterpriseapi + - https://learn.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient + +The API uses a ClientSecret to connect to MS Graph API, so create a Secret from Azure portal (this is not the recommended approach, but works for the demo. For production, I recommend you to use a certificate). +The API needs the following permissions to __Microsoft Graph API__: + +| Scope | Type | +| ----------- | ----------------------- | +| Group.ReadWrite.All | Delegated | +| Directory.Read.All | Delegated | + +Also, the API needs to be configured in the __Expose an API__ section, and configure a new scope named: __Teams.Manage__. + +Once the API is registered in Azure AD, we must configure permissions for SPFx to access the API. This can be done in different ways. I suggest you to use the M365 CLI, with the following command: + +``` +m365 spo serviceprincipal grant add --resource 'Teamified_Services' --scope 'Teams.Manage' +``` + +## Solution + +| Solution | Author(s) | +| ----------- | ------------------------------------------------------- | +| react-kiota-custom-api-client | [Luis Mañez](https://github.com/luismanez) ([MS MVP](https://mvp.microsoft.com/en-us/PublicProfile/5002617), [ClearPeople](https://www.clearpeople.com), [@luismanez](https://twitter.com/luismanez)) | + +## Version history + +| Version | Date | Comments | +| ------- | ---------------- | --------------- | +| 1.0 | November 1, 2022 | Initial release | + +## Minimal Path to Awesome + +- Clone this repository +- Edit the file __TeamifiedApi/appsettings.json__ with your Azure Active Directory API registration data (ClientId, TenantId, etc) +- Edit the file __teamified-client/src/webparts/teamsList/components/TeamsList.tsx__ and set the proper values in the following code: +```typescript + // #region ******************** UPDATE WITH YOUR TENANT DATA ******************** + private readonly azureAdApplicationIdUri: string = "api://{AZURE_AD_CLIENT_ID}"; + private readonly apiHost: string = "{YOUR_API}.azurewebsites.net"; + // #endregion +``` +- Ensure the API is up and running (you can run your API in localhost, using Visual Studio or the dotnet CLI, no need to publish it to Azure or any other hosting) +- Ensure that you are at the solution folder +- in the command-line run: + - **npm install** + - **gulp serve** + +## Features + +This extension illustrates the following concepts: + +- using Kiota tool to generate a client for any API described by OpenAPI standard. +- using Kiota SPFx Authentication library, to provide Authentication to the Kiota client +- protecting a dotnet webapi using Azure AD and Microsoft.Identity.Web library +- calling MS Graph API from a dotnet webapi + +## References + +- [Kiota official documentation](https://microsoft.github.io/kiota/) +- [Kiota TypeScript library](https://github.com/microsoft/kiota-typescript) +- [Getting started with SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant) +- [Building for Microsoft teams](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/build-for-teams-overview) +- [Use Microsoft Graph in your solution](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/using-microsoft-graph-apis) +- [Publish SharePoint Framework applications to the Marketplace](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/publish-to-marketplace-overview) +- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - Guidance, tooling, samples and open-source controls for your Microsoft 365 development + +## Help +We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues. + +If you're having issues building the solution, please run spfx doctor from within the solution folder to diagnose incompatibility issues with your environment. + +You can try looking at issues related to this sample to see if anybody else is having the same issues. + +You can also try looking at discussions related to this sample and see what the community is saying. + +If you encounter any issues using this sample, create a new issue. + +For questions regarding this sample, create a new question. + +Finally, if you have an idea for improvement, make a suggestion. + +## Disclaimer +THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Diagnostics/DiagnosticsModule.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Diagnostics/DiagnosticsModule.cs new file mode 100644 index 000000000..4a05399a7 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Diagnostics/DiagnosticsModule.cs @@ -0,0 +1,20 @@ +using Teamified.Api.Teams.Models; + +namespace Teamified.Api.Diagnostics; + +public static class DiagnosticsModule +{ + public static IEndpointRouteBuilder MapDiagnosticsEndpoints(this IEndpointRouteBuilder endpoints) + { + endpoints.MapGet("/ping", () => new Ping { + Id = Guid.NewGuid(), + Now = DateTime.Now.ToString() + }) + .Produces(200) + .WithName("Ping") + .WithTags("DiagnosticsModule") + .AllowAnonymous(); + + return endpoints; + } +} \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/GlobalUsings.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/GlobalUsings.cs new file mode 100644 index 000000000..85f382de1 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/GlobalUsings.cs @@ -0,0 +1,4 @@ +global using Microsoft.AspNetCore.Authorization; +global using Microsoft.AspNetCore.Mvc; +global using Microsoft.Identity.Web; +global using System.Security.Claims; \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Program.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Program.cs new file mode 100644 index 000000000..acb7933fe --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Program.cs @@ -0,0 +1,74 @@ +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.OpenApi.Models; +using Teamified.Api.Diagnostics; +using Teamified.Api.Teams; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen( + c => + { + c.AddServer(new OpenApiServer() // Required by Kiota when creating the SDK + { + Url = "https://localhost:7295" + }); + c.AddServer(new OpenApiServer() + { + Url = "https://teamifiedapi.azurewebsites.net" + }); + }); + +builder.Services.AddMediatR(m => m.AsScoped(), typeof(Program)); + +builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) + .AddMicrosoftIdentityWebApi(builder.Configuration) + .EnableTokenAcquisitionToCallDownstreamApi(options => { builder.Configuration.Bind("AzureAd", options); }) + .AddMicrosoftGraph(builder.Configuration.GetSection("MicrosoftGraph")) + .AddInMemoryTokenCaches(); // Advice: Use Distributed TokenCache (redis, sql...) + +builder.Services.AddAuthorization(cfg => { + cfg.FallbackPolicy = new AuthorizationPolicyBuilder() + .RequireAuthenticatedUser() + .Build(); +}); + +builder.Services.AddHttpContextAccessor(); + +const string MyAllowSpecificOrigins = "_teamifiedOpenCors"; +builder.Services.AddCors(options => +{ + options.AddPolicy(name: MyAllowSpecificOrigins, + policy => + { + policy + .AllowAnyOrigin() + .AllowAnyHeader(); + }); +}); + +builder.Services.RegisterTeamsModule(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseCors(MyAllowSpecificOrigins); + +app.UseAuthentication(); +app.UseAuthorization(); + +app.MapDiagnosticsEndpoints(); +app.MapTeamsEndpoints(); + +app.Run(); \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Properties/launchSettings.json b/samples/react-kiota-custom-api-client/TeamifiedApi/Properties/launchSettings.json new file mode 100644 index 000000000..1d975f8d3 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:26861", + "sslPort": 44374 + } + }, + "profiles": { + "TeamifiedApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7089;http://localhost:5115", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/TeamifiedApi.csproj b/samples/react-kiota-custom-api-client/TeamifiedApi/TeamifiedApi.csproj new file mode 100644 index 000000000..5b6c7328b --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/TeamifiedApi.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Commands/ProvisionTeam/ProvisionTeamCommand.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Commands/ProvisionTeam/ProvisionTeamCommand.cs new file mode 100644 index 000000000..b424af232 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Commands/ProvisionTeam/ProvisionTeamCommand.cs @@ -0,0 +1,35 @@ +using MediatR; +using Teamified.Api.Teams.Interfaces; +using Teamified.Api.Teams.Models; + +namespace Teamified.Api.Teams.Commands.ProvisionTeam; + +public class ProvisionTeamCommand : IRequest +{ + public string DisplayName { get; set; } + public string Description { get; set; } +} + +public class ProvisionTeamCommandHandler : IRequestHandler +{ + private readonly ITeamsService _teamsService; + public ProvisionTeamCommandHandler(ITeamsService teamsService) + { + _teamsService = teamsService; + } + + public async Task Handle( + ProvisionTeamCommand request, + CancellationToken cancellationToken) + { + var team = new Team + { + DisplayName = request.DisplayName, + Description = request.Description + }; + + var newTeamLocation = await _teamsService.ProvisionTeam(team); + + return newTeamLocation; + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/GetTeam.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/GetTeam.cs new file mode 100644 index 000000000..6d70d8147 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/GetTeam.cs @@ -0,0 +1,15 @@ +using MediatR; +using Teamified.Api.Teams.Queries.GetTeam; + +namespace Teamified.Api.Teams.Endpoints; + +public static class GetTeam +{ + public static async Task Handle( + IMediator mediator, Guid id) + { + var teams = await mediator.Send(new GetTeamQuery { GroupId = id }); + + return Results.Ok(teams); + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/ListTeams.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/ListTeams.cs new file mode 100644 index 000000000..f6115cbea --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/ListTeams.cs @@ -0,0 +1,15 @@ +using MediatR; +using Teamified.Api.Teams.Queries.ListTeams; + +namespace Teamified.Api.Teams.Endpoints +{ + public class ListTeams + { + public static async Task Handle(IMediator mediator) + { + var teams = await mediator.Send(new ListTeamsQuery()); + + return Results.Ok(teams); + } + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/ProvisionTeam.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/ProvisionTeam.cs new file mode 100644 index 000000000..e67153523 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Endpoints/ProvisionTeam.cs @@ -0,0 +1,17 @@ +using MediatR; +using Teamified.Api.Teams.Commands.ProvisionTeam; + +namespace Teamified.Api.Teams.Endpoints +{ + public class ProvisionTeam + { + public static async Task Handle( + IMediator mediator, + ProvisionTeamCommand command) + { + var newTeamLocation = await mediator.Send(command); + + return Results.Accepted(newTeamLocation); + } + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Infrastructure/TeamsService.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Infrastructure/TeamsService.cs new file mode 100644 index 000000000..c7faa48cf --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Infrastructure/TeamsService.cs @@ -0,0 +1,112 @@ +using Microsoft.Graph; +using Teamified.Api.Teams.Interfaces; + +namespace Teamified.Api.Teams.Infrastructure; +public class TeamsService : ITeamsService +{ + private readonly GraphServiceClient _graphServiceClient; + private readonly IHttpContextAccessor _context; + + public TeamsService( + GraphServiceClient graphServiceClient, + IHttpContextAccessor httpContextAccessor) + { + _graphServiceClient = graphServiceClient; + _context = httpContextAccessor; + } + public async Task GetTeamByGroupId(Guid groupId) + { + var group = await _graphServiceClient.Groups[groupId.ToString()] + .Request() + .Expand("members($select=id,displayName,userPrincipalName,jobTitle,mail)") // can´t expand more than 1 item (owners, members does not work) + .Select(g => new { g.Id, g.DisplayName, g.Description, g.Members }) + .GetAsync(); + + var team = Models.Team.MapFromGraphGroup(group); + + var groupOwners = await _graphServiceClient.Groups[groupId.ToString()] + .Owners + .Request() + .Select("id,displayName,userPrincipalName,jobTitle,mail") + .GetAsync(); + + var owners = groupOwners.CurrentPage; + + team.AddOwners(owners); + + var teamChannels = await _graphServiceClient.Teams[groupId.ToString()] + .Channels + .Request() + .GetAsync(); + + var channels = teamChannels.CurrentPage; + + team.AddChannels(channels); + + return team; + } + + public async Task> ListTeams() + { + var teamsCollection = await _graphServiceClient.Groups + .Request() + .Filter("resourceProvisioningOptions/Any(x:x eq 'Team')") + .Expand("members($select=id,displayName,userPrincipalName,jobTitle,mail)") // can´t expand more than 1 item (owners, members does not work), but for this Listing endpoint is fine. + .Select(g => new { g.Id, g.DisplayName, g.Description, g.Members }) + .GetAsync(); + + var teams = teamsCollection.CurrentPage; + + var result = teams.Select(t => Models.Team.MapFromGraphGroup(t)); + + return result; + } + + public async Task ProvisionTeam(Models.Team team) + { + var currentUserId = _context.HttpContext.User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; + + var newTeam = new Team() + { + DisplayName = team.DisplayName, + Description = team.Description, + AdditionalData = new Dictionary() + { + {"template@odata.bind", "https://graph.microsoft.com/v1.0/teamsTemplates('standard')"} + }, + Members = new TeamMembersCollectionPage() + { + new AadUserConversationMember + { + Roles = new List() + { + "owner" + }, + AdditionalData = new Dictionary() + { + {"user@odata.bind", $"https://graph.microsoft.com/v1.0/users/{currentUserId}"} + } + } + }, Channels = new TeamChannelsCollectionPage + { + new Channel + { + DisplayName = "KickOff Channel", + IsFavoriteByDefault = true, + Description = "As per company policy, place here data related with the Kickoff of the Team" + } + } + }; + + var result = await _graphServiceClient.Teams + .Request() + .AddResponseAsync(newTeam); + + if (result.HttpHeaders.TryGetValues("Location", out var locationValues)) + { + return locationValues?.First(); + } + + return "Something went wrong. Location not found"; + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Interfaces/ITeamsService.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Interfaces/ITeamsService.cs new file mode 100644 index 000000000..071f176af --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Interfaces/ITeamsService.cs @@ -0,0 +1,11 @@ +using Teamified.Api.Teams.Models; + +namespace Teamified.Api.Teams.Interfaces +{ + public interface ITeamsService + { + Task> ListTeams(); + Task GetTeamByGroupId(Guid groupId); + Task ProvisionTeam(Team team); + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Channel.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Channel.cs new file mode 100644 index 000000000..9bf6c1794 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Channel.cs @@ -0,0 +1,25 @@ +namespace Teamified.Api.Teams.Models; + +public sealed class Channel +{ + public string Id { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + + public Channel() + { + Id = "unknown"; + DisplayName = "unknown"; + Description = "unknown"; + } + + internal static Channel MapFromGraphChannel(Microsoft.Graph.Channel c) + { + return new Channel + { + Id = c.Id, + DisplayName = c.DisplayName, + Description = c.Description + }; + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/IdentityPrincipal.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/IdentityPrincipal.cs new file mode 100644 index 000000000..b46e7d3d7 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/IdentityPrincipal.cs @@ -0,0 +1,32 @@ +using Microsoft.Graph; + +namespace Teamified.Api.Teams.Models; + +public sealed class IdentityPrincipal +{ + public Guid Id { get; set; } + public string UserPrincipalName { get; set; } + public string Email { get; set; } + public string DisplayName { get; set; } + public string JobTitle { get; set; } + + public IdentityPrincipal() + { + UserPrincipalName = "unknown"; + Email = "unknown"; + DisplayName = "unknown"; + JobTitle = "unknown"; + } + + public static IdentityPrincipal MapFromDirectoryObject(DirectoryObject directoryObject) + { + return new IdentityPrincipal + { + Id = Guid.Parse(directoryObject.Id), + DisplayName = ((User)directoryObject).DisplayName, + Email = ((User)directoryObject).Mail, + JobTitle = ((User)directoryObject).JobTitle, + UserPrincipalName = ((User)directoryObject).UserPrincipalName + }; + } +} \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Ping.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Ping.cs new file mode 100644 index 000000000..df9a82184 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Ping.cs @@ -0,0 +1,7 @@ +namespace Teamified.Api.Teams.Models; + +public class Ping +{ + public Guid Id { get; set; } + public string Now { get; set; } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Team.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Team.cs new file mode 100644 index 000000000..2ae5dff83 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Models/Team.cs @@ -0,0 +1,45 @@ +using Microsoft.Graph; + +namespace Teamified.Api.Teams.Models; + +public sealed class Team +{ + public string Id { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public IEnumerable Owners { get; set; } + public IEnumerable Members { get; set; } + public IEnumerable Channels { get; set; } + + public Team() + { + Id = "unknown"; + DisplayName = "unknown"; + Description = "unknown"; + Owners = new List(); + Members = new List(); + Channels = new List(); + } + + public static Team MapFromGraphGroup(Group graphGroup) + { + return new Team + { + Id = graphGroup.Id, + Description = graphGroup.Description, + DisplayName = graphGroup.DisplayName, + Members = graphGroup.Members != null ? graphGroup.Members.Select(m => IdentityPrincipal.MapFromDirectoryObject(m)) : new List(), + Owners = graphGroup.Owners != null ? graphGroup.Owners.Select(o => IdentityPrincipal.MapFromDirectoryObject(o)) : new List() + }; + } + + internal void AddOwners(IList owners) + { + Owners = owners.Select(o => IdentityPrincipal.MapFromDirectoryObject(o)); + } + + internal void AddChannels(IList channels) + { + Channels = channels.Select(c => Channel.MapFromGraphChannel(c)); + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Queries/GetTeam/GetTeamQuery.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Queries/GetTeam/GetTeamQuery.cs new file mode 100644 index 000000000..e37a8ce02 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Queries/GetTeam/GetTeamQuery.cs @@ -0,0 +1,27 @@ +using MediatR; +using Teamified.Api.Teams.Interfaces; +using Teamified.Api.Teams.Models; + +namespace Teamified.Api.Teams.Queries.GetTeam; + +public sealed class GetTeamQuery : IRequest +{ + public Guid GroupId { get; set; } +} + +public sealed class GetTeamQueryHandler : IRequestHandler +{ + private readonly ITeamsService _teamsService; + + public GetTeamQueryHandler(ITeamsService teamsService) + { + _teamsService = teamsService; + } + + public async Task Handle( + GetTeamQuery request, + CancellationToken cancellationToken) + { + return await _teamsService.GetTeamByGroupId(request.GroupId); + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Queries/ListTeams/ListTeamsQuery.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Queries/ListTeams/ListTeamsQuery.cs new file mode 100644 index 000000000..b29cedbbf --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/Queries/ListTeams/ListTeamsQuery.cs @@ -0,0 +1,27 @@ +using MediatR; +using Teamified.Api.Teams.Interfaces; +using Teamified.Api.Teams.Models; + +namespace Teamified.Api.Teams.Queries.ListTeams; + +public class ListTeamsQuery : IRequest> +{ + +} + +public class ListTeamsQueryHandler : IRequestHandler> +{ + private readonly ITeamsService _teamsService; + + public ListTeamsQueryHandler(ITeamsService teamsService) + { + _teamsService = teamsService; + } + + public async Task> Handle( + ListTeamsQuery request, + CancellationToken cancellationToken) + { + return await _teamsService.ListTeams(); + } +} \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/TeamsModule.cs b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/TeamsModule.cs new file mode 100644 index 000000000..6f1e5a629 --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/Teams/TeamsModule.cs @@ -0,0 +1,37 @@ +using Teamified.Api.Teams.Endpoints; +using Teamified.Api.Teams.Infrastructure; +using Teamified.Api.Teams.Interfaces; +using Teamified.Api.Teams.Models; + +namespace Teamified.Api.Teams +{ + public static class TeamsModule + { + public static IServiceCollection RegisterTeamsModule(this IServiceCollection services) + { + services.AddScoped(); + + return services; + } + + public static IEndpointRouteBuilder MapTeamsEndpoints(this IEndpointRouteBuilder endpoints) + { + endpoints.MapGet("/teams", ListTeams.Handle) + .Produces>(200) + .WithName("ListTeams") + .WithTags("TeamsModule"); + + endpoints.MapGet("/teams/{id:guid}", GetTeam.Handle) + .Produces(200) + .WithName("GetTeam") + .WithTags("TeamsModule"); + + endpoints.MapPost("/teams", ProvisionTeam.Handle) + .Produces(202) + .WithName("ProvisionTeam") + .WithTags("TeamsModule"); + + return endpoints; + } + } +} diff --git a/samples/react-kiota-custom-api-client/TeamifiedApi/appsettings.json b/samples/react-kiota-custom-api-client/TeamifiedApi/appsettings.json new file mode 100644 index 000000000..3e30613ee --- /dev/null +++ b/samples/react-kiota-custom-api-client/TeamifiedApi/appsettings.json @@ -0,0 +1,19 @@ +{ + //"AzureAd": { + // "Instance": "https://login.microsoftonline.com/", + // "ClientId": "", + // "TenantId": "", + // "ClientSecret": "" + //}, + //"MicrosoftGraph": { + // "BaseUrl": "https://graph.microsoft.com/v1.0", + // "Scopes": "https://graph.microsoft.com/.default" + //}, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/samples/react-kiota-custom-api-client/assets/react-kiota-custom-api-client.png b/samples/react-kiota-custom-api-client/assets/react-kiota-custom-api-client.png new file mode 100644 index 000000000..46c78cc4f Binary files /dev/null and b/samples/react-kiota-custom-api-client/assets/react-kiota-custom-api-client.png differ diff --git a/samples/react-kiota-custom-api-client/teamified-client/.eslintrc.js b/samples/react-kiota-custom-api-client/teamified-client/.eslintrc.js new file mode 100644 index 000000000..6ebb2a10f --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/.eslintrc.js @@ -0,0 +1,378 @@ +require('@rushstack/eslint-config/patch/modern-module-resolution'); +module.exports = { + extends: ['@microsoft/eslint-config-spfx/lib/profiles/react'], + parserOptions: { tsconfigRootDir: __dirname }, + overrides: [ + { + files: ['*.ts', '*.tsx'], + parser: '@typescript-eslint/parser', + 'parserOptions': { + 'project': './tsconfig.json', + 'ecmaVersion': 2018, + 'sourceType': 'module' + }, + rules: { + // Prevent usage of the JavaScript null value, while allowing code to access existing APIs that may require null. https://www.npmjs.com/package/@rushstack/eslint-plugin + '@rushstack/no-new-null': 1, + // Require Jest module mocking APIs to be called before any other statements in their code block. https://www.npmjs.com/package/@rushstack/eslint-plugin + '@rushstack/hoist-jest-mock': 1, + // Require regular expressions to be constructed from string constants rather than dynamically building strings at runtime. https://www.npmjs.com/package/@rushstack/eslint-plugin-security + '@rushstack/security/no-unsafe-regexp': 1, + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + '@typescript-eslint/adjacent-overload-signatures': 1, + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + // + // CONFIGURATION: By default, these are banned: String, Boolean, Number, Object, Symbol + '@typescript-eslint/ban-types': [ + 1, + { + 'extendDefaults': false, + 'types': { + 'String': { + 'message': 'Use \'string\' instead', + 'fixWith': 'string' + }, + 'Boolean': { + 'message': 'Use \'boolean\' instead', + 'fixWith': 'boolean' + }, + 'Number': { + 'message': 'Use \'number\' instead', + 'fixWith': 'number' + }, + 'Object': { + 'message': 'Use \'object\' instead, or else define a proper TypeScript type:' + }, + 'Symbol': { + 'message': 'Use \'symbol\' instead', + 'fixWith': 'symbol' + }, + 'Function': { + 'message': 'The \'Function\' type accepts any function-like value.\nIt provides no type safety when calling the function, which can be a common source of bugs.\nIt also accepts things like class declarations, which will throw at runtime as they will not be called with \'new\'.\nIf you are expecting the function to accept certain arguments, you should explicitly define the function shape.' + } + } + } + ], + // RATIONALE: Code is more readable when the type of every variable is immediately obvious. + // Even if the compiler may be able to infer a type, this inference will be unavailable + // to a person who is reviewing a GitHub diff. This rule makes writing code harder, + // but writing code is a much less important activity than reading it. + // + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + '@typescript-eslint/explicit-function-return-type': [ + 1, + { + 'allowExpressions': true, + 'allowTypedFunctionExpressions': true, + 'allowHigherOrderFunctions': false + } + ], + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + // Rationale to disable: although this is a recommended rule, it is up to dev to select coding style. + // Set to 1 (warning) or 2 (error) to enable. + '@typescript-eslint/explicit-member-accessibility': 0, + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + '@typescript-eslint/no-array-constructor': 1, + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + // + // RATIONALE: The "any" keyword disables static type checking, the main benefit of using TypeScript. + // This rule should be suppressed only in very special cases such as JSON.stringify() + // where the type really can be anything. Even if the type is flexible, another type + // may be more appropriate such as "unknown", "{}", or "Record". + '@typescript-eslint/no-explicit-any': 1, + // RATIONALE: The #1 rule of promises is that every promise chain must be terminated by a catch() + // handler. Thus wherever a Promise arises, the code must either append a catch handler, + // or else return the object to a caller (who assumes this responsibility). Unterminated + // promise chains are a serious issue. Besides causing errors to be silently ignored, + // they can also cause a NodeJS process to terminate unexpectedly. + '@typescript-eslint/no-floating-promises': 2, + // RATIONALE: Catches a common coding mistake. + '@typescript-eslint/no-for-in-array': 2, + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + '@typescript-eslint/no-misused-new': 2, + // RATIONALE: The "namespace" keyword is not recommended for organizing code because JavaScript lacks + // a "using" statement to traverse namespaces. Nested namespaces prevent certain bundler + // optimizations. If you are declaring loose functions/variables, it's better to make them + // static members of a class, since classes support property getters and their private + // members are accessible by unit tests. Also, the exercise of choosing a meaningful + // class name tends to produce more discoverable APIs: for example, search+replacing + // the function "reverse()" is likely to return many false matches, whereas if we always + // write "Text.reverse()" is more unique. For large scale organization, it's recommended + // to decompose your code into separate NPM packages, which ensures that component + // dependencies are tracked more conscientiously. + // + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + '@typescript-eslint/no-namespace': [ + 1, + { + 'allowDeclarations': false, + 'allowDefinitionFiles': false + } + ], + // RATIONALE: Parameter properties provide a shorthand such as "constructor(public title: string)" + // that avoids the effort of declaring "title" as a field. This TypeScript feature makes + // code easier to write, but arguably sacrifices readability: In the notes for + // "@typescript-eslint/member-ordering" we pointed out that fields are central to + // a class's design, so we wouldn't want to bury them in a constructor signature + // just to save some typing. + // + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + // Set to 1 (warning) or 2 (error) to enable the rule + '@typescript-eslint/no-parameter-properties': 0, + // RATIONALE: When left in shipping code, unused variables often indicate a mistake. Dead code + // may impact performance. + // + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + '@typescript-eslint/no-unused-vars': [ + 1, + { + 'vars': 'all', + // Unused function arguments often indicate a mistake in JavaScript code. However in TypeScript code, + // the compiler catches most of those mistakes, and unused arguments are fairly common for type signatures + // that are overriding a base class method or implementing an interface. + 'args': 'none' + } + ], + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + '@typescript-eslint/no-use-before-define': [ + 2, + { + 'functions': false, + 'classes': true, + 'variables': true, + 'enums': true, + 'typedefs': true + } + ], + // Disallows require statements except in import statements. + // In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6 style imports or import foo = require("foo") imports. + '@typescript-eslint/no-var-requires': 'error', + // RATIONALE: The "module" keyword is deprecated except when describing legacy libraries. + // + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + '@typescript-eslint/prefer-namespace-keyword': 1, + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + // Rationale to disable: it's up to developer to decide if he wants to add type annotations + // Set to 1 (warning) or 2 (error) to enable the rule + '@typescript-eslint/no-inferrable-types': 0, + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + // Rationale to disable: declaration of empty interfaces may be helpful for generic types scenarios + '@typescript-eslint/no-empty-interface': 0, + // RATIONALE: This rule warns if setters are defined without getters, which is probably a mistake. + 'accessor-pairs': 1, + // RATIONALE: In TypeScript, if you write x["y"] instead of x.y, it disables type checking. + 'dot-notation': [ + 1, + { + 'allowPattern': '^_' + } + ], + // RATIONALE: Catches code that is likely to be incorrect + 'eqeqeq': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'for-direction': 1, + // RATIONALE: Catches a common coding mistake. + 'guard-for-in': 2, + // RATIONALE: If you have more than 2,000 lines in a single source file, it's probably time + // to split up your code. + 'max-lines': ['warn', { max: 2000 }], + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-async-promise-executor': 2, + // RATIONALE: Deprecated language feature. + 'no-caller': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-compare-neg-zero': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-cond-assign': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-constant-condition': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-control-regex': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-debugger': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-delete-var': 2, + // RATIONALE: Catches code that is likely to be incorrect + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-duplicate-case': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-empty': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-empty-character-class': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-empty-pattern': 1, + // RATIONALE: Eval is a security concern and a performance concern. + 'no-eval': 1, + // RATIONALE: Catches code that is likely to be incorrect + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-ex-assign': 2, + // RATIONALE: System types are global and should not be tampered with in a scalable code base. + // If two different libraries (or two versions of the same library) both try to modify + // a type, only one of them can win. Polyfills are acceptable because they implement + // a standardized interoperable contract, but polyfills are generally coded in plain + // JavaScript. + 'no-extend-native': 1, + // Disallow unnecessary labels + 'no-extra-label': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-fallthrough': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-func-assign': 1, + // RATIONALE: Catches a common coding mistake. + 'no-implied-eval': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-invalid-regexp': 2, + // RATIONALE: Catches a common coding mistake. + 'no-label-var': 2, + // RATIONALE: Eliminates redundant code. + 'no-lone-blocks': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-misleading-character-class': 2, + // RATIONALE: Catches a common coding mistake. + 'no-multi-str': 2, + // RATIONALE: It's generally a bad practice to call "new Thing()" without assigning the result to + // a variable. Either it's part of an awkward expression like "(new Thing()).doSomething()", + // or else implies that the constructor is doing nontrivial computations, which is often + // a poor class design. + 'no-new': 1, + // RATIONALE: Obsolete language feature that is deprecated. + 'no-new-func': 2, + // RATIONALE: Obsolete language feature that is deprecated. + 'no-new-object': 2, + // RATIONALE: Obsolete notation. + 'no-new-wrappers': 1, + // RATIONALE: Catches code that is likely to be incorrect + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-octal': 2, + // RATIONALE: Catches code that is likely to be incorrect + 'no-octal-escape': 2, + // RATIONALE: Catches code that is likely to be incorrect + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-regex-spaces': 2, + // RATIONALE: Catches a common coding mistake. + 'no-return-assign': 2, + // RATIONALE: Security risk. + 'no-script-url': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-self-assign': 2, + // RATIONALE: Catches a common coding mistake. + 'no-self-compare': 2, + // RATIONALE: This avoids statements such as "while (a = next(), a && a.length);" that use + // commas to create compound expressions. In general code is more readable if each + // step is split onto a separate line. This also makes it easier to set breakpoints + // in the debugger. + 'no-sequences': 1, + // RATIONALE: Catches code that is likely to be incorrect + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-shadow-restricted-names': 2, + // RATIONALE: Obsolete language feature that is deprecated. + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-sparse-arrays': 2, + // RATIONALE: Although in theory JavaScript allows any possible data type to be thrown as an exception, + // such flexibility adds pointless complexity, by requiring every catch block to test + // the type of the object that it receives. Whereas if catch blocks can always assume + // that their object implements the "Error" contract, then the code is simpler, and + // we generally get useful additional information like a call stack. + 'no-throw-literal': 2, + // RATIONALE: Catches a common coding mistake. + 'no-unmodified-loop-condition': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-unsafe-finally': 2, + // RATIONALE: Catches a common coding mistake. + 'no-unused-expressions': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-unused-labels': 1, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-useless-catch': 1, + // RATIONALE: Avoids a potential performance problem. + 'no-useless-concat': 1, + // RATIONALE: The "var" keyword is deprecated because of its confusing "hoisting" behavior. + // Always use "let" or "const" instead. + // + // STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json + 'no-var': 2, + // RATIONALE: Generally not needed in modern code. + 'no-void': 1, + // RATIONALE: Obsolete language feature that is deprecated. + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'no-with': 2, + // RATIONALE: Makes logic easier to understand, since constants always have a known value + // @typescript-eslint\eslint-plugin\dist\configs\eslint-recommended.js + 'prefer-const': 1, + // RATIONALE: Catches a common coding mistake where "resolve" and "reject" are confused. + 'promise/param-names': 2, + // RATIONALE: Catches code that is likely to be incorrect + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'require-atomic-updates': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'require-yield': 1, + // "Use strict" is redundant when using the TypeScript compiler. + 'strict': [ + 2, + 'never' + ], + // RATIONALE: Catches code that is likely to be incorrect + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + 'use-isnan': 2, + // STANDARDIZED BY: eslint\conf\eslint-recommended.js + // Set to 1 (warning) or 2 (error) to enable. + // Rationale to disable: !!{} + 'no-extra-boolean-cast': 0, + // ==================================================================== + // @microsoft/eslint-plugin-spfx + // ==================================================================== + '@microsoft/spfx/import-requires-chunk-name': 1, + '@microsoft/spfx/no-require-ensure': 2, + '@microsoft/spfx/pair-react-dom-render-unmount': 1 + } + }, + { + // For unit tests, we can be a little bit less strict. The settings below revise the + // defaults specified in the extended configurations, as well as above. + files: [ + // Test files + '*.test.ts', + '*.test.tsx', + '*.spec.ts', + '*.spec.tsx', + + // Facebook convention + '**/__mocks__/*.ts', + '**/__mocks__/*.tsx', + '**/__tests__/*.ts', + '**/__tests__/*.tsx', + + // Microsoft convention + '**/test/*.ts', + '**/test/*.tsx' + ], + rules: { + 'no-new': 0, + 'class-name': 0, + 'export-name': 0, + forin: 0, + 'label-position': 0, + 'member-access': 2, + 'no-arg': 0, + 'no-console': 0, + 'no-construct': 0, + 'no-duplicate-variable': 2, + 'no-eval': 0, + 'no-function-expression': 2, + 'no-internal-module': 2, + 'no-shadowed-variable': 2, + 'no-switch-case-fall-through': 2, + 'no-unnecessary-semicolons': 2, + 'no-unused-expression': 2, + 'no-with-statement': 2, + semicolon: 2, + 'trailing-comma': 0, + typedef: 0, + 'typedef-whitespace': 0, + 'use-named-parameter': 2, + 'variable-name': 0, + whitespace: 0 + } + } + ] +}; \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/teamified-client/.gitignore b/samples/react-kiota-custom-api-client/teamified-client/.gitignore new file mode 100644 index 000000000..51ca7b9e7 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/.gitignore @@ -0,0 +1,34 @@ +# Logs +logs +*.log +npm-debug.log* + +# Dependency directories +node_modules + +# Build generated files +dist +lib +release +solution +temp +*.sppkg +.heft + +# Coverage directory used by tools like istanbul +coverage + +# OSX +.DS_Store + +# Visual Studio files +.ntvs_analysis.dat +.vs +bin +obj + +# Resx Generated Code +*.resx.ts + +# Styles Generated Code +*.scss.ts diff --git a/samples/react-kiota-custom-api-client/teamified-client/.npmignore b/samples/react-kiota-custom-api-client/teamified-client/.npmignore new file mode 100644 index 000000000..ae0b487c0 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/.npmignore @@ -0,0 +1,16 @@ +!dist +config + +gulpfile.js + +release +src +temp + +tsconfig.json +tslint.json + +*.log + +.yo-rc.json +.vscode diff --git a/samples/react-kiota-custom-api-client/teamified-client/.yo-rc.json b/samples/react-kiota-custom-api-client/teamified-client/.yo-rc.json new file mode 100644 index 000000000..48d3a60c2 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/.yo-rc.json @@ -0,0 +1,16 @@ +{ + "@microsoft/generator-sharepoint": { + "plusBeta": false, + "isCreatingSolution": true, + "version": "1.15.2", + "libraryName": "teamified-client", + "libraryId": "8635e38d-a794-47a5-8ee4-447fece15941", + "environment": "spo", + "packageManager": "npm", + "solutionName": "teamified-client", + "solutionShortDescription": "teamified-client description", + "skipFeatureDeployment": true, + "isDomainIsolated": false, + "componentType": "webpart" + } +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/README.md b/samples/react-kiota-custom-api-client/teamified-client/README.md new file mode 100644 index 000000000..d93ccaa7a --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/README.md @@ -0,0 +1,73 @@ +# teamified-client + +## Summary + +Short summary on functionality and used technologies. + +[picture of the solution in action, if possible] + +## Used SharePoint Framework Version + +![version](https://img.shields.io/badge/version-1.13-green.svg) + +## Applies to + +- [SharePoint Framework](https://aka.ms/spfx) +- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant) + +> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram) + +## Prerequisites + +> Any special pre-requisites? + +## Solution + +| Solution | Author(s) | +| ----------- | ------------------------------------------------------- | +| folder name | Author details (name, company, twitter alias with link) | + +## Version history + +| Version | Date | Comments | +| ------- | ---------------- | --------------- | +| 1.1 | March 10, 2021 | Update comment | +| 1.0 | January 29, 2021 | Initial release | + +## Disclaimer + +**THIS CODE IS PROVIDED _AS IS_ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.** + +--- + +## Minimal Path to Awesome + +- Clone this repository +- Ensure that you are at the solution folder +- in the command-line run: + - **npm install** + - **gulp serve** + +> Include any additional steps as needed. + +## Features + +Description of the extension that expands upon high-level summary above. + +This extension illustrates the following concepts: + +- topic 1 +- topic 2 +- topic 3 + +> Notice that better pictures and documentation will increase the sample usage and the value you are providing for others. Thanks for your submissions advance. + +> Share your web part with others through Microsoft 365 Patterns and Practices program to get visibility and exposure. More details on the community, open-source projects and other activities from http://aka.ms/m365pnp. + +## References + +- [Getting started with SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant) +- [Building for Microsoft teams](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/build-for-teams-overview) +- [Use Microsoft Graph in your solution](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/using-microsoft-graph-apis) +- [Publish SharePoint Framework applications to the Marketplace](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/publish-to-marketplace-overview) +- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - Guidance, tooling, samples and open-source controls for your Microsoft 365 development diff --git a/samples/react-kiota-custom-api-client/teamified-client/config/config.json b/samples/react-kiota-custom-api-client/teamified-client/config/config.json new file mode 100644 index 000000000..99b087112 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/config/config.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json", + "version": "2.0", + "bundles": { + "teams-list-web-part": { + "components": [ + { + "entrypoint": "./lib/webparts/teamsList/TeamsListWebPart.js", + "manifest": "./src/webparts/teamsList/TeamsListWebPart.manifest.json" + } + ] + } + }, + "externals": {}, + "localizedResources": { + "TeamsListWebPartStrings": "lib/webparts/teamsList/loc/{locale}.js" + } +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/config/deploy-azure-storage.json b/samples/react-kiota-custom-api-client/teamified-client/config/deploy-azure-storage.json new file mode 100644 index 000000000..0ac40c871 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/config/deploy-azure-storage.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json", + "workingDir": "./release/assets/", + "account": "", + "container": "teamified-client", + "accessKey": "" +} \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/teamified-client/config/package-solution.json b/samples/react-kiota-custom-api-client/teamified-client/config/package-solution.json new file mode 100644 index 000000000..c36200057 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/config/package-solution.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json", + "solution": { + "name": "teamified-client-client-side-solution", + "id": "8635e38d-a794-47a5-8ee4-447fece15941", + "version": "1.0.0.0", + "includeClientSideAssets": true, + "skipFeatureDeployment": true, + "isDomainIsolated": false, + "developer": { + "name": "", + "websiteUrl": "", + "privacyUrl": "", + "termsOfUseUrl": "", + "mpnId": "Undefined-1.15.2" + }, + "metadata": { + "shortDescription": { + "default": "teamified-client description" + }, + "longDescription": { + "default": "teamified-client description" + }, + "screenshotPaths": [], + "videoUrl": "", + "categories": [] + }, + "features": [ + { + "title": "teamified-client Feature", + "description": "The feature that activates elements of the teamified-client solution.", + "id": "5940d3fd-d3e8-44be-a153-d25e04db2c11", + "version": "1.0.0.0" + } + ] + }, + "paths": { + "zippedPackage": "solution/teamified-client.sppkg" + } +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/config/serve.json b/samples/react-kiota-custom-api-client/teamified-client/config/serve.json new file mode 100644 index 000000000..e05918a99 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/config/serve.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json", + "port": 4321, + "https": true, + "initialPage": "https://enter-your-SharePoint-site/_layouts/workbench.aspx" +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/config/write-manifests.json b/samples/react-kiota-custom-api-client/teamified-client/config/write-manifests.json new file mode 100644 index 000000000..bad352605 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/config/write-manifests.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json", + "cdnBasePath": "" +} \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/teamified-client/gulpfile.js b/samples/react-kiota-custom-api-client/teamified-client/gulpfile.js new file mode 100644 index 000000000..be2918708 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/gulpfile.js @@ -0,0 +1,16 @@ +'use strict'; + +const build = require('@microsoft/sp-build-web'); + +build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`); + +var getTasks = build.rig.getTasks; +build.rig.getTasks = function () { + var result = getTasks.call(build.rig); + + result.set('serve', result.get('serve-deprecated')); + + return result; +}; + +build.initialize(require('gulp')); diff --git a/samples/react-kiota-custom-api-client/teamified-client/package.json b/samples/react-kiota-custom-api-client/teamified-client/package.json new file mode 100644 index 000000000..d8c756870 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/package.json @@ -0,0 +1,43 @@ +{ + "name": "teamified-client", + "version": "0.0.1", + "private": true, + "main": "lib/index.js", + "scripts": { + "build": "gulp bundle", + "clean": "gulp clean", + "test": "gulp test" + }, + "dependencies": { + "@fluentui/react": "^8.99.2", + "@microsoft/kiota-abstractions": "^1.0.0-preview.6", + "@microsoft/kiota-authentication-spfx": "^1.0.0-preview.1", + "@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.8", + "@microsoft/kiota-serialization-json": "^1.0.0-preview.8", + "@microsoft/kiota-serialization-text": "^1.0.0-preview.7", + "@microsoft/sp-core-library": "1.15.2", + "@microsoft/sp-lodash-subset": "1.15.2", + "@microsoft/sp-office-ui-fabric-core": "1.15.2", + "@microsoft/sp-property-pane": "1.15.2", + "@microsoft/sp-webpart-base": "1.15.2", + "office-ui-fabric-react": "7.185.7", + "react": "16.13.1", + "react-dom": "16.13.1", + "tslib": "2.3.1" + }, + "devDependencies": { + "@microsoft/rush-stack-compiler-4.5": "0.2.2", + "@rushstack/eslint-config": "2.5.1", + "@microsoft/eslint-plugin-spfx": "1.15.2", + "@microsoft/eslint-config-spfx": "1.15.2", + "@microsoft/sp-build-web": "1.15.2", + "@types/webpack-env": "~1.15.2", + "ajv": "^6.12.5", + "gulp": "4.0.2", + "typescript": "4.5.5", + "@types/react": "16.9.51", + "@types/react-dom": "16.9.8", + "eslint-plugin-react-hooks": "4.3.0", + "@microsoft/sp-module-interfaces": "1.15.2" + } +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/index.ts b/samples/react-kiota-custom-api-client/teamified-client/src/index.ts new file mode 100644 index 000000000..fb81db1e2 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/index.ts @@ -0,0 +1 @@ +// A file is required to be in the root of the /src directory by the TypeScript compiler diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/TeamsListWebPart.manifest.json b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/TeamsListWebPart.manifest.json new file mode 100644 index 000000000..e68f64a20 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/TeamsListWebPart.manifest.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json", + "id": "a4533e12-f41c-448b-a1c8-2cb0ce6ad3bc", + "alias": "TeamsListWebPart", + "componentType": "WebPart", + + // The "*" signifies that the version should be taken from the package.json + "version": "*", + "manifestVersion": 2, + + // If true, the component can only be installed on sites where Custom Script is allowed. + // Components that allow authors to embed arbitrary script code should set this to true. + // https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f + "requiresCustomScript": false, + "supportedHosts": ["SharePointWebPart", "TeamsPersonalApp", "TeamsTab", "SharePointFullPage"], + "supportsThemeVariants": true, + + "preconfiguredEntries": [{ + "groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Advanced + "group": { "default": "Advanced" }, + "title": { "default": "TeamsList" }, + "description": { "default": "TeamsList description" }, + "officeFabricIconFontName": "Page", + "properties": { + "description": "TeamsList" + } + }] +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/TeamsListWebPart.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/TeamsListWebPart.ts new file mode 100644 index 000000000..922660c1a --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/TeamsListWebPart.ts @@ -0,0 +1,101 @@ +import * as React from 'react'; +import * as ReactDom from 'react-dom'; +import { Version } from '@microsoft/sp-core-library'; +import { + IPropertyPaneConfiguration, + PropertyPaneTextField +} from '@microsoft/sp-property-pane'; +import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base'; +import { IReadonlyTheme } from '@microsoft/sp-component-base'; + +import * as strings from 'TeamsListWebPartStrings'; +import TeamsList from './components/TeamsList'; +import { ITeamsListProps } from './components/ITeamsListProps'; + +export interface ITeamsListWebPartProps { + description: string; +} + +export default class TeamsListWebPart extends BaseClientSideWebPart { + + private _isDarkTheme: boolean = false; + private _environmentMessage: string = ''; + + public render(): void { + const element: React.ReactElement = React.createElement( + TeamsList, + { + description: this.properties.description, + isDarkTheme: this._isDarkTheme, + environmentMessage: this._environmentMessage, + hasTeamsContext: !!this.context.sdks.microsoftTeams, + userDisplayName: this.context.pageContext.user.displayName, + aadTokenProviderFactory: this.context.aadTokenProviderFactory + } + ); + + ReactDom.render(element, this.domElement); + } + + protected onInit(): Promise { + this._environmentMessage = this._getEnvironmentMessage(); + + return super.onInit(); + } + + private _getEnvironmentMessage(): string { + if (!!this.context.sdks.microsoftTeams) { // running in Teams + return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentTeams : strings.AppTeamsTabEnvironment; + } + + return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentSharePoint : strings.AppSharePointEnvironment; + } + + protected onThemeChanged(currentTheme: IReadonlyTheme | undefined): void { + if (!currentTheme) { + return; + } + + this._isDarkTheme = !!currentTheme.isInverted; + const { + semanticColors + } = currentTheme; + + if (semanticColors) { + this.domElement.style.setProperty('--bodyText', semanticColors.bodyText || null); + this.domElement.style.setProperty('--link', semanticColors.link || null); + this.domElement.style.setProperty('--linkHovered', semanticColors.linkHovered || null); + } + + } + + protected onDispose(): void { + ReactDom.unmountComponentAtNode(this.domElement); + } + + protected get dataVersion(): Version { + return Version.parse('1.0'); + } + + protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { + return { + pages: [ + { + header: { + description: strings.PropertyPaneDescription + }, + groups: [ + { + groupName: strings.BasicGroupName, + groupFields: [ + PropertyPaneTextField('description', { + label: strings.DescriptionFieldLabel + }) + ] + } + ] + } + ] + }; + } +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/assets/welcome-dark.png b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/assets/welcome-dark.png new file mode 100644 index 000000000..16f04d404 Binary files /dev/null and b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/assets/welcome-dark.png differ diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/assets/welcome-light.png b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/assets/welcome-light.png new file mode 100644 index 000000000..16f04d404 Binary files /dev/null and b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/assets/welcome-light.png differ diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/channel.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/channel.ts new file mode 100644 index 000000000..c82ad3673 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/channel.ts @@ -0,0 +1,73 @@ +import {Parsable, ParseNode, SerializationWriter} from '@microsoft/kiota-abstractions'; + +export class Channel implements Parsable { + /** The description property */ + private _description?: string | undefined; + /** The displayName property */ + private _displayName?: string | undefined; + /** The id property */ + private _id?: string | undefined; + /** + * Gets the description property value. The description property + * @returns a string + */ + public get description() { + return this._description; + }; + /** + * Sets the description property value. The description property + * @param value Value to set for the description property. + */ + public set description(value: string | undefined) { + this._description = value; + }; + /** + * Gets the displayName property value. The displayName property + * @returns a string + */ + public get displayName() { + return this._displayName; + }; + /** + * Sets the displayName property value. The displayName property + * @param value Value to set for the displayName property. + */ + public set displayName(value: string | undefined) { + this._displayName = value; + }; + /** + * The deserialization information for the current model + * @returns a Record void> + */ + public getFieldDeserializers() : Record void> { + return { + "description": n => { this.description = n.getStringValue(); }, + "displayName": n => { this.displayName = n.getStringValue(); }, + "id": n => { this.id = n.getStringValue(); }, + }; + }; + /** + * Gets the id property value. The id property + * @returns a string + */ + public get id() { + return this._id; + }; + /** + * Sets the id property value. The id property + * @param value Value to set for the id property. + */ + public set id(value: string | undefined) { + this._id = value; + }; + /** + * Serializes information the current object + * @param writer Serialization writer to use to serialize this model + */ + public serialize(writer: SerializationWriter) : void { + if(!writer) throw new Error("writer cannot be undefined"); + writer.writeStringValue("description", this.description); + writer.writeStringValue("displayName", this.displayName); + writer.writeStringValue("id", this.id); + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createChannelFromDiscriminatorValue.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createChannelFromDiscriminatorValue.ts new file mode 100644 index 000000000..140017fae --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createChannelFromDiscriminatorValue.ts @@ -0,0 +1,7 @@ +import {Channel} from './index'; +import {ParseNode} from '@microsoft/kiota-abstractions'; + +export function createChannelFromDiscriminatorValue(parseNode: ParseNode | undefined) : Channel { + if(!parseNode) throw new Error("parseNode cannot be undefined"); + return new Channel(); +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createIdentityPrincipalFromDiscriminatorValue.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createIdentityPrincipalFromDiscriminatorValue.ts new file mode 100644 index 000000000..2369db787 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createIdentityPrincipalFromDiscriminatorValue.ts @@ -0,0 +1,7 @@ +import {IdentityPrincipal} from './index'; +import {ParseNode} from '@microsoft/kiota-abstractions'; + +export function createIdentityPrincipalFromDiscriminatorValue(parseNode: ParseNode | undefined) : IdentityPrincipal { + if(!parseNode) throw new Error("parseNode cannot be undefined"); + return new IdentityPrincipal(); +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createPingFromDiscriminatorValue.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createPingFromDiscriminatorValue.ts new file mode 100644 index 000000000..61832a967 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createPingFromDiscriminatorValue.ts @@ -0,0 +1,7 @@ +import {Ping} from './index'; +import {ParseNode} from '@microsoft/kiota-abstractions'; + +export function createPingFromDiscriminatorValue(parseNode: ParseNode | undefined) : Ping { + if(!parseNode) throw new Error("parseNode cannot be undefined"); + return new Ping(); +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createProvisionTeamCommandFromDiscriminatorValue.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createProvisionTeamCommandFromDiscriminatorValue.ts new file mode 100644 index 000000000..9a8cd88c7 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createProvisionTeamCommandFromDiscriminatorValue.ts @@ -0,0 +1,7 @@ +import {ProvisionTeamCommand} from './index'; +import {ParseNode} from '@microsoft/kiota-abstractions'; + +export function createProvisionTeamCommandFromDiscriminatorValue(parseNode: ParseNode | undefined) : ProvisionTeamCommand { + if(!parseNode) throw new Error("parseNode cannot be undefined"); + return new ProvisionTeamCommand(); +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createTeamFromDiscriminatorValue.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createTeamFromDiscriminatorValue.ts new file mode 100644 index 000000000..5fb01c8f7 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/createTeamFromDiscriminatorValue.ts @@ -0,0 +1,7 @@ +import {Team} from './index'; +import {ParseNode} from '@microsoft/kiota-abstractions'; + +export function createTeamFromDiscriminatorValue(parseNode: ParseNode | undefined) : Team { + if(!parseNode) throw new Error("parseNode cannot be undefined"); + return new Team(); +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/identityPrincipal.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/identityPrincipal.ts new file mode 100644 index 000000000..990b25b39 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/identityPrincipal.ts @@ -0,0 +1,109 @@ +import {Parsable, ParseNode, SerializationWriter} from '@microsoft/kiota-abstractions'; + +export class IdentityPrincipal implements Parsable { + /** The displayName property */ + private _displayName?: string | undefined; + /** The email property */ + private _email?: string | undefined; + /** The id property */ + private _id?: string | undefined; + /** The jobTitle property */ + private _jobTitle?: string | undefined; + /** The userPrincipalName property */ + private _userPrincipalName?: string | undefined; + /** + * Gets the displayName property value. The displayName property + * @returns a string + */ + public get displayName() { + return this._displayName; + }; + /** + * Sets the displayName property value. The displayName property + * @param value Value to set for the displayName property. + */ + public set displayName(value: string | undefined) { + this._displayName = value; + }; + /** + * Gets the email property value. The email property + * @returns a string + */ + public get email() { + return this._email; + }; + /** + * Sets the email property value. The email property + * @param value Value to set for the email property. + */ + public set email(value: string | undefined) { + this._email = value; + }; + /** + * The deserialization information for the current model + * @returns a Record void> + */ + public getFieldDeserializers() : Record void> { + return { + "displayName": n => { this.displayName = n.getStringValue(); }, + "email": n => { this.email = n.getStringValue(); }, + "id": n => { this.id = n.getStringValue(); }, + "jobTitle": n => { this.jobTitle = n.getStringValue(); }, + "userPrincipalName": n => { this.userPrincipalName = n.getStringValue(); }, + }; + }; + /** + * Gets the id property value. The id property + * @returns a string + */ + public get id() { + return this._id; + }; + /** + * Sets the id property value. The id property + * @param value Value to set for the id property. + */ + public set id(value: string | undefined) { + this._id = value; + }; + /** + * Gets the jobTitle property value. The jobTitle property + * @returns a string + */ + public get jobTitle() { + return this._jobTitle; + }; + /** + * Sets the jobTitle property value. The jobTitle property + * @param value Value to set for the jobTitle property. + */ + public set jobTitle(value: string | undefined) { + this._jobTitle = value; + }; + /** + * Serializes information the current object + * @param writer Serialization writer to use to serialize this model + */ + public serialize(writer: SerializationWriter) : void { + if(!writer) throw new Error("writer cannot be undefined"); + writer.writeStringValue("displayName", this.displayName); + writer.writeStringValue("email", this.email); + writer.writeStringValue("id", this.id); + writer.writeStringValue("jobTitle", this.jobTitle); + writer.writeStringValue("userPrincipalName", this.userPrincipalName); + }; + /** + * Gets the userPrincipalName property value. The userPrincipalName property + * @returns a string + */ + public get userPrincipalName() { + return this._userPrincipalName; + }; + /** + * Sets the userPrincipalName property value. The userPrincipalName property + * @param value Value to set for the userPrincipalName property. + */ + public set userPrincipalName(value: string | undefined) { + this._userPrincipalName = value; + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/index.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/index.ts new file mode 100644 index 000000000..df08105cd --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/index.ts @@ -0,0 +1,5 @@ +export * from './team' +export * from './ping' +export * from './identityPrincipal' +export * from './provisionTeamCommand' +export * from './channel' diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/ping.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/ping.ts new file mode 100644 index 000000000..b1e2e885b --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/ping.ts @@ -0,0 +1,55 @@ +import {Parsable, ParseNode, SerializationWriter} from '@microsoft/kiota-abstractions'; + +export class Ping implements Parsable { + /** The id property */ + private _id?: string | undefined; + /** The now property */ + private _now?: string | undefined; + /** + * The deserialization information for the current model + * @returns a Record void> + */ + public getFieldDeserializers() : Record void> { + return { + "id": n => { this.id = n.getStringValue(); }, + "now": n => { this.now = n.getStringValue(); }, + }; + }; + /** + * Gets the id property value. The id property + * @returns a string + */ + public get id() { + return this._id; + }; + /** + * Sets the id property value. The id property + * @param value Value to set for the id property. + */ + public set id(value: string | undefined) { + this._id = value; + }; + /** + * Gets the now property value. The now property + * @returns a string + */ + public get now() { + return this._now; + }; + /** + * Sets the now property value. The now property + * @param value Value to set for the now property. + */ + public set now(value: string | undefined) { + this._now = value; + }; + /** + * Serializes information the current object + * @param writer Serialization writer to use to serialize this model + */ + public serialize(writer: SerializationWriter) : void { + if(!writer) throw new Error("writer cannot be undefined"); + writer.writeStringValue("id", this.id); + writer.writeStringValue("now", this.now); + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/provisionTeamCommand.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/provisionTeamCommand.ts new file mode 100644 index 000000000..ed925a92a --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/provisionTeamCommand.ts @@ -0,0 +1,55 @@ +import {Parsable, ParseNode, SerializationWriter} from '@microsoft/kiota-abstractions'; + +export class ProvisionTeamCommand implements Parsable { + /** The description property */ + private _description?: string | undefined; + /** The displayName property */ + private _displayName?: string | undefined; + /** + * Gets the description property value. The description property + * @returns a string + */ + public get description() { + return this._description; + }; + /** + * Sets the description property value. The description property + * @param value Value to set for the description property. + */ + public set description(value: string | undefined) { + this._description = value; + }; + /** + * Gets the displayName property value. The displayName property + * @returns a string + */ + public get displayName() { + return this._displayName; + }; + /** + * Sets the displayName property value. The displayName property + * @param value Value to set for the displayName property. + */ + public set displayName(value: string | undefined) { + this._displayName = value; + }; + /** + * The deserialization information for the current model + * @returns a Record void> + */ + public getFieldDeserializers() : Record void> { + return { + "description": n => { this.description = n.getStringValue(); }, + "displayName": n => { this.displayName = n.getStringValue(); }, + }; + }; + /** + * Serializes information the current object + * @param writer Serialization writer to use to serialize this model + */ + public serialize(writer: SerializationWriter) : void { + if(!writer) throw new Error("writer cannot be undefined"); + writer.writeStringValue("description", this.description); + writer.writeStringValue("displayName", this.displayName); + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/team.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/team.ts new file mode 100644 index 000000000..de68d9759 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/models/team.ts @@ -0,0 +1,130 @@ +import {createChannelFromDiscriminatorValue} from './createChannelFromDiscriminatorValue'; +import {createIdentityPrincipalFromDiscriminatorValue} from './createIdentityPrincipalFromDiscriminatorValue'; +import {Channel, IdentityPrincipal} from './index'; +import {Parsable, ParseNode, SerializationWriter} from '@microsoft/kiota-abstractions'; + +export class Team implements Parsable { + /** The channels property */ + private _channels?: Channel[] | undefined; + /** The description property */ + private _description?: string | undefined; + /** The displayName property */ + private _displayName?: string | undefined; + /** The id property */ + private _id?: string | undefined; + /** The members property */ + private _members?: IdentityPrincipal[] | undefined; + /** The owners property */ + private _owners?: IdentityPrincipal[] | undefined; + /** + * Gets the channels property value. The channels property + * @returns a Channel + */ + public get channels() { + return this._channels; + }; + /** + * Sets the channels property value. The channels property + * @param value Value to set for the channels property. + */ + public set channels(value: Channel[] | undefined) { + this._channels = value; + }; + /** + * Gets the description property value. The description property + * @returns a string + */ + public get description() { + return this._description; + }; + /** + * Sets the description property value. The description property + * @param value Value to set for the description property. + */ + public set description(value: string | undefined) { + this._description = value; + }; + /** + * Gets the displayName property value. The displayName property + * @returns a string + */ + public get displayName() { + return this._displayName; + }; + /** + * Sets the displayName property value. The displayName property + * @param value Value to set for the displayName property. + */ + public set displayName(value: string | undefined) { + this._displayName = value; + }; + /** + * The deserialization information for the current model + * @returns a Record void> + */ + public getFieldDeserializers() : Record void> { + return { + "channels": n => { this.channels = n.getCollectionOfObjectValues(createChannelFromDiscriminatorValue); }, + "description": n => { this.description = n.getStringValue(); }, + "displayName": n => { this.displayName = n.getStringValue(); }, + "id": n => { this.id = n.getStringValue(); }, + "members": n => { this.members = n.getCollectionOfObjectValues(createIdentityPrincipalFromDiscriminatorValue); }, + "owners": n => { this.owners = n.getCollectionOfObjectValues(createIdentityPrincipalFromDiscriminatorValue); }, + }; + }; + /** + * Gets the id property value. The id property + * @returns a string + */ + public get id() { + return this._id; + }; + /** + * Sets the id property value. The id property + * @param value Value to set for the id property. + */ + public set id(value: string | undefined) { + this._id = value; + }; + /** + * Gets the members property value. The members property + * @returns a IdentityPrincipal + */ + public get members() { + return this._members; + }; + /** + * Sets the members property value. The members property + * @param value Value to set for the members property. + */ + public set members(value: IdentityPrincipal[] | undefined) { + this._members = value; + }; + /** + * Gets the owners property value. The owners property + * @returns a IdentityPrincipal + */ + public get owners() { + return this._owners; + }; + /** + * Sets the owners property value. The owners property + * @param value Value to set for the owners property. + */ + public set owners(value: IdentityPrincipal[] | undefined) { + this._owners = value; + }; + /** + * Serializes information the current object + * @param writer Serialization writer to use to serialize this model + */ + public serialize(writer: SerializationWriter) : void { + if(!writer) throw new Error("writer cannot be undefined"); + writer.writeCollectionOfObjectValues("channels", this.channels); + writer.writeStringValue("description", this.description); + writer.writeStringValue("displayName", this.displayName); + writer.writeStringValue("id", this.id); + writer.writeCollectionOfObjectValues("members", this.members); + writer.writeCollectionOfObjectValues("owners", this.owners); + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/ping/pingRequestBuilder.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/ping/pingRequestBuilder.ts new file mode 100644 index 000000000..91e15c539 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/ping/pingRequestBuilder.ts @@ -0,0 +1,45 @@ +import {Ping} from '../models/'; +import {createPingFromDiscriminatorValue} from '../models/createPingFromDiscriminatorValue'; +import {PingRequestBuilderGetRequestConfiguration} from './pingRequestBuilderGetRequestConfiguration'; +import {getPathParameters, HttpMethod, Parsable, ParsableFactory, RequestAdapter, RequestInformation, RequestOption, ResponseHandler} from '@microsoft/kiota-abstractions'; + +/** Builds and executes requests for operations under /ping */ +export class PingRequestBuilder { + /** Path parameters for the request */ + private readonly pathParameters: Record; + /** The request adapter to use to execute the requests. */ + private readonly requestAdapter: RequestAdapter; + /** Url template to use to build the URL for the current request builder */ + private readonly urlTemplate: string; + /** + * Instantiates a new PingRequestBuilder and sets the default values. + * @param pathParameters The raw url or the Url template parameters for the request. + * @param requestAdapter The request adapter to use to execute the requests. + */ + public constructor(pathParameters: Record | string | undefined, requestAdapter: RequestAdapter) { + if(!pathParameters) throw new Error("pathParameters cannot be undefined"); + if(!requestAdapter) throw new Error("requestAdapter cannot be undefined"); + this.urlTemplate = "{+baseurl}/ping"; + const urlTplParams = getPathParameters(pathParameters); + this.pathParameters = urlTplParams; + this.requestAdapter = requestAdapter; + }; + public createGetRequestInformation(requestConfiguration?: PingRequestBuilderGetRequestConfiguration | undefined) : RequestInformation { + const requestInfo = new RequestInformation(); + requestInfo.urlTemplate = this.urlTemplate; + requestInfo.pathParameters = this.pathParameters; + requestInfo.httpMethod = HttpMethod.GET; + requestInfo.headers["Accept"] = "application/json"; + if (requestConfiguration) { + requestInfo.addRequestHeaders(requestConfiguration.headers); + requestInfo.addRequestOptions(requestConfiguration.options); + } + return requestInfo; + }; + public get(requestConfiguration?: PingRequestBuilderGetRequestConfiguration | undefined, responseHandler?: ResponseHandler | undefined) : Promise { + const requestInfo = this.createGetRequestInformation( + requestConfiguration + ); + return this.requestAdapter?.sendAsync(requestInfo, createPingFromDiscriminatorValue, responseHandler, undefined) ?? Promise.reject(new Error('http core is null')); + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/ping/pingRequestBuilderGetRequestConfiguration.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/ping/pingRequestBuilderGetRequestConfiguration.ts new file mode 100644 index 000000000..a7d833787 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/ping/pingRequestBuilderGetRequestConfiguration.ts @@ -0,0 +1,9 @@ +import {RequestOption} from '@microsoft/kiota-abstractions'; + +/** Configuration for the request such as headers, query parameters, and middleware options. */ +export class PingRequestBuilderGetRequestConfiguration { + /** Request headers */ + public headers?: Record | undefined; + /** Request options */ + public options?: RequestOption[] | undefined; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teamifiedApiClient.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teamifiedApiClient.ts new file mode 100644 index 000000000..7c47e9318 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teamifiedApiClient.ts @@ -0,0 +1,52 @@ +import {PingRequestBuilder} from './ping/pingRequestBuilder'; +import {TeamsItemRequestBuilder} from './teams/item/teamsItemRequestBuilder'; +import {TeamsRequestBuilder} from './teams/teamsRequestBuilder'; +import {enableBackingStoreForSerializationWriterFactory, getPathParameters, ParseNodeFactoryRegistry, registerDefaultDeserializer, registerDefaultSerializer, RequestAdapter, SerializationWriterFactoryRegistry} from '@microsoft/kiota-abstractions'; +import {JsonParseNodeFactory, JsonSerializationWriterFactory} from '@microsoft/kiota-serialization-json'; +import {TextParseNodeFactory, TextSerializationWriterFactory} from '@microsoft/kiota-serialization-text'; + +/** The main entry point of the SDK, exposes the configuration and the fluent API. */ +export class TeamifiedApiClient { + /** Path parameters for the request */ + private readonly pathParameters: Record; + /** The ping property */ + public get ping(): PingRequestBuilder { + return new PingRequestBuilder(this.pathParameters, this.requestAdapter); + } + /** The request adapter to use to execute the requests. */ + private readonly requestAdapter: RequestAdapter; + /** The teams property */ + public get teams(): TeamsRequestBuilder { + return new TeamsRequestBuilder(this.pathParameters, this.requestAdapter); + } + /** Url template to use to build the URL for the current request builder */ + private readonly urlTemplate: string; + /** + * Instantiates a new TeamifiedApiClient and sets the default values. + * @param requestAdapter The request adapter to use to execute the requests. + */ + public constructor(requestAdapter: RequestAdapter) { + if(!requestAdapter) throw new Error("requestAdapter cannot be undefined"); + this.pathParameters = {}; + this.urlTemplate = "{+baseurl}"; + this.requestAdapter = requestAdapter; + registerDefaultSerializer(JsonSerializationWriterFactory); + registerDefaultSerializer(TextSerializationWriterFactory); + registerDefaultDeserializer(JsonParseNodeFactory); + registerDefaultDeserializer(TextParseNodeFactory); + if (requestAdapter.baseUrl === undefined || requestAdapter.baseUrl === "") { + requestAdapter.baseUrl = "https://localhost:7295"; + } + }; + /** + * Gets an item from the Teamified.Sdk.teams.item collection + * @param id Unique identifier of the item + * @returns a TeamsItemRequestBuilder + */ + public teamsById(id: string) : TeamsItemRequestBuilder { + if(!id) throw new Error("id cannot be undefined"); + const urlTplParams = getPathParameters(this.pathParameters); + urlTplParams["id"] = id + return new TeamsItemRequestBuilder(urlTplParams, this.requestAdapter); + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/item/teamsItemRequestBuilder.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/item/teamsItemRequestBuilder.ts new file mode 100644 index 000000000..7930c08c8 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/item/teamsItemRequestBuilder.ts @@ -0,0 +1,45 @@ +import {Team} from '../../models/'; +import {createTeamFromDiscriminatorValue} from '../../models/createTeamFromDiscriminatorValue'; +import {TeamsItemRequestBuilderGetRequestConfiguration} from './teamsItemRequestBuilderGetRequestConfiguration'; +import {getPathParameters, HttpMethod, Parsable, ParsableFactory, RequestAdapter, RequestInformation, RequestOption, ResponseHandler} from '@microsoft/kiota-abstractions'; + +/** Builds and executes requests for operations under /teams/{id} */ +export class TeamsItemRequestBuilder { + /** Path parameters for the request */ + private readonly pathParameters: Record; + /** The request adapter to use to execute the requests. */ + private readonly requestAdapter: RequestAdapter; + /** Url template to use to build the URL for the current request builder */ + private readonly urlTemplate: string; + /** + * Instantiates a new TeamsItemRequestBuilder and sets the default values. + * @param pathParameters The raw url or the Url template parameters for the request. + * @param requestAdapter The request adapter to use to execute the requests. + */ + public constructor(pathParameters: Record | string | undefined, requestAdapter: RequestAdapter) { + if(!pathParameters) throw new Error("pathParameters cannot be undefined"); + if(!requestAdapter) throw new Error("requestAdapter cannot be undefined"); + this.urlTemplate = "{+baseurl}/teams/{id}"; + const urlTplParams = getPathParameters(pathParameters); + this.pathParameters = urlTplParams; + this.requestAdapter = requestAdapter; + }; + public createGetRequestInformation(requestConfiguration?: TeamsItemRequestBuilderGetRequestConfiguration | undefined) : RequestInformation { + const requestInfo = new RequestInformation(); + requestInfo.urlTemplate = this.urlTemplate; + requestInfo.pathParameters = this.pathParameters; + requestInfo.httpMethod = HttpMethod.GET; + requestInfo.headers["Accept"] = "application/json"; + if (requestConfiguration) { + requestInfo.addRequestHeaders(requestConfiguration.headers); + requestInfo.addRequestOptions(requestConfiguration.options); + } + return requestInfo; + }; + public get(requestConfiguration?: TeamsItemRequestBuilderGetRequestConfiguration | undefined, responseHandler?: ResponseHandler | undefined) : Promise { + const requestInfo = this.createGetRequestInformation( + requestConfiguration + ); + return this.requestAdapter?.sendAsync(requestInfo, createTeamFromDiscriminatorValue, responseHandler, undefined) ?? Promise.reject(new Error('http core is null')); + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/item/teamsItemRequestBuilderGetRequestConfiguration.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/item/teamsItemRequestBuilderGetRequestConfiguration.ts new file mode 100644 index 000000000..7907f4364 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/item/teamsItemRequestBuilderGetRequestConfiguration.ts @@ -0,0 +1,9 @@ +import {RequestOption} from '@microsoft/kiota-abstractions'; + +/** Configuration for the request such as headers, query parameters, and middleware options. */ +export class TeamsItemRequestBuilderGetRequestConfiguration { + /** Request headers */ + public headers?: Record | undefined; + /** Request options */ + public options?: RequestOption[] | undefined; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilder.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilder.ts new file mode 100644 index 000000000..1dcaa6339 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilder.ts @@ -0,0 +1,67 @@ +import {ProvisionTeamCommand, Team} from '../models/'; +import {createTeamFromDiscriminatorValue} from '../models/createTeamFromDiscriminatorValue'; +import {TeamsRequestBuilderGetRequestConfiguration} from './teamsRequestBuilderGetRequestConfiguration'; +import {TeamsRequestBuilderPostRequestConfiguration} from './teamsRequestBuilderPostRequestConfiguration'; +import {getPathParameters, HttpMethod, Parsable, ParsableFactory, RequestAdapter, RequestInformation, RequestOption, ResponseHandler} from '@microsoft/kiota-abstractions'; + +/** Builds and executes requests for operations under /teams */ +export class TeamsRequestBuilder { + /** Path parameters for the request */ + private readonly pathParameters: Record; + /** The request adapter to use to execute the requests. */ + private readonly requestAdapter: RequestAdapter; + /** Url template to use to build the URL for the current request builder */ + private readonly urlTemplate: string; + /** + * Instantiates a new TeamsRequestBuilder and sets the default values. + * @param pathParameters The raw url or the Url template parameters for the request. + * @param requestAdapter The request adapter to use to execute the requests. + */ + public constructor(pathParameters: Record | string | undefined, requestAdapter: RequestAdapter) { + if(!pathParameters) throw new Error("pathParameters cannot be undefined"); + if(!requestAdapter) throw new Error("requestAdapter cannot be undefined"); + this.urlTemplate = "{+baseurl}/teams"; + const urlTplParams = getPathParameters(pathParameters); + this.pathParameters = urlTplParams; + this.requestAdapter = requestAdapter; + }; + public createGetRequestInformation(requestConfiguration?: TeamsRequestBuilderGetRequestConfiguration | undefined) : RequestInformation { + const requestInfo = new RequestInformation(); + requestInfo.urlTemplate = this.urlTemplate; + requestInfo.pathParameters = this.pathParameters; + requestInfo.httpMethod = HttpMethod.GET; + requestInfo.headers["Accept"] = "application/json"; + if (requestConfiguration) { + requestInfo.addRequestHeaders(requestConfiguration.headers); + requestInfo.addRequestOptions(requestConfiguration.options); + } + return requestInfo; + }; + public createPostRequestInformation(body: ProvisionTeamCommand | undefined, requestConfiguration?: TeamsRequestBuilderPostRequestConfiguration | undefined) : RequestInformation { + if(!body) throw new Error("body cannot be undefined"); + const requestInfo = new RequestInformation(); + requestInfo.urlTemplate = this.urlTemplate; + requestInfo.pathParameters = this.pathParameters; + requestInfo.httpMethod = HttpMethod.POST; + requestInfo.headers["Accept"] = "application/json"; + if (requestConfiguration) { + requestInfo.addRequestHeaders(requestConfiguration.headers); + requestInfo.addRequestOptions(requestConfiguration.options); + } + requestInfo.setContentFromParsable(this.requestAdapter, "application/json", body); + return requestInfo; + }; + public get(requestConfiguration?: TeamsRequestBuilderGetRequestConfiguration | undefined, responseHandler?: ResponseHandler | undefined) : Promise { + const requestInfo = this.createGetRequestInformation( + requestConfiguration + ); + return this.requestAdapter?.sendCollectionAsync(requestInfo, createTeamFromDiscriminatorValue, responseHandler, undefined) ?? Promise.reject(new Error('http core is null')); + }; + public post(body: ProvisionTeamCommand | undefined, requestConfiguration?: TeamsRequestBuilderPostRequestConfiguration | undefined, responseHandler?: ResponseHandler | undefined) : Promise { + if(!body) throw new Error("body cannot be undefined"); + const requestInfo = this.createPostRequestInformation( + body, requestConfiguration + ); + return this.requestAdapter?.sendPrimitiveAsync(requestInfo, "string", responseHandler, undefined) ?? Promise.reject(new Error('http core is null')); + }; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilderGetRequestConfiguration.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilderGetRequestConfiguration.ts new file mode 100644 index 000000000..633599466 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilderGetRequestConfiguration.ts @@ -0,0 +1,9 @@ +import {RequestOption} from '@microsoft/kiota-abstractions'; + +/** Configuration for the request such as headers, query parameters, and middleware options. */ +export class TeamsRequestBuilderGetRequestConfiguration { + /** Request headers */ + public headers?: Record | undefined; + /** Request options */ + public options?: RequestOption[] | undefined; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilderPostRequestConfiguration.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilderPostRequestConfiguration.ts new file mode 100644 index 000000000..3e64e7109 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/client/teams/teamsRequestBuilderPostRequestConfiguration.ts @@ -0,0 +1,9 @@ +import {RequestOption} from '@microsoft/kiota-abstractions'; + +/** Configuration for the request such as headers, query parameters, and middleware options. */ +export class TeamsRequestBuilderPostRequestConfiguration { + /** Request headers */ + public headers?: Record | undefined; + /** Request options */ + public options?: RequestOption[] | undefined; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/ITeamsListProps.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/ITeamsListProps.ts new file mode 100644 index 000000000..02332cbd5 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/ITeamsListProps.ts @@ -0,0 +1,10 @@ +import { AadTokenProviderFactory } from '@microsoft/sp-http'; + +export interface ITeamsListProps { + description: string; + isDarkTheme: boolean; + environmentMessage: string; + hasTeamsContext: boolean; + userDisplayName: string; + aadTokenProviderFactory: AadTokenProviderFactory; +} \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/ITeamsListState.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/ITeamsListState.ts new file mode 100644 index 000000000..b52f3f043 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/ITeamsListState.ts @@ -0,0 +1,6 @@ +import { Team } from '../client/models'; + + +export interface ITeamsListState { + teams: Team[]; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/TeamsList.module.scss b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/TeamsList.module.scss new file mode 100644 index 000000000..2406e9e61 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/TeamsList.module.scss @@ -0,0 +1,50 @@ +@import '~office-ui-fabric-react/dist/sass/References.scss'; + +.teamsList { + overflow: hidden; + padding: 1em; + color: "[theme:bodyText, default: #323130]"; + color: var(--bodyText); + &.teams { + font-family: $ms-font-family-fallbacks; + } +} + +ul.nobullets { + list-style-type: none; /* Remove bullets */ + padding: 5px; /* Remove padding */ + margin: 0; /* Remove margins */ +} + +.welcome { + text-align: center; +} + +.welcomeImage { + max-width: 420px; +} + +.facepile { + padding-left: 15px; +} + +.wrapper { + display: grid; + grid-template-columns: 1fr 1fr; + padding: 5px; + row-gap: 1em; +} + +.links { + a { + text-decoration: none; + color: "[theme:link, default:#03787c]"; + color: var(--link); // note: CSS Custom Properties support is limited to modern browsers only + + &:hover { + text-decoration: underline; + color: "[theme:linkHovered, default: #014446]"; + color: var(--linkHovered); // note: CSS Custom Properties support is limited to modern browsers only + } + } +} \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/TeamsList.tsx b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/TeamsList.tsx new file mode 100644 index 000000000..8252bf199 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/components/TeamsList.tsx @@ -0,0 +1,124 @@ +import * as React from 'react'; +import styles from './TeamsList.module.scss'; +import { ITeamsListProps } from './ITeamsListProps'; +import { ITeamsListState } from "./ITeamsListState"; +import { escape } from '@microsoft/sp-lodash-subset'; +import { AadTokenProvider } from '@microsoft/sp-http'; +import { FetchRequestAdapter } from '@microsoft/kiota-http-fetchlibrary'; +import { TeamifiedApiClient } from '../client/teamifiedApiClient'; +import { AzureAdSpfxAuthenticationProvider } from '@microsoft/kiota-authentication-spfx'; + +import { + ImageFit, + MessageBar, PersonaSize +} from '@fluentui/react'; +import { + DocumentCard, + DocumentCardDetails, + DocumentCardPreview, + DocumentCardTitle, + IDocumentCardPreviewProps, + DocumentCardType, +} from '@fluentui/react/lib/DocumentCard'; +import { Facepile, IFacepilePersona } from '@fluentui/react/lib/Facepile'; + +export default class TeamsList extends React.Component { + + // #region ******************** UPDATE WITH YOUR TENANT DATA ******************** + private readonly azureAdApplicationIdUri: string = "api://{AZURE_AD_CLIENT_ID}"; + private readonly apiHost: string = "{YOUR_API}.azurewebsites.net"; + // #endregion + + constructor(props: ITeamsListProps) { + super(props); + this.state = { + teams: [] + }; + } + + public componentDidMount(): void { + this.props.aadTokenProviderFactory.getTokenProvider() + .then((tokenProvider: AadTokenProvider): void => { + + const authProvider = + new AzureAdSpfxAuthenticationProvider( + tokenProvider, + this.azureAdApplicationIdUri, + new Set([ + this.apiHost + ])); + + const adapter = new FetchRequestAdapter(authProvider); + adapter.baseUrl = `https://${this.apiHost}`; + + const teamifiedClient = new TeamifiedApiClient(adapter); + + teamifiedClient.teams.get().then(teams => { + console.log(teams); + this.setState({ + teams: teams + }); + }) + .catch(e => {console.log(e)}); + }) + .catch(e => {console.log(e)}); + } + + public render(): React.ReactElement { + const { + isDarkTheme, + environmentMessage, + hasTeamsContext, + userDisplayName + } = this.props; + + const teams = this.state.teams.length > 0 ? +
{this.state.teams.map((t, i) => { + const imageIndex = 100 + i; + const previewProps: IDocumentCardPreviewProps = { + previewImages: [ + { + previewImageSrc: `https://picsum.photos/id/${imageIndex}/318/150`, + imageFit: ImageFit.cover, + width: 318, + height: 150, + }, + ], + }; + + const personas: IFacepilePersona[] = t.members.map(m => { + const nameSplit: string[] = m.displayName.split(' '); + const firstNameInitial: string = nameSplit[0].substring(0, 1).toUpperCase(); + const lastNameInitial: string = nameSplit[1] ? nameSplit[1].substring(0, 1).toUpperCase() : ''; + const persona: IFacepilePersona = { + personaName: m.displayName, + imageInitials: `${firstNameInitial} ${lastNameInitial}` + } + return persona; + }); + + return ( + + + + + + + + ); + })} +
:
Loading data...
+ + return ( +
+
+ + Welcome, {escape(userDisplayName)}. {environmentMessage} +
+
+ {teams} +
+
+ ); + } +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/loc/en-us.js b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/loc/en-us.js new file mode 100644 index 000000000..7efbd643f --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/loc/en-us.js @@ -0,0 +1,11 @@ +define([], function() { + return { + "PropertyPaneDescription": "Description", + "BasicGroupName": "Group Name", + "DescriptionFieldLabel": "Description Field", + "AppLocalEnvironmentSharePoint": "The app is running on your local environment as SharePoint web part", + "AppLocalEnvironmentTeams": "The app is running on your local environment as Microsoft Teams app", + "AppSharePointEnvironment": "The app is running on SharePoint page", + "AppTeamsTabEnvironment": "The app is running in Microsoft Teams" + } +}); \ No newline at end of file diff --git a/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/loc/mystrings.d.ts b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/loc/mystrings.d.ts new file mode 100644 index 000000000..ad59adf96 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/src/webparts/teamsList/loc/mystrings.d.ts @@ -0,0 +1,14 @@ +declare interface ITeamsListWebPartStrings { + PropertyPaneDescription: string; + BasicGroupName: string; + DescriptionFieldLabel: string; + AppLocalEnvironmentSharePoint: string; + AppLocalEnvironmentTeams: string; + AppSharePointEnvironment: string; + AppTeamsTabEnvironment: string; +} + +declare module 'TeamsListWebPartStrings' { + const strings: ITeamsListWebPartStrings; + export = strings; +} diff --git a/samples/react-kiota-custom-api-client/teamified-client/teams/a4533e12-f41c-448b-a1c8-2cb0ce6ad3bc_color.png b/samples/react-kiota-custom-api-client/teamified-client/teams/a4533e12-f41c-448b-a1c8-2cb0ce6ad3bc_color.png new file mode 100644 index 000000000..0e1f764fa Binary files /dev/null and b/samples/react-kiota-custom-api-client/teamified-client/teams/a4533e12-f41c-448b-a1c8-2cb0ce6ad3bc_color.png differ diff --git a/samples/react-kiota-custom-api-client/teamified-client/teams/a4533e12-f41c-448b-a1c8-2cb0ce6ad3bc_outline.png b/samples/react-kiota-custom-api-client/teamified-client/teams/a4533e12-f41c-448b-a1c8-2cb0ce6ad3bc_outline.png new file mode 100644 index 000000000..892868fab Binary files /dev/null and b/samples/react-kiota-custom-api-client/teamified-client/teams/a4533e12-f41c-448b-a1c8-2cb0ce6ad3bc_outline.png differ diff --git a/samples/react-kiota-custom-api-client/teamified-client/tsconfig.json b/samples/react-kiota-custom-api-client/teamified-client/tsconfig.json new file mode 100644 index 000000000..cb3c4af63 --- /dev/null +++ b/samples/react-kiota-custom-api-client/teamified-client/tsconfig.json @@ -0,0 +1,37 @@ +{ + "extends": "./node_modules/@microsoft/rush-stack-compiler-4.5/includes/tsconfig-web.json", + "compilerOptions": { + "target": "es5", + "forceConsistentCasingInFileNames": true, + "module": "esnext", + "moduleResolution": "node", + "jsx": "react", + "declaration": true, + "sourceMap": true, + "experimentalDecorators": true, + "skipLibCheck": true, + "outDir": "lib", + "inlineSources": false, + "strictNullChecks": false, + "noUnusedLocals": false, + "noImplicitAny": true, + + "typeRoots": [ + "./node_modules/@types", + "./node_modules/@microsoft" + ], + "types": [ + "webpack-env" + ], + "lib": [ + "es5", + "dom", + "es2015.collection", + "es2015.promise" + ] + }, + "include": [ + "src/**/*.ts", + "src/**/*.tsx" + ] +}