@openfin/core 31.74.19 → 31.74.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/core",
3
- "version": "31.74.19",
3
+ "version": "31.74.21",
4
4
  "license": "SEE LICENSE IN LICENSE.MD",
5
5
  "main": "./src/mock.js",
6
6
  "types": "./src/mock.d.ts",
@@ -169,11 +169,15 @@ class Fdc3Module extends base_1.Base {
169
169
  }
170
170
  catch (error) {
171
171
  if (error.message === utils_2.BROKER_ERRORS.joinSessionContextGroupWithJoinContextGroup) {
172
- throw new Error('The Channel you have tried to join is an App Channel. Custom Channels can only be defined by the Interop Broker through code or manifest configuration. Please use getOrCreateChannel.');
172
+ console.error('The Channel you have tried to join is an App Channel. Custom Channels can only be defined by the Interop Broker through code or manifest configuration. Please use getOrCreateChannel.');
173
173
  }
174
174
  else {
175
- throw new Error(error.message);
175
+ console.error(error.message);
176
176
  }
177
+ if (error.message.startsWith('Attempting to join a context group that does not exist')) {
178
+ throw new Error(utils_1.ChannelError.NoChannelFound);
179
+ }
180
+ throw new Error(utils_1.ChannelError.AccessDenied);
177
181
  }
178
182
  }
179
183
  /**
@@ -317,8 +321,19 @@ class Fdc3Module extends base_1.Base {
317
321
  this.wire.sendAction('fdc3-get-or-create-channel').catch((e) => {
318
322
  // we do not want to expose this error, just continue if this analytics-only call fails
319
323
  });
320
- const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
321
- return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
324
+ const systemChannels = await this.getSystemChannels();
325
+ const userChannel = systemChannels.find((channel) => channel.id === channelId);
326
+ if (userChannel) {
327
+ return { ...userChannel, type: 'system', ...(0, utils_1.getUnsupportedChannelApis)() };
328
+ }
329
+ try {
330
+ const sessionContextGroup = await this.fin.me.interop.joinSessionContextGroup(channelId);
331
+ return (0, utils_1.buildAppChannelObject)(sessionContextGroup);
332
+ }
333
+ catch (error) {
334
+ console.error(error.message);
335
+ throw new Error(utils_1.ChannelError.CreationFailed);
336
+ }
322
337
  }
323
338
  /**
324
339
  * Returns metadata relating to the FDC3 object and its provider, including the supported version of the FDC3 specification and the name of the provider of the implementation.
@@ -348,27 +348,27 @@ class Fdc3Module2 extends base_1.Base {
348
348
  // The FDC3 Intenter handler only expects the context and contextMetadata to be passed to the handler,
349
349
  // so we wrap it here and only pass those paramaters.
350
350
  const contextHandler = async (raisedIntent) => {
351
+ let intentResult;
352
+ let intentResultToSend;
351
353
  const { context, metadata: intentMetadata } = raisedIntent;
352
354
  const { contextMetadata, metadata, ...rest } = context;
353
- let intentResult;
355
+ const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
354
356
  try {
355
357
  const newContext = metadata ? { metadata, ...rest } : { ...rest };
356
358
  intentResult = await handler(newContext, contextMetadata);
359
+ intentResultToSend = intentResult;
357
360
  }
358
361
  catch (error) {
359
362
  intentResult = error;
363
+ intentResultToSend = { error: true };
360
364
  }
361
- const intentResolutionResultId = (intentMetadata === null || intentMetadata === void 0 ? void 0 : intentMetadata.intentResolutionResultId) || (metadata === null || metadata === void 0 ? void 0 : metadata.intentResolutionResultId);
362
365
  if (intentResolutionResultId) {
363
- // Send whatever the result is.
364
- this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResult);
366
+ this.fin.InterApplicationBus.publish(intentResolutionResultId, intentResultToSend);
365
367
  }
366
368
  if (intentResult instanceof Error) {
367
369
  throw new Error(intentResult.message);
368
370
  }
369
- else {
370
- return intentResult;
371
- }
371
+ return intentResult;
372
372
  };
373
373
  return this.fin.me.interop.registerIntentHandler(contextHandler, intent, { fdc3Version: '2.0' });
374
374
  }
@@ -21,8 +21,25 @@ export declare enum ResultError {
21
21
  */
22
22
  IntentHandlerRejected = "IntentHandlerRejected"
23
23
  }
24
+ export declare enum ChannelError {
25
+ /** Returned if the specified channel is not found when attempting to join a
26
+ * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
27
+ */
28
+ NoChannelFound = "NoChannelFound",
29
+ /** SHOULD be returned when a request to join a user channel or to a retrieve
30
+ * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
31
+ * of the DesktopAgent (`fdc3`) object is denied.
32
+ */
33
+ AccessDenied = "AccessDenied",
34
+ /** SHOULD be returned when a channel cannot be created or retrieved via the
35
+ * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
36
+ */
37
+ CreationFailed = "CreationFailed"
38
+ }
24
39
  export declare const buildPrivateChannelObject: (privateChannelClient: PrivateChannelClient) => PrivateChannel;
25
40
  export declare const buildAppChannelObject: (sessionContextGroup: OpenFin.SessionContextGroup) => Channel;
26
41
  export declare const connectPrivateChannel: (channelId: string) => Promise<PrivateChannel>;
42
+ export declare const isContext: (context: unknown) => context is Context;
43
+ export declare const isChannel: (channel: unknown) => channel is Channel;
27
44
  export declare const getIntentResolution: (interopModule: OpenFin.InteropClient, context: Context, app?: AppIdentifier | TargetApp, intent?: string) => Promise<IntentResolution>;
28
45
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getIntentResolution = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
3
+ exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const PrivateChannelClient_1 = require("./PrivateChannelClient");
6
6
  const getUnsupportedChannelApis = (channelType) => {
@@ -35,6 +35,22 @@ var ResultError;
35
35
  */
36
36
  ResultError["IntentHandlerRejected"] = "IntentHandlerRejected";
37
37
  })(ResultError = exports.ResultError || (exports.ResultError = {}));
38
+ var ChannelError;
39
+ (function (ChannelError) {
40
+ /** Returned if the specified channel is not found when attempting to join a
41
+ * channel via the `joinUserChannel` function of the DesktopAgent (`fdc3`).
42
+ */
43
+ ChannelError["NoChannelFound"] = "NoChannelFound";
44
+ /** SHOULD be returned when a request to join a user channel or to a retrieve
45
+ * a Channel object via the `joinUserChannel` or `getOrCreateChannel` methods
46
+ * of the DesktopAgent (`fdc3`) object is denied.
47
+ */
48
+ ChannelError["AccessDenied"] = "AccessDenied";
49
+ /** SHOULD be returned when a channel cannot be created or retrieved via the
50
+ * `getOrCreateChannel` method of the DesktopAgent (`fdc3`).
51
+ */
52
+ ChannelError["CreationFailed"] = "CreationFailed";
53
+ })(ChannelError = exports.ChannelError || (exports.ChannelError = {}));
38
54
  const buildPrivateChannelObject = (privateChannelClient) => {
39
55
  let clientDisconnected = false;
40
56
  const checkIfClientDisconnected = () => {
@@ -122,6 +138,22 @@ const connectPrivateChannel = async (channelId) => {
122
138
  }
123
139
  };
124
140
  exports.connectPrivateChannel = connectPrivateChannel;
141
+ const isContext = (context) => {
142
+ if (context && typeof context === 'object' && 'type' in context) {
143
+ const { type } = context;
144
+ return typeof type === 'string';
145
+ }
146
+ return false;
147
+ };
148
+ exports.isContext = isContext;
149
+ const isChannel = (channel) => {
150
+ if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
151
+ const { type, id } = channel;
152
+ return (typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private'));
153
+ }
154
+ return false;
155
+ };
156
+ exports.isChannel = isChannel;
125
157
  const getIntentResolution = async (interopModule, context, app, intent) => {
126
158
  // Generate an ID to make a session context group with. We will pass that ID to the Broker.
127
159
  // The broker will then setContext on that session context group later with our Intent Result,
@@ -138,31 +170,33 @@ const getIntentResolution = async (interopModule, context, app, intent) => {
138
170
  // Set up the getResult call.
139
171
  const getResult = async () => {
140
172
  let intentResult = await getResultPromise;
141
- if (!intentResult) {
173
+ if (!intentResult || typeof intentResult !== 'object') {
142
174
  throw new Error(ResultError.NoResultReturned);
143
175
  }
144
- if (intentResult instanceof Error) {
176
+ const { error } = intentResult;
177
+ if (error) {
145
178
  throw new Error(ResultError.IntentHandlerRejected);
146
179
  }
147
- if (typeof intentResult === 'object') {
180
+ if ((0, exports.isChannel)(intentResult)) {
148
181
  const { id, type } = intentResult;
149
- if (type && id && typeof id === 'string') {
150
- switch (type) {
151
- case 'private': {
152
- intentResult = await (0, exports.connectPrivateChannel)(id);
153
- break;
154
- }
155
- case 'app': {
156
- const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
157
- intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
158
- break;
159
- }
160
- default: {
161
- break;
162
- }
182
+ switch (type) {
183
+ case 'private': {
184
+ intentResult = await (0, exports.connectPrivateChannel)(id);
185
+ break;
186
+ }
187
+ case 'app': {
188
+ const sessionContextGroup = await interopModule.joinSessionContextGroup(id);
189
+ intentResult = (0, exports.buildAppChannelObject)(sessionContextGroup);
190
+ break;
191
+ }
192
+ default: {
193
+ break;
163
194
  }
164
195
  }
165
196
  }
197
+ else if (!(0, exports.isContext)(intentResult)) {
198
+ throw new Error(ResultError.NoResultReturned);
199
+ }
166
200
  return intentResult;
167
201
  };
168
202
  // Finally fire the intent.