UNPKG

@gooddata/api-client-bear

Version:
64 lines 2.4 kB
import { UserModuleDecorator } from "../decoratedModules/user.js"; export class UserModuleWithCaching extends UserModuleDecorator { ctx; constructor(decorated, ctx) { super(decorated); this.ctx = ctx; } /** * This function provides an authentication entry point to the GD API. It is needed to authenticate * by calling this function prior any other API calls. After providing valid credentials * every subsequent API call in a current session will be authenticated. */ login(username, password) { this.ctx.caches.currentProfile = null; return super.login(username, password); } /** * This function provides an authentication entry point to the GD API via SSO * https://help.gooddata.com/display/developer/GoodData+PGP+Single+Sign-On * * @param encryptedClaims - PGP message * @param ssoProvider - name of the SSO provider * @param targetUrl - where to redirect after the SSO flow, set this to `/gdc/account/token` */ loginSso(encryptedClaims, ssoProvider, targetUrl) { this.ctx.caches.currentProfile = null; return super.loginSso(encryptedClaims, ssoProvider, targetUrl); } /** * Logs out current user */ async logout() { this.ctx.caches.currentProfile = null; return super.logout(); } /** * Gets current user's profile * Uses caching to prevent multiple calls. * Cache is discarded during logout or next login. * @returns Resolves with account setting object */ getCurrentProfile() { if (this.ctx.caches.currentProfile) { return this.ctx.caches.currentProfile; } const promise = super.getCurrentProfile(); this.ctx.caches.currentProfile = promise; return promise; } /** * Updates user's profile settings * @param profileId - User profile identifier * @param profileSetting - the profile setting update payload */ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types updateProfileSettings(profileId, profileSetting) { this.ctx.caches.currentProfile = null; return super.updateProfileSettings(profileId, profileSetting); } } export function cachedUser(ctx) { return (original) => new UserModuleWithCaching(original, ctx); } //# sourceMappingURL=user.js.map