@codiac.io/codiac-cli 1.3.126 → 1.3.129
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/README.md +1 -1
- package/dist/apis/codiac-api-nats/gen/client.d.ts +72 -11
- package/dist/apis/codiac-api-nats/gen/client.js +967 -84
- package/dist/apis/codiac-api-nats/gen/client.js.map +1 -1
- package/dist/apis/codiac-api-nats/gen/config.d.ts +3 -15
- package/dist/apis/codiac-api-nats/gen/config.js +5 -4
- package/dist/apis/codiac-api-nats/gen/config.js.map +1 -1
- package/dist/apis/codiac-api-nats/gen/contracts/transformers.gen.d.ts +3 -2
- package/dist/apis/codiac-api-nats/gen/contracts/transformers.gen.js +23 -18
- package/dist/apis/codiac-api-nats/gen/contracts/transformers.gen.js.map +1 -1
- package/dist/apis/codiac-api-nats/gen/contracts/types.gen.d.ts +72 -20
- package/dist/apis/codiac-api-nats/gen/contracts/types.gen.js +18 -7
- package/dist/apis/codiac-api-nats/gen/contracts/types.gen.js.map +1 -1
- package/dist/apis/codiac-api-nats/gen/contracts.ng.d.ts +34 -7
- package/dist/apis/codiac-api-nats/gen/contracts.ng.js +1 -2
- package/dist/apis/codiac-api-nats/gen/contracts.ng.js.map +1 -1
- package/dist/apis/codiac-relay-nats/gen/client.d.ts +10 -13
- package/dist/apis/codiac-relay-nats/gen/client.js +35 -73
- package/dist/apis/codiac-relay-nats/gen/client.js.map +1 -1
- package/dist/apis/codiac-relay-nats/gen/config.d.ts +3 -16
- package/dist/apis/codiac-relay-nats/gen/config.js +7 -5
- package/dist/apis/codiac-relay-nats/gen/config.js.map +1 -1
- package/dist/apis/codiac-relay-nats/gen/contracts/types.gen.d.ts +3 -3
- package/dist/apis/codiac-relay-nats/gen/contracts.ng.d.ts +0 -7
- package/dist/apis/codiac-relay-nats/gen/contracts.ng.js +2 -2
- package/dist/apis/codiac-relay-nats/gen/contracts.ng.js.map +1 -1
- package/dist/apis/nats/nats-client.d.ts +0 -47
- package/dist/apis/nats/nats-client.js +279 -335
- package/dist/apis/nats/nats-client.js.map +1 -1
- package/dist/bootstrapper-for-api-clients.d.ts +1 -0
- package/dist/bootstrapper-for-api-clients.js +15 -2
- package/dist/bootstrapper-for-api-clients.js.map +1 -1
- package/dist/bootstrapper-for-enterprise-commands.js +22 -5
- package/dist/bootstrapper-for-enterprise-commands.js.map +1 -1
- package/dist/command-base-enterprise.d.ts +1 -1
- package/dist/command-base-enterprise.js +24 -8
- package/dist/command-base-enterprise.js.map +1 -1
- package/dist/commands/cluster/start.js +3 -3
- package/dist/commands/cluster/start.js.map +1 -1
- package/dist/commands/cluster/stop.js +3 -3
- package/dist/commands/cluster/stop.js.map +1 -1
- package/dist/commands/noc/cluster/create.js +3 -3
- package/dist/commands/noc/cluster/create.js.map +1 -1
- package/dist/commands/noc/cluster/destroy.js +3 -3
- package/dist/commands/noc/cluster/destroy.js.map +1 -1
- package/dist/ops/terminal-command-runner/local-command-runner.d.ts +1 -1
- package/dist/relay/relay-container.js +1 -1
- package/dist/relay/wsclient/relay-websocket-client.d.ts +2 -2
- package/dist/relay/wsclient/relay-websocket-client.js +1 -1
- package/dist/relay/wsclient/relay-websocket-client.js.map +1 -1
- package/dist/relay/wsclient/socket-contracts.d.ts +1 -1
- package/dist/sdk-adapters/azure/az-interactive-login-configurator.d.ts +1 -1
- package/dist/sdk-adapters/azure/az-interactive-login-configurator.js +95 -56
- package/dist/sdk-adapters/azure/az-interactive-login-configurator.js.map +1 -1
- package/dist/sdk-adapters/azure/azure-resource-configurator.d.ts +1 -1
- package/dist/sdk-adapters/azure/azure-resource-configurator.js +7 -7
- package/dist/sdk-adapters/azure/azure-resource-configurator.js.map +1 -1
- package/dist/uilogic/i-messaging-client.d.ts +0 -56
- package/dist/uilogic/i-messaging-client.js +84 -9
- package/dist/uilogic/i-messaging-client.js.map +1 -1
- package/dist/uilogic/lrp-watcher-predef.d.ts +1 -1
- package/dist/uilogic/lrp-watcher-predef.js +1 -1
- package/dist/uilogic/lrp-watcher-predef.js.map +1 -1
- package/dist/uilogic/lrp-watcher.d.ts +1 -1
- package/dist/uilogic/lrp-watcher.js +2 -2
- package/dist/uilogic/lrp-watcher.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +8 -7
|
@@ -4,18 +4,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.RelayNatsClient = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const inversify_1 = require("inversify");
|
|
7
|
-
const buffer_1 = require("buffer");
|
|
8
7
|
const codiac_common_1 = require("@codiac.io/codiac-common");
|
|
9
8
|
const contracts_1 = require("@codiac.io/codiac-common/contracts");
|
|
10
9
|
const jwt_lib_1 = require("@codiac.io/jwt-lib");
|
|
11
10
|
const token_1 = require("../common/token");
|
|
12
11
|
const config_1 = require("./config");
|
|
13
12
|
const Nats = require("@nats-io/nats-core");
|
|
14
|
-
const Transport = require("@nats-io/transport-node");
|
|
15
13
|
const Utils = require("../common/utils");
|
|
16
|
-
const jwt = require("@codiac.io/jwt-lib");
|
|
17
14
|
const _ = require("lodash");
|
|
18
15
|
const token_utils_1 = require("../common/token-utils");
|
|
16
|
+
const nats_1 = require("@codiac.io/codiac-messaging/dist/nats");
|
|
17
|
+
const codiac_messaging_1 = require("@codiac.io/codiac-messaging");
|
|
19
18
|
// FOR nats websocket error: WebSocket not defined.
|
|
20
19
|
if (typeof WebSocket === 'undefined') {
|
|
21
20
|
const Ws = require('ws');
|
|
@@ -23,15 +22,21 @@ if (typeof WebSocket === 'undefined') {
|
|
|
23
22
|
}
|
|
24
23
|
let RelayNatsClient = RelayNatsClient_1 = class RelayNatsClient {
|
|
25
24
|
static bootstrap(ioc, settings) {
|
|
25
|
+
let ultimate;
|
|
26
26
|
if (ioc.isBound(config_1.RelayNatsClientConfig)) {
|
|
27
27
|
const existing = ioc.get(config_1.RelayNatsClientConfig);
|
|
28
|
-
|
|
28
|
+
ultimate = _.assignIn({}, existing, settings);
|
|
29
29
|
ioc.rebind(config_1.RelayNatsClientConfig).toConstantValue(ultimate);
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
|
|
32
|
+
ultimate = _.assignIn({}, this.DEFAULTS, settings);
|
|
33
33
|
ioc.bind(config_1.RelayNatsClientConfig).toConstantValue(ultimate);
|
|
34
34
|
}
|
|
35
|
+
nats_1.NatsConnector.bootstrap(ioc, {
|
|
36
|
+
natsInstance: ultimate.natsInstance,
|
|
37
|
+
baseUrl: ultimate.baseUrl,
|
|
38
|
+
connectTimeoutInMs: ultimate.connectTimeoutInMs
|
|
39
|
+
}, ultimate.natsInstance);
|
|
35
40
|
// COMMENTED OUT BC:
|
|
36
41
|
// We cant bind the client here bc we need to use lazy-loaded properties
|
|
37
42
|
// to get injected dependencies, not ioc directly
|
|
@@ -49,19 +54,17 @@ let RelayNatsClient = RelayNatsClient_1 = class RelayNatsClient {
|
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
/** This factory method is just for convenience and hasty backward compatibility with consumers not using ioc. */
|
|
52
|
-
static create(logger, configuration, codiacJwt) {
|
|
57
|
+
static create(logger, connector, configuration, codiacJwt) {
|
|
53
58
|
let tokenCreds;
|
|
54
59
|
if (codiacJwt) {
|
|
55
60
|
tokenCreds = (typeof codiacJwt == 'string') ? { jwtToken: codiacJwt } : codiacJwt;
|
|
56
61
|
}
|
|
57
|
-
return new RelayNatsClient_1(logger, configuration !== null && configuration !== void 0 ? configuration : this.DEFAULTS, tokenCreds);
|
|
62
|
+
return new RelayNatsClient_1(logger, configuration !== null && configuration !== void 0 ? configuration : this.DEFAULTS, connector, tokenCreds);
|
|
58
63
|
}
|
|
59
|
-
|
|
60
|
-
return this._nc;
|
|
61
|
-
}
|
|
62
|
-
constructor(logger, _settings, _tokenCredentials) {
|
|
64
|
+
constructor(logger, _settings, connector, _tokenCredentials) {
|
|
63
65
|
this.logger = logger;
|
|
64
66
|
this._settings = _settings;
|
|
67
|
+
this.connector = connector;
|
|
65
68
|
this._tokenCredentials = _tokenCredentials;
|
|
66
69
|
this.Auth = new AuthOperations(this);
|
|
67
70
|
this.Call = new OtherOperations(this);
|
|
@@ -82,8 +85,9 @@ let RelayNatsClient = RelayNatsClient_1 = class RelayNatsClient {
|
|
|
82
85
|
this.ScopedSetting = new ScopedSettingCruds(this);
|
|
83
86
|
this.SetupJournal = new SetupJournalCruds(this);
|
|
84
87
|
this.ZombiePeriod = new ZombiePeriodCruds(this);
|
|
85
|
-
this.clientType = _settings.baseUrl.toLowerCase().startsWith("nats://") ? "nats" : "websockets";
|
|
86
88
|
this.TokenUtils = new token_utils_1.TokenUtils(this.logger);
|
|
89
|
+
if (_tokenCredentials === null || _tokenCredentials === void 0 ? void 0 : _tokenCredentials.jwtToken)
|
|
90
|
+
this.connector.setUserToken(_tokenCredentials.jwtToken);
|
|
87
91
|
this.endpoints = {};
|
|
88
92
|
}
|
|
89
93
|
registerEndpoints(endpoints) {
|
|
@@ -112,80 +116,35 @@ let RelayNatsClient = RelayNatsClient_1 = class RelayNatsClient {
|
|
|
112
116
|
return found;
|
|
113
117
|
}
|
|
114
118
|
isExpired(token, throwOnError = false) {
|
|
115
|
-
return this.
|
|
119
|
+
return this.connector.isExpired(token, throwOnError);
|
|
116
120
|
}
|
|
117
121
|
/** Sets the user context to impersonate in requests made to the api. */
|
|
118
122
|
setUserToken(token) {
|
|
119
|
-
|
|
120
|
-
this._tokenCredentials.jwtToken = token;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
this._tokenCredentials = { jwtToken: token };
|
|
124
|
-
}
|
|
123
|
+
this.connector.setUserToken(token);
|
|
125
124
|
}
|
|
126
125
|
connect() {
|
|
127
|
-
var _a, _b, _c, _d;
|
|
128
126
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
|
|
130
|
-
// Assemble authenticator from codiac jwt
|
|
131
|
-
const codiacJwt = (_a = this._tokenCredentials) === null || _a === void 0 ? void 0 : _a.jwtToken;
|
|
132
|
-
if (codiacJwt == undefined) {
|
|
133
|
-
throw new Error("No token client available.");
|
|
134
|
-
}
|
|
135
|
-
const payload = (_b = new jwt.JwtEncoder().tryDecode(codiacJwt)) === null || _b === void 0 ? void 0 : _b.payload;
|
|
136
|
-
if (payload == undefined)
|
|
137
|
-
throw new Error("Empty jwt payload");
|
|
138
|
-
const gck = payload[RelayNatsClient_1.CLAIM_FOR_GLOBAL_CLIENT_KEY];
|
|
139
|
-
if (gck == undefined)
|
|
140
|
-
throw new Error("No global client key was available in the token payload.");
|
|
141
|
-
const natsCreds = buffer_1.Buffer.from(gck, 'base64').toString('utf-8');
|
|
142
|
-
const opts = {
|
|
143
|
-
servers: this._settings.baseUrl,
|
|
144
|
-
authenticator: [
|
|
145
|
-
Nats.tokenAuthenticator(codiacJwt),
|
|
146
|
-
Nats.credsAuthenticator(new TextEncoder().encode(natsCreds))
|
|
147
|
-
],
|
|
148
|
-
verbose: true,
|
|
149
|
-
timeout: this.settings.connectTimeoutInMs
|
|
150
|
-
};
|
|
151
|
-
if (this.clientType === "websockets") {
|
|
152
|
-
RelayNatsClient_1._nc = yield Nats.wsconnect(opts);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
RelayNatsClient_1._nc = yield Transport.connect(opts);
|
|
156
|
-
}
|
|
157
|
-
this.logger.write(`Connected to ${this._settings.baseUrl}`);
|
|
158
|
-
return (_c = RelayNatsClient_1.nc) === null || _c === void 0 ? void 0 : _c.info;
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
this.logger.error((_d = err.message) !== null && _d !== void 0 ? _d : "Error connecting to nats: (no error message available)");
|
|
162
|
-
throw err;
|
|
163
|
-
}
|
|
127
|
+
return yield this.connector.connect();
|
|
164
128
|
});
|
|
165
129
|
}
|
|
166
130
|
isConnected() {
|
|
167
|
-
return
|
|
131
|
+
return this.connector.isConnected();
|
|
168
132
|
}
|
|
169
133
|
disconnect() {
|
|
170
134
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
171
|
-
yield
|
|
135
|
+
yield this.connector.disconnect();
|
|
172
136
|
return;
|
|
173
137
|
});
|
|
174
138
|
}
|
|
175
139
|
/** Disregards any instances and checks the underlying connection store
|
|
176
140
|
* for any connections that are currently not closed or draining. */
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return (this.nc != undefined) && (!this.nc.isClosed() && !this.nc.isDraining());
|
|
141
|
+
areAnyConnected() {
|
|
142
|
+
return this.connector.areAnyConnected();
|
|
180
143
|
}
|
|
181
144
|
/** Closes any unclosed connections in the underlying connection store (regardless of instances). */
|
|
182
|
-
|
|
183
|
-
var _a;
|
|
145
|
+
disconnectAll() {
|
|
184
146
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
|
|
186
|
-
yield ((_a = this.nc) === null || _a === void 0 ? void 0 : _a.close());
|
|
187
|
-
}
|
|
188
|
-
return;
|
|
147
|
+
return this.connector.disconnectAll();
|
|
189
148
|
});
|
|
190
149
|
}
|
|
191
150
|
get tokenCredentials() {
|
|
@@ -241,7 +200,10 @@ let RelayNatsClient = RelayNatsClient_1 = class RelayNatsClient {
|
|
|
241
200
|
if (!this.isConnected()) {
|
|
242
201
|
yield this.connect();
|
|
243
202
|
}
|
|
244
|
-
|
|
203
|
+
if (!this.connector.connection) {
|
|
204
|
+
throw new Error("The messaging client unexpectedly lost its connection instance. Please try again.");
|
|
205
|
+
}
|
|
206
|
+
const res = yield this.connector.connection.request(subject, JSON.stringify(req), {
|
|
245
207
|
headers: reqHeaders,
|
|
246
208
|
timeout: (_a = options === null || options === void 0 ? void 0 : options.requestTimeoutInMs) !== null && _a !== void 0 ? _a : this.settings.requestTimeoutInMs
|
|
247
209
|
});
|
|
@@ -262,17 +224,17 @@ RelayNatsClient.apiVersion = "version";
|
|
|
262
224
|
/** The name of the jwt claim in the codiac token that holds the nats credentials. */
|
|
263
225
|
RelayNatsClient.CLAIM_FOR_GLOBAL_CLIENT_KEY = "gck";
|
|
264
226
|
RelayNatsClient.DEFAULTS = {
|
|
265
|
-
baseUrl: "
|
|
266
|
-
requestTimeoutInMs:
|
|
267
|
-
connectTimeoutInMs: 30000
|
|
227
|
+
baseUrl: "nats://localhost:4222",
|
|
228
|
+
requestTimeoutInMs: 180000,
|
|
229
|
+
connectTimeoutInMs: 30000
|
|
268
230
|
};
|
|
269
231
|
RelayNatsClient = RelayNatsClient_1 = tslib_1.__decorate([
|
|
270
232
|
(0, inversify_1.injectable)(),
|
|
271
233
|
tslib_1.__param(0, (0, inversify_1.inject)(codiac_common_1.INTERFACES.IBetterLogger)),
|
|
272
234
|
tslib_1.__param(1, (0, inversify_1.inject)(config_1.RelayNatsClientConfig)),
|
|
273
|
-
tslib_1.__param(2, (0, inversify_1.inject)(
|
|
274
|
-
tslib_1.
|
|
275
|
-
|
|
235
|
+
tslib_1.__param(2, (0, inversify_1.inject)(codiac_messaging_1.StreamingConstants.IStreamingConnector)),
|
|
236
|
+
tslib_1.__param(3, (0, inversify_1.inject)(token_1.TokenCreds)),
|
|
237
|
+
tslib_1.__metadata("design:paramtypes", [Object, config_1.RelayNatsClientConfig, Object, token_1.TokenCreds])
|
|
276
238
|
], RelayNatsClient);
|
|
277
239
|
exports.RelayNatsClient = RelayNatsClient;
|
|
278
240
|
// // EXAMPLE
|