@phpsandbox/sdk 0.0.67 → 0.1.1

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.
Files changed (42) hide show
  1. package/README.md +10 -13
  2. package/dist/auth.d.ts +0 -1
  3. package/dist/auth.js +0 -3
  4. package/dist/beacon/index.d.ts +2 -0
  5. package/dist/beacon/index.js +5 -0
  6. package/dist/browser/phpsandbox-sdk.esm.js +311 -1016
  7. package/dist/browser/phpsandbox-sdk.esm.min.js +24 -24
  8. package/dist/browser/phpsandbox-sdk.iife.js +311 -1016
  9. package/dist/browser/phpsandbox-sdk.iife.min.js +24 -24
  10. package/dist/filesystem.d.ts +2 -1
  11. package/dist/filesystem.js +35 -2
  12. package/dist/index.d.ts +15 -24
  13. package/dist/index.js +19 -28
  14. package/dist/publications.d.ts +222 -0
  15. package/dist/{deployments.js → publications.js} +65 -70
  16. package/dist/repl.d.ts +0 -2
  17. package/dist/repl.js +0 -3
  18. package/dist/runtime/rest.js +1 -1
  19. package/dist/schemas/{deployments.d.ts → publications.d.ts} +68 -68
  20. package/dist/schemas/publications.js +133 -0
  21. package/dist/shell.d.ts +43 -22
  22. package/dist/shell.js +103 -75
  23. package/dist/terminal.d.ts +1 -3
  24. package/dist/terminal.js +2 -5
  25. package/docs/api-summary.md +13 -10
  26. package/docs/cdn-usage.md +4 -4
  27. package/docs/getting-started.md +6 -6
  28. package/examples/README.md +8 -9
  29. package/examples/basic.ts +1 -1
  30. package/examples/git-merge-smoke.ts +2 -2
  31. package/examples/laravel-load-test.ts +14 -19
  32. package/examples/notebook-readonly-smoke.ts +11 -11
  33. package/examples/publication-provider-label.ts +11 -0
  34. package/examples/{deploy-cloudflare-container.ts → publish-cloudflare-container.ts} +11 -11
  35. package/examples/{deploy-laravel-cloud.ts → publish-laravel-cloud.ts} +11 -11
  36. package/examples/{deploy-ssh-agent.ts → publish-ssh-agent.ts} +15 -16
  37. package/package.json +7 -2
  38. package/dist/deployments.d.ts +0 -253
  39. package/dist/laravel.d.ts +0 -22
  40. package/dist/laravel.js +0 -11
  41. package/dist/schemas/deployments.js +0 -133
  42. package/examples/deployment-provider-label.ts +0 -11
@@ -1,14 +1,14 @@
1
1
  import { ApiError } from './index.js';
2
- import { DeploymentEventDataSchema, DeploymentLogChunkDataSchema, DeployStreamSseEventNameSchema, DeployStreamSseEventSchema, } from './schemas/deployments.js';
3
- export * from './schemas/deployments.js';
4
- export class NotebookDeploymentApi {
2
+ import { PublicationEventDataSchema, PublicationLogChunkDataSchema, PublishStreamSseEventNameSchema, PublishStreamSseEventSchema, } from './schemas/publications.js';
3
+ export * from './schemas/publications.js';
4
+ export class NotebookPublicationApi {
5
5
  constructor(client) {
6
6
  this.client = client;
7
7
  }
8
8
  async current(notebookId) {
9
9
  try {
10
- const response = await this.client.get(`/notebook/${notebookId}/deployment`);
11
- return new DeploymentInstance(response.data, this.client, notebookId);
10
+ const response = await this.client.get(`/notebook/${notebookId}/publication`);
11
+ return new PublicationInstance(response.data, this.client, notebookId);
12
12
  }
13
13
  catch (error) {
14
14
  if (error instanceof ApiError && error.status === 404) {
@@ -18,74 +18,69 @@ export class NotebookDeploymentApi {
18
18
  }
19
19
  }
20
20
  async publish(notebookId, input) {
21
- const response = await this.client.post(`/notebook/${notebookId}/deployment/publish`, input);
22
- const run = new DeploymentRun(new DeploymentInstance(response.data, this.client, notebookId), this.client);
21
+ const response = await this.client.post(`/notebook/${notebookId}/publication`, input);
22
+ const run = new PublicationRun(new PublicationInstance(response.data, this.client, notebookId), this.client);
23
23
  run.start();
24
24
  return run;
25
25
  }
26
- async slugAvailability(id, slug) {
27
- const query = new URLSearchParams({ slug }).toString();
28
- const response = await this.client.get(`/notebook/${id}/deployment/slug-availability?${query}`);
29
- return response.data;
30
- }
31
26
  }
32
- export class DeploymentApi {
27
+ export class PublicationApi {
33
28
  constructor(client) {
34
29
  this.client = client;
35
30
  }
36
31
  async get(id) {
37
- const response = await this.client.get(`/deployments/${id}`);
38
- return new DeploymentInstance(response.data, this.client);
32
+ const response = await this.client.get(`/publications/${id}`);
33
+ return new PublicationInstance(response.data, this.client);
39
34
  }
40
- async delete(id) {
41
- await this.client.delete(`/deployments/${id}`);
35
+ async destroy(id) {
36
+ await this.client.delete(`/publications/${id}`);
42
37
  }
43
38
  async setProtection(id, input) {
44
- const response = await this.client.put(`/deployments/${id}/protection`, input);
45
- return new DeploymentInstance(response.data, this.client);
39
+ const response = await this.client.put(`/publications/${id}/protection`, input);
40
+ return new PublicationInstance(response.data, this.client);
46
41
  }
47
42
  async protection(id) {
48
- const response = await this.client.get(`/deployments/${id}/protection`);
43
+ const response = await this.client.get(`/publications/${id}/protection`);
49
44
  return response.data;
50
45
  }
51
46
  async createProtectionSession(id) {
52
- const response = await this.client.post(`/deployments/${id}/protection/session`);
47
+ const response = await this.client.post(`/publications/${id}/protection/session`);
53
48
  return response.data;
54
49
  }
55
50
  async disableProtection(id) {
56
- const response = await this.client.delete(`/deployments/${id}/protection`);
57
- return new DeploymentInstance(response.data, this.client);
51
+ const response = await this.client.delete(`/publications/${id}/protection`);
52
+ return new PublicationInstance(response.data, this.client);
58
53
  }
59
54
  async setFeedback(id, input) {
60
- const response = await this.client.put(`/deployments/${id}/feedback`, input);
61
- return new DeploymentInstance(response.data, this.client);
55
+ const response = await this.client.put(`/publications/${id}/feedback`, input);
56
+ return new PublicationInstance(response.data, this.client);
62
57
  }
63
58
  async listDomains(id) {
64
- const response = await this.client.get(`/deployments/${id}/domains`);
65
- return unwrapDeploymentDomainCollection(response.data);
59
+ const response = await this.client.get(`/publications/${id}/domains`);
60
+ return unwrapPublicationDomainCollection(response.data);
66
61
  }
67
62
  async createDomain(id, input) {
68
- const response = await this.client.post(`/deployments/${id}/domains`, input);
63
+ const response = await this.client.post(`/publications/${id}/domains`, input);
69
64
  return response.data;
70
65
  }
71
66
  async refreshDomain(id, domainId) {
72
- const response = await this.client.post(`/deployments/${id}/domains/${domainId}/refresh`);
67
+ const response = await this.client.post(`/publications/${id}/domains/${domainId}/refresh`);
73
68
  return response.data;
74
69
  }
75
70
  async deleteDomain(id, domainId) {
76
- await this.client.delete(`/deployments/${id}/domains/${domainId}`);
71
+ await this.client.delete(`/publications/${id}/domains/${domainId}`);
77
72
  }
78
73
  async events(id) {
79
- return parseNdjsonStream(await this.client.stream(`/deployments/${id}/events/stream`), DeploymentEventDataSchema);
74
+ return parseNdjsonStream(await this.client.stream(`/publications/${id}/events/stream`), PublicationEventDataSchema);
80
75
  }
81
76
  async buildLogs(id, buildId) {
82
- return parseNdjsonStream(await this.client.stream(`/deployments/${id}/builds/${buildId}/logs/stream`), DeploymentLogChunkDataSchema);
77
+ return parseNdjsonStream(await this.client.stream(`/publications/${id}/builds/${buildId}/logs/stream`), PublicationLogChunkDataSchema);
83
78
  }
84
79
  async logs(id) {
85
- return parseNdjsonStream(await this.client.stream(`/deployments/${id}/logs/stream`), DeploymentLogChunkDataSchema);
80
+ return parseNdjsonStream(await this.client.stream(`/publications/${id}/logs/stream`), PublicationLogChunkDataSchema);
86
81
  }
87
82
  }
88
- export class DeploymentRun {
83
+ export class PublicationRun {
89
84
  constructor(initial, client) {
90
85
  this.initial = initial;
91
86
  this.client = client;
@@ -116,7 +111,7 @@ export class DeploymentRun {
116
111
  this.start();
117
112
  return this.resultPromise;
118
113
  }
119
- async deployment() {
114
+ async publication() {
120
115
  await this.result();
121
116
  return this.initial.refresh();
122
117
  }
@@ -124,9 +119,9 @@ export class DeploymentRun {
124
119
  if (this.started) {
125
120
  return this;
126
121
  }
127
- const eventStreamUrl = this.initial.data.eventStreamUrl ?? this.initial.data.okraUrl;
122
+ const eventStreamUrl = this.initial.data.eventStreamUrl;
128
123
  if (!eventStreamUrl) {
129
- throw new Error(`Deployment ${this.initial.data.id} has no eventStreamUrl for SSE streaming`);
124
+ throw new Error(`Publication ${this.initial.data.id} has no eventStreamUrl for SSE streaming`);
130
125
  }
131
126
  this.started = true;
132
127
  this.resultPromise = new Promise((resolve, reject) => {
@@ -138,7 +133,7 @@ export class DeploymentRun {
138
133
  return this;
139
134
  }
140
135
  subscribe() {
141
- const queue = new AsyncDeployEventQueue();
136
+ const queue = new AsyncPublishEventQueue();
142
137
  for (const event of this.bufferedEvents) {
143
138
  queue.push(event);
144
139
  }
@@ -156,7 +151,7 @@ export class DeploymentRun {
156
151
  async consumeStream(eventStreamUrl) {
157
152
  try {
158
153
  const stream = await this.client.sse(eventStreamUrl);
159
- for await (const event of readDeployStreamEvents(stream)) {
154
+ for await (const event of readPublishStreamEvents(stream)) {
160
155
  this.publish(event);
161
156
  if (event.type === 'result') {
162
157
  const { type: _, ...result } = event;
@@ -165,7 +160,7 @@ export class DeploymentRun {
165
160
  }
166
161
  }
167
162
  if (!this.finalResult) {
168
- throw new Error('Deploy stream ended without result');
163
+ throw new Error('Publish stream ended without result');
169
164
  }
170
165
  this.closeSubscribers();
171
166
  }
@@ -196,33 +191,33 @@ export class DeploymentRun {
196
191
  this.subscribers.clear();
197
192
  }
198
193
  }
199
- export class DeploymentInstance {
194
+ export class PublicationInstance {
200
195
  constructor(data, client, notebookId) {
201
196
  this.data = data;
202
197
  this.client = client;
203
198
  this.notebookId = notebookId;
204
199
  }
205
200
  async refresh() {
206
- const response = await this.client.get(`/deployments/${this.data.id}`);
207
- return new DeploymentInstance(response.data, this.client, this.notebookId);
201
+ const response = await this.client.get(`/publications/${this.data.id}`);
202
+ return new PublicationInstance(response.data, this.client, this.notebookId);
208
203
  }
209
204
  publish() {
210
205
  if (!this.notebookId) {
211
- return Promise.reject(new Error('Deployment publish requires a notebook-scoped deployment instance.'));
206
+ return Promise.reject(new Error('Publishing requires a notebook-scoped publication instance.'));
212
207
  }
213
- return this.client.notebook.deployment.publish(this.notebookId);
208
+ return this.client.notebook.publication.publish(this.notebookId);
214
209
  }
215
- delete() {
216
- return this.client.deployments.delete(this.data.id);
210
+ destroy() {
211
+ return this.client.publications.destroy(this.data.id);
217
212
  }
218
213
  async wait(options = {}) {
219
214
  const intervalMs = options.intervalMs ?? 1000;
220
215
  const timeoutMs = options.timeoutMs ?? 300000;
221
216
  const startedAt = Date.now();
222
217
  let current = this;
223
- while (!deploymentStatusIsTerminal(current.data.status)) {
218
+ while (!publicationStatusIsTerminal(current.data.status)) {
224
219
  if (Date.now() - startedAt > timeoutMs) {
225
- throw new Error(`Timed out waiting for deployment ${this.data.id}`);
220
+ throw new Error(`Timed out waiting for publication ${this.data.id}`);
226
221
  }
227
222
  await delay(intervalMs);
228
223
  current = await current.refresh();
@@ -230,58 +225,58 @@ export class DeploymentInstance {
230
225
  return current;
231
226
  }
232
227
  events() {
233
- return this.client.deployments.events(this.data.id);
228
+ return this.client.publications.events(this.data.id);
234
229
  }
235
230
  buildLogs(buildId = this.data.latestBuild?.id ?? '') {
236
231
  if (buildId === '') {
237
- return Promise.reject(new Error('Deployment has no latest build id'));
232
+ return Promise.reject(new Error('Publication has no latest build id'));
238
233
  }
239
- return this.client.deployments.buildLogs(this.data.id, buildId);
234
+ return this.client.publications.buildLogs(this.data.id, buildId);
240
235
  }
241
236
  logs() {
242
- return this.client.deployments.logs(this.data.id);
237
+ return this.client.publications.logs(this.data.id);
243
238
  }
244
239
  setProtection(input) {
245
- return this.client.deployments.setProtection(this.data.id, input);
240
+ return this.client.publications.setProtection(this.data.id, input);
246
241
  }
247
242
  protection() {
248
- return this.client.deployments.protection(this.data.id);
243
+ return this.client.publications.protection(this.data.id);
249
244
  }
250
245
  createProtectionSession() {
251
- return this.client.deployments.createProtectionSession(this.data.id);
246
+ return this.client.publications.createProtectionSession(this.data.id);
252
247
  }
253
248
  disableProtection() {
254
- return this.client.deployments.disableProtection(this.data.id);
249
+ return this.client.publications.disableProtection(this.data.id);
255
250
  }
256
251
  setFeedback(input) {
257
- return this.client.deployments.setFeedback(this.data.id, input);
252
+ return this.client.publications.setFeedback(this.data.id, input);
258
253
  }
259
254
  domains() {
260
- return this.client.deployments.listDomains(this.data.id);
255
+ return this.client.publications.listDomains(this.data.id);
261
256
  }
262
257
  addDomain(input) {
263
- return this.client.deployments.createDomain(this.data.id, input);
258
+ return this.client.publications.createDomain(this.data.id, input);
264
259
  }
265
260
  refreshDomain(domainId) {
266
- return this.client.deployments.refreshDomain(this.data.id, domainId);
261
+ return this.client.publications.refreshDomain(this.data.id, domainId);
267
262
  }
268
263
  deleteDomain(domainId) {
269
- return this.client.deployments.deleteDomain(this.data.id, domainId);
264
+ return this.client.publications.deleteDomain(this.data.id, domainId);
270
265
  }
271
266
  }
272
- function deploymentStatusIsTerminal(status) {
267
+ function publicationStatusIsTerminal(status) {
273
268
  return ['healthy', 'failed', 'stopped', 'deleted', 'delete_failed'].includes(status);
274
269
  }
275
270
  function delay(ms) {
276
271
  return new Promise((resolve) => setTimeout(resolve, ms));
277
272
  }
278
- function unwrapDeploymentDomainCollection(input) {
273
+ function unwrapPublicationDomainCollection(input) {
279
274
  if (Array.isArray(input)) {
280
275
  return input;
281
276
  }
282
277
  return Array.isArray(input.data) ? input.data : [];
283
278
  }
284
- class AsyncDeployEventQueue {
279
+ class AsyncPublishEventQueue {
285
280
  constructor() {
286
281
  this.values = [];
287
282
  this.pending = [];
@@ -343,7 +338,7 @@ class AsyncDeployEventQueue {
343
338
  });
344
339
  }
345
340
  }
346
- async function* readDeployStreamEvents(stream) {
341
+ async function* readPublishStreamEvents(stream) {
347
342
  const reader = parseSSEStream(stream).getReader();
348
343
  try {
349
344
  while (true) {
@@ -351,7 +346,7 @@ async function* readDeployStreamEvents(stream) {
351
346
  if (done) {
352
347
  return;
353
348
  }
354
- const event = parseDeployStreamEvent(value);
349
+ const event = parsePublishStreamEvent(value);
355
350
  if (event) {
356
351
  yield event;
357
352
  }
@@ -361,11 +356,11 @@ async function* readDeployStreamEvents(stream) {
361
356
  reader.releaseLock();
362
357
  }
363
358
  }
364
- function parseDeployStreamEvent(event) {
365
- if (!DeployStreamSseEventNameSchema.safeParse(event.event).success) {
359
+ function parsePublishStreamEvent(event) {
360
+ if (!PublishStreamSseEventNameSchema.safeParse(event.event).success) {
366
361
  return null;
367
362
  }
368
- return DeployStreamSseEventSchema.parse(event);
363
+ return PublishStreamSseEventSchema.parse(event);
369
364
  }
370
365
  function parseSSEStream(input) {
371
366
  const decoder = new TextDecoder();
package/dist/repl.d.ts CHANGED
@@ -17,7 +17,6 @@ export interface ReplActions {
17
17
  input: string;
18
18
  }>;
19
19
  'repl.stop': Action<{}, void>;
20
- 'repl.start': Action<{}>;
21
20
  'repl.resize': Action<{
22
21
  cols: number;
23
22
  rows: number;
@@ -32,7 +31,6 @@ export default class Repl {
32
31
  eval(code: string, args?: string, repl?: ReplOption): Promise<EvalResult>;
33
32
  write(input: string): Promise<void>;
34
33
  stop(): Promise<void>;
35
- start(): Promise<void>;
36
34
  resize(cols: number, rows: number): Promise<void>;
37
35
  listen<T extends keyof ReplEvents>(event: T, handler: (data: ReplEvents[T]) => void): Disposable;
38
36
  onOutput(handler: (data: ReplEvents['repl.output']) => void): Disposable;
package/dist/repl.js CHANGED
@@ -11,9 +11,6 @@ export default class Repl {
11
11
  stop() {
12
12
  return this.okra.invoke('repl.stop');
13
13
  }
14
- start() {
15
- return this.okra.invoke('repl.start');
16
- }
17
14
  resize(cols, rows) {
18
15
  return this.okra.invoke('repl.resize', { cols, rows });
19
16
  }
@@ -62,7 +62,7 @@ export class RestRuntimeInvoker {
62
62
  this.refresh = refresh;
63
63
  this.refreshPromise = null;
64
64
  this.notebookId = data.id;
65
- this.configure(data.runtimeUrl ?? data.okraUrl);
65
+ this.configure(data.runtimeUrl);
66
66
  }
67
67
  configure(runtimeUrl) {
68
68
  const actionUrl = new URL(runtimeUrl);