/************************************************************************* * Copyright 2020 Adobe * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in * accordance with the terms of the Adobe license agreement accompanying * it. If you have received this file from a source other than Adobe, * then your use, modification, or distribution of it requires the prior * written permission of Adobe. **************************************************************************/ /** * API to request user-specific information such as IMS organization, IMS profile, access token, * tenant, etc. It also provides solutions with other capabilities such as notifying the shell that * the session has expired and configuring a logout URL to expire custom sessions. * * ***Import:*** * * ```typescript * import user from '@adobe/exc-app/user'; * ``` * * ***Default export:*** * * [UserApi](../interfaces/user.userapi.md#interface-userapi) * * ***Usage:*** * * Below is an example of how to get various attributes associated to the user: * * ```typescript * import user from '@adobe/exc-app/user'; * * const [avatar, collaborator, instance, orgInfo, org, name, orgs, token, profile, locale, languages, subOrg, tenant, theme, userCollaborators, userInstances] = await Promise.all([ * user.get('avatar'), * user.get('collaborator'), * user.get('instance'), * user.get('imsInfo'), * user.get('imsOrg'), * user.get('imsOrgName'), * user.get('imsOrgs'), * user.get('imsToken'), * user.get('imsProfile'), * user.get('locale'), * user.get('preferredLanguages'), * user.get('processedImsOrg'), * user.get('subOrg'), * user.get('tenant'), * user.get('theme'), * user.get('userCollaborators'), * user.get('userInstances') * ]); * ``` * * ### Receiving updates * * You can also listen for updates on the requested data by listening to specific change events. * * These change events are emitted from the api that the data is requested from. For example, if a * user calls `await user.get('locale');` they must listen for the change event on * `user.on('change:locale')`. If a user calls `await user.get('imsOrg')` they must listen for the * change event on `user.on('change:imsOrg')`. Here is a more detailed example of how the promise * api and change events can be used to keep track of specific values from the config: * * ```typescript * import user from '@adobe/exc-app/user'; * * constructor() { * this.state = {org: null, shell: {}}; * * user.on('change:imsOrg', (org) => { * this.setState({org}); * }); * } * * async componentDidMount() { * const org = await user.get('imsOrg'); * this.setState({org}); * } * ``` * * imsInfo is a special case. When listening for updates on imsInfo, the callback will receive * two arguments. The first is the entire imsInfo object. The second is an object containing only * the values that have changed (for example, an org change between an individual account and a * type2e account will cause the imsProfile to change, while an org change within the same account will not). * * ```typescript * user.on('change:imsInfo', (info, changed) => { * if ('imsProfile' in changed) { * // load information for new account * } * * this.setState({...info}); * }); * ``` * @packageDocumentation * @module user */ import EventEmitter from './src/EventEmitter'; import type { ProcessedImsOrg } from './RuntimeConfiguration'; import type { Sandbox } from './appcontext'; export type { Sandbox }; export declare enum CollaboratorType { ADVERTISER = "ADVERTISER", DATA_PARTNER = "DATA_PARTNER", ID_PARTNER = "ID_PARTNER", PUBLISHER = "PUBLISHER" } export interface Collaborator { /** * Collaborator instance ID */ id: string; /** * Collaborator name */ name: string; /** * Collaborator type (persona type) */ type: CollaboratorType; } export declare enum InstanceType { PRODUCTION = "PRODUCTION", SANDBOX = "SANDBOX" } export interface Instance { /** * Instance instance ID */ id: string; /** * Instance name */ name: string; /** * Instance type */ type: InstanceType; } /** * Logout URL can either be a string or an object. The object includes the URL * to be called on logout and whether this URL should be the only version of the * host in the logout list. */ export type LogoutUrl = string | { distinctDomain?: boolean; url: string; }; export interface IMS { client_id: string; scopes: string; } /** * ImsInfo encompasses all of the information associated with a given ims org. */ export interface IMSInfo { imsOrg?: string; imsOrgName?: string; imsProfile?: Record; imsToken?: string; locale?: string; localeOriginal?: string; tenant?: string; } export declare enum LAST_LOGIN_EIM_FILTERS { USER_ID = "USER_ID", AUTH_ID = "AUTH_ID" } export type LastLoginFilters = keyof typeof LAST_LOGIN_EIM_FILTERS; export interface LoginDataEntry { appId: string; authId: string; imsOrgId: string; lastLogin: string; userId: string; } export interface LastLoginOptions { appIds?: string[]; imsOrgId?: string; userId?: string; } export interface UserInfo { collaborator: Collaborator; instance: Instance; imsInfo: IMSInfo; imsOrg: string; imsOrgName: string; imsOrgs: { label: string; value: string; }[]; imsToken: string; imsProfile: Record; locale: string; localeOriginal: string; preferredLanguages: string[]; processedImsOrg: ProcessedImsOrg; s2Theme: 'dark' | 'light'; sandbox: Sandbox; sandboxes: Array; subOrg: string | null; tenant: string; theme: 'spectrum--darkest' | 'spectrum--lightest'; userCollaborators: Collaborator[]; userInstances: Instance[]; } interface UserInfoEvent { 'change:avatar': string; 'change:collaborator': Collaborator; 'change:instance': Instance; 'change:imsInfo': IMSInfo; 'change:imsOrg': string; 'change:imsOrgName': string; 'change:imsOrgs': { label: string; value: string; }[]; 'change:imsToken': string; 'change:imsProfile': Record; 'change:locale': string; 'change:localeOriginal': string; 'change:preferredLanguages': string[]; 'change:processedImsOrg': ProcessedImsOrg; 'change:s2Theme': string; 'change:sandbox': Sandbox; 'change:sandboxes': Array; 'change:subOrg': string | null; 'change:tenant': string; 'change:theme': string; 'change:userCollaborators': Collaborator[]; 'change:userInstances': Instance[]; } export interface AEMInstance { domain: string; environment: string; matchesRepoParam?: boolean; path: string; rootTemplate?: string; title: string; type: string; } export interface AEMInstanceOptions { filterByRepoParam?: boolean; } export interface RolesPickerConfig { enabled?: boolean; environment?: string; show?: boolean; } export interface UserApi extends EventEmitter { /** * API to notify the unified shell that APIs are returning 401 and user needs to be * re-authenticated. */ authExpired(reason?: string, data?: Record): void; /** * API to generate a sub-org based on a provided product context and overrides. * @param productContext The product context entry for the sub-org to generate. * @param overrides Any override values that will be applied on top of the product context. */ generateSubOrg(productContext: Record, overrides?: Record): Promise; /** * API to get fulfillable items for a service code. * @param serviceCode The service code tied to the fulfillable items to fetch. */ getFulfillableItems(serviceCode: string): Promise; /** * API to get last login data by app id. * @param options Options for last login data filtering (Optional). * @param options.appId The app id to fetch the last login for. */ getLastLogin(options?: LastLoginOptions): Promise; /** * API to list the AEM instances associated with the current IMS Org. * @param options Options for AEM instance filtering (Optional). */ getAEMInstances(options?: AEMInstanceOptions): Promise; /** * Gets the specified type of information about an user. * @param type The type of information to get. */ get(type: T): Promise; /** * Optional. When specified this URL will be invoked upon user logging out. This is useful to * reduce the number of lingering sessions for solutions who have their own sessions server * (in addition to IMS). */ logoutUrl?: LogoutUrl; /** * If language picker should be opened. */ showLanguagePicker: boolean | undefined; /** * If roles picker should be opened. */ showRolesPicker: boolean | undefined; /** * Environment-based configuration of roles picker dialog to be shared across apps */ rolesPickerConfig?: RolesPickerConfig | undefined; } declare const user: UserApi; export default user;