@castari/sdk 0.1.2 → 0.1.3
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/client.d.ts +6 -0
- package/dist/client.js +20 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export interface ClientOptions extends Partial<QueryConfig> {
|
|
|
24
24
|
platformUrl?: string;
|
|
25
25
|
/** Optional sessionId to resume */
|
|
26
26
|
resume?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Use the platform API as a WebSocket proxy instead of connecting directly to the sandbox.
|
|
29
|
+
* Useful when your network blocks the sandbox preview domains.
|
|
30
|
+
* Defaults to false.
|
|
31
|
+
*/
|
|
32
|
+
useProxy?: boolean;
|
|
27
33
|
}
|
|
28
34
|
export declare class CastariClient {
|
|
29
35
|
private ws?;
|
package/dist/client.js
CHANGED
|
@@ -150,11 +150,30 @@ export class CastariClient {
|
|
|
150
150
|
const errorText = await response.text();
|
|
151
151
|
throw new Error(`Failed to start sandbox: ${errorText}`);
|
|
152
152
|
}
|
|
153
|
-
const { id, url, authHeaders, authParams } = await response.json();
|
|
153
|
+
const { id, url, proxyUrl, authHeaders, authParams } = await response.json();
|
|
154
154
|
this.sandboxId = id;
|
|
155
|
+
const useProxy = this.options.useProxy ?? (process.env.CASTARI_USE_PROXY === 'true');
|
|
155
156
|
if (this.options.debug) {
|
|
156
157
|
console.log(`✅ Sandbox started: ${id} at ${url}`);
|
|
158
|
+
if (useProxy && proxyUrl) {
|
|
159
|
+
console.log(`🔀 Using proxy mode via ${proxyUrl}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// If proxy mode is enabled and we have a proxy URL, use it
|
|
163
|
+
if (useProxy && proxyUrl) {
|
|
164
|
+
// Proxy mode: connect through platform API
|
|
165
|
+
const proxyConfigUrl = `${platformUrl}/proxy/${id}/config`;
|
|
166
|
+
const proxyWsUrl = proxyUrl;
|
|
167
|
+
return {
|
|
168
|
+
configUrl: proxyConfigUrl,
|
|
169
|
+
wsUrl: proxyWsUrl,
|
|
170
|
+
// No auth headers/params needed - proxy handles sandbox auth
|
|
171
|
+
cleanup: async () => {
|
|
172
|
+
await this.stop({ delete: true });
|
|
173
|
+
}
|
|
174
|
+
};
|
|
157
175
|
}
|
|
176
|
+
// Direct mode: connect to sandbox directly
|
|
158
177
|
const baseUrl = url.replace(/\/$/, '');
|
|
159
178
|
const configUrl = `${baseUrl.replace('ws://', 'http://').replace('wss://', 'https://')}/config`;
|
|
160
179
|
const wsUrlBase = `${baseUrl.replace('https://', 'wss://').replace('http://', 'ws://')}/ws`;
|