@symbiosis-lab/moss-api 0.1.0 → 0.3.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/dist/index.d.mts +298 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +296 -1
- package/dist/index.mjs.map +1 -1
- package/dist/testing/index.d.mts +253 -0
- package/dist/testing/index.d.mts.map +1 -0
- package/dist/testing/index.mjs +359 -0
- package/dist/testing/index.mjs.map +1 -0
- package/package.json +5 -1
package/dist/index.d.mts
CHANGED
|
@@ -137,6 +137,13 @@ interface TauriCore {
|
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* Get the Tauri core API
|
|
140
|
+
*
|
|
141
|
+
* @deprecated Use higher-level APIs instead:
|
|
142
|
+
* - File operations: `readFile`, `writeFile`, `listFiles`, `fileExists`
|
|
143
|
+
* - HTTP: `fetchUrl`, `downloadAsset`
|
|
144
|
+
* - Binary execution: `executeBinary`
|
|
145
|
+
* - Cookies: `getPluginCookie`, `setPluginCookie`
|
|
146
|
+
*
|
|
140
147
|
* @throws Error if Tauri is not available
|
|
141
148
|
*/
|
|
142
149
|
declare function getTauriCore(): TauriCore;
|
|
@@ -207,5 +214,295 @@ declare function openBrowser(url: string): Promise<void>;
|
|
|
207
214
|
*/
|
|
208
215
|
declare function closeBrowser(): Promise<void>;
|
|
209
216
|
//#endregion
|
|
210
|
-
|
|
217
|
+
//#region src/utils/filesystem.d.ts
|
|
218
|
+
/**
|
|
219
|
+
* File system operations for Moss plugins
|
|
220
|
+
*
|
|
221
|
+
* These functions abstract away the underlying Tauri commands,
|
|
222
|
+
* providing a clean API for plugins to read/write project files.
|
|
223
|
+
*/
|
|
224
|
+
/**
|
|
225
|
+
* Read a file from the project directory
|
|
226
|
+
*
|
|
227
|
+
* @param projectPath - Absolute path to the project directory
|
|
228
|
+
* @param relativePath - Path relative to the project root
|
|
229
|
+
* @returns File contents as a string
|
|
230
|
+
* @throws Error if file cannot be read
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const content = await readFile("/path/to/project", "src/index.ts");
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
declare function readFile(projectPath: string, relativePath: string): Promise<string>;
|
|
238
|
+
/**
|
|
239
|
+
* Write content to a file in the project directory
|
|
240
|
+
*
|
|
241
|
+
* Creates parent directories if they don't exist.
|
|
242
|
+
*
|
|
243
|
+
* @param projectPath - Absolute path to the project directory
|
|
244
|
+
* @param relativePath - Path relative to the project root
|
|
245
|
+
* @param content - Content to write to the file
|
|
246
|
+
* @throws Error if file cannot be written
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* await writeFile("/path/to/project", "output/result.md", "# Hello World");
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
declare function writeFile(projectPath: string, relativePath: string, content: string): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* List all files in a project directory
|
|
256
|
+
*
|
|
257
|
+
* Returns file paths relative to the project root.
|
|
258
|
+
*
|
|
259
|
+
* @param projectPath - Absolute path to the project directory
|
|
260
|
+
* @returns Array of relative file paths
|
|
261
|
+
* @throws Error if directory cannot be listed
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const files = await listFiles("/path/to/project");
|
|
266
|
+
* // ["src/index.ts", "package.json", "README.md"]
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
declare function listFiles(projectPath: string): Promise<string[]>;
|
|
270
|
+
/**
|
|
271
|
+
* Check if a file exists in the project directory
|
|
272
|
+
*
|
|
273
|
+
* @param projectPath - Absolute path to the project directory
|
|
274
|
+
* @param relativePath - Path relative to the project root
|
|
275
|
+
* @returns true if file exists, false otherwise
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* if (await fileExists("/path/to/project", "config.json")) {
|
|
280
|
+
* // load config
|
|
281
|
+
* }
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
declare function fileExists(projectPath: string, relativePath: string): Promise<boolean>;
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/utils/http.d.ts
|
|
287
|
+
/**
|
|
288
|
+
* HTTP operations for Moss plugins
|
|
289
|
+
*
|
|
290
|
+
* These functions provide HTTP capabilities that bypass browser CORS
|
|
291
|
+
* restrictions by using Rust's HTTP client under the hood.
|
|
292
|
+
*/
|
|
293
|
+
/**
|
|
294
|
+
* Options for HTTP fetch requests
|
|
295
|
+
*/
|
|
296
|
+
interface FetchOptions {
|
|
297
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
298
|
+
timeoutMs?: number;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Result from an HTTP fetch operation
|
|
302
|
+
*/
|
|
303
|
+
interface FetchResult {
|
|
304
|
+
/** HTTP status code */
|
|
305
|
+
status: number;
|
|
306
|
+
/** Whether the request was successful (2xx status) */
|
|
307
|
+
ok: boolean;
|
|
308
|
+
/** Content-Type header from response */
|
|
309
|
+
contentType: string | null;
|
|
310
|
+
/** Response body as Uint8Array */
|
|
311
|
+
body: Uint8Array;
|
|
312
|
+
/** Get response body as text */
|
|
313
|
+
text(): string;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Options for asset download
|
|
317
|
+
*/
|
|
318
|
+
interface DownloadOptions {
|
|
319
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
320
|
+
timeoutMs?: number;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Result from an asset download operation
|
|
324
|
+
*/
|
|
325
|
+
interface DownloadResult {
|
|
326
|
+
/** HTTP status code */
|
|
327
|
+
status: number;
|
|
328
|
+
/** Whether the request was successful (2xx status) */
|
|
329
|
+
ok: boolean;
|
|
330
|
+
/** Content-Type header from response */
|
|
331
|
+
contentType: string | null;
|
|
332
|
+
/** Number of bytes written to disk */
|
|
333
|
+
bytesWritten: number;
|
|
334
|
+
/** Actual path where file was saved (relative to project) */
|
|
335
|
+
actualPath: string;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Fetch a URL using Rust's HTTP client (bypasses CORS)
|
|
339
|
+
*
|
|
340
|
+
* @param url - URL to fetch
|
|
341
|
+
* @param options - Optional fetch configuration
|
|
342
|
+
* @returns Fetch result with status, body, and helpers
|
|
343
|
+
* @throws Error if network request fails
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const result = await fetchUrl("https://api.example.com/data");
|
|
348
|
+
* if (result.ok) {
|
|
349
|
+
* const data = JSON.parse(result.text());
|
|
350
|
+
* }
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
declare function fetchUrl(url: string, options?: FetchOptions): Promise<FetchResult>;
|
|
354
|
+
/**
|
|
355
|
+
* Download a URL and save directly to disk
|
|
356
|
+
*
|
|
357
|
+
* Downloads the file and writes it directly to disk without passing
|
|
358
|
+
* the binary data through JavaScript. The filename is derived from
|
|
359
|
+
* the URL, and file extension is inferred from Content-Type if needed.
|
|
360
|
+
*
|
|
361
|
+
* @param url - URL to download
|
|
362
|
+
* @param projectPath - Absolute path to the project directory
|
|
363
|
+
* @param targetDir - Target directory within project (e.g., "assets")
|
|
364
|
+
* @param options - Optional download configuration
|
|
365
|
+
* @returns Download result with actual path where file was saved
|
|
366
|
+
* @throws Error if download or write fails
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* const result = await downloadAsset(
|
|
371
|
+
* "https://example.com/image",
|
|
372
|
+
* "/path/to/project",
|
|
373
|
+
* "assets"
|
|
374
|
+
* );
|
|
375
|
+
* if (result.ok) {
|
|
376
|
+
* console.log(`Saved to ${result.actualPath}`); // e.g., "assets/image.png"
|
|
377
|
+
* }
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
declare function downloadAsset(url: string, projectPath: string, targetDir: string, options?: DownloadOptions): Promise<DownloadResult>;
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/utils/binary.d.ts
|
|
383
|
+
/**
|
|
384
|
+
* Binary execution for Moss plugins
|
|
385
|
+
*
|
|
386
|
+
* Allows plugins to execute external binaries (git, npm, etc.)
|
|
387
|
+
* in a controlled environment.
|
|
388
|
+
*/
|
|
389
|
+
/**
|
|
390
|
+
* Options for executing a binary
|
|
391
|
+
*/
|
|
392
|
+
interface ExecuteOptions {
|
|
393
|
+
/** Path to the binary (can be just the name if in PATH) */
|
|
394
|
+
binaryPath: string;
|
|
395
|
+
/** Arguments to pass to the binary */
|
|
396
|
+
args: string[];
|
|
397
|
+
/** Working directory for execution */
|
|
398
|
+
workingDir: string;
|
|
399
|
+
/** Timeout in milliseconds (default: 60000) */
|
|
400
|
+
timeoutMs?: number;
|
|
401
|
+
/** Additional environment variables */
|
|
402
|
+
env?: Record<string, string>;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Result from binary execution
|
|
406
|
+
*/
|
|
407
|
+
interface ExecuteResult {
|
|
408
|
+
/** Whether the command succeeded (exit code 0) */
|
|
409
|
+
success: boolean;
|
|
410
|
+
/** Exit code from the process */
|
|
411
|
+
exitCode: number;
|
|
412
|
+
/** Standard output from the process */
|
|
413
|
+
stdout: string;
|
|
414
|
+
/** Standard error output from the process */
|
|
415
|
+
stderr: string;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Execute an external binary
|
|
419
|
+
*
|
|
420
|
+
* @param options - Execution options including binary path, args, and working directory
|
|
421
|
+
* @returns Execution result with stdout, stderr, and exit code
|
|
422
|
+
* @throws Error if binary cannot be executed
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```typescript
|
|
426
|
+
* // Run git status
|
|
427
|
+
* const result = await executeBinary({
|
|
428
|
+
* binaryPath: "git",
|
|
429
|
+
* args: ["status"],
|
|
430
|
+
* workingDir: "/path/to/repo",
|
|
431
|
+
* });
|
|
432
|
+
*
|
|
433
|
+
* if (result.success) {
|
|
434
|
+
* console.log(result.stdout);
|
|
435
|
+
* } else {
|
|
436
|
+
* console.error(result.stderr);
|
|
437
|
+
* }
|
|
438
|
+
* ```
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* // Run npm install with timeout
|
|
443
|
+
* const result = await executeBinary({
|
|
444
|
+
* binaryPath: "npm",
|
|
445
|
+
* args: ["install"],
|
|
446
|
+
* workingDir: "/path/to/project",
|
|
447
|
+
* timeoutMs: 120000,
|
|
448
|
+
* env: { NODE_ENV: "production" },
|
|
449
|
+
* });
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
declare function executeBinary(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/utils/cookies.d.ts
|
|
455
|
+
/**
|
|
456
|
+
* Cookie management for Moss plugins
|
|
457
|
+
*
|
|
458
|
+
* Allows plugins to store and retrieve authentication cookies
|
|
459
|
+
* for external services (e.g., Matters.town, GitHub).
|
|
460
|
+
*/
|
|
461
|
+
/**
|
|
462
|
+
* A cookie stored for plugin authentication
|
|
463
|
+
*/
|
|
464
|
+
interface Cookie {
|
|
465
|
+
/** Cookie name */
|
|
466
|
+
name: string;
|
|
467
|
+
/** Cookie value */
|
|
468
|
+
value: string;
|
|
469
|
+
/** Optional domain for the cookie */
|
|
470
|
+
domain?: string;
|
|
471
|
+
/** Optional path for the cookie */
|
|
472
|
+
path?: string;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Get stored cookies for a plugin
|
|
476
|
+
*
|
|
477
|
+
* @param pluginName - Name of the plugin
|
|
478
|
+
* @param projectPath - Absolute path to the project directory
|
|
479
|
+
* @returns Array of stored cookies
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```typescript
|
|
483
|
+
* const cookies = await getPluginCookie("matters-syndicator", "/path/to/project");
|
|
484
|
+
* const token = cookies.find(c => c.name === "__access_token");
|
|
485
|
+
* if (token) {
|
|
486
|
+
* // Use token for authenticated requests
|
|
487
|
+
* }
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
declare function getPluginCookie(pluginName: string, projectPath: string): Promise<Cookie[]>;
|
|
491
|
+
/**
|
|
492
|
+
* Store cookies for a plugin
|
|
493
|
+
*
|
|
494
|
+
* @param pluginName - Name of the plugin
|
|
495
|
+
* @param projectPath - Absolute path to the project directory
|
|
496
|
+
* @param cookies - Array of cookies to store
|
|
497
|
+
*
|
|
498
|
+
* @example
|
|
499
|
+
* ```typescript
|
|
500
|
+
* await setPluginCookie("my-plugin", "/path/to/project", [
|
|
501
|
+
* { name: "session", value: "abc123" }
|
|
502
|
+
* ]);
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
declare function setPluginCookie(pluginName: string, projectPath: string, cookies: Cookie[]): Promise<void>;
|
|
506
|
+
//#endregion
|
|
507
|
+
export { AfterDeployContext, ArticleInfo, BaseContext, BeforeBuildContext, CompleteMessage, Cookie, DeploymentInfo, DownloadOptions, DownloadResult, ErrorMessage, ExecuteOptions, ExecuteResult, FetchOptions, FetchResult, HookResult, LogMessage, OnBuildContext, OnDeployContext, PluginCategory, PluginManifest, PluginMessage, ProgressMessage, ProjectInfo, SourceFiles, TauriCore, closeBrowser, downloadAsset, error, executeBinary, fetchUrl, fileExists, getMessageContext, getPluginCookie, getTauriCore, isTauriAvailable, listFiles, log, openBrowser, readFile, reportComplete, reportError, reportProgress, sendMessage, setMessageContext, setPluginCookie, warn, writeFile };
|
|
211
508
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/plugin.ts","../src/types/context.ts","../src/types/hooks.ts","../src/types/messages.ts","../src/utils/tauri.ts","../src/utils/messaging.ts","../src/utils/logger.ts","../src/utils/browser.ts"],"sourcesContent":[],"mappings":";;AAIA;AAOA;AAWY,UAlBK,WAAA,CAkBS;;;;ECbT,aAAA,CAAW,EAAA,MAAA;AAU5B;AAKiB,UDbA,cAAA,CCae;EAOf,IAAA,EAAA,MAAA;EAQA,OAAA,EAAA,MAAA;EAGL,KAAA,EAAA,MAAA;EACG,QAAA,ED5BH,cC4BG;EAJ6B,WAAA,CAAA,EAAA,MAAA;EAAW,IAAA,CAAA,EAAA,MAAA;EAUtC,MAAA,CAAA,EAAA,MAAW;EAUX,MAAA,CAAA,EDxCN,MCwCiB,CAAA,MAAA,EAAA,OAIb,CAAA;AASf;KDlDY,cAAA;;;;;;ACbK,UAAA,WAAA,CAAW;EAUX,YAAA,EAAA,MAAA;EAKA,QAAA,EAAA,MAAA;EAOA,YAAA,EAnBD,WAmBiB;EAQhB,MAAA,EA1BP,MA0BO,CAAA,MAAmB,EAAA,OAAA,CAAA;;;;;AAUnB,UA9BA,kBAAA,SAA2B,WA8BhB,CAAA,CAU5B;AAaA;;;UAhDiB,cAAA,SAAuB;ECfvB,YAAA,EDgBD,WCbD;;;;ACLf;AACI,UFuBa,eAAA,SAAwB,WEvBrC,CAAA;EACA,UAAA,EAAA,MAAA;EACA,UAAA,EAAA,MAAA,EAAA;;;AAGJ;AAMA;AAQiB,UFYA,kBAAA,SAA2B,WEZf,CAAA;EAOZ,UAAA,EAAA,MAAe;;YFQpB;eACG;AGvCf;;;;AACqE,UH4CpD,WAAA,CG5CoD;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/plugin.ts","../src/types/context.ts","../src/types/hooks.ts","../src/types/messages.ts","../src/utils/tauri.ts","../src/utils/messaging.ts","../src/utils/logger.ts","../src/utils/browser.ts","../src/utils/filesystem.ts","../src/utils/http.ts","../src/utils/binary.ts","../src/utils/cookies.ts"],"sourcesContent":[],"mappings":";;AAIA;AAOA;AAWY,UAlBK,WAAA,CAkBS;;;;ECbT,aAAA,CAAW,EAAA,M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AA,MAAA;EAJ6B;EAAW,MAAA,CAAA,EAAA,MAAA;EAUtC;EAUA,IAAA,CAAA,EAAA,MAAA;AAajB;;;;AC/DA;;;;ACFA;;;;;;AAMA;AAMA;AAQA;AAOiB,iBQaK,eAAA,CRbU,UAAA,EAAA,MAAA,EAAA,WAAA,EAAA,MAAA,CAAA,EQgB7B,ORhB6B,CQgBrB,MRhBqB,EAAA,CAAA;;;;AC9BhC;;;;;AAqBA;AAWA;;;;ACtBA;AAQgB,iBMiDM,eAAA,CNjDW,UAAA,EAAA,MAAA,EAAA,WAAA,EAAA,MAAA,EAAA,OAAA,EMoDtB,MNpDsB,EAAA,CAAA,EMqD9B,ONrD8B,CAAA,IAAA,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
//#region src/utils/tauri.ts
|
|
2
2
|
/**
|
|
3
3
|
* Get the Tauri core API
|
|
4
|
+
*
|
|
5
|
+
* @deprecated Use higher-level APIs instead:
|
|
6
|
+
* - File operations: `readFile`, `writeFile`, `listFiles`, `fileExists`
|
|
7
|
+
* - HTTP: `fetchUrl`, `downloadAsset`
|
|
8
|
+
* - Binary execution: `executeBinary`
|
|
9
|
+
* - Cookies: `getPluginCookie`, `setPluginCookie`
|
|
10
|
+
*
|
|
4
11
|
* @throws Error if Tauri is not available
|
|
5
12
|
*/
|
|
6
13
|
function getTauriCore() {
|
|
@@ -139,5 +146,293 @@ async function closeBrowser() {
|
|
|
139
146
|
}
|
|
140
147
|
|
|
141
148
|
//#endregion
|
|
142
|
-
|
|
149
|
+
//#region src/utils/filesystem.ts
|
|
150
|
+
/**
|
|
151
|
+
* File system operations for Moss plugins
|
|
152
|
+
*
|
|
153
|
+
* These functions abstract away the underlying Tauri commands,
|
|
154
|
+
* providing a clean API for plugins to read/write project files.
|
|
155
|
+
*/
|
|
156
|
+
/**
|
|
157
|
+
* Read a file from the project directory
|
|
158
|
+
*
|
|
159
|
+
* @param projectPath - Absolute path to the project directory
|
|
160
|
+
* @param relativePath - Path relative to the project root
|
|
161
|
+
* @returns File contents as a string
|
|
162
|
+
* @throws Error if file cannot be read
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const content = await readFile("/path/to/project", "src/index.ts");
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
async function readFile(projectPath, relativePath) {
|
|
170
|
+
return getTauriCore().invoke("read_project_file", {
|
|
171
|
+
projectPath,
|
|
172
|
+
relativePath
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Write content to a file in the project directory
|
|
177
|
+
*
|
|
178
|
+
* Creates parent directories if they don't exist.
|
|
179
|
+
*
|
|
180
|
+
* @param projectPath - Absolute path to the project directory
|
|
181
|
+
* @param relativePath - Path relative to the project root
|
|
182
|
+
* @param content - Content to write to the file
|
|
183
|
+
* @throws Error if file cannot be written
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* await writeFile("/path/to/project", "output/result.md", "# Hello World");
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
async function writeFile(projectPath, relativePath, content) {
|
|
191
|
+
await getTauriCore().invoke("write_project_file", {
|
|
192
|
+
projectPath,
|
|
193
|
+
relativePath,
|
|
194
|
+
data: content
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* List all files in a project directory
|
|
199
|
+
*
|
|
200
|
+
* Returns file paths relative to the project root.
|
|
201
|
+
*
|
|
202
|
+
* @param projectPath - Absolute path to the project directory
|
|
203
|
+
* @returns Array of relative file paths
|
|
204
|
+
* @throws Error if directory cannot be listed
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const files = await listFiles("/path/to/project");
|
|
209
|
+
* // ["src/index.ts", "package.json", "README.md"]
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
async function listFiles(projectPath) {
|
|
213
|
+
return getTauriCore().invoke("list_project_files", { projectPath });
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check if a file exists in the project directory
|
|
217
|
+
*
|
|
218
|
+
* @param projectPath - Absolute path to the project directory
|
|
219
|
+
* @param relativePath - Path relative to the project root
|
|
220
|
+
* @returns true if file exists, false otherwise
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* if (await fileExists("/path/to/project", "config.json")) {
|
|
225
|
+
* // load config
|
|
226
|
+
* }
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
async function fileExists(projectPath, relativePath) {
|
|
230
|
+
try {
|
|
231
|
+
await readFile(projectPath, relativePath);
|
|
232
|
+
return true;
|
|
233
|
+
} catch {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/utils/http.ts
|
|
240
|
+
/**
|
|
241
|
+
* HTTP operations for Moss plugins
|
|
242
|
+
*
|
|
243
|
+
* These functions provide HTTP capabilities that bypass browser CORS
|
|
244
|
+
* restrictions by using Rust's HTTP client under the hood.
|
|
245
|
+
*/
|
|
246
|
+
/**
|
|
247
|
+
* Fetch a URL using Rust's HTTP client (bypasses CORS)
|
|
248
|
+
*
|
|
249
|
+
* @param url - URL to fetch
|
|
250
|
+
* @param options - Optional fetch configuration
|
|
251
|
+
* @returns Fetch result with status, body, and helpers
|
|
252
|
+
* @throws Error if network request fails
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const result = await fetchUrl("https://api.example.com/data");
|
|
257
|
+
* if (result.ok) {
|
|
258
|
+
* const data = JSON.parse(result.text());
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
async function fetchUrl(url, options = {}) {
|
|
263
|
+
const { timeoutMs = 3e4 } = options;
|
|
264
|
+
const result = await getTauriCore().invoke("fetch_url", {
|
|
265
|
+
url,
|
|
266
|
+
timeoutMs
|
|
267
|
+
});
|
|
268
|
+
const binaryString = atob(result.body_base64);
|
|
269
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
270
|
+
for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
|
|
271
|
+
return {
|
|
272
|
+
status: result.status,
|
|
273
|
+
ok: result.ok,
|
|
274
|
+
contentType: result.content_type,
|
|
275
|
+
body: bytes,
|
|
276
|
+
text() {
|
|
277
|
+
return new TextDecoder().decode(bytes);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Download a URL and save directly to disk
|
|
283
|
+
*
|
|
284
|
+
* Downloads the file and writes it directly to disk without passing
|
|
285
|
+
* the binary data through JavaScript. The filename is derived from
|
|
286
|
+
* the URL, and file extension is inferred from Content-Type if needed.
|
|
287
|
+
*
|
|
288
|
+
* @param url - URL to download
|
|
289
|
+
* @param projectPath - Absolute path to the project directory
|
|
290
|
+
* @param targetDir - Target directory within project (e.g., "assets")
|
|
291
|
+
* @param options - Optional download configuration
|
|
292
|
+
* @returns Download result with actual path where file was saved
|
|
293
|
+
* @throws Error if download or write fails
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const result = await downloadAsset(
|
|
298
|
+
* "https://example.com/image",
|
|
299
|
+
* "/path/to/project",
|
|
300
|
+
* "assets"
|
|
301
|
+
* );
|
|
302
|
+
* if (result.ok) {
|
|
303
|
+
* console.log(`Saved to ${result.actualPath}`); // e.g., "assets/image.png"
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
async function downloadAsset(url, projectPath, targetDir, options = {}) {
|
|
308
|
+
const { timeoutMs = 3e4 } = options;
|
|
309
|
+
const result = await getTauriCore().invoke("download_asset", {
|
|
310
|
+
url,
|
|
311
|
+
projectPath,
|
|
312
|
+
targetDir,
|
|
313
|
+
timeoutMs
|
|
314
|
+
});
|
|
315
|
+
return {
|
|
316
|
+
status: result.status,
|
|
317
|
+
ok: result.ok,
|
|
318
|
+
contentType: result.content_type,
|
|
319
|
+
bytesWritten: result.bytes_written,
|
|
320
|
+
actualPath: result.actual_path
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/utils/binary.ts
|
|
326
|
+
/**
|
|
327
|
+
* Binary execution for Moss plugins
|
|
328
|
+
*
|
|
329
|
+
* Allows plugins to execute external binaries (git, npm, etc.)
|
|
330
|
+
* in a controlled environment.
|
|
331
|
+
*/
|
|
332
|
+
/**
|
|
333
|
+
* Execute an external binary
|
|
334
|
+
*
|
|
335
|
+
* @param options - Execution options including binary path, args, and working directory
|
|
336
|
+
* @returns Execution result with stdout, stderr, and exit code
|
|
337
|
+
* @throws Error if binary cannot be executed
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```typescript
|
|
341
|
+
* // Run git status
|
|
342
|
+
* const result = await executeBinary({
|
|
343
|
+
* binaryPath: "git",
|
|
344
|
+
* args: ["status"],
|
|
345
|
+
* workingDir: "/path/to/repo",
|
|
346
|
+
* });
|
|
347
|
+
*
|
|
348
|
+
* if (result.success) {
|
|
349
|
+
* console.log(result.stdout);
|
|
350
|
+
* } else {
|
|
351
|
+
* console.error(result.stderr);
|
|
352
|
+
* }
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```typescript
|
|
357
|
+
* // Run npm install with timeout
|
|
358
|
+
* const result = await executeBinary({
|
|
359
|
+
* binaryPath: "npm",
|
|
360
|
+
* args: ["install"],
|
|
361
|
+
* workingDir: "/path/to/project",
|
|
362
|
+
* timeoutMs: 120000,
|
|
363
|
+
* env: { NODE_ENV: "production" },
|
|
364
|
+
* });
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
async function executeBinary(options) {
|
|
368
|
+
const { binaryPath, args, workingDir, timeoutMs = 6e4, env } = options;
|
|
369
|
+
const result = await getTauriCore().invoke("execute_binary", {
|
|
370
|
+
binaryPath,
|
|
371
|
+
args,
|
|
372
|
+
workingDir,
|
|
373
|
+
timeoutMs,
|
|
374
|
+
env
|
|
375
|
+
});
|
|
376
|
+
return {
|
|
377
|
+
success: result.success,
|
|
378
|
+
exitCode: result.exit_code,
|
|
379
|
+
stdout: result.stdout,
|
|
380
|
+
stderr: result.stderr
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/utils/cookies.ts
|
|
386
|
+
/**
|
|
387
|
+
* Cookie management for Moss plugins
|
|
388
|
+
*
|
|
389
|
+
* Allows plugins to store and retrieve authentication cookies
|
|
390
|
+
* for external services (e.g., Matters.town, GitHub).
|
|
391
|
+
*/
|
|
392
|
+
/**
|
|
393
|
+
* Get stored cookies for a plugin
|
|
394
|
+
*
|
|
395
|
+
* @param pluginName - Name of the plugin
|
|
396
|
+
* @param projectPath - Absolute path to the project directory
|
|
397
|
+
* @returns Array of stored cookies
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```typescript
|
|
401
|
+
* const cookies = await getPluginCookie("matters-syndicator", "/path/to/project");
|
|
402
|
+
* const token = cookies.find(c => c.name === "__access_token");
|
|
403
|
+
* if (token) {
|
|
404
|
+
* // Use token for authenticated requests
|
|
405
|
+
* }
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
async function getPluginCookie(pluginName, projectPath) {
|
|
409
|
+
return getTauriCore().invoke("get_plugin_cookie", {
|
|
410
|
+
pluginName,
|
|
411
|
+
projectPath
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Store cookies for a plugin
|
|
416
|
+
*
|
|
417
|
+
* @param pluginName - Name of the plugin
|
|
418
|
+
* @param projectPath - Absolute path to the project directory
|
|
419
|
+
* @param cookies - Array of cookies to store
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```typescript
|
|
423
|
+
* await setPluginCookie("my-plugin", "/path/to/project", [
|
|
424
|
+
* { name: "session", value: "abc123" }
|
|
425
|
+
* ]);
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
async function setPluginCookie(pluginName, projectPath, cookies) {
|
|
429
|
+
await getTauriCore().invoke("set_plugin_cookie", {
|
|
430
|
+
pluginName,
|
|
431
|
+
projectPath,
|
|
432
|
+
cookies
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
//#endregion
|
|
437
|
+
export { closeBrowser, downloadAsset, error, executeBinary, fetchUrl, fileExists, getMessageContext, getPluginCookie, getTauriCore, isTauriAvailable, listFiles, log, openBrowser, readFile, reportComplete, reportError, reportProgress, sendMessage, setMessageContext, setPluginCookie, warn, writeFile };
|
|
143
438
|
//# sourceMappingURL=index.mjs.map
|