@sandbox-engine/sdk 0.2.2 → 0.2.4

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.js CHANGED
@@ -53,6 +53,10 @@ var WsEmitterAdapter = class extends import_node_events.EventEmitter {
53
53
  ws.addEventListener("error", (e) => this.emit("error", e));
54
54
  ws.addEventListener("close", () => this.emit("close"));
55
55
  ws.addEventListener("open", () => this.emit("open"));
56
+ const state = ws.readyState;
57
+ if (state === 1) {
58
+ queueMicrotask(() => this.emit("open"));
59
+ }
56
60
  }
57
61
  ws;
58
62
  OPEN = 1;
@@ -131,10 +135,10 @@ var HttpClient = class {
131
135
  // CF Workers: uses fetch() with Upgrade header (supports Authorization).
132
136
  // Node.js: uses the ws package (installed as an optional dependency).
133
137
  async openWebSocket(path) {
134
- const wsUrl = this.baseUrl.replace(/^http/, "ws") + path;
135
138
  const authHeader = `Bearer ${this.apiKey}`;
136
139
  if (IS_CF_WORKERS) {
137
- const resp = await fetch(wsUrl, {
140
+ const httpUrl = this.baseUrl + path;
141
+ const resp = await fetch(httpUrl, {
138
142
  headers: {
139
143
  Upgrade: "websocket",
140
144
  Connection: "Upgrade",
@@ -145,6 +149,7 @@ var HttpClient = class {
145
149
  if (!cfWs) throw new Error("WebSocket upgrade failed \u2014 server did not accept");
146
150
  return new WsEmitterAdapter(cfWs);
147
151
  }
152
+ const wsUrl = this.baseUrl.replace(/^http/, "ws") + path;
148
153
  const { default: WS } = await import("ws");
149
154
  return new WS(wsUrl, { headers: { authorization: authHeader } });
150
155
  }
package/dist/index.mjs CHANGED
@@ -12,6 +12,10 @@ var WsEmitterAdapter = class extends EventEmitter {
12
12
  ws.addEventListener("error", (e) => this.emit("error", e));
13
13
  ws.addEventListener("close", () => this.emit("close"));
14
14
  ws.addEventListener("open", () => this.emit("open"));
15
+ const state = ws.readyState;
16
+ if (state === 1) {
17
+ queueMicrotask(() => this.emit("open"));
18
+ }
15
19
  }
16
20
  ws;
17
21
  OPEN = 1;
@@ -90,10 +94,10 @@ var HttpClient = class {
90
94
  // CF Workers: uses fetch() with Upgrade header (supports Authorization).
91
95
  // Node.js: uses the ws package (installed as an optional dependency).
92
96
  async openWebSocket(path) {
93
- const wsUrl = this.baseUrl.replace(/^http/, "ws") + path;
94
97
  const authHeader = `Bearer ${this.apiKey}`;
95
98
  if (IS_CF_WORKERS) {
96
- const resp = await fetch(wsUrl, {
99
+ const httpUrl = this.baseUrl + path;
100
+ const resp = await fetch(httpUrl, {
97
101
  headers: {
98
102
  Upgrade: "websocket",
99
103
  Connection: "Upgrade",
@@ -104,6 +108,7 @@ var HttpClient = class {
104
108
  if (!cfWs) throw new Error("WebSocket upgrade failed \u2014 server did not accept");
105
109
  return new WsEmitterAdapter(cfWs);
106
110
  }
111
+ const wsUrl = this.baseUrl.replace(/^http/, "ws") + path;
107
112
  const { default: WS } = await import("ws");
108
113
  return new WS(wsUrl, { headers: { authorization: authHeader } });
109
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sandbox-engine/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "SDK for creating and managing isolated sandbox environments",
5
5
  "keywords": [
6
6
  "sandbox",