@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
|
@@ -1,337 +1,281 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
NatsClientSettings
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
282
|
-
let result = new contracts_1.Result(false);
|
|
283
|
-
try {
|
|
284
|
-
if (this.cnxn == undefined || this.cnxn.isClosed()) {
|
|
285
|
-
yield this.connect();
|
|
286
|
-
}
|
|
287
|
-
if (this.cnxn == undefined)
|
|
288
|
-
throw new Error(`Unable to perform request: Failed connecting to nats server.`);
|
|
289
|
-
const subject = (_a = meta === null || meta === void 0 ? void 0 : meta.subject) !== null && _a !== void 0 ? _a : i_messaging_client_1.MessagingDefaults.SUBJECT;
|
|
290
|
-
const payload = this.serialize(msg);
|
|
291
|
-
let optz = {
|
|
292
|
-
timeout: (timeoutInSecs !== null && timeoutInSecs !== void 0 ? timeoutInSecs : this.settings.requestTimeoutInSecs) * 1000
|
|
293
|
-
}; // <--- These will likely need to be exposed very soon
|
|
294
|
-
var ultimateMeta = (meta != undefined) ? _.omit(meta, "subject", "replyOn") : {};
|
|
295
|
-
if (ultimateMeta.action == undefined)
|
|
296
|
-
ultimateMeta.action = i_messaging_client_1.MessagingDefaults.ACTION;
|
|
297
|
-
if (ultimateMeta.correlationId == undefined)
|
|
298
|
-
ultimateMeta.correlationId = guid_typescript_1.Guid.raw();
|
|
299
|
-
optz.headers = this.convertToNatsHeaders(ultimateMeta);
|
|
300
|
-
// Add auth token header if not already provided.
|
|
301
|
-
if (((_b = this.apiUserCreds) === null || _b === void 0 ? void 0 : _b.apiToken) && !optz.headers.has(NatsClient_1.DEFAULT_TOKEN_HEADER_PARAM)) {
|
|
302
|
-
optz.headers.set(NatsClient_1.DEFAULT_TOKEN_HEADER_PARAM, this.apiUserCreds.apiToken);
|
|
303
|
-
}
|
|
304
|
-
// TRIGGER AND WAIT FOR IT...
|
|
305
|
-
let rawRes = yield this.cnxn.request(subject, payload, optz);
|
|
306
|
-
this.logger.debug("Received response to request in topic ".concat(subject, ": ", rawRes.string()));
|
|
307
|
-
result = this.deserialize(rawRes);
|
|
308
|
-
}
|
|
309
|
-
catch (err) {
|
|
310
|
-
result.message = "Error requesting in subject ".concat((_c = meta === null || meta === void 0 ? void 0 : meta.subject) !== null && _c !== void 0 ? _c : i_messaging_client_1.MessagingDefaults.SUBJECT, ": ", (_d = err.name) !== null && _d !== void 0 ? _d : "", (_f = (_e = err.message) !== null && _e !== void 0 ? _e : err.stack) !== null && _f !== void 0 ? _f : "");
|
|
311
|
-
result.error = err;
|
|
312
|
-
this.logger.error(result.message, meta);
|
|
313
|
-
}
|
|
314
|
-
finally {
|
|
315
|
-
return result;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
NatsClient.defaults = {
|
|
321
|
-
natsHost: "localhost",
|
|
322
|
-
natsPort: 4222,
|
|
323
|
-
serializer: "json",
|
|
324
|
-
requestTimeoutInSecs: 30
|
|
325
|
-
};
|
|
326
|
-
/** Applied to this.tokenHeaderParam in the ctor.
|
|
327
|
-
* Typical name of the http request header that declares the authentication token for the request. */
|
|
328
|
-
NatsClient.DEFAULT_TOKEN_HEADER_PARAM = "authorization";
|
|
329
|
-
NatsClient = NatsClient_1 = tslib_1.__decorate([
|
|
330
|
-
(0, inversify_1.injectable)(),
|
|
331
|
-
tslib_1.__param(0, (0, inversify_1.inject)(codiac_api_1.ApiUserCreds)),
|
|
332
|
-
tslib_1.__param(1, (0, inversify_1.inject)(NatsClientSettings)),
|
|
333
|
-
tslib_1.__param(2, (0, inversify_1.inject)(codiac_common_1.INTERFACES.IBetterLogger)),
|
|
334
|
-
tslib_1.__metadata("design:paramtypes", [Object, Object, Object])
|
|
335
|
-
], NatsClient);
|
|
336
|
-
exports.NatsClient = NatsClient;
|
|
2
|
+
// COMMENTED OUT BC: Migrated to @codiac.io/codiac-messaging
|
|
3
|
+
// import { inject, injectable, interfaces } from "inversify";
|
|
4
|
+
// import * as _ from "lodash";
|
|
5
|
+
// import { Guid } from "guid-typescript";
|
|
6
|
+
// import * as nats from "nats";
|
|
7
|
+
// import * as YAML from "yaml";
|
|
8
|
+
// import { IBetterLogger, INTERFACES } from "@codiac.io/codiac-common";
|
|
9
|
+
// import { Result } from "@codiac.io/codiac-common/contracts";
|
|
10
|
+
// import { IMessageReceivedMeta, IMessageSendMeta, IMessagingClient, MessagePayload, MessagingDefaults } from "@codiac.io/codiac-messaging/dist/nats/client"; // "../../uilogic/i-messaging-client";
|
|
11
|
+
// import { ApiUserCreds } from "../codiac-api";
|
|
12
|
+
// @injectable()
|
|
13
|
+
// export class NatsClientSettings {
|
|
14
|
+
// constructor(
|
|
15
|
+
// public natsHost: string,
|
|
16
|
+
// public natsPort: number,
|
|
17
|
+
// public serializer: "json" | "yaml" | "string",
|
|
18
|
+
// /** The amount of time to wait for a response to a given request. */
|
|
19
|
+
// public requestTimeoutInSecs: number
|
|
20
|
+
// ) {
|
|
21
|
+
// }
|
|
22
|
+
// }
|
|
23
|
+
// @injectable()
|
|
24
|
+
// export class NatsClient implements IMessagingClient {
|
|
25
|
+
// public static bootstrap(ioc: interfaces.Container, settings?: Partial<NatsClientSettings>): void {
|
|
26
|
+
// ioc.bind(NatsClientSettings).toConstantValue(settings as NatsClientSettings);
|
|
27
|
+
// ioc.bind(NatsClient).toSelf();
|
|
28
|
+
// }
|
|
29
|
+
// public static defaults: NatsClientSettings = {
|
|
30
|
+
// natsHost: "localhost",
|
|
31
|
+
// natsPort: 4222,
|
|
32
|
+
// serializer: "json",
|
|
33
|
+
// requestTimeoutInSecs: 30
|
|
34
|
+
// }
|
|
35
|
+
// /** Applied to this.tokenHeaderParam in the ctor.
|
|
36
|
+
// * Typical name of the http request header that declares the authentication token for the request. */
|
|
37
|
+
// public static DEFAULT_TOKEN_HEADER_PARAM = "authorization";
|
|
38
|
+
// constructor(
|
|
39
|
+
// @inject(ApiUserCreds) private apiUserCreds: ApiUserCreds | undefined,
|
|
40
|
+
// @inject(NatsClientSettings) settings: Partial<NatsClientSettings>,
|
|
41
|
+
// @inject(INTERFACES.IBetterLogger) private logger: IBetterLogger,
|
|
42
|
+
// ) {
|
|
43
|
+
// this.settings = _.merge({}, NatsClient.defaults, settings ?? {}); // Overlays the provided settings over the defaults
|
|
44
|
+
// this.natsUrl = "nats://".concat(this.settings.natsHost, ":", this.settings.natsPort.toString());
|
|
45
|
+
// }
|
|
46
|
+
// public settings: NatsClientSettings;
|
|
47
|
+
// public natsUrl: string;
|
|
48
|
+
// private cnxn: nats.NatsConnection | undefined;
|
|
49
|
+
// private listeners: nats.Subscription[] = [];
|
|
50
|
+
// public async connect(): Promise<string> {
|
|
51
|
+
// try {
|
|
52
|
+
// this.cnxn = await nats.connect({
|
|
53
|
+
// servers: [this.natsUrl]
|
|
54
|
+
// });
|
|
55
|
+
// return this.connectionId!;
|
|
56
|
+
// } catch (err) {
|
|
57
|
+
// const errMsg = "Error connecting to ".concat("[", this.natsUrl, "]: ", err.message ?? "no details available");
|
|
58
|
+
// this.logger.error(errMsg, err.stack);
|
|
59
|
+
// throw new Error(errMsg);
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
// public async disconnect(): Promise<void> {
|
|
63
|
+
// try {
|
|
64
|
+
// if (this.cnxn && (!this.cnxn.isClosed())) {
|
|
65
|
+
// this.logger.detail(`Closing connection`);
|
|
66
|
+
// await this.cnxn.drain();
|
|
67
|
+
// await this.cnxn.close();
|
|
68
|
+
// } else {
|
|
69
|
+
// this.logger.detail(`Skipping disconnect: No connection is currently open.`);
|
|
70
|
+
// }
|
|
71
|
+
// return;
|
|
72
|
+
// } catch (err) {
|
|
73
|
+
// throw err;
|
|
74
|
+
// }
|
|
75
|
+
// }
|
|
76
|
+
// public isConnected(): boolean {
|
|
77
|
+
// return !(this.cnxn == undefined || this.cnxn.isClosed());
|
|
78
|
+
// }
|
|
79
|
+
// public get connectionId(): string | undefined {
|
|
80
|
+
// return this.cnxn?.info?.client_id.toString();
|
|
81
|
+
// }
|
|
82
|
+
// /** TODO: Expose typesafe messages instead of raw nats.Msg */
|
|
83
|
+
// public subscribe<TMsg extends MessagePayload>(topics: string, handler: (err: Error | null, msg: TMsg, meta: IMessageReceivedMeta, raw: nats.Msg) => Promise<void>): string {
|
|
84
|
+
// // if (this.cnxn == undefined || this.cnxn.isClosed()) {
|
|
85
|
+
// // await this.connect();
|
|
86
|
+
// // }
|
|
87
|
+
// // if (this.cnxn == undefined) throw new Error(`Unable to subscribe: Failed connecting to nats server.`);
|
|
88
|
+
// try {
|
|
89
|
+
// if (!this.isConnected() || this.cnxn == undefined) {
|
|
90
|
+
// throw new Error("Client is not connected to the nats server.");
|
|
91
|
+
// }
|
|
92
|
+
// let optz: nats.SubscriptionOptions = {
|
|
93
|
+
// callback: async (errResponse, natsMsg) => {
|
|
94
|
+
// try {
|
|
95
|
+
// this.logger.debug("received message ".concat(natsMsg.sid.toString(), " ", natsMsg.subject));
|
|
96
|
+
// // let asString = natsMsg.string();
|
|
97
|
+
// // EXTRACT META OBJECT
|
|
98
|
+
// let meta: IMessageReceivedMeta = {
|
|
99
|
+
// sid: natsMsg.sid,
|
|
100
|
+
// subject: natsMsg.subject,
|
|
101
|
+
// action: natsMsg.headers?.get("action") ?? MessagingDefaults.ACTION,
|
|
102
|
+
// correlationId: natsMsg.headers?.get("correlationId") ?? Guid.raw(),
|
|
103
|
+
// };
|
|
104
|
+
// if (natsMsg.headers) {
|
|
105
|
+
// let dict: { [key: string]: string } = {};
|
|
106
|
+
// // filter to prevent overwriting any IMessageReceivedMeta properties
|
|
107
|
+
// // This will forfeit any colliding custom headers
|
|
108
|
+
// // TO allow for that, consider isolating custom meta with a separate "custom" property.
|
|
109
|
+
// natsMsg.headers.keys().filter(k => !Object.keys(meta).includes(k)).forEach(k => {
|
|
110
|
+
// const val = natsMsg.headers?.get(k);
|
|
111
|
+
// if (val != undefined) dict[k] = val;
|
|
112
|
+
// });
|
|
113
|
+
// meta = _.merge(meta, dict);
|
|
114
|
+
// }
|
|
115
|
+
// if (natsMsg.reply) meta.replyOn = natsMsg.reply;
|
|
116
|
+
// // DESERIALIZE
|
|
117
|
+
// // TODO: Consider a tryParse/else to support messages as native types (string|number|boolean)
|
|
118
|
+
// let msg: TMsg;
|
|
119
|
+
// try {
|
|
120
|
+
// msg = this.deserialize(natsMsg);
|
|
121
|
+
// } catch (err) {
|
|
122
|
+
// this.logger.error(err.message);
|
|
123
|
+
// if (errResponse == undefined) {
|
|
124
|
+
// errResponse = err;
|
|
125
|
+
// } else {
|
|
126
|
+
// // This isnt a good spot for this error,
|
|
127
|
+
// // but if nats is already returning a transmission error,
|
|
128
|
+
// // then its very possible that a malformed message is related to the problem.
|
|
129
|
+
// errResponse.chainedError = err;
|
|
130
|
+
// }
|
|
131
|
+
// msg = <any>natsMsg.string() as TMsg; // sent OUT just like it was sent IN
|
|
132
|
+
// }
|
|
133
|
+
// // FIRE THE PROVIDED HANDLER...
|
|
134
|
+
// await handler(errResponse, msg, meta, natsMsg);
|
|
135
|
+
// } catch (err) {
|
|
136
|
+
// this.logger.error("Error handling message SID:".concat(natsMsg.sid.toString(), ", on ", topics, ": ", err.name ?? "", err.message ?? err.stack ?? ""));
|
|
137
|
+
// } finally {
|
|
138
|
+
// return;
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
141
|
+
// }; // <--- These will likely need to be exposed very soon
|
|
142
|
+
// let subx = this.cnxn.subscribe(topics, optz);
|
|
143
|
+
// this.listeners.push(subx);
|
|
144
|
+
// const subxId = subx.getID().toString();
|
|
145
|
+
// this.logger.notice("Successfully subscribed to: ".concat("[", topics, "]", ", [subxId: ", subxId, "]"));
|
|
146
|
+
// return subxId;
|
|
147
|
+
// } catch (err) {
|
|
148
|
+
// let errMsg = "Error subscribing: ".concat((err.name != "Error") ? err.name ?? "" : "", " ", err.message ?? err.stack ?? "");
|
|
149
|
+
// this.logger.error(errMsg, err.stack);
|
|
150
|
+
// throw new Error(errMsg);
|
|
151
|
+
// }
|
|
152
|
+
// }
|
|
153
|
+
// /** Stops listening on the given topics. */
|
|
154
|
+
// public async unsubscribe(topics: string, options?: { force?: boolean, subscriptionId?: string }): Promise<boolean> {
|
|
155
|
+
// try {
|
|
156
|
+
// let subx = this.listeners.find(sx => sx.getSubject() === topics);
|
|
157
|
+
// if (subx != undefined) {
|
|
158
|
+
// if (options?.force != true) {
|
|
159
|
+
// await subx?.drain();
|
|
160
|
+
// }
|
|
161
|
+
// subx.unsubscribe();
|
|
162
|
+
// this.logger.notice("Successfully unsubscribed from: ".concat("[", topics, "]"));
|
|
163
|
+
// return true;
|
|
164
|
+
// } else {
|
|
165
|
+
// this.logger.warn("Unable to unsubscribe, no subscription found for: ".concat("[", topics, "]"));
|
|
166
|
+
// return false;
|
|
167
|
+
// }
|
|
168
|
+
// } catch (err) {
|
|
169
|
+
// this.logger.error("Error unsubscribing: ".concat(err.name ?? "", err.message ?? err.stack ?? ""));
|
|
170
|
+
// return false;
|
|
171
|
+
// }
|
|
172
|
+
// }
|
|
173
|
+
// /** THrows any errors. */
|
|
174
|
+
// private deserialize<T>(raw: nats.Msg): T {
|
|
175
|
+
// let output: T;
|
|
176
|
+
// try {
|
|
177
|
+
// if (this.settings.serializer === "string") {
|
|
178
|
+
// output = <any>raw.string() as T;
|
|
179
|
+
// } else {
|
|
180
|
+
// let asString = raw.string();
|
|
181
|
+
// output = (this.settings.serializer == 'yaml') ? YAML.parse(asString) : JSON.parse(asString) as T;
|
|
182
|
+
// }
|
|
183
|
+
// return output;
|
|
184
|
+
// } catch (err) {
|
|
185
|
+
// let msg = "Error deserializing message on ".concat(raw.subject, " to ", this.settings.serializer, ": ", err.message ?? err.stack ?? "");
|
|
186
|
+
// this.logger.error(msg);
|
|
187
|
+
// // output = raw.string() as T;
|
|
188
|
+
// throw new Error(msg);
|
|
189
|
+
// }
|
|
190
|
+
// }
|
|
191
|
+
// private serialize(msg: MessagePayload): nats.Payload {
|
|
192
|
+
// try {
|
|
193
|
+
// let payload: nats.Payload;
|
|
194
|
+
// if (typeof msg === 'string') {
|
|
195
|
+
// payload = msg; // already serialized
|
|
196
|
+
// } else {
|
|
197
|
+
// // TODO: support a dataype or serializer override specified in the meta
|
|
198
|
+
// payload = (this.settings.serializer == "yaml") ? YAML.stringify(msg) : JSON.stringify(msg);
|
|
199
|
+
// }
|
|
200
|
+
// // Commented out bc we're only transmitting within the local machine,
|
|
201
|
+
// // so serializing to int array is just adding processing time,
|
|
202
|
+
// // without any improvement to latency or security.
|
|
203
|
+
// // return Buffer.from(payload, 'utf8');
|
|
204
|
+
// return payload;
|
|
205
|
+
// } catch (err) {
|
|
206
|
+
// let msg = "Error serializing message to ".concat(this.settings.serializer, ": ", err.message ?? err.stack ?? "");
|
|
207
|
+
// this.logger.error(msg, err.stack);
|
|
208
|
+
// throw new Error(msg);
|
|
209
|
+
// }
|
|
210
|
+
// }
|
|
211
|
+
// // public async publish<TMsg>(topic: string, msg: TMsg, headers?: { [name: string]: string }, replyOn?: string): Promise<void> {
|
|
212
|
+
// public async publish(msg: MessagePayload, meta?: Partial<IMessageSendMeta>): Promise<void> {
|
|
213
|
+
// if (this.cnxn == undefined || this.cnxn.isClosed()) {
|
|
214
|
+
// await this.connect();
|
|
215
|
+
// }
|
|
216
|
+
// if (this.cnxn == undefined) throw new Error(`Unable to publish message: Failed connecting to nats server.`);
|
|
217
|
+
// try {
|
|
218
|
+
// const subject = meta?.subject ?? MessagingDefaults.SUBJECT;
|
|
219
|
+
// const payload = this.serialize(msg);
|
|
220
|
+
// let optz: nats.PublishOptions = {}; // <--- These will likely need to be exposed very soon
|
|
221
|
+
// var ultimateMeta = (meta != undefined) ? _.omit(meta, "subject", "replyOn") : {};
|
|
222
|
+
// if (ultimateMeta.action == undefined) ultimateMeta.action = MessagingDefaults.ACTION;
|
|
223
|
+
// if (ultimateMeta.correlationId == undefined) ultimateMeta.correlationId = Guid.raw();
|
|
224
|
+
// optz.headers = this.convertToNatsHeaders(ultimateMeta);
|
|
225
|
+
// // Add auth token header if not already provided.
|
|
226
|
+
// if (this.apiUserCreds?.apiToken && !optz.headers.has(NatsClient.DEFAULT_TOKEN_HEADER_PARAM)) {
|
|
227
|
+
// optz.headers.set(NatsClient.DEFAULT_TOKEN_HEADER_PARAM, this.apiUserCreds.apiToken)
|
|
228
|
+
// }
|
|
229
|
+
// if (meta?.replyOn) optz.reply = meta.replyOn;
|
|
230
|
+
// // SET IT AND FORGET IT...
|
|
231
|
+
// // NOTE: to get a response, use "request()" instead of "publish()"
|
|
232
|
+
// this.cnxn.publish(subject, payload, optz);
|
|
233
|
+
// } catch (err) {
|
|
234
|
+
// this.logger.error("Error publishing: ".concat(err.name ?? "", err.message ?? err.stack ?? ""), meta);
|
|
235
|
+
// } finally {
|
|
236
|
+
// return;
|
|
237
|
+
// }
|
|
238
|
+
// }
|
|
239
|
+
// private convertToNatsHeaders(meta?: { [key: string]: any }): nats.MsgHdrsImpl {
|
|
240
|
+
// let headers = new nats.MsgHdrsImpl(); // <-- is this what they want us doing here?
|
|
241
|
+
// if (meta) {
|
|
242
|
+
// Object.keys(meta).forEach(k => {
|
|
243
|
+
// headers.append(k, meta[k]);
|
|
244
|
+
// });
|
|
245
|
+
// }
|
|
246
|
+
// return headers;
|
|
247
|
+
// }
|
|
248
|
+
// public async request<TMsg extends MessagePayload, TRes extends Result>(msg: TMsg, meta?: Partial<IMessageSendMeta>, timeoutInSecs?: number): Promise<TRes> {
|
|
249
|
+
// let result = new Result(false);
|
|
250
|
+
// try {
|
|
251
|
+
// if (this.cnxn == undefined || this.cnxn.isClosed()) {
|
|
252
|
+
// await this.connect();
|
|
253
|
+
// }
|
|
254
|
+
// if (this.cnxn == undefined) throw new Error(`Unable to perform request: Failed connecting to nats server.`);
|
|
255
|
+
// const subject = meta?.subject ?? MessagingDefaults.SUBJECT;
|
|
256
|
+
// const payload = this.serialize(msg);
|
|
257
|
+
// let optz: nats.RequestOptions = {
|
|
258
|
+
// timeout: (timeoutInSecs ?? this.settings.requestTimeoutInSecs) * 1000
|
|
259
|
+
// }; // <--- These will likely need to be exposed very soon
|
|
260
|
+
// var ultimateMeta = (meta != undefined) ? _.omit(meta, "subject", "replyOn") : {};
|
|
261
|
+
// if (ultimateMeta.action == undefined) ultimateMeta.action = MessagingDefaults.ACTION;
|
|
262
|
+
// if (ultimateMeta.correlationId == undefined) ultimateMeta.correlationId = Guid.raw();
|
|
263
|
+
// optz.headers = this.convertToNatsHeaders(ultimateMeta);
|
|
264
|
+
// // Add auth token header if not already provided.
|
|
265
|
+
// if (this.apiUserCreds?.apiToken && !optz.headers.has(NatsClient.DEFAULT_TOKEN_HEADER_PARAM)) {
|
|
266
|
+
// optz.headers.set(NatsClient.DEFAULT_TOKEN_HEADER_PARAM, this.apiUserCreds.apiToken)
|
|
267
|
+
// }
|
|
268
|
+
// // TRIGGER AND WAIT FOR IT...
|
|
269
|
+
// let rawRes = await this.cnxn.request(subject, payload, optz);
|
|
270
|
+
// this.logger.debug("Received response to request in topic ".concat(subject, ": ", rawRes.string()));
|
|
271
|
+
// result = this.deserialize<TRes>(rawRes);
|
|
272
|
+
// } catch (err) {
|
|
273
|
+
// result.message = "Error requesting in subject ".concat(meta?.subject ?? MessagingDefaults.SUBJECT, ": ", err.name ?? "", err.message ?? err.stack ?? "");
|
|
274
|
+
// result.error = err;
|
|
275
|
+
// this.logger.error(result.message, meta);
|
|
276
|
+
// } finally {
|
|
277
|
+
// return result as TRes;
|
|
278
|
+
// }
|
|
279
|
+
// }
|
|
280
|
+
// }
|
|
337
281
|
//# sourceMappingURL=nats-client.js.map
|