@interopio/browser 3.3.4 → 3.3.5-next.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.
@@ -13,10 +13,56 @@ const parseConfig = (config) => {
13
13
  return combined;
14
14
  };
15
15
 
16
+ const Glue42CoreMessageTypes = {
17
+ platformUnload: { name: "platformUnload" },
18
+ transportSwitchRequest: { name: "transportSwitchRequest" },
19
+ transportSwitchResponse: { name: "transportSwitchResponse" },
20
+ getCurrentTransport: { name: "getCurrentTransport" },
21
+ getCurrentTransportResponse: { name: "getCurrentTransportResponse" },
22
+ checkPreferredLogic: { name: "checkPreferredLogic" },
23
+ checkPreferredConnection: { name: "checkPreferredConnection" },
24
+ checkPreferredLogicResponse: { name: "checkPreferredLogicResponse" },
25
+ checkPreferredConnectionResponse: { name: "checkPreferredConnectionResponse" }
26
+ };
27
+ const webPlatformTransportName = "web-platform";
28
+ const latestFDC3Type = "latest_fdc3_type";
29
+ const errorChannel = new MessageChannel();
30
+
31
+ const extractErrorMsg = (error) => {
32
+ if (typeof error === "string") {
33
+ return error;
34
+ }
35
+ if (error?.message) {
36
+ return typeof error.message === "string" ? error.message : JSON.stringify(error.message);
37
+ }
38
+ return JSON.stringify(error);
39
+ };
40
+ const runDecoderWithIOError = (decoder, json) => {
41
+ try {
42
+ const result = decoder.runWithException(json);
43
+ return result;
44
+ }
45
+ catch (error) {
46
+ return ioError.raiseError(error, true);
47
+ }
48
+ };
49
+
50
+ class IOError {
51
+ raiseError(error, shouldThrowOriginalError) {
52
+ const errorMessage = extractErrorMsg(error);
53
+ errorChannel.port1.postMessage(errorMessage);
54
+ if (shouldThrowOriginalError) {
55
+ throw error;
56
+ }
57
+ throw new Error(errorMessage);
58
+ }
59
+ }
60
+ const ioError = new IOError();
61
+
16
62
  const checkSingleton = () => {
17
63
  const ioConnectBrowserNamespace = window.glue42core || window.iobrowser;
18
64
  if (ioConnectBrowserNamespace && ioConnectBrowserNamespace.webStarted) {
19
- throw new Error("IoConnect Browser has already been started for this application.");
65
+ return ioError.raiseError("IoConnect Browser has already been started for this application.");
20
66
  }
21
67
  if (!ioConnectBrowserNamespace) {
22
68
  window.iobrowser = { webStarted: true };
@@ -1989,7 +2035,7 @@ const windowOperationTypesDecoder = oneOf$1(constant$1("openWindow"), constant$1
1989
2035
  const appManagerOperationTypesDecoder = oneOf$1(constant$1("appHello"), constant$1("appDirectoryStateChange"), constant$1("instanceStarted"), constant$1("instanceStopped"), constant$1("applicationStart"), constant$1("instanceStop"), constant$1("clear"));
1990
2036
  const layoutsOperationTypesDecoder = oneOf$1(constant$1("layoutAdded"), constant$1("layoutChanged"), constant$1("layoutRemoved"), constant$1("layoutRenamed"), constant$1("get"), constant$1("getAll"), constant$1("export"), constant$1("import"), constant$1("remove"), constant$1("rename"), constant$1("clientSaveRequest"), constant$1("getGlobalPermissionState"), constant$1("checkGlobalActivated"), constant$1("requestGlobalPermission"), constant$1("getDefaultGlobal"), constant$1("setDefaultGlobal"), constant$1("clearDefaultGlobal"), constant$1("updateMetadata"));
1991
2037
  const notificationsOperationTypesDecoder = oneOf$1(constant$1("raiseNotification"), constant$1("requestPermission"), constant$1("notificationShow"), constant$1("notificationClick"), constant$1("getPermission"), constant$1("list"), constant$1("notificationRaised"), constant$1("notificationClosed"), constant$1("click"), constant$1("clear"), constant$1("clearAll"), constant$1("configure"), constant$1("getConfiguration"), constant$1("configurationChanged"), constant$1("setState"), constant$1("clearOld"), constant$1("activeCountChange"), constant$1("stateChange"));
1992
- const systemOperationTypesDecoder = oneOf$1(constant$1("getEnvironment"), constant$1("getBase"), constant$1("platformShutdown"));
2038
+ const systemOperationTypesDecoder = oneOf$1(constant$1("getEnvironment"), constant$1("getBase"), constant$1("platformShutdown"), constant$1("isFdc3DataWrappingSupported"), constant$1("clientError"));
1993
2039
  const windowRelativeDirectionDecoder = oneOf$1(constant$1("top"), constant$1("left"), constant$1("right"), constant$1("bottom"));
1994
2040
  const windowBoundsDecoder = object$1({
1995
2041
  top: number$1(),
@@ -2379,7 +2425,8 @@ const intentRequestDecoder = object$1({
2379
2425
  options: optional$1(windowOpenSettingsDecoder),
2380
2426
  handlers: optional$1(array$1(intentHandlerDecoder)),
2381
2427
  timeout: optional$1(nonNegativeNumberDecoder),
2382
- waitUserResponseIndefinitely: optional$1(boolean$1())
2428
+ waitUserResponseIndefinitely: optional$1(boolean$1()),
2429
+ clearSavedHandler: optional$1(boolean$1())
2383
2430
  });
2384
2431
  const raiseRequestDecoder = oneOf$1(nonEmptyStringDecoder, intentRequestDecoder);
2385
2432
  const resolverConfigDecoder = object$1({
@@ -2435,6 +2482,11 @@ const getIntentsResultDecoder = object$1({
2435
2482
  const channelNameDecoder = (channelNames) => {
2436
2483
  return nonEmptyStringDecoder.where(s => channelNames.includes(s), "Expected a valid channel name");
2437
2484
  };
2485
+ const publishOptionsDecoder = optional$1(oneOf$1(nonEmptyStringDecoder, object$1({
2486
+ name: optional$1(nonEmptyStringDecoder),
2487
+ fdc3: optional$1(boolean$1())
2488
+ })));
2489
+ const fdc3ContextDecoder = anyJson$1().where((value) => typeof value.type === "string", "Expected a valid FDC3 Context with compulsory 'type' field");
2438
2490
  const interopActionSettingsDecoder = object$1({
2439
2491
  method: nonEmptyStringDecoder,
2440
2492
  arguments: optional$1(anyJson$1()),
@@ -2711,6 +2763,9 @@ const prefsHelloSuccessDecoder = object$1({
2711
2763
  app: nonEmptyStringDecoder,
2712
2764
  }),
2713
2765
  });
2766
+ const clientErrorDataDecoder = object$1({
2767
+ message: nonEmptyStringDecoder
2768
+ });
2714
2769
 
2715
2770
  const operations$9 = {
2716
2771
  openWindow: { name: "openWindow", dataDecoder: openWindowConfigDecoder, resultDecoder: coreWindowDataDecoder },
@@ -2912,12 +2967,12 @@ class WebWindowModel {
2912
2967
  }
2913
2968
  onFocusChanged(callback) {
2914
2969
  if (typeof callback !== "function") {
2915
- throw new Error("Cannot subscribe to context changes, because the provided callback is not a function!");
2970
+ return ioError.raiseError("Cannot subscribe to context changes, because the provided callback is not a function!");
2916
2971
  }
2917
2972
  return this.registry.add("focus-change", callback);
2918
2973
  }
2919
2974
  async moveResize(dimension) {
2920
- const targetBounds = boundsDecoder.runWithException(dimension);
2975
+ const targetBounds = runDecoderWithIOError(boundsDecoder, dimension);
2921
2976
  const commandArgs = Object.assign({}, targetBounds, { windowId: this.id, relative: false });
2922
2977
  await this._bridge.send("windows", operations$9.moveResize, commandArgs);
2923
2978
  return this.me;
@@ -2927,10 +2982,10 @@ class WebWindowModel {
2927
2982
  return this.me;
2928
2983
  }
2929
2984
  if (typeof width !== "undefined") {
2930
- nonNegativeNumberDecoder.runWithException(width);
2985
+ runDecoderWithIOError(nonNegativeNumberDecoder, width);
2931
2986
  }
2932
2987
  if (typeof height !== "undefined") {
2933
- nonNegativeNumberDecoder.runWithException(height);
2988
+ runDecoderWithIOError(nonNegativeNumberDecoder, height);
2934
2989
  }
2935
2990
  const commandArgs = Object.assign({}, { width, height }, { windowId: this.id, relative: true });
2936
2991
  await this._bridge.send("windows", operations$9.moveResize, commandArgs);
@@ -2941,10 +2996,10 @@ class WebWindowModel {
2941
2996
  return this.me;
2942
2997
  }
2943
2998
  if (typeof top !== "undefined") {
2944
- number$1().runWithException(top);
2999
+ runDecoderWithIOError(number$1(), top);
2945
3000
  }
2946
3001
  if (typeof left !== "undefined") {
2947
- number$1().runWithException(left);
3002
+ runDecoderWithIOError(number$1(), left);
2948
3003
  }
2949
3004
  const commandArgs = Object.assign({}, { top, left }, { windowId: this.id, relative: true });
2950
3005
  await this._bridge.send("windows", operations$9.moveResize, commandArgs);
@@ -2968,7 +3023,7 @@ class WebWindowModel {
2968
3023
  return result.title;
2969
3024
  }
2970
3025
  async setTitle(title) {
2971
- const ttl = nonEmptyStringDecoder.runWithException(title);
3026
+ const ttl = runDecoderWithIOError(nonEmptyStringDecoder, title);
2972
3027
  await this._bridge.send("windows", operations$9.setTitle, { windowId: this.id, title: ttl });
2973
3028
  return this.me;
2974
3029
  }
@@ -2982,12 +3037,12 @@ class WebWindowModel {
2982
3037
  return rest;
2983
3038
  }
2984
3039
  async updateContext(context) {
2985
- const ctx = anyDecoder.runWithException(context);
3040
+ const ctx = runDecoderWithIOError(anyDecoder, context);
2986
3041
  await this._bridge.contextLib.update(this.myCtxKey, ctx);
2987
3042
  return this.me;
2988
3043
  }
2989
3044
  async setContext(context) {
2990
- const ctx = anyDecoder.runWithException(context);
3045
+ const ctx = runDecoderWithIOError(anyDecoder, context);
2991
3046
  const current = await this._bridge.contextLib.get(this.myCtxKey);
2992
3047
  const newCtx = current.___io___ ? { ...ctx, ___io___: current.___io___ } : ctx;
2993
3048
  await this._bridge.contextLib.set(this.myCtxKey, newCtx);
@@ -2995,7 +3050,7 @@ class WebWindowModel {
2995
3050
  }
2996
3051
  onContextUpdated(callback) {
2997
3052
  if (typeof callback !== "function") {
2998
- throw new Error("Cannot subscribe to context changes, because the provided callback is not a function!");
3053
+ return ioError.raiseError("Cannot subscribe to context changes, because the provided callback is not a function!");
2999
3054
  }
3000
3055
  const wrappedCallback = (data) => {
3001
3056
  const { ___io___, ...rest } = data;
@@ -3105,21 +3160,21 @@ class WindowsController {
3105
3160
  }
3106
3161
  async handleBridgeMessage(args) {
3107
3162
  await this.platformRegistration;
3108
- const operationName = windowOperationTypesDecoder.runWithException(args.operation);
3163
+ const operationName = runDecoderWithIOError(windowOperationTypesDecoder, args.operation);
3109
3164
  const operation = operations$9[operationName];
3110
3165
  if (!operation.execute) {
3111
3166
  return;
3112
3167
  }
3113
3168
  let operationData = args.data;
3114
3169
  if (operation.dataDecoder) {
3115
- operationData = operation.dataDecoder.runWithException(args.data);
3170
+ operationData = runDecoderWithIOError(operation.dataDecoder, args.data);
3116
3171
  }
3117
3172
  return await operation.execute(operationData);
3118
3173
  }
3119
3174
  async open(name, url, options) {
3120
- nonEmptyStringDecoder.runWithException(name);
3121
- nonEmptyStringDecoder.runWithException(url);
3122
- const settings = windowOpenSettingsDecoder.runWithException(options);
3175
+ runDecoderWithIOError(nonEmptyStringDecoder, name);
3176
+ runDecoderWithIOError(nonEmptyStringDecoder, url);
3177
+ const settings = runDecoderWithIOError(windowOpenSettingsDecoder, options);
3123
3178
  const windowSuccess = await this.bridge.send("windows", operations$9.openWindow, { name, url, options: settings });
3124
3179
  return this.waitForWindowAdded(windowSuccess.windowId);
3125
3180
  }
@@ -3127,7 +3182,7 @@ class WindowsController {
3127
3182
  return this.allWindowProjections.map((projection) => projection.api);
3128
3183
  }
3129
3184
  findById(id) {
3130
- nonEmptyStringDecoder.runWithException(id);
3185
+ runDecoderWithIOError(nonEmptyStringDecoder, id);
3131
3186
  return this.allWindowProjections.find((projection) => projection.id === id)?.api;
3132
3187
  }
3133
3188
  toApi() {
@@ -3159,25 +3214,25 @@ class WindowsController {
3159
3214
  }
3160
3215
  onWindowAdded(callback) {
3161
3216
  if (typeof callback !== "function") {
3162
- throw new Error("Cannot subscribe to window added, because the provided callback is not a function!");
3217
+ return ioError.raiseError("Cannot subscribe to window added, because the provided callback is not a function!");
3163
3218
  }
3164
3219
  return this.registry.add("window-added", callback);
3165
3220
  }
3166
3221
  onWindowRemoved(callback) {
3167
3222
  if (typeof callback !== "function") {
3168
- throw new Error("Cannot subscribe to window removed, because the provided callback is not a function!");
3223
+ return ioError.raiseError("Cannot subscribe to window removed, because the provided callback is not a function!");
3169
3224
  }
3170
3225
  return this.registry.add("window-removed", callback);
3171
3226
  }
3172
3227
  onWindowGotFocus(callback) {
3173
3228
  if (typeof callback !== "function") {
3174
- throw new Error("Cannot subscribe to onWindowGotFocus, because the provided callback is not a function!");
3229
+ return ioError.raiseError("Cannot subscribe to onWindowGotFocus, because the provided callback is not a function!");
3175
3230
  }
3176
3231
  return this.registry.add("window-got-focus", callback);
3177
3232
  }
3178
3233
  onWindowLostFocus(callback) {
3179
3234
  if (typeof callback !== "function") {
3180
- throw new Error("Cannot subscribe to onWindowLostFocus, because the provided callback is not a function!");
3235
+ return ioError.raiseError("Cannot subscribe to onWindowLostFocus, because the provided callback is not a function!");
3181
3236
  }
3182
3237
  return this.registry.add("window-lost-focus", callback);
3183
3238
  }
@@ -3193,7 +3248,7 @@ class WindowsController {
3193
3248
  this.logger.trace("i am not treated as a workspace frame, setting my window");
3194
3249
  const myWindow = windows.find((w) => w.windowId === this.publicWindowId);
3195
3250
  if (!myWindow) {
3196
- throw new Error("Cannot initialize the window library, because I received no information about me from the platform");
3251
+ return ioError.raiseError("Cannot initialize the window library, because I received no information about me from the platform");
3197
3252
  }
3198
3253
  const myProjection = await this.ioc.buildWebWindow(this.publicWindowId, myWindow.name);
3199
3254
  this.me = myProjection.api;
@@ -3233,7 +3288,7 @@ class WindowsController {
3233
3288
  }
3234
3289
  async handleGetBounds() {
3235
3290
  if (!this.me && !this.isWorkspaceFrame) {
3236
- throw new Error("This window cannot report it's bounds, because it is not a Glue Window, most likely because it is an iframe");
3291
+ return ioError.raiseError("This window cannot report it's bounds, because it is not a Glue Window, most likely because it is an iframe");
3237
3292
  }
3238
3293
  return {
3239
3294
  windowId: this.isWorkspaceFrame ? "noop" : this.me.id,
@@ -3247,7 +3302,7 @@ class WindowsController {
3247
3302
  }
3248
3303
  async handleGetTitle() {
3249
3304
  if (!this.me) {
3250
- throw new Error("This window cannot report it's title, because it is not a Glue Window, most likely because it is an iframe");
3305
+ return ioError.raiseError("This window cannot report it's title, because it is not a Glue Window, most likely because it is an iframe");
3251
3306
  }
3252
3307
  return {
3253
3308
  windowId: this.me.id,
@@ -3256,7 +3311,7 @@ class WindowsController {
3256
3311
  }
3257
3312
  async handleGetUrl() {
3258
3313
  if (!this.me) {
3259
- throw new Error("This window cannot report it's url, because it is not a Glue Window, most likely because it is an iframe");
3314
+ return ioError.raiseError("This window cannot report it's url, because it is not a Glue Window, most likely because it is an iframe");
3260
3315
  }
3261
3316
  return {
3262
3317
  windowId: this.me.id,
@@ -3335,7 +3390,7 @@ class WindowsController {
3335
3390
  }
3336
3391
  async handleGetChannel() {
3337
3392
  if (!this.me) {
3338
- throw new Error("This window cannot report it's channel, because it is not a Glue Window, most likely because it is an iframe");
3393
+ return ioError.raiseError("This window cannot report it's channel, because it is not a Glue Window, most likely because it is an iframe");
3339
3394
  }
3340
3395
  const channel = this.channelsController.my();
3341
3396
  return {
@@ -3402,14 +3457,14 @@ class GlueBridge {
3402
3457
  operation.dataDecoder.runWithException(operationData);
3403
3458
  }
3404
3459
  catch (error) {
3405
- throw new Error(`Unexpected Web->Platform outgoing validation error: ${error.message}, for operation: ${operation.name} and input: ${JSON.stringify(error.input)}`);
3460
+ return ioError.raiseError(`Unexpected Web->Platform outgoing validation error: ${error.message}, for operation: ${operation.name} and input: ${JSON.stringify(error.input)}`);
3406
3461
  }
3407
3462
  }
3408
3463
  const operationSupported = webOptions?.includeOperationCheck ?
3409
3464
  (await this.checkOperationSupported(domain, operation)).isSupported :
3410
3465
  true;
3411
3466
  if (!operationSupported) {
3412
- throw new Error(`Cannot complete operation: ${operation.name} for domain: ${domain} because this client is connected to a platform which does not support it`);
3467
+ return ioError.raiseError(`Cannot complete operation: ${operation.name} for domain: ${domain} because this client is connected to a platform which does not support it`);
3413
3468
  }
3414
3469
  try {
3415
3470
  const operationResult = await this.transmitMessage(domain, operation, operationData, options);
@@ -3419,16 +3474,16 @@ class GlueBridge {
3419
3474
  return operationResult;
3420
3475
  }
3421
3476
  catch (error) {
3422
- if (error.kind) {
3423
- throw new Error(`Unexpected Web<-Platform incoming validation error: ${error.message}, for operation: ${operation.name} and input: ${JSON.stringify(error.input)}`);
3477
+ if (error?.kind) {
3478
+ return ioError.raiseError(`Unexpected Web<-Platform incoming validation error: ${error.message}, for operation: ${operation.name} and input: ${JSON.stringify(error.input)}`);
3424
3479
  }
3425
- throw new Error(error.message);
3480
+ return ioError.raiseError(error);
3426
3481
  }
3427
3482
  }
3428
3483
  async createNotificationsSteam() {
3429
3484
  const streamExists = this.coreGlue.interop.methods().some((method) => method.name === GlueCorePlusThemesStream);
3430
3485
  if (!streamExists) {
3431
- throw new Error("Cannot subscribe to theme changes, because the underlying interop stream does not exist. Most likely this is the case when this client is not connected to Core Plus.");
3486
+ return ioError.raiseError("Cannot subscribe to theme changes, because the underlying interop stream does not exist. Most likely this is the case when this client is not connected to Core Plus.");
3432
3487
  }
3433
3488
  return this.coreGlue.interop.subscribe(GlueCorePlusThemesStream, this.communicationId ? { target: { instance: this.communicationId } } : undefined);
3434
3489
  }
@@ -3567,33 +3622,33 @@ class AppManagerController {
3567
3622
  }
3568
3623
  async handleBridgeMessage(args) {
3569
3624
  await this.platformRegistration;
3570
- const operationName = appManagerOperationTypesDecoder.runWithException(args.operation);
3625
+ const operationName = runDecoderWithIOError(appManagerOperationTypesDecoder, args.operation);
3571
3626
  const operation = operations$8[operationName];
3572
3627
  if (!operation.execute) {
3573
3628
  return;
3574
3629
  }
3575
3630
  let operationData = args.data;
3576
3631
  if (operation.dataDecoder) {
3577
- operationData = operation.dataDecoder.runWithException(args.data);
3632
+ operationData = runDecoderWithIOError(operation.dataDecoder, args.data);
3578
3633
  }
3579
3634
  return await operation.execute(operationData);
3580
3635
  }
3581
3636
  onInstanceStarted(callback) {
3582
3637
  if (typeof callback !== "function") {
3583
- throw new Error("onInstanceStarted requires a single argument of type function");
3638
+ return ioError.raiseError("onInstanceStarted requires a single argument of type function");
3584
3639
  }
3585
3640
  return this.registry.add("instance-started", callback, this.instances);
3586
3641
  }
3587
3642
  onInstanceStopped(callback) {
3588
3643
  if (typeof callback !== "function") {
3589
- throw new Error("onInstanceStopped requires a single argument of type function");
3644
+ return ioError.raiseError("onInstanceStopped requires a single argument of type function");
3590
3645
  }
3591
3646
  return this.registry.add("instance-stopped", callback);
3592
3647
  }
3593
3648
  async startApplication(appName, context, options) {
3594
3649
  const channels = await this.channelsController.all();
3595
3650
  if (options?.channelId && !channels.includes(options.channelId)) {
3596
- throw new Error(`The channel with name "${options.channelId}" doesn't exist!`);
3651
+ return ioError.raiseError(`The channel with name "${options.channelId}" doesn't exist!`);
3597
3652
  }
3598
3653
  const startOptions = {
3599
3654
  name: appName,
@@ -3615,7 +3670,7 @@ class AppManagerController {
3615
3670
  return this.ioc.buildInstance(openResult, app);
3616
3671
  }
3617
3672
  getApplication(name) {
3618
- const verifiedName = nonEmptyStringDecoder.runWithException(name);
3673
+ const verifiedName = runDecoderWithIOError(nonEmptyStringDecoder, name);
3619
3674
  return this.applications.find((app) => app.name === verifiedName);
3620
3675
  }
3621
3676
  getInstances() {
@@ -3653,19 +3708,19 @@ class AppManagerController {
3653
3708
  }
3654
3709
  onAppAdded(callback) {
3655
3710
  if (typeof callback !== "function") {
3656
- throw new Error("onAppAdded requires a single argument of type function");
3711
+ return ioError.raiseError("onAppAdded requires a single argument of type function");
3657
3712
  }
3658
3713
  return this.registry.add("application-added", callback, this.applications);
3659
3714
  }
3660
3715
  onAppRemoved(callback) {
3661
3716
  if (typeof callback !== "function") {
3662
- throw new Error("onAppRemoved requires a single argument of type function");
3717
+ return ioError.raiseError("onAppRemoved requires a single argument of type function");
3663
3718
  }
3664
3719
  return this.registry.add("application-removed", callback);
3665
3720
  }
3666
3721
  onAppChanged(callback) {
3667
3722
  if (typeof callback !== "function") {
3668
- throw new Error("onAppChanged requires a single argument of type function");
3723
+ return ioError.raiseError("onAppChanged requires a single argument of type function");
3669
3724
  }
3670
3725
  return this.registry.add("application-changed", callback);
3671
3726
  }
@@ -3706,7 +3761,7 @@ class AppManagerController {
3706
3761
  }
3707
3762
  const application = this.applications.find((app) => app.name === instanceData.applicationName);
3708
3763
  if (!application) {
3709
- throw new Error(`Cannot add instance: ${instanceData.id}, because there is no application definition associated with it`);
3764
+ return ioError.raiseError(`Cannot add instance: ${instanceData.id}, because there is no application definition associated with it`);
3710
3765
  }
3711
3766
  const instance = this.ioc.buildInstance(instanceData, application);
3712
3767
  this.instances.push(instance);
@@ -3730,12 +3785,12 @@ class AppManagerController {
3730
3785
  this.registry.execute("instance-stopped", instance);
3731
3786
  }
3732
3787
  async import(definitions, mode = "replace") {
3733
- importModeDecoder.runWithException(mode);
3788
+ runDecoderWithIOError(importModeDecoder, mode);
3734
3789
  if (!Array.isArray(definitions)) {
3735
- throw new Error("Import must be called with an array of definitions");
3790
+ return ioError.raiseError("Import must be called with an array of definitions");
3736
3791
  }
3737
3792
  if (definitions.length > 10000) {
3738
- throw new Error("Cannot import more than 10000 app definitions in Glue42 Core.");
3793
+ return ioError.raiseError("Cannot import more than 10000 app definitions in Glue42 Core.");
3739
3794
  }
3740
3795
  const parseResult = definitions.reduce((soFar, definition) => {
3741
3796
  const decodeResult = allApplicationDefinitionsDecoder.run(definition);
@@ -3755,7 +3810,7 @@ class AppManagerController {
3755
3810
  };
3756
3811
  }
3757
3812
  async remove(name) {
3758
- nonEmptyStringDecoder.runWithException(name);
3813
+ runDecoderWithIOError(nonEmptyStringDecoder, name);
3759
3814
  await this.bridge.send("appManager", operations$8.remove, { name }, { methodResponseTimeoutMs: this.baseApplicationsTimeoutMS });
3760
3815
  }
3761
3816
  async clear() {
@@ -3863,7 +3918,7 @@ class ApplicationModel {
3863
3918
  }
3864
3919
  onInstanceStarted(callback) {
3865
3920
  if (typeof callback !== "function") {
3866
- throw new Error("OnInstanceStarted requires a single argument of type function");
3921
+ return ioError.raiseError("OnInstanceStarted requires a single argument of type function");
3867
3922
  }
3868
3923
  return this.controller.onInstanceStarted((instance) => {
3869
3924
  if (instance.application.name === this.data.name) {
@@ -3873,7 +3928,7 @@ class ApplicationModel {
3873
3928
  }
3874
3929
  onInstanceStopped(callback) {
3875
3930
  if (typeof callback !== "function") {
3876
- throw new Error("OnInstanceStarted requires a single argument of type function");
3931
+ return ioError.raiseError("OnInstanceStarted requires a single argument of type function");
3877
3932
  }
3878
3933
  return this.controller.onInstanceStopped((instance) => {
3879
3934
  if (instance.application.name === this.data.name) {
@@ -3882,8 +3937,8 @@ class ApplicationModel {
3882
3937
  });
3883
3938
  }
3884
3939
  async start(context, options) {
3885
- const verifiedContext = startApplicationContextDecoder.runWithException(context);
3886
- const verifiedOptions = startApplicationOptionsDecoder.runWithException(options);
3940
+ const verifiedContext = runDecoderWithIOError(startApplicationContextDecoder, context);
3941
+ const verifiedOptions = runDecoderWithIOError(startApplicationOptionsDecoder, options);
3887
3942
  return this.controller.startApplication(this.data.name, verifiedContext, verifiedOptions);
3888
3943
  }
3889
3944
  }
@@ -3932,14 +3987,14 @@ class LayoutsController {
3932
3987
  coreGlue.layouts = api;
3933
3988
  }
3934
3989
  async handleBridgeMessage(args) {
3935
- const operationName = layoutsOperationTypesDecoder.runWithException(args.operation);
3990
+ const operationName = runDecoderWithIOError(layoutsOperationTypesDecoder, args.operation);
3936
3991
  const operation = operations$7[operationName];
3937
3992
  if (!operation.execute) {
3938
3993
  return;
3939
3994
  }
3940
3995
  let operationData = args.data;
3941
3996
  if (operation.dataDecoder) {
3942
- operationData = operation.dataDecoder.runWithException(args.data);
3997
+ operationData = runDecoderWithIOError(operation.dataDecoder, args.data);
3943
3998
  }
3944
3999
  return await operation.execute(operationData);
3945
4000
  }
@@ -3976,28 +4031,28 @@ class LayoutsController {
3976
4031
  operations$7.clientSaveRequest.execute = this.handleSaveRequest.bind(this);
3977
4032
  }
3978
4033
  async get(name, type) {
3979
- nonEmptyStringDecoder.runWithException(name);
3980
- layoutTypeDecoder.runWithException(type);
4034
+ runDecoderWithIOError(nonEmptyStringDecoder, name);
4035
+ runDecoderWithIOError(layoutTypeDecoder, type);
3981
4036
  const result = await this.bridge.send("layouts", operations$7.get, { name, type });
3982
4037
  return result.layout;
3983
4038
  }
3984
4039
  async getAll(type) {
3985
- layoutTypeDecoder.runWithException(type);
4040
+ runDecoderWithIOError(layoutTypeDecoder, type);
3986
4041
  const result = await this.bridge.send("layouts", operations$7.getAll, { type });
3987
4042
  return result.summaries;
3988
4043
  }
3989
4044
  async export(type) {
3990
- layoutTypeDecoder.runWithException(type);
4045
+ runDecoderWithIOError(layoutTypeDecoder, type);
3991
4046
  const result = await this.bridge.send("layouts", operations$7.export, { type });
3992
4047
  return result.layouts;
3993
4048
  }
3994
4049
  async import(layouts, mode = "replace") {
3995
- importModeDecoder.runWithException(mode);
4050
+ runDecoderWithIOError(importModeDecoder, mode);
3996
4051
  if (!Array.isArray(layouts)) {
3997
- throw new Error("Import must be called with an array of layouts");
4052
+ return ioError.raiseError("Import must be called with an array of layouts");
3998
4053
  }
3999
4054
  if (layouts.length > 1000) {
4000
- throw new Error("Cannot import more than 1000 layouts at once in Glue42 Core.");
4055
+ return ioError.raiseError("Cannot import more than 1000 layouts at once in Glue42 Core.");
4001
4056
  }
4002
4057
  const parseResult = layouts.reduce((soFar, layout) => {
4003
4058
  const decodeResult = glueLayoutDecoder.run(layout);
@@ -4013,18 +4068,18 @@ class LayoutsController {
4013
4068
  await this.bridge.send("layouts", operations$7.import, { layouts: layoutsToImport, mode });
4014
4069
  }
4015
4070
  async save(layout) {
4016
- newLayoutOptionsDecoder.runWithException(layout);
4071
+ runDecoderWithIOError(newLayoutOptionsDecoder, layout);
4017
4072
  const saveResult = await this.bridge.send("layouts", operations$7.save, { layout });
4018
4073
  return saveResult.layout;
4019
4074
  }
4020
4075
  async restore(options) {
4021
- restoreOptionsDecoder.runWithException(options);
4076
+ runDecoderWithIOError(restoreOptionsDecoder, options);
4022
4077
  const invocationTimeout = options.timeout ? options.timeout * 2 : this.defaultLayoutRestoreTimeoutMS;
4023
4078
  await this.bridge.send("layouts", operations$7.restore, { layout: options }, { methodResponseTimeoutMs: invocationTimeout });
4024
4079
  }
4025
4080
  async remove(type, name) {
4026
- layoutTypeDecoder.runWithException(type);
4027
- nonEmptyStringDecoder.runWithException(name);
4081
+ runDecoderWithIOError(layoutTypeDecoder, type);
4082
+ runDecoderWithIOError(nonEmptyStringDecoder, name);
4028
4083
  await this.bridge.send("layouts", operations$7.remove, { type, name });
4029
4084
  }
4030
4085
  async handleSaveRequest(config) {
@@ -4056,7 +4111,7 @@ class LayoutsController {
4056
4111
  const globalNamespace = window.glue42core || window.iobrowser;
4057
4112
  const amIWorkspaceFrame = globalNamespace.isPlatformFrame;
4058
4113
  if (myWindow.name !== "Platform" && !amIWorkspaceFrame) {
4059
- throw new Error("Cannot request permission for multi-window placement from any app other than the Platform.");
4114
+ return ioError.raiseError("Cannot request permission for multi-window placement from any app other than the Platform.");
4060
4115
  }
4061
4116
  const requestResult = await this.bridge.send("layouts", operations$7.requestGlobalPermission, undefined, { methodResponseTimeoutMs: 180000 });
4062
4117
  return { permissionGranted: requestResult.isAvailable };
@@ -4070,20 +4125,20 @@ class LayoutsController {
4070
4125
  return requestResult.layout;
4071
4126
  }
4072
4127
  async setDefaultGlobal(name) {
4073
- nonEmptyStringDecoder.runWithException(name);
4128
+ runDecoderWithIOError(nonEmptyStringDecoder, name);
4074
4129
  await this.bridge.send("layouts", operations$7.setDefaultGlobal, { name }, undefined, { includeOperationCheck: true });
4075
4130
  }
4076
4131
  async clearDefaultGlobal() {
4077
4132
  await this.bridge.send("layouts", operations$7.clearDefaultGlobal, undefined, undefined, { includeOperationCheck: true });
4078
4133
  }
4079
4134
  async rename(layout, newName) {
4080
- glueLayoutDecoder.runWithException(layout);
4081
- nonEmptyStringDecoder.runWithException(newName);
4135
+ runDecoderWithIOError(glueLayoutDecoder, layout);
4136
+ runDecoderWithIOError(nonEmptyStringDecoder, newName);
4082
4137
  const result = await this.bridge.send("layouts", operations$7.rename, { layout, newName }, undefined, { includeOperationCheck: true });
4083
4138
  return result;
4084
4139
  }
4085
4140
  async updateMetadata(layout) {
4086
- glueLayoutDecoder.runWithException(layout);
4141
+ runDecoderWithIOError(glueLayoutDecoder, layout);
4087
4142
  await this.bridge.send("layouts", operations$7.updateMetadata, { layout }, undefined, { includeOperationCheck: true });
4088
4143
  }
4089
4144
  onAdded(callback) {
@@ -4099,16 +4154,16 @@ class LayoutsController {
4099
4154
  }
4100
4155
  onRenamed(callback) {
4101
4156
  if (typeof callback !== "function") {
4102
- throw new Error("Cannot subscribe to onRenamed, because the provided callback is not a function!");
4157
+ return ioError.raiseError("Cannot subscribe to onRenamed, because the provided callback is not a function!");
4103
4158
  }
4104
4159
  return this.registry.add(operations$7.layoutRenamed.name, callback);
4105
4160
  }
4106
4161
  subscribeOnSaveRequested(callback) {
4107
4162
  if (typeof callback !== "function") {
4108
- throw new Error("Cannot subscribe to onSaveRequested, because the provided argument is not a valid callback function.");
4163
+ return ioError.raiseError("Cannot subscribe to onSaveRequested, because the provided argument is not a valid callback function.");
4109
4164
  }
4110
4165
  if (this.saveRequestSubscription) {
4111
- throw new Error("Cannot subscribe to onSaveRequested, because this client has already subscribed and only one subscription is supported. Consider unsubscribing from the initial one.");
4166
+ return ioError.raiseError("Cannot subscribe to onSaveRequested, because this client has already subscribed and only one subscription is supported. Consider unsubscribing from the initial one.");
4112
4167
  }
4113
4168
  this.saveRequestSubscription = callback;
4114
4169
  return () => {
@@ -4186,14 +4241,14 @@ class NotificationsController {
4186
4241
  this.logger.trace("notifications are ready");
4187
4242
  }
4188
4243
  async handleBridgeMessage(args) {
4189
- const operationName = notificationsOperationTypesDecoder.runWithException(args.operation);
4244
+ const operationName = runDecoderWithIOError(notificationsOperationTypesDecoder, args.operation);
4190
4245
  const operation = operations$6[operationName];
4191
4246
  if (!operation.execute) {
4192
4247
  return;
4193
4248
  }
4194
4249
  let operationData = args.data;
4195
4250
  if (operation.dataDecoder) {
4196
- operationData = operation.dataDecoder.runWithException(args.data);
4251
+ operationData = runDecoderWithIOError(operation.dataDecoder, args.data);
4197
4252
  }
4198
4253
  return await operation.execute(operationData);
4199
4254
  }
@@ -4229,12 +4284,12 @@ class NotificationsController {
4229
4284
  return permissionResult.permissionGranted;
4230
4285
  }
4231
4286
  async raise(options) {
4232
- const settings = glue42NotificationOptionsDecoder.runWithException(options);
4287
+ const settings = runDecoderWithIOError(glue42NotificationOptionsDecoder, options);
4233
4288
  settings.showToast = typeof settings.showToast === "boolean" ? settings.showToast : true;
4234
4289
  settings.showInPanel = typeof settings.showInPanel === "boolean" ? settings.showInPanel : true;
4235
4290
  const permissionGranted = await this.requestPermission();
4236
4291
  if (!permissionGranted) {
4237
- throw new Error("Cannot raise the notification, because the user has declined the permission request");
4292
+ return ioError.raiseError("Cannot raise the notification, because the user has declined the permission request");
4238
4293
  }
4239
4294
  const id = nanoid$1(10);
4240
4295
  const raiseResult = await this.bridge.send("notifications", operations$6.raiseNotification, { settings, id });
@@ -4248,25 +4303,25 @@ class NotificationsController {
4248
4303
  }
4249
4304
  onRaised(callback) {
4250
4305
  if (typeof callback !== "function") {
4251
- throw new Error("onRaised expects a callback of type function");
4306
+ return ioError.raiseError("onRaised expects a callback of type function");
4252
4307
  }
4253
4308
  return this.registry.add("notification-raised", callback);
4254
4309
  }
4255
4310
  onClosed(callback) {
4256
4311
  if (typeof callback !== "function") {
4257
- throw new Error("onRaised expects a callback of type function");
4312
+ return ioError.raiseError("onClosed expects a callback of type function");
4258
4313
  }
4259
4314
  return this.registry.add("notification-closed", callback);
4260
4315
  }
4261
4316
  async click(id, action) {
4262
- nonEmptyStringDecoder.runWithException(id);
4317
+ runDecoderWithIOError(nonEmptyStringDecoder, id);
4263
4318
  if (action) {
4264
- nonEmptyStringDecoder.runWithException(action);
4319
+ runDecoderWithIOError(nonEmptyStringDecoder, action);
4265
4320
  }
4266
4321
  await this.bridge.send("notifications", operations$6.click, { id, action }, undefined, { includeOperationCheck: true });
4267
4322
  }
4268
4323
  async clear(id) {
4269
- nonEmptyStringDecoder.runWithException(id);
4324
+ runDecoderWithIOError(nonEmptyStringDecoder, id);
4270
4325
  await this.bridge.send("notifications", operations$6.clear, { id }, undefined, { includeOperationCheck: true });
4271
4326
  }
4272
4327
  async clearAll() {
@@ -4276,7 +4331,7 @@ class NotificationsController {
4276
4331
  await this.bridge.send("notifications", operations$6.clearOld, undefined, undefined, { includeOperationCheck: true });
4277
4332
  }
4278
4333
  async configure(config) {
4279
- const verifiedConfig = notificationsConfigurationDecoder.runWithException(config);
4334
+ const verifiedConfig = runDecoderWithIOError(notificationsConfigurationDecoder, config);
4280
4335
  await this.bridge.send("notifications", operations$6.configure, { configuration: verifiedConfig }, undefined, { includeOperationCheck: true });
4281
4336
  }
4282
4337
  async getConfiguration() {
@@ -4288,30 +4343,30 @@ class NotificationsController {
4288
4343
  return response.configuration.sourceFilter;
4289
4344
  }
4290
4345
  async setFilter(filter) {
4291
- const verifiedFilter = notificationFilterDecoder.runWithException(filter);
4346
+ const verifiedFilter = runDecoderWithIOError(notificationFilterDecoder, filter);
4292
4347
  await this.bridge.send("notifications", operations$6.configure, { configuration: { sourceFilter: verifiedFilter } }, undefined, { includeOperationCheck: true });
4293
4348
  return verifiedFilter;
4294
4349
  }
4295
4350
  async setState(id, state) {
4296
- nonEmptyStringDecoder.runWithException(id);
4297
- notificationStateDecoder.runWithException(state);
4351
+ runDecoderWithIOError(nonEmptyStringDecoder, id);
4352
+ runDecoderWithIOError(notificationStateDecoder, state);
4298
4353
  await this.bridge.send("notifications", operations$6.setState, { id, state }, undefined, { includeOperationCheck: true });
4299
4354
  }
4300
4355
  onConfigurationChanged(callback) {
4301
4356
  if (typeof callback !== "function") {
4302
- throw new Error("Cannot subscribe to configuration changed, because the provided callback is not a function!");
4357
+ return ioError.raiseError("Cannot subscribe to configuration changed, because the provided callback is not a function!");
4303
4358
  }
4304
4359
  return this.registry.add("notifications-config-changed", callback);
4305
4360
  }
4306
4361
  onActiveCountChanged(callback) {
4307
4362
  if (typeof callback !== "function") {
4308
- throw new Error("Cannot subscribe to onActiveCountChanged changed, because the provided callback is not a function!");
4363
+ return ioError.raiseError("Cannot subscribe to onActiveCountChanged changed, because the provided callback is not a function!");
4309
4364
  }
4310
4365
  return this.registry.add("notifications-active-count-changed", callback);
4311
4366
  }
4312
4367
  onStateChanged(callback) {
4313
4368
  if (typeof callback !== "function") {
4314
- throw new Error("Cannot subscribe to onStateChanged changed, because the provided callback is not a function!");
4369
+ return ioError.raiseError("Cannot subscribe to onStateChanged changed, because the provided callback is not a function!");
4315
4370
  }
4316
4371
  return this.registry.add("notification-state-changed", callback);
4317
4372
  }
@@ -4392,6 +4447,7 @@ class IntentsController {
4392
4447
  interop;
4393
4448
  legacyIntentsController;
4394
4449
  myIntents = new Set();
4450
+ prefsController;
4395
4451
  useIntentsResolverUI = true;
4396
4452
  intentsResolverAppName;
4397
4453
  intentResolverResponseTimeout;
@@ -4402,6 +4458,7 @@ class IntentsController {
4402
4458
  this.bridge = ioc.bridge;
4403
4459
  this.interop = coreGlue.interop;
4404
4460
  this.legacyIntentsController = ioc.legacyIntentsHelper;
4461
+ this.prefsController = ioc.prefsController;
4405
4462
  this.checkIfIntentsResolverIsEnabled(ioc.config);
4406
4463
  const api = this.toApi();
4407
4464
  this.logger.trace("no need for platform registration, attaching the intents property to glue and returning");
@@ -4412,14 +4469,14 @@ class IntentsController {
4412
4469
  this.unregisterIntentPromises = [];
4413
4470
  }
4414
4471
  async handleBridgeMessage(args) {
4415
- const operationName = intentsOperationTypesDecoder.runWithException(args.operation);
4472
+ const operationName = runDecoderWithIOError(intentsOperationTypesDecoder, args.operation);
4416
4473
  const operation = operations$5[operationName];
4417
4474
  if (!operation.execute) {
4418
4475
  return;
4419
4476
  }
4420
4477
  let operationData = args.data;
4421
4478
  if (operation.dataDecoder) {
4422
- operationData = operation.dataDecoder.runWithException(args.data);
4479
+ operationData = runDecoderWithIOError(operation.dataDecoder, args.data);
4423
4480
  }
4424
4481
  return await operation.execute(operationData);
4425
4482
  }
@@ -4431,16 +4488,25 @@ class IntentsController {
4431
4488
  register: this.register.bind(this),
4432
4489
  find: this.find.bind(this),
4433
4490
  filterHandlers: this.filterHandlers.bind(this),
4434
- getIntents: this.getIntentsByHandler.bind(this)
4491
+ getIntents: this.getIntentsByHandler.bind(this),
4492
+ clearSavedHandlers: this.clearSavedHandlers.bind(this)
4435
4493
  };
4436
4494
  return api;
4437
4495
  }
4438
4496
  async raise(request) {
4439
- const validatedIntentRequest = raiseRequestDecoder.runWithException(request);
4497
+ const validatedIntentRequest = runDecoderWithIOError(raiseRequestDecoder, request);
4440
4498
  const intentRequest = typeof validatedIntentRequest === "string"
4441
4499
  ? { intent: validatedIntentRequest }
4442
4500
  : validatedIntentRequest;
4443
4501
  await Promise.all(this.unregisterIntentPromises);
4502
+ if (intentRequest.clearSavedHandler) {
4503
+ this.logger.trace(`User removes saved handler for intent ${intentRequest.intent}`);
4504
+ await this.removeRememberedHandler(intentRequest.intent);
4505
+ }
4506
+ const resultFromRememberedHandler = await this.checkHandleRaiseWithRememberedHandler(intentRequest);
4507
+ if (resultFromRememberedHandler) {
4508
+ return resultFromRememberedHandler;
4509
+ }
4444
4510
  const requestWithResolverInfo = { intentRequest, resolverConfig: this.getResolverConfigByRequest({ intentRequest }) };
4445
4511
  const isRaiseOperationSupported = await this.isRaiseOperationSupported();
4446
4512
  if (!isRaiseOperationSupported.supported) {
@@ -4490,16 +4556,16 @@ class IntentsController {
4490
4556
  return result.intents;
4491
4557
  }
4492
4558
  addIntentListener(intent, handler) {
4493
- AddIntentListenerDecoder.runWithException(intent);
4559
+ runDecoderWithIOError(AddIntentListenerDecoder, intent);
4494
4560
  if (typeof handler !== "function") {
4495
- throw new Error("Cannot add intent listener, because the provided handler is not a function!");
4561
+ return ioError.raiseError("Cannot add intent listener, because the provided handler is not a function!");
4496
4562
  }
4497
4563
  let registerPromise;
4498
4564
  const intentName = typeof intent === "string" ? intent : intent.intent;
4499
4565
  const methodName = this.buildInteropMethodName(intentName);
4500
4566
  const alreadyRegistered = this.myIntents.has(intentName);
4501
4567
  if (alreadyRegistered) {
4502
- throw new Error(`Intent listener for intent ${intentName} already registered!`);
4568
+ return ioError.raiseError(`Intent listener for intent ${intentName} already registered!`);
4503
4569
  }
4504
4570
  this.myIntents.add(intentName);
4505
4571
  const result = {
@@ -4528,16 +4594,16 @@ class IntentsController {
4528
4594
  return result;
4529
4595
  }
4530
4596
  async register(intent, handler) {
4531
- AddIntentListenerDecoder.runWithException(intent);
4597
+ runDecoderWithIOError(AddIntentListenerDecoder, intent);
4532
4598
  if (typeof handler !== "function") {
4533
- throw new Error("Cannot add intent listener, because the provided handler is not a function!");
4599
+ return ioError.raiseError("Cannot add intent listener, because the provided handler is not a function!");
4534
4600
  }
4535
4601
  await Promise.all(this.unregisterIntentPromises);
4536
4602
  const intentName = typeof intent === "string" ? intent : intent.intent;
4537
4603
  const methodName = this.buildInteropMethodName(intentName);
4538
4604
  const alreadyRegistered = this.myIntents.has(intentName);
4539
4605
  if (alreadyRegistered) {
4540
- throw new Error(`Intent listener for intent ${intentName} already registered!`);
4606
+ return ioError.raiseError(`Intent listener for intent ${intentName} already registered!`);
4541
4607
  }
4542
4608
  this.myIntents.add(intentName);
4543
4609
  let intentFlag = {};
@@ -4556,7 +4622,7 @@ class IntentsController {
4556
4622
  }
4557
4623
  catch (err) {
4558
4624
  this.myIntents.delete(intentName);
4559
- throw new Error(`Registration of a method with name ${methodName} failed with reason: ${JSON.stringify(err)}`);
4625
+ return ioError.raiseError(`Registration of a method with name ${methodName} failed with reason: ${JSON.stringify(err)}`);
4560
4626
  }
4561
4627
  return {
4562
4628
  unsubscribe: () => this.unsubscribeIntent(intentName)
@@ -4565,7 +4631,7 @@ class IntentsController {
4565
4631
  async find(intentFilter) {
4566
4632
  let data = undefined;
4567
4633
  if (typeof intentFilter !== "undefined") {
4568
- const intentFilterObj = findFilterDecoder.runWithException(intentFilter);
4634
+ const intentFilterObj = runDecoderWithIOError(findFilterDecoder, intentFilter);
4569
4635
  if (typeof intentFilterObj === "string") {
4570
4636
  data = {
4571
4637
  filter: {
@@ -4583,6 +4649,10 @@ class IntentsController {
4583
4649
  const result = await this.bridge.send("intents", operations$5.findIntent, data);
4584
4650
  return result.intents;
4585
4651
  }
4652
+ async clearSavedHandlers() {
4653
+ this.logger.trace("Removing all saved handlers from prefs storage for current app");
4654
+ await this.prefsController.update({ intents: undefined });
4655
+ }
4586
4656
  checkIfIntentsResolverIsEnabled(options) {
4587
4657
  this.useIntentsResolverUI = typeof options.intents?.enableIntentsResolverUI === "boolean"
4588
4658
  ? options.intents.enableIntentsResolverUI
@@ -4611,10 +4681,10 @@ class IntentsController {
4611
4681
  });
4612
4682
  }
4613
4683
  async filterHandlers(handlerFilter) {
4614
- handlersFilterDecoder.runWithException(handlerFilter);
4684
+ runDecoderWithIOError(handlersFilterDecoder, handlerFilter);
4615
4685
  this.checkIfAtLeastOneFilterIsPresent(handlerFilter);
4616
4686
  if (handlerFilter.openResolver && !this.useIntentsResolverUI) {
4617
- throw new Error("Cannot resolve 'filterHandlers' request using Intents Resolver UI because it's globally disabled");
4687
+ return ioError.raiseError("Cannot resolve 'filterHandlers' request using Intents Resolver UI because it's globally disabled");
4618
4688
  }
4619
4689
  const methodResponseTimeoutMs = (handlerFilter.timeout || DEFAULT_PICK_HANDLER_BY_TIMEOUT) + ADDITIONAL_BRIDGE_OPERATION_TIMEOUT;
4620
4690
  const filterHandlersRequestWithResolverConfig = { filterHandlersRequest: handlerFilter, resolverConfig: this.getResolverConfigByRequest({ handlerFilter }) };
@@ -4624,36 +4694,71 @@ class IntentsController {
4624
4694
  checkIfAtLeastOneFilterIsPresent(filter) {
4625
4695
  const errorMsg = "Provide at least one filter criteria of the following: 'intent' | 'contextTypes' | 'resultType' | 'applicationNames'";
4626
4696
  if (!Object.keys(filter).length) {
4627
- throw new Error(errorMsg);
4697
+ return ioError.raiseError(errorMsg);
4628
4698
  }
4629
4699
  const { intent, resultType, contextTypes, applicationNames } = filter;
4630
4700
  const existingValidContextTypes = contextTypes?.length;
4631
4701
  const existingValidApplicationNames = applicationNames?.length;
4632
4702
  if (!intent && !resultType && !existingValidContextTypes && !existingValidApplicationNames) {
4633
- throw new Error(errorMsg);
4703
+ return ioError.raiseError(errorMsg);
4634
4704
  }
4635
4705
  }
4636
4706
  async getIntentsByHandler(handler) {
4637
- intentHandlerDecoder.runWithException(handler);
4707
+ runDecoderWithIOError(intentHandlerDecoder, handler);
4638
4708
  const result = await this.bridge.send("intents", operations$5.getIntentsByHandler, handler, undefined, { includeOperationCheck: true });
4639
4709
  return result;
4640
4710
  }
4711
+ async removeRememberedHandler(intentName) {
4712
+ this.logger.trace(`Removing saved handler from prefs storage for intent ${intentName}`);
4713
+ const prefs = await this.prefsController.get();
4714
+ const intentPrefs = prefs.data?.intents;
4715
+ if (!intentPrefs) {
4716
+ this.logger.trace("No app prefs found for current app");
4717
+ return;
4718
+ }
4719
+ delete intentPrefs[intentName];
4720
+ const updatedPrefs = {
4721
+ ...prefs.data,
4722
+ intents: intentPrefs
4723
+ };
4724
+ await this.prefsController.update(updatedPrefs);
4725
+ this.logger.trace(`Handler saved choice for intent ${intentName} removed successfully`);
4726
+ }
4727
+ async checkForRememberedHandler(intentRequest) {
4728
+ const prefs = await this.prefsController.get();
4729
+ const prefsForIntent = prefs.data?.intents?.[intentRequest.intent];
4730
+ return prefsForIntent?.handler;
4731
+ }
4732
+ async checkHandleRaiseWithRememberedHandler(intentRequest) {
4733
+ const rememberedHandler = await this.checkForRememberedHandler(intentRequest);
4734
+ if (!rememberedHandler) {
4735
+ return;
4736
+ }
4737
+ const operationData = {
4738
+ intentRequest: {
4739
+ ...intentRequest,
4740
+ target: {
4741
+ app: rememberedHandler.applicationName,
4742
+ instance: rememberedHandler.instanceId
4743
+ }
4744
+ },
4745
+ resolverConfig: {
4746
+ enabled: false,
4747
+ appName: this.intentsResolverAppName,
4748
+ waitResponseTimeout: intentRequest.timeout || DEFAULT_PICK_HANDLER_BY_TIMEOUT
4749
+ }
4750
+ };
4751
+ try {
4752
+ const response = await this.bridge.send("intents", operations$5.raise, operationData);
4753
+ return response;
4754
+ }
4755
+ catch (error) {
4756
+ this.logger.trace("Could not raise intent to remembered handler. Removing it from Prefs store");
4757
+ await this.removeRememberedHandler(intentRequest.intent);
4758
+ }
4759
+ }
4641
4760
  }
4642
4761
 
4643
- const Glue42CoreMessageTypes = {
4644
- platformUnload: { name: "platformUnload" },
4645
- transportSwitchRequest: { name: "transportSwitchRequest" },
4646
- transportSwitchResponse: { name: "transportSwitchResponse" },
4647
- getCurrentTransport: { name: "getCurrentTransport" },
4648
- getCurrentTransportResponse: { name: "getCurrentTransportResponse" },
4649
- checkPreferredLogic: { name: "checkPreferredLogic" },
4650
- checkPreferredConnection: { name: "checkPreferredConnection" },
4651
- checkPreferredLogicResponse: { name: "checkPreferredLogicResponse" },
4652
- checkPreferredConnectionResponse: { name: "checkPreferredConnectionResponse" }
4653
- };
4654
- const webPlatformTransportName = "web-platform";
4655
- const latestFDC3Type = "latest_fdc3_type";
4656
-
4657
4762
  const operations$4 = {
4658
4763
  addChannel: { name: "addChannel", dataDecoder: channelContextDecoder },
4659
4764
  removeChannel: { name: "removeChannel", dataDecoder: removeChannelDataDecoder },
@@ -4701,14 +4806,14 @@ class ChannelsController {
4701
4806
  coreGlue.channels = api;
4702
4807
  }
4703
4808
  async handleBridgeMessage(args) {
4704
- const operationName = channelsOperationTypesDecoder.runWithException(args.operation);
4809
+ const operationName = runDecoderWithIOError(channelsOperationTypesDecoder, args.operation);
4705
4810
  const operation = operations$4[operationName];
4706
4811
  if (!operation.execute) {
4707
4812
  return;
4708
4813
  }
4709
4814
  let operationData = args.data;
4710
4815
  if (operation.dataDecoder) {
4711
- operationData = operation.dataDecoder.runWithException(args.data);
4816
+ operationData = runDecoderWithIOError(operation.dataDecoder, args.data);
4712
4817
  }
4713
4818
  return await operation.execute(operationData);
4714
4819
  }
@@ -4726,8 +4831,8 @@ class ChannelsController {
4726
4831
  }
4727
4832
  async join(name, windowId) {
4728
4833
  const channelNames = this.getAllChannelNames();
4729
- channelNameDecoder(channelNames).runWithException(name);
4730
- optionalNonEmptyStringDecoder.runWithException(windowId);
4834
+ runDecoderWithIOError(channelNameDecoder(channelNames), name);
4835
+ runDecoderWithIOError(optionalNonEmptyStringDecoder, windowId);
4731
4836
  if (!windowId || windowId === this.windowsController.my().id) {
4732
4837
  await this.switchToChannel(name);
4733
4838
  }
@@ -4824,16 +4929,16 @@ class ChannelsController {
4824
4929
  return;
4825
4930
  }
4826
4931
  if (fdc3PropsArr.length > 1) {
4827
- throw new Error("FDC3 does not support updating of multiple context keys");
4932
+ return ioError.raiseError("FDC3 does not support updating of multiple context keys");
4828
4933
  }
4829
4934
  return fdc3PropsArr[0].split("_").slice(1).join("_");
4830
4935
  }
4831
4936
  subscribe(callback) {
4832
4937
  if (typeof callback !== "function") {
4833
- throw new Error("Cannot subscribe to channels, because the provided callback is not a function!");
4938
+ return ioError.raiseError("Cannot subscribe to channels, because the provided callback is not a function!");
4834
4939
  }
4835
4940
  const currentChannel = this.current();
4836
- const wrappedCallback = this.getWrappedCallbackWithPermissionCheck(callback);
4941
+ const wrappedCallback = this.getWrappedSubscribeCallback(callback);
4837
4942
  if (currentChannel) {
4838
4943
  this.replaySubscribe(wrappedCallback, currentChannel);
4839
4944
  }
@@ -4841,31 +4946,35 @@ class ChannelsController {
4841
4946
  }
4842
4947
  async subscribeFor(name, callback) {
4843
4948
  const channelNames = this.getAllChannelNames();
4844
- channelNameDecoder(channelNames).runWithException(name);
4949
+ runDecoderWithIOError(channelNameDecoder(channelNames), name);
4845
4950
  if (typeof callback !== "function") {
4846
- throw new Error(`Cannot subscribe to channel ${name}, because the provided callback is not a function!`);
4951
+ return ioError.raiseError(`Cannot subscribe to channel ${name}, because the provided callback is not a function!`);
4847
4952
  }
4848
4953
  const contextName = this.createContextName(name);
4849
- const wrappedCallback = this.getWrappedCallbackWithPermissionCheck(callback);
4954
+ const wrappedCallback = this.getWrappedSubscribeCallback(callback);
4850
4955
  return this.contexts.subscribe(contextName, (context, _, __, ___, extraData) => {
4851
4956
  wrappedCallback(context.data, context, extraData?.updaterId);
4852
4957
  });
4853
4958
  }
4854
- publish(data, name) {
4959
+ async publish(data, options) {
4855
4960
  if (typeof data !== "object") {
4856
- throw new Error("Cannot publish to channel, because the provided data is not an object!");
4961
+ return ioError.raiseError("Cannot publish to channel, because the provided data is not an object!");
4857
4962
  }
4858
- if (typeof name !== "undefined") {
4963
+ runDecoderWithIOError(publishOptionsDecoder, options);
4964
+ if (typeof options === "object") {
4965
+ return this.publishWithOptions(data, options);
4966
+ }
4967
+ if (typeof options === "string") {
4859
4968
  const channelNames = this.getAllChannelNames();
4860
- channelNameDecoder(channelNames).runWithException(name);
4969
+ runDecoderWithIOError(channelNameDecoder(channelNames), options);
4861
4970
  }
4862
- const channelName = name || this.currentChannelName;
4971
+ const channelName = typeof options === "string" ? options : this.currentChannelName;
4863
4972
  if (!channelName) {
4864
- throw new Error("Cannot publish to channel, because not joined to a channel!");
4973
+ return ioError.raiseError("Cannot publish to channel, because not joined to a channel!");
4865
4974
  }
4866
4975
  const canPublish = this.isAllowedByRestrictions(channelName, "write");
4867
4976
  if (!canPublish) {
4868
- throw new Error(`Cannot publish on channel ${channelName} due to restrictions`);
4977
+ return ioError.raiseError(`Cannot publish on channel ${channelName} due to restrictions`);
4869
4978
  }
4870
4979
  return this.updateData(channelName, data);
4871
4980
  }
@@ -4875,38 +4984,52 @@ class ChannelsController {
4875
4984
  }
4876
4985
  async get(name) {
4877
4986
  const channelNames = this.getAllChannelNames();
4878
- channelNameDecoder(channelNames).runWithException(name);
4987
+ runDecoderWithIOError(channelNameDecoder(channelNames), name);
4879
4988
  const contextName = this.createContextName(name);
4880
4989
  const channelContext = await this.contexts.get(contextName);
4881
4990
  if (channelContext.latest_fdc3_type) {
4882
- const { latest_fdc3_type, ...rest } = channelContext;
4883
- return { ...rest };
4991
+ return this.getContextWithFdc3Data(channelContext);
4884
4992
  }
4885
4993
  return channelContext;
4886
4994
  }
4995
+ getContextWithFdc3Data(channelContext) {
4996
+ const { latest_fdc3_type, ...rest } = channelContext;
4997
+ const parsedType = latest_fdc3_type.split("&").join(".");
4998
+ const fdc3Context = { type: parsedType, ...rest.data[`fdc3_${latest_fdc3_type}`] };
4999
+ delete rest.data[`fdc3_${latest_fdc3_type}`];
5000
+ const context = {
5001
+ name: channelContext.name,
5002
+ meta: channelContext.meta,
5003
+ data: {
5004
+ ...rest.data,
5005
+ fdc3: fdc3Context
5006
+ }
5007
+ };
5008
+ return context;
5009
+ }
4887
5010
  current() {
4888
5011
  return this.currentChannelName;
4889
5012
  }
4890
5013
  changed(callback) {
4891
5014
  if (typeof callback !== "function") {
4892
- throw new Error("Cannot subscribe to channel changed, because the provided callback is not a function!");
5015
+ return ioError.raiseError("Cannot subscribe to channel changed, because the provided callback is not a function!");
4893
5016
  }
4894
5017
  return this.registry.add(this.ChangedKey, callback);
4895
5018
  }
4896
5019
  async add(info) {
4897
- const channelContext = channelContextDecoder.runWithException(info);
5020
+ const channelContext = runDecoderWithIOError(channelContextDecoder, info);
4898
5021
  const channelWithSuchNameExists = this.getAllChannelNames().includes(channelContext.name);
4899
5022
  if (channelWithSuchNameExists) {
4900
- throw new Error("There's an already existing channel with such name");
5023
+ return ioError.raiseError("There's an already existing channel with such name");
4901
5024
  }
4902
5025
  await this.bridge.send("channels", operations$4.addChannel, channelContext);
4903
5026
  return channelContext;
4904
5027
  }
4905
5028
  async remove(name) {
4906
- nonEmptyStringDecoder.runWithException(name);
5029
+ runDecoderWithIOError(nonEmptyStringDecoder, name);
4907
5030
  const channelWithSuchNameExists = this.getAllChannelNames().includes(name);
4908
5031
  if (!channelWithSuchNameExists) {
4909
- throw new Error("There's no channel with such name");
5032
+ return ioError.raiseError("There's no channel with such name");
4910
5033
  }
4911
5034
  await this.bridge.send("channels", operations$4.removeChannel, { name }, undefined, { includeOperationCheck: true });
4912
5035
  }
@@ -4936,7 +5059,7 @@ class ChannelsController {
4936
5059
  }
4937
5060
  async getWindowsOnChannel(channel) {
4938
5061
  const channelNames = this.getAllChannelNames();
4939
- channelNameDecoder(channelNames).runWithException(channel);
5062
+ runDecoderWithIOError(channelNameDecoder(channelNames), channel);
4940
5063
  const { windowIds } = await this.bridge.send("channels", operations$4.getWindowIdsOnChannel, { channel }, undefined, { includeOperationCheck: true });
4941
5064
  const result = windowIds.reduce((windows, windowId) => {
4942
5065
  const window = this.windowsController.findById(windowId);
@@ -4946,7 +5069,7 @@ class ChannelsController {
4946
5069
  }
4947
5070
  async getWindowsWithChannels(filter) {
4948
5071
  const operationData = filter !== undefined
4949
- ? { filter: windowWithChannelFilterDecoder.runWithException(filter) }
5072
+ ? { filter: runDecoderWithIOError(windowWithChannelFilterDecoder, filter) }
4950
5073
  : {};
4951
5074
  const { windowIdsWithChannels } = await this.bridge.send("channels", operations$4.getWindowIdsWithChannels, operationData, undefined, { includeOperationCheck: true });
4952
5075
  const result = windowIdsWithChannels.reduce((windowsWithChannels, { application, channel, windowId }) => {
@@ -4956,9 +5079,9 @@ class ChannelsController {
4956
5079
  return result;
4957
5080
  }
4958
5081
  async restrict(config) {
4959
- channelRestrictionsDecoder.runWithException(config);
5082
+ runDecoderWithIOError(channelRestrictionsDecoder, config);
4960
5083
  const channelNames = this.getAllChannelNames();
4961
- channelNameDecoder(channelNames).runWithException(config.name);
5084
+ runDecoderWithIOError(channelNameDecoder(channelNames), config.name);
4962
5085
  const forAnotherClient = config.windowId && config.windowId !== this.windowsController.my().id;
4963
5086
  if (forAnotherClient) {
4964
5087
  return this.bridge.send("channels", operations$4.restrict, { config }, undefined, { includeOperationCheck: true });
@@ -4974,14 +5097,14 @@ class ChannelsController {
4974
5097
  this.replaySubscribeCallback(config.name);
4975
5098
  }
4976
5099
  async getRestrictions(windowId) {
4977
- optionalNonEmptyStringDecoder.runWithException(windowId);
5100
+ runDecoderWithIOError(optionalNonEmptyStringDecoder, windowId);
4978
5101
  if (!windowId || windowId === this.windowsController.my().id) {
4979
5102
  return this.getMyRestrictions();
4980
5103
  }
4981
5104
  return this.bridge.send("channels", operations$4.getRestrictions, { windowId }, undefined, { includeOperationCheck: true });
4982
5105
  }
4983
5106
  async restrictAll(restrictions) {
4984
- restrictionsConfigDecoder.runWithException(restrictions);
5107
+ runDecoderWithIOError(restrictionsConfigDecoder, restrictions);
4985
5108
  const allChannelNames = this.getAllChannelNames();
4986
5109
  const forAnotherClient = restrictions.windowId && restrictions.windowId !== this.windowsController.my().id;
4987
5110
  if (forAnotherClient) {
@@ -5012,16 +5135,6 @@ class ChannelsController {
5012
5135
  const restrictions = Object.values(sessionStorageData?.restrictions || {});
5013
5136
  return { channels: restrictions };
5014
5137
  }
5015
- getWrappedCallbackWithPermissionCheck(callback) {
5016
- const wrappedCallback = (data, context, updaterId) => {
5017
- const canRead = this.isAllowedByRestrictions(context.name, "read");
5018
- if (!canRead) {
5019
- return;
5020
- }
5021
- callback(data, context, updaterId);
5022
- };
5023
- return wrappedCallback;
5024
- }
5025
5138
  replaySubscribeCallback(channelName) {
5026
5139
  const contextName = this.createContextName(channelName);
5027
5140
  this.contexts.subscribe(contextName, (context, _, __, ___, extraData) => {
@@ -5042,32 +5155,82 @@ class ChannelsController {
5042
5155
  }
5043
5156
  return prevRestrictions[channelName].read;
5044
5157
  }
5158
+ async publishWithOptions(data, options) {
5159
+ if (options.name) {
5160
+ const channelNames = this.getAllChannelNames();
5161
+ runDecoderWithIOError(channelNameDecoder(channelNames), options.name);
5162
+ }
5163
+ const channelName = options.name || this.currentChannelName;
5164
+ if (!channelName) {
5165
+ return ioError.raiseError("Cannot publish to channel, because not joined to a channel!");
5166
+ }
5167
+ const canPublish = this.isAllowedByRestrictions(channelName, "write");
5168
+ if (!canPublish) {
5169
+ return ioError.raiseError(`Cannot publish on channel ${channelName} due to restrictions`);
5170
+ }
5171
+ if (!options.fdc3) {
5172
+ return this.updateData(channelName, data);
5173
+ }
5174
+ return this.publishFdc3Data(channelName, data);
5175
+ }
5176
+ async publishFdc3Data(channelName, data) {
5177
+ runDecoderWithIOError(fdc3ContextDecoder, data);
5178
+ const { type, ...rest } = data;
5179
+ const parsedType = type.split(".").join("&");
5180
+ const fdc3DataToPublish = { [`fdc3_${parsedType}`]: rest };
5181
+ return this.updateData(channelName, fdc3DataToPublish);
5182
+ }
5183
+ getWrappedSubscribeCallback(callback) {
5184
+ const wrappedCallback = (channelData, context, updaterId) => {
5185
+ const canRead = this.isAllowedByRestrictions(context.name, "read");
5186
+ if (!canRead) {
5187
+ return;
5188
+ }
5189
+ const { data, latest_fdc3_type } = context;
5190
+ if (!latest_fdc3_type) {
5191
+ callback(channelData, context, updaterId);
5192
+ return;
5193
+ }
5194
+ const parsedType = latest_fdc3_type.split("&").join(".");
5195
+ const latestTypePropName = `fdc3_${latest_fdc3_type}`;
5196
+ const fdc3Data = { type: parsedType, ...data[latestTypePropName] };
5197
+ const { [latestTypePropName]: latestFDC3Type, ...rest } = channelData;
5198
+ callback({ ...rest, fdc3: fdc3Data }, context, updaterId);
5199
+ };
5200
+ return wrappedCallback;
5201
+ }
5045
5202
  }
5046
5203
 
5047
5204
  const operations$3 = {
5048
5205
  getEnvironment: { name: "getEnvironment", resultDecoder: anyDecoder },
5049
5206
  getBase: { name: "getBase", resultDecoder: anyDecoder },
5050
- platformShutdown: { name: "platformShutdown" }
5207
+ platformShutdown: { name: "platformShutdown" },
5208
+ isFdc3DataWrappingSupported: { name: "isFdc3DataWrappingSupported" },
5209
+ clientError: { name: "clientError", dataDecoder: clientErrorDataDecoder },
5051
5210
  };
5052
5211
 
5053
5212
  class SystemController {
5054
5213
  bridge;
5055
5214
  ioc;
5215
+ errorPort = errorChannel.port2;
5056
5216
  async start(coreGlue, ioc) {
5057
5217
  this.bridge = ioc.bridge;
5058
5218
  this.ioc = ioc;
5059
5219
  this.addOperationsExecutors();
5220
+ this.errorPort.onmessage = async (event) => {
5221
+ await this.bridge.send("system", operations$3.clientError, { message: event.data }, undefined, { includeOperationCheck: true });
5222
+ };
5060
5223
  await this.setEnvironment();
5061
5224
  }
5062
5225
  async handleBridgeMessage(args) {
5063
- const operationName = systemOperationTypesDecoder.runWithException(args.operation);
5226
+ const operationName = runDecoderWithIOError(systemOperationTypesDecoder, args.operation);
5064
5227
  const operation = operations$3[operationName];
5065
5228
  if (!operation.execute) {
5066
5229
  return;
5067
5230
  }
5068
5231
  let operationData = args.data;
5069
5232
  if (operation.dataDecoder) {
5070
- operationData = operation.dataDecoder.runWithException(args.data);
5233
+ operationData = runDecoderWithIOError(operation.dataDecoder, args.data);
5071
5234
  }
5072
5235
  return await operation.execute(operationData);
5073
5236
  }
@@ -5087,6 +5250,10 @@ class SystemController {
5087
5250
  }
5088
5251
  addOperationsExecutors() {
5089
5252
  operations$3.platformShutdown.execute = this.processPlatformShutdown.bind(this);
5253
+ operations$3.isFdc3DataWrappingSupported.execute = this.handleIsFdc3DataWrappingSupported.bind(this);
5254
+ }
5255
+ async handleIsFdc3DataWrappingSupported() {
5256
+ return { isSupported: true };
5090
5257
  }
5091
5258
  }
5092
5259
 
@@ -5318,7 +5485,7 @@ class PreferredConnectionController {
5318
5485
  }
5319
5486
  const isConnectedToPlatform = this.coreGlue.connection.transport.name() === webPlatformTransportName;
5320
5487
  if (!isConnectedToPlatform) {
5321
- throw new Error("Cannot initiate the Glue Web Bridge, because the initial connection was not handled by a Web Platform transport.");
5488
+ return ioError.raiseError("Cannot initiate the Glue Web Bridge, because the initial connection was not handled by a Web Platform transport.");
5322
5489
  }
5323
5490
  if (!this.coreGlue.connection.transport.isPreferredActivated) {
5324
5491
  this.logger.trace("The platform of this client was configured without a preferred connection, skipping the rest of the initialization.");
@@ -5499,7 +5666,7 @@ class LegacyIntentsHelper {
5499
5666
  const { intentRequest, resolverConfig } = requestWithResolverInfo;
5500
5667
  const intent = (await findIntentFn(intentRequest.intent)).find(intent => intent.name === intentRequest.intent);
5501
5668
  if (!intent) {
5502
- throw new Error(`Intent with name ${intentRequest.intent} not found`);
5669
+ return ioError.raiseError(`Intent with name ${intentRequest.intent} not found`);
5503
5670
  }
5504
5671
  const { open, reason } = this.checkIfResolverShouldBeOpened(intent, intentRequest, resolverConfig);
5505
5672
  if (!open) {
@@ -5536,7 +5703,7 @@ class LegacyIntentsHelper {
5536
5703
  }
5537
5704
  catch (error) {
5538
5705
  this.stopResolverInstance(instanceId);
5539
- throw new Error(error);
5706
+ return ioError.raiseError(error);
5540
5707
  }
5541
5708
  }
5542
5709
  invokeRaiseIntent(requestObj) {
@@ -5732,12 +5899,12 @@ class ThemesController {
5732
5899
  return bridgeResponse.themes;
5733
5900
  }
5734
5901
  async select(name) {
5735
- nonEmptyStringDecoder.runWithException(name);
5902
+ runDecoderWithIOError(nonEmptyStringDecoder, name);
5736
5903
  await this.bridge.send("themes", operations$1.select, { name }, undefined, { includeOperationCheck: true });
5737
5904
  }
5738
5905
  async onChanged(callback) {
5739
5906
  if (typeof callback !== "function") {
5740
- throw new Error("onChanged requires a callback of type function");
5907
+ return ioError.raiseError("onChanged requires a callback of type function");
5741
5908
  }
5742
5909
  const subReady = this.themesSubscription ?
5743
5910
  Promise.resolve() :
@@ -5849,17 +6016,27 @@ class PrefsController {
5849
6016
  coreGlue.prefs = api;
5850
6017
  }
5851
6018
  async handleBridgeMessage(args) {
5852
- const operationName = prefsOperationTypesDecoder.runWithException(args.operation);
6019
+ const operationName = runDecoderWithIOError(prefsOperationTypesDecoder, args.operation);
5853
6020
  const operation = operations[operationName];
5854
6021
  if (!operation.execute) {
5855
6022
  return;
5856
6023
  }
5857
6024
  let operationData = args.data;
5858
6025
  if (operation.dataDecoder) {
5859
- operationData = operation.dataDecoder.runWithException(args.data);
6026
+ operationData = runDecoderWithIOError(operation.dataDecoder, args.data);
5860
6027
  }
5861
6028
  return await operation.execute(operationData);
5862
6029
  }
6030
+ async get(app) {
6031
+ const verifiedApp = app === undefined || app === null ? this.getMyAppName() : nonEmptyStringDecoder.runWithException(app);
6032
+ const { prefs } = await this.bridge.send("prefs", operations.get, { app: verifiedApp }, undefined, { includeOperationCheck: true });
6033
+ return prefs;
6034
+ }
6035
+ async update(data, options) {
6036
+ const verifiedOptions = optional$1(basePrefsConfigDecoder).runWithException(options);
6037
+ const app = verifiedOptions?.app ?? this.getMyAppName();
6038
+ await this.updateFor(app, data);
6039
+ }
5863
6040
  addOperationsExecutors() {
5864
6041
  operations.prefsChanged.execute = this.handleOnChanged.bind(this);
5865
6042
  }
@@ -5887,26 +6064,21 @@ class PrefsController {
5887
6064
  await this.bridge.send("prefs", operations.clearAll, undefined, undefined, { includeOperationCheck: true });
5888
6065
  }
5889
6066
  async clearFor(app) {
5890
- const verifiedApp = nonEmptyStringDecoder.runWithException(app);
6067
+ const verifiedApp = runDecoderWithIOError(nonEmptyStringDecoder, app);
5891
6068
  await this.bridge.send("prefs", operations.clear, { app: verifiedApp }, undefined, { includeOperationCheck: true });
5892
6069
  }
5893
- async get(app) {
5894
- const verifiedApp = app === undefined || app === null ? this.getMyAppName() : nonEmptyStringDecoder.runWithException(app);
5895
- const { prefs } = await this.bridge.send("prefs", operations.get, { app: verifiedApp }, undefined, { includeOperationCheck: true });
5896
- return prefs;
5897
- }
5898
6070
  async getAll() {
5899
6071
  const result = await this.bridge.send("prefs", operations.getAll, undefined, undefined, { includeOperationCheck: true });
5900
6072
  return result;
5901
6073
  }
5902
6074
  async set(data, options) {
5903
- const verifiedOptions = optional$1(basePrefsConfigDecoder).runWithException(options);
6075
+ const verifiedOptions = runDecoderWithIOError(optional$1(basePrefsConfigDecoder), options);
5904
6076
  const app = verifiedOptions?.app ?? this.getMyAppName();
5905
6077
  await this.setFor(app, data);
5906
6078
  }
5907
6079
  async setFor(app, data) {
5908
- const verifiedApp = nonEmptyStringDecoder.runWithException(app);
5909
- const verifiedData = object$1().runWithException(data);
6080
+ const verifiedApp = runDecoderWithIOError(nonEmptyStringDecoder, app);
6081
+ const verifiedData = runDecoderWithIOError(object$1(), data);
5910
6082
  await this.bridge.send("prefs", operations.set, { app: verifiedApp, data: verifiedData }, undefined, { includeOperationCheck: true });
5911
6083
  }
5912
6084
  subscribe(callback) {
@@ -5914,33 +6086,28 @@ class PrefsController {
5914
6086
  return this.subscribeFor(app, callback);
5915
6087
  }
5916
6088
  subscribeFor(app, callback) {
5917
- const verifiedApp = nonEmptyStringDecoder.runWithException(app);
6089
+ const verifiedApp = runDecoderWithIOError(nonEmptyStringDecoder, app);
5918
6090
  const applications = this.appManagerController.getApplications();
5919
6091
  const isValidApp = verifiedApp === this.platformAppName || applications.some((application) => application.name === verifiedApp);
5920
6092
  if (!isValidApp) {
5921
- throw new Error(`The provided app name "${app}" is not valid.`);
6093
+ return ioError.raiseError(`The provided app name "${app}" is not valid.`);
5922
6094
  }
5923
6095
  if (typeof callback !== "function") {
5924
- throw new Error("Cannot subscribe to prefs, because the provided callback is not a function!");
6096
+ return ioError.raiseError("Cannot subscribe to prefs, because the provided callback is not a function!");
5925
6097
  }
5926
6098
  const subscriptionKey = this.getSubscriptionKey(verifiedApp);
5927
6099
  this.get(verifiedApp).then(callback);
5928
6100
  return this.registry.add(subscriptionKey, callback);
5929
6101
  }
5930
- async update(data, options) {
5931
- const verifiedOptions = optional$1(basePrefsConfigDecoder).runWithException(options);
5932
- const app = verifiedOptions?.app ?? this.getMyAppName();
5933
- await this.updateFor(app, data);
5934
- }
5935
6102
  async updateFor(app, data) {
5936
- const verifiedApp = nonEmptyStringDecoder.runWithException(app);
5937
- const verifiedData = object$1().runWithException(data);
6103
+ const verifiedApp = runDecoderWithIOError(nonEmptyStringDecoder, app);
6104
+ const verifiedData = runDecoderWithIOError(object$1(), data);
5938
6105
  await this.bridge.send("prefs", operations.update, { app: verifiedApp, data: verifiedData }, undefined, { includeOperationCheck: true });
5939
6106
  }
5940
6107
  getMyAppName() {
5941
6108
  const myAppName = this.config.isPlatformInternal ? this.platformAppName : this.appManagerController.me?.application.name;
5942
6109
  if (!myAppName) {
5943
- throw new Error("App Preferences operations can not be executed for windows that do not have app!");
6110
+ return ioError.raiseError("App Preferences operations can not be executed for windows that do not have app!");
5944
6111
  }
5945
6112
  return myAppName;
5946
6113
  }
@@ -6112,7 +6279,7 @@ class IoC {
6112
6279
  }
6113
6280
  }
6114
6281
 
6115
- var version$1 = "3.3.4";
6282
+ var version$1 = "3.3.5-next.0";
6116
6283
 
6117
6284
  const createFactoryFunction = (coreFactoryFunction) => {
6118
6285
  return async (userConfig) => {
@@ -6132,11 +6299,16 @@ const createFactoryFunction = (coreFactoryFunction) => {
6132
6299
  logger.trace("the bridge has been started, initializing all controllers");
6133
6300
  await Promise.all(Object.values(ioc.controllers).map((controller) => controller.start(glue, ioc)));
6134
6301
  logger.trace("all controllers reported started, starting all additional libraries");
6135
- await Promise.all(config.libraries.map((lib) => lib(glue, config)));
6136
- logger.trace("all libraries were started");
6137
- ioc.eventsDispatcher.start(glue);
6138
- logger.trace("start event dispatched, glue is ready, returning it");
6139
- return glue;
6302
+ try {
6303
+ await Promise.all(config.libraries.map((lib) => lib(glue, config)));
6304
+ logger.trace("all libraries were started");
6305
+ ioc.eventsDispatcher.start(glue);
6306
+ logger.trace("start event dispatched, glue is ready, returning it");
6307
+ return glue;
6308
+ }
6309
+ catch (error) {
6310
+ return ioError.raiseError(error, true);
6311
+ }
6140
6312
  };
6141
6313
  };
6142
6314
 
@@ -9069,7 +9241,7 @@ const ContextMessageReplaySpec = {
9069
9241
  }
9070
9242
  };
9071
9243
 
9072
- var version = "6.3.4";
9244
+ var version = "6.3.5-next.0";
9073
9245
 
9074
9246
  function prepareConfig (configuration, ext, glue42gd) {
9075
9247
  let nodeStartingContext;