@interopio/fdc3-web-bridge 1.1.0 → 1.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Tick42
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Tick42
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/changelog.md CHANGED
@@ -1,4 +1,6 @@
1
- 1.1.0
2
- feat: io.Connect Browser 4.1
3
- 1.0.0
1
+ 1.2.0
2
+ feat: io.Connect Browser 4.2
3
+ 1.1.0
4
+ feat: io.Connect Browser 4.1
5
+ 1.0.0
4
6
  feat: Initial release with io.Connect Browser 4.0
@@ -1577,6 +1577,9 @@ Decoder.lazy;
1577
1577
 
1578
1578
  const nonEmptyStringDecoder$4 = string().where((s) => s.length > 0, "Expected a non-empty string");
1579
1579
  const nonNegativeNumberDecoder = number().where((num) => num >= 0, "Expected a non-negative number");
1580
+ const regexDecoder = anyJson().andThen((value) => {
1581
+ return value instanceof RegExp ? anyJson() : fail(`expected a regex, got a ${typeof value}`);
1582
+ });
1580
1583
 
1581
1584
  const intentDefinitionDecoder = object({
1582
1585
  name: nonEmptyStringDecoder$4,
@@ -1903,7 +1906,8 @@ class FDC3Service {
1903
1906
  const decoders$1 = {
1904
1907
  common: {
1905
1908
  nonEmptyStringDecoder: nonEmptyStringDecoder$4,
1906
- nonNegativeNumberDecoder
1909
+ nonNegativeNumberDecoder,
1910
+ regexDecoder
1907
1911
  },
1908
1912
  fdc3: {
1909
1913
  allDefinitionsDecoder,
@@ -1993,7 +1997,7 @@ const wcp1HelloPayloadDecoder = object$1({
1993
1997
  channelSelector: optional$1(boolean$1()),
1994
1998
  fdc3Version: nonEmptyStringDecoder$3,
1995
1999
  identityUrl: nonEmptyStringDecoder$3,
1996
- resolver: optional$1(boolean$1())
2000
+ intentResolver: optional$1(boolean$1())
1997
2001
  });
1998
2002
  const wcp1HelloMetaDecoder = object$1({
1999
2003
  connectionAttemptUuid: nonEmptyStringDecoder$3,
@@ -2833,13 +2837,14 @@ class BridgeController {
2833
2837
  }
2834
2838
  handleHelloConnectionRequest(source, origin, data) {
2835
2839
  if (this._messageChannel) {
2836
- console.warn(`${WCPMessageTypes.WCP1Hello} already heard. Message channel port created`);
2840
+ this.logMessage({ level: "warn", message: `${WCPMessageTypes.WCP1Hello} already heard. Message channel port created` });
2837
2841
  return;
2838
2842
  }
2843
+ this.logMessage({ level: "info", message: `Received ${WCPMessageTypes.WCP1Hello} request: ${JSON.stringify(data)} from origin: ${origin}` });
2839
2844
  const decodedRequest = wcp1HelloDecoder.run(data);
2840
2845
  if (!decodedRequest.ok) {
2841
2846
  const errorMsg = `Received invalid '${WCPMessageTypes.WCP1Hello}' request: ${JSON.stringify(data)}. Reason: ${decodedRequest.error.message} at ${decodedRequest.error.at}`;
2842
- console.error(errorMsg);
2847
+ this.logMessage({ level: "error", message: errorMsg });
2843
2848
  source.postMessage({ error: "MalformedMessage", message: errorMsg }, origin);
2844
2849
  return;
2845
2850
  }
@@ -2850,9 +2855,9 @@ class BridgeController {
2850
2855
  window.removeEventListener("message", this._globalMessageHandler);
2851
2856
  }
2852
2857
  async handlePortMessage(event) {
2853
- this.logger?.info(`Received port message with data: ${JSON.stringify(event.data)}}`);
2858
+ this.logMessage({ level: "info", message: `Received port message with data: ${JSON.stringify(event.data)}` });
2854
2859
  if (!this._connectionCompleted && event.data?.type !== WCPMessageTypes.WCP6Goodbye && event.data.type !== WCPMessageTypes.WCP4ValidateAppIdentity) {
2855
- console.warn("Web Connection Protocol not completed yet. Ignoring message");
2860
+ this.logMessage({ level: "warn", message: "Web Connection Protocol not completed yet. Ignoring message" });
2856
2861
  return;
2857
2862
  }
2858
2863
  if (event.data?.type === WCPMessageTypes.WCP4ValidateAppIdentity) {
@@ -2862,33 +2867,36 @@ class BridgeController {
2862
2867
  return this.handleGoodbyeRequest(event.data);
2863
2868
  }
2864
2869
  const result = await this.ioc.domainsController.handleMessage(event.data);
2865
- this.logger?.info(`Sending response message: ${JSON.stringify(result)}`);
2870
+ this.logMessage({ level: "info", message: `Sending response message: ${JSON.stringify(result)}` });
2866
2871
  this.sendMessage(result);
2867
2872
  }
2868
2873
  async handleAppIdentityValidationRequest(data) {
2869
2874
  const decodedRequest = wcp4ValidateAppIdentityDecoder.run(data);
2870
2875
  if (!decodedRequest.ok) {
2871
2876
  const errorMsg = `Received invalid '${WCPMessageTypes.WCP4ValidateAppIdentity}' request: ${JSON.stringify(data)}. Reason: ${decodedRequest.error.message} at ${decodedRequest.error.at}`;
2872
- console.error(errorMsg);
2877
+ this.logMessage({ level: "error", message: errorMsg });
2873
2878
  this.sendMessage({ error: "MalformedMessage", message: errorMsg });
2874
2879
  return;
2875
2880
  }
2876
2881
  const { actualUrl, identityUrl } = data.payload;
2877
2882
  await this.ioController.initializeLibs();
2878
2883
  this.logger = this.ioController.io?.logger.subLogger("bridge.controller");
2879
- this.logger?.info(`IOBrowser and FDC3 libs are initialized. Received ${data.type} request: ${JSON.stringify(data)}`);
2884
+ this.logMessage({ level: "info", message: `IOBrowser and FDC3 libs are initialized. Received ${data.type} request: ${JSON.stringify(data)}` });
2880
2885
  const validationResult = this.ioController.validateIdentity({ actualUrl, identityUrl, helloMsgOrigin: this._helloMessageOrigin });
2881
2886
  if (!validationResult.isValid) {
2882
- this.logger?.info(`App validation failure. Reason: ${validationResult.message}`);
2883
2887
  this.sendValidationFailure(data.meta.connectionAttemptUuid, validationResult.message);
2884
2888
  this.cleanSetup();
2885
2889
  return;
2886
2890
  }
2887
2891
  await this.sendValidationSuccess(data.meta.connectionAttemptUuid, validationResult.appId);
2888
- this.logger?.info(`App validation is successful. Connection is completed`);
2892
+ this.logMessage({ level: "info", message: `App validation is successful. Connection is completed` });
2889
2893
  this._connectionCompleted = true;
2890
2894
  }
2891
2895
  sendHandshake(source, origin, data) {
2896
+ this.ioc.uiConfig = {
2897
+ isChannelSelectorEnabled: !!data.payload.channelSelector,
2898
+ isIntentResolverEnabled: !!data.payload.intentResolver,
2899
+ };
2892
2900
  const handshakeMsg = {
2893
2901
  type: WCPMessageTypes.WCP3Handshake,
2894
2902
  meta: {
@@ -2896,12 +2904,13 @@ class BridgeController {
2896
2904
  timestamp: new Date()
2897
2905
  },
2898
2906
  payload: {
2899
- channelSelectorUrl: true,
2900
- intentResolverUrl: true,
2901
- fdc3Version: window.fdc3Info.standardVersion,
2907
+ channelSelectorUrl: this.ioc.uiConfig.isChannelSelectorEnabled,
2908
+ intentResolverUrl: this.ioc.uiConfig.isIntentResolverEnabled,
2909
+ fdc3Version: window.fdc3Info?.standardVersion,
2902
2910
  }
2903
2911
  };
2904
2912
  const transfer = this._messageChannel ? [this._messageChannel.port2] : undefined;
2913
+ this.logMessage({ level: "info", message: `Sending ${WCPMessageTypes.WCP3Handshake} message: ${JSON.stringify(handshakeMsg)} to origin: ${origin}` });
2905
2914
  source.postMessage(handshakeMsg, origin, transfer);
2906
2915
  }
2907
2916
  sendValidationFailure(attempt, errorMsg) {
@@ -2915,7 +2924,7 @@ class BridgeController {
2915
2924
  message: errorMsg
2916
2925
  }
2917
2926
  };
2918
- console.warn(`App Identity Validation failed. Reason: ${errorMsg}`);
2927
+ this.logMessage({ level: "error", message: `App validation failure. Reason: ${errorMsg}. Sending ${WCPMessageTypes.WCP5ValidateAppIdentityFailedResponse} message: ${JSON.stringify(validationFailureMsg)}` });
2919
2928
  this.sendMessage(validationFailureMsg);
2920
2929
  }
2921
2930
  async sendValidationSuccess(attempt, appId) {
@@ -2936,6 +2945,7 @@ class BridgeController {
2936
2945
  implementationMetadata
2937
2946
  }
2938
2947
  };
2948
+ this.logMessage({ level: "info", message: `App Identity Validation successful. Sending ${WCPMessageTypes.WCP5ValidateAppIdentityResponse} message: ${JSON.stringify(validationSuccessMsg)}` });
2939
2949
  this.sendMessage(validationSuccessMsg);
2940
2950
  }
2941
2951
  cleanSetup() {
@@ -2945,20 +2955,29 @@ class BridgeController {
2945
2955
  this._connectionCompleted = false;
2946
2956
  this._messageChannel = undefined;
2947
2957
  if (window.__karma__) {
2948
- this.configure();
2949
- this.ioController._initializationStarted = false;
2958
+ this.testCleanupSetup();
2950
2959
  }
2951
2960
  }
2961
+ testCleanupSetup() {
2962
+ this.ioc.resetState();
2963
+ this.ioc.bridgeController.configure();
2964
+ }
2952
2965
  handleGoodbyeRequest(data) {
2953
2966
  const decodedRequest = wcp6GoodbyeRequestDecoder.run(data);
2954
2967
  if (!decodedRequest.ok) {
2955
2968
  const errorMsg = `Received invalid '${WCPMessageTypes.WCP6Goodbye}' request: ${JSON.stringify(data)}. Reason: ${decodedRequest.error.message} at ${decodedRequest.error.at}`;
2956
- console.error(errorMsg);
2969
+ this.logMessage({ level: "error", message: errorMsg });
2957
2970
  this.sendMessage({ error: "MalformedMessage", message: errorMsg });
2958
2971
  return;
2959
2972
  }
2960
2973
  this.cleanSetup();
2961
2974
  }
2975
+ logMessage({ level, message }) {
2976
+ if (this.logger) {
2977
+ return this.logger[level](message);
2978
+ }
2979
+ console[level](message);
2980
+ }
2962
2981
  }
2963
2982
 
2964
2983
  class DomainsController {
@@ -2987,14 +3006,12 @@ class DomainsController {
2987
3006
  this.logger?.error(`Cannot find domain for message type: ${data.type}`);
2988
3007
  return { error: "MalformedMessage", message: `Received unsupported message type: ${data.type}` };
2989
3008
  }
2990
- this.logger?.info(`Sending request ${data.type} to domain '${domain.name}'`);
2991
3009
  const result = await domain.controller.handleControl(data);
2992
3010
  const decodedResultTypeResponse = responseMessageTypeDecoder.run(result.type);
2993
3011
  if (!decodedResultTypeResponse.ok) {
2994
3012
  this.logger?.error(`Received invalid response type: ${JSON.stringify(data)}`);
2995
3013
  return { error: "MalformedMessage", message: `Received invalid response message type: ${decodedResultTypeResponse.error.message}` };
2996
3014
  }
2997
- this.logger?.info(`Returning domain result: ${JSON.stringify(result)}`);
2998
3015
  return result;
2999
3016
  }
3000
3017
  setupDomains() {
@@ -3348,6 +3365,7 @@ const raiseIntentResultResponseDecoder = object$1({
3348
3365
  class IntentsController {
3349
3366
  sendBridgeMessage;
3350
3367
  addPrivateChannel;
3368
+ isIntentResolverEnabled;
3351
3369
  logger;
3352
3370
  listenersCollection = {};
3353
3371
  intentResolutionsCollection = {};
@@ -3363,9 +3381,10 @@ class IntentsController {
3363
3381
  raiseIntentRequest: { requestType: "raiseIntentRequest", requestDecoder: raiseIntentRequestDecoder, responseType: "raiseIntentResponse", responseDecoder: raiseIntentResponseDecoder, execute: this.handleRaiseIntentRequest.bind(this) },
3364
3382
  raiseIntentResultRequest: { requestType: "raiseIntentResultRequest", requestDecoder: raiseIntentResultRequestDecoder, responseType: "raiseIntentResultResponse", responseDecoder: raiseIntentResultResponseDecoder, execute: this.handleRaiseIntentResultResponse.bind(this) },
3365
3383
  };
3366
- constructor(sendBridgeMessage, addPrivateChannel, logger) {
3384
+ constructor(sendBridgeMessage, addPrivateChannel, isIntentResolverEnabled, logger) {
3367
3385
  this.sendBridgeMessage = sendBridgeMessage;
3368
3386
  this.addPrivateChannel = addPrivateChannel;
3387
+ this.isIntentResolverEnabled = isIntentResolverEnabled;
3369
3388
  this.logger = logger;
3370
3389
  }
3371
3390
  async handleControl(request) {
@@ -3484,7 +3503,10 @@ class IntentsController {
3484
3503
  intentEventResultPromise.resolve(payload.intentResult);
3485
3504
  return {};
3486
3505
  }
3487
- async handleRaiseIntentForContextRequest({ meta, payload }) {
3506
+ async handleRaiseIntentForContextRequest({ meta, payload, type }) {
3507
+ if (this.isIntentResolverEnabled && !payload.app) {
3508
+ return this.handleRaiseIntentForContextRequestWithResolver({ payload, meta, type });
3509
+ }
3488
3510
  const intentResolution = await window.fdc3?.raiseIntentForContext(payload.context, payload.app);
3489
3511
  if (!intentResolution) {
3490
3512
  return { error: "IntentDeliveryFailed" };
@@ -3499,7 +3521,24 @@ class IntentsController {
3499
3521
  });
3500
3522
  return { intentResolution: intentResolutionToReturn };
3501
3523
  }
3502
- async handleRaiseIntentRequest({ payload, meta }) {
3524
+ async handleRaiseIntentForContextRequestWithResolver({ payload, meta, type }) {
3525
+ const appIntents = await window.fdc3?.findIntentsByContext(payload.context);
3526
+ if (!appIntents || !appIntents.length) {
3527
+ return { error: "NoAppsFound" };
3528
+ }
3529
+ const allAvailableHandlers = appIntents.map((intent) => intent.apps).flat();
3530
+ if (allAvailableHandlers.length > 1) {
3531
+ this.logger?.info(`Multiple apps found for context type '${payload.context.type}'. Requesting user to select app using the Intent Resolver UI. Apps: ${JSON.stringify(allAvailableHandlers)}`);
3532
+ return { appIntents };
3533
+ }
3534
+ const updatedPayload = { ...payload, app: allAvailableHandlers[0] };
3535
+ this.logger?.info(`Only one app found to handle context type '${payload.context.type}'. Proceeding to raise intent to app: '${updatedPayload.app}'`);
3536
+ return this.handleRaiseIntentForContextRequest({ type, meta, payload: updatedPayload });
3537
+ }
3538
+ async handleRaiseIntentRequest({ payload, meta, type }) {
3539
+ if (this.isIntentResolverEnabled && !payload.app) {
3540
+ return this.handleRaiseIntentRequestWithResolver({ payload, meta, type });
3541
+ }
3503
3542
  const intentResolution = await window.fdc3?.raiseIntent(payload.intent, payload.context, payload.app);
3504
3543
  if (!intentResolution) {
3505
3544
  return { error: "IntentDeliveryFailed" };
@@ -3514,6 +3553,19 @@ class IntentsController {
3514
3553
  });
3515
3554
  return { intentResolution: intentResolutionToReturn };
3516
3555
  }
3556
+ async handleRaiseIntentRequestWithResolver({ payload, meta, type }) {
3557
+ const appIntent = await window.fdc3?.findIntent(payload.intent, payload.context);
3558
+ if (!appIntent || !appIntent.apps.length) {
3559
+ return { error: "NoAppsFound" };
3560
+ }
3561
+ if (appIntent.apps.length > 1) {
3562
+ this.logger?.info(`Multiple apps found for intent '${payload.intent}'. Requesting user to select app using the Intent Resolver UI. Apps: ${JSON.stringify(appIntent.apps)}`);
3563
+ return { appIntent };
3564
+ }
3565
+ const updatedPayload = { ...payload, app: appIntent.apps[0] };
3566
+ this.logger?.info(`Only one app found to handle intent. Proceeding to raise intent to app: '${updatedPayload.app}'`);
3567
+ return this.handleRaiseIntentRequest({ type, meta, payload: updatedPayload });
3568
+ }
3517
3569
  async handleRaiseIntentResultResponse({ payload, meta }) {
3518
3570
  this.logger?.info(`handleRaiseIntentResultResponse called with payload: ${JSON.stringify(payload)} and meta: ${JSON.stringify(meta)}`);
3519
3571
  const intentResolution = await this.intentResolutionsCollection[meta.requestUuid];
@@ -3526,8 +3578,8 @@ class IntentsController {
3526
3578
  this.logger?.info(`Received intent result: ${JSON.stringify(result)}`);
3527
3579
  if (!result) {
3528
3580
  const intentStr = payload.intent ? "intent '" + payload.intent + "'" : "";
3529
- const contextStr = payload.context ? "context type '" + payload.context + "'" : "";
3530
- this.logger?.info(`Intent result is void for ${intentStr}${contextStr} and requestUuid: ${meta.requestUuid}`);
3581
+ const contextStr = payload.context ? "context type '" + payload.context.type + "'" : "";
3582
+ this.logger?.info(`Intent result is void for ${intentStr}, ${contextStr} and requestUuid: ${meta.requestUuid}`);
3531
3583
  return { intentResult: undefined };
3532
3584
  }
3533
3585
  const intentResult = this.extractRaiseIntentResult(result);
@@ -3595,6 +3647,22 @@ class IoC {
3595
3647
  _channelsController;
3596
3648
  _intentsController;
3597
3649
  _applicationsController;
3650
+ _uiConfig;
3651
+ resetState() {
3652
+ this._bridgeController = undefined;
3653
+ this._ioController = undefined;
3654
+ this._domainsController = undefined;
3655
+ this._channelsController = undefined;
3656
+ this._intentsController = undefined;
3657
+ this._applicationsController = undefined;
3658
+ this._uiConfig = undefined;
3659
+ }
3660
+ get uiConfig() {
3661
+ return this._uiConfig;
3662
+ }
3663
+ set uiConfig(value) {
3664
+ this._uiConfig = value;
3665
+ }
3598
3666
  get bridgeController() {
3599
3667
  if (!this._bridgeController) {
3600
3668
  this._bridgeController = new BridgeController(this.ioController, this);
@@ -3624,7 +3692,7 @@ class IoC {
3624
3692
  }
3625
3693
  get intentsController() {
3626
3694
  if (!this._intentsController) {
3627
- this._intentsController = new IntentsController(this.bridgeController.sendMessage.bind(this.bridgeController), this.channelsController.addPrivateChannel.bind(this.channelsController), this.ioController.getLogger("intents.controller"));
3695
+ this._intentsController = new IntentsController(this.bridgeController.sendMessage.bind(this.bridgeController), this.channelsController.addPrivateChannel.bind(this.channelsController), this.uiConfig.isIntentResolverEnabled, this.ioController.getLogger("intents.controller"));
3628
3696
  }
3629
3697
  return this._intentsController;
3630
3698
  }
@@ -3636,7 +3704,7 @@ class IoC {
3636
3704
  }
3637
3705
  }
3638
3706
 
3639
- var version = "1.1.0";
3707
+ var version = "1.2.0";
3640
3708
 
3641
3709
  window.fdc3WebBridgeInfo = {
3642
3710
  version