@interopio/fdc3 2.7.1 → 2.8.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.
@@ -5007,6 +5007,9 @@
5007
5007
 
5008
5008
  const nonEmptyStringDecoder$1 = string$1().where((s) => s.length > 0, "Expected a non-empty string");
5009
5009
  const nonNegativeNumberDecoder = number$1().where((num) => num >= 0, "Expected a non-negative number");
5010
+ const regexDecoder = anyJson$1().andThen((value) => {
5011
+ return value instanceof RegExp ? anyJson$1() : fail(`expected a regex, got a ${typeof value}`);
5012
+ });
5010
5013
 
5011
5014
  const intentDefinitionDecoder = object$1({
5012
5015
  name: nonEmptyStringDecoder$1,
@@ -5333,7 +5336,8 @@
5333
5336
  const decoders$1 = {
5334
5337
  common: {
5335
5338
  nonEmptyStringDecoder: nonEmptyStringDecoder$1,
5336
- nonNegativeNumberDecoder
5339
+ nonNegativeNumberDecoder,
5340
+ regexDecoder
5337
5341
  },
5338
5342
  fdc3: {
5339
5343
  allDefinitionsDecoder,
@@ -6265,9 +6269,6 @@
6265
6269
  })
6266
6270
  })
6267
6271
  });
6268
- object({
6269
- channelId: optional(nonEmptyStringDecoder)
6270
- });
6271
6272
  const privateChannelEventTypesDecoder = oneOf(constant("addContextListener"), constant("unsubscribe"), constant("disconnect"));
6272
6273
  const optionalPrivateChannelEventTypesDecoder = optional(privateChannelEventTypesDecoder);
6273
6274
  const optionalFdc3EventTypesDecoder = optional(constant("userChannelChanged"));
@@ -6320,12 +6321,12 @@
6320
6321
  interopInstance() {
6321
6322
  return this.glue.interop.instance;
6322
6323
  }
6323
- async getApplication(name) {
6324
+ async getApplication(options) {
6324
6325
  const isAppsAPIAvailable = this.isAppsAPIAvailable();
6325
6326
  if (!isAppsAPIAvailable) {
6326
- return this.glue.appManager.application(name);
6327
+ return this.glue.appManager.application(options.name);
6327
6328
  }
6328
- const app = await this.glue.apps.registry.get({ name });
6329
+ const app = await this.glue.apps.registry.get(options);
6329
6330
  return app ?? undefined;
6330
6331
  }
6331
6332
  async getApplicationInstances(appName) {
@@ -6344,6 +6345,21 @@
6344
6345
  const appInstance = await this.glue.apps.instances.get({ id });
6345
6346
  return appInstance ?? undefined;
6346
6347
  }
6348
+ async getIoCDAppConfiguration(app) {
6349
+ const isAppsAPIAvailable = this.isAppsAPIAvailable();
6350
+ if (!isAppsAPIAvailable) {
6351
+ return app.getConfiguration();
6352
+ }
6353
+ const definition = app.definition;
6354
+ if (definition) {
6355
+ return definition;
6356
+ }
6357
+ const appWithDefinition = await this.glue.apps.registry.get({ name: app.name, includeDefinition: true });
6358
+ if (!appWithDefinition?.definition) {
6359
+ throw new Error(`Application definition for app '${app.name}' could not be found`);
6360
+ }
6361
+ return appWithDefinition.definition;
6362
+ }
6347
6363
  async startApplication({ app, context, waitForInstanceReady }) {
6348
6364
  const isAppsAPIAvailable = this.isAppsAPIAvailable();
6349
6365
  if (!isAppsAPIAvailable) {
@@ -6361,13 +6377,14 @@
6361
6377
  return this.glue.intents.find(intentFilter);
6362
6378
  }
6363
6379
  async raiseIntent(request) {
6364
- return this.glue.intents.raise(request);
6380
+ const result = await this.glue.intents.raise(request);
6381
+ return result;
6365
6382
  }
6366
6383
  doesFilterHandlersExist() {
6367
6384
  return !!this.glue.intents.filterHandlers;
6368
6385
  }
6369
6386
  async filterHandlers(handlerFilter) {
6370
- if (!this.glue.intents.filterHandlers) {
6387
+ if (!this.doesFilterHandlersExist()) {
6371
6388
  throw new Error("Intents method 'filterHandlers' does not exist");
6372
6389
  }
6373
6390
  return this.glue.intents.filterHandlers(handlerFilter);
@@ -6389,10 +6406,10 @@
6389
6406
  return myWin.getContext();
6390
6407
  }
6391
6408
  async addIntentListener(intent, handler) {
6392
- if (typeof this.glue.intents.register === "function") {
6393
- return await this.glue.intents.register(intent, handler);
6409
+ if (typeof this.glue.intents.register !== "function") {
6410
+ return this.glue.intents.addIntentListener(intent, handler);
6394
6411
  }
6395
- return this.glue.intents.addIntentListener(intent, handler);
6412
+ return this.glue.intents.register(intent, handler);
6396
6413
  }
6397
6414
  getAllContexts() {
6398
6415
  return this.glue.contexts.all();
@@ -6417,7 +6434,7 @@
6417
6434
  async getMyChannels() {
6418
6435
  if (!this.glue.channels.getMyChannels) {
6419
6436
  const myChannel = await this.glue.channels.getMy();
6420
- return [myChannel];
6437
+ return myChannel ? [myChannel] : [];
6421
6438
  }
6422
6439
  return this.glue.channels.getMyChannels();
6423
6440
  }
@@ -6466,12 +6483,16 @@
6466
6483
  return this.glue.channels.get(channelId);
6467
6484
  }
6468
6485
  getMyWindow() {
6469
- const win = this.glue.windows.my();
6470
- const isValidWindow = isValidNonEmptyObject(win);
6486
+ const myWindow = this.glue.windows.my();
6487
+ const isValidWindow = isValidNonEmptyObject(myWindow);
6471
6488
  if (isValidWindow) {
6472
- return win;
6489
+ return myWindow;
6490
+ }
6491
+ const myInstance = this.getMyInteropInstance();
6492
+ if (!myInstance?.instance) {
6493
+ return;
6473
6494
  }
6474
- return this.glue.windows.findById(this.glue.interop.instance.instance);
6495
+ return this.glue.windows.findById(myInstance.instance);
6475
6496
  }
6476
6497
  getMyInteropInstance() {
6477
6498
  return this.glue.interop.instance;
@@ -6565,8 +6586,8 @@
6565
6586
  async checkIsFdc3DataWrappingSupported() {
6566
6587
  const inBrowserNamespace = this.isRunningInBrowser();
6567
6588
  const methodName = inBrowserNamespace ? BrowserClientControlMethodName : DesktopClientControlMethodName;
6568
- const myServer = this.glue.interop.servers().find((server) => server.instance === this.glue.interop.instance.instance);
6569
- if (!myServer) {
6589
+ const myServer = this.getInteropServers().find((server) => server.instance === this.glue.interop.instance.instance && server.isLocal);
6590
+ if (!myServer || typeof myServer.getMethods !== "function") {
6570
6591
  return false;
6571
6592
  }
6572
6593
  const registersControlMethod = myServer.getMethods().some((method) => method.name === methodName);
@@ -6593,13 +6614,13 @@
6593
6614
  return this.glue.interop.instance.peerId === updaterId;
6594
6615
  }
6595
6616
  getContextMetadata(updaterId) {
6596
- const instanceServer = this.glue.interop.servers().find((server) => server.peerId === updaterId);
6617
+ const instanceServer = this.getInteropServers().find((server) => server.peerId === updaterId);
6597
6618
  if (!instanceServer) {
6598
6619
  return;
6599
6620
  }
6600
6621
  return {
6601
6622
  source: {
6602
- appId: instanceServer.application ?? instanceServer.applicationName,
6623
+ appId: (instanceServer.application ?? instanceServer.applicationName),
6603
6624
  instanceId: instanceServer.instance
6604
6625
  }
6605
6626
  };
@@ -8440,9 +8461,9 @@
8440
8461
  async getCurrentChannels() {
8441
8462
  return this.channelsController.getCurrentChannels(generateCommandId());
8442
8463
  }
8443
- async leaveChannel(channelId) {
8444
- nonEmptyStringDecoder.runWithException(channelId);
8445
- return this.channelsController.leave(generateCommandId(), { channelId });
8464
+ async leaveChannel(channel) {
8465
+ nonEmptyStringDecoder.runWithException(channel);
8466
+ return this.channelsController.leave(generateCommandId(), { channel });
8446
8467
  }
8447
8468
  async leaveCurrentChannels() {
8448
8469
  return this.channelsController.leave(generateCommandId());
@@ -8670,7 +8691,7 @@
8670
8691
  if (!context && !resultType) {
8671
8692
  return this.convertGlue42IntentToFDC3Intent(searchedGlueIntent);
8672
8693
  }
8673
- const contextType = (context && context.type === fdc3NothingContextType) ? undefined : context?.type;
8694
+ const contextType = context?.type === fdc3NothingContextType ? undefined : context?.type;
8674
8695
  const filteredIntent = this.getGlueIntentWithFilteredHandlers(searchedGlueIntent, { contextType, resultType });
8675
8696
  if (!filteredIntent.handlers.length) {
8676
8697
  throw new Error(ResolveError.NoAppsFound);
@@ -8793,7 +8814,7 @@
8793
8814
  this._logger?.warn(`Cannot get prefs due to the following error: ${error}`);
8794
8815
  return;
8795
8816
  }
8796
- const intentPrefs = prefs.data?.intents;
8817
+ const intentPrefs = prefs?.data?.intents;
8797
8818
  if (!intentPrefs) {
8798
8819
  return;
8799
8820
  }
@@ -8822,7 +8843,7 @@
8822
8843
  const appName = typeof target === "string" ? target : target.appId;
8823
8844
  const instanceId = typeof target === "string" ? undefined : target.instanceId;
8824
8845
  this.logger?.info(`[${commandId}] - Checking if application with name ${appName} exists`);
8825
- const app = await this.glueController.getApplication(appName);
8846
+ const app = await this.glueController.getApplication({ name: appName, includeDefinition: true, includeInstances: true });
8826
8847
  const serverInstances = this.serverInstanceAsIntentHandler(intent.name);
8827
8848
  if (!app && (typeof target === "string" || !target.instanceId || !serverInstances.length)) {
8828
8849
  throw new Error(ResolveError.TargetAppUnavailable);
@@ -8836,8 +8857,9 @@
8836
8857
  this.logger?.log(`[${commandId}] - returning all handlers for intent ${intent.name} and target: ${JSON.stringify(target)}`);
8837
8858
  return { name: intent.name, handlers: validHandlersByApplicationName };
8838
8859
  }
8860
+ const appInstances = app?.instances ?? await (this.glueController.getApplicationInstances(appName));
8839
8861
  const isValidInstanceOfTheApp = app
8840
- ? app.instances.find((inst) => inst.id === instanceId)
8862
+ ? appInstances.find((inst) => inst.id === instanceId)
8841
8863
  : serverInstances.find((inst) => inst.instance === instanceId);
8842
8864
  if (!isValidInstanceOfTheApp) {
8843
8865
  throw new Error(ResolveError.TargetInstanceUnavailable);
@@ -8904,17 +8926,23 @@
8904
8926
  }
8905
8927
  async convertGlue42IntentToFDC3Intent(glueIntent) {
8906
8928
  const { name, handlers } = glueIntent;
8929
+ const displayName = handlers.find((handler) => handler.displayName)?.displayName ?? name;
8907
8930
  const apps = await Promise.all(handlers.map(async (handler) => {
8908
8931
  const appName = handler.applicationName;
8909
- const app = await this.glueController.getApplication(appName);
8910
- const icons = (handler.applicationIcon ? [handler.applicationIcon, ...(app?.userProperties.icons ?? [])] : (app?.userProperties.icons ?? [])).filter((icon) => !!icon).map((icon) => ({ src: icon }));
8911
- const images = (app?.userProperties.images ?? []).filter((image) => !!image).map((image) => ({ src: image }));
8932
+ const app = await this.glueController.getApplication({ name: appName, includeDefinition: true });
8933
+ const icons = [app?.icon, ...(app?.userProperties?.icons ?? []), ...(app?.customProperties?.icons ?? [])]
8934
+ .filter((icon) => !!icon)
8935
+ .map((icon) => ({ src: icon }));
8936
+ const images = [...(app?.userProperties?.images ?? []), ...(app?.customProperties?.images ?? [])]
8937
+ .filter((image) => !!image)
8938
+ .map((image) => ({ src: image }));
8939
+ const tooltip = app?.title || app?.userProperties?.tooltip || `${appName} (${handler.type})`;
8912
8940
  return {
8913
8941
  appId: appName,
8914
8942
  instanceId: handler.instanceId,
8915
8943
  name: appName,
8916
8944
  title: handler.applicationTitle || handler.instanceTitle || appName,
8917
- tooltip: app?.userProperties.tooltip ?? `${appName} (${handler.type})`,
8945
+ tooltip,
8918
8946
  description: handler.applicationDescription,
8919
8947
  icons,
8920
8948
  images,
@@ -8922,7 +8950,7 @@
8922
8950
  };
8923
8951
  }));
8924
8952
  const appIntent = {
8925
- intent: { name, displayName: handlers[0].displayName || "" },
8953
+ intent: { name, displayName },
8926
8954
  apps
8927
8955
  };
8928
8956
  return appIntent;
@@ -9036,7 +9064,7 @@
9036
9064
  await this.glueController.gluePromise;
9037
9065
  this.logger?.log(`[${commandId}] - open() invoked with target ${JSON.stringify(target)} ${context ? `and contextType ${context.type}` : ""}`);
9038
9066
  const name = typeof target === "object" ? target.appId : target;
9039
- const app = await this.glueController.getApplication(name);
9067
+ const app = await this.glueController.getApplication({ name });
9040
9068
  if (!app) {
9041
9069
  throw new Error(OpenError.AppNotFound);
9042
9070
  }
@@ -9059,12 +9087,12 @@
9059
9087
  await this.glueController.gluePromise;
9060
9088
  this.logger?.info(`[${commandId}] - findInstances() invoked with appIdentifier ${JSON.stringify(appIdentifier)}`);
9061
9089
  const { appId } = appIdentifier;
9062
- const app = await this.glueController.getApplication(appId);
9090
+ const app = await this.glueController.getApplication({ name: appId, includeInstances: true, includeDefinition: true });
9063
9091
  if (!app) {
9064
9092
  throw new Error(ResolveError.NoAppsFound);
9065
9093
  }
9066
- const glueInstances = await this.glueController.getApplicationInstances(appId);
9067
- const fdc3Instances = glueInstances.map(glueInst => this.parseGlueInstToAppIdentifier(glueInst));
9094
+ const appInstances = app.instances ?? await this.glueController.getApplicationInstances(appId);
9095
+ const fdc3Instances = appInstances.map(glueInst => this.parseGlueInstToAppIdentifier(glueInst));
9068
9096
  this.logger?.info(`[${commandId}] - ids of opened instances for appIdentifier ${JSON.stringify(appIdentifier)}: ${JSON.stringify(fdc3Instances.map(inst => inst.instanceId))}`);
9069
9097
  return fdc3Instances;
9070
9098
  }
@@ -9072,7 +9100,7 @@
9072
9100
  await this.glueController.gluePromise;
9073
9101
  this.logger?.info(`[${commandId}] - getAppMetadata() invoked with appIdentifier ${JSON.stringify(appIdentifier)}`);
9074
9102
  const { appId, instanceId } = appIdentifier;
9075
- const app = await this.glueController.getApplication(appId);
9103
+ const app = await this.glueController.getApplication({ name: appId, includeDefinition: true, includeInstances: true });
9076
9104
  if (!app) {
9077
9105
  throw new Error(OpenError.AppNotFound);
9078
9106
  }
@@ -9106,7 +9134,7 @@
9106
9134
  async getCurrentAppMetadata() {
9107
9135
  const myInstance = this.glueController.interopInstance();
9108
9136
  const myInstanceApplicationName = myInstance.application ?? myInstance.applicationName;
9109
- const myApp = await this.glueController.getApplication(myInstanceApplicationName);
9137
+ const myApp = await this.glueController.getApplication({ name: myInstanceApplicationName, includeDefinition: true });
9110
9138
  if (myApp) {
9111
9139
  return { appId: myApp.name, instanceId: myInstance.instance };
9112
9140
  }
@@ -9120,40 +9148,43 @@
9120
9148
  };
9121
9149
  }
9122
9150
  async parseGlueAppToAppMetadata(app, instance) {
9123
- const appMetadata = await this.getBaseGlueAppToAppMetadata(app);
9151
+ const inBrowserNamespace = this.glueController.isRunningInBrowser();
9152
+ const appMetadata = inBrowserNamespace
9153
+ ? await this.getBaseGlueAppToAppMetadataInBrowser(app)
9154
+ : await this.getBaseGlueAppToAppMetadataInDesktop(app);
9124
9155
  if (!instance) {
9125
9156
  return appMetadata;
9126
9157
  }
9127
- return this.addInstanceMetadataToAppMetadata(appMetadata, instance);
9158
+ const instanceData = {
9159
+ instanceId: instance.id,
9160
+ instanceMetadata: this.isApplicationInstance(instance) ? instance.interopInstance : instance.agm
9161
+ };
9162
+ return { ...appMetadata, ...instanceData };
9128
9163
  }
9129
- async getBaseGlueAppToAppMetadata(app) {
9130
- const inBrowserNamespace = this.glueController.isRunningInBrowser();
9131
- const appConfiguration = inBrowserNamespace
9132
- ? app.userProperties
9133
- : await app.getConfiguration();
9134
- const icon = inBrowserNamespace
9135
- ? app.icon
9136
- : (await app.getConfiguration()).icon;
9137
- const desktopScreenshots = appConfiguration.customProperties?.screenshots ?? appConfiguration.userProperties?.screenshots;
9138
- const screenshots = inBrowserNamespace
9139
- ? appConfiguration.screenshots
9140
- : desktopScreenshots;
9164
+ async getBaseGlueAppToAppMetadataInDesktop(app) {
9165
+ const appConfiguration = await this.glueController.getIoCDAppConfiguration(app);
9166
+ const screenshots = appConfiguration.customProperties?.screenshots ?? appConfiguration.userProperties?.screenshots;
9141
9167
  return {
9142
- appId: app.name,
9143
- name: app.name,
9144
- version: app.version,
9168
+ appId: appConfiguration.name,
9169
+ name: appConfiguration.name,
9170
+ version: appConfiguration.version,
9145
9171
  description: appConfiguration.description,
9146
- title: app.title,
9147
- icons: icon ? [{ src: icon }] : [],
9172
+ title: appConfiguration.title,
9173
+ icons: appConfiguration.icon ? [{ src: appConfiguration.icon }] : [],
9148
9174
  tooltip: appConfiguration.tooltip,
9149
9175
  screenshots
9150
9176
  };
9151
9177
  }
9152
- addInstanceMetadataToAppMetadata(appMetadata, instance) {
9178
+ async getBaseGlueAppToAppMetadataInBrowser(app) {
9153
9179
  return {
9154
- ...appMetadata,
9155
- instanceId: instance.id,
9156
- instanceMetadata: this.isApplicationInstance(instance) ? instance.interopInstance : instance.agm
9180
+ appId: app.name,
9181
+ name: app.name,
9182
+ version: app.version,
9183
+ description: app.userProperties.description,
9184
+ title: app.title,
9185
+ icons: app.icon ? [{ src: app.icon }] : [],
9186
+ tooltip: app.userProperties.tooltip,
9187
+ screenshots: app.userProperties.screenshots
9157
9188
  };
9158
9189
  }
9159
9190
  isApplicationInstance(instance) {
@@ -9162,7 +9193,7 @@
9162
9193
  async openAppWithContext(app, context) {
9163
9194
  const guid = nanoid();
9164
9195
  const startContext = this.buildStartContext(context, guid);
9165
- const wrappedPromise = this.createContextListenerWrappedPromise(app);
9196
+ const wrappedPromise = this.createContextListenerWrappedPromise(app.name);
9166
9197
  this.appsStateStore.addOpenAppPromise(guid, wrappedPromise);
9167
9198
  try {
9168
9199
  const glueInst = await this.glueController.startApplication({
@@ -9196,15 +9227,16 @@
9196
9227
  }
9197
9228
  };
9198
9229
  }
9199
- createContextListenerWrappedPromise(app) {
9230
+ createContextListenerWrappedPromise(appName) {
9200
9231
  let resolve = () => { };
9201
9232
  let reject = () => { };
9233
+ const timeoutMessage = `Timeout of ${this.defaultContextListenerInvokedPromiseTimeout}ms hit waiting for application with appId: ${appName} to register context listener`;
9202
9234
  const promise = promisePlus(() => {
9203
9235
  return new Promise((res, rej) => {
9204
9236
  resolve = res;
9205
9237
  reject = rej;
9206
9238
  });
9207
- }, this.defaultContextListenerInvokedPromiseTimeout, `Timeout of ${this.defaultContextListenerInvokedPromiseTimeout}ms hit waiting for application with appId: ${app.name} to register context listener`);
9239
+ }, this.defaultContextListenerInvokedPromiseTimeout, timeoutMessage);
9208
9240
  return { promise, resolve, reject };
9209
9241
  }
9210
9242
  }
@@ -10062,12 +10094,12 @@
10062
10094
  async leave(commandId, options) {
10063
10095
  await this.initDonePromise;
10064
10096
  this.logger?.info(`[${commandId}] - leave() invoked with options: ${JSON.stringify(options)}`);
10065
- if (!options?.channelId) {
10097
+ if (!options?.channel) {
10066
10098
  this.logger?.info(`[${commandId}] - leaving all channels`);
10067
10099
  return this.glueController.leaveChannel();
10068
10100
  }
10069
10101
  const allIoChannels = await this.glueController.listAllChannels();
10070
- const ioChannelToLeave = allIoChannels.find((ch) => ch.meta.fdc3?.id === options.channelId);
10102
+ const ioChannelToLeave = allIoChannels.find((ch) => ch.meta.fdc3?.id === options.channel);
10071
10103
  if (!ioChannelToLeave) {
10072
10104
  throw new Error(ChannelError.NoChannelFound);
10073
10105
  }
@@ -10266,7 +10298,11 @@
10266
10298
  return context.latest_fdc3_type ? this.parser.parseContextsDataToInitialFDC3Data(context) : null;
10267
10299
  }
10268
10300
  const parsedType = this.parser.mapFDC3TypeToChannelsDelimiter(contextType);
10269
- const { data } = await this.glueController.getChannel(ioChannelName);
10301
+ const ioChannel = await this.glueController.getChannel(ioChannelName);
10302
+ if (!ioChannel) {
10303
+ return null;
10304
+ }
10305
+ const { data } = ioChannel;
10270
10306
  return data?.[`fdc3_${parsedType}`]
10271
10307
  ? this.parser.parseContextsDataToInitialFDC3Data({ data, latest_fdc3_type: parsedType })
10272
10308
  : null;
@@ -10315,6 +10351,9 @@
10315
10351
  throw new Error(ChannelError.AccessDenied);
10316
10352
  }
10317
10353
  const ioChannel = await this.glueController.getChannel(ioChannelName);
10354
+ if (!ioChannel) {
10355
+ return null;
10356
+ }
10318
10357
  if (!contextType) {
10319
10358
  return ioChannel.data.fdc3 || null;
10320
10359
  }
@@ -10541,9 +10580,10 @@
10541
10580
  return ioc.fdc3;
10542
10581
  };
10543
10582
 
10544
- var version = "2.7.1";
10583
+ var version = "2.8.0";
10545
10584
 
10546
- const globalScope = typeof process !== "undefined" ? process : window;
10585
+ const inNodeEnv = typeof process !== "undefined" && typeof window === "undefined" && typeof document === "undefined";
10586
+ const globalScope = inNodeEnv ? process : window;
10547
10587
  globalScope.fdc3Info = {
10548
10588
  provider: "io.Connect",
10549
10589
  providerVersion: version,