@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.
@@ -2484,6 +2484,9 @@
2484
2484
  const channelNameDecoder = (channelNames) => {
2485
2485
  return nonEmptyStringDecoder.where(s => channelNames.includes(s), "Expected a valid channel name");
2486
2486
  };
2487
+ const fdc3OptionsDecoder = object$1({
2488
+ contextType: optional$1(nonEmptyStringDecoder)
2489
+ });
2487
2490
  const publishOptionsDecoder = optional$1(oneOf$1(nonEmptyStringDecoder, object$1({
2488
2491
  name: optional$1(nonEmptyStringDecoder),
2489
2492
  fdc3: optional$1(boolean$1())
@@ -2546,7 +2549,8 @@
2546
2549
  id: nonEmptyStringDecoder,
2547
2550
  state: notificationStateDecoder
2548
2551
  });
2549
- const channelContextDecoder = object$1({
2552
+ object$1().where((value) => value.fdc3 ? typeof value.fdc3.type === "string" : true, "Expected a valid FDC3 Context with compulsory 'type' field");
2553
+ const channelDefinitionDecoder = object$1({
2550
2554
  name: nonEmptyStringDecoder,
2551
2555
  meta: object$1({
2552
2556
  color: nonEmptyStringDecoder
@@ -4736,6 +4740,9 @@
4736
4740
  return prefsForIntent?.handler;
4737
4741
  }
4738
4742
  async checkHandleRaiseWithRememberedHandler(intentRequest) {
4743
+ if (intentRequest.target) {
4744
+ return;
4745
+ }
4739
4746
  const rememberedHandler = await this.checkForRememberedHandler(intentRequest);
4740
4747
  if (!rememberedHandler) {
4741
4748
  return;
@@ -4766,7 +4773,7 @@
4766
4773
  }
4767
4774
 
4768
4775
  const operations$4 = {
4769
- addChannel: { name: "addChannel", dataDecoder: channelContextDecoder },
4776
+ addChannel: { name: "addChannel", dataDecoder: channelDefinitionDecoder },
4770
4777
  removeChannel: { name: "removeChannel", dataDecoder: removeChannelDataDecoder },
4771
4778
  getMyChannel: { name: "getMyChannel", resultDecoder: getMyChanelResultDecoder },
4772
4779
  getWindowIdsOnChannel: { name: "getWindowIdsOnChannel", dataDecoder: getWindowIdsOnChannelDataDecoder, resultDecoder: getWindowIdsOnChannelResultDecoder },
@@ -4939,25 +4946,35 @@
4939
4946
  }
4940
4947
  return fdc3PropsArr[0].split("_").slice(1).join("_");
4941
4948
  }
4942
- subscribe(callback) {
4949
+ subscribe(callback, options) {
4943
4950
  if (typeof callback !== "function") {
4944
4951
  return ioError.raiseError("Cannot subscribe to channels, because the provided callback is not a function!");
4945
4952
  }
4953
+ if (options) {
4954
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
4955
+ }
4946
4956
  const currentChannel = this.current();
4947
- const wrappedCallback = this.getWrappedSubscribeCallback(callback);
4957
+ const wrappedCallback = options?.contextType
4958
+ ? this.getWrappedSubscribeCallbackWithFdc3Type(callback, options.contextType)
4959
+ : this.getWrappedSubscribeCallback(callback);
4948
4960
  if (currentChannel) {
4949
4961
  this.replaySubscribe(wrappedCallback, currentChannel);
4950
4962
  }
4951
4963
  return this.registry.add(this.SubsKey, wrappedCallback);
4952
4964
  }
4953
- async subscribeFor(name, callback) {
4965
+ async subscribeFor(name, callback, options) {
4954
4966
  const channelNames = this.getAllChannelNames();
4955
4967
  runDecoderWithIOError(channelNameDecoder(channelNames), name);
4956
4968
  if (typeof callback !== "function") {
4957
4969
  return ioError.raiseError(`Cannot subscribe to channel ${name}, because the provided callback is not a function!`);
4958
4970
  }
4971
+ if (options) {
4972
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
4973
+ }
4959
4974
  const contextName = this.createContextName(name);
4960
- const wrappedCallback = this.getWrappedSubscribeCallback(callback);
4975
+ const wrappedCallback = options?.contextType
4976
+ ? this.getWrappedSubscribeCallbackWithFdc3Type(callback, options.contextType)
4977
+ : this.getWrappedSubscribeCallback(callback);
4961
4978
  return this.contexts.subscribe(contextName, (context, _, __, ___, extraData) => {
4962
4979
  wrappedCallback(context.data, context, extraData?.updaterId);
4963
4980
  });
@@ -4988,16 +5005,38 @@
4988
5005
  const channelNames = this.getAllChannelNames();
4989
5006
  return channelNames;
4990
5007
  }
4991
- async get(name) {
5008
+ async get(name, options) {
4992
5009
  const channelNames = this.getAllChannelNames();
4993
5010
  runDecoderWithIOError(channelNameDecoder(channelNames), name);
5011
+ if (options) {
5012
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
5013
+ }
4994
5014
  const contextName = this.createContextName(name);
4995
5015
  const channelContext = await this.contexts.get(contextName);
5016
+ if (options?.contextType) {
5017
+ return this.getContextForFdc3Type(channelContext, options.contextType);
5018
+ }
4996
5019
  if (channelContext.latest_fdc3_type) {
4997
5020
  return this.getContextWithFdc3Data(channelContext);
4998
5021
  }
4999
5022
  return channelContext;
5000
5023
  }
5024
+ getContextForFdc3Type(channelContext, searchedType) {
5025
+ const encodedType = `fdc3_${searchedType.split(".").join("&")}`;
5026
+ if (!channelContext.data[encodedType]) {
5027
+ return {
5028
+ name: channelContext.name,
5029
+ meta: channelContext.meta,
5030
+ data: {}
5031
+ };
5032
+ }
5033
+ const fdc3Context = { type: searchedType, ...channelContext.data[encodedType] };
5034
+ return {
5035
+ name: channelContext.name,
5036
+ meta: channelContext.meta,
5037
+ data: { fdc3: fdc3Context }
5038
+ };
5039
+ }
5001
5040
  getContextWithFdc3Data(channelContext) {
5002
5041
  const { latest_fdc3_type, ...rest } = channelContext;
5003
5042
  const parsedType = latest_fdc3_type.split("&").join(".");
@@ -5023,13 +5062,17 @@
5023
5062
  return this.registry.add(this.ChangedKey, callback);
5024
5063
  }
5025
5064
  async add(info) {
5026
- const channelContext = runDecoderWithIOError(channelContextDecoder, info);
5065
+ const channelContext = runDecoderWithIOError(channelDefinitionDecoder, info);
5027
5066
  const channelWithSuchNameExists = this.getAllChannelNames().includes(channelContext.name);
5028
5067
  if (channelWithSuchNameExists) {
5029
5068
  return ioError.raiseError("There's an already existing channel with such name");
5030
5069
  }
5031
5070
  await this.bridge.send("channels", operations$4.addChannel, channelContext);
5032
- return channelContext;
5071
+ return {
5072
+ name: channelContext.name,
5073
+ meta: channelContext.meta,
5074
+ data: channelContext.data || {}
5075
+ };
5033
5076
  }
5034
5077
  async remove(name) {
5035
5078
  runDecoderWithIOError(nonEmptyStringDecoder, name);
@@ -5057,11 +5100,14 @@
5057
5100
  })
5058
5101
  .catch(err => this.logger.trace(err));
5059
5102
  };
5060
- async getMy() {
5103
+ async getMy(options) {
5061
5104
  if (!this.currentChannelName) {
5062
5105
  return;
5063
5106
  }
5064
- return this.get(this.currentChannelName);
5107
+ if (options) {
5108
+ runDecoderWithIOError(fdc3OptionsDecoder, options);
5109
+ }
5110
+ return this.get(this.currentChannelName, options);
5065
5111
  }
5066
5112
  async getWindowsOnChannel(channel) {
5067
5113
  const channelNames = this.getAllChannelNames();
@@ -5205,6 +5251,36 @@
5205
5251
  };
5206
5252
  return wrappedCallback;
5207
5253
  }
5254
+ getWrappedSubscribeCallbackWithFdc3Type(callback, fdc3Type) {
5255
+ const didReplay = { replayed: false };
5256
+ const wrappedCallback = (_, context, updaterId) => {
5257
+ const canRead = this.isAllowedByRestrictions(context.name, "read");
5258
+ if (!canRead) {
5259
+ return;
5260
+ }
5261
+ const { data, latest_fdc3_type } = context;
5262
+ const searchedType = `fdc3_${fdc3Type.split(".").join("&")}`;
5263
+ if (!data[searchedType]) {
5264
+ return;
5265
+ }
5266
+ if (didReplay.replayed) {
5267
+ return this.parseDataAndInvokeSubscribeCallback({ latestFdc3TypeEncoded: latest_fdc3_type, searchedType: fdc3Type, callback, context, updaterId });
5268
+ }
5269
+ const fdc3Data = { type: fdc3Type, ...data[searchedType] };
5270
+ callback({ fdc3: fdc3Data }, context, updaterId);
5271
+ didReplay.replayed = true;
5272
+ };
5273
+ return wrappedCallback;
5274
+ }
5275
+ parseDataAndInvokeSubscribeCallback(args) {
5276
+ const { latestFdc3TypeEncoded, searchedType, callback, context, updaterId } = args;
5277
+ const latestPublishedType = latestFdc3TypeEncoded.split("&").join(".");
5278
+ if (latestPublishedType !== searchedType) {
5279
+ return;
5280
+ }
5281
+ const fdc3Data = { type: searchedType, ...context.data[`fdc3_${latestFdc3TypeEncoded}`] };
5282
+ callback({ fdc3: fdc3Data }, context, updaterId);
5283
+ }
5208
5284
  }
5209
5285
 
5210
5286
  const operations$3 = {
@@ -6302,16 +6378,12 @@
6302
6378
  }
6303
6379
  }
6304
6380
 
6305
- var version$1 = "3.4.5";
6381
+ var version$1 = "3.4.6";
6306
6382
 
6307
6383
  const createFactoryFunction = (coreFactoryFunction) => {
6308
- return async (userConfig) => {
6309
- if (window.glue42gd || window.iodesktop) {
6310
- return enterprise(userConfig);
6311
- }
6384
+ let cachedApiPromise;
6385
+ const initAPI = async (config) => {
6312
6386
  const ioc = new IoC();
6313
- const config = parseConfig(userConfig);
6314
- checkSingleton();
6315
6387
  const glue = await PromiseWrap(() => coreFactoryFunction(config, { version: version$1 }), 30000, "Glue Web initialization timed out, because core didn't resolve");
6316
6388
  const logger = glue.logger.subLogger("web.main.controller");
6317
6389
  ioc.defineGlue(glue);
@@ -6333,6 +6405,22 @@
6333
6405
  return ioError.raiseError(error, true);
6334
6406
  }
6335
6407
  };
6408
+ const factory = (userConfig) => {
6409
+ if (window.glue42gd || window.iodesktop) {
6410
+ return enterprise(userConfig);
6411
+ }
6412
+ const config = parseConfig(userConfig);
6413
+ try {
6414
+ checkSingleton();
6415
+ }
6416
+ catch (error) {
6417
+ return typeof cachedApiPromise === "undefined" ? Promise.reject(new Error(error)) : cachedApiPromise;
6418
+ }
6419
+ const apiPromise = initAPI(config);
6420
+ cachedApiPromise = userConfig?.memoizeAPI ? apiPromise : undefined;
6421
+ return apiPromise;
6422
+ };
6423
+ return factory;
6336
6424
  };
6337
6425
 
6338
6426
  var MetricTypes = {