@api-client/core 0.5.7 → 0.5.10
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 +3 -1
- package/build/browser.js +1 -1
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +3 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/src/models/Environment.js +1 -0
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/Request.js +1 -1
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestAuthorization.js +2 -1
- package/build/src/models/RequestAuthorization.js.map +1 -1
- package/build/src/models/store/Breadcrumb.d.ts +17 -0
- package/build/src/models/store/Breadcrumb.js +2 -0
- package/build/src/models/store/Breadcrumb.js.map +1 -0
- package/build/src/models/store/Capabilities.d.ts +77 -0
- package/build/src/models/store/Capabilities.js +2 -0
- package/build/src/models/store/Capabilities.js.map +1 -0
- package/build/src/models/store/File.d.ts +67 -8
- package/build/src/models/store/File.js +144 -27
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Permission.d.ts +16 -1
- package/build/src/models/store/Permission.js +27 -1
- package/build/src/models/store/Permission.js.map +1 -1
- package/build/src/models/{RevisionInfo.d.ts → store/Revision.d.ts} +2 -2
- package/build/src/models/store/Revision.js +2 -0
- package/build/src/models/store/Revision.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.d.ts +8 -0
- package/build/src/runtime/store/FilesSdk.js +38 -0
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +4 -0
- package/build/src/runtime/store/RouteBuilder.js +6 -0
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/package.json +1 -1
- package/src/models/Environment.ts +1 -0
- package/src/models/Request.ts +1 -1
- package/src/models/RequestAuthorization.ts +2 -1
- package/src/models/store/Breadcrumb.ts +17 -0
- package/src/models/store/Capabilities.ts +77 -0
- package/src/models/store/File.ts +177 -28
- package/src/models/store/Permission.ts +30 -3
- package/src/models/{RevisionInfo.ts → store/Revision.ts} +2 -2
- package/src/runtime/store/FilesSdk.ts +38 -0
- package/src/runtime/store/RouteBuilder.ts +7 -0
- package/build/src/models/RevisionInfo.js +0 -2
- package/build/src/models/RevisionInfo.js.map +0 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A schema describing a breadcrumb for a file.
|
|
3
|
+
*/
|
|
4
|
+
export interface IBreadcrumb {
|
|
5
|
+
/**
|
|
6
|
+
* The key of the parent item
|
|
7
|
+
*/
|
|
8
|
+
key: string;
|
|
9
|
+
/**
|
|
10
|
+
* The parent's kind
|
|
11
|
+
*/
|
|
12
|
+
kind: string;
|
|
13
|
+
/**
|
|
14
|
+
* The parent's name
|
|
15
|
+
*/
|
|
16
|
+
displayName: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capabilities the current user has on this file.
|
|
3
|
+
* This is populated by the store each time the user requests
|
|
4
|
+
* a file.
|
|
5
|
+
*/
|
|
6
|
+
export interface ICapabilities {
|
|
7
|
+
/**
|
|
8
|
+
* Whether the user can edit the current file.
|
|
9
|
+
* The permission to edit can be inherited from a containing space so not visible
|
|
10
|
+
* in the file's permissions.
|
|
11
|
+
*/
|
|
12
|
+
canEdit: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the user can comment on the current file.
|
|
15
|
+
* The permission to edit can be inherited from a containing space so not visible
|
|
16
|
+
* in the file's permissions.
|
|
17
|
+
*/
|
|
18
|
+
canComment: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the user can share the current file.
|
|
21
|
+
* The permission to edit can be inherited from a containing space so not visible
|
|
22
|
+
* in the file's permissions.
|
|
23
|
+
*/
|
|
24
|
+
canShare: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the user can make a copy of the file.
|
|
27
|
+
*
|
|
28
|
+
* Note, this is reserved for future use an currently not supported by the store.
|
|
29
|
+
*
|
|
30
|
+
* The permission to edit can be inherited from a containing space so not visible
|
|
31
|
+
* in the file's permissions.
|
|
32
|
+
*/
|
|
33
|
+
canCopy?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the user can read revisions of the file.
|
|
36
|
+
*
|
|
37
|
+
* Note, this is reserved for future use an currently not supported by the store.
|
|
38
|
+
*
|
|
39
|
+
* The permission to edit can be inherited from a containing space so not visible
|
|
40
|
+
* in the file's permissions.
|
|
41
|
+
*/
|
|
42
|
+
canReadRevisions?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the user can add children to the file.
|
|
45
|
+
* This can be `true` only for user spaces.
|
|
46
|
+
*/
|
|
47
|
+
canAddChildren: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the user can permanently delete the file.
|
|
50
|
+
*
|
|
51
|
+
* The permission to edit can be inherited from a containing space so not visible
|
|
52
|
+
* in the file's permissions.
|
|
53
|
+
*/
|
|
54
|
+
canDelete: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Only set for user spaces. Otherwise it is always `false`.
|
|
57
|
+
* Whether the user can list children of the user space.
|
|
58
|
+
*/
|
|
59
|
+
canListChildren: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the user can rename the file.
|
|
62
|
+
*/
|
|
63
|
+
canRename: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the user can move the file to trash.
|
|
66
|
+
*/
|
|
67
|
+
canTrash: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the user can move the file back from trash.
|
|
70
|
+
*/
|
|
71
|
+
canUntrash: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether the user can read media for the file.
|
|
74
|
+
* This is always `false` for a user space which has no media.
|
|
75
|
+
*/
|
|
76
|
+
canReadMedia: boolean;
|
|
77
|
+
}
|
package/src/models/store/File.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { IPermission } from './Permission.js';
|
|
1
|
+
import { IPermission, Permission, PermissionRole } from './Permission.js';
|
|
2
2
|
import { IModification } from './Modification.js';
|
|
3
3
|
import { IDeletion } from './Deletion.js';
|
|
4
4
|
import { IUser, Kind as UserKind } from './User.js';
|
|
5
5
|
import { IThing, Thing } from '../Thing.js';
|
|
6
6
|
import v4 from '../../lib/uuid.js';
|
|
7
|
+
import { ICapabilities } from './Capabilities.js';
|
|
7
8
|
|
|
8
9
|
export const DefaultOwner = 'default';
|
|
9
10
|
|
|
@@ -56,6 +57,18 @@ export interface IStoredFile {
|
|
|
56
57
|
* An arbitrary list of labels applied to the file.
|
|
57
58
|
*/
|
|
58
59
|
labels?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* This is populated when reading a file from the store.
|
|
62
|
+
* A list of actions the user can perform on the file.
|
|
63
|
+
*
|
|
64
|
+
* This is a readonly field and it is ignored when creating / updating the file.
|
|
65
|
+
*/
|
|
66
|
+
capabilities?: ICapabilities;
|
|
67
|
+
/**
|
|
68
|
+
* The color of the icon to render for this file in the file explorer.
|
|
69
|
+
* This should be a hex format, e.g.: #c00 for red.
|
|
70
|
+
*/
|
|
71
|
+
iconColor?: string;
|
|
59
72
|
}
|
|
60
73
|
|
|
61
74
|
/**
|
|
@@ -75,6 +88,15 @@ export interface IFile extends IStoredFile {
|
|
|
75
88
|
permissions: IPermission[];
|
|
76
89
|
}
|
|
77
90
|
|
|
91
|
+
const parentsSymbol = Symbol('parents');
|
|
92
|
+
const deletedSymbol = Symbol('deleted');
|
|
93
|
+
const deletedInfoSymbol = Symbol('deletedInfo');
|
|
94
|
+
const ownerSymbol = Symbol('owner');
|
|
95
|
+
const lastModifiedSymbol = Symbol('lastModified');
|
|
96
|
+
const capabilitiesSymbol = Symbol('capabilities');
|
|
97
|
+
const permissionsSymbol = Symbol('permissions');
|
|
98
|
+
const permissionIdsSymbol = Symbol('permissionIds');
|
|
99
|
+
|
|
78
100
|
export class StoredFile {
|
|
79
101
|
/**
|
|
80
102
|
* The kind of the File
|
|
@@ -88,6 +110,9 @@ export class StoredFile {
|
|
|
88
110
|
* The name of the environment.
|
|
89
111
|
*/
|
|
90
112
|
info: Thing = Thing.fromName('');
|
|
113
|
+
|
|
114
|
+
[parentsSymbol]: string[] = [];
|
|
115
|
+
|
|
91
116
|
/**
|
|
92
117
|
* The list of parents of the object. It is an ordered list of parents
|
|
93
118
|
* from the top (first element) to the lowest parent in the tree (last element).
|
|
@@ -95,39 +120,84 @@ export class StoredFile {
|
|
|
95
120
|
* This property cannot be manipulated directly by the client. Should be treated as
|
|
96
121
|
* opaque value.
|
|
97
122
|
*/
|
|
98
|
-
parents: string[]
|
|
123
|
+
get parents(): string[] {
|
|
124
|
+
return this[parentsSymbol];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
[permissionIdsSymbol]: ReadonlyArray<string> = [];
|
|
128
|
+
|
|
99
129
|
/**
|
|
100
130
|
* The list of permissions to this file object.
|
|
101
131
|
*
|
|
102
132
|
* This property cannot be manipulated directly by the client. Should be treated as
|
|
103
133
|
* opaque value.
|
|
104
134
|
*/
|
|
105
|
-
permissionIds: string
|
|
135
|
+
get permissionIds(): ReadonlyArray<string> {
|
|
136
|
+
return this[permissionIdsSymbol];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
[deletedSymbol]?: boolean;
|
|
140
|
+
|
|
106
141
|
/**
|
|
107
142
|
* Whether the file object is deleted.
|
|
108
143
|
*/
|
|
109
|
-
deleted
|
|
144
|
+
get deleted(): boolean {
|
|
145
|
+
return this[deletedSymbol] || false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
[deletedInfoSymbol]?: Readonly<IDeletion>;
|
|
149
|
+
|
|
110
150
|
/**
|
|
111
151
|
* The information about the delete information.
|
|
112
152
|
* Always set when the `delete` is true.
|
|
113
153
|
*/
|
|
114
|
-
deletedInfo
|
|
154
|
+
get deletedInfo(): Readonly<IDeletion> | undefined {
|
|
155
|
+
return this[deletedInfoSymbol];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
[ownerSymbol]: string = DefaultOwner;
|
|
159
|
+
|
|
115
160
|
/**
|
|
116
161
|
* The owner of this space. The id of the User object.
|
|
117
162
|
* Set to `default` when there are no users in the system (no authentication).
|
|
118
163
|
*/
|
|
119
|
-
owner
|
|
164
|
+
get owner(): string {
|
|
165
|
+
return this[ownerSymbol];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
[lastModifiedSymbol]: Readonly<IModification> = { user: '', time: 0, byMe: false };
|
|
169
|
+
|
|
120
170
|
/**
|
|
121
171
|
* The last modification made to this file.
|
|
122
172
|
*/
|
|
123
|
-
lastModified: IModification
|
|
173
|
+
get lastModified(): Readonly<IModification> {
|
|
174
|
+
return this[lastModifiedSymbol];
|
|
175
|
+
}
|
|
176
|
+
|
|
124
177
|
/**
|
|
125
178
|
* An arbitrary list of labels applied to the file.
|
|
126
179
|
*/
|
|
127
180
|
labels?: string[];
|
|
128
181
|
|
|
182
|
+
[capabilitiesSymbol]?: Readonly<ICapabilities>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* This is populated when reading a file from the store.
|
|
186
|
+
* A list of actions the user can perform on the file.
|
|
187
|
+
*
|
|
188
|
+
* This is a readonly field and it is ignored when creating / updating the file.
|
|
189
|
+
*/
|
|
190
|
+
get capabilities(): Readonly<ICapabilities> | undefined {
|
|
191
|
+
return this[capabilitiesSymbol];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* The color of the icon to render for this file in the file explorer.
|
|
196
|
+
*/
|
|
197
|
+
iconColor?: string;
|
|
198
|
+
|
|
129
199
|
new(init: IStoredFile): void {
|
|
130
|
-
const { key = v4(), info, kind, parents=[], permissionIds=[], deleted, deletedInfo, owner = DefaultOwner, lastModified, labels } = init;
|
|
200
|
+
const { key = v4(), info, kind, parents=[], permissionIds=[], deleted, deletedInfo, owner = DefaultOwner, lastModified, labels, iconColor } = init;
|
|
131
201
|
this.key = key;
|
|
132
202
|
this.kind = kind;
|
|
133
203
|
if (info) {
|
|
@@ -135,22 +205,27 @@ export class StoredFile {
|
|
|
135
205
|
} else {
|
|
136
206
|
this.info = Thing.fromName('');
|
|
137
207
|
}
|
|
138
|
-
this
|
|
139
|
-
this
|
|
140
|
-
this
|
|
141
|
-
this
|
|
208
|
+
this[parentsSymbol] = [...parents];
|
|
209
|
+
this[permissionIdsSymbol] = [...permissionIds];
|
|
210
|
+
this[ownerSymbol] = owner;
|
|
211
|
+
this[lastModifiedSymbol] = lastModified ? Object.freeze({ ...lastModified }) : Object.freeze({ user: '', time: 0, byMe: false });
|
|
142
212
|
if (typeof deleted === 'boolean') {
|
|
143
|
-
this
|
|
144
|
-
this
|
|
213
|
+
this[deletedSymbol] = deleted;
|
|
214
|
+
this[deletedInfoSymbol] = deletedInfo ? Object.freeze({ ...deletedInfo }) : undefined;
|
|
145
215
|
} else {
|
|
146
|
-
this
|
|
147
|
-
this
|
|
216
|
+
this[deletedSymbol] = undefined;
|
|
217
|
+
this[deletedInfoSymbol] = undefined;
|
|
148
218
|
}
|
|
149
219
|
if (Array.isArray(labels)) {
|
|
150
|
-
this.labels = labels;
|
|
220
|
+
this.labels = [...labels];
|
|
151
221
|
} else {
|
|
152
222
|
this.labels = undefined;
|
|
153
223
|
}
|
|
224
|
+
if (iconColor) {
|
|
225
|
+
this.iconColor = iconColor;
|
|
226
|
+
} else {
|
|
227
|
+
this.iconColor = undefined;
|
|
228
|
+
}
|
|
154
229
|
}
|
|
155
230
|
|
|
156
231
|
toJSON(): IStoredFile {
|
|
@@ -159,17 +234,20 @@ export class StoredFile {
|
|
|
159
234
|
key: this.key,
|
|
160
235
|
kind: this.kind,
|
|
161
236
|
info: this.info.toJSON(),
|
|
162
|
-
parents: this.parents,
|
|
163
|
-
permissionIds: this.permissionIds,
|
|
164
|
-
lastModified: this.lastModified,
|
|
237
|
+
parents: [...this.parents],
|
|
238
|
+
permissionIds: [...this.permissionIds],
|
|
239
|
+
lastModified: { ...this.lastModified },
|
|
165
240
|
owner,
|
|
166
241
|
};
|
|
167
242
|
if (this.deleted) {
|
|
168
243
|
result.deleted = this.deleted;
|
|
169
|
-
result.deletedInfo = this.deletedInfo;
|
|
244
|
+
result.deletedInfo = { ...this.deletedInfo } as IDeletion;
|
|
170
245
|
}
|
|
171
246
|
if (Array.isArray(this.labels)) {
|
|
172
|
-
result.labels = this.labels;
|
|
247
|
+
result.labels = [...this.labels];
|
|
248
|
+
}
|
|
249
|
+
if (this.iconColor) {
|
|
250
|
+
result.iconColor = this.iconColor;
|
|
173
251
|
}
|
|
174
252
|
return result;
|
|
175
253
|
}
|
|
@@ -187,7 +265,7 @@ export class StoredFile {
|
|
|
187
265
|
if (user.kind !== UserKind) {
|
|
188
266
|
throw new Error(`Invalid value for the user when setting "lastModified".`);
|
|
189
267
|
}
|
|
190
|
-
this
|
|
268
|
+
this[lastModifiedSymbol] = {
|
|
191
269
|
byMe: false,
|
|
192
270
|
time: Date.now(),
|
|
193
271
|
user: user.key,
|
|
@@ -234,35 +312,106 @@ export class StoredFile {
|
|
|
234
312
|
if (user.kind !== UserKind) {
|
|
235
313
|
throw new Error(`Invalid value for the user when setting "lastModified".`);
|
|
236
314
|
}
|
|
237
|
-
this
|
|
238
|
-
this
|
|
315
|
+
this[deletedSymbol] = true;
|
|
316
|
+
this[deletedInfoSymbol] = {
|
|
239
317
|
byMe: false,
|
|
240
318
|
time: Date.now(),
|
|
241
319
|
user: user.key,
|
|
242
320
|
name: user.name,
|
|
243
321
|
};
|
|
244
322
|
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Creates the Capabilities object for a file giving user level.
|
|
326
|
+
*
|
|
327
|
+
* @param file The file object to create the capabilities to. The object is not mutated.
|
|
328
|
+
* @param role The user role to the file.
|
|
329
|
+
*/
|
|
330
|
+
static createFileCapabilities(file: IStoredFile | StoredFile, role?: PermissionRole): ICapabilities {
|
|
331
|
+
const isCommenter = Permission.hasRole('commenter', role);
|
|
332
|
+
const isOwner = Permission.hasRole('owner', role);
|
|
333
|
+
const isReader = Permission.hasRole('reader', role);
|
|
334
|
+
const isWriter = Permission.hasRole('writer', role);
|
|
335
|
+
const result: ICapabilities = {
|
|
336
|
+
canEdit: isWriter,
|
|
337
|
+
canComment: isCommenter,
|
|
338
|
+
// This is open to discussion. Technically sharing is writing to a file resource.
|
|
339
|
+
// However, should we allow to share the file by a user that has read access?
|
|
340
|
+
canShare: isWriter,
|
|
341
|
+
// not yet supported in the store
|
|
342
|
+
canCopy: false,
|
|
343
|
+
// not yet supported in the store. Currently the user can read revisions when they have read access to the file.
|
|
344
|
+
canReadRevisions: isReader,
|
|
345
|
+
canAddChildren: false,
|
|
346
|
+
// debatable, can writer permanently delete a file?
|
|
347
|
+
canDelete: isOwner,
|
|
348
|
+
canListChildren: false,
|
|
349
|
+
canRename: isWriter,
|
|
350
|
+
// debatable, can writer trash a file?
|
|
351
|
+
canTrash: isOwner,
|
|
352
|
+
canUntrash: isOwner,
|
|
353
|
+
canReadMedia: false,
|
|
354
|
+
};
|
|
355
|
+
// Do not use the `WorkspaceKind` reference here as it's circular and creates
|
|
356
|
+
// an error.
|
|
357
|
+
if (file.kind === 'Core#Space' && isWriter) {
|
|
358
|
+
result.canAddChildren = true;
|
|
359
|
+
}
|
|
360
|
+
if (file.kind === 'Core#Space') {
|
|
361
|
+
result.canListChildren = isReader;
|
|
362
|
+
}
|
|
363
|
+
if (file.kind !== 'Core#Space') {
|
|
364
|
+
result.canReadMedia = isReader;
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
createFileCapabilities(role: PermissionRole): ICapabilities {
|
|
370
|
+
return File.createFileCapabilities(this, role);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Mutates the file object by setting the `byMe` properties (on deleted and modified info)
|
|
375
|
+
*
|
|
376
|
+
* Note, this can be done only on file schema (IFile). The `File` object has
|
|
377
|
+
* this properties frozen.
|
|
378
|
+
*
|
|
379
|
+
* @param file The file to mutate
|
|
380
|
+
* @param user The user key to compare.
|
|
381
|
+
*/
|
|
382
|
+
static updateByMeMeta(file: IFile, user: string): void {
|
|
383
|
+
if (file.deletedInfo) {
|
|
384
|
+
file.deletedInfo.byMe = file.deletedInfo.user === user;
|
|
385
|
+
}
|
|
386
|
+
if (file.lastModified) {
|
|
387
|
+
file.lastModified.byMe = file.lastModified.user === user;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
245
390
|
}
|
|
246
391
|
|
|
247
392
|
export class File extends StoredFile {
|
|
393
|
+
[permissionsSymbol]: ReadonlyArray<IPermission> = [];
|
|
394
|
+
|
|
248
395
|
/**
|
|
249
396
|
* Populated by the server when reading the file. The list of permissions to the object.
|
|
250
397
|
*
|
|
251
398
|
* This property cannot be manipulated directly by the client. Should be treated as
|
|
252
399
|
* opaque value.
|
|
253
400
|
*/
|
|
254
|
-
permissions: IPermission
|
|
401
|
+
get permissions(): ReadonlyArray<IPermission> {
|
|
402
|
+
return this[permissionsSymbol];
|
|
403
|
+
}
|
|
255
404
|
|
|
256
405
|
new(init: IFile): void {
|
|
257
406
|
super.new(init);
|
|
258
407
|
const { permissions=[] } = init;
|
|
259
|
-
this
|
|
408
|
+
this[permissionsSymbol] = permissions.map(i => ({ ...i }));
|
|
260
409
|
}
|
|
261
410
|
|
|
262
411
|
toJSON(): IFile {
|
|
263
412
|
const result: IFile = {
|
|
264
413
|
...super.toJSON(),
|
|
265
|
-
permissions: this.permissions,
|
|
414
|
+
permissions: [...this.permissions],
|
|
266
415
|
};
|
|
267
416
|
return result;
|
|
268
417
|
}
|
|
@@ -4,6 +4,7 @@ export const Kind = 'Core#Permission';
|
|
|
4
4
|
|
|
5
5
|
export type PermissionType = 'user' | 'group' | 'anyone';
|
|
6
6
|
export type PermissionRole = 'owner' | 'reader' | 'commenter' | 'writer';
|
|
7
|
+
const orderedRoles: PermissionRole[] = ["reader", "commenter", "writer", "owner"];
|
|
7
8
|
|
|
8
9
|
interface IBasePermission {
|
|
9
10
|
/**
|
|
@@ -47,7 +48,6 @@ interface IBasePermission {
|
|
|
47
48
|
* The store id of the user that added this permission.
|
|
48
49
|
*/
|
|
49
50
|
addingUser: string;
|
|
50
|
-
|
|
51
51
|
/**
|
|
52
52
|
* Whether the permission object is deleted.
|
|
53
53
|
*/
|
|
@@ -65,7 +65,7 @@ interface IBasePermission {
|
|
|
65
65
|
/**
|
|
66
66
|
* A schema describing a permission to a store object.
|
|
67
67
|
*/
|
|
68
|
-
export interface IPermission extends IBasePermission{
|
|
68
|
+
export interface IPermission extends IBasePermission {
|
|
69
69
|
kind: typeof Kind;
|
|
70
70
|
/**
|
|
71
71
|
* The data store key of the permission.
|
|
@@ -142,6 +142,7 @@ export class Permission {
|
|
|
142
142
|
*
|
|
143
143
|
* @param role The user role to set.
|
|
144
144
|
* @param user The user id that has the role.
|
|
145
|
+
* @param addingUser The key of the user that created this permission
|
|
145
146
|
*/
|
|
146
147
|
static fromUserRole(role: PermissionRole, user: string, addingUser: string): Permission {
|
|
147
148
|
const init: IPermission = {
|
|
@@ -160,6 +161,7 @@ export class Permission {
|
|
|
160
161
|
*
|
|
161
162
|
* @param role The group role to set.
|
|
162
163
|
* @param group The group id that has the role.
|
|
164
|
+
* @param addingUser The key of the user that created this permission
|
|
163
165
|
*/
|
|
164
166
|
static fromGroupRole(role: PermissionRole, group: string, addingUser: string): Permission {
|
|
165
167
|
const init: IPermission = {
|
|
@@ -177,7 +179,7 @@ export class Permission {
|
|
|
177
179
|
* Creates a Permission object for a group.
|
|
178
180
|
*
|
|
179
181
|
* @param role The group role to set.
|
|
180
|
-
* @param
|
|
182
|
+
* @param addingUser The key of the user that created this permission
|
|
181
183
|
*/
|
|
182
184
|
static fromAnyoneRole(role: PermissionRole, addingUser: string): Permission {
|
|
183
185
|
const init: IPermission = {
|
|
@@ -268,6 +270,31 @@ export class Permission {
|
|
|
268
270
|
return true;
|
|
269
271
|
}
|
|
270
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Checks whether the current user role meets the minimum required role.
|
|
275
|
+
*
|
|
276
|
+
* @param minimumLevel The minimum requested role
|
|
277
|
+
* @param currentRole The user role. When not set it always returns false.
|
|
278
|
+
* @returns True if the `currentRole` is at least the `minimumRole`
|
|
279
|
+
*/
|
|
280
|
+
static hasRole(minimumLevel: PermissionRole, currentRole?: PermissionRole): boolean {
|
|
281
|
+
if (!currentRole) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
const currentAccessIndex = orderedRoles.indexOf(currentRole);
|
|
285
|
+
const requestedAccessIndex = orderedRoles.indexOf(minimumLevel);
|
|
286
|
+
// the current must be at least at the index of requested.
|
|
287
|
+
return currentAccessIndex >= requestedAccessIndex;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Link to the `Permission.hasRole(minimumLevel, currentRole)`.
|
|
292
|
+
* @see {@link Permission.hasRole}
|
|
293
|
+
*/
|
|
294
|
+
hasRole(minimumLevel: PermissionRole, currentRole: PermissionRole): boolean {
|
|
295
|
+
return Permission.hasRole(minimumLevel, currentRole);
|
|
296
|
+
}
|
|
297
|
+
|
|
271
298
|
toJSON(): IPermission {
|
|
272
299
|
const result: IPermission = {
|
|
273
300
|
kind: Kind,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IModification } from './
|
|
1
|
+
import { IModification } from './Modification.js';
|
|
2
2
|
|
|
3
3
|
export const Kind = 'Core#Revision';
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ export const Kind = 'Core#Revision';
|
|
|
6
6
|
* The definition of a patch revision.
|
|
7
7
|
* The revision is created with the `@api-client/json` library.
|
|
8
8
|
*/
|
|
9
|
-
export interface
|
|
9
|
+
export interface IRevision {
|
|
10
10
|
/**
|
|
11
11
|
* The datastore key for this patch object.
|
|
12
12
|
*/
|
|
@@ -148,6 +148,44 @@ export class FilesSdk extends SdkBase {
|
|
|
148
148
|
return data;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Reads a number of files in a bulk operation.
|
|
153
|
+
*
|
|
154
|
+
* @param keys The list of keys to read. When the user has no access to the file it returns undefined
|
|
155
|
+
* in that place. It also inserts `undefined` in place of a file that doesn't exist.
|
|
156
|
+
* @param request Optional request options.
|
|
157
|
+
*/
|
|
158
|
+
async readBulk(keys: string[], request: ISdkRequestOptions = {}): Promise<IListResponse<IFile|undefined>> {
|
|
159
|
+
const token = request.token || this.sdk.token;
|
|
160
|
+
const url = this.sdk.getUrl(RouteBuilder.filesBulk());
|
|
161
|
+
const body = JSON.stringify(keys);
|
|
162
|
+
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
163
|
+
this.inspectCommonStatusCodes(result.status, result.body);
|
|
164
|
+
const E_PREFIX = 'Unable to read files in bulk. ';
|
|
165
|
+
if (result.status !== 200) {
|
|
166
|
+
this.logInvalidResponse(result);
|
|
167
|
+
let e = this.createGenericSdkError(result.body)
|
|
168
|
+
if (!e) {
|
|
169
|
+
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
170
|
+
e.response = result.body;
|
|
171
|
+
}
|
|
172
|
+
throw e;
|
|
173
|
+
}
|
|
174
|
+
if (!result.body) {
|
|
175
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
176
|
+
}
|
|
177
|
+
let data: IListResponse<IFile | undefined>;
|
|
178
|
+
try {
|
|
179
|
+
data = JSON.parse(result.body);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
182
|
+
}
|
|
183
|
+
if (!Array.isArray(data.data)) {
|
|
184
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
185
|
+
}
|
|
186
|
+
return data;
|
|
187
|
+
}
|
|
188
|
+
|
|
151
189
|
/**
|
|
152
190
|
* Patches file's meta in the store.
|
|
153
191
|
*
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RevisionInfo.js","sourceRoot":"","sources":["../../../src/models/RevisionInfo.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,IAAI,GAAG,eAAe,CAAC"}
|