1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.User = exports.Profile = exports.Access = exports.Name = exports.Last = void 0;
|
19 | class Last {
|
20 |
|
21 | constructor(user) {
|
22 | if (user.lastSeen) {
|
23 | this.seen = new Date(user.lastSeen);
|
24 | }
|
25 | }
|
26 | }
|
27 | exports.Last = Last;
|
28 | class Name {
|
29 |
|
30 | constructor(profile) {
|
31 | this.display = profile.displayName;
|
32 | this.family = profile.familyName;
|
33 | this.given = profile.givenName;
|
34 | }
|
35 | }
|
36 | exports.Name = Name;
|
37 | class Access {
|
38 |
|
39 | constructor(user) {
|
40 | this.token = user.accessToken;
|
41 | }
|
42 | }
|
43 | exports.Access = Access;
|
44 | class Profile {
|
45 |
|
46 | constructor(user) {
|
47 | this.token = user.idToken;
|
48 | }
|
49 |
|
50 | async _verify(client, id) {
|
51 | const login = (await client.verifyIdToken({
|
52 | idToken: this.token,
|
53 | audience: id,
|
54 | }));
|
55 | this.payload = login.getPayload();
|
56 | return this.payload;
|
57 | }
|
58 | }
|
59 | exports.Profile = Profile;
|
60 | class User {
|
61 |
|
62 | constructor(raw = {}, initial) {
|
63 | this.raw = raw;
|
64 | const { userStorage } = this.raw;
|
65 | this.storage = userStorage ? JSON.parse(userStorage).data : initial || {};
|
66 | this.locale = this.raw.locale;
|
67 | this.verification = this.raw.userVerificationStatus;
|
68 | this.permissions = this.raw.permissions || [];
|
69 | this.last = new Last(this.raw);
|
70 | const profile = this.raw.profile || {};
|
71 | this.name = new Name(profile);
|
72 | this.entitlements = this.raw.packageEntitlements || [];
|
73 | this.access = new Access(this.raw);
|
74 | this.profile = new Profile(this.raw);
|
75 | }
|
76 |
|
77 | _serialize() {
|
78 | return JSON.stringify({ data: this.storage });
|
79 | }
|
80 |
|
81 | async _verifyProfile(client, id) {
|
82 | const payload = await this.profile._verify(client, id);
|
83 | this.email = payload.email;
|
84 | return payload;
|
85 | }
|
86 | }
|
87 | exports.User = User;
|
88 |
|
\ | No newline at end of file |