@opentap/runner-client 1.2.0-beta.1 → 1.2.0-beta.2
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/lib/BaseClient.d.ts +19 -2
- package/lib/BaseClient.js +48 -10
- package/package.json +1 -1
package/lib/BaseClient.d.ts
CHANGED
|
@@ -4,7 +4,18 @@ export declare class BaseClient {
|
|
|
4
4
|
private connection;
|
|
5
5
|
private baseSubject;
|
|
6
6
|
private connectionOptions;
|
|
7
|
+
private domainAccess;
|
|
8
|
+
private _accessToken;
|
|
9
|
+
private _headers;
|
|
7
10
|
private _timeout;
|
|
11
|
+
/** Get request access token */
|
|
12
|
+
get accessToken(): string;
|
|
13
|
+
/** Set request access token */
|
|
14
|
+
set accessToken(value: string);
|
|
15
|
+
/** Get request headers */
|
|
16
|
+
get headers(): Headers;
|
|
17
|
+
/** Set request headers */
|
|
18
|
+
set headers(value: Headers);
|
|
8
19
|
/** Get timeout */
|
|
9
20
|
get timeout(): number;
|
|
10
21
|
/** Set timeout */
|
|
@@ -18,6 +29,11 @@ export declare class BaseClient {
|
|
|
18
29
|
* @returns Promise of an object
|
|
19
30
|
*/
|
|
20
31
|
protected request<T>(subject: string, payload?: any, options?: RequestOptions): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Build the headers' object.
|
|
34
|
+
* @returns {MsgHdrs} Header object
|
|
35
|
+
*/
|
|
36
|
+
private buildHeaders;
|
|
21
37
|
/**
|
|
22
38
|
* Subscribes to given subject.
|
|
23
39
|
* @param subject The subject to subscribe
|
|
@@ -42,9 +58,10 @@ export declare class BaseClient {
|
|
|
42
58
|
close(): Promise<void>;
|
|
43
59
|
/**
|
|
44
60
|
* Add a domain specific access token to the dictionary.
|
|
45
|
-
* @param domain
|
|
46
|
-
* @param accessToken
|
|
61
|
+
* @param {string} domain
|
|
62
|
+
* @param {string} accessToken
|
|
47
63
|
*/
|
|
64
|
+
addDomainAccessToken(domain: string, accessToken: string): void;
|
|
48
65
|
/**
|
|
49
66
|
* Generic error callback function.
|
|
50
67
|
* @returns
|
package/lib/BaseClient.js
CHANGED
|
@@ -46,15 +46,40 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
import { ErrorResponse, } from './DTOs';
|
|
49
|
-
import { Empty, ErrorCode, JSONCodec, StringCodec, connect, } from 'nats.ws/cjs/nats.js';
|
|
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 () {
|
|
52
52
|
function BaseClient(baseSubject, options) {
|
|
53
|
-
|
|
53
|
+
this.domainAccess = new Map();
|
|
54
|
+
this._headers = new Headers();
|
|
54
55
|
this.baseSubject = baseSubject;
|
|
55
56
|
this.connectionOptions = __assign({}, options) || {};
|
|
56
57
|
this.connectionOptions.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || DEFAULT_TIMEOUT;
|
|
57
58
|
}
|
|
59
|
+
Object.defineProperty(BaseClient.prototype, "accessToken", {
|
|
60
|
+
/** Get request access token */
|
|
61
|
+
get: function () {
|
|
62
|
+
return this._accessToken;
|
|
63
|
+
},
|
|
64
|
+
/** Set request access token */
|
|
65
|
+
set: function (value) {
|
|
66
|
+
this._accessToken = value;
|
|
67
|
+
},
|
|
68
|
+
enumerable: false,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(BaseClient.prototype, "headers", {
|
|
72
|
+
/** Get request headers */
|
|
73
|
+
get: function () {
|
|
74
|
+
return this._headers;
|
|
75
|
+
},
|
|
76
|
+
/** Set request headers */
|
|
77
|
+
set: function (value) {
|
|
78
|
+
this._headers = value;
|
|
79
|
+
},
|
|
80
|
+
enumerable: false,
|
|
81
|
+
configurable: true
|
|
82
|
+
});
|
|
58
83
|
Object.defineProperty(BaseClient.prototype, "timeout", {
|
|
59
84
|
/** Get timeout */
|
|
60
85
|
get: function () {
|
|
@@ -76,7 +101,7 @@ var BaseClient = /** @class */ (function () {
|
|
|
76
101
|
*/
|
|
77
102
|
BaseClient.prototype.request = function (subject, payload, options) {
|
|
78
103
|
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
-
var stringCodec, data, opts;
|
|
104
|
+
var stringCodec, data, headers, opts;
|
|
80
105
|
var _this = this;
|
|
81
106
|
return __generator(this, function (_a) {
|
|
82
107
|
switch (_a.label) {
|
|
@@ -88,7 +113,8 @@ var BaseClient = /** @class */ (function () {
|
|
|
88
113
|
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
|
|
89
114
|
stringCodec = StringCodec();
|
|
90
115
|
data = payload ? stringCodec.encode(JSON.stringify(payload)) : Empty;
|
|
91
|
-
|
|
116
|
+
headers = this.buildHeaders();
|
|
117
|
+
opts = __assign(__assign({}, options), { timeout: this.timeout, headers: headers });
|
|
92
118
|
return [4 /*yield*/, this.connection
|
|
93
119
|
.request(subject, data, opts)
|
|
94
120
|
.then(function (message) {
|
|
@@ -116,6 +142,18 @@ var BaseClient = /** @class */ (function () {
|
|
|
116
142
|
});
|
|
117
143
|
});
|
|
118
144
|
};
|
|
145
|
+
/**
|
|
146
|
+
* Build the headers' object.
|
|
147
|
+
* @returns {MsgHdrs} Header object
|
|
148
|
+
*/
|
|
149
|
+
BaseClient.prototype.buildHeaders = function () {
|
|
150
|
+
var _a, _b;
|
|
151
|
+
var _headers = headers();
|
|
152
|
+
this._accessToken && _headers.set('Authorization', this._accessToken);
|
|
153
|
+
(_a = this.domainAccess) === null || _a === void 0 ? void 0 : _a.forEach(function (value, key) { return _headers.append('DomainAuthorization', "".concat(key, "|").concat(value)); });
|
|
154
|
+
(_b = this._headers) === null || _b === void 0 ? void 0 : _b.forEach(function (value, key) { return _headers.append(key, value); });
|
|
155
|
+
return _headers;
|
|
156
|
+
};
|
|
119
157
|
/**
|
|
120
158
|
* Subscribes to given subject.
|
|
121
159
|
* @param subject The subject to subscribe
|
|
@@ -199,14 +237,14 @@ var BaseClient = /** @class */ (function () {
|
|
|
199
237
|
};
|
|
200
238
|
/**
|
|
201
239
|
* Add a domain specific access token to the dictionary.
|
|
202
|
-
* @param domain
|
|
203
|
-
* @param accessToken
|
|
240
|
+
* @param {string} domain
|
|
241
|
+
* @param {string} accessToken
|
|
204
242
|
*/
|
|
205
|
-
|
|
206
|
-
if (!domain)
|
|
207
|
-
|
|
243
|
+
BaseClient.prototype.addDomainAccessToken = function (domain, accessToken) {
|
|
244
|
+
if (!domain || !accessToken)
|
|
245
|
+
return;
|
|
208
246
|
this.domainAccess.set(domain, accessToken);
|
|
209
|
-
}
|
|
247
|
+
};
|
|
210
248
|
/**
|
|
211
249
|
* Generic error callback function.
|
|
212
250
|
* @returns
|