/
user.ts
73 lines (61 loc) · 1.43 KB
/
user.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { AxiosInstance } from 'axios'
import { freezeSys, toPlainObject } from 'contentful-sdk-core'
import cloneDeep from 'lodash/cloneDeep'
import enhanceWithMethods from '../enhance-with-methods'
import { wrapCollection } from '../common-utils'
import { DefaultElements, BasicMetaSysProps } from '../common-types'
export type UserProps = {
/**
* System metadata
*/
sys: BasicMetaSysProps
/**
* First name of the user
*/
firstName: string
/**
* Last name of the user
*/
lastName: string
/**
* Url to the users avatar
*/
avatarUrl: string
/**
* Email address of the user
*/
email: string
/**
* Activation flag
*/
activated: boolean
/**
* Number of sign ins
*/
signInCount: number
/**
* User confirmation flag
*/
confirmed: boolean
'2faEnabled': boolean
cookieConsentData: string
}
export interface User extends UserProps, DefaultElements<UserProps> {}
/**
* @private
* @param http - HTTP client instance
* @param data - Raw data
* @return Normalized user
*/
export function wrapUser(http: AxiosInstance, data: UserProps): User {
const user = toPlainObject(cloneDeep(data))
const userWithMethods = enhanceWithMethods(user, {})
return freezeSys(userWithMethods)
}
/**
* @private
* @param http - HTTP client instance
* @param data - Raw data collection
* @return Normalized user collection
*/
export const wrapUserCollection = wrapCollection(wrapUser)