@phpsandbox/sdk 0.1.18 → 0.1.20

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/index.d.ts CHANGED
@@ -9,7 +9,7 @@ import Repl, { ReplActions, ReplEvents } from './repl.js';
9
9
  import { ShellEvents, ShellActions, type ProcessResult, type ShellProcess } from './shell.js';
10
10
  import Services, { ServiceActions, ServiceEvents } from './services.js';
11
11
  import Config, { ConfigActions } from './config.js';
12
- import Git, { GitActions } from './git.js';
12
+ import Git, { GitActions, type GitSyncAuthor } from './git.js';
13
13
  import { Disposable } from './types.js';
14
14
  import { RemoteError } from './errors/index.js';
15
15
  import { PublicationApi, PublicationInstance, PublicationRun, type PublishInput } from './publications.js';
@@ -133,7 +133,12 @@ export interface NotebookImportInspectionData {
133
133
  reason: string | null;
134
134
  requiredSecrets: NotebookImportRequiredSecret[];
135
135
  }
136
+ export interface NotebookGitConfiguration {
137
+ /** Set a sandbox default identity, or use null to reset it to the Helfer bot. */
138
+ author: GitSyncAuthor | null;
139
+ }
136
140
  export interface NotebookLifecycleInput {
141
+ git?: NotebookGitConfiguration;
137
142
  persistent?: true;
138
143
  }
139
144
  export interface CreateNotebookInput extends NotebookLifecycleInput {
@@ -144,6 +149,11 @@ export interface CreateNotebookInput extends NotebookLifecycleInput {
144
149
  secrets?: UpsertNotebookSecretItemInput[];
145
150
  }
146
151
  export type ForkNotebookInput = NotebookLifecycleInput;
152
+ export interface UpdateNotebookInput {
153
+ title?: string;
154
+ visibility?: 'public' | 'private' | 'unlisted';
155
+ git?: NotebookGitConfiguration;
156
+ }
147
157
  export interface NotebookPolicyData {
148
158
  autoDeleteWhenStale: boolean;
149
159
  staleAfterMinutes: number | null;
@@ -340,7 +350,7 @@ declare class ClientImplementation {
340
350
  data: T;
341
351
  }>;
342
352
  stream(path: string): Promise<ReadableStream<Uint8Array>>;
343
- sse(url: string): Promise<ReadableStream<Uint8Array>>;
353
+ sse(url: string, signal?: AbortSignal): Promise<ReadableStream<Uint8Array>>;
344
354
  private makeRequest;
345
355
  private fetchResponse;
346
356
  }
@@ -365,6 +375,9 @@ export interface NotebookData {
365
375
  slug?: string;
366
376
  description?: string | null;
367
377
  policy?: NotebookPolicyData;
378
+ git?: {
379
+ author: GitSyncAuthor;
380
+ };
368
381
  }
369
382
  export declare class NotebookInstance {
370
383
  #private;
@@ -394,6 +407,8 @@ export declare class NotebookInstance {
394
407
  private readonly disposables;
395
408
  constructor(data: NotebookData, client: Client);
396
409
  ready(): Promise<NotebookInitSuccessResult>;
410
+ /** Update sandbox metadata and Git defaults without restarting it. */
411
+ update(input: UpdateNotebookInput): Promise<NotebookData>;
397
412
  fork(input?: Partial<ForkNotebookInput>): Promise<NotebookInstance>;
398
413
  publication(): Promise<PublicationInstance | null>;
399
414
  publish(input?: PublishInput): Promise<PublicationRun>;
package/dist/index.js CHANGED
@@ -124,13 +124,14 @@ class ClientImplementation {
124
124
  }
125
125
  return response.body;
126
126
  }
127
- async sse(url) {
127
+ async sse(url, signal) {
128
128
  const response = await this.fetchResponse(authenticatedRequest(url, {
129
129
  method: 'GET',
130
130
  headers: {
131
131
  ...this.headers,
132
132
  'Accept': 'text/event-stream',
133
133
  },
134
+ ...(signal === undefined ? {} : { signal }),
134
135
  }));
135
136
  if (!response.ok) {
136
137
  throw await responseError(response);
@@ -296,6 +297,12 @@ export class NotebookInstance {
296
297
  // Just apply a reasonable timeout for the entire initialization process
297
298
  return ready();
298
299
  }
300
+ /** Update sandbox metadata and Git defaults without restarting it. */
301
+ async update(input) {
302
+ const response = await this.client.put(`/notebook/${this.data.id}`, input);
303
+ Object.assign(this.data, response.data);
304
+ return this.data;
305
+ }
299
306
  async fork(input = {}) {
300
307
  const response = await this.client.post(`/notebook/${this.data.id}/fork`, input);
301
308
  return new NotebookInstance(response.data, this.client);
@@ -146,6 +146,7 @@ export declare class PublicationApi {
146
146
  export declare class PublicationRun<TProvider extends PublicationProviderName = PublicationProviderName> {
147
147
  readonly initial: PublicationInstance<TProvider>;
148
148
  private readonly client;
149
+ private readonly streamAbort;
149
150
  private started;
150
151
  private completed;
151
152
  private finalError;
@@ -160,6 +161,8 @@ export declare class PublicationRun<TProvider extends PublicationProviderName =
160
161
  result(): Promise<PublishStreamResult>;
161
162
  publication(): Promise<PublicationInstance<TProvider>>;
162
163
  start(): this;
164
+ /** Stop observing this run; the server-side publication continues. */
165
+ dispose(): void;
163
166
  private subscribe;
164
167
  private consumeStream;
165
168
  private publish;
@@ -33,6 +33,7 @@ export class PublicationRun {
33
33
  constructor(initial, client) {
34
34
  this.initial = initial;
35
35
  this.client = client;
36
+ this.streamAbort = new AbortController();
36
37
  this.started = false;
37
38
  this.completed = false;
38
39
  this.finalError = null;
@@ -81,6 +82,19 @@ export class PublicationRun {
81
82
  void this.consumeStream(eventStreamUrl);
82
83
  return this;
83
84
  }
85
+ /** Stop observing this run; the server-side publication continues. */
86
+ dispose() {
87
+ if (this.completed)
88
+ return;
89
+ const error = new DOMException('Stopped observing publication; deployment continues.', 'AbortError');
90
+ if (!this.started) {
91
+ this.started = true;
92
+ this.resultPromise = Promise.reject(error);
93
+ this.resultPromise.catch(() => undefined);
94
+ }
95
+ this.streamAbort.abort(error);
96
+ this.fail(error);
97
+ }
84
98
  subscribe() {
85
99
  const queue = new AsyncPublishEventQueue();
86
100
  for (const event of this.bufferedEvents) {
@@ -99,7 +113,7 @@ export class PublicationRun {
99
113
  }
100
114
  async consumeStream(eventStreamUrl) {
101
115
  try {
102
- const stream = await this.client.sse(eventStreamUrl);
116
+ const stream = await this.client.sse(eventStreamUrl, this.streamAbort.signal);
103
117
  for await (const event of readPublishStreamEvents(stream)) {
104
118
  this.publish(event);
105
119
  if (event.type === 'result') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phpsandbox/sdk",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "The TypeScript SDK for PHPSandbox cloud development environments",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",