UNPKG

4.61 kBTypeScriptView Raw
1import { PartialJSONObject, ReadonlyJSONObject } from '@lumino/coreutils';
2import { Poll } from '@lumino/polling';
3import { ISignal } from '@lumino/signaling';
4import { ServerConnection } from '../serverconnection';
5import { BaseManager, IManager as IBaseManager } from '../basemanager';
6/**
7 * The user API service manager.
8 */
9export declare class UserManager extends BaseManager implements User.IManager {
10 private _isReady;
11 private _ready;
12 private _pollSpecs;
13 private _identity;
14 private _permissions;
15 private _userChanged;
16 private _connectionFailure;
17 /**
18 * Create a new user manager.
19 */
20 constructor(options?: UserManager.IOptions);
21 /**
22 * The server settings for the manager.
23 */
24 readonly serverSettings: ServerConnection.ISettings;
25 /**
26 * Test whether the manager is ready.
27 */
28 get isReady(): boolean;
29 /**
30 * A promise that fulfills when the manager is ready.
31 */
32 get ready(): Promise<void>;
33 /**
34 * Get the most recently fetched identity.
35 */
36 get identity(): User.IIdentity | null;
37 /**
38 * Get the most recently fetched permissions.
39 */
40 get permissions(): ReadonlyJSONObject | null;
41 /**
42 * A signal emitted when the user changes.
43 */
44 get userChanged(): ISignal<this, User.IUser>;
45 /**
46 * A signal emitted when there is a connection failure.
47 */
48 get connectionFailure(): ISignal<this, Error>;
49 /**
50 * Dispose of the resources used by the manager.
51 */
52 dispose(): void;
53 /**
54 * Force a refresh of the specs from the server.
55 *
56 * @returns A promise that resolves when the specs are fetched.
57 *
58 * #### Notes
59 * This is intended to be called only in response to a user action,
60 * since the manager maintains its internal state.
61 */
62 refreshUser(): Promise<void>;
63 /**
64 * Execute a request to the server to poll the user and update state.
65 */
66 protected requestUser(): Promise<void>;
67}
68/**
69 * A namespace for `UserManager` statics.
70 */
71export declare namespace UserManager {
72 /**
73 * The instantiation options for a user manager.
74 */
75 interface IOptions extends BaseManager.IOptions {
76 /**
77 * When the manager stops polling the API. Defaults to `when-hidden`.
78 */
79 standby?: Poll.Standby | (() => boolean | Poll.Standby);
80 }
81}
82/**
83 * A namespace for user API interfaces.
84 */
85export declare namespace User {
86 /**
87 * The interface describing a user identity.
88 */
89 interface IUser {
90 readonly identity: IIdentity;
91 readonly permissions: PartialJSONObject;
92 }
93 /**
94 * The interface describing a user identity.
95 */
96 interface IIdentity extends PartialJSONObject {
97 /**
98 * User's unique identifier.
99 */
100 readonly username: string;
101 /**
102 * User's full name.
103 */
104 readonly name: string;
105 /**
106 * Shorter version of the name for displaying it on the UI.
107 */
108 readonly display_name: string;
109 /**
110 * User's name initials.
111 */
112 readonly initials: string;
113 /**
114 * User's cursor color and icon color if avatar_url is undefined
115 * (there is no image).
116 */
117 readonly color: string;
118 /**
119 * User's avatar url.
120 * The url to the user's image for the icon.
121 */
122 readonly avatar_url?: string;
123 }
124 /**
125 * Object which manages user's identity.
126 *
127 * #### Notes
128 * The manager is responsible for maintaining the state of the user.
129 */
130 interface IManager extends IBaseManager {
131 /**
132 * A signal emitted when the user changes.
133 */
134 userChanged: ISignal<this, User.IUser>;
135 /**
136 * User's identity.
137 *
138 * #### Notes
139 * The value will be null until the manager is ready.
140 */
141 readonly identity: User.IIdentity | null;
142 /**
143 * User's permissions.
144 *
145 * #### Notes
146 * The value will be null until the manager is ready.
147 */
148 readonly permissions: ReadonlyJSONObject | null;
149 /**
150 * Force a refresh of user's identity from the server.
151 *
152 * @returns A promise that resolves when the identity is fetched.
153 *
154 * #### Notes
155 * This is intended to be called only in response to a user action,
156 * since the manager maintains its internal state.
157 */
158 refreshUser(): Promise<void>;
159 }
160}
161
\No newline at end of file