@auroraview/sdk 0.3.21 → 0.3.22

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 (2) hide show
  1. package/README.md +316 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,316 @@
1
+ # @auroraview/sdk
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@auroraview/sdk.svg)](https://www.npmjs.com/package/@auroraview/sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Framework-agnostic SDK for AuroraView WebView bridge. Provides type-safe APIs for communication between JavaScript and Python in AuroraView applications.
7
+
8
+ ## Features
9
+
10
+ - 🎯 **Type-safe** - Full TypeScript support with comprehensive type definitions
11
+ - 🔌 **Framework Adapters** - First-class support for React and Vue 3
12
+ - 📡 **IPC Communication** - Call Python methods, invoke plugin commands, and emit events
13
+ - 🔄 **State Sync** - Reactive shared state between JavaScript and Python
14
+ - 📁 **File System API** - Read, write, and manage files
15
+ - 💬 **Dialog API** - Native file dialogs and message boxes
16
+ - 📋 **Clipboard API** - Read and write clipboard content
17
+ - 🐚 **Shell API** - Execute commands and open URLs
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @auroraview/sdk
23
+ # or
24
+ pnpm add @auroraview/sdk
25
+ # or
26
+ yarn add @auroraview/sdk
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ### Vanilla JavaScript/TypeScript
32
+
33
+ ```typescript
34
+ import { createAuroraView } from '@auroraview/sdk';
35
+
36
+ const av = createAuroraView();
37
+
38
+ // Wait for bridge to be ready
39
+ await av.whenReady();
40
+
41
+ // Call a Python method
42
+ const result = await av.call('api.greet', { name: 'World' });
43
+
44
+ // Invoke a plugin command
45
+ const files = await av.invoke('plugin:fs|read_dir', { path: '/tmp' });
46
+
47
+ // Subscribe to events
48
+ av.on('custom:event', (data) => {
49
+ console.log('Received:', data);
50
+ });
51
+
52
+ // Emit events to Python
53
+ av.emit('user:action', { type: 'click' });
54
+ ```
55
+
56
+ ### React
57
+
58
+ ```tsx
59
+ import { useAuroraView, useAuroraEvent, useAuroraCall, useAuroraState } from '@auroraview/sdk/react';
60
+
61
+ function App() {
62
+ const { client, isReady } = useAuroraView();
63
+
64
+ // Subscribe to events
65
+ useAuroraEvent('notification', (data) => {
66
+ console.log('Notification:', data);
67
+ });
68
+
69
+ // Call API with loading/error states
70
+ const { execute, loading, data, error } = useAuroraCall<string>('api.greet');
71
+
72
+ // Reactive shared state
73
+ const [theme, setTheme] = useAuroraState<string>('theme', 'light');
74
+
75
+ return (
76
+ <div>
77
+ <button onClick={() => execute({ name: 'World' })} disabled={loading || !isReady}>
78
+ {loading ? 'Loading...' : 'Greet'}
79
+ </button>
80
+ {data && <p>Result: {data}</p>}
81
+ {error && <p>Error: {error.message}</p>}
82
+ <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
83
+ Theme: {theme}
84
+ </button>
85
+ </div>
86
+ );
87
+ }
88
+ ```
89
+
90
+ ### Vue 3
91
+
92
+ ```vue
93
+ <script setup lang="ts">
94
+ import { useAuroraView, useAuroraEvent, useAuroraCall, useAuroraState } from '@auroraview/sdk/vue';
95
+
96
+ const { client, isReady } = useAuroraView();
97
+
98
+ // Subscribe to events
99
+ useAuroraEvent('notification', (data) => {
100
+ console.log('Notification:', data);
101
+ });
102
+
103
+ // Call API with loading/error states
104
+ const { execute, loading, data, error } = useAuroraCall<string>('api.greet');
105
+
106
+ // Reactive shared state
107
+ const theme = useAuroraState<string>('theme', 'light');
108
+ </script>
109
+
110
+ <template>
111
+ <div>
112
+ <button @click="execute({ name: 'World' })" :disabled="loading || !isReady">
113
+ {{ loading ? 'Loading...' : 'Greet' }}
114
+ </button>
115
+ <p v-if="data">Result: {{ data }}</p>
116
+ <p v-if="error">Error: {{ error.message }}</p>
117
+ <button @click="theme = theme === 'light' ? 'dark' : 'light'">
118
+ Theme: {{ theme }}
119
+ </button>
120
+ </div>
121
+ </template>
122
+ ```
123
+
124
+ ## API Reference
125
+
126
+ ### Core Client
127
+
128
+ ```typescript
129
+ interface AuroraViewClient {
130
+ // RPC-style call to Python method
131
+ call<T>(method: string, params?: unknown): Promise<T>;
132
+
133
+ // Invoke plugin command
134
+ invoke<T>(cmd: string, args?: Record<string, unknown>): Promise<T>;
135
+
136
+ // Fire-and-forget event to Python
137
+ emit(event: string, data?: unknown): void;
138
+
139
+ // Subscribe to events from Python
140
+ on<T>(event: string, handler: (data: T) => void): () => void;
141
+
142
+ // Subscribe once
143
+ once<T>(event: string, handler: (data: T) => void): () => void;
144
+
145
+ // Unsubscribe
146
+ off(event: string, handler?: EventHandler): void;
147
+
148
+ // Check if bridge is ready
149
+ isReady(): boolean;
150
+
151
+ // Wait for bridge to be ready
152
+ whenReady(): Promise<AuroraViewClient>;
153
+
154
+ // Built-in APIs
155
+ readonly fs: FileSystemAPI | undefined;
156
+ readonly dialog: DialogAPI | undefined;
157
+ readonly clipboard: ClipboardAPI | undefined;
158
+ readonly shell: ShellAPI | undefined;
159
+ readonly state: AuroraViewState | undefined;
160
+ }
161
+ ```
162
+
163
+ ### React Hooks
164
+
165
+ | Hook | Description |
166
+ |------|-------------|
167
+ | `useAuroraView()` | Get client instance and ready state |
168
+ | `useAuroraEvent(event, handler)` | Subscribe to an event |
169
+ | `useAuroraEvents(events)` | Subscribe to multiple events |
170
+ | `useAuroraCall<T>(method)` | Call API with loading/error states |
171
+ | `useAuroraInvoke<T>(cmd)` | Invoke plugin with loading/error states |
172
+ | `useAuroraState<T>(key, default?)` | Reactive shared state |
173
+ | `useProcessEvents(options)` | Subscribe to process stdout/stderr/exit |
174
+
175
+ ### Vue Composables
176
+
177
+ | Composable | Description |
178
+ |------------|-------------|
179
+ | `useAuroraView()` | Get client ref and ready state |
180
+ | `useAuroraEvent(event, handler)` | Subscribe to an event |
181
+ | `useAuroraEvents(events)` | Subscribe to multiple events |
182
+ | `useAuroraCall<T>(method)` | Call API with reactive loading/error |
183
+ | `useAuroraInvoke<T>(cmd)` | Invoke plugin with reactive loading/error |
184
+ | `useAuroraState<T>(key, default?)` | Two-way reactive shared state |
185
+ | `useProcessEvents(options)` | Subscribe to process events |
186
+
187
+ ### File System API
188
+
189
+ ```typescript
190
+ const av = createAuroraView();
191
+
192
+ // Read file
193
+ const content = await av.fs?.readFile('/path/to/file.txt');
194
+
195
+ // Write file
196
+ await av.fs?.writeFile('/path/to/file.txt', 'Hello World');
197
+
198
+ // Read directory
199
+ const entries = await av.fs?.readDir('/path/to/dir', true); // recursive
200
+
201
+ // Check existence
202
+ const exists = await av.fs?.exists('/path/to/file.txt');
203
+
204
+ // Get file stats
205
+ const stat = await av.fs?.stat('/path/to/file.txt');
206
+
207
+ // Create directory
208
+ await av.fs?.createDir('/path/to/new/dir', true); // recursive
209
+
210
+ // Copy/Move/Delete
211
+ await av.fs?.copy('/from', '/to');
212
+ await av.fs?.rename('/from', '/to');
213
+ await av.fs?.remove('/path', true); // recursive
214
+ ```
215
+
216
+ ### Dialog API
217
+
218
+ ```typescript
219
+ const av = createAuroraView();
220
+
221
+ // Open file dialog
222
+ const { path, cancelled } = await av.dialog?.openFile({
223
+ title: 'Select File',
224
+ filters: [{ name: 'Images', extensions: ['png', 'jpg'] }]
225
+ });
226
+
227
+ // Open folder dialog
228
+ const { path } = await av.dialog?.openFolder();
229
+
230
+ // Save file dialog
231
+ const { path } = await av.dialog?.saveFile({
232
+ defaultName: 'document.txt'
233
+ });
234
+
235
+ // Message dialogs
236
+ await av.dialog?.info('Operation completed', 'Success');
237
+ await av.dialog?.warning('Are you sure?', 'Warning');
238
+ await av.dialog?.error('Something went wrong', 'Error');
239
+
240
+ // Confirmation
241
+ const confirmed = await av.dialog?.ask('Delete this file?', 'Confirm');
242
+ ```
243
+
244
+ ### Clipboard API
245
+
246
+ ```typescript
247
+ const av = createAuroraView();
248
+
249
+ // Text
250
+ await av.clipboard?.writeText('Hello');
251
+ const text = await av.clipboard?.readText();
252
+
253
+ // Image (base64)
254
+ const imageData = await av.clipboard?.readImage();
255
+ await av.clipboard?.writeImage(base64Data);
256
+
257
+ // Clear
258
+ await av.clipboard?.clear();
259
+ ```
260
+
261
+ ### Shell API
262
+
263
+ ```typescript
264
+ const av = createAuroraView();
265
+
266
+ // Open URL in browser
267
+ await av.shell?.open('https://example.com');
268
+
269
+ // Open file with default app
270
+ await av.shell?.openPath('/path/to/document.pdf');
271
+
272
+ // Show in file manager
273
+ await av.shell?.showInFolder('/path/to/file');
274
+
275
+ // Execute command
276
+ const { code, stdout, stderr } = await av.shell?.execute('ls', ['-la']);
277
+
278
+ // Spawn process (non-blocking)
279
+ const { pid } = await av.shell?.spawn('node', ['server.js']);
280
+
281
+ // Get environment
282
+ const path = await av.shell?.getEnv('PATH');
283
+ const allEnv = await av.shell?.getEnvAll();
284
+ ```
285
+
286
+ ## TypeScript Support
287
+
288
+ The SDK is written in TypeScript and provides comprehensive type definitions. All APIs are fully typed.
289
+
290
+ ```typescript
291
+ import type {
292
+ AuroraViewClient,
293
+ EventHandler,
294
+ FileFilter,
295
+ DirEntry,
296
+ FileStat,
297
+ ExecuteResult,
298
+ // ... and more
299
+ } from '@auroraview/sdk';
300
+ ```
301
+
302
+ ## Browser Compatibility
303
+
304
+ The SDK is designed to work within AuroraView's WebView environment. It requires:
305
+ - ES2020+ support
306
+ - `window.auroraview` bridge object (injected by AuroraView runtime)
307
+
308
+ ## License
309
+
310
+ MIT © [AuroraView Contributors](https://github.com/loonghao/auroraview)
311
+
312
+ ## Links
313
+
314
+ - [Documentation](https://loonghao.github.io/auroraview/)
315
+ - [GitHub Repository](https://github.com/loonghao/auroraview)
316
+ - [Issue Tracker](https://github.com/loonghao/auroraview/issues)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auroraview/sdk",
3
- "version": "0.3.21",
3
+ "version": "0.3.22",
4
4
  "description": "Framework-agnostic SDK for AuroraView WebView bridge",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",