@progress-chef/platform-tenant-preference-service
v1.0.0
Published
Angular service for managing tenant system preferences from the Chef Platform.
Downloads
395
Keywords
Readme
Platform Tenant Preference Service
Angular service for managing tenant system preferences from the Chef Platform.
Overview
This library provides the TenantPreferencesService which manages tenant system preferences data from the shared NgRx store (ChefPlatformSystemTenantSharedFacadeService). It offers a clean API for accessing tenant preferences like AI enablement, Opsmith enablement, and other feature flags.
Installation
npm install @progress-chef/platform-tenant-preference-service
# or
yarn add @progress-chef/platform-tenant-preference-serviceDependencies
This library has peer dependencies on:
@progress-chef/platform-shared-store- NgRx store facades for Chef Platform APIs@progress-chef/platform-storage-service- Browser storage utilitiesjwt-decode- JWT token decodingrxjs- Reactive programming
Usage
Import the Service
import { TenantPreferencesService } from '@progress-chef/platform-tenant-preference-service';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html'
})
export class MyComponent {
constructor(private tenantPreferencesService: TenantPreferencesService) {}
}Fetch Tenant Preferences
ngOnInit() {
const tenantId = this.tenantPreferencesService.getTenantIdFromToken();
const baseUrl = 'https://api.chef.io';
if (tenantId) {
this.tenantPreferencesService.fetchTenantPreferences(tenantId, baseUrl);
}
}Check AI Enablement
this.tenantPreferencesService.isAiEnabled$().subscribe(isEnabled => {
if (isEnabled) {
// AI features are enabled
}
});Check Opsmith Enablement
this.tenantPreferencesService.isOpsmithEnabled$().subscribe(isEnabled => {
if (isEnabled) {
// Opsmith features are enabled
}
});Get Complete Preferences State
this.tenantPreferencesService.getPreferencesState$().subscribe(state => {
console.log('Preferences:', state.preferences);
console.log('Loading:', state.loading);
console.log('Error:', state.error);
});Reset Preferences (e.g., on logout)
onLogout() {
this.tenantPreferencesService.resetPreferences();
}API
Methods
fetchTenantPreferences(tenantId: string, baseUrl: string): void- Fetch tenant preferences from APIisAiEnabled$(): Observable<boolean | null>- Observable for AI-enabled flagisOpsmithEnabled$(): Observable<boolean | null>- Observable for Opsmith-enabled flaggetPreferencesState$(): Observable<TenantPreferencesState>- Observable for complete stateisLoading$(): Observable<boolean>- Observable for loading statusgetTenantIdFromToken(): string | null- Extract tenant ID from JWT tokenresetPreferences(): void- Reset preferences state
Interfaces
export interface TenantSystemPreferences {
'ai-enabled'?: boolean;
[key: string]: any;
}
export interface TenantPreferencesState {
preferences: TenantSystemPreferences | null;
loading: boolean;
error: string | null;
}Build
yarn build:platform-tenant-preference-serviceTest
yarn testPublishing
After building the library:
cd dist/platform-tenant-preference-service
yarn publishArchitecture
This service acts as a facade over the ChefPlatformSystemTenantSharedFacadeService from @progress-chef/platform-shared-store, providing a simplified API specifically for tenant preferences. It:
- Dispatches actions to fetch tenant preferences
- Subscribes to store updates
- Transforms API data format (array to object)
- Provides reactive streams for specific preference flags
- Handles loading and error states
License
Apache-2.0
