@opentap/runner-client 1.0.0-beta.75 → 1.0.0-beta.76

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.
@@ -2,23 +2,13 @@ import { ConnectionOptions, RequestOptions } from 'nats.ws/cjs/nats.js';
2
2
  import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileParameter, FileResponse, ListItemType, ProfileGroup, RepositoryPackageReference, RepositorySettingsPackageDefinition, SettingsTapPackage } from './DTOs';
3
3
  export declare class BaseClient {
4
4
  private connection;
5
- private domainAccess;
6
- private _accessToken;
7
- /** Get access token */
8
- get accessToken(): string;
9
- /** Set access token */
10
- set accessToken(value: string);
5
+ private baseSubject;
6
+ private connectionOptions;
11
7
  private _timeout;
12
8
  /** Get timeout */
13
9
  get timeout(): number;
14
10
  /** Set timeout */
15
11
  set timeout(value: number);
16
- private _baseSubject;
17
- /** Get subject */
18
- get baseSubject(): string;
19
- private _connectionOptions;
20
- /** Get connection options */
21
- get connectionOptions(): ConnectionOptions;
22
12
  constructor(baseSubject: string, options: ConnectionOptions);
23
13
  /**
24
14
  * Send a request to the nats server.
@@ -38,7 +28,7 @@ export declare class BaseClient {
38
28
  * Create a connection to the nats server.
39
29
  * @param {ConnectionOptions} options
40
30
  */
41
- private connect;
31
+ connect(): Promise<void>;
42
32
  /**
43
33
  * Close the connection.
44
34
  */
@@ -48,7 +38,6 @@ export declare class BaseClient {
48
38
  * @param domain
49
39
  * @param accessToken
50
40
  */
51
- protected setDomainAccessToken(domain: string, accessToken: string): void;
52
41
  /**
53
42
  * Generic error callback function.
54
43
  * @returns
package/lib/BaseClient.js CHANGED
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,32 +48,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
48
  // ! import { connect, ConnectionOptions, Empty, JSONCodec, NatsConnection, RequestOptions, StringCodec } from 'nats.ws' if consuming this library in angular >= 13.
38
49
  import { connect, Empty, ErrorCode, JSONCodec, StringCodec } from 'nats.ws/cjs/nats.js';
39
50
  import { ErrorResponse, } from './DTOs';
51
+ var DEFAULT_TIMEOUT = 6000;
40
52
  var BaseClient = /** @class */ (function () {
41
53
  function BaseClient(baseSubject, options) {
42
- this.domainAccess = new Map();
43
- this._baseSubject = baseSubject;
44
- this._connectionOptions = options || { servers: 'ws://localhost:443' };
45
- var undefinedSubject = function () {
46
- throw new Error('A base subject must be specified');
47
- };
48
- baseSubject ? this.connect(this._connectionOptions) : undefinedSubject();
54
+ //this.domainAccess = new Map<string, string>();
55
+ this.baseSubject = baseSubject;
56
+ this.connectionOptions = __assign({}, options) || {};
57
+ this.connectionOptions.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || DEFAULT_TIMEOUT;
49
58
  }
50
- Object.defineProperty(BaseClient.prototype, "accessToken", {
51
- /** Get access token */
52
- get: function () {
53
- return this._accessToken;
54
- },
55
- /** Set access token */
56
- set: function (value) {
57
- this._accessToken = value;
58
- },
59
- enumerable: false,
60
- configurable: true
61
- });
62
59
  Object.defineProperty(BaseClient.prototype, "timeout", {
63
60
  /** Get timeout */
64
61
  get: function () {
65
- return this._timeout;
62
+ return this._timeout || DEFAULT_TIMEOUT;
66
63
  },
67
64
  /** Set timeout */
68
65
  set: function (value) {
@@ -71,22 +68,6 @@ var BaseClient = /** @class */ (function () {
71
68
  enumerable: false,
72
69
  configurable: true
73
70
  });
74
- Object.defineProperty(BaseClient.prototype, "baseSubject", {
75
- /** Get subject */
76
- get: function () {
77
- return this._baseSubject;
78
- },
79
- enumerable: false,
80
- configurable: true
81
- });
82
- Object.defineProperty(BaseClient.prototype, "connectionOptions", {
83
- /** Get connection options */
84
- get: function () {
85
- return this._connectionOptions;
86
- },
87
- enumerable: false,
88
- configurable: true
89
- });
90
71
  /**
91
72
  * Send a request to the nats server.
92
73
  * @param subject The subject to request
@@ -96,7 +77,7 @@ var BaseClient = /** @class */ (function () {
96
77
  */
97
78
  BaseClient.prototype.request = function (subject, payload, options) {
98
79
  return __awaiter(this, void 0, void 0, function () {
99
- var stringCodec, data;
80
+ var stringCodec, data, opts;
100
81
  var _this = this;
101
82
  return __generator(this, function (_a) {
102
83
  switch (_a.label) {
@@ -104,14 +85,15 @@ var BaseClient = /** @class */ (function () {
104
85
  if (!subject)
105
86
  return [2 /*return*/, Promise.reject('Subject is not defined!')];
106
87
  if (!this.connection)
107
- return [2 /*return*/, Promise.reject('Connection is down! Please try again!')];
88
+ return [2 /*return*/, Promise.reject('Connection is not up yet! Please try again later!')];
108
89
  if (this.connection.isClosed())
109
90
  return [2 /*return*/, Promise.reject('Connection has been closed! Please reconnect!')];
110
91
  subject = "".concat(this.baseSubject, ".Request.").concat(subject);
111
92
  stringCodec = StringCodec();
112
93
  data = payload ? stringCodec.encode(JSON.stringify(payload)) : Empty;
94
+ opts = __assign(__assign({}, options), { timeout: this.timeout });
113
95
  return [4 /*yield*/, this.connection
114
- .request(subject, data, options)
96
+ .request(subject, data, opts)
115
97
  .then(function (message) {
116
98
  var jsonCodec = JSONCodec();
117
99
  var response = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
@@ -146,24 +128,31 @@ var BaseClient = /** @class */ (function () {
146
128
  * Create a connection to the nats server.
147
129
  * @param {ConnectionOptions} options
148
130
  */
149
- BaseClient.prototype.connect = function (options) {
131
+ BaseClient.prototype.connect = function () {
150
132
  return __awaiter(this, void 0, void 0, function () {
151
133
  var error_1;
152
134
  var _this = this;
153
135
  return __generator(this, function (_a) {
154
136
  switch (_a.label) {
155
137
  case 0:
156
- _a.trys.push([0, 2, , 3]);
157
- return [4 /*yield*/, connect(options).then(function (connection) {
158
- _this.connection = connection;
159
- })];
138
+ if (!this.baseSubject)
139
+ return [2 /*return*/, Promise.reject('Subject must be given')];
140
+ if (this.connection)
141
+ return [2 /*return*/, Promise.resolve()];
142
+ _a.label = 1;
160
143
  case 1:
161
- _a.sent();
162
- return [3 /*break*/, 3];
163
- case 2:
144
+ _a.trys.push([1, 3, , 4]);
145
+ return [4 /*yield*/, connect(this.connectionOptions)
146
+ .then(function (connection) {
147
+ _this.connection = connection;
148
+ return Promise.resolve();
149
+ })
150
+ .catch(function (error) { return Promise.reject("Failed to connect to ".concat(_this.connectionOptions.servers, " with ").concat(error)); })];
151
+ case 2: return [2 /*return*/, _a.sent()];
152
+ case 3:
164
153
  error_1 = _a.sent();
165
- throw new Error("connection to ".concat(options.servers, " failed due to ").concat(error_1));
166
- case 3: return [2 /*return*/];
154
+ return [2 /*return*/, Promise.reject("Failed to connect to ".concat(this.connectionOptions.servers, " with ").concat(error_1))];
155
+ case 4: return [2 /*return*/];
167
156
  }
168
157
  });
169
158
  });
@@ -194,11 +183,11 @@ var BaseClient = /** @class */ (function () {
194
183
  * @param domain
195
184
  * @param accessToken
196
185
  */
197
- BaseClient.prototype.setDomainAccessToken = function (domain, accessToken) {
198
- if (!domain)
199
- return;
186
+ /* protected setDomainAccessToken(domain: string, accessToken: string): void {
187
+ if (!domain) return;
188
+
200
189
  this.domainAccess.set(domain, accessToken);
201
- };
190
+ } */
202
191
  /**
203
192
  * Generic error callback function.
204
193
  * @returns
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { RunnerClient } from './RunnerClient';
2
2
  export { SessionClient } from './SessionClient';
3
3
  export * from './DTOs';
4
+ export * from 'nats.ws/lib/nats-base-client/types';
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { RunnerClient } from './RunnerClient';
2
2
  export { SessionClient } from './SessionClient';
3
3
  export * from './DTOs';
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "1.0.0-beta.75",
3
+ "version": "1.0.0-beta.76",
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",