@interopio/browser 3.4.4 → 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,11 @@
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
7
+ 3.4.5
8
+ feat: update prefs api to support non-existent apps
1
9
  3.4.4
2
10
  fix: Added missing fdc3 dependency
3
11
  3.4.3
@@ -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
@@ -2758,6 +2762,7 @@ const prefsHelloSuccessDecoder = object$1({
2758
2762
  platform: object$1({
2759
2763
  app: nonEmptyStringDecoder,
2760
2764
  }),
2765
+ validNonExistentApps: optional$1(array$1(nonEmptyStringDecoder)),
2761
2766
  });
2762
2767
  const clientErrorDataDecoder = object$1({
2763
2768
  message: nonEmptyStringDecoder
@@ -4729,6 +4734,9 @@ class IntentsController {
4729
4734
  return prefsForIntent?.handler;
4730
4735
  }
4731
4736
  async checkHandleRaiseWithRememberedHandler(intentRequest) {
4737
+ if (intentRequest.target) {
4738
+ return;
4739
+ }
4732
4740
  const rememberedHandler = await this.checkForRememberedHandler(intentRequest);
4733
4741
  if (!rememberedHandler) {
4734
4742
  return;
@@ -4759,7 +4767,7 @@ class IntentsController {
4759
4767
  }
4760
4768
 
4761
4769
  const operations$4 = {
4762
- addChannel: { name: "addChannel", dataDecoder: channelContextDecoder },
4770
+ addChannel: { name: "addChannel", dataDecoder: channelDefinitionDecoder },
4763
4771
  removeChannel: { name: "removeChannel", dataDecoder: removeChannelDataDecoder },
4764
4772
  getMyChannel: { name: "getMyChannel", resultDecoder: getMyChanelResultDecoder },
4765
4773
  getWindowIdsOnChannel: { name: "getWindowIdsOnChannel", dataDecoder: getWindowIdsOnChannelDataDecoder, resultDecoder: getWindowIdsOnChannelResultDecoder },
@@ -4932,25 +4940,35 @@ class ChannelsController {
4932
4940
  }
4933
4941
  return fdc3PropsArr[0].split("_").slice(1).join("_");
4934
4942
  }
4935
- subscribe(callback) {
4943
+ subscribe(callback, options) {
4936
4944
  if (typeof callback !== "function") {
4937
4945
  return ioError.raiseError("Cannot subscribe to channels, because the provided callback is not a function!");
4938
4946
  }
4947
+ if (options) {
4948
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
4949
+ }
4939
4950
  const currentChannel = this.current();
4940
- const wrappedCallback = this.getWrappedSubscribeCallback(callback);
4951
+ const wrappedCallback = options?.contextType
4952
+ ? this.getWrappedSubscribeCallbackWithFdc3Type(callback, options.contextType)
4953
+ : this.getWrappedSubscribeCallback(callback);
4941
4954
  if (currentChannel) {
4942
4955
  this.replaySubscribe(wrappedCallback, currentChannel);
4943
4956
  }
4944
4957
  return this.registry.add(this.SubsKey, wrappedCallback);
4945
4958
  }
4946
- async subscribeFor(name, callback) {
4959
+ async subscribeFor(name, callback, options) {
4947
4960
  const channelNames = this.getAllChannelNames();
4948
4961
  runDecoderWithIOError(channelNameDecoder(channelNames), name);
4949
4962
  if (typeof callback !== "function") {
4950
4963
  return ioError.raiseError(`Cannot subscribe to channel ${name}, because the provided callback is not a function!`);
4951
4964
  }
4965
+ if (options) {
4966
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
4967
+ }
4952
4968
  const contextName = this.createContextName(name);
4953
- const wrappedCallback = this.getWrappedSubscribeCallback(callback);
4969
+ const wrappedCallback = options?.contextType
4970
+ ? this.getWrappedSubscribeCallbackWithFdc3Type(callback, options.contextType)
4971
+ : this.getWrappedSubscribeCallback(callback);
4954
4972
  return this.contexts.subscribe(contextName, (context, _, __, ___, extraData) => {
4955
4973
  wrappedCallback(context.data, context, extraData?.updaterId);
4956
4974
  });
@@ -4981,16 +4999,38 @@ class ChannelsController {
4981
4999
  const channelNames = this.getAllChannelNames();
4982
5000
  return channelNames;
4983
5001
  }
4984
- async get(name) {
5002
+ async get(name, options) {
4985
5003
  const channelNames = this.getAllChannelNames();
4986
5004
  runDecoderWithIOError(channelNameDecoder(channelNames), name);
5005
+ if (options) {
5006
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
5007
+ }
4987
5008
  const contextName = this.createContextName(name);
4988
5009
  const channelContext = await this.contexts.get(contextName);
5010
+ if (options?.contextType) {
5011
+ return this.getContextForFdc3Type(channelContext, options.contextType);
5012
+ }
4989
5013
  if (channelContext.latest_fdc3_type) {
4990
5014
  return this.getContextWithFdc3Data(channelContext);
4991
5015
  }
4992
5016
  return channelContext;
4993
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
+ }
4994
5034
  getContextWithFdc3Data(channelContext) {
4995
5035
  const { latest_fdc3_type, ...rest } = channelContext;
4996
5036
  const parsedType = latest_fdc3_type.split("&").join(".");
@@ -5016,13 +5056,17 @@ class ChannelsController {
5016
5056
  return this.registry.add(this.ChangedKey, callback);
5017
5057
  }
5018
5058
  async add(info) {
5019
- const channelContext = runDecoderWithIOError(channelContextDecoder, info);
5059
+ const channelContext = runDecoderWithIOError(channelDefinitionDecoder, info);
5020
5060
  const channelWithSuchNameExists = this.getAllChannelNames().includes(channelContext.name);
5021
5061
  if (channelWithSuchNameExists) {
5022
5062
  return ioError.raiseError("There's an already existing channel with such name");
5023
5063
  }
5024
5064
  await this.bridge.send("channels", operations$4.addChannel, channelContext);
5025
- return channelContext;
5065
+ return {
5066
+ name: channelContext.name,
5067
+ meta: channelContext.meta,
5068
+ data: channelContext.data || {}
5069
+ };
5026
5070
  }
5027
5071
  async remove(name) {
5028
5072
  runDecoderWithIOError(nonEmptyStringDecoder, name);
@@ -5050,11 +5094,14 @@ class ChannelsController {
5050
5094
  })
5051
5095
  .catch(err => this.logger.trace(err));
5052
5096
  };
5053
- async getMy() {
5097
+ async getMy(options) {
5054
5098
  if (!this.currentChannelName) {
5055
5099
  return;
5056
5100
  }
5057
- return this.get(this.currentChannelName);
5101
+ if (options) {
5102
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
5103
+ }
5104
+ return this.get(this.currentChannelName, options);
5058
5105
  }
5059
5106
  async getWindowsOnChannel(channel) {
5060
5107
  const channelNames = this.getAllChannelNames();
@@ -5198,6 +5245,36 @@ class ChannelsController {
5198
5245
  };
5199
5246
  return wrappedCallback;
5200
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
+ }
5201
5278
  }
5202
5279
 
5203
5280
  const operations$3 = {
@@ -6007,6 +6084,7 @@ class PrefsController {
6007
6084
  appManagerController;
6008
6085
  platformAppName;
6009
6086
  registry = CallbackRegistryFactory$1();
6087
+ validNonExistentApps;
6010
6088
  handlePlatformShutdown() {
6011
6089
  this.registry.clear();
6012
6090
  }
@@ -6020,6 +6098,7 @@ class PrefsController {
6020
6098
  try {
6021
6099
  const prefsHelloSuccess = await this.bridge.send("prefs", operations.prefsHello, undefined, undefined, { includeOperationCheck: true });
6022
6100
  this.platformAppName = prefsHelloSuccess.platform.app;
6101
+ this.validNonExistentApps = prefsHelloSuccess.validNonExistentApps ?? [];
6023
6102
  }
6024
6103
  catch (error) {
6025
6104
  this.logger.warn("The platform of this client is outdated and does not support Prefs API.");
@@ -6042,12 +6121,12 @@ class PrefsController {
6042
6121
  return await operation.execute(operationData);
6043
6122
  }
6044
6123
  async get(app) {
6045
- const verifiedApp = app === undefined || app === null ? this.getMyAppName() : nonEmptyStringDecoder.runWithException(app);
6124
+ const verifiedApp = app === undefined || app === null ? this.getMyAppName() : runDecoderWithIOError(nonEmptyStringDecoder, app);
6046
6125
  const { prefs } = await this.bridge.send("prefs", operations.get, { app: verifiedApp }, undefined, { includeOperationCheck: true });
6047
6126
  return prefs;
6048
6127
  }
6049
6128
  async update(data, options) {
6050
- const verifiedOptions = optional$1(basePrefsConfigDecoder).runWithException(options);
6129
+ const verifiedOptions = runDecoderWithIOError(optional$1(basePrefsConfigDecoder), options);
6051
6130
  const app = verifiedOptions?.app ?? this.getMyAppName();
6052
6131
  await this.updateFor(app, data);
6053
6132
  }
@@ -6102,7 +6181,7 @@ class PrefsController {
6102
6181
  subscribeFor(app, callback) {
6103
6182
  const verifiedApp = runDecoderWithIOError(nonEmptyStringDecoder, app);
6104
6183
  const applications = this.appManagerController.getApplications();
6105
- const isValidApp = verifiedApp === this.platformAppName || applications.some((application) => application.name === verifiedApp);
6184
+ const isValidApp = verifiedApp === this.platformAppName || applications.some((application) => application.name === verifiedApp) || this.validNonExistentApps.includes(verifiedApp);
6106
6185
  if (!isValidApp) {
6107
6186
  return ioError.raiseError(`The provided app name "${app}" is not valid.`);
6108
6187
  }
@@ -6293,16 +6372,12 @@ class IoC {
6293
6372
  }
6294
6373
  }
6295
6374
 
6296
- var version$1 = "3.4.4";
6375
+ var version$1 = "3.4.6";
6297
6376
 
6298
6377
  const createFactoryFunction = (coreFactoryFunction) => {
6299
- return async (userConfig) => {
6300
- if (window.glue42gd || window.iodesktop) {
6301
- return enterprise(userConfig);
6302
- }
6378
+ let cachedApiPromise;
6379
+ const initAPI = async (config) => {
6303
6380
  const ioc = new IoC();
6304
- const config = parseConfig(userConfig);
6305
- checkSingleton();
6306
6381
  const glue = await PromiseWrap(() => coreFactoryFunction(config, { version: version$1 }), 30000, "Glue Web initialization timed out, because core didn't resolve");
6307
6382
  const logger = glue.logger.subLogger("web.main.controller");
6308
6383
  ioc.defineGlue(glue);
@@ -6324,6 +6399,22 @@ const createFactoryFunction = (coreFactoryFunction) => {
6324
6399
  return ioError.raiseError(error, true);
6325
6400
  }
6326
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;
6327
6418
  };
6328
6419
 
6329
6420
  var MetricTypes = {