intraactive-sdk-helper
v2.0.3
Published
Helper funcions for web development
Downloads
273
Readme
IntraActive SDK Helper
Helper functions and services for web development with Microsoft authentication and fetch utilities.
Features
- MSAL Client Service: Easy integration with @azure/msal-browser for authentication and token management.
- Teams Client Service: Simplified access to @microsoft/teams-js authentication.
- Dependency Injection Container: Lightweight DI for managing service lifetimes (singleton, transient).
- Fetch Utilities: Enhanced fetch with automatic token injection, error handling, and re-authentication support.
Installation
npm install intraactive-sdk-helperUsage
Importing Services
import { MsalClientService, TeamsClientService, Container } from 'intraactive-sdk-helper';Example: Using the DI Container
import { Container, MsalClientService } from 'intraactive-sdk-helper';
import { PublicClientApplication } from '@azure/msal-browser';
// Create the PublicClientApplication
const msalInstance = new PublicClientApplication({ /* config */ });
// Create a new instance of MsalClientService with the required scope
const msalClientService = new MsalClientService(msalInstance, ['user.read']);
// Create the container and inject the MsalClientService
const container = new Container();
container.asSingleton(MsalClientService, msalClientService);
const msalService = container.resolve(MsalClientService);
msalService.getToken().then(token => {
// Use token
});Example: Fetch with Automatic Token
import { FetchProxy } from 'intraactive-sdk-helper';
// Create a new fetchProxy instance and use the container created at the step above
const fetchProxy = new FetchProxy('https://api.example.com/data', {
method: "GET"
})
.withContainer(container);
fetchProxy.fetch().then(response => {
// Handle response
});Scripts
npm run build— Build the project using tsup.npm run test— Run all unit tests.npm run tsc— Type-check the project.
Development
- Clone the repository.
- Install dependencies:
npm ci - Run tests:
npm test - Build:
npm run build
License
MIT
Maintained by IntraActive
