@phpsandbox/sdk 0.1.10 → 0.1.12
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 +1 -0
- package/dist/browser/phpsandbox-sdk.esm.js +22 -11
- package/dist/browser/phpsandbox-sdk.esm.min.js +10 -10
- package/dist/browser/phpsandbox-sdk.iife.js +22 -11
- package/dist/browser/phpsandbox-sdk.iife.min.js +10 -10
- package/dist/http.d.ts +6 -0
- package/dist/http.js +11 -0
- package/dist/index.js +4 -6
- package/dist/ports.d.ts +1 -0
- package/dist/ports.js +3 -0
- package/dist/runtime/rest.js +3 -2
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.js +3 -0
- package/docs/api-summary.md +1 -0
- package/package.json +1 -1
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workers does not support `redirect: "error"`, while `follow` can
|
|
3
|
+
* forward authorization headers across redirects. Handle redirects manually so
|
|
4
|
+
* authenticated requests never follow them.
|
|
5
|
+
*/
|
|
6
|
+
export declare function authenticatedRequest(input: URL | string, init: RequestInit): Request;
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Workers does not support `redirect: "error"`, while `follow` can
|
|
3
|
+
* forward authorization headers across redirects. Handle redirects manually so
|
|
4
|
+
* authenticated requests never follow them.
|
|
5
|
+
*/
|
|
6
|
+
export function authenticatedRequest(input, init) {
|
|
7
|
+
return new Request(input, {
|
|
8
|
+
...init,
|
|
9
|
+
redirect: 'manual',
|
|
10
|
+
});
|
|
11
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ import { RestRuntimeInvoker } from './runtime/rest.js';
|
|
|
30
30
|
import { Feedback } from './feedback.js';
|
|
31
31
|
import { IntegrationApi } from './integrations.js';
|
|
32
32
|
import { SandboxIntegrationApi } from './sandbox-integrations.js';
|
|
33
|
+
import { authenticatedRequest } from './http.js';
|
|
33
34
|
export { LspConnection } from './lsp.js';
|
|
34
35
|
export { FileChangeFilter, FileChangeType, FileType, } from './filesystem.js';
|
|
35
36
|
export { notebookBuiltinServices, notebookKnownServices } from './services.js';
|
|
@@ -105,10 +106,9 @@ class ClientImplementation {
|
|
|
105
106
|
return this.makeRequest('PATCH', path, { body: body === undefined ? undefined : JSON.stringify(body) });
|
|
106
107
|
}
|
|
107
108
|
async stream(path) {
|
|
108
|
-
const response = await this.fetchResponse(
|
|
109
|
+
const response = await this.fetchResponse(authenticatedRequest(new URL(path.replace(/^\//, ''), this.baseUrl), {
|
|
109
110
|
method: 'GET',
|
|
110
111
|
headers: this.headers,
|
|
111
|
-
redirect: 'error',
|
|
112
112
|
}));
|
|
113
113
|
if (!response.ok) {
|
|
114
114
|
throw remoteError('core', errorPayload(await responsePayload(response)), response);
|
|
@@ -119,9 +119,8 @@ class ClientImplementation {
|
|
|
119
119
|
return response.body;
|
|
120
120
|
}
|
|
121
121
|
async sse(url) {
|
|
122
|
-
const response = await this.fetchResponse(
|
|
122
|
+
const response = await this.fetchResponse(authenticatedRequest(url, {
|
|
123
123
|
method: 'GET',
|
|
124
|
-
redirect: 'error',
|
|
125
124
|
headers: {
|
|
126
125
|
...this.headers,
|
|
127
126
|
'Accept': 'text/event-stream',
|
|
@@ -136,11 +135,10 @@ class ClientImplementation {
|
|
|
136
135
|
return response.body;
|
|
137
136
|
}
|
|
138
137
|
async makeRequest(method, path, init) {
|
|
139
|
-
const response = await this.fetchResponse(
|
|
138
|
+
const response = await this.fetchResponse(authenticatedRequest(new URL(path.replace(/^\//, ''), this.baseUrl), {
|
|
140
139
|
method,
|
|
141
140
|
...init,
|
|
142
141
|
headers: this.headers,
|
|
143
|
-
redirect: 'error',
|
|
144
142
|
}));
|
|
145
143
|
if (!response.ok) {
|
|
146
144
|
throw remoteError('core', errorPayload(await responsePayload(response)), response);
|
package/dist/ports.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export default class Ports {
|
|
|
6
6
|
private readonly telemetry;
|
|
7
7
|
constructor(okra: NotebookInstance, telemetry: RuntimeTelemetry);
|
|
8
8
|
list(): Promise<PortInfo[]>;
|
|
9
|
+
resolve(port: number): Promise<PortInfo>;
|
|
9
10
|
watch(options?: RuntimeWatchOptions): ReadableStream<PortInfo[]>;
|
|
10
11
|
}
|
package/dist/ports.js
CHANGED
|
@@ -7,6 +7,9 @@ export default class Ports {
|
|
|
7
7
|
list() {
|
|
8
8
|
return this.okra.invoke('container.opened-ports');
|
|
9
9
|
}
|
|
10
|
+
resolve(port) {
|
|
11
|
+
return this.okra.invoke('container.resolve-port', { port });
|
|
12
|
+
}
|
|
10
13
|
watch(options = {}) {
|
|
11
14
|
return watchRuntimeTelemetry(this.okra, this.telemetry, 'ports', 'container.ports', (ports) => ports, options);
|
|
12
15
|
}
|
package/dist/runtime/rest.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PHPSandboxError, RemoteError, TransportError, remoteError } from '../errors/index.js';
|
|
2
|
+
import { authenticatedRequest } from '../http.js';
|
|
2
3
|
const restActionRoutes = {
|
|
3
4
|
'runtime.ready': { method: 'GET', path: '/runtime' },
|
|
4
5
|
'config.get': { method: 'GET', path: '/runtime/config' },
|
|
@@ -8,6 +9,7 @@ const restActionRoutes = {
|
|
|
8
9
|
'container.stop': { method: 'POST', path: '/runtime/container/stop' },
|
|
9
10
|
'container.set-php': { method: 'PUT', path: '/runtime/container/php' },
|
|
10
11
|
'container.opened-ports': { method: 'GET', path: '/runtime/container/ports' },
|
|
12
|
+
'container.resolve-port': { method: 'POST', path: '/runtime/container/ports/resolve' },
|
|
11
13
|
'container.stats': { method: 'GET', path: '/runtime/container/stats' },
|
|
12
14
|
'terminal.list': { method: 'GET', path: '/runtime/terminals' },
|
|
13
15
|
'shell.exec': { method: 'POST', path: '/runtime/executions' },
|
|
@@ -119,12 +121,11 @@ export class RestRuntimeInvoker {
|
|
|
119
121
|
Authorization: `Bearer ${this.ticket}`,
|
|
120
122
|
};
|
|
121
123
|
const body = runtimeActionRequestBody(action, data, url, headers);
|
|
122
|
-
return
|
|
124
|
+
return authenticatedRequest(url, {
|
|
123
125
|
method: route.method,
|
|
124
126
|
headers,
|
|
125
127
|
body: route.method === 'GET' ? undefined : body,
|
|
126
128
|
signal,
|
|
127
|
-
redirect: 'error',
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
async refreshAuthorization() {
|
package/dist/runtime.d.ts
CHANGED
|
@@ -28,6 +28,9 @@ export interface RuntimeActions {
|
|
|
28
28
|
'container.restart': Action<{}, void>;
|
|
29
29
|
'container.stop': Action<{}, void>;
|
|
30
30
|
'container.opened-ports': Action<{}, PortInfo[]>;
|
|
31
|
+
'container.resolve-port': Action<{
|
|
32
|
+
port: number;
|
|
33
|
+
}, PortInfo>;
|
|
31
34
|
'container.stats': Action<{}, RuntimeStats | null>;
|
|
32
35
|
'container.set-php': Action<{
|
|
33
36
|
version: string;
|
|
@@ -54,6 +57,7 @@ export declare class RuntimePorts {
|
|
|
54
57
|
private readonly ports;
|
|
55
58
|
constructor(ports: Ports);
|
|
56
59
|
list(): Promise<PortInfo[]>;
|
|
60
|
+
resolve(port: number): Promise<PortInfo>;
|
|
57
61
|
watch(options?: RuntimeWatchOptions): ReadableStream<PortInfo[]>;
|
|
58
62
|
}
|
|
59
63
|
export default class Runtime {
|
package/dist/runtime.js
CHANGED
package/docs/api-summary.md
CHANGED
|
@@ -62,6 +62,7 @@ Connection lifecycle methods, streaming actions, and event subscriptions require
|
|
|
62
62
|
|
|
63
63
|
- `notebook.runtime.logs.follow({ signal? })` returns `ReadableStream<RuntimeLogEntry>`
|
|
64
64
|
- `notebook.runtime.ports.list()` returns the current preview ports
|
|
65
|
+
- `notebook.runtime.ports.resolve(port)` returns preview routing information even when the port is not open
|
|
65
66
|
- `notebook.runtime.ports.watch({ signal? })` returns `ReadableStream<PortInfo[]>`
|
|
66
67
|
- `notebook.runtime.metrics.current()` returns the current CPU, memory, and disk sample
|
|
67
68
|
- `notebook.runtime.metrics.watch({ signal? })` returns `ReadableStream<RuntimeStats>`
|
package/package.json
CHANGED