@wix/wix-code-diagnostics-plugin 1.1.5 → 1.1.7

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/README.md CHANGED
@@ -39,3 +39,38 @@ best-effort and never fails the CLI run.
39
39
  > Interim: until the CLI exposes `build`/`preview` error + success events, the
40
40
  > plugin subscribes to the dev process's `dc-updated` event to exercise the
41
41
  > transport end to end.
42
+
43
+ ## Runtime errors stream (`wix dev` only)
44
+
45
+ On `cli:setup` with `cmd === 'dev'` the plugin also starts a local WebSocket
46
+ server so the editor can show runtime errors from the running app:
47
+
48
+ | | |
49
+ |---|---|
50
+ | Endpoint | `ws://127.0.0.1:52415/runtime-errors` |
51
+ | Port | `52415` — fixed, like the CLI dev server's `52401`. `52402` is taken by the codegen agent |
52
+ | Bind | Loopback only (`127.0.0.1`). Remote editors reach it through the remote-machine dispatcher, never directly |
53
+ | Through the dispatcher | `wss://<editor-host>/remote-machine/studio-proxy/projects/<projectId>/ports/52415/runtime-errors`. The dispatcher forwards the **full** original path, so the server strips `/remote-machine/{proxy,studio-proxy}/projects/<id>/ports/<port>` before matching |
54
+ | Why WebSocket | The dispatcher buffers whole HTTP response bodies, so SSE (or any HTTP streaming) never reaches the editor. WebSocket upgrades are streamed through it frame by frame |
55
+ | Messages | JSON text frames: `{ "type": "runtime-error", "error": { id, name, message, file, line, column, stack, timestamp } }` and `{ "type": "ping" }` |
56
+ | Replay | Ring buffer of the last 100 errors, replayed on connect. `?after=<id>` replays only what came after that error; an unknown id (buffer rolled over) replays everything |
57
+ | Heartbeat | `{ "type": "ping" }` every ~25s. Application-level on purpose: browsers cannot observe protocol pings, and the editor needs to tell a live socket from a dead one |
58
+ | Status probe | A plain `GET` on the same path answers `200 { transport, path, bufferedErrors, connectedClients }` — handy for checking the proxy route from a browser tab |
59
+ | Slow clients | A socket whose unsent bytes reach 1 MB is terminated, so a stalled editor tab cannot grow the dev process's memory |
60
+ | Shutdown | When `wix dev` exits the process ends and the editor sees an abnormal close (`1006`); treat it like any dropped socket and reconnect with `?after=`. The programmatic `close()` sends `1001` (going away) and cuts a peer that does not answer within 1 s |
61
+ | Origins | `editor.wix.com`, `manage.wix.com`, `*.editor.wix.com`, `*.wix-code.com`. An `Origin` outside that list gets `403` on the upgrade and on the probe; a request with no `Origin` is served |
62
+ | Origin override | `WIX_CODE_RUNTIME_ERRORS_ALLOWED_ORIGINS` replaces the list entirely — comma-separated. A hostname (`editor.wix.com`) matches on any scheme and port; a full origin (`http://localhost:3000`) matches **exactly**, that scheme and that port only; `*.editor.wix.com` matches any subdomain. An entry that is neither (`localhost:3000`, with a port but no scheme) is ambiguous, so it is dropped with a warning rather than widened. Set this to run a local editor against the stream |
63
+ | Port clash | A second `wix dev` in the same sandbox cannot have `52415`. The stream moves to an ephemeral port and says so in the CLI output — the editor only looks at `52415`, so that run's errors do not reach it |
64
+
65
+ The plugin subscribes to the CLI's `runtime-error` event — that subscription is
66
+ what enables capture on the CLI side. Each error is serialized, passed through a
67
+ fingerprint dedup (1s window) and a rate cap (50 per 10s), then buffered and
68
+ broadcast.
69
+
70
+ Runtime errors are ephemeral by design: no orchestrator, no persistence, and the
71
+ buffer dies with the dev server. The stream part is active on every `wix dev`
72
+ run, independent of the two diagnostics env vars above.
73
+
74
+ `ws` is bundled into `dist/index.mjs`, so the published package still has no
75
+ runtime dependencies. Its optional native accelerators (`bufferutil`,
76
+ `utf-8-validate`) are left external and simply absent.
@@ -0,0 +1,25 @@
1
+ export declare const RUNTIME_ERRORS_PORT = 52415;
2
+ export declare const RUNTIME_ERRORS_PATH = "/runtime-errors";
3
+ /**
4
+ * Prefix the remote-machine dispatcher leaves on the request path when the editor reaches the
5
+ * sandbox through `https://<editor-host>/remote-machine/{proxy,studio-proxy}/projects/<projectId>/ports/<port>/…`.
6
+ * The dispatcher forwards the full original path, and the sandbox agent strips only its own
7
+ * `/dispatcher/<port>` prefix, so the plugin has to drop this one itself.
8
+ */
9
+ export declare const REMOTE_MACHINE_PROXY_PREFIX: RegExp;
10
+ export declare const REPLAY_AFTER_PARAM = "after";
11
+ export declare const HEARTBEAT_INTERVAL_MS = 25000;
12
+ export declare const CLOSE_GRACE_MS = 1000;
13
+ export declare const RUNTIME_ERRORS_BUFFER_SIZE = 100;
14
+ export declare const DEDUP_WINDOW_MS = 1000;
15
+ export declare const MAX_ERRORS_PER_WINDOW = 50;
16
+ export declare const RATE_WINDOW_MS = 10000;
17
+ export declare const MAX_TRACKED_FINGERPRINTS = 128;
18
+ export declare const ALLOWED_ORIGINS_ENV = "WIX_CODE_RUNTIME_ERRORS_ALLOWED_ORIGINS";
19
+ export declare const DEFAULT_ORIGIN_ALLOWLIST: {
20
+ readonly hosts: readonly ["editor.wix.com", "manage.wix.com"];
21
+ readonly suffixes: readonly [".editor.wix.com", ".wix-code.com"];
22
+ };
23
+ export declare const RUNTIME_ERRORS_HOST = "127.0.0.1";
24
+ export declare const MAX_CLIENT_BUFFER_BYTES = 1048576;
25
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,eAAO,MAAM,mBAAmB,oBAAoB,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,QAC0C,CAAC;AAEnF,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAE5C,eAAO,MAAM,cAAc,OAAQ,CAAC;AAEpC,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAE9C,eAAO,MAAM,eAAe,OAAQ,CAAC;AAErC,eAAO,MAAM,qBAAqB,KAAK,CAAC;AAExC,eAAO,MAAM,cAAc,QAAS,CAAC;AAErC,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,eAAO,MAAM,mBAAmB,4CAA4C,CAAC;AAE7E,eAAO,MAAM,wBAAwB;;;CAG3B,CAAC;AAEX,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAE/C,eAAO,MAAM,uBAAuB,UAAY,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
- import type { WixCliPlugin } from './types';
2
- export declare const wixCodeDiagnosticsPlugin: () => WixCliPlugin;
1
+ export { wixCodeDiagnosticsPlugin } from './plugin';
2
+ export type { WixCodeDiagnosticsPluginOptions } from './plugin';
3
3
  export type { WixCliPlugin, CliErrorCtx } from './types';
4
4
  export { reportDiagnostic, cliErrorToCodeErrors } from './reportDiagnostic';
5
5
  export { readAppConfig } from './appConfig';
6
+ export { startRuntimeErrorsServer } from './runtimeErrorsServer';
7
+ export type { RuntimeErrorsServer, RuntimeErrorsServerOptions } from './runtimeErrorsServer';
8
+ export { serializeRuntimeError, createRuntimeErrorLimiter } from './runtimeError';
9
+ export type { SerializedRuntimeError } from './runtimeError';
10
+ export type { RuntimeErrorsMessage } from './protocol';
11
+ export { parseRequestPath } from './requestPath';
12
+ export { RUNTIME_ERRORS_PORT, RUNTIME_ERRORS_HOST, RUNTIME_ERRORS_PATH, REPLAY_AFTER_PARAM, REMOTE_MACHINE_PROXY_PREFIX, } from './constants';
6
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAM5C,eAAO,MAAM,wBAAwB,QAAO,YAwB3C,CAAC;AAEF,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,YAAY,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,YAAY,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAC7F,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAClF,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,2BAA2B,GAC5B,MAAM,aAAa,CAAC"}