@openfin/core 29.72.13 → 29.72.14

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.
@@ -17,8 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  /* global window, location */
18
18
  /* eslint-disable class-methods-use-this */
19
19
  const transport_errors_1 = require("../transport/transport-errors");
20
- class OpenFinEnvironment {
20
+ const browser_1 = require("./browser");
21
+ // Inherits the following BrowserEnvironment methods: getRtcPeer, getRandomId, getUrl, getWsConstructor.
22
+ class OpenFinEnvironment extends browser_1.BrowserEnvironment {
21
23
  constructor() {
24
+ super();
22
25
  _ready.set(this, void 0);
23
26
  this.writeToken = (path, token) => {
24
27
  throw new transport_errors_1.NotImplementedError('Not Implemented');
@@ -45,10 +48,6 @@ class OpenFinEnvironment {
45
48
  }
46
49
  return opts;
47
50
  };
48
- this.getRandomId = () => {
49
- const intArray = new Uint32Array(1);
50
- return window.crypto.getRandomValues(intArray)[0].toString(32);
51
- };
52
51
  this.getWebWindow = (identity) => {
53
52
  return fin.__internal_.getWebWindow(identity.name);
54
53
  };
@@ -61,9 +60,6 @@ class OpenFinEnvironment {
61
60
  this.raiseEvent = (eventName, eventArgs) => {
62
61
  this.raiseEventAsync(eventName, eventArgs);
63
62
  };
64
- this.getUrl = () => {
65
- return location.href;
66
- };
67
63
  this.raiseEventAsync = fin.__internal_.raiseEventAsync;
68
64
  delete fin.__internal_.raiseEventAsync;
69
65
  this.childViews = fin.__internal_.childViews;
@@ -79,9 +75,6 @@ class OpenFinEnvironment {
79
75
  ...((_b = (_a = fin.__internal_.initialOptions.experimental) === null || _a === void 0 ? void 0 : _a.defaultChannelOptions) !== null && _b !== void 0 ? _b : {})
80
76
  };
81
77
  }
82
- getRtcPeer() {
83
- return new RTCPeerConnection();
84
- }
85
78
  async getManagerConstructor() {
86
79
  const ManagerConstructor = (await Promise.resolve().then(() => require(
87
80
  /* webpackChunkName: 'layout' */
package/src/fdc3.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fdc3FromFin = void 0;
4
+ const fdc3_1 = require("./api/interop/fdc3/fdc3");
5
+ async function fdc3FromFin(fin, version) {
6
+ // @ts-expect-error
7
+ return fdc3_1.getFdc3(fin.wire, version);
8
+ }
9
+ exports.fdc3FromFin = fdc3FromFin;
package/src/mock.js CHANGED
@@ -79,6 +79,9 @@ class MockEnvironment {
79
79
  whenReady() {
80
80
  throw new Error(me_1.environmentUnsupportedMessage);
81
81
  }
82
+ getWsConstructor() {
83
+ throw new Error('Method not implemented.');
84
+ }
82
85
  }
83
86
  exports.fin = ((typeof window !== 'undefined' && ((_a = window) === null || _a === void 0 ? void 0 : _a.fin)) ||
84
87
  (() => {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
- import { Wire, WireConstructor, ExistingConnectConfig, InternalConnectConfig } from './wire';
3
+ import { Wire, WireConstructor, ExistingConnectConfig, InternalConnectConfig, RemoteConfig } from './wire';
4
4
  import { Environment } from '../environment/environment';
5
5
  import { RuntimeEvent } from '../api/events/base';
6
6
  import EventAggregator from '../api/events/eventAggregator';
@@ -25,8 +25,10 @@ declare class Transport<MeType extends EntityType = EntityType> extends EventEmi
25
25
  connectSync: () => void;
26
26
  getPort: () => string;
27
27
  shutdown(): Promise<void>;
28
- connect(config: InternalConnectConfig): Promise<string | void>;
29
- connectByPort(config: ExistingConnectConfig): Promise<string>;
28
+ connect(config: InternalConnectConfig | RemoteConfig): Promise<string | void>;
29
+ private connectRemote;
30
+ connectByPort(config: ExistingConnectConfig): Promise<void>;
31
+ private authorize;
30
32
  sendAction<T extends keyof ProtocolMap = string>(action: T, payload?: ProtocolMap[T]['request'], uncorrelated?: boolean): Promise<Message<{
31
33
  data: ProtocolMap[T]['response'];
32
34
  } & ProtocolMap[T]['specialResponse']>>;
@@ -59,6 +59,9 @@ class Transport extends events_1.EventEmitter {
59
59
  return wire.shutdown();
60
60
  }
61
61
  async connect(config) {
62
+ if (wire_1.isRemoteConfig(config)) {
63
+ return this.connectRemote(config);
64
+ }
62
65
  if (wire_1.isExistingConnectConfig(config)) {
63
66
  return this.connectByPort(config);
64
67
  }
@@ -68,11 +71,15 @@ class Transport extends events_1.EventEmitter {
68
71
  }
69
72
  return undefined;
70
73
  }
74
+ async connectRemote(config) {
75
+ await __classPrivateFieldGet(this, _wire).connect(config.address, this.environment.getWsConstructor());
76
+ return this.authorize(config);
77
+ }
71
78
  async connectByPort(config) {
72
79
  const { address, uuid } = config;
73
80
  const reqAuthPayload = { ...config, type: 'file-token' };
74
81
  const wire = __classPrivateFieldGet(this, _wire);
75
- await wire.connect(address);
82
+ await wire.connect(address, this.environment.getWsConstructor());
76
83
  const requestExtAuthRet = await this.sendAction('request-external-authorization', {
77
84
  uuid,
78
85
  type: 'file-token'
@@ -80,8 +87,10 @@ class Transport extends events_1.EventEmitter {
80
87
  if (requestExtAuthRet.action !== 'external-authorization-response') {
81
88
  throw new transport_errors_1.UnexpectedActionError(requestExtAuthRet.action);
82
89
  }
83
- const { token } = requestExtAuthRet.payload;
84
90
  await this.environment.writeToken(requestExtAuthRet.payload.file, requestExtAuthRet.payload.token);
91
+ return this.authorize(reqAuthPayload);
92
+ }
93
+ async authorize(reqAuthPayload) {
85
94
  const requestAuthRet = await this.sendAction('request-authorization', reqAuthPayload, true);
86
95
  if (requestAuthRet.action !== 'authorization-response') {
87
96
  throw new transport_errors_1.UnexpectedActionError(requestAuthRet.action);
@@ -89,9 +98,6 @@ class Transport extends events_1.EventEmitter {
89
98
  else if (requestAuthRet.payload.success !== true) {
90
99
  throw new transport_errors_1.RuntimeError(requestAuthRet.payload);
91
100
  }
92
- else {
93
- return token;
94
- }
95
101
  }
96
102
  sendAction(action, payload = {}, uncorrelated = false
97
103
  // specialResponse type is only used for 'requestAuthorization'
@@ -2,7 +2,7 @@
2
2
  /// <reference types="node" />
3
3
  import EventEmitter = NodeJS.EventEmitter;
4
4
  export declare type Wire = EventEmitter & {
5
- connect(address: string): Promise<any>;
5
+ connect(address: string, WsConstructor: typeof WebSocket): Promise<any>;
6
6
  connectSync(): any;
7
7
  send(data: any): Promise<any>;
8
8
  shutdown(): Promise<void>;
@@ -64,8 +64,12 @@ export declare type NewConnectConfig = ConfigWithUuid & ConfigWithRuntime;
64
64
  export declare type PortDiscoveryConfig = (ExternalConfig & ConfigWithRuntime) | NewConnectConfig;
65
65
  export declare type ConnectConfig = ExistingConnectConfig | NewConnectConfig | ExternalConfig;
66
66
  export declare type InternalConnectConfig = ExistingConnectConfig | NewConnectConfig;
67
+ export interface RemoteConfig extends ExistingConnectConfig {
68
+ token: string;
69
+ }
67
70
  export declare function isExternalConfig(config: ConnectConfig): config is ExternalConfig;
68
71
  export declare function isExistingConnectConfig(config: any): config is ExistingConnectConfig;
72
+ export declare function isRemoteConfig(config: any): config is RemoteConfig;
69
73
  export declare function isNewConnectConfig(config: any): config is NewConnectConfig;
70
74
  export declare function isPortDiscoveryConfig(config: any): config is PortDiscoveryConfig;
71
75
  export declare function isInternalConnectConfig(config: any): config is InternalConnectConfig;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isInternalConnectConfig = exports.isPortDiscoveryConfig = exports.isNewConnectConfig = exports.isExistingConnectConfig = exports.isExternalConfig = void 0;
3
+ exports.isInternalConnectConfig = exports.isPortDiscoveryConfig = exports.isNewConnectConfig = exports.isRemoteConfig = exports.isExistingConnectConfig = exports.isExternalConfig = void 0;
4
4
  function isExternalConfig(config) {
5
5
  if (typeof config.manifestUrl === 'string') {
6
6
  return true;
@@ -12,6 +12,10 @@ function isExistingConnectConfig(config) {
12
12
  return hasUuid(config) && typeof config.address === 'string';
13
13
  }
14
14
  exports.isExistingConnectConfig = isExistingConnectConfig;
15
+ function isRemoteConfig(config) {
16
+ return isExistingConnectConfig(config) && typeof config.token === 'string';
17
+ }
18
+ exports.isRemoteConfig = isRemoteConfig;
15
19
  function hasUuid(config) {
16
20
  return typeof config.uuid === 'string';
17
21
  }