@phpsandbox/sdk 0.1.9 → 0.1.11
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 +42 -50
- package/dist/beacon/index.d.ts +1 -7
- package/dist/beacon/index.js +14 -13
- package/dist/beacon/navigator.d.ts +8 -36
- package/dist/beacon/navigator.js +1 -62
- package/dist/browser/phpsandbox-sdk.esm.js +552 -692
- package/dist/browser/phpsandbox-sdk.esm.min.js +24 -24
- package/dist/browser/phpsandbox-sdk.iife.js +552 -692
- package/dist/browser/phpsandbox-sdk.iife.min.js +35 -35
- package/dist/composer.d.ts +10 -8
- package/dist/composer.js +18 -18
- package/dist/errors/index.d.ts +43 -8
- package/dist/errors/index.js +120 -14
- package/dist/feedback.js +1 -2
- package/dist/filesystem.d.ts +0 -17
- package/dist/filesystem.js +2 -21
- package/dist/git.d.ts +1 -5
- package/dist/git.js +6 -8
- package/dist/http.d.ts +6 -0
- package/dist/http.js +11 -0
- package/dist/index.d.ts +54 -144
- package/dist/index.js +170 -289
- package/dist/integrations.d.ts +0 -2
- package/dist/integrations.js +5 -11
- package/dist/log.d.ts +0 -2
- package/dist/lsp.js +1 -1
- package/dist/metrics.d.ts +3 -3
- package/dist/ports.d.ts +1 -1
- package/dist/publications.d.ts +4 -54
- package/dist/publications.js +25 -103
- package/dist/runtime/rest.js +35 -18
- package/dist/runtime.d.ts +68 -0
- package/dist/runtime.js +46 -0
- package/dist/sandbox-integrations.d.ts +1 -2
- package/dist/sandbox-integrations.js +11 -14
- package/dist/schemas/publications.d.ts +0 -6
- package/dist/schemas/publications.js +0 -1
- package/dist/servers.d.ts +4 -2
- package/dist/servers.js +5 -8
- package/dist/shell.d.ts +2 -14
- package/dist/shell.js +1 -21
- package/dist/socket/index.d.ts +6 -7
- package/dist/socket/index.js +39 -25
- package/dist/types.d.ts +0 -12
- package/dist/types.js +1 -15
- package/docs/api-summary.md +28 -28
- package/docs/cdn-usage.md +43 -55
- package/docs/getting-started.md +43 -26
- package/examples/README.md +5 -35
- package/examples/basic.ts +9 -18
- package/examples/get.ts +2 -2
- package/examples/git-merge-smoke.ts +2 -3
- package/examples/laravel-load-test.ts +31 -36
- package/examples/notebook-readonly-smoke.ts +12 -26
- package/examples/publication-provider-label.ts +1 -1
- package/examples/publish-cloudflare-container.ts +2 -2
- package/examples/publish-laravel-cloud.ts +2 -2
- package/examples/publish-ssh-agent.ts +2 -2
- package/package.json +4 -3
- package/dist/container.d.ts +0 -65
- package/dist/container.js +0 -30
package/dist/index.js
CHANGED
|
@@ -12,14 +12,10 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
12
12
|
var _NotebookInstance_instances, _NotebookInstance_initPromise, _NotebookInstance_init;
|
|
13
13
|
import { Filesystem } from './filesystem.js';
|
|
14
14
|
import Terminals from './terminal.js';
|
|
15
|
-
import Container from './container.js';
|
|
16
15
|
import Auth from './auth.js';
|
|
17
16
|
import Lsp from './lsp.js';
|
|
18
17
|
import Composer from './composer.js';
|
|
19
|
-
import
|
|
20
|
-
import Metrics from './metrics.js';
|
|
21
|
-
import Ports from './ports.js';
|
|
22
|
-
import { RuntimeTelemetry } from './runtime-telemetry.js';
|
|
18
|
+
import Runtime from './runtime.js';
|
|
23
19
|
import Repl from './repl.js';
|
|
24
20
|
import Shell from './shell.js';
|
|
25
21
|
import Services from './services.js';
|
|
@@ -27,33 +23,18 @@ import Config from './config.js';
|
|
|
27
23
|
import { Transport } from './socket/index.js';
|
|
28
24
|
import EventManager from './events/index.js';
|
|
29
25
|
import Git from './git.js';
|
|
30
|
-
import {
|
|
31
|
-
import { PublicationApi,
|
|
26
|
+
import { PHPSandboxError, RemoteError, TransportError, remoteError, } from './errors/index.js';
|
|
27
|
+
import { PublicationApi, PublicationInstance, PublicationRun, } from './publications.js';
|
|
32
28
|
import { ServerApi } from './servers.js';
|
|
33
29
|
import { RestRuntimeInvoker } from './runtime/rest.js';
|
|
34
30
|
import { Feedback } from './feedback.js';
|
|
35
31
|
import { IntegrationApi } from './integrations.js';
|
|
36
32
|
import { SandboxIntegrationApi } from './sandbox-integrations.js';
|
|
37
|
-
|
|
38
|
-
export
|
|
39
|
-
export
|
|
40
|
-
export
|
|
41
|
-
export
|
|
42
|
-
export * from './metrics.js';
|
|
43
|
-
export * from './ports.js';
|
|
44
|
-
export * from './runtime-telemetry.js';
|
|
45
|
-
export * from './shell.js';
|
|
46
|
-
export * from './terminal.js';
|
|
47
|
-
export * from './git.js';
|
|
48
|
-
export * from './services.js';
|
|
49
|
-
export * from './config.js';
|
|
50
|
-
export * from './utils/promise.js';
|
|
51
|
-
export * from './errors/index.js';
|
|
52
|
-
export * from './publications.js';
|
|
53
|
-
export * from './servers.js';
|
|
54
|
-
export * from './feedback.js';
|
|
55
|
-
export * from './integrations.js';
|
|
56
|
-
export * from './sandbox-integrations.js';
|
|
33
|
+
import { authenticatedRequest } from './http.js';
|
|
34
|
+
export { LspConnection } from './lsp.js';
|
|
35
|
+
export { FileChangeFilter, FileChangeType, FileType, } from './filesystem.js';
|
|
36
|
+
export { notebookBuiltinServices, notebookKnownServices } from './services.js';
|
|
37
|
+
export { PHPSandboxError, RemoteError, TransportError, } from './errors/index.js';
|
|
57
38
|
function normalizeNotebookSecretInputs(input) {
|
|
58
39
|
if (Array.isArray(input)) {
|
|
59
40
|
return input;
|
|
@@ -63,88 +44,20 @@ function normalizeNotebookSecretInputs(input) {
|
|
|
63
44
|
...(typeof value === 'string' ? { value } : value),
|
|
64
45
|
}));
|
|
65
46
|
}
|
|
66
|
-
|
|
67
|
-
constructor(message, data = {}) {
|
|
68
|
-
super(message);
|
|
69
|
-
this.message = message;
|
|
70
|
-
this.data = data;
|
|
71
|
-
this.name = 'NotebookInitError';
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export class ApiError extends Error {
|
|
75
|
-
constructor(response, body) {
|
|
76
|
-
const data = parseApiErrorBody(body);
|
|
77
|
-
const apiMessage = apiErrorMessage(data, body);
|
|
78
|
-
super(`PHPSandbox API Error: ${response.status} ${response.statusText}${apiMessage === '' ? '' : ` - ${apiMessage}`}`);
|
|
79
|
-
this.response = response;
|
|
80
|
-
this.body = body;
|
|
81
|
-
this.status = response.status;
|
|
82
|
-
this.data = data;
|
|
83
|
-
this.apiMessage = apiMessage === '' ? undefined : apiMessage;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function parseApiErrorBody(body) {
|
|
87
|
-
try {
|
|
88
|
-
return JSON.parse(body);
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function apiErrorMessage(data, fallback) {
|
|
95
|
-
if (data !== null && typeof data === 'object') {
|
|
96
|
-
const record = data;
|
|
97
|
-
if (typeof record.message === 'string' && record.message.trim() !== '') {
|
|
98
|
-
return record.message.trim();
|
|
99
|
-
}
|
|
100
|
-
if (record.error !== undefined) {
|
|
101
|
-
return typeof record.error === 'string' ? record.error.trim() : JSON.stringify(record.error);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return fallback.trim();
|
|
105
|
-
}
|
|
106
|
-
export class NotebookApi {
|
|
47
|
+
class NotebookApi {
|
|
107
48
|
constructor(client) {
|
|
108
49
|
this.client = client;
|
|
109
|
-
this.secrets = new NotebookSecretApi(client);
|
|
110
|
-
this.composerCredentials = new NotebookComposerCredentialApi(client);
|
|
111
|
-
this.preview = new NotebookPreviewApi(client);
|
|
112
|
-
this.mail = new NotebookMailApi(client);
|
|
113
|
-
this.publication = new NotebookPublicationApi(client);
|
|
114
50
|
}
|
|
115
|
-
async create(template, input = {}
|
|
51
|
+
async create(template, input = {}) {
|
|
116
52
|
const response = await this.client.post('/notebook', { template, ...input });
|
|
117
|
-
|
|
118
|
-
if (!init) {
|
|
119
|
-
return instance;
|
|
120
|
-
}
|
|
121
|
-
return this.init(instance);
|
|
53
|
+
return new NotebookInstance(response.data, this.client);
|
|
122
54
|
}
|
|
123
55
|
async get(id) {
|
|
124
56
|
const response = await this.client.get(`/notebook/${id}`);
|
|
125
57
|
return new NotebookInstance(response.data, this.client);
|
|
126
58
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return new NotebookInstance(response.data, this.client);
|
|
130
|
-
}
|
|
131
|
-
async destroy(id) {
|
|
132
|
-
await this.client.delete(`/notebook/${id}`);
|
|
133
|
-
}
|
|
134
|
-
async fork(id, input = {}) {
|
|
135
|
-
const response = await this.client.post(`/notebook/${id}/fork`, input);
|
|
136
|
-
return new NotebookInstance(response.data, this.client);
|
|
137
|
-
}
|
|
138
|
-
async gitCredentials(id) {
|
|
139
|
-
const response = await this.client.post(`/notebook/${id}/git/credentials`);
|
|
140
|
-
return response.data;
|
|
141
|
-
}
|
|
142
|
-
openFromData(data) {
|
|
143
|
-
return this.init(new NotebookInstance(data, this.client));
|
|
144
|
-
}
|
|
145
|
-
async init(instance) {
|
|
146
|
-
await instance.ready();
|
|
147
|
-
return instance;
|
|
59
|
+
open(data) {
|
|
60
|
+
return new NotebookInstance(data, this.client);
|
|
148
61
|
}
|
|
149
62
|
}
|
|
150
63
|
function normalizeApiBaseUrl(url) {
|
|
@@ -155,18 +68,18 @@ function normalizeApiBaseUrl(url) {
|
|
|
155
68
|
baseUrl.hash = '';
|
|
156
69
|
return baseUrl.toString();
|
|
157
70
|
}
|
|
158
|
-
|
|
71
|
+
class ClientImplementation {
|
|
159
72
|
get runtimeTransport() {
|
|
160
73
|
return this.runtimeTransportValue;
|
|
161
74
|
}
|
|
162
|
-
constructor(token, url = 'https://api.phpsandbox.io/v1', options = {}) {
|
|
163
|
-
this.runtimeTransportValue = 'realtime';
|
|
75
|
+
constructor(token, url = 'https://api.phpsandbox.io/v1', options = {}, runtimeTransport = 'realtime') {
|
|
164
76
|
this.fetch = globalThis.fetch;
|
|
165
77
|
this.publications = new PublicationApi(this);
|
|
166
78
|
this.notebook = new NotebookApi(this);
|
|
167
79
|
this.servers = new ServerApi(this);
|
|
168
80
|
this.integrations = new IntegrationApi(this);
|
|
169
|
-
this.options =
|
|
81
|
+
this.options = { ...options };
|
|
82
|
+
this.runtimeTransportValue = runtimeTransport;
|
|
170
83
|
this.baseUrl = normalizeApiBaseUrl(url);
|
|
171
84
|
if (options.fetch) {
|
|
172
85
|
this.fetch = options.fetch;
|
|
@@ -193,20 +106,20 @@ export class Client {
|
|
|
193
106
|
return this.makeRequest('PATCH', path, { body: body === undefined ? undefined : JSON.stringify(body) });
|
|
194
107
|
}
|
|
195
108
|
async stream(path) {
|
|
196
|
-
const response = await this.
|
|
109
|
+
const response = await this.fetchResponse(authenticatedRequest(new URL(path.replace(/^\//, ''), this.baseUrl), {
|
|
197
110
|
method: 'GET',
|
|
198
111
|
headers: this.headers,
|
|
199
112
|
}));
|
|
200
113
|
if (!response.ok) {
|
|
201
|
-
throw
|
|
114
|
+
throw remoteError('core', errorPayload(await responsePayload(response)), response);
|
|
202
115
|
}
|
|
203
116
|
if (!response.body) {
|
|
204
|
-
throw new
|
|
117
|
+
throw new TransportError('PHPSandbox API response body is not readable.', 'InvalidResponse', response);
|
|
205
118
|
}
|
|
206
119
|
return response.body;
|
|
207
120
|
}
|
|
208
121
|
async sse(url) {
|
|
209
|
-
const response = await this.
|
|
122
|
+
const response = await this.fetchResponse(authenticatedRequest(url, {
|
|
210
123
|
method: 'GET',
|
|
211
124
|
headers: {
|
|
212
125
|
...this.headers,
|
|
@@ -214,135 +127,88 @@ export class Client {
|
|
|
214
127
|
},
|
|
215
128
|
}));
|
|
216
129
|
if (!response.ok) {
|
|
217
|
-
throw
|
|
130
|
+
throw remoteError('core', errorPayload(await responsePayload(response)), response);
|
|
218
131
|
}
|
|
219
132
|
if (!response.body) {
|
|
220
|
-
throw new
|
|
133
|
+
throw new TransportError('PHPSandbox API SSE response body is not readable.', 'InvalidResponse', response);
|
|
221
134
|
}
|
|
222
135
|
return response.body;
|
|
223
136
|
}
|
|
224
137
|
async makeRequest(method, path, init) {
|
|
225
|
-
const response = await this.
|
|
138
|
+
const response = await this.fetchResponse(authenticatedRequest(new URL(path.replace(/^\//, ''), this.baseUrl), {
|
|
226
139
|
method,
|
|
227
140
|
...init,
|
|
228
141
|
headers: this.headers,
|
|
229
142
|
}));
|
|
230
143
|
if (!response.ok) {
|
|
231
|
-
throw
|
|
144
|
+
throw remoteError('core', errorPayload(await responsePayload(response)), response);
|
|
232
145
|
}
|
|
233
146
|
if (response.status === 204) {
|
|
234
147
|
return { data: undefined };
|
|
235
148
|
}
|
|
236
149
|
const body = await response.text();
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
150
|
+
if (body === '') {
|
|
151
|
+
throw new TransportError('PHPSandbox API returned an empty response.', 'InvalidResponse', response);
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
const payload = JSON.parse(body);
|
|
155
|
+
if (payload === null || typeof payload !== 'object' || Array.isArray(payload) || !Object.prototype.hasOwnProperty.call(payload, 'data')) {
|
|
156
|
+
throw new TransportError('PHPSandbox API returned an invalid success response.', 'InvalidResponse', response);
|
|
157
|
+
}
|
|
158
|
+
return payload;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (TransportError.is(error)) {
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
throw new TransportError('PHPSandbox API returned an invalid JSON response.', 'InvalidResponse', error);
|
|
165
|
+
}
|
|
243
166
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
167
|
+
async fetchResponse(request) {
|
|
168
|
+
try {
|
|
169
|
+
return await this.fetch(request);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
if (error instanceof DOMException && error.name === 'AbortError') {
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
throw new TransportError('Unable to reach the PHPSandbox API.', 'ConnectionFailed', error);
|
|
176
|
+
}
|
|
248
177
|
}
|
|
249
178
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
async list(id, options) {
|
|
255
|
-
const params = new URLSearchParams();
|
|
256
|
-
if (options?.environment)
|
|
257
|
-
params.set('environment', options.environment);
|
|
258
|
-
const query = params.toString();
|
|
259
|
-
const response = await this.client.get(`/notebook/${id}/secrets${query ? `?${query}` : ''}`);
|
|
260
|
-
return response.data;
|
|
179
|
+
async function responsePayload(response) {
|
|
180
|
+
const body = await response.text();
|
|
181
|
+
if (body === '') {
|
|
182
|
+
return undefined;
|
|
261
183
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const response = await this.client.put(`/notebook/${id}/secrets`, payload);
|
|
265
|
-
return response.data;
|
|
266
|
-
}
|
|
267
|
-
async setMany(id, input) {
|
|
268
|
-
const response = await this.client.put(`/notebook/${id}/secrets`, {
|
|
269
|
-
secrets: normalizeNotebookSecretInputs(input),
|
|
270
|
-
});
|
|
271
|
-
return response.data;
|
|
184
|
+
try {
|
|
185
|
+
return JSON.parse(body);
|
|
272
186
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (options?.environment)
|
|
276
|
-
params.set('environment', options.environment);
|
|
277
|
-
const query = params.toString();
|
|
278
|
-
await this.client.delete(`/notebook/${id}/secrets/${encodeURIComponent(name)}${query ? `?${query}` : ''}`);
|
|
187
|
+
catch (error) {
|
|
188
|
+
throw new TransportError('PHPSandbox API returned an invalid JSON response.', 'InvalidResponse', error);
|
|
279
189
|
}
|
|
280
190
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
async set(id, input) {
|
|
286
|
-
const response = await this.client.put(`/notebook/${id}/composer/credentials`, input);
|
|
287
|
-
return response.data;
|
|
288
|
-
}
|
|
289
|
-
async remove(id, type, url) {
|
|
290
|
-
const params = new URLSearchParams({ type });
|
|
291
|
-
if (url)
|
|
292
|
-
params.set('url', url);
|
|
293
|
-
await this.client.delete(`/notebook/${id}/composer/credentials?${params.toString()}`);
|
|
294
|
-
}
|
|
191
|
+
function errorPayload(payload) {
|
|
192
|
+
return payload !== null && typeof payload === 'object' && !Array.isArray(payload)
|
|
193
|
+
? payload.error
|
|
194
|
+
: undefined;
|
|
295
195
|
}
|
|
296
|
-
export class
|
|
196
|
+
export class PHPSandbox {
|
|
297
197
|
constructor(client) {
|
|
298
198
|
this.client = client;
|
|
199
|
+
this.notebook = client.notebook;
|
|
200
|
+
this.publications = client.publications;
|
|
201
|
+
this.servers = client.servers;
|
|
202
|
+
this.integrations = client.integrations;
|
|
299
203
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const response = await this.client.get(`/notebook/${id}/preview${query}`);
|
|
303
|
-
return response.data;
|
|
304
|
-
}
|
|
305
|
-
async setPassword(id, input) {
|
|
306
|
-
const response = await this.client.put(`/notebook/${id}/preview`, input);
|
|
307
|
-
return response.data;
|
|
308
|
-
}
|
|
309
|
-
async disable(id) {
|
|
310
|
-
await this.client.delete(`/notebook/${id}/preview`);
|
|
311
|
-
}
|
|
312
|
-
async createSession(id, input) {
|
|
313
|
-
const response = await this.client.post(`/notebook/${id}/preview/session`, input);
|
|
314
|
-
return response.data;
|
|
315
|
-
}
|
|
316
|
-
async createHandoff(id, input) {
|
|
317
|
-
const response = await this.client.post(`/notebook/${id}/preview/handoff`, input);
|
|
318
|
-
return response.data;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
export class NotebookMailApi {
|
|
322
|
-
constructor(client) {
|
|
323
|
-
this.client = client;
|
|
324
|
-
}
|
|
325
|
-
async status(id) {
|
|
326
|
-
const response = await this.client.get(`/notebook/${id}/mail`);
|
|
327
|
-
return response.data;
|
|
328
|
-
}
|
|
329
|
-
async enable(id) {
|
|
330
|
-
const response = await this.client.put(`/notebook/${id}/mail`);
|
|
331
|
-
return response.data;
|
|
332
|
-
}
|
|
333
|
-
async disable(id) {
|
|
334
|
-
await this.client.delete(`/notebook/${id}/mail`);
|
|
335
|
-
}
|
|
336
|
-
async list(id, options = {}) {
|
|
337
|
-
const response = await this.client.get(`/notebook/${id}/mails${formatQueryString(options)}`);
|
|
338
|
-
return response.data;
|
|
204
|
+
get runtimeTransport() {
|
|
205
|
+
return this.client.runtimeTransport;
|
|
339
206
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
return response.data;
|
|
207
|
+
static realtime(token, url = 'https://api.phpsandbox.io/v1', options = {}) {
|
|
208
|
+
return new PHPSandbox(new ClientImplementation(token, url, options));
|
|
343
209
|
}
|
|
344
|
-
|
|
345
|
-
|
|
210
|
+
static rest(token, url = 'https://api.phpsandbox.io/v1', options = {}) {
|
|
211
|
+
return new PHPSandbox(new ClientImplementation(token, url, options, 'rest'));
|
|
346
212
|
}
|
|
347
213
|
}
|
|
348
214
|
export class NotebookInstance {
|
|
@@ -378,7 +244,6 @@ export class NotebookInstance {
|
|
|
378
244
|
};
|
|
379
245
|
this.socket = new Transport(connectionUrl, this.emitter, {
|
|
380
246
|
debug: client.options.debug,
|
|
381
|
-
startClosed: client.options.startClosed,
|
|
382
247
|
webSocket: client.options.webSocket,
|
|
383
248
|
});
|
|
384
249
|
this.watchConnection();
|
|
@@ -389,12 +254,8 @@ export class NotebookInstance {
|
|
|
389
254
|
this.auth = new Auth(this);
|
|
390
255
|
this.lsp = new Lsp(this);
|
|
391
256
|
this.composer = new Composer(this, client);
|
|
392
|
-
|
|
393
|
-
this.logs = new Logs(this, telemetry);
|
|
394
|
-
this.metrics = new Metrics(this, telemetry);
|
|
395
|
-
this.ports = new Ports(this, telemetry);
|
|
257
|
+
this.runtime = new Runtime(this);
|
|
396
258
|
this.repl = new Repl(this);
|
|
397
|
-
this.container = new Container(this);
|
|
398
259
|
this.shell = new Shell(this);
|
|
399
260
|
this.git = new Git(this, client);
|
|
400
261
|
this.services = new Services(this);
|
|
@@ -419,7 +280,7 @@ export class NotebookInstance {
|
|
|
419
280
|
* If ready is called, ensure the websocket is open so server-driven
|
|
420
281
|
* initialization can begin, but do not block on an extra ping roundtrip.
|
|
421
282
|
*/
|
|
422
|
-
if (
|
|
283
|
+
if (!socket.isConnected) {
|
|
423
284
|
await socket.connect();
|
|
424
285
|
}
|
|
425
286
|
return __classPrivateFieldGet(this, _NotebookInstance_initPromise, "f");
|
|
@@ -428,14 +289,27 @@ export class NotebookInstance {
|
|
|
428
289
|
// Just apply a reasonable timeout for the entire initialization process
|
|
429
290
|
return ready();
|
|
430
291
|
}
|
|
431
|
-
fork(input = {}) {
|
|
432
|
-
|
|
292
|
+
async fork(input = {}) {
|
|
293
|
+
const response = await this.client.post(`/notebook/${this.data.id}/fork`, input);
|
|
294
|
+
return new NotebookInstance(response.data, this.client);
|
|
433
295
|
}
|
|
434
|
-
publication() {
|
|
435
|
-
|
|
296
|
+
async publication() {
|
|
297
|
+
try {
|
|
298
|
+
const response = await this.client.get(`/notebook/${this.data.id}/publication`);
|
|
299
|
+
return new PublicationInstance(response.data, this.client, this.data.id);
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
if (RemoteError.is(error) && error.status === 404) {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
436
307
|
}
|
|
437
|
-
publish(input) {
|
|
438
|
-
|
|
308
|
+
async publish(input) {
|
|
309
|
+
const response = await this.client.post(`/notebook/${this.data.id}/publication`, input);
|
|
310
|
+
const run = new PublicationRun(new PublicationInstance(response.data, this.client, this.data.id), this.client);
|
|
311
|
+
run.start();
|
|
312
|
+
return run;
|
|
439
313
|
}
|
|
440
314
|
run(command, argsOrOpts = [], opts) {
|
|
441
315
|
if (Array.isArray(argsOrOpts)) {
|
|
@@ -449,19 +323,20 @@ export class NotebookInstance {
|
|
|
449
323
|
}
|
|
450
324
|
return this.run(command, argsOrOpts).wait();
|
|
451
325
|
}
|
|
452
|
-
|
|
453
|
-
|
|
326
|
+
async destroy() {
|
|
327
|
+
await this.client.delete(`/notebook/${this.data.id}`);
|
|
328
|
+
this.socket?.terminate(new RemoteError('Notebook has been deleted.', {
|
|
329
|
+
source: 'runtime',
|
|
330
|
+
status: 503,
|
|
331
|
+
code: 'NotebookUnavailable',
|
|
332
|
+
details: { id: this.data.id },
|
|
333
|
+
}));
|
|
454
334
|
}
|
|
455
|
-
|
|
456
|
-
return this.
|
|
457
|
-
this.socket?.terminate(new NotebookUnavailableError('Notebook has been deleted.', { id: this.data.id }));
|
|
458
|
-
});
|
|
335
|
+
restart() {
|
|
336
|
+
return this.invoke('container.restart');
|
|
459
337
|
}
|
|
460
338
|
stop() {
|
|
461
|
-
return this.container.stop
|
|
462
|
-
}
|
|
463
|
-
restart() {
|
|
464
|
-
return this.container.restart();
|
|
339
|
+
return this.invoke('container.stop');
|
|
465
340
|
}
|
|
466
341
|
invoke(action, data = {}, options = {}) {
|
|
467
342
|
if (this.restInvoker !== null) {
|
|
@@ -478,9 +353,6 @@ export class NotebookInstance {
|
|
|
478
353
|
}
|
|
479
354
|
return this.realtimeSocket().send(action, data || {});
|
|
480
355
|
}
|
|
481
|
-
ping() {
|
|
482
|
-
return this.invoke('ping');
|
|
483
|
-
}
|
|
484
356
|
listen(event, handler) {
|
|
485
357
|
const disposable = this.emitter.listen(event, handler);
|
|
486
358
|
this.disposables.push(disposable);
|
|
@@ -495,9 +367,6 @@ export class NotebookInstance {
|
|
|
495
367
|
connected() {
|
|
496
368
|
return this.waitForSocketConnection({ rejectOnClose: true });
|
|
497
369
|
}
|
|
498
|
-
whenConnected() {
|
|
499
|
-
return this.waitForSocketConnection({ rejectOnClose: false });
|
|
500
|
-
}
|
|
501
370
|
waitForSocketConnection(options) {
|
|
502
371
|
const socket = this.realtimeSocket();
|
|
503
372
|
const terminalError = socket.getTerminalError();
|
|
@@ -570,7 +439,7 @@ export class NotebookInstance {
|
|
|
570
439
|
}
|
|
571
440
|
restInitialization() {
|
|
572
441
|
if (this.restInvoker === null) {
|
|
573
|
-
throw new
|
|
442
|
+
throw new PHPSandboxError('This operation requires the REST transport.');
|
|
574
443
|
}
|
|
575
444
|
if (__classPrivateFieldGet(this, _NotebookInstance_initPromise, "f") === null) {
|
|
576
445
|
__classPrivateFieldSet(this, _NotebookInstance_initPromise, this.restInvoker.ready().then((result) => {
|
|
@@ -582,15 +451,12 @@ export class NotebookInstance {
|
|
|
582
451
|
}
|
|
583
452
|
return __classPrivateFieldGet(this, _NotebookInstance_initPromise, "f");
|
|
584
453
|
}
|
|
585
|
-
update(input) {
|
|
586
|
-
return this.client.notebook.update(this.data.id, input);
|
|
587
|
-
}
|
|
588
454
|
onDidInitialize(handler) {
|
|
589
455
|
return this.listen('notebook.initialized', handler);
|
|
590
456
|
}
|
|
591
457
|
async reconnect() {
|
|
592
458
|
const socket = this.realtimeSocket();
|
|
593
|
-
const whenConnected = this.
|
|
459
|
+
const whenConnected = this.waitForSocketConnection({ rejectOnClose: false });
|
|
594
460
|
// Use the socket's reconnect method which preserves listeners
|
|
595
461
|
// and uses the underlying ReconnectingWebSocket mechanism
|
|
596
462
|
socket.reconnect();
|
|
@@ -605,7 +471,7 @@ export class NotebookInstance {
|
|
|
605
471
|
}
|
|
606
472
|
realtimeSocket() {
|
|
607
473
|
if (this.socket === null) {
|
|
608
|
-
throw new
|
|
474
|
+
throw new PHPSandboxError('This operation requires the realtime transport.');
|
|
609
475
|
}
|
|
610
476
|
return this.socket;
|
|
611
477
|
}
|
|
@@ -617,7 +483,12 @@ _NotebookInstance_initPromise = new WeakMap(), _NotebookInstance_instances = new
|
|
|
617
483
|
initializationListener.dispose();
|
|
618
484
|
this.initialized = result;
|
|
619
485
|
if (result.type === 'error') {
|
|
620
|
-
reject(new
|
|
486
|
+
reject(new RemoteError(result.message, {
|
|
487
|
+
source: 'runtime',
|
|
488
|
+
status: 503,
|
|
489
|
+
code: 'NotebookInitializationFailed',
|
|
490
|
+
details: result.data,
|
|
491
|
+
}));
|
|
621
492
|
return;
|
|
622
493
|
}
|
|
623
494
|
resolve(result);
|
|
@@ -635,79 +506,89 @@ _NotebookInstance_initPromise = new WeakMap(), _NotebookInstance_instances = new
|
|
|
635
506
|
void __classPrivateFieldGet(this, _NotebookInstance_initPromise, "f").catch(() => { });
|
|
636
507
|
return __classPrivateFieldGet(this, _NotebookInstance_initPromise, "f");
|
|
637
508
|
};
|
|
638
|
-
|
|
509
|
+
class NotebookSecrets {
|
|
639
510
|
constructor(client, notebookId) {
|
|
640
511
|
this.client = client;
|
|
641
512
|
this.notebookId = notebookId;
|
|
642
513
|
}
|
|
643
|
-
list(options) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
return this.client.notebook.secrets.setMany(this.notebookId, input);
|
|
651
|
-
}
|
|
652
|
-
delete(name, options) {
|
|
653
|
-
return this.client.notebook.secrets.delete(this.notebookId, name, options);
|
|
514
|
+
async list(options) {
|
|
515
|
+
const params = new URLSearchParams();
|
|
516
|
+
if (options?.environment)
|
|
517
|
+
params.set('environment', options.environment);
|
|
518
|
+
const query = params.toString();
|
|
519
|
+
const response = await this.client.get(`/notebook/${this.notebookId}/secrets${query ? `?${query}` : ''}`);
|
|
520
|
+
return response.data;
|
|
654
521
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
this.notebookId = notebookId;
|
|
522
|
+
async set(name, input) {
|
|
523
|
+
const payload = typeof input === 'string' ? { name, value: input } : { name, ...input };
|
|
524
|
+
const response = await this.client.put(`/notebook/${this.notebookId}/secrets`, payload);
|
|
525
|
+
return response.data;
|
|
660
526
|
}
|
|
661
|
-
|
|
662
|
-
|
|
527
|
+
async setMany(input) {
|
|
528
|
+
const response = await this.client.put(`/notebook/${this.notebookId}/secrets`, {
|
|
529
|
+
secrets: normalizeNotebookSecretInputs(input),
|
|
530
|
+
});
|
|
531
|
+
return response.data;
|
|
663
532
|
}
|
|
664
|
-
|
|
665
|
-
|
|
533
|
+
async delete(name, options) {
|
|
534
|
+
const params = new URLSearchParams();
|
|
535
|
+
if (options?.environment)
|
|
536
|
+
params.set('environment', options.environment);
|
|
537
|
+
const query = params.toString();
|
|
538
|
+
await this.client.delete(`/notebook/${this.notebookId}/secrets/${encodeURIComponent(name)}${query ? `?${query}` : ''}`);
|
|
666
539
|
}
|
|
667
540
|
}
|
|
668
|
-
|
|
541
|
+
class NotebookPreview {
|
|
669
542
|
constructor(client, notebookId) {
|
|
670
543
|
this.client = client;
|
|
671
544
|
this.notebookId = notebookId;
|
|
672
545
|
}
|
|
673
|
-
get(url) {
|
|
674
|
-
|
|
546
|
+
async get(url) {
|
|
547
|
+
const query = url === undefined ? '' : `?${new URLSearchParams({ url }).toString()}`;
|
|
548
|
+
const response = await this.client.get(`/notebook/${this.notebookId}/preview${query}`);
|
|
549
|
+
return response.data;
|
|
675
550
|
}
|
|
676
|
-
setPassword(input) {
|
|
677
|
-
|
|
551
|
+
async setPassword(input) {
|
|
552
|
+
const response = await this.client.put(`/notebook/${this.notebookId}/preview`, input);
|
|
553
|
+
return response.data;
|
|
678
554
|
}
|
|
679
|
-
disable() {
|
|
680
|
-
|
|
555
|
+
async disable() {
|
|
556
|
+
await this.client.delete(`/notebook/${this.notebookId}/preview`);
|
|
681
557
|
}
|
|
682
|
-
createSession(input) {
|
|
683
|
-
|
|
558
|
+
async createSession(input) {
|
|
559
|
+
const response = await this.client.post(`/notebook/${this.notebookId}/preview/session`, input);
|
|
560
|
+
return response.data;
|
|
684
561
|
}
|
|
685
|
-
createHandoff(input) {
|
|
686
|
-
|
|
562
|
+
async createHandoff(input) {
|
|
563
|
+
const response = await this.client.post(`/notebook/${this.notebookId}/preview/handoff`, input);
|
|
564
|
+
return response.data;
|
|
687
565
|
}
|
|
688
566
|
}
|
|
689
|
-
|
|
567
|
+
class NotebookMail {
|
|
690
568
|
constructor(client, notebookId) {
|
|
691
569
|
this.client = client;
|
|
692
570
|
this.notebookId = notebookId;
|
|
693
571
|
}
|
|
694
|
-
status() {
|
|
695
|
-
|
|
572
|
+
async status() {
|
|
573
|
+
const response = await this.client.get(`/notebook/${this.notebookId}/mail`);
|
|
574
|
+
return response.data;
|
|
696
575
|
}
|
|
697
|
-
enable() {
|
|
698
|
-
|
|
576
|
+
async enable() {
|
|
577
|
+
const response = await this.client.put(`/notebook/${this.notebookId}/mail`);
|
|
578
|
+
return response.data;
|
|
699
579
|
}
|
|
700
|
-
disable() {
|
|
701
|
-
|
|
580
|
+
async disable() {
|
|
581
|
+
await this.client.delete(`/notebook/${this.notebookId}/mail`);
|
|
702
582
|
}
|
|
703
|
-
list(options = {}) {
|
|
704
|
-
return this.client.notebook
|
|
583
|
+
async list(options = {}) {
|
|
584
|
+
return this.client.get(`/notebook/${this.notebookId}/mails${formatQueryString(options)}`);
|
|
705
585
|
}
|
|
706
|
-
get(hash) {
|
|
707
|
-
|
|
586
|
+
async get(hash) {
|
|
587
|
+
const response = await this.client.get(`/notebook/${this.notebookId}/mails/${encodeURIComponent(hash)}`);
|
|
588
|
+
return response.data;
|
|
708
589
|
}
|
|
709
|
-
delete(hash) {
|
|
710
|
-
|
|
590
|
+
async delete(hash) {
|
|
591
|
+
await this.client.delete(`/notebook/${this.notebookId}/mails/${encodeURIComponent(hash)}`);
|
|
711
592
|
}
|
|
712
593
|
}
|
|
713
594
|
function formatQueryString(params) {
|