@openfin/core 32.75.13 → 32.75.18

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": "32.75.13",
3
+ "version": "32.75.18",
4
4
  "license": "SEE LICENSE IN LICENSE.MD",
5
5
  "main": "./src/mock.js",
6
6
  "types": "./src/mock.d.ts",
@@ -19,22 +19,24 @@ const provider_1 = require("./provider");
19
19
  const base_1 = require("../../base");
20
20
  const connection_manager_1 = require("./connection-manager");
21
21
  const events_1 = require("events");
22
+ const lazy_1 = require("../../../util/lazy");
22
23
  class Channel extends base_1.EmitterBase {
23
24
  constructor(wire) {
24
25
  super(wire, 'channel');
25
26
  _Channel_connectionManager.set(this, void 0);
26
27
  _Channel_internalEmitter.set(this, new events_1.EventEmitter());
27
- _Channel_readyToConnect.set(this, void 0);
28
- __classPrivateFieldSet(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
29
28
  // OpenFin API has not been injected at construction time, *must* wait for API to be ready.
30
- __classPrivateFieldSet(this, _Channel_readyToConnect, this.wire.environment.whenReady().then(() => {
31
- this.on('disconnected', (eventPayload) => {
32
- client_1.default.handleProviderDisconnect(eventPayload);
33
- }).catch((e) => console.error('Error setting up a disconnected listener:', e));
34
- return this.on('connected', (...args) => {
35
- __classPrivateFieldGet(this, _Channel_internalEmitter, "f").emit('connected', ...args);
36
- });
37
- }), "f");
29
+ _Channel_readyToConnect.set(this, new lazy_1.AsyncRetryableLazy(async () => {
30
+ await Promise.all([
31
+ this.on('disconnected', (eventPayload) => {
32
+ client_1.default.handleProviderDisconnect(eventPayload);
33
+ }),
34
+ this.on('connected', (...args) => {
35
+ __classPrivateFieldGet(this, _Channel_internalEmitter, "f").emit('connected', ...args);
36
+ })
37
+ ]).catch(() => new Error('error setting up channel connection listeners'));
38
+ }));
39
+ __classPrivateFieldSet(this, _Channel_connectionManager, new connection_manager_1.ConnectionManager(wire), "f");
38
40
  }
39
41
  async channelExists(channelName) {
40
42
  const channels = await this.getAllChannels();
@@ -50,6 +52,9 @@ class Channel extends base_1.EmitterBase {
50
52
  await this.on('disconnected', listener);
51
53
  }
52
54
  async connect(channelName, options = {}) {
55
+ // Make sure we don't connect before listeners are set up
56
+ // This also errors if we're not in OpenFin, ensuring we don't run unnecessary code
57
+ await __classPrivateFieldGet(this, _Channel_readyToConnect, "f").getValue();
53
58
  if (!channelName || typeof channelName !== 'string') {
54
59
  throw new Error('Please provide a channelName string to connect to a channel.');
55
60
  }
@@ -59,8 +64,6 @@ class Channel extends base_1.EmitterBase {
59
64
  const channelExists = await this.channelExists(channelName);
60
65
  if (!channelExists) {
61
66
  console.warn(`Channel not found for channelName: ${channelName}, waiting for channel connection.`);
62
- // Safeguard to ensure 'connected' listener was already added if we need to wait.
63
- await __classPrivateFieldGet(this, _Channel_readyToConnect, "f");
64
67
  await new Promise((resolve) => {
65
68
  const connectedListener = (payload) => {
66
69
  if (channelName === payload.channelName) {
@@ -0,0 +1,27 @@
1
+ import { Environment } from './environment';
2
+ import type * as OpenFin from '../OpenFin';
3
+ import { NewConnectConfig } from '../transport/wire';
4
+ import { EntityType } from '../OpenFin';
5
+ export declare class MockEnvironment implements Environment {
6
+ getDefaultChannelOptions(): {
7
+ create: OpenFin.ChannelCreateOptions;
8
+ connect: OpenFin.ChannelConnectOptions;
9
+ };
10
+ getRtcPeer(): RTCPeerConnection;
11
+ initLayout(): Promise<never>;
12
+ initPlatform(): Promise<never>;
13
+ observeBounds(): never;
14
+ writeToken(path: string, token: string): Promise<string>;
15
+ retrievePort(config: NewConnectConfig): Promise<number>;
16
+ getNextMessageId(): string;
17
+ getRandomId(): string;
18
+ createChildContent(options: any): Promise<any>;
19
+ getWebWindow(identity: OpenFin.Identity): globalThis.Window;
20
+ getCurrentEntityIdentity(): OpenFin.EntityInfo;
21
+ getCurrentEntityType(): EntityType;
22
+ raiseEvent(eventName: string, eventArgs: any): void;
23
+ getUrl(): string;
24
+ whenReady(): Promise<void>;
25
+ childViews: boolean;
26
+ getWsConstructor(): any;
27
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockEnvironment = void 0;
4
+ const me_1 = require("../api/me");
5
+ class MockEnvironment {
6
+ constructor() {
7
+ this.childViews = true;
8
+ }
9
+ getDefaultChannelOptions() {
10
+ throw new Error(me_1.environmentUnsupportedMessage);
11
+ }
12
+ getRtcPeer() {
13
+ throw new Error(me_1.environmentUnsupportedMessage);
14
+ }
15
+ initLayout() {
16
+ throw new Error(me_1.environmentUnsupportedMessage);
17
+ }
18
+ initPlatform() {
19
+ throw new Error(me_1.environmentUnsupportedMessage);
20
+ }
21
+ observeBounds() {
22
+ throw new Error(me_1.environmentUnsupportedMessage);
23
+ }
24
+ writeToken(path, token) {
25
+ throw new Error(me_1.environmentUnsupportedMessage);
26
+ }
27
+ retrievePort(config) {
28
+ throw new Error(me_1.environmentUnsupportedMessage);
29
+ }
30
+ getNextMessageId() {
31
+ throw new Error(me_1.environmentUnsupportedMessage);
32
+ }
33
+ getRandomId() {
34
+ throw new Error(me_1.environmentUnsupportedMessage);
35
+ }
36
+ createChildContent(options) {
37
+ throw new Error(me_1.environmentUnsupportedMessage);
38
+ }
39
+ getWebWindow(identity) {
40
+ throw new Error(me_1.environmentUnsupportedMessage);
41
+ }
42
+ getCurrentEntityIdentity() {
43
+ throw new Error(me_1.environmentUnsupportedMessage);
44
+ }
45
+ getCurrentEntityType() {
46
+ return 'unknown';
47
+ }
48
+ raiseEvent(eventName, eventArgs) {
49
+ throw new Error(me_1.environmentUnsupportedMessage);
50
+ }
51
+ getUrl() {
52
+ throw new Error(me_1.environmentUnsupportedMessage);
53
+ }
54
+ whenReady() {
55
+ throw new Error(me_1.environmentUnsupportedMessage);
56
+ }
57
+ getWsConstructor() {
58
+ throw new Error('Method not implemented.');
59
+ }
60
+ }
61
+ exports.MockEnvironment = MockEnvironment;
package/src/mock.js CHANGED
@@ -1,97 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fin = void 0;
4
- /* eslint-disable import/prefer-default-export */
5
- /* eslint-disable spaced-comment */
6
- /* eslint-disable @typescript-eslint/triple-slash-reference */
7
- /* eslint-disable @typescript-eslint/explicit-function-return-type */
8
- /* eslint-disable class-methods-use-this */
9
- const events_1 = require("events");
10
4
  const OpenFin = require("./OpenFin");
11
5
  const fin_1 = require("./api/fin");
12
6
  const transport_1 = require("./transport/transport");
13
- const me_1 = require("./api/me");
14
- class MockWire extends events_1.EventEmitter {
15
- connect(address) {
16
- throw new Error('You are not running in OpenFin.');
17
- }
18
- connectSync() {
19
- throw new Error('You are not running in OpenFin.');
20
- }
21
- send(data) {
22
- throw new Error('You are not running in OpenFin.');
23
- }
24
- shutdown() {
25
- throw new Error('You are not running in OpenFin.');
26
- }
27
- getPort() {
28
- throw new Error('This transport has no port');
29
- }
30
- // eslint-disable-next-line no-useless-constructor
31
- constructor() {
32
- super();
33
- }
34
- }
35
- class MockEnvironment {
36
- constructor() {
37
- this.childViews = true;
38
- }
39
- getDefaultChannelOptions() {
40
- throw new Error(me_1.environmentUnsupportedMessage);
41
- }
42
- getRtcPeer() {
43
- throw new Error(me_1.environmentUnsupportedMessage);
44
- }
45
- initLayout() {
46
- throw new Error(me_1.environmentUnsupportedMessage);
47
- }
48
- initPlatform() {
49
- throw new Error(me_1.environmentUnsupportedMessage);
50
- }
51
- observeBounds() {
52
- throw new Error(me_1.environmentUnsupportedMessage);
53
- }
54
- writeToken(path, token) {
55
- throw new Error(me_1.environmentUnsupportedMessage);
56
- }
57
- retrievePort(config) {
58
- throw new Error(me_1.environmentUnsupportedMessage);
59
- }
60
- getNextMessageId() {
61
- throw new Error(me_1.environmentUnsupportedMessage);
62
- }
63
- getRandomId() {
64
- throw new Error(me_1.environmentUnsupportedMessage);
65
- }
66
- createChildContent(options) {
67
- throw new Error(me_1.environmentUnsupportedMessage);
68
- }
69
- getWebWindow(identity) {
70
- throw new Error(me_1.environmentUnsupportedMessage);
71
- }
72
- getCurrentEntityIdentity() {
73
- throw new Error(me_1.environmentUnsupportedMessage);
74
- }
75
- getCurrentEntityType() {
76
- return 'unknown';
77
- }
78
- raiseEvent(eventName, eventArgs) {
79
- throw new Error(me_1.environmentUnsupportedMessage);
80
- }
81
- getUrl() {
82
- throw new Error(me_1.environmentUnsupportedMessage);
83
- }
84
- whenReady() {
85
- throw new Error(me_1.environmentUnsupportedMessage);
86
- }
87
- getWsConstructor() {
88
- throw new Error('Method not implemented.');
89
- }
90
- }
7
+ const mockEnvironment_1 = require("./environment/mockEnvironment");
8
+ const mockWire_1 = require("./transport/mockWire");
91
9
  exports.fin = ((typeof window !== 'undefined' && (window === null || window === void 0 ? void 0 : window.fin)) ||
92
10
  (() => {
93
- const environment = new MockEnvironment();
94
- const transport = new transport_1.Transport(MockWire, environment, {
11
+ const environment = new mockEnvironment_1.MockEnvironment();
12
+ const transport = new transport_1.Transport(mockWire_1.MockWire, environment, {
95
13
  uuid: '',
96
14
  name: ''
97
15
  });
@@ -82,10 +82,8 @@ export interface ProtocolMap extends ProtocolMapBase {
82
82
  };
83
83
  response: OpenFin.NativeWindowIntegrationProviderAuthorization;
84
84
  };
85
- 'get-permissions': {
86
- request: void;
87
- response: any;
88
- };
85
+ 'get-permissions': GetterCall<any>;
86
+ 'get-all-channels': GetterCall<OpenFin.ProviderIdentity[]>;
89
87
  'set-file-download-location': {
90
88
  request: OpenFin.ApplicationIdentity & {
91
89
  downloadLocation: string;
@@ -160,10 +158,7 @@ export interface ProtocolMap extends ProtocolMapBase {
160
158
  };
161
159
  response: void;
162
160
  };
163
- 'system-get-printers': {
164
- request: void;
165
- response: OpenFin.PrinterInfo[];
166
- };
161
+ 'system-get-printers': GetterCall<OpenFin.PrinterInfo[]>;
167
162
  'system-register-shutdown-handler': VoidCall;
168
163
  }
169
164
  type ApiCall<Request, Response> = {
@@ -171,6 +166,7 @@ type ApiCall<Request, Response> = {
171
166
  response: Response;
172
167
  };
173
168
  type VoidCall = ApiCall<void, void>;
169
+ type GetterCall<T> = ApiCall<void, T>;
174
170
  type IdentityCall<AdditionalPayload = {}, Response = void> = ApiCall<AdditionalPayload & OpenFin.Identity, Response>;
175
171
  interface ProtocolMapBase {
176
172
  [action: string]: {
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { Wire } from './wire';
4
+ export declare class MockWire extends EventEmitter implements Wire {
5
+ connect(address: string): Promise<any>;
6
+ connectSync(): any;
7
+ send(data: any): Promise<any>;
8
+ shutdown(): Promise<void>;
9
+ getPort(): string;
10
+ constructor();
11
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockWire = void 0;
4
+ const events_1 = require("events");
5
+ class MockWire extends events_1.EventEmitter {
6
+ connect(address) {
7
+ throw new Error('You are not running in OpenFin.');
8
+ }
9
+ connectSync() {
10
+ throw new Error('You are not running in OpenFin.');
11
+ }
12
+ send(data) {
13
+ throw new Error('You are not running in OpenFin.');
14
+ }
15
+ shutdown() {
16
+ throw new Error('You are not running in OpenFin.');
17
+ }
18
+ getPort() {
19
+ throw new Error('This transport has no port');
20
+ }
21
+ // eslint-disable-next-line no-useless-constructor
22
+ constructor() {
23
+ super();
24
+ }
25
+ }
26
+ exports.MockWire = MockWire;
@@ -14,3 +14,21 @@ export declare class Lazy<T> {
14
14
  */
15
15
  getValue(): T;
16
16
  }
17
+ /**
18
+ * Handy class for managing asynchronous dependencies of classes.
19
+ *
20
+ * Will call asynchronous producer only after `getValue` is called. If the
21
+ * deferred code errors, we can try it again by re-calling `getValue` after
22
+ * the promise rejects.
23
+ */
24
+ export declare class AsyncRetryableLazy<T> {
25
+ private producerFn;
26
+ constructor(producerFn: () => Promise<T>);
27
+ private promise?;
28
+ /**
29
+ * Lazily get the value returned by the async producer.
30
+ *
31
+ * @returns The value returned from the producer function
32
+ */
33
+ getValue(): Promise<T>;
34
+ }
package/src/util/lazy.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Lazy = void 0;
3
+ exports.AsyncRetryableLazy = exports.Lazy = void 0;
4
4
  /**
5
5
  * Handy class for managing asynchronous dependencies of classes.
6
6
  *
@@ -24,3 +24,31 @@ class Lazy {
24
24
  }
25
25
  }
26
26
  exports.Lazy = Lazy;
27
+ /**
28
+ * Handy class for managing asynchronous dependencies of classes.
29
+ *
30
+ * Will call asynchronous producer only after `getValue` is called. If the
31
+ * deferred code errors, we can try it again by re-calling `getValue` after
32
+ * the promise rejects.
33
+ */
34
+ class AsyncRetryableLazy {
35
+ // eslint-disable-next-line
36
+ constructor(producerFn) {
37
+ this.producerFn = producerFn;
38
+ }
39
+ /**
40
+ * Lazily get the value returned by the async producer.
41
+ *
42
+ * @returns The value returned from the producer function
43
+ */
44
+ async getValue() {
45
+ if (!this.promise) {
46
+ this.promise = this.producerFn().catch((e) => {
47
+ delete this.promise;
48
+ throw e;
49
+ });
50
+ }
51
+ return this.promise;
52
+ }
53
+ }
54
+ exports.AsyncRetryableLazy = AsyncRetryableLazy;