@symbiosis-lab/moss-api 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.
- package/LICENSE +21 -0
- package/README.md +142 -0
- package/dist/index.d.mts +211 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +143 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Symbiosis Lab
|
|
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
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# moss-api
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Symbiosis-Lab/moss-api/actions/workflows/ci.yml)
|
|
4
|
+
[](https://codecov.io/gh/Symbiosis-Lab/moss-api)
|
|
5
|
+
[](https://www.npmjs.com/package/moss-api)
|
|
6
|
+
|
|
7
|
+
Official API for building Moss plugins. Provides types and utilities for plugin development.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install moss-api
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Types
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import type {
|
|
21
|
+
OnDeployContext,
|
|
22
|
+
AfterDeployContext,
|
|
23
|
+
HookResult,
|
|
24
|
+
PluginManifest,
|
|
25
|
+
PluginCategory,
|
|
26
|
+
} from "moss-api";
|
|
27
|
+
|
|
28
|
+
// Define your plugin manifest
|
|
29
|
+
const manifest: PluginManifest = {
|
|
30
|
+
name: "my-plugin",
|
|
31
|
+
version: "1.0.0",
|
|
32
|
+
entry: "main.js",
|
|
33
|
+
category: "deployer",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Implement a hook
|
|
37
|
+
async function onDeploy(context: OnDeployContext): Promise<HookResult> {
|
|
38
|
+
// Your deployment logic here
|
|
39
|
+
return { success: true, message: "Deployed successfully" };
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Utilities
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import {
|
|
47
|
+
setMessageContext,
|
|
48
|
+
reportProgress,
|
|
49
|
+
reportError,
|
|
50
|
+
reportComplete,
|
|
51
|
+
log,
|
|
52
|
+
warn,
|
|
53
|
+
error,
|
|
54
|
+
} from "moss-api";
|
|
55
|
+
|
|
56
|
+
// Set plugin context (call once at plugin initialization)
|
|
57
|
+
setMessageContext("my-plugin", "on_deploy");
|
|
58
|
+
|
|
59
|
+
// Report progress during long operations
|
|
60
|
+
await reportProgress("deploying", 50, 100, "Uploading files...");
|
|
61
|
+
|
|
62
|
+
// Log messages
|
|
63
|
+
await log("Deployment started");
|
|
64
|
+
await warn("Deprecation warning");
|
|
65
|
+
await error("Something went wrong");
|
|
66
|
+
|
|
67
|
+
// Report errors with context
|
|
68
|
+
await reportError("Upload failed", "network", false);
|
|
69
|
+
|
|
70
|
+
// Report completion with result
|
|
71
|
+
await reportComplete({ url: "https://example.com" });
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Browser Utilities
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { openBrowser, closeBrowser } from "moss-api";
|
|
78
|
+
|
|
79
|
+
// Open authentication page in plugin browser window
|
|
80
|
+
await openBrowser("https://example.com/auth");
|
|
81
|
+
|
|
82
|
+
// Close browser window when done
|
|
83
|
+
await closeBrowser();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Tauri Utilities
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { getTauriCore, isTauriAvailable } from "moss-api";
|
|
90
|
+
|
|
91
|
+
// Check if running in Tauri environment
|
|
92
|
+
if (isTauriAvailable()) {
|
|
93
|
+
const core = getTauriCore();
|
|
94
|
+
const result = await core.invoke("my_command", { arg: "value" });
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### Types
|
|
101
|
+
|
|
102
|
+
| Type | Description |
|
|
103
|
+
|------|-------------|
|
|
104
|
+
| `ProjectInfo` | Project metadata (type, folders, files) |
|
|
105
|
+
| `PluginManifest` | Plugin configuration (name, version, entry, category) |
|
|
106
|
+
| `PluginCategory` | Union: "generator" \| "deployer" \| "syndicator" \| "enhancer" \| "processor" |
|
|
107
|
+
| `BaseContext` | Base hook context with project info |
|
|
108
|
+
| `BeforeBuildContext` | Context for before_build hook |
|
|
109
|
+
| `OnBuildContext` | Context for on_build hook (includes source files) |
|
|
110
|
+
| `OnDeployContext` | Context for on_deploy hook (includes output files) |
|
|
111
|
+
| `AfterDeployContext` | Context for after_deploy hook (includes articles, deployment) |
|
|
112
|
+
| `SourceFiles` | Categorized source files (markdown, pages, docx, other) |
|
|
113
|
+
| `ArticleInfo` | Article metadata for syndication |
|
|
114
|
+
| `DeploymentInfo` | Deployment result (method, url, timestamp, metadata) |
|
|
115
|
+
| `HookResult` | Standard hook return type |
|
|
116
|
+
| `PluginMessage` | Union of all message types |
|
|
117
|
+
| `LogMessage` | Log message with level |
|
|
118
|
+
| `ProgressMessage` | Progress update message |
|
|
119
|
+
| `ErrorMessage` | Error message with context and fatal flag |
|
|
120
|
+
| `CompleteMessage` | Completion message with result |
|
|
121
|
+
|
|
122
|
+
### Functions
|
|
123
|
+
|
|
124
|
+
| Function | Description |
|
|
125
|
+
|----------|-------------|
|
|
126
|
+
| `getTauriCore()` | Get Tauri API (throws if unavailable) |
|
|
127
|
+
| `isTauriAvailable()` | Check if Tauri is available |
|
|
128
|
+
| `setMessageContext(pluginName, hookName)` | Set context for messages |
|
|
129
|
+
| `getMessageContext()` | Get current message context |
|
|
130
|
+
| `sendMessage(message)` | Send raw message to Moss |
|
|
131
|
+
| `reportProgress(phase, current, total, message?)` | Report progress |
|
|
132
|
+
| `reportError(error, context?, fatal?)` | Report error |
|
|
133
|
+
| `reportComplete(result)` | Report completion |
|
|
134
|
+
| `log(message)` | Log info message |
|
|
135
|
+
| `warn(message)` | Log warning message |
|
|
136
|
+
| `error(message)` | Log error message |
|
|
137
|
+
| `openBrowser(url)` | Open URL in plugin browser |
|
|
138
|
+
| `closeBrowser()` | Close plugin browser |
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
MIT - see [LICENSE](LICENSE) for details.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
//#region src/types/plugin.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base plugin types shared across all Moss plugins
|
|
4
|
+
*/
|
|
5
|
+
interface ProjectInfo {
|
|
6
|
+
project_type: string;
|
|
7
|
+
content_folders: string[];
|
|
8
|
+
total_files: number;
|
|
9
|
+
homepage_file?: string;
|
|
10
|
+
}
|
|
11
|
+
interface PluginManifest {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
entry: string;
|
|
15
|
+
category: PluginCategory;
|
|
16
|
+
global_name?: string;
|
|
17
|
+
icon?: string;
|
|
18
|
+
domain?: string;
|
|
19
|
+
config?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
type PluginCategory = "generator" | "deployer" | "syndicator" | "enhancer" | "processor";
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/types/context.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* Base context shared by all hooks
|
|
26
|
+
*/
|
|
27
|
+
interface BaseContext {
|
|
28
|
+
project_path: string;
|
|
29
|
+
moss_dir: string;
|
|
30
|
+
project_info: ProjectInfo;
|
|
31
|
+
config: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Context for before_build hook
|
|
35
|
+
*/
|
|
36
|
+
interface BeforeBuildContext extends BaseContext {}
|
|
37
|
+
/**
|
|
38
|
+
* Context for on_build hook (generator plugins)
|
|
39
|
+
*/
|
|
40
|
+
interface OnBuildContext extends BaseContext {
|
|
41
|
+
source_files: SourceFiles;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Context for on_deploy hook (deployer plugins)
|
|
45
|
+
*/
|
|
46
|
+
interface OnDeployContext extends BaseContext {
|
|
47
|
+
output_dir: string;
|
|
48
|
+
site_files: string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Context for after_deploy hook (syndicator plugins)
|
|
52
|
+
*/
|
|
53
|
+
interface AfterDeployContext extends BaseContext {
|
|
54
|
+
output_dir: string;
|
|
55
|
+
site_files: string[];
|
|
56
|
+
articles: ArticleInfo[];
|
|
57
|
+
deployment?: DeploymentInfo;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Source files categorized by type
|
|
61
|
+
*/
|
|
62
|
+
interface SourceFiles {
|
|
63
|
+
markdown: string[];
|
|
64
|
+
pages: string[];
|
|
65
|
+
docx: string[];
|
|
66
|
+
other: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Article information for syndication
|
|
70
|
+
*/
|
|
71
|
+
interface ArticleInfo {
|
|
72
|
+
source_path: string;
|
|
73
|
+
title: string;
|
|
74
|
+
content: string;
|
|
75
|
+
frontmatter: Record<string, unknown>;
|
|
76
|
+
url_path: string;
|
|
77
|
+
date?: string;
|
|
78
|
+
tags: string[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Deployment result information
|
|
82
|
+
*/
|
|
83
|
+
interface DeploymentInfo {
|
|
84
|
+
method: string;
|
|
85
|
+
url: string;
|
|
86
|
+
deployed_at: string;
|
|
87
|
+
metadata: Record<string, string>;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/types/hooks.d.ts
|
|
91
|
+
/**
|
|
92
|
+
* Standard result returned from hook execution
|
|
93
|
+
*/
|
|
94
|
+
interface HookResult {
|
|
95
|
+
success: boolean;
|
|
96
|
+
message?: string;
|
|
97
|
+
deployment?: DeploymentInfo;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/types/messages.d.ts
|
|
101
|
+
/**
|
|
102
|
+
* Plugin message types for communication with Moss
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* Messages that plugins can send to Moss
|
|
106
|
+
*/
|
|
107
|
+
type PluginMessage = LogMessage | ProgressMessage | ErrorMessage | CompleteMessage;
|
|
108
|
+
interface LogMessage {
|
|
109
|
+
type: "log";
|
|
110
|
+
level: "log" | "warn" | "error";
|
|
111
|
+
message: string;
|
|
112
|
+
}
|
|
113
|
+
interface ProgressMessage {
|
|
114
|
+
type: "progress";
|
|
115
|
+
phase: string;
|
|
116
|
+
current: number;
|
|
117
|
+
total: number;
|
|
118
|
+
message?: string;
|
|
119
|
+
}
|
|
120
|
+
interface ErrorMessage {
|
|
121
|
+
type: "error";
|
|
122
|
+
error: string;
|
|
123
|
+
context?: string;
|
|
124
|
+
fatal: boolean;
|
|
125
|
+
}
|
|
126
|
+
interface CompleteMessage {
|
|
127
|
+
type: "complete";
|
|
128
|
+
result: unknown;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/utils/tauri.d.ts
|
|
132
|
+
/**
|
|
133
|
+
* Tauri core utilities for plugin communication
|
|
134
|
+
*/
|
|
135
|
+
interface TauriCore {
|
|
136
|
+
invoke: <T>(cmd: string, args?: Record<string, unknown>) => Promise<T>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get the Tauri core API
|
|
140
|
+
* @throws Error if Tauri is not available
|
|
141
|
+
*/
|
|
142
|
+
declare function getTauriCore(): TauriCore;
|
|
143
|
+
/**
|
|
144
|
+
* Check if Tauri is available
|
|
145
|
+
*/
|
|
146
|
+
declare function isTauriAvailable(): boolean;
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/utils/messaging.d.ts
|
|
149
|
+
/**
|
|
150
|
+
* Set the message context for subsequent messages
|
|
151
|
+
* This is typically called automatically by the plugin runtime
|
|
152
|
+
*/
|
|
153
|
+
declare function setMessageContext(pluginName: string, hookName: string): void;
|
|
154
|
+
/**
|
|
155
|
+
* Get the current message context
|
|
156
|
+
*/
|
|
157
|
+
declare function getMessageContext(): {
|
|
158
|
+
pluginName: string;
|
|
159
|
+
hookName: string;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Send a message to Moss
|
|
163
|
+
* Silently fails if Tauri is unavailable (useful for testing)
|
|
164
|
+
*/
|
|
165
|
+
declare function sendMessage(message: PluginMessage): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Report progress to Moss
|
|
168
|
+
*/
|
|
169
|
+
declare function reportProgress(phase: string, current: number, total: number, message?: string): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Report an error to Moss
|
|
172
|
+
*/
|
|
173
|
+
declare function reportError(error: string, context?: string, fatal?: boolean): Promise<void>;
|
|
174
|
+
/**
|
|
175
|
+
* Report completion to Moss
|
|
176
|
+
*/
|
|
177
|
+
declare function reportComplete(result: unknown): Promise<void>;
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/utils/logger.d.ts
|
|
180
|
+
/**
|
|
181
|
+
* Logging utilities for plugins
|
|
182
|
+
*/
|
|
183
|
+
/**
|
|
184
|
+
* Log an informational message
|
|
185
|
+
*/
|
|
186
|
+
declare function log(message: string): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Log a warning message
|
|
189
|
+
*/
|
|
190
|
+
declare function warn(message: string): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Log an error message
|
|
193
|
+
*/
|
|
194
|
+
declare function error(message: string): Promise<void>;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/utils/browser.d.ts
|
|
197
|
+
/**
|
|
198
|
+
* Browser utilities for plugins
|
|
199
|
+
* Abstracts Tauri browser commands to decouple plugins from internal APIs
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* Open a URL in the plugin browser window
|
|
203
|
+
*/
|
|
204
|
+
declare function openBrowser(url: string): Promise<void>;
|
|
205
|
+
/**
|
|
206
|
+
* Close the plugin browser window
|
|
207
|
+
*/
|
|
208
|
+
declare function closeBrowser(): Promise<void>;
|
|
209
|
+
//#endregion
|
|
210
|
+
export { AfterDeployContext, ArticleInfo, BaseContext, BeforeBuildContext, CompleteMessage, DeploymentInfo, ErrorMessage, HookResult, LogMessage, OnBuildContext, OnDeployContext, PluginCategory, PluginManifest, PluginMessage, ProgressMessage, ProjectInfo, SourceFiles, TauriCore, closeBrowser, error, getMessageContext, getTauriCore, isTauriAvailable, log, openBrowser, reportComplete, reportError, reportProgress, sendMessage, setMessageContext, warn };
|
|
211
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +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":"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"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
//#region src/utils/tauri.ts
|
|
2
|
+
/**
|
|
3
|
+
* Get the Tauri core API
|
|
4
|
+
* @throws Error if Tauri is not available
|
|
5
|
+
*/
|
|
6
|
+
function getTauriCore() {
|
|
7
|
+
const w = window;
|
|
8
|
+
if (!w.__TAURI__?.core) throw new Error("Tauri core not available");
|
|
9
|
+
return w.__TAURI__.core;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Check if Tauri is available
|
|
13
|
+
*/
|
|
14
|
+
function isTauriAvailable() {
|
|
15
|
+
return !!window.__TAURI__?.core;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/utils/messaging.ts
|
|
20
|
+
let currentPluginName = "";
|
|
21
|
+
let currentHookName = "";
|
|
22
|
+
/**
|
|
23
|
+
* Set the message context for subsequent messages
|
|
24
|
+
* This is typically called automatically by the plugin runtime
|
|
25
|
+
*/
|
|
26
|
+
function setMessageContext(pluginName, hookName) {
|
|
27
|
+
currentPluginName = pluginName;
|
|
28
|
+
currentHookName = hookName;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the current message context
|
|
32
|
+
*/
|
|
33
|
+
function getMessageContext() {
|
|
34
|
+
return {
|
|
35
|
+
pluginName: currentPluginName,
|
|
36
|
+
hookName: currentHookName
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Send a message to Moss
|
|
41
|
+
* Silently fails if Tauri is unavailable (useful for testing)
|
|
42
|
+
*/
|
|
43
|
+
async function sendMessage(message) {
|
|
44
|
+
if (!isTauriAvailable()) return;
|
|
45
|
+
try {
|
|
46
|
+
await getTauriCore().invoke("plugin_message", {
|
|
47
|
+
pluginName: currentPluginName,
|
|
48
|
+
hookName: currentHookName,
|
|
49
|
+
message
|
|
50
|
+
});
|
|
51
|
+
} catch {}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Report progress to Moss
|
|
55
|
+
*/
|
|
56
|
+
async function reportProgress(phase, current, total, message) {
|
|
57
|
+
await sendMessage({
|
|
58
|
+
type: "progress",
|
|
59
|
+
phase,
|
|
60
|
+
current,
|
|
61
|
+
total,
|
|
62
|
+
message
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Report an error to Moss
|
|
67
|
+
*/
|
|
68
|
+
async function reportError(error$1, context, fatal = false) {
|
|
69
|
+
await sendMessage({
|
|
70
|
+
type: "error",
|
|
71
|
+
error: error$1,
|
|
72
|
+
context,
|
|
73
|
+
fatal
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Report completion to Moss
|
|
78
|
+
*/
|
|
79
|
+
async function reportComplete(result) {
|
|
80
|
+
await sendMessage({
|
|
81
|
+
type: "complete",
|
|
82
|
+
result
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/utils/logger.ts
|
|
88
|
+
/**
|
|
89
|
+
* Logging utilities for plugins
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* Log an informational message
|
|
93
|
+
*/
|
|
94
|
+
async function log(message) {
|
|
95
|
+
await sendMessage({
|
|
96
|
+
type: "log",
|
|
97
|
+
level: "log",
|
|
98
|
+
message
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Log a warning message
|
|
103
|
+
*/
|
|
104
|
+
async function warn(message) {
|
|
105
|
+
await sendMessage({
|
|
106
|
+
type: "log",
|
|
107
|
+
level: "warn",
|
|
108
|
+
message
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Log an error message
|
|
113
|
+
*/
|
|
114
|
+
async function error(message) {
|
|
115
|
+
await sendMessage({
|
|
116
|
+
type: "log",
|
|
117
|
+
level: "error",
|
|
118
|
+
message
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/utils/browser.ts
|
|
124
|
+
/**
|
|
125
|
+
* Browser utilities for plugins
|
|
126
|
+
* Abstracts Tauri browser commands to decouple plugins from internal APIs
|
|
127
|
+
*/
|
|
128
|
+
/**
|
|
129
|
+
* Open a URL in the plugin browser window
|
|
130
|
+
*/
|
|
131
|
+
async function openBrowser(url) {
|
|
132
|
+
await getTauriCore().invoke("open_plugin_browser", { url });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Close the plugin browser window
|
|
136
|
+
*/
|
|
137
|
+
async function closeBrowser() {
|
|
138
|
+
await getTauriCore().invoke("close_plugin_browser", {});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
export { closeBrowser, error, getMessageContext, getTauriCore, isTauriAvailable, log, openBrowser, reportComplete, reportError, reportProgress, sendMessage, setMessageContext, warn };
|
|
143
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/utils/tauri.ts","../src/utils/messaging.ts","../src/utils/logger.ts","../src/utils/browser.ts"],"sourcesContent":["/**\n * Tauri core utilities for plugin communication\n */\n\nexport interface TauriCore {\n invoke: <T>(cmd: string, args?: Record<string, unknown>) => Promise<T>;\n}\n\ninterface TauriWindow {\n __TAURI__?: {\n core: TauriCore;\n };\n}\n\n/**\n * Get the Tauri core API\n * @throws Error if Tauri is not available\n */\nexport function getTauriCore(): TauriCore {\n const w = window as unknown as TauriWindow;\n if (!w.__TAURI__?.core) {\n throw new Error(\"Tauri core not available\");\n }\n return w.__TAURI__.core;\n}\n\n/**\n * Check if Tauri is available\n */\nexport function isTauriAvailable(): boolean {\n const w = window as unknown as TauriWindow;\n return !!w.__TAURI__?.core;\n}\n","/**\n * Plugin messaging utilities for communicating with Moss\n */\n\nimport type { PluginMessage } from \"../types/messages\";\nimport { getTauriCore, isTauriAvailable } from \"./tauri\";\n\nlet currentPluginName = \"\";\nlet currentHookName = \"\";\n\n/**\n * Set the message context for subsequent messages\n * This is typically called automatically by the plugin runtime\n */\nexport function setMessageContext(pluginName: string, hookName: string): void {\n currentPluginName = pluginName;\n currentHookName = hookName;\n}\n\n/**\n * Get the current message context\n */\nexport function getMessageContext(): { pluginName: string; hookName: string } {\n return { pluginName: currentPluginName, hookName: currentHookName };\n}\n\n/**\n * Send a message to Moss\n * Silently fails if Tauri is unavailable (useful for testing)\n */\nexport async function sendMessage(message: PluginMessage): Promise<void> {\n if (!isTauriAvailable()) {\n return;\n }\n\n try {\n await getTauriCore().invoke(\"plugin_message\", {\n pluginName: currentPluginName,\n hookName: currentHookName,\n message,\n });\n } catch {\n // Silently fail - logging would be recursive\n }\n}\n\n/**\n * Report progress to Moss\n */\nexport async function reportProgress(\n phase: string,\n current: number,\n total: number,\n message?: string\n): Promise<void> {\n await sendMessage({ type: \"progress\", phase, current, total, message });\n}\n\n/**\n * Report an error to Moss\n */\nexport async function reportError(\n error: string,\n context?: string,\n fatal = false\n): Promise<void> {\n await sendMessage({ type: \"error\", error, context, fatal });\n}\n\n/**\n * Report completion to Moss\n */\nexport async function reportComplete(result: unknown): Promise<void> {\n await sendMessage({ type: \"complete\", result });\n}\n","/**\n * Logging utilities for plugins\n */\n\nimport { sendMessage } from \"./messaging\";\n\n/**\n * Log an informational message\n */\nexport async function log(message: string): Promise<void> {\n await sendMessage({ type: \"log\", level: \"log\", message });\n}\n\n/**\n * Log a warning message\n */\nexport async function warn(message: string): Promise<void> {\n await sendMessage({ type: \"log\", level: \"warn\", message });\n}\n\n/**\n * Log an error message\n */\nexport async function error(message: string): Promise<void> {\n await sendMessage({ type: \"log\", level: \"error\", message });\n}\n","/**\n * Browser utilities for plugins\n * Abstracts Tauri browser commands to decouple plugins from internal APIs\n */\n\nimport { getTauriCore } from \"./tauri\";\n\n/**\n * Open a URL in the plugin browser window\n */\nexport async function openBrowser(url: string): Promise<void> {\n await getTauriCore().invoke(\"open_plugin_browser\", { url });\n}\n\n/**\n * Close the plugin browser window\n */\nexport async function closeBrowser(): Promise<void> {\n await getTauriCore().invoke(\"close_plugin_browser\", {});\n}\n"],"mappings":";;;;;AAkBA,SAAgB,eAA0B;CACxC,MAAM,IAAI;AACV,KAAI,CAAC,EAAE,WAAW,KAChB,OAAM,IAAI,MAAM,2BAA2B;AAE7C,QAAO,EAAE,UAAU;;;;;AAMrB,SAAgB,mBAA4B;AAE1C,QAAO,CAAC,CADE,OACC,WAAW;;;;;ACxBxB,IAAI,oBAAoB;AACxB,IAAI,kBAAkB;;;;;AAMtB,SAAgB,kBAAkB,YAAoB,UAAwB;AAC5E,qBAAoB;AACpB,mBAAkB;;;;;AAMpB,SAAgB,oBAA8D;AAC5E,QAAO;EAAE,YAAY;EAAmB,UAAU;EAAiB;;;;;;AAOrE,eAAsB,YAAY,SAAuC;AACvE,KAAI,CAAC,kBAAkB,CACrB;AAGF,KAAI;AACF,QAAM,cAAc,CAAC,OAAO,kBAAkB;GAC5C,YAAY;GACZ,UAAU;GACV;GACD,CAAC;SACI;;;;;AAQV,eAAsB,eACpB,OACA,SACA,OACA,SACe;AACf,OAAM,YAAY;EAAE,MAAM;EAAY;EAAO;EAAS;EAAO;EAAS,CAAC;;;;;AAMzE,eAAsB,YACpB,SACA,SACA,QAAQ,OACO;AACf,OAAM,YAAY;EAAE,MAAM;EAAS;EAAO;EAAS;EAAO,CAAC;;;;;AAM7D,eAAsB,eAAe,QAAgC;AACnE,OAAM,YAAY;EAAE,MAAM;EAAY;EAAQ,CAAC;;;;;;;;;;;AChEjD,eAAsB,IAAI,SAAgC;AACxD,OAAM,YAAY;EAAE,MAAM;EAAO,OAAO;EAAO;EAAS,CAAC;;;;;AAM3D,eAAsB,KAAK,SAAgC;AACzD,OAAM,YAAY;EAAE,MAAM;EAAO,OAAO;EAAQ;EAAS,CAAC;;;;;AAM5D,eAAsB,MAAM,SAAgC;AAC1D,OAAM,YAAY;EAAE,MAAM;EAAO,OAAO;EAAS;EAAS,CAAC;;;;;;;;;;;;ACd7D,eAAsB,YAAY,KAA4B;AAC5D,OAAM,cAAc,CAAC,OAAO,uBAAuB,EAAE,KAAK,CAAC;;;;;AAM7D,eAAsB,eAA8B;AAClD,OAAM,cAAc,CAAC,OAAO,wBAAwB,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@symbiosis-lab/moss-api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Official API for building Moss plugins - types and utilities for plugin development",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.mjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.mts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.mts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsdown",
|
|
22
|
+
"dev": "tsdown --watch",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"test:coverage": "vitest run --coverage",
|
|
26
|
+
"prepublishOnly": "npm run build && npm run test"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"moss",
|
|
30
|
+
"plugin",
|
|
31
|
+
"sdk",
|
|
32
|
+
"api",
|
|
33
|
+
"tauri",
|
|
34
|
+
"publishing",
|
|
35
|
+
"syndication"
|
|
36
|
+
],
|
|
37
|
+
"author": "Guo Liu",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/Symbiosis-Lab/moss-api.git"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/Symbiosis-Lab/moss-api/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/Symbiosis-Lab/moss-api#readme",
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
55
|
+
"tsdown": "^0.18.0",
|
|
56
|
+
"typescript": "^5.3.0",
|
|
57
|
+
"vitest": "^3.2.4"
|
|
58
|
+
}
|
|
59
|
+
}
|