@api-client/core 0.5.9 → 0.5.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.
Files changed (55) hide show
  1. package/build/browser.d.ts +2 -0
  2. package/build/browser.js +2 -0
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +2 -0
  5. package/build/index.js +2 -0
  6. package/build/index.js.map +1 -1
  7. package/build/src/lib/calculators/DataCalculator.d.ts +3 -3
  8. package/build/src/lib/calculators/DataCalculator.js +3 -3
  9. package/build/src/lib/calculators/DataCalculator.js.map +1 -1
  10. package/build/src/lib/events/Utils.d.ts +1 -0
  11. package/build/src/lib/events/Utils.js +6 -0
  12. package/build/src/lib/events/Utils.js.map +1 -0
  13. package/build/src/lib/parsers/UriTemplate.d.ts +94 -0
  14. package/build/src/lib/parsers/UriTemplate.js +419 -0
  15. package/build/src/lib/parsers/UriTemplate.js.map +1 -0
  16. package/build/src/lib/parsers/UrlEncoder.d.ts +5 -0
  17. package/build/src/lib/parsers/UrlEncoder.js +49 -0
  18. package/build/src/lib/parsers/UrlEncoder.js.map +1 -1
  19. package/build/src/models/HttpProject.d.ts +11 -1
  20. package/build/src/models/HttpProject.js +18 -6
  21. package/build/src/models/HttpProject.js.map +1 -1
  22. package/build/src/models/ProjectParent.d.ts +9 -0
  23. package/build/src/models/ProjectParent.js +25 -0
  24. package/build/src/models/ProjectParent.js.map +1 -1
  25. package/build/src/models/Property.d.ts +8 -0
  26. package/build/src/models/Property.js +17 -0
  27. package/build/src/models/Property.js.map +1 -1
  28. package/build/src/models/Server.d.ts +14 -1
  29. package/build/src/models/Server.js +31 -1
  30. package/build/src/models/Server.js.map +1 -1
  31. package/build/src/runtime/actions/runnable/DeleteCookieRunnable.d.ts +1 -1
  32. package/build/src/runtime/actions/runnable/SetCookieRunnable.d.ts +1 -1
  33. package/build/src/runtime/actions/runnable/SetVariableRunnable.d.ts +1 -1
  34. package/build/src/runtime/http-engine/CoreEngine.d.ts +1 -1
  35. package/build/src/runtime/store/FilesSdk.d.ts +16 -0
  36. package/build/src/runtime/store/FilesSdk.js +53 -0
  37. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  38. package/build/src/runtime/store/RouteBuilder.d.ts +4 -0
  39. package/build/src/runtime/store/RouteBuilder.js +6 -0
  40. package/build/src/runtime/store/RouteBuilder.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/lib/calculators/DataCalculator.ts +3 -3
  43. package/src/lib/events/Utils.ts +5 -0
  44. package/src/lib/parsers/UriTemplate.ts +494 -0
  45. package/src/lib/parsers/UrlEncoder.ts +51 -0
  46. package/src/models/HttpProject.ts +20 -7
  47. package/src/models/ProjectParent.ts +27 -0
  48. package/src/models/Property.ts +18 -0
  49. package/src/models/Server.ts +32 -1
  50. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +1 -1
  51. package/src/runtime/actions/runnable/SetCookieRunnable.ts +1 -1
  52. package/src/runtime/actions/runnable/SetVariableRunnable.ts +1 -1
  53. package/src/runtime/http-engine/CoreEngine.ts +1 -1
  54. package/src/runtime/store/FilesSdk.ts +54 -0
  55. package/src/runtime/store/RouteBuilder.ts +7 -0
@@ -1,3 +1,6 @@
1
+ import { IProperty, Property } from './Property.js';
2
+ import { UriTemplate } from '../lib/parsers/UriTemplate.js';
3
+
1
4
  export const Kind = 'Core#Server';
2
5
 
3
6
  export interface IServer {
@@ -129,8 +132,10 @@ export class Server {
129
132
 
130
133
  /**
131
134
  * Constructs the final URI from the server configuration.
135
+ *
136
+ * @param variables When set it evaluates the generated URI against these variables
132
137
  */
133
- readUri(): string {
138
+ readUri(variables?: (IProperty | Property)[]): string {
134
139
  const { uri, protocol, basePath } = this;
135
140
  let result = '';
136
141
  if (!uri) {
@@ -148,6 +153,32 @@ export class Server {
148
153
  }
149
154
  result += basePath.startsWith('/') ? basePath : `/${basePath}`
150
155
  }
156
+ if (variables) {
157
+ return this.evaluateUri(result, variables);
158
+ }
159
+ return result;
160
+ }
161
+
162
+ /**
163
+ * Evaluates the URI against the variables.
164
+ *
165
+ * Note, this doesn't throw errors. When error occurs it returns the input string.
166
+ *
167
+ * @param uri The URI to process
168
+ * @param variables The list of variables to use
169
+ * @returns Expanded URI.
170
+ */
171
+ protected evaluateUri(uri: string, variables: (IProperty | Property)[]): string {
172
+ if (!variables || !variables.length) {
173
+ return uri;
174
+ }
175
+ let result = uri;
176
+ try {
177
+ const map = Property.toMap(variables);
178
+ result = new UriTemplate(uri).expand(map, { ignoreMissing: true });
179
+ } catch (e) {
180
+ //
181
+ }
151
182
  return result;
152
183
  }
153
184
  }
@@ -2,7 +2,7 @@ import { IHttpRequest } from 'src/models/HttpRequest.js';
2
2
  import { ActionRunnable } from './ActionRunnable.js';
3
3
  import { IDeleteCookieAction } from '../../../models/actions/runnable/DeleteCookieAction.js';
4
4
  import { Events } from '../../../events/Events.js';
5
- import { IRequestLog } from 'src/models/RequestLog.js';
5
+ import { IRequestLog } from '../../../models/RequestLog.js';
6
6
 
7
7
  export class DeleteCookieRunnable extends ActionRunnable {
8
8
  async response(log: IRequestLog): Promise<void> {
@@ -4,7 +4,7 @@ import { ActionRunnable } from './ActionRunnable.js';
4
4
  import { ISetCookieAction } from '../../../models/actions/runnable/SetCookieAction.js';
5
5
  import { Events } from '../../../events/Events.js';
6
6
  import { RequestDataExtractor } from '../../../data/RequestDataExtractor.js';
7
- import { IRequestLog } from 'src/models/RequestLog.js';
7
+ import { IRequestLog } from '../../../models/RequestLog.js';
8
8
 
9
9
  export class SetCookieRunnable extends ActionRunnable {
10
10
  async request(request: IHttpRequest): Promise<void> {
@@ -3,7 +3,7 @@ import { ActionRunnable } from './ActionRunnable.js';
3
3
  import { ISetVariableAction } from '../../../models/actions/runnable/SetVariableAction.js';
4
4
  import { Events } from '../../../events/Events.js';
5
5
  import { RequestDataExtractor } from '../../../data/RequestDataExtractor.js';
6
- import { IRequestLog } from 'src/models/RequestLog.js';
6
+ import { IRequestLog } from '../../../models/RequestLog.js';
7
7
 
8
8
  export class SetVariableRunnable extends ActionRunnable {
9
9
  async request(request: IHttpRequest): Promise<void> {
@@ -3,7 +3,7 @@ import tls from 'tls';
3
3
  import http from 'http';
4
4
  import https from 'https';
5
5
  import { HttpEngine, HttpEngineOptions, HeadersReceivedDetail } from './HttpEngine.js';
6
- import { IRequestLog } from 'src/models/RequestLog.js';
6
+ import { IRequestLog } from '../../models/RequestLog.js';
7
7
  import { IHttpRequest } from '../../models/HttpRequest.js';
8
8
  import { Response } from '../../models/Response.js';
9
9
  import { SerializableError } from '../../models/SerializableError.js';
@@ -148,6 +148,44 @@ export class FilesSdk extends SdkBase {
148
148
  return data;
149
149
  }
150
150
 
151
+ /**
152
+ * Reads a number of files in a bulk operation.
153
+ *
154
+ * @param keys The list of keys to read. When the user has no access to the file it returns undefined
155
+ * in that place. It also inserts `undefined` in place of a file that doesn't exist.
156
+ * @param request Optional request options.
157
+ */
158
+ async readBulk(keys: string[], request: ISdkRequestOptions = {}): Promise<IListResponse<IFile|undefined>> {
159
+ const token = request.token || this.sdk.token;
160
+ const url = this.sdk.getUrl(RouteBuilder.filesBulk());
161
+ const body = JSON.stringify(keys);
162
+ const result = await this.sdk.http.post(url.toString(), { token, body });
163
+ this.inspectCommonStatusCodes(result.status, result.body);
164
+ const E_PREFIX = 'Unable to read files in bulk. ';
165
+ if (result.status !== 200) {
166
+ this.logInvalidResponse(result);
167
+ let e = this.createGenericSdkError(result.body)
168
+ if (!e) {
169
+ e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
170
+ e.response = result.body;
171
+ }
172
+ throw e;
173
+ }
174
+ if (!result.body) {
175
+ throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
176
+ }
177
+ let data: IListResponse<IFile | undefined>;
178
+ try {
179
+ data = JSON.parse(result.body);
180
+ } catch (e) {
181
+ throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
182
+ }
183
+ if (!Array.isArray(data.data)) {
184
+ throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
185
+ }
186
+ return data;
187
+ }
188
+
151
189
  /**
152
190
  * Patches file's meta in the store.
153
191
  *
@@ -300,4 +338,20 @@ export class FilesSdk extends SdkBase {
300
338
  const url = this.sdk.getUrl(RouteBuilder.files());
301
339
  return this.sdk.ws.createAndConnect(url.toString(), token);
302
340
  }
341
+
342
+ /**
343
+ * Creates a WS client that listens to the file events.
344
+ *
345
+ * @param key The file key to observe
346
+ * @param media Whether to observe changes to the file media instead of meta.
347
+ * @param request Optional request options.
348
+ */
349
+ async observeFile(key: string, media?: boolean, request: ISdkRequestOptions = {}): Promise<WebSocketNode | WebSocket> {
350
+ const token = request.token || this.sdk.token;
351
+ const url = this.sdk.getUrl(RouteBuilder.file(key));
352
+ if (media) {
353
+ url.searchParams.set('alt', 'media');
354
+ }
355
+ return this.sdk.ws.createAndConnect(url.toString(), token);
356
+ }
303
357
  }
@@ -9,6 +9,13 @@ export class RouteBuilder {
9
9
  return '/files';
10
10
  }
11
11
 
12
+ /**
13
+ * @returns The path to the /files/bulk route.
14
+ */
15
+ static filesBulk(): string {
16
+ return '/files/bulk';
17
+ }
18
+
12
19
  /**
13
20
  * @returns The path to the /files/[id] route.
14
21
  */