@api-client/core 0.5.10 → 0.5.14

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 (67) hide show
  1. package/build/browser.d.ts +3 -1
  2. package/build/browser.js +3 -0
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +3 -1
  5. package/build/index.js +3 -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/models/{Backend.d.ts → store/Backend.d.ts} +70 -4
  32. package/build/src/models/store/Backend.js +3 -0
  33. package/build/src/models/store/Backend.js.map +1 -0
  34. package/build/src/runtime/actions/runnable/DeleteCookieRunnable.d.ts +1 -1
  35. package/build/src/runtime/actions/runnable/SetCookieRunnable.d.ts +1 -1
  36. package/build/src/runtime/actions/runnable/SetVariableRunnable.d.ts +1 -1
  37. package/build/src/runtime/http-engine/CoreEngine.d.ts +1 -1
  38. package/build/src/runtime/store/BackendSdk.d.ts +1 -1
  39. package/build/src/runtime/store/FilesSdk.d.ts +11 -4
  40. package/build/src/runtime/store/FilesSdk.js +17 -1
  41. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  42. package/build/src/runtime/store/HistorySdk.d.ts +1 -1
  43. package/build/src/runtime/store/Sdk.d.ts +1 -1
  44. package/build/src/runtime/store/SharedSdk.d.ts +1 -1
  45. package/build/src/runtime/store/UsersSdk.d.ts +1 -1
  46. package/package.json +1 -1
  47. package/src/lib/calculators/DataCalculator.ts +3 -3
  48. package/src/lib/events/Utils.ts +5 -0
  49. package/src/lib/parsers/UriTemplate.ts +494 -0
  50. package/src/lib/parsers/UrlEncoder.ts +51 -0
  51. package/src/models/HttpProject.ts +20 -7
  52. package/src/models/ProjectParent.ts +27 -0
  53. package/src/models/Property.ts +18 -0
  54. package/src/models/Server.ts +32 -1
  55. package/src/models/{Backend.ts → store/Backend.ts} +76 -4
  56. package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +1 -1
  57. package/src/runtime/actions/runnable/SetCookieRunnable.ts +1 -1
  58. package/src/runtime/actions/runnable/SetVariableRunnable.ts +1 -1
  59. package/src/runtime/http-engine/CoreEngine.ts +1 -1
  60. package/src/runtime/store/BackendSdk.ts +1 -1
  61. package/src/runtime/store/FilesSdk.ts +23 -7
  62. package/src/runtime/store/HistorySdk.ts +1 -1
  63. package/src/runtime/store/Sdk.ts +1 -1
  64. package/src/runtime/store/SharedSdk.ts +1 -1
  65. package/src/runtime/store/UsersSdk.ts +1 -1
  66. package/build/src/models/Backend.js +0 -2
  67. package/build/src/models/Backend.js.map +0 -1
@@ -1107,6 +1107,26 @@ export class HttpProject extends ProjectParent {
1107
1107
  return result.reverse();
1108
1108
  }
1109
1109
 
1110
+ /**
1111
+ * @returns Returns the effective environments. If the project has been initialized with an environment then it is returned. Otherwise other environments.
1112
+ */
1113
+ getEnvironments(): Environment[] {
1114
+ if (Array.isArray(this.initEnvironments)) {
1115
+ return this.initEnvironments;
1116
+ }
1117
+ return super.getEnvironments();
1118
+ }
1119
+
1120
+ /**
1121
+ * Finds a definition for an environment regardless of its parent.
1122
+ *
1123
+ * @param key The Key of the environment to find.
1124
+ * @returns The environment definition or undefined if not found.
1125
+ */
1126
+ findEnvironment(key: string): Environment | undefined {
1127
+ return this.definitions.environments.find(i => i.key === key);
1128
+ }
1129
+
1110
1130
  /**
1111
1131
  * Makes a copy of this project.
1112
1132
  */
@@ -1257,13 +1277,6 @@ export class HttpProject extends ProjectParent {
1257
1277
  return this.definitions.schemas;
1258
1278
  }
1259
1279
 
1260
- getEnvironments(): Environment[] {
1261
- if (Array.isArray(this.initEnvironments)) {
1262
- return this.initEnvironments;
1263
- }
1264
- return super.getEnvironments();
1265
- }
1266
-
1267
1280
  /**
1268
1281
  * Iterates over requests in the project.
1269
1282
  */
@@ -110,4 +110,31 @@ export abstract class ProjectParent implements ProjectDefinitionProperty {
110
110
  });
111
111
  return result;
112
112
  }
113
+
114
+ /**
115
+ * @param key The environment key to read.
116
+ */
117
+ getEnvironment(key: string): Environment | undefined {
118
+ const { environments } = this;
119
+ if (!environments.length) {
120
+ return undefined;
121
+ }
122
+ const has = environments.includes(key);
123
+ if (!has) {
124
+ return undefined;
125
+ }
126
+ const project = this.getProject();
127
+ if (!project.definitions.environments) {
128
+ return undefined;
129
+ }
130
+ return project.definitions.environments.find(i => i.key === key);
131
+ }
132
+
133
+ /**
134
+ * This is a link to the `getEnvironments()`. The difference is that on the
135
+ * project level it won't return environments defined with the class initialization.
136
+ */
137
+ listEnvironments(): Environment[] {
138
+ return this.getEnvironments();
139
+ }
113
140
  }
@@ -420,4 +420,22 @@ export class Property {
420
420
  }
421
421
  return result;
422
422
  }
423
+
424
+ /**
425
+ * Maps the list of properties to a single map.
426
+ * It overrides previously defined properties on the map in case of multiple variables with the same name.
427
+ *
428
+ * @param properties The list of properties to map.
429
+ * @returns A map where keys are property names and values are the property values.
430
+ */
431
+ static toMap(properties: (IProperty | Property)[]): Record<string, any> {
432
+ const result: Record<string, any> = {};
433
+ properties.forEach(p => {
434
+ if (p.enabled === false) {
435
+ return;
436
+ }
437
+ result[p.name] = p.value;
438
+ });
439
+ return result;
440
+ }
423
441
  }
@@ -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
  }
@@ -1,4 +1,7 @@
1
1
  /* eslint-disable import/export */
2
+
3
+ import { JsonPatch } from '@api-client/json'
4
+
2
5
  export type BackendMode = 'single-user' | 'multi-user';
3
6
 
4
7
  export interface IBackendInfo {
@@ -16,14 +19,45 @@ export interface IBackendInfo {
16
19
  * @default single-user
17
20
  */
18
21
  mode: BackendMode;
22
+
19
23
  /**
20
- * Optional, the store base path when set on the configuration.
24
+ * Client authentication configuration
21
25
  */
22
- prefix?: string;
26
+ auth: {
27
+ /**
28
+ * The path to the authentication endpoint.
29
+ * This is always populated whether the store is in the single- or multi-user mode.
30
+ */
31
+ path: string;
32
+ /**
33
+ * When configured, the OAuth2 redirect URI.
34
+ */
35
+ redirect?: string;
36
+ /**
37
+ * When configured the type of the authentication protocol.
38
+ */
39
+ type?: string;
40
+ }
41
+
23
42
  /**
24
- * The path to the authentication endpoint.
43
+ * The information about hosting.
25
44
  */
26
- authPath: string;
45
+ hosting: {
46
+ /**
47
+ * Optional, the store base path when set on the configuration.
48
+ */
49
+ prefix?: string;
50
+ /**
51
+ * When configured with the host information, this is the public host name of the store.
52
+ * When using udp to discover the store in the local network, this is the ip address of the machine the store
53
+ * is running on.
54
+ */
55
+ host?: string;
56
+ /**
57
+ * The port number the store operates on.
58
+ */
59
+ port: number;
60
+ }
27
61
  }
28
62
 
29
63
  export interface IBackendCommand {
@@ -205,3 +239,41 @@ export interface IHistoryAppListOptions extends IListOptions {
205
239
  */
206
240
  id: string;
207
241
  }
242
+
243
+ /**
244
+ * An interface describing a schema to be sent to the server
245
+ * when making a patch of a file.
246
+ */
247
+ export interface IPatchInfo {
248
+ /**
249
+ * Auto generated by the client sending the PATCH.
250
+ */
251
+ id: string;
252
+ /**
253
+ * The application id that generated the patch.
254
+ * This is a string that is assigned to each application in the suite.
255
+ * External applications need to use a constant string for their apps.
256
+ */
257
+ app: string;
258
+ /**
259
+ * The version of the application that generated the patch.
260
+ * This can and will be used to handle potential differences between suite applications.
261
+ */
262
+ appVersion: string;
263
+ /**
264
+ * The patch generated by the client.
265
+ */
266
+ patch: JsonPatch;
267
+ }
268
+
269
+ /**
270
+ * A schema sent by the store server in a response to the patch request.
271
+ * It contains an information about the applied patch, the reverse operation associated with it,
272
+ * application information, and the generated by the client patch id.
273
+ */
274
+ export interface IPatchRevision extends IPatchInfo {
275
+ /**
276
+ * The patch to apply to the object to revert the changes.
277
+ */
278
+ revert: JsonPatch;
279
+ }
@@ -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';
@@ -1,6 +1,6 @@
1
1
  import { SdkBase } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
- import { IBackendInfo } from '../../models/Backend.js';
3
+ import { IBackendInfo } from '../../models/store/Backend.js';
4
4
 
5
5
  export class BackendSdk extends SdkBase {
6
6
  /**
@@ -1,8 +1,7 @@
1
1
  import WebSocketNode from 'ws';
2
- import { Patch } from '@api-client/json';
3
2
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION, ISdkRequestOptions } from './SdkBase.js';
4
3
  import { RouteBuilder } from './RouteBuilder.js';
5
- import { IListOptions, IListResponse } from '../../models/Backend.js';
4
+ import { IListOptions, IListResponse, IPatchInfo, IPatchRevision } from '../../models/store/Backend.js';
6
5
  import { AccessOperation } from '../../models/store/Permission.js';
7
6
  import { IUser } from '../../models/store/User.js';
8
7
  import { IFile } from '../../models/store/File.js';
@@ -193,7 +192,7 @@ export class FilesSdk extends SdkBase {
193
192
  * @param value The patch to apply.
194
193
  * @param request Optional request options.
195
194
  */
196
- patch(key: string, value: Patch.JsonPatch, media: false, request?: ISdkRequestOptions): Promise<Patch.JsonPatch>;
195
+ patch(key: string, value: IPatchInfo, media: false, request?: ISdkRequestOptions): Promise<IPatchRevision>;
197
196
 
198
197
  /**
199
198
  * Patches file's content in the store.
@@ -202,7 +201,7 @@ export class FilesSdk extends SdkBase {
202
201
  * @param value The patch to apply.
203
202
  * @param request Optional request options.
204
203
  */
205
- patch(key: string, value: Patch.JsonPatch, media: true, request?: ISdkRequestOptions): Promise<Patch.JsonPatch>;
204
+ patch(key: string, value: IPatchInfo, media: true, request?: ISdkRequestOptions): Promise<IPatchRevision>;
206
205
 
207
206
  /**
208
207
  * Patches a file in the store.
@@ -211,7 +210,7 @@ export class FilesSdk extends SdkBase {
211
210
  * @param request Optional request options.
212
211
  * @returns The JSON patch to revert the change using the `@api-client/json` library
213
212
  */
214
- async patch(key: string, value: Patch.JsonPatch, media?: boolean, request: ISdkRequestOptions = {}): Promise<Patch.JsonPatch> {
213
+ async patch(key: string, value: IPatchInfo, media?: boolean, request: ISdkRequestOptions = {}): Promise<IPatchRevision> {
215
214
  const token = request.token || this.sdk.token;
216
215
  const url = this.sdk.getUrl(RouteBuilder.file(key));
217
216
  if (media) {
@@ -233,16 +232,17 @@ export class FilesSdk extends SdkBase {
233
232
  if (!result.body) {
234
233
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
235
234
  }
236
- let data: any;
235
+ let data: IPatchRevision;
237
236
  try {
238
237
  data = JSON.parse(result.body);
239
238
  } catch (e) {
240
239
  throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
241
240
  }
241
+ // revert is added to the response
242
242
  if (!data.revert) {
243
243
  throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
244
244
  }
245
- return data.revert as Patch.JsonPatch;
245
+ return data;
246
246
  }
247
247
 
248
248
  /**
@@ -338,4 +338,20 @@ export class FilesSdk extends SdkBase {
338
338
  const url = this.sdk.getUrl(RouteBuilder.files());
339
339
  return this.sdk.ws.createAndConnect(url.toString(), token);
340
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
+ }
341
357
  }
@@ -1,6 +1,6 @@
1
1
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION, ISdkRequestOptions } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
- import { IListResponse, HistoryListOptions, IHistoryRequestListOptions } from '../../models/Backend.js';
3
+ import { IListResponse, HistoryListOptions, IHistoryRequestListOptions } from '../../models/store/Backend.js';
4
4
  import { IHttpHistory, IHttpHistoryBulkAdd, Kind as HttpHistoryKind } from '../../models/HttpHistory.js';
5
5
 
6
6
  export class HistorySdk extends SdkBase {
@@ -1,4 +1,4 @@
1
- import { IListOptions } from '../../models/Backend.js';
1
+ import { IListOptions } from '../../models/store/Backend.js';
2
2
  import { Http } from './Http.js';
3
3
  import { WsClient } from './WsClient.js';
4
4
  import { AuthSdk } from './AuthSdk.js';
@@ -1,6 +1,6 @@
1
1
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, ISdkRequestOptions } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
- import { IListOptions, IListResponse } from '../../models/Backend.js';
3
+ import { IListOptions, IListResponse } from '../../models/store/Backend.js';
4
4
  import { Kind as ProjectKind } from '../../models/Project.js';
5
5
  import { Kind as WorkspaceKind } from '../../models/Workspace.js';
6
6
  import { IFile } from '../../models/store/File.js';
@@ -1,6 +1,6 @@
1
1
  import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, ISdkRequestOptions } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
- import { IListOptions, IListResponse } from '../../models/Backend.js';
3
+ import { IListOptions, IListResponse } from '../../models/store/Backend.js';
4
4
  import { IUser } from '../../models/store/User.js';
5
5
 
6
6
  export class UsersSdk extends SdkBase {
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Backend.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Backend.js","sourceRoot":"","sources":["../../../src/models/Backend.ts"],"names":[],"mappings":""}