@jay-framework/editor-server 0.11.0 → 0.13.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.ts +3 -1
- package/dist/index.js +26 -5
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DevServerProtocol, PublishMessage, PublishResponse, SaveImageMessage, SaveImageResponse, HasImageMessage, HasImageResponse, GetProjectInfoMessage, GetProjectInfoResponse } from '@jay-framework/editor-protocol';
|
|
1
|
+
import { DevServerProtocol, PublishMessage, PublishResponse, SaveImageMessage, SaveImageResponse, HasImageMessage, HasImageResponse, GetProjectInfoMessage, GetProjectInfoResponse, ExportMessage, ExportResponse, ImportMessage, ImportResponse } from '@jay-framework/editor-protocol';
|
|
2
2
|
|
|
3
3
|
interface EditorServerOptions {
|
|
4
4
|
editorId?: string;
|
|
@@ -25,6 +25,8 @@ declare class EditorServer implements DevServerProtocol {
|
|
|
25
25
|
onSaveImage(callback: (params: SaveImageMessage) => Promise<SaveImageResponse>): void;
|
|
26
26
|
onHasImage(callback: (params: HasImageMessage) => Promise<HasImageResponse>): void;
|
|
27
27
|
onGetProjectInfo(callback: (params: GetProjectInfoMessage) => Promise<GetProjectInfoResponse>): void;
|
|
28
|
+
onExport<TVendorDoc>(callback: (params: ExportMessage<TVendorDoc>) => Promise<ExportResponse>): void;
|
|
29
|
+
onImport<TVendorDoc>(callback: (params: ImportMessage<TVendorDoc>) => Promise<ImportResponse<TVendorDoc>>): void;
|
|
28
30
|
private handlePortDiscovery;
|
|
29
31
|
private setupSocketHandlers;
|
|
30
32
|
private isLocalhost;
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { Server } from "socket.io";
|
|
8
8
|
import { createServer } from "http";
|
|
9
9
|
import getPort from "get-port";
|
|
10
|
+
import { getLogger } from "@jay-framework/logger";
|
|
10
11
|
import { createProtocolResponse } from "@jay-framework/editor-protocol";
|
|
11
12
|
const ALLOWED_ORIGINS = [
|
|
12
13
|
"https://www.figma.com",
|
|
@@ -46,7 +47,7 @@ class EditorServer {
|
|
|
46
47
|
);
|
|
47
48
|
res.setHeader("Access-Control-Allow-Credentials", "true");
|
|
48
49
|
if (!this.isLocalhost(clientIP)) {
|
|
49
|
-
|
|
50
|
+
getLogger().warn(`Rejected connection from non-localhost IP: ${clientIP}`);
|
|
50
51
|
res.writeHead(403, { "Content-Type": "application/json" });
|
|
51
52
|
res.end(
|
|
52
53
|
JSON.stringify({
|
|
@@ -74,7 +75,7 @@ class EditorServer {
|
|
|
74
75
|
this.setupSocketHandlers();
|
|
75
76
|
return new Promise((resolve, reject) => {
|
|
76
77
|
this.httpServer.listen(this.port, () => {
|
|
77
|
-
|
|
78
|
+
getLogger().info(`Editor server started on port ${this.port}`);
|
|
78
79
|
resolve({ port: this.port, editorId: this.editorId || "init" });
|
|
79
80
|
});
|
|
80
81
|
this.httpServer.on("error", reject);
|
|
@@ -101,6 +102,12 @@ class EditorServer {
|
|
|
101
102
|
onGetProjectInfo(callback) {
|
|
102
103
|
this.handlers.getProjectInfo = callback;
|
|
103
104
|
}
|
|
105
|
+
onExport(callback) {
|
|
106
|
+
this.handlers.export = callback;
|
|
107
|
+
}
|
|
108
|
+
onImport(callback) {
|
|
109
|
+
this.handlers.import = callback;
|
|
110
|
+
}
|
|
104
111
|
handlePortDiscovery(req, res) {
|
|
105
112
|
const url = new URL(req.url, `http://localhost:${this.port}`);
|
|
106
113
|
const tabId = url.searchParams.get("id");
|
|
@@ -127,11 +134,13 @@ class EditorServer {
|
|
|
127
134
|
this.io.on("connection", (socket) => {
|
|
128
135
|
const clientIP = socket.handshake.address;
|
|
129
136
|
if (!this.isLocalhost(clientIP)) {
|
|
130
|
-
|
|
137
|
+
getLogger().warn(
|
|
138
|
+
`Rejected WebSocket connection from non-localhost IP: ${clientIP}`
|
|
139
|
+
);
|
|
131
140
|
socket.disconnect(true);
|
|
132
141
|
return;
|
|
133
142
|
}
|
|
134
|
-
|
|
143
|
+
getLogger().info(`Editor Socket connected: ${socket.id} from ${clientIP}`);
|
|
135
144
|
socket.on("protocol-message", async (message) => {
|
|
136
145
|
try {
|
|
137
146
|
const response = await this.handleProtocolMessage(message);
|
|
@@ -147,7 +156,7 @@ class EditorServer {
|
|
|
147
156
|
}
|
|
148
157
|
});
|
|
149
158
|
socket.on("disconnect", () => {
|
|
150
|
-
|
|
159
|
+
getLogger().info(`Editor Socket disconnected: ${socket.id}`);
|
|
151
160
|
});
|
|
152
161
|
});
|
|
153
162
|
}
|
|
@@ -183,6 +192,18 @@ class EditorServer {
|
|
|
183
192
|
payload
|
|
184
193
|
);
|
|
185
194
|
return createProtocolResponse(id, infoResult);
|
|
195
|
+
case "export":
|
|
196
|
+
if (!this.handlers.export) {
|
|
197
|
+
throw new Error("Export handler not registered");
|
|
198
|
+
}
|
|
199
|
+
const exportResult = await this.handlers.export(payload);
|
|
200
|
+
return createProtocolResponse(id, exportResult);
|
|
201
|
+
case "import":
|
|
202
|
+
if (!this.handlers.import) {
|
|
203
|
+
throw new Error("Import handler not registered");
|
|
204
|
+
}
|
|
205
|
+
const importResult = await this.handlers.import(payload);
|
|
206
|
+
return createProtocolResponse(id, importResult);
|
|
186
207
|
default:
|
|
187
208
|
throw new Error(`Unknown message type: ${payload.type}`);
|
|
188
209
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/editor-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,16 +20,17 @@
|
|
|
20
20
|
"test:watch": "vitest"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@jay-framework/editor-protocol": "^0.
|
|
23
|
+
"@jay-framework/editor-protocol": "^0.13.0",
|
|
24
|
+
"@jay-framework/logger": "^0.13.0",
|
|
24
25
|
"get-port": "^7.0.0",
|
|
25
26
|
"socket.io": "^4.7.4",
|
|
26
27
|
"uuid": "^9.0.1",
|
|
27
28
|
"yaml": "^2.3.4"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@jay-framework/dev-environment": "^0.
|
|
31
|
-
"@jay-framework/editor-client": "^0.
|
|
32
|
-
"@jay-framework/jay-cli": "^0.
|
|
31
|
+
"@jay-framework/dev-environment": "^0.13.0",
|
|
32
|
+
"@jay-framework/editor-client": "^0.13.0",
|
|
33
|
+
"@jay-framework/jay-cli": "^0.13.0",
|
|
33
34
|
"@types/express": "^5.0.2",
|
|
34
35
|
"@types/node": "^22.15.21",
|
|
35
36
|
"@types/uuid": "^9.0.7",
|