flipper-frontend-core 0.0.1-security → 0.1.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.
Files changed (74) hide show
  1. package/README.md +2 -4
  2. package/lib/AbstractClient.d.ts +65 -0
  3. package/lib/AbstractClient.d.ts.map +1 -0
  4. package/lib/AbstractClient.js +334 -0
  5. package/lib/AbstractClient.js.map +1 -0
  6. package/lib/RenderHost.d.ts +84 -0
  7. package/lib/RenderHost.d.ts.map +1 -0
  8. package/lib/RenderHost.js +11 -0
  9. package/lib/RenderHost.js.map +1 -0
  10. package/lib/client/FlipperServerClient.d.ts +10 -0
  11. package/lib/client/FlipperServerClient.d.ts.map +1 -0
  12. package/lib/client/FlipperServerClient.js +140 -0
  13. package/lib/client/FlipperServerClient.js.map +1 -0
  14. package/lib/devices/ArchivedDevice.d.ts +21 -0
  15. package/lib/devices/ArchivedDevice.d.ts.map +1 -0
  16. package/lib/devices/ArchivedDevice.js +49 -0
  17. package/lib/devices/ArchivedDevice.js.map +1 -0
  18. package/lib/devices/BaseDevice.d.ts +71 -0
  19. package/lib/devices/BaseDevice.d.ts.map +1 -0
  20. package/lib/devices/BaseDevice.js +245 -0
  21. package/lib/devices/BaseDevice.js.map +1 -0
  22. package/lib/devices/TestDevice.d.ts +8 -0
  23. package/lib/devices/TestDevice.d.ts.map +1 -0
  24. package/lib/devices/TestDevice.js +27 -0
  25. package/lib/devices/TestDevice.js.map +1 -0
  26. package/lib/fb/constants.d.ts +5 -0
  27. package/lib/fb/constants.d.ts.map +1 -0
  28. package/lib/fb/constants.js +6 -0
  29. package/lib/fb/constants.js.map +1 -0
  30. package/lib/fb-stubs/constants.d.ts +5 -0
  31. package/lib/fb-stubs/constants.d.ts.map +1 -0
  32. package/lib/fb-stubs/constants.js +6 -0
  33. package/lib/fb-stubs/constants.js.map +1 -0
  34. package/lib/flipperLibImplementation/downloadFile.d.ts +4 -0
  35. package/lib/flipperLibImplementation/downloadFile.d.ts.map +1 -0
  36. package/lib/flipperLibImplementation/downloadFile.js +40 -0
  37. package/lib/flipperLibImplementation/downloadFile.js.map +1 -0
  38. package/lib/flipperLibImplementation/index.d.ts +5 -0
  39. package/lib/flipperLibImplementation/index.d.ts.map +1 -0
  40. package/lib/flipperLibImplementation/index.js +61 -0
  41. package/lib/flipperLibImplementation/index.js.map +1 -0
  42. package/lib/globalObject.d.ts +16 -0
  43. package/lib/globalObject.d.ts.map +1 -0
  44. package/lib/globalObject.js +10 -0
  45. package/lib/globalObject.js.map +1 -0
  46. package/lib/index.d.ts +12 -0
  47. package/lib/index.d.ts.map +1 -0
  48. package/lib/index.js +39 -0
  49. package/lib/index.js.map +1 -0
  50. package/lib/plugins.d.ts +31 -0
  51. package/lib/plugins.d.ts.map +1 -0
  52. package/lib/plugins.js +181 -0
  53. package/lib/plugins.js.map +1 -0
  54. package/lib/utils/createServerAddOnControls.d.ts +3 -0
  55. package/lib/utils/createServerAddOnControls.d.ts.map +1 -0
  56. package/lib/utils/createServerAddOnControls.js +60 -0
  57. package/lib/utils/createServerAddOnControls.js.map +1 -0
  58. package/lib/utils/isPluginCompatible.d.ts +4 -0
  59. package/lib/utils/isPluginCompatible.d.ts.map +1 -0
  60. package/lib/utils/isPluginCompatible.js +18 -0
  61. package/lib/utils/isPluginCompatible.js.map +1 -0
  62. package/lib/utils/isPluginVersionMoreRecent.d.ts +4 -0
  63. package/lib/utils/isPluginVersionMoreRecent.d.ts.map +1 -0
  64. package/lib/utils/isPluginVersionMoreRecent.js +28 -0
  65. package/lib/utils/isPluginVersionMoreRecent.js.map +1 -0
  66. package/lib/utils/isProduction.d.ts +2 -0
  67. package/lib/utils/isProduction.d.ts.map +1 -0
  68. package/lib/utils/isProduction.js +8 -0
  69. package/lib/utils/isProduction.js.map +1 -0
  70. package/lib/utils/pluginKey.d.ts +5 -0
  71. package/lib/utils/pluginKey.d.ts.map +1 -0
  72. package/lib/utils/pluginKey.js +18 -0
  73. package/lib/utils/pluginKey.js.map +1 -0
  74. package/package.json +35 -3
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- # Security holding package
1
+ # flipper-frontend-core (TBD)
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
-
5
- Please refer to www.npmjs.com/advisories?search=flipper-frontend-core for more information.
3
+ Exposes core functionality for Flipper frontends: Flipper Electron, Flipper Browser UI, Flipper Server Companion.
@@ -0,0 +1,65 @@
1
+ import BaseDevice from './devices/BaseDevice';
2
+ import { Logger, FlipperServer } from 'flipper-common';
3
+ import EventEmitter from 'eventemitter3';
4
+ import { ClientQuery, ClientResponseType, ClientErrorType } from 'flipper-common';
5
+ import { _SandyPluginInstance, _SandyPluginDefinition } from 'flipper-plugin-core';
6
+ declare type Plugins = Set<string>;
7
+ declare type PluginsArr = Array<string>;
8
+ export declare type Params = {
9
+ api: string;
10
+ method: string;
11
+ params?: Object;
12
+ };
13
+ export declare type RequestMetadata = {
14
+ method: string;
15
+ id: number;
16
+ params: Params | undefined;
17
+ };
18
+ export interface ClientConnection {
19
+ send(data: any): void;
20
+ sendExpectResponse(data: any): Promise<ClientResponseType>;
21
+ }
22
+ export default abstract class AbstractClient extends EventEmitter {
23
+ connected: import("flipper-plugin-core").Atom<boolean>;
24
+ id: string;
25
+ query: ClientQuery;
26
+ sdkVersion: number;
27
+ messageIdCounter: number;
28
+ plugins: Plugins;
29
+ backgroundPlugins: Plugins;
30
+ connection: ClientConnection | null | undefined;
31
+ activePlugins: Set<string>;
32
+ device: BaseDevice;
33
+ logger: Logger;
34
+ sandyPluginStates: Map<string, _SandyPluginInstance>;
35
+ private readonly serverAddOnControls;
36
+ private readonly flipperServer;
37
+ constructor(id: string, query: ClientQuery, conn: ClientConnection | null | undefined, logger: Logger, plugins: Plugins | null | undefined, device: BaseDevice, flipperServer: FlipperServer);
38
+ isBackgroundPlugin(pluginId: string): boolean;
39
+ protected abstract shouldConnectAsBackgroundPlugin(pluginId: string): boolean;
40
+ init(): Promise<void>;
41
+ protected loadPlugins(_phase: 'init' | 'refresh'): Promise<Plugins>;
42
+ protected loadPlugin(plugin: _SandyPluginDefinition, initialState?: Record<string, any>): void;
43
+ startPluginIfNeeded(plugin: _SandyPluginDefinition | undefined): void;
44
+ stopPluginIfNeeded(pluginId: string, _force?: boolean): void;
45
+ disconnect(): void;
46
+ destroy(): void;
47
+ protected abstract getPlugin(pluginId: string): Promise<_SandyPluginDefinition | undefined>;
48
+ protected getBackgroundPlugins(): Promise<PluginsArr>;
49
+ refreshPlugins(): Promise<void>;
50
+ onMessage(msg: string): void;
51
+ protected handleExecuteMessage(params: Params): boolean;
52
+ protected onResponse(data: ClientResponseType, resolve: ((a: any) => any) | undefined, reject: (error: ClientErrorType) => any): void;
53
+ protected rawCall<T>(method: string, fromPlugin: boolean, params?: Params): Promise<T>;
54
+ protected isAcceptingMessagesFromPlugin(plugin: string | null | undefined): boolean | null | undefined;
55
+ protected getPerformanceMark(data: RequestMetadata): string;
56
+ protected getLogEventName(data: RequestMetadata): string;
57
+ initPlugin(pluginId: string): void;
58
+ deinitPlugin(pluginId: string): void;
59
+ protected rawSend(method: string, params?: Object): void;
60
+ call(api: string, method: string, fromPlugin: boolean, params?: Object): Promise<Object>;
61
+ send(api: string, method: string, params?: Object): void;
62
+ supportsMethod(api: string, method: string): Promise<boolean>;
63
+ }
64
+ export {};
65
+ //# sourceMappingURL=AbstractClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractClient.d.ts","sourceRoot":"","sources":["../src/AbstractClient.tsx"],"names":[],"mappings":"AAYA,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAC,MAAM,EAAE,aAAa,EAAsB,MAAM,gBAAgB,CAAC;AAK1E,OAAO,YAAY,MAAM,eAAe,CAAC;AAGzC,OAAO,EAEL,WAAW,EACX,kBAAkB,EAClB,eAAe,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,oBAAoB,EAEpB,sBA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AAI,GAAG,SAAS;IAIzE,SAAS,CAAC,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM;IAK3D,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM;IAOxD,UAAU,CAAC,QAAQ,EAAE,MAAM;IAS3B,YAAY,CAAC,QAAQ,EAAE,MAAM;IAS7B,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAmBxD,IAAI,CACF,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,OAAO,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;IAiClB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAWlD,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAYpE"}
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const flipper_common_1 = require("flipper-common");
7
+ const eventemitter3_1 = __importDefault(require("eventemitter3"));
8
+ const pluginKey_1 = require("./utils/pluginKey");
9
+ const immer_1 = require("immer");
10
+ const flipper_common_2 = require("flipper-common");
11
+ const flipper_plugin_core_1 = require("flipper-plugin-core");
12
+ const createServerAddOnControls_1 = require("./utils/createServerAddOnControls");
13
+ const isProduction_1 = __importDefault(require("./utils/isProduction"));
14
+ class AbstractClient extends eventemitter3_1.default {
15
+ constructor(id, query, conn, logger, plugins, device, flipperServer) {
16
+ super();
17
+ this.connected = (0, flipper_plugin_core_1.createState)(false);
18
+ this.sandyPluginStates = new Map();
19
+ this.connected.set(!!conn);
20
+ this.plugins = plugins ? plugins : new Set();
21
+ this.backgroundPlugins = new Set();
22
+ this.connection = conn;
23
+ this.id = id;
24
+ this.query = query;
25
+ this.sdkVersion = query.sdk_version || 0;
26
+ this.messageIdCounter = 0;
27
+ this.logger = logger;
28
+ this.activePlugins = new Set();
29
+ this.device = device;
30
+ this.flipperServer = flipperServer;
31
+ this.serverAddOnControls = (0, createServerAddOnControls_1.createServerAddOnControls)(this.flipperServer);
32
+ }
33
+ isBackgroundPlugin(pluginId) {
34
+ return this.backgroundPlugins.has(pluginId);
35
+ }
36
+ async init() {
37
+ await this.loadPlugins('init');
38
+ await Promise.all([...this.plugins].map(async (pluginId) => this.startPluginIfNeeded(await this.getPlugin(pluginId))));
39
+ this.backgroundPlugins = new Set(await this.getBackgroundPlugins());
40
+ this.backgroundPlugins.forEach((plugin) => {
41
+ if (this.shouldConnectAsBackgroundPlugin(plugin)) {
42
+ this.initPlugin(plugin);
43
+ }
44
+ });
45
+ this.emit('plugins-change');
46
+ }
47
+ async loadPlugins(_phase) {
48
+ const { plugins } = await (0, flipper_common_2.timeout)(30 * 1000, this.rawCall('getPlugins', false), 'Fetch plugin timeout for ' + this.id);
49
+ this.plugins = new Set(plugins);
50
+ console.info('AbstractClient.loadPlugins', this.query, plugins);
51
+ return plugins;
52
+ }
53
+ loadPlugin(plugin, initialState) {
54
+ try {
55
+ const pluginInstance = new flipper_plugin_core_1._SandyPluginInstance(this.serverAddOnControls, (0, flipper_plugin_core_1.getFlipperLib)(), plugin, this, (0, pluginKey_1.getPluginKey)(this.id, { serial: this.query.device_id }, plugin.id), initialState);
56
+ pluginInstance.events.on('error', (message) => {
57
+ const error = {
58
+ message,
59
+ name: 'Plugin Error',
60
+ stacktrace: '',
61
+ };
62
+ this.emit('error', error);
63
+ });
64
+ this.sandyPluginStates.set(plugin.id, pluginInstance);
65
+ }
66
+ catch (e) {
67
+ console.error(`Failed to start plugin '${plugin.id}': `, e);
68
+ }
69
+ }
70
+ startPluginIfNeeded(plugin) {
71
+ if (plugin && !this.sandyPluginStates.has(plugin.id)) {
72
+ this.loadPlugin(plugin);
73
+ }
74
+ }
75
+ stopPluginIfNeeded(pluginId, _force = false) {
76
+ const instance = this.sandyPluginStates.get(pluginId);
77
+ if (instance) {
78
+ instance.destroy();
79
+ this.sandyPluginStates.delete(pluginId);
80
+ }
81
+ }
82
+ disconnect() {
83
+ this.sandyPluginStates.forEach((instance) => {
84
+ instance.disconnect();
85
+ });
86
+ this.emit('close');
87
+ this.connected.set(false);
88
+ }
89
+ destroy() {
90
+ this.disconnect();
91
+ this.plugins.forEach((pluginId) => this.stopPluginIfNeeded(pluginId, true));
92
+ this.serverAddOnControls.unsubscribe();
93
+ }
94
+ async getBackgroundPlugins() {
95
+ if (this.sdkVersion < 4) {
96
+ return [];
97
+ }
98
+ const data = await (0, flipper_common_2.timeout)(30 * 1000, this.rawCall('getBackgroundPlugins', false), 'Fetch background plugins timeout for ' + this.id);
99
+ return data.plugins;
100
+ }
101
+ async refreshPlugins() {
102
+ const oldBackgroundPlugins = this.backgroundPlugins;
103
+ await this.loadPlugins('refresh');
104
+ await Promise.all([...this.plugins].map(async (pluginId) => this.startPluginIfNeeded(await this.getPlugin(pluginId))));
105
+ const newBackgroundPlugins = await this.getBackgroundPlugins();
106
+ this.backgroundPlugins = new Set(newBackgroundPlugins);
107
+ oldBackgroundPlugins.forEach((plugin) => {
108
+ if (!this.backgroundPlugins.has(plugin)) {
109
+ this.deinitPlugin(plugin);
110
+ }
111
+ });
112
+ newBackgroundPlugins.forEach((plugin) => {
113
+ if (!oldBackgroundPlugins.has(plugin) &&
114
+ this.shouldConnectAsBackgroundPlugin(plugin)) {
115
+ this.initPlugin(plugin);
116
+ }
117
+ });
118
+ this.emit('plugins-change');
119
+ }
120
+ onMessage(msg) {
121
+ var _a, _b, _c, _d;
122
+ if (typeof msg !== 'string') {
123
+ return;
124
+ }
125
+ let rawData;
126
+ try {
127
+ rawData = (0, immer_1.freeze)(JSON.parse(msg), true);
128
+ }
129
+ catch (err) {
130
+ console.error(`Invalid JSON: ${msg}`, 'clientMessage');
131
+ return;
132
+ }
133
+ const data = rawData;
134
+ const { id, method } = data;
135
+ this.emit('flipper-debug-message', {
136
+ device: (_a = this.device) === null || _a === void 0 ? void 0 : _a.displayTitle(),
137
+ app: this.query.app,
138
+ flipperInternalMethod: method,
139
+ plugin: (_b = data.params) === null || _b === void 0 ? void 0 : _b.api,
140
+ pluginMethod: (_c = data.params) === null || _c === void 0 ? void 0 : _c.method,
141
+ payload: (_d = data.params) === null || _d === void 0 ? void 0 : _d.params,
142
+ direction: 'toFlipper:message',
143
+ });
144
+ if (id == null) {
145
+ const { error } = data;
146
+ if (error != null) {
147
+ console.error(`Error received from device ${method ? `when calling ${method}` : ''}: ${error.message} + \nDevice Stack Trace: ${error.stacktrace}`, 'deviceError');
148
+ this.emit('error', error);
149
+ }
150
+ else if (method === 'refreshPlugins') {
151
+ this.refreshPlugins();
152
+ }
153
+ else if (method === 'execute') {
154
+ if (!data.params) {
155
+ throw new Error('expected params');
156
+ }
157
+ const params = data.params;
158
+ const bytes = msg.length * 2;
159
+ this.emit('bytes-received', params.api, bytes);
160
+ if (bytes > 5 * 1024 * 1024) {
161
+ console.warn(`Plugin '${params.api}' received excessively large message for '${params.method}': ${Math.round(bytes / 1024)}kB`);
162
+ }
163
+ const handled = this.handleExecuteMessage(params);
164
+ if (!handled && !(0, isProduction_1.default)()) {
165
+ console.warn(`Unhandled message ${params.api}.${params.method}`);
166
+ }
167
+ }
168
+ return;
169
+ }
170
+ }
171
+ handleExecuteMessage(params) {
172
+ const pluginInstance = this.sandyPluginStates.get(params.api);
173
+ if (!pluginInstance) {
174
+ return false;
175
+ }
176
+ pluginInstance.receiveMessages([params]);
177
+ return true;
178
+ }
179
+ onResponse(data, resolve, reject) {
180
+ if (data.success) {
181
+ resolve && resolve(data.success);
182
+ }
183
+ else if (data.error) {
184
+ reject(data.error);
185
+ const { error } = data;
186
+ if (error) {
187
+ this.emit('error', error);
188
+ }
189
+ }
190
+ else {
191
+ }
192
+ }
193
+ rawCall(method, fromPlugin, params) {
194
+ return new Promise(async (resolve, reject) => {
195
+ var _a, _b;
196
+ const id = this.messageIdCounter++;
197
+ const metadata = {
198
+ method,
199
+ id,
200
+ params,
201
+ };
202
+ const data = {
203
+ id,
204
+ method,
205
+ params,
206
+ };
207
+ const plugin = params ? params.api : undefined;
208
+ console.debug(data, 'message:call');
209
+ const mark = this.getPerformanceMark(metadata);
210
+ performance.mark(mark);
211
+ if (!this.connected.get()) {
212
+ reject(new flipper_common_1.NoLongerConnectedToClientError());
213
+ return;
214
+ }
215
+ if (!fromPlugin || this.isAcceptingMessagesFromPlugin(plugin)) {
216
+ try {
217
+ const response = await this.connection.sendExpectResponse(data);
218
+ if (!fromPlugin || this.isAcceptingMessagesFromPlugin(plugin)) {
219
+ const logEventName = this.getLogEventName(data);
220
+ this.logger.trackTimeSince(mark, logEventName);
221
+ this.emit('bytes-received', plugin || 'unknown', response.length * 2);
222
+ this.onResponse(response, resolve, reject);
223
+ this.emit('flipper-debug-message', {
224
+ device: (_a = this.device) === null || _a === void 0 ? void 0 : _a.displayTitle(),
225
+ app: this.query.app,
226
+ flipperInternalMethod: method,
227
+ payload: response,
228
+ plugin,
229
+ pluginMethod: params === null || params === void 0 ? void 0 : params.method,
230
+ direction: 'toFlipper:response',
231
+ });
232
+ }
233
+ }
234
+ catch (error) {
235
+ reject(new Error('Unable to send, connection error: ' + error));
236
+ }
237
+ }
238
+ else {
239
+ reject(new Error(`Cannot send ${method}, client is not accepting messages for plugin ${plugin}`));
240
+ }
241
+ this.emit('flipper-debug-message', {
242
+ device: (_b = this.device) === null || _b === void 0 ? void 0 : _b.displayTitle(),
243
+ app: this.query.app,
244
+ flipperInternalMethod: method,
245
+ plugin: params === null || params === void 0 ? void 0 : params.api,
246
+ pluginMethod: params === null || params === void 0 ? void 0 : params.method,
247
+ payload: params === null || params === void 0 ? void 0 : params.params,
248
+ direction: 'toClient:call',
249
+ });
250
+ });
251
+ }
252
+ isAcceptingMessagesFromPlugin(plugin) {
253
+ return this.connection && (!plugin || this.activePlugins.has(plugin));
254
+ }
255
+ getPerformanceMark(data) {
256
+ const { method, id } = data;
257
+ return `request_response_${method}_${id}`;
258
+ }
259
+ getLogEventName(data) {
260
+ const { method, params } = data;
261
+ return params && params.api && params.method
262
+ ? `request_response_${method}_${params.api}_${params.method}`
263
+ : `request_response_${method}`;
264
+ }
265
+ initPlugin(pluginId) {
266
+ this.activePlugins.add(pluginId);
267
+ const instance = this.sandyPluginStates.get(pluginId);
268
+ if (this.connected.get() && instance) {
269
+ this.rawSend('init', { plugin: pluginId });
270
+ instance.connect();
271
+ }
272
+ }
273
+ deinitPlugin(pluginId) {
274
+ this.activePlugins.delete(pluginId);
275
+ const instance = this.sandyPluginStates.get(pluginId);
276
+ instance === null || instance === void 0 ? void 0 : instance.disconnect();
277
+ if (this.connected.get() && instance) {
278
+ this.rawSend('deinit', { plugin: pluginId });
279
+ }
280
+ }
281
+ rawSend(method, params) {
282
+ var _a;
283
+ const data = {
284
+ method,
285
+ params,
286
+ };
287
+ console.debug(data, 'message:send');
288
+ if (this.connection) {
289
+ this.connection.send(data);
290
+ }
291
+ this.emit('flipper-debug-message', {
292
+ device: (_a = this.device) === null || _a === void 0 ? void 0 : _a.displayTitle(),
293
+ app: this.query.app,
294
+ flipperInternalMethod: method,
295
+ payload: params,
296
+ direction: 'toClient:send',
297
+ });
298
+ }
299
+ call(api, method, fromPlugin, params) {
300
+ return (0, flipper_common_1.reportPluginFailures)(this.rawCall('execute', fromPlugin, {
301
+ api,
302
+ method,
303
+ params,
304
+ }).catch((err) => {
305
+ if (this.connected.get()) {
306
+ if (err.toString().includes('Socket closed unexpectedly')) {
307
+ console.warn(`Failed to call device due to unexpected disconnect: ${err}`);
308
+ this.disconnect();
309
+ return {};
310
+ }
311
+ throw err;
312
+ }
313
+ return {};
314
+ }), `Call-${method}`, api);
315
+ }
316
+ send(api, method, params) {
317
+ if (!(0, isProduction_1.default)()) {
318
+ console.warn(`${api}:${method || ''} client.send() is deprecated. Please use call() instead so you can handle errors.`);
319
+ }
320
+ return this.rawSend('execute', { api, method, params });
321
+ }
322
+ async supportsMethod(api, method) {
323
+ if (!this.connected.get()) {
324
+ return false;
325
+ }
326
+ const response = await this.rawCall('isMethodSupported', true, {
327
+ api,
328
+ method,
329
+ });
330
+ return response.isSupported;
331
+ }
332
+ }
333
+ exports.default = AbstractClient;
334
+ //# sourceMappingURL=AbstractClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractClient.js","sourceRoot":"","sources":["../src/AbstractClient.tsx"],"names":[],"mappings":";;;;;AAcA,mDAGwB;AACxB,kEAAyC;AACzC,iDAA+C;AAC/C,iCAA6B;AAC7B,mDAKwB;AACxB,6DAK6B;AAC7B,iFAA4E;AAC5E,wEAAgD;AAqBhD,MAA8B,cAAe,SAAQ,uBAAY;IAkB/D,YACE,EAAU,EACV,KAAkB,EAClB,IAAyC,EACzC,MAAc,EACd,OAAmC,EACnC,MAAkB,EAClB,aAA4B;QAE5B,KAAK,EAAE,CAAC;QA1BV,cAAS,GAAG,IAAA,iCAAW,EAAC,KAAK,CAAC,CAAC;QAa/B,sBAAiB,GAAG,IAAI,GAAG,EAA6C,CAAC;QAcvE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;QAC7C,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,WAAW,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,gB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ACnB,OAAO,CAAC,IAAI,CACV,GAAG,GAAG,IACJ,MAAM,IAAI,EACZ,mFAAmF,CACpF,CAAC;SACH;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAC,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,GAAW,EAAE,MAAc;QAC9C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE;YACzB,OAAO,KAAK,CAAC;SACd;QACD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAEhC,mBAAmB,EAAE,IAAI,EAAE;YAC5B,GAAG;YACH,MAAM;SACP,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,WAAW,CAAC;IAC9B,CAAC;CACF;AApdD,iCAodC"}
@@ -0,0 +1,84 @@
1
+ import { FlipperLib, Notification } from 'flipper-plugin-core';
2
+ import { FlipperServer, FlipperServerConfig } from 'flipper-common';
3
+ declare type NotificationEvents = 'show' | 'click' | 'close' | 'reply' | 'action';
4
+ declare type PluginNotification = {
5
+ notification: Notification;
6
+ pluginId: string;
7
+ client: null | string;
8
+ };
9
+ declare type Icon = {
10
+ name: string;
11
+ variant: 'outline' | 'filled';
12
+ size: number;
13
+ density: number;
14
+ };
15
+ interface NotificationAction {
16
+ text?: string;
17
+ type: 'button';
18
+ }
19
+ interface NotificationConstructorOptions {
20
+ title: string;
21
+ body: string;
22
+ actions?: NotificationAction[];
23
+ closeButtonText?: string;
24
+ }
25
+ declare type MainProcessEvents = {
26
+ 'flipper-protocol-handler': [query: string];
27
+ 'open-flipper-file': [url: string];
28
+ notificationEvent: [
29
+ eventName: NotificationEvents,
30
+ pluginNotification: PluginNotification,
31
+ arg: null | string | number
32
+ ];
33
+ trackUsage: any[];
34
+ getLaunchTime: [launchStartTime: number];
35
+ };
36
+ declare type ChildProcessEvents = {
37
+ setTheme: [theme: 'dark' | 'light' | 'system'];
38
+ sendNotification: [
39
+ {
40
+ payload: NotificationConstructorOptions;
41
+ pluginNotification: PluginNotification;
42
+ closeAfter?: number;
43
+ }
44
+ ];
45
+ getLaunchTime: [];
46
+ componentDidMount: [];
47
+ };
48
+ export interface RenderHost {
49
+ readTextFromClipboard(): string | undefined;
50
+ writeTextToClipboard(text: string): void;
51
+ showSaveDialog?(options: {
52
+ defaultPath?: string;
53
+ message?: string;
54
+ title?: string;
55
+ }): Promise<string | undefined>;
56
+ showOpenDialog?(options: {
57
+ defaultPath?: string;
58
+ filter?: {
59
+ extensions: string[];
60
+ name: string;
61
+ };
62
+ }): Promise<string | undefined>;
63
+ showSelectDirectoryDialog?(defaultPath?: string): Promise<string | undefined>;
64
+ importFile: FlipperLib['importFile'];
65
+ exportFile: FlipperLib['exportFile'];
66
+ exportFileBinary: FlipperLib['exportFileBinary'];
67
+ hasFocus(): boolean;
68
+ onIpcEvent<Event extends keyof MainProcessEvents>(event: Event, callback: (...arg: MainProcessEvents[Event]) => void): void;
69
+ sendIpcEvent<Event extends keyof ChildProcessEvents>(event: Event, ...args: ChildProcessEvents[Event]): void;
70
+ shouldUseDarkColors(): boolean;
71
+ restartFlipper(update?: boolean): void;
72
+ openLink(url: string): void;
73
+ GK(gatekeeper: string): boolean;
74
+ flipperServer: FlipperServer;
75
+ serverConfig: FlipperServerConfig;
76
+ requirePlugin(path: string): Promise<any>;
77
+ getStaticResourceUrl(relativePath: string): string;
78
+ getLocalIconUrl?(icon: Icon, publicUrl: string): string;
79
+ unloadModule?(path: string): void;
80
+ getPercentCPUUsage?(): number;
81
+ }
82
+ export declare function getRenderHostInstance(): RenderHost;
83
+ export {};
84
+ //# sourceMappingURL=RenderHost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderHost.d.ts","sourceRoot":"","sources":["../src/RenderHost.tsx"],"names":[],"mappings":"AASA,OAAO,EAAC,UAAU,EAAE,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAC,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EACjD,KAAK,EAAE,KAAK,EACZ,GAAG,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,GACjC,IAAI,CAAC;IACR,mBAAmB,IAAI,OAAO,CAAC;IAC/B,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,EAAE,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,mBAAmB,CAAC;IAClC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;IAEnD,eAAe,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IACxD,YAAY,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,kBAAkB,CAAC,IAAI,MAAM,CAAC;CAC/B;AAED,wBAAgB,qBAAqB,IAAI,UAAU,CAKlD"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRenderHostInstance = void 0;
4
+ function getRenderHostInstance() {
5
+ if (!FlipperRenderHostInstance) {
6
+ throw new Error('global FlipperRenderHostInstance was never set');
7
+ }
8
+ return FlipperRenderHostInstance;
9
+ }
10
+ exports.getRenderHostInstance = getRenderHostInstance;
11
+ //# sourceMappingURL=RenderHost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderHost.js","sourceRoot":"","sources":["../src/RenderHost.tsx"],"names":[],"mappings":";;;AAwJA,SAAgB,qBAAqB;IACnC,IAAI,CAAC,yBAAyB,EAAE;QAC9B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;KACnE;IACD,OAAO,yBAAyB,CAAC;AACnC,CAAC;AALD,sDAKC"}
@@ -0,0 +1,10 @@
1
+ import { FlipperServer } from 'flipper-common';
2
+ import ReconnectingWebSocket from 'reconnecting-websocket';
3
+ export declare enum FlipperServerState {
4
+ CONNECTING = 0,
5
+ CONNECTED = 1,
6
+ DISCONNECTED = 2
7
+ }
8
+ export declare function createFlipperServer(host: string, port: number, onStateChange: (state: FlipperServerState) => void): Promise<FlipperServer>;
9
+ export declare function createFlipperServerWithSocket(socket: ReconnectingWebSocket, onStateChange: (state: FlipperServerState) => void): Promise<FlipperServer>;
10
+ //# sourceMappingURL=FlipperServerClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FlipperServerClient.d.ts","sourceRoot":"","sources":["../../src/client/FlipperServerClient.tsx"],"names":[],"mappings":"AAUA,OAAO,EAEL,aAAa,EAId,MAAM,gBAAgB,CAAC;AACxB,OAAO,qBAAqB,MAAM,wBAAwB,CAAC;AAK3D,oBAAY,kBAAkB;IAC5B,UAAU,IAAA;IACV,SAAS,IAAA;IACT,YAAY,IAAA;CACb;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GACjD,OAAO,CAAC,aAAa,CAAC,CAGxB;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,qBAAqB,EAC7B,aAAa,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GACjD,OAAO,CAAC,aAAa,CAAC,CAyJxB"}