@interopio/browser 3.2.2 → 3.3.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.
@@ -1678,7 +1678,8 @@
1678
1678
  hidden: optional(boolean())
1679
1679
  });
1680
1680
  const hostManifestsBrowserDecoder = oneOf(object({
1681
- "Glue42": oneOf(glue42HostManifestsBrowserDecoder, anyJson())
1681
+ "ioConnect": optional(oneOf(glue42HostManifestsBrowserDecoder, anyJson())),
1682
+ "Glue42": optional(oneOf(glue42HostManifestsBrowserDecoder, anyJson()))
1682
1683
  }), anyJson());
1683
1684
  const v1DefinitionDecoder = object({
1684
1685
  name: nonEmptyStringDecoder$1,
@@ -1784,7 +1785,7 @@
1784
1785
  }
1785
1786
  const userProperties = this.getUserPropertiesFromDefinition(definition, version);
1786
1787
  const createOptions = { url: this.getUrl(definition, version) };
1787
- let baseApplicationData = {
1788
+ const baseApplicationData = {
1788
1789
  name: definition.appId,
1789
1790
  type: "window",
1790
1791
  createOptions,
@@ -1801,17 +1802,18 @@
1801
1802
  caption: definition.description,
1802
1803
  fdc3: version === "2.0" ? { ...definition, definitionVersion: "2.0" } : undefined,
1803
1804
  };
1804
- if (definition.hostManifests?.["Glue42"]) {
1805
- const decodeRes = glue42HostManifestsBrowserDecoder.run(definition.hostManifests["Glue42"]);
1806
- if (!decodeRes.ok) {
1807
- throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(decodeRes.error)}`);
1808
- }
1809
- if (!Object.keys(decodeRes.result).length) {
1810
- throw new Error("Invalid 'hostManifests['Glue42]' key");
1811
- }
1812
- baseApplicationData = this.mergeBaseAppDataWithGlueManifest(baseApplicationData, decodeRes.result);
1805
+ const ioConnectDefinition = definition.hostManifests?.ioConnect || definition.hostManifests?.["Glue42"];
1806
+ if (!ioConnectDefinition) {
1807
+ return baseApplicationData;
1808
+ }
1809
+ const ioDefinitionDecodeRes = glue42HostManifestsBrowserDecoder.run(ioConnectDefinition);
1810
+ if (!ioDefinitionDecodeRes.ok) {
1811
+ throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(ioDefinitionDecodeRes.error)}`);
1813
1812
  }
1814
- return baseApplicationData;
1813
+ if (!Object.keys(ioDefinitionDecodeRes.result).length) {
1814
+ return baseApplicationData;
1815
+ }
1816
+ return this.mergeBaseAppDataWithGlueManifest(baseApplicationData, ioDefinitionDecodeRes.result);
1815
1817
  }
1816
1818
  parseToDesktopAppConfig(definition) {
1817
1819
  const { isFdc3, version } = this.isFdc3Definition(definition);
@@ -1848,7 +1850,7 @@
1848
1850
  };
1849
1851
  }
1850
1852
  const fdc3v2Definition = definition;
1851
- let desktopDefinition = {
1853
+ const desktopDefinition = {
1852
1854
  name: fdc3v2Definition.appId,
1853
1855
  type: this.fdc3ToDesktopDefinitionType[fdc3v2Definition.type],
1854
1856
  details: fdc3v2Definition.details,
@@ -1860,13 +1862,14 @@
1860
1862
  intents: this.getIntentsFromV2AppDefinition(fdc3v2Definition),
1861
1863
  fdc3: { ...fdc3v2Definition, definitionVersion: "2.0" }
1862
1864
  };
1863
- if (fdc3v2Definition.hostManifests?.["Glue42"]) {
1864
- if (typeof fdc3v2Definition.hostManifests["Glue42"] !== "object" || Array.isArray(fdc3v2Definition.hostManifests["Glue42"])) {
1865
- throw new Error("Invalid 'hostManifests['Glue42]' key");
1866
- }
1867
- desktopDefinition = this.mergeDesktopConfigWithGlueManifest(desktopDefinition, fdc3v2Definition.hostManifests?.["Glue42"]);
1865
+ const ioConnectDefinition = definition.hostManifests?.ioConnect || definition.hostManifests?.["Glue42"];
1866
+ if (!ioConnectDefinition) {
1867
+ return desktopDefinition;
1868
1868
  }
1869
- return desktopDefinition;
1869
+ if (typeof ioConnectDefinition !== "object" || Array.isArray(ioConnectDefinition)) {
1870
+ throw new Error(`Invalid '${definition.hostManifests.ioConnect ? "hostManifests.ioConnect" : "hostManifests['Glue42']"}' key`);
1871
+ }
1872
+ return this.mergeDesktopConfigWithGlueManifest(desktopDefinition, ioConnectDefinition);
1870
1873
  }
1871
1874
  getUserPropertiesFromDefinition(definition, version) {
1872
1875
  if (version === "1.2") {
@@ -1990,7 +1993,7 @@
1990
1993
  const libDomainDecoder = oneOf$1(constant$1("system"), constant$1("windows"), constant$1("appManager"), constant$1("layouts"), constant$1("intents"), constant$1("notifications"), constant$1("channels"), constant$1("extension"), constant$1("themes"), constant$1("prefs"));
1991
1994
  const windowOperationTypesDecoder = oneOf$1(constant$1("openWindow"), constant$1("windowHello"), constant$1("windowAdded"), constant$1("windowRemoved"), constant$1("getBounds"), constant$1("getFrameBounds"), constant$1("getUrl"), constant$1("moveResize"), constant$1("focus"), constant$1("close"), constant$1("getTitle"), constant$1("setTitle"), constant$1("focusChange"), constant$1("getChannel"));
1992
1995
  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"));
1993
- const layoutsOperationTypesDecoder = oneOf$1(constant$1("layoutAdded"), constant$1("layoutChanged"), constant$1("layoutRemoved"), constant$1("get"), constant$1("getAll"), constant$1("export"), constant$1("import"), constant$1("remove"), constant$1("clientSaveRequest"), constant$1("getGlobalPermissionState"), constant$1("checkGlobalActivated"), constant$1("requestGlobalPermission"), constant$1("getDefaultGlobal"), constant$1("setDefaultGlobal"), constant$1("clearDefaultGlobal"));
1996
+ 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"));
1994
1997
  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"));
1995
1998
  const systemOperationTypesDecoder = oneOf$1(constant$1("getEnvironment"), constant$1("getBase"), constant$1("platformShutdown"));
1996
1999
  const windowRelativeDirectionDecoder = oneOf$1(constant$1("top"), constant$1("left"), constant$1("right"), constant$1("bottom"));
@@ -2291,6 +2294,16 @@
2291
2294
  const saveLayoutConfigDecoder = object$1({
2292
2295
  layout: newLayoutOptionsDecoder
2293
2296
  });
2297
+ const renameLayoutConfigDecoder = object$1({
2298
+ layout: glueLayoutDecoder,
2299
+ newName: nonEmptyStringDecoder
2300
+ });
2301
+ const layoutResultDecoder = object$1({
2302
+ status: nonEmptyStringDecoder
2303
+ });
2304
+ const updateLayoutMetadataConfigDecoder = object$1({
2305
+ layout: glueLayoutDecoder,
2306
+ });
2294
2307
  const restoreLayoutConfigDecoder = object$1({
2295
2308
  layout: restoreOptionsDecoder
2296
2309
  });
@@ -2304,7 +2317,7 @@
2304
2317
  const layoutsImportConfigDecoder = object$1({
2305
2318
  layouts: array$1(glueLayoutDecoder),
2306
2319
  mode: importModeDecoder,
2307
- isManagerOperation: optional$1(boolean$1())
2320
+ skipManagerRequest: optional$1(boolean$1())
2308
2321
  });
2309
2322
  const allLayoutsSummariesResultDecoder = object$1({
2310
2323
  summaries: array$1(layoutSummaryDecoder)
@@ -2492,6 +2505,38 @@
2492
2505
  }),
2493
2506
  data: optional$1(object$1()),
2494
2507
  });
2508
+ const removeChannelDataDecoder = object$1({
2509
+ name: nonEmptyStringDecoder
2510
+ });
2511
+ const channelRestrictionsDecoder = object$1({
2512
+ name: nonEmptyStringDecoder,
2513
+ read: boolean$1(),
2514
+ write: boolean$1(),
2515
+ windowId: optional$1(nonEmptyStringDecoder)
2516
+ });
2517
+ const channelRestrictionConfigWithWindowIdDecoder = object$1({
2518
+ name: nonEmptyStringDecoder,
2519
+ read: boolean$1(),
2520
+ write: boolean$1(),
2521
+ windowId: nonEmptyStringDecoder
2522
+ });
2523
+ const restrictionConfigDataDecoder = object$1({
2524
+ config: channelRestrictionConfigWithWindowIdDecoder
2525
+ });
2526
+ const restrictionsDecoder = object$1({
2527
+ channels: array$1(channelRestrictionsDecoder)
2528
+ });
2529
+ const getRestrictionsDataDecoder = object$1({
2530
+ windowId: nonEmptyStringDecoder
2531
+ });
2532
+ const restrictionsConfigDecoder = object$1({
2533
+ read: boolean$1(),
2534
+ write: boolean$1(),
2535
+ windowId: optional$1(nonEmptyStringDecoder)
2536
+ });
2537
+ const restrictAllDataDecoder = object$1({
2538
+ restrictions: restrictionsConfigDecoder
2539
+ });
2495
2540
  const raiseNotificationDecoder = object$1({
2496
2541
  settings: glue42NotificationOptionsDecoder,
2497
2542
  id: nonEmptyStringDecoder
@@ -2610,7 +2655,7 @@
2610
2655
  const getWindowIdsOnChannelResultDecoder = object$1({
2611
2656
  windowIds: array$1(nonEmptyStringDecoder)
2612
2657
  });
2613
- const channelsOperationTypesDecoder = oneOf$1(constant$1("addChannel"), constant$1("getMyChannel"), constant$1("getWindowIdsOnChannel"), constant$1("getWindowIdsWithChannels"), constant$1("joinChannel"));
2658
+ const channelsOperationTypesDecoder = oneOf$1(constant$1("addChannel"), constant$1("getMyChannel"), constant$1("getWindowIdsOnChannel"), constant$1("getWindowIdsWithChannels"), constant$1("joinChannel"), constant$1("restrict"), constant$1("getRestrictions"), constant$1("restrictAll"));
2614
2659
  const getMyChanelResultDecoder = object$1({
2615
2660
  channel: optional$1(nonEmptyStringDecoder)
2616
2661
  });
@@ -2939,7 +2984,8 @@
2939
2984
  }
2940
2985
  async getContext() {
2941
2986
  const ctx = await this._bridge.contextLib.get(this.myCtxKey);
2942
- return ctx;
2987
+ const { ___io___, ...rest } = ctx;
2988
+ return rest;
2943
2989
  }
2944
2990
  async updateContext(context) {
2945
2991
  const ctx = anyDecoder.runWithException(context);
@@ -2948,7 +2994,9 @@
2948
2994
  }
2949
2995
  async setContext(context) {
2950
2996
  const ctx = anyDecoder.runWithException(context);
2951
- await this._bridge.contextLib.set(this.myCtxKey, ctx);
2997
+ const current = await this._bridge.contextLib.get(this.myCtxKey);
2998
+ const newCtx = current.___io___ ? { ...ctx, ___io___: current.___io___ } : ctx;
2999
+ await this._bridge.contextLib.set(this.myCtxKey, newCtx);
2952
3000
  return this.me;
2953
3001
  }
2954
3002
  onContextUpdated(callback) {
@@ -2956,7 +3004,8 @@
2956
3004
  throw new Error("Cannot subscribe to context changes, because the provided callback is not a function!");
2957
3005
  }
2958
3006
  const wrappedCallback = (data) => {
2959
- callback(data, this.me);
3007
+ const { ___io___, ...rest } = data;
3008
+ callback(rest, this.me);
2960
3009
  };
2961
3010
  return this.registry.add("context-updated", wrappedCallback);
2962
3011
  }
@@ -3849,11 +3898,13 @@
3849
3898
  layoutAdded: { name: "layoutAdded", dataDecoder: glueLayoutDecoder },
3850
3899
  layoutChanged: { name: "layoutChanged", dataDecoder: glueLayoutDecoder },
3851
3900
  layoutRemoved: { name: "layoutRemoved", dataDecoder: glueLayoutDecoder },
3901
+ layoutRenamed: { name: "layoutRenamed", dataDecoder: glueLayoutDecoder },
3852
3902
  get: { name: "get", dataDecoder: simpleLayoutConfigDecoder, resultDecoder: optionalSimpleLayoutResult },
3853
3903
  getAll: { name: "getAll", dataDecoder: getAllLayoutsConfigDecoder, resultDecoder: allLayoutsSummariesResultDecoder },
3854
3904
  export: { name: "export", dataDecoder: getAllLayoutsConfigDecoder, resultDecoder: allLayoutsFullConfigDecoder },
3855
3905
  import: { name: "import", dataDecoder: layoutsImportConfigDecoder },
3856
3906
  remove: { name: "remove", dataDecoder: simpleLayoutConfigDecoder },
3907
+ rename: { name: "rename", dataDecoder: renameLayoutConfigDecoder, resultDecoder: layoutResultDecoder },
3857
3908
  save: { name: "save", dataDecoder: saveLayoutConfigDecoder, resultDecoder: simpleLayoutResultDecoder },
3858
3909
  restore: { name: "restore", dataDecoder: restoreLayoutConfigDecoder },
3859
3910
  clientSaveRequest: { name: "clientSaveRequest", dataDecoder: platformSaveRequestConfigDecoder, resultDecoder: saveRequestClientResponseDecoder },
@@ -3862,7 +3913,8 @@
3862
3913
  checkGlobalActivated: { name: "checkGlobalActivated", resultDecoder: simpleAvailabilityResultDecoder },
3863
3914
  getDefaultGlobal: { name: "getDefaultGlobal", resultDecoder: optionalSimpleLayoutResult },
3864
3915
  setDefaultGlobal: { name: "setDefaultGlobal", dataDecoder: setDefaultGlobalConfigDecoder },
3865
- clearDefaultGlobal: { name: "clearDefaultGlobal" }
3916
+ clearDefaultGlobal: { name: "clearDefaultGlobal" },
3917
+ updateMetadata: { name: "updateMetadata", dataDecoder: updateLayoutMetadataConfigDecoder }
3866
3918
  };
3867
3919
 
3868
3920
  class LayoutsController {
@@ -3915,7 +3967,10 @@
3915
3967
  getGlobalTypeState: this.checkGlobalActivated.bind(this),
3916
3968
  getDefaultGlobal: this.getDefaultGlobal.bind(this),
3917
3969
  setDefaultGlobal: this.setDefaultGlobal.bind(this),
3918
- clearDefaultGlobal: this.clearDefaultGlobal.bind(this)
3970
+ clearDefaultGlobal: this.clearDefaultGlobal.bind(this),
3971
+ rename: this.rename.bind(this),
3972
+ onRenamed: this.onRenamed.bind(this),
3973
+ updateMetadata: this.updateMetadata.bind(this)
3919
3974
  };
3920
3975
  return Object.freeze(api);
3921
3976
  }
@@ -3923,6 +3978,7 @@
3923
3978
  operations$7.layoutAdded.execute = this.handleOnAdded.bind(this);
3924
3979
  operations$7.layoutChanged.execute = this.handleOnChanged.bind(this);
3925
3980
  operations$7.layoutRemoved.execute = this.handleOnRemoved.bind(this);
3981
+ operations$7.layoutRenamed.execute = this.handleOnRenamed.bind(this);
3926
3982
  operations$7.clientSaveRequest.execute = this.handleSaveRequest.bind(this);
3927
3983
  }
3928
3984
  async get(name, type) {
@@ -4026,6 +4082,16 @@
4026
4082
  async clearDefaultGlobal() {
4027
4083
  await this.bridge.send("layouts", operations$7.clearDefaultGlobal, undefined, undefined, { includeOperationCheck: true });
4028
4084
  }
4085
+ async rename(layout, newName) {
4086
+ glueLayoutDecoder.runWithException(layout);
4087
+ nonEmptyStringDecoder.runWithException(newName);
4088
+ const result = await this.bridge.send("layouts", operations$7.rename, { layout, newName }, undefined, { includeOperationCheck: true });
4089
+ return result;
4090
+ }
4091
+ async updateMetadata(layout) {
4092
+ glueLayoutDecoder.runWithException(layout);
4093
+ await this.bridge.send("layouts", operations$7.updateMetadata, { layout }, undefined, { includeOperationCheck: true });
4094
+ }
4029
4095
  onAdded(callback) {
4030
4096
  this.export("Global").then((layouts) => layouts.forEach((layout) => callback(layout))).catch(() => { });
4031
4097
  this.export("Workspace").then((layouts) => layouts.forEach((layout) => callback(layout))).catch(() => { });
@@ -4037,6 +4103,12 @@
4037
4103
  onRemoved(callback) {
4038
4104
  return this.registry.add(operations$7.layoutRemoved.name, callback);
4039
4105
  }
4106
+ onRenamed(callback) {
4107
+ if (typeof callback !== "function") {
4108
+ throw new Error("Cannot subscribe to onRenamed, because the provided callback is not a function!");
4109
+ }
4110
+ return this.registry.add(operations$7.layoutRenamed.name, callback);
4111
+ }
4040
4112
  subscribeOnSaveRequested(callback) {
4041
4113
  if (typeof callback !== "function") {
4042
4114
  throw new Error("Cannot subscribe to onSaveRequested, because the provided argument is not a valid callback function.");
@@ -4058,6 +4130,9 @@
4058
4130
  async handleOnRemoved(layout) {
4059
4131
  this.registry.execute(operations$7.layoutRemoved.name, layout);
4060
4132
  }
4133
+ async handleOnRenamed(layout) {
4134
+ this.registry.execute(operations$7.layoutRenamed.name, layout);
4135
+ }
4061
4136
  }
4062
4137
 
4063
4138
  const operations$6 = {
@@ -4588,10 +4663,14 @@
4588
4663
 
4589
4664
  const operations$4 = {
4590
4665
  addChannel: { name: "addChannel", dataDecoder: channelContextDecoder },
4666
+ removeChannel: { name: "removeChannel", dataDecoder: removeChannelDataDecoder },
4591
4667
  getMyChannel: { name: "getMyChannel", resultDecoder: getMyChanelResultDecoder },
4592
4668
  getWindowIdsOnChannel: { name: "getWindowIdsOnChannel", dataDecoder: getWindowIdsOnChannelDataDecoder, resultDecoder: getWindowIdsOnChannelResultDecoder },
4593
4669
  getWindowIdsWithChannels: { name: "getWindowIdsWithChannels", dataDecoder: wrappedWindowWithChannelFilterDecoder, resultDecoder: getWindowIdsWithChannelsResultDecoder },
4594
4670
  joinChannel: { name: "joinChannel", dataDecoder: joinChannelDataDecoder },
4671
+ restrict: { name: "restrict", dataDecoder: restrictionConfigDataDecoder },
4672
+ getRestrictions: { name: "getRestrictions", dataDecoder: getRestrictionsDataDecoder, resultDecoder: restrictionsDecoder },
4673
+ restrictAll: { name: "restrictAll", dataDecoder: restrictAllDataDecoder }
4595
4674
  };
4596
4675
 
4597
4676
  class ChannelsController {
@@ -4612,6 +4691,9 @@
4612
4691
  addOperationsExecutors() {
4613
4692
  operations$4.getMyChannel.execute = this.handleGetMyChannel.bind(this);
4614
4693
  operations$4.joinChannel.execute = this.handleJoinChannel.bind(this);
4694
+ operations$4.restrict.execute = ({ config }) => this.restrict(config);
4695
+ operations$4.getRestrictions.execute = ({ windowId }) => this.getRestrictions(windowId);
4696
+ operations$4.restrictAll.execute = ({ restrictions }) => this.restrictAll(restrictions);
4615
4697
  }
4616
4698
  async start(coreGlue, ioc) {
4617
4699
  this.logger = coreGlue.logger.subLogger("channels.controller.web");
@@ -4684,9 +4766,13 @@
4684
4766
  changed: this.changed.bind(this),
4685
4767
  onChanged: this.onChanged.bind(this),
4686
4768
  add: this.add.bind(this),
4769
+ remove: this.remove.bind(this),
4687
4770
  getMy: this.getMy.bind(this),
4688
4771
  getWindowsOnChannel: this.getWindowsOnChannel.bind(this),
4689
4772
  getWindowsWithChannels: this.getWindowsWithChannels.bind(this),
4773
+ restrict: this.restrict.bind(this),
4774
+ getRestrictions: this.getRestrictions.bind(this),
4775
+ restrictAll: this.restrictAll.bind(this)
4690
4776
  };
4691
4777
  return Object.freeze(api);
4692
4778
  }
@@ -4754,10 +4840,11 @@
4754
4840
  throw new Error("Cannot subscribe to channels, because the provided callback is not a function!");
4755
4841
  }
4756
4842
  const currentChannel = this.current();
4843
+ const wrappedCallback = this.getWrappedCallbackWithPermissionCheck(callback);
4757
4844
  if (currentChannel) {
4758
- this.replaySubscribe(callback, currentChannel);
4845
+ this.replaySubscribe(wrappedCallback, currentChannel);
4759
4846
  }
4760
- return this.registry.add(this.SubsKey, callback);
4847
+ return this.registry.add(this.SubsKey, wrappedCallback);
4761
4848
  }
4762
4849
  async subscribeFor(name, callback) {
4763
4850
  const channelNames = this.getAllChannelNames();
@@ -4766,8 +4853,9 @@
4766
4853
  throw new Error(`Cannot subscribe to channel ${name}, because the provided callback is not a function!`);
4767
4854
  }
4768
4855
  const contextName = this.createContextName(name);
4856
+ const wrappedCallback = this.getWrappedCallbackWithPermissionCheck(callback);
4769
4857
  return this.contexts.subscribe(contextName, (context, _, __, ___, extraData) => {
4770
- callback(context.data, context, extraData?.updaterId);
4858
+ wrappedCallback(context.data, context, extraData?.updaterId);
4771
4859
  });
4772
4860
  }
4773
4861
  publish(data, name) {
@@ -4777,12 +4865,16 @@
4777
4865
  if (typeof name !== "undefined") {
4778
4866
  const channelNames = this.getAllChannelNames();
4779
4867
  channelNameDecoder(channelNames).runWithException(name);
4780
- return this.updateData(name, data);
4781
4868
  }
4782
- if (typeof this.currentChannelName === "undefined") {
4869
+ const channelName = name || this.currentChannelName;
4870
+ if (!channelName) {
4783
4871
  throw new Error("Cannot publish to channel, because not joined to a channel!");
4784
4872
  }
4785
- return this.updateData(this.currentChannelName, data);
4873
+ const canPublish = this.isAllowedByRestrictions(channelName, "write");
4874
+ if (!canPublish) {
4875
+ throw new Error(`Cannot publish on channel ${channelName} due to restrictions`);
4876
+ }
4877
+ return this.updateData(channelName, data);
4786
4878
  }
4787
4879
  async all() {
4788
4880
  const channelNames = this.getAllChannelNames();
@@ -4817,6 +4909,14 @@
4817
4909
  await this.bridge.send("channels", operations$4.addChannel, channelContext);
4818
4910
  return channelContext;
4819
4911
  }
4912
+ async remove(name) {
4913
+ nonEmptyStringDecoder.runWithException(name);
4914
+ const channelWithSuchNameExists = this.getAllChannelNames().includes(name);
4915
+ if (!channelWithSuchNameExists) {
4916
+ throw new Error("There's no channel with such name");
4917
+ }
4918
+ await this.bridge.send("channels", operations$4.removeChannel, { name }, undefined, { includeOperationCheck: true });
4919
+ }
4820
4920
  replaySubscribe = (callback, channelId) => {
4821
4921
  this.get(channelId)
4822
4922
  .then((channelContext) => {
@@ -4862,6 +4962,93 @@
4862
4962
  }, []);
4863
4963
  return result;
4864
4964
  }
4965
+ async restrict(config) {
4966
+ channelRestrictionsDecoder.runWithException(config);
4967
+ const channelNames = this.getAllChannelNames();
4968
+ channelNameDecoder(channelNames).runWithException(config.name);
4969
+ const forAnotherClient = config.windowId && config.windowId !== this.windowsController.my().id;
4970
+ if (forAnotherClient) {
4971
+ return this.bridge.send("channels", operations$4.restrict, { config }, undefined, { includeOperationCheck: true });
4972
+ }
4973
+ const sessionStorageData = this.sessionController.getWindowData();
4974
+ const restrictions = sessionStorageData?.restrictions ? { ...sessionStorageData.restrictions, [config.name]: config } : { [config.name]: config };
4975
+ const currentChannel = await this.getMy();
4976
+ const prevReadAllowed = this.checkPreviousReadAllowed(currentChannel?.name);
4977
+ this.sessionController.setWindowData(restrictions, "restrictions");
4978
+ if (!currentChannel || prevReadAllowed || !config.read || currentChannel.name !== config.name) {
4979
+ return;
4980
+ }
4981
+ this.replaySubscribeCallback(config.name);
4982
+ }
4983
+ async getRestrictions(windowId) {
4984
+ optionalNonEmptyStringDecoder.runWithException(windowId);
4985
+ if (!windowId || windowId === this.windowsController.my().id) {
4986
+ return this.getMyRestrictions();
4987
+ }
4988
+ return this.bridge.send("channels", operations$4.getRestrictions, { windowId }, undefined, { includeOperationCheck: true });
4989
+ }
4990
+ async restrictAll(restrictions) {
4991
+ restrictionsConfigDecoder.runWithException(restrictions);
4992
+ const allChannelNames = this.getAllChannelNames();
4993
+ const forAnotherClient = restrictions.windowId && restrictions.windowId !== this.windowsController.my().id;
4994
+ if (forAnotherClient) {
4995
+ return this.bridge.send("channels", operations$4.restrictAll, { restrictions }, undefined, { includeOperationCheck: true });
4996
+ }
4997
+ const allRestrictions = {};
4998
+ allChannelNames.forEach((name) => {
4999
+ allRestrictions[name] = { ...restrictions, name };
5000
+ });
5001
+ const currentChannel = await this.getMy();
5002
+ const prevReadAllowed = this.checkPreviousReadAllowed(currentChannel?.name);
5003
+ this.sessionController.setWindowData(allRestrictions, "restrictions");
5004
+ if (!currentChannel || prevReadAllowed || !restrictions.read) {
5005
+ return;
5006
+ }
5007
+ this.replaySubscribeCallback(currentChannel.name);
5008
+ }
5009
+ isAllowedByRestrictions(channelName, action) {
5010
+ const { channels } = this.getMyRestrictions();
5011
+ if (!channels?.length) {
5012
+ return true;
5013
+ }
5014
+ const restriction = channels.find((restriction) => restriction.name === channelName);
5015
+ return restriction ? restriction[action] : true;
5016
+ }
5017
+ getMyRestrictions() {
5018
+ const sessionStorageData = this.sessionController.getWindowData();
5019
+ const restrictions = Object.values(sessionStorageData?.restrictions || {});
5020
+ return { channels: restrictions };
5021
+ }
5022
+ getWrappedCallbackWithPermissionCheck(callback) {
5023
+ const wrappedCallback = (data, context, updaterId) => {
5024
+ const canRead = this.isAllowedByRestrictions(context.name, "read");
5025
+ if (!canRead) {
5026
+ return;
5027
+ }
5028
+ callback(data, context, updaterId);
5029
+ };
5030
+ return wrappedCallback;
5031
+ }
5032
+ replaySubscribeCallback(channelName) {
5033
+ const contextName = this.createContextName(channelName);
5034
+ this.contexts.subscribe(contextName, (context, _, __, ___, extraData) => {
5035
+ this.registry.execute(this.SubsKey, context.data, context, extraData?.updaterId);
5036
+ }).then((unsub) => {
5037
+ if (unsub && typeof unsub === "function") {
5038
+ unsub();
5039
+ }
5040
+ }).catch(err => this.logger.error(err));
5041
+ }
5042
+ checkPreviousReadAllowed(channelName) {
5043
+ if (!channelName) {
5044
+ return true;
5045
+ }
5046
+ const prevRestrictions = this.sessionController.getWindowData().restrictions;
5047
+ if (!prevRestrictions?.[channelName]) {
5048
+ return true;
5049
+ }
5050
+ return prevRestrictions[channelName].read;
5051
+ }
4865
5052
  }
4866
5053
 
4867
5054
  const operations$3 = {
@@ -5932,7 +6119,7 @@
5932
6119
  }
5933
6120
  }
5934
6121
 
5935
- var version$1 = "3.2.2";
6122
+ var version$1 = "3.3.0";
5936
6123
 
5937
6124
  const createFactoryFunction = (coreFactoryFunction) => {
5938
6125
  return async (userConfig) => {
@@ -8890,7 +9077,7 @@
8890
9077
  }
8891
9078
  };
8892
9079
 
8893
- var version = "6.2.2";
9080
+ var version = "6.3.0";
8894
9081
 
8895
9082
  function prepareConfig (configuration, ext, glue42gd) {
8896
9083
  let nodeStartingContext;