@opentap/runner-client 1.2.0-beta.3 → 1.2.0-beta.5

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.
@@ -29,6 +29,13 @@ export declare class BaseClient {
29
29
  * @returns Promise of an object
30
30
  */
31
31
  protected request<T>(subject: string, payload?: any, options?: RequestOptions): Promise<T>;
32
+ /**
33
+ * Handle the error
34
+ * @param error
35
+ * @param subject
36
+ * @returns
37
+ */
38
+ private natsErrorHandler;
32
39
  /**
33
40
  * Build the headers' object.
34
41
  * @returns {MsgHdrs} Header object
package/lib/BaseClient.js CHANGED
@@ -45,7 +45,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- import { ErrorResponse, } from './DTOs';
48
+ import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, ListItemType, ProfileGroup, } from './DTOs';
49
49
  import { Empty, ErrorCode, JSONCodec, StringCodec, connect, headers, } from 'nats.ws/cjs/nats.js';
50
50
  var DEFAULT_TIMEOUT = 6000;
51
51
  var BaseClient = /** @class */ (function () {
@@ -123,25 +123,33 @@ var BaseClient = /** @class */ (function () {
123
123
  var jsonCodec = JSONCodec();
124
124
  response = jsonCodec.decode(message.data);
125
125
  }
126
- return _this.isErrorResponse(response)
127
- ? Promise.reject("".concat(JSON.stringify(ErrorResponse.fromJS(response))))
128
- : Promise.resolve(response);
126
+ return _this.isErrorResponse(response) ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response);
129
127
  })
130
- .catch(function (error) {
131
- switch (error === null || error === void 0 ? void 0 : error.code) {
132
- case ErrorCode.NoResponders:
133
- return Promise.reject("No responders to ".concat(subject));
134
- case ErrorCode.Timeout:
135
- return Promise.reject("".concat(subject, " timed out"));
136
- default:
137
- return Promise.reject("".concat(subject, ": ").concat(error));
138
- }
139
- })];
128
+ .catch(function (error) { return Promise.reject(_this.natsErrorHandler(error, subject)); })];
140
129
  case 1: return [2 /*return*/, _a.sent()];
141
130
  }
142
131
  });
143
132
  });
144
133
  };
134
+ /**
135
+ * Handle the error
136
+ * @param error
137
+ * @param subject
138
+ * @returns
139
+ */
140
+ BaseClient.prototype.natsErrorHandler = function (error, subject) {
141
+ var errorResponse = new ErrorResponse(error);
142
+ errorResponse.subject = subject;
143
+ errorResponse.stackTrace = error === null || error === void 0 ? void 0 : error.stack;
144
+ switch (error === null || error === void 0 ? void 0 : error.code) {
145
+ case ErrorCode.NoResponders:
146
+ errorResponse.message = 'No Responders';
147
+ break;
148
+ default:
149
+ errorResponse.message = error.message;
150
+ }
151
+ return errorResponse;
152
+ };
145
153
  /**
146
154
  * Build the headers' object.
147
155
  * @returns {MsgHdrs} Header object
@@ -251,7 +259,7 @@ var BaseClient = /** @class */ (function () {
251
259
  */
252
260
  BaseClient.prototype.error = function () {
253
261
  return function (error) {
254
- throw new Error(error);
262
+ throw error;
255
263
  };
256
264
  };
257
265
  /**
@@ -266,7 +274,14 @@ var BaseClient = /** @class */ (function () {
266
274
  * @returns {{Promise<ComponentSettingsIdentifier[]>}}
267
275
  */
268
276
  BaseClient.prototype.getComponentSettingsOverview = function () {
269
- return this.request('GetComponentSettingsOverview').then(this.success()).catch(this.error());
277
+ return this.request('GetComponentSettingsOverview')
278
+ .then(function (componentSettingsIdentifiers) {
279
+ return componentSettingsIdentifiers.map(function (componentSettingsIdentifier) {
280
+ return ComponentSettingsIdentifier.fromJS(componentSettingsIdentifier);
281
+ });
282
+ })
283
+ .then(this.success())
284
+ .catch(this.error());
270
285
  };
271
286
  /**
272
287
  * Change componentsettings
@@ -277,11 +292,10 @@ var BaseClient = /** @class */ (function () {
277
292
  */
278
293
  BaseClient.prototype.setComponentSettings = function (groupName, name, returnedSettings) {
279
294
  var setComponentSettingsRequest = { groupName: groupName, name: name, returnedSettings: returnedSettings };
280
- return groupName && name && returnedSettings
281
- ? this.request('SetComponentSettings', setComponentSettingsRequest)
282
- .then(this.success())
283
- .catch(this.error())
284
- : Promise.reject('all parameters must be defined');
295
+ return this.request('SetComponentSettings', setComponentSettingsRequest)
296
+ .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
297
+ .then(this.success())
298
+ .catch(this.error());
285
299
  };
286
300
  /**
287
301
  * Retrieve componentsettings
@@ -291,11 +305,10 @@ var BaseClient = /** @class */ (function () {
291
305
  */
292
306
  BaseClient.prototype.getComponentSettings = function (groupName, name) {
293
307
  var getComponentSettingsRequest = { groupName: groupName, name: name };
294
- return groupName && name
295
- ? this.request('GetComponentSettings', getComponentSettingsRequest)
296
- .then(this.success())
297
- .catch(this.error())
298
- : Promise.reject('all parameters must be defined');
308
+ return this.request('GetComponentSettings', getComponentSettingsRequest)
309
+ .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
310
+ .then(this.success())
311
+ .catch(this.error());
299
312
  };
300
313
  /**
301
314
  * Retrieve componentsettings list item
@@ -306,11 +319,10 @@ var BaseClient = /** @class */ (function () {
306
319
  */
307
320
  BaseClient.prototype.getComponentSettingsListItem = function (groupName, name, index) {
308
321
  var getComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index };
309
- return groupName && name
310
- ? this.request('GetComponentSettingsListItem', getComponentSettingsListItemRequest)
311
- .then(this.success())
312
- .catch(this.error())
313
- : Promise.reject('all parameters must be defined');
322
+ return this.request('GetComponentSettingsListItem', getComponentSettingsListItemRequest)
323
+ .then(function (componentSettingsListItem) { return ComponentSettingsListItem.fromJS(componentSettingsListItem); })
324
+ .then(this.success())
325
+ .catch(this.error());
314
326
  };
315
327
  /**
316
328
  * Set componentsettings list item settings
@@ -322,11 +334,10 @@ var BaseClient = /** @class */ (function () {
322
334
  */
323
335
  BaseClient.prototype.setComponentSettingsListItem = function (groupName, name, index, item) {
324
336
  var setComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index, item: item };
325
- return groupName && name && item
326
- ? this.request('SetComponentSettingsListItem', setComponentSettingsListItemRequest)
327
- .then(this.success())
328
- .catch(this.error())
329
- : Promise.reject('all parameters must be defined');
337
+ return this.request('SetComponentSettingsListItem', setComponentSettingsListItemRequest)
338
+ .then(function (componentSettingsListItem) { return ComponentSettingsListItem.fromJS(componentSettingsListItem); })
339
+ .then(this.success())
340
+ .catch(this.error());
330
341
  };
331
342
  /**
332
343
  * Get component setting data grid
@@ -343,11 +354,10 @@ var BaseClient = /** @class */ (function () {
343
354
  index: index,
344
355
  propertyName: propertyName,
345
356
  };
346
- return groupName && name && propertyName
347
- ? this.request('GetComponentSettingDataGrid', getComponentSettingDataGridRequest)
348
- .then(this.success())
349
- .catch(this.error())
350
- : Promise.reject('all parameters must be defined');
357
+ return this.request('GetComponentSettingDataGrid', getComponentSettingDataGridRequest)
358
+ .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
359
+ .then(this.success())
360
+ .catch(this.error());
351
361
  };
352
362
  /**
353
363
  * Set component setting data grid
@@ -366,11 +376,10 @@ var BaseClient = /** @class */ (function () {
366
376
  propertyName: propertyName,
367
377
  dataGridControl: dataGridControl,
368
378
  };
369
- return groupName && name && propertyName && dataGridControl
370
- ? this.request('SetComponentSettingDataGrid', setComponentSettingDataGridRequest)
371
- .then(this.success())
372
- .catch(this.error())
373
- : Promise.reject('all parameters must be defined');
379
+ return this.request('SetComponentSettingDataGrid', setComponentSettingDataGridRequest)
380
+ .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
381
+ .then(this.success())
382
+ .catch(this.error());
374
383
  };
375
384
  /**
376
385
  * Add component setting item type to data grid
@@ -389,11 +398,10 @@ var BaseClient = /** @class */ (function () {
389
398
  propertyName: propertyName,
390
399
  typeName: typeName,
391
400
  };
392
- return groupName && name && propertyName && typeName
393
- ? this.request('AddComponentSettingDataGridItemType', addComponentSettingDataGridItemTypeRequest)
394
- .then(this.success())
395
- .catch(this.error())
396
- : Promise.reject('all parameters must be defined');
401
+ return this.request('AddComponentSettingDataGridItemType', addComponentSettingDataGridItemTypeRequest)
402
+ .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
403
+ .then(this.success())
404
+ .catch(this.error());
397
405
  };
398
406
  /**
399
407
  * Add component setting item to data grid
@@ -410,11 +418,10 @@ var BaseClient = /** @class */ (function () {
410
418
  index: index,
411
419
  propertyName: propertyName,
412
420
  };
413
- return groupName && name && propertyName
414
- ? this.request('AddComponentSettingDataGridItem', getComponentSettingDataGridRequest)
415
- .then(this.success())
416
- .catch(this.error())
417
- : Promise.reject('all parameters must be defined');
421
+ return this.request('AddComponentSettingDataGridItem', getComponentSettingDataGridRequest)
422
+ .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
423
+ .then(this.success())
424
+ .catch(this.error());
418
425
  };
419
426
  /**
420
427
  * Get item types available in the component setting data grid
@@ -431,11 +438,10 @@ var BaseClient = /** @class */ (function () {
431
438
  index: index,
432
439
  propertyName: propertyName,
433
440
  };
434
- return groupName && name && propertyName
435
- ? this.request('GetComponentSettingDataGridTypes', getComponentSettingDataGridRequest)
436
- .then(this.success())
437
- .catch(this.error())
438
- : Promise.reject('all parameters must be defined');
441
+ return this.request('GetComponentSettingDataGridTypes', getComponentSettingDataGridRequest)
442
+ .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return ListItemType.fromJS(listItemType); }); })
443
+ .then(this.success())
444
+ .catch(this.error());
439
445
  };
440
446
  /**
441
447
  * Change componentsettings profiles
@@ -443,16 +449,20 @@ var BaseClient = /** @class */ (function () {
443
449
  * @returns {Promise<ProfileGroup[]>}
444
450
  */
445
451
  BaseClient.prototype.setComponentSettingsProfiles = function (returnedSettings) {
446
- return returnedSettings
447
- ? this.request('SetComponentSettingsProfiles', returnedSettings).then(this.success()).catch(this.error())
448
- : Promise.reject('returnedSettings must be defined');
452
+ return this.request('SetComponentSettingsProfiles', returnedSettings)
453
+ .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return ProfileGroup.fromJS(profileGroup); }); })
454
+ .then(this.success())
455
+ .catch(this.error());
449
456
  };
450
457
  /**
451
458
  * Get componentsettings profiles
452
459
  * @returns {Promise<ProfileGroup[]>}
453
460
  */
454
461
  BaseClient.prototype.getComponentSettingsProfiles = function () {
455
- return this.request('GetComponentSettingsProfiles').then(this.success()).catch(this.error());
462
+ return this.request('GetComponentSettingsProfiles')
463
+ .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return ProfileGroup.fromJS(profileGroup); }); })
464
+ .then(this.success())
465
+ .catch(this.error());
456
466
  };
457
467
  /**
458
468
  * Upload exported OpenTAP Settings files
@@ -471,11 +481,10 @@ var BaseClient = /** @class */ (function () {
471
481
  * @returns {Promise<ErrorResponse[]>}
472
482
  */
473
483
  BaseClient.prototype.loadComponentSettingsFromRepository = function (packageReference) {
474
- return packageReference
475
- ? this.request('LoadComponentSettingsFromRepository', packageReference)
476
- .then(this.success())
477
- .catch(this.error())
478
- : Promise.reject('packageReference must be defined');
484
+ return this.request('LoadComponentSettingsFromRepository', packageReference)
485
+ .then(function (errorResponses) { return errorResponses.map(function (errorResponse) { return ErrorResponse.fromJS(errorResponse); }); })
486
+ .then(this.success())
487
+ .catch(this.error());
479
488
  };
480
489
  /**
481
490
  * Save a TapPackage containing component settings in a package repository
@@ -495,11 +504,10 @@ var BaseClient = /** @class */ (function () {
495
504
  */
496
505
  BaseClient.prototype.getComponentSettingsListAvailableTypes = function (groupName, name) {
497
506
  var getComponentSettingsRequest = { groupName: groupName, name: name };
498
- return groupName && name
499
- ? this.request('GetComponentSettingsListAvailableTypes', getComponentSettingsRequest)
500
- .then(this.success())
501
- .catch(this.error())
502
- : Promise.reject('all parameters must be defined');
507
+ return this.request('GetComponentSettingsListAvailableTypes', getComponentSettingsRequest)
508
+ .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return ListItemType.fromJS(listItemType); }); })
509
+ .then(this.success())
510
+ .catch(this.error());
503
511
  };
504
512
  /**
505
513
  * Adds a new item to a component settings list
@@ -510,11 +518,10 @@ var BaseClient = /** @class */ (function () {
510
518
  */
511
519
  BaseClient.prototype.addComponentSettingsListItem = function (groupName, name, typeName) {
512
520
  var addComponentSettingsListItemRequest = { groupName: groupName, name: name, typeName: typeName };
513
- return groupName && name && typeName
514
- ? this.request('AddComponentSettingsListItem', addComponentSettingsListItemRequest)
515
- .then(this.success())
516
- .catch(this.error())
517
- : Promise.reject('all parameters must be defined');
521
+ return this.request('AddComponentSettingsListItem', addComponentSettingsListItemRequest)
522
+ .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return ListItemType.fromJS(listItemType); }); })
523
+ .then(this.success())
524
+ .catch(this.error());
518
525
  };
519
526
  /**
520
527
  * Get settings package files
package/lib/DTOs.d.ts CHANGED
@@ -37,6 +37,7 @@ export declare class ErrorResponse implements IErrorResponse {
37
37
  source?: string | undefined;
38
38
  stackTrace?: string | undefined;
39
39
  inner?: ErrorResponse | undefined;
40
+ subject?: string | undefined;
40
41
  constructor(data?: IErrorResponse);
41
42
  init(_data?: any): void;
42
43
  static fromJS(data: any): ErrorResponse;
package/lib/index.d.ts CHANGED
@@ -2,3 +2,5 @@ export { RunnerClient } from './RunnerClient';
2
2
  export { SessionClient } from './SessionClient';
3
3
  export * from './DTOs';
4
4
  export * from 'nats.ws/lib/nats-base-client/types';
5
+ export * from 'nats.ws/lib/nats-base-client/authenticator';
6
+ export * from 'nats.ws/lib/nats-base-client/error';
package/lib/index.js CHANGED
@@ -2,3 +2,5 @@ export { RunnerClient } from './RunnerClient';
2
2
  export { SessionClient } from './SessionClient';
3
3
  export * from './DTOs';
4
4
  export * from 'nats.ws/lib/nats-base-client/types'; // TODO: Delete this line if you are consuming this library in angular > v11. The types export will be done automatically.
5
+ export * from 'nats.ws/lib/nats-base-client/authenticator';
6
+ export * from 'nats.ws/lib/nats-base-client/error';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "1.2.0-beta.3",
3
+ "version": "1.2.0-beta.5",
4
4
  "description": "This is the TypeScript Client for the OpenTAP Runner Plugin.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",