@api-client/core 0.5.3 → 0.5.6
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 -0
- package/build/browser.js +1 -0
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/src/models/Backend.d.ts +7 -9
- package/build/src/models/HttpHistory.d.ts +2 -2
- package/build/src/models/Project.d.ts +1 -1
- package/build/src/models/Project.js +2 -2
- package/build/src/models/Project.js.map +1 -1
- package/build/src/models/RevisionInfo.d.ts +2 -2
- package/build/src/models/SerializableError.d.ts +1 -0
- package/build/src/models/SerializableError.js.map +1 -1
- package/build/src/models/store/File.js +2 -2
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/runtime/store/Errors.d.ts +50 -0
- package/build/src/runtime/store/Errors.js +63 -0
- package/build/src/runtime/store/Errors.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.d.ts +94 -0
- package/build/src/runtime/store/FilesSdk.js +247 -0
- package/build/src/runtime/store/FilesSdk.js.map +1 -0
- package/build/src/runtime/store/HistorySdk.d.ts +14 -7
- package/build/src/runtime/store/HistorySdk.js +34 -12
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +9 -17
- package/build/src/runtime/store/RouteBuilder.js +14 -26
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/Sdk.d.ts +6 -7
- package/build/src/runtime/store/Sdk.js +6 -7
- package/build/src/runtime/store/Sdk.js.map +1 -1
- package/build/src/runtime/store/SdkBase.d.ts +16 -6
- package/build/src/runtime/store/SdkBase.js +54 -4
- package/build/src/runtime/store/SdkBase.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.d.ts +8 -2
- package/build/src/runtime/store/SharedSdk.js +22 -8
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/StoreSdkNode.d.ts +1 -1
- package/build/src/runtime/store/StoreSdkWeb.d.ts +1 -1
- package/build/src/runtime/store/UsersSdk.d.ts +10 -4
- package/build/src/runtime/store/UsersSdk.js +12 -6
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/package.json +3 -4
- package/src/models/Backend.ts +7 -9
- package/src/models/HttpHistory.ts +2 -2
- package/src/models/Project.ts +2 -2
- package/src/models/RevisionInfo.ts +2 -2
- package/src/models/SerializableError.ts +1 -0
- package/src/models/store/File.ts +2 -2
- package/src/runtime/store/Errors.ts +100 -0
- package/src/runtime/store/FilesSdk.ts +302 -0
- package/src/runtime/store/HistorySdk.ts +42 -17
- package/src/runtime/store/RouteBuilder.ts +14 -28
- package/src/runtime/store/Sdk.ts +7 -7
- package/src/runtime/store/SdkBase.ts +63 -9
- package/src/runtime/store/SharedSdk.ts +27 -10
- package/src/runtime/store/StoreSdkNode.ts +1 -1
- package/src/runtime/store/StoreSdkWeb.ts +1 -1
- package/src/runtime/store/UsersSdk.ts +14 -8
- package/build/src/runtime/store/ProjectsSdk.d.ts +0 -43
- package/build/src/runtime/store/ProjectsSdk.js +0 -144
- package/build/src/runtime/store/ProjectsSdk.js.map +0 -1
- package/build/src/runtime/store/SpacesSdk.d.ts +0 -62
- package/build/src/runtime/store/SpacesSdk.js +0 -194
- package/build/src/runtime/store/SpacesSdk.js.map +0 -1
- package/json8-patch.d.ts +0 -270
- package/src/runtime/store/ProjectsSdk.ts +0 -147
- package/src/runtime/store/SpacesSdk.ts +0 -209
package/json8-patch.d.ts
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
declare module "json8-patch" {
|
|
2
|
-
export interface BaseOperation {
|
|
3
|
-
path: string;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export interface AddOperation extends BaseOperation {
|
|
7
|
-
op: "add";
|
|
8
|
-
value: any;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface RemoveOperation extends BaseOperation {
|
|
12
|
-
op: "remove";
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The JSON patch replace operation
|
|
17
|
-
*/
|
|
18
|
-
export interface ReplaceOperation extends BaseOperation {
|
|
19
|
-
op: "replace";
|
|
20
|
-
value: any;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The JSON patch move operation
|
|
25
|
-
*/
|
|
26
|
-
export interface MoveOperation extends BaseOperation {
|
|
27
|
-
op: "move";
|
|
28
|
-
from: any;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The JSON patch copy operation.
|
|
33
|
-
*/
|
|
34
|
-
export interface CopyOperation extends BaseOperation {
|
|
35
|
-
op: "copy";
|
|
36
|
-
from: any;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* The JSON patch test operation
|
|
41
|
-
*/
|
|
42
|
-
export interface TestOperation extends BaseOperation {
|
|
43
|
-
op: "test";
|
|
44
|
-
value: any;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* All possible JSON patch operations
|
|
49
|
-
*/
|
|
50
|
-
export type JsonPatchOperation = AddOperation | RemoveOperation | ReplaceOperation | MoveOperation | CopyOperation | TestOperation;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A JSON patch as specified in RFC 6902
|
|
54
|
-
*/
|
|
55
|
-
export type JsonPatch = JsonPatchOperation[];
|
|
56
|
-
|
|
57
|
-
export interface ApplyResult<T> {
|
|
58
|
-
doc: T;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface ApplyResultWithRevert<T> extends ApplyResult<T> {
|
|
62
|
-
revert: JsonPatch;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type PatchResult<T> = ApplyResult<T>;
|
|
66
|
-
export type PatchResultWithRevert<T> = ApplyResultWithRevert<T>;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* The operation is atomic, if any of the patch operation fails, the document will be restored to its original state and an error will be thrown.
|
|
70
|
-
* @param doc The document to apply the patch operation to
|
|
71
|
-
* @param patch The patch operations
|
|
72
|
-
* @param options With `{reversible: false}` it will not return an additional value in the form of a `revert` property.
|
|
73
|
-
* @returns An object with a doc property because per specification a patch can replace the original root document.
|
|
74
|
-
*/
|
|
75
|
-
export function apply<T>(doc: T, patch: JsonPatch, options?: { reversible: false }): ApplyResult<T>;
|
|
76
|
-
/**
|
|
77
|
-
* The operation is atomic, if any of the patch operation fails, the document will be restored to its original state and an error will be thrown.
|
|
78
|
-
* @param doc The document to apply the patch operation to
|
|
79
|
-
* @param patch The patch operations
|
|
80
|
-
* @param options With `{reversible: true}` it will return an additional value in the form of a `revert` property.
|
|
81
|
-
* @returns An object with a doc property because per specification a patch can replace the original root document.
|
|
82
|
-
*/
|
|
83
|
-
export function apply<T>(doc: T, patch: JsonPatch, options?: { reversible: true }): ApplyResultWithRevert<T>;
|
|
84
|
-
/**
|
|
85
|
-
* Alias for the `apply()` method.
|
|
86
|
-
*/
|
|
87
|
-
export function patch<T>(doc: T, patch: JsonPatch, options?: { reversible: false }): PatchResult<T>;
|
|
88
|
-
/**
|
|
89
|
-
* Alias for the `apply()` method.
|
|
90
|
-
*/
|
|
91
|
-
export function patch<T>(doc: T, patch: JsonPatch, options?: { reversible: true }): PatchResultWithRevert<T>;
|
|
92
|
-
/**
|
|
93
|
-
* ```javascript
|
|
94
|
-
* ooPatch.diff(true, false);
|
|
95
|
-
* // [{"op": "replace", "path": "", "value": "false"}]
|
|
96
|
-
*
|
|
97
|
-
* ooPatch.diff([], []);
|
|
98
|
-
* // []
|
|
99
|
-
*
|
|
100
|
-
* ooPatch.diff({}, { foo: "bar" });
|
|
101
|
-
* // [{"op": "add", "path": "/foo", "value": "bar"}]
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
* @returns A diff in the form of a JSON Patch for 2 JSON values.
|
|
105
|
-
*/
|
|
106
|
-
export function diff(doc1: unknown, doc2: unknown): JsonPatch;
|
|
107
|
-
/**
|
|
108
|
-
* If the patch or apply method is called with a third argument `{reversible: true}` it will return an additional value in the form of a revert property.
|
|
109
|
-
*
|
|
110
|
-
* The revert object can be used to revert a patch on a document.
|
|
111
|
-
*
|
|
112
|
-
* ```javascript
|
|
113
|
-
* // apply the patch with the reversible option
|
|
114
|
-
* var applyResult = ooPatch.apply(doc, patch, { reversible: true });
|
|
115
|
-
* doc = applyResult.doc;
|
|
116
|
-
*
|
|
117
|
-
* // revert the patch
|
|
118
|
-
* doc = ooPatch.revert(doc, applyResult.revert).doc;
|
|
119
|
-
* // doc is strictly identical to the original
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* See also the `buildRevertPatch()` function which offers more flexibility.
|
|
123
|
-
*/
|
|
124
|
-
export function revert<T>(doc: T, revertPatch: JsonPatch): ApplyResult<T>;
|
|
125
|
-
/**
|
|
126
|
-
* This method only check for JSON Patch semantic.
|
|
127
|
-
*
|
|
128
|
-
* ```javascript
|
|
129
|
-
* ooPatch.valid({}) // false
|
|
130
|
-
* ooPatch.valid([{}] // false
|
|
131
|
-
* ooPatch.valid([{op: "foo", path: null, value: undefined}]) // false
|
|
132
|
-
* ooPatch.valid([{op: "add", path: "/foo"}]) // false
|
|
133
|
-
*
|
|
134
|
-
* ooPatch.valid([]) // true
|
|
135
|
-
* ooPatch.valid([{op: "add", path: "/foo", value: "bar"}]) // true
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
* @returns `true` if the patch is valid, `false` otherwise.
|
|
139
|
-
*/
|
|
140
|
-
export function valid(patch: JsonPatch): boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Builds a valid JSON Patch from the result of a reversible `apply` operation.
|
|
143
|
-
* You can then use this patch with `apply()` method to revert a previously applied patch.
|
|
144
|
-
*
|
|
145
|
-
* Because `buildRevertPatch` + `apply` offers more flexibility over `revert` it is preferred.
|
|
146
|
-
*
|
|
147
|
-
* - use pack/unpack with the result of `buildRevertPatch` making it ideal for storage or transport
|
|
148
|
-
* - reverse a revert (and so on...) with `{reversible: true}`
|
|
149
|
-
* - `diff` between reverts
|
|
150
|
-
* - merge multiple reverts into one
|
|
151
|
-
* - rebase reverts
|
|
152
|
-
*
|
|
153
|
-
* @param revert The revert value from the `apply()` or `patch()` method with `{reversible: true}`
|
|
154
|
-
* @returns JSON Patch
|
|
155
|
-
*/
|
|
156
|
-
export function buildRevertPatch(revert: JsonPatch): JsonPatch;
|
|
157
|
-
|
|
158
|
-
export interface OperationResult<T> {
|
|
159
|
-
/**
|
|
160
|
-
* The patched document
|
|
161
|
-
*/
|
|
162
|
-
doc: T;
|
|
163
|
-
/**
|
|
164
|
-
* The previous/replaced value if any
|
|
165
|
-
*/
|
|
166
|
-
previous?: T;
|
|
167
|
-
idx?: number;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Add the value to the specified JSON Pointer location.
|
|
172
|
-
* @param doc JSON document to set the value to
|
|
173
|
-
* @param path JSON Pointer string or tokens path
|
|
174
|
-
* @param value The value to add
|
|
175
|
-
*/
|
|
176
|
-
export function add<T>(doc: T, path: string | string[], value: unknown): OperationResult<T>;
|
|
177
|
-
/**
|
|
178
|
-
* Copy the value at the specified JSON Pointer location to another location.
|
|
179
|
-
*
|
|
180
|
-
* @param doc JSON document to copy the value from and to
|
|
181
|
-
* @param path JSON Pointer string or tokens path
|
|
182
|
-
* @param dest JSON Pointer string destination of the value
|
|
183
|
-
*/
|
|
184
|
-
export function copy<T>(doc: T, path: string | string[], dest: string): OperationResult<T>;
|
|
185
|
-
/**
|
|
186
|
-
* Moves the value at the specified JSON Pointer location to another location.
|
|
187
|
-
*
|
|
188
|
-
* @param doc JSON document to move the value from and to
|
|
189
|
-
* @param path JSON Pointer string or tokens path
|
|
190
|
-
* @param dest JSON Pointer string destination of the value
|
|
191
|
-
*/
|
|
192
|
-
export function move<T>(doc: T, path: string | string[], dest: string): OperationResult<T>;
|
|
193
|
-
/**
|
|
194
|
-
* Removes the value at the JSON Pointer location.
|
|
195
|
-
*
|
|
196
|
-
* @param doc JSON document to search into
|
|
197
|
-
* @param path JSON Pointer string or tokens patch
|
|
198
|
-
*/
|
|
199
|
-
export function remove<T>(doc: T, path: string | string[]): OperationResult<T>;
|
|
200
|
-
/**
|
|
201
|
-
* Replaces the value at the JSON Pointer location
|
|
202
|
-
*
|
|
203
|
-
* @param doc JSON document
|
|
204
|
-
* @param path JSON Pointer string or tokens patch
|
|
205
|
-
* @param value JSON object to replace with
|
|
206
|
-
*/
|
|
207
|
-
export function replace<T>(doc: T, path: string | string[], value: unknown): OperationResult<T>;
|
|
208
|
-
/**
|
|
209
|
-
* Tests that the value at the specified JSON Pointer location is equal to the specified value.
|
|
210
|
-
*
|
|
211
|
-
* @param doc JSON document
|
|
212
|
-
* @param path JSON Pointer string or tokens patch
|
|
213
|
-
* @param value The value to compare with
|
|
214
|
-
*/
|
|
215
|
-
export function test<T>(doc: T, path: string | string[], value: unknown): OperationResult<T>;
|
|
216
|
-
/**
|
|
217
|
-
* Get the value at the JSON Pointer location.
|
|
218
|
-
*
|
|
219
|
-
* @param doc JSON document
|
|
220
|
-
* @param path JSON Pointer string or tokens patch
|
|
221
|
-
* @returns The value at the JSON Pointer location
|
|
222
|
-
*/
|
|
223
|
-
export function get(doc: unknown, path: string | string[]): unknown;
|
|
224
|
-
/**
|
|
225
|
-
* Checks if the document has the property at the specified JSON Pointer location.
|
|
226
|
-
*
|
|
227
|
-
* @param doc JSON document
|
|
228
|
-
* @param path JSON Pointer string or tokens path
|
|
229
|
-
*/
|
|
230
|
-
export function has(doc: unknown, path: string | string[]): boolean;
|
|
231
|
-
/**
|
|
232
|
-
* Per specification patches are pretty verbose. JSON8 provides the `pack()` and the `unpack()` methods
|
|
233
|
-
* to reduce the size of patches and save memory / space / bandwidth.
|
|
234
|
-
*
|
|
235
|
-
* ```javascript
|
|
236
|
-
* var patch = [
|
|
237
|
-
* { op: "add", path: "/a/b/c", value: ["foo", "bar"] },
|
|
238
|
-
* { op: "remove", path: "/a/b/c" },
|
|
239
|
-
* { op: "replace", path: "/a/b/c", value: 42 },
|
|
240
|
-
* { op: "move", from: "/a/b/c", path: "/a/b/d" },
|
|
241
|
-
* { op: "copy", from: "/a/b/c", path: "/a/b/e" },
|
|
242
|
-
* { op: "test", path: "/a/b/c", value: "foo" },
|
|
243
|
-
* ];
|
|
244
|
-
*
|
|
245
|
-
* var packed = ooPatch.pack(patch);
|
|
246
|
-
*
|
|
247
|
-
* // [
|
|
248
|
-
* // [0, "/a/b/c", ["foo", "bar"]],
|
|
249
|
-
* // [1, "/a/b/c"],
|
|
250
|
-
* // [2, "/a/b/c", 42],
|
|
251
|
-
* // [3, "/a/b/d", "/a/b/c"],
|
|
252
|
-
* // [4, "/a/b/e", "/a/b/c"],
|
|
253
|
-
* // [5, "/a/b/c", "foo"]
|
|
254
|
-
* // ]
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
export function pack(patch: JsonPatch): any[];
|
|
258
|
-
/**
|
|
259
|
-
* Reverses the `pack()` on a patch.
|
|
260
|
-
*
|
|
261
|
-
* @param packed Previously packed values.
|
|
262
|
-
* @returns Restored patch value.
|
|
263
|
-
*/
|
|
264
|
-
export function unpack(packed: any[]): JsonPatch;
|
|
265
|
-
/**
|
|
266
|
-
* Concatenates multiple patches into one.
|
|
267
|
-
*/
|
|
268
|
-
export function concat(...patches: JsonPatch): JsonPatch;
|
|
269
|
-
|
|
270
|
-
}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { JsonPatch } from 'json8-patch';
|
|
2
|
-
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
|
|
3
|
-
import { RouteBuilder } from './RouteBuilder.js';
|
|
4
|
-
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
5
|
-
import { HttpProject, IHttpProject, Kind as HttpProjectKind } from '../../models/HttpProject.js';
|
|
6
|
-
|
|
7
|
-
export class ProjectsSdk extends SdkBase {
|
|
8
|
-
/**
|
|
9
|
-
* Creates a project in a user space.
|
|
10
|
-
*
|
|
11
|
-
* @param space The user space key
|
|
12
|
-
* @param project THe project to create
|
|
13
|
-
* @returns The key of the created project.
|
|
14
|
-
*/
|
|
15
|
-
async create(space: string, project: IHttpProject | HttpProject): Promise<string> {
|
|
16
|
-
const { token } = this.sdk;
|
|
17
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProjects(space));
|
|
18
|
-
const body = JSON.stringify(project);
|
|
19
|
-
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
20
|
-
this.inspectCommonStatusCodes(result.status);
|
|
21
|
-
const E_PREFIX = 'Unable to create a project. ';
|
|
22
|
-
if (result.status !== 204) {
|
|
23
|
-
this.logInvalidResponse(result);
|
|
24
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
25
|
-
}
|
|
26
|
-
const location = result.headers.get('location');
|
|
27
|
-
if (!location) {
|
|
28
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
|
|
29
|
-
}
|
|
30
|
-
const id = location.split('/').pop();
|
|
31
|
-
return id as string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Reads a project definition from the store.
|
|
36
|
-
* @param space The user space key
|
|
37
|
-
* @param project The project key
|
|
38
|
-
* @returns The definition of the project.
|
|
39
|
-
*/
|
|
40
|
-
async read(space: string, project: string): Promise<IHttpProject> {
|
|
41
|
-
const { token } = this.sdk;
|
|
42
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
43
|
-
const result = await this.sdk.http.get(url.toString(), { token });
|
|
44
|
-
this.inspectCommonStatusCodes(result.status);
|
|
45
|
-
const E_PREFIX = 'Unable to read a project. ';
|
|
46
|
-
if (result.status !== 200) {
|
|
47
|
-
this.logInvalidResponse(result);
|
|
48
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
49
|
-
}
|
|
50
|
-
if (!result.body) {
|
|
51
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
52
|
-
}
|
|
53
|
-
let data: IHttpProject;
|
|
54
|
-
try {
|
|
55
|
-
data = JSON.parse(result.body);
|
|
56
|
-
} catch (e) {
|
|
57
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
58
|
-
}
|
|
59
|
-
if (data.kind !== HttpProjectKind) {
|
|
60
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
61
|
-
}
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Lists projects in the space
|
|
67
|
-
*
|
|
68
|
-
* @param space The user space key
|
|
69
|
-
* @param options Optional query options.
|
|
70
|
-
*/
|
|
71
|
-
async list(space: string, options?: IListOptions): Promise<IListResponse> {
|
|
72
|
-
const { token } = this.sdk;
|
|
73
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProjects(space));
|
|
74
|
-
this.sdk.appendListOptions(url, options);
|
|
75
|
-
const result = await this.sdk.http.get(url.toString(), { token });
|
|
76
|
-
this.inspectCommonStatusCodes(result.status);
|
|
77
|
-
const E_PREFIX = 'Unable to list projects. ';
|
|
78
|
-
if (result.status !== 200) {
|
|
79
|
-
this.logInvalidResponse(result);
|
|
80
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
81
|
-
}
|
|
82
|
-
if (!result.body) {
|
|
83
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
84
|
-
}
|
|
85
|
-
let data: IListResponse;
|
|
86
|
-
try {
|
|
87
|
-
data = JSON.parse(result.body);
|
|
88
|
-
} catch (e) {
|
|
89
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
90
|
-
}
|
|
91
|
-
if (!Array.isArray(data.data)) {
|
|
92
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
93
|
-
}
|
|
94
|
-
return data;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Deletes a project form the store.
|
|
99
|
-
*
|
|
100
|
-
* @param space The key of the parent space.
|
|
101
|
-
* @param project The key of the project to delete.
|
|
102
|
-
*/
|
|
103
|
-
async delete(space: string, project: string): Promise<void> {
|
|
104
|
-
const { token } = this.sdk;
|
|
105
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
106
|
-
const result = await this.sdk.http.delete(url.toString(), { token });
|
|
107
|
-
this.inspectCommonStatusCodes(result.status);
|
|
108
|
-
const E_PREFIX = 'Unable to delete a project. ';
|
|
109
|
-
if (result.status !== 204) {
|
|
110
|
-
this.logInvalidResponse(result);
|
|
111
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Patches a project in the store.
|
|
117
|
-
* @param space The key of the parent user space
|
|
118
|
-
* @param project The key of project to patch.
|
|
119
|
-
* @param value The JSON patch to be processed.
|
|
120
|
-
* @returns The JSON patch to revert the change using the `json8-patch` library
|
|
121
|
-
*/
|
|
122
|
-
async patch(space: string, project: string, value: JsonPatch): Promise<JsonPatch> {
|
|
123
|
-
const { token } = this.sdk;
|
|
124
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
125
|
-
const body = JSON.stringify(value);
|
|
126
|
-
const result = await this.sdk.http.patch(url.toString(), { token, body });
|
|
127
|
-
this.inspectCommonStatusCodes(result.status);
|
|
128
|
-
const E_PREFIX = 'Unable to patch a project. ';
|
|
129
|
-
if (result.status !== 200) {
|
|
130
|
-
this.logInvalidResponse(result);
|
|
131
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
132
|
-
}
|
|
133
|
-
if (!result.body) {
|
|
134
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
135
|
-
}
|
|
136
|
-
let data: any;
|
|
137
|
-
try {
|
|
138
|
-
data = JSON.parse(result.body);
|
|
139
|
-
} catch (e) {
|
|
140
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
141
|
-
}
|
|
142
|
-
if (!data.revert) {
|
|
143
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
144
|
-
}
|
|
145
|
-
return data.revert as JsonPatch;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { JsonPatch } from 'json8-patch';
|
|
2
|
-
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
|
|
3
|
-
import { RouteBuilder } from './RouteBuilder.js';
|
|
4
|
-
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
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
|
-
}
|
|
16
|
-
|
|
17
|
-
export class SpacesSdk extends SdkBase {
|
|
18
|
-
/**
|
|
19
|
-
* Lists spaces in the store.
|
|
20
|
-
* @param options Optional query options.
|
|
21
|
-
*/
|
|
22
|
-
async list(options?: IListOptions): Promise<IListResponse> {
|
|
23
|
-
const { token } = this.sdk;
|
|
24
|
-
const url = this.sdk.getUrl(RouteBuilder.spaces());
|
|
25
|
-
this.sdk.appendListOptions(url, options);
|
|
26
|
-
const result = await this.sdk.http.get(url.toString(), { token });
|
|
27
|
-
this.inspectCommonStatusCodes(result.status);
|
|
28
|
-
const E_PREFIX = 'Unable to list spaces. ';
|
|
29
|
-
if (result.status !== 200) {
|
|
30
|
-
this.logInvalidResponse(result);
|
|
31
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
32
|
-
}
|
|
33
|
-
if (!result.body) {
|
|
34
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
35
|
-
}
|
|
36
|
-
let data: IListResponse;
|
|
37
|
-
try {
|
|
38
|
-
data = JSON.parse(result.body);
|
|
39
|
-
} catch (e) {
|
|
40
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
41
|
-
}
|
|
42
|
-
if (!Array.isArray(data.data)) {
|
|
43
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
44
|
-
}
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Creates a workspace in the store.
|
|
50
|
-
* @param space The workspace definition.
|
|
51
|
-
* @returns The key of the creates space.
|
|
52
|
-
*/
|
|
53
|
-
async create(space: IWorkspace | Workspace, opts: ISpaceCreateOptions = {}): Promise<string> {
|
|
54
|
-
const { token } = this.sdk;
|
|
55
|
-
const path = opts.parent ? RouteBuilder.space(opts.parent) : RouteBuilder.spaces();
|
|
56
|
-
const url = this.sdk.getUrl(path);
|
|
57
|
-
const body = JSON.stringify(space);
|
|
58
|
-
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
59
|
-
this.inspectCommonStatusCodes(result.status);
|
|
60
|
-
const E_PREFIX = 'Unable to create a user space. ';
|
|
61
|
-
if (result.status !== 204) {
|
|
62
|
-
this.logInvalidResponse(result);
|
|
63
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
64
|
-
}
|
|
65
|
-
const location = result.headers.get('location');
|
|
66
|
-
if (!location) {
|
|
67
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
|
|
68
|
-
}
|
|
69
|
-
const id = location.split('/').pop();
|
|
70
|
-
return id as string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Reads a user space definition from the store.
|
|
75
|
-
* @param key The user space key
|
|
76
|
-
* @returns The definition of the user space.
|
|
77
|
-
*/
|
|
78
|
-
async read(key: string): Promise<IWorkspace> {
|
|
79
|
-
const { token } = this.sdk;
|
|
80
|
-
const url = this.sdk.getUrl(RouteBuilder.space(key));
|
|
81
|
-
const result = await this.sdk.http.get(url.toString(), { token });
|
|
82
|
-
this.inspectCommonStatusCodes(result.status);
|
|
83
|
-
const E_PREFIX = 'Unable to read a user space. ';
|
|
84
|
-
if (result.status !== 200) {
|
|
85
|
-
this.logInvalidResponse(result);
|
|
86
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
87
|
-
}
|
|
88
|
-
if (!result.body) {
|
|
89
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
90
|
-
}
|
|
91
|
-
let data: IWorkspace;
|
|
92
|
-
try {
|
|
93
|
-
data = JSON.parse(result.body);
|
|
94
|
-
} catch (e) {
|
|
95
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
96
|
-
}
|
|
97
|
-
if (data.kind !== WorkspaceKind) {
|
|
98
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
99
|
-
}
|
|
100
|
-
return data;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Patches a user space in the store.
|
|
105
|
-
* @param key The key of the user space to patch
|
|
106
|
-
* @param value The JSON patch to be processed.
|
|
107
|
-
* @returns The JSON patch to revert the change using the `json8-patch` library
|
|
108
|
-
*/
|
|
109
|
-
async patch(key: string, value: JsonPatch): Promise<JsonPatch> {
|
|
110
|
-
const { token } = this.sdk;
|
|
111
|
-
const url = this.sdk.getUrl(RouteBuilder.space(key));
|
|
112
|
-
const body = JSON.stringify(value);
|
|
113
|
-
const result = await this.sdk.http.patch(url.toString(), { token, body });
|
|
114
|
-
this.inspectCommonStatusCodes(result.status);
|
|
115
|
-
const E_PREFIX = 'Unable to patch a user space. ';
|
|
116
|
-
if (result.status !== 200) {
|
|
117
|
-
this.logInvalidResponse(result);
|
|
118
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
119
|
-
}
|
|
120
|
-
if (!result.body) {
|
|
121
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
122
|
-
}
|
|
123
|
-
let data: any;
|
|
124
|
-
try {
|
|
125
|
-
data = JSON.parse(result.body);
|
|
126
|
-
} catch (e) {
|
|
127
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
128
|
-
}
|
|
129
|
-
if (!data.revert) {
|
|
130
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
131
|
-
}
|
|
132
|
-
return data.revert as JsonPatch;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Deletes the space in the store.
|
|
137
|
-
*
|
|
138
|
-
* @param key The key of the space to delete.
|
|
139
|
-
*/
|
|
140
|
-
async delete(key: string): Promise<void> {
|
|
141
|
-
const { token } = this.sdk;
|
|
142
|
-
const url = this.sdk.getUrl(RouteBuilder.space(key));
|
|
143
|
-
const result = await this.sdk.http.delete(url.toString(), { token });
|
|
144
|
-
this.inspectCommonStatusCodes(result.status);
|
|
145
|
-
const E_PREFIX = 'Unable to delete a user space. ';
|
|
146
|
-
if (result.status !== 204) {
|
|
147
|
-
this.logInvalidResponse(result);
|
|
148
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Updates the sharing options of the space.
|
|
154
|
-
*
|
|
155
|
-
* @param key The user space key
|
|
156
|
-
* @param value The patch operation on the space's ACL
|
|
157
|
-
*/
|
|
158
|
-
async patchUsers(key: string, value: AccessOperation[]): Promise<void> {
|
|
159
|
-
const { token } = this.sdk;
|
|
160
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceUsers(key));
|
|
161
|
-
const body = JSON.stringify(value);
|
|
162
|
-
const result = await this.sdk.http.patch(url.toString(), { token, body });
|
|
163
|
-
this.inspectCommonStatusCodes(result.status);
|
|
164
|
-
const E_PREFIX = 'Unable to patch a user space. ';
|
|
165
|
-
if (result.status !== 204) {
|
|
166
|
-
this.logInvalidResponse(result);
|
|
167
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Lists uses having access to the user space.
|
|
173
|
-
*
|
|
174
|
-
* @param key The user space key
|
|
175
|
-
*/
|
|
176
|
-
async listUsers(key: string): Promise<IListResponse> {
|
|
177
|
-
const { token } = this.sdk;
|
|
178
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceUsers(key));
|
|
179
|
-
const result = await this.sdk.http.get(url.toString(), { token });
|
|
180
|
-
this.inspectCommonStatusCodes(result.status);
|
|
181
|
-
const E_PREFIX = 'Unable to list users in the space. ';
|
|
182
|
-
if (result.status !== 200) {
|
|
183
|
-
this.logInvalidResponse(result);
|
|
184
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
185
|
-
}
|
|
186
|
-
if (!result.body) {
|
|
187
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
188
|
-
}
|
|
189
|
-
let data: IListResponse;
|
|
190
|
-
try {
|
|
191
|
-
data = JSON.parse(result.body);
|
|
192
|
-
} catch (e) {
|
|
193
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
194
|
-
}
|
|
195
|
-
if (!Array.isArray(data.data)) {
|
|
196
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
197
|
-
}
|
|
198
|
-
return data;
|
|
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
|
-
}
|
|
209
|
-
}
|