@microsoft/power-apps
v0.3.21
Published
Power Apps SDK
Readme
Power Apps client library
This project contains the APIs needed to:
- Initialize apps that can be hosted in the Power Platform.
- Enable developers to interact with data sources including multiple connectors and Dataverse.
Getting Started
Go to the instructions to get samples, tutorials and more information about code apps.
Installation
npm install @microsoft/power-appsUsage
Install the package using npm.
Initialization
import { initialize } from '@microsoft/power-apps/app';Make sure the initialize API is the first thing your app calls. Failing to do so will result in the app failing to load. If data calls are made before initialize is completed this will cause the data retrieval to be unsuccessful.
Data
Data operations are performed via a client. A client can be fetched via the getClient method.
import { getClient } from '@microsoft/power-apps/data';When used in tandem with pac cli, data operations can be performed like so:
const client = getClient({
users: {
tableId: "<id>",
apis: {},
},
});
/* retrieve single record */
client.retrieveRecordAsync<User>("users", /* id */, /* query options */);
/* retrive multiple records */
client.retrieveMultipleRecordsAsync<User>("users", /* query options */);
/* create new record */
client.createRecordAsync<User, User>("users", /* data */);
/* update existing record */
client.updateRecordAsync<User, User>("users", /* id */, /* data */);
/* delete existing record */
client.deleteRecordAsync("users", /* id */);Context
import { getContext } from '@microsoft/power-apps/app';
import type { IContext } from '@microsoft/power-apps/app';Use the getContext API to retrieve the context from the app, user and host. The context will have the following structure:
export interface IContext {
app: IAppContext;
host: IHostContext;
user: IUserContext;
}
export interface IUserContext {
fullName?: string;
objectId?: string;
tenantId?: string;
userPrincipalName?: string;
}
export interface IAppContext {
appId: string;
appSettings: object;
environmentId: string;
queryParams: Record<string, string>;
}
export interface IHostContext {
sessionId: string;
}