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