Skip to content

Commit 29a6359

Browse files
authored
feat: better typings for user API (#744)
1 parent 00f7ad1 commit 29a6359

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/types/api.types.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ContentType, EditorInterface, SpaceMembership } from './entities'
1+
import { ContentType, EditorInterface, SpaceMembership, Role } from './entities'
22
import { EntryAPI } from './entry.types'
33
import { SpaceAPI } from './space.types'
44
import { WindowAPI } from './window.types'
@@ -10,6 +10,7 @@ import { NavigatorAPI } from './navigator.types'
1010
import { EntryFieldInfo, FieldInfo } from './field.types'
1111

1212
/* User API */
13+
1314
export interface UserAPI {
1415
sys: {
1516
id: string
@@ -19,7 +20,14 @@ export interface UserAPI {
1920
lastName: string
2021
email: string
2122
avatarUrl: string
22-
spaceMembership: SpaceMembership
23+
// Although called SpaceMembership, this type does not abide to entity
24+
// with same name. Keeping it the same (with more precise types) for
25+
// backwards compatibility
26+
spaceMembership: {
27+
sys: Pick<SpaceMembership['sys'], 'id' | 'type'>
28+
admin: SpaceMembership['admin']
29+
roles: Pick<Role, 'name' | 'description'>[]
30+
}
2331
}
2432

2533
/* Locales API */

lib/types/entities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type {
1010
SpaceMembershipProps as SpaceMembership,
1111
ContentFields as ContentTypeField,
1212
EntryProps as Entry,
13+
RoleProps as Role,
1314
KeyValueMap,
1415
} from 'contentful-management/types'
1516

lib/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type {
4343
TagVisibility,
4444
Task,
4545
Entry,
46+
Role,
4647
} from './entities'
4748

4849
export type { EntryAPI, TaskAPI, TaskInputData } from './entry.types'

0 commit comments

Comments
 (0)