@openfin/core 25.68.30 → 25.70.2

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.
Files changed (199) hide show
  1. package/OpenFin.d.ts +30 -826
  2. package/README.md +12 -2
  3. package/package.json +1 -1
  4. package/src/api/application/Factory.d.ts +145 -145
  5. package/src/api/application/Factory.js +229 -229
  6. package/src/api/application/Instance.d.ts +301 -302
  7. package/src/api/application/Instance.js +412 -412
  8. package/src/api/application/index.d.ts +3 -3
  9. package/src/api/application/index.js +15 -15
  10. package/src/api/base.d.ts +43 -43
  11. package/src/api/base.js +177 -177
  12. package/src/api/clipboard/index.d.ts +69 -69
  13. package/src/api/clipboard/index.js +88 -88
  14. package/src/api/events/application.d.ts +69 -0
  15. package/src/api/events/application.js +2 -0
  16. package/src/api/events/base.d.ts +17 -0
  17. package/src/api/events/base.js +2 -0
  18. package/src/api/events/channel.d.ts +10 -11
  19. package/src/api/events/channel.js +2 -2
  20. package/src/api/events/emitterMap.d.ts +11 -11
  21. package/src/api/events/emitterMap.js +35 -35
  22. package/src/api/events/eventAggregator.d.ts +5 -5
  23. package/src/api/events/eventAggregator.js +43 -43
  24. package/src/api/events/externalApplication.d.ts +5 -0
  25. package/src/api/events/externalApplication.js +2 -0
  26. package/src/api/events/frame.d.ts +9 -0
  27. package/src/api/events/frame.js +2 -0
  28. package/src/api/events/globalHotkey.d.ts +10 -0
  29. package/src/api/events/globalHotkey.js +2 -0
  30. package/src/api/events/platform.d.ts +18 -0
  31. package/src/api/events/platform.js +2 -0
  32. package/src/api/events/system.d.ts +22 -0
  33. package/src/api/events/system.js +2 -0
  34. package/src/api/events/view.d.ts +56 -0
  35. package/src/api/events/view.js +2 -0
  36. package/src/api/events/webcontents.d.ts +48 -0
  37. package/src/api/events/webcontents.js +2 -0
  38. package/src/api/events/window.d.ts +176 -0
  39. package/src/api/events/window.js +2 -0
  40. package/src/api/external-application/Factory.d.ts +26 -26
  41. package/src/api/external-application/Factory.js +40 -40
  42. package/src/api/external-application/Instance.d.ts +101 -102
  43. package/src/api/external-application/Instance.js +109 -109
  44. package/src/api/external-application/index.d.ts +3 -3
  45. package/src/api/external-application/index.js +15 -15
  46. package/src/api/fin.d.ts +49 -49
  47. package/src/api/fin.js +43 -43
  48. package/src/api/frame/Factory.d.ts +36 -36
  49. package/src/api/frame/Factory.js +69 -69
  50. package/src/api/frame/Instance.d.ts +121 -121
  51. package/src/api/frame/Instance.js +130 -130
  52. package/src/api/frame/index.d.ts +3 -3
  53. package/src/api/frame/index.js +15 -15
  54. package/src/api/global-hotkey/index.d.ts +38 -38
  55. package/src/api/global-hotkey/index.js +58 -58
  56. package/src/api/interappbus/channel/channel.d.ts +26 -26
  57. package/src/api/interappbus/channel/channel.js +77 -77
  58. package/src/api/interappbus/channel/channels-docs.d.ts +318 -318
  59. package/src/api/interappbus/channel/channels-docs.js +376 -376
  60. package/src/api/interappbus/channel/client.d.ts +22 -22
  61. package/src/api/interappbus/channel/client.js +84 -84
  62. package/src/api/interappbus/channel/connection-manager.d.ts +28 -28
  63. package/src/api/interappbus/channel/connection-manager.js +244 -244
  64. package/src/api/interappbus/channel/index.d.ts +22 -23
  65. package/src/api/interappbus/channel/index.js +121 -121
  66. package/src/api/interappbus/channel/protocols/classic/message-receiver.d.ts +13 -13
  67. package/src/api/interappbus/channel/protocols/classic/message-receiver.js +73 -73
  68. package/src/api/interappbus/channel/protocols/classic/strategy.d.ts +22 -22
  69. package/src/api/interappbus/channel/protocols/classic/strategy.js +84 -84
  70. package/src/api/interappbus/channel/protocols/combined/strategy.d.ts +20 -20
  71. package/src/api/interappbus/channel/protocols/combined/strategy.js +58 -58
  72. package/src/api/interappbus/channel/protocols/index.d.ts +44 -44
  73. package/src/api/interappbus/channel/protocols/index.js +2 -2
  74. package/src/api/interappbus/channel/protocols/protocol-manager.d.ts +10 -10
  75. package/src/api/interappbus/channel/protocols/protocol-manager.js +43 -43
  76. package/src/api/interappbus/channel/protocols/rtc/endpoint.d.ts +23 -23
  77. package/src/api/interappbus/channel/protocols/rtc/endpoint.js +135 -135
  78. package/src/api/interappbus/channel/protocols/rtc/ice-manager.d.ts +30 -30
  79. package/src/api/interappbus/channel/protocols/rtc/ice-manager.js +131 -131
  80. package/src/api/interappbus/channel/protocols/rtc/strategy.d.ts +22 -22
  81. package/src/api/interappbus/channel/protocols/rtc/strategy.js +87 -87
  82. package/src/api/interappbus/channel/protocols/strategy-types.d.ts +13 -13
  83. package/src/api/interappbus/channel/protocols/strategy-types.js +2 -2
  84. package/src/api/interappbus/channel/protocols/strategy.d.ts +15 -15
  85. package/src/api/interappbus/channel/protocols/strategy.js +2 -2
  86. package/src/api/interappbus/channel/provider.d.ts +31 -31
  87. package/src/api/interappbus/channel/provider.js +160 -160
  88. package/src/api/interappbus/index.d.ts +85 -86
  89. package/src/api/interappbus/index.js +175 -175
  90. package/src/api/interop/Factory.d.ts +37 -37
  91. package/src/api/interop/Factory.js +54 -54
  92. package/src/api/interop/InteropBroker.d.ts +363 -363
  93. package/src/api/interop/InteropBroker.js +914 -914
  94. package/src/api/interop/InteropClient.d.ts +268 -268
  95. package/src/api/interop/InteropClient.js +450 -450
  96. package/src/api/interop/SessionContextGroupBroker.d.ts +26 -26
  97. package/src/api/interop/SessionContextGroupBroker.js +107 -107
  98. package/src/api/interop/SessionContextGroupClient.d.ts +20 -20
  99. package/src/api/interop/SessionContextGroupClient.js +85 -85
  100. package/src/api/interop/fdc3/fdc3-1.2.d.ts +187 -187
  101. package/src/api/interop/fdc3/fdc3-1.2.js +385 -385
  102. package/src/api/interop/fdc3/fdc3.js +17 -17
  103. package/src/api/interop/fdc3/utils.d.ts +6 -6
  104. package/src/api/interop/fdc3/utils.js +17 -17
  105. package/src/api/interop/index.d.ts +4 -4
  106. package/src/api/interop/index.js +16 -16
  107. package/src/api/interop/utils.d.ts +11 -11
  108. package/src/api/interop/utils.js +36 -36
  109. package/src/api/me.d.ts +38 -35
  110. package/src/api/me.js +128 -60
  111. package/src/api/platform/Factory.d.ts +109 -109
  112. package/src/api/platform/Factory.js +188 -188
  113. package/src/api/platform/Instance.d.ts +122 -122
  114. package/src/api/platform/Instance.js +298 -298
  115. package/src/api/platform/common-utils.d.ts +6 -6
  116. package/src/api/platform/common-utils.js +16 -16
  117. package/src/api/platform/index.d.ts +3 -3
  118. package/src/api/platform/index.js +15 -15
  119. package/src/api/platform/layout/Factory.d.ts +108 -108
  120. package/src/api/platform/layout/Factory.js +189 -189
  121. package/src/api/platform/layout/Instance.d.ts +49 -49
  122. package/src/api/platform/layout/Instance.js +99 -99
  123. package/src/api/platform/layout/index.d.ts +2 -2
  124. package/src/api/platform/layout/index.js +14 -14
  125. package/src/api/platform/layout/shapes.d.ts +11 -0
  126. package/src/api/{window → platform/layout}/shapes.js +2 -2
  127. package/src/api/snapshot-source/Factory.d.ts +36 -36
  128. package/src/api/snapshot-source/Factory.js +65 -65
  129. package/src/api/snapshot-source/Instance.d.ts +30 -30
  130. package/src/api/snapshot-source/Instance.js +134 -134
  131. package/src/api/snapshot-source/index.d.ts +3 -3
  132. package/src/api/snapshot-source/index.js +15 -15
  133. package/src/api/snapshot-source/utils.d.ts +1 -1
  134. package/src/api/snapshot-source/utils.js +5 -5
  135. package/src/api/system/index.d.ts +960 -961
  136. package/src/api/system/index.js +1241 -1241
  137. package/src/api/view/Factory.d.ts +49 -49
  138. package/src/api/view/Factory.js +103 -103
  139. package/src/api/view/Instance.d.ts +387 -380
  140. package/src/api/view/Instance.js +422 -415
  141. package/src/api/view/index.d.ts +3 -3
  142. package/src/api/view/index.js +15 -15
  143. package/src/api/webcontents/main.d.ts +36 -36
  144. package/src/api/webcontents/main.js +82 -82
  145. package/src/api/window/Factory.d.ts +44 -44
  146. package/src/api/window/Factory.js +91 -91
  147. package/src/api/window/Instance.d.ts +972 -966
  148. package/src/api/window/Instance.js +1209 -1202
  149. package/src/api/window/index.d.ts +3 -5
  150. package/src/api/window/index.js +15 -17
  151. package/src/environment/environment.d.ts +28 -25
  152. package/src/environment/environment.js +4 -4
  153. package/src/environment/node-env.d.ts +25 -26
  154. package/src/environment/node-env.js +64 -64
  155. package/src/environment/openfin-env.d.ts +29 -30
  156. package/src/environment/openfin-env.js +107 -107
  157. package/src/mock.d.ts +3 -3
  158. package/src/mock.js +91 -90
  159. package/src/shapes/ERROR_BOX_TYPES.d.ts +1 -0
  160. package/src/shapes/ERROR_BOX_TYPES.js +2 -0
  161. package/src/shapes/WebOptions.d.ts +12 -0
  162. package/src/shapes/WebOptions.js +2 -0
  163. package/src/shapes/WindowOptions.d.ts +42 -0
  164. package/src/shapes/WindowOptions.js +2 -0
  165. package/src/shapes/protocol.d.ts +178 -0
  166. package/src/shapes/protocol.js +2 -0
  167. package/src/transport/fin_store.d.ts +4 -4
  168. package/src/transport/fin_store.js +16 -16
  169. package/src/transport/transport-errors.d.ts +18 -18
  170. package/src/transport/transport-errors.js +37 -37
  171. package/src/transport/transport.d.ts +56 -43
  172. package/src/transport/transport.js +181 -181
  173. package/src/transport/wire.d.ts +71 -11
  174. package/src/transport/wire.js +32 -32
  175. package/src/util/asyncFilter.d.ts +1 -1
  176. package/src/util/asyncFilter.js +7 -7
  177. package/src/util/errors.d.ts +9 -5
  178. package/src/util/errors.js +11 -11
  179. package/src/util/exhaustive.d.ts +1 -1
  180. package/src/util/exhaustive.js +7 -7
  181. package/src/util/http.d.ts +11 -11
  182. package/src/util/http.js +83 -83
  183. package/src/util/normalize-config.d.ts +3 -5
  184. package/src/util/normalize-config.js +47 -47
  185. package/src/util/promises.d.ts +5 -5
  186. package/src/util/promises.js +27 -27
  187. package/src/util/ref-counter.d.ts +7 -7
  188. package/src/util/ref-counter.js +51 -51
  189. package/src/util/runtimeVersioning.d.ts +3 -3
  190. package/src/util/runtimeVersioning.js +25 -25
  191. package/src/util/utilTypes.d.ts +8 -8
  192. package/src/util/utilTypes.js +2 -2
  193. package/src/util/validate.d.ts +3 -3
  194. package/src/util/validate.js +11 -11
  195. package/docs.README(OLD).md +0 -82
  196. package/resources/win/OpenFinRVM.exe +0 -0
  197. package/src/api/window/bounds-changed.d.ts +0 -10
  198. package/src/api/window/bounds-changed.js +0 -6
  199. package/src/api/window/shapes.d.ts +0 -13
@@ -1,43 +1,56 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
3
- import EventAggregator from '../api/events/eventAggregator';
4
- import { EntityTypeHelpers } from '../api/me';
5
- import { Environment } from '../environment/environment';
6
- import EntityType = OpenFin.EntityType;
7
- import Message = OpenFin.Message;
8
- import Payload = OpenFin.Payload;
9
- import ProtocolMap = OpenFin.ProtocolMap;
10
- import MessageHandler = OpenFin.MessageHandler;
11
- import Wire = OpenFin.Wire;
12
- import WireConstructor = OpenFin.WireConstructor;
13
- import InternalConnectConfig = OpenFin.InternalConnectConfig;
14
- import ExistingConnectConfig = OpenFin.ExistingConnectConfig;
15
- declare class Transport<MeType extends EntityType = EntityType> extends EventEmitter {
16
- #private;
17
- protected wireListeners: Map<number, {
18
- resolve: Function;
19
- reject: Function;
20
- }>;
21
- protected uncorrelatedListener: Function;
22
- me: OpenFin.EntityInfo & EntityTypeHelpers<MeType>;
23
- environment: Environment;
24
- topicRefMap: Map<string, number>;
25
- sendRaw: Wire['send'];
26
- eventAggregator: EventAggregator;
27
- protected messageHandlers: MessageHandler[];
28
- constructor(WireType: WireConstructor, environment: Environment, config: OpenFin.Identity);
29
- connectSync: () => void;
30
- getPort: () => string;
31
- shutdown(): Promise<void>;
32
- connect(config: InternalConnectConfig): Promise<string | void>;
33
- connectByPort(config: ExistingConnectConfig): Promise<string>;
34
- sendAction<T extends keyof ProtocolMap = string>(action: T, payload?: ProtocolMap[T]['request'], uncorrelated?: boolean): Promise<Message<{
35
- data: ProtocolMap[T]['response'];
36
- } & ProtocolMap[T]['specialResponse']>>;
37
- ferryAction(origData: any): Promise<Message<any>>;
38
- registerMessageHandler(handler: MessageHandler): void;
39
- protected addWireListener(id: number, resolve: Function, reject: Function, uncorrelated: boolean): void;
40
- protected onmessage(data: Message<Payload>): void;
41
- protected handleMessage(data: Message<Payload>): boolean;
42
- }
43
- export default Transport;
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { Wire, WireConstructor, ExistingConnectConfig, InternalConnectConfig } from './wire';
4
+ import { Environment } from '../environment/environment';
5
+ import { RuntimeEvent } from '../api/events/base';
6
+ import EventAggregator from '../api/events/eventAggregator';
7
+ import { EntityTypeHelpers } from '../api/me';
8
+ import { ProtocolMap } from '../shapes/protocol';
9
+ import EntityType = OpenFin.EntityType;
10
+ export declare type MessageHandler = (data: any) => boolean;
11
+ declare class Transport<MeType extends EntityType = EntityType> extends EventEmitter {
12
+ #private;
13
+ protected wireListeners: Map<number, {
14
+ resolve: Function;
15
+ reject: Function;
16
+ }>;
17
+ protected uncorrelatedListener: Function;
18
+ me: OpenFin.EntityInfo & EntityTypeHelpers<MeType>;
19
+ environment: Environment;
20
+ topicRefMap: Map<string, number>;
21
+ sendRaw: Wire['send'];
22
+ eventAggregator: EventAggregator;
23
+ protected messageHandlers: MessageHandler[];
24
+ constructor(WireType: WireConstructor, environment: Environment, config: OpenFin.Identity);
25
+ connectSync: () => void;
26
+ getPort: () => string;
27
+ shutdown(): Promise<void>;
28
+ connect(config: InternalConnectConfig): Promise<string | void>;
29
+ connectByPort(config: ExistingConnectConfig): Promise<string>;
30
+ sendAction<T extends keyof ProtocolMap = string>(action: T, payload?: ProtocolMap[T]['request'], uncorrelated?: boolean): Promise<Message<{
31
+ data: ProtocolMap[T]['response'];
32
+ } & ProtocolMap[T]['specialResponse']>>;
33
+ ferryAction(origData: any): Promise<Message<any>>;
34
+ registerMessageHandler(handler: MessageHandler): void;
35
+ protected addWireListener(id: number, resolve: Function, reject: Function, uncorrelated: boolean): void;
36
+ protected onmessage(data: Message<Payload>): void;
37
+ protected handleMessage(data: Message<Payload>): boolean;
38
+ }
39
+ export default Transport;
40
+ export interface Message<T> {
41
+ action: string;
42
+ payload: T;
43
+ correlationId?: number;
44
+ }
45
+ export interface EventMessage extends Message<RuntimeEvent> {
46
+ action: 'process-desktop-event';
47
+ payload: RuntimeEvent;
48
+ }
49
+ export interface Payload {
50
+ success: boolean;
51
+ data: any;
52
+ }
53
+ export interface AuthorizationPayload {
54
+ token: string;
55
+ file: string;
56
+ }
@@ -1,181 +1,181 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
- if (!privateMap.has(receiver)) {
4
- throw new TypeError("attempted to set private field on non-instance");
5
- }
6
- privateMap.set(receiver, value);
7
- return value;
8
- };
9
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
- if (!privateMap.has(receiver)) {
11
- throw new TypeError("attempted to get private field on non-instance");
12
- }
13
- return privateMap.get(receiver);
14
- };
15
- var _wire;
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const events_1 = require("events");
18
- const wire_1 = require("./wire");
19
- const transport_errors_1 = require("./transport-errors");
20
- const eventAggregator_1 = require("../api/events/eventAggregator");
21
- const me_1 = require("../api/me");
22
- class Transport extends events_1.EventEmitter {
23
- constructor(WireType, environment, config) {
24
- super();
25
- this.wireListeners = new Map();
26
- this.topicRefMap = new Map();
27
- this.eventAggregator = new eventAggregator_1.default();
28
- this.messageHandlers = [this.eventAggregator.dispatchEvent];
29
- _wire.set(this, void 0);
30
- this.connectSync = () => {
31
- const wire = __classPrivateFieldGet(this, _wire);
32
- wire.connectSync();
33
- };
34
- // This function is only used in our tests.
35
- this.getPort = () => {
36
- if (this.environment.constructor.name !== 'NodeEnvironment') {
37
- throw new transport_errors_1.NotImplementedError('Not Implemented');
38
- }
39
- const wire = __classPrivateFieldGet(this, _wire);
40
- return wire.wire.url.split(':').slice(-1)[0];
41
- };
42
- __classPrivateFieldSet(this, _wire, new WireType(this.onmessage.bind(this)));
43
- this.environment = environment;
44
- this.sendRaw = __classPrivateFieldGet(this, _wire).send.bind(__classPrivateFieldGet(this, _wire));
45
- this.registerMessageHandler(this.handleMessage.bind(this));
46
- __classPrivateFieldGet(this, _wire).on('disconnected', () => {
47
- for (const [, { reject }] of this.wireListeners) {
48
- reject('Remote connection has closed');
49
- }
50
- this.wireListeners.clear();
51
- this.emit('disconnected');
52
- });
53
- const { uuid, name } = config;
54
- const entityType = this.environment.getCurrentEntityType();
55
- this.me = me_1.getBaseMe(entityType, uuid, name);
56
- }
57
- shutdown() {
58
- const wire = __classPrivateFieldGet(this, _wire);
59
- return wire.shutdown();
60
- }
61
- async connect(config) {
62
- if (wire_1.isExistingConnectConfig(config)) {
63
- return this.connectByPort(config);
64
- }
65
- if (wire_1.isNewConnectConfig(config)) {
66
- const port = await this.environment.retrievePort(config);
67
- return this.connectByPort({ ...config, address: `ws://localhost:${port}` });
68
- }
69
- return undefined;
70
- }
71
- async connectByPort(config) {
72
- const { address, uuid } = config;
73
- const reqAuthPayload = { ...config, type: 'file-token' };
74
- const wire = __classPrivateFieldGet(this, _wire);
75
- await wire.connect(address);
76
- const requestExtAuthRet = await this.sendAction('request-external-authorization', {
77
- uuid,
78
- type: 'file-token'
79
- }, true);
80
- if (requestExtAuthRet.action !== 'external-authorization-response') {
81
- throw new transport_errors_1.UnexpectedActionError(requestExtAuthRet.action);
82
- }
83
- const { token } = requestExtAuthRet.payload;
84
- await this.environment.writeToken(requestExtAuthRet.payload.file, requestExtAuthRet.payload.token);
85
- const requestAuthRet = await this.sendAction('request-authorization', reqAuthPayload, true);
86
- if (requestAuthRet.action !== 'authorization-response') {
87
- throw new transport_errors_1.UnexpectedActionError(requestAuthRet.action);
88
- }
89
- else if (requestAuthRet.payload.success !== true) {
90
- throw new transport_errors_1.RuntimeError(requestAuthRet.payload);
91
- }
92
- else {
93
- return token;
94
- }
95
- }
96
- sendAction(action, payload = {}, uncorrelated = false
97
- // specialResponse type is only used for 'requestAuthorization'
98
- ) {
99
- return new Promise((resolve, reject) => {
100
- const id = this.environment.getNextMessageId();
101
- const msg = {
102
- action,
103
- payload,
104
- messageId: id
105
- };
106
- const wire = __classPrivateFieldGet(this, _wire);
107
- this.addWireListener(id, resolve, reject, uncorrelated);
108
- return wire.send(msg).catch(reject);
109
- });
110
- }
111
- ferryAction(origData) {
112
- return new Promise((resolve, reject) => {
113
- const id = this.environment.getNextMessageId();
114
- origData.messageId = id;
115
- const resolver = (data) => {
116
- resolve(data.payload);
117
- };
118
- const wire = __classPrivateFieldGet(this, _wire);
119
- return wire
120
- .send(origData)
121
- .then(() => this.addWireListener(id, resolver, reject, false))
122
- .catch(reject);
123
- });
124
- }
125
- registerMessageHandler(handler) {
126
- this.messageHandlers.push(handler);
127
- }
128
- addWireListener(id, resolve, reject, uncorrelated) {
129
- if (uncorrelated) {
130
- this.uncorrelatedListener = resolve;
131
- }
132
- else if (this.wireListeners.has(id)) {
133
- reject(new transport_errors_1.DuplicateCorrelationError(String(id)));
134
- }
135
- else {
136
- this.wireListeners.set(id, { resolve, reject });
137
- }
138
- // Timeout and reject()?
139
- }
140
- // This method executes message handlers until the _one_ that handles the message (returns truthy) has run
141
- onmessage(data) {
142
- for (const h of this.messageHandlers) {
143
- h.call(null, data);
144
- }
145
- }
146
- handleMessage(data) {
147
- const id = data.correlationId || NaN;
148
- if (!('correlationId' in data)) {
149
- if (this.uncorrelatedListener) {
150
- this.uncorrelatedListener.call(null, data);
151
- }
152
- this.uncorrelatedListener = () => {
153
- // empty block
154
- };
155
- }
156
- else if (!this.wireListeners.has(id)) {
157
- return false;
158
- }
159
- else {
160
- // We just checked for existence above
161
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
162
- const { resolve, reject } = this.wireListeners.get(id);
163
- if (data.action !== 'ack') {
164
- reject(new transport_errors_1.NoAckError(data.action));
165
- }
166
- else if (!('payload' in data)) {
167
- reject(new transport_errors_1.RuntimeError(data));
168
- }
169
- else if (!data.payload.success) {
170
- reject(new transport_errors_1.RuntimeError(data.payload));
171
- }
172
- else {
173
- resolve.call(null, data);
174
- }
175
- this.wireListeners.delete(id);
176
- }
177
- return true;
178
- }
179
- }
180
- _wire = new WeakMap();
181
- exports.default = Transport;
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
3
+ if (!privateMap.has(receiver)) {
4
+ throw new TypeError("attempted to set private field on non-instance");
5
+ }
6
+ privateMap.set(receiver, value);
7
+ return value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
10
+ if (!privateMap.has(receiver)) {
11
+ throw new TypeError("attempted to get private field on non-instance");
12
+ }
13
+ return privateMap.get(receiver);
14
+ };
15
+ var _wire;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const events_1 = require("events");
18
+ const wire_1 = require("./wire");
19
+ const transport_errors_1 = require("./transport-errors");
20
+ const eventAggregator_1 = require("../api/events/eventAggregator");
21
+ const me_1 = require("../api/me");
22
+ class Transport extends events_1.EventEmitter {
23
+ constructor(WireType, environment, config) {
24
+ super();
25
+ this.wireListeners = new Map();
26
+ this.topicRefMap = new Map();
27
+ this.eventAggregator = new eventAggregator_1.default();
28
+ this.messageHandlers = [this.eventAggregator.dispatchEvent];
29
+ _wire.set(this, void 0);
30
+ this.connectSync = () => {
31
+ const wire = __classPrivateFieldGet(this, _wire);
32
+ wire.connectSync();
33
+ };
34
+ // This function is only used in our tests.
35
+ this.getPort = () => {
36
+ if (this.environment.constructor.name !== 'NodeEnvironment') {
37
+ throw new transport_errors_1.NotImplementedError('Not Implemented');
38
+ }
39
+ const wire = __classPrivateFieldGet(this, _wire);
40
+ return wire.wire.url.split(':').slice(-1)[0];
41
+ };
42
+ __classPrivateFieldSet(this, _wire, new WireType(this.onmessage.bind(this)));
43
+ this.environment = environment;
44
+ this.sendRaw = __classPrivateFieldGet(this, _wire).send.bind(__classPrivateFieldGet(this, _wire));
45
+ this.registerMessageHandler(this.handleMessage.bind(this));
46
+ __classPrivateFieldGet(this, _wire).on('disconnected', () => {
47
+ for (const [, { reject }] of this.wireListeners) {
48
+ reject('Remote connection has closed');
49
+ }
50
+ this.wireListeners.clear();
51
+ this.emit('disconnected');
52
+ });
53
+ const { uuid, name } = config;
54
+ const entityType = this.environment.getCurrentEntityType();
55
+ this.me = me_1.getBaseMe(entityType, uuid, name);
56
+ }
57
+ shutdown() {
58
+ const wire = __classPrivateFieldGet(this, _wire);
59
+ return wire.shutdown();
60
+ }
61
+ async connect(config) {
62
+ if (wire_1.isExistingConnectConfig(config)) {
63
+ return this.connectByPort(config);
64
+ }
65
+ if (wire_1.isNewConnectConfig(config)) {
66
+ const port = await this.environment.retrievePort(config);
67
+ return this.connectByPort({ ...config, address: `ws://localhost:${port}` });
68
+ }
69
+ return undefined;
70
+ }
71
+ async connectByPort(config) {
72
+ const { address, uuid } = config;
73
+ const reqAuthPayload = { ...config, type: 'file-token' };
74
+ const wire = __classPrivateFieldGet(this, _wire);
75
+ await wire.connect(address);
76
+ const requestExtAuthRet = await this.sendAction('request-external-authorization', {
77
+ uuid,
78
+ type: 'file-token'
79
+ }, true);
80
+ if (requestExtAuthRet.action !== 'external-authorization-response') {
81
+ throw new transport_errors_1.UnexpectedActionError(requestExtAuthRet.action);
82
+ }
83
+ const { token } = requestExtAuthRet.payload;
84
+ await this.environment.writeToken(requestExtAuthRet.payload.file, requestExtAuthRet.payload.token);
85
+ const requestAuthRet = await this.sendAction('request-authorization', reqAuthPayload, true);
86
+ if (requestAuthRet.action !== 'authorization-response') {
87
+ throw new transport_errors_1.UnexpectedActionError(requestAuthRet.action);
88
+ }
89
+ else if (requestAuthRet.payload.success !== true) {
90
+ throw new transport_errors_1.RuntimeError(requestAuthRet.payload);
91
+ }
92
+ else {
93
+ return token;
94
+ }
95
+ }
96
+ sendAction(action, payload = {}, uncorrelated = false
97
+ // specialResponse type is only used for 'requestAuthorization'
98
+ ) {
99
+ return new Promise((resolve, reject) => {
100
+ const id = this.environment.getNextMessageId();
101
+ const msg = {
102
+ action,
103
+ payload,
104
+ messageId: id
105
+ };
106
+ const wire = __classPrivateFieldGet(this, _wire);
107
+ this.addWireListener(id, resolve, reject, uncorrelated);
108
+ return wire.send(msg).catch(reject);
109
+ });
110
+ }
111
+ ferryAction(origData) {
112
+ return new Promise((resolve, reject) => {
113
+ const id = this.environment.getNextMessageId();
114
+ origData.messageId = id;
115
+ const resolver = (data) => {
116
+ resolve(data.payload);
117
+ };
118
+ const wire = __classPrivateFieldGet(this, _wire);
119
+ return wire
120
+ .send(origData)
121
+ .then(() => this.addWireListener(id, resolver, reject, false))
122
+ .catch(reject);
123
+ });
124
+ }
125
+ registerMessageHandler(handler) {
126
+ this.messageHandlers.push(handler);
127
+ }
128
+ addWireListener(id, resolve, reject, uncorrelated) {
129
+ if (uncorrelated) {
130
+ this.uncorrelatedListener = resolve;
131
+ }
132
+ else if (this.wireListeners.has(id)) {
133
+ reject(new transport_errors_1.DuplicateCorrelationError(String(id)));
134
+ }
135
+ else {
136
+ this.wireListeners.set(id, { resolve, reject });
137
+ }
138
+ // Timeout and reject()?
139
+ }
140
+ // This method executes message handlers until the _one_ that handles the message (returns truthy) has run
141
+ onmessage(data) {
142
+ for (const h of this.messageHandlers) {
143
+ h.call(null, data);
144
+ }
145
+ }
146
+ handleMessage(data) {
147
+ const id = data.correlationId || NaN;
148
+ if (!('correlationId' in data)) {
149
+ if (this.uncorrelatedListener) {
150
+ this.uncorrelatedListener.call(null, data);
151
+ }
152
+ this.uncorrelatedListener = () => {
153
+ // empty block
154
+ };
155
+ }
156
+ else if (!this.wireListeners.has(id)) {
157
+ return false;
158
+ }
159
+ else {
160
+ // We just checked for existence above
161
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
162
+ const { resolve, reject } = this.wireListeners.get(id);
163
+ if (data.action !== 'ack') {
164
+ reject(new transport_errors_1.NoAckError(data.action));
165
+ }
166
+ else if (!('payload' in data)) {
167
+ reject(new transport_errors_1.RuntimeError(data));
168
+ }
169
+ else if (!data.payload.success) {
170
+ reject(new transport_errors_1.RuntimeError(data.payload));
171
+ }
172
+ else {
173
+ resolve.call(null, data);
174
+ }
175
+ this.wireListeners.delete(id);
176
+ }
177
+ return true;
178
+ }
179
+ }
180
+ _wire = new WeakMap();
181
+ exports.default = Transport;
@@ -1,11 +1,71 @@
1
- import ConnectConfig = OpenFin.ConnectConfig;
2
- import ExternalConfig = OpenFin.ExternalConfig;
3
- import ExistingConnectConfig = OpenFin.ExistingConnectConfig;
4
- import NewConnectConfig = OpenFin.NewConnectConfig;
5
- import PortDiscoveryConfig = OpenFin.PortDiscoveryConfig;
6
- import InternalConnectConfig = OpenFin.InternalConnectConfig;
7
- export declare function isExternalConfig(config: ConnectConfig): config is ExternalConfig;
8
- export declare function isExistingConnectConfig(config: any): config is ExistingConnectConfig;
9
- export declare function isNewConnectConfig(config: any): config is NewConnectConfig;
10
- export declare function isPortDiscoveryConfig(config: any): config is PortDiscoveryConfig;
11
- export declare function isInternalConnectConfig(config: any): config is InternalConnectConfig;
1
+ /// <reference types="mocha" />
2
+ /// <reference types="node" />
3
+ import EventEmitter = NodeJS.EventEmitter;
4
+ export declare type Wire = EventEmitter & {
5
+ connect(address: string): Promise<any>;
6
+ connectSync(): any;
7
+ send(data: any): Promise<any>;
8
+ shutdown(): Promise<void>;
9
+ };
10
+ export declare type WireConstructor = {
11
+ new (onmessage: (data: any) => void): Wire;
12
+ };
13
+ export declare type RuntimeConfig = {
14
+ version: string;
15
+ fallbackVersion?: string;
16
+ securityRealm?: string;
17
+ verboseLogging?: boolean;
18
+ arguments?: string;
19
+ rvmDir?: string;
20
+ };
21
+ export declare type ServiceConfig = {
22
+ name: string;
23
+ manifestUrl: string;
24
+ };
25
+ export declare type BaseConfig = {
26
+ uuid?: string;
27
+ address?: string;
28
+ name?: string;
29
+ nonPersistent?: boolean;
30
+ runtimeClient?: boolean;
31
+ licenseKey?: string;
32
+ client?: any;
33
+ manifestUrl?: string;
34
+ startupApp?: any;
35
+ lrsUrl?: string;
36
+ assetsUrl?: string;
37
+ devToolsPort?: number;
38
+ installerUI?: boolean;
39
+ runtime?: RuntimeConfig;
40
+ services?: ServiceConfig[];
41
+ appAssets?: [{
42
+ src: string;
43
+ alias: string;
44
+ target: string;
45
+ version: string;
46
+ args: string;
47
+ }];
48
+ customItems?: [any];
49
+ timeout?: number;
50
+ };
51
+ export declare type ConfigWithUuid = BaseConfig & {
52
+ uuid: string;
53
+ };
54
+ export declare type ExistingConnectConfig = ConfigWithUuid & {
55
+ address: string;
56
+ };
57
+ export declare type ConfigWithRuntime = BaseConfig & {
58
+ runtime: RuntimeConfig;
59
+ };
60
+ export declare type ExternalConfig = BaseConfig & {
61
+ manifestUrl: string;
62
+ };
63
+ export declare type NewConnectConfig = ConfigWithUuid & ConfigWithRuntime;
64
+ export declare type PortDiscoveryConfig = (ExternalConfig & ConfigWithRuntime) | NewConnectConfig;
65
+ export declare type ConnectConfig = ExistingConnectConfig | NewConnectConfig | ExternalConfig;
66
+ export declare type InternalConnectConfig = ExistingConnectConfig | NewConnectConfig;
67
+ export declare function isExternalConfig(config: ConnectConfig): config is ExternalConfig;
68
+ export declare function isExistingConnectConfig(config: any): config is ExistingConnectConfig;
69
+ export declare function isNewConnectConfig(config: any): config is NewConnectConfig;
70
+ export declare function isPortDiscoveryConfig(config: any): config is PortDiscoveryConfig;
71
+ export declare function isInternalConnectConfig(config: any): config is InternalConnectConfig;
@@ -1,32 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isInternalConnectConfig = exports.isPortDiscoveryConfig = exports.isNewConnectConfig = exports.isExistingConnectConfig = exports.isExternalConfig = void 0;
4
- function isExternalConfig(config) {
5
- if (typeof config.manifestUrl === 'string') {
6
- return true;
7
- }
8
- return false;
9
- }
10
- exports.isExternalConfig = isExternalConfig;
11
- function isExistingConnectConfig(config) {
12
- return hasUuid(config) && typeof config.address === 'string';
13
- }
14
- exports.isExistingConnectConfig = isExistingConnectConfig;
15
- function hasUuid(config) {
16
- return typeof config.uuid === 'string';
17
- }
18
- function hasRuntimeVersion(config) {
19
- return config.runtime && typeof config.runtime.version === 'string';
20
- }
21
- function isNewConnectConfig(config) {
22
- return hasUuid(config) && hasRuntimeVersion(config);
23
- }
24
- exports.isNewConnectConfig = isNewConnectConfig;
25
- function isPortDiscoveryConfig(config) {
26
- return (isExternalConfig(config) && hasRuntimeVersion(config)) || isNewConnectConfig(config);
27
- }
28
- exports.isPortDiscoveryConfig = isPortDiscoveryConfig;
29
- function isInternalConnectConfig(config) {
30
- return isExistingConnectConfig(config) || isNewConnectConfig(config);
31
- }
32
- exports.isInternalConnectConfig = isInternalConnectConfig;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isInternalConnectConfig = exports.isPortDiscoveryConfig = exports.isNewConnectConfig = exports.isExistingConnectConfig = exports.isExternalConfig = void 0;
4
+ function isExternalConfig(config) {
5
+ if (typeof config.manifestUrl === 'string') {
6
+ return true;
7
+ }
8
+ return false;
9
+ }
10
+ exports.isExternalConfig = isExternalConfig;
11
+ function isExistingConnectConfig(config) {
12
+ return hasUuid(config) && typeof config.address === 'string';
13
+ }
14
+ exports.isExistingConnectConfig = isExistingConnectConfig;
15
+ function hasUuid(config) {
16
+ return typeof config.uuid === 'string';
17
+ }
18
+ function hasRuntimeVersion(config) {
19
+ return config.runtime && typeof config.runtime.version === 'string';
20
+ }
21
+ function isNewConnectConfig(config) {
22
+ return hasUuid(config) && hasRuntimeVersion(config);
23
+ }
24
+ exports.isNewConnectConfig = isNewConnectConfig;
25
+ function isPortDiscoveryConfig(config) {
26
+ return (isExternalConfig(config) && hasRuntimeVersion(config)) || isNewConnectConfig(config);
27
+ }
28
+ exports.isPortDiscoveryConfig = isPortDiscoveryConfig;
29
+ function isInternalConnectConfig(config) {
30
+ return isExistingConnectConfig(config) || isNewConnectConfig(config);
31
+ }
32
+ exports.isInternalConnectConfig = isInternalConnectConfig;
@@ -1 +1 @@
1
- export declare function asyncFilter<T>(values: T[], callback: (value: T) => Promise<boolean>): Promise<T[]>;
1
+ export declare function asyncFilter<T>(values: T[], callback: (value: T) => Promise<boolean>): Promise<T[]>;
@@ -1,7 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asyncFilter = void 0;
4
- async function asyncFilter(values, callback) {
5
- return Promise.all(values.map(callback)).then((results) => values.filter((_, i) => results[i]));
6
- }
7
- exports.asyncFilter = asyncFilter;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asyncFilter = void 0;
4
+ async function asyncFilter(values, callback) {
5
+ return Promise.all(values.map(callback)).then((results) => values.filter((_, i) => results[i]));
6
+ }
7
+ exports.asyncFilter = asyncFilter;
@@ -1,5 +1,9 @@
1
- /**
2
- * This function converts JS errors into plain objects
3
- */
4
- import ErrorPlainObject = OpenFin.ErrorPlainObject;
5
- export declare function errorToPOJO(error: Error): ErrorPlainObject;
1
+ /**
2
+ * This function converts JS errors into plain objects
3
+ */
4
+ export declare type ErrorPlainObject = {
5
+ stack: string;
6
+ message: string;
7
+ toString(): string;
8
+ };
9
+ export declare function errorToPOJO(error: Error): ErrorPlainObject;