@api-client/core 0.4.4 → 0.5.2
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 +6 -4
- package/build/browser.js +5 -3
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +6 -4
- package/build/index.js +5 -3
- 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 +11 -2
- package/build/src/models/Workspace.d.ts +5 -46
- package/build/src/models/Workspace.js +12 -43
- package/build/src/models/Workspace.js.map +1 -1
- package/build/src/models/store/File.d.ts +98 -0
- package/build/src/models/store/File.js +91 -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 +196 -0
- package/build/src/models/store/Permission.js +221 -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/RouteBuilder.d.ts +1 -0
- package/build/src/runtime/store/RouteBuilder.js +3 -0
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/Sdk.d.ts +5 -0
- package/build/src/runtime/store/Sdk.js +8 -0
- package/build/src/runtime/store/Sdk.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.d.ts +9 -0
- package/build/src/runtime/store/SharedSdk.js +35 -0
- package/build/src/runtime/store/SharedSdk.js.map +1 -0
- package/build/src/runtime/store/SpacesSdk.d.ts +17 -5
- package/build/src/runtime/store/SpacesSdk.js +11 -2
- package/build/src/runtime/store/SpacesSdk.js.map +1 -1
- package/build/src/runtime/store/StoreSdkNode.d.ts +2 -0
- package/build/src/runtime/store/StoreSdkNode.js.map +1 -1
- package/build/src/runtime/store/StoreSdkWeb.d.ts +2 -0
- package/build/src/runtime/store/StoreSdkWeb.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 +11 -2
- package/src/models/Workspace.ts +16 -67
- package/src/models/store/File.ts +149 -0
- package/src/models/store/Group.ts +21 -0
- package/src/models/store/Permission.ts +332 -0
- package/src/models/store/User.ts +83 -0
- package/src/runtime/store/RouteBuilder.ts +4 -0
- package/src/runtime/store/Sdk.ts +8 -0
- package/src/runtime/store/SharedSdk.ts +35 -0
- package/src/runtime/store/SpacesSdk.ts +26 -7
- package/src/runtime/store/StoreSdkNode.ts +3 -0
- package/src/runtime/store/StoreSdkWeb.ts +3 -0
- package/src/runtime/store/UsersSdk.ts +1 -1
- package/build/src/models/User.js.map +0 -1
- package/src/models/User.ts +0 -138
|
@@ -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,332 @@
|
|
|
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
|
+
interface IBasePermission {
|
|
9
|
+
/**
|
|
10
|
+
* The type of the permission.
|
|
11
|
+
*
|
|
12
|
+
* - `user` can access the file by a specific user
|
|
13
|
+
* - `group` can access the file by a group of users
|
|
14
|
+
* - `anyone` the object can be searched by anyone who has access to the store.
|
|
15
|
+
*
|
|
16
|
+
* Note, the `anyone` object does not mean that the end-user sees the file when
|
|
17
|
+
* listing objects in the store. It means the file can be searched for.
|
|
18
|
+
*/
|
|
19
|
+
type: PermissionType;
|
|
20
|
+
/**
|
|
21
|
+
* The id of the owner of the permission.
|
|
22
|
+
* The value depends on the `type`. For the `user` type it is the user id.
|
|
23
|
+
* The `group` means the group id. It is not set when the role is `anyone`.
|
|
24
|
+
*/
|
|
25
|
+
owner?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The role granted by this permission.
|
|
28
|
+
*/
|
|
29
|
+
role: PermissionRole;
|
|
30
|
+
/**
|
|
31
|
+
* The "pretty" name to render with the permission.
|
|
32
|
+
*
|
|
33
|
+
* - `user` type - user's full name
|
|
34
|
+
* - `group` type - the name of the group
|
|
35
|
+
* - `anyone` type - no render name
|
|
36
|
+
*/
|
|
37
|
+
displayName?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Optional expiration date of the permission. This is the timestamp when the permission expires.
|
|
40
|
+
* When creating / updating the permission the expiration date must:
|
|
41
|
+
*
|
|
42
|
+
* - be used on a user or a group
|
|
43
|
+
* - the time must be in the future
|
|
44
|
+
*/
|
|
45
|
+
expirationTime?: number;
|
|
46
|
+
/**
|
|
47
|
+
* The store id of the user that added this permission.
|
|
48
|
+
*/
|
|
49
|
+
addingUser: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether the permission object is deleted.
|
|
53
|
+
*/
|
|
54
|
+
deleted?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The timestamp of when the permission was deleted.
|
|
57
|
+
*/
|
|
58
|
+
deletedTime?: number;
|
|
59
|
+
/**
|
|
60
|
+
* The id of the user that has deleted the permission.
|
|
61
|
+
*/
|
|
62
|
+
deletingUser?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A schema describing a permission to a store object.
|
|
67
|
+
*/
|
|
68
|
+
export interface IPermission extends IBasePermission{
|
|
69
|
+
kind: typeof Kind;
|
|
70
|
+
/**
|
|
71
|
+
* The data store key of the permission.
|
|
72
|
+
* This property is generated by the store and is not writable.
|
|
73
|
+
*/
|
|
74
|
+
key: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export class Permission {
|
|
78
|
+
kind = Kind;
|
|
79
|
+
/**
|
|
80
|
+
* The data store key of the permission.
|
|
81
|
+
* This property is generated by the store and is not writable.
|
|
82
|
+
*/
|
|
83
|
+
key = '';
|
|
84
|
+
/**
|
|
85
|
+
* The type of the permission.
|
|
86
|
+
*
|
|
87
|
+
* - `user` can access the file by a specific user
|
|
88
|
+
* - `group` can access the file by a group of users
|
|
89
|
+
* - `anyone` the object can be searched by anyone who has access to the store.
|
|
90
|
+
*
|
|
91
|
+
* Note, the `anyone` object does not mean that the end-user sees the file when
|
|
92
|
+
* listing objects in the store. It means the file can be searched for.
|
|
93
|
+
*/
|
|
94
|
+
type: PermissionType = 'user';
|
|
95
|
+
/**
|
|
96
|
+
* The id of the owner of the permission.
|
|
97
|
+
* The value depends on the `type`. For the `user` type it is the user id.
|
|
98
|
+
* The `group` means the group id. It is not set when the role is `anyone`.
|
|
99
|
+
*/
|
|
100
|
+
owner?: string;
|
|
101
|
+
/**
|
|
102
|
+
* The role granted by this permission.
|
|
103
|
+
*/
|
|
104
|
+
role: PermissionRole = 'reader';
|
|
105
|
+
/**
|
|
106
|
+
* The "pretty" name to render with the permission.
|
|
107
|
+
*
|
|
108
|
+
* - `user` type - user's full name
|
|
109
|
+
* - `group` type - the name of the group
|
|
110
|
+
* - `anyone` type - no render name
|
|
111
|
+
*/
|
|
112
|
+
displayName?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Optional expiration date of the permission. This is the timestamp when the permission expires.
|
|
115
|
+
* When creating / updating the permission the expiration date must:
|
|
116
|
+
*
|
|
117
|
+
* - be used on a user or a group
|
|
118
|
+
* - the time must be in the future
|
|
119
|
+
*/
|
|
120
|
+
expirationTime?: number;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The store id of the user that added this permission.
|
|
124
|
+
*/
|
|
125
|
+
addingUser: string = '';
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Whether the file object is deleted.
|
|
129
|
+
*/
|
|
130
|
+
deleted?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* The timestamp of when the file was deleted.
|
|
133
|
+
*/
|
|
134
|
+
deletedTime?: number;
|
|
135
|
+
/**
|
|
136
|
+
* The id of the user that has deleted the file.
|
|
137
|
+
*/
|
|
138
|
+
deletingUser?: string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Creates a Permission object for a user.
|
|
142
|
+
*
|
|
143
|
+
* @param role The user role to set.
|
|
144
|
+
* @param user The user id that has the role.
|
|
145
|
+
*/
|
|
146
|
+
static fromUserRole(role: PermissionRole, user: string, addingUser: string): Permission {
|
|
147
|
+
const init: IPermission = {
|
|
148
|
+
key: v4(),
|
|
149
|
+
kind: Kind,
|
|
150
|
+
owner: user,
|
|
151
|
+
role,
|
|
152
|
+
type: 'user',
|
|
153
|
+
addingUser,
|
|
154
|
+
};
|
|
155
|
+
return new Permission(init);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Creates a Permission object for a group.
|
|
160
|
+
*
|
|
161
|
+
* @param role The group role to set.
|
|
162
|
+
* @param group The group id that has the role.
|
|
163
|
+
*/
|
|
164
|
+
static fromGroupRole(role: PermissionRole, group: string, addingUser: string): Permission {
|
|
165
|
+
const init: IPermission = {
|
|
166
|
+
key: v4(),
|
|
167
|
+
kind: Kind,
|
|
168
|
+
owner: group,
|
|
169
|
+
role,
|
|
170
|
+
type: 'group',
|
|
171
|
+
addingUser,
|
|
172
|
+
};
|
|
173
|
+
return new Permission(init);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Creates a Permission object for a group.
|
|
178
|
+
*
|
|
179
|
+
* @param role The group role to set.
|
|
180
|
+
* @param group The group id that has the role.
|
|
181
|
+
*/
|
|
182
|
+
static fromAnyoneRole(role: PermissionRole, addingUser: string): Permission {
|
|
183
|
+
const init: IPermission = {
|
|
184
|
+
key: v4(),
|
|
185
|
+
kind: Kind,
|
|
186
|
+
role,
|
|
187
|
+
type: 'anyone',
|
|
188
|
+
addingUser,
|
|
189
|
+
};
|
|
190
|
+
return new Permission(init);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Creates a permission object from other than key and kind values.
|
|
195
|
+
*/
|
|
196
|
+
static fromValues(init: IBasePermission): Permission {
|
|
197
|
+
return new Permission({
|
|
198
|
+
...init,
|
|
199
|
+
key: v4(),
|
|
200
|
+
kind: Kind,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
constructor(input?: string | IPermission) {
|
|
205
|
+
let init: IPermission;
|
|
206
|
+
if (typeof input === 'string') {
|
|
207
|
+
init = JSON.parse(input);
|
|
208
|
+
} else if (typeof input === 'object') {
|
|
209
|
+
init = input;
|
|
210
|
+
} else {
|
|
211
|
+
init = {
|
|
212
|
+
kind: Kind,
|
|
213
|
+
key: v4(),
|
|
214
|
+
owner: '',
|
|
215
|
+
role: 'reader',
|
|
216
|
+
type: 'user',
|
|
217
|
+
addingUser: '',
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
this.new(init);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Creates a new environment clearing anything that is so far defined.
|
|
225
|
+
*
|
|
226
|
+
* Note, this throws an error when the environment is not a space.
|
|
227
|
+
*/
|
|
228
|
+
new(init: IPermission): void {
|
|
229
|
+
if (!Permission.isPermission(init)) {
|
|
230
|
+
throw new Error(`Not a permission.`);
|
|
231
|
+
}
|
|
232
|
+
const { key = v4(), owner, role, type, displayName, expirationTime, addingUser, deleted, deletedTime, deletingUser } = init;
|
|
233
|
+
this.kind = Kind;
|
|
234
|
+
this.key = key;
|
|
235
|
+
this.owner = owner;
|
|
236
|
+
this.role = role;
|
|
237
|
+
this.type = type;
|
|
238
|
+
this.addingUser = addingUser;
|
|
239
|
+
if (displayName) {
|
|
240
|
+
this.displayName = displayName;
|
|
241
|
+
} else {
|
|
242
|
+
this.displayName = undefined;
|
|
243
|
+
}
|
|
244
|
+
if (typeof expirationTime === 'number') {
|
|
245
|
+
this.expirationTime = expirationTime;
|
|
246
|
+
} else {
|
|
247
|
+
this.expirationTime = undefined;
|
|
248
|
+
}
|
|
249
|
+
if (typeof deleted === 'boolean') {
|
|
250
|
+
this.deleted = deleted;
|
|
251
|
+
this.deletedTime = deletedTime;
|
|
252
|
+
this.deletingUser = deletingUser;
|
|
253
|
+
} else {
|
|
254
|
+
this.deleted = undefined;
|
|
255
|
+
this.deletedTime = undefined;
|
|
256
|
+
this.deletingUser = undefined;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Checks whether the input is a definition of an user space.
|
|
262
|
+
*/
|
|
263
|
+
static isPermission(input: unknown): boolean {
|
|
264
|
+
const typed = input as IPermission;
|
|
265
|
+
if (!input || typed.kind !== Kind) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
toJSON(): IPermission {
|
|
272
|
+
const result: IPermission = {
|
|
273
|
+
kind: Kind,
|
|
274
|
+
key: this.key,
|
|
275
|
+
role: this.role,
|
|
276
|
+
type: this.type,
|
|
277
|
+
addingUser: this.addingUser,
|
|
278
|
+
};
|
|
279
|
+
if (this.owner) {
|
|
280
|
+
result.owner = this.owner;
|
|
281
|
+
}
|
|
282
|
+
if (this.displayName) {
|
|
283
|
+
result.displayName = this.displayName;
|
|
284
|
+
}
|
|
285
|
+
if (this.expirationTime) {
|
|
286
|
+
result.expirationTime = this.expirationTime;
|
|
287
|
+
}
|
|
288
|
+
if (typeof this.deleted === 'boolean') {
|
|
289
|
+
result.deleted = this.deleted;
|
|
290
|
+
|
|
291
|
+
if (this.deletedTime) {
|
|
292
|
+
result.deletedTime = this.deletedTime;
|
|
293
|
+
}
|
|
294
|
+
if (this.deletingUser) {
|
|
295
|
+
result.deletingUser = this.deletingUser;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* This is used in the communication with the backend to add/change user's access to the resource.
|
|
304
|
+
*/
|
|
305
|
+
export interface IAccessOperation {
|
|
306
|
+
/**
|
|
307
|
+
* The user or group id. Not populated for `anyone` type.
|
|
308
|
+
*/
|
|
309
|
+
id?: string;
|
|
310
|
+
/**
|
|
311
|
+
* The permission type
|
|
312
|
+
*/
|
|
313
|
+
type: PermissionType;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface IAccessAddOperation extends IAccessOperation {
|
|
317
|
+
op: "add";
|
|
318
|
+
/**
|
|
319
|
+
* The level that the user or the group has access to.
|
|
320
|
+
*/
|
|
321
|
+
value: PermissionRole;
|
|
322
|
+
/**
|
|
323
|
+
* The timestamp when the permission expires.
|
|
324
|
+
*/
|
|
325
|
+
expirationTime?: number;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export interface IAccessRemoveOperation extends IAccessOperation {
|
|
329
|
+
op: "remove";
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
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
|
+
}
|
package/src/runtime/store/Sdk.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { SpacesSdk } from './SpacesSdk.js';
|
|
|
7
7
|
import { ProjectsSdk } from './ProjectsSdk.js';
|
|
8
8
|
import { UsersSdk } from './UsersSdk.js';
|
|
9
9
|
import { HistorySdk } from './HistorySdk.js';
|
|
10
|
+
import { SharedSdk } from './SharedSdk.js';
|
|
10
11
|
|
|
11
12
|
const baseUriSymbol = Symbol('baseUri');
|
|
12
13
|
|
|
@@ -50,6 +51,10 @@ export abstract class Sdk {
|
|
|
50
51
|
* The history data.
|
|
51
52
|
*/
|
|
52
53
|
history = new HistorySdk(this);
|
|
54
|
+
/**
|
|
55
|
+
* The shared data.
|
|
56
|
+
*/
|
|
57
|
+
shared = new SharedSdk(this);
|
|
53
58
|
|
|
54
59
|
|
|
55
60
|
[baseUriSymbol] = '';
|
|
@@ -126,6 +131,9 @@ export abstract class Sdk {
|
|
|
126
131
|
searchParams.append('queryField', field);
|
|
127
132
|
});
|
|
128
133
|
}
|
|
134
|
+
if (options.parent) {
|
|
135
|
+
searchParams.set('parent', options.parent);
|
|
136
|
+
}
|
|
129
137
|
}
|
|
130
138
|
}
|
|
131
139
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN } from './SdkBase.js';
|
|
2
|
+
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
+
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
4
|
+
|
|
5
|
+
export class SharedSdk extends SdkBase {
|
|
6
|
+
/**
|
|
7
|
+
* Lists shared with the user spaces.
|
|
8
|
+
* @param options Optional query options.
|
|
9
|
+
*/
|
|
10
|
+
async list(options?: IListOptions): Promise<IListResponse> {
|
|
11
|
+
const { token } = this.sdk;
|
|
12
|
+
const url = this.sdk.getUrl(RouteBuilder.sharedSpaces());
|
|
13
|
+
this.sdk.appendListOptions(url, options);
|
|
14
|
+
const result = await this.sdk.http.get(url.toString(), { token });
|
|
15
|
+
this.inspectCommonStatusCodes(result.status);
|
|
16
|
+
const E_PREFIX = 'Unable to list spaces. ';
|
|
17
|
+
if (result.status !== 200) {
|
|
18
|
+
this.logInvalidResponse(result);
|
|
19
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
20
|
+
}
|
|
21
|
+
if (!result.body) {
|
|
22
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
23
|
+
}
|
|
24
|
+
let data: IListResponse;
|
|
25
|
+
try {
|
|
26
|
+
data = JSON.parse(result.body);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
29
|
+
}
|
|
30
|
+
if (!Array.isArray(data.data)) {
|
|
31
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
32
|
+
}
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -2,8 +2,17 @@ import { JsonPatch } from 'json8-patch';
|
|
|
2
2
|
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
|
|
3
3
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
4
4
|
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
5
|
-
import { IWorkspace,
|
|
6
|
-
import {
|
|
5
|
+
import { IWorkspace, Workspace, Kind as WorkspaceKind } from '../../models/Workspace.js';
|
|
6
|
+
import { AccessOperation } from '../../models/store/Permission.js';
|
|
7
|
+
import WebSocketNode from 'ws';
|
|
8
|
+
|
|
9
|
+
export interface ISpaceCreateOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Optional parent space id.
|
|
12
|
+
* When set it creates a space under this parent.
|
|
13
|
+
*/
|
|
14
|
+
parent?: string;
|
|
15
|
+
}
|
|
7
16
|
|
|
8
17
|
export class SpacesSdk extends SdkBase {
|
|
9
18
|
/**
|
|
@@ -41,9 +50,10 @@ export class SpacesSdk extends SdkBase {
|
|
|
41
50
|
* @param space The workspace definition.
|
|
42
51
|
* @returns The key of the creates space.
|
|
43
52
|
*/
|
|
44
|
-
async create(space: IWorkspace | Workspace): Promise<string> {
|
|
53
|
+
async create(space: IWorkspace | Workspace, opts: ISpaceCreateOptions = {}): Promise<string> {
|
|
45
54
|
const { token } = this.sdk;
|
|
46
|
-
const
|
|
55
|
+
const path = opts.parent ? RouteBuilder.space(opts.parent) : RouteBuilder.spaces();
|
|
56
|
+
const url = this.sdk.getUrl(path);
|
|
47
57
|
const body = JSON.stringify(space);
|
|
48
58
|
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
49
59
|
this.inspectCommonStatusCodes(result.status);
|
|
@@ -65,7 +75,7 @@ export class SpacesSdk extends SdkBase {
|
|
|
65
75
|
* @param key The user space key
|
|
66
76
|
* @returns The definition of the user space.
|
|
67
77
|
*/
|
|
68
|
-
async read(key: string): Promise<
|
|
78
|
+
async read(key: string): Promise<IWorkspace> {
|
|
69
79
|
const { token } = this.sdk;
|
|
70
80
|
const url = this.sdk.getUrl(RouteBuilder.space(key));
|
|
71
81
|
const result = await this.sdk.http.get(url.toString(), { token });
|
|
@@ -78,7 +88,7 @@ export class SpacesSdk extends SdkBase {
|
|
|
78
88
|
if (!result.body) {
|
|
79
89
|
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
80
90
|
}
|
|
81
|
-
let data:
|
|
91
|
+
let data: IWorkspace;
|
|
82
92
|
try {
|
|
83
93
|
data = JSON.parse(result.body);
|
|
84
94
|
} catch (e) {
|
|
@@ -145,7 +155,7 @@ export class SpacesSdk extends SdkBase {
|
|
|
145
155
|
* @param key The user space key
|
|
146
156
|
* @param value The patch operation on the space's ACL
|
|
147
157
|
*/
|
|
148
|
-
async patchUsers(key: string, value:
|
|
158
|
+
async patchUsers(key: string, value: AccessOperation[]): Promise<void> {
|
|
149
159
|
const { token } = this.sdk;
|
|
150
160
|
const url = this.sdk.getUrl(RouteBuilder.spaceUsers(key));
|
|
151
161
|
const body = JSON.stringify(value);
|
|
@@ -187,4 +197,13 @@ export class SpacesSdk extends SdkBase {
|
|
|
187
197
|
}
|
|
188
198
|
return data;
|
|
189
199
|
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Creates a WS client that listens to the spaces events.
|
|
203
|
+
*/
|
|
204
|
+
async observeSpaces(): Promise<WebSocketNode | WebSocket> {
|
|
205
|
+
const { token } = this.sdk;
|
|
206
|
+
const url = this.sdk.getUrl(RouteBuilder.spaces());
|
|
207
|
+
return this.sdk.ws.createAndConnect(url.toString(), token);
|
|
208
|
+
}
|
|
190
209
|
}
|
|
@@ -4,6 +4,9 @@ import { Sdk } from './Sdk.js';
|
|
|
4
4
|
import { Http } from './Http.js';
|
|
5
5
|
import { WsClient } from './WsClient.js';
|
|
6
6
|
|
|
7
|
+
export { IStoreTokenInfo, IStoreResponse, IStoreRequestOptions } from './SdkBase.js';
|
|
8
|
+
export { ISpaceCreateOptions } from './SpacesSdk.js';
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* NodeJS API for API Client's net-store module.
|
|
9
12
|
*/
|
|
@@ -4,6 +4,9 @@ import { Sdk } from './Sdk.js';
|
|
|
4
4
|
import { Http } from './Http.js';
|
|
5
5
|
import { WsClient } from './WsClient.js';
|
|
6
6
|
|
|
7
|
+
export { IStoreTokenInfo, IStoreResponse, IStoreRequestOptions } from './SdkBase.js';
|
|
8
|
+
export { ISpaceCreateOptions } from './SpacesSdk.js';
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* NodeJS API for API Client's net-store module.
|
|
9
12
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN } from './SdkBase.js';
|
|
2
2
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
3
|
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
4
|
-
import { IUser } from '../../models/User.js';
|
|
4
|
+
import { IUser } from '../../models/store/User.js';
|
|
5
5
|
|
|
6
6
|
export class UsersSdk extends SdkBase {
|
|
7
7
|
async me(): Promise<IUser> {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"User.js","sourceRoot":"","sources":["../../../src/models/User.ts"],"names":[],"mappings":"AAgEA,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAC"}
|