@opentap/runner-client 4.0.0 → 4.2.0

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.
@@ -6,6 +6,9 @@ interface BaseClientRequestOptions {
6
6
  rawResponse?: boolean;
7
7
  fullSubject?: boolean;
8
8
  timeout?: number;
9
+ headers?: {
10
+ [key: string]: string;
11
+ };
9
12
  }
10
13
  export declare class BaseClient {
11
14
  readonly baseSubject: string;
@@ -102,8 +102,13 @@ var BaseClient = /** @class */ (function () {
102
102
  enumerable: false,
103
103
  configurable: true
104
104
  });
105
- BaseClient.prototype.withTimeout = function (promise, timeout) {
106
- return Promise.race([promise, new Promise(function (_, reject) { return setTimeout(function () { return reject(new Error(nats_ws_1.ErrorCode.Timeout)); }, timeout); })]);
105
+ BaseClient.prototype.withTimeout = function (promise, timeout, subject) {
106
+ return Promise.race([
107
+ promise,
108
+ new Promise(function (_, reject) {
109
+ return setTimeout(function () { return reject(new Error("".concat(nats_ws_1.ErrorCode.Timeout, ": '").concat(subject, "' timed out after ").concat(timeout, "ms"))); }, timeout);
110
+ }),
111
+ ]);
107
112
  };
108
113
  /**
109
114
  * Send a request to the nats server.
@@ -128,6 +133,12 @@ var BaseClient = /** @class */ (function () {
128
133
  return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
129
134
  data = this.encode(payload);
130
135
  headers = this.buildHeaders();
136
+ if (options === null || options === void 0 ? void 0 : options.headers) {
137
+ Object.entries(options.headers).forEach(function (_a) {
138
+ var key = _a[0], value = _a[1];
139
+ return headers.append(key, value);
140
+ });
141
+ }
131
142
  timeout = (options === null || options === void 0 ? void 0 : options.timeout) || this.timeout;
132
143
  replySubject = (_b = (_a = options === null || options === void 0 ? void 0 : options.publishOptions) === null || _a === void 0 ? void 0 : _a.reply) !== null && _b !== void 0 ? _b : "".concat(subject, ".Reply.").concat((0, uuid_1.v4)());
133
144
  serverMaxPayload = (_d = (_c = this.connection) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.max_payload;
@@ -217,7 +228,7 @@ var BaseClient = /** @class */ (function () {
217
228
  this.connection.publish(subject, nats_ws_1.Empty, opts);
218
229
  }
219
230
  // Now that we have sent the terminating chunk, the result should arrive on our promise.
220
- return [2 /*return*/, this.withTimeout(responsePromise, timeout).catch(function (err) {
231
+ return [2 /*return*/, this.withTimeout(responsePromise, timeout, subject).catch(function (err) {
221
232
  subscription.unsubscribe();
222
233
  return Promise.reject(_this.natsErrorHandler(err, subject));
223
234
  })];
@@ -832,6 +832,7 @@ export declare class RunStatus implements IRunStatus {
832
832
  failedToStart?: boolean;
833
833
  sessionState?: SessionState;
834
834
  executingSteps?: string[] | undefined;
835
+ createdAt?: string | undefined;
835
836
  constructor(data?: IRunStatus);
836
837
  init(_data?: any): void;
837
838
  static fromJS(data: any): RunStatus;
@@ -844,6 +845,7 @@ export interface IRunStatus {
844
845
  failedToStart?: boolean;
845
846
  sessionState?: SessionState;
846
847
  executingSteps?: string[] | undefined;
848
+ createdAt?: string | undefined;
847
849
  }
848
850
  export declare class EditStatus implements IEditStatus {
849
851
  undoBufferSize?: number;
package/dist/cjs/DTOs.js CHANGED
@@ -2350,7 +2350,7 @@ var RunStatus = /** @class */ (function () {
2350
2350
  }
2351
2351
  }
2352
2352
  RunStatus.prototype.init = function (_data) {
2353
- var _a;
2353
+ var _a, _b;
2354
2354
  if (_data) {
2355
2355
  this.sessionId = _data['SessionId'];
2356
2356
  this.verdict = _data['Verdict'];
@@ -2359,11 +2359,12 @@ var RunStatus = /** @class */ (function () {
2359
2359
  this.sessionState = (_a = _data['SessionState']) !== null && _a !== void 0 ? _a : _data['sessionState'];
2360
2360
  if (Array.isArray(_data['ExecutingSteps'])) {
2361
2361
  this.executingSteps = [];
2362
- for (var _i = 0, _b = _data['ExecutingSteps']; _i < _b.length; _i++) {
2363
- var item = _b[_i];
2362
+ for (var _i = 0, _c = _data['ExecutingSteps']; _i < _c.length; _i++) {
2363
+ var item = _c[_i];
2364
2364
  this.executingSteps.push(item);
2365
2365
  }
2366
2366
  }
2367
+ this.createdAt = (_b = _data['CreatedAt']) !== null && _b !== void 0 ? _b : undefined;
2367
2368
  }
2368
2369
  };
2369
2370
  RunStatus.fromJS = function (data) {
@@ -2386,6 +2387,7 @@ var RunStatus = /** @class */ (function () {
2386
2387
  data['ExecutingSteps'].push(item);
2387
2388
  }
2388
2389
  }
2390
+ data['CreatedAt'] = this.createdAt;
2389
2391
  return data;
2390
2392
  };
2391
2393
  return RunStatus;
@@ -54,9 +54,10 @@ export declare class RunnerClient extends BaseClient {
54
54
  /**
55
55
  * Shut down a session
56
56
  * @param sessionId the ID of the session to shut down
57
+ * @param force When true, the Runner terminates the session subprocess immediately without attempting a graceful shutdown.
57
58
  * @returns {{Promise<void>}}
58
59
  */
59
- shutdownSession(sessionId: string): Promise<void>;
60
+ shutdownSession(sessionId: string, force?: boolean): Promise<void>;
60
61
  /**
61
62
  * Start a session
62
63
  * @returns {{Promise<Session>}}
@@ -221,11 +221,15 @@ var RunnerClient = /** @class */ (function (_super) {
221
221
  /**
222
222
  * Shut down a session
223
223
  * @param sessionId the ID of the session to shut down
224
+ * @param force When true, the Runner terminates the session subprocess immediately without attempting a graceful shutdown.
224
225
  * @returns {{Promise<void>}}
225
226
  */
226
- RunnerClient.prototype.shutdownSession = function (sessionId) {
227
+ RunnerClient.prototype.shutdownSession = function (sessionId, force) {
228
+ if (force === void 0) { force = false; }
227
229
  return (sessionId === null || sessionId === void 0 ? void 0 : sessionId.length) > 0
228
- ? this.request('ShutdownSession', sessionId).then(this.success()).catch(this.error())
230
+ ? this.request('ShutdownSession', sessionId, force ? { headers: { Force: 'true' } } : undefined)
231
+ .then(this.success())
232
+ .catch(this.error())
229
233
  : Promise.reject('sessionId is not defined');
230
234
  };
231
235
  /**
@@ -6,6 +6,9 @@ interface BaseClientRequestOptions {
6
6
  rawResponse?: boolean;
7
7
  fullSubject?: boolean;
8
8
  timeout?: number;
9
+ headers?: {
10
+ [key: string]: string;
11
+ };
9
12
  }
10
13
  export declare class BaseClient {
11
14
  readonly baseSubject: string;
@@ -49,8 +49,11 @@ export class BaseClient {
49
49
  this.connectionOptions.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || DEFAULT_TIMEOUT;
50
50
  this.eventEmitter = new EventEmitter();
51
51
  }
52
- withTimeout(promise, timeout) {
53
- return Promise.race([promise, new Promise((_, reject) => setTimeout(() => reject(new Error(ErrorCode.Timeout)), timeout))]);
52
+ withTimeout(promise, timeout, subject) {
53
+ return Promise.race([
54
+ promise,
55
+ new Promise((_, reject) => setTimeout(() => reject(new Error(`${ErrorCode.Timeout}: '${subject}' timed out after ${timeout}ms`)), timeout)),
56
+ ]);
54
57
  }
55
58
  /**
56
59
  * Send a request to the nats server.
@@ -72,6 +75,9 @@ export class BaseClient {
72
75
  return Promise.reject(`${subject}: Connection has been closed! Please reconnect!`);
73
76
  const data = this.encode(payload);
74
77
  const headers = this.buildHeaders();
78
+ if (options === null || options === void 0 ? void 0 : options.headers) {
79
+ Object.entries(options.headers).forEach(([key, value]) => headers.append(key, value));
80
+ }
75
81
  const timeout = (options === null || options === void 0 ? void 0 : options.timeout) || this.timeout;
76
82
  // Generate a unique reply subject that we can subscribe to
77
83
  const replySubject = (_b = (_a = options === null || options === void 0 ? void 0 : options.publishOptions) === null || _a === void 0 ? void 0 : _a.reply) !== null && _b !== void 0 ? _b : `${subject}.Reply.${uuidv4()}`;
@@ -175,7 +181,7 @@ export class BaseClient {
175
181
  this.connection.publish(subject, Empty, opts);
176
182
  }
177
183
  // Now that we have sent the terminating chunk, the result should arrive on our promise.
178
- return this.withTimeout(responsePromise, timeout).catch(err => {
184
+ return this.withTimeout(responsePromise, timeout, subject).catch(err => {
179
185
  subscription.unsubscribe();
180
186
  return Promise.reject(this.natsErrorHandler(err, subject));
181
187
  });
@@ -832,6 +832,7 @@ export declare class RunStatus implements IRunStatus {
832
832
  failedToStart?: boolean;
833
833
  sessionState?: SessionState;
834
834
  executingSteps?: string[] | undefined;
835
+ createdAt?: string | undefined;
835
836
  constructor(data?: IRunStatus);
836
837
  init(_data?: any): void;
837
838
  static fromJS(data: any): RunStatus;
@@ -844,6 +845,7 @@ export interface IRunStatus {
844
845
  failedToStart?: boolean;
845
846
  sessionState?: SessionState;
846
847
  executingSteps?: string[] | undefined;
848
+ createdAt?: string | undefined;
847
849
  }
848
850
  export declare class EditStatus implements IEditStatus {
849
851
  undoBufferSize?: number;
package/dist/mjs/DTOs.js CHANGED
@@ -2057,7 +2057,7 @@ export class RunStatus {
2057
2057
  }
2058
2058
  }
2059
2059
  init(_data) {
2060
- var _a;
2060
+ var _a, _b;
2061
2061
  if (_data) {
2062
2062
  this.sessionId = _data['SessionId'];
2063
2063
  this.verdict = _data['Verdict'];
@@ -2069,6 +2069,7 @@ export class RunStatus {
2069
2069
  for (const item of _data['ExecutingSteps'])
2070
2070
  this.executingSteps.push(item);
2071
2071
  }
2072
+ this.createdAt = (_b = _data['CreatedAt']) !== null && _b !== void 0 ? _b : undefined;
2072
2073
  }
2073
2074
  }
2074
2075
  static fromJS(data) {
@@ -2089,6 +2090,7 @@ export class RunStatus {
2089
2090
  for (const item of this.executingSteps)
2090
2091
  data['ExecutingSteps'].push(item);
2091
2092
  }
2093
+ data['CreatedAt'] = this.createdAt;
2092
2094
  return data;
2093
2095
  }
2094
2096
  }
@@ -54,9 +54,10 @@ export declare class RunnerClient extends BaseClient {
54
54
  /**
55
55
  * Shut down a session
56
56
  * @param sessionId the ID of the session to shut down
57
+ * @param force When true, the Runner terminates the session subprocess immediately without attempting a graceful shutdown.
57
58
  * @returns {{Promise<void>}}
58
59
  */
59
- shutdownSession(sessionId: string): Promise<void>;
60
+ shutdownSession(sessionId: string, force?: boolean): Promise<void>;
60
61
  /**
61
62
  * Start a session
62
63
  * @returns {{Promise<Session>}}
@@ -161,11 +161,14 @@ export class RunnerClient extends BaseClient {
161
161
  /**
162
162
  * Shut down a session
163
163
  * @param sessionId the ID of the session to shut down
164
+ * @param force When true, the Runner terminates the session subprocess immediately without attempting a graceful shutdown.
164
165
  * @returns {{Promise<void>}}
165
166
  */
166
- shutdownSession(sessionId) {
167
+ shutdownSession(sessionId, force = false) {
167
168
  return (sessionId === null || sessionId === void 0 ? void 0 : sessionId.length) > 0
168
- ? this.request('ShutdownSession', sessionId).then(this.success()).catch(this.error())
169
+ ? this.request('ShutdownSession', sessionId, force ? { headers: { Force: 'true' } } : undefined)
170
+ .then(this.success())
171
+ .catch(this.error())
169
172
  : Promise.reject('sessionId is not defined');
170
173
  }
171
174
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "4.0.0",
3
+ "version": "4.2.0",
4
4
  "description": "This is the web client for the OpenTAP Runner.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/mjs/index.js",