@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.
- package/build/browser.d.ts +2 -0
- package/build/browser.js +2 -0
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/src/lib/calculators/DataCalculator.d.ts +3 -3
- package/build/src/lib/calculators/DataCalculator.js +3 -3
- package/build/src/lib/calculators/DataCalculator.js.map +1 -1
- package/build/src/lib/events/Utils.d.ts +1 -0
- package/build/src/lib/events/Utils.js +6 -0
- package/build/src/lib/events/Utils.js.map +1 -0
- package/build/src/lib/parsers/UriTemplate.d.ts +94 -0
- package/build/src/lib/parsers/UriTemplate.js +419 -0
- package/build/src/lib/parsers/UriTemplate.js.map +1 -0
- package/build/src/lib/parsers/UrlEncoder.d.ts +5 -0
- package/build/src/lib/parsers/UrlEncoder.js +49 -0
- package/build/src/lib/parsers/UrlEncoder.js.map +1 -1
- package/build/src/models/HttpProject.d.ts +11 -1
- package/build/src/models/HttpProject.js +18 -6
- package/build/src/models/HttpProject.js.map +1 -1
- package/build/src/models/ProjectParent.d.ts +9 -0
- package/build/src/models/ProjectParent.js +25 -0
- package/build/src/models/ProjectParent.js.map +1 -1
- package/build/src/models/Property.d.ts +8 -0
- package/build/src/models/Property.js +17 -0
- package/build/src/models/Property.js.map +1 -1
- package/build/src/models/Server.d.ts +14 -1
- package/build/src/models/Server.js +31 -1
- package/build/src/models/Server.js.map +1 -1
- package/build/src/runtime/actions/runnable/DeleteCookieRunnable.d.ts +1 -1
- package/build/src/runtime/actions/runnable/SetCookieRunnable.d.ts +1 -1
- package/build/src/runtime/actions/runnable/SetVariableRunnable.d.ts +1 -1
- package/build/src/runtime/http-engine/CoreEngine.d.ts +1 -1
- package/build/src/runtime/store/FilesSdk.d.ts +16 -0
- package/build/src/runtime/store/FilesSdk.js +53 -0
- package/build/src/runtime/store/FilesSdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +4 -0
- package/build/src/runtime/store/RouteBuilder.js +6 -0
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/calculators/DataCalculator.ts +3 -3
- package/src/lib/events/Utils.ts +5 -0
- package/src/lib/parsers/UriTemplate.ts +494 -0
- package/src/lib/parsers/UrlEncoder.ts +51 -0
- package/src/models/HttpProject.ts +20 -7
- package/src/models/ProjectParent.ts +27 -0
- package/src/models/Property.ts +18 -0
- package/src/models/Server.ts +32 -1
- package/src/runtime/actions/runnable/DeleteCookieRunnable.ts +1 -1
- package/src/runtime/actions/runnable/SetCookieRunnable.ts +1 -1
- package/src/runtime/actions/runnable/SetVariableRunnable.ts +1 -1
- package/src/runtime/http-engine/CoreEngine.ts +1 -1
- package/src/runtime/store/FilesSdk.ts +54 -0
- package/src/runtime/store/RouteBuilder.ts +7 -0
package/src/models/Server.ts
CHANGED
|
@@ -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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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
|
}
|