@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.es.js
CHANGED
|
@@ -13,6 +13,203 @@ 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 promisePlus = (promise, timeoutMilliseconds, timeoutMessage) => {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
const timeout = setTimeout(() => {
|
|
75
|
+
const message = timeoutMessage || `Promise timeout hit: ${timeoutMilliseconds}`;
|
|
76
|
+
reject(message);
|
|
77
|
+
}, timeoutMilliseconds);
|
|
78
|
+
promise()
|
|
79
|
+
.then((result) => {
|
|
80
|
+
clearTimeout(timeout);
|
|
81
|
+
resolve(result);
|
|
82
|
+
})
|
|
83
|
+
.catch((error) => {
|
|
84
|
+
clearTimeout(timeout);
|
|
85
|
+
reject(error);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const generateCommandId = () => {
|
|
90
|
+
return nanoid();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const connectBrowserAppProps = ["name", "title", "version", "customProperties", "icon", "caption", "type"];
|
|
94
|
+
const fdc3v2AppProps = ["appId", "name", "type", "details", "version", "title", "tooltip", "lang", "description", "categories", "icons", "screenshots", "contactEmail", "moreInfo", "publisher", "customConfig", "hostManifests", "interop", "localizedVersions"];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Wraps values in an `Ok` type.
|
|
98
|
+
*
|
|
99
|
+
* Example: `ok(5) // => {ok: true, result: 5}`
|
|
100
|
+
*/
|
|
101
|
+
var ok$1 = function (result) { return ({ ok: true, result: result }); };
|
|
102
|
+
/**
|
|
103
|
+
* Wraps errors in an `Err` type.
|
|
104
|
+
*
|
|
105
|
+
* Example: `err('on fire') // => {ok: false, error: 'on fire'}`
|
|
106
|
+
*/
|
|
107
|
+
var err$1 = function (error) { return ({ ok: false, error: error }); };
|
|
108
|
+
/**
|
|
109
|
+
* Create a `Promise` that either resolves with the result of `Ok` or rejects
|
|
110
|
+
* with the error of `Err`.
|
|
111
|
+
*/
|
|
112
|
+
var asPromise$1 = function (r) {
|
|
113
|
+
return r.ok === true ? Promise.resolve(r.result) : Promise.reject(r.error);
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Unwraps a `Result` and returns either the result of an `Ok`, or
|
|
117
|
+
* `defaultValue`.
|
|
118
|
+
*
|
|
119
|
+
* Example:
|
|
120
|
+
* ```
|
|
121
|
+
* Result.withDefault(5, number().run(json))
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* It would be nice if `Decoder` had an instance method that mirrored this
|
|
125
|
+
* function. Such a method would look something like this:
|
|
126
|
+
* ```
|
|
127
|
+
* class Decoder<A> {
|
|
128
|
+
* runWithDefault = (defaultValue: A, json: any): A =>
|
|
129
|
+
* Result.withDefault(defaultValue, this.run(json));
|
|
130
|
+
* }
|
|
131
|
+
*
|
|
132
|
+
* number().runWithDefault(5, json)
|
|
133
|
+
* ```
|
|
134
|
+
* Unfortunately, the type of `defaultValue: A` on the method causes issues
|
|
135
|
+
* with type inference on the `object` decoder in some situations. While these
|
|
136
|
+
* inference issues can be solved by providing the optional type argument for
|
|
137
|
+
* `object`s, the extra trouble and confusion doesn't seem worth it.
|
|
138
|
+
*/
|
|
139
|
+
var withDefault$1 = function (defaultValue, r) {
|
|
140
|
+
return r.ok === true ? r.result : defaultValue;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Return the successful result, or throw an error.
|
|
144
|
+
*/
|
|
145
|
+
var withException$1 = function (r) {
|
|
146
|
+
if (r.ok === true) {
|
|
147
|
+
return r.result;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
throw r.error;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Apply `f` to the result of an `Ok`, or pass the error through.
|
|
155
|
+
*/
|
|
156
|
+
var map$1 = function (f, r) {
|
|
157
|
+
return r.ok === true ? ok$1(f(r.result)) : r;
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Apply `f` to the result of two `Ok`s, or pass an error through. If both
|
|
161
|
+
* `Result`s are errors then the first one is returned.
|
|
162
|
+
*/
|
|
163
|
+
var map2$1 = function (f, ar, br) {
|
|
164
|
+
return ar.ok === false ? ar :
|
|
165
|
+
br.ok === false ? br :
|
|
166
|
+
ok$1(f(ar.result, br.result));
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Apply `f` to the error of an `Err`, or pass the success through.
|
|
170
|
+
*/
|
|
171
|
+
var mapError$1 = function (f, r) {
|
|
172
|
+
return r.ok === true ? r : err$1(f(r.error));
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Chain together a sequence of computations that may fail, similar to a
|
|
176
|
+
* `Promise`. If the first computation fails then the error will propagate
|
|
177
|
+
* through. If it succeeds, then `f` will be applied to the value, returning a
|
|
178
|
+
* new `Result`.
|
|
179
|
+
*/
|
|
180
|
+
var andThen$1 = function (f, r) {
|
|
181
|
+
return r.ok === true ? f(r.result) : r;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/*! *****************************************************************************
|
|
185
|
+
Copyright (c) Microsoft Corporation.
|
|
186
|
+
|
|
187
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
188
|
+
purpose with or without fee is hereby granted.
|
|
189
|
+
|
|
190
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
191
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
192
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
193
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
194
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
195
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
196
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
197
|
+
***************************************************************************** */
|
|
198
|
+
/* global Reflect, Promise */
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
var __assign$1 = function() {
|
|
203
|
+
__assign$1 = Object.assign || function __assign(t) {
|
|
204
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
205
|
+
s = arguments[i];
|
|
206
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
207
|
+
}
|
|
208
|
+
return t;
|
|
209
|
+
};
|
|
210
|
+
return __assign$1.apply(this, arguments);
|
|
211
|
+
};
|
|
212
|
+
|
|
16
213
|
function __rest$1(s, e) {
|
|
17
214
|
var t = {};
|
|
18
215
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -25,73 +222,1034 @@ function __rest$1(s, e) {
|
|
|
25
222
|
return t;
|
|
26
223
|
}
|
|
27
224
|
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
225
|
+
function isEqual$1(a, b) {
|
|
226
|
+
if (a === b) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
if (a === null && b === null) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
if (typeof (a) !== typeof (b)) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
if (typeof (a) === 'object') {
|
|
236
|
+
// Array
|
|
237
|
+
if (Array.isArray(a)) {
|
|
238
|
+
if (!Array.isArray(b)) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
if (a.length !== b.length) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
for (var i = 0; i < a.length; i++) {
|
|
245
|
+
if (!isEqual$1(a[i], b[i])) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
// Hash table
|
|
252
|
+
var keys = Object.keys(a);
|
|
253
|
+
if (keys.length !== Object.keys(b).length) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
for (var i = 0; i < keys.length; i++) {
|
|
257
|
+
if (!b.hasOwnProperty(keys[i])) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
if (!isEqual$1(a[keys[i]], b[keys[i]])) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/*
|
|
268
|
+
* Helpers
|
|
269
|
+
*/
|
|
270
|
+
var isJsonArray$1 = function (json) { return Array.isArray(json); };
|
|
271
|
+
var isJsonObject$1 = function (json) {
|
|
272
|
+
return typeof json === 'object' && json !== null && !isJsonArray$1(json);
|
|
273
|
+
};
|
|
274
|
+
var typeString$1 = function (json) {
|
|
275
|
+
switch (typeof json) {
|
|
276
|
+
case 'string':
|
|
277
|
+
return 'a string';
|
|
278
|
+
case 'number':
|
|
279
|
+
return 'a number';
|
|
280
|
+
case 'boolean':
|
|
281
|
+
return 'a boolean';
|
|
282
|
+
case 'undefined':
|
|
283
|
+
return 'undefined';
|
|
284
|
+
case 'object':
|
|
285
|
+
if (json instanceof Array) {
|
|
286
|
+
return 'an array';
|
|
287
|
+
}
|
|
288
|
+
else if (json === null) {
|
|
289
|
+
return 'null';
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
return 'an object';
|
|
293
|
+
}
|
|
294
|
+
default:
|
|
295
|
+
return JSON.stringify(json);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var expectedGot$1 = function (expected, got) {
|
|
299
|
+
return "expected " + expected + ", got " + typeString$1(got);
|
|
300
|
+
};
|
|
301
|
+
var printPath$1 = function (paths) {
|
|
302
|
+
return paths.map(function (path) { return (typeof path === 'string' ? "." + path : "[" + path + "]"); }).join('');
|
|
303
|
+
};
|
|
304
|
+
var prependAt$1 = function (newAt, _a) {
|
|
305
|
+
var at = _a.at, rest = __rest$1(_a, ["at"]);
|
|
306
|
+
return (__assign$1({ at: newAt + (at || '') }, rest));
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Decoders transform json objects with unknown structure into known and
|
|
310
|
+
* verified forms. You can create objects of type `Decoder<A>` with either the
|
|
311
|
+
* primitive decoder functions, such as `boolean()` and `string()`, or by
|
|
312
|
+
* applying higher-order decoders to the primitives, such as `array(boolean())`
|
|
313
|
+
* or `dict(string())`.
|
|
314
|
+
*
|
|
315
|
+
* Each of the decoder functions are available both as a static method on
|
|
316
|
+
* `Decoder` and as a function alias -- for example the string decoder is
|
|
317
|
+
* defined at `Decoder.string()`, but is also aliased to `string()`. Using the
|
|
318
|
+
* function aliases exported with the library is recommended.
|
|
319
|
+
*
|
|
320
|
+
* `Decoder` exposes a number of 'run' methods, which all decode json in the
|
|
321
|
+
* same way, but communicate success and failure in different ways. The `map`
|
|
322
|
+
* and `andThen` methods modify decoders without having to call a 'run' method.
|
|
323
|
+
*
|
|
324
|
+
* Alternatively, the main decoder `run()` method returns an object of type
|
|
325
|
+
* `Result<A, DecoderError>`. This library provides a number of helper
|
|
326
|
+
* functions for dealing with the `Result` type, so you can do all the same
|
|
327
|
+
* things with a `Result` as with the decoder methods.
|
|
328
|
+
*/
|
|
329
|
+
var Decoder$1 = /** @class */ (function () {
|
|
330
|
+
/**
|
|
331
|
+
* The Decoder class constructor is kept private to separate the internal
|
|
332
|
+
* `decode` function from the external `run` function. The distinction
|
|
333
|
+
* between the two functions is that `decode` returns a
|
|
334
|
+
* `Partial<DecoderError>` on failure, which contains an unfinished error
|
|
335
|
+
* report. When `run` is called on a decoder, the relevant series of `decode`
|
|
336
|
+
* calls is made, and then on failure the resulting `Partial<DecoderError>`
|
|
337
|
+
* is turned into a `DecoderError` by filling in the missing information.
|
|
338
|
+
*
|
|
339
|
+
* While hiding the constructor may seem restrictive, leveraging the
|
|
340
|
+
* provided decoder combinators and helper functions such as
|
|
341
|
+
* `andThen` and `map` should be enough to build specialized decoders as
|
|
342
|
+
* needed.
|
|
343
|
+
*/
|
|
344
|
+
function Decoder(decode) {
|
|
345
|
+
var _this = this;
|
|
346
|
+
this.decode = decode;
|
|
347
|
+
/**
|
|
348
|
+
* Run the decoder and return a `Result` with either the decoded value or a
|
|
349
|
+
* `DecoderError` containing the json input, the location of the error, and
|
|
350
|
+
* the error message.
|
|
351
|
+
*
|
|
352
|
+
* Examples:
|
|
353
|
+
* ```
|
|
354
|
+
* number().run(12)
|
|
355
|
+
* // => {ok: true, result: 12}
|
|
356
|
+
*
|
|
357
|
+
* string().run(9001)
|
|
358
|
+
* // =>
|
|
359
|
+
* // {
|
|
360
|
+
* // ok: false,
|
|
361
|
+
* // error: {
|
|
362
|
+
* // kind: 'DecoderError',
|
|
363
|
+
* // input: 9001,
|
|
364
|
+
* // at: 'input',
|
|
365
|
+
* // message: 'expected a string, got 9001'
|
|
366
|
+
* // }
|
|
367
|
+
* // }
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
this.run = function (json) {
|
|
371
|
+
return mapError$1(function (error) { return ({
|
|
372
|
+
kind: 'DecoderError',
|
|
373
|
+
input: json,
|
|
374
|
+
at: 'input' + (error.at || ''),
|
|
375
|
+
message: error.message || ''
|
|
376
|
+
}); }, _this.decode(json));
|
|
377
|
+
};
|
|
378
|
+
/**
|
|
379
|
+
* Run the decoder as a `Promise`.
|
|
380
|
+
*/
|
|
381
|
+
this.runPromise = function (json) { return asPromise$1(_this.run(json)); };
|
|
382
|
+
/**
|
|
383
|
+
* Run the decoder and return the value on success, or throw an exception
|
|
384
|
+
* with a formatted error string.
|
|
385
|
+
*/
|
|
386
|
+
this.runWithException = function (json) { return withException$1(_this.run(json)); };
|
|
387
|
+
/**
|
|
388
|
+
* Construct a new decoder that applies a transformation to the decoded
|
|
389
|
+
* result. If the decoder succeeds then `f` will be applied to the value. If
|
|
390
|
+
* it fails the error will propagated through.
|
|
391
|
+
*
|
|
392
|
+
* Example:
|
|
393
|
+
* ```
|
|
394
|
+
* number().map(x => x * 5).run(10)
|
|
395
|
+
* // => {ok: true, result: 50}
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
this.map = function (f) {
|
|
399
|
+
return new Decoder(function (json) { return map$1(f, _this.decode(json)); });
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Chain together a sequence of decoders. The first decoder will run, and
|
|
403
|
+
* then the function will determine what decoder to run second. If the result
|
|
404
|
+
* of the first decoder succeeds then `f` will be applied to the decoded
|
|
405
|
+
* value. If it fails the error will propagate through.
|
|
406
|
+
*
|
|
407
|
+
* This is a very powerful method -- it can act as both the `map` and `where`
|
|
408
|
+
* methods, can improve error messages for edge cases, and can be used to
|
|
409
|
+
* make a decoder for custom types.
|
|
410
|
+
*
|
|
411
|
+
* Example of adding an error message:
|
|
412
|
+
* ```
|
|
413
|
+
* const versionDecoder = valueAt(['version'], number());
|
|
414
|
+
* const infoDecoder3 = object({a: boolean()});
|
|
415
|
+
*
|
|
416
|
+
* const decoder = versionDecoder.andThen(version => {
|
|
417
|
+
* switch (version) {
|
|
418
|
+
* case 3:
|
|
419
|
+
* return infoDecoder3;
|
|
420
|
+
* default:
|
|
421
|
+
* return fail(`Unable to decode info, version ${version} is not supported.`);
|
|
422
|
+
* }
|
|
423
|
+
* });
|
|
424
|
+
*
|
|
425
|
+
* decoder.run({version: 3, a: true})
|
|
426
|
+
* // => {ok: true, result: {a: true}}
|
|
427
|
+
*
|
|
428
|
+
* decoder.run({version: 5, x: 'abc'})
|
|
429
|
+
* // =>
|
|
430
|
+
* // {
|
|
431
|
+
* // ok: false,
|
|
432
|
+
* // error: {... message: 'Unable to decode info, version 5 is not supported.'}
|
|
433
|
+
* // }
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* Example of decoding a custom type:
|
|
437
|
+
* ```
|
|
438
|
+
* // nominal type for arrays with a length of at least one
|
|
439
|
+
* type NonEmptyArray<T> = T[] & { __nonEmptyArrayBrand__: void };
|
|
440
|
+
*
|
|
441
|
+
* const nonEmptyArrayDecoder = <T>(values: Decoder<T>): Decoder<NonEmptyArray<T>> =>
|
|
442
|
+
* array(values).andThen(arr =>
|
|
443
|
+
* arr.length > 0
|
|
444
|
+
* ? succeed(createNonEmptyArray(arr))
|
|
445
|
+
* : fail(`expected a non-empty array, got an empty array`)
|
|
446
|
+
* );
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
449
|
+
this.andThen = function (f) {
|
|
450
|
+
return new Decoder(function (json) {
|
|
451
|
+
return andThen$1(function (value) { return f(value).decode(json); }, _this.decode(json));
|
|
452
|
+
});
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* Add constraints to a decoder _without_ changing the resulting type. The
|
|
456
|
+
* `test` argument is a predicate function which returns true for valid
|
|
457
|
+
* inputs. When `test` fails on an input, the decoder fails with the given
|
|
458
|
+
* `errorMessage`.
|
|
459
|
+
*
|
|
460
|
+
* ```
|
|
461
|
+
* const chars = (length: number): Decoder<string> =>
|
|
462
|
+
* string().where(
|
|
463
|
+
* (s: string) => s.length === length,
|
|
464
|
+
* `expected a string of length ${length}`
|
|
465
|
+
* );
|
|
466
|
+
*
|
|
467
|
+
* chars(5).run('12345')
|
|
468
|
+
* // => {ok: true, result: '12345'}
|
|
469
|
+
*
|
|
470
|
+
* chars(2).run('HELLO')
|
|
471
|
+
* // => {ok: false, error: {... message: 'expected a string of length 2'}}
|
|
472
|
+
*
|
|
473
|
+
* chars(12).run(true)
|
|
474
|
+
* // => {ok: false, error: {... message: 'expected a string, got a boolean'}}
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
this.where = function (test, errorMessage) {
|
|
478
|
+
return _this.andThen(function (value) { return (test(value) ? Decoder.succeed(value) : Decoder.fail(errorMessage)); });
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Decoder primitive that validates strings, and fails on all other input.
|
|
483
|
+
*/
|
|
484
|
+
Decoder.string = function () {
|
|
485
|
+
return new Decoder(function (json) {
|
|
486
|
+
return typeof json === 'string'
|
|
487
|
+
? ok$1(json)
|
|
488
|
+
: err$1({ message: expectedGot$1('a string', json) });
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
/**
|
|
492
|
+
* Decoder primitive that validates numbers, and fails on all other input.
|
|
493
|
+
*/
|
|
494
|
+
Decoder.number = function () {
|
|
495
|
+
return new Decoder(function (json) {
|
|
496
|
+
return typeof json === 'number'
|
|
497
|
+
? ok$1(json)
|
|
498
|
+
: err$1({ message: expectedGot$1('a number', json) });
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Decoder primitive that validates booleans, and fails on all other input.
|
|
503
|
+
*/
|
|
504
|
+
Decoder.boolean = function () {
|
|
505
|
+
return new Decoder(function (json) {
|
|
506
|
+
return typeof json === 'boolean'
|
|
507
|
+
? ok$1(json)
|
|
508
|
+
: err$1({ message: expectedGot$1('a boolean', json) });
|
|
509
|
+
});
|
|
510
|
+
};
|
|
511
|
+
Decoder.constant = function (value) {
|
|
512
|
+
return new Decoder(function (json) {
|
|
513
|
+
return isEqual$1(json, value)
|
|
514
|
+
? ok$1(value)
|
|
515
|
+
: err$1({ message: "expected " + JSON.stringify(value) + ", got " + JSON.stringify(json) });
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
Decoder.object = function (decoders) {
|
|
519
|
+
return new Decoder(function (json) {
|
|
520
|
+
if (isJsonObject$1(json) && decoders) {
|
|
521
|
+
var obj = {};
|
|
522
|
+
for (var key in decoders) {
|
|
523
|
+
if (decoders.hasOwnProperty(key)) {
|
|
524
|
+
var r = decoders[key].decode(json[key]);
|
|
525
|
+
if (r.ok === true) {
|
|
526
|
+
// tslint:disable-next-line:strict-type-predicates
|
|
527
|
+
if (r.result !== undefined) {
|
|
528
|
+
obj[key] = r.result;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
else if (json[key] === undefined) {
|
|
532
|
+
return err$1({ message: "the key '" + key + "' is required but was not present" });
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
return err$1(prependAt$1("." + key, r.error));
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return ok$1(obj);
|
|
540
|
+
}
|
|
541
|
+
else if (isJsonObject$1(json)) {
|
|
542
|
+
return ok$1(json);
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
return err$1({ message: expectedGot$1('an object', json) });
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
};
|
|
549
|
+
Decoder.array = function (decoder) {
|
|
550
|
+
return new Decoder(function (json) {
|
|
551
|
+
if (isJsonArray$1(json) && decoder) {
|
|
552
|
+
var decodeValue_1 = function (v, i) {
|
|
553
|
+
return mapError$1(function (err$$1) { return prependAt$1("[" + i + "]", err$$1); }, decoder.decode(v));
|
|
554
|
+
};
|
|
555
|
+
return json.reduce(function (acc, v, i) {
|
|
556
|
+
return map2$1(function (arr, result) { return arr.concat([result]); }, acc, decodeValue_1(v, i));
|
|
557
|
+
}, ok$1([]));
|
|
558
|
+
}
|
|
559
|
+
else if (isJsonArray$1(json)) {
|
|
560
|
+
return ok$1(json);
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
return err$1({ message: expectedGot$1('an array', json) });
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
Decoder.tuple = function (decoders) {
|
|
568
|
+
return new Decoder(function (json) {
|
|
569
|
+
if (isJsonArray$1(json)) {
|
|
570
|
+
if (json.length !== decoders.length) {
|
|
571
|
+
return err$1({
|
|
572
|
+
message: "expected a tuple of length " + decoders.length + ", got one of length " + json.length
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
var result = [];
|
|
576
|
+
for (var i = 0; i < decoders.length; i++) {
|
|
577
|
+
var nth = decoders[i].decode(json[i]);
|
|
578
|
+
if (nth.ok) {
|
|
579
|
+
result[i] = nth.result;
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
return err$1(prependAt$1("[" + i + "]", nth.error));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return ok$1(result);
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
return err$1({ message: expectedGot$1("a tuple of length " + decoders.length, json) });
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
Decoder.union = function (ad, bd) {
|
|
593
|
+
var decoders = [];
|
|
594
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
595
|
+
decoders[_i - 2] = arguments[_i];
|
|
596
|
+
}
|
|
597
|
+
return Decoder.oneOf.apply(Decoder, [ad, bd].concat(decoders));
|
|
598
|
+
};
|
|
599
|
+
Decoder.intersection = function (ad, bd) {
|
|
600
|
+
var ds = [];
|
|
601
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
602
|
+
ds[_i - 2] = arguments[_i];
|
|
603
|
+
}
|
|
604
|
+
return new Decoder(function (json) {
|
|
605
|
+
return [ad, bd].concat(ds).reduce(function (acc, decoder) { return map2$1(Object.assign, acc, decoder.decode(json)); }, ok$1({}));
|
|
606
|
+
});
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* Escape hatch to bypass validation. Always succeeds and types the result as
|
|
610
|
+
* `any`. Useful for defining decoders incrementally, particularly for
|
|
611
|
+
* complex objects.
|
|
612
|
+
*
|
|
613
|
+
* Example:
|
|
614
|
+
* ```
|
|
615
|
+
* interface User {
|
|
616
|
+
* name: string;
|
|
617
|
+
* complexUserData: ComplexType;
|
|
618
|
+
* }
|
|
619
|
+
*
|
|
620
|
+
* const userDecoder: Decoder<User> = object({
|
|
621
|
+
* name: string(),
|
|
622
|
+
* complexUserData: anyJson()
|
|
623
|
+
* });
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
Decoder.anyJson = function () { return new Decoder(function (json) { return ok$1(json); }); };
|
|
627
|
+
/**
|
|
628
|
+
* Decoder identity function which always succeeds and types the result as
|
|
629
|
+
* `unknown`.
|
|
630
|
+
*/
|
|
631
|
+
Decoder.unknownJson = function () {
|
|
632
|
+
return new Decoder(function (json) { return ok$1(json); });
|
|
633
|
+
};
|
|
634
|
+
/**
|
|
635
|
+
* Decoder for json objects where the keys are unknown strings, but the values
|
|
636
|
+
* should all be of the same type.
|
|
637
|
+
*
|
|
638
|
+
* Example:
|
|
639
|
+
* ```
|
|
640
|
+
* dict(number()).run({chocolate: 12, vanilla: 10, mint: 37});
|
|
641
|
+
* // => {ok: true, result: {chocolate: 12, vanilla: 10, mint: 37}}
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
Decoder.dict = function (decoder) {
|
|
645
|
+
return new Decoder(function (json) {
|
|
646
|
+
if (isJsonObject$1(json)) {
|
|
647
|
+
var obj = {};
|
|
648
|
+
for (var key in json) {
|
|
649
|
+
if (json.hasOwnProperty(key)) {
|
|
650
|
+
var r = decoder.decode(json[key]);
|
|
651
|
+
if (r.ok === true) {
|
|
652
|
+
obj[key] = r.result;
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
return err$1(prependAt$1("." + key, r.error));
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return ok$1(obj);
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
return err$1({ message: expectedGot$1('an object', json) });
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
};
|
|
666
|
+
/**
|
|
667
|
+
* Decoder for values that may be `undefined`. This is primarily helpful for
|
|
668
|
+
* decoding interfaces with optional fields.
|
|
669
|
+
*
|
|
670
|
+
* Example:
|
|
671
|
+
* ```
|
|
672
|
+
* interface User {
|
|
673
|
+
* id: number;
|
|
674
|
+
* isOwner?: boolean;
|
|
675
|
+
* }
|
|
676
|
+
*
|
|
677
|
+
* const decoder: Decoder<User> = object({
|
|
678
|
+
* id: number(),
|
|
679
|
+
* isOwner: optional(boolean())
|
|
680
|
+
* });
|
|
681
|
+
* ```
|
|
682
|
+
*/
|
|
683
|
+
Decoder.optional = function (decoder) {
|
|
684
|
+
return new Decoder(function (json) { return (json === undefined || json === null ? ok$1(undefined) : decoder.decode(json)); });
|
|
685
|
+
};
|
|
686
|
+
/**
|
|
687
|
+
* Decoder that attempts to run each decoder in `decoders` and either succeeds
|
|
688
|
+
* with the first successful decoder, or fails after all decoders have failed.
|
|
689
|
+
*
|
|
690
|
+
* Note that `oneOf` expects the decoders to all have the same return type,
|
|
691
|
+
* while `union` creates a decoder for the union type of all the input
|
|
692
|
+
* decoders.
|
|
693
|
+
*
|
|
694
|
+
* Examples:
|
|
695
|
+
* ```
|
|
696
|
+
* oneOf(string(), number().map(String))
|
|
697
|
+
* oneOf(constant('start'), constant('stop'), succeed('unknown'))
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
Decoder.oneOf = function () {
|
|
701
|
+
var decoders = [];
|
|
702
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
703
|
+
decoders[_i] = arguments[_i];
|
|
704
|
+
}
|
|
705
|
+
return new Decoder(function (json) {
|
|
706
|
+
var errors = [];
|
|
707
|
+
for (var i = 0; i < decoders.length; i++) {
|
|
708
|
+
var r = decoders[i].decode(json);
|
|
709
|
+
if (r.ok === true) {
|
|
710
|
+
return r;
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
errors[i] = r.error;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
var errorsList = errors
|
|
717
|
+
.map(function (error) { return "at error" + (error.at || '') + ": " + error.message; })
|
|
718
|
+
.join('", "');
|
|
719
|
+
return err$1({
|
|
720
|
+
message: "expected a value matching one of the decoders, got the errors [\"" + errorsList + "\"]"
|
|
721
|
+
});
|
|
722
|
+
});
|
|
723
|
+
};
|
|
724
|
+
/**
|
|
725
|
+
* Decoder that always succeeds with either the decoded value, or a fallback
|
|
726
|
+
* default value.
|
|
727
|
+
*/
|
|
728
|
+
Decoder.withDefault = function (defaultValue, decoder) {
|
|
729
|
+
return new Decoder(function (json) {
|
|
730
|
+
return ok$1(withDefault$1(defaultValue, decoder.decode(json)));
|
|
731
|
+
});
|
|
732
|
+
};
|
|
733
|
+
/**
|
|
734
|
+
* Decoder that pulls a specific field out of a json structure, instead of
|
|
735
|
+
* decoding and returning the full structure. The `paths` array describes the
|
|
736
|
+
* object keys and array indices to traverse, so that values can be pulled out
|
|
737
|
+
* of a nested structure.
|
|
738
|
+
*
|
|
739
|
+
* Example:
|
|
740
|
+
* ```
|
|
741
|
+
* const decoder = valueAt(['a', 'b', 0], string());
|
|
742
|
+
*
|
|
743
|
+
* decoder.run({a: {b: ['surprise!']}})
|
|
744
|
+
* // => {ok: true, result: 'surprise!'}
|
|
745
|
+
*
|
|
746
|
+
* decoder.run({a: {x: 'cats'}})
|
|
747
|
+
* // => {ok: false, error: {... at: 'input.a.b[0]' message: 'path does not exist'}}
|
|
748
|
+
* ```
|
|
749
|
+
*
|
|
750
|
+
* Note that the `decoder` is ran on the value found at the last key in the
|
|
751
|
+
* path, even if the last key is not found. This allows the `optional`
|
|
752
|
+
* decoder to succeed when appropriate.
|
|
753
|
+
* ```
|
|
754
|
+
* const optionalDecoder = valueAt(['a', 'b', 'c'], optional(string()));
|
|
755
|
+
*
|
|
756
|
+
* optionalDecoder.run({a: {b: {c: 'surprise!'}}})
|
|
757
|
+
* // => {ok: true, result: 'surprise!'}
|
|
758
|
+
*
|
|
759
|
+
* optionalDecoder.run({a: {b: 'cats'}})
|
|
760
|
+
* // => {ok: false, error: {... at: 'input.a.b.c' message: 'expected an object, got "cats"'}
|
|
761
|
+
*
|
|
762
|
+
* optionalDecoder.run({a: {b: {z: 1}}})
|
|
763
|
+
* // => {ok: true, result: undefined}
|
|
764
|
+
* ```
|
|
765
|
+
*/
|
|
766
|
+
Decoder.valueAt = function (paths, decoder) {
|
|
767
|
+
return new Decoder(function (json) {
|
|
768
|
+
var jsonAtPath = json;
|
|
769
|
+
for (var i = 0; i < paths.length; i++) {
|
|
770
|
+
if (jsonAtPath === undefined) {
|
|
771
|
+
return err$1({
|
|
772
|
+
at: printPath$1(paths.slice(0, i + 1)),
|
|
773
|
+
message: 'path does not exist'
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
else if (typeof paths[i] === 'string' && !isJsonObject$1(jsonAtPath)) {
|
|
777
|
+
return err$1({
|
|
778
|
+
at: printPath$1(paths.slice(0, i + 1)),
|
|
779
|
+
message: expectedGot$1('an object', jsonAtPath)
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
else if (typeof paths[i] === 'number' && !isJsonArray$1(jsonAtPath)) {
|
|
783
|
+
return err$1({
|
|
784
|
+
at: printPath$1(paths.slice(0, i + 1)),
|
|
785
|
+
message: expectedGot$1('an array', jsonAtPath)
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
jsonAtPath = jsonAtPath[paths[i]];
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return mapError$1(function (error) {
|
|
793
|
+
return jsonAtPath === undefined
|
|
794
|
+
? { at: printPath$1(paths), message: 'path does not exist' }
|
|
795
|
+
: prependAt$1(printPath$1(paths), error);
|
|
796
|
+
}, decoder.decode(jsonAtPath));
|
|
797
|
+
});
|
|
798
|
+
};
|
|
799
|
+
/**
|
|
800
|
+
* Decoder that ignores the input json and always succeeds with `fixedValue`.
|
|
801
|
+
*/
|
|
802
|
+
Decoder.succeed = function (fixedValue) {
|
|
803
|
+
return new Decoder(function (json) { return ok$1(fixedValue); });
|
|
804
|
+
};
|
|
805
|
+
/**
|
|
806
|
+
* Decoder that ignores the input json and always fails with `errorMessage`.
|
|
807
|
+
*/
|
|
808
|
+
Decoder.fail = function (errorMessage) {
|
|
809
|
+
return new Decoder(function (json) { return err$1({ message: errorMessage }); });
|
|
810
|
+
};
|
|
811
|
+
/**
|
|
812
|
+
* Decoder that allows for validating recursive data structures. Unlike with
|
|
813
|
+
* functions, decoders assigned to variables can't reference themselves
|
|
814
|
+
* before they are fully defined. We can avoid prematurely referencing the
|
|
815
|
+
* decoder by wrapping it in a function that won't be called until use, at
|
|
816
|
+
* which point the decoder has been defined.
|
|
817
|
+
*
|
|
818
|
+
* Example:
|
|
819
|
+
* ```
|
|
820
|
+
* interface Comment {
|
|
821
|
+
* msg: string;
|
|
822
|
+
* replies: Comment[];
|
|
823
|
+
* }
|
|
824
|
+
*
|
|
825
|
+
* const decoder: Decoder<Comment> = object({
|
|
826
|
+
* msg: string(),
|
|
827
|
+
* replies: lazy(() => array(decoder))
|
|
828
|
+
* });
|
|
829
|
+
* ```
|
|
830
|
+
*/
|
|
831
|
+
Decoder.lazy = function (mkDecoder) {
|
|
832
|
+
return new Decoder(function (json) { return mkDecoder().decode(json); });
|
|
833
|
+
};
|
|
834
|
+
return Decoder;
|
|
835
|
+
}());
|
|
836
|
+
|
|
837
|
+
/* tslint:disable:variable-name */
|
|
838
|
+
/** See `Decoder.string` */
|
|
839
|
+
var string$1 = Decoder$1.string;
|
|
840
|
+
/** See `Decoder.number` */
|
|
841
|
+
var number$1 = Decoder$1.number;
|
|
842
|
+
/** See `Decoder.boolean` */
|
|
843
|
+
var boolean = Decoder$1.boolean;
|
|
844
|
+
/** See `Decoder.anyJson` */
|
|
845
|
+
var anyJson$1 = Decoder$1.anyJson;
|
|
846
|
+
/** See `Decoder.unknownJson` */
|
|
847
|
+
Decoder$1.unknownJson;
|
|
848
|
+
/** See `Decoder.constant` */
|
|
849
|
+
var constant$1 = Decoder$1.constant;
|
|
850
|
+
/** See `Decoder.object` */
|
|
851
|
+
var object$1 = Decoder$1.object;
|
|
852
|
+
/** See `Decoder.array` */
|
|
853
|
+
var array$1 = Decoder$1.array;
|
|
854
|
+
/** See `Decoder.tuple` */
|
|
855
|
+
Decoder$1.tuple;
|
|
856
|
+
/** See `Decoder.dict` */
|
|
857
|
+
var dict = Decoder$1.dict;
|
|
858
|
+
/** See `Decoder.optional` */
|
|
859
|
+
var optional$1 = Decoder$1.optional;
|
|
860
|
+
/** See `Decoder.oneOf` */
|
|
861
|
+
var oneOf$1 = Decoder$1.oneOf;
|
|
862
|
+
/** See `Decoder.union` */
|
|
863
|
+
Decoder$1.union;
|
|
864
|
+
/** See `Decoder.intersection` */
|
|
865
|
+
Decoder$1.intersection;
|
|
866
|
+
/** See `Decoder.withDefault` */
|
|
867
|
+
Decoder$1.withDefault;
|
|
868
|
+
/** See `Decoder.valueAt` */
|
|
869
|
+
Decoder$1.valueAt;
|
|
870
|
+
/** See `Decoder.succeed` */
|
|
871
|
+
Decoder$1.succeed;
|
|
872
|
+
/** See `Decoder.fail` */
|
|
873
|
+
Decoder$1.fail;
|
|
874
|
+
/** See `Decoder.lazy` */
|
|
875
|
+
Decoder$1.lazy;
|
|
876
|
+
|
|
877
|
+
const nonEmptyStringDecoder$1 = string$1().where((s) => s.length > 0, "Expected a non-empty string");
|
|
878
|
+
const nonNegativeNumberDecoder = number$1().where((num) => num >= 0, "Expected a non-negative number");
|
|
879
|
+
|
|
880
|
+
const intentDefinitionDecoder = object$1({
|
|
881
|
+
name: nonEmptyStringDecoder$1,
|
|
882
|
+
displayName: optional$1(string$1()),
|
|
883
|
+
contexts: optional$1(array$1(string$1())),
|
|
884
|
+
customConfig: optional$1(object$1())
|
|
885
|
+
});
|
|
886
|
+
const v2TypeDecoder = oneOf$1(constant$1("web"), constant$1("native"), constant$1("citrix"), constant$1("onlineNative"), constant$1("other"));
|
|
887
|
+
const v2DetailsDecoder = object$1({
|
|
888
|
+
url: nonEmptyStringDecoder$1
|
|
889
|
+
});
|
|
890
|
+
const v2IconDecoder = object$1({
|
|
891
|
+
src: nonEmptyStringDecoder$1,
|
|
892
|
+
size: optional$1(nonEmptyStringDecoder$1),
|
|
893
|
+
type: optional$1(nonEmptyStringDecoder$1)
|
|
894
|
+
});
|
|
895
|
+
const v2ScreenshotDecoder = object$1({
|
|
896
|
+
src: nonEmptyStringDecoder$1,
|
|
897
|
+
size: optional$1(nonEmptyStringDecoder$1),
|
|
898
|
+
type: optional$1(nonEmptyStringDecoder$1),
|
|
899
|
+
label: optional$1(nonEmptyStringDecoder$1)
|
|
900
|
+
});
|
|
901
|
+
const v2ListensForIntentDecoder = object$1({
|
|
902
|
+
contexts: array$1(nonEmptyStringDecoder$1),
|
|
903
|
+
displayName: optional$1(nonEmptyStringDecoder$1),
|
|
904
|
+
resultType: optional$1(nonEmptyStringDecoder$1),
|
|
905
|
+
customConfig: optional$1(anyJson$1())
|
|
906
|
+
});
|
|
907
|
+
const v2IntentsDecoder = object$1({
|
|
908
|
+
listensFor: optional$1(dict(v2ListensForIntentDecoder)),
|
|
909
|
+
raises: optional$1(dict(array$1(nonEmptyStringDecoder$1)))
|
|
910
|
+
});
|
|
911
|
+
const v2UserChannelDecoder = object$1({
|
|
912
|
+
broadcasts: optional$1(array$1(nonEmptyStringDecoder$1)),
|
|
913
|
+
listensFor: optional$1(array$1(nonEmptyStringDecoder$1))
|
|
914
|
+
});
|
|
915
|
+
const v2AppChannelDecoder = object$1({
|
|
916
|
+
name: nonEmptyStringDecoder$1,
|
|
917
|
+
description: optional$1(nonEmptyStringDecoder$1),
|
|
918
|
+
broadcasts: optional$1(array$1(nonEmptyStringDecoder$1)),
|
|
919
|
+
listensFor: optional$1(array$1(nonEmptyStringDecoder$1))
|
|
920
|
+
});
|
|
921
|
+
const v2InteropDecoder = object$1({
|
|
922
|
+
intents: optional$1(v2IntentsDecoder),
|
|
923
|
+
userChannels: optional$1(v2UserChannelDecoder),
|
|
924
|
+
appChannels: optional$1(array$1(v2AppChannelDecoder))
|
|
925
|
+
});
|
|
926
|
+
const glue42ApplicationDetailsDecoder = object$1({
|
|
927
|
+
url: nonEmptyStringDecoder$1,
|
|
928
|
+
top: optional$1(number$1()),
|
|
929
|
+
left: optional$1(number$1()),
|
|
930
|
+
width: optional$1(nonNegativeNumberDecoder),
|
|
931
|
+
height: optional$1(nonNegativeNumberDecoder)
|
|
932
|
+
});
|
|
933
|
+
const glue42HostManifestsBrowserDecoder = object$1({
|
|
934
|
+
name: optional$1(nonEmptyStringDecoder$1),
|
|
935
|
+
type: optional$1(nonEmptyStringDecoder$1.where((s) => s === "window", "Expected a value of window")),
|
|
936
|
+
title: optional$1(nonEmptyStringDecoder$1),
|
|
937
|
+
version: optional$1(nonEmptyStringDecoder$1),
|
|
938
|
+
customProperties: optional$1(anyJson$1()),
|
|
939
|
+
icon: optional$1(string$1()),
|
|
940
|
+
caption: optional$1(string$1()),
|
|
941
|
+
details: optional$1(glue42ApplicationDetailsDecoder),
|
|
942
|
+
intents: optional$1(array$1(intentDefinitionDecoder)),
|
|
943
|
+
hidden: optional$1(boolean())
|
|
944
|
+
});
|
|
945
|
+
const hostManifestsBrowserDecoder = oneOf$1(object$1({
|
|
946
|
+
"Glue42": oneOf$1(glue42HostManifestsBrowserDecoder, anyJson$1())
|
|
947
|
+
}), anyJson$1());
|
|
948
|
+
const v1DefinitionDecoder = object$1({
|
|
949
|
+
name: nonEmptyStringDecoder$1,
|
|
950
|
+
appId: nonEmptyStringDecoder$1,
|
|
951
|
+
title: optional$1(nonEmptyStringDecoder$1),
|
|
952
|
+
version: optional$1(nonEmptyStringDecoder$1),
|
|
953
|
+
manifest: nonEmptyStringDecoder$1,
|
|
954
|
+
manifestType: nonEmptyStringDecoder$1,
|
|
955
|
+
tooltip: optional$1(nonEmptyStringDecoder$1),
|
|
956
|
+
description: optional$1(nonEmptyStringDecoder$1),
|
|
957
|
+
contactEmail: optional$1(nonEmptyStringDecoder$1),
|
|
958
|
+
supportEmail: optional$1(nonEmptyStringDecoder$1),
|
|
959
|
+
publisher: optional$1(nonEmptyStringDecoder$1),
|
|
960
|
+
images: optional$1(array$1(object$1({ url: optional$1(nonEmptyStringDecoder$1) }))),
|
|
961
|
+
icons: optional$1(array$1(object$1({ icon: optional$1(nonEmptyStringDecoder$1) }))),
|
|
962
|
+
customConfig: anyJson$1(),
|
|
963
|
+
intents: optional$1(array$1(intentDefinitionDecoder))
|
|
964
|
+
});
|
|
965
|
+
const v2LocalizedDefinitionDecoder = object$1({
|
|
966
|
+
appId: optional$1(nonEmptyStringDecoder$1),
|
|
967
|
+
name: optional$1(nonEmptyStringDecoder$1),
|
|
968
|
+
details: optional$1(v2DetailsDecoder),
|
|
969
|
+
version: optional$1(nonEmptyStringDecoder$1),
|
|
970
|
+
title: optional$1(nonEmptyStringDecoder$1),
|
|
971
|
+
tooltip: optional$1(nonEmptyStringDecoder$1),
|
|
972
|
+
lang: optional$1(nonEmptyStringDecoder$1),
|
|
973
|
+
description: optional$1(nonEmptyStringDecoder$1),
|
|
974
|
+
categories: optional$1(array$1(nonEmptyStringDecoder$1)),
|
|
975
|
+
icons: optional$1(array$1(v2IconDecoder)),
|
|
976
|
+
screenshots: optional$1(array$1(v2ScreenshotDecoder)),
|
|
977
|
+
contactEmail: optional$1(nonEmptyStringDecoder$1),
|
|
978
|
+
supportEmail: optional$1(nonEmptyStringDecoder$1),
|
|
979
|
+
moreInfo: optional$1(nonEmptyStringDecoder$1),
|
|
980
|
+
publisher: optional$1(nonEmptyStringDecoder$1),
|
|
981
|
+
customConfig: optional$1(array$1(anyJson$1())),
|
|
982
|
+
hostManifests: optional$1(hostManifestsBrowserDecoder),
|
|
983
|
+
interop: optional$1(v2InteropDecoder)
|
|
984
|
+
});
|
|
985
|
+
const v2DefinitionDecoder = object$1({
|
|
986
|
+
appId: nonEmptyStringDecoder$1,
|
|
987
|
+
name: nonEmptyStringDecoder$1,
|
|
988
|
+
type: v2TypeDecoder,
|
|
989
|
+
details: v2DetailsDecoder,
|
|
990
|
+
version: optional$1(nonEmptyStringDecoder$1),
|
|
991
|
+
title: optional$1(nonEmptyStringDecoder$1),
|
|
992
|
+
tooltip: optional$1(nonEmptyStringDecoder$1),
|
|
993
|
+
lang: optional$1(nonEmptyStringDecoder$1),
|
|
994
|
+
description: optional$1(nonEmptyStringDecoder$1),
|
|
995
|
+
categories: optional$1(array$1(nonEmptyStringDecoder$1)),
|
|
996
|
+
icons: optional$1(array$1(v2IconDecoder)),
|
|
997
|
+
screenshots: optional$1(array$1(v2ScreenshotDecoder)),
|
|
998
|
+
contactEmail: optional$1(nonEmptyStringDecoder$1),
|
|
999
|
+
supportEmail: optional$1(nonEmptyStringDecoder$1),
|
|
1000
|
+
moreInfo: optional$1(nonEmptyStringDecoder$1),
|
|
1001
|
+
publisher: optional$1(nonEmptyStringDecoder$1),
|
|
1002
|
+
customConfig: optional$1(array$1(anyJson$1())),
|
|
1003
|
+
hostManifests: optional$1(hostManifestsBrowserDecoder),
|
|
1004
|
+
interop: optional$1(v2InteropDecoder),
|
|
1005
|
+
localizedVersions: optional$1(dict(v2LocalizedDefinitionDecoder))
|
|
1006
|
+
});
|
|
1007
|
+
const allDefinitionsDecoder = oneOf$1(v1DefinitionDecoder, v2DefinitionDecoder);
|
|
1008
|
+
|
|
1009
|
+
const parseDecoderErrorToStringMessage = (error) => {
|
|
1010
|
+
return `${error.kind} at ${error.at}: ${JSON.stringify(error.input)}. Reason - ${error.message}`;
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
class FDC3Service {
|
|
1014
|
+
constructor() {
|
|
1015
|
+
this.fdc3ToDesktopDefinitionType = {
|
|
1016
|
+
web: "window",
|
|
1017
|
+
native: "exe",
|
|
1018
|
+
citrix: "citrix",
|
|
1019
|
+
onlineNative: "clickonce",
|
|
1020
|
+
other: "window"
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
toApi() {
|
|
1024
|
+
return {
|
|
1025
|
+
isFdc3Definition: this.isFdc3Definition.bind(this),
|
|
1026
|
+
parseToBrowserBaseAppData: this.parseToBrowserBaseAppData.bind(this),
|
|
1027
|
+
parseToDesktopAppConfig: this.parseToDesktopAppConfig.bind(this)
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
isFdc3Definition(definition) {
|
|
1031
|
+
const decodeRes = allDefinitionsDecoder.run(definition);
|
|
1032
|
+
if (!decodeRes.ok) {
|
|
1033
|
+
return { isFdc3: false, reason: parseDecoderErrorToStringMessage(decodeRes.error) };
|
|
1034
|
+
}
|
|
1035
|
+
if (definition.appId && definition.details) {
|
|
1036
|
+
return { isFdc3: true, version: "2.0" };
|
|
1037
|
+
}
|
|
1038
|
+
if (definition.manifest) {
|
|
1039
|
+
return { isFdc3: true, version: "1.2" };
|
|
1040
|
+
}
|
|
1041
|
+
return { isFdc3: false, reason: "The passed definition is not FDC3" };
|
|
1042
|
+
}
|
|
1043
|
+
parseToBrowserBaseAppData(definition) {
|
|
1044
|
+
var _a;
|
|
1045
|
+
const { isFdc3, version } = this.isFdc3Definition(definition);
|
|
1046
|
+
if (!isFdc3) {
|
|
1047
|
+
throw new Error("The passed definition is not FDC3");
|
|
1048
|
+
}
|
|
1049
|
+
const decodeRes = allDefinitionsDecoder.run(definition);
|
|
1050
|
+
if (!decodeRes.ok) {
|
|
1051
|
+
throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(decodeRes.error)}`);
|
|
1052
|
+
}
|
|
1053
|
+
const userProperties = this.getUserPropertiesFromDefinition(definition, version);
|
|
1054
|
+
const createOptions = { url: this.getUrl(definition, version) };
|
|
1055
|
+
let baseApplicationData = {
|
|
1056
|
+
name: definition.appId,
|
|
1057
|
+
type: "window",
|
|
1058
|
+
createOptions,
|
|
1059
|
+
userProperties: Object.assign(Object.assign({}, userProperties), { intents: version === "1.2"
|
|
1060
|
+
? userProperties.intents
|
|
1061
|
+
: this.getIntentsFromV2AppDefinition(definition), details: createOptions }),
|
|
1062
|
+
title: definition.title,
|
|
1063
|
+
version: definition.version,
|
|
1064
|
+
icon: this.getIconFromDefinition(definition, version),
|
|
1065
|
+
caption: definition.description,
|
|
1066
|
+
fdc3: version === "2.0" ? Object.assign(Object.assign({}, definition), { definitionVersion: "2.0" }) : undefined,
|
|
1067
|
+
};
|
|
1068
|
+
if ((_a = definition.hostManifests) === null || _a === void 0 ? void 0 : _a["Glue42"]) {
|
|
1069
|
+
const decodeRes = glue42HostManifestsBrowserDecoder.run(definition.hostManifests["Glue42"]);
|
|
1070
|
+
if (!decodeRes.ok) {
|
|
1071
|
+
throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(decodeRes.error)}`);
|
|
1072
|
+
}
|
|
1073
|
+
if (!Object.keys(decodeRes.result).length) {
|
|
1074
|
+
throw new Error("Invalid 'hostManifests['Glue42]' key");
|
|
1075
|
+
}
|
|
1076
|
+
baseApplicationData = this.mergeBaseAppDataWithGlueManifest(baseApplicationData, decodeRes.result);
|
|
1077
|
+
}
|
|
1078
|
+
return baseApplicationData;
|
|
1079
|
+
}
|
|
1080
|
+
parseToDesktopAppConfig(definition) {
|
|
1081
|
+
var _a, _b, _c;
|
|
1082
|
+
const { isFdc3, version } = this.isFdc3Definition(definition);
|
|
1083
|
+
if (!isFdc3) {
|
|
1084
|
+
throw new Error("The passed definition is not FDC3");
|
|
1085
|
+
}
|
|
1086
|
+
const decodeRes = allDefinitionsDecoder.run(definition);
|
|
1087
|
+
if (!decodeRes.ok) {
|
|
1088
|
+
throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(decodeRes.error)}`);
|
|
1089
|
+
}
|
|
1090
|
+
if (version === "1.2") {
|
|
1091
|
+
const fdc3v1Definition = definition;
|
|
1092
|
+
return {
|
|
1093
|
+
name: fdc3v1Definition.appId,
|
|
1094
|
+
type: "window",
|
|
1095
|
+
details: {
|
|
1096
|
+
url: this.getUrl(definition, version)
|
|
1097
|
+
},
|
|
1098
|
+
version: fdc3v1Definition.version,
|
|
1099
|
+
title: fdc3v1Definition.title,
|
|
1100
|
+
tooltip: fdc3v1Definition.tooltip,
|
|
1101
|
+
caption: fdc3v1Definition.description,
|
|
1102
|
+
icon: (_a = fdc3v1Definition.icons) === null || _a === void 0 ? void 0 : _a[0].icon,
|
|
1103
|
+
intents: fdc3v1Definition.intents,
|
|
1104
|
+
customProperties: {
|
|
1105
|
+
manifestType: fdc3v1Definition.manifestType,
|
|
1106
|
+
images: fdc3v1Definition.images,
|
|
1107
|
+
contactEmail: fdc3v1Definition.contactEmail,
|
|
1108
|
+
supportEmail: fdc3v1Definition.supportEmail,
|
|
1109
|
+
publisher: fdc3v1Definition.publisher,
|
|
1110
|
+
icons: fdc3v1Definition.icons,
|
|
1111
|
+
customConfig: fdc3v1Definition.customConfig
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
const fdc3v2Definition = definition;
|
|
1116
|
+
let desktopDefinition = {
|
|
1117
|
+
name: fdc3v2Definition.appId,
|
|
1118
|
+
type: this.fdc3ToDesktopDefinitionType[fdc3v2Definition.type],
|
|
1119
|
+
details: fdc3v2Definition.details,
|
|
1120
|
+
version: fdc3v2Definition.version,
|
|
1121
|
+
title: fdc3v2Definition.title,
|
|
1122
|
+
tooltip: fdc3v2Definition.tooltip,
|
|
1123
|
+
caption: fdc3v2Definition.description,
|
|
1124
|
+
icon: this.getIconFromDefinition(fdc3v2Definition, "2.0"),
|
|
1125
|
+
intents: this.getIntentsFromV2AppDefinition(fdc3v2Definition),
|
|
1126
|
+
fdc3: Object.assign(Object.assign({}, fdc3v2Definition), { definitionVersion: "2.0" })
|
|
1127
|
+
};
|
|
1128
|
+
if ((_b = fdc3v2Definition.hostManifests) === null || _b === void 0 ? void 0 : _b["Glue42"]) {
|
|
1129
|
+
if (typeof fdc3v2Definition.hostManifests["Glue42"] !== "object" || Array.isArray(fdc3v2Definition.hostManifests["Glue42"])) {
|
|
1130
|
+
throw new Error("Invalid 'hostManifests['Glue42]' key");
|
|
1131
|
+
}
|
|
1132
|
+
desktopDefinition = this.mergeDesktopConfigWithGlueManifest(desktopDefinition, (_c = fdc3v2Definition.hostManifests) === null || _c === void 0 ? void 0 : _c["Glue42"]);
|
|
1133
|
+
}
|
|
1134
|
+
return desktopDefinition;
|
|
1135
|
+
}
|
|
1136
|
+
getUserPropertiesFromDefinition(definition, version) {
|
|
1137
|
+
if (version === "1.2") {
|
|
1138
|
+
return Object.fromEntries(Object.entries(definition).filter(([key]) => !connectBrowserAppProps.includes(key)));
|
|
1139
|
+
}
|
|
1140
|
+
return Object.fromEntries(Object.entries(definition).filter(([key]) => !connectBrowserAppProps.includes(key) && !fdc3v2AppProps.includes(key)));
|
|
1141
|
+
}
|
|
1142
|
+
getUrl(definition, version) {
|
|
1143
|
+
var _a, _b;
|
|
1144
|
+
let url;
|
|
1145
|
+
if (version === "1.2") {
|
|
1146
|
+
const parsedManifest = JSON.parse(definition.manifest);
|
|
1147
|
+
url = ((_a = parsedManifest.details) === null || _a === void 0 ? void 0 : _a.url) || parsedManifest.url;
|
|
1148
|
+
}
|
|
1149
|
+
else {
|
|
1150
|
+
url = (_b = definition.details) === null || _b === void 0 ? void 0 : _b.url;
|
|
1151
|
+
}
|
|
1152
|
+
if (!url || typeof url !== "string") {
|
|
1153
|
+
throw new Error(`Invalid FDC3 ${version} definition. Provide valid 'url' under '${version === "1.2" ? "manifest" : "details"}' key`);
|
|
1154
|
+
}
|
|
1155
|
+
return url;
|
|
1156
|
+
}
|
|
1157
|
+
getIntentsFromV2AppDefinition(definition) {
|
|
1158
|
+
var _a, _b;
|
|
1159
|
+
const fdc3Intents = (_b = (_a = definition.interop) === null || _a === void 0 ? void 0 : _a.intents) === null || _b === void 0 ? void 0 : _b.listensFor;
|
|
1160
|
+
if (!fdc3Intents) {
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
const intents = Object.entries(fdc3Intents).map((fdc3Intent) => {
|
|
1164
|
+
const [intentName, intentData] = fdc3Intent;
|
|
1165
|
+
return Object.assign({ name: intentName }, intentData);
|
|
1166
|
+
});
|
|
1167
|
+
return intents;
|
|
1168
|
+
}
|
|
1169
|
+
getIconFromDefinition(definition, version) {
|
|
1170
|
+
var _a, _b, _c, _d;
|
|
1171
|
+
if (version === "1.2") {
|
|
1172
|
+
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;
|
|
1173
|
+
}
|
|
1174
|
+
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;
|
|
1175
|
+
}
|
|
1176
|
+
mergeBaseAppDataWithGlueManifest(baseAppData, hostManifestDefinition) {
|
|
1177
|
+
let baseApplicationDefinition = baseAppData;
|
|
1178
|
+
if (hostManifestDefinition.details) {
|
|
1179
|
+
const details = Object.assign(Object.assign({}, baseAppData.createOptions), hostManifestDefinition.details);
|
|
1180
|
+
baseApplicationDefinition.createOptions = details;
|
|
1181
|
+
baseApplicationDefinition.userProperties.details = details;
|
|
1182
|
+
}
|
|
1183
|
+
if (Array.isArray(hostManifestDefinition.intents)) {
|
|
1184
|
+
baseApplicationDefinition.userProperties.intents = (baseApplicationDefinition.userProperties.intents || []).concat(hostManifestDefinition.intents);
|
|
1185
|
+
}
|
|
1186
|
+
baseApplicationDefinition = Object.assign(Object.assign({}, baseApplicationDefinition), hostManifestDefinition);
|
|
1187
|
+
delete baseApplicationDefinition.details;
|
|
1188
|
+
delete baseApplicationDefinition.intents;
|
|
1189
|
+
return baseApplicationDefinition;
|
|
1190
|
+
}
|
|
1191
|
+
mergeDesktopConfigWithGlueManifest(config, desktopDefinition) {
|
|
1192
|
+
const appConfig = Object.assign({}, config, desktopDefinition, { details: Object.assign(Object.assign({}, config.details), desktopDefinition.details) });
|
|
1193
|
+
if (Array.isArray(desktopDefinition.intents)) {
|
|
1194
|
+
appConfig.intents = (config.intents || []).concat(desktopDefinition.intents);
|
|
1195
|
+
}
|
|
1196
|
+
return appConfig;
|
|
1197
|
+
}
|
|
36
1198
|
}
|
|
37
1199
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
} else {
|
|
48
|
-
id += '_';
|
|
1200
|
+
const decoders$1 = {
|
|
1201
|
+
common: {
|
|
1202
|
+
nonEmptyStringDecoder: nonEmptyStringDecoder$1,
|
|
1203
|
+
nonNegativeNumberDecoder
|
|
1204
|
+
},
|
|
1205
|
+
fdc3: {
|
|
1206
|
+
allDefinitionsDecoder,
|
|
1207
|
+
v1DefinitionDecoder,
|
|
1208
|
+
v2DefinitionDecoder
|
|
49
1209
|
}
|
|
50
|
-
|
|
51
|
-
}, '');
|
|
1210
|
+
};
|
|
52
1211
|
|
|
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
|
-
reject(error);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
const generateCommandId = () => {
|
|
92
|
-
return nanoid();
|
|
1212
|
+
var INTENTS_ERRORS;
|
|
1213
|
+
(function (INTENTS_ERRORS) {
|
|
1214
|
+
INTENTS_ERRORS["USER_CANCELLED"] = "User Closed Intents Resolver UI without choosing a handler";
|
|
1215
|
+
INTENTS_ERRORS["CALLER_NOT_DEFINED"] = "Caller Id is not defined";
|
|
1216
|
+
INTENTS_ERRORS["TIMEOUT_HIT"] = "Timeout hit";
|
|
1217
|
+
INTENTS_ERRORS["INTENT_NOT_FOUND"] = "Cannot find Intent";
|
|
1218
|
+
INTENTS_ERRORS["HANDLER_NOT_FOUND"] = "Cannot find Intent Handler";
|
|
1219
|
+
INTENTS_ERRORS["TARGET_INSTANCE_UNAVAILABLE"] = "Cannot start Target Instance";
|
|
1220
|
+
INTENTS_ERRORS["INTENT_DELIVERY_FAILED"] = "Target Instance did not add a listener";
|
|
1221
|
+
INTENTS_ERRORS["RESOLVER_UNAVAILABLE"] = "Intents Resolver UI unavailable";
|
|
1222
|
+
INTENTS_ERRORS["RESOLVER_TIMEOUT"] = "User did not choose a handler";
|
|
1223
|
+
INTENTS_ERRORS["INVALID_RESOLVER_RESPONSE"] = "Intents Resolver UI returned invalid response";
|
|
1224
|
+
INTENTS_ERRORS["INTENT_HANDLER_REJECTION"] = "Intent Handler function processing the raised intent threw an error or rejected the promise it returned";
|
|
1225
|
+
})(INTENTS_ERRORS || (INTENTS_ERRORS = {}));
|
|
1226
|
+
|
|
1227
|
+
let IoC$1 = class IoC {
|
|
1228
|
+
constructor() {
|
|
1229
|
+
this._decoders = decoders$1;
|
|
1230
|
+
this._errors = {
|
|
1231
|
+
intents: INTENTS_ERRORS
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
get fdc3() {
|
|
1235
|
+
if (!this._fdc3) {
|
|
1236
|
+
this._fdc3 = new FDC3Service().toApi();
|
|
1237
|
+
}
|
|
1238
|
+
return this._fdc3;
|
|
1239
|
+
}
|
|
1240
|
+
get decoders() {
|
|
1241
|
+
return this._decoders;
|
|
1242
|
+
}
|
|
1243
|
+
get errors() {
|
|
1244
|
+
return this._errors;
|
|
1245
|
+
}
|
|
93
1246
|
};
|
|
94
1247
|
|
|
1248
|
+
const ioc = new IoC$1();
|
|
1249
|
+
ioc.fdc3;
|
|
1250
|
+
ioc.decoders;
|
|
1251
|
+
const errors = ioc.errors;
|
|
1252
|
+
|
|
95
1253
|
var IntentHandlerResultTypes;
|
|
96
1254
|
(function (IntentHandlerResultTypes) {
|
|
97
1255
|
IntentHandlerResultTypes["Context"] = "Context";
|
|
@@ -189,7 +1347,8 @@ const Fdc3SupportedIntentTypes = {
|
|
|
189
1347
|
"fdc3.instrument",
|
|
190
1348
|
"fdc3.organization"
|
|
191
1349
|
]
|
|
192
|
-
};
|
|
1350
|
+
};
|
|
1351
|
+
const IO_ERRORS = errors.intents;
|
|
193
1352
|
|
|
194
1353
|
const ioConnectFDC3SystemMethod = "FDC3.Collaborate";
|
|
195
1354
|
const PrivateChannelPrefix = "___privateFDC3Channel___";
|
|
@@ -1104,6 +2263,26 @@ class GlueController {
|
|
|
1104
2263
|
return this.glue.intents.raise(request);
|
|
1105
2264
|
});
|
|
1106
2265
|
}
|
|
2266
|
+
doesFilterHandlersExist() {
|
|
2267
|
+
return !!this.glue.intents.filterHandlers;
|
|
2268
|
+
}
|
|
2269
|
+
filterHandlers(handlerFilter) {
|
|
2270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2271
|
+
if (!this.glue.intents.filterHandlers) {
|
|
2272
|
+
throw new Error("Intents method 'filterHandlers' does not exist");
|
|
2273
|
+
}
|
|
2274
|
+
return this.glue.intents.filterHandlers(handlerFilter);
|
|
2275
|
+
});
|
|
2276
|
+
}
|
|
2277
|
+
doesGetIntentsExist() {
|
|
2278
|
+
return !!this.glue.intents.getIntents;
|
|
2279
|
+
}
|
|
2280
|
+
getIntents(handler) {
|
|
2281
|
+
if (!this.glue.intents.getIntents) {
|
|
2282
|
+
throw new Error("Intents method 'getIntents' does not exist");
|
|
2283
|
+
}
|
|
2284
|
+
return this.glue.intents.getIntents(handler);
|
|
2285
|
+
}
|
|
1107
2286
|
getMyWindowContext() {
|
|
1108
2287
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1109
2288
|
const myWin = this.getMyWindow();
|
|
@@ -1234,7 +2413,8 @@ class GlueController {
|
|
|
1234
2413
|
return this.glue.interop.servers(methodFilter);
|
|
1235
2414
|
}
|
|
1236
2415
|
initSubLogger(name) {
|
|
1237
|
-
|
|
2416
|
+
var _a;
|
|
2417
|
+
return (_a = this.logger) === null || _a === void 0 ? void 0 : _a.subLogger(name);
|
|
1238
2418
|
}
|
|
1239
2419
|
invokePreviouslyBroadcastedData({ callback, contextData, metadata, contextType }) {
|
|
1240
2420
|
const invokeForType = contextType || this.channelsParser.mapChannelsDelimiterToFDC3Type(contextData.latest_fdc3_type);
|
|
@@ -1314,23 +2494,150 @@ const REQUEST_GLUE = "requestGlue";
|
|
|
1314
2494
|
const REQUEST_GLUE_RESPONSE = "requestGlueResponse";
|
|
1315
2495
|
const FDC3_READY = "fdc3Ready";
|
|
1316
2496
|
|
|
1317
|
-
class EventDispatcher {
|
|
1318
|
-
fireFdc3Ready() {
|
|
1319
|
-
const event = new Event(FDC3_READY);
|
|
1320
|
-
window.dispatchEvent(event);
|
|
1321
|
-
}
|
|
1322
|
-
fireNotifyStarted() {
|
|
1323
|
-
this.send(NOTIFY_STARTED);
|
|
1324
|
-
}
|
|
1325
|
-
fireRequestGlue() {
|
|
1326
|
-
this.send(REQUEST_GLUE);
|
|
1327
|
-
}
|
|
1328
|
-
send(eventName, message) {
|
|
1329
|
-
const payload = { glue42: { event: eventName, message } };
|
|
1330
|
-
const event = new CustomEvent(GLUE42_EVENT_NAME, { detail: payload });
|
|
1331
|
-
window.dispatchEvent(event);
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
2497
|
+
class EventDispatcher {
|
|
2498
|
+
fireFdc3Ready() {
|
|
2499
|
+
const event = new Event(FDC3_READY);
|
|
2500
|
+
window.dispatchEvent(event);
|
|
2501
|
+
}
|
|
2502
|
+
fireNotifyStarted() {
|
|
2503
|
+
this.send(NOTIFY_STARTED);
|
|
2504
|
+
}
|
|
2505
|
+
fireRequestGlue() {
|
|
2506
|
+
this.send(REQUEST_GLUE);
|
|
2507
|
+
}
|
|
2508
|
+
send(eventName, message) {
|
|
2509
|
+
const payload = { glue42: { event: eventName, message } };
|
|
2510
|
+
const event = new CustomEvent(GLUE42_EVENT_NAME, { detail: payload });
|
|
2511
|
+
window.dispatchEvent(event);
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
// To parse this data:
|
|
2516
|
+
|
|
2517
|
+
/**
|
|
2518
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2519
|
+
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
2520
|
+
*/
|
|
2521
|
+
/** Constants representing the errors that can be encountered when calling the `open` method on the DesktopAgent object (`fdc3`). */
|
|
2522
|
+
var OpenError;
|
|
2523
|
+
(function (OpenError) {
|
|
2524
|
+
/** Returned if the specified application is not found.*/
|
|
2525
|
+
OpenError["AppNotFound"] = "AppNotFound";
|
|
2526
|
+
/** Returned if the specified application fails to launch correctly.*/
|
|
2527
|
+
OpenError["ErrorOnLaunch"] = "ErrorOnLaunch";
|
|
2528
|
+
/** 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.*/
|
|
2529
|
+
OpenError["AppTimeout"] = "AppTimeout";
|
|
2530
|
+
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
2531
|
+
OpenError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
2532
|
+
/** 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.*/
|
|
2533
|
+
OpenError["MalformedContext"] = "MalformedContext";
|
|
2534
|
+
/** @experimental Returned if the specified Desktop Agent is not found, via a connected Desktop Agent Bridge.*/
|
|
2535
|
+
OpenError["DesktopAgentNotFound"] = "DesktopAgentNotFound";
|
|
2536
|
+
})(OpenError || (OpenError = {}));
|
|
2537
|
+
/** Constants representing the errors that can be encountered when calling the `findIntent`, `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the DesktopAgent (`fdc3`). */
|
|
2538
|
+
var ResolveError;
|
|
2539
|
+
(function (ResolveError) {
|
|
2540
|
+
/** SHOULD be returned if no apps are available that can resolve the intent and context combination.*/
|
|
2541
|
+
ResolveError["NoAppsFound"] = "NoAppsFound";
|
|
2542
|
+
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
2543
|
+
ResolveError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
2544
|
+
/** Returned if the user cancelled the resolution request, for example by closing or cancelling a resolver UI.*/
|
|
2545
|
+
ResolveError["UserCancelled"] = "UserCancelledResolution";
|
|
2546
|
+
/** 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.*/
|
|
2547
|
+
ResolveError["ResolverTimeout"] = "ResolverTimeout";
|
|
2548
|
+
/** Returned if a specified target application is not available or a new instance of it cannot be opened. */
|
|
2549
|
+
ResolveError["TargetAppUnavailable"] = "TargetAppUnavailable";
|
|
2550
|
+
/** Returned if a specified target application instance is not available, for example because it has been closed. */
|
|
2551
|
+
ResolveError["TargetInstanceUnavailable"] = "TargetInstanceUnavailable";
|
|
2552
|
+
/** 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.*/
|
|
2553
|
+
ResolveError["IntentDeliveryFailed"] = "IntentDeliveryFailed";
|
|
2554
|
+
/** 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.*/
|
|
2555
|
+
ResolveError["MalformedContext"] = "MalformedContext";
|
|
2556
|
+
/** @experimental Returned if the specified Desktop Agent is not found, via a connected Desktop Agent Bridge.*/
|
|
2557
|
+
ResolveError["DesktopAgentNotFound"] = "DesktopAgentNotFound";
|
|
2558
|
+
})(ResolveError || (ResolveError = {}));
|
|
2559
|
+
var ResultError;
|
|
2560
|
+
(function (ResultError) {
|
|
2561
|
+
/** Returned if the intent handler exited without returning a valid result (a promise resolving to a Context, Channel object or void). */
|
|
2562
|
+
ResultError["NoResultReturned"] = "NoResultReturned";
|
|
2563
|
+
/** Returned if the Intent handler function processing the raised intent throws an error or rejects the Promise it returned. */
|
|
2564
|
+
ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
|
|
2565
|
+
})(ResultError || (ResultError = {}));
|
|
2566
|
+
var ChannelError;
|
|
2567
|
+
(function (ChannelError) {
|
|
2568
|
+
/** Returned if the specified channel is not found when attempting to join a channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).*/
|
|
2569
|
+
ChannelError["NoChannelFound"] = "NoChannelFound";
|
|
2570
|
+
/** 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. */
|
|
2571
|
+
ChannelError["AccessDenied"] = "AccessDenied";
|
|
2572
|
+
/** SHOULD be returned when a channel cannot be created or retrieved via the `getOrCreateChannel` method of the DesktopAgent (`fdc3`).*/
|
|
2573
|
+
ChannelError["CreationFailed"] = "CreationFailed";
|
|
2574
|
+
/** 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.*/
|
|
2575
|
+
ChannelError["MalformedContext"] = "MalformedContext";
|
|
2576
|
+
})(ChannelError || (ChannelError = {}));
|
|
2577
|
+
var BridgingError;
|
|
2578
|
+
(function (BridgingError) {
|
|
2579
|
+
/** @experimental Returned if a Desktop Agent did not return a response, via Desktop Agent Bridging, within the alloted timeout. */
|
|
2580
|
+
BridgingError["ResponseTimedOut"] = "ResponseToBridgeTimedOut";
|
|
2581
|
+
/** @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. */
|
|
2582
|
+
BridgingError["AgentDisconnected"] = "AgentDisconnected";
|
|
2583
|
+
/** @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. */
|
|
2584
|
+
BridgingError["NotConnectedToBridge"] = "NotConnectedToBridge";
|
|
2585
|
+
/** @experimental Returned if a message to a Bridge deviates from the schema for that message sufficiently that it could not be processed. */
|
|
2586
|
+
BridgingError["MalformedMessage"] = "MalformedMessage";
|
|
2587
|
+
})(BridgingError || (BridgingError = {}));
|
|
2588
|
+
|
|
2589
|
+
/**
|
|
2590
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2591
|
+
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
2592
|
+
*/
|
|
2593
|
+
var ContextTypes;
|
|
2594
|
+
(function (ContextTypes) {
|
|
2595
|
+
ContextTypes["Chart"] = "fdc3.chart";
|
|
2596
|
+
ContextTypes["ChatInitSettings"] = "fdc3.chat.initSettings";
|
|
2597
|
+
ContextTypes["ChatRoom"] = "fdc3.chat.room";
|
|
2598
|
+
ContextTypes["Contact"] = "fdc3.contact";
|
|
2599
|
+
ContextTypes["ContactList"] = "fdc3.contactList";
|
|
2600
|
+
ContextTypes["Country"] = "fdc3.country";
|
|
2601
|
+
ContextTypes["Currency"] = "fdc3.currency";
|
|
2602
|
+
ContextTypes["Email"] = "fdc3.email";
|
|
2603
|
+
ContextTypes["Instrument"] = "fdc3.instrument";
|
|
2604
|
+
ContextTypes["InstrumentList"] = "fdc3.instrumentList";
|
|
2605
|
+
ContextTypes["Interaction"] = "fdc3.interaction";
|
|
2606
|
+
ContextTypes["Nothing"] = "fdc3.nothing";
|
|
2607
|
+
ContextTypes["Organization"] = "fdc3.organization";
|
|
2608
|
+
ContextTypes["Portfolio"] = "fdc3.portfolio";
|
|
2609
|
+
ContextTypes["Position"] = "fdc3.position";
|
|
2610
|
+
ContextTypes["ChatSearchCriteria"] = "fdc3.chat.searchCriteria";
|
|
2611
|
+
ContextTypes["TimeRange"] = "fdc3.timerange";
|
|
2612
|
+
ContextTypes["TransactionResult"] = "fdc3.transactionResult";
|
|
2613
|
+
ContextTypes["Valuation"] = "fdc3.valuation";
|
|
2614
|
+
})(ContextTypes || (ContextTypes = {}));
|
|
2615
|
+
|
|
2616
|
+
/**
|
|
2617
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
2618
|
+
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
2619
|
+
*/
|
|
2620
|
+
var Intents;
|
|
2621
|
+
(function (Intents) {
|
|
2622
|
+
Intents["CreateInteraction"] = "CreateInteraction";
|
|
2623
|
+
Intents["SendChatMessage"] = "SendChatMessage";
|
|
2624
|
+
Intents["StartCall"] = "StartCall";
|
|
2625
|
+
Intents["StartChat"] = "StartChat";
|
|
2626
|
+
Intents["StartEmail"] = "StartEmail";
|
|
2627
|
+
Intents["ViewAnalysis"] = "ViewAnalysis";
|
|
2628
|
+
Intents["ViewChat"] = "ViewChat";
|
|
2629
|
+
Intents["ViewChart"] = "ViewChart";
|
|
2630
|
+
Intents["ViewContact"] = "ViewContact";
|
|
2631
|
+
Intents["ViewHoldings"] = "ViewHoldings";
|
|
2632
|
+
Intents["ViewInstrument"] = "ViewInstrument";
|
|
2633
|
+
Intents["ViewInteractions"] = "ViewInteractions";
|
|
2634
|
+
Intents["ViewMessages"] = "ViewMessages";
|
|
2635
|
+
Intents["ViewNews"] = "ViewNews";
|
|
2636
|
+
Intents["ViewOrders"] = "ViewOrders";
|
|
2637
|
+
Intents["ViewProfile"] = "ViewProfile";
|
|
2638
|
+
Intents["ViewQuote"] = "ViewQuote";
|
|
2639
|
+
Intents["ViewResearch"] = "ViewResearch";
|
|
2640
|
+
})(Intents || (Intents = {}));
|
|
1334
2641
|
|
|
1335
2642
|
class DesktopAgent {
|
|
1336
2643
|
constructor(intentsController, applicationController, channelsController) {
|
|
@@ -1366,7 +2673,10 @@ class DesktopAgent {
|
|
|
1366
2673
|
open(target, context) {
|
|
1367
2674
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1368
2675
|
targetAppDecoder.runWithException(target);
|
|
1369
|
-
optionalContextDecoder.
|
|
2676
|
+
const contextDecoderResult = optionalContextDecoder.run(context);
|
|
2677
|
+
if (!contextDecoderResult.ok) {
|
|
2678
|
+
throw new Error(OpenError.MalformedContext);
|
|
2679
|
+
}
|
|
1370
2680
|
return this.applicationController.open({ commandId: generateCommandId(), target, context });
|
|
1371
2681
|
});
|
|
1372
2682
|
}
|
|
@@ -1389,7 +2699,10 @@ class DesktopAgent {
|
|
|
1389
2699
|
}
|
|
1390
2700
|
broadcast(context) {
|
|
1391
2701
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1392
|
-
contextDecoder.
|
|
2702
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2703
|
+
if (!contextDecoderResult.ok) {
|
|
2704
|
+
throw new Error(ChannelError.MalformedContext);
|
|
2705
|
+
}
|
|
1393
2706
|
return this.channelsController.broadcast(generateCommandId(), context);
|
|
1394
2707
|
});
|
|
1395
2708
|
}
|
|
@@ -1413,7 +2726,7 @@ class DesktopAgent {
|
|
|
1413
2726
|
nonEmptyStringDecoder.runWithException(intent);
|
|
1414
2727
|
const contextDecoderResult = optionalContextDecoder.run(context);
|
|
1415
2728
|
if (!contextDecoderResult.ok) {
|
|
1416
|
-
throw new Error(
|
|
2729
|
+
throw new Error(ResolveError.MalformedContext);
|
|
1417
2730
|
}
|
|
1418
2731
|
optionalNonEmptyStringDecoder.runWithException(resultType);
|
|
1419
2732
|
return this.intentsController.findIntent({ commandId: generateCommandId(), intent, context: contextDecoderResult.result, resultType });
|
|
@@ -1423,7 +2736,7 @@ class DesktopAgent {
|
|
|
1423
2736
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1424
2737
|
const contextDecoderResult = contextDecoder.run(context);
|
|
1425
2738
|
if (!contextDecoderResult.ok) {
|
|
1426
|
-
throw new Error(
|
|
2739
|
+
throw new Error(ResolveError.MalformedContext);
|
|
1427
2740
|
}
|
|
1428
2741
|
optionalNonEmptyStringDecoder.runWithException(resultType);
|
|
1429
2742
|
return this.intentsController.findIntentsByContext({ commandId: generateCommandId(), context: contextDecoderResult.result, resultType });
|
|
@@ -1432,14 +2745,20 @@ class DesktopAgent {
|
|
|
1432
2745
|
raiseIntent(intent, context, app) {
|
|
1433
2746
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1434
2747
|
nonEmptyStringDecoder.runWithException(intent);
|
|
1435
|
-
contextDecoder.
|
|
2748
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2749
|
+
if (!contextDecoderResult.ok) {
|
|
2750
|
+
throw new Error(ResolveError.MalformedContext);
|
|
2751
|
+
}
|
|
1436
2752
|
optionalAppIdentifier.runWithException(app);
|
|
1437
2753
|
return this.intentsController.raiseIntent({ commandId: generateCommandId(), intent, context, target: app });
|
|
1438
2754
|
});
|
|
1439
2755
|
}
|
|
1440
2756
|
raiseIntentForContext(context, app) {
|
|
1441
2757
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1442
|
-
contextDecoder.
|
|
2758
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2759
|
+
if (!contextDecoderResult.ok) {
|
|
2760
|
+
throw new Error(ResolveError.MalformedContext);
|
|
2761
|
+
}
|
|
1443
2762
|
optionalTargetApp.runWithException(app);
|
|
1444
2763
|
return this.intentsController.raiseIntentForContext({ commandId: generateCommandId(), context, target: app });
|
|
1445
2764
|
});
|
|
@@ -1516,7 +2835,10 @@ class AppChannel {
|
|
|
1516
2835
|
}
|
|
1517
2836
|
broadcast(context) {
|
|
1518
2837
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1519
|
-
contextDecoder.
|
|
2838
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2839
|
+
if (!contextDecoderResult.ok) {
|
|
2840
|
+
throw new Error(ChannelError.MalformedContext);
|
|
2841
|
+
}
|
|
1520
2842
|
return this.channelsController.broadcast(generateCommandId(), context, this.id);
|
|
1521
2843
|
});
|
|
1522
2844
|
}
|
|
@@ -1561,7 +2883,7 @@ class ChannelsParser {
|
|
|
1561
2883
|
return this.mapChannelsDelimiterToFDC3Type(withoutPrefix);
|
|
1562
2884
|
}
|
|
1563
2885
|
parseFDC3ContextToGlueContexts(context) {
|
|
1564
|
-
const { type } = context, rest = __rest$
|
|
2886
|
+
const { type } = context, rest = __rest$2(context, ["type"]);
|
|
1565
2887
|
const parsedType = this.mapFDC3TypeToChannelsDelimiter(type);
|
|
1566
2888
|
return { path: `${this.channelsFdc3DataPrefix}${parsedType}`, value: rest };
|
|
1567
2889
|
}
|
|
@@ -1576,137 +2898,6 @@ class ChannelsParser {
|
|
|
1576
2898
|
}
|
|
1577
2899
|
}
|
|
1578
2900
|
|
|
1579
|
-
/**
|
|
1580
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
1581
|
-
* Copyright FINOS FDC3 contributors - see NOTICE file
|
|
1582
|
-
*/
|
|
1583
|
-
/** Constants representing the errors that can be encountered when calling the `open` method on the DesktopAgent object (`fdc3`). */
|
|
1584
|
-
var OpenError;
|
|
1585
|
-
(function (OpenError) {
|
|
1586
|
-
/** Returned if the specified application is not found.*/
|
|
1587
|
-
OpenError["AppNotFound"] = "AppNotFound";
|
|
1588
|
-
/** Returned if the specified application fails to launch correctly.*/
|
|
1589
|
-
OpenError["ErrorOnLaunch"] = "ErrorOnLaunch";
|
|
1590
|
-
/** 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.*/
|
|
1591
|
-
OpenError["AppTimeout"] = "AppTimeout";
|
|
1592
|
-
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
1593
|
-
OpenError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
1594
|
-
/** 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.*/
|
|
1595
|
-
OpenError["MalformedContext"] = "MalformedContext";
|
|
1596
|
-
})(OpenError || (OpenError = {}));
|
|
1597
|
-
/** Constants representing the errors that can be encountered when calling the `findIntent`, `findIntentsByContext`, `raiseIntent` or `raiseIntentForContext` methods on the DesktopAgent (`fdc3`). */
|
|
1598
|
-
var ResolveError;
|
|
1599
|
-
(function (ResolveError) {
|
|
1600
|
-
/** SHOULD be returned if no apps are available that can resolve the intent and context combination.*/
|
|
1601
|
-
ResolveError["NoAppsFound"] = "NoAppsFound";
|
|
1602
|
-
/** Returned if the FDC3 desktop agent implementation is not currently able to handle the request.*/
|
|
1603
|
-
ResolveError["ResolverUnavailable"] = "ResolverUnavailable";
|
|
1604
|
-
/** Returned if the user cancelled the resolution request, for example by closing or cancelling a resolver UI.*/
|
|
1605
|
-
ResolveError["UserCancelled"] = "UserCancelledResolution";
|
|
1606
|
-
/** 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.*/
|
|
1607
|
-
ResolveError["ResolverTimeout"] = "ResolverTimeout";
|
|
1608
|
-
/** Returned if a specified target application is not available or a new instance of it cannot be opened. */
|
|
1609
|
-
ResolveError["TargetAppUnavailable"] = "TargetAppUnavailable";
|
|
1610
|
-
/** Returned if a specified target application instance is not available, for example because it has been closed. */
|
|
1611
|
-
ResolveError["TargetInstanceUnavailable"] = "TargetInstanceUnavailable";
|
|
1612
|
-
/** 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.*/
|
|
1613
|
-
ResolveError["IntentDeliveryFailed"] = "IntentDeliveryFailed";
|
|
1614
|
-
/** 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.*/
|
|
1615
|
-
ResolveError["MalformedContext"] = "MalformedContext";
|
|
1616
|
-
})(ResolveError || (ResolveError = {}));
|
|
1617
|
-
var ResultError;
|
|
1618
|
-
(function (ResultError) {
|
|
1619
|
-
/** Returned if the intent handler exited without returning a valid result (a promise resolving to a Context, Channel object or void). */
|
|
1620
|
-
ResultError["NoResultReturned"] = "NoResultReturned";
|
|
1621
|
-
/** Returned if the Intent handler function processing the raised intent throws an error or rejects the Promise it returned. */
|
|
1622
|
-
ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
|
|
1623
|
-
})(ResultError || (ResultError = {}));
|
|
1624
|
-
var ChannelError;
|
|
1625
|
-
(function (ChannelError) {
|
|
1626
|
-
/** Returned if the specified channel is not found when attempting to join a channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).*/
|
|
1627
|
-
ChannelError["NoChannelFound"] = "NoChannelFound";
|
|
1628
|
-
/** 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. */
|
|
1629
|
-
ChannelError["AccessDenied"] = "AccessDenied";
|
|
1630
|
-
/** SHOULD be returned when a channel cannot be created or retrieved via the `getOrCreateChannel` method of the DesktopAgent (`fdc3`).*/
|
|
1631
|
-
ChannelError["CreationFailed"] = "CreationFailed";
|
|
1632
|
-
/** 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.*/
|
|
1633
|
-
ChannelError["MalformedContext"] = "MalformedContext";
|
|
1634
|
-
})(ChannelError || (ChannelError = {}));
|
|
1635
|
-
|
|
1636
|
-
var ContextTypes;
|
|
1637
|
-
(function (ContextTypes) {
|
|
1638
|
-
ContextTypes["Chart"] = "fdc3.chart";
|
|
1639
|
-
ContextTypes["ChatInitSettings"] = "fdc3.chat.initSettings";
|
|
1640
|
-
ContextTypes["Contact"] = "fdc3.contact";
|
|
1641
|
-
ContextTypes["ContactList"] = "fdc3.contactList";
|
|
1642
|
-
ContextTypes["Country"] = "fdc3.country";
|
|
1643
|
-
ContextTypes["Currency"] = "fdc3.currency";
|
|
1644
|
-
ContextTypes["Email"] = "fdc3.email";
|
|
1645
|
-
ContextTypes["Instrument"] = "fdc3.instrument";
|
|
1646
|
-
ContextTypes["InstrumentList"] = "fdc3.instrumentList";
|
|
1647
|
-
ContextTypes["Organization"] = "fdc3.organization";
|
|
1648
|
-
ContextTypes["Portfolio"] = "fdc3.portfolio";
|
|
1649
|
-
ContextTypes["Position"] = "fdc3.position";
|
|
1650
|
-
ContextTypes["Nothing"] = "fdc3.nothing";
|
|
1651
|
-
ContextTypes["TimeRange"] = "fdc3.timerange";
|
|
1652
|
-
ContextTypes["Valuation"] = "fdc3.valuation";
|
|
1653
|
-
})(ContextTypes || (ContextTypes = {}));
|
|
1654
|
-
|
|
1655
|
-
// To parse this data:
|
|
1656
|
-
//
|
|
1657
|
-
// import { Convert, Chart, ChatInitSettings, Contact, ContactList, Context, Country, Currency, Email, Instrument, InstrumentList, Nothing, Organization, Portfolio, Position, TimeRange, Valuation } from "./file";
|
|
1658
|
-
//
|
|
1659
|
-
// const chart = Convert.toChart(json);
|
|
1660
|
-
// const chatInitSettings = Convert.toChatInitSettings(json);
|
|
1661
|
-
// const contact = Convert.toContact(json);
|
|
1662
|
-
// const contactList = Convert.toContactList(json);
|
|
1663
|
-
// const context = Convert.toContext(json);
|
|
1664
|
-
// const country = Convert.toCountry(json);
|
|
1665
|
-
// const currency = Convert.toCurrency(json);
|
|
1666
|
-
// const email = Convert.toEmail(json);
|
|
1667
|
-
// const instrument = Convert.toInstrument(json);
|
|
1668
|
-
// const instrumentList = Convert.toInstrumentList(json);
|
|
1669
|
-
// const nothing = Convert.toNothing(json);
|
|
1670
|
-
// const organization = Convert.toOrganization(json);
|
|
1671
|
-
// const portfolio = Convert.toPortfolio(json);
|
|
1672
|
-
// const position = Convert.toPosition(json);
|
|
1673
|
-
// const timeRange = Convert.toTimeRange(json);
|
|
1674
|
-
// const valuation = Convert.toValuation(json);
|
|
1675
|
-
//
|
|
1676
|
-
// These functions will throw an error if the JSON doesn't
|
|
1677
|
-
// match the expected interface, even if the JSON is valid.
|
|
1678
|
-
var Style;
|
|
1679
|
-
(function (Style) {
|
|
1680
|
-
Style["Bar"] = "bar";
|
|
1681
|
-
Style["Candle"] = "candle";
|
|
1682
|
-
Style["Custom"] = "custom";
|
|
1683
|
-
Style["Heatmap"] = "heatmap";
|
|
1684
|
-
Style["Histogram"] = "histogram";
|
|
1685
|
-
Style["Line"] = "line";
|
|
1686
|
-
Style["Mountain"] = "mountain";
|
|
1687
|
-
Style["Pie"] = "pie";
|
|
1688
|
-
Style["Scatter"] = "scatter";
|
|
1689
|
-
Style["StackedBar"] = "stacked-bar";
|
|
1690
|
-
})(Style || (Style = {}));
|
|
1691
|
-
|
|
1692
|
-
var Intents;
|
|
1693
|
-
(function (Intents) {
|
|
1694
|
-
Intents["StartCall"] = "StartCall";
|
|
1695
|
-
Intents["StartChat"] = "StartChat";
|
|
1696
|
-
Intents["StartEmail"] = "StartEmail";
|
|
1697
|
-
Intents["ViewAnalysis"] = "ViewAnalysis";
|
|
1698
|
-
Intents["ViewChart"] = "ViewChart";
|
|
1699
|
-
Intents["ViewContact"] = "ViewContact";
|
|
1700
|
-
Intents["ViewHoldings"] = "ViewHoldings";
|
|
1701
|
-
Intents["ViewInstrument"] = "ViewInstrument";
|
|
1702
|
-
Intents["ViewInteractions"] = "ViewInteractions";
|
|
1703
|
-
Intents["ViewNews"] = "ViewNews";
|
|
1704
|
-
Intents["ViewOrders"] = "ViewOrders";
|
|
1705
|
-
Intents["ViewProfile"] = "ViewProfile";
|
|
1706
|
-
Intents["ViewQuote"] = "ViewQuote";
|
|
1707
|
-
Intents["ViewResearch"] = "ViewResearch";
|
|
1708
|
-
})(Intents || (Intents = {}));
|
|
1709
|
-
|
|
1710
2901
|
class UserChannel {
|
|
1711
2902
|
constructor(channelsController, glueChannel) {
|
|
1712
2903
|
this.channelsController = channelsController;
|
|
@@ -1732,7 +2923,10 @@ class UserChannel {
|
|
|
1732
2923
|
}
|
|
1733
2924
|
broadcast(context) {
|
|
1734
2925
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1735
|
-
contextDecoder.
|
|
2926
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
2927
|
+
if (!contextDecoderResult.ok) {
|
|
2928
|
+
throw new Error(ChannelError.MalformedContext);
|
|
2929
|
+
}
|
|
1736
2930
|
return this.channelsController.broadcast(generateCommandId(), context, this.id);
|
|
1737
2931
|
});
|
|
1738
2932
|
}
|
|
@@ -1791,6 +2985,19 @@ class IntentsController {
|
|
|
1791
2985
|
this.channelsController = channelsController;
|
|
1792
2986
|
this.channelsFactory = channelsFactory;
|
|
1793
2987
|
this.glueEventsController = glueEventsController;
|
|
2988
|
+
this.ioToFDC3ErrorsDict = {
|
|
2989
|
+
[IO_ERRORS.USER_CANCELLED]: ResolveError.UserCancelled,
|
|
2990
|
+
[IO_ERRORS.TIMEOUT_HIT]: ResolveError.IntentDeliveryFailed,
|
|
2991
|
+
[IO_ERRORS.TARGET_INSTANCE_UNAVAILABLE]: ResolveError.TargetInstanceUnavailable,
|
|
2992
|
+
[IO_ERRORS.RESOLVER_UNAVAILABLE]: ResolveError.ResolverUnavailable,
|
|
2993
|
+
[IO_ERRORS.RESOLVER_TIMEOUT]: ResolveError.ResolverTimeout,
|
|
2994
|
+
[IO_ERRORS.INVALID_RESOLVER_RESPONSE]: ResolveError.IntentDeliveryFailed,
|
|
2995
|
+
[IO_ERRORS.INTENT_NOT_FOUND]: ResolveError.NoAppsFound,
|
|
2996
|
+
[IO_ERRORS.INTENT_DELIVERY_FAILED]: ResolveError.IntentDeliveryFailed,
|
|
2997
|
+
[IO_ERRORS.HANDLER_NOT_FOUND]: ResolveError.NoAppsFound,
|
|
2998
|
+
[IO_ERRORS.CALLER_NOT_DEFINED]: ResolveError.IntentDeliveryFailed,
|
|
2999
|
+
[IO_ERRORS.INTENT_HANDLER_REJECTION]: ResultError.IntentHandlerRejected
|
|
3000
|
+
};
|
|
1794
3001
|
}
|
|
1795
3002
|
get logger() {
|
|
1796
3003
|
if (!this._logger) {
|
|
@@ -1799,9 +3006,10 @@ class IntentsController {
|
|
|
1799
3006
|
return this._logger;
|
|
1800
3007
|
}
|
|
1801
3008
|
findIntent({ commandId, intent, context, resultType }) {
|
|
3009
|
+
var _a;
|
|
1802
3010
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1803
3011
|
yield this.glueController.gluePromise;
|
|
1804
|
-
this.logger.info(`[${commandId}] - findIntent() invoked for intent ${intent} with contextType ${context === null || context === void 0 ? void 0 : context.type} and resultType ${resultType}`);
|
|
3012
|
+
(_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}`);
|
|
1805
3013
|
const glueIntents = yield this.glueController.findIntents({ name: intent });
|
|
1806
3014
|
if (!glueIntents.length) {
|
|
1807
3015
|
throw { message: ResolveError.NoAppsFound, reason: `There are no apps handling the passed intent ${intent}` };
|
|
@@ -1822,14 +3030,15 @@ class IntentsController {
|
|
|
1822
3030
|
});
|
|
1823
3031
|
}
|
|
1824
3032
|
findIntentsByContext({ commandId, context, resultType }) {
|
|
3033
|
+
var _a, _b;
|
|
1825
3034
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1826
3035
|
yield this.glueController.gluePromise;
|
|
1827
|
-
this.logger.info(`[${commandId}] - findIntentsByContext() invoked for context type ${context.type} and resultType ${resultType}`);
|
|
3036
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - findIntentsByContext() invoked for context type ${context.type} and resultType ${resultType}`);
|
|
1828
3037
|
const glueIntents = yield this.glueController.findIntents({ contextType: context.type, resultType });
|
|
1829
3038
|
if (!glueIntents.length) {
|
|
1830
3039
|
throw { message: ResolveError.NoAppsFound, reason: `No apps registering intent with contextType ${context.type} ${resultType ? `and resultType ${resultType}` : ""}` };
|
|
1831
3040
|
}
|
|
1832
|
-
this.logger.info(`[${commandId}] - parsing glue intents to fdc3 intents and returning`);
|
|
3041
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - parsing glue intents to fdc3 intents and returning`);
|
|
1833
3042
|
return glueIntents.map((glueIntent) => {
|
|
1834
3043
|
const intentWithFilteredHandlers = this.getGlueIntentWithFilteredHandlers(glueIntent, { contextType: context.type, resultType });
|
|
1835
3044
|
return this.convertGlue42IntentToFDC3Intent(intentWithFilteredHandlers);
|
|
@@ -1837,10 +3046,10 @@ class IntentsController {
|
|
|
1837
3046
|
});
|
|
1838
3047
|
}
|
|
1839
3048
|
raiseIntent({ commandId, intent, context, target }) {
|
|
1840
|
-
var _a;
|
|
3049
|
+
var _a, _b, _c, _d, _e;
|
|
1841
3050
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1842
3051
|
yield this.glueController.gluePromise;
|
|
1843
|
-
this.logger.info(`[${commandId}] - raiseIntent() invoked for intent ${intent} with contextType: ${context.type} and target: ${target}`);
|
|
3052
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - raiseIntent() invoked for intent ${intent} with contextType: ${context.type} and target: ${target}`);
|
|
1844
3053
|
const glueContext = { type: context.type, data: Object.assign({}, context) };
|
|
1845
3054
|
const searchedGlueIntent = (yield this.glueController.findIntents({ name: intent })).find(glueIntent => glueIntent.name === intent);
|
|
1846
3055
|
if (!searchedGlueIntent) {
|
|
@@ -1848,18 +3057,18 @@ class IntentsController {
|
|
|
1848
3057
|
}
|
|
1849
3058
|
const filteredGlueIntent = this.filterGlueIntentHandlers({ commandId, intent: searchedGlueIntent, context, target });
|
|
1850
3059
|
if (!target) {
|
|
1851
|
-
this.logger.info(`[${commandId}] - raising intent ${intent} with contextType ${context.type} and handlers ${filteredGlueIntent.handlers.map(h => h.applicationName && h.instanceId)}`);
|
|
3060
|
+
(_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)}`);
|
|
1852
3061
|
return this.invokeRaiseIntent(commandId, { intent, context: glueContext, handlers: filteredGlueIntent.handlers });
|
|
1853
3062
|
}
|
|
1854
3063
|
if (typeof target === "string" || !target.instanceId) {
|
|
1855
|
-
this.logger.info(`[${commandId}] - target app ${target.appId} is a valid handler. Raising intent ${intent} with contextType ${context.type} and handlers ${filteredGlueIntent.handlers}`);
|
|
3064
|
+
(_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}`);
|
|
1856
3065
|
return this.invokeRaiseIntent(commandId, {
|
|
1857
3066
|
intent,
|
|
1858
3067
|
context: glueContext,
|
|
1859
|
-
target: { app: target.appId, instance: (
|
|
3068
|
+
target: { app: target.appId, instance: (_d = filteredGlueIntent.handlers.find((h) => h.instanceId)) === null || _d === void 0 ? void 0 : _d.instanceId }
|
|
1860
3069
|
});
|
|
1861
3070
|
}
|
|
1862
|
-
this.logger.info(`[${commandId}] - raising intent ${intent} with contextType ${context.type} to target instance of app ${target.appId} and id ${target.instanceId}`);
|
|
3071
|
+
(_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}`);
|
|
1863
3072
|
return this.invokeRaiseIntent(commandId, {
|
|
1864
3073
|
intent,
|
|
1865
3074
|
context: glueContext,
|
|
@@ -1868,24 +3077,43 @@ class IntentsController {
|
|
|
1868
3077
|
});
|
|
1869
3078
|
}
|
|
1870
3079
|
raiseIntentForContext({ commandId, context, target }) {
|
|
3080
|
+
var _a, _b, _c;
|
|
1871
3081
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1872
3082
|
yield this.glueController.gluePromise;
|
|
1873
|
-
this.logger.info(`[${commandId}] - raiseIntentForContext() invoked with contextType ${context.type} and target ${target}`);
|
|
1874
|
-
const
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
reason: `No apps registering intent with contextType ${context.type} ${target ? `and target ${JSON.stringify(target)}` : ""}`
|
|
1879
|
-
};
|
|
3083
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - raiseIntentForContext() invoked with contextType ${context.type} and target ${target}`);
|
|
3084
|
+
const filteredHandlersMethodExist = this.glueController.doesFilterHandlersExist();
|
|
3085
|
+
const getIntentsMethodExist = this.glueController.doesGetIntentsExist();
|
|
3086
|
+
if (!filteredHandlersMethodExist || !getIntentsMethodExist || target) {
|
|
3087
|
+
return this.legacyRaiseIntentForContext({ commandId, context, target });
|
|
1880
3088
|
}
|
|
1881
|
-
|
|
3089
|
+
const filteredHandlersResPromise = this.glueController.filterHandlers({ contextTypes: [context.type] })
|
|
3090
|
+
.catch((err) => {
|
|
3091
|
+
throw this.parseIoToFdc3Error(err);
|
|
3092
|
+
});
|
|
3093
|
+
const { handlers } = yield filteredHandlersResPromise;
|
|
3094
|
+
if (!handlers.length) {
|
|
3095
|
+
const errorMsg = `${ResolveError.NoAppsFound} - Cannot find Intent Handlers for intents with context type ${context.type}`;
|
|
3096
|
+
(_b = this._logger) === null || _b === void 0 ? void 0 : _b.warn(`[${commandId}] - ${errorMsg}`);
|
|
3097
|
+
throw new Error(ResolveError.NoAppsFound);
|
|
3098
|
+
}
|
|
3099
|
+
if (handlers.length > 1) {
|
|
3100
|
+
return this.legacyRaiseIntentForContext({ commandId, context, target });
|
|
3101
|
+
}
|
|
3102
|
+
const handler = handlers[0];
|
|
3103
|
+
const { intents } = yield this.glueController.getIntents(handler);
|
|
3104
|
+
const validIntent = intents.find((intentInfo) => { var _a; return (_a = intentInfo.contextTypes) === null || _a === void 0 ? void 0 : _a.includes(context.type); });
|
|
3105
|
+
if (!validIntent) {
|
|
3106
|
+
(_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}`);
|
|
3107
|
+
throw new Error(ResolveError.IntentDeliveryFailed);
|
|
3108
|
+
}
|
|
3109
|
+
return this.invokeRaiseIntent(commandId, { intent: validIntent.intent, context, target: { app: handler.applicationName, instance: handler.instanceId } });
|
|
1882
3110
|
});
|
|
1883
3111
|
}
|
|
1884
3112
|
addIntentListener({ commandId, intent, handler }) {
|
|
1885
|
-
var _a, _b;
|
|
3113
|
+
var _a, _b, _c;
|
|
1886
3114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1887
3115
|
yield this.glueController.gluePromise;
|
|
1888
|
-
this.logger.info(`[${commandId}] - addIntentListener() invoked for intent ${intent}`);
|
|
3116
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - addIntentListener() invoked for intent ${intent}`);
|
|
1889
3117
|
const wrappedHandler = this.getWrappedIntentHandler(handler);
|
|
1890
3118
|
const myInstance = this.glueController.getMyInteropInstance();
|
|
1891
3119
|
const myApplication = this.glueController.getApplication(myInstance.applicationName);
|
|
@@ -1893,11 +3121,11 @@ class IntentsController {
|
|
|
1893
3121
|
const globalBrowserNamespace = window.glue42core || window.iobrowser;
|
|
1894
3122
|
const globalDesktopNamespace = window.glue42gd || window.iodesktop;
|
|
1895
3123
|
if (globalBrowserNamespace) {
|
|
1896
|
-
appConfigIntentDef = (
|
|
3124
|
+
appConfigIntentDef = (_b = myApplication === null || myApplication === void 0 ? void 0 : myApplication.userProperties.intents) === null || _b === void 0 ? void 0 : _b.find((appIntent) => appIntent.name === intent);
|
|
1897
3125
|
}
|
|
1898
3126
|
if (globalDesktopNamespace) {
|
|
1899
3127
|
const appConfig = yield myApplication.getConfiguration();
|
|
1900
|
-
appConfigIntentDef = (
|
|
3128
|
+
appConfigIntentDef = (_c = appConfig === null || appConfig === void 0 ? void 0 : appConfig.intents) === null || _c === void 0 ? void 0 : _c.find((appIntent) => appIntent.name === intent);
|
|
1901
3129
|
}
|
|
1902
3130
|
const intentRequest = {
|
|
1903
3131
|
intent,
|
|
@@ -1912,32 +3140,34 @@ class IntentsController {
|
|
|
1912
3140
|
});
|
|
1913
3141
|
}
|
|
1914
3142
|
filterGlueIntentHandlers({ commandId, intent, context, target }) {
|
|
3143
|
+
var _a, _b;
|
|
1915
3144
|
let filteredGlueIntent;
|
|
1916
3145
|
filteredGlueIntent = this.filterIntentHandlersByContext(intent, context);
|
|
1917
3146
|
if (!target) {
|
|
1918
|
-
this.logger.info(`[${commandId}] - There's no passed target, intent handlers are filtered only by context type`);
|
|
3147
|
+
(_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`);
|
|
1919
3148
|
return filteredGlueIntent;
|
|
1920
3149
|
}
|
|
1921
|
-
this.logger.log(`[${commandId}] - filtering handlers by target (${JSON.stringify(target)}) for intent ${intent.name}`);
|
|
3150
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log(`[${commandId}] - filtering handlers by target (${JSON.stringify(target)}) for intent ${intent.name}`);
|
|
1922
3151
|
filteredGlueIntent = this.filterIntentHandlersByTarget({ intent, target, commandId });
|
|
1923
3152
|
return filteredGlueIntent;
|
|
1924
3153
|
}
|
|
1925
3154
|
filterIntentHandlersByTarget({ intent, target, commandId }) {
|
|
3155
|
+
var _a, _b, _c, _d;
|
|
1926
3156
|
const appName = typeof target === "string" ? target : target.appId;
|
|
1927
3157
|
const instanceId = typeof target === "string" ? undefined : target.instanceId;
|
|
1928
|
-
this.logger.info(`[${commandId}] - Checking if application with name ${appName} exists`);
|
|
3158
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - Checking if application with name ${appName} exists`);
|
|
1929
3159
|
const app = this.glueController.getApplication(appName);
|
|
1930
3160
|
const serverInstances = this.serverInstanceAsIntentHandler(intent.name);
|
|
1931
3161
|
if (!app && (typeof target === "string" || !target.instanceId || !serverInstances.length)) {
|
|
1932
3162
|
throw { message: ResolveError.TargetAppUnavailable, reason: `There's no app with appId ${appName}` };
|
|
1933
3163
|
}
|
|
1934
|
-
this.logger.info(`[${commandId}] - target app ${appName} found. Filtering handlers by applicationName: ${appName}`);
|
|
3164
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - target app ${appName} found. Filtering handlers by applicationName: ${appName}`);
|
|
1935
3165
|
const validHandlersByApplicationName = intent.handlers.filter((handler) => handler.applicationName === appName);
|
|
1936
3166
|
if (!validHandlersByApplicationName.length) {
|
|
1937
3167
|
throw { message: ResolveError.NoAppsFound, reason: `Intent ${intent.name} exists but there's no app with appId ${appName} registering it` };
|
|
1938
3168
|
}
|
|
1939
3169
|
if (!instanceId) {
|
|
1940
|
-
this.logger.log(`[${commandId}] - returning all handlers for intent ${intent.name} and target: ${JSON.stringify(target)}`);
|
|
3170
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.log(`[${commandId}] - returning all handlers for intent ${intent.name} and target: ${JSON.stringify(target)}`);
|
|
1941
3171
|
return { name: intent.name, handlers: validHandlersByApplicationName };
|
|
1942
3172
|
}
|
|
1943
3173
|
const isValidInstanceOfTheApp = app
|
|
@@ -1946,7 +3176,7 @@ class IntentsController {
|
|
|
1946
3176
|
if (!isValidInstanceOfTheApp) {
|
|
1947
3177
|
throw { message: ResolveError.TargetInstanceUnavailable, reason: `There's no instance with id ${instanceId} of the passed app ${appName}` };
|
|
1948
3178
|
}
|
|
1949
|
-
this.logger.info(`[${commandId}] - Filtering handlers by instanceId: ${instanceId}`);
|
|
3179
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.info(`[${commandId}] - Filtering handlers by instanceId: ${instanceId}`);
|
|
1950
3180
|
const validHandlersByInstanceId = validHandlersByApplicationName.filter((handler) => handler.instanceId === instanceId);
|
|
1951
3181
|
if (!validHandlersByInstanceId.length) {
|
|
1952
3182
|
throw { message: ResolveError.IntentDeliveryFailed, reason: `There's no instance with id ${instanceId} of app ${appName} registering intent ${intent.name}` };
|
|
@@ -1968,9 +3198,17 @@ class IntentsController {
|
|
|
1968
3198
|
return filteredGlueIntent;
|
|
1969
3199
|
}
|
|
1970
3200
|
getResult(commandId, glueIntentResult) {
|
|
3201
|
+
var _a, _b, _c;
|
|
1971
3202
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1972
|
-
this.logger.info(`[${commandId}] - getResult() of IntentResolution invoked`);
|
|
3203
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getResult() of IntentResolution invoked`);
|
|
1973
3204
|
const { result } = glueIntentResult;
|
|
3205
|
+
if (result.fdc3error) {
|
|
3206
|
+
throw result.fdc3error;
|
|
3207
|
+
}
|
|
3208
|
+
if (!result || typeof result !== "object" || Array.isArray(result) || (isValidNonEmptyObject(result) && !result.fdc3intentContext && !result.fdc3intentChannel && !result.fdc3error)) {
|
|
3209
|
+
(_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`);
|
|
3210
|
+
throw new Error(ResultError.NoResultReturned);
|
|
3211
|
+
}
|
|
1974
3212
|
if (!isValidNonEmptyObject(result)) {
|
|
1975
3213
|
return;
|
|
1976
3214
|
}
|
|
@@ -1999,7 +3237,7 @@ class IntentsController {
|
|
|
1999
3237
|
}
|
|
2000
3238
|
};
|
|
2001
3239
|
yield this.glueController.invokeSystemMethod(joinChannelArgs, glueIntentResult.handler.instanceId);
|
|
2002
|
-
this.logger.info(`[${commandId}] - returning private channel`);
|
|
3240
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - returning private channel`);
|
|
2003
3241
|
return channel.toApi();
|
|
2004
3242
|
});
|
|
2005
3243
|
}
|
|
@@ -2032,10 +3270,10 @@ class IntentsController {
|
|
|
2032
3270
|
if (isContext(data)) {
|
|
2033
3271
|
return IntentHandlerResultTypes.Context;
|
|
2034
3272
|
}
|
|
2035
|
-
throw new Error("Async handler function should return a promise that resolves to a Context or Channel");
|
|
2036
3273
|
}
|
|
2037
3274
|
getWrappedIntentHandler(handler) {
|
|
2038
3275
|
const wrappedHandler = (glue42Context, caller) => __awaiter(this, void 0, void 0, function* () {
|
|
3276
|
+
var _a;
|
|
2039
3277
|
const contextMetadata = caller
|
|
2040
3278
|
? {
|
|
2041
3279
|
source: {
|
|
@@ -2044,11 +3282,23 @@ class IntentsController {
|
|
|
2044
3282
|
}
|
|
2045
3283
|
}
|
|
2046
3284
|
: undefined;
|
|
2047
|
-
|
|
3285
|
+
let handlerResult;
|
|
3286
|
+
try {
|
|
3287
|
+
handlerResult = yield handler(Object.assign(Object.assign({}, glue42Context.data), { type: glue42Context.type || "" }), contextMetadata);
|
|
3288
|
+
}
|
|
3289
|
+
catch (error) {
|
|
3290
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(typeof error === "string" ? error : error.message || JSON.stringify(error));
|
|
3291
|
+
throw new Error(ResultError.IntentHandlerRejected);
|
|
3292
|
+
}
|
|
2048
3293
|
if (!handlerResult) {
|
|
2049
3294
|
return;
|
|
2050
3295
|
}
|
|
2051
3296
|
const handlerResultType = this.getResultType(handlerResult);
|
|
3297
|
+
if (!handlerResultType) {
|
|
3298
|
+
return {
|
|
3299
|
+
fdc3error: { message: ResultError.NoResultReturned, reason: "The intent handler exited without returning a valid result - a promise resolving to a Context, Channel object or void" }
|
|
3300
|
+
};
|
|
3301
|
+
}
|
|
2052
3302
|
return handlerResultType === IntentHandlerResultTypes.Channel
|
|
2053
3303
|
? { fdc3intentChannel: extractChannelMetadata(handlerResult) }
|
|
2054
3304
|
: { fdc3intentContext: { contextType: handlerResult.type, payload: handlerResult } };
|
|
@@ -2092,13 +3342,34 @@ class IntentsController {
|
|
|
2092
3342
|
};
|
|
2093
3343
|
}
|
|
2094
3344
|
catch (error) {
|
|
2095
|
-
throw
|
|
3345
|
+
throw this.parseIoToFdc3Error(error);
|
|
3346
|
+
}
|
|
3347
|
+
});
|
|
3348
|
+
}
|
|
3349
|
+
parseIoToFdc3Error(error) {
|
|
3350
|
+
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); }));
|
|
3351
|
+
const fdc3Error = ioError ? this.ioToFDC3ErrorsDict[ioError] : ResolveError.IntentDeliveryFailed;
|
|
3352
|
+
const stringifiedError = typeof error === "string" ? error : JSON.stringify(error);
|
|
3353
|
+
const reason = error instanceof Error ? error.message : stringifiedError;
|
|
3354
|
+
return { message: fdc3Error, reason };
|
|
3355
|
+
}
|
|
3356
|
+
legacyRaiseIntentForContext({ commandId, context, target }) {
|
|
3357
|
+
var _a;
|
|
3358
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3359
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - raiseIntentForContext() invoked with contextType ${context.type} and target ${target}`);
|
|
3360
|
+
const appIntents = yield this.findIntentsByContext({ commandId, context });
|
|
3361
|
+
if (!appIntents || appIntents.length === 0) {
|
|
3362
|
+
throw {
|
|
3363
|
+
message: ResolveError.NoAppsFound,
|
|
3364
|
+
reason: `No apps registering intent with contextType ${context.type} ${target ? `and target ${JSON.stringify(target)}` : ""}`
|
|
3365
|
+
};
|
|
2096
3366
|
}
|
|
3367
|
+
return this.raiseIntent({ commandId, intent: appIntents[0].intent.name, context, target });
|
|
2097
3368
|
});
|
|
2098
3369
|
}
|
|
2099
3370
|
}
|
|
2100
3371
|
|
|
2101
|
-
var version = "2.
|
|
3372
|
+
var version = "2.2.0";
|
|
2102
3373
|
|
|
2103
3374
|
class ApplicationsController {
|
|
2104
3375
|
constructor(glueController, appsStateStore, glueEventsController) {
|
|
@@ -2114,9 +3385,10 @@ class ApplicationsController {
|
|
|
2114
3385
|
return this._logger;
|
|
2115
3386
|
}
|
|
2116
3387
|
open({ commandId, target, context }) {
|
|
3388
|
+
var _a, _b, _c, _d;
|
|
2117
3389
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2118
3390
|
yield this.glueController.gluePromise;
|
|
2119
|
-
this.logger.log(`[${commandId}] - open() invoked with target ${target} ${context ? `and contextType ${context.type}` : ""}`);
|
|
3391
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - open() invoked with target ${target} ${context ? `and contextType ${context.type}` : ""}`);
|
|
2120
3392
|
const name = typeof target === "object" ? target.appId : target;
|
|
2121
3393
|
const app = this.glueController.getApplication(name);
|
|
2122
3394
|
if (!app) {
|
|
@@ -2124,13 +3396,13 @@ class ApplicationsController {
|
|
|
2124
3396
|
}
|
|
2125
3397
|
if (context) {
|
|
2126
3398
|
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2127
|
-
this.logger.info(`[${commandId}] - opening app ${app} with startup context`);
|
|
3399
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - opening app ${app} with startup context`);
|
|
2128
3400
|
return this.openAppWithContext(app, context);
|
|
2129
3401
|
}
|
|
2130
3402
|
try {
|
|
2131
|
-
this.logger.info(`[${commandId}] - opening app ${app}`);
|
|
3403
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - opening app ${app}`);
|
|
2132
3404
|
const glueInst = yield app.start();
|
|
2133
|
-
this.logger.info(`[${commandId}] - instance with id ${glueInst.id} started`);
|
|
3405
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.info(`[${commandId}] - instance with id ${glueInst.id} started`);
|
|
2134
3406
|
return this.parseGlueInstToAppIdentifier(glueInst);
|
|
2135
3407
|
}
|
|
2136
3408
|
catch (error) {
|
|
@@ -2139,9 +3411,10 @@ class ApplicationsController {
|
|
|
2139
3411
|
});
|
|
2140
3412
|
}
|
|
2141
3413
|
findInstances({ commandId, appIdentifier }) {
|
|
3414
|
+
var _a, _b;
|
|
2142
3415
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2143
3416
|
yield this.glueController.gluePromise;
|
|
2144
|
-
this.logger.info(`[${commandId}] - findInstances() invoked with appIdentifier ${appIdentifier}`);
|
|
3417
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - findInstances() invoked with appIdentifier ${appIdentifier}`);
|
|
2145
3418
|
const { appId } = appIdentifier;
|
|
2146
3419
|
const app = this.glueController.getApplication(appId);
|
|
2147
3420
|
if (!app) {
|
|
@@ -2149,41 +3422,44 @@ class ApplicationsController {
|
|
|
2149
3422
|
}
|
|
2150
3423
|
const glueInstances = this.glueController.getApplicationInstances(appId);
|
|
2151
3424
|
const fdc3Instances = glueInstances.map(glueInst => this.parseGlueInstToAppIdentifier(glueInst));
|
|
2152
|
-
this.logger.info(`[${commandId}] - ids of opened instances for appIdentifier ${appIdentifier}: ${JSON.stringify(fdc3Instances.map(inst => inst.instanceId))}`);
|
|
3425
|
+
(_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))}`);
|
|
2153
3426
|
return fdc3Instances;
|
|
2154
3427
|
});
|
|
2155
3428
|
}
|
|
2156
3429
|
getAppMetadata({ commandId, appIdentifier }) {
|
|
3430
|
+
var _a, _b, _c;
|
|
2157
3431
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2158
3432
|
yield this.glueController.gluePromise;
|
|
2159
|
-
this.logger.info(`[${commandId}] - getAppMetadata() invoked with appIdentifier ${appIdentifier}`);
|
|
3433
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getAppMetadata() invoked with appIdentifier ${appIdentifier}`);
|
|
2160
3434
|
const { appId, instanceId } = appIdentifier;
|
|
2161
3435
|
const app = this.glueController.getApplication(appId);
|
|
2162
3436
|
if (!app) {
|
|
2163
3437
|
throw { message: OpenError.AppNotFound, reason: `Cannot find application with appId: ${appId}` };
|
|
2164
3438
|
}
|
|
2165
3439
|
if (!instanceId) {
|
|
2166
|
-
this.logger.info(`[${commandId}] - no opened instances found. Parsing app ${app}`);
|
|
3440
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - no opened instances found. Parsing app ${app}`);
|
|
2167
3441
|
return this.parseGlueAppToAppMetadata(app);
|
|
2168
3442
|
}
|
|
2169
3443
|
const instance = this.glueController.getAppInstanceById(instanceId);
|
|
2170
3444
|
const appMetadata = this.parseGlueAppToAppMetadata(app, instance);
|
|
2171
|
-
this.logger.info(`[${commandId}] - found app metadata: ${appMetadata}`);
|
|
3445
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - found app metadata: ${appMetadata}`);
|
|
2172
3446
|
return appMetadata;
|
|
2173
3447
|
});
|
|
2174
3448
|
}
|
|
2175
3449
|
getInfo({ commandId }) {
|
|
3450
|
+
var _a;
|
|
2176
3451
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2177
3452
|
yield this.glueController.gluePromise;
|
|
2178
|
-
this.logger.info(`${commandId} - getInfo() invoked`);
|
|
3453
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`${commandId} - getInfo() invoked`);
|
|
2179
3454
|
const appMetadata = yield this.getCurrentAppMetadata();
|
|
2180
3455
|
return {
|
|
2181
3456
|
provider: "io.Connect",
|
|
2182
3457
|
providerVersion: version,
|
|
2183
|
-
fdc3Version: "2.
|
|
3458
|
+
fdc3Version: "2.1",
|
|
2184
3459
|
optionalFeatures: {
|
|
2185
3460
|
OriginatingAppMetadata: true,
|
|
2186
|
-
UserChannelMembershipAPIs: true
|
|
3461
|
+
UserChannelMembershipAPIs: true,
|
|
3462
|
+
DesktopAgentBridging: false
|
|
2187
3463
|
},
|
|
2188
3464
|
appMetadata
|
|
2189
3465
|
};
|
|
@@ -2307,22 +3583,23 @@ class ChannelsController {
|
|
|
2307
3583
|
});
|
|
2308
3584
|
}
|
|
2309
3585
|
addContextListener({ commandId, handler, contextType, channelId }) {
|
|
2310
|
-
var _a;
|
|
3586
|
+
var _a, _b, _c;
|
|
2311
3587
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2312
3588
|
yield this.initDonePromise;
|
|
2313
|
-
this.logger.info(`[${commandId}] - addContextListener() invoked for contextType ${contextType} and channelId ${channelId}`);
|
|
3589
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - addContextListener() invoked for contextType ${contextType} and channelId ${channelId}`);
|
|
2314
3590
|
if (this.invokeContextHandlerWithStartupContext && !channelId) {
|
|
2315
|
-
this.logger.info(`[${commandId}] - trying to invoke context handler with window context`);
|
|
2316
|
-
this.handleWindowContextOnOpening(commandId, handler, contextType).catch((err) => this.logger.warn(`[${commandId}] - ${err}`));
|
|
3591
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - trying to invoke context handler with window context`);
|
|
3592
|
+
this.handleWindowContextOnOpening(commandId, handler, contextType).catch((err) => { var _a; return (_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(`[${commandId}] - ${err}`); });
|
|
2317
3593
|
}
|
|
2318
|
-
const channelIdToSubscribeTo = channelId || ((
|
|
3594
|
+
const channelIdToSubscribeTo = channelId || ((_c = this.channelsStateStore.currentChannel) === null || _c === void 0 ? void 0 : _c.id);
|
|
2319
3595
|
return this.addContextListenerByChannelId({ commandId, handler, invokedOnChannelModel: !!channelId, channelId: channelIdToSubscribeTo, contextType });
|
|
2320
3596
|
});
|
|
2321
3597
|
}
|
|
2322
3598
|
broadcast(commandId, context, channelId) {
|
|
3599
|
+
var _a;
|
|
2323
3600
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2324
3601
|
yield this.initDonePromise;
|
|
2325
|
-
this.logger.info(`[${commandId}] - broadcast() invoked with contextType ${context.type} and channelId ${channelId}`);
|
|
3602
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - broadcast() invoked with contextType ${context.type} and channelId ${channelId}`);
|
|
2326
3603
|
const canBroadcast = this.isBroadcastPermitted(commandId, channelId);
|
|
2327
3604
|
if (!canBroadcast) {
|
|
2328
3605
|
return;
|
|
@@ -2332,16 +3609,18 @@ class ChannelsController {
|
|
|
2332
3609
|
});
|
|
2333
3610
|
}
|
|
2334
3611
|
getUserChannels(commandId) {
|
|
3612
|
+
var _a;
|
|
2335
3613
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2336
3614
|
yield this.initDonePromise;
|
|
2337
|
-
this.logger.info(`[${commandId}] - getUserChannels() invoked`);
|
|
3615
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getUserChannels() invoked`);
|
|
2338
3616
|
return Object.values(this.channelsStateStore.userChannels);
|
|
2339
3617
|
});
|
|
2340
3618
|
}
|
|
2341
3619
|
getOrCreateChannel({ commandId, channelId }) {
|
|
3620
|
+
var _a;
|
|
2342
3621
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2343
3622
|
yield this.initDonePromise;
|
|
2344
|
-
this.logger.info(`[${commandId}] - getOrCreateChannel() invoked for channel with id ${channelId}`);
|
|
3623
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getOrCreateChannel() invoked for channel with id ${channelId}`);
|
|
2345
3624
|
const isUserChannel = this.isUserChannel(channelId);
|
|
2346
3625
|
if (isUserChannel) {
|
|
2347
3626
|
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" };
|
|
@@ -2354,9 +3633,10 @@ class ChannelsController {
|
|
|
2354
3633
|
});
|
|
2355
3634
|
}
|
|
2356
3635
|
joinUserChannel({ commandId, channelId }) {
|
|
3636
|
+
var _a, _b;
|
|
2357
3637
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2358
3638
|
yield this.initDonePromise;
|
|
2359
|
-
this.logger.info(`[${commandId}] - joinUserChannel() invoked for channel with id ${channelId}`);
|
|
3639
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - joinUserChannel() invoked for channel with id ${channelId}`);
|
|
2360
3640
|
const isAppChannel = this.doesAppChannelExist(channelId);
|
|
2361
3641
|
if (isAppChannel) {
|
|
2362
3642
|
throw { message: ChannelError.AccessDenied, reason: "Cannot join an app channel" };
|
|
@@ -2367,53 +3647,56 @@ class ChannelsController {
|
|
|
2367
3647
|
}
|
|
2368
3648
|
const glueChannelName = this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId);
|
|
2369
3649
|
this.channelsStateStore.currentChannel = channelToJoin;
|
|
2370
|
-
this.logger.info(`[${commandId}] - joining fdc3 user channel with id ${channelId} (underlying glue channel: ${glueChannelName})`);
|
|
3650
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - joining fdc3 user channel with id ${channelId} (underlying glue channel: ${glueChannelName})`);
|
|
2371
3651
|
yield this.glueController.joinChannel(glueChannelName);
|
|
2372
3652
|
});
|
|
2373
3653
|
}
|
|
2374
3654
|
getCurrentChannel(commandId) {
|
|
3655
|
+
var _a;
|
|
2375
3656
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2376
3657
|
yield this.initDonePromise;
|
|
2377
|
-
this.logger.info(`[${commandId}] - getCurrentChannel() invoked`);
|
|
3658
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getCurrentChannel() invoked`);
|
|
2378
3659
|
return this.channelsStateStore.currentChannel;
|
|
2379
3660
|
});
|
|
2380
3661
|
}
|
|
2381
3662
|
leaveCurrentChannel(commandId) {
|
|
3663
|
+
var _a, _b, _c;
|
|
2382
3664
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2383
3665
|
yield this.initDonePromise;
|
|
2384
|
-
this.logger.info(`[${commandId}] - leaveCurrentChannel() invoked`);
|
|
3666
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - leaveCurrentChannel() invoked`);
|
|
2385
3667
|
if (!this.channelsStateStore.currentChannel) {
|
|
2386
|
-
this.logger.info(`[${commandId}] - no channel to leave`);
|
|
3668
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - no channel to leave`);
|
|
2387
3669
|
return;
|
|
2388
3670
|
}
|
|
2389
3671
|
yield this.glueController.leaveChannel();
|
|
2390
3672
|
this.channelsStateStore.currentChannel = null;
|
|
2391
|
-
this.logger.info(`[${commandId}] - current channel is left. unsubscribing from all listeners`);
|
|
3673
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - current channel is left. unsubscribing from all listeners`);
|
|
2392
3674
|
});
|
|
2393
3675
|
}
|
|
2394
3676
|
getContextForChannel({ commandId, channelId, contextType }) {
|
|
3677
|
+
var _a, _b, _c, _d, _e;
|
|
2395
3678
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2396
3679
|
yield this.initDonePromise;
|
|
2397
|
-
this.logger.info(`[${commandId}] - getContextForChannel() invoked for channel with id ${channelId}`);
|
|
3680
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - getContextForChannel() invoked for channel with id ${channelId}`);
|
|
2398
3681
|
const isUserChannel = this.isUserChannel(channelId);
|
|
2399
3682
|
if (!contextType) {
|
|
2400
|
-
this.logger.info(`[${commandId}] - retrieving latest context broadcasted on channel with id ${channelId}`);
|
|
3683
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - retrieving latest context broadcasted on channel with id ${channelId}`);
|
|
2401
3684
|
let context;
|
|
2402
3685
|
if (isUserChannel) {
|
|
2403
3686
|
const glueChannelName = this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId);
|
|
2404
3687
|
const glueChannelWithPrefix = this.channelsParser.mapChannelNameToContextName(glueChannelName);
|
|
2405
|
-
this.logger.info(`[${commandId}] - getting context for user channel with id ${channelId} (underlying glue channel ${glueChannelName})`);
|
|
3688
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - getting context for user channel with id ${channelId} (underlying glue channel ${glueChannelName})`);
|
|
2406
3689
|
context = yield this.glueController.getContext(glueChannelWithPrefix);
|
|
2407
3690
|
}
|
|
2408
3691
|
else {
|
|
2409
|
-
this.logger.info(`[${commandId}] - getting context for app channel with id ${channelId}`);
|
|
3692
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.info(`[${commandId}] - getting context for app channel with id ${channelId}`);
|
|
2410
3693
|
context = yield this.glueController.getContext(channelId);
|
|
2411
3694
|
}
|
|
2412
3695
|
return context.latest_fdc3_type
|
|
2413
3696
|
? this.channelsParser.parseContextsDataToInitialFDC3Data(context)
|
|
2414
3697
|
: null;
|
|
2415
3698
|
}
|
|
2416
|
-
this.logger.info(`[${commandId}] Retrieving latest context of type ${contextType} broadcasted on ${isUserChannel ? "user" : "app"} channel with id ${channelId}`);
|
|
3699
|
+
(_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}`);
|
|
2417
3700
|
const parsedType = this.channelsParser.mapFDC3TypeToChannelsDelimiter(contextType);
|
|
2418
3701
|
const { data } = isUserChannel
|
|
2419
3702
|
? yield this.glueController.getChannel(this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId))
|
|
@@ -2424,9 +3707,10 @@ class ChannelsController {
|
|
|
2424
3707
|
});
|
|
2425
3708
|
}
|
|
2426
3709
|
createPrivateChannel(commandId) {
|
|
3710
|
+
var _a;
|
|
2427
3711
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2428
3712
|
yield this.initDonePromise;
|
|
2429
|
-
this.logger.info(`[${commandId}] - createPrivateChannel() invoked`);
|
|
3713
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - createPrivateChannel() invoked`);
|
|
2430
3714
|
const channelId = `${PrivateChannelPrefix}${nanoid()}`;
|
|
2431
3715
|
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2432
3716
|
const pc = this.buildPrivateChannel(channelId, commandId, true);
|
|
@@ -2450,26 +3734,30 @@ class ChannelsController {
|
|
|
2450
3734
|
return this.glueController.getMyInteropInstance();
|
|
2451
3735
|
}
|
|
2452
3736
|
addClientToPrivateChannel(commandId, channelId, clientId) {
|
|
3737
|
+
var _a;
|
|
2453
3738
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2454
|
-
this.logger.info(`[${commandId}] - client with id ${clientId} added to private channel with id ${channelId}`);
|
|
3739
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - client with id ${clientId} added to private channel with id ${channelId}`);
|
|
2455
3740
|
yield this.glueController.updateContext(channelId, { clientId });
|
|
2456
3741
|
});
|
|
2457
3742
|
}
|
|
2458
3743
|
isPrivateChannelDisconnected({ commandId, channelId }) {
|
|
3744
|
+
var _a;
|
|
2459
3745
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2460
|
-
this.logger.info(`[${commandId}] - checking if private channel with id ${channelId} is disconnected`);
|
|
3746
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - checking if private channel with id ${channelId} is disconnected`);
|
|
2461
3747
|
const context = yield this.glueController.getContext(channelId);
|
|
2462
3748
|
return !!context.disconnected;
|
|
2463
3749
|
});
|
|
2464
3750
|
}
|
|
2465
3751
|
subscribeOnInstanceStop(channelId, handler, commandId) {
|
|
2466
|
-
|
|
3752
|
+
var _a;
|
|
3753
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - subscribing onInstanceStopped callback for channel with id ${channelId}`);
|
|
2467
3754
|
return this.glueController.registerOnInstanceStopped(handler.bind(this));
|
|
2468
3755
|
}
|
|
2469
3756
|
buildPrivateChannel(channelId, commandId, isCreator) {
|
|
3757
|
+
var _a;
|
|
2470
3758
|
const logger = this.glueController.initSubLogger(channelId);
|
|
2471
3759
|
const channel = this.buildChannel(ChannelTypes.Private, { id: channelId, logger, isCreator });
|
|
2472
|
-
this.logger.info(`[${commandId}] - private channel with id ${channelId} created. Adding it to the store`);
|
|
3760
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - private channel with id ${channelId} created. Adding it to the store`);
|
|
2473
3761
|
this.channelsStateStore.addPrivateChannel(channel);
|
|
2474
3762
|
return channel;
|
|
2475
3763
|
}
|
|
@@ -2507,70 +3795,73 @@ class ChannelsController {
|
|
|
2507
3795
|
});
|
|
2508
3796
|
}
|
|
2509
3797
|
isBroadcastPermitted(commandId, channelId) {
|
|
3798
|
+
var _a, _b;
|
|
2510
3799
|
if (channelId) {
|
|
2511
3800
|
return true;
|
|
2512
3801
|
}
|
|
2513
3802
|
if (!this.channelsStateStore.currentChannel) {
|
|
2514
|
-
this.logger.info(`[${commandId}] - invocation of broadcast ignored - no channel to broadcast to`);
|
|
3803
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - invocation of broadcast ignored - no channel to broadcast to`);
|
|
2515
3804
|
console.error("You need to join a user channel in order to broadcast");
|
|
2516
3805
|
return false;
|
|
2517
3806
|
}
|
|
2518
3807
|
if (this.channelsStateStore.currentChannel.type === ChannelTypes.App) {
|
|
2519
|
-
this.logger.info(`[${commandId}] - invocation of broadcast ignored - cannot broadcast on app channel directly`);
|
|
3808
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - invocation of broadcast ignored - cannot broadcast on app channel directly`);
|
|
2520
3809
|
console.error("You can't broadcast to an app channel directly - use channel's broadcast method instead");
|
|
2521
3810
|
return false;
|
|
2522
3811
|
}
|
|
2523
3812
|
return true;
|
|
2524
3813
|
}
|
|
2525
3814
|
handleWindowContextOnOpening(commandId, handler, contextType) {
|
|
3815
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
2526
3816
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2527
3817
|
const myWindow = this.glueController.getMyWindow();
|
|
2528
3818
|
if (!myWindow) {
|
|
2529
|
-
this.logger.trace(`[${commandId}] - Cannot get window context because this is not a Glue window, it's probably an iframe`);
|
|
3819
|
+
(_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`);
|
|
2530
3820
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2531
3821
|
return;
|
|
2532
3822
|
}
|
|
2533
3823
|
const windowContext = yield myWindow.getContext();
|
|
2534
3824
|
if (!windowContext) {
|
|
2535
|
-
this.logger.trace(`[${commandId}] - Cannot get window context because this is not a Glue window, it's probably an iframe`);
|
|
3825
|
+
(_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`);
|
|
2536
3826
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2537
3827
|
return;
|
|
2538
3828
|
}
|
|
2539
3829
|
if (!isValidNonEmptyObject(windowContext) || !windowContext.fdc3) {
|
|
2540
|
-
this.logger.info(`[${commandId}] - addContextListener handler won't be invoked - startup context is empty`);
|
|
3830
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info(`[${commandId}] - addContextListener handler won't be invoked - startup context is empty`);
|
|
2541
3831
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2542
3832
|
return;
|
|
2543
3833
|
}
|
|
2544
3834
|
yield this.glueEventsController.initializeCollaborateMethod();
|
|
2545
3835
|
FDC3StartupContextDecoder.runWithException(windowContext);
|
|
2546
3836
|
const { fdc3 } = windowContext;
|
|
2547
|
-
this.logger.trace(`[${commandId}] - received FDC3 startup context from ${JSON.stringify(fdc3.openApp)} for contextType ${fdc3.context.contextType}`);
|
|
3837
|
+
(_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}`);
|
|
2548
3838
|
const isSameContextType = contextType ? fdc3.context.contextType === contextType : true;
|
|
2549
3839
|
if (!isSameContextType) {
|
|
2550
|
-
this.logger.info(`[${commandId}] - addContextListener handler won't be invoked for contextType ${contextType} for startup context with type: ${fdc3.context.contextType}`);
|
|
3840
|
+
(_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}`);
|
|
2551
3841
|
return;
|
|
2552
3842
|
}
|
|
2553
|
-
this.logger.info(`[${commandId}] - invoking addContextListener handler with startup context with type ${fdc3.context.contextType}`);
|
|
3843
|
+
(_f = this.logger) === null || _f === void 0 ? void 0 : _f.info(`[${commandId}] - invoking addContextListener handler with startup context with type ${fdc3.context.contextType}`);
|
|
2554
3844
|
try {
|
|
2555
3845
|
handler(fdc3.context.payload, { source: fdc3.openApp });
|
|
2556
3846
|
}
|
|
2557
3847
|
catch (error) {
|
|
2558
|
-
this.logger.error(typeof error === "string" ? error : error.message ? JSON.stringify(error.message) : JSON.stringify(error));
|
|
3848
|
+
(_g = this.logger) === null || _g === void 0 ? void 0 : _g.error(typeof error === "string" ? error : error.message ? JSON.stringify(error.message) : JSON.stringify(error));
|
|
2559
3849
|
}
|
|
2560
3850
|
this.invokeContextHandlerWithStartupContext = false;
|
|
2561
|
-
this.logger.trace(`[${commandId}] - invoking response method to with target ${JSON.stringify(fdc3.openApp)}`);
|
|
3851
|
+
(_h = this.logger) === null || _h === void 0 ? void 0 : _h.trace(`[${commandId}] - invoking response method to with target ${JSON.stringify(fdc3.openApp)}`);
|
|
2562
3852
|
yield this.invokeSystemMethod({ action: "startupContextOpened", correlationId: fdc3.collaborationId }, fdc3.openApp.instanceId);
|
|
2563
|
-
this.logger.trace(`[${commandId}] - system method invocation success for 'startupContextOpened' heard`);
|
|
3853
|
+
(_j = this.logger) === null || _j === void 0 ? void 0 : _j.trace(`[${commandId}] - system method invocation success for 'startupContextOpened' heard`);
|
|
2564
3854
|
});
|
|
2565
3855
|
}
|
|
2566
3856
|
getOrCreateAppChannel(commandId, channelId) {
|
|
3857
|
+
var _a, _b;
|
|
2567
3858
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2568
3859
|
const exists = this.doesAppChannelExist(channelId);
|
|
2569
3860
|
if (!exists) {
|
|
2570
|
-
this.logger.info(`[${commandId}] - app channel with id ${channelId} does not exist. Creating one`);
|
|
3861
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - app channel with id ${channelId} does not exist. Creating one`);
|
|
2571
3862
|
yield this.glueController.updateContext(channelId, {});
|
|
2572
3863
|
}
|
|
2573
|
-
this.logger.info(`[${commandId}] - returning app channel with id ${channelId}`);
|
|
3864
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - returning app channel with id ${channelId}`);
|
|
2574
3865
|
const logger = this.glueController.initSubLogger(`app.channel.${channelId}`);
|
|
2575
3866
|
return this.buildChannel(ChannelTypes.App, { id: channelId, logger });
|
|
2576
3867
|
});
|
|
@@ -2585,22 +3876,24 @@ class ChannelsController {
|
|
|
2585
3876
|
return !!this.channelsStateStore.userChannels[channelId];
|
|
2586
3877
|
}
|
|
2587
3878
|
broadcastByChannelId(commandId, channelId, context) {
|
|
3879
|
+
var _a, _b;
|
|
2588
3880
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2589
3881
|
const isUserChannel = this.isUserChannel(channelId);
|
|
2590
3882
|
if (!isUserChannel) {
|
|
2591
|
-
this.logger.info(`[${commandId}] - broadcasting on app channel with id ${channelId}`);
|
|
3883
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - broadcasting on app channel with id ${channelId}`);
|
|
2592
3884
|
return this.glueController.updateContextWithLatestFdc3Type(channelId, context);
|
|
2593
3885
|
}
|
|
2594
3886
|
const glueChannelName = this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId);
|
|
2595
|
-
this.logger.info(`[${commandId}] - broadcasting on fdc3 user channel with id ${channelId} (underlying glue channel: ${glueChannelName})`);
|
|
3887
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - broadcasting on fdc3 user channel with id ${channelId} (underlying glue channel: ${glueChannelName})`);
|
|
2596
3888
|
return this.glueController.channelsUpdate(glueChannelName, context);
|
|
2597
3889
|
});
|
|
2598
3890
|
}
|
|
2599
3891
|
addContextListenerByChannelId({ commandId, channelId, handler, contextType, invokedOnChannelModel }) {
|
|
3892
|
+
var _a, _b;
|
|
2600
3893
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2601
3894
|
const subHandler = parseContextHandler(handler, contextType);
|
|
2602
3895
|
if (!channelId) {
|
|
2603
|
-
this.logger.info(`[${commandId}] - Creating a channel subscription using glue.channels.subscribe`);
|
|
3896
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - Creating a channel subscription using glue.channels.subscribe`);
|
|
2604
3897
|
const unsubscribe = this.glueController.channelsSubscribe(subHandler, contextType);
|
|
2605
3898
|
return { unsubscribe };
|
|
2606
3899
|
}
|
|
@@ -2609,11 +3902,12 @@ class ChannelsController {
|
|
|
2609
3902
|
return this.addContextListenerOnUserChannel({ commandId, channelId, handler: subHandler, contextType, invokedOnChannelModel });
|
|
2610
3903
|
}
|
|
2611
3904
|
if (channelType === ChannelTypes.App) {
|
|
2612
|
-
this.logger.info(`[${commandId}] - subscribing for fdc3 app channel with id ${channelId} (underlying glue context with same name)`);
|
|
3905
|
+
(_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)`);
|
|
2613
3906
|
const unsubscribe = yield this.glueController.contextsSubscribe(channelId, subHandler);
|
|
2614
3907
|
return {
|
|
2615
3908
|
unsubscribe: () => {
|
|
2616
|
-
|
|
3909
|
+
var _a;
|
|
3910
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - invoking unsubscribe for app channel with id ${channelId}`);
|
|
2617
3911
|
unsubscribe();
|
|
2618
3912
|
}
|
|
2619
3913
|
};
|
|
@@ -2622,20 +3916,22 @@ class ChannelsController {
|
|
|
2622
3916
|
});
|
|
2623
3917
|
}
|
|
2624
3918
|
addContextListenerOnUserChannel({ commandId, channelId, handler, invokedOnChannelModel, contextType }) {
|
|
3919
|
+
var _a, _b;
|
|
2625
3920
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2626
3921
|
let unsubscribe;
|
|
2627
3922
|
if (invokedOnChannelModel) {
|
|
2628
3923
|
const contextToSubscribeTo = this.channelsParser.mapChannelNameToContextName(this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId));
|
|
2629
|
-
this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
3924
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
2630
3925
|
unsubscribe = yield this.glueController.contextsSubscribe(contextToSubscribeTo, handler);
|
|
2631
3926
|
}
|
|
2632
3927
|
else {
|
|
2633
|
-
this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
3928
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
|
|
2634
3929
|
unsubscribe = this.glueController.channelsSubscribe(handler, contextType);
|
|
2635
3930
|
}
|
|
2636
3931
|
return {
|
|
2637
3932
|
unsubscribe: () => {
|
|
2638
|
-
|
|
3933
|
+
var _a;
|
|
3934
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.info(`[${commandId}] - invoking unsubscribe for fdc3 user channel with id ${channelId}`);
|
|
2639
3935
|
unsubscribe();
|
|
2640
3936
|
}
|
|
2641
3937
|
};
|
|
@@ -2913,7 +4209,7 @@ class PrivateChannel {
|
|
|
2913
4209
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2914
4210
|
this.setCollaborator(collaborator, commandId);
|
|
2915
4211
|
yield Promise.all(this.myListenerTypesBeforeBound.map((contextType) => {
|
|
2916
|
-
var _a;
|
|
4212
|
+
var _a, _b;
|
|
2917
4213
|
const listenerAddedArgs = {
|
|
2918
4214
|
action: "addedContextListenerOnPrivateChannel",
|
|
2919
4215
|
correlationId: this.id,
|
|
@@ -2922,25 +4218,28 @@ class PrivateChannel {
|
|
|
2922
4218
|
contextType: contextType || undefined
|
|
2923
4219
|
}
|
|
2924
4220
|
};
|
|
2925
|
-
this.logger.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
2926
|
-
return this.channelsController.invokeSystemMethod(listenerAddedArgs, (
|
|
2927
|
-
})).catch((err) => this.logger.error(err));
|
|
4221
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
4222
|
+
return this.channelsController.invokeSystemMethod(listenerAddedArgs, (_b = this.collaborator) === null || _b === void 0 ? void 0 : _b.instanceId);
|
|
4223
|
+
})).catch((err) => { var _a; return (_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(err); });
|
|
2928
4224
|
});
|
|
2929
4225
|
}
|
|
2930
4226
|
handleCollaboratorBroadcast(context, metadata, commandId) {
|
|
2931
|
-
|
|
4227
|
+
var _a, _b;
|
|
4228
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - heard context with type ${context.type} broadcasted on the channel`);
|
|
2932
4229
|
this.lastBroadcastedContextType = context.type;
|
|
2933
4230
|
this.broadcastedContexts[context.type] = { context, metadata };
|
|
2934
|
-
this.logger.trace(`[${commandId}] - invoking all context listeners`);
|
|
4231
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - invoking all context listeners`);
|
|
2935
4232
|
this.registry.execute(PrivateChannelEventMethods.ListenerAdded, context, metadata);
|
|
2936
4233
|
}
|
|
2937
4234
|
handleCollaboratorAddContextListener(contextType, commandId) {
|
|
2938
|
-
|
|
4235
|
+
var _a;
|
|
4236
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - heard collaborator added context listener for type ${contextType}`);
|
|
2939
4237
|
this.collaboratorListenerTypes.push(contextType);
|
|
2940
4238
|
this.registry.execute(PrivateChannelEventMethods.OnAddContextListener, contextType);
|
|
2941
4239
|
}
|
|
2942
4240
|
handleCollaboratorRemovedListener(contextType, commandId) {
|
|
2943
|
-
|
|
4241
|
+
var _a;
|
|
4242
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - heard collaborator removed context listener with type ${contextType}`);
|
|
2944
4243
|
const index = this.collaboratorListenerTypes.indexOf(contextType);
|
|
2945
4244
|
this.collaboratorListenerTypes.splice(index, 1);
|
|
2946
4245
|
this.registry.execute(PrivateChannelEventMethods.OnUnsubscribe, contextType);
|
|
@@ -2951,6 +4250,7 @@ class PrivateChannel {
|
|
|
2951
4250
|
this.registry.execute(PrivateChannelEventMethods.OnDisconnect);
|
|
2952
4251
|
}
|
|
2953
4252
|
announceJoin(targetInstance, commandId) {
|
|
4253
|
+
var _a, _b;
|
|
2954
4254
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2955
4255
|
const joinChannelArgs = {
|
|
2956
4256
|
action: "joinPrivateChannel",
|
|
@@ -2959,18 +4259,21 @@ class PrivateChannel {
|
|
|
2959
4259
|
channelId: this.id
|
|
2960
4260
|
}
|
|
2961
4261
|
};
|
|
2962
|
-
this.logger.trace(`[${commandId}] - announcing ${"joinPrivateChannel"} to target instance with id ${JSON.stringify(targetInstance)}`);
|
|
4262
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - announcing ${"joinPrivateChannel"} to target instance with id ${JSON.stringify(targetInstance)}`);
|
|
2963
4263
|
yield this.channelsController.invokeSystemMethod(joinChannelArgs, targetInstance);
|
|
2964
|
-
this.logger.trace(`[${commandId}] - collaborator received ${"joinPrivateChannel"} action`);
|
|
4264
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - collaborator received ${"joinPrivateChannel"} action`);
|
|
2965
4265
|
});
|
|
2966
4266
|
}
|
|
2967
4267
|
broadcast(context) {
|
|
2968
|
-
var _a;
|
|
4268
|
+
var _a, _b, _c;
|
|
2969
4269
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4270
|
+
const contextDecoderResult = contextDecoder.run(context);
|
|
4271
|
+
if (!contextDecoderResult.ok) {
|
|
4272
|
+
throw new Error(ChannelError.MalformedContext);
|
|
4273
|
+
}
|
|
2970
4274
|
const commandId = generateCommandId();
|
|
2971
4275
|
this.ensureAlive(commandId);
|
|
2972
4276
|
this.ensureBound(commandId, "broadcast");
|
|
2973
|
-
contextDecoder.runWithException(context);
|
|
2974
4277
|
this.lastBroadcastedContextType = context.type;
|
|
2975
4278
|
this.broadcastedContexts[context.type] = { context, metadata: this.myAppMetadata };
|
|
2976
4279
|
const broadcastArgs = {
|
|
@@ -2982,27 +4285,29 @@ class PrivateChannel {
|
|
|
2982
4285
|
payload: context
|
|
2983
4286
|
}
|
|
2984
4287
|
};
|
|
2985
|
-
this.logger.trace(`[${commandId}] - announcing ${"publishOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
2986
|
-
yield this.channelsController.invokeSystemMethod(broadcastArgs, (
|
|
2987
|
-
this.logger.trace(`[${commandId}] - collaborator received context for action ${"publishOnPrivateChannel"}`);
|
|
4288
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - announcing ${"publishOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
4289
|
+
yield this.channelsController.invokeSystemMethod(broadcastArgs, (_b = this.collaborator) === null || _b === void 0 ? void 0 : _b.instanceId);
|
|
4290
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.trace(`[${commandId}] - collaborator received context for action ${"publishOnPrivateChannel"}`);
|
|
2988
4291
|
});
|
|
2989
4292
|
}
|
|
2990
4293
|
getCurrentContext(contextType) {
|
|
4294
|
+
var _a, _b;
|
|
2991
4295
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2992
4296
|
const commandId = generateCommandId();
|
|
2993
4297
|
this.ensureAlive(commandId);
|
|
2994
|
-
|
|
4298
|
+
const contextTypeMessage = contextType ? ` with contextType ${contextType}` : "";
|
|
4299
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - getCurrentContext invoked ${contextTypeMessage}`);
|
|
2995
4300
|
optionalNonEmptyStringDecoder.runWithException(contextType);
|
|
2996
4301
|
if (!contextType && !this.lastBroadcastedContextType) {
|
|
2997
4302
|
return null;
|
|
2998
4303
|
}
|
|
2999
4304
|
const searchedType = contextType || this.lastBroadcastedContextType;
|
|
3000
|
-
this.logger.trace(`[${commandId}] - Returning context with type ${searchedType}`);
|
|
4305
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - Returning context with type ${searchedType}`);
|
|
3001
4306
|
return this.broadcastedContexts[searchedType].context;
|
|
3002
4307
|
});
|
|
3003
4308
|
}
|
|
3004
4309
|
addContextListener(contextType, handler) {
|
|
3005
|
-
var _a;
|
|
4310
|
+
var _a, _b, _c, _d;
|
|
3006
4311
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3007
4312
|
const commandId = generateCommandId();
|
|
3008
4313
|
this.ensureAlive(commandId);
|
|
@@ -3010,7 +4315,7 @@ class PrivateChannel {
|
|
|
3010
4315
|
if (typeof handler !== "function") {
|
|
3011
4316
|
throw { message: ChannelError.AccessDenied, reason: `Expected function as an argument, got ${typeof contextType}` };
|
|
3012
4317
|
}
|
|
3013
|
-
this.logger.trace(`[${commandId}] - adding subscription for broadcasted contexts with type: ${contextType}`);
|
|
4318
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - adding subscription for broadcasted contexts with type: ${contextType}`);
|
|
3014
4319
|
const subHandler = (data, metadata) => {
|
|
3015
4320
|
if (contextType) {
|
|
3016
4321
|
if (data.type === contextType) {
|
|
@@ -3032,9 +4337,9 @@ class PrivateChannel {
|
|
|
3032
4337
|
contextType: contextType || undefined
|
|
3033
4338
|
}
|
|
3034
4339
|
};
|
|
3035
|
-
this.logger.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
3036
|
-
yield this.channelsController.invokeSystemMethod(listenerAddedArgs, (
|
|
3037
|
-
this.logger.trace(`[${commandId}] - collaborator received action ${"addedContextListenerOnPrivateChannel"}`);
|
|
4340
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - announcing ${"addedContextListenerOnPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
4341
|
+
yield this.channelsController.invokeSystemMethod(listenerAddedArgs, (_c = this.collaborator) === null || _c === void 0 ? void 0 : _c.instanceId);
|
|
4342
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.trace(`[${commandId}] - collaborator received action ${"addedContextListenerOnPrivateChannel"}`);
|
|
3038
4343
|
}
|
|
3039
4344
|
else {
|
|
3040
4345
|
this.myListenerTypesBeforeBound.push(contextType);
|
|
@@ -3057,7 +4362,7 @@ class PrivateChannel {
|
|
|
3057
4362
|
}
|
|
3058
4363
|
getAddContextListenerUnsub(unsub, contextType, commandId) {
|
|
3059
4364
|
return () => __awaiter(this, void 0, void 0, function* () {
|
|
3060
|
-
var _a;
|
|
4365
|
+
var _a, _b, _c;
|
|
3061
4366
|
unsub();
|
|
3062
4367
|
if (!this.collaborator) {
|
|
3063
4368
|
const index = this.myListenerTypesBeforeBound.indexOf(contextType);
|
|
@@ -3072,9 +4377,9 @@ class PrivateChannel {
|
|
|
3072
4377
|
contextType: contextType || undefined
|
|
3073
4378
|
}
|
|
3074
4379
|
};
|
|
3075
|
-
this.logger.trace(`[${commandId}] - announcing unsubscribe from context listener for type ${contextType}`);
|
|
3076
|
-
yield this.channelsController.invokeSystemMethod(unsubArgs, (
|
|
3077
|
-
this.logger.trace(`[${commandId}] - collaborator heard ${"removedContextListenerOnPrivateChannel"}`);
|
|
4380
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - announcing unsubscribe from context listener for type ${contextType}`);
|
|
4381
|
+
yield this.channelsController.invokeSystemMethod(unsubArgs, (_b = this.collaborator) === null || _b === void 0 ? void 0 : _b.instanceId);
|
|
4382
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.trace(`[${commandId}] - collaborator heard ${"removedContextListenerOnPrivateChannel"}`);
|
|
3078
4383
|
});
|
|
3079
4384
|
}
|
|
3080
4385
|
onAddContextListener(handler) {
|
|
@@ -3105,7 +4410,7 @@ class PrivateChannel {
|
|
|
3105
4410
|
return AsyncListener(unsub);
|
|
3106
4411
|
}
|
|
3107
4412
|
disconnect() {
|
|
3108
|
-
var _a;
|
|
4413
|
+
var _a, _b, _c, _d;
|
|
3109
4414
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3110
4415
|
const commandId = generateCommandId();
|
|
3111
4416
|
if (this.isCreator && !this.collaborator) {
|
|
@@ -3114,9 +4419,9 @@ class PrivateChannel {
|
|
|
3114
4419
|
}
|
|
3115
4420
|
this.ensureAlive(commandId);
|
|
3116
4421
|
this.ensureBound(commandId, "disconnect");
|
|
3117
|
-
this.logger.trace(`[${commandId}] - disconnect invoked`);
|
|
4422
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.trace(`[${commandId}] - disconnect invoked`);
|
|
3118
4423
|
this.disconnected = true;
|
|
3119
|
-
this.logger.trace(`[${commandId}] - announcing ${"disconnectedFromPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
4424
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.trace(`[${commandId}] - announcing ${"disconnectedFromPrivateChannel"} to collaborator ${JSON.stringify(this.collaborator)}`);
|
|
3120
4425
|
const disconnectArgs = {
|
|
3121
4426
|
action: "disconnectedFromPrivateChannel",
|
|
3122
4427
|
correlationId: this.id,
|
|
@@ -3125,27 +4430,29 @@ class PrivateChannel {
|
|
|
3125
4430
|
}
|
|
3126
4431
|
};
|
|
3127
4432
|
this.channelsController.removePrivateChannelFromStoreById(this.id);
|
|
3128
|
-
yield this.channelsController.invokeSystemMethod(disconnectArgs, (
|
|
3129
|
-
this.logger.trace(`[${commandId}] - collaborator received action ${"disconnectedFromPrivateChannel"}`);
|
|
4433
|
+
yield this.channelsController.invokeSystemMethod(disconnectArgs, (_c = this.collaborator) === null || _c === void 0 ? void 0 : _c.instanceId);
|
|
4434
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.trace(`[${commandId}] - collaborator received action ${"disconnectedFromPrivateChannel"}`);
|
|
3130
4435
|
if (this.unsubFromInstanceStopped) {
|
|
3131
4436
|
this.unsubFromInstanceStopped();
|
|
3132
4437
|
}
|
|
3133
4438
|
});
|
|
3134
4439
|
}
|
|
3135
4440
|
ensureAlive(commandId) {
|
|
4441
|
+
var _a;
|
|
3136
4442
|
if (!this.disconnected) {
|
|
3137
4443
|
return;
|
|
3138
4444
|
}
|
|
3139
4445
|
const errorMsg = "Channel is disconnected - operation is no longer available";
|
|
3140
|
-
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
4446
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`[${commandId}] - ${errorMsg}`);
|
|
3141
4447
|
throw { message: ChannelError.AccessDenied, reason: errorMsg };
|
|
3142
4448
|
}
|
|
3143
4449
|
ensureBound(commandId, operation) {
|
|
4450
|
+
var _a;
|
|
3144
4451
|
if (this.collaborator) {
|
|
3145
4452
|
return;
|
|
3146
4453
|
}
|
|
3147
4454
|
const errorMsg = `There's no collaborator on the other side of the channel - operation ${operation} is unavailable`;
|
|
3148
|
-
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
4455
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`[${commandId}] - ${errorMsg}`);
|
|
3149
4456
|
throw { message: ChannelError.AccessDenied, reason: errorMsg };
|
|
3150
4457
|
}
|
|
3151
4458
|
subscribeForCollaboratorInstanceStop(commandId) {
|
|
@@ -3216,17 +4523,18 @@ class GlueEventsController {
|
|
|
3216
4523
|
return !!methodsByThisInstance.length;
|
|
3217
4524
|
}
|
|
3218
4525
|
handleReceivedAction(eventArgs, instance) {
|
|
4526
|
+
var _a, _b;
|
|
3219
4527
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3220
4528
|
const argsDecodeResult = SystemMethodInvocationArgumentDecoder.run(eventArgs);
|
|
3221
4529
|
if (!argsDecodeResult.ok) {
|
|
3222
4530
|
throw new Error(`Interop Method ${ioConnectFDC3SystemMethod} invoked with invalid argument object - ${argsDecodeResult.error}`);
|
|
3223
4531
|
}
|
|
3224
4532
|
const commandId = generateCommandId();
|
|
3225
|
-
this.logger.log(`${commandId} - received system method from instance with id ${instance.instance} for action ${eventArgs.action} with arguments: ${JSON.stringify(eventArgs)}`);
|
|
4533
|
+
(_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)}`);
|
|
3226
4534
|
const operation = this.actionDictionary[eventArgs.action];
|
|
3227
4535
|
if (!operation) {
|
|
3228
4536
|
const errorMsg = `Unsupported private channel action: ${eventArgs.action}`;
|
|
3229
|
-
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
4537
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error(`[${commandId}] - ${errorMsg}`);
|
|
3230
4538
|
throw new Error(errorMsg);
|
|
3231
4539
|
}
|
|
3232
4540
|
yield operation(eventArgs, instance, commandId);
|
|
@@ -3239,10 +4547,11 @@ class GlueEventsController {
|
|
|
3239
4547
|
return this._logger;
|
|
3240
4548
|
}
|
|
3241
4549
|
validateAndRetrieveChannel({ action, correlationId }, instance, commandId) {
|
|
4550
|
+
var _a, _b, _c;
|
|
3242
4551
|
const privateChannel = this.channelsStateStore.getPrivateChannelById(correlationId);
|
|
3243
4552
|
if (!privateChannel) {
|
|
3244
4553
|
const errorMsg = `There's no private channel with id ${correlationId}`;
|
|
3245
|
-
this.logger.error(`[${commandId}] - ${errorMsg}`);
|
|
4554
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`[${commandId}] - ${errorMsg}`);
|
|
3246
4555
|
throw new Error(errorMsg);
|
|
3247
4556
|
}
|
|
3248
4557
|
const channelCollaborator = privateChannel.getCollaborator();
|
|
@@ -3250,26 +4559,27 @@ class GlueEventsController {
|
|
|
3250
4559
|
return privateChannel;
|
|
3251
4560
|
}
|
|
3252
4561
|
if (channelCollaborator && channelCollaborator.instanceId === instance.instance) {
|
|
3253
|
-
this.logger.log(`[${commandId}] - request sent from correct collaborator with id ${instance.instance}. Returning channel`);
|
|
4562
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log(`[${commandId}] - request sent from correct collaborator with id ${instance.instance}. Returning channel`);
|
|
3254
4563
|
return privateChannel;
|
|
3255
4564
|
}
|
|
3256
4565
|
const errorMsg = `Cannot proceed with action ${action} - ${channelCollaborator
|
|
3257
4566
|
? `private channel ${correlationId} established communication with collaborator with id ${channelCollaborator}`
|
|
3258
4567
|
: `no collaborator joined private channel with id ${correlationId}`}`;
|
|
3259
|
-
this.logger.error(errorMsg);
|
|
4568
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.error(errorMsg);
|
|
3260
4569
|
throw new Error(errorMsg);
|
|
3261
4570
|
}
|
|
3262
4571
|
handleJoin(eventArgs, instance, commandId) {
|
|
4572
|
+
var _a;
|
|
3263
4573
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3264
4574
|
const collaborator = { appId: instance.application || instance.applicationName, instanceId: instance.instance };
|
|
3265
4575
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3266
4576
|
yield privateChannel.handleCollaboratorJoin(collaborator, commandId);
|
|
3267
|
-
this.logger.log(`[${commandId}] - collaborator ${JSON.stringify(collaborator)} set for private channel with id ${eventArgs.correlationId}`);
|
|
4577
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - collaborator ${JSON.stringify(collaborator)} set for private channel with id ${eventArgs.correlationId}`);
|
|
3268
4578
|
});
|
|
3269
4579
|
}
|
|
3270
4580
|
handlePublish(eventArgs, instance, commandId) {
|
|
3271
|
-
var _a, _b;
|
|
3272
|
-
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, adding context with type ${(
|
|
4581
|
+
var _a, _b, _c;
|
|
4582
|
+
(_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`);
|
|
3273
4583
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3274
4584
|
const metadata = {
|
|
3275
4585
|
source: {
|
|
@@ -3277,33 +4587,35 @@ class GlueEventsController {
|
|
|
3277
4587
|
instanceId: instance.instance
|
|
3278
4588
|
}
|
|
3279
4589
|
};
|
|
3280
|
-
privateChannel.handleCollaboratorBroadcast((
|
|
4590
|
+
privateChannel.handleCollaboratorBroadcast((_c = eventArgs.collaborationObject) === null || _c === void 0 ? void 0 : _c.payload, metadata, commandId);
|
|
3281
4591
|
}
|
|
3282
4592
|
handleContextListenerAdded(eventArgs, instance, commandId) {
|
|
3283
|
-
var _a;
|
|
3284
|
-
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onAddContextListener' callbacks`);
|
|
4593
|
+
var _a, _b;
|
|
4594
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onAddContextListener' callbacks`);
|
|
3285
4595
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3286
|
-
privateChannel.handleCollaboratorAddContextListener(((
|
|
4596
|
+
privateChannel.handleCollaboratorAddContextListener(((_b = eventArgs.collaborationObject) === null || _b === void 0 ? void 0 : _b.contextType) || null, commandId);
|
|
3287
4597
|
}
|
|
3288
4598
|
handleContextListenerRemoved(eventArgs, instance, commandId) {
|
|
3289
|
-
var _a;
|
|
3290
|
-
this.logger.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onUnsubscribe' callbacks`);
|
|
4599
|
+
var _a, _b;
|
|
4600
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onUnsubscribe' callbacks`);
|
|
3291
4601
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3292
|
-
privateChannel.handleCollaboratorRemovedListener(((
|
|
4602
|
+
privateChannel.handleCollaboratorRemovedListener(((_b = eventArgs.collaborationObject) === null || _b === void 0 ? void 0 : _b.contextType) || null, commandId);
|
|
3293
4603
|
}
|
|
3294
4604
|
handleDisconnect(eventArgs, instance, commandId) {
|
|
3295
|
-
|
|
4605
|
+
var _a;
|
|
4606
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.log(`[${commandId}] - received ${eventArgs.action} action, invoking all 'onDisconnect' callbacks`);
|
|
3296
4607
|
const privateChannel = this.validateAndRetrieveChannel(eventArgs, instance, commandId);
|
|
3297
4608
|
privateChannel.handleCollaboratorDisconnect();
|
|
3298
4609
|
}
|
|
3299
4610
|
handleStartupContextOpened(eventArgs, instance, commandId) {
|
|
3300
|
-
|
|
4611
|
+
var _a, _b, _c;
|
|
4612
|
+
(_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}`);
|
|
3301
4613
|
const wrappedPromise = this.appsStateStore.getOpenAppPromise(eventArgs.correlationId);
|
|
3302
4614
|
if (!wrappedPromise) {
|
|
3303
|
-
this.logger.log(`[${commandId}] - there's no open app promise related to guid ${eventArgs.correlationId}`);
|
|
4615
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.log(`[${commandId}] - there's no open app promise related to guid ${eventArgs.correlationId}`);
|
|
3304
4616
|
return;
|
|
3305
4617
|
}
|
|
3306
|
-
this.logger.log(`[${commandId}] - resolving open app promise related to guid ${eventArgs.correlationId} from instance with id ${instance.instance}`);
|
|
4618
|
+
(_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}`);
|
|
3307
4619
|
wrappedPromise.resolve();
|
|
3308
4620
|
}
|
|
3309
4621
|
}
|