@oldzy/conduit-electron-adapter 1.0.11 → 1.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.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Conduit
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Conduit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,170 +1,202 @@
1
- # Conduit Electron Adapter
2
-
3
- Electron IPC adapter for [@oldzy/conduit](https://github.com/oldzy/conduit), enabling seamless communication between Electron's main and renderer processes.
4
-
5
- ## Features
6
-
7
- - 🔌 IPC-based communication between main and renderer processes
8
- - 🎯 Request/Response pattern with UUID tracking
9
- - 📡 Separate handlers for simple and streaming responses
10
- - 🚫 Request cancellation support
11
- - 💉 Automatic dependency injection for Electron App and IpcMain
12
- - 🔄 AbortController integration for async operations
13
- - 🔒 Type-safe with TypeScript generics
14
-
15
- ## Installation
16
-
17
- ```bash
18
- npm install @oldzy/conduit-electron-adapter
19
- ```
20
-
21
- ## Usage
22
-
23
- ### Main Process
24
-
25
- ```typescript
26
- import { Application } from '@oldzy/conduit';
27
- import { ElectronAdapter } from '@oldzy/conduit-electron-adapter';
28
-
29
- const app = new Application();
30
- const electronAdapter = new ElectronAdapter();
31
-
32
- app.useAdapter(electronAdapter);
33
-
34
- // Register your handlers...
35
- await app.build();
36
- ```
37
-
38
- ### Preload Script
39
-
40
- Configure your Electron window to use the preload script:
41
-
42
- ```typescript
43
- import { BrowserWindow } from 'electron';
44
- import path from 'path';
45
-
46
- // Use require.resolve to get the preload path from node_modules
47
- const preloadPath = require.resolve('@oldzy/conduit-electron-adapter/preload');
48
-
49
- const mainWindow = new BrowserWindow({
50
- webPreferences: {
51
- preload: preloadPath,
52
- contextIsolation: true,
53
- nodeIntegration: false
54
- }
55
- });
56
- ```
57
-
58
- The preload script automatically:
59
- - Exposes `conduit` to the renderer via `contextBridge`
60
- - Handles all IPC listeners for streaming, errors, and cancellation
61
- - Manages request timeout (30 seconds)
62
- - Cleans up listeners automatically
63
-
64
- ### Renderer Process
65
-
66
- ```typescript
67
- // Simple request/response (for SimpleHandler)
68
- const response = await window.conduit.send<GetUserResponse>({
69
- uuid: crypto.randomUUID(),
70
- type: 'GET_USER',
71
- userId: '123'
72
- });
73
- console.log(response.userName);
74
-
75
- // Streaming request (for StreamingHandler)
76
- await window.conduit.stream<LogChunkResponse>(
77
- {
78
- uuid: crypto.randomUUID(),
79
- type: 'STREAM_LOGS',
80
- filename: 'app.log'
81
- },
82
- (chunk) => {
83
- console.log('Received chunk:', chunk.line);
84
- }
85
- );
86
-
87
- // Cancel a request
88
- await window.conduit.cancel('request-uuid');
89
- ```
90
-
91
- ## API
92
-
93
- ### ElectronAdapter (Main Process)
94
-
95
- The adapter automatically:
96
- - Registers `conduit:send` IPC handler for simple requests (SimpleHandler)
97
- - Registers `conduit:stream` IPC handler for streaming requests (StreamingHandler)
98
- - Registers `conduit:cancel` IPC handler for cancelling requests
99
- - Injects `ElectronApp` (app instance) and `IpcMain` into the service container
100
- - Manages streaming responses via IPC events
101
- - Handles request cancellation with AbortController
102
-
103
- ### IConduitService (Renderer Process)
104
-
105
- The `window.conduit` object is automatically typed when you import the package:
106
-
107
- ```typescript
108
- import '@oldzy/conduit-electron-adapter';
109
-
110
- // Now window.conduit is fully typed!
111
- const response = await window.conduit.send<MyResponse>(request);
112
- ```
113
-
114
- ```typescript
115
- interface IConduitService {
116
- send: <TResponse extends BaseResponse>(
117
- request: BaseRequest
118
- ) => Promise<TResponse>;
119
- stream: <TResponse extends BaseResponse>(
120
- request: BaseRequest,
121
- onData: (response: TResponse) => void
122
- ) => Promise<void>;
123
- cancel: (requestUuid: string) => Promise<void>;
124
- }
125
- ```
126
-
127
- #### Methodstimeout (30s) and cleanup
128
-
129
- - **`cancel(requestUuid)`** - Cancel a pending request by UUID
130
-
131
- **Important**: Use `send()` for SimpleHandler and `stream()` for StreamingHandler. Using the wrong method will result in an error.
132
-
133
- ### IPC Channels
134
-
135
- Internal channels (handled automatically by the preload script):
136
- - `conduit:send` - Send a simple request (invoke) - returns response
137
- - `conduit:stream` - Start a streaming request (invoke) - sends chunks via eventsuest (invoke) - sends chunks via eventsd cleanup
138
-
139
- - **`cancel(requestUuid)`** - Cancel a pending request by UUID
140
-
141
- **Important**: Use `send()` for SimpleHandler and `stream()` for StreamingHandler. Using the wrong method will result in an error.
142
- - **`cancel(requestUuid)`** - Cancel a pending request by UUID
143
-
144
- ### IPC Channels
145
-
146
- Internal channels (handled automatically by the preload script):
147
- - `conduit:send` - Send a request (invoke)
148
- - `conduit:cancel` - Cancel a pending request (invoke)
149
- - `conduit:response:data:{uuid}` - Streaming response data (listener)
150
- - `conduit:response:complete:{uuid}` - Stream completed (listener)
151
- - `conduit:response:error:{uuid}` - Error occurred (listener)
152
- - `conduit:response:cancelled:{uuid}` - Request was cancelled (listener)
153
-
154
- ### Types
155
-
156
- ```typescript
157
- interface ErrorResponse {
158
- class ErrorResponse extends BaseResponse {
159
- constructor(
160
- public requestUuid: string,
161
- public error: string,
162
- public stack?: string
163
- );
164
- }
165
- ```
166
-
167
- **Note**: The `window.conduit` type is automatically available when you import the package in your TypeScript files.
168
- ## License
169
-
170
- MIT
1
+ # Conduit Electron Adapter
2
+
3
+ Electron IPC adapter for [@oldzy/conduit](https://github.com/oldzy/conduit), enabling seamless communication between Electron's main and renderer processes.
4
+
5
+ ## Features
6
+
7
+ - 🔌 IPC-based communication between main and renderer processes
8
+ - 🎯 Request/Response pattern with UUID tracking
9
+ - 📡 Separate handlers for simple and streaming responses
10
+ - 🚫 Request cancellation support
11
+ - 💉 Automatic dependency injection for Electron App and IpcMain
12
+ - 🔄 AbortController integration for async operations
13
+ - 🔒 Type-safe with TypeScript generics
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @oldzy/conduit-electron-adapter
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### Main Process
24
+
25
+ ```typescript
26
+ import { Application } from '@oldzy/conduit';
27
+ import { ElectronAdapter } from '@oldzy/conduit-electron-adapter';
28
+
29
+ const app = new Application();
30
+ const electronAdapter = new ElectronAdapter();
31
+
32
+ app.useAdapter(electronAdapter);
33
+
34
+ // Register your handlers...
35
+ await app.build();
36
+ ```
37
+
38
+ ### Preload Script
39
+
40
+ Configure your Electron window to use the preload script:
41
+
42
+ ```typescript
43
+ import { BrowserWindow } from 'electron';
44
+ import path from 'path';
45
+
46
+ // Use require.resolve to get the preload path from node_modules
47
+ const preloadPath = require.resolve('@oldzy/conduit-electron-adapter/preload');
48
+
49
+ const mainWindow = new BrowserWindow({
50
+ webPreferences: {
51
+ preload: preloadPath,
52
+ contextIsolation: true,
53
+ nodeIntegration: false
54
+ }
55
+ });
56
+ ```
57
+
58
+ The preload script automatically:
59
+ - Exposes `conduit` to the renderer via `contextBridge`
60
+ - Handles all IPC listeners for streaming, errors, and cancellation
61
+ - Manages request timeout (30 seconds)
62
+ - Cleans up listeners automatically
63
+
64
+ ### Renderer Process
65
+
66
+ ```typescript
67
+ // Simple request/response (for SimpleHandler)
68
+ const response = await window.conduit.send<GetUserResponse>({
69
+ uuid: crypto.randomUUID(),
70
+ type: 'GET_USER',
71
+ userId: '123'
72
+ });
73
+ console.log(response.userName);
74
+
75
+ // Streaming request (for StreamingHandler)
76
+ await window.conduit.stream<LogChunkResponse>(
77
+ {
78
+ uuid: crypto.randomUUID(),
79
+ type: 'STREAM_LOGS',
80
+ filename: 'app.log'
81
+ },
82
+ (chunk) => {
83
+ console.log('Received chunk:', chunk.line);
84
+ }
85
+ );
86
+
87
+ // Cancel a request
88
+ await window.conduit.cancel('request-uuid');
89
+ ```
90
+
91
+ ## API
92
+
93
+ ### ElectronAdapter (Main Process)
94
+
95
+ The adapter automatically:
96
+ - Registers `conduit:send` IPC handler for simple requests (SimpleHandler)
97
+ - Registers `conduit:stream` IPC handler for streaming requests (StreamingHandler)
98
+ - Registers `conduit:cancel` IPC handler for cancelling requests
99
+ - Injects `ElectronApp` (app instance) and `IpcMain` into the service container
100
+ - Manages streaming responses via IPC events
101
+ - Handles request cancellation with AbortController
102
+
103
+ ### IConduitService (Renderer Process)
104
+
105
+ The `window.conduit` object is automatically typed when you import the package:
106
+
107
+ ```typescript
108
+ import '@oldzy/conduit-electron-adapter';
109
+
110
+ // Now window.conduit is fully typed!
111
+ const response = await window.conduit.send<MyResponse>(request);
112
+ ```
113
+
114
+ ```typescript
115
+ interface IConduitService {
116
+ send: <TResponse extends BaseResponse>(
117
+ request: BaseRequest
118
+ ) => Promise<TResponse>;
119
+ stream: <TResponse extends BaseResponse>(
120
+ request: BaseRequest,
121
+ onData: (response: TResponse) => void
122
+ ) => Promise<void>;
123
+ cancel: (requestUuid: string) => Promise<void>;
124
+ }
125
+ ```
126
+
127
+ #### Methodstimeout (30s) and cleanup
128
+
129
+ - **`cancel(requestUuid)`** - Cancel a pending request by UUID
130
+
131
+ **Important**: Use `send()` for SimpleHandler and `stream()` for StreamingHandler. Using the wrong method will result in an error.
132
+
133
+ ### IPC Channels
134
+
135
+ Internal channels (handled automatically by the preload script):
136
+ - `conduit:send` - Send a simple request (invoke) - returns response
137
+ - `conduit:stream` - Start a streaming request (invoke) - sends chunks via eventsuest (invoke) - sends chunks via eventsd cleanup
138
+
139
+ - **`cancel(requestUuid)`** - Cancel a pending request by UUID
140
+
141
+ **Important**: Use `send()` for SimpleHandler and `stream()` for StreamingHandler. Using the wrong method will result in an error.
142
+ - **`cancel(requestUuid)`** - Cancel a pending request by UUID
143
+
144
+ ### IPC Channels
145
+
146
+ Internal channels (handled automatically by the preload script):
147
+ - `conduit:send` - Send a request (invoke)
148
+ - `conduit:cancel` - Cancel a pending request (invoke)
149
+ - `conduit:response:data:{uuid}` - Streaming response data (listener)
150
+ - `conduit:response:complete:{uuid}` - Stream completed (listener)
151
+ - `conduit:response:error:{uuid}` - Error occurred (listener)
152
+ - `conduit:response:cancelled:{uuid}` - Request was cancelled (listener)
153
+
154
+ ### Types
155
+
156
+ ```typescript
157
+ interface ErrorResponse {
158
+ class ErrorResponse extends BaseResponse {
159
+ constructor(
160
+ public requestUuid: string,
161
+ public error: string,
162
+ public stack?: string
163
+ );
164
+ }
165
+ ```
166
+
167
+ **Note**: The `window.conduit` type is automatically available when you import the package in your TypeScript files.
168
+
169
+ ## Releasing
170
+
171
+ This project uses [release-please](https://github.com/googleapis/release-please) to automate versioning and npm publishing via GitHub Actions.
172
+
173
+ ### How it works
174
+
175
+ 1. Push commits to `main` using **Conventional Commits** prefixes
176
+ 2. Release-please automatically creates/updates a release PR with version bump and changelog
177
+ 3. Merge the PR when you're ready → tag, GitHub Release, and npm publish happen automatically
178
+
179
+ ### Commit prefixes
180
+
181
+ | Prefix | Version bump | Example |
182
+ |---|---|---|
183
+ | `fix:` | **patch** (1.0.0 → 1.0.1) | `fix: resolve scoped service disposal` |
184
+ | `feat:` | **minor** (1.0.0 → 1.1.0) | `feat: add async handler support` |
185
+ | `feat!:` or `BREAKING CHANGE:` | **major** (1.0.0 → 2.0.0) | `feat!: redesign mediator API` |
186
+
187
+ Commits without these prefixes are ignored for versioning purposes.
188
+
189
+ ### Authentication
190
+
191
+ Publishing uses [npm trusted publishing](https://docs.npmjs.com/trusted-publishers) (OIDC) — no npm token secret needed. Configure the trusted publisher on npmjs.com:
192
+
193
+ 1. Go to **npmjs.com** → **@oldzy/conduit** → **Settings** → **Trusted Publisher**
194
+ 2. Select **GitHub Actions** and fill in:
195
+ - **Organization or user**: `oldzy`
196
+ - **Repository**: `conduit-electron-adpater`
197
+ - **Workflow filename**: `release-please.yml`
198
+ 3. Save
199
+
200
+ ## License
201
+
202
+ MIT
package/dist/index.d.mts CHANGED
@@ -27,10 +27,10 @@ declare class ErrorResponse extends BaseResponse {
27
27
  constructor(requestUuid: string, error: string, stack?: string | undefined);
28
28
  }
29
29
 
30
- declare global {
31
- interface Window {
32
- conduit: IConduitService;
33
- }
30
+ declare global {
31
+ interface Window {
32
+ conduit: IConduitService;
33
+ }
34
34
  }
35
35
 
36
36
  export { ELECTRON_APP_SERVICE_KEY, ElectronAdapter, ErrorResponse, IConduitService, IPC_MAIN_SERVICE_KEY };
package/dist/index.d.ts CHANGED
@@ -27,10 +27,10 @@ declare class ErrorResponse extends BaseResponse {
27
27
  constructor(requestUuid: string, error: string, stack?: string | undefined);
28
28
  }
29
29
 
30
- declare global {
31
- interface Window {
32
- conduit: IConduitService;
33
- }
30
+ declare global {
31
+ interface Window {
32
+ conduit: IConduitService;
33
+ }
34
34
  }
35
35
 
36
36
  export { ELECTRON_APP_SERVICE_KEY, ElectronAdapter, ErrorResponse, IConduitService, IPC_MAIN_SERVICE_KEY };
package/package.json CHANGED
@@ -1,74 +1,74 @@
1
- {
2
- "name": "@oldzy/conduit-electron-adapter",
3
- "version": "1.0.11",
4
- "description": "Electron IPC adapter for @oldzy/conduit - enables seamless communication between main and renderer processes",
5
- "author": "oldzy",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/oldzy/conduit-electron-adapter.git"
10
- },
11
- "main": "dist/index.js",
12
- "types": "dist/index.d.ts",
13
- "exports": {
14
- ".": {
15
- "types": "./dist/index.d.ts",
16
- "require": "./dist/index.js",
17
- "import": "./dist/index.mjs"
18
- },
19
- "./preload": {
20
- "types": "./dist/preload.d.ts",
21
- "require": "./dist/preload.js",
22
- "import": "./dist/preload.mjs"
23
- }
24
- },
25
- "files": [
26
- "dist",
27
- "README.md",
28
- "LICENSE"
29
- ],
30
- "scripts": {
31
- "build": "tsup",
32
- "build:prod": "cross-env NODE_ENV=production tsup",
33
- "dev": "tsup --watch",
34
- "test": "vitest",
35
- "test:ui": "vitest --ui",
36
- "test:coverage": "vitest --coverage",
37
- "test:watch": "vitest --watch",
38
- "lint": "eslint src",
39
- "prepublishOnly": "npm run build:prod && npm test",
40
- "publish:npm": "npm run build:prod && npm test && npm publish --access public"
41
- },
42
- "keywords": [
43
- "conduit",
44
- "electron",
45
- "ipc",
46
- "adapter",
47
- "electron-adapter",
48
- "electron-ipc",
49
- "mediator",
50
- "request-response",
51
- "streaming",
52
- "contextbridge",
53
- "preload"
54
- ],
55
- "devDependencies": {
56
- "@swc/core": "^1.15.2",
57
- "@types/node": "^24.10.1",
58
- "@vitest/coverage-v8": "^4.0.9",
59
- "@vitest/ui": "^4.0.9",
60
- "cross-env": "^10.1.0",
61
- "eslint": "^9.39.1",
62
- "tsup": "^8.5.1",
63
- "typescript": "^5.9.3",
64
- "unplugin-swc": "^1.5.8",
65
- "vitest": "^4.0.9"
66
- },
67
- "dependencies": {
68
- "@oldzy/conduit": "^1.0.10",
69
- "electron": "^39.2.7"
70
- },
71
- "engines": {
72
- "node": ">=18.0.0"
73
- }
74
- }
1
+ {
2
+ "name": "@oldzy/conduit-electron-adapter",
3
+ "version": "1.1.0",
4
+ "description": "Electron IPC adapter for @oldzy/conduit - enables seamless communication between main and renderer processes",
5
+ "author": "oldzy",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/oldzy/conduit-electron-adapter.git"
10
+ },
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "require": "./dist/index.js",
17
+ "import": "./dist/index.mjs"
18
+ },
19
+ "./preload": {
20
+ "types": "./dist/preload.d.ts",
21
+ "require": "./dist/preload.js",
22
+ "import": "./dist/preload.mjs"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsup",
32
+ "build:prod": "cross-env NODE_ENV=production tsup",
33
+ "dev": "tsup --watch",
34
+ "test": "vitest",
35
+ "test:ui": "vitest --ui",
36
+ "test:coverage": "vitest --coverage",
37
+ "test:watch": "vitest --watch",
38
+ "lint": "eslint src",
39
+ "prepublishOnly": "npm run build:prod && npm test",
40
+ "publish:npm": "npm run build:prod && npm test && npm publish --access public"
41
+ },
42
+ "keywords": [
43
+ "conduit",
44
+ "electron",
45
+ "ipc",
46
+ "adapter",
47
+ "electron-adapter",
48
+ "electron-ipc",
49
+ "mediator",
50
+ "request-response",
51
+ "streaming",
52
+ "contextbridge",
53
+ "preload"
54
+ ],
55
+ "devDependencies": {
56
+ "@swc/core": "^1.15.2",
57
+ "@types/node": "^24.10.1",
58
+ "@vitest/coverage-v8": "^4.0.9",
59
+ "@vitest/ui": "^4.0.9",
60
+ "cross-env": "^10.1.0",
61
+ "eslint": "^9.39.1",
62
+ "tsup": "^8.5.1",
63
+ "typescript": "^5.9.3",
64
+ "unplugin-swc": "^1.5.8",
65
+ "vitest": "^4.0.9"
66
+ },
67
+ "dependencies": {
68
+ "@oldzy/conduit": "^1.1.0",
69
+ "electron": "^39.2.7"
70
+ },
71
+ "engines": {
72
+ "node": ">=18.0.0"
73
+ }
74
+ }