@api-client/core 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.d.ts +5 -2
- package/build/browser.js +3 -1
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +5 -2
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/src/mocking/ProjectMock.d.ts +1 -1
- package/build/src/mocking/lib/User.d.ts +1 -6
- package/build/src/mocking/lib/User.js +1 -15
- package/build/src/mocking/lib/User.js.map +1 -1
- package/build/src/models/Backend.d.ts +10 -2
- package/build/src/models/Workspace.d.ts +5 -35
- package/build/src/models/Workspace.js +13 -35
- package/build/src/models/Workspace.js.map +1 -1
- package/build/src/models/store/File.d.ts +88 -0
- package/build/src/models/store/File.js +82 -0
- package/build/src/models/store/File.js.map +1 -0
- package/build/src/models/store/Group.d.ts +21 -0
- package/build/src/models/store/Group.js +2 -0
- package/build/src/models/store/Group.js.map +1 -0
- package/build/src/models/store/Permission.d.ts +189 -0
- package/build/src/models/store/Permission.js +211 -0
- package/build/src/models/store/Permission.js.map +1 -0
- package/build/src/models/{User.d.ts → store/User.d.ts} +12 -59
- package/build/src/models/{User.js → store/User.js} +0 -0
- package/build/src/models/store/User.js.map +1 -0
- package/build/src/runtime/store/SpacesSdk.d.ts +4 -4
- package/build/src/runtime/store/SpacesSdk.js.map +1 -1
- package/build/src/runtime/store/UsersSdk.d.ts +1 -1
- package/package.json +1 -1
- package/src/mocking/ProjectMock.ts +1 -1
- package/src/mocking/lib/User.ts +1 -21
- package/src/models/Backend.ts +10 -2
- package/src/models/Workspace.ts +16 -54
- package/src/models/store/File.ts +135 -0
- package/src/models/store/Group.ts +21 -0
- package/src/models/store/Permission.ts +318 -0
- package/src/models/store/User.ts +83 -0
- package/src/runtime/store/SpacesSdk.ts +5 -5
- package/src/runtime/store/UsersSdk.ts +1 -1
- package/build/src/models/User.js.map +0 -1
- package/src/models/User.ts +0 -138
package/src/models/Workspace.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IFile, File } from "./store/File.js";
|
|
2
2
|
import { IThing, Thing, Kind as ThingKind } from './Thing.js';
|
|
3
3
|
import v4 from '../lib/uuid.js';
|
|
4
4
|
|
|
@@ -9,7 +9,7 @@ export const Kind = 'Core#Space';
|
|
|
9
9
|
* A working space is a logical container in the data store
|
|
10
10
|
* created by the system users, where they can store their projects and other data.
|
|
11
11
|
*/
|
|
12
|
-
export interface IWorkspace {
|
|
12
|
+
export interface IWorkspace extends IFile {
|
|
13
13
|
kind: typeof Kind;
|
|
14
14
|
/**
|
|
15
15
|
* The space identifier.
|
|
@@ -19,27 +19,11 @@ export interface IWorkspace {
|
|
|
19
19
|
* The environment's meta info.
|
|
20
20
|
*/
|
|
21
21
|
info: IThing;
|
|
22
|
-
/**
|
|
23
|
-
* The list of users added to this space. May not be set when owner did not add anyone to the space.
|
|
24
|
-
*/
|
|
25
|
-
users?: string[];
|
|
26
22
|
/**
|
|
27
23
|
* The owner of this space. The id of the User object.
|
|
28
24
|
* Set to `default` when there are no users in the system (no authentication).
|
|
29
25
|
*/
|
|
30
26
|
owner: string;
|
|
31
|
-
/**
|
|
32
|
-
* The list of project keys added to the workspace.
|
|
33
|
-
* @deprecated This is not actually used.
|
|
34
|
-
*/
|
|
35
|
-
projects: string[];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The workspace information set to a specific client what contains user specific data.
|
|
40
|
-
*/
|
|
41
|
-
export interface IUserWorkspace extends IWorkspace {
|
|
42
|
-
access: AccessControlLevel;
|
|
43
27
|
}
|
|
44
28
|
|
|
45
29
|
export const DefaultOwner = 'default';
|
|
@@ -50,7 +34,7 @@ export const DefaultOwner = 'default';
|
|
|
50
34
|
* A working space is a logical container in the data store
|
|
51
35
|
* created by the system users, where they can store their projects and other data.
|
|
52
36
|
*/
|
|
53
|
-
export class Workspace {
|
|
37
|
+
export class Workspace extends File {
|
|
54
38
|
kind = Kind;
|
|
55
39
|
/**
|
|
56
40
|
* The space identifier.
|
|
@@ -60,26 +44,11 @@ export class Workspace {
|
|
|
60
44
|
* The name of the environment.
|
|
61
45
|
*/
|
|
62
46
|
info: Thing = new Thing({ kind: ThingKind });
|
|
63
|
-
/**
|
|
64
|
-
* The list of users added to this space. May not be set when owner did not add anyone to the space.
|
|
65
|
-
*/
|
|
66
|
-
users?: string[];
|
|
67
47
|
/**
|
|
68
48
|
* The owner of this space. The id of the User object.
|
|
69
49
|
* Set to `default` when there are no users in the system (no authentication).
|
|
70
50
|
*/
|
|
71
51
|
owner = '';
|
|
72
|
-
/**
|
|
73
|
-
* The list of keys of projects added to the workspace.
|
|
74
|
-
* @deprecated This is not actually used.
|
|
75
|
-
*/
|
|
76
|
-
projects: string[] = [];
|
|
77
|
-
/**
|
|
78
|
-
* Only set when the object was created from the data received by the API Client backend.
|
|
79
|
-
* Level access of the current user to the space.
|
|
80
|
-
* Note, this information is never serialized with the object.
|
|
81
|
-
*/
|
|
82
|
-
access?: AccessControlLevel;
|
|
83
52
|
|
|
84
53
|
/**
|
|
85
54
|
* Creates a new Space object from a name.
|
|
@@ -95,7 +64,9 @@ export class Workspace {
|
|
|
95
64
|
kind: Kind,
|
|
96
65
|
info: info.toJSON(),
|
|
97
66
|
owner,
|
|
98
|
-
|
|
67
|
+
parents: [],
|
|
68
|
+
permissionIds: [],
|
|
69
|
+
permissions: [],
|
|
99
70
|
});
|
|
100
71
|
return definition;
|
|
101
72
|
}
|
|
@@ -103,7 +74,8 @@ export class Workspace {
|
|
|
103
74
|
/**
|
|
104
75
|
* @param input The environment definition used to restore the state.
|
|
105
76
|
*/
|
|
106
|
-
constructor(input?: string | IWorkspace
|
|
77
|
+
constructor(input?: string | IWorkspace) {
|
|
78
|
+
super();
|
|
107
79
|
let init: IWorkspace;
|
|
108
80
|
if (typeof input === 'string') {
|
|
109
81
|
init = JSON.parse(input);
|
|
@@ -118,7 +90,9 @@ export class Workspace {
|
|
|
118
90
|
name: '',
|
|
119
91
|
},
|
|
120
92
|
owner: DefaultOwner,
|
|
121
|
-
|
|
93
|
+
parents: [],
|
|
94
|
+
permissionIds: [],
|
|
95
|
+
permissions: [],
|
|
122
96
|
};
|
|
123
97
|
}
|
|
124
98
|
this.new(init);
|
|
@@ -129,29 +103,20 @@ export class Workspace {
|
|
|
129
103
|
*
|
|
130
104
|
* Note, this throws an error when the environment is not a space.
|
|
131
105
|
*/
|
|
132
|
-
new(init: IWorkspace
|
|
106
|
+
new(init: IWorkspace): void {
|
|
133
107
|
if (!Workspace.isWorkspace(init)) {
|
|
134
108
|
throw new Error(`Not a space.`);
|
|
135
109
|
}
|
|
136
|
-
|
|
110
|
+
super.new(init);
|
|
111
|
+
const { key = v4(), info, owner = DefaultOwner } = init;
|
|
137
112
|
this.kind = Kind;
|
|
138
113
|
this.key = key;
|
|
139
|
-
this.projects = projects;
|
|
140
114
|
this.owner = owner;
|
|
141
115
|
if (info) {
|
|
142
116
|
this.info = new Thing(info);
|
|
143
117
|
} else {
|
|
144
118
|
this.info = new Thing({ kind: ThingKind, name: '' });
|
|
145
119
|
}
|
|
146
|
-
if (Array.isArray(users)) {
|
|
147
|
-
this.users = [...users];
|
|
148
|
-
} else {
|
|
149
|
-
this.users = [];
|
|
150
|
-
}
|
|
151
|
-
const typed = init as IUserWorkspace;
|
|
152
|
-
if (typed.access) {
|
|
153
|
-
this.access = typed.access;
|
|
154
|
-
}
|
|
155
120
|
}
|
|
156
121
|
|
|
157
122
|
/**
|
|
@@ -166,17 +131,14 @@ export class Workspace {
|
|
|
166
131
|
}
|
|
167
132
|
|
|
168
133
|
toJSON(): IWorkspace {
|
|
169
|
-
const {
|
|
134
|
+
const { owner = DefaultOwner } = this;
|
|
170
135
|
const result: IWorkspace = {
|
|
171
136
|
kind: Kind,
|
|
172
137
|
key: this.key,
|
|
173
138
|
info: this.info.toJSON(),
|
|
174
|
-
projects,
|
|
175
139
|
owner,
|
|
140
|
+
...super.toJSON(),
|
|
176
141
|
};
|
|
177
|
-
if (Array.isArray(users) && users.length) {
|
|
178
|
-
result.users = [...users];
|
|
179
|
-
}
|
|
180
142
|
return result;
|
|
181
143
|
}
|
|
182
144
|
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { IPermission } from './Permission.js';
|
|
2
|
+
|
|
3
|
+
export interface IStoredFile {
|
|
4
|
+
/**
|
|
5
|
+
* The list of parents of the object. It is an ordered list of parents
|
|
6
|
+
* from the top (first element) to the lowest parent in the tree (last element).
|
|
7
|
+
*
|
|
8
|
+
* After creating the object, this property cannot be manipulated directly by the client.
|
|
9
|
+
* Should be treated as opaque value.
|
|
10
|
+
*/
|
|
11
|
+
parents: string[];
|
|
12
|
+
/**
|
|
13
|
+
* The list of permissions to this file object.
|
|
14
|
+
*
|
|
15
|
+
* This property cannot be manipulated directly by the client. Should be treated as
|
|
16
|
+
* opaque value.
|
|
17
|
+
*/
|
|
18
|
+
permissionIds: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Whether the file object is deleted.
|
|
21
|
+
*/
|
|
22
|
+
deleted?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The timestamp of when the file was deleted.
|
|
25
|
+
*/
|
|
26
|
+
deletedTime?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The id of the user that has deleted the file.
|
|
29
|
+
*/
|
|
30
|
+
deletingUser?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* An interface describing an object in the data store that
|
|
35
|
+
* describes a file or an object that can be treated as a file or a folder.
|
|
36
|
+
*/
|
|
37
|
+
export interface IFile extends IStoredFile {
|
|
38
|
+
/**
|
|
39
|
+
* Populated by the server when reading the file. The list of permissions to the object.
|
|
40
|
+
*
|
|
41
|
+
* This property cannot be manipulated directly by the client. Should be treated as
|
|
42
|
+
* opaque value.
|
|
43
|
+
*
|
|
44
|
+
* Data store implementation note, this is not stored in the store but it is populated
|
|
45
|
+
* when reading the object.
|
|
46
|
+
*/
|
|
47
|
+
permissions: IPermission[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class StoredFile {
|
|
51
|
+
/**
|
|
52
|
+
* The list of parents of the object. It is an ordered list of parents
|
|
53
|
+
* from the top (first element) to the lowest parent in the tree (last element).
|
|
54
|
+
*
|
|
55
|
+
* This property cannot be manipulated directly by the client. Should be treated as
|
|
56
|
+
* opaque value.
|
|
57
|
+
*/
|
|
58
|
+
parents: string[] = [];
|
|
59
|
+
/**
|
|
60
|
+
* The list of permissions to this file object.
|
|
61
|
+
*
|
|
62
|
+
* This property cannot be manipulated directly by the client. Should be treated as
|
|
63
|
+
* opaque value.
|
|
64
|
+
*/
|
|
65
|
+
permissionIds: string[] = [];
|
|
66
|
+
/**
|
|
67
|
+
* Whether the file object is deleted.
|
|
68
|
+
*/
|
|
69
|
+
deleted?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The timestamp of when the file was deleted.
|
|
72
|
+
*/
|
|
73
|
+
deletedTime?: number;
|
|
74
|
+
/**
|
|
75
|
+
* The id of the user that has deleted the file.
|
|
76
|
+
*/
|
|
77
|
+
deletingUser?: string;
|
|
78
|
+
|
|
79
|
+
new(init: IStoredFile): void {
|
|
80
|
+
const { parents=[], permissionIds=[], deleted, deletedTime, deletingUser } = init;
|
|
81
|
+
this.parents = parents;
|
|
82
|
+
this.permissionIds = permissionIds;
|
|
83
|
+
if (typeof deleted === 'boolean') {
|
|
84
|
+
this.deleted = deleted;
|
|
85
|
+
this.deletedTime = deletedTime;
|
|
86
|
+
this.deletingUser = deletingUser;
|
|
87
|
+
} else {
|
|
88
|
+
this.deleted = undefined;
|
|
89
|
+
this.deletedTime = undefined;
|
|
90
|
+
this.deletingUser = undefined;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
toJSON(): IStoredFile {
|
|
95
|
+
const result: IStoredFile = {
|
|
96
|
+
parents: this.parents,
|
|
97
|
+
permissionIds: this.permissionIds,
|
|
98
|
+
};
|
|
99
|
+
if (typeof this.deleted === 'boolean') {
|
|
100
|
+
result.deleted = this.deleted;
|
|
101
|
+
|
|
102
|
+
if (this.deletedTime) {
|
|
103
|
+
result.deletedTime = this.deletedTime;
|
|
104
|
+
}
|
|
105
|
+
if (this.deletingUser) {
|
|
106
|
+
result.deletingUser = this.deletingUser;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class File extends StoredFile {
|
|
114
|
+
/**
|
|
115
|
+
* Populated by the server when reading the file. The list of permissions to the object.
|
|
116
|
+
*
|
|
117
|
+
* This property cannot be manipulated directly by the client. Should be treated as
|
|
118
|
+
* opaque value.
|
|
119
|
+
*/
|
|
120
|
+
permissions: IPermission[] = [];
|
|
121
|
+
|
|
122
|
+
new(init: IFile): void {
|
|
123
|
+
super.new(init);
|
|
124
|
+
const { permissions=[] } = init;
|
|
125
|
+
this.permissions = permissions;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
toJSON(): IFile {
|
|
129
|
+
const result: IFile = {
|
|
130
|
+
...super.toJSON(),
|
|
131
|
+
permissions: this.permissions,
|
|
132
|
+
};
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An object representing a user group.
|
|
3
|
+
*/
|
|
4
|
+
export interface IGroup {
|
|
5
|
+
/**
|
|
6
|
+
* The key of the group.
|
|
7
|
+
*/
|
|
8
|
+
key: string;
|
|
9
|
+
/**
|
|
10
|
+
* The name of the group
|
|
11
|
+
*/
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* The id of the user that created this group.
|
|
15
|
+
*/
|
|
16
|
+
owner: string;
|
|
17
|
+
/**
|
|
18
|
+
* The list of users in this group.
|
|
19
|
+
*/
|
|
20
|
+
users: string[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import v4 from '../../lib/uuid.js';
|
|
2
|
+
|
|
3
|
+
export const Kind = 'Core#Permission';
|
|
4
|
+
|
|
5
|
+
export type PermissionType = 'user' | 'group' | 'anyone';
|
|
6
|
+
export type PermissionRole = 'owner' | 'reader' | 'commenter' | 'writer';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A schema describing a permission to a store object.
|
|
10
|
+
*/
|
|
11
|
+
export interface IPermission {
|
|
12
|
+
kind: typeof Kind;
|
|
13
|
+
/**
|
|
14
|
+
* The data store key of the permission.
|
|
15
|
+
* This property is generated by the store and is not writable.
|
|
16
|
+
*/
|
|
17
|
+
key: string;
|
|
18
|
+
/**
|
|
19
|
+
* The type of the permission.
|
|
20
|
+
*
|
|
21
|
+
* - `user` can access the file by a specific user
|
|
22
|
+
* - `group` can access the file by a group of users
|
|
23
|
+
* - `anyone` the object can be searched by anyone who has access to the store.
|
|
24
|
+
*
|
|
25
|
+
* Note, the `anyone` object does not mean that the end-user sees the file when
|
|
26
|
+
* listing objects in the store. It means the file can be searched for.
|
|
27
|
+
*/
|
|
28
|
+
type: PermissionType;
|
|
29
|
+
/**
|
|
30
|
+
* The id of the owner of the permission.
|
|
31
|
+
* The value depends on the `type`. For the `user` type it is the user id.
|
|
32
|
+
* The `group` means the group id. It is not set when the role is `anyone`.
|
|
33
|
+
*/
|
|
34
|
+
owner?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The role granted by this permission.
|
|
37
|
+
*/
|
|
38
|
+
role: PermissionRole;
|
|
39
|
+
/**
|
|
40
|
+
* The "pretty" name to render with the permission.
|
|
41
|
+
*
|
|
42
|
+
* - `user` type - user's full name
|
|
43
|
+
* - `group` type - the name of the group
|
|
44
|
+
* - `anyone` type - no render name
|
|
45
|
+
*/
|
|
46
|
+
displayName?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Optional expiration date of the permission. This is the timestamp when the permission expires.
|
|
49
|
+
* When creating / updating the permission the expiration date must:
|
|
50
|
+
*
|
|
51
|
+
* - be used on a user or a group
|
|
52
|
+
* - the time must be in the future
|
|
53
|
+
*/
|
|
54
|
+
expirationTime?: number;
|
|
55
|
+
/**
|
|
56
|
+
* The store id of the user that added this permission.
|
|
57
|
+
*/
|
|
58
|
+
addingUser: string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Whether the permission object is deleted.
|
|
62
|
+
*/
|
|
63
|
+
deleted?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The timestamp of when the permission was deleted.
|
|
66
|
+
*/
|
|
67
|
+
deletedTime?: number;
|
|
68
|
+
/**
|
|
69
|
+
* The id of the user that has deleted the permission.
|
|
70
|
+
*/
|
|
71
|
+
deletingUser?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class Permission {
|
|
75
|
+
kind = Kind;
|
|
76
|
+
/**
|
|
77
|
+
* The data store key of the permission.
|
|
78
|
+
* This property is generated by the store and is not writable.
|
|
79
|
+
*/
|
|
80
|
+
key = '';
|
|
81
|
+
/**
|
|
82
|
+
* The type of the permission.
|
|
83
|
+
*
|
|
84
|
+
* - `user` can access the file by a specific user
|
|
85
|
+
* - `group` can access the file by a group of users
|
|
86
|
+
* - `anyone` the object can be searched by anyone who has access to the store.
|
|
87
|
+
*
|
|
88
|
+
* Note, the `anyone` object does not mean that the end-user sees the file when
|
|
89
|
+
* listing objects in the store. It means the file can be searched for.
|
|
90
|
+
*/
|
|
91
|
+
type: PermissionType = 'user';
|
|
92
|
+
/**
|
|
93
|
+
* The id of the owner of the permission.
|
|
94
|
+
* The value depends on the `type`. For the `user` type it is the user id.
|
|
95
|
+
* The `group` means the group id. It is not set when the role is `anyone`.
|
|
96
|
+
*/
|
|
97
|
+
owner?: string;
|
|
98
|
+
/**
|
|
99
|
+
* The role granted by this permission.
|
|
100
|
+
*/
|
|
101
|
+
role: PermissionRole = 'reader';
|
|
102
|
+
/**
|
|
103
|
+
* The "pretty" name to render with the permission.
|
|
104
|
+
*
|
|
105
|
+
* - `user` type - user's full name
|
|
106
|
+
* - `group` type - the name of the group
|
|
107
|
+
* - `anyone` type - no render name
|
|
108
|
+
*/
|
|
109
|
+
displayName?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Optional expiration date of the permission. This is the timestamp when the permission expires.
|
|
112
|
+
* When creating / updating the permission the expiration date must:
|
|
113
|
+
*
|
|
114
|
+
* - be used on a user or a group
|
|
115
|
+
* - the time must be in the future
|
|
116
|
+
*/
|
|
117
|
+
expirationTime?: number;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The store id of the user that added this permission.
|
|
121
|
+
*/
|
|
122
|
+
addingUser: string = '';
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Whether the file object is deleted.
|
|
126
|
+
*/
|
|
127
|
+
deleted?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* The timestamp of when the file was deleted.
|
|
130
|
+
*/
|
|
131
|
+
deletedTime?: number;
|
|
132
|
+
/**
|
|
133
|
+
* The id of the user that has deleted the file.
|
|
134
|
+
*/
|
|
135
|
+
deletingUser?: string;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Creates a Permission object for a user.
|
|
139
|
+
*
|
|
140
|
+
* @param role The user role to set.
|
|
141
|
+
* @param user The user id that has the role.
|
|
142
|
+
*/
|
|
143
|
+
static fromUserRole(role: PermissionRole, user: string, addingUser: string): Permission {
|
|
144
|
+
const init: IPermission = {
|
|
145
|
+
key: v4(),
|
|
146
|
+
kind: Kind,
|
|
147
|
+
owner: user,
|
|
148
|
+
role,
|
|
149
|
+
type: 'user',
|
|
150
|
+
addingUser,
|
|
151
|
+
};
|
|
152
|
+
return new Permission(init);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Creates a Permission object for a group.
|
|
157
|
+
*
|
|
158
|
+
* @param role The group role to set.
|
|
159
|
+
* @param group The group id that has the role.
|
|
160
|
+
*/
|
|
161
|
+
static fromGroupRole(role: PermissionRole, group: string, addingUser: string): Permission {
|
|
162
|
+
const init: IPermission = {
|
|
163
|
+
key: v4(),
|
|
164
|
+
kind: Kind,
|
|
165
|
+
owner: group,
|
|
166
|
+
role,
|
|
167
|
+
type: 'group',
|
|
168
|
+
addingUser,
|
|
169
|
+
};
|
|
170
|
+
return new Permission(init);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Creates a Permission object for a group.
|
|
175
|
+
*
|
|
176
|
+
* @param role The group role to set.
|
|
177
|
+
* @param group The group id that has the role.
|
|
178
|
+
*/
|
|
179
|
+
static fromAnyoneRole(role: PermissionRole, addingUser: string): Permission {
|
|
180
|
+
const init: IPermission = {
|
|
181
|
+
key: v4(),
|
|
182
|
+
kind: Kind,
|
|
183
|
+
role,
|
|
184
|
+
type: 'anyone',
|
|
185
|
+
addingUser,
|
|
186
|
+
};
|
|
187
|
+
return new Permission(init);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
constructor(input?: string | IPermission) {
|
|
191
|
+
let init: IPermission;
|
|
192
|
+
if (typeof input === 'string') {
|
|
193
|
+
init = JSON.parse(input);
|
|
194
|
+
} else if (typeof input === 'object') {
|
|
195
|
+
init = input;
|
|
196
|
+
} else {
|
|
197
|
+
init = {
|
|
198
|
+
kind: Kind,
|
|
199
|
+
key: v4(),
|
|
200
|
+
owner: '',
|
|
201
|
+
role: 'reader',
|
|
202
|
+
type: 'user',
|
|
203
|
+
addingUser: '',
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
this.new(init);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Creates a new environment clearing anything that is so far defined.
|
|
211
|
+
*
|
|
212
|
+
* Note, this throws an error when the environment is not a space.
|
|
213
|
+
*/
|
|
214
|
+
new(init: IPermission): void {
|
|
215
|
+
if (!Permission.isPermission(init)) {
|
|
216
|
+
throw new Error(`Not a permission.`);
|
|
217
|
+
}
|
|
218
|
+
const { key = v4(), owner, role, type, displayName, expirationTime, addingUser, deleted, deletedTime, deletingUser } = init;
|
|
219
|
+
this.kind = Kind;
|
|
220
|
+
this.key = key;
|
|
221
|
+
this.owner = owner;
|
|
222
|
+
this.role = role;
|
|
223
|
+
this.type = type;
|
|
224
|
+
this.addingUser = addingUser;
|
|
225
|
+
if (displayName) {
|
|
226
|
+
this.displayName = displayName;
|
|
227
|
+
} else {
|
|
228
|
+
this.displayName = undefined;
|
|
229
|
+
}
|
|
230
|
+
if (typeof expirationTime === 'number') {
|
|
231
|
+
this.expirationTime = expirationTime;
|
|
232
|
+
} else {
|
|
233
|
+
this.expirationTime = undefined;
|
|
234
|
+
}
|
|
235
|
+
if (typeof deleted === 'boolean') {
|
|
236
|
+
this.deleted = deleted;
|
|
237
|
+
this.deletedTime = deletedTime;
|
|
238
|
+
this.deletingUser = deletingUser;
|
|
239
|
+
} else {
|
|
240
|
+
this.deleted = undefined;
|
|
241
|
+
this.deletedTime = undefined;
|
|
242
|
+
this.deletingUser = undefined;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Checks whether the input is a definition of an user space.
|
|
248
|
+
*/
|
|
249
|
+
static isPermission(input: unknown): boolean {
|
|
250
|
+
const typed = input as IPermission;
|
|
251
|
+
if (!input || typed.kind !== Kind) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
toJSON(): IPermission {
|
|
258
|
+
const result: IPermission = {
|
|
259
|
+
kind: Kind,
|
|
260
|
+
key: this.key,
|
|
261
|
+
role: this.role,
|
|
262
|
+
type: this.type,
|
|
263
|
+
addingUser: this.addingUser,
|
|
264
|
+
};
|
|
265
|
+
if (this.owner) {
|
|
266
|
+
result.owner = this.owner;
|
|
267
|
+
}
|
|
268
|
+
if (this.displayName) {
|
|
269
|
+
result.displayName = this.displayName;
|
|
270
|
+
}
|
|
271
|
+
if (this.expirationTime) {
|
|
272
|
+
result.expirationTime = this.expirationTime;
|
|
273
|
+
}
|
|
274
|
+
if (typeof this.deleted === 'boolean') {
|
|
275
|
+
result.deleted = this.deleted;
|
|
276
|
+
|
|
277
|
+
if (this.deletedTime) {
|
|
278
|
+
result.deletedTime = this.deletedTime;
|
|
279
|
+
}
|
|
280
|
+
if (this.deletingUser) {
|
|
281
|
+
result.deletingUser = this.deletingUser;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* This is used in the communication with the backend to add/change user's access to the resource.
|
|
290
|
+
*/
|
|
291
|
+
export interface IAccessOperation {
|
|
292
|
+
/**
|
|
293
|
+
* The user or group id. Not populated for `anyone` type.
|
|
294
|
+
*/
|
|
295
|
+
id?: string;
|
|
296
|
+
/**
|
|
297
|
+
* The permission type
|
|
298
|
+
*/
|
|
299
|
+
type: PermissionType;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface IAccessAddOperation extends IAccessOperation {
|
|
303
|
+
op: "add";
|
|
304
|
+
/**
|
|
305
|
+
* The level that the user or the group has access to.
|
|
306
|
+
*/
|
|
307
|
+
value: PermissionRole;
|
|
308
|
+
/**
|
|
309
|
+
* The timestamp when the permission expires.
|
|
310
|
+
*/
|
|
311
|
+
expirationTime?: number;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface IAccessRemoveOperation extends IAccessOperation {
|
|
315
|
+
op: "remove";
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export type AccessOperation = IAccessAddOperation | IAccessRemoveOperation;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export interface IEmail {
|
|
2
|
+
/**
|
|
3
|
+
* When available the email of the user.
|
|
4
|
+
*/
|
|
5
|
+
email?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Whether the `email` was verified.
|
|
8
|
+
* Not verified emails should have limited use in the system.
|
|
9
|
+
*/
|
|
10
|
+
verified?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IUserPicture {
|
|
14
|
+
/**
|
|
15
|
+
* When available, the URL to the user's picture image.
|
|
16
|
+
*/
|
|
17
|
+
url?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Alternative to the `imageUrl`. When set it is a data URL value of the image.
|
|
20
|
+
*/
|
|
21
|
+
data?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const Kind = 'Core#User';
|
|
25
|
+
|
|
26
|
+
interface BaseUser {
|
|
27
|
+
kind: typeof Kind;
|
|
28
|
+
/**
|
|
29
|
+
* Data store key of the user.
|
|
30
|
+
*/
|
|
31
|
+
key: string;
|
|
32
|
+
/**
|
|
33
|
+
* The display name of the user.
|
|
34
|
+
*/
|
|
35
|
+
name: string;
|
|
36
|
+
/**
|
|
37
|
+
* When available the email of the user.
|
|
38
|
+
*/
|
|
39
|
+
email?: IEmail[];
|
|
40
|
+
/**
|
|
41
|
+
* The user picture to render.
|
|
42
|
+
*/
|
|
43
|
+
picture?: IUserPicture;
|
|
44
|
+
/**
|
|
45
|
+
* General purpose tags field.
|
|
46
|
+
*/
|
|
47
|
+
tags?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Optional user locale information.
|
|
50
|
+
*/
|
|
51
|
+
locale?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Optional metadata related to the auth provider.
|
|
54
|
+
*/
|
|
55
|
+
provider?: unknown;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the user is deleted from the system.
|
|
58
|
+
*/
|
|
59
|
+
deleted?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* The timestamp of when the user was deleted.
|
|
62
|
+
*/
|
|
63
|
+
deletedTime?: number;
|
|
64
|
+
/**
|
|
65
|
+
* The id of the user that deleted the user.
|
|
66
|
+
*/
|
|
67
|
+
deletingUser?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Represents a user in the system.
|
|
72
|
+
* This can be embedded in various situations like project's revision history,
|
|
73
|
+
* ACL, Authorization, etc.
|
|
74
|
+
*
|
|
75
|
+
* Note, the store implementation may have additional fields that support external
|
|
76
|
+
* identity providers. However, this is not exposed to the user through the API.
|
|
77
|
+
*/
|
|
78
|
+
export interface IUser extends BaseUser {
|
|
79
|
+
/**
|
|
80
|
+
* Optional metadata related to the auth provider.
|
|
81
|
+
*/
|
|
82
|
+
provider?: unknown;
|
|
83
|
+
}
|