@appport/transport-electron 1.0.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.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # @appport/transport-electron
2
+
3
+ The Electron IPC transport: main-process binding, preload bridge and renderer
4
+ transport, over a single generic channel.
5
+
6
+ ```js
7
+ // main process
8
+ import { ipcMain } from "electron";
9
+ import { serveElectronIpc } from "@appport/transport-electron";
10
+
11
+ serveElectronIpc({
12
+ server,
13
+ ipcMain,
14
+ validateSender: (event) => event.senderFrame?.url?.startsWith("file://") ?? false,
15
+ identify: (event) => resolveIdentity(event)
16
+ });
17
+ ```
18
+
19
+ ```js
20
+ // preload.cjs
21
+ const { contextBridge, ipcRenderer } = require("electron");
22
+ const { exposeAppPort } = require("@appport/transport-electron/preload");
23
+
24
+ exposeAppPort(contextBridge, ipcRenderer);
25
+ ```
26
+
27
+ ```ts
28
+ // renderer
29
+ import { createElectronTransport } from "@appport/transport-electron";
30
+
31
+ const transport = createElectronTransport(); // uses window.appport
32
+ ```
33
+
34
+ ## Why one channel
35
+
36
+ The AppPort envelope identifies the capability, so there is one IPC channel,
37
+ `appport:message`, not one per operation. Channels named `save-document` and
38
+ `open-document` would put the application API into the transport, which is what
39
+ the protocol exists to prevent.
40
+
41
+ ## Why a bridge, not ipcRenderer
42
+
43
+ Electron's guidance is to expose narrowly scoped context-bridge APIs; exposing
44
+ `ipcRenderer` grants arbitrary message access. The bridge here is two functions:
45
+ send an envelope, receive envelopes.
46
+
47
+ ## Trust
48
+
49
+ IPC is not identity. `validateSender` decides whether a frame may speak AppPort
50
+ at all, `identify` resolves the session, and every capability is still
51
+ authorized. Envelopes queue behind identity resolution, so the first request is
52
+ never dispatched as anonymous.
53
+
54
+ The package depends on structural types rather than on `electron`, so the same
55
+ build works in the main process, the preload script and the renderer — and so
56
+ the transport can be tested without launching a browser.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@appport/transport-electron` — the Electron IPC transport (§23, §28).
3
+ *
4
+ * Main-process binding, preload bridge and renderer transport, over a single
5
+ * generic IPC channel.
6
+ */
7
+ export * from "./types.js";
8
+ export * from "./main.js";
9
+ export * from "./preload.js";
10
+ export * from "./renderer.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@appport/transport-electron` — the Electron IPC transport (§23, §28).
3
+ *
4
+ * Main-process binding, preload bridge and renderer transport, over a single
5
+ * generic IPC channel.
6
+ */
7
+ export * from "./types.js";
8
+ export * from "./main.js";
9
+ export * from "./preload.js";
10
+ export * from "./renderer.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
package/dist/main.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { AppPortServer, Identity } from "@appport/server";
2
+ import { type IpcMainEventLike, type IpcMainLike } from "./types.js";
3
+ export interface ElectronMainOptions {
4
+ server: AppPortServer;
5
+ ipcMain: IpcMainLike;
6
+ /** IPC channel name. One channel carries every capability (§28). */
7
+ channel?: string;
8
+ /**
9
+ * Decides whether a renderer may speak AppPort at all.
10
+ *
11
+ * Electron recommends validating the sender rather than trusting any frame
12
+ * that can reach IPC. Returning false drops the message silently.
13
+ */
14
+ validateSender?: (event: IpcMainEventLike) => boolean;
15
+ /** Resolves an identity for a renderer. IPC is not identity (§37). */
16
+ identify?: (event: IpcMainEventLike) => Identity | Promise<Identity>;
17
+ }
18
+ export interface ElectronMainBinding {
19
+ /** Stops listening and releases every renderer connection. */
20
+ dispose(): void;
21
+ readonly connectionCount: number;
22
+ }
23
+ /**
24
+ * Serves AppPort over Electron IPC from the main process (§28).
25
+ *
26
+ * One generic channel carries every capability; the envelope identifies the
27
+ * capability. Generating a channel per operation would put the application API
28
+ * into the transport, which is the mistake the protocol exists to prevent.
29
+ */
30
+ export declare function serveElectronIpc(options: ElectronMainOptions): ElectronMainBinding;
31
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqB,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAmB,KAAK,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtF,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,WAAW,CAAC;IACrB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC;IACtD,sEAAsE;IACtE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAYD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,mBAAmB,CAoDlF"}
package/dist/main.js ADDED
@@ -0,0 +1,61 @@
1
+ import {} from "@appport/protocol";
2
+ import { APPPORT_CHANNEL } from "./types.js";
3
+ /**
4
+ * Serves AppPort over Electron IPC from the main process (§28).
5
+ *
6
+ * One generic channel carries every capability; the envelope identifies the
7
+ * capability. Generating a channel per operation would put the application API
8
+ * into the transport, which is the mistake the protocol exists to prevent.
9
+ */
10
+ export function serveElectronIpc(options) {
11
+ const channel = options.channel ?? APPPORT_CHANNEL;
12
+ const renderers = new Map();
13
+ const listener = (event, ...args) => {
14
+ if (options.validateSender && !options.validateSender(event))
15
+ return;
16
+ const payload = args[0];
17
+ const senderId = event.sender.id;
18
+ let state = renderers.get(senderId);
19
+ if (!state) {
20
+ const connection = options.server.createConnection({
21
+ transport: "ipc",
22
+ send: (envelope) => {
23
+ if (event.sender.isDestroyed?.())
24
+ return;
25
+ event.sender.send(channel, envelope);
26
+ }
27
+ });
28
+ state = {
29
+ connection,
30
+ queue: options.identify
31
+ ? Promise.resolve(options.identify(event)).then((identity) => connection.authenticate(identity))
32
+ : Promise.resolve()
33
+ };
34
+ renderers.set(senderId, state);
35
+ event.sender.once?.("destroyed", () => {
36
+ const existing = renderers.get(senderId);
37
+ if (existing) {
38
+ options.server.releaseConnection(existing.connection);
39
+ renderers.delete(senderId);
40
+ }
41
+ });
42
+ }
43
+ const current = state;
44
+ current.queue = current.queue
45
+ .then(() => current.connection.acceptValue(payload))
46
+ .catch(() => undefined);
47
+ };
48
+ options.ipcMain.on(channel, listener);
49
+ return {
50
+ get connectionCount() {
51
+ return renderers.size;
52
+ },
53
+ dispose() {
54
+ options.ipcMain.removeListener(channel, listener);
55
+ for (const state of renderers.values())
56
+ options.server.releaseConnection(state.connection);
57
+ renderers.clear();
58
+ }
59
+ };
60
+ }
61
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAE,eAAe,EAA2C,MAAM,YAAY,CAAC;AAkCtF;;;;;;GAMG;AAC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AAE,CAAC,WAAW,EAAE,GAAG,EAAE;gBACpC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBACzC,IAAI,QAAQ,EAAE,CAAC;oBACb,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;oBACtD,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC7B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC;QACtB,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK;aAC1B,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;aACnD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC,CAAC;IAEF,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEtC,OAAO;QACL,IAAI,eAAe;YACjB,OAAO,SAAS,CAAC,IAAI,CAAC;QACxB,CAAC;QACD,OAAO;YACL,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAClD,KAAK,MAAM,KAAK,IAAI,SAAS,CAAC,MAAM,EAAE;gBAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC3F,SAAS,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type ContextBridgeLike, type IpcRendererLike } from "./types.js";
2
+ export interface ExposeOptions {
3
+ channel?: string;
4
+ /** Global key the bridge is exposed under. Defaults to `appport`. */
5
+ key?: string;
6
+ }
7
+ /**
8
+ * Exposes the AppPort bridge to the renderer from a preload script (§28).
9
+ *
10
+ * The renderer receives two functions — send an envelope, receive envelopes —
11
+ * and never `ipcRenderer` itself. That is the difference between a scoped API
12
+ * and arbitrary message access.
13
+ *
14
+ * ```js
15
+ * // preload.cjs
16
+ * const { contextBridge, ipcRenderer } = require("electron");
17
+ * const { exposeAppPort } = require("@appport/transport-electron/preload");
18
+ * exposeAppPort(contextBridge, ipcRenderer);
19
+ * ```
20
+ */
21
+ export declare function exposeAppPort(contextBridge: ContextBridgeLike, ipcRenderer: IpcRendererLike, options?: ExposeOptions): void;
22
+ //# sourceMappingURL=preload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAE3G,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,iBAAiB,EAChC,WAAW,EAAE,eAAe,EAC5B,OAAO,GAAE,aAAkB,GAC1B,IAAI,CAaN"}
@@ -0,0 +1,29 @@
1
+ import { APPPORT_CHANNEL, APPPORT_GLOBAL } from "./types.js";
2
+ /**
3
+ * Exposes the AppPort bridge to the renderer from a preload script (§28).
4
+ *
5
+ * The renderer receives two functions — send an envelope, receive envelopes —
6
+ * and never `ipcRenderer` itself. That is the difference between a scoped API
7
+ * and arbitrary message access.
8
+ *
9
+ * ```js
10
+ * // preload.cjs
11
+ * const { contextBridge, ipcRenderer } = require("electron");
12
+ * const { exposeAppPort } = require("@appport/transport-electron/preload");
13
+ * exposeAppPort(contextBridge, ipcRenderer);
14
+ * ```
15
+ */
16
+ export function exposeAppPort(contextBridge, ipcRenderer, options = {}) {
17
+ const channel = options.channel ?? APPPORT_CHANNEL;
18
+ contextBridge.exposeInMainWorld(options.key ?? APPPORT_GLOBAL, {
19
+ send(envelope) {
20
+ ipcRenderer.send(channel, envelope);
21
+ },
22
+ receive(listener) {
23
+ const handler = (_event, envelope) => listener(envelope);
24
+ ipcRenderer.on(channel, handler);
25
+ return () => ipcRenderer.removeListener(channel, handler);
26
+ }
27
+ });
28
+ }
29
+ //# sourceMappingURL=preload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preload.js","sourceRoot":"","sources":["../src/preload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAgD,MAAM,YAAY,CAAC;AAQ3G;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,aAAgC,EAChC,WAA4B,EAC5B,UAAyB,EAAE;IAE3B,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,eAAe,CAAC;IAEnD,aAAa,CAAC,iBAAiB,CAAC,OAAO,CAAC,GAAG,IAAI,cAAc,EAAE;QAC7D,IAAI,CAAC,QAAiB;YACpB,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,CAAC,QAAqC;YAC3C,MAAM,OAAO,GAAG,CAAC,MAAe,EAAE,QAAiB,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAC3E,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACjC,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { type AppTransport } from "@appport/client";
2
+ import { type AppPortBridge } from "./types.js";
3
+ export interface ElectronTransportOptions {
4
+ /** The preload bridge. Defaults to `window.appport`. */
5
+ bridge?: AppPortBridge;
6
+ /** Global key the bridge was exposed under. */
7
+ key?: string;
8
+ }
9
+ /**
10
+ * The renderer-side Electron IPC transport (§28).
11
+ *
12
+ * Application code sees the same client as on the web; only the carrier under
13
+ * it changes.
14
+ */
15
+ export declare function createElectronTransport(options?: ElectronTransportOptions): AppTransport;
16
+ //# sourceMappingURL=renderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,KAAK,YAAY,EAAuB,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,wBAAwB;IACvC,wDAAwD;IACxD,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,wBAA6B,GAAG,YAAY,CAiC5F"}
@@ -0,0 +1,36 @@
1
+ import { errors } from "@appport/protocol";
2
+ import { createDuplexTransport } from "@appport/client";
3
+ import { APPPORT_GLOBAL } from "./types.js";
4
+ /**
5
+ * The renderer-side Electron IPC transport (§28).
6
+ *
7
+ * Application code sees the same client as on the web; only the carrier under
8
+ * it changes.
9
+ */
10
+ export function createElectronTransport(options = {}) {
11
+ const resolveBridge = () => {
12
+ const bridge = options.bridge ??
13
+ globalThis[options.key ?? APPPORT_GLOBAL];
14
+ if (!bridge) {
15
+ throw errors.internal("The AppPort preload bridge is not available; call exposeAppPort() from the preload script");
16
+ }
17
+ return bridge;
18
+ };
19
+ let release;
20
+ return createDuplexTransport({
21
+ kind: "ipc",
22
+ features: { events: true, streams: true, persistent: true },
23
+ async open(handlers) {
24
+ const bridge = resolveBridge();
25
+ release = bridge.receive((envelope) => handlers.onEnvelope(envelope));
26
+ },
27
+ send(envelope) {
28
+ resolveBridge().send(envelope);
29
+ },
30
+ async close() {
31
+ release?.();
32
+ release = undefined;
33
+ }
34
+ });
35
+ }
36
+ //# sourceMappingURL=renderer.js.map
@@ -0,0 +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s this transport touches.
3
+ *
4
+ * The package deliberately does not depend on `electron`: it is used from the
5
+ * main process, the preload script and the renderer, and each of those has a
6
+ * different module graph. Structural typing also keeps the transport testable
7
+ * without launching a browser (§56).
8
+ */
9
+ export interface IpcMainEventLike {
10
+ sender: {
11
+ id: number;
12
+ send(channel: string, ...args: unknown[]): void;
13
+ once?(event: string, listener: () => void): void;
14
+ isDestroyed?(): boolean;
15
+ };
16
+ senderFrame?: {
17
+ url?: string;
18
+ } | null;
19
+ }
20
+ export interface IpcMainLike {
21
+ on(channel: string, listener: (event: IpcMainEventLike, ...args: unknown[]) => void): void;
22
+ removeListener(channel: string, listener: (event: IpcMainEventLike, ...args: unknown[]) => void): void;
23
+ }
24
+ export interface IpcRendererLike {
25
+ send(channel: string, ...args: unknown[]): void;
26
+ on(channel: string, listener: (event: unknown, ...args: unknown[]) => void): void;
27
+ removeListener(channel: string, listener: (event: unknown, ...args: unknown[]) => void): void;
28
+ }
29
+ export interface ContextBridgeLike {
30
+ exposeInMainWorld(key: string, api: unknown): void;
31
+ }
32
+ /**
33
+ * The narrow surface the preload script exposes to the renderer.
34
+ *
35
+ * Electron's security guidance is to expose scoped APIs rather than
36
+ * `ipcRenderer` itself, because raw IPC access is arbitrary message access
37
+ * (§28). AppPort needs exactly two operations, so that is all the bridge has.
38
+ */
39
+ export interface AppPortBridge {
40
+ /** Sends one AppPort envelope to the main process. */
41
+ send(envelope: unknown): void;
42
+ /** Registers a listener for envelopes pushed by the main process. */
43
+ receive(listener: (envelope: unknown) => void): () => void;
44
+ }
45
+ /** The single AppPort IPC channel (§28). Never one channel per operation. */
46
+ export declare const APPPORT_CHANNEL = "appport:message";
47
+ /** The global key the preload bridge is exposed under. */
48
+ export declare const APPPORT_GLOBAL = "appport";
49
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WA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ED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9B,qEAAqE;IACrE,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAC5D;AAED,6EAA6E;AAC7E,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAEjD,0DAA0D;AAC1D,eAAO,MAAM,cAAc,YAAY,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ /** The single AppPort IPC channel (§28). Never one channel per operation. */
2
+ export const APPPORT_CHANNEL = "appport:message";
3
+ /** The global key the preload bridge is exposed under. */
4
+ export const APPPORT_GLOBAL = "appport";
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA+CA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEjD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@appport/transport-electron",
3
+ "version": "1.0.0",
4
+ "description": "Electron IPC AppPort transport.",
5
+ "license": "Apache-2.0",
6
+ "repository": { "type": "git", "url": "git+https://github.com/rkendel1/appport.git", "directory": "packages/transports/electron" },
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./main": {
16
+ "types": "./dist/main.d.ts",
17
+ "import": "./dist/main.js"
18
+ },
19
+ "./preload": {
20
+ "types": "./dist/preload.d.ts",
21
+ "import": "./dist/preload.js"
22
+ },
23
+ "./renderer": {
24
+ "types": "./dist/renderer.d.ts",
25
+ "import": "./dist/renderer.js"
26
+ },
27
+ "./types": {
28
+ "types": "./dist/types.d.ts",
29
+ "import": "./dist/types.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "README.md"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsc -b",
38
+ "clean": "tsc -b --clean"
39
+ },
40
+ "dependencies": {
41
+ "@appport/protocol": "1.0.0",
42
+ "@appport/client": "1.0.0",
43
+ "@appport/server": "1.0.0"
44
+ },
45
+ "publishConfig": { "access": "public" }
46
+ }