@api-client/core 0.8.22 → 0.9.1

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 (207) hide show
  1. package/build/browser.d.ts +12 -5
  2. package/build/browser.js +2 -3
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +12 -5
  5. package/build/index.js +2 -4
  6. package/build/index.js.map +1 -1
  7. package/build/src/events/BaseEvents.d.ts +137 -18
  8. package/build/src/events/BaseEvents.js.map +1 -1
  9. package/build/src/events/EventTypes.d.ts +0 -14
  10. package/build/src/events/EventTypes.js +0 -2
  11. package/build/src/events/EventTypes.js.map +1 -1
  12. package/build/src/events/Events.d.ts +1 -5
  13. package/build/src/events/Events.js +0 -2
  14. package/build/src/events/Events.js.map +1 -1
  15. package/build/src/events/transport/TransportEventTypes.d.ts +0 -1
  16. package/build/src/events/transport/TransportEventTypes.js +0 -1
  17. package/build/src/events/transport/TransportEventTypes.js.map +1 -1
  18. package/build/src/events/transport/TransportEvents.d.ts +0 -8
  19. package/build/src/events/transport/TransportEvents.js +0 -11
  20. package/build/src/events/transport/TransportEvents.js.map +1 -1
  21. package/build/src/mocking/ProjectMock.d.ts +0 -3
  22. package/build/src/mocking/ProjectMock.js +0 -3
  23. package/build/src/mocking/ProjectMock.js.map +1 -1
  24. package/build/src/mocking/lib/History.js +5 -0
  25. package/build/src/mocking/lib/History.js.map +1 -1
  26. package/build/src/models/{Workspace.d.ts → Folder.d.ts} +7 -7
  27. package/build/src/models/{Workspace.js → Folder.js} +5 -5
  28. package/build/src/models/Folder.js.map +1 -0
  29. package/build/src/models/HttpHistory.d.ts +38 -43
  30. package/build/src/models/HttpHistory.js +27 -34
  31. package/build/src/models/HttpHistory.js.map +1 -1
  32. package/build/src/models/HttpProject.d.ts +0 -2
  33. package/build/src/models/HttpProject.js +0 -27
  34. package/build/src/models/HttpProject.js.map +1 -1
  35. package/build/src/models/Project.d.ts +0 -8
  36. package/build/src/models/Project.js +0 -4
  37. package/build/src/models/Project.js.map +1 -1
  38. package/build/src/models/ProjectFolder.d.ts +0 -2
  39. package/build/src/models/ProjectFolder.js +0 -14
  40. package/build/src/models/ProjectFolder.js.map +1 -1
  41. package/build/src/models/ProjectItem.d.ts +0 -2
  42. package/build/src/models/ProjectItem.js +0 -20
  43. package/build/src/models/ProjectItem.js.map +1 -1
  44. package/build/src/models/ProjectRequest.d.ts +2 -3
  45. package/build/src/models/ProjectRequest.js.map +1 -1
  46. package/build/src/models/RequestConfig.d.ts +1 -1
  47. package/build/src/models/Space.d.ts +25 -0
  48. package/build/src/models/Space.js +76 -0
  49. package/build/src/models/Space.js.map +1 -0
  50. package/build/src/models/TrashEntry.d.ts +27 -0
  51. package/build/src/models/TrashEntry.js +2 -0
  52. package/build/src/models/TrashEntry.js.map +1 -0
  53. package/build/src/models/store/Backend.d.ts +0 -315
  54. package/build/src/models/store/Backend.js +0 -1
  55. package/build/src/models/store/Backend.js.map +1 -1
  56. package/build/src/models/store/File.d.ts +31 -1
  57. package/build/src/models/store/File.js +6 -6
  58. package/build/src/models/store/File.js.map +1 -1
  59. package/build/src/proxy/HttpProjectProxy.d.ts +4 -0
  60. package/build/src/proxy/HttpProjectProxy.js +10 -2
  61. package/build/src/proxy/HttpProjectProxy.js.map +1 -1
  62. package/build/src/proxy/ProxyService.d.ts +0 -10
  63. package/build/src/proxy/ProxyService.js +0 -14
  64. package/build/src/proxy/ProxyService.js.map +1 -1
  65. package/build/src/runtime/node/InteropInterfaces.d.ts +1 -2
  66. package/build/src/runtime/node/ProjectParallelRunner.d.ts +2 -3
  67. package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
  68. package/build/src/runtime/node/ProjectRequestRunner.d.ts +7 -8
  69. package/build/src/runtime/node/ProjectRequestRunner.js +2 -3
  70. package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
  71. package/build/src/runtime/node/ProjectRunner.d.ts +3 -4
  72. package/build/src/runtime/node/ProjectRunner.js.map +1 -1
  73. package/build/src/runtime/node/ProjectRunnerWorker.js +0 -4
  74. package/build/src/runtime/node/ProjectRunnerWorker.js.map +1 -1
  75. package/build/src/runtime/store/CertificatesSdk.d.ts +46 -0
  76. package/build/src/runtime/store/CertificatesSdk.js +227 -0
  77. package/build/src/runtime/store/CertificatesSdk.js.map +1 -0
  78. package/build/src/runtime/store/FilesSdk.d.ts +21 -16
  79. package/build/src/runtime/store/FilesSdk.js +75 -23
  80. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  81. package/build/src/runtime/store/HistorySdk.d.ts +11 -8
  82. package/build/src/runtime/store/HistorySdk.js +140 -17
  83. package/build/src/runtime/store/HistorySdk.js.map +1 -1
  84. package/build/src/runtime/store/RevisionsSdk.d.ts +12 -0
  85. package/build/src/runtime/store/RevisionsSdk.js +43 -0
  86. package/build/src/runtime/store/RevisionsSdk.js.map +1 -0
  87. package/build/src/runtime/store/RouteBuilder.d.ts +16 -18
  88. package/build/src/runtime/store/RouteBuilder.js +33 -60
  89. package/build/src/runtime/store/RouteBuilder.js.map +1 -1
  90. package/build/src/runtime/store/Sdk.d.ts +10 -7
  91. package/build/src/runtime/store/Sdk.js +12 -5
  92. package/build/src/runtime/store/Sdk.js.map +1 -1
  93. package/build/src/runtime/store/SdkBase.js.map +1 -1
  94. package/build/src/runtime/store/SharedSdk.d.ts +2 -2
  95. package/build/src/runtime/store/SharedSdk.js.map +1 -1
  96. package/build/src/runtime/store/SpacesSdk.d.ts +29 -0
  97. package/build/src/runtime/store/SpacesSdk.js +135 -0
  98. package/build/src/runtime/store/SpacesSdk.js.map +1 -0
  99. package/build/src/runtime/store/TrashSdk.d.ts +35 -0
  100. package/build/src/runtime/store/TrashSdk.js +155 -0
  101. package/build/src/runtime/store/TrashSdk.js.map +1 -0
  102. package/build/src/runtime/store/UsersSdk.d.ts +2 -2
  103. package/build/src/runtime/store/UsersSdk.js.map +1 -1
  104. package/build/src/runtime/store/interfaces/ApiClientStore.d.ts +30 -0
  105. package/build/src/runtime/store/interfaces/ApiClientStore.js +2 -0
  106. package/build/src/runtime/store/interfaces/ApiClientStore.js.map +1 -0
  107. package/build/src/runtime/store/interfaces/Certificates.d.ts +49 -0
  108. package/build/src/runtime/store/interfaces/Certificates.js +2 -0
  109. package/build/src/runtime/store/interfaces/Certificates.js.map +1 -0
  110. package/build/src/runtime/store/interfaces/Files.d.ts +63 -0
  111. package/build/src/runtime/store/interfaces/Files.js +2 -0
  112. package/build/src/runtime/store/interfaces/Files.js.map +1 -0
  113. package/build/src/runtime/store/interfaces/History.d.ts +63 -0
  114. package/build/src/runtime/store/interfaces/History.js +2 -0
  115. package/build/src/runtime/store/interfaces/History.js.map +1 -0
  116. package/build/src/runtime/store/interfaces/Media.d.ts +42 -0
  117. package/build/src/runtime/store/interfaces/Media.js +2 -0
  118. package/build/src/runtime/store/interfaces/Media.js.map +1 -0
  119. package/build/src/runtime/store/interfaces/Revisions.d.ts +25 -0
  120. package/build/src/runtime/store/interfaces/Revisions.js +2 -0
  121. package/build/src/runtime/store/interfaces/Revisions.js.map +1 -0
  122. package/build/src/runtime/store/interfaces/Spaces.d.ts +42 -0
  123. package/build/src/runtime/store/interfaces/Spaces.js +2 -0
  124. package/build/src/runtime/store/interfaces/Spaces.js.map +1 -0
  125. package/build/src/runtime/store/interfaces/Trash.d.ts +38 -0
  126. package/build/src/runtime/store/interfaces/Trash.js +2 -0
  127. package/build/src/runtime/store/interfaces/Trash.js.map +1 -0
  128. package/package.json +1 -1
  129. package/src/events/BaseEvents.ts +148 -18
  130. package/src/events/EventTypes.ts +0 -2
  131. package/src/events/Events.ts +0 -2
  132. package/src/events/transport/TransportEventTypes.ts +0 -1
  133. package/src/events/transport/TransportEvents.ts +0 -13
  134. package/src/mocking/ProjectMock.ts +0 -4
  135. package/src/mocking/lib/History.ts +5 -0
  136. package/src/models/{Workspace.ts → Folder.ts} +12 -12
  137. package/src/models/HttpHistory.ts +53 -63
  138. package/src/models/HttpProject.ts +0 -29
  139. package/src/models/Project.ts +0 -8
  140. package/src/models/ProjectFolder.ts +0 -16
  141. package/src/models/ProjectItem.ts +0 -18
  142. package/src/models/ProjectRequest.ts +3 -4
  143. package/src/models/RequestConfig.ts +1 -1
  144. package/src/models/Space.ts +91 -0
  145. package/src/models/TrashEntry.ts +29 -0
  146. package/src/models/store/Backend.ts +0 -342
  147. package/src/models/store/File.ts +39 -6
  148. package/src/proxy/HttpProjectProxy.ts +14 -2
  149. package/src/proxy/ProxyService.ts +0 -15
  150. package/src/proxy/readme.md +0 -1
  151. package/src/runtime/node/InteropInterfaces.ts +1 -2
  152. package/src/runtime/node/ProjectParallelRunner.ts +2 -3
  153. package/src/runtime/node/ProjectRequestRunner.ts +13 -14
  154. package/src/runtime/node/ProjectRunner.ts +3 -4
  155. package/src/runtime/node/ProjectRunnerWorker.ts +1 -4
  156. package/src/runtime/store/CertificatesSdk.ts +231 -0
  157. package/src/runtime/store/FilesSdk.ts +88 -35
  158. package/src/runtime/store/HistorySdk.ts +145 -33
  159. package/src/runtime/store/RevisionsSdk.ts +44 -0
  160. package/src/runtime/store/RouteBuilder.ts +37 -69
  161. package/src/runtime/store/Sdk.ts +17 -7
  162. package/src/runtime/store/SdkBase.ts +1 -1
  163. package/src/runtime/store/SharedSdk.ts +3 -3
  164. package/src/runtime/store/SpacesSdk.ts +136 -0
  165. package/src/runtime/store/TrashSdk.ts +159 -0
  166. package/src/runtime/store/UsersSdk.ts +3 -3
  167. package/src/runtime/store/interfaces/ApiClientStore.ts +39 -0
  168. package/src/runtime/store/interfaces/Certificates.ts +56 -0
  169. package/src/runtime/store/interfaces/Files.ts +70 -0
  170. package/src/runtime/store/interfaces/History.ts +64 -0
  171. package/src/runtime/store/interfaces/Media.ts +46 -0
  172. package/src/runtime/store/interfaces/Revisions.ts +27 -0
  173. package/src/runtime/store/interfaces/Spaces.ts +48 -0
  174. package/src/runtime/store/interfaces/Trash.ts +42 -0
  175. package/build/src/events/models/ClientCertificateEvents.d.ts +0 -54
  176. package/build/src/events/models/ClientCertificateEvents.js +0 -78
  177. package/build/src/events/models/ClientCertificateEvents.js.map +0 -1
  178. package/build/src/events/models/ModelEventTypes.d.ts +0 -13
  179. package/build/src/events/models/ModelEventTypes.js +0 -14
  180. package/build/src/events/models/ModelEventTypes.js.map +0 -1
  181. package/build/src/events/models/ModelEvents.d.ts +0 -4
  182. package/build/src/events/models/ModelEvents.js +0 -5
  183. package/build/src/events/models/ModelEvents.js.map +0 -1
  184. package/build/src/mocking/lib/App.d.ts +0 -36
  185. package/build/src/mocking/lib/App.js +0 -70
  186. package/build/src/mocking/lib/App.js.map +0 -1
  187. package/build/src/models/AppProject.d.ts +0 -817
  188. package/build/src/models/AppProject.js +0 -1721
  189. package/build/src/models/AppProject.js.map +0 -1
  190. package/build/src/models/AppRequest.d.ts +0 -69
  191. package/build/src/models/AppRequest.js +0 -150
  192. package/build/src/models/AppRequest.js.map +0 -1
  193. package/build/src/models/Workspace.js.map +0 -1
  194. package/build/src/proxy/AppProjectProxy.d.ts +0 -28
  195. package/build/src/proxy/AppProjectProxy.js +0 -107
  196. package/build/src/proxy/AppProjectProxy.js.map +0 -1
  197. package/build/src/runtime/store/AppSdk.d.ts +0 -213
  198. package/build/src/runtime/store/AppSdk.js +0 -836
  199. package/build/src/runtime/store/AppSdk.js.map +0 -1
  200. package/src/events/models/ClientCertificateEvents.ts +0 -85
  201. package/src/events/models/ModelEventTypes.ts +0 -13
  202. package/src/events/models/ModelEvents.ts +0 -5
  203. package/src/mocking/lib/App.ts +0 -101
  204. package/src/models/AppProject.ts +0 -2188
  205. package/src/models/AppRequest.ts +0 -176
  206. package/src/proxy/AppProjectProxy.ts +0 -126
  207. package/src/runtime/store/AppSdk.ts +0 -842
@@ -1,13 +1,13 @@
1
1
  import WebSocketNode from 'ws';
2
- import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION, ISdkRequestOptions } from './SdkBase.js';
2
+ import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, ISdkRequestOptions } from './SdkBase.js';
3
3
  import { RouteBuilder } from './RouteBuilder.js';
4
- import { IListOptions, IListResponse, IPatchInfo, IPatchRevision, IAccessPatchInfo } from '../../models/store/Backend.js';
5
4
  import { IUser } from '../../models/store/User.js';
6
- import { IFile } from '../../models/store/File.js';
5
+ import { FileBreadcrumb, IFile } from '../../models/store/File.js';
7
6
  import { Kind as ProjectKind } from '../../models/Project.js';
8
- import { Kind as WorkspaceKind } from '../../models/Workspace.js';
7
+ import { Kind as FolderKind } from '../../models/Folder.js';
9
8
  import { Kind as DataNamespaceKind } from '../../models/data/DataNamespace.js';
10
9
  import { SdkError } from './Errors.js';
10
+ import { ContextListResult, IPatchInfo, IPatchRevision, IAccessPatchInfo, ContextSpaceListOptions, ContextChangeRecord, IBulkOperationResult } from '../../events/BaseEvents.js';
11
11
 
12
12
  export interface IMetaCreateOptions {
13
13
  /**
@@ -29,7 +29,7 @@ export interface IFileCreateOptions extends IMetaCreateOptions, IMediaCreateOpti
29
29
 
30
30
  }
31
31
 
32
- export type ListFileKind = typeof ProjectKind | typeof WorkspaceKind | typeof DataNamespaceKind;
32
+ export type ListFileKind = typeof ProjectKind | typeof FolderKind | typeof DataNamespaceKind;
33
33
 
34
34
  /**
35
35
  * In the store, the file is represented by the meta and the media.
@@ -45,7 +45,7 @@ export class FilesSdk extends SdkBase {
45
45
  * @param options Optional query options.
46
46
  * @param request Optional request options.
47
47
  */
48
- async list(kinds?: ListFileKind[], options?: IListOptions, request: ISdkRequestOptions = {}): Promise<IListResponse<IFile>> {
48
+ async list(kinds?: ListFileKind[], options?: ContextSpaceListOptions, request: ISdkRequestOptions = {}): Promise<ContextListResult<IFile>> {
49
49
  const token = request.token || this.sdk.token;
50
50
  const url = this.sdk.getUrl(RouteBuilder.files());
51
51
  this.sdk.appendListOptions(url, options);
@@ -67,7 +67,7 @@ export class FilesSdk extends SdkBase {
67
67
  if (!result.body) {
68
68
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
69
69
  }
70
- let data: IListResponse<IFile>;
70
+ let data: ContextListResult<IFile>;
71
71
  try {
72
72
  data = JSON.parse(result.body);
73
73
  } catch (e) {
@@ -88,10 +88,10 @@ export class FilesSdk extends SdkBase {
88
88
  * @param request Optional request details
89
89
  * @returns The id of the created file meta.
90
90
  */
91
- async create(meta: IFile, contents: unknown, opts: IFileCreateOptions = {}, request: ISdkRequestOptions = {}): Promise<string> {
92
- const id = await this.createMeta(meta, opts, request);
93
- await this.createMedia(contents, id, opts, request);
94
- return id;
91
+ async create(meta: IFile, contents: unknown, space: string, opts: IFileCreateOptions = {}, request: ISdkRequestOptions = {}): Promise<ContextChangeRecord<IFile>> {
92
+ const result = await this.createMeta(meta, space, opts, request);
93
+ await this.createMedia(contents, result.key, opts, request);
94
+ return result;
95
95
  }
96
96
 
97
97
  /**
@@ -102,10 +102,10 @@ export class FilesSdk extends SdkBase {
102
102
  * @param request Optional request options.
103
103
  * @returns The key of the creates file.
104
104
  */
105
- async createMeta(file: IFile, opts: IMetaCreateOptions = {}, request: ISdkRequestOptions = {}): Promise<string> {
105
+ async createMeta(file: IFile, space: string, opts: IMetaCreateOptions = {}, request: ISdkRequestOptions = {}): Promise<ContextChangeRecord<IFile>> {
106
106
  const token = request.token || this.sdk.token;
107
- const path = RouteBuilder.files();
108
- const url = this.sdk.getUrl(path);
107
+ const url = this.sdk.getUrl(RouteBuilder.files());
108
+ url.searchParams.set('space', space);
109
109
  if (opts.parent) {
110
110
  url.searchParams.set('parent', opts.parent);
111
111
  }
@@ -119,7 +119,7 @@ export class FilesSdk extends SdkBase {
119
119
  });
120
120
  this.inspectCommonStatusCodes(result.status, result.body);
121
121
  const E_PREFIX = 'Unable to create a file. ';
122
- if (result.status !== 204) {
122
+ if (result.status !== 200) {
123
123
  this.logInvalidResponse(result);
124
124
  let e = this.createGenericSdkError(result.body)
125
125
  if (!e) {
@@ -128,12 +128,20 @@ export class FilesSdk extends SdkBase {
128
128
  }
129
129
  throw e;
130
130
  }
131
- const location = result.headers.get('location');
132
- if (!location) {
133
- throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
131
+
132
+ if (!result.body) {
133
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
134
+ }
135
+ let data: ContextChangeRecord<IFile>;
136
+ try {
137
+ data = JSON.parse(result.body);
138
+ } catch (e) {
139
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
134
140
  }
135
- const id = location.split('/').pop();
136
- return id as string;
141
+ if (!data.key) {
142
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
143
+ }
144
+ return data;
137
145
  }
138
146
 
139
147
  /**
@@ -183,7 +191,8 @@ export class FilesSdk extends SdkBase {
183
191
  * @param request Optional request options.
184
192
  * @returns THe file metadata
185
193
  */
186
- read(key: string, media: false, request?: ISdkRequestOptions): Promise<IFile>;
194
+ read(space: string, key: string, media: false, request?: ISdkRequestOptions): Promise<IFile>;
195
+
187
196
  /**
188
197
  * Reads file contents from the store.
189
198
  *
@@ -191,7 +200,7 @@ export class FilesSdk extends SdkBase {
191
200
  * @param request Optional request options.
192
201
  * @returns THe file contents
193
202
  */
194
- read(key: string, media: true, request?: ISdkRequestOptions): Promise<unknown>;
203
+ read(space: string, key: string, media: true, request?: ISdkRequestOptions): Promise<unknown>;
195
204
 
196
205
  /**
197
206
  * Reads a user file definition from the store.
@@ -199,9 +208,10 @@ export class FilesSdk extends SdkBase {
199
208
  * @param media When true it reads file contents rather than metadata.
200
209
  * @param request Optional request options.
201
210
  */
202
- async read(key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<IFile | unknown> {
211
+ async read(space: string, key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<IFile | unknown> {
203
212
  const token = request.token || this.sdk.token;
204
213
  const url = this.sdk.getUrl(RouteBuilder.file(key));
214
+ url.searchParams.set('space', space);
205
215
  if (media) {
206
216
  url.searchParams.set('alt', 'media');
207
217
  }
@@ -226,8 +236,10 @@ export class FilesSdk extends SdkBase {
226
236
  } catch (e) {
227
237
  throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
228
238
  }
229
- if (!data.kind) {
230
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
239
+ if (!media) {
240
+ if (!data.kind) {
241
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
242
+ }
231
243
  }
232
244
  return data;
233
245
  }
@@ -239,9 +251,10 @@ export class FilesSdk extends SdkBase {
239
251
  * in that place. It also inserts `undefined` in place of a file that doesn't exist.
240
252
  * @param request Optional request options.
241
253
  */
242
- async readBulk(keys: string[], request: ISdkRequestOptions = {}): Promise<IListResponse<IFile|undefined>> {
254
+ async readBulk(space: string, keys: string[], request: ISdkRequestOptions = {}): Promise<IBulkOperationResult<IFile>> {
243
255
  const token = request.token || this.sdk.token;
244
256
  const url = this.sdk.getUrl(RouteBuilder.filesBatch());
257
+ url.searchParams.set('space', space);
245
258
  const body = JSON.stringify(keys);
246
259
  const result = await this.sdk.http.post(url.toString(), { token, body });
247
260
  this.inspectCommonStatusCodes(result.status, result.body);
@@ -258,7 +271,7 @@ export class FilesSdk extends SdkBase {
258
271
  if (!result.body) {
259
272
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
260
273
  }
261
- let data: IListResponse<IFile | undefined>;
274
+ let data: IBulkOperationResult<IFile>;
262
275
  try {
263
276
  data = JSON.parse(result.body);
264
277
  } catch (e) {
@@ -277,7 +290,7 @@ export class FilesSdk extends SdkBase {
277
290
  * @param value The patch to apply.
278
291
  * @param request Optional request options.
279
292
  */
280
- patch(key: string, value: IPatchInfo, media: false, request?: ISdkRequestOptions): Promise<IPatchRevision>;
293
+ patch(space: string, key: string, value: IPatchInfo, media: false, request?: ISdkRequestOptions): Promise<IPatchRevision>;
281
294
 
282
295
  /**
283
296
  * Patches file's content in the store.
@@ -286,7 +299,7 @@ export class FilesSdk extends SdkBase {
286
299
  * @param value The patch to apply.
287
300
  * @param request Optional request options.
288
301
  */
289
- patch(key: string, value: IPatchInfo, media: true, request?: ISdkRequestOptions): Promise<IPatchRevision>;
302
+ patch(space: string, key: string, value: IPatchInfo, media: true, request?: ISdkRequestOptions): Promise<IPatchRevision>;
290
303
 
291
304
  /**
292
305
  * Patches a file in the store.
@@ -295,9 +308,10 @@ export class FilesSdk extends SdkBase {
295
308
  * @param request Optional request options.
296
309
  * @returns The JSON patch to revert the change using the `@api-client/json` library
297
310
  */
298
- async patch(key: string, value: IPatchInfo, media?: boolean, request: ISdkRequestOptions = {}): Promise<IPatchRevision> {
311
+ async patch(space: string, key: string, value: IPatchInfo, media?: boolean, request: ISdkRequestOptions = {}): Promise<IPatchRevision> {
299
312
  const token = request.token || this.sdk.token;
300
313
  const url = this.sdk.getUrl(RouteBuilder.file(key));
314
+ url.searchParams.set('space', space);
301
315
  if (media) {
302
316
  url.searchParams.set('alt', 'media');
303
317
  }
@@ -336,9 +350,10 @@ export class FilesSdk extends SdkBase {
336
350
  * @param key The key of the file to delete.
337
351
  * @param request Optional request options.
338
352
  */
339
- async delete(key: string, request: ISdkRequestOptions = {}): Promise<void> {
353
+ async delete(space: string, key: string, request: ISdkRequestOptions = {}): Promise<void> {
340
354
  const token = request.token || this.sdk.token;
341
355
  const url = this.sdk.getUrl(RouteBuilder.file(key));
356
+ url.searchParams.set('space', space);
342
357
  const result = await this.sdk.http.delete(url.toString(), { token });
343
358
  this.inspectCommonStatusCodes(result.status, result.body);
344
359
  const E_PREFIX = 'Unable to delete a file. ';
@@ -360,9 +375,10 @@ export class FilesSdk extends SdkBase {
360
375
  * @param value The patch operation on the file's ACL
361
376
  * @param request Optional request options.
362
377
  */
363
- async patchUsers(key: string, value: IAccessPatchInfo, request: ISdkRequestOptions = {}): Promise<void> {
378
+ async patchUsers(space: string, key: string, value: IAccessPatchInfo, request: ISdkRequestOptions = {}): Promise<void> {
364
379
  const token = request.token || this.sdk.token;
365
380
  const url = this.sdk.getUrl(RouteBuilder.fileUsers(key));
381
+ url.searchParams.set('space', space);
366
382
  const body = JSON.stringify(value);
367
383
  const result = await this.sdk.http.patch(url.toString(), { token, body });
368
384
  this.inspectCommonStatusCodes(result.status, result.body);
@@ -384,9 +400,10 @@ export class FilesSdk extends SdkBase {
384
400
  * @param key The file key
385
401
  * @param request Optional request options.
386
402
  */
387
- async listUsers(key: string, request: ISdkRequestOptions = {}): Promise<IListResponse<IUser>> {
403
+ async listUsers(space: string, key: string, request: ISdkRequestOptions = {}): Promise<ContextListResult<IUser>> {
388
404
  const token = request.token || this.sdk.token;
389
405
  const url = this.sdk.getUrl(RouteBuilder.fileUsers(key));
406
+ url.searchParams.set('space', space);
390
407
  const result = await this.sdk.http.get(url.toString(), { token });
391
408
  this.inspectCommonStatusCodes(result.status, result.body);
392
409
  const E_PREFIX = 'Unable to list users in the file. ';
@@ -402,7 +419,7 @@ export class FilesSdk extends SdkBase {
402
419
  if (!result.body) {
403
420
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
404
421
  }
405
- let data: IListResponse<IUser>;
422
+ let data: ContextListResult<IUser>;
406
423
  try {
407
424
  data = JSON.parse(result.body);
408
425
  } catch (e) {
@@ -431,12 +448,48 @@ export class FilesSdk extends SdkBase {
431
448
  * @param media Whether to observe changes to the file media instead of meta.
432
449
  * @param request Optional request options.
433
450
  */
434
- async observeFile(key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<WebSocketNode | WebSocket> {
451
+ async observeFile(space: string, key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<WebSocketNode | WebSocket> {
435
452
  const token = request.token || this.sdk.token;
436
453
  const url = this.sdk.getUrl(RouteBuilder.file(key));
454
+ url.searchParams.set('space', space);
437
455
  if (media) {
438
456
  url.searchParams.set('alt', 'media');
439
457
  }
440
458
  return this.sdk.ws.createAndConnect(url.toString(), token);
441
459
  }
460
+
461
+ /**
462
+ * Lists breadcrumbs to the file.
463
+ * @param key The lowest file in the hierarchy
464
+ */
465
+ async breadcrumbs(space: string, key: string, request: ISdkRequestOptions = {}): Promise<ContextListResult<FileBreadcrumb>> {
466
+ const token = request.token || this.sdk.token;
467
+ const url = this.sdk.getUrl(RouteBuilder.fileBreadcrumbs(key));
468
+ url.searchParams.set('space', space);
469
+ const result = await this.sdk.http.get(url.toString(), { token });
470
+ this.inspectCommonStatusCodes(result.status, result.body);
471
+ const E_PREFIX = 'Unable to read a file. ';
472
+ if (result.status !== 200) {
473
+ this.logInvalidResponse(result);
474
+ let e = this.createGenericSdkError(result.body)
475
+ if (!e) {
476
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
477
+ e.response = result.body;
478
+ }
479
+ throw e;
480
+ }
481
+ if (!result.body) {
482
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
483
+ }
484
+ let data: ContextListResult<FileBreadcrumb>;
485
+ try {
486
+ data = JSON.parse(result.body);
487
+ } catch (e) {
488
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
489
+ }
490
+ if (!Array.isArray(data.items)) {
491
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
492
+ }
493
+ return data;
494
+ }
442
495
  }
@@ -1,7 +1,8 @@
1
- import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION, ISdkRequestOptions } from './SdkBase.js';
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 { IListResponse, HistoryListOptions, IHistoryRequestListOptions } from '../../models/store/Backend.js';
4
3
  import { IHttpHistory, IHttpHistoryBulkAdd, Kind as HttpHistoryKind } from '../../models/HttpHistory.js';
4
+ import { ContextChangeRecord, ContextDeleteRecord, ContextListResult, HistoryListOptions, IBulkOperationResult, IHistoryRequestListOptions } from '../../events/BaseEvents.js';
5
+ import { SdkError } from './Errors.js';
5
6
 
6
7
  export class HistorySdk extends SdkBase {
7
8
  /**
@@ -17,7 +18,7 @@ export class HistorySdk extends SdkBase {
17
18
  * @param request Optional request options.
18
19
  * @returns The key of the created history.
19
20
  */
20
- async create(history: IHttpHistory, request: ISdkRequestOptions = {}): Promise<string> {
21
+ async add(history: IHttpHistory, request: ISdkRequestOptions = {}): Promise<ContextChangeRecord<IHttpHistory>> {
21
22
  const token = request.token || this.sdk.token;
22
23
  const url = this.sdk.getUrl(RouteBuilder.history());
23
24
  const body = JSON.stringify(history);
@@ -26,14 +27,26 @@ export class HistorySdk extends SdkBase {
26
27
  const E_PREFIX = 'Unable to create a history. ';
27
28
  if (result.status !== 200) {
28
29
  this.logInvalidResponse(result);
29
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
30
+ let e = this.createGenericSdkError(result.body)
31
+ if (!e) {
32
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
33
+ e.response = result.body;
34
+ }
35
+ throw e;
30
36
  }
31
- const location = result.headers.get('location');
32
- if (!location) {
33
- throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
37
+ if (!result.body) {
38
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
39
+ }
40
+ let data: ContextChangeRecord<IHttpHistory>;
41
+ try {
42
+ data = JSON.parse(result.body);
43
+ } catch (e) {
44
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
34
45
  }
35
- const id = location.split('/').pop();
36
- return id as string;
46
+ if (!data.key) {
47
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
48
+ }
49
+ return data;
37
50
  }
38
51
 
39
52
  /**
@@ -42,7 +55,7 @@ export class HistorySdk extends SdkBase {
42
55
  * @param info The bulk create info object.
43
56
  * @param request Optional request options.
44
57
  */
45
- async createBulk(info: IHttpHistoryBulkAdd, request: ISdkRequestOptions = {}): Promise<string[]> {
58
+ async createBulk(info: IHttpHistoryBulkAdd, request: ISdkRequestOptions = {}): Promise<IBulkOperationResult<ContextChangeRecord<IHttpHistory>>> {
46
59
  const token = request.token || this.sdk.token;
47
60
  const url = this.sdk.getUrl(RouteBuilder.historyBatchCreate());
48
61
  const body = JSON.stringify(info);
@@ -51,17 +64,25 @@ export class HistorySdk extends SdkBase {
51
64
  const E_PREFIX = 'Unable to create a bulk history. ';
52
65
  if (result.status !== 200) {
53
66
  this.logInvalidResponse(result);
54
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
67
+ let e = this.createGenericSdkError(result.body)
68
+ if (!e) {
69
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
70
+ e.response = result.body;
71
+ }
72
+ throw e;
55
73
  }
56
74
  if (!result.body) {
57
75
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
58
76
  }
59
- let data: string[];
77
+ let data: IBulkOperationResult<ContextChangeRecord<IHttpHistory>>;
60
78
  try {
61
79
  data = JSON.parse(result.body).items;
62
80
  } catch (e) {
63
81
  throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
64
82
  }
83
+ if (!data.items) {
84
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
85
+ }
65
86
  return data;
66
87
  }
67
88
 
@@ -71,7 +92,7 @@ export class HistorySdk extends SdkBase {
71
92
  * @param options Optional query options.
72
93
  * @param request Optional request options.
73
94
  */
74
- async list(options: HistoryListOptions, request: ISdkRequestOptions = {}): Promise<IListResponse<IHttpHistory>> {
95
+ async list(options: HistoryListOptions, request: ISdkRequestOptions = {}): Promise<ContextListResult<IHttpHistory>> {
75
96
  const token = request.token || this.sdk.token;
76
97
  const url = this.sdk.getUrl(RouteBuilder.history());
77
98
  this.appendHistoryListParameters(url, options);
@@ -80,12 +101,17 @@ export class HistorySdk extends SdkBase {
80
101
  const E_PREFIX = 'Unable to list history. ';
81
102
  if (result.status !== 200) {
82
103
  this.logInvalidResponse(result);
83
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
104
+ let e = this.createGenericSdkError(result.body)
105
+ if (!e) {
106
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
107
+ e.response = result.body;
108
+ }
109
+ throw e;
84
110
  }
85
111
  if (!result.body) {
86
112
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
87
113
  }
88
- let data: IListResponse<IHttpHistory>;
114
+ let data: ContextListResult<IHttpHistory>;
89
115
  try {
90
116
  data = JSON.parse(result.body);
91
117
  } catch (e) {
@@ -100,6 +126,7 @@ export class HistorySdk extends SdkBase {
100
126
  appendHistoryListParameters(url: URL, options: HistoryListOptions): void {
101
127
  this.sdk.appendListOptions(url, options);
102
128
  const { searchParams } = url;
129
+ searchParams.set('space', options.space);
103
130
  if (options.type) {
104
131
  searchParams.set('type', options.type);
105
132
  }
@@ -121,32 +148,61 @@ export class HistorySdk extends SdkBase {
121
148
  * @param key The key returned by the store when created the history. Also available via the `key` property on the history object.
122
149
  * @param request Optional request options.
123
150
  */
124
- delete(key: string, request?: ISdkRequestOptions): Promise<void>;
125
- /**
126
- * Deletes a list of history objects in a batch operation.
127
- *
128
- * @param keys The keys returned by the store when created the history. Also available via the `key` property on the history object.
129
- * @param request Optional request options.
130
- */
131
- delete(keys: string[], request?: ISdkRequestOptions): Promise<void>;
151
+ async delete(key: string, request: ISdkRequestOptions = {}): Promise<void> {
152
+ const token = request.token || this.sdk.token;
153
+ const path = RouteBuilder.historyItem(key);
154
+ const url = this.sdk.getUrl(path);
155
+
156
+ const result = await this.sdk.http.post(url.toString(), { token });
157
+ this.inspectCommonStatusCodes(result.status);
158
+ const E_PREFIX = 'Unable to delete history. ';
159
+ if (result.status !== 204) {
160
+ this.logInvalidResponse(result);
161
+ let e = this.createGenericSdkError(result.body)
162
+ if (!e) {
163
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
164
+ e.response = result.body;
165
+ }
166
+ throw e;
167
+ }
168
+ }
169
+
132
170
  /**
133
- * Deletes a history or a list of history objects from the store.
134
- * @param key A key or a list of keys.
171
+ * Deletes history in a bulk operation.
172
+ * @param keys The list of keys of history objects to delete.
135
173
  * @param request Optional request options.
174
+ * @returns The list of delete records.
136
175
  */
137
- async delete(key: string | string[], request: ISdkRequestOptions = {}): Promise<void> {
176
+ async deleteBulk(keys: string[], request: ISdkRequestOptions = {}): Promise<IBulkOperationResult<ContextDeleteRecord>> {
138
177
  const token = request.token || this.sdk.token;
139
- const isArray = Array.isArray(key);
140
- const path = isArray ? RouteBuilder.historyBatchDelete() : RouteBuilder.historyItem(key);
178
+ const path = RouteBuilder.historyBatchDelete();
141
179
  const url = this.sdk.getUrl(path);
142
-
143
- const result = isArray ? await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(key) }) : await this.sdk.http.delete(url.toString(), { token });
180
+ const result = await this.sdk.http.post(url.toString(), { token, body: JSON.stringify(keys) });
144
181
  this.inspectCommonStatusCodes(result.status);
145
182
  const E_PREFIX = 'Unable to delete history. ';
146
- if (result.status !== 204) {
183
+ if (result.status !== 200) {
147
184
  this.logInvalidResponse(result);
148
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
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
+ if (!result.body) {
193
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
194
+ }
195
+
196
+ let data: IBulkOperationResult<ContextDeleteRecord>;
197
+ try {
198
+ data = JSON.parse(result.body);
199
+ } catch (e) {
200
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
149
201
  }
202
+ if (!Array.isArray(data.items)) {
203
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
204
+ }
205
+ return data;
150
206
  }
151
207
 
152
208
  /**
@@ -163,7 +219,12 @@ export class HistorySdk extends SdkBase {
163
219
  const E_PREFIX = 'Unable to read a history. ';
164
220
  if (result.status !== 200) {
165
221
  this.logInvalidResponse(result);
166
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
222
+ let e = this.createGenericSdkError(result.body)
223
+ if (!e) {
224
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
225
+ e.response = result.body;
226
+ }
227
+ throw e;
167
228
  }
168
229
  if (!result.body) {
169
230
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
@@ -179,4 +240,55 @@ export class HistorySdk extends SdkBase {
179
240
  }
180
241
  return data;
181
242
  }
243
+
244
+ async clearSpace(spaceKey: string, request: ISdkRequestOptions = {}): Promise<void> {
245
+ const token = request.token || this.sdk.token;
246
+ const url = this.sdk.getUrl(RouteBuilder.historyClear('space', spaceKey));
247
+ const result = await this.sdk.http.delete(url.toString(), { token });
248
+ this.inspectCommonStatusCodes(result.status, result.body);
249
+ const E_PREFIX = 'Unable to clear history for the space. ';
250
+ if (result.status !== 204) {
251
+ this.logInvalidResponse(result);
252
+ let e = this.createGenericSdkError(result.body)
253
+ if (!e) {
254
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
255
+ e.response = result.body;
256
+ }
257
+ throw e;
258
+ }
259
+ }
260
+
261
+ async clearProject(spaceKey: string, projectKey: string, request: ISdkRequestOptions = {}): Promise<void> {
262
+ const token = request.token || this.sdk.token;
263
+ const url = this.sdk.getUrl(RouteBuilder.historyClear('project', spaceKey, projectKey));
264
+ const result = await this.sdk.http.delete(url.toString(), { token });
265
+ this.inspectCommonStatusCodes(result.status, result.body);
266
+ const E_PREFIX = 'Unable to clear history for the project. ';
267
+ if (result.status !== 204) {
268
+ this.logInvalidResponse(result);
269
+ let e = this.createGenericSdkError(result.body)
270
+ if (!e) {
271
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
272
+ e.response = result.body;
273
+ }
274
+ throw e;
275
+ }
276
+ }
277
+
278
+ async clearRequest(spaceKey: string, projectKey: string, requestKey: string, request: ISdkRequestOptions = {}): Promise<void> {
279
+ const token = request.token || this.sdk.token;
280
+ const url = this.sdk.getUrl(RouteBuilder.historyClear('request', spaceKey, projectKey, requestKey));
281
+ const result = await this.sdk.http.delete(url.toString(), { token });
282
+ this.inspectCommonStatusCodes(result.status, result.body);
283
+ const E_PREFIX = 'Unable to clear history for the request. ';
284
+ if (result.status !== 204) {
285
+ this.logInvalidResponse(result);
286
+ let e = this.createGenericSdkError(result.body)
287
+ if (!e) {
288
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
289
+ e.response = result.body;
290
+ }
291
+ throw e;
292
+ }
293
+ }
182
294
  }
@@ -0,0 +1,44 @@
1
+ import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, ISdkRequestOptions } from './SdkBase.js';
2
+ import { RouteBuilder } from './RouteBuilder.js';
3
+ import { ContextListResult, ContextSpaceListOptions } from '../../events/BaseEvents.js';
4
+ import { SdkError } from './Errors.js';
5
+ import { IRevision } from '../../models/store/Revision.js';
6
+
7
+ export class RevisionsSdk extends SdkBase {
8
+ /**
9
+ * Lists revisions for a single file.
10
+ *
11
+ * @param key The id of the file to lists revisions for.
12
+ * @param options The list query options
13
+ */
14
+ async list(key: string, options: ContextSpaceListOptions, request: ISdkRequestOptions = {}): Promise<ContextListResult<IRevision>> {
15
+ const token = request.token || this.sdk.token;
16
+ const url = this.sdk.getUrl(RouteBuilder.fileRevisions(key));
17
+ this.sdk.appendListOptions(url, options);
18
+ const result = await this.sdk.http.get(url.toString(), { token });
19
+ this.inspectCommonStatusCodes(result.status);
20
+ const E_PREFIX = 'Unable to list revisions for a file. ';
21
+ if (result.status !== 200) {
22
+ this.logInvalidResponse(result);
23
+ let e = this.createGenericSdkError(result.body)
24
+ if (!e) {
25
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
26
+ e.response = result.body;
27
+ }
28
+ throw e;
29
+ }
30
+ if (!result.body) {
31
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
32
+ }
33
+ let data: ContextListResult<IRevision>;
34
+ try {
35
+ data = JSON.parse(result.body);
36
+ } catch (e) {
37
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
38
+ }
39
+ if (!Array.isArray(data.items)) {
40
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
41
+ }
42
+ return data;
43
+ }
44
+ }