@api-client/core 0.9.10 → 0.9.12
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 +1 -1
- package/build/browser.js +1 -0
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/src/events/BaseEvents.d.ts +5 -1
- package/build/src/models/TrashEntry.d.ts +19 -0
- package/build/src/runtime/store/FilesSdk.d.ts +20 -0
- package/build/src/runtime/store/FilesSdk.js +47 -1
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +5 -2
- package/build/src/runtime/store/RouteBuilder.js +14 -4
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/SdkBase.d.ts +18 -0
- package/build/src/runtime/store/SdkBase.js +59 -0
- package/build/src/runtime/store/SdkBase.js.map +1 -1
- package/build/src/runtime/store/SpacesSdk.d.ts +26 -1
- package/build/src/runtime/store/SpacesSdk.js +67 -0
- package/build/src/runtime/store/SpacesSdk.js.map +1 -1
- package/build/src/runtime/store/TrashSdk.d.ts +12 -2
- package/build/src/runtime/store/TrashSdk.js +47 -16
- package/build/src/runtime/store/TrashSdk.js.map +1 -1
- package/build/src/runtime/store/interfaces/Trash.d.ts +17 -5
- package/package.json +1 -1
- package/src/events/BaseEvents.ts +5 -1
- package/src/models/TrashEntry.ts +20 -0
- package/src/runtime/store/FilesSdk.ts +61 -2
- package/src/runtime/store/RouteBuilder.ts +17 -4
- package/src/runtime/store/SdkBase.ts +65 -0
- package/src/runtime/store/SpacesSdk.ts +72 -1
- package/src/runtime/store/TrashSdk.ts +63 -18
- package/src/runtime/store/interfaces/Trash.ts +20 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpacesSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/SpacesSdk.ts"],"names":[],"mappings":"AAAA,OAAO,E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GAAqB;YAC9B,KAAK,EAAE,CAAC,EAAE,CAAC;YACX,EAAE,EAAE,IAAI,EAAE;SACX,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,KAAa,EAAE,YAAoB,EAAE,OAA4B;QAChF,MAAM,EAAE,GAA2B;YACjC,EAAE,EAAE,QAAQ;YACZ,IAAI,EAAE,MAAM;YACZ,EAAE,EAAE,YAAY;SACjB,CAAC;QACF,MAAM,KAAK,GAAqB;YAC9B,KAAK,EAAE,CAAC,EAAE,CAAC;YACX,EAAE,EAAE,IAAI,EAAE;SACX,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SdkBase, ISdkRequestOptions } from './SdkBase.js';
|
|
2
|
-
import { ContextChangeRecord, ContextListResult, ContextSpaceListOptions } from '../../events/BaseEvents.js';
|
|
2
|
+
import { ContextChangeRecord, ContextDeleteRecord, ContextListResult, ContextSpaceListOptions, IBulkOperationResult } from '../../events/BaseEvents.js';
|
|
3
3
|
import { IFile } from '../../models/store/File.js';
|
|
4
4
|
import { TrashEntry, TrashEntryCreate } from '../../models/TrashEntry.js';
|
|
5
5
|
export declare class TrashSdk extends SdkBase {
|
|
@@ -16,10 +16,19 @@ export declare class TrashSdk extends SdkBase {
|
|
|
16
16
|
*/
|
|
17
17
|
list(options: ContextSpaceListOptions, request?: ISdkRequestOptions): Promise<ContextListResult<TrashEntry>>;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Permanently deletes a file.
|
|
20
|
+
*
|
|
20
21
|
* @param key The key of the deleted object
|
|
21
22
|
*/
|
|
22
23
|
delete(key: string, request?: ISdkRequestOptions): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Permanently deletes a number of files in a batch operation.
|
|
26
|
+
*
|
|
27
|
+
* @param keys The list of trash entry keys to delete.
|
|
28
|
+
* @param request Optional request options.
|
|
29
|
+
* @returns The list of delete records.
|
|
30
|
+
*/
|
|
31
|
+
batchDelete(keys: string[], request?: ISdkRequestOptions): Promise<IBulkOperationResult<ContextDeleteRecord>>;
|
|
23
32
|
/**
|
|
24
33
|
* Restores a file from the trash.
|
|
25
34
|
* It deletes a trash entry and updates the `file` object.
|
|
@@ -27,6 +36,7 @@ export declare class TrashSdk extends SdkBase {
|
|
|
27
36
|
* @param key The key of the file to restore
|
|
28
37
|
*/
|
|
29
38
|
restore(key: string, request?: ISdkRequestOptions): Promise<ContextChangeRecord<IFile>>;
|
|
39
|
+
batchRestore(keys: string[], request?: ISdkRequestOptions): Promise<IBulkOperationResult<ContextChangeRecord<IFile>>>;
|
|
30
40
|
/**
|
|
31
41
|
* Empties the trash for the given space.
|
|
32
42
|
* @param space The space key to remove trash for.
|
|
@@ -76,24 +76,25 @@ export class TrashSdk extends SdkBase {
|
|
|
76
76
|
return data;
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
*
|
|
79
|
+
* Permanently deletes a file.
|
|
80
|
+
*
|
|
80
81
|
* @param key The key of the deleted object
|
|
81
82
|
*/
|
|
82
83
|
async delete(key, request = {}) {
|
|
83
|
-
const token = request.token || this.sdk.token;
|
|
84
84
|
const url = this.sdk.getUrl(RouteBuilder.trashItem(key));
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
return this.genericDelete(url, key, request);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Permanently deletes a number of files in a batch operation.
|
|
89
|
+
*
|
|
90
|
+
* @param keys The list of trash entry keys to delete.
|
|
91
|
+
* @param request Optional request options.
|
|
92
|
+
* @returns The list of delete records.
|
|
93
|
+
*/
|
|
94
|
+
async batchDelete(keys, request = {}) {
|
|
95
|
+
const path = RouteBuilder.trashBatchDelete();
|
|
96
|
+
const url = this.sdk.getUrl(path);
|
|
97
|
+
return this.genericBatchDelete(url, keys, request);
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
100
|
* Restores a file from the trash.
|
|
@@ -102,12 +103,12 @@ export class TrashSdk extends SdkBase {
|
|
|
102
103
|
* @param key The key of the file to restore
|
|
103
104
|
*/
|
|
104
105
|
async restore(key, request = {}) {
|
|
105
|
-
const token = request.token || this.sdk.token;
|
|
106
106
|
const url = this.sdk.getUrl(RouteBuilder.trashRestore(key));
|
|
107
|
+
const token = request.token || this.sdk.token;
|
|
107
108
|
const result = await this.sdk.http.put(url.toString(), { token });
|
|
108
109
|
this.inspectCommonStatusCodes(result);
|
|
109
110
|
const E_PREFIX = 'Unable to restore from trash. ';
|
|
110
|
-
if (result.status !==
|
|
111
|
+
if (result.status !== 200) {
|
|
111
112
|
this.logInvalidResponse(result);
|
|
112
113
|
let e = this.createGenericSdkError(result.body);
|
|
113
114
|
if (!e) {
|
|
@@ -131,6 +132,36 @@ export class TrashSdk extends SdkBase {
|
|
|
131
132
|
}
|
|
132
133
|
return data;
|
|
133
134
|
}
|
|
135
|
+
async batchRestore(keys, request = {}) {
|
|
136
|
+
const url = this.sdk.getUrl(RouteBuilder.trashBatchRestore());
|
|
137
|
+
const token = request.token || this.sdk.token;
|
|
138
|
+
const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(keys) });
|
|
139
|
+
this.inspectCommonStatusCodes(result);
|
|
140
|
+
const E_PREFIX = 'Unable to restore from trash. ';
|
|
141
|
+
if (result.status !== 200) {
|
|
142
|
+
this.logInvalidResponse(result);
|
|
143
|
+
let e = this.createGenericSdkError(result.body);
|
|
144
|
+
if (!e) {
|
|
145
|
+
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
146
|
+
e.response = result.body;
|
|
147
|
+
}
|
|
148
|
+
throw e;
|
|
149
|
+
}
|
|
150
|
+
if (!result.body) {
|
|
151
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
152
|
+
}
|
|
153
|
+
let data;
|
|
154
|
+
try {
|
|
155
|
+
data = JSON.parse(result.body);
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
159
|
+
}
|
|
160
|
+
if (!Array.isArray(data.items)) {
|
|
161
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
162
|
+
}
|
|
163
|
+
return data;
|
|
164
|
+
}
|
|
134
165
|
/**
|
|
135
166
|
* Empties the trash for the given space.
|
|
136
167
|
* @param space The space key to remove trash for.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TrashSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TrashSdk.js","sourceRoot":"","sources":["../../../../src/runtime/store/TrashSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAEnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAQjD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC,MAAM,OAAO,QAAS,SAAQ,OAAO;IACnC;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAC,KAAuB,EAAE,KAAa,EAAE,UAA8B,EAAE;QAChF,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,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AK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,GAAG,kBAAkB,GAAG,CAAC,CAAC;SACtD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK,CAAC,KAAa,EAAE,UAA8B,EAAE;QACzD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACrE,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,QAAQ,GAAG,yBAAyB,CAAC;QAC3C,IAAI,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE;YACzB,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;YAChC,IAAI,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;YAC/C,IAAI,CAAC,CAAC,EAAE;gBACN,CAAC,GAAG,IAAI,QAAQ,CAAC,GAAG,QAAQ,GAAG,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;gBACnF,CAAC,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC;aAC1B;YACD,MAAM,CAAC,CAAC;SACT;IACH,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IFile } from "../../../models/store/File.js";
|
|
2
|
-
import { ContextChangeRecord, ContextListResult, ContextSpaceListOptions } from "../../../events/BaseEvents.js";
|
|
2
|
+
import { ContextChangeRecord, ContextDeleteRecord, ContextListResult, ContextSpaceListOptions, IBulkOperationResult } from "../../../events/BaseEvents.js";
|
|
3
3
|
import { TrashEntry, TrashEntryCreate } from "../../../models/TrashEntry.js";
|
|
4
4
|
/**
|
|
5
5
|
* A store for the file trash.
|
|
@@ -19,17 +19,29 @@ export interface Trash {
|
|
|
19
19
|
*/
|
|
20
20
|
list(options: ContextSpaceListOptions): Promise<ContextListResult<TrashEntry>>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Permanently deletes a file.
|
|
23
|
+
*
|
|
23
24
|
* @param key The key of the deleted object
|
|
24
25
|
*/
|
|
25
|
-
delete(key: string): Promise<
|
|
26
|
+
delete(key: string): Promise<ContextDeleteRecord>;
|
|
27
|
+
/**
|
|
28
|
+
* Permanently deletes a number of files in a batch operation.
|
|
29
|
+
*
|
|
30
|
+
* @param keys The list of trash entry keys to delete.
|
|
31
|
+
*/
|
|
32
|
+
batchDelete(keys: string[]): Promise<IBulkOperationResult<ContextDeleteRecord>>;
|
|
26
33
|
/**
|
|
27
|
-
* Restores
|
|
28
|
-
* It deletes a trash entry and updates the `file` object.
|
|
34
|
+
* Restores trash entries permanently from the store.
|
|
29
35
|
*
|
|
30
36
|
* @param key The key of the file to restore
|
|
31
37
|
*/
|
|
32
38
|
restore(key: string): Promise<ContextChangeRecord<IFile>>;
|
|
39
|
+
/**
|
|
40
|
+
* Restores multiple files in a batch operation.
|
|
41
|
+
*
|
|
42
|
+
* @param keys The lit of trash keys to restore.
|
|
43
|
+
*/
|
|
44
|
+
batchRestore(keys: string[]): Promise<IBulkOperationResult<ContextChangeRecord<IFile>>>;
|
|
33
45
|
/**
|
|
34
46
|
* Empties the trash for the given space.
|
|
35
47
|
* @param space The space key to remove trash for.
|
package/package.json
CHANGED
package/src/events/BaseEvents.ts
CHANGED
|
@@ -563,7 +563,11 @@ export interface IPatchInfo extends IPatchBase {
|
|
|
563
563
|
* An interface describing a schema to be sent to the server
|
|
564
564
|
* when making a patch with user access to a file.
|
|
565
565
|
*/
|
|
566
|
-
export interface IAccessPatchInfo
|
|
566
|
+
export interface IAccessPatchInfo {
|
|
567
|
+
/**
|
|
568
|
+
* Auto generated by the client sending the PATCH.
|
|
569
|
+
*/
|
|
570
|
+
id: string;
|
|
567
571
|
/**
|
|
568
572
|
* The patch generated by the client.
|
|
569
573
|
*/
|
package/src/models/TrashEntry.ts
CHANGED
|
@@ -17,6 +17,22 @@ export interface TrashEntryCreate {
|
|
|
17
17
|
name: string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The trash entry object capabilities for the current user.
|
|
22
|
+
* Note, this information has no effect on the backend and only tells the client application
|
|
23
|
+
* what operations on the file are permitted.
|
|
24
|
+
*/
|
|
25
|
+
export interface TrashCapabilities {
|
|
26
|
+
/**
|
|
27
|
+
* Whether the current user can restore the file.
|
|
28
|
+
*/
|
|
29
|
+
canRestore: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the current user can permanently delete the file.
|
|
32
|
+
*/
|
|
33
|
+
canDelete: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
20
36
|
export interface TrashEntry extends TrashEntryCreate {
|
|
21
37
|
/**
|
|
22
38
|
* The key of the trash entry.
|
|
@@ -26,4 +42,8 @@ export interface TrashEntry extends TrashEntryCreate {
|
|
|
26
42
|
* The delete info.
|
|
27
43
|
*/
|
|
28
44
|
info: IDeletion;
|
|
45
|
+
/**
|
|
46
|
+
* Trash entry capabilities for the user.
|
|
47
|
+
*/
|
|
48
|
+
capabilities: TrashCapabilities;
|
|
29
49
|
}
|
|
@@ -7,7 +7,19 @@ import { Kind as ProjectKind } from '../../models/Project.js';
|
|
|
7
7
|
import { Kind as FolderKind } from '../../models/Folder.js';
|
|
8
8
|
import { Kind as DataNamespaceKind } from '../../models/data/DataNamespace.js';
|
|
9
9
|
import { SdkError } from './Errors.js';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ContextListResult,
|
|
12
|
+
IPatchInfo,
|
|
13
|
+
IPatchRevision,
|
|
14
|
+
IAccessPatchInfo,
|
|
15
|
+
ContextChangeRecord,
|
|
16
|
+
IBulkOperationResult,
|
|
17
|
+
ContextListOptions,
|
|
18
|
+
} from '../../events/BaseEvents.js';
|
|
19
|
+
import {
|
|
20
|
+
IAccessAddOperation, IAccessRemoveOperation, PermissionRole
|
|
21
|
+
} from '../..//models/store/Permission.js';
|
|
22
|
+
import uuid from '../../lib/uuid.js';
|
|
11
23
|
|
|
12
24
|
export interface IMetaCreateOptions {
|
|
13
25
|
/**
|
|
@@ -374,6 +386,7 @@ export class FilesSdk extends SdkBase {
|
|
|
374
386
|
/**
|
|
375
387
|
* Updates the sharing options of the file.
|
|
376
388
|
*
|
|
389
|
+
* @param space The parent space key
|
|
377
390
|
* @param key The file key
|
|
378
391
|
* @param value The patch operation on the file's ACL
|
|
379
392
|
* @param request Optional request options.
|
|
@@ -385,7 +398,7 @@ export class FilesSdk extends SdkBase {
|
|
|
385
398
|
const body = JSON.stringify(value);
|
|
386
399
|
const result = await this.sdk.http.patch(url.toString(), { token, body });
|
|
387
400
|
this.inspectCommonStatusCodes(result);
|
|
388
|
-
const E_PREFIX = 'Unable to patch
|
|
401
|
+
const E_PREFIX = 'Unable to patch the file. ';
|
|
389
402
|
if (result.status !== 204) {
|
|
390
403
|
this.logInvalidResponse(result);
|
|
391
404
|
let e = this.createGenericSdkError(result.body)
|
|
@@ -397,6 +410,52 @@ export class FilesSdk extends SdkBase {
|
|
|
397
410
|
}
|
|
398
411
|
}
|
|
399
412
|
|
|
413
|
+
/**
|
|
414
|
+
* A shorthand method to add access to the file to a single user.
|
|
415
|
+
*
|
|
416
|
+
* @param space The parent space key
|
|
417
|
+
* @param key The file key
|
|
418
|
+
* @param otherUserKey The key of the user that gets access to the space
|
|
419
|
+
* @param role The user role to grant
|
|
420
|
+
* @param expires Optionally, when the permission expires.
|
|
421
|
+
*/
|
|
422
|
+
async addUser(space: string, key: string, otherUserKey: string, role: PermissionRole, expires?: number, request?: ISdkRequestOptions): Promise<void> {
|
|
423
|
+
const op: IAccessAddOperation = {
|
|
424
|
+
op: 'add',
|
|
425
|
+
type: 'user',
|
|
426
|
+
value: role,
|
|
427
|
+
id: otherUserKey,
|
|
428
|
+
};
|
|
429
|
+
if (typeof expires === 'number') {
|
|
430
|
+
op.expirationTime = expires;
|
|
431
|
+
}
|
|
432
|
+
const patch: IAccessPatchInfo = {
|
|
433
|
+
patch: [op],
|
|
434
|
+
id: uuid(),
|
|
435
|
+
};
|
|
436
|
+
return this.patchUsers(space, key, patch, request);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* A shorthand method to remove access to the space to a single user.
|
|
441
|
+
*
|
|
442
|
+
* @param space The space key to share
|
|
443
|
+
* @param key The file key
|
|
444
|
+
* @param otherUserKey The key of the user that gets access to the space
|
|
445
|
+
*/
|
|
446
|
+
async removeUser(space: string, key: string, otherUserKey: string, request?: ISdkRequestOptions): Promise<void> {
|
|
447
|
+
const op: IAccessRemoveOperation = {
|
|
448
|
+
op: 'remove',
|
|
449
|
+
type: 'user',
|
|
450
|
+
id: otherUserKey,
|
|
451
|
+
};
|
|
452
|
+
const patch: IAccessPatchInfo = {
|
|
453
|
+
patch: [op],
|
|
454
|
+
id: uuid(),
|
|
455
|
+
};
|
|
456
|
+
return this.patchUsers(space, key, patch, request);
|
|
457
|
+
}
|
|
458
|
+
|
|
400
459
|
/**
|
|
401
460
|
* Lists uses having access to the file.
|
|
402
461
|
*
|
|
@@ -10,6 +10,10 @@ export class RouteBuilder {
|
|
|
10
10
|
return `/spaces/${key}`;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
static spaceUsers(key: string): string {
|
|
14
|
+
return `/spaces/${key}/users`;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
18
|
* @returns The path to the /files route.
|
|
15
19
|
*/
|
|
@@ -127,15 +131,24 @@ export class RouteBuilder {
|
|
|
127
131
|
return `/trash`
|
|
128
132
|
}
|
|
129
133
|
|
|
130
|
-
static trashItem(
|
|
131
|
-
|
|
134
|
+
static trashItem(trashKey: string): string {
|
|
135
|
+
// GET + DELETE (link to ./delete)
|
|
136
|
+
return `/trash/${trashKey}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static trashRestore(trashKey: string): string {
|
|
140
|
+
return `/trash/${trashKey}/restore`
|
|
132
141
|
}
|
|
133
142
|
|
|
134
143
|
static trashEmpty(space: string): string {
|
|
135
144
|
return `/trash/empty/${space}`
|
|
136
145
|
}
|
|
137
146
|
|
|
138
|
-
static
|
|
139
|
-
return `/trash/restore
|
|
147
|
+
static trashBatchRestore(): string {
|
|
148
|
+
return `/trash/batch/restore`
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static trashBatchDelete(): string {
|
|
152
|
+
return `/trash/batch/delete`;
|
|
140
153
|
}
|
|
141
154
|
}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import { Headers } from '../../lib/headers/Headers.js';
|
|
3
3
|
import { Sdk } from './Sdk.js';
|
|
4
4
|
import { SdkError, IApiError } from './Errors.js';
|
|
5
|
+
import {
|
|
6
|
+
ContextDeleteRecord,
|
|
7
|
+
IBulkOperationResult
|
|
8
|
+
} from '../../events/BaseEvents.js';
|
|
5
9
|
|
|
6
10
|
export interface ISdkRequestOptions {
|
|
7
11
|
/**
|
|
@@ -125,4 +129,65 @@ export class SdkBase {
|
|
|
125
129
|
e.response = body;
|
|
126
130
|
return e;
|
|
127
131
|
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A generic (common) method to batch-delete object from the store.
|
|
135
|
+
*
|
|
136
|
+
* @param url The URL object to make the request.
|
|
137
|
+
* @param keys The list of keys to delete
|
|
138
|
+
* @param request Optional request options.
|
|
139
|
+
* @returns THe list of context delete records.
|
|
140
|
+
*/
|
|
141
|
+
protected async genericBatchDelete(url: URL, keys: string[], request: ISdkRequestOptions = {}): Promise<IBulkOperationResult<ContextDeleteRecord>> {
|
|
142
|
+
const token = request.token || this.sdk.token;
|
|
143
|
+
const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(keys) });
|
|
144
|
+
this.inspectCommonStatusCodes(result);
|
|
145
|
+
const E_PREFIX = 'Unable to delete in batch. ';
|
|
146
|
+
if (result.status !== 200) {
|
|
147
|
+
this.logInvalidResponse(result);
|
|
148
|
+
let e = this.createGenericSdkError(result.body)
|
|
149
|
+
if (!e) {
|
|
150
|
+
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
151
|
+
e.response = result.body;
|
|
152
|
+
}
|
|
153
|
+
throw e;
|
|
154
|
+
}
|
|
155
|
+
if (!result.body) {
|
|
156
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let data: IBulkOperationResult<ContextDeleteRecord>;
|
|
160
|
+
try {
|
|
161
|
+
data = JSON.parse(result.body);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
164
|
+
}
|
|
165
|
+
if (!Array.isArray(data.items)) {
|
|
166
|
+
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
167
|
+
}
|
|
168
|
+
return data;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Generic (common) function to delete an entity in the store.
|
|
173
|
+
*
|
|
174
|
+
* @param url The URL to make the DELETE request to.
|
|
175
|
+
* @param key The key of the entity to restore.
|
|
176
|
+
* @param request Optional request options.
|
|
177
|
+
*/
|
|
178
|
+
protected async genericDelete(url: URL, key: string, request: ISdkRequestOptions = {}): Promise<void> {
|
|
179
|
+
const token = request.token || this.sdk.token;
|
|
180
|
+
const result = await this.sdk.http.delete(url.toString(), { token });
|
|
181
|
+
this.inspectCommonStatusCodes(result);
|
|
182
|
+
const E_PREFIX = 'Unable to delete the object. ';
|
|
183
|
+
if (result.status !== 204) {
|
|
184
|
+
this.logInvalidResponse(result);
|
|
185
|
+
let e = this.createGenericSdkError(result.body)
|
|
186
|
+
if (!e) {
|
|
187
|
+
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
188
|
+
e.response = result.body;
|
|
189
|
+
}
|
|
190
|
+
throw e;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
128
193
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, ISdkRequestOptions } from './SdkBase.js';
|
|
2
2
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
-
import { ContextChangeRecord, ContextListOptions, ContextListResult } from '../../events/BaseEvents.js';
|
|
3
|
+
import { ContextChangeRecord, ContextListOptions, ContextListResult, IAccessPatchInfo } from '../../events/BaseEvents.js';
|
|
4
4
|
import { ISpace, Kind as SpaceKind } from '../../models/Space.js';
|
|
5
|
+
import { IAccessAddOperation, IAccessRemoveOperation, PermissionRole } from '../../models/store/Permission.js';
|
|
5
6
|
import { SdkError } from './Errors.js';
|
|
7
|
+
import uuid from '../../lib/uuid.js';
|
|
6
8
|
|
|
7
9
|
export class SpacesSdk extends SdkBase {
|
|
8
10
|
/**
|
|
@@ -133,4 +135,73 @@ export class SpacesSdk extends SdkBase {
|
|
|
133
135
|
throw e;
|
|
134
136
|
}
|
|
135
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Updates the sharing options of the space.
|
|
141
|
+
*
|
|
142
|
+
* @param key The space key
|
|
143
|
+
* @param value The patch operation on the space's ACL
|
|
144
|
+
* @param request Optional request options.
|
|
145
|
+
*/
|
|
146
|
+
async patchUsers(space: string, value: IAccessPatchInfo, request: ISdkRequestOptions = {}): Promise<void> {
|
|
147
|
+
const token = request.token || this.sdk.token;
|
|
148
|
+
const url = this.sdk.getUrl(RouteBuilder.spaceUsers(space));
|
|
149
|
+
const body = JSON.stringify(value);
|
|
150
|
+
const result = await this.sdk.http.patch(url.toString(), { token, body });
|
|
151
|
+
this.inspectCommonStatusCodes(result);
|
|
152
|
+
const E_PREFIX = 'Unable to patch the space. ';
|
|
153
|
+
if (result.status !== 204) {
|
|
154
|
+
this.logInvalidResponse(result);
|
|
155
|
+
let e = this.createGenericSdkError(result.body)
|
|
156
|
+
if (!e) {
|
|
157
|
+
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
158
|
+
e.response = result.body;
|
|
159
|
+
}
|
|
160
|
+
throw e;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A shorthand method to add access to the space to a single user.
|
|
166
|
+
*
|
|
167
|
+
* @param space The space key to share
|
|
168
|
+
* @param otherUserKey The key of the user that gets access to the space
|
|
169
|
+
* @param role The user role to grant
|
|
170
|
+
* @param expires Optionally, when the permission expires.
|
|
171
|
+
*/
|
|
172
|
+
async addUser(space: string, otherUserKey: string, role: PermissionRole, expires?: number, request?: ISdkRequestOptions): Promise<void> {
|
|
173
|
+
const op: IAccessAddOperation = {
|
|
174
|
+
op: 'add',
|
|
175
|
+
type: 'user',
|
|
176
|
+
value: role,
|
|
177
|
+
id: otherUserKey,
|
|
178
|
+
};
|
|
179
|
+
if (typeof expires === 'number') {
|
|
180
|
+
op.expirationTime = expires;
|
|
181
|
+
}
|
|
182
|
+
const patch: IAccessPatchInfo = {
|
|
183
|
+
patch: [op],
|
|
184
|
+
id: uuid(),
|
|
185
|
+
};
|
|
186
|
+
return this.patchUsers(space, patch, request);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* A shorthand method to remove access to the space to a single user.
|
|
191
|
+
*
|
|
192
|
+
* @param space The space key to share
|
|
193
|
+
* @param otherUserKey The key of the user that gets access to the space
|
|
194
|
+
*/
|
|
195
|
+
async removeUser(space: string, otherUserKey: string, request?: ISdkRequestOptions): Promise<void> {
|
|
196
|
+
const op: IAccessRemoveOperation = {
|
|
197
|
+
op: 'remove',
|
|
198
|
+
type: 'user',
|
|
199
|
+
id: otherUserKey,
|
|
200
|
+
};
|
|
201
|
+
const patch: IAccessPatchInfo = {
|
|
202
|
+
patch: [op],
|
|
203
|
+
id: uuid(),
|
|
204
|
+
};
|
|
205
|
+
return this.patchUsers(space, patch, request);
|
|
206
|
+
}
|
|
136
207
|
}
|