-
Notifications
You must be signed in to change notification settings - Fork 28
/
user-info.ts
55 lines (47 loc) · 1.74 KB
/
user-info.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Contact, AccessTokenData } from '../../../js-miniapp-bridge/src';
import { getBridge } from '../utils';
/**
* Interfaces to retrieve User profile related information.
*/
export interface UserInfoProvider {
/**
* Fetches the username from host app.
* You should request the {@link CustomPermissionName.USER_NAME} permission before using this method.
* @returns Username saved in the host app user profile.
*/
getUserName(): Promise<string>;
/**
* Fetches the profile photo URI from host app.
* You should request the {@link CustomPermissionName.PROFILE_PHOTO} permission before using this method.
* @returns Profile photo saved in the host app user profile.
*/
getProfilePhoto(): Promise<string>;
/**
* Fetches the contact list from host app.
* You should request the {@link CustomPermissionName.CONTACT_LIST} permission before using this method.
* @returns Contact list in the host app user profile.
*/
getContacts(): Promise<Contact[]>;
/**
* Fetches the access token from host app.
* @param audience one of the audiences provided in MiniApp manifest
* @param scopes scopes array associated to the audience
* @returns Access token from native host app.
*/
getAccessToken(audience: string, scopes: string[]): Promise<AccessTokenData>;
}
/** @internal */
export class UserInfo implements UserInfoProvider {
getUserName(): Promise<string> {
return getBridge().getUserName();
}
getProfilePhoto(): Promise<string> {
return getBridge().getProfilePhoto();
}
getContacts(): Promise<Contact[]> {
return getBridge().getContacts();
}
getAccessToken(audience: string, scopes: string[]): Promise<AccessTokenData> {
return getBridge().getAccessToken(audience, scopes);
}
}