@interopio/fdc3 2.1.3 → 2.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.
- package/dist/fdc3.electron.es.js +1685 -373
- package/dist/fdc3.electron.umd.js +1685 -373
- package/dist/fdc3.es.js +1674 -362
- package/dist/fdc3.umd.js +1674 -362
- package/package.json +4 -3
package/dist/fdc3.electron.es.js
CHANGED
|
@@ -13,6 +13,214 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */
|
|
15
15
|
|
|
16
|
+
function __rest$2(s, e) {
|
|
17
|
+
var t = {};
|
|
18
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
19
|
+
t[p] = s[p];
|
|
20
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
21
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
22
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
23
|
+
t[p[i]] = s[p[i]];
|
|
24
|
+
}
|
|
25
|
+
return t;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let nanoid = (size = 21) =>
|
|
39
|
+
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
|
40
|
+
byte &= 63;
|
|
41
|
+
if (byte < 36) {
|
|
42
|
+
id += byte.toString(36);
|
|
43
|
+
} else if (byte < 62) {
|
|
44
|
+
id += (byte - 26).toString(36).toUpperCase();
|
|
45
|
+
} else if (byte > 62) {
|
|
46
|
+
id += '-';
|
|
47
|
+
} else {
|
|
48
|
+
id += '_';
|
|
49
|
+
}
|
|
50
|
+
return id
|
|
51
|
+
}, '');
|
|
52
|
+
|
|
53
|
+
const isValidNonEmptyObject = (obj) => {
|
|
54
|
+
return typeof obj === "object" && !Array.isArray(obj) && Object.keys(obj).length !== 0;
|
|
55
|
+
};
|
|
56
|
+
const AsyncListener = (actualUnsub) => {
|
|
57
|
+
return {
|
|
58
|
+
unsubscribe() {
|
|
59
|
+
if (!actualUnsub) {
|
|
60
|
+
console.error("Failed to unsubscribe!");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof actualUnsub === "function") {
|
|
64
|
+
actualUnsub();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
actualUnsub.then((unsubFunc) => unsubFunc()).catch(console.error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const checkIfInElectron = (globalFdc3) => {
|
|
73
|
+
const hasGlue42electron = typeof window !== "undefined" && "glue42electron" in window;
|
|
74
|
+
if (!hasGlue42electron) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const runningInElectron = typeof process !== "undefined" && "contextIsolated" in process;
|
|
78
|
+
if (runningInElectron) {
|
|
79
|
+
const contextBridge = require("electron").contextBridge;
|
|
80
|
+
contextBridge.exposeInMainWorld("fdc3", globalFdc3);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const promisePlus = (promise, timeoutMilliseconds, timeoutMessage) => {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const timeout = setTimeout(() => {
|
|
86
|
+
const message = timeoutMessage || `Promise timeout hit: ${timeoutMilliseconds}`;
|
|
87
|
+
reject(message);
|
|
88
|
+
}, timeoutMilliseconds);
|
|
89
|
+
promise()
|
|
90
|
+
.then((result) => {
|
|
91
|
+
clearTimeout(timeout);
|
|
92
|
+
resolve(result);
|
|
93
|
+
})
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
clearTimeout(timeout);
|
|
96
|
+
reject(error);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
const generateCommandId = () => {
|
|
101
|
+
return nanoid();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const connectBrowserAppProps = ["name", "title", "version", "customProperties", "icon", "caption", "type"];
|
|
105
|
+
const fdc3v2AppProps = ["appId", "name", "type", "details", "version", "title", "tooltip", "lang", "description", "categories", "icons", "screenshots", "contactEmail", "moreInfo", "publisher", "customConfig", "hostManifests", "interop", "localizedVersions"];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Wraps values in an `Ok` type.
|
|
109
|
+
*
|
|
110
|
+
* Example: `ok(5) // => {ok: true, result: 5}`
|
|
111
|
+
*/
|
|
112
|
+
var ok$1 = function (result) { return ({ ok: true, result: result }); };
|
|
113
|
+
/**
|
|
114
|
+
* Wraps errors in an `Err` type.
|
|
115
|
+
*
|
|
116
|
+
* Example: `err('on fire') // => {ok: false, error: 'on fire'}`
|
|
117
|
+
*/
|
|
118
|
+
var err$1 = function (error) { return ({ ok: false, error: error }); };
|
|
119
|
+
/**
|
|
120
|
+
* Create a `Promise` that either resolves with the result of `Ok` or rejects
|
|
121
|
+
* with the error of `Err`.
|
|
122
|
+
*/
|
|
123
|
+
var asPromise$1 = function (r) {
|
|
124
|
+
return r.ok === true ? Promise.resolve(r.result) : Promise.reject(r.error);
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Unwraps a `Result` and returns either the result of an `Ok`, or
|
|
128
|
+
* `defaultValue`.
|
|
129
|
+
*
|
|
130
|
+
* Example:
|
|
131
|
+
* ```
|
|
132
|
+
* Result.withDefault(5, number().run(json))
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* It would be nice if `Decoder` had an instance method that mirrored this
|
|
136
|
+
* function. Such a method would look something like this:
|
|
137
|
+
* ```
|
|
138
|
+
* class Decoder<A> {
|
|
139
|
+
* runWithDefault = (defaultValue: A, json: any): A =>
|
|
140
|
+
* Result.withDefault(defaultValue, this.run(json));
|
|
141
|
+
* }
|
|
142
|
+
*
|
|
143
|
+
* number().runWithDefault(5, json)
|
|
144
|
+
* ```
|
|
145
|
+
* Unfortunately, the type of `defaultValue: A` on the method causes issues
|
|
146
|
+
* with type inference on the `object` decoder in some situations. While these
|
|
147
|
+
* inference issues can be solved by providing the optional type argument for
|
|
148
|
+
* `object`s, the extra trouble and confusion doesn't seem worth it.
|
|
149
|
+
*/
|
|
150
|
+
var withDefault$1 = function (defaultValue, r) {
|
|
151
|
+
return r.ok === true ? r.result : defaultValue;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Return the successful result, or throw an error.
|
|
155
|
+
*/
|
|
156
|
+
var withException$1 = function (r) {
|
|
157
|
+
if (r.ok === true) {
|
|
158
|
+
return r.result;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
throw r.error;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Apply `f` to the result of an `Ok`, or pass the error through.
|
|
166
|
+
*/
|
|
167
|
+
var map$1 = function (f, r) {
|
|
168
|
+
return r.ok === true ? ok$1(f(r.result)) : r;
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Apply `f` to the result of two `Ok`s, or pass an error through. If both
|
|
172
|
+
* `Result`s are errors then the first one is returned.
|
|
173
|
+
*/
|
|
174
|
+
var map2$1 = function (f, ar, br) {
|
|
175
|
+
return ar.ok === false ? ar :
|
|
176
|
+
br.ok === false ? br :
|
|
177
|
+
ok$1(f(ar.result, br.result));
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Apply `f` to the error of an `Err`, or pass the success through.
|
|
181
|
+
*/
|
|
182
|
+
var mapError$1 = function (f, r) {
|
|
183
|
+
return r.ok === true ? r : err$1(f(r.error));
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Chain together a sequence of computations that may fail, similar to a
|
|
187
|
+
* `Promise`. If the first computation fails then the error will propagate
|
|
188
|
+
* through. If it succeeds, then `f` will be applied to the value, returning a
|
|
189
|
+
* new `Result`.
|
|
190
|
+
*/
|
|
191
|
+
var andThen$1 = function (f, r) {
|
|
192
|
+
return r.ok === true ? f(r.result) : r;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/*! *****************************************************************************
|
|
196
|
+
Copyright (c) Microsoft Corporation.
|
|
197
|
+
|
|
198
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
199
|
+
purpose with or without fee is hereby granted.
|
|
200
|
+
|
|
201
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
202
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
203
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
204
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
205
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
206
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
207
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
208
|
+
***************************************************************************** */
|
|
209
|
+
/* global Reflect, Promise */
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
var __assign$1 = function() {
|
|
214
|
+
__assign$1 = Object.assign || function __assign(t) {
|
|
215
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
216
|
+
s = arguments[i];
|
|
217
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
218
|
+
}
|
|
219
|
+
return t;
|
|
220
|
+
};
|
|
221
|
+
return __assign$1.apply(this, arguments);
|
|
222
|
+
};
|
|
223
|
+
|
|
16
224
|
function __rest$1(s, e) {
|
|
17
225
|
var t = {};
|
|
18
226
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -25,84 +233,1034 @@ function __rest$1(s, e) {
|
|
|
25
233
|
return t;
|
|
26
234
|
}
|
|
27
235
|
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
236
|
+
function isEqual$1(a, b) {
|
|
237
|
+
if (a === b) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
if (a === null && b === null) {
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
243
|
+
if (typeof (a) !== typeof (b)) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
if (typeof (a) === 'object') {
|
|
247
|
+
// Array
|
|
248
|
+
if (Array.isArray(a)) {
|
|
249
|
+
if (!Array.isArray(b)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
if (a.length !== b.length) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
for (var i = 0; i < a.length; i++) {
|
|
256
|
+
if (!isEqual$1(a[i], b[i])) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
// Hash table
|
|
263
|
+
var keys = Object.keys(a);
|
|
264
|
+
if (keys.length !== Object.keys(b).length) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
for (var i = 0; i < keys.length; i++) {
|
|
268
|
+
if (!b.hasOwnProperty(keys[i])) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
if (!isEqual$1(a[keys[i]], b[keys[i]])) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/*
|
|
279
|
+
* Helpers
|
|
280
|
+
*/
|
|
281
|
+
var isJsonArray$1 = function (json) { return Array.isArray(json); };
|
|
282
|
+
var isJsonObject$1 = function (json) {
|
|
283
|
+
return typeof json === 'object' && json !== null && !isJsonArray$1(json);
|
|
284
|
+
};
|
|
285
|
+
var typeString$1 = function (json) {
|
|
286
|
+
switch (typeof json) {
|
|
287
|
+
case 'string':
|
|
288
|
+
return 'a string';
|
|
289
|
+
case 'number':
|
|
290
|
+
return 'a number';
|
|
291
|
+
case 'boolean':
|
|
292
|
+
return 'a boolean';
|
|
293
|
+
case 'undefined':
|
|
294
|
+
return 'undefined';
|
|
295
|
+
case 'object':
|
|
296
|
+
if (json instanceof Array) {
|
|
297
|
+
return 'an array';
|
|
298
|
+
}
|
|
299
|
+
else if (json === null) {
|
|
300
|
+
return 'null';
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
return 'an object';
|
|
304
|
+
}
|
|
305
|
+
default:
|
|
306
|
+
return JSON.stringify(json);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
var expectedGot$1 = function (expected, got) {
|
|
310
|
+
return "expected " + expected + ", got " + typeString$1(got);
|
|
311
|
+
};
|
|
312
|
+
var printPath$1 = function (paths) {
|
|
313
|
+
return paths.map(function (path) { return (typeof path === 'string' ? "." + path : "[" + path + "]"); }).join('');
|
|
314
|
+
};
|
|
315
|
+
var prependAt$1 = function (newAt, _a) {
|
|
316
|
+
var at = _a.at, rest = __rest$1(_a, ["at"]);
|
|
317
|
+
return (__assign$1({ at: newAt + (at || '') }, rest));
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Decoders transform json objects with unknown structure into known and
|
|
321
|
+
* verified forms. You can create objects of type `Decoder<A>` with either the
|
|
322
|
+
* primitive decoder functions, such as `boolean()` and `string()`, or by
|
|
323
|
+
* applying higher-order decoders to the primitives, such as `array(boolean())`
|
|
324
|
+
* or `dict(string())`.
|
|
325
|
+
*
|
|
326
|
+
* Each of the decoder functions are available both as a static method on
|
|
327
|
+
* `Decoder` and as a function alias -- for example the string decoder is
|
|
328
|
+
* defined at `Decoder.string()`, but is also aliased to `string()`. Using the
|
|
329
|
+
* function aliases exported with the library is recommended.
|
|
330
|
+
*
|
|
331
|
+
* `Decoder` exposes a number of 'run' methods, which all decode json in the
|
|
332
|
+
* same way, but communicate success and failure in different ways. The `map`
|
|
333
|
+
* and `andThen` methods modify decoders without having to call a 'run' method.
|
|
334
|
+
*
|
|
335
|
+
* Alternatively, the main decoder `run()` method returns an object of type
|
|
336
|
+
* `Result<A, DecoderError>`. This library provides a number of helper
|
|
337
|
+
* functions for dealing with the `Result` type, so you can do all the same
|
|
338
|
+
* things with a `Result` as with the decoder methods.
|
|
339
|
+
*/
|
|
340
|
+
var Decoder$1 = /** @class */ (function () {
|
|
341
|
+
/**
|
|
342
|
+
* The Decoder class constructor is kept private to separate the internal
|
|
343
|
+
* `decode` function from the external `run` function. The distinction
|
|
344
|
+
* between the two functions is that `decode` returns a
|
|
345
|
+
* `Partial<DecoderError>` on failure, which contains an unfinished error
|
|
346
|
+
* report. When `run` is called on a decoder, the relevant series of `decode`
|
|
347
|
+
* calls is made, and then on failure the resulting `Partial<DecoderError>`
|
|
348
|
+
* is turned into a `DecoderError` by filling in the missing information.
|
|
349
|
+
*
|
|
350
|
+
* While hiding the constructor may seem restrictive, leveraging the
|
|
351
|
+
* provided decoder combinators and helper functions such as
|
|
352
|
+
* `andThen` and `map` should be enough to build specialized decoders as
|
|
353
|
+
* needed.
|
|
354
|
+
*/
|
|
355
|
+
function Decoder(decode) {
|
|
356
|
+
var _this = this;
|
|
357
|
+
this.decode = decode;
|
|
358
|
+
/**
|
|
359
|
+
* Run the decoder and return a `Result` with either the decoded value or a
|
|
360
|
+
* `DecoderError` containing the json input, the location of the error, and
|
|
361
|
+
* the error message.
|
|
362
|
+
*
|
|
363
|
+
* Examples:
|
|
364
|
+
* ```
|
|
365
|
+
* number().run(12)
|
|
366
|
+
* // => {ok: true, result: 12}
|
|
367
|
+
*
|
|
368
|
+
* string().run(9001)
|
|
369
|
+
* // =>
|
|
370
|
+
* // {
|
|
371
|
+
* // ok: false,
|
|
372
|
+
* // error: {
|
|
373
|
+
* // kind: 'DecoderError',
|
|
374
|
+
* // input: 9001,
|
|
375
|
+
* // at: 'input',
|
|
376
|
+
* // message: 'expected a string, got 9001'
|
|
377
|
+
* // }
|
|
378
|
+
* // }
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
this.run = function (json) {
|
|
382
|
+
return mapError$1(function (error) { return ({
|
|
383
|
+
kind: 'DecoderError',
|
|
384
|
+
input: json,
|
|
385
|
+
at: 'input' + (error.at || ''),
|
|
386
|
+
message: error.message || ''
|
|
387
|
+
}); }, _this.decode(json));
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Run the decoder as a `Promise`.
|
|
391
|
+
*/
|
|
392
|
+
this.runPromise = function (json) { return asPromise$1(_this.run(json)); };
|
|
393
|
+
/**
|
|
394
|
+
* Run the decoder and return the value on success, or throw an exception
|
|
395
|
+
* with a formatted error string.
|
|
396
|
+
*/
|
|
397
|
+
this.runWithException = function (json) { return withException$1(_this.run(json)); };
|
|
398
|
+
/**
|
|
399
|
+
* Construct a new decoder that applies a transformation to the decoded
|
|
400
|
+
* result. If the decoder succeeds then `f` will be applied to the value. If
|
|
401
|
+
* it fails the error will propagated through.
|
|
402
|
+
*
|
|
403
|
+
* Example:
|
|
404
|
+
* ```
|
|
405
|
+
* number().map(x => x * 5).run(10)
|
|
406
|
+
* // => {ok: true, result: 50}
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
this.map = function (f) {
|
|
410
|
+
return new Decoder(function (json) { return map$1(f, _this.decode(json)); });
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Chain together a sequence of decoders. The first decoder will run, and
|
|
414
|
+
* then the function will determine what decoder to run second. If the result
|
|
415
|
+
* of the first decoder succeeds then `f` will be applied to the decoded
|
|
416
|
+
* value. If it fails the error will propagate through.
|
|
417
|
+
*
|
|
418
|
+
* This is a very powerful method -- it can act as both the `map` and `where`
|
|
419
|
+
* methods, can improve error messages for edge cases, and can be used to
|
|
420
|
+
* make a decoder for custom types.
|
|
421
|
+
*
|
|
422
|
+
* Example of adding an error message:
|
|
423
|
+
* ```
|
|
424
|
+
* const versionDecoder = valueAt(['version'], number());
|
|
425
|
+
* const infoDecoder3 = object({a: boolean()});
|
|
426
|
+
*
|
|
427
|
+
* const decoder = versionDecoder.andThen(version => {
|
|
428
|
+
* switch (version) {
|
|
429
|
+
* case 3:
|
|
430
|
+
* return infoDecoder3;
|
|
431
|
+
* default:
|
|
432
|
+
* return fail(`Unable to decode info, version ${version} is not supported.`);
|
|
433
|
+
* }
|
|
434
|
+
* });
|
|
435
|
+
*
|
|
436
|
+
* decoder.run({version: 3, a: true})
|
|
437
|
+
* // => {ok: true, result: {a: true}}
|
|
438
|
+
*
|
|
439
|
+
* decoder.run({version: 5, x: 'abc'})
|
|
440
|
+
* // =>
|
|
441
|
+
* // {
|
|
442
|
+
* // ok: false,
|
|
443
|
+
* // error: {... message: 'Unable to decode info, version 5 is not supported.'}
|
|
444
|
+
* // }
|
|
445
|
+
* ```
|
|
446
|
+
*
|
|
447
|
+
* Example of decoding a custom type:
|
|
448
|
+
* ```
|
|
449
|
+
* // nominal type for arrays with a length of at least one
|
|
450
|
+
* type NonEmptyArray<T> = T[] & { __nonEmptyArrayBrand__: void };
|
|
451
|
+
*
|
|
452
|
+
* const nonEmptyArrayDecoder = <T>(values: Decoder<T>): Decoder<NonEmptyArray<T>> =>
|
|
453
|
+
* array(values).andThen(arr =>
|
|
454
|
+
* arr.length > 0
|
|
455
|
+
* ? succeed(createNonEmptyArray(arr))
|
|
456
|
+
* : fail(`expected a non-empty array, got an empty array`)
|
|
457
|
+
* );
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
this.andThen = function (f) {
|
|
461
|
+
return new Decoder(function (json) {
|
|
462
|
+
return andThen$1(function (value) { return f(value).decode(json); }, _this.decode(json));
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
/**
|
|
466
|
+
* Add constraints to a decoder _without_ changing the resulting type. The
|
|
467
|
+
* `test` argument is a predicate function which returns true for valid
|
|
468
|
+
* inputs. When `test` fails on an input, the decoder fails with the given
|
|
469
|
+
* `errorMessage`.
|
|
470
|
+
*
|
|
471
|
+
* ```
|
|
472
|
+
* const chars = (length: number): Decoder<string> =>
|
|
473
|
+
* string().where(
|
|
474
|
+
* (s: string) => s.length === length,
|
|
475
|
+
* `expected a string of length ${length}`
|
|
476
|
+
* );
|
|
477
|
+
*
|
|
478
|
+
* chars(5).run('12345')
|
|
479
|
+
* // => {ok: true, result: '12345'}
|
|
480
|
+
*
|
|
481
|
+
* chars(2).run('HELLO')
|
|
482
|
+
* // => {ok: false, error: {... message: 'expected a string of length 2'}}
|
|
483
|
+
*
|
|
484
|
+
* chars(12).run(true)
|
|
485
|
+
* // => {ok: false, error: {... message: 'expected a string, got a boolean'}}
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
this.where = function (test, errorMessage) {
|
|
489
|
+
return _this.andThen(function (value) { return (test(value) ? Decoder.succeed(value) : Decoder.fail(errorMessage)); });
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Decoder primitive that validates strings, and fails on all other input.
|
|
494
|
+
*/
|
|
495
|
+
Decoder.string = function () {
|
|
496
|
+
return new Decoder(function (json) {
|
|
497
|
+
return typeof json === 'string'
|
|
498
|
+
? ok$1(json)
|
|
499
|
+
: err$1({ message: expectedGot$1('a string', json) });
|
|
500
|
+
});
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* Decoder primitive that validates numbers, and fails on all other input.
|
|
504
|
+
*/
|
|
505
|
+
Decoder.number = function () {
|
|
506
|
+
return new Decoder(function (json) {
|
|
507
|
+
return typeof json === 'number'
|
|
508
|
+
? ok$1(json)
|
|
509
|
+
: err$1({ message: expectedGot$1('a number', json) });
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Decoder primitive that validates booleans, and fails on all other input.
|
|
514
|
+
*/
|
|
515
|
+
Decoder.boolean = function () {
|
|
516
|
+
return new Decoder(function (json) {
|
|
517
|
+
return typeof json === 'boolean'
|
|
518
|
+
? ok$1(json)
|
|
519
|
+
: err$1({ message: expectedGot$1('a boolean', json) });
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
Decoder.constant = function (value) {
|
|
523
|
+
return new Decoder(function (json) {
|
|
524
|
+
return isEqual$1(json, value)
|
|
525
|
+
? ok$1(value)
|
|
526
|
+
: err$1({ message: "expected " + JSON.stringify(value) + ", got " + JSON.stringify(json) });
|
|
527
|
+
});
|
|
528
|
+
};
|
|
529
|
+
Decoder.object = function (decoders) {
|
|
530
|
+
return new Decoder(function (json) {
|
|
531
|
+
if (isJsonObject$1(json) && decoders) {
|
|
532
|
+
var obj = {};
|
|
533
|
+
for (var key in decoders) {
|
|
534
|
+
if (decoders.hasOwnProperty(key)) {
|
|
535
|
+
var r = decoders[key].decode(json[key]);
|
|
536
|
+
if (r.ok === true) {
|
|
537
|
+
// tslint:disable-next-line:strict-type-predicates
|
|
538
|
+
if (r.result !== undefined) {
|
|
539
|
+
obj[key] = r.result;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
else if (json[key] === undefined) {
|
|
543
|
+
return err$1({ message: "the key '" + key + "' is required but was not present" });
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
return err$1(prependAt$1("." + key, r.error));
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return ok$1(obj);
|
|
551
|
+
}
|
|
552
|
+
else if (isJsonObject$1(json)) {
|
|
553
|
+
return ok$1(json);
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
return err$1({ message: expectedGot$1('an object', json) });
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
};
|
|
560
|
+
Decoder.array = function (decoder) {
|
|
561
|
+
return new Decoder(function (json) {
|
|
562
|
+
if (isJsonArray$1(json) && decoder) {
|
|
563
|
+
var decodeValue_1 = function (v, i) {
|
|
564
|
+
return mapError$1(function (err$$1) { return prependAt$1("[" + i + "]", err$$1); }, decoder.decode(v));
|
|
565
|
+
};
|
|
566
|
+
return json.reduce(function (acc, v, i) {
|
|
567
|
+
return map2$1(function (arr, result) { return arr.concat([result]); }, acc, decodeValue_1(v, i));
|
|
568
|
+
}, ok$1([]));
|
|
569
|
+
}
|
|
570
|
+
else if (isJsonArray$1(json)) {
|
|
571
|
+
return ok$1(json);
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
return err$1({ message: expectedGot$1('an array', json) });
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
};
|
|
578
|
+
Decoder.tuple = function (decoders) {
|
|
579
|
+
return new Decoder(function (json) {
|
|
580
|
+
if (isJsonArray$1(json)) {
|
|
581
|
+
if (json.length !== decoders.length) {
|
|
582
|
+
return err$1({
|
|
583
|
+
message: "expected a tuple of length " + decoders.length + ", got one of length " + json.length
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
var result = [];
|
|
587
|
+
for (var i = 0; i < decoders.length; i++) {
|
|
588
|
+
var nth = decoders[i].decode(json[i]);
|
|
589
|
+
if (nth.ok) {
|
|
590
|
+
result[i] = nth.result;
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
return err$1(prependAt$1("[" + i + "]", nth.error));
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return ok$1(result);
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
return err$1({ message: expectedGot$1("a tuple of length " + decoders.length, json) });
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
};
|
|
603
|
+
Decoder.union = function (ad, bd) {
|
|
604
|
+
var decoders = [];
|
|
605
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
606
|
+
decoders[_i - 2] = arguments[_i];
|
|
607
|
+
}
|
|
608
|
+
return Decoder.oneOf.apply(Decoder, [ad, bd].concat(decoders));
|
|
609
|
+
};
|
|
610
|
+
Decoder.intersection = function (ad, bd) {
|
|
611
|
+
var ds = [];
|
|
612
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
613
|
+
ds[_i - 2] = arguments[_i];
|
|
614
|
+
}
|
|
615
|
+
return new Decoder(function (json) {
|
|
616
|
+
return [ad, bd].concat(ds).reduce(function (acc, decoder) { return map2$1(Object.assign, acc, decoder.decode(json)); }, ok$1({}));
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* Escape hatch to bypass validation. Always succeeds and types the result as
|
|
621
|
+
* `any`. Useful for defining decoders incrementally, particularly for
|
|
622
|
+
* complex objects.
|
|
623
|
+
*
|
|
624
|
+
* Example:
|
|
625
|
+
* ```
|
|
626
|
+
* interface User {
|
|
627
|
+
* name: string;
|
|
628
|
+
* complexUserData: ComplexType;
|
|
629
|
+
* }
|
|
630
|
+
*
|
|
631
|
+
* const userDecoder: Decoder<User> = object({
|
|
632
|
+
* name: string(),
|
|
633
|
+
* complexUserData: anyJson()
|
|
634
|
+
* });
|
|
635
|
+
* ```
|
|
636
|
+
*/
|
|
637
|
+
Decoder.anyJson = function () { return new Decoder(function (json) { return ok$1(json); }); };
|
|
638
|
+
/**
|
|
639
|
+
* Decoder identity function which always succeeds and types the result as
|
|
640
|
+
* `unknown`.
|
|
641
|
+
*/
|
|
642
|
+
Decoder.unknownJson = function () {
|
|
643
|
+
return new Decoder(function (json) { return ok$1(json); });
|
|
644
|
+
};
|
|
645
|
+
/**
|
|
646
|
+
* Decoder for json objects where the keys are unknown strings, but the values
|
|
647
|
+
* should all be of the same type.
|
|
648
|
+
*
|
|
649
|
+
* Example:
|
|
650
|
+
* ```
|
|
651
|
+
* dict(number()).run({chocolate: 12, vanilla: 10, mint: 37});
|
|
652
|
+
* // => {ok: true, result: {chocolate: 12, vanilla: 10, mint: 37}}
|
|
653
|
+
* ```
|
|
654
|
+
*/
|
|
655
|
+
Decoder.dict = function (decoder) {
|
|
656
|
+
return new Decoder(function (json) {
|
|
657
|
+
if (isJsonObject$1(json)) {
|
|
658
|
+
var obj = {};
|
|
659
|
+
for (var key in json) {
|
|
660
|
+
if (json.hasOwnProperty(key)) {
|
|
661
|
+
var r = decoder.decode(json[key]);
|
|
662
|
+
if (r.ok === true) {
|
|
663
|
+
obj[key] = r.result;
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
return err$1(prependAt$1("." + key, r.error));
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return ok$1(obj);
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
return err$1({ message: expectedGot$1('an object', json) });
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
};
|
|
677
|
+
/**
|
|
678
|
+
* Decoder for values that may be `undefined`. This is primarily helpful for
|
|
679
|
+
* decoding interfaces with optional fields.
|
|
680
|
+
*
|
|
681
|
+
* Example:
|
|
682
|
+
* ```
|
|
683
|
+
* interface User {
|
|
684
|
+
* id: number;
|
|
685
|
+
* isOwner?: boolean;
|
|
686
|
+
* }
|
|
687
|
+
*
|
|
688
|
+
* const decoder: Decoder<User> = object({
|
|
689
|
+
* id: number(),
|
|
690
|
+
* isOwner: optional(boolean())
|
|
691
|
+
* });
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
694
|
+
Decoder.optional = function (decoder) {
|
|
695
|
+
return new Decoder(function (json) { return (json === undefined || json === null ? ok$1(undefined) : decoder.decode(json)); });
|
|
696
|
+
};
|
|
697
|
+
/**
|
|
698
|
+
* Decoder that attempts to run each decoder in `decoders` and either succeeds
|
|
699
|
+
* with the first successful decoder, or fails after all decoders have failed.
|
|
700
|
+
*
|
|
701
|
+
* Note that `oneOf` expects the decoders to all have the same return type,
|
|
702
|
+
* while `union` creates a decoder for the union type of all the input
|
|
703
|
+
* decoders.
|
|
704
|
+
*
|
|
705
|
+
* Examples:
|
|
706
|
+
* ```
|
|
707
|
+
* oneOf(string(), number().map(String))
|
|
708
|
+
* oneOf(constant('start'), constant('stop'), succeed('unknown'))
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
Decoder.oneOf = function () {
|
|
712
|
+
var decoders = [];
|
|
713
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
714
|
+
decoders[_i] = arguments[_i];
|
|
715
|
+
}
|
|
716
|
+
return new Decoder(function (json) {
|
|
717
|
+
var errors = [];
|
|
718
|
+
for (var i = 0; i < decoders.length; i++) {
|
|
719
|
+
var r = decoders[i].decode(json);
|
|
720
|
+
if (r.ok === true) {
|
|
721
|
+
return r;
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
errors[i] = r.error;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
var errorsList = errors
|
|
728
|
+
.map(function (error) { return "at error" + (error.at || '') + ": " + error.message; })
|
|
729
|
+
.join('", "');
|
|
730
|
+
return err$1({
|
|
731
|
+
message: "expected a value matching one of the decoders, got the errors [\"" + errorsList + "\"]"
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
};
|
|
735
|
+
/**
|
|
736
|
+
* Decoder that always succeeds with either the decoded value, or a fallback
|
|
737
|
+
* default value.
|
|
738
|
+
*/
|
|
739
|
+
Decoder.withDefault = function (defaultValue, decoder) {
|
|
740
|
+
return new Decoder(function (json) {
|
|
741
|
+
return ok$1(withDefault$1(defaultValue, decoder.decode(json)));
|
|
742
|
+
});
|
|
743
|
+
};
|
|
744
|
+
/**
|
|
745
|
+
* Decoder that pulls a specific field out of a json structure, instead of
|
|
746
|
+
* decoding and returning the full structure. The `paths` array describes the
|
|
747
|
+
* object keys and array indices to traverse, so that values can be pulled out
|
|
748
|
+
* of a nested structure.
|
|
749
|
+
*
|
|
750
|
+
* Example:
|
|
751
|
+
* ```
|
|
752
|
+
* const decoder = valueAt(['a', 'b', 0], string());
|
|
753
|
+
*
|
|
754
|
+
* decoder.run({a: {b: ['surprise!']}})
|
|
755
|
+
* // => {ok: true, result: 'surprise!'}
|
|
756
|
+
*
|
|
757
|
+
* decoder.run({a: {x: 'cats'}})
|
|
758
|
+
* // => {ok: false, error: {... at: 'input.a.b[0]' message: 'path does not exist'}}
|
|
759
|
+
* ```
|
|
760
|
+
*
|
|
761
|
+
* Note that the `decoder` is ran on the value found at the last key in the
|
|
762
|
+
* path, even if the last key is not found. This allows the `optional`
|
|
763
|
+
* decoder to succeed when appropriate.
|
|
764
|
+
* ```
|
|
765
|
+
* const optionalDecoder = valueAt(['a', 'b', 'c'], optional(string()));
|
|
766
|
+
*
|
|
767
|
+
* optionalDecoder.run({a: {b: {c: 'surprise!'}}})
|
|
768
|
+
* // => {ok: true, result: 'surprise!'}
|
|
769
|
+
*
|
|
770
|
+
* optionalDecoder.run({a: {b: 'cats'}})
|
|
771
|
+
* // => {ok: false, error: {... at: 'input.a.b.c' message: 'expected an object, got "cats"'}
|
|
772
|
+
*
|
|
773
|
+
* optionalDecoder.run({a: {b: {z: 1}}})
|
|
774
|
+
* // => {ok: true, result: undefined}
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
777
|
+
Decoder.valueAt = function (paths, decoder) {
|
|
778
|
+
return new Decoder(function (json) {
|
|
779
|
+
var jsonAtPath = json;
|
|
780
|
+
for (var i = 0; i < paths.length; i++) {
|
|
781
|
+
if (jsonAtPath === undefined) {
|
|
782
|
+
return err$1({
|
|
783
|
+
at: printPath$1(paths.slice(0, i + 1)),
|
|
784
|
+
message: 'path does not exist'
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
else if (typeof paths[i] === 'string' && !isJsonObject$1(jsonAtPath)) {
|
|
788
|
+
return err$1({
|
|
789
|
+
at: printPath$1(paths.slice(0, i + 1)),
|
|
790
|
+
message: expectedGot$1('an object', jsonAtPath)
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
else if (typeof paths[i] === 'number' && !isJsonArray$1(jsonAtPath)) {
|
|
794
|
+
return err$1({
|
|
795
|
+
at: printPath$1(paths.slice(0, i + 1)),
|
|
796
|
+
message: expectedGot$1('an array', jsonAtPath)
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
jsonAtPath = jsonAtPath[paths[i]];
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return mapError$1(function (error) {
|
|
804
|
+
return jsonAtPath === undefined
|
|
805
|
+
? { at: printPath$1(paths), message: 'path does not exist' }
|
|
806
|
+
: prependAt$1(printPath$1(paths), error);
|
|
807
|
+
}, decoder.decode(jsonAtPath));
|
|
808
|
+
});
|
|
809
|
+
};
|
|
810
|
+
/**
|
|
811
|
+
* Decoder that ignores the input json and always succeeds with `fixedValue`.
|
|
812
|
+
*/
|
|
813
|
+
Decoder.succeed = function (fixedValue) {
|
|
814
|
+
return new Decoder(function (json) { return ok$1(fixedValue); });
|
|
815
|
+
};
|
|
816
|
+
/**
|
|
817
|
+
* Decoder that ignores the input json and always fails with `errorMessage`.
|
|
818
|
+
*/
|
|
819
|
+
Decoder.fail = function (errorMessage) {
|
|
820
|
+
return new Decoder(function (json) { return err$1({ message: errorMessage }); });
|
|
821
|
+
};
|
|
822
|
+
/**
|
|
823
|
+
* Decoder that allows for validating recursive data structures. Unlike with
|
|
824
|
+
* functions, decoders assigned to variables can't reference themselves
|
|
825
|
+
* before they are fully defined. We can avoid prematurely referencing the
|
|
826
|
+
* decoder by wrapping it in a function that won't be called until use, at
|
|
827
|
+
* which point the decoder has been defined.
|
|
828
|
+
*
|
|
829
|
+
* Example:
|
|
830
|
+
* ```
|
|
831
|
+
* interface Comment {
|
|
832
|
+
* msg: string;
|
|
833
|
+
* replies: Comment[];
|
|
834
|
+
* }
|
|
835
|
+
*
|
|
836
|
+
* const decoder: Decoder<Comment> = object({
|
|
837
|
+
* msg: string(),
|
|
838
|
+
* replies: lazy(() => array(decoder))
|
|
839
|
+
* });
|
|
840
|
+
* ```
|
|
841
|
+
*/
|
|
842
|
+
Decoder.lazy = function (mkDecoder) {
|
|
843
|
+
return new Decoder(function (json) { return mkDecoder().decode(json); });
|
|
844
|
+
};
|
|
845
|
+
return Decoder;
|
|
846
|
+
}());
|
|
847
|
+
|
|
848
|
+
/* tslint:disable:variable-name */
|
|
849
|
+
/** See `Decoder.string` */
|
|
850
|
+
var string$1 = Decoder$1.string;
|
|
851
|
+
/** See `Decoder.number` */
|
|
852
|
+
var number$1 = Decoder$1.number;
|
|
853
|
+
/** See `Decoder.boolean` */
|
|
854
|
+
var boolean = Decoder$1.boolean;
|
|
855
|
+
/** See `Decoder.anyJson` */
|
|
856
|
+
var anyJson$1 = Decoder$1.anyJson;
|
|
857
|
+
/** See `Decoder.unknownJson` */
|
|
858
|
+
Decoder$1.unknownJson;
|
|
859
|
+
/** See `Decoder.constant` */
|
|
860
|
+
var constant$1 = Decoder$1.constant;
|
|
861
|
+
/** See `Decoder.object` */
|
|
862
|
+
var object$1 = Decoder$1.object;
|
|
863
|
+
/** See `Decoder.array` */
|
|
864
|
+
var array$1 = Decoder$1.array;
|
|
865
|
+
/** See `Decoder.tuple` */
|
|
866
|
+
Decoder$1.tuple;
|
|
867
|
+
/** See `Decoder.dict` */
|
|
868
|
+
var dict = Decoder$1.dict;
|
|
869
|
+
/** See `Decoder.optional` */
|
|
870
|
+
var optional$1 = Decoder$1.optional;
|
|
871
|
+
/** See `Decoder.oneOf` */
|
|
872
|
+
var oneOf$1 = Decoder$1.oneOf;
|
|
873
|
+
/** See `Decoder.union` */
|
|
874
|
+
Decoder$1.union;
|
|
875
|
+
/** See `Decoder.intersection` */
|
|
876
|
+
Decoder$1.intersection;
|
|
877
|
+
/** See `Decoder.withDefault` */
|
|
878
|
+
Decoder$1.withDefault;
|
|
879
|
+
/** See `Decoder.valueAt` */
|
|
880
|
+
Decoder$1.valueAt;
|
|
881
|
+
/** See `Decoder.succeed` */
|
|
882
|
+
Decoder$1.succeed;
|
|
883
|
+
/** See `Decoder.fail` */
|
|
884
|
+
Decoder$1.fail;
|
|
885
|
+
/** See `Decoder.lazy` */
|
|
886
|
+
Decoder$1.lazy;
|
|
887
|
+
|
|
888
|
+
const nonEmptyStringDecoder$1 = string$1().where((s) => s.length > 0, "Expected a non-empty string");
|
|
889
|
+
const nonNegativeNumberDecoder = number$1().where((num) => num >= 0, "Expected a non-negative number");
|
|
890
|
+
|
|
891
|
+
const intentDefinitionDecoder = object$1({
|
|
892
|
+
name: nonEmptyStringDecoder$1,
|
|
893
|
+
displayName: optional$1(string$1()),
|
|
894
|
+
contexts: optional$1(array$1(string$1())),
|
|
895
|
+
customConfig: optional$1(object$1())
|
|
896
|
+
});
|
|
897
|
+
const v2TypeDecoder = oneOf$1(constant$1("web"), constant$1("native"), constant$1("citrix"), constant$1("onlineNative"), constant$1("other"));
|
|
898
|
+
const v2DetailsDecoder = object$1({
|
|
899
|
+
url: nonEmptyStringDecoder$1
|
|
900
|
+
});
|
|
901
|
+
const v2IconDecoder = object$1({
|
|
902
|
+
src: nonEmptyStringDecoder$1,
|
|
903
|
+
size: optional$1(nonEmptyStringDecoder$1),
|
|
904
|
+
type: optional$1(nonEmptyStringDecoder$1)
|
|
905
|
+
});
|
|
906
|
+
const v2ScreenshotDecoder = object$1({
|
|
907
|
+
src: nonEmptyStringDecoder$1,
|
|
908
|
+
size: optional$1(nonEmptyStringDecoder$1),
|
|
909
|
+
type: optional$1(nonEmptyStringDecoder$1),
|
|
910
|
+
label: optional$1(nonEmptyStringDecoder$1)
|
|
911
|
+
});
|
|
912
|
+
const v2ListensForIntentDecoder = object$1({
|
|
913
|
+
contexts: array$1(nonEmptyStringDecoder$1),
|
|
914
|
+
displayName: optional$1(nonEmptyStringDecoder$1),
|
|
915
|
+
resultType: optional$1(nonEmptyStringDecoder$1),
|
|
916
|
+
customConfig: optional$1(anyJson$1())
|
|
917
|
+
});
|
|
918
|
+
const v2IntentsDecoder = object$1({
|
|
919
|
+
listensFor: optional$1(dict(v2ListensForIntentDecoder)),
|
|
920
|
+
raises: optional$1(dict(array$1(nonEmptyStringDecoder$1)))
|
|
921
|
+
});
|
|
922
|
+
const v2UserChannelDecoder = object$1({
|
|
923
|
+
broadcasts: optional$1(array$1(nonEmptyStringDecoder$1)),
|
|
924
|
+
listensFor: optional$1(array$1(nonEmptyStringDecoder$1))
|
|
925
|
+
});
|
|
926
|
+
const v2AppChannelDecoder = object$1({
|
|
927
|
+
name: nonEmptyStringDecoder$1,
|
|
928
|
+
description: optional$1(nonEmptyStringDecoder$1),
|
|
929
|
+
broadcasts: optional$1(array$1(nonEmptyStringDecoder$1)),
|
|
930
|
+
listensFor: optional$1(array$1(nonEmptyStringDecoder$1))
|
|
931
|
+
});
|
|
932
|
+
const v2InteropDecoder = object$1({
|
|
933
|
+
intents: optional$1(v2IntentsDecoder),
|
|
934
|
+
userChannels: optional$1(v2UserChannelDecoder),
|
|
935
|
+
appChannels: optional$1(array$1(v2AppChannelDecoder))
|
|
936
|
+
});
|
|
937
|
+
const glue42ApplicationDetailsDecoder = object$1({
|
|
938
|
+
url: nonEmptyStringDecoder$1,
|
|
939
|
+
top: optional$1(number$1()),
|
|
940
|
+
left: optional$1(number$1()),
|
|
941
|
+
width: optional$1(nonNegativeNumberDecoder),
|
|
942
|
+
height: optional$1(nonNegativeNumberDecoder)
|
|
943
|
+
});
|
|
944
|
+
const glue42HostManifestsBrowserDecoder = object$1({
|
|
945
|
+
name: optional$1(nonEmptyStringDecoder$1),
|
|
946
|
+
type: optional$1(nonEmptyStringDecoder$1.where((s) => s === "window", "Expected a value of window")),
|
|
947
|
+
title: optional$1(nonEmptyStringDecoder$1),
|
|
948
|
+
version: optional$1(nonEmptyStringDecoder$1),
|
|
949
|
+
customProperties: optional$1(anyJson$1()),
|
|
950
|
+
icon: optional$1(string$1()),
|
|
951
|
+
caption: optional$1(string$1()),
|
|
952
|
+
details: optional$1(glue42ApplicationDetailsDecoder),
|
|
953
|
+
intents: optional$1(array$1(intentDefinitionDecoder)),
|
|
954
|
+
hidden: optional$1(boolean())
|
|
955
|
+
});
|
|
956
|
+
const hostManifestsBrowserDecoder = oneOf$1(object$1({
|
|
957
|
+
"Glue42": oneOf$1(glue42HostManifestsBrowserDecoder, anyJson$1())
|
|
958
|
+
}), anyJson$1());
|
|
959
|
+
const v1DefinitionDecoder = object$1({
|
|
960
|
+
name: nonEmptyStringDecoder$1,
|
|
961
|
+
appId: nonEmptyStringDecoder$1,
|
|
962
|
+
title: optional$1(nonEmptyStringDecoder$1),
|
|
963
|
+
version: optional$1(nonEmptyStringDecoder$1),
|
|
964
|
+
manifest: nonEmptyStringDecoder$1,
|
|
965
|
+
manifestType: nonEmptyStringDecoder$1,
|
|
966
|
+
tooltip: optional$1(nonEmptyStringDecoder$1),
|
|
967
|
+
description: optional$1(nonEmptyStringDecoder$1),
|
|
968
|
+
contactEmail: optional$1(nonEmptyStringDecoder$1),
|
|
969
|
+
supportEmail: optional$1(nonEmptyStringDecoder$1),
|
|
970
|
+
publisher: optional$1(nonEmptyStringDecoder$1),
|
|
971
|
+
images: optional$1(array$1(object$1({ url: optional$1(nonEmptyStringDecoder$1) }))),
|
|
972
|
+
icons: optional$1(array$1(object$1({ icon: optional$1(nonEmptyStringDecoder$1) }))),
|
|
973
|
+
customConfig: anyJson$1(),
|
|
974
|
+
intents: optional$1(array$1(intentDefinitionDecoder))
|
|
975
|
+
});
|
|
976
|
+
const v2LocalizedDefinitionDecoder = object$1({
|
|
977
|
+
appId: optional$1(nonEmptyStringDecoder$1),
|
|
978
|
+
name: optional$1(nonEmptyStringDecoder$1),
|
|
979
|
+
details: optional$1(v2DetailsDecoder),
|
|
980
|
+
version: optional$1(nonEmptyStringDecoder$1),
|
|
981
|
+
title: optional$1(nonEmptyStringDecoder$1),
|
|
982
|
+
tooltip: optional$1(nonEmptyStringDecoder$1),
|
|
983
|
+
lang: optional$1(nonEmptyStringDecoder$1),
|
|
984
|
+
description: optional$1(nonEmptyStringDecoder$1),
|
|
985
|
+
categories: optional$1(array$1(nonEmptyStringDecoder$1)),
|
|
986
|
+
icons: optional$1(array$1(v2IconDecoder)),
|
|
987
|
+
screenshots: optional$1(array$1(v2ScreenshotDecoder)),
|
|
988
|
+
contactEmail: optional$1(nonEmptyStringDecoder$1),
|
|
989
|
+
supportEmail: optional$1(nonEmptyStringDecoder$1),
|
|
990
|
+
moreInfo: optional$1(nonEmptyStringDecoder$1),
|
|
991
|
+
publisher: optional$1(nonEmptyStringDecoder$1),
|
|
992
|
+
customConfig: optional$1(array$1(anyJson$1())),
|
|
993
|
+
hostManifests: optional$1(hostManifestsBrowserDecoder),
|
|
994
|
+
interop: optional$1(v2InteropDecoder)
|
|
995
|
+
});
|
|
996
|
+
const v2DefinitionDecoder = object$1({
|
|
997
|
+
appId: nonEmptyStringDecoder$1,
|
|
998
|
+
name: nonEmptyStringDecoder$1,
|
|
999
|
+
type: v2TypeDecoder,
|
|
1000
|
+
details: v2DetailsDecoder,
|
|
1001
|
+
version: optional$1(nonEmptyStringDecoder$1),
|
|
1002
|
+
title: optional$1(nonEmptyStringDecoder$1),
|
|
1003
|
+
tooltip: optional$1(nonEmptyStringDecoder$1),
|
|
1004
|
+
lang: optional$1(nonEmptyStringDecoder$1),
|
|
1005
|
+
description: optional$1(nonEmptyStringDecoder$1),
|
|
1006
|
+
categories: optional$1(array$1(nonEmptyStringDecoder$1)),
|
|
1007
|
+
icons: optional$1(array$1(v2IconDecoder)),
|
|
1008
|
+
screenshots: optional$1(array$1(v2ScreenshotDecoder)),
|
|
1009
|
+
contactEmail: optional$1(nonEmptyStringDecoder$1),
|
|
1010
|
+
supportEmail: optional$1(nonEmptyStringDecoder$1),
|
|
1011
|
+
moreInfo: optional$1(nonEmptyStringDecoder$1),
|
|
1012
|
+
publisher: optional$1(nonEmptyStringDecoder$1),
|
|
1013
|
+
customConfig: optional$1(array$1(anyJson$1())),
|
|
1014
|
+
hostManifests: optional$1(hostManifestsBrowserDecoder),
|
|
1015
|
+
interop: optional$1(v2InteropDecoder),
|
|
1016
|
+
localizedVersions: optional$1(dict(v2LocalizedDefinitionDecoder))
|
|
1017
|
+
});
|
|
1018
|
+
const allDefinitionsDecoder = oneOf$1(v1DefinitionDecoder, v2DefinitionDecoder);
|
|
1019
|
+
|
|
1020
|
+
const parseDecoderErrorToStringMessage = (error) => {
|
|
1021
|
+
return `${error.kind} at ${error.at}: ${JSON.stringify(error.input)}. Reason - ${error.message}`;
|
|
1022
|
+
};
|
|
1023
|
+
|
|
1024
|
+
class FDC3Service {
|
|
1025
|
+
constructor() {
|
|
1026
|
+
this.fdc3ToDesktopDefinitionType = {
|
|
1027
|
+
web: "window",
|
|
1028
|
+
native: "exe",
|
|
1029
|
+
citrix: "citrix",
|
|
1030
|
+
onlineNative: "clickonce",
|
|
1031
|
+
other: "window"
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
toApi() {
|
|
1035
|
+
return {
|
|
1036
|
+
isFdc3Definition: this.isFdc3Definition.bind(this),
|
|
1037
|
+
parseToBrowserBaseAppData: this.parseToBrowserBaseAppData.bind(this),
|
|
1038
|
+
parseToDesktopAppConfig: this.parseToDesktopAppConfig.bind(this)
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
isFdc3Definition(definition) {
|
|
1042
|
+
const decodeRes = allDefinitionsDecoder.run(definition);
|
|
1043
|
+
if (!decodeRes.ok) {
|
|
1044
|
+
return { isFdc3: false, reason: parseDecoderErrorToStringMessage(decodeRes.error) };
|
|
1045
|
+
}
|
|
1046
|
+
if (definition.appId && definition.details) {
|
|
1047
|
+
return { isFdc3: true, version: "2.0" };
|
|
1048
|
+
}
|
|
1049
|
+
if (definition.manifest) {
|
|
1050
|
+
return { isFdc3: true, version: "1.2" };
|
|
1051
|
+
}
|
|
1052
|
+
return { isFdc3: false, reason: "The passed definition is not FDC3" };
|
|
1053
|
+
}
|
|
1054
|
+
parseToBrowserBaseAppData(definition) {
|
|
1055
|
+
var _a;
|
|
1056
|
+
const { isFdc3, version } = this.isFdc3Definition(definition);
|
|
1057
|
+
if (!isFdc3) {
|
|
1058
|
+
throw new Error("The passed definition is not FDC3");
|
|
1059
|
+
}
|
|
1060
|
+
const decodeRes = allDefinitionsDecoder.run(definition);
|
|
1061
|
+
if (!decodeRes.ok) {
|
|
1062
|
+
throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(decodeRes.error)}`);
|
|
1063
|
+
}
|
|
1064
|
+
const userProperties = this.getUserPropertiesFromDefinition(definition, version);
|
|
1065
|
+
const createOptions = { url: this.getUrl(definition, version) };
|
|
1066
|
+
let baseApplicationData = {
|
|
1067
|
+
name: definition.appId,
|
|
1068
|
+
type: "window",
|
|
1069
|
+
createOptions,
|
|
1070
|
+
userProperties: Object.assign(Object.assign({}, userProperties), { intents: version === "1.2"
|
|
1071
|
+
? userProperties.intents
|
|
1072
|
+
: this.getIntentsFromV2AppDefinition(definition), details: createOptions }),
|
|
1073
|
+
title: definition.title,
|
|
1074
|
+
version: definition.version,
|
|
1075
|
+
icon: this.getIconFromDefinition(definition, version),
|
|
1076
|
+
caption: definition.description,
|
|
1077
|
+
fdc3: version === "2.0" ? Object.assign(Object.assign({}, definition), { definitionVersion: "2.0" }) : undefined,
|
|
1078
|
+
};
|
|
1079
|
+
if ((_a = definition.hostManifests) === null || _a === void 0 ? void 0 : _a["Glue42"]) {
|
|
1080
|
+
const decodeRes = glue42HostManifestsBrowserDecoder.run(definition.hostManifests["Glue42"]);
|
|
1081
|
+
if (!decodeRes.ok) {
|
|
1082
|
+
throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(decodeRes.error)}`);
|
|
1083
|
+
}
|
|
1084
|
+
if (!Object.keys(decodeRes.result).length) {
|
|
1085
|
+
throw new Error("Invalid 'hostManifests['Glue42]' key");
|
|
1086
|
+
}
|
|
1087
|
+
baseApplicationData = this.mergeBaseAppDataWithGlueManifest(baseApplicationData, decodeRes.result);
|
|
1088
|
+
}
|
|
1089
|
+
return baseApplicationData;
|
|
1090
|
+
}
|
|
1091
|
+
parseToDesktopAppConfig(definition) {
|
|
1092
|
+
var _a, _b, _c;
|
|
1093
|
+
const { isFdc3, version } = this.isFdc3Definition(definition);
|
|
1094
|
+
if (!isFdc3) {
|
|
1095
|
+
throw new Error("The passed definition is not FDC3");
|
|
1096
|
+
}
|
|
1097
|
+
const decodeRes = allDefinitionsDecoder.run(definition);
|
|
1098
|
+
if (!decodeRes.ok) {
|
|
1099
|
+
throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(decodeRes.error)}`);
|
|
1100
|
+
}
|
|
1101
|
+
if (version === "1.2") {
|
|
1102
|
+
const fdc3v1Definition = definition;
|
|
1103
|
+
return {
|
|
1104
|
+
name: fdc3v1Definition.appId,
|
|
1105
|
+
type: "window",
|
|
1106
|
+
details: {
|
|
1107
|
+
url: this.getUrl(definition, version)
|
|
1108
|
+
},
|
|
1109
|
+
version: fdc3v1Definition.version,
|
|
1110
|
+
title: fdc3v1Definition.title,
|
|
1111
|
+
tooltip: fdc3v1Definition.tooltip,
|
|
1112
|
+
caption: fdc3v1Definition.description,
|
|
1113
|
+
icon: (_a = fdc3v1Definition.icons) === null || _a === void 0 ? void 0 : _a[0].icon,
|
|
1114
|
+
intents: fdc3v1Definition.intents,
|
|
1115
|
+
customProperties: {
|
|
1116
|
+
manifestType: fdc3v1Definition.manifestType,
|
|
1117
|
+
images: fdc3v1Definition.images,
|
|
1118
|
+
contactEmail: fdc3v1Definition.contactEmail,
|
|
1119
|
+
supportEmail: fdc3v1Definition.supportEmail,
|
|
1120
|
+
publisher: fdc3v1Definition.publisher,
|
|
1121
|
+
icons: fdc3v1Definition.icons,
|
|
1122
|
+
customConfig: fdc3v1Definition.customConfig
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
const fdc3v2Definition = definition;
|
|
1127
|
+
let desktopDefinition = {
|
|
1128
|
+
name: fdc3v2Definition.appId,
|
|
1129
|
+
type: this.fdc3ToDesktopDefinitionType[fdc3v2Definition.type],
|
|
1130
|
+
details: fdc3v2Definition.details,
|
|
1131
|
+
version: fdc3v2Definition.version,
|
|
1132
|
+
title: fdc3v2Definition.title,
|
|
1133
|
+
tooltip: fdc3v2Definition.tooltip,
|
|
1134
|
+
caption: fdc3v2Definition.description,
|
|
1135
|
+
icon: this.getIconFromDefinition(fdc3v2Definition, "2.0"),
|
|
1136
|
+
intents: this.getIntentsFromV2AppDefinition(fdc3v2Definition),
|
|
1137
|
+
fdc3: Object.assign(Object.assign({}, fdc3v2Definition), { definitionVersion: "2.0" })
|
|
1138
|
+
};
|
|
1139
|
+
if ((_b = fdc3v2Definition.hostManifests) === null || _b === void 0 ? void 0 : _b["Glue42"]) {
|
|
1140
|
+
if (typeof fdc3v2Definition.hostManifests["Glue42"] !== "object" || Array.isArray(fdc3v2Definition.hostManifests["Glue42"])) {
|
|
1141
|
+
throw new Error("Invalid 'hostManifests['Glue42]' key");
|
|
1142
|
+
}
|
|
1143
|
+
desktopDefinition = this.mergeDesktopConfigWithGlueManifest(desktopDefinition, (_c = fdc3v2Definition.hostManifests) === null || _c === void 0 ? void 0 : _c["Glue42"]);
|
|
1144
|
+
}
|
|
1145
|
+
return desktopDefinition;
|
|
1146
|
+
}
|
|
1147
|
+
getUserPropertiesFromDefinition(definition, version) {
|
|
1148
|
+
if (version === "1.2") {
|
|
1149
|
+
return Object.fromEntries(Object.entries(definition).filter(([key]) => !connectBrowserAppProps.includes(key)));
|
|
1150
|
+
}
|
|
1151
|
+
return Object.fromEntries(Object.entries(definition).filter(([key]) => !connectBrowserAppProps.includes(key) && !fdc3v2AppProps.includes(key)));
|
|
1152
|
+
}
|
|
1153
|
+
getUrl(definition, version) {
|
|
1154
|
+
var _a, _b;
|
|
1155
|
+
let url;
|
|
1156
|
+
if (version === "1.2") {
|
|
1157
|
+
const parsedManifest = JSON.parse(definition.manifest);
|
|
1158
|
+
url = ((_a = parsedManifest.details) === null || _a === void 0 ? void 0 : _a.url) || parsedManifest.url;
|
|
1159
|
+
}
|
|
1160
|
+
else {
|
|
1161
|
+
url = (_b = definition.details) === null || _b === void 0 ? void 0 : _b.url;
|
|
1162
|
+
}
|
|
1163
|
+
if (!url || typeof url !== "string") {
|
|
1164
|
+
throw new Error(`Invalid FDC3 ${version} definition. Provide valid 'url' under '${version === "1.2" ? "manifest" : "details"}' key`);
|
|
1165
|
+
}
|
|
1166
|
+
return url;
|
|
1167
|
+
}
|
|
1168
|
+
getIntentsFromV2AppDefinition(definition) {
|
|
1169
|
+
var _a, _b;
|
|
1170
|
+
const fdc3Intents = (_b = (_a = definition.interop) === null || _a === void 0 ? void 0 : _a.intents) === null || _b === void 0 ? void 0 : _b.listensFor;
|
|
1171
|
+
if (!fdc3Intents) {
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
const intents = Object.entries(fdc3Intents).map((fdc3Intent) => {
|
|
1175
|
+
const [intentName, intentData] = fdc3Intent;
|
|
1176
|
+
return Object.assign({ name: intentName }, intentData);
|
|
1177
|
+
});
|
|
1178
|
+
return intents;
|
|
1179
|
+
}
|
|
1180
|
+
getIconFromDefinition(definition, version) {
|
|
1181
|
+
var _a, _b, _c, _d;
|
|
1182
|
+
if (version === "1.2") {
|
|
1183
|
+
return ((_b = (_a = definition.icons) === null || _a === void 0 ? void 0 : _a.find((iconDef) => iconDef.icon)) === null || _b === void 0 ? void 0 : _b.icon) || undefined;
|
|
1184
|
+
}
|
|
1185
|
+
return ((_d = (_c = definition.icons) === null || _c === void 0 ? void 0 : _c.find((iconDef) => iconDef.src)) === null || _d === void 0 ? void 0 : _d.src) || undefined;
|
|
1186
|
+
}
|
|
1187
|
+
mergeBaseAppDataWithGlueManifest(baseAppData, hostManifestDefinition) {
|
|
1188
|
+
let baseApplicationDefinition = baseAppData;
|
|
1189
|
+
if (hostManifestDefinition.details) {
|
|
1190
|
+
const details = Object.assign(Object.assign({}, baseAppData.createOptions), hostManifestDefinition.details);
|
|
1191
|
+
baseApplicationDefinition.createOptions = details;
|
|
1192
|
+
baseApplicationDefinition.userProperties.details = details;
|
|
1193
|
+
}
|
|
1194
|
+
if (Array.isArray(hostManifestDefinition.intents)) {
|
|
1195
|
+
baseApplicationDefinition.userProperties.intents = (baseApplicationDefinition.userProperties.intents || []).concat(hostManifestDefinition.intents);
|
|
1196
|
+
}
|
|
1197
|
+
baseApplicationDefinition = Object.assign(Object.assign({}, baseApplicationDefinition), hostManifestDefinition);
|
|
1198
|
+
delete baseApplicationDefinition.details;
|
|
1199
|
+
delete baseApplicationDefinition.intents;
|
|
1200
|
+
return baseApplicationDefinition;
|
|
1201
|
+
}
|
|
1202
|
+
mergeDesktopConfigWithGlueManifest(config, desktopDefinition) {
|
|
1203
|
+
const appConfig = Object.assign({}, config, desktopDefinition, { details: Object.assign(Object.assign({}, config.details), desktopDefinition.details) });
|
|
1204
|
+
if (Array.isArray(desktopDefinition.intents)) {
|
|
1205
|
+
appConfig.intents = (config.intents || []).concat(desktopDefinition.intents);
|
|
1206
|
+
}
|
|
1207
|
+
return appConfig;
|
|
1208
|
+
}
|
|
36
1209
|
}
|
|
37
1210
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
} else {
|
|
48
|
-
id += '_';
|
|
1211
|
+
const decoders$1 = {
|
|
1212
|
+
common: {
|
|
1213
|
+
nonEmptyStringDecoder: nonEmptyStringDecoder$1,
|
|
1214
|
+
nonNegativeNumberDecoder
|
|
1215
|
+
},
|
|
1216
|
+
fdc3: {
|
|
1217
|
+
allDefinitionsDecoder,
|
|
1218
|
+
v1DefinitionDecoder,
|
|
1219
|
+
v2DefinitionDecoder
|
|
49
1220
|
}
|
|
50
|
-
|
|
51
|
-
}, '');
|
|
1221
|
+
};
|
|
52
1222
|
|
|
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
|
-
const timeout = setTimeout(() => {
|
|
88
|
-
const message = timeoutMessage || `Promise timeout hit: ${timeoutMilliseconds}`;
|
|
89
|
-
reject(message);
|
|
90
|
-
}, timeoutMilliseconds);
|
|
91
|
-
promise()
|
|
92
|
-
.then((result) => {
|
|
93
|
-
clearTimeout(timeout);
|
|
94
|
-
resolve(result);
|
|
95
|
-
})
|
|
96
|
-
.catch((error) => {
|
|
97
|
-
clearTimeout(timeout);
|
|
98
|
-
reject(error);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
const generateCommandId = () => {
|
|
103
|
-
return nanoid();
|
|
1223
|
+
var INTENTS_ERRORS;
|
|
1224
|
+
(function (INTENTS_ERRORS) {
|
|
1225
|
+
INTENTS_ERRORS["USER_CANCELLED"] = "User Closed Intents Resolver UI without choosing a handler";
|
|
1226
|
+
INTENTS_ERRORS["CALLER_NOT_DEFINED"] = "Caller Id is not defined";
|
|
1227
|
+
INTENTS_ERRORS["TIMEOUT_HIT"] = "Timeout hit";
|
|
1228
|
+
INTENTS_ERRORS["INTENT_NOT_FOUND"] = "Cannot find Intent";
|
|
1229
|
+
INTENTS_ERRORS["HANDLER_NOT_FOUND"] = "Cannot find Intent Handler";
|
|
1230
|
+
INTENTS_ERRORS["TARGET_INSTANCE_UNAVAILABLE"] = "Cannot start Target Instance";
|
|
1231
|
+
INTENTS_ERRORS["INTENT_DELIVERY_FAILED"] = "Target Instance did not add a listener";
|
|
1232
|
+
INTENTS_ERRORS["RESOLVER_UNAVAILABLE"] = "Intents Resolver UI unavailable";
|
|
1233
|
+
INTENTS_ERRORS["RESOLVER_TIMEOUT"] = "User did not choose a handler";
|
|
1234
|
+
INTENTS_ERRORS["INVALID_RESOLVER_RESPONSE"] = "Intents Resolver UI returned invalid response";
|
|
1235
|
+
INTENTS_ERRORS["INTENT_HANDLER_REJECTION"] = "Intent Handler function processing the raised intent threw an error or rejected the promise it returned";
|
|
1236
|
+
})(INTENTS_ERRORS || (INTENTS_ERRORS = {}));
|
|
1237
|
+
|
|
1238
|
+
let IoC$1 = class IoC {
|
|
1239
|
+
constructor() {
|
|
1240
|
+
this._decoders = decoders$1;
|
|
1241
|
+
this._errors = {
|
|
1242
|
+
intents: INTENTS_ERRORS
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
get fdc3() {
|
|
1246
|
+
if (!this._fdc3) {
|
|
1247
|
+
this._fdc3 = new FDC3Service().toApi();
|
|
1248
|
+
}
|
|
1249
|
+
return this._fdc3;
|
|
1250
|
+
}
|
|
1251
|
+
get decoders() {
|
|
1252
|
+
return this._decoders;
|
|
1253
|
+
}
|
|
1254
|
+
get errors() {
|
|
1255
|
+
return this._errors;
|
|
1256
|
+
}
|
|
104
1257
|
};
|
|
105
1258
|
|
|
1259
|
+
const ioc = new IoC$1();
|
|
1260
|
+
ioc.fdc3;
|
|
1261
|
+
ioc.decoders;
|
|
1262
|
+
const errors = ioc.errors;
|
|
1263
|
+
|
|
106
1264
|
var IntentHandlerResultTypes;
|
|
107
1265
|
(function (IntentHandlerResultTypes) {
|
|
108
1266
|
IntentHandlerResultTypes["Context"] = "Context";
|
|
@@ -200,7 +1358,8 @@ const Fdc3SupportedIntentTypes = {
|
|
|
200
1358
|
"fdc3.instrument",
|
|
201
1359
|
"fdc3.organization"
|
|
202
1360
|
]
|
|
203
|
-
};
|
|
1361
|
+
};
|
|
1362
|
+
const IO_ERRORS = errors.intents;
|
|
204
1363
|
|
|
205
1364
|
const ioConnectFDC3SystemMethod = "FDC3.Collaborate";
|
|
206
1365
|
const PrivateChannelPrefix = "___privateFDC3Channel___";
|
|
@@ -1115,6 +2274,26 @@ class GlueController {
|
|
|
1115
2274
|
return this.glue.intents.raise(request);
|
|
1116
2275
|
});
|
|
1117
2276
|
}
|
|
2277
|
+
doesFilterHandlersExist() {
|
|
2278
|
+
return !!this.glue.intents.filterHandlers;
|
|
2279
|
+
}
|
|
2280
|
+
filterHandlers(handlerFilter) {
|
|
2281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2282
|
+
if (!this.glue.intents.filterHandlers) {
|
|
2283
|
+
throw new Error("Intents method 'filterHandlers' does not exist");
|
|
2284
|
+
}
|
|
2285
|
+
return this.glue.intents.filterHandlers(handlerFilter);
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2288
|
+
doesGetIntentsExist() {
|
|
2289
|
+
return !!this.glue.intents.getIntents;
|
|
2290
|
+
}
|
|
2291
|
+
getIntents(handler) {
|
|
2292
|
+
if (!this.glue.intents.getIntents) {
|
|
2293
|
+
throw new Error("Intents method 'getIntents' does not exist");
|
|
2294
|
+
}
|
|
2295
|
+
return this.glue.intents.getIntents(handler);
|
|
2296
|
+
}
|
|
1118
2297
|
getMyWindowContext() {
|
|
1119
2298
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1120
2299
|
const myWin = this.getMyWindow();
|
|
@@ -1245,7 +2424,8 @@ class GlueController {
|
|
|
1245
2424
|
return this.glue.interop.servers(methodFilter);
|
|
1246
2425
|
}
|
|
1247
2426
|
initSubLogger(name) {
|
|
1248
|
-
|
|
2427
|
+
var _a;
|
|
2428
|
+
return (_a = this.logger) === null || _a === void 0 ? void 0 : _a.subLogger(name);
|
|
1249
2429
|
}
|
|
1250
2430
|
invokePreviouslyBroadcastedData({ callback, contextData, metadata, contextType }) {
|
|
1251
2431
|
const invokeForType = contextType || this.channelsParser.mapChannelsDelimiterToFDC3Type(contextData.latest_fdc3_type);
|
|
@@ -1325,23 +2505,150 @@ const REQUEST_GLUE = "requestGlue";
|
|
|
1325
2505
|
const REQUEST_GLUE_RESPONSE = "requestGlueResponse";
|
|
1326
2506
|
const FDC3_READY = "fdc3Ready";
|
|
1327
2507
|
|
|
1328
|
-
class EventDispatcher {
|
|
1329
|
-
fireFdc3Ready() {
|
|
1330
|
-
const event = new Event(FDC3_READY);
|
|
1331
|
-
window.dispatchEvent(event);
|
|
1332
|
-
}
|
|
1333
|
-
fireNotifyStarted() {
|
|
1334
|
-
this.send(NOTIFY_STARTED);
|
|
1335
|
-
}
|
|
1336
|
-
fireRequestGlue() {
|
|
1337
|
-
this.send(REQUEST_GLUE);
|
|
1338
|
-
}
|
|
1339
|
-
send(eventName, message) {
|
|
1340
|
-
const payload = { glue42: { event: eventName, message } };
|
|
1341
|
-
const event = new CustomEvent(GLUE42_EVENT_NAME, { detail: payload });
|
|
1342
|
-
window.dispatchEvent(event);
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
2508
|
+
class EventDispatcher {
|
|
2509
|
+
fireFdc3Ready() {
|
|
2510
|
+
const event = new Event(FDC3_READY);
|
|
2511
|
+
window.dispatchEvent(event);
|
|
2512
|
+
}
|
|
2513
|
+
fireNotifyStarted() {
|
|
2514
|
+
this.send(NOTIFY_STARTED);
|
|
2515
|
+
}
|
|
2516
|
+
fireRequestGlue() {
|
|
2517
|
+
this.send(REQUEST_GLUE);
|
|
2518
|
+
}
|
|
2519
|
+
send(eventName, message) {
|
|
2520
|
+
const payload = { glue42: { event: eventName, message } };
|
|
2521
|
+
const event = new CustomEvent(GLUE42_EVENT_NAME, { detail: payload });
|
|
2522
|
+
window.dispatchEvent(event);
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
|
|
2526
|
+
// To parse this data:
|
|
2527
|
+
|
|
2528
|
+
/**
|
|
2529
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2530
|
+
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
2531
|
+
*/
|
|
2532
|
+
/** Constants representing the errors that can be encountered when calling the `open` method on the DesktopAgent object (`fdc3`). */
|
|
2533
|
+
var OpenError;
|
|
2534
|
+
(function (OpenError) {
|
|
2535
|
+
/** Returned if the specified application is not found.*/
|
|
2536
|
+
OpenError["AppNotFound"] = "AppNotFound";
|
|
2537
|
+
/** Returned if the specified application fails to launch correctly.*/
|
|
2538
|
+
OpenError["ErrorOnLaunch"] = "ErrorOnLaunch";
|
|
2539
|
+
/** Returned if the specified application launches but fails to add a context listener in order to receive the context passed to the `fdc3.open` call.*/
|
|
2540
|
+
OpenError["AppTimeout"] = "AppTimeout";
|
|
2541
|
+
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
2542
|
+
OpenError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
2543
|
+
/** Returned if a call to the `open` function is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
2544
|
+
OpenError["MalformedContext"] = "MalformedContext";
|
|
2545
|
+
/** @experimental Returned if the specified Desktop Agent is not found, via a connected Desktop Agent Bridge.*/
|
|
2546
|
+
OpenError["DesktopAgentNotFound"] = "DesktopAgentNotFound";
|
|
2547
|
+
})(OpenError || (OpenError = {}));
|
|
2548
|
+
/** Constants representing the errors that can be encountered when calling the `findIntent`, `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the DesktopAgent (`fdc3`). */
|
|
2549
|
+
var ResolveError;
|
|
2550
|
+
(function (ResolveError) {
|
|
2551
|
+
/** SHOULD be returned if no apps are available that can resolve the intent and context combination.*/
|
|
2552
|
+
ResolveError["NoAppsFound"] = "NoAppsFound";
|
|
2553
|
+
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
2554
|
+
ResolveError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
2555
|
+
/** Returned if the user cancelled the resolution request, for example by closing or cancelling a resolver UI.*/
|
|
2556
|
+
ResolveError["UserCancelled"] = "UserCancelledResolution";
|
|
2557
|
+
/** SHOULD be returned if a timeout cancels an intent resolution that required user interaction. Please use `ResolverUnavailable` instead for situations where a resolver UI or similar fails.*/
|
|
2558
|
+
ResolveError["ResolverTimeout"] = "ResolverTimeout";
|
|
2559
|
+
/** Returned if a specified target application is not available or a new instance of it cannot be opened. */
|
|
2560
|
+
ResolveError["TargetAppUnavailable"] = "TargetAppUnavailable";
|
|
2561
|
+
/** Returned if a specified target application instance is not available, for example because it has been closed. */
|
|
2562
|
+
ResolveError["TargetInstanceUnavailable"] = "TargetInstanceUnavailable";
|
|
2563
|
+
/** Returned if the intent and context could not be delivered to the selected application or instance, for example because it has not added an intent handler within a timeout.*/
|
|
2564
|
+
ResolveError["IntentDeliveryFailed"] = "IntentDeliveryFailed";
|
|
2565
|
+
/** Returned if a call to one of the `raiseIntent` functions is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
2566
|
+
ResolveError["MalformedContext"] = "MalformedContext";
|
|
2567
|
+
/** @experimental Returned if the specified Desktop Agent is not found, via a connected Desktop Agent Bridge.*/
|
|
2568
|
+
ResolveError["DesktopAgentNotFound"] = "DesktopAgentNotFound";
|
|
2569
|
+
})(ResolveError || (ResolveError = {}));
|
|
2570
|
+
var ResultError;
|
|
2571
|
+
(function (ResultError) {
|
|
2572
|
+
/** Returned if the intent handler exited without returning a valid result (a promise resolving to a Context, Channel object or void). */
|
|
2573
|
+
ResultError["NoResultReturned"] = "NoResultReturned";
|
|
2574
|
+
/** Returned if the Intent handler function processing the raised intent throws an error or rejects the Promise it returned. */
|
|
2575
|
+
ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
|
|
2576
|
+
})(ResultError || (ResultError = {}));
|
|
2577
|
+
var ChannelError;
|
|
2578
|
+
(function (ChannelError) {
|
|
2579
|
+
/** Returned if the specified channel is not found when attempting to join a channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).*/
|
|
2580
|
+
ChannelError["NoChannelFound"] = "NoChannelFound";
|
|
2581
|
+
/** SHOULD be returned when a request to join a user channel or to a retrieve a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods of the DesktopAgent (`fdc3`) object is denied. */
|
|
2582
|
+
ChannelError["AccessDenied"] = "AccessDenied";
|
|
2583
|
+
/** SHOULD be returned when a channel cannot be created or retrieved via the `getOrCreateChannel` method of the DesktopAgent (`fdc3`).*/
|
|
2584
|
+
ChannelError["CreationFailed"] = "CreationFailed";
|
|
2585
|
+
/** Returned if a call to the `broadcast` functions is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
2586
|
+
ChannelError["MalformedContext"] = "MalformedContext";
|
|
2587
|
+
})(ChannelError || (ChannelError = {}));
|
|
2588
|
+
var BridgingError;
|
|
2589
|
+
(function (BridgingError) {
|
|
2590
|
+
/** @experimental Returned if a Desktop Agent did not return a response, via Desktop Agent Bridging, within the alloted timeout. */
|
|
2591
|
+
BridgingError["ResponseTimedOut"] = "ResponseToBridgeTimedOut";
|
|
2592
|
+
/** @experimental Returned if a Desktop Agent that has been targeted by a particular request has been disconnected from the Bridge before a response has been received from it. */
|
|
2593
|
+
BridgingError["AgentDisconnected"] = "AgentDisconnected";
|
|
2594
|
+
/** @experimental Returned for FDC3 API calls that are specified with arguments indicating that a remote Desktop agent should be targeted (e.g. raiseIntent with an app on a remote DesktopAgent targeted), when the local Desktop Agent is not connected to a bridge. */
|
|
2595
|
+
BridgingError["NotConnectedToBridge"] = "NotConnectedToBridge";
|
|
2596
|
+
/** @experimental Returned if a message to a Bridge deviates from the schema for that message sufficiently that it could not be processed. */
|
|
2597
|
+
BridgingError["MalformedMessage"] = "MalformedMessage";
|
|
2598
|
+
})(BridgingError || (BridgingError = {}));
|
|
2599
|
+
|
|
2600
|
+
/**
|
|
2601
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2602
|
+
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
2603
|
+
*/
|
|
2604
|
+
var ContextTypes;
|
|
2605
|
+
(function (ContextTypes) {
|
|
2606
|
+
ContextTypes["Chart"] = "fdc3.chart";
|
|
2607
|
+
ContextTypes["ChatInitSettings"] = "fdc3.chat.initSettings";
|
|
2608
|
+
ContextTypes["ChatRoom"] = "fdc3.chat.room";
|
|
2609
|
+
ContextTypes["Contact"] = "fdc3.contact";
|
|
2610
|
+
ContextTypes["ContactList"] = "fdc3.contactList";
|
|
2611
|
+
ContextTypes["Country"] = "fdc3.country";
|
|
2612
|
+
ContextTypes["Currency"] = "fdc3.currency";
|
|
2613
|
+
ContextTypes["Email"] = "fdc3.email";
|
|
2614
|
+
ContextTypes["Instrument"] = "fdc3.instrument";
|
|
2615
|
+
ContextTypes["InstrumentList"] = "fdc3.instrumentList";
|
|
2616
|
+
ContextTypes["Interaction"] = "fdc3.interaction";
|
|
2617
|
+
ContextTypes["Nothing"] = "fdc3.nothing";
|
|
2618
|
+
ContextTypes["Organization"] = "fdc3.organization";
|
|
2619
|
+
ContextTypes["Portfolio"] = "fdc3.portfolio";
|
|
2620
|
+
ContextTypes["Position"] = "fdc3.position";
|
|
2621
|
+
ContextTypes["ChatSearchCriteria"] = "fdc3.chat.searchCriteria";
|
|
2622
|
+
ContextTypes["TimeRange"] = "fdc3.timerange";
|
|
2623
|
+
ContextTypes["TransactionResult"] = "fdc3.transactionResult";
|
|
2624
|
+
ContextTypes["Valuation"] = "fdc3.valuation";
|
|
2625
|
+
})(ContextTypes || (ContextTypes = {}));
|
|
2626
|
+
|
|
2627
|
+
/**
|
|
2628
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2629
|
+
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
2630
|
+
*/
|
|
2631
|
+
var Intents;
|
|
2632
|
+
(function (Intents) {
|
|
2633
|
+
Intents["CreateInteraction"] = "CreateInteraction";
|
|
2634
|
+
Intents["SendChatMessage"] = "SendChatMessage";
|
|
2635
|
+
Intents["StartCall"] = "StartCall";
|
|
2636
|
+
Intents["StartChat"] = "StartChat";
|
|
2637
|
+
Intents["StartEmail"] = "StartEmail";
|
|
2638
|
+
Intents["ViewAnalysis"] = "ViewAnalysis";
|
|
2639
|
+
Intents["ViewChat"] = "ViewChat";
|
|
2640
|
+
Intents["ViewChart"] = "ViewChart";
|
|
2641
|
+
Intents["ViewContact"] = "ViewContact";
|
|
2642
|
+
Intents["ViewHoldings"] = "ViewHoldings";
|
|
2643
|
+
Intents["ViewInstrument"] = "ViewInstrument";
|
|
2644
|
+
Intents["ViewInteractions"] = "ViewInteractions";
|
|
2645
|
+
Intents["ViewMessages"] = "ViewMessages";
|
|
2646
|
+
Intents["ViewNews"] = "ViewNews";
|
|
2647
|
+
Intents["ViewOrders"] = "ViewOrders";
|
|
2648
|
+
Intents["ViewProfile"] = "ViewProfile";
|
|
2649
|
+
Intents["ViewQuote"] = "ViewQuote";
|
|
2650
|
+
Intents["ViewResearch"] = "ViewResearch";
|
|
2651
|
+
})(Intents || (Intents = {}));
|
|
1345
2652
|
|
|
1346
2653
|
class DesktopAgent {
|
|
1347
2654
|
constructor(intentsController, applicationController, channelsController) {
|
|
@@ -1377,7 +2684,10 @@ class DesktopAgent {
|
|
|
1377
2684
|
open(target, context) {
|
|
1378
2685
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1379
2686
|
targetAppDecoder.runWithException(target);
|
|
1380
|
-
optionalContextDecoder.
|
|
2687
|
+
const contextDecoderResult = optionalContextDecoder.run(context);
|
|
2688
|
+
if (!contextDecoderResult.ok) {
|
|
2689
|
+
throw new Error(OpenError.MalformedContext);
|
|
2690
|
+
}
|
|
1381
2691
|
return this.applicationController.open({ commandId: generateCommandId(), target, context });
|
|
1382
2692
|
});
|
|
1383
2693
|
}
|
|
@@ -1400,7 +2710,10 @@ class DesktopAgent {
|
|
|
1400
2710
|
}
|
|
1401
2711
|
broadcast(context) {
|
|
1402
2712
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1403
|
-
contextDecoder.
|
|
2713
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2714
|
+
if (!contextDecoderResult.ok) {
|
|
2715
|
+
throw new Error(ChannelError.MalformedContext);
|
|
2716
|
+
}
|
|
1404
2717
|
return this.channelsController.broadcast(generateCommandId(), context);
|
|
1405
2718
|
});
|
|
1406
2719
|
}
|
|
@@ -1424,7 +2737,7 @@ class DesktopAgent {
|
|
|
1424
2737
|
nonEmptyStringDecoder.runWithException(intent);
|
|
1425
2738
|
const contextDecoderResult = optionalContextDecoder.run(context);
|
|
1426
2739
|
if (!contextDecoderResult.ok) {
|
|
1427
|
-
throw new Error(
|
|
2740
|
+
throw new Error(ResolveError.MalformedContext);
|
|
1428
2741
|
}
|
|
1429
2742
|
optionalNonEmptyStringDecoder.runWithException(resultType);
|
|
1430
2743
|
return this.intentsController.findIntent({ commandId: generateCommandId(), intent, context: contextDecoderResult.result, resultType });
|
|
@@ -1434,7 +2747,7 @@ class DesktopAgent {
|
|
|
1434
2747
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1435
2748
|
const contextDecoderResult = contextDecoder.run(context);
|
|
1436
2749
|
if (!contextDecoderResult.ok) {
|
|
1437
|
-
throw new Error(
|
|
2750
|
+
throw new Error(ResolveError.MalformedContext);
|
|
1438
2751
|
}
|
|
1439
2752
|
optionalNonEmptyStringDecoder.runWithException(resultType);
|
|
1440
2753
|
return this.intentsController.findIntentsByContext({ commandId: generateCommandId(), context: contextDecoderResult.result, resultType });
|
|
@@ -1443,14 +2756,20 @@ class DesktopAgent {
|
|
|
1443
2756
|
raiseIntent(intent, context, app) {
|
|
1444
2757
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1445
2758
|
nonEmptyStringDecoder.runWithException(intent);
|
|
1446
|
-
contextDecoder.
|
|
2759
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2760
|
+
if (!contextDecoderResult.ok) {
|
|
2761
|
+
throw new Error(ResolveError.MalformedContext);
|
|
2762
|
+
}
|
|
1447
2763
|
optionalAppIdentifier.runWithException(app);
|
|
1448
2764
|
return this.intentsController.raiseIntent({ commandId: generateCommandId(), intent, context, target: app });
|
|
1449
2765
|
});
|
|
1450
2766
|
}
|
|
1451
2767
|
raiseIntentForContext(context, app) {
|
|
1452
2768
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1453
|
-
contextDecoder.
|
|
2769
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2770
|
+
if (!contextDecoderResult.ok) {
|
|
2771
|
+
throw new Error(ResolveError.MalformedContext);
|
|
2772
|
+
}
|
|
1454
2773
|
optionalTargetApp.runWithException(app);
|
|
1455
2774
|
return this.intentsController.raiseIntentForContext({ commandId: generateCommandId(), context, target: app });
|
|
1456
2775
|
});
|
|
@@ -1527,7 +2846,10 @@ class AppChannel {
|
|
|
1527
2846
|
}
|
|
1528
2847
|
broadcast(context) {
|
|
1529
2848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1530
|
-
contextDecoder.
|
|
2849
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2850
|
+
if (!contextDecoderResult.ok) {
|
|
2851
|
+
throw new Error(ChannelError.MalformedContext);
|
|
2852
|
+
}
|
|
1531
2853
|
return this.channelsController.broadcast(generateCommandId(), context, this.id);
|
|
1532
2854
|
});
|
|
1533
2855
|
}
|
|
@@ -1572,7 +2894,7 @@ class ChannelsParser {
|
|
|
1572
2894
|
return this.mapChannelsDelimiterToFDC3Type(withoutPrefix);
|
|
1573
2895
|
}
|
|
1574
2896
|
parseFDC3ContextToGlueContexts(context) {
|
|
1575
|
-
const { type } = context, rest = __rest$
|
|
2897
|
+
const { type } = context, rest = __rest$2(context, ["type"]);
|
|
1576
2898
|
const parsedType = this.mapFDC3TypeToChannelsDelimiter(type);
|
|
1577
2899
|
return { path: `${this.channelsFdc3DataPrefix}${parsedType}`, value: rest };
|
|
1578
2900
|
}
|
|
@@ -1587,137 +2909,6 @@ class ChannelsParser {
|
|
|
1587
2909
|
}
|
|
1588
2910
|
}
|
|
1589
2911
|
|
|
1590
|
-
/**
|
|
1591
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
1592
|
-
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
1593
|
-
*/
|
|
1594
|
-
/** Constants representing the errors that can be encountered when calling the `open` method on the DesktopAgent object (`fdc3`). */
|
|
1595
|
-
var OpenError;
|
|
1596
|
-
(function (OpenError) {
|
|
1597
|
-
/** Returned if the specified application is not found.*/
|
|
1598
|
-
OpenError["AppNotFound"] = "AppNotFound";
|
|
1599
|
-
/** Returned if the specified application fails to launch correctly.*/
|
|
1600
|
-
OpenError["ErrorOnLaunch"] = "ErrorOnLaunch";
|
|
1601
|
-
/** Returned if the specified application launches but fails to add a context listener in order to receive the context passed to the `fdc3.open` call.*/
|
|
1602
|
-
OpenError["AppTimeout"] = "AppTimeout";
|
|
1603
|
-
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
1604
|
-
OpenError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
1605
|
-
/** Returned if a call to the `open` function is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
1606
|
-
OpenError["MalformedContext"] = "MalformedContext";
|
|
1607
|
-
})(OpenError || (OpenError = {}));
|
|
1608
|
-
/** Constants representing the errors that can be encountered when calling the `findIntent`, `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the DesktopAgent (`fdc3`). */
|
|
1609
|
-
var ResolveError;
|
|
1610
|
-
(function (ResolveError) {
|
|
1611
|
-
/** SHOULD be returned if no apps are available that can resolve the intent and context combination.*/
|
|
1612
|
-
ResolveError["NoAppsFound"] = "NoAppsFound";
|
|
1613
|
-
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
1614
|
-
ResolveError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
1615
|
-
/** Returned if the user cancelled the resolution request, for example by closing or cancelling a resolver UI.*/
|
|
1616
|
-
ResolveError["UserCancelled"] = "UserCancelledResolution";
|
|
1617
|
-
/** SHOULD be returned if a timeout cancels an intent resolution that required user interaction. Please use `ResolverUnavailable` instead for situations where a resolver UI or similar fails.*/
|
|
1618
|
-
ResolveError["ResolverTimeout"] = "ResolverTimeout";
|
|
1619
|
-
/** Returned if a specified target application is not available or a new instance of it cannot be opened. */
|
|
1620
|
-
ResolveError["TargetAppUnavailable"] = "TargetAppUnavailable";
|
|
1621
|
-
/** Returned if a specified target application instance is not available, for example because it has been closed. */
|
|
1622
|
-
ResolveError["TargetInstanceUnavailable"] = "TargetInstanceUnavailable";
|
|
1623
|
-
/** Returned if the intent and context could not be delivered to the selected application or instance, for example because it has not added an intent handler within a timeout.*/
|
|
1624
|
-
ResolveError["IntentDeliveryFailed"] = "IntentDeliveryFailed";
|
|
1625
|
-
/** Returned if a call to one of the `raiseIntent` functions is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
1626
|
-
ResolveError["MalformedContext"] = "MalformedContext";
|
|
1627
|
-
})(ResolveError || (ResolveError = {}));
|
|
1628
|
-
var ResultError;
|
|
1629
|
-
(function (ResultError) {
|
|
1630
|
-
/** Returned if the intent handler exited without returning a valid result (a promise resolving to a Context, Channel object or void). */
|
|
1631
|
-
ResultError["NoResultReturned"] = "NoResultReturned";
|
|
1632
|
-
/** Returned if the Intent handler function processing the raised intent throws an error or rejects the Promise it returned. */
|
|
1633
|
-
ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
|
|
1634
|
-
})(ResultError || (ResultError = {}));
|
|
1635
|
-
var ChannelError;
|
|
1636
|
-
(function (ChannelError) {
|
|
1637
|
-
/** Returned if the specified channel is not found when attempting to join a channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).*/
|
|
1638
|
-
ChannelError["NoChannelFound"] = "NoChannelFound";
|
|
1639
|
-
/** SHOULD be returned when a request to join a user channel or to a retrieve a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods of the DesktopAgent (`fdc3`) object is denied. */
|
|
1640
|
-
ChannelError["AccessDenied"] = "AccessDenied";
|
|
1641
|
-
/** SHOULD be returned when a channel cannot be created or retrieved via the `getOrCreateChannel` method of the DesktopAgent (`fdc3`).*/
|
|
1642
|
-
ChannelError["CreationFailed"] = "CreationFailed";
|
|
1643
|
-
/** Returned if a call to the `broadcast` functions is made with an invalid context argument. Contexts should be Objects with at least a `type` field that has a `string` value.*/
|
|
1644
|
-
ChannelError["MalformedContext"] = "MalformedContext";
|
|
1645
|
-
})(ChannelError || (ChannelError = {}));
|
|
1646
|
-
|
|
1647
|
-
var ContextTypes;
|
|
1648
|
-
(function (ContextTypes) {
|
|
1649
|
-
ContextTypes["Chart"] = "fdc3.chart";
|
|
1650
|
-
ContextTypes["ChatInitSettings"] = "fdc3.chat.initSettings";
|
|
1651
|
-
ContextTypes["Contact"] = "fdc3.contact";
|
|
1652
|
-
ContextTypes["ContactList"] = "fdc3.contactList";
|
|
1653
|
-
ContextTypes["Country"] = "fdc3.country";
|
|
1654
|
-
ContextTypes["Currency"] = "fdc3.currency";
|
|
1655
|
-
ContextTypes["Email"] = "fdc3.email";
|
|
1656
|
-
ContextTypes["Instrument"] = "fdc3.instrument";
|
|
1657
|
-
ContextTypes["InstrumentList"] = "fdc3.instrumentList";
|
|
1658
|
-
ContextTypes["Organization"] = "fdc3.organization";
|
|
1659
|
-
ContextTypes["Portfolio"] = "fdc3.portfolio";
|
|
1660
|
-
ContextTypes["Position"] = "fdc3.position";
|
|
1661
|
-
ContextTypes["Nothing"] = "fdc3.nothing";
|
|
1662
|
-
ContextTypes["TimeRange"] = "fdc3.timerange";
|
|
1663
|
-
ContextTypes["Valuation"] = "fdc3.valuation";
|
|
1664
|
-
})(ContextTypes || (ContextTypes = {}));
|
|
1665
|
-
|
|
1666
|
-
// To parse this data:
|
|
1667
|
-
//
|
|
1668
|
-
// import { Convert, Chart, ChatInitSettings, Contact, ContactList, Context, Country, Currency, Email, Instrument, InstrumentList, Nothing, Organization, Portfolio, Position, TimeRange, Valuation } from "./file";
|
|
1669
|
-
//
|
|
1670
|
-
// const chart = Convert.toChart(json);
|
|
1671
|
-
// const chatInitSettings = Convert.toChatInitSettings(json);
|
|
1672
|
-
// const contact = Convert.toContact(json);
|
|
1673
|
-
// const contactList = Convert.toContactList(json);
|
|
1674
|
-
// const context = Convert.toContext(json);
|
|
1675
|
-
// const country = Convert.toCountry(json);
|
|
1676
|
-
// const currency = Convert.toCurrency(json);
|
|
1677
|
-
// const email = Convert.toEmail(json);
|
|
1678
|
-
// const instrument = Convert.toInstrument(json);
|
|
1679
|
-
// const instrumentList = Convert.toInstrumentList(json);
|
|
1680
|
-
// const nothing = Convert.toNothing(json);
|
|
1681
|
-
// const organization = Convert.toOrganization(json);
|
|
1682
|
-
// const portfolio = Convert.toPortfolio(json);
|
|
1683
|
-
// const position = Convert.toPosition(json);
|
|
1684
|
-
// const timeRange = Convert.toTimeRange(json);
|
|
1685
|
-
// const valuation = Convert.toValuation(json);
|
|
1686
|
-
//
|
|
1687
|
-
// These functions will throw an error if the JSON doesn't
|
|
1688
|
-
// match the expected interface, even if the JSON is valid.
|
|
1689
|
-
var Style;
|
|
1690
|
-
(function (Style) {
|
|
1691
|
-
Style["Bar"] = "bar";
|
|
1692
|
-
Style["Candle"] = "candle";
|
|
1693
|
-
Style["Custom"] = "custom";
|
|
1694
|
-
Style["Heatmap"] = "heatmap";
|
|
1695
|
-
Style["Histogram"] = "histogram";
|
|
1696
|
-
Style["Line"] = "line";
|
|
1697
|
-
Style["Mountain"] = "mountain";
|
|
1698
|
-
Style["Pie"] = "pie";
|
|
1699
|
-
Style["Scatter"] = "scatter";
|
|
1700
|
-
Style["StackedBar"] = "stacked-bar";
|
|
1701
|
-
})(Style || (Style = {}));
|
|
1702
|
-
|
|
1703
|
-
var Intents;
|
|
1704
|
-
(function (Intents) {
|
|
1705
|
-
Intents["StartCall"] = "StartCall";
|
|
1706
|
-
Intents["StartChat"] = "StartChat";
|
|
1707
|
-
Intents["StartEmail"] = "StartEmail";
|
|
1708
|
-
Intents["ViewAnalysis"] = "ViewAnalysis";
|
|
1709
|
-
Intents["ViewChart"] = "ViewChart";
|
|
1710
|
-
Intents["ViewContact"] = "ViewContact";
|
|
1711
|
-
Intents["ViewHoldings"] = "ViewHoldings";
|
|
1712
|
-
Intents["ViewInstrument"] = "ViewInstrument";
|
|
1713
|
-
Intents["ViewInteractions"] = "ViewInteractions";
|
|
1714
|
-
Intents["ViewNews"] = "ViewNews";
|
|
1715
|
-
Intents["ViewOrders"] = "ViewOrders";
|
|
1716
|
-
Intents["ViewProfile"] = "ViewProfile";
|
|
1717
|
-
Intents["ViewQuote"] = "ViewQuote";
|
|
1718
|
-
Intents["ViewResearch"] = "ViewResearch";
|
|
1719
|
-
})(Intents || (Intents = {}));
|
|
1720
|
-
|
|
1721
2912
|
class UserChannel {
|
|
1722
2913
|
constructor(channelsController, glueChannel) {
|
|
1723
2914
|
this.channelsController = channelsController;
|
|
@@ -1743,7 +2934,10 @@ class UserChannel {
|
|
|
1743
2934
|
}
|
|
1744
2935
|
broadcast(context) {
|
|
1745
2936
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1746
|
-
contextDecoder.
|
|
2937
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2938
|
+
if (!contextDecoderResult.ok) {
|
|
2939
|
+
throw new Error(ChannelError.MalformedContext);
|
|
2940
|
+
}
|
|
1747
2941
|
return this.channelsController.broadcast(generateCommandId(), context, this.id);
|
|
1748
2942
|
});
|
|
1749
2943
|
}
|
|
@@ -1802,6 +2996,19 @@ class IntentsController {
|
|
|
1802
2996
|
this.channelsController = channelsController;
|
|
1803
2997
|
this.channelsFactory = channelsFactory;
|
|
1804
2998
|
this.glueEventsController = glueEventsController;
|
|
2999
|
+
this.ioToFDC3ErrorsDict = {
|
|
3000
|
+
[IO_ERRORS.USER_CANCELLED]: ResolveError.UserCancelled,
|
|
3001
|
+
[IO_ERRORS.TIMEOUT_HIT]: ResolveError.IntentDeliveryFailed,
|
|
3002
|
+
[IO_ERRORS.TARGET_INSTANCE_UNAVAILABLE]: ResolveError.TargetInstanceUnavailable,
|
|
3003
|
+
[IO_ERRORS.RESOLVER_UNAVAILABLE]: ResolveError.ResolverUnavailable,
|
|
3004
|
+
[IO_ERRORS.RESOLVER_TIMEOUT]: ResolveError.ResolverTimeout,
|
|
3005
|
+
[IO_ERRORS.INVALID_RESOLVER_RESPONSE]: ResolveError.IntentDeliveryFailed,
|
|
3006
|
+
[IO_ERRORS.INTENT_NOT_FOUND]: ResolveError.NoAppsFound,
|
|
3007
|
+
[IO_ERRORS.INTENT_DELIVERY_FAILED]: ResolveError.IntentDeliveryFailed,
|
|
3008
|
+
[IO_ERRORS.HANDLER_NOT_FOUND]: ResolveError.NoAppsFound,
|
|
3009
|
+
[IO_ERRORS.CALLER_NOT_DEFINED]: ResolveError.IntentDeliveryFailed,
|
|
3010
|
+
[IO_ERRORS.INTENT_HANDLER_REJECTION]: ResultError.IntentHandlerRejected
|
|
3011
|
+
};
|
|
1805
3012
|
}
|
|
1806
3013
|
get logger() {
|
|
1807
3014
|
if (!this._logger) {
|
|
@@ -1810,9 +3017,10 @@ class IntentsController {
|
|
|
1810
3017
|
return this._logger;
|
|
1811
3018
|
}
|
|
1812
3019
|
findIntent({ commandId, intent, context, resultType }) {
|
|
3020
|
+
var _a;
|
|
1813
3021
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1814
3022
|
yield this.glueController.gluePromise;
|
|
1815
|
-
this.logger.info(`[${commandId}] - findIntent() invoked for intent ${intent} with contextType ${context === null || context === void 0 ? void 0 : context.type} and resultType ${resultType}`);
|
|
3023
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - findIntent() invoked for intent ${intent} with contextType ${context === null || context === void 0 ? void 0 : context.type} and resultType ${resultType}`);
|
|
1816
3024
|
const glueIntents = yield this.glueController.findIntents({ name: intent });
|
|
1817
3025
|
if (!glueIntents.length) {
|
|
1818
3026
|
throw { message: ResolveError.NoAppsFound, reason: `There are no apps handling the passed intent ${intent}` };
|
|
@@ -1833,14 +3041,15 @@ class IntentsController {
|
|
|
1833
3041
|
});
|
|
1834
3042
|
}
|
|
1835
3043
|
findIntentsByContext({ commandId, context, resultType }) {
|
|
3044
|
+
var _a, _b;
|
|
1836
3045
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1837
3046
|
yield this.glueController.gluePromise;
|
|
1838
|
-
this.logger.info(`[${commandId}] - findIntentsByContext() invoked for context type ${context.type} and resultType ${resultType}`);
|
|
3047
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - findIntentsByContext() invoked for context type ${context.type} and resultType ${resultType}`);
|
|
1839
3048
|
const glueIntents = yield this.glueController.findIntents({ contextType: context.type, resultType });
|
|
1840
3049
|
if (!glueIntents.length) {
|
|
1841
3050
|
throw { message: ResolveError.NoAppsFound, reason: `No apps registering intent with contextType ${context.type} ${resultType ? `and resultType ${resultType}` : ""}` };
|
|
1842
3051
|
}
|
|
1843
|
-
this.logger.info(`[${commandId}] - parsing glue intents to fdc3 intents and returning`);
|
|
3052
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - parsing glue intents to fdc3 intents and returning`);
|
|
1844
3053
|
return glueIntents.map((glueIntent) => {
|
|
1845
3054
|
const intentWithFilteredHandlers = this.getGlueIntentWithFilteredHandlers(glueIntent, { contextType: context.type, resultType });
|
|
1846
3055
|
return this.convertGlue42IntentToFDC3Intent(intentWithFilteredHandlers);
|
|
@@ -1848,10 +3057,10 @@ class IntentsController {
|
|
|
1848
3057
|
});
|
|
1849
3058
|
}
|
|
1850
3059
|
raiseIntent({ commandId, intent, context, target }) {
|
|
1851
|
-
var _a;
|
|
3060
|
+
var _a, _b, _c, _d, _e;
|
|
1852
3061
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1853
3062
|
yield this.glueController.gluePromise;
|
|
1854
|
-
this.logger.info(`[${commandId}] - raiseIntent() invoked for intent ${intent} with contextType: ${context.type} and target: ${target}`);
|
|
3063
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - raiseIntent() invoked for intent ${intent} with contextType: ${context.type} and target: ${target}`);
|
|
1855
3064
|
const glueContext = { type: context.type, data: Object.assign({}, context) };
|
|
1856
3065
|
const searchedGlueIntent = (yield this.glueController.findIntents({ name: intent })).find(glueIntent => glueIntent.name === intent);
|
|
1857
3066
|
if (!searchedGlueIntent) {
|
|
@@ -1859,18 +3068,18 @@ class IntentsController {
|
|
|
1859
3068
|
}
|
|
1860
3069
|
const filteredGlueIntent = this.filterGlueIntentHandlers({ commandId, intent: searchedGlueIntent, context, target });
|
|
1861
3070
|
if (!target) {
|
|
1862
|
-
this.logger.info(`[${commandId}] - raising intent ${intent} with contextType ${context.type} and handlers ${filteredGlueIntent.handlers.map(h => h.applicationName && h.instanceId)}`);
|
|
3071
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - raising intent ${intent} with contextType ${context.type} and handlers ${filteredGlueIntent.handlers.map(h => h.applicationName && h.instanceId)}`);
|
|
1863
3072
|
return this.invokeRaiseIntent(commandId, { intent, context: glueContext, handlers: filteredGlueIntent.handlers });
|
|
1864
3073
|
}
|
|
1865
3074
|
if (typeof target === "string" || !target.instanceId) {
|
|
1866
|
-
this.logger.info(`[${commandId}] - target app ${target.appId} is a valid handler. Raising intent ${intent} with contextType ${context.type} and handlers ${filteredGlueIntent.handlers}`);
|
|
3075
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - target app ${target.appId} is a valid handler. Raising intent ${intent} with contextType ${context.type} and handlers ${filteredGlueIntent.handlers}`);
|
|
1867
3076
|
return this.invokeRaiseIntent(commandId, {
|
|
1868
3077
|
intent,
|
|
1869
3078
|
context: glueContext,
|
|
1870
|
-
target: { app: target.appId, instance: (
|
|
3079
|
+
target: { app: target.appId, instance: (_d = filteredGlueIntent.handlers.find((h) => h.instanceId)) === null || _d === void 0 ? void 0 : _d.instanceId }
|
|
1871
3080
|
});
|
|
1872
3081
|
}
|
|
1873
|
-
this.logger.info(`[${commandId}] - raising intent ${intent} with contextType ${context.type} to target instance of app ${target.appId} and id ${target.instanceId}`);
|
|
3082
|
+
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.info(`[${commandId}] - raising intent ${intent} with contextType ${context.type} to target instance of app ${target.appId} and id ${target.instanceId}`);
|
|
1874
3083
|
return this.invokeRaiseIntent(commandId, {
|
|
1875
3084
|
intent,
|
|
1876
3085
|
context: glueContext,
|
|
@@ -1879,24 +3088,43 @@ class IntentsController {
|
|
|
1879
3088
|
});
|
|
1880
3089
|
}
|
|
1881
3090
|
raiseIntentForContext({ commandId, context, target }) {
|
|
3091
|
+
var _a, _b, _c;
|
|
1882
3092
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1883
3093
|
yield this.glueController.gluePromise;
|
|
1884
|
-
this.logger.info(`[${commandId}] - raiseIntentForContext() invoked with contextType ${context.type} and target ${target}`);
|
|
1885
|
-
const
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
reason: `No apps registering intent with contextType ${context.type} ${target ? `and target ${JSON.stringify(target)}` : ""}`
|
|
1890
|
-
};
|
|
3094
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - raiseIntentForContext() invoked with contextType ${context.type} and target ${target}`);
|
|
3095
|
+
const filteredHandlersMethodExist = this.glueController.doesFilterHandlersExist();
|
|
3096
|
+
const getIntentsMethodExist = this.glueController.doesGetIntentsExist();
|
|
3097
|
+
if (!filteredHandlersMethodExist || !getIntentsMethodExist || target) {
|
|
3098
|
+
return this.legacyRaiseIntentForContext({ commandId, context, target });
|
|
1891
3099
|
}
|
|
1892
|
-
|
|
3100
|
+
const filteredHandlersResPromise = this.glueController.filterHandlers({ contextTypes: [context.type] })
|
|
3101
|
+
.catch((err) => {
|
|
3102
|
+
throw this.parseIoToFdc3Error(err);
|
|
3103
|
+
});
|
|
3104
|
+
const { handlers } = yield filteredHandlersResPromise;
|
|
3105
|
+
if (!handlers.length) {
|
|
3106
|
+
const errorMsg = `${ResolveError.NoAppsFound} - Cannot find Intent Handlers for intents with context type ${context.type}`;
|
|
3107
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.warn(`[${commandId}] - ${errorMsg}`);
|
|
3108
|
+
throw new Error(ResolveError.NoAppsFound);
|
|
3109
|
+
}
|
|
3110
|
+
if (handlers.length > 1) {
|
|
3111
|
+
return this.legacyRaiseIntentForContext({ commandId, context, target });
|
|
3112
|
+
}
|
|
3113
|
+
const handler = handlers[0];
|
|
3114
|
+
const { intents } = yield this.glueController.getIntents(handler);
|
|
3115
|
+
const validIntent = intents.find((intentInfo) => { var _a; return (_a = intentInfo.contextTypes) === null || _a === void 0 ? void 0 : _a.includes(context.type); });
|
|
3116
|
+
if (!validIntent) {
|
|
3117
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.warn(`[${commandId}] - ${ResolveError.IntentDeliveryFailed} - There's no valid intent for handler ${JSON.stringify(handler)} and context type ${context.type}`);
|
|
3118
|
+
throw new Error(ResolveError.IntentDeliveryFailed);
|
|
3119
|
+
}
|
|
3120
|
+
return this.invokeRaiseIntent(commandId, { intent: validIntent.intent, context, target: { app: handler.applicationName, instance: handler.instanceId } });
|
|
1893
3121
|
});
|
|
1894
3122
|
}
|
|
1895
3123
|
addIntentListener({ commandId, intent, handler }) {
|
|
1896
|
-
var _a, _b;
|
|
3124
|
+
var _a, _b, _c;
|
|
1897
3125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1898
3126
|
yield this.glueController.gluePromise;
|
|
1899
|
-
this.logger.info(`[${commandId}] - addIntentListener() invoked for intent ${intent}`);
|
|
3127
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - addIntentListener() invoked for intent ${intent}`);
|
|
1900
3128
|
const wrappedHandler = this.getWrappedIntentHandler(handler);
|
|
1901
3129
|
const myInstance = this.glueController.getMyInteropInstance();
|
|
1902
3130
|
const myApplication = this.glueController.getApplication(myInstance.applicationName);
|
|
@@ -1904,11 +3132,11 @@ class IntentsController {
|
|
|
1904
3132
|
const globalBrowserNamespace = window.glue42core || window.iobrowser;
|
|
1905
3133
|
const globalDesktopNamespace = window.glue42gd || window.iodesktop;
|
|
1906
3134
|
if (globalBrowserNamespace) {
|
|
1907
|
-
appConfigIntentDef = (
|
|
3135
|
+
appConfigIntentDef = (_b = myApplication === null || myApplication === void 0 ? void 0 : myApplication.userProperties.intents) === null || _b === void 0 ? void 0 : _b.find((appIntent) => appIntent.name === intent);
|
|
1908
3136
|
}
|
|
1909
3137
|
if (globalDesktopNamespace) {
|
|
1910
3138
|
const appConfig = yield myApplication.getConfiguration();
|
|
1911
|
-
appConfigIntentDef = (
|
|
3139
|
+
appConfigIntentDef = (_c = appConfig === null || appConfig === void 0 ? void 0 : appConfig.intents) === null || _c === void 0 ? void 0 : _c.find((appIntent) => appIntent.name === intent);
|
|
1912
3140
|
}
|
|
1913
3141
|
const intentRequest = {
|
|
1914
3142
|
intent,
|
|
@@ -1923,32 +3151,34 @@ class IntentsController {
|
|
|
1923
3151
|
});
|
|
1924
3152
|
}
|
|
1925
3153
|
filterGlueIntentHandlers({ commandId, intent, context, target }) {
|
|
3154
|
+
var _a, _b;
|
|
1926
3155
|
let filteredGlueIntent;
|
|
1927
3156
|
filteredGlueIntent = this.filterIntentHandlersByContext(intent, context);
|
|
1928
3157
|
if (!target) {
|
|
1929
|
-
this.logger.info(`[${commandId}] - There's no passed target, intent handlers are filtered only by context type`);
|
|
3158
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - There's no passed target, intent handlers are filtered only by context type`);
|
|
1930
3159
|
return filteredGlueIntent;
|
|
1931
3160
|
}
|
|
1932
|
-
this.logger.log(`[${commandId}] - filtering handlers by target (${JSON.stringify(target)}) for intent ${intent.name}`);
|
|
3161
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log(`[${commandId}] - filtering handlers by target (${JSON.stringify(target)}) for intent ${intent.name}`);
|
|
1933
3162
|
filteredGlueIntent = this.filterIntentHandlersByTarget({ intent, target, commandId });
|
|
1934
3163
|
return filteredGlueIntent;
|
|
1935
3164
|
}
|
|
1936
3165
|
filterIntentHandlersByTarget({ intent, target, commandId }) {
|
|
3166
|
+
var _a, _b, _c, _d;
|
|
1937
3167
|
const appName = typeof target === "string" ? target : target.appId;
|
|
1938
3168
|
const instanceId = typeof target === "string" ? undefined : target.instanceId;
|
|
1939
|
-
this.logger.info(`[${commandId}] - Checking if application with name ${appName} exists`);
|
|
3169
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - Checking if application with name ${appName} exists`);
|
|
1940
3170
|
const app = this.glueController.getApplication(appName);
|
|
1941
3171
|
const serverInstances = this.serverInstanceAsIntentHandler(intent.name);
|
|
1942
3172
|
if (!app && (typeof target === "string" || !target.instanceId || !serverInstances.length)) {
|
|
1943
3173
|
throw { message: ResolveError.TargetAppUnavailable, reason: `There's no app with appId ${appName}` };
|
|
1944
3174
|
}
|
|
1945
|
-
this.logger.info(`[${commandId}] - target app ${appName} found. Filtering handlers by applicationName: ${appName}`);
|
|
3175
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - target app ${appName} found. Filtering handlers by applicationName: ${appName}`);
|
|
1946
3176
|
const validHandlersByApplicationName = intent.handlers.filter((handler) => handler.applicationName === appName);
|
|
1947
3177
|
if (!validHandlersByApplicationName.length) {
|
|
1948
3178
|
throw { message: ResolveError.NoAppsFound, reason: `Intent ${intent.name} exists but there's no app with appId ${appName} registering it` };
|
|
1949
3179
|
}
|
|
1950
3180
|
if (!instanceId) {
|
|
1951
|
-
this.logger.log(`[${commandId}] - returning all handlers for intent ${intent.name} and target: ${JSON.stringify(target)}`);
|
|
3181
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.log(`[${commandId}] - returning all handlers for intent ${intent.name} and target: ${JSON.stringify(target)}`);
|
|
1952
3182
|
return { name: intent.name, handlers: validHandlersByApplicationName };
|
|
1953
3183
|
}
|
|
1954
3184
|
const isValidInstanceOfTheApp = app
|
|
@@ -1957,7 +3187,7 @@ class IntentsController {
|
|
|
1957
3187
|
if (!isValidInstanceOfTheApp) {
|
|
1958
3188
|
throw { message: ResolveError.TargetInstanceUnavailable, reason: `There's no instance with id ${instanceId} of the passed app ${appName}` };
|
|
1959
3189
|
}
|
|
1960
|
-
this.logger.info(`[${commandId}] - Filtering handlers by instanceId: ${instanceId}`);
|
|
3190
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.info(`[${commandId}] - Filtering handlers by instanceId: ${instanceId}`);
|
|
1961
3191
|
const validHandlersByInstanceId = validHandlersByApplicationName.filter((handler) => handler.instanceId === instanceId);
|
|
1962
3192
|
if (!validHandlersByInstanceId.length) {
|
|
1963
3193
|
throw { message: ResolveError.IntentDeliveryFailed, reason: `There's no instance with id ${instanceId} of app ${appName} registering intent ${intent.name}` };
|
|
@@ -1979,9 +3209,17 @@ class IntentsController {
|
|
|
1979
3209
|
return filteredGlueIntent;
|
|
1980
3210
|
}
|
|
1981
3211
|
getResult(commandId, glueIntentResult) {
|
|
3212
|
+
var _a, _b, _c;
|
|
1982
3213
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1983
|
-
this.logger.info(`[${commandId}] - getResult() of IntentResolution invoked`);
|
|
3214
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getResult() of IntentResolution invoked`);
|
|
1984
3215
|
const { result } = glueIntentResult;
|
|
3216
|
+
if (result.fdc3error) {
|
|
3217
|
+
throw result.fdc3error;
|
|
3218
|
+
}
|
|
3219
|
+
if (!result || typeof result !== "object" || Array.isArray(result) || (isValidNonEmptyObject(result) && !result.fdc3intentContext && !result.fdc3intentChannel && !result.fdc3error)) {
|
|
3220
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.warn(`[${commandId}] - ${ResultError.NoResultReturned} - The intent handler exited without returning a valid result - a promise resolving to a Context, Channel object or void`);
|
|
3221
|
+
throw new Error(ResultError.NoResultReturned);
|
|
3222
|
+
}
|
|
1985
3223
|
if (!isValidNonEmptyObject(result)) {
|
|
1986
3224
|
return;
|
|
1987
3225
|
}
|
|
@@ -2010,7 +3248,7 @@ class IntentsController {
|
|
|
2010
3248
|
}
|
|
2011
3249
|
};
|
|
2012
3250
|
yield this.glueController.invokeSystemMethod(joinChannelArgs, glueIntentResult.handler.instanceId);
|
|
2013
|
-
this.logger.info(`[${commandId}] - returning private channel`);
|
|
3251
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - returning private channel`);
|
|
2014
3252
|
return channel.toApi();
|
|
2015
3253
|
});
|
|
2016
3254
|
}
|
|
@@ -2043,10 +3281,10 @@ class IntentsController {
|
|
|
2043
3281
|
if (isContext(data)) {
|
|
2044
3282
|
return IntentHandlerResultTypes.Context;
|
|
2045
3283
|
}
|
|
2046
|
-
throw new Error("Async handler function should return a promise that resolves to a Context or Channel");
|
|
2047
3284
|
}
|
|
2048
3285
|
getWrappedIntentHandler(handler) {
|
|
2049
3286
|
const wrappedHandler = (glue42Context, caller) => __awaiter(this, void 0, void 0, function* () {
|
|
3287
|
+
var _a;
|
|
2050
3288
|
const contextMetadata = caller
|
|
2051
3289
|
? {
|
|
2052
3290
|
source: {
|
|
@@ -2055,11 +3293,23 @@ class IntentsController {
|
|
|
2055
3293
|
}
|
|
2056
3294
|
}
|
|
2057
3295
|
: undefined;
|
|
2058
|
-
|
|
3296
|
+
let handlerResult;
|
|
3297
|
+
try {
|
|
3298
|
+
handlerResult = yield handler(Object.assign(Object.assign({}, glue42Context.data), { type: glue42Context.type || "" }), contextMetadata);
|
|
3299
|
+
}
|
|
3300
|
+
catch (error) {
|
|
3301
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(typeof error === "string" ? error : error.message || JSON.stringify(error));
|
|
3302
|
+
throw new Error(ResultError.IntentHandlerRejected);
|
|
3303
|
+
}
|
|
2059
3304
|
if (!handlerResult) {
|
|
2060
3305
|
return;
|
|
2061
3306
|
}
|
|
2062
3307
|
const handlerResultType = this.getResultType(handlerResult);
|
|
3308
|
+
if (!handlerResultType) {
|
|
3309
|
+
return {
|
|
3310
|
+
fdc3error: { message: ResultError.NoResultReturned, reason: "The intent handler exited without returning a valid result - a promise resolving to a Context, Channel object or void" }
|
|
3311
|
+
};
|
|
3312
|
+
}
|
|
2063
3313
|
return handlerResultType === IntentHandlerResultTypes.Channel
|
|
2064
3314
|
? { fdc3intentChannel: extractChannelMetadata(handlerResult) }
|
|
2065
3315
|
: { fdc3intentContext: { contextType: handlerResult.type, payload: handlerResult } };
|
|
@@ -2103,13 +3353,34 @@ class IntentsController {
|
|
|
2103
3353
|
};
|
|
2104
3354
|
}
|
|
2105
3355
|
catch (error) {
|
|
2106
|
-
throw
|
|
3356
|
+
throw this.parseIoToFdc3Error(error);
|
|
3357
|
+
}
|
|
3358
|
+
});
|
|
3359
|
+
}
|
|
3360
|
+
parseIoToFdc3Error(error) {
|
|
3361
|
+
const ioError = Object.keys(this.ioToFDC3ErrorsDict).find(((ioError) => { var _a; return (_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(ioError); }));
|
|
3362
|
+
const fdc3Error = ioError ? this.ioToFDC3ErrorsDict[ioError] : ResolveError.IntentDeliveryFailed;
|
|
3363
|
+
const stringifiedError = typeof error === "string" ? error : JSON.stringify(error);
|
|
3364
|
+
const reason = error instanceof Error ? error.message : stringifiedError;
|
|
3365
|
+
return { message: fdc3Error, reason };
|
|
3366
|
+
}
|
|
3367
|
+
legacyRaiseIntentForContext({ commandId, context, target }) {
|
|
3368
|
+
var _a;
|
|
3369
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3370
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - raiseIntentForContext() invoked with contextType ${context.type} and target ${target}`);
|
|
3371
|
+
const appIntents = yield this.findIntentsByContext({ commandId, context });
|
|
3372
|
+
if (!appIntents || appIntents.length === 0) {
|
|
3373
|
+
throw {
|
|
3374
|
+
message: ResolveError.NoAppsFound,
|
|
3375
|
+
reason: `No apps registering intent with contextType ${context.type} ${target ? `and target ${JSON.stringify(target)}` : ""}`
|
|
3376
|
+
};
|
|
2107
3377
|
}
|
|
3378
|
+
return this.raiseIntent({ commandId, intent: appIntents[0].intent.name, context, target });
|
|
2108
3379
|
});
|
|
2109
3380
|
}
|
|
2110
3381
|
}
|
|
2111
3382
|
|
|
2112
|
-
var version = "2.
|
|
3383
|
+
var version = "2.2.0";
|
|
2113
3384
|
|
|
2114
3385
|
class ApplicationsController {
|
|
2115
3386
|
constructor(glueController, appsStateStore, glueEventsController) {
|
|
@@ -2125,9 +3396,10 @@ class ApplicationsController {
|
|
|
2125
3396
|
return this._logger;
|
|
2126
3397
|
}
|
|
2127
3398
|
open({ commandId, target, context }) {
|
|
3399
|
+
var _a, _b, _c, _d;
|
|
2128
3400
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2129
3401
|
yield this.glueController.gluePromise;
|
|
2130
|
-
this.logger.log(`[${commandId}] - open() invoked with target ${target} ${context ? `and contextType ${context.type}` : ""}`);
|
|
3402
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - open() invoked with target ${target} ${context ? `and contextType ${context.type}` : ""}`);
|
|
2131
3403
|
const name = typeof target === "object" ? target.appId : target;
|
|
2132
3404
|
const app = this.glueController.getApplication(name);
|
|
2133
3405
|
if (!app) {
|
|
@@ -2135,13 +3407,13 @@ class ApplicationsController {
|
|
|
2135
3407
|
}
|
|
2136
3408
|
if (context) {
|
|
2137
3409
|
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2138
|
-
this.logger.info(`[${commandId}] - opening app ${app} with startup context`);
|
|
3410
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - opening app ${app} with startup context`);
|
|
2139
3411
|
return this.openAppWithContext(app, context);
|
|
2140
3412
|
}
|
|
2141
3413
|
try {
|
|
2142
|
-
this.logger.info(`[${commandId}] - opening app ${app}`);
|
|
3414
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - opening app ${app}`);
|
|
2143
3415
|
const glueInst = yield app.start();
|
|
2144
|
-
this.logger.info(`[${commandId}] - instance with id ${glueInst.id} started`);
|
|
3416
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.info(`[${commandId}] - instance with id ${glueInst.id} started`);
|
|
2145
3417
|
return this.parseGlueInstToAppIdentifier(glueInst);
|
|
2146
3418
|
}
|
|
2147
3419
|
catch (error) {
|
|
@@ -2150,9 +3422,10 @@ class ApplicationsController {
|
|
|
2150
3422
|
});
|
|
2151
3423
|
}
|
|
2152
3424
|
findInstances({ commandId, appIdentifier }) {
|
|
3425
|
+
var _a, _b;
|
|
2153
3426
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2154
3427
|
yield this.glueController.gluePromise;
|
|
2155
|
-
this.logger.info(`[${commandId}] - findInstances() invoked with appIdentifier ${appIdentifier}`);
|
|
3428
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - findInstances() invoked with appIdentifier ${appIdentifier}`);
|
|
2156
3429
|
const { appId } = appIdentifier;
|
|
2157
3430
|
const app = this.glueController.getApplication(appId);
|
|
2158
3431
|
if (!app) {
|
|
@@ -2160,41 +3433,44 @@ class ApplicationsController {
|
|
|
2160
3433
|
}
|
|
2161
3434
|
const glueInstances = this.glueController.getApplicationInstances(appId);
|
|
2162
3435
|
const fdc3Instances = glueInstances.map(glueInst => this.parseGlueInstToAppIdentifier(glueInst));
|
|
2163
|
-
this.logger.info(`[${commandId}] - ids of opened instances for appIdentifier ${appIdentifier}: ${JSON.stringify(fdc3Instances.map(inst => inst.instanceId))}`);
|
|
3436
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - ids of opened instances for appIdentifier ${appIdentifier}: ${JSON.stringify(fdc3Instances.map(inst => inst.instanceId))}`);
|
|
2164
3437
|
return fdc3Instances;
|
|
2165
3438
|
});
|
|
2166
3439
|
}
|
|
2167
3440
|
getAppMetadata({ commandId, appIdentifier }) {
|
|
3441
|
+
var _a, _b, _c;
|
|
2168
3442
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2169
3443
|
yield this.glueController.gluePromise;
|
|
2170
|
-
this.logger.info(`[${commandId}] - getAppMetadata() invoked with appIdentifier ${appIdentifier}`);
|
|
3444
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getAppMetadata() invoked with appIdentifier ${appIdentifier}`);
|
|
2171
3445
|
const { appId, instanceId } = appIdentifier;
|
|
2172
3446
|
const app = this.glueController.getApplication(appId);
|
|
2173
3447
|
if (!app) {
|
|
2174
3448
|
throw { message: OpenError.AppNotFound, reason: `Cannot find application with appId: ${appId}` };
|
|
2175
3449
|
}
|
|
2176
3450
|
if (!instanceId) {
|
|
2177
|
-
this.logger.info(`[${commandId}] - no opened instances found. Parsing app ${app}`);
|
|
3451
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - no opened instances found. Parsing app ${app}`);
|
|
2178
3452
|
return this.parseGlueAppToAppMetadata(app);
|
|
2179
3453
|
}
|
|
2180
3454
|
const instance = this.glueController.getAppInstanceById(instanceId);
|
|
2181
3455
|
const appMetadata = this.parseGlueAppToAppMetadata(app, instance);
|
|
2182
|
-
this.logger.info(`[${commandId}] - found app metadata: ${appMetadata}`);
|
|
3456
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - found app metadata: ${appMetadata}`);
|
|
2183
3457
|
return appMetadata;
|
|
2184
3458
|
});
|
|
2185
3459
|
}
|
|
2186
3460
|
getInfo({ commandId }) {
|
|
3461
|
+
var _a;
|
|
2187
3462
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2188
3463
|
yield this.glueController.gluePromise;
|
|
2189
|
-
this.logger.info(`${commandId} - getInfo() invoked`);
|
|
3464
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`${commandId} - getInfo() invoked`);
|
|
2190
3465
|
const appMetadata = yield this.getCurrentAppMetadata();
|
|
2191
3466
|
return {
|
|
2192
3467
|
provider: "io.Connect",
|
|
2193
3468
|
providerVersion: version,
|
|
2194
|
-
fdc3Version: "2.
|
|
3469
|
+
fdc3Version: "2.1",
|
|
2195
3470
|
optionalFeatures: {
|
|
2196
3471
|
OriginatingAppMetadata: true,
|
|
2197
|
-
UserChannelMembershipAPIs: true
|
|
3472
|
+
UserChannelMembershipAPIs: true,
|
|
3473
|
+
DesktopAgentBridging: false
|
|
2198
3474
|
},
|
|
2199
3475
|
appMetadata
|
|
2200
3476
|
};
|
|
@@ -2318,22 +3594,23 @@ class ChannelsController {
|
|
|
2318
3594
|
});
|
|
2319
3595
|
}
|
|
2320
3596
|
addContextListener({ commandId, handler, contextType, channelId }) {
|
|
2321
|
-
var _a;
|
|
3597
|
+
var _a, _b, _c;
|
|
2322
3598
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2323
3599
|
yield this.initDonePromise;
|
|
2324
|
-
this.logger.info(`[${commandId}] - addContextListener() invoked for contextType ${contextType} and channelId ${channelId}`);
|
|
3600
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - addContextListener() invoked for contextType ${contextType} and channelId ${channelId}`);
|
|
2325
3601
|
if (this.invokeContextHandlerWithStartupContext && !channelId) {
|
|
2326
|
-
this.logger.info(`[${commandId}] - trying to invoke context handler with window context`);
|
|
2327
|
-
this.handleWindowContextOnOpening(commandId, handler, contextType).catch((err) => this.logger.warn(`[${commandId}] - ${err}`));
|
|
3602
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - trying to invoke context handler with window context`);
|
|
3603
|
+
this.handleWindowContextOnOpening(commandId, handler, contextType).catch((err) => { var _a; return (_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(`[${commandId}] - ${err}`); });
|
|
2328
3604
|
}
|
|
2329
|
-
const channelIdToSubscribeTo = channelId || ((
|
|
3605
|
+
const channelIdToSubscribeTo = channelId || ((_c = this.channelsStateStore.currentChannel) === null || _c === void 0 ? void 0 : _c.id);
|
|
2330
3606
|
return this.addContextListenerByChannelId({ commandId, handler, invokedOnChannelModel: !!channelId, channelId: channelIdToSubscribeTo, contextType });
|
|
2331
3607
|
});
|
|
2332
3608
|
}
|
|
2333
3609
|
broadcast(commandId, context, channelId) {
|
|
3610
|
+
var _a;
|
|
2334
3611
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2335
3612
|
yield this.initDonePromise;
|
|
2336
|
-
this.logger.info(`[${commandId}] - broadcast() invoked with contextType ${context.type} and channelId ${channelId}`);
|
|
3613
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - broadcast() invoked with contextType ${context.type} and channelId ${channelId}`);
|
|
2337
3614
|
const canBroadcast = this.isBroadcastPermitted(commandId, channelId);
|
|
2338
3615
|
if (!canBroadcast) {
|
|
2339
3616
|
return;
|
|
@@ -2343,16 +3620,18 @@ class ChannelsController {
|
|
|
2343
3620
|
});
|
|
2344
3621
|
}
|
|
2345
3622
|
getUserChannels(commandId) {
|
|
3623
|
+
var _a;
|
|
2346
3624
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2347
3625
|
yield this.initDonePromise;
|
|
2348
|
-
this.logger.info(`[${commandId}] - getUserChannels() invoked`);
|
|
3626
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getUserChannels() invoked`);
|
|
2349
3627
|
return Object.values(this.channelsStateStore.userChannels);
|
|
2350
3628
|
});
|
|
2351
3629
|
}
|
|
2352
3630
|
getOrCreateChannel({ commandId, channelId }) {
|
|
3631
|
+
var _a;
|
|
2353
3632
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2354
3633
|
yield this.initDonePromise;
|
|
2355
|
-
this.logger.info(`[${commandId}] - getOrCreateChannel() invoked for channel with id ${channelId}`);
|
|
3634
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getOrCreateChannel() invoked for channel with id ${channelId}`);
|
|
2356
3635
|
const isUserChannel = this.isUserChannel(channelId);
|
|
2357
3636
|
if (isUserChannel) {
|
|
2358
3637
|
throw { message: ChannelError.AccessDenied, reason: "There's an already existing system channel with passed id. Retrieve it using fdc3.getSystemChannels() or create a new app channel with a different id" };
|
|
@@ -2365,9 +3644,10 @@ class ChannelsController {
|
|
|
2365
3644
|
});
|
|
2366
3645
|
}
|
|
2367
3646
|
joinUserChannel({ commandId, channelId }) {
|
|
3647
|
+
var _a, _b;
|
|
2368
3648
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2369
3649
|
yield this.initDonePromise;
|
|
2370
|
-
this.logger.info(`[${commandId}] - joinUserChannel() invoked for channel with id ${channelId}`);
|
|
3650
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - joinUserChannel() invoked for channel with id ${channelId}`);
|
|
2371
3651
|
const isAppChannel = this.doesAppChannelExist(channelId);
|
|
2372
3652
|
if (isAppChannel) {
|
|
2373
3653
|
throw { message: ChannelError.AccessDenied, reason: "Cannot join an app channel" };
|
|
@@ -2378,53 +3658,56 @@ class ChannelsController {
|
|
|
2378
3658
|
}
|
|
2379
3659
|
const glueChannelName = this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId);
|
|
2380
3660
|
this.channelsStateStore.currentChannel = channelToJoin;
|
|
2381
|
-
this.logger.info(`[${commandId}] - joining fdc3 user channel with id ${channelId} (underlying glue channel: ${glueChannelName})`);
|
|
3661
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - joining fdc3 user channel with id ${channelId} (underlying glue channel: ${glueChannelName})`);
|
|
2382
3662
|
yield this.glueController.joinChannel(glueChannelName);
|
|
2383
3663
|
});
|
|
2384
3664
|
}
|
|
2385
3665
|
getCurrentChannel(commandId) {
|
|
3666
|
+
var _a;
|
|
2386
3667
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2387
3668
|
yield this.initDonePromise;
|
|
2388
|
-
this.logger.info(`[${commandId}] - getCurrentChannel() invoked`);
|
|
3669
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getCurrentChannel() invoked`);
|
|
2389
3670
|
return this.channelsStateStore.currentChannel;
|
|
2390
3671
|
});
|
|
2391
3672
|
}
|
|
2392
3673
|
leaveCurrentChannel(commandId) {
|
|
3674
|
+
var _a, _b, _c;
|
|
2393
3675
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2394
3676
|
yield this.initDonePromise;
|
|
2395
|
-
this.logger.info(`[${commandId}] - leaveCurrentChannel() invoked`);
|
|
3677
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - leaveCurrentChannel() invoked`);
|
|
2396
3678
|
if (!this.channelsStateStore.currentChannel) {
|
|
2397
|
-
this.logger.info(`[${commandId}] - no channel to leave`);
|
|
3679
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - no channel to leave`);
|
|
2398
3680
|
return;
|
|
2399
3681
|
}
|
|
2400
3682
|
yield this.glueController.leaveChannel();
|
|
2401
3683
|
this.channelsStateStore.currentChannel = null;
|
|
2402
|
-
this.logger.info(`[${commandId}] - current channel is left. unsubscribing from all listeners`);
|
|
3684
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - current channel is left. unsubscribing from all listeners`);
|
|
2403
3685
|
});
|
|
2404
3686
|
}
|
|
2405
3687
|
getContextForChannel({ commandId, channelId, contextType }) {
|
|
3688
|
+
var _a, _b, _c, _d, _e;
|
|
2406
3689
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2407
3690
|
yield this.initDonePromise;
|
|
2408
|
-
this.logger.info(`[${commandId}] - getContextForChannel() invoked for channel with id ${channelId}`);
|
|
3691
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getContextForChannel() invoked for channel with id ${channelId}`);
|
|
2409
3692
|
const isUserChannel = this.isUserChannel(channelId);
|
|
2410
3693
|
if (!contextType) {
|
|
2411
|
-
this.logger.info(`[${commandId}] - retrieving latest context broadcasted on channel with id ${channelId}`);
|
|
3694
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - retrieving latest context broadcasted on channel with id ${channelId}`);
|
|
2412
3695
|
let context;
|
|
2413
3696
|
if (isUserChannel) {
|
|
2414
3697
|
const glueChannelName = this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId);
|
|
2415
3698
|
const glueChannelWithPrefix = this.channelsParser.mapChannelNameToContextName(glueChannelName);
|
|
2416
|
-
this.logger.info(`[${commandId}] - getting context for user channel with id ${channelId} (underlying glue channel ${glueChannelName})`);
|
|
3699
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - getting context for user channel with id ${channelId} (underlying glue channel ${glueChannelName})`);
|
|
2417
3700
|
context = yield this.glueController.getContext(glueChannelWithPrefix);
|
|
2418
3701
|
}
|
|
2419
3702
|
else {
|
|
2420
|
-
this.logger.info(`[${commandId}] - getting context for app channel with id ${channelId}`);
|
|
3703
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.info(`[${commandId}] - getting context for app channel with id ${channelId}`);
|
|
2421
3704
|
context = yield this.glueController.getContext(channelId);
|
|
2422
3705
|
}
|
|
2423
3706
|
return context.latest_fdc3_type
|
|
2424
3707
|
? this.channelsParser.parseContextsDataToInitialFDC3Data(context)
|
|
2425
3708
|
: null;
|
|
2426
3709
|
}
|
|
2427
|
-
this.logger.info(`[${commandId}] Retrieving latest context of type ${contextType} broadcasted on ${isUserChannel ? "user" : "app"} channel with id ${channelId}`);
|
|
3710
|
+
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.info(`[${commandId}] Retrieving latest context of type ${contextType} broadcasted on ${isUserChannel ? "user" : "app"} channel with id ${channelId}`);
|
|
2428
3711
|
const parsedType = this.channelsParser.mapFDC3TypeToChannelsDelimiter(contextType);
|
|
2429
3712
|
const { data } = isUserChannel
|
|
2430
3713
|
? yield this.glueController.getChannel(this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId))
|
|
@@ -2435,9 +3718,10 @@ class ChannelsController {
|
|
|
2435
3718
|
});
|
|
2436
3719
|
}
|
|
2437
3720
|
createPrivateChannel(commandId) {
|
|
3721
|
+
var _a;
|
|
2438
3722
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2439
3723
|
yield this.initDonePromise;
|
|
2440
|
-
this.logger.info(`[${commandId}] - createPrivateChannel() invoked`);
|
|
3724
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - createPrivateChannel() invoked`);
|
|
2441
3725
|
const channelId = `${PrivateChannelPrefix}${nanoid()}`;
|
|
2442
3726
|
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2443
3727
|
const pc = this.buildPrivateChannel(channelId, commandId, true);
|
|
@@ -2461,26 +3745,30 @@ class ChannelsController {
|
|
|
2461
3745
|
return this.glueController.getMyInteropInstance();
|
|
2462
3746
|
}
|
|
2463
3747
|
addClientToPrivateChannel(commandId, channelId, clientId) {
|
|
3748
|
+
var _a;
|
|
2464
3749
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2465
|
-
this.logger.info(`[${commandId}] - client with id ${clientId} added to private channel with id ${channelId}`);
|
|
3750
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - client with id ${clientId} added to private channel with id ${channelId}`);
|
|
2466
3751
|
yield this.glueController.updateContext(channelId, { clientId });
|
|
2467
3752
|
});
|
|
2468
3753
|
}
|
|
2469
3754
|
isPrivateChannelDisconnected({ commandId, channelId }) {
|
|
3755
|
+
var _a;
|
|
2470
3756
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2471
|
-
this.logger.info(`[${commandId}] - checking if private channel with id ${channelId} is disconnected`);
|
|
3757
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - checking if private channel with id ${channelId} is disconnected`);
|
|
2472
3758
|
const context = yield this.glueController.getContext(channelId);
|
|
2473
3759
|
return !!context.disconnected;
|
|
2474
3760
|
});
|
|
2475
3761
|
}
|
|
2476
3762
|
subscribeOnInstanceStop(channelId, handler, commandId) {
|
|
2477
|
-
|
|
3763
|
+
var _a;
|
|
3764
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - subscribing onInstanceStopped callback for channel with id ${channelId}`);
|
|
2478
3765
|
return this.glueController.registerOnInstanceStopped(handler.bind(this));
|
|
2479
3766
|
}
|
|
2480
3767
|
buildPrivateChannel(channelId, commandId, isCreator) {
|
|
3768
|
+
var _a;
|
|
2481
3769
|
const logger = this.glueController.initSubLogger(channelId);
|
|
2482
3770
|
const channel = this.buildChannel(ChannelTypes.Private, { id: channelId, logger, isCreator });
|
|
2483
|
-
this.logger.info(`[${commandId}] - private channel with id ${channelId} created. Adding it to the store`);
|
|
3771
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - private channel with id ${channelId} created. Adding it to the store`);
|
|
2484
3772
|
this.channelsStateStore.addPrivateChannel(channel);
|
|
2485
3773
|
return channel;
|
|
2486
3774
|
}
|
|
@@ -2518,70 +3806,73 @@ class ChannelsController {
|
|
|
2518
3806
|
});
|
|
2519
3807
|
}
|
|
2520
3808
|
isBroadcastPermitted(commandId, channelId) {
|
|
3809
|
+
var _a, _b;
|
|
2521
3810
|
if (channelId) {
|
|
2522
3811
|
return true;
|
|
2523
3812
|
}
|
|
2524
3813
|
if (!this.channelsStateStore.currentChannel) {
|
|
2525
|
-
this.logger.info(`[${commandId}] - invocation of broadcast ignored - no channel to broadcast to`);
|
|
3814
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - invocation of broadcast ignored - no channel to broadcast to`);
|
|
2526
3815
|
console.error("You need to join a user channel in order to broadcast");
|
|
2527
3816
|
return false;
|
|
2528
3817
|
}
|
|
2529
3818
|
if (this.channelsStateStore.currentChannel.type === ChannelTypes.App) {
|
|
2530
|
-
this.logger.info(`[${commandId}] - invocation of broadcast ignored - cannot broadcast on app channel directly`);
|
|
3819
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - invocation of broadcast ignored - cannot broadcast on app channel directly`);
|
|
2531
3820
|
console.error("You can't broadcast to an app channel directly - use channel's broadcast method instead");
|
|
2532
3821
|
return false;
|
|
2533
3822
|
}
|
|
2534
3823
|
return true;
|
|
2535
3824
|
}
|
|
2536
3825
|
handleWindowContextOnOpening(commandId, handler, contextType) {
|
|
3826
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2537
3827
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2538
3828
|
const myWindow = this.glueController.getMyWindow();
|
|
2539
3829
|
if (!myWindow) {
|
|
2540
|
-
this.logger.trace(`[${commandId}] - Cannot get window context because this is not a Glue window, it's probably an iframe`);
|
|
3830
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - Cannot get window context because this is not a Glue window, it's probably an iframe`);
|
|
2541
3831
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2542
3832
|
return;
|
|
2543
3833
|
}
|
|
2544
3834
|
const windowContext = yield myWindow.getContext();
|
|
2545
3835
|
if (!windowContext) {
|
|
2546
|
-
this.logger.trace(`[${commandId}] - Cannot get window context because this is not a Glue window, it's probably an iframe`);
|
|
3836
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - Cannot get window context because this is not a Glue window, it's probably an iframe`);
|
|
2547
3837
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2548
3838
|
return;
|
|
2549
3839
|
}
|
|
2550
3840
|
if (!isValidNonEmptyObject(windowContext) || !windowContext.fdc3) {
|
|
2551
|
-
this.logger.info(`[${commandId}] - addContextListener handler won't be invoked - startup context is empty`);
|
|
3841
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - addContextListener handler won't be invoked - startup context is empty`);
|
|
2552
3842
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2553
3843
|
return;
|
|
2554
3844
|
}
|
|
2555
3845
|
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2556
3846
|
FDC3StartupContextDecoder.runWithException(windowContext);
|
|
2557
3847
|
const { fdc3 } = windowContext;
|
|
2558
|
-
this.logger.trace(`[${commandId}] - received FDC3 startup context from ${JSON.stringify(fdc3.openApp)} for contextType ${fdc3.context.contextType}`);
|
|
3848
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.trace(`[${commandId}] - received FDC3 startup context from ${JSON.stringify(fdc3.openApp)} for contextType ${fdc3.context.contextType}`);
|
|
2559
3849
|
const isSameContextType = contextType ? fdc3.context.contextType === contextType : true;
|
|
2560
3850
|
if (!isSameContextType) {
|
|
2561
|
-
this.logger.info(`[${commandId}] - addContextListener handler won't be invoked for contextType ${contextType} for startup context with type: ${fdc3.context.contextType}`);
|
|
3851
|
+
(_e = this.logger) === null || _e === void 0 ? void 0 : _e.info(`[${commandId}] - addContextListener handler won't be invoked for contextType ${contextType} for startup context with type: ${fdc3.context.contextType}`);
|
|
2562
3852
|
return;
|
|
2563
3853
|
}
|
|
2564
|
-
this.logger.info(`[${commandId}] - invoking addContextListener handler with startup context with type ${fdc3.context.contextType}`);
|
|
3854
|
+
(_f = this.logger) === null || _f === void 0 ? void 0 : _f.info(`[${commandId}] - invoking addContextListener handler with startup context with type ${fdc3.context.contextType}`);
|
|
2565
3855
|
try {
|
|
2566
3856
|
handler(fdc3.context.payload, { source: fdc3.openApp });
|
|
2567
3857
|
}
|
|
2568
3858
|
catch (error) {
|
|
2569
|
-
this.logger.error(typeof error === "string" ? error : error.message ? JSON.stringify(error.message) : JSON.stringify(error));
|
|
3859
|
+
(_g = this.logger) === null || _g === void 0 ? void 0 : _g.error(typeof error === "string" ? error : error.message ? JSON.stringify(error.message) : JSON.stringify(error));
|
|
2570
3860
|
}
|
|
2571
3861
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2572
|
-
this.logger.trace(`[${commandId}] - invoking response method to with target ${JSON.stringify(fdc3.openApp)}`);
|
|
3862
|
+
(_h = this.logger) === null || _h === void 0 ? void 0 : _h.trace(`[${commandId}] - invoking response method to with target ${JSON.stringify(fdc3.openApp)}`);
|
|
2573
3863
|
yield this.invokeSystemMethod({ action: "startupContextOpened", correlationId: fdc3.collaborationId }, fdc3.openApp.instanceId);
|
|
2574
|
-
this.logger.trace(`[${commandId}] - system method invocation success for 'startupContextOpened' heard`);
|
|
3864
|
+
(_j = this.logger) === null || _j === void 0 ? void 0 : _j.trace(`[${commandId}] - system method invocation success for 'startupContextOpened' heard`);
|
|
2575
3865
|
});
|
|
2576
3866
|
}
|
|
2577
3867
|
getOrCreateAppChannel(commandId, channelId) {
|
|
3868
|
+
var _a, _b;
|
|
2578
3869
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2579
3870
|
const exists = this.doesAppChannelExist(channelId);
|
|
2580
3871
|
if (!exists) {
|
|
2581
|
-
this.logger.info(`[${commandId}] - app channel with id ${channelId} does not exist. Creating one`);
|
|
3872
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - app channel with id ${channelId} does not exist. Creating one`);
|
|
2582
3873
|
yield this.glueController.updateContext(channelId, {});
|
|
2583
3874
|
}
|
|
2584
|
-
this.logger.info(`[${commandId}] - returning app channel with id ${channelId}`);
|
|
3875
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - returning app channel with id ${channelId}`);
|
|
2585
3876
|
const logger = this.glueController.initSubLogger(`app.channel.${channelId}`);
|
|
2586
3877
|
return this.buildChannel(ChannelTypes.App, { id: channelId, logger });
|
|
2587
3878
|
});
|
|
@@ -2596,22 +3887,24 @@ class ChannelsController {
|
|
|
2596
3887
|
return !!this.channelsStateStore.userChannels[channelId];
|
|
2597
3888
|
}
|
|
2598
3889
|
broadcastByChannelId(commandId, channelId, context) {
|
|
3890
|
+
var _a, _b;
|
|
2599
3891
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2600
3892
|
const isUserChannel = this.isUserChannel(channelId);
|
|
2601
3893
|
if (!isUserChannel) {
|
|
2602
|
-
this.logger.info(`[${commandId}] - broadcasting on app channel with id ${channelId}`);
|
|
3894
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - broadcasting on app channel with id ${channelId}`);
|
|
2603
3895
|
return this.glueController.updateContextWithLatestFdc3Type(channelId, context);
|
|
2604
3896
|
}
|
|
2605
3897
|
const glueChannelName = this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId);
|
|
2606
|
-
this.logger.info(`[${commandId}] - broadcasting on fdc3 user channel with id ${channelId} (underlying glue channel: ${glueChannelName})`);
|
|
3898
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - broadcasting on fdc3 user channel with id ${channelId} (underlying glue channel: ${glueChannelName})`);
|
|
2607
3899
|
return this.glueController.channelsUpdate(glueChannelName, context);
|
|
2608
3900
|
});
|
|
2609
3901
|
}
|
|
2610
3902
|
addContextListenerByChannelId({ commandId, channelId, handler, contextType, invokedOnChannelModel }) {
|
|
3903
|
+
var _a, _b;
|
|
2611
3904
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2612
3905
|
const subHandler = parseContextHandler(handler, contextType);
|
|
2613
3906
|
if (!channelId) {
|
|
2614
|
-
this.logger.info(`[${commandId}] - Creating a channel subscription using glue.channels.subscribe`);
|
|
3907
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - Creating a channel subscription using glue.channels.subscribe`);
|
|
2615
3908
|
const unsubscribe = this.glueController.channelsSubscribe(subHandler, contextType);
|
|
2616
3909
|
return { unsubscribe };
|
|
2617
3910
|
}
|
|
@@ -2620,11 +3913,12 @@ class ChannelsController {
|
|
|
2620
3913
|
return this.addContextListenerOnUserChannel({ commandId, channelId, handler: subHandler, contextType, invokedOnChannelModel });
|
|
2621
3914
|
}
|
|
2622
3915
|
if (channelType === ChannelTypes.App) {
|
|
2623
|
-
this.logger.info(`[${commandId}] - subscribing for fdc3 app channel with id ${channelId} (underlying glue context with same name)`);
|
|
3916
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - subscribing for fdc3 app channel with id ${channelId} (underlying glue context with same name)`);
|
|
2624
3917
|
const unsubscribe = yield this.glueController.contextsSubscribe(channelId, subHandler);
|
|
2625
3918
|
return {
|
|
2626
3919
|
unsubscribe: () => {
|
|
2627
|
-
|
|
3920
|
+
var _a;
|
|
3921
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - invoking unsubscribe for app channel with id ${channelId}`);
|
|
2628
3922
|
unsubscribe();
|
|
2629
3923
|
}
|
|
2630
3924
|
};
|
|
@@ -2633,20 +3927,22 @@ class ChannelsController {
|
|
|
2633
3927
|
});
|
|
2634
3928
|
}
|
|
2635
3929
|
addContextListenerOnUserChannel({ commandId, channelId, handler, invokedOnChannelModel, contextType }) {
|
|
3930
|
+
var _a, _b;
|
|
2636
3931
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2637
3932
|
let unsubscribe;
|
|
2638
3933
|
if (invokedOnChannelModel) {
|
|
2639
3934
|
const contextToSubscribeTo = this.channelsParser.mapChannelNameToContextName(this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId));
|
|
2640
|
-
this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
3935
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
2641
3936
|
unsubscribe = yield this.glueController.contextsSubscribe(contextToSubscribeTo, handler);
|
|
2642
3937
|
}
|
|
2643
3938
|
else {
|
|
2644
|
-
this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
3939
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
2645
3940
|
unsubscribe = this.glueController.channelsSubscribe(handler, contextType);
|
|
2646
3941
|
}
|
|
2647
3942
|
return {
|
|
2648
3943
|
unsubscribe: () => {
|
|
2649
|
-
|
|
3944
|
+
var _a;
|
|
3945
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - invoking unsubscribe for fdc3 user channel with id ${channelId}`);
|
|
2650
3946
|
unsubscribe();
|
|
2651
3947
|
}
|
|
2652
3948
|
};
|
|
@@ -2924,7 +4220,7 @@ class PrivateChannel {
|
|
|
2924
4220
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2925
4221
|
this.setCollaborator(collaborator, commandId);
|
|
2926
4222
|
yield Promise.all(this.myListenerTypesBeforeBound.map((contextType) => {
|
|
2927
|
-
var _a;
|
|
4223
|
+
var _a, _b;
|
|
2928
4224
|
const listenerAddedArgs = {
|
|
2929
4225
|
action: "addedContextListenerOnPrivateChannel",
|
|
2930
4226
|
correlationId: this.id,
|
|
@@ -2933,25 +4229,28 @@ class PrivateChannel {
|
|
|
2933
4229
|
contextType: contextType || undefined
|
|
2934
4230
|
}
|
|
2935
4231
|
};
|
|
2936
|
-
this.logger.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
2937
|
-
return this.channelsController.invokeSystemMethod(listenerAddedArgs, (
|
|
2938
|
-
})).catch((err) => this.logger.error(err));
|
|
4232
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
4233
|
+
return this.channelsController.invokeSystemMethod(listenerAddedArgs, (_b = this.collaborator) === null || _b === void 0 ? void 0 : _b.instanceId);
|
|
4234
|
+
})).catch((err) => { var _a; return (_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(err); });
|
|
2939
4235
|
});
|
|
2940
4236
|
}
|
|
2941
4237
|
handleCollaboratorBroadcast(context, metadata, commandId) {
|
|
2942
|
-
|
|
4238
|
+
var _a, _b;
|
|
4239
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - heard context with type ${context.type} broadcasted on the channel`);
|
|
2943
4240
|
this.lastBroadcastedContextType = context.type;
|
|
2944
4241
|
this.broadcastedContexts[context.type] = { context, metadata };
|
|
2945
|
-
this.logger.trace(`[${commandId}] - invoking all context listeners`);
|
|
4242
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - invoking all context listeners`);
|
|
2946
4243
|
this.registry.execute(PrivateChannelEventMethods.ListenerAdded, context, metadata);
|
|
2947
4244
|
}
|
|
2948
4245
|
handleCollaboratorAddContextListener(contextType, commandId) {
|
|
2949
|
-
|
|
4246
|
+
var _a;
|
|
4247
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - heard collaborator added context listener for type ${contextType}`);
|
|
2950
4248
|
this.collaboratorListenerTypes.push(contextType);
|
|
2951
4249
|
this.registry.execute(PrivateChannelEventMethods.OnAddContextListener, contextType);
|
|
2952
4250
|
}
|
|
2953
4251
|
handleCollaboratorRemovedListener(contextType, commandId) {
|
|
2954
|
-
|
|
4252
|
+
var _a;
|
|
4253
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - heard collaborator removed context listener with type ${contextType}`);
|
|
2955
4254
|
const index = this.collaboratorListenerTypes.indexOf(contextType);
|
|
2956
4255
|
this.collaboratorListenerTypes.splice(index, 1);
|
|
2957
4256
|
this.registry.execute(PrivateChannelEventMethods.OnUnsubscribe, contextType);
|
|
@@ -2962,6 +4261,7 @@ class PrivateChannel {
|
|
|
2962
4261
|
this.registry.execute(PrivateChannelEventMethods.OnDisconnect);
|
|
2963
4262
|
}
|
|
2964
4263
|
announceJoin(targetInstance, commandId) {
|
|
4264
|
+
var _a, _b;
|
|
2965
4265
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2966
4266
|
const joinChannelArgs = {
|
|
2967
4267
|
action: "joinPrivateChannel",
|
|
@@ -2970,18 +4270,21 @@ class PrivateChannel {
|
|
|
2970
4270
|
channelId: this.id
|
|
2971
4271
|
}
|
|
2972
4272
|
};
|
|
2973
|
-
this.logger.trace(`[${commandId}] - announcing ${"joinPrivateChannel"} to target instance with id ${JSON.stringify(targetInstance)}`);
|
|
4273
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - announcing ${"joinPrivateChannel"} to target instance with id ${JSON.stringify(targetInstance)}`);
|
|
2974
4274
|
yield this.channelsController.invokeSystemMethod(joinChannelArgs, targetInstance);
|
|
2975
|
-
this.logger.trace(`[${commandId}] - collaborator received ${"joinPrivateChannel"} action`);
|
|
4275
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - collaborator received ${"joinPrivateChannel"} action`);
|
|
2976
4276
|
});
|
|
2977
4277
|
}
|
|
2978
4278
|
broadcast(context) {
|
|
2979
|
-
var _a;
|
|
4279
|
+
var _a, _b, _c;
|
|
2980
4280
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4281
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
4282
|
+
if (!contextDecoderResult.ok) {
|
|
4283
|
+
throw new Error(ChannelError.MalformedContext);
|
|
4284
|
+
}
|
|
2981
4285
|
const commandId = generateCommandId();
|
|
2982
4286
|
this.ensureAlive(commandId);
|
|
2983
4287
|
this.ensureBound(commandId, "broadcast");
|
|
2984
|
-
contextDecoder.runWithException(context);
|
|
2985
4288
|
this.lastBroadcastedContextType = context.type;
|
|
2986
4289
|
this.broadcastedContexts[context.type] = { context, metadata: this.myAppMetadata };
|
|
2987
4290
|
const broadcastArgs = {
|
|
@@ -2993,27 +4296,29 @@ class PrivateChannel {
|
|
|
2993
4296
|
payload: context
|
|
2994
4297
|
}
|
|
2995
4298
|
};
|
|
2996
|
-
this.logger.trace(`[${commandId}] - announcing ${"publishOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
2997
|
-
yield this.channelsController.invokeSystemMethod(broadcastArgs, (
|
|
2998
|
-
this.logger.trace(`[${commandId}] - collaborator received context for action ${"publishOnPrivateChannel"}`);
|
|
4299
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - announcing ${"publishOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
4300
|
+
yield this.channelsController.invokeSystemMethod(broadcastArgs, (_b = this.collaborator) === null || _b === void 0 ? void 0 : _b.instanceId);
|
|
4301
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.trace(`[${commandId}] - collaborator received context for action ${"publishOnPrivateChannel"}`);
|
|
2999
4302
|
});
|
|
3000
4303
|
}
|
|
3001
4304
|
getCurrentContext(contextType) {
|
|
4305
|
+
var _a, _b;
|
|
3002
4306
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3003
4307
|
const commandId = generateCommandId();
|
|
3004
4308
|
this.ensureAlive(commandId);
|
|
3005
|
-
|
|
4309
|
+
const contextTypeMessage = contextType ? ` with contextType ${contextType}` : "";
|
|
4310
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - getCurrentContext invoked ${contextTypeMessage}`);
|
|
3006
4311
|
optionalNonEmptyStringDecoder.runWithException(contextType);
|
|
3007
4312
|
if (!contextType && !this.lastBroadcastedContextType) {
|
|
3008
4313
|
return null;
|
|
3009
4314
|
}
|
|
3010
4315
|
const searchedType = contextType || this.lastBroadcastedContextType;
|
|
3011
|
-
this.logger.trace(`[${commandId}] - Returning context with type ${searchedType}`);
|
|
4316
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - Returning context with type ${searchedType}`);
|
|
3012
4317
|
return this.broadcastedContexts[searchedType].context;
|
|
3013
4318
|
});
|
|
3014
4319
|
}
|
|
3015
4320
|
addContextListener(contextType, handler) {
|
|
3016
|
-
var _a;
|
|
4321
|
+
var _a, _b, _c, _d;
|
|
3017
4322
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3018
4323
|
const commandId = generateCommandId();
|
|
3019
4324
|
this.ensureAlive(commandId);
|
|
@@ -3021,7 +4326,7 @@ class PrivateChannel {
|
|
|
3021
4326
|
if (typeof handler !== "function") {
|
|
3022
4327
|
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof contextType}` };
|
|
3023
4328
|
}
|
|
3024
|
-
this.logger.trace(`[${commandId}] - adding subscription for broadcasted contexts with type: ${contextType}`);
|
|
4329
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - adding subscription for broadcasted contexts with type: ${contextType}`);
|
|
3025
4330
|
const subHandler = (data, metadata) => {
|
|
3026
4331
|
if (contextType) {
|
|
3027
4332
|
if (data.type === contextType) {
|
|
@@ -3043,9 +4348,9 @@ class PrivateChannel {
|
|
|
3043
4348
|
contextType: contextType || undefined
|
|
3044
4349
|
}
|
|
3045
4350
|
};
|
|
3046
|
-
this.logger.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
3047
|
-
yield this.channelsController.invokeSystemMethod(listenerAddedArgs, (
|
|
3048
|
-
this.logger.trace(`[${commandId}] - collaborator received action ${"addedContextListenerOnPrivateChannel"}`);
|
|
4351
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
4352
|
+
yield this.channelsController.invokeSystemMethod(listenerAddedArgs, (_c = this.collaborator) === null || _c === void 0 ? void 0 : _c.instanceId);
|
|
4353
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.trace(`[${commandId}] - collaborator received action ${"addedContextListenerOnPrivateChannel"}`);
|
|
3049
4354
|
}
|
|
3050
4355
|
else {
|
|
3051
4356
|
this.myListenerTypesBeforeBound.push(contextType);
|
|
@@ -3068,7 +4373,7 @@ class PrivateChannel {
|
|
|
3068
4373
|
}
|
|
3069
4374
|
getAddContextListenerUnsub(unsub, contextType, commandId) {
|
|
3070
4375
|
return () => __awaiter(this, void 0, void 0, function* () {
|
|
3071
|
-
var _a;
|
|
4376
|
+
var _a, _b, _c;
|
|
3072
4377
|
unsub();
|
|
3073
4378
|
if (!this.collaborator) {
|
|
3074
4379
|
const index = this.myListenerTypesBeforeBound.indexOf(contextType);
|
|
@@ -3083,9 +4388,9 @@ class PrivateChannel {
|
|
|
3083
4388
|
contextType: contextType || undefined
|
|
3084
4389
|
}
|
|
3085
4390
|
};
|
|
3086
|
-
this.logger.trace(`[${commandId}] - announcing unsubscribe from context listener for type ${contextType}`);
|
|
3087
|
-
yield this.channelsController.invokeSystemMethod(unsubArgs, (
|
|
3088
|
-
this.logger.trace(`[${commandId}] - collaborator heard ${"removedContextListenerOnPrivateChannel"}`);
|
|
4391
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - announcing unsubscribe from context listener for type ${contextType}`);
|
|
4392
|
+
yield this.channelsController.invokeSystemMethod(unsubArgs, (_b = this.collaborator) === null || _b === void 0 ? void 0 : _b.instanceId);
|
|
4393
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.trace(`[${commandId}] - collaborator heard ${"removedContextListenerOnPrivateChannel"}`);
|
|
3089
4394
|
});
|
|
3090
4395
|
}
|
|
3091
4396
|
onAddContextListener(handler) {
|
|
@@ -3116,7 +4421,7 @@ class PrivateChannel {
|
|
|
3116
4421
|
return AsyncListener(unsub);
|
|
3117
4422
|
}
|
|
3118
4423
|
disconnect() {
|
|
3119
|
-
var _a;
|
|
4424
|
+
var _a, _b, _c, _d;
|
|
3120
4425
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3121
4426
|
const commandId = generateCommandId();
|
|
3122
4427
|
if (this.isCreator && !this.collaborator) {
|
|
@@ -3125,9 +4430,9 @@ class PrivateChannel {
|
|
|
3125
4430
|
}
|
|
3126
4431
|
this.ensureAlive(commandId);
|
|
3127
4432
|
this.ensureBound(commandId, "disconnect");
|
|
3128
|
-
this.logger.trace(`[${commandId}] - disconnect invoked`);
|
|
4433
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - disconnect invoked`);
|
|
3129
4434
|
this.disconnected = true;
|
|
3130
|
-
this.logger.trace(`[${commandId}] - announcing ${"disconnectedFromPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
4435
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - announcing ${"disconnectedFromPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
3131
4436
|
const disconnectArgs = {
|
|
3132
4437
|
action: "disconnectedFromPrivateChannel",
|
|
3133
4438
|
correlationId: this.id,
|
|
@@ -3136,27 +4441,29 @@ class PrivateChannel {
|
|
|
3136
4441
|
}
|
|
3137
4442
|
};
|
|
3138
4443
|
this.channelsController.removePrivateChannelFromStoreById(this.id);
|
|
3139
|
-
yield this.channelsController.invokeSystemMethod(disconnectArgs, (
|
|
3140
|
-
this.logger.trace(`[${commandId}] - collaborator received action ${"disconnectedFromPrivateChannel"}`);
|
|
4444
|
+
yield this.channelsController.invokeSystemMethod(disconnectArgs, (_c = this.collaborator) === null || _c === void 0 ? void 0 : _c.instanceId);
|
|
4445
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.trace(`[${commandId}] - collaborator received action ${"disconnectedFromPrivateChannel"}`);
|
|
3141
4446
|
if (this.unsubFromInstanceStopped) {
|
|
3142
4447
|
this.unsubFromInstanceStopped();
|
|
3143
4448
|
}
|
|
3144
4449
|
});
|
|
3145
4450
|
}
|
|
3146
4451
|
ensureAlive(commandId) {
|
|
4452
|
+
var _a;
|
|
3147
4453
|
if (!this.disconnected) {
|
|
3148
4454
|
return;
|
|
3149
4455
|
}
|
|
3150
4456
|
const errorMsg = "Channel is disconnected - operation is no longer available";
|
|
3151
|
-
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
4457
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`[${commandId}] - ${errorMsg}`);
|
|
3152
4458
|
throw { message: ChannelError.AccessDenied, reason: errorMsg };
|
|
3153
4459
|
}
|
|
3154
4460
|
ensureBound(commandId, operation) {
|
|
4461
|
+
var _a;
|
|
3155
4462
|
if (this.collaborator) {
|
|
3156
4463
|
return;
|
|
3157
4464
|
}
|
|
3158
4465
|
const errorMsg = `There's no collaborator on the other side of the channel - operation ${operation} is unavailable`;
|
|
3159
|
-
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
4466
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`[${commandId}] - ${errorMsg}`);
|
|
3160
4467
|
throw { message: ChannelError.AccessDenied, reason: errorMsg };
|
|
3161
4468
|
}
|
|
3162
4469
|
subscribeForCollaboratorInstanceStop(commandId) {
|
|
@@ -3227,17 +4534,18 @@ class GlueEventsController {
|
|
|
3227
4534
|
return !!methodsByThisInstance.length;
|
|
3228
4535
|
}
|
|
3229
4536
|
handleReceivedAction(eventArgs, instance) {
|
|
4537
|
+
var _a, _b;
|
|
3230
4538
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3231
4539
|
const argsDecodeResult = SystemMethodInvocationArgumentDecoder.run(eventArgs);
|
|
3232
4540
|
if (!argsDecodeResult.ok) {
|
|
3233
4541
|
throw new Error(`Interop Method ${ioConnectFDC3SystemMethod} invoked with invalid argument object - ${argsDecodeResult.error}`);
|
|
3234
4542
|
}
|
|
3235
4543
|
const commandId = generateCommandId();
|
|
3236
|
-
this.logger.log(`${commandId} - received system method from instance with id ${instance.instance} for action ${eventArgs.action} with arguments: ${JSON.stringify(eventArgs)}`);
|
|
4544
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`${commandId} - received system method from instance with id ${instance.instance} for action ${eventArgs.action} with arguments: ${JSON.stringify(eventArgs)}`);
|
|
3237
4545
|
const operation = this.actionDictionary[eventArgs.action];
|
|
3238
4546
|
if (!operation) {
|
|
3239
4547
|
const errorMsg = `Unsupported private channel action: ${eventArgs.action}`;
|
|
3240
|
-
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
4548
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error(`[${commandId}] - ${errorMsg}`);
|
|
3241
4549
|
throw new Error(errorMsg);
|
|
3242
4550
|
}
|
|
3243
4551
|
yield operation(eventArgs, instance, commandId);
|
|
@@ -3250,10 +4558,11 @@ class GlueEventsController {
|
|
|
3250
4558
|
return this._logger;
|
|
3251
4559
|
}
|
|
3252
4560
|
validateAndRetrieveChannel({ action, correlationId }, instance, commandId) {
|
|
4561
|
+
var _a, _b, _c;
|
|
3253
4562
|
const privateChannel = this.channelsStateStore.getPrivateChannelById(correlationId);
|
|
3254
4563
|
if (!privateChannel) {
|
|
3255
4564
|
const errorMsg = `There's no private channel with id ${correlationId}`;
|
|
3256
|
-
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
4565
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`[${commandId}] - ${errorMsg}`);
|
|
3257
4566
|
throw new Error(errorMsg);
|
|
3258
4567
|
}
|
|
3259
4568
|
const channelCollaborator = privateChannel.getCollaborator();
|
|
@@ -3261,26 +4570,27 @@ class GlueEventsController {
|
|
|
3261
4570
|
return privateChannel;
|
|
3262
4571
|
}
|
|
3263
4572
|
if (channelCollaborator && channelCollaborator.instanceId === instance.instance) {
|
|
3264
|
-
this.logger.log(`[${commandId}] - request sent from correct collaborator with id ${instance.instance}. Returning channel`);
|
|
4573
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log(`[${commandId}] - request sent from correct collaborator with id ${instance.instance}. Returning channel`);
|
|
3265
4574
|
return privateChannel;
|
|
3266
4575
|
}
|
|
3267
4576
|
const errorMsg = `Cannot proceed with action ${action} - ${channelCollaborator
|
|
3268
4577
|
? `private channel ${correlationId} established communication with collaborator with id ${channelCollaborator}`
|
|
3269
4578
|
: `no collaborator joined private channel with id ${correlationId}`}`;
|
|
3270
|
-
this.logger.error(errorMsg);
|
|
4579
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.error(errorMsg);
|
|
3271
4580
|
throw new Error(errorMsg);
|
|
3272
4581
|
}
|
|
3273
4582
|
handleJoin(eventArgs, instance, commandId) {
|
|
4583
|
+
var _a;
|
|
3274
4584
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3275
4585
|
const collaborator = { appId: instance.application || instance.applicationName, instanceId: instance.instance };
|
|
3276
4586
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3277
4587
|
yield privateChannel.handleCollaboratorJoin(collaborator, commandId);
|
|
3278
|
-
this.logger.log(`[${commandId}] - collaborator ${JSON.stringify(collaborator)} set for private channel with id ${eventArgs.correlationId}`);
|
|
4588
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - collaborator ${JSON.stringify(collaborator)} set for private channel with id ${eventArgs.correlationId}`);
|
|
3279
4589
|
});
|
|
3280
4590
|
}
|
|
3281
4591
|
handlePublish(eventArgs, instance, commandId) {
|
|
3282
|
-
var _a, _b;
|
|
3283
|
-
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, adding context with type ${(
|
|
4592
|
+
var _a, _b, _c;
|
|
4593
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - received ${eventArgs.action} action, adding context with type ${(_b = eventArgs.collaborationObject) === null || _b === void 0 ? void 0 : _b.contextType} to the private channel broadcasted contexts`);
|
|
3284
4594
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3285
4595
|
const metadata = {
|
|
3286
4596
|
source: {
|
|
@@ -3288,33 +4598,35 @@ class GlueEventsController {
|
|
|
3288
4598
|
instanceId: instance.instance
|
|
3289
4599
|
}
|
|
3290
4600
|
};
|
|
3291
|
-
privateChannel.handleCollaboratorBroadcast((
|
|
4601
|
+
privateChannel.handleCollaboratorBroadcast((_c = eventArgs.collaborationObject) === null || _c === void 0 ? void 0 : _c.payload, metadata, commandId);
|
|
3292
4602
|
}
|
|
3293
4603
|
handleContextListenerAdded(eventArgs, instance, commandId) {
|
|
3294
|
-
var _a;
|
|
3295
|
-
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onAddContextListener' callbacks`);
|
|
4604
|
+
var _a, _b;
|
|
4605
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onAddContextListener' callbacks`);
|
|
3296
4606
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3297
|
-
privateChannel.handleCollaboratorAddContextListener(((
|
|
4607
|
+
privateChannel.handleCollaboratorAddContextListener(((_b = eventArgs.collaborationObject) === null || _b === void 0 ? void 0 : _b.contextType) || null, commandId);
|
|
3298
4608
|
}
|
|
3299
4609
|
handleContextListenerRemoved(eventArgs, instance, commandId) {
|
|
3300
|
-
var _a;
|
|
3301
|
-
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onUnsubscribe' callbacks`);
|
|
4610
|
+
var _a, _b;
|
|
4611
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onUnsubscribe' callbacks`);
|
|
3302
4612
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3303
|
-
privateChannel.handleCollaboratorRemovedListener(((
|
|
4613
|
+
privateChannel.handleCollaboratorRemovedListener(((_b = eventArgs.collaborationObject) === null || _b === void 0 ? void 0 : _b.contextType) || null, commandId);
|
|
3304
4614
|
}
|
|
3305
4615
|
handleDisconnect(eventArgs, instance, commandId) {
|
|
3306
|
-
|
|
4616
|
+
var _a;
|
|
4617
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onDisconnect' callbacks`);
|
|
3307
4618
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3308
4619
|
privateChannel.handleCollaboratorDisconnect();
|
|
3309
4620
|
}
|
|
3310
4621
|
handleStartupContextOpened(eventArgs, instance, commandId) {
|
|
3311
|
-
|
|
4622
|
+
var _a, _b, _c;
|
|
4623
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - received ${eventArgs.action} with correlationId: ${eventArgs.correlationId} from instance with id ${instance.instance}`);
|
|
3312
4624
|
const wrappedPromise = this.appsStateStore.getOpenAppPromise(eventArgs.correlationId);
|
|
3313
4625
|
if (!wrappedPromise) {
|
|
3314
|
-
this.logger.log(`[${commandId}] - there's no open app promise related to guid ${eventArgs.correlationId}`);
|
|
4626
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log(`[${commandId}] - there's no open app promise related to guid ${eventArgs.correlationId}`);
|
|
3315
4627
|
return;
|
|
3316
4628
|
}
|
|
3317
|
-
this.logger.log(`[${commandId}] - resolving open app promise related to guid ${eventArgs.correlationId} from instance with id ${instance.instance}`);
|
|
4629
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.log(`[${commandId}] - resolving open app promise related to guid ${eventArgs.correlationId} from instance with id ${instance.instance}`);
|
|
3318
4630
|
wrappedPromise.resolve();
|
|
3319
4631
|
}
|
|
3320
4632
|
}
|