@api-client/core 0.9.0 → 0.9.3

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.
Files changed (35) hide show
  1. package/build/src/events/BaseEvents.d.ts +12 -0
  2. package/build/src/events/BaseEvents.js.map +1 -1
  3. package/build/src/models/Space.d.ts +7 -24
  4. package/build/src/models/Space.js +36 -41
  5. package/build/src/models/Space.js.map +1 -1
  6. package/build/src/models/store/File.d.ts +1 -1
  7. package/build/src/models/store/File.js +1 -1
  8. package/build/src/proxy/HttpProjectProxy.d.ts +4 -0
  9. package/build/src/proxy/HttpProjectProxy.js +10 -2
  10. package/build/src/proxy/HttpProjectProxy.js.map +1 -1
  11. package/build/src/runtime/store/CertificatesSdk.js +1 -1
  12. package/build/src/runtime/store/CertificatesSdk.js.map +1 -1
  13. package/build/src/runtime/store/FilesSdk.d.ts +14 -13
  14. package/build/src/runtime/store/FilesSdk.js +22 -11
  15. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  16. package/build/src/runtime/store/HistorySdk.d.ts +2 -2
  17. package/build/src/runtime/store/HistorySdk.js +8 -8
  18. package/build/src/runtime/store/HistorySdk.js.map +1 -1
  19. package/build/src/runtime/store/SharedSdk.d.ts +2 -2
  20. package/build/src/runtime/store/SharedSdk.js +2 -1
  21. package/build/src/runtime/store/SharedSdk.js.map +1 -1
  22. package/build/src/runtime/store/interfaces/Files.d.ts +5 -5
  23. package/build/src/runtime/store/interfaces/History.d.ts +2 -2
  24. package/data/models/example-generator-api.json +8 -8
  25. package/package.json +1 -1
  26. package/src/events/BaseEvents.ts +12 -0
  27. package/src/models/Space.ts +42 -56
  28. package/src/models/store/File.ts +1 -1
  29. package/src/proxy/HttpProjectProxy.ts +14 -2
  30. package/src/runtime/store/CertificatesSdk.ts +1 -1
  31. package/src/runtime/store/FilesSdk.ts +27 -16
  32. package/src/runtime/store/HistorySdk.ts +8 -8
  33. package/src/runtime/store/SharedSdk.ts +3 -2
  34. package/src/runtime/store/interfaces/Files.ts +5 -5
  35. package/src/runtime/store/interfaces/History.ts +2 -2
@@ -7,7 +7,7 @@ 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 { ContextListResult, IPatchInfo, IPatchRevision, IAccessPatchInfo, ContextSpaceListOptions, ContextChangeRecord, IBulkOperationResult } from '../../events/BaseEvents.js';
10
+ import { ContextListResult, IPatchInfo, IPatchRevision, IAccessPatchInfo, ContextChangeRecord, IBulkOperationResult, ContextListOptions } from '../../events/BaseEvents.js';
11
11
 
12
12
  export interface IMetaCreateOptions {
13
13
  /**
@@ -41,17 +41,19 @@ export class FilesSdk extends SdkBase {
41
41
  /**
42
42
  * Lists files (spaces, projects, etc) in the store.
43
43
  *
44
+ * @param space the parent space for files.
44
45
  * @param kinds Optional list of kinds to limit the file types in the result. Spaces are always included.
45
46
  * @param options Optional query options.
46
47
  * @param request Optional request options.
47
48
  */
48
- async list(kinds?: ListFileKind[], options?: ContextSpaceListOptions, request: ISdkRequestOptions = {}): Promise<ContextListResult<IFile>> {
49
+ async list(space: string, kinds?: ListFileKind[], options?: ContextListOptions, request: ISdkRequestOptions = {}): Promise<ContextListResult<IFile>> {
49
50
  const token = request.token || this.sdk.token;
50
51
  const url = this.sdk.getUrl(RouteBuilder.files());
51
52
  this.sdk.appendListOptions(url, options);
52
53
  if (Array.isArray(kinds)) {
53
54
  kinds.forEach(k => url.searchParams.append('kind', k));
54
55
  }
56
+ url.searchParams.set('space', space);
55
57
  const result = await this.sdk.http.get(url.toString(), { token });
56
58
  this.inspectCommonStatusCodes(result.status, result.body);
57
59
  const E_PREFIX = 'Unable to list files. ';
@@ -90,7 +92,7 @@ export class FilesSdk extends SdkBase {
90
92
  */
91
93
  async create(meta: IFile, contents: unknown, space: string, opts: IFileCreateOptions = {}, request: ISdkRequestOptions = {}): Promise<ContextChangeRecord<IFile>> {
92
94
  const result = await this.createMeta(meta, space, opts, request);
93
- await this.createMedia(contents, result.key, opts, request);
95
+ await this.createMedia(contents, result.key, space, opts, request);
94
96
  return result;
95
97
  }
96
98
 
@@ -152,10 +154,11 @@ export class FilesSdk extends SdkBase {
152
154
  * @param opts Contents create options. You can define content's mime type here.
153
155
  * @param request Optional request.
154
156
  */
155
- async createMedia(contents: unknown, key: string, opts: IMediaCreateOptions = {}, request: ISdkRequestOptions = {}): Promise<void> {
157
+ async createMedia(contents: unknown, space: string, key: string, opts: IMediaCreateOptions = {}, request: ISdkRequestOptions = {}): Promise<void> {
156
158
  const token = request.token || this.sdk.token;
157
159
  const path = RouteBuilder.file(key);
158
160
  const url = this.sdk.getUrl(path);
161
+ url.searchParams.set('space', space);
159
162
  url.searchParams.set('alt', 'media');
160
163
  const mime = opts.mime || 'application/json';
161
164
  let body: string;
@@ -191,7 +194,7 @@ export class FilesSdk extends SdkBase {
191
194
  * @param request Optional request options.
192
195
  * @returns THe file metadata
193
196
  */
194
- read(key: string, media: false, request?: ISdkRequestOptions): Promise<IFile>;
197
+ read(space: string, key: string, media: false, request?: ISdkRequestOptions): Promise<IFile>;
195
198
 
196
199
  /**
197
200
  * Reads file contents from the store.
@@ -200,7 +203,7 @@ export class FilesSdk extends SdkBase {
200
203
  * @param request Optional request options.
201
204
  * @returns THe file contents
202
205
  */
203
- read(key: string, media: true, request?: ISdkRequestOptions): Promise<unknown>;
206
+ read(space: string, key: string, media: true, request?: ISdkRequestOptions): Promise<unknown>;
204
207
 
205
208
  /**
206
209
  * Reads a user file definition from the store.
@@ -208,9 +211,10 @@ export class FilesSdk extends SdkBase {
208
211
  * @param media When true it reads file contents rather than metadata.
209
212
  * @param request Optional request options.
210
213
  */
211
- async read(key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<IFile | unknown> {
214
+ async read(space: string, key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<IFile | unknown> {
212
215
  const token = request.token || this.sdk.token;
213
216
  const url = this.sdk.getUrl(RouteBuilder.file(key));
217
+ url.searchParams.set('space', space);
214
218
  if (media) {
215
219
  url.searchParams.set('alt', 'media');
216
220
  }
@@ -250,9 +254,10 @@ export class FilesSdk extends SdkBase {
250
254
  * in that place. It also inserts `undefined` in place of a file that doesn't exist.
251
255
  * @param request Optional request options.
252
256
  */
253
- async readBulk(keys: string[], request: ISdkRequestOptions = {}): Promise<IBulkOperationResult<IFile>> {
257
+ async readBulk(space: string, keys: string[], request: ISdkRequestOptions = {}): Promise<IBulkOperationResult<IFile>> {
254
258
  const token = request.token || this.sdk.token;
255
259
  const url = this.sdk.getUrl(RouteBuilder.filesBatch());
260
+ url.searchParams.set('space', space);
256
261
  const body = JSON.stringify(keys);
257
262
  const result = await this.sdk.http.post(url.toString(), { token, body });
258
263
  this.inspectCommonStatusCodes(result.status, result.body);
@@ -288,7 +293,7 @@ export class FilesSdk extends SdkBase {
288
293
  * @param value The patch to apply.
289
294
  * @param request Optional request options.
290
295
  */
291
- patch(key: string, value: IPatchInfo, media: false, request?: ISdkRequestOptions): Promise<IPatchRevision>;
296
+ patch(space: string, key: string, value: IPatchInfo, media: false, request?: ISdkRequestOptions): Promise<IPatchRevision>;
292
297
 
293
298
  /**
294
299
  * Patches file's content in the store.
@@ -297,7 +302,7 @@ export class FilesSdk extends SdkBase {
297
302
  * @param value The patch to apply.
298
303
  * @param request Optional request options.
299
304
  */
300
- patch(key: string, value: IPatchInfo, media: true, request?: ISdkRequestOptions): Promise<IPatchRevision>;
305
+ patch(space: string, key: string, value: IPatchInfo, media: true, request?: ISdkRequestOptions): Promise<IPatchRevision>;
301
306
 
302
307
  /**
303
308
  * Patches a file in the store.
@@ -306,9 +311,10 @@ export class FilesSdk extends SdkBase {
306
311
  * @param request Optional request options.
307
312
  * @returns The JSON patch to revert the change using the `@api-client/json` library
308
313
  */
309
- async patch(key: string, value: IPatchInfo, media?: boolean, request: ISdkRequestOptions = {}): Promise<IPatchRevision> {
314
+ async patch(space: string, key: string, value: IPatchInfo, media?: boolean, request: ISdkRequestOptions = {}): Promise<IPatchRevision> {
310
315
  const token = request.token || this.sdk.token;
311
316
  const url = this.sdk.getUrl(RouteBuilder.file(key));
317
+ url.searchParams.set('space', space);
312
318
  if (media) {
313
319
  url.searchParams.set('alt', 'media');
314
320
  }
@@ -347,9 +353,10 @@ export class FilesSdk extends SdkBase {
347
353
  * @param key The key of the file to delete.
348
354
  * @param request Optional request options.
349
355
  */
350
- async delete(key: string, request: ISdkRequestOptions = {}): Promise<void> {
356
+ async delete(space: string, key: string, request: ISdkRequestOptions = {}): Promise<void> {
351
357
  const token = request.token || this.sdk.token;
352
358
  const url = this.sdk.getUrl(RouteBuilder.file(key));
359
+ url.searchParams.set('space', space);
353
360
  const result = await this.sdk.http.delete(url.toString(), { token });
354
361
  this.inspectCommonStatusCodes(result.status, result.body);
355
362
  const E_PREFIX = 'Unable to delete a file. ';
@@ -371,9 +378,10 @@ export class FilesSdk extends SdkBase {
371
378
  * @param value The patch operation on the file's ACL
372
379
  * @param request Optional request options.
373
380
  */
374
- async patchUsers(key: string, value: IAccessPatchInfo, request: ISdkRequestOptions = {}): Promise<void> {
381
+ async patchUsers(space: string, key: string, value: IAccessPatchInfo, request: ISdkRequestOptions = {}): Promise<void> {
375
382
  const token = request.token || this.sdk.token;
376
383
  const url = this.sdk.getUrl(RouteBuilder.fileUsers(key));
384
+ url.searchParams.set('space', space);
377
385
  const body = JSON.stringify(value);
378
386
  const result = await this.sdk.http.patch(url.toString(), { token, body });
379
387
  this.inspectCommonStatusCodes(result.status, result.body);
@@ -395,9 +403,10 @@ export class FilesSdk extends SdkBase {
395
403
  * @param key The file key
396
404
  * @param request Optional request options.
397
405
  */
398
- async listUsers(key: string, request: ISdkRequestOptions = {}): Promise<ContextListResult<IUser>> {
406
+ async listUsers(space: string, key: string, request: ISdkRequestOptions = {}): Promise<ContextListResult<IUser>> {
399
407
  const token = request.token || this.sdk.token;
400
408
  const url = this.sdk.getUrl(RouteBuilder.fileUsers(key));
409
+ url.searchParams.set('space', space);
401
410
  const result = await this.sdk.http.get(url.toString(), { token });
402
411
  this.inspectCommonStatusCodes(result.status, result.body);
403
412
  const E_PREFIX = 'Unable to list users in the file. ';
@@ -442,9 +451,10 @@ export class FilesSdk extends SdkBase {
442
451
  * @param media Whether to observe changes to the file media instead of meta.
443
452
  * @param request Optional request options.
444
453
  */
445
- async observeFile(key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<WebSocketNode | WebSocket> {
454
+ async observeFile(space: string, key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<WebSocketNode | WebSocket> {
446
455
  const token = request.token || this.sdk.token;
447
456
  const url = this.sdk.getUrl(RouteBuilder.file(key));
457
+ url.searchParams.set('space', space);
448
458
  if (media) {
449
459
  url.searchParams.set('alt', 'media');
450
460
  }
@@ -455,9 +465,10 @@ export class FilesSdk extends SdkBase {
455
465
  * Lists breadcrumbs to the file.
456
466
  * @param key The lowest file in the hierarchy
457
467
  */
458
- async breadcrumbs(key: string, request: ISdkRequestOptions = {}): Promise<ContextListResult<FileBreadcrumb>> {
468
+ async breadcrumbs(space: string, key: string, request: ISdkRequestOptions = {}): Promise<ContextListResult<FileBreadcrumb>> {
459
469
  const token = request.token || this.sdk.token;
460
470
  const url = this.sdk.getUrl(RouteBuilder.fileBreadcrumbs(key));
471
+ url.searchParams.set('space', space);
461
472
  const result = await this.sdk.http.get(url.toString(), { token });
462
473
  this.inspectCommonStatusCodes(result.status, result.body);
463
474
  const E_PREFIX = 'Unable to read a file. ';
@@ -76,12 +76,12 @@ export class HistorySdk extends SdkBase {
76
76
  }
77
77
  let data: IBulkOperationResult<ContextChangeRecord<IHttpHistory>>;
78
78
  try {
79
- data = JSON.parse(result.body).items;
79
+ data = JSON.parse(result.body);
80
80
  } catch (e) {
81
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
81
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}`);
82
82
  }
83
83
  if (!data.items) {
84
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
84
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}`);
85
85
  }
86
86
  return data;
87
87
  }
@@ -153,7 +153,7 @@ export class HistorySdk extends SdkBase {
153
153
  const path = RouteBuilder.historyItem(key);
154
154
  const url = this.sdk.getUrl(path);
155
155
 
156
- const result = await this.sdk.http.post(url.toString(), { token });
156
+ const result = await this.sdk.http.delete(url.toString(), { token });
157
157
  this.inspectCommonStatusCodes(result.status);
158
158
  const E_PREFIX = 'Unable to delete history. ';
159
159
  if (result.status !== 204) {
@@ -258,9 +258,9 @@ export class HistorySdk extends SdkBase {
258
258
  }
259
259
  }
260
260
 
261
- async clearProject(projectKey: string, request: ISdkRequestOptions = {}): Promise<void> {
261
+ async clearProject(spaceKey: string, projectKey: string, request: ISdkRequestOptions = {}): Promise<void> {
262
262
  const token = request.token || this.sdk.token;
263
- const url = this.sdk.getUrl(RouteBuilder.historyClear('project', projectKey));
263
+ const url = this.sdk.getUrl(RouteBuilder.historyClear('project', spaceKey, projectKey));
264
264
  const result = await this.sdk.http.delete(url.toString(), { token });
265
265
  this.inspectCommonStatusCodes(result.status, result.body);
266
266
  const E_PREFIX = 'Unable to clear history for the project. ';
@@ -275,9 +275,9 @@ export class HistorySdk extends SdkBase {
275
275
  }
276
276
  }
277
277
 
278
- async clearRequest(projectKey: string, requestKey: string, request: ISdkRequestOptions = {}): Promise<void> {
278
+ async clearRequest(spaceKey: string, projectKey: string, requestKey: string, request: ISdkRequestOptions = {}): Promise<void> {
279
279
  const token = request.token || this.sdk.token;
280
- const url = this.sdk.getUrl(RouteBuilder.historyClear('request', projectKey, requestKey));
280
+ const url = this.sdk.getUrl(RouteBuilder.historyClear('request', spaceKey, projectKey, requestKey));
281
281
  const result = await this.sdk.http.delete(url.toString(), { token });
282
282
  this.inspectCommonStatusCodes(result.status, result.body);
283
283
  const E_PREFIX = 'Unable to clear history for the request. ';
@@ -3,7 +3,7 @@ import { RouteBuilder } from './RouteBuilder.js';
3
3
  import { IFile } from '../../models/store/File.js';
4
4
  import { SdkError } from './Errors.js';
5
5
  import { ListFileKind } from './FilesSdk.js';
6
- import { ContextListResult, ContextSpaceListOptions } from '../../events/BaseEvents.js';
6
+ import { ContextListOptions, ContextListResult } from '../../events/BaseEvents.js';
7
7
 
8
8
  export class SharedSdk extends SdkBase {
9
9
  /**
@@ -13,13 +13,14 @@ export class SharedSdk extends SdkBase {
13
13
  * @param options Optional query options.
14
14
  * @param request Optional request options.
15
15
  */
16
- async list(kinds?: ListFileKind[], options?: ContextSpaceListOptions, request: ISdkRequestOptions = {}): Promise<ContextListResult<IFile>> {
16
+ async list(space: string, kinds?: ListFileKind[], options?: ContextListOptions, request: ISdkRequestOptions = {}): Promise<ContextListResult<IFile>> {
17
17
  const token = request.token || this.sdk.token;
18
18
  const url = this.sdk.getUrl(RouteBuilder.shared());
19
19
  this.sdk.appendListOptions(url, options);
20
20
  if (Array.isArray(kinds)) {
21
21
  kinds.forEach(k => url.searchParams.append('kind', k));
22
22
  }
23
+ url.searchParams.set('space', space);
23
24
  const result = await this.sdk.http.get(url.toString(), { token });
24
25
  this.inspectCommonStatusCodes(result.status, result.body);
25
26
  const E_PREFIX = 'Unable to list spaces. ';
@@ -29,7 +29,7 @@ export interface Files {
29
29
  *
30
30
  * @param key The id of the file to read the metadata for.
31
31
  */
32
- read(key: string): Promise<IFile>;
32
+ read(space: string, key: string): Promise<IFile>;
33
33
 
34
34
  /**
35
35
  * Reads multiple files in a single call.
@@ -42,7 +42,7 @@ export interface Files {
42
42
  *
43
43
  * @param keys The list of keys to read
44
44
  */
45
- readBulk(keys: string[]): Promise<IBulkOperationResult<IFile>>;
45
+ readBulk(space: string, keys: string[]): Promise<IBulkOperationResult<IFile>>;
46
46
 
47
47
  /**
48
48
  * Marks file as deleted.
@@ -51,7 +51,7 @@ export interface Files {
51
51
  *
52
52
  * @param key The database id of the file to remove.
53
53
  */
54
- delete(key: string): Promise<ContextDeleteRecord>;
54
+ delete(space: string, key: string): Promise<ContextDeleteRecord>;
55
55
 
56
56
  /**
57
57
  * This is the preferred way to update a file metadata. It allows to apply a reversible patch
@@ -60,11 +60,11 @@ export interface Files {
60
60
  * @param key The datastore id of the file to patch
61
61
  * @param info The patch to apply.
62
62
  */
63
- patch(key: string, info: IPatchInfo): Promise<IPatchRevision>;
63
+ patch(space: string, key: string, info: IPatchInfo): Promise<IPatchRevision>;
64
64
 
65
65
  /**
66
66
  * Lists breadcrumbs to the file.
67
67
  * @param key The lowest file in the hierarchy
68
68
  */
69
- breadcrumbs(key: string): Promise<ContextListResult<FileBreadcrumb>>;
69
+ breadcrumbs(space: string, key: string): Promise<ContextListResult<FileBreadcrumb>>;
70
70
  }
@@ -53,12 +53,12 @@ export interface History {
53
53
  *
54
54
  * @param project The parent project key
55
55
  */
56
- clearProject(project: string): Promise<void>;
56
+ clearProject(space: string, project: string): Promise<void>;
57
57
  /**
58
58
  * Clears all history from a request
59
59
  *
60
60
  * @param project The parent project key
61
61
  * @param request The parent request key
62
62
  */
63
- clearRequest(project: string, request: string): Promise<void>;
63
+ clearRequest(space: string, project: string, request: string): Promise<void>;
64
64
  }