@interopio/browser 3.4.5 → 3.4.6

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/browser.d.ts CHANGED
@@ -99,6 +99,13 @@ export namespace IOConnectBrowser {
99
99
  */
100
100
  exposeAPI?: boolean;
101
101
 
102
+ /**
103
+ * If `true`, when the io.Connect API factory function is invoked more than once in the same app,
104
+ * it will return the already initialized API object, instead of throwing an error.
105
+ * @default false
106
+ */
107
+ memoizeAPI?: boolean;
108
+
102
109
  /**
103
110
  * A list of io.Connect libraries which will be initiated internally and provide access to specific functionalities
104
111
  */
@@ -925,17 +932,19 @@ export namespace IOConnectBrowser {
925
932
  * Tracks the data in the current channel. Persisted after a channel change.
926
933
  * The callback isn't called when you publish the data.
927
934
  * @param callback Callback function to handle the received data.
935
+ * @param options Settings for subscribing to an FDC3 context published in the io.Connect Channel.
928
936
  * @returns Unsubscribe function.
929
937
  */
930
- subscribe(callback: (data: any, context: ChannelContext, updaterId: string) => void): UnsubscribeFunction;
938
+ subscribe(callback: (data: any, context: ChannelContext, updaterId: string) => void, options?: FDC3Options): UnsubscribeFunction;
931
939
 
932
940
  /**
933
941
  * Tracks the data in a given channel.
934
942
  * @param name The channel to track.
935
943
  * @param callback Callback function to handle the received data.
944
+ * @param options Settings for subscribing to an FDC3 context published in the io.Connect Channel.
936
945
  * @returns Promise that resolves with an unsubscribe function.
937
946
  */
938
- subscribeFor(name: string, callback: (data: any, context: ChannelContext, updaterId: string) => void): Promise<UnsubscribeFunction>;
947
+ subscribeFor(name: string, callback: (data: any, context: ChannelContext, updaterId: string) => void, options?: FDC3Options): Promise<UnsubscribeFunction>;
939
948
 
940
949
  /**
941
950
  * Updates the context of the current or a given channel.
@@ -960,9 +969,10 @@ export namespace IOConnectBrowser {
960
969
  /**
961
970
  * Returns the context of a given channel.
962
971
  * @param name The name of the channel whose context to return.
972
+ * @param options Settings for retrieving an FDC3 context published in the io.Connect Channel.
963
973
  * @returns Promise that resolves with the context of the given channel.
964
974
  */
965
- get(name: string): Promise<ChannelContext>;
975
+ get(name: string, options?: FDC3Options): Promise<ChannelContext>;
966
976
 
967
977
  /**
968
978
  * Joins a new channel by name. Leaves the current channel.
@@ -1010,7 +1020,7 @@ export namespace IOConnectBrowser {
1010
1020
  * Adds a new Channel.
1011
1021
  * @param info Initial Channel context.
1012
1022
  */
1013
- add(info: ChannelContext): Promise<ChannelContext>;
1023
+ add(info: ChannelDefinition): Promise<ChannelContext>;
1014
1024
 
1015
1025
  /**
1016
1026
  * Removes a Channel.
@@ -1020,9 +1030,10 @@ export namespace IOConnectBrowser {
1020
1030
 
1021
1031
  /**
1022
1032
  * Retrieves the context of the current Channel.
1033
+ * @param options Settings for retrieving an FDC3 context published in the io.Connect Channel.
1023
1034
  * @returns Promise that resolves with the context of the current Channel.
1024
1035
  */
1025
- getMy(): Promise<ChannelContext | undefined>;
1036
+ getMy(options?: FDC3Options): Promise<ChannelContext | undefined>;
1026
1037
 
1027
1038
  /**
1028
1039
  * Retrieves all windows on a specified Channel.
@@ -1060,6 +1071,16 @@ export namespace IOConnectBrowser {
1060
1071
  restrictAll(restrictions: RestrictionsConfig): Promise<void>;
1061
1072
  }
1062
1073
 
1074
+ /**
1075
+ * Settings for retrieving and subscribing for FDC3 contexts published in an io.Connect Channel.
1076
+ */
1077
+ export interface FDC3Options {
1078
+ /**
1079
+ * Type of the FDC3 context to retrieve or to which to subscribe.
1080
+ */
1081
+ contextType?: string;
1082
+ }
1083
+
1063
1084
  /**
1064
1085
  * Options for updating a Channel context with the `publish()` method.
1065
1086
  */
@@ -1113,6 +1134,18 @@ export namespace IOConnectBrowser {
1113
1134
  windowId?: string;
1114
1135
  }
1115
1136
 
1137
+ /**
1138
+ * Initial context for creating a channel runtime.
1139
+ */
1140
+ export interface ChannelDefinition {
1141
+ /** Unique name of the context. */
1142
+ name: string;
1143
+ /** Channel meta data (display name, color, image, etc.) */
1144
+ meta: any;
1145
+ /** Channel data. */
1146
+ data?: any;
1147
+ }
1148
+
1116
1149
  /**
1117
1150
  * Channel context object.
1118
1151
  */
package/changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ 3.4.6
2
+ feat: Enable support for io.CB API Memoization
3
+ feat: Add optional IOConnectBrowser.Channels.Fdc3Options param in get, getMy, subscribe and subscribeFor methods.
4
+ fix: io.channels.add() decoder
5
+ chore: Add try-catch block around saving handler in Prefs API
6
+ chore: Add check if intentRequest.target is passed to ignore saved handler in Prefs API if there's a target
1
7
  3.4.5
2
8
  feat: update prefs api to support non-existent apps
3
9
  3.4.4
@@ -2478,6 +2478,9 @@ const getIntentsResultDecoder = object$1({
2478
2478
  const channelNameDecoder = (channelNames) => {
2479
2479
  return nonEmptyStringDecoder.where(s => channelNames.includes(s), "Expected a valid channel name");
2480
2480
  };
2481
+ const fdc3OptionsDecoder = object$1({
2482
+ contextType: optional$1(nonEmptyStringDecoder)
2483
+ });
2481
2484
  const publishOptionsDecoder = optional$1(oneOf$1(nonEmptyStringDecoder, object$1({
2482
2485
  name: optional$1(nonEmptyStringDecoder),
2483
2486
  fdc3: optional$1(boolean$1())
@@ -2540,7 +2543,8 @@ const notificationSetStateRequestDecoder = object$1({
2540
2543
  id: nonEmptyStringDecoder,
2541
2544
  state: notificationStateDecoder
2542
2545
  });
2543
- const channelContextDecoder = object$1({
2546
+ object$1().where((value) => value.fdc3 ? typeof value.fdc3.type === "string" : true, "Expected a valid FDC3 Context with compulsory 'type' field");
2547
+ const channelDefinitionDecoder = object$1({
2544
2548
  name: nonEmptyStringDecoder,
2545
2549
  meta: object$1({
2546
2550
  color: nonEmptyStringDecoder
@@ -4730,6 +4734,9 @@ class IntentsController {
4730
4734
  return prefsForIntent?.handler;
4731
4735
  }
4732
4736
  async checkHandleRaiseWithRememberedHandler(intentRequest) {
4737
+ if (intentRequest.target) {
4738
+ return;
4739
+ }
4733
4740
  const rememberedHandler = await this.checkForRememberedHandler(intentRequest);
4734
4741
  if (!rememberedHandler) {
4735
4742
  return;
@@ -4760,7 +4767,7 @@ class IntentsController {
4760
4767
  }
4761
4768
 
4762
4769
  const operations$4 = {
4763
- addChannel: { name: "addChannel", dataDecoder: channelContextDecoder },
4770
+ addChannel: { name: "addChannel", dataDecoder: channelDefinitionDecoder },
4764
4771
  removeChannel: { name: "removeChannel", dataDecoder: removeChannelDataDecoder },
4765
4772
  getMyChannel: { name: "getMyChannel", resultDecoder: getMyChanelResultDecoder },
4766
4773
  getWindowIdsOnChannel: { name: "getWindowIdsOnChannel", dataDecoder: getWindowIdsOnChannelDataDecoder, resultDecoder: getWindowIdsOnChannelResultDecoder },
@@ -4933,25 +4940,35 @@ class ChannelsController {
4933
4940
  }
4934
4941
  return fdc3PropsArr[0].split("_").slice(1).join("_");
4935
4942
  }
4936
- subscribe(callback) {
4943
+ subscribe(callback, options) {
4937
4944
  if (typeof callback !== "function") {
4938
4945
  return ioError.raiseError("Cannot subscribe to channels, because the provided callback is not a function!");
4939
4946
  }
4947
+ if (options) {
4948
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
4949
+ }
4940
4950
  const currentChannel = this.current();
4941
- const wrappedCallback = this.getWrappedSubscribeCallback(callback);
4951
+ const wrappedCallback = options?.contextType
4952
+ ? this.getWrappedSubscribeCallbackWithFdc3Type(callback, options.contextType)
4953
+ : this.getWrappedSubscribeCallback(callback);
4942
4954
  if (currentChannel) {
4943
4955
  this.replaySubscribe(wrappedCallback, currentChannel);
4944
4956
  }
4945
4957
  return this.registry.add(this.SubsKey, wrappedCallback);
4946
4958
  }
4947
- async subscribeFor(name, callback) {
4959
+ async subscribeFor(name, callback, options) {
4948
4960
  const channelNames = this.getAllChannelNames();
4949
4961
  runDecoderWithIOError(channelNameDecoder(channelNames), name);
4950
4962
  if (typeof callback !== "function") {
4951
4963
  return ioError.raiseError(`Cannot subscribe to channel ${name}, because the provided callback is not a function!`);
4952
4964
  }
4965
+ if (options) {
4966
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
4967
+ }
4953
4968
  const contextName = this.createContextName(name);
4954
- const wrappedCallback = this.getWrappedSubscribeCallback(callback);
4969
+ const wrappedCallback = options?.contextType
4970
+ ? this.getWrappedSubscribeCallbackWithFdc3Type(callback, options.contextType)
4971
+ : this.getWrappedSubscribeCallback(callback);
4955
4972
  return this.contexts.subscribe(contextName, (context, _, __, ___, extraData) => {
4956
4973
  wrappedCallback(context.data, context, extraData?.updaterId);
4957
4974
  });
@@ -4982,16 +4999,38 @@ class ChannelsController {
4982
4999
  const channelNames = this.getAllChannelNames();
4983
5000
  return channelNames;
4984
5001
  }
4985
- async get(name) {
5002
+ async get(name, options) {
4986
5003
  const channelNames = this.getAllChannelNames();
4987
5004
  runDecoderWithIOError(channelNameDecoder(channelNames), name);
5005
+ if (options) {
5006
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
5007
+ }
4988
5008
  const contextName = this.createContextName(name);
4989
5009
  const channelContext = await this.contexts.get(contextName);
5010
+ if (options?.contextType) {
5011
+ return this.getContextForFdc3Type(channelContext, options.contextType);
5012
+ }
4990
5013
  if (channelContext.latest_fdc3_type) {
4991
5014
  return this.getContextWithFdc3Data(channelContext);
4992
5015
  }
4993
5016
  return channelContext;
4994
5017
  }
5018
+ getContextForFdc3Type(channelContext, searchedType) {
5019
+ const encodedType = `fdc3_${searchedType.split(".").join("&")}`;
5020
+ if (!channelContext.data[encodedType]) {
5021
+ return {
5022
+ name: channelContext.name,
5023
+ meta: channelContext.meta,
5024
+ data: {}
5025
+ };
5026
+ }
5027
+ const fdc3Context = { type: searchedType, ...channelContext.data[encodedType] };
5028
+ return {
5029
+ name: channelContext.name,
5030
+ meta: channelContext.meta,
5031
+ data: { fdc3: fdc3Context }
5032
+ };
5033
+ }
4995
5034
  getContextWithFdc3Data(channelContext) {
4996
5035
  const { latest_fdc3_type, ...rest } = channelContext;
4997
5036
  const parsedType = latest_fdc3_type.split("&").join(".");
@@ -5017,13 +5056,17 @@ class ChannelsController {
5017
5056
  return this.registry.add(this.ChangedKey, callback);
5018
5057
  }
5019
5058
  async add(info) {
5020
- const channelContext = runDecoderWithIOError(channelContextDecoder, info);
5059
+ const channelContext = runDecoderWithIOError(channelDefinitionDecoder, info);
5021
5060
  const channelWithSuchNameExists = this.getAllChannelNames().includes(channelContext.name);
5022
5061
  if (channelWithSuchNameExists) {
5023
5062
  return ioError.raiseError("There's an already existing channel with such name");
5024
5063
  }
5025
5064
  await this.bridge.send("channels", operations$4.addChannel, channelContext);
5026
- return channelContext;
5065
+ return {
5066
+ name: channelContext.name,
5067
+ meta: channelContext.meta,
5068
+ data: channelContext.data || {}
5069
+ };
5027
5070
  }
5028
5071
  async remove(name) {
5029
5072
  runDecoderWithIOError(nonEmptyStringDecoder, name);
@@ -5051,11 +5094,14 @@ class ChannelsController {
5051
5094
  })
5052
5095
  .catch(err => this.logger.trace(err));
5053
5096
  };
5054
- async getMy() {
5097
+ async getMy(options) {
5055
5098
  if (!this.currentChannelName) {
5056
5099
  return;
5057
5100
  }
5058
- return this.get(this.currentChannelName);
5101
+ if (options) {
5102
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
5103
+ }
5104
+ return this.get(this.currentChannelName, options);
5059
5105
  }
5060
5106
  async getWindowsOnChannel(channel) {
5061
5107
  const channelNames = this.getAllChannelNames();
@@ -5199,6 +5245,36 @@ class ChannelsController {
5199
5245
  };
5200
5246
  return wrappedCallback;
5201
5247
  }
5248
+ getWrappedSubscribeCallbackWithFdc3Type(callback, fdc3Type) {
5249
+ const didReplay = { replayed: false };
5250
+ const wrappedCallback = (_, context, updaterId) => {
5251
+ const canRead = this.isAllowedByRestrictions(context.name, "read");
5252
+ if (!canRead) {
5253
+ return;
5254
+ }
5255
+ const { data, latest_fdc3_type } = context;
5256
+ const searchedType = `fdc3_${fdc3Type.split(".").join("&")}`;
5257
+ if (!data[searchedType]) {
5258
+ return;
5259
+ }
5260
+ if (didReplay.replayed) {
5261
+ return this.parseDataAndInvokeSubscribeCallback({ latestFdc3TypeEncoded: latest_fdc3_type, searchedType: fdc3Type, callback, context, updaterId });
5262
+ }
5263
+ const fdc3Data = { type: fdc3Type, ...data[searchedType] };
5264
+ callback({ fdc3: fdc3Data }, context, updaterId);
5265
+ didReplay.replayed = true;
5266
+ };
5267
+ return wrappedCallback;
5268
+ }
5269
+ parseDataAndInvokeSubscribeCallback(args) {
5270
+ const { latestFdc3TypeEncoded, searchedType, callback, context, updaterId } = args;
5271
+ const latestPublishedType = latestFdc3TypeEncoded.split("&").join(".");
5272
+ if (latestPublishedType !== searchedType) {
5273
+ return;
5274
+ }
5275
+ const fdc3Data = { type: searchedType, ...context.data[`fdc3_${latestFdc3TypeEncoded}`] };
5276
+ callback({ fdc3: fdc3Data }, context, updaterId);
5277
+ }
5202
5278
  }
5203
5279
 
5204
5280
  const operations$3 = {
@@ -6296,16 +6372,12 @@ class IoC {
6296
6372
  }
6297
6373
  }
6298
6374
 
6299
- var version$1 = "3.4.5";
6375
+ var version$1 = "3.4.6";
6300
6376
 
6301
6377
  const createFactoryFunction = (coreFactoryFunction) => {
6302
- return async (userConfig) => {
6303
- if (window.glue42gd || window.iodesktop) {
6304
- return enterprise(userConfig);
6305
- }
6378
+ let cachedApiPromise;
6379
+ const initAPI = async (config) => {
6306
6380
  const ioc = new IoC();
6307
- const config = parseConfig(userConfig);
6308
- checkSingleton();
6309
6381
  const glue = await PromiseWrap(() => coreFactoryFunction(config, { version: version$1 }), 30000, "Glue Web initialization timed out, because core didn't resolve");
6310
6382
  const logger = glue.logger.subLogger("web.main.controller");
6311
6383
  ioc.defineGlue(glue);
@@ -6327,6 +6399,22 @@ const createFactoryFunction = (coreFactoryFunction) => {
6327
6399
  return ioError.raiseError(error, true);
6328
6400
  }
6329
6401
  };
6402
+ const factory = (userConfig) => {
6403
+ if (window.glue42gd || window.iodesktop) {
6404
+ return enterprise(userConfig);
6405
+ }
6406
+ const config = parseConfig(userConfig);
6407
+ try {
6408
+ checkSingleton();
6409
+ }
6410
+ catch (error) {
6411
+ return typeof cachedApiPromise === "undefined" ? Promise.reject(new Error(error)) : cachedApiPromise;
6412
+ }
6413
+ const apiPromise = initAPI(config);
6414
+ cachedApiPromise = userConfig?.memoizeAPI ? apiPromise : undefined;
6415
+ return apiPromise;
6416
+ };
6417
+ return factory;
6330
6418
  };
6331
6419
 
6332
6420
  var MetricTypes = {