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