@phpsandbox/sdk 0.0.36 → 0.0.38

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 CHANGED
@@ -110,6 +110,7 @@ Each `NotebookInstance` exposes service clients:
110
110
  - `notebook.auth` (`Auth`)
111
111
  - `notebook.log` (`Log`)
112
112
  - `notebook.services` (`Services`)
113
+ - `notebook.mail` (`NotebookMail`)
113
114
 
114
115
  Notes:
115
116
 
@@ -208,6 +209,22 @@ const history = await notebook.git.log('main');
208
209
  console.log(history[0]);
209
210
  ```
210
211
 
212
+ ### Mail
213
+
214
+ ```ts
215
+ const state = await notebook.mail.status();
216
+
217
+ if (!state.enabled) {
218
+ await notebook.mail.enable();
219
+ }
220
+
221
+ const mails = await notebook.mail.list();
222
+ const mail = await notebook.mail.get(mails.data[0].hash);
223
+
224
+ await notebook.mail.delete(mail.hash);
225
+ await notebook.mail.disable();
226
+ ```
227
+
211
228
  ### Events
212
229
 
213
230
  ```ts
@@ -624,8 +624,46 @@ var Terminal = class {
624
624
  listen(event, handler) {
625
625
  return this.okra.listen(event, handler);
626
626
  }
627
+ async attach(id, opts) {
628
+ const handle = this.processHandle(id, opts?.abortSignal);
629
+ const task = await this.okra.invoke(
630
+ "terminal.attach",
631
+ {
632
+ id,
633
+ replayHistory: opts?.replayHistory
634
+ },
635
+ { abortSignal: opts?.abortSignal }
636
+ );
637
+ if (!task) {
638
+ handle.dispose();
639
+ return false;
640
+ }
641
+ return {
642
+ ...handle.process,
643
+ ...task
644
+ };
645
+ }
627
646
  async spawn(command, args, opts) {
628
647
  const id = opts?.id || nanoid();
648
+ const handle = this.processHandle(id, opts?.abortSignal);
649
+ const { abortSignal, ...otherOpts } = opts ?? {};
650
+ const result = await this.okra.invoke(
651
+ "terminal.spawn",
652
+ {
653
+ command: [command, ...args],
654
+ opts: {
655
+ id,
656
+ ...otherOpts
657
+ }
658
+ },
659
+ { abortSignal }
660
+ );
661
+ return {
662
+ ...handle.process,
663
+ ...result
664
+ };
665
+ }
666
+ processHandle(id, abortSignal) {
629
667
  const disposables = /* @__PURE__ */ new Set();
630
668
  const dispose = () => {
631
669
  for (const disposable of disposables) {
@@ -675,28 +713,18 @@ var Terminal = class {
675
713
  const resize = (dimensions) => {
676
714
  this.okra.invoke("terminal.resize", { id, width: dimensions.cols, height: dimensions.rows });
677
715
  };
678
- const { abortSignal, ...otherOpts } = opts ?? {};
679
716
  if (abortSignal) {
680
717
  abortSignal.addEventListener("abort", kill);
681
718
  }
682
- const result = await this.okra.invoke(
683
- "terminal.spawn",
684
- {
685
- command: [command, ...args],
686
- opts: {
687
- id,
688
- ...otherOpts
689
- }
690
- },
691
- { abortSignal }
692
- );
693
719
  return {
694
- exit,
695
- input,
696
- output,
697
- kill,
698
- resize,
699
- ...result
720
+ process: {
721
+ exit,
722
+ input,
723
+ output,
724
+ kill,
725
+ resize
726
+ },
727
+ dispose
700
728
  };
701
729
  }
702
730
  };
@@ -4972,6 +5000,7 @@ var NotebookApi = class {
4972
5000
  this.client = client;
4973
5001
  this.secrets = new NotebookSecretApi(client);
4974
5002
  this.previewAuth = new NotebookPreviewAuthApi(client);
5003
+ this.mail = new NotebookMailApi(client);
4975
5004
  }
4976
5005
  async create(template, input = {}, init = true) {
4977
5006
  const response = await this.client.post("/notebook", { template, ...input });
@@ -5094,6 +5123,35 @@ var NotebookPreviewAuthApi = class {
5094
5123
  await this.client.delete(`/notebook/${id}/preview-auth`);
5095
5124
  }
5096
5125
  };
5126
+ var NotebookMailApi = class {
5127
+ constructor(client) {
5128
+ this.client = client;
5129
+ }
5130
+ async status(id) {
5131
+ const response = await this.client.get(`/notebook/${id}/mail`);
5132
+ return response.data;
5133
+ }
5134
+ async enable(id) {
5135
+ const response = await this.client.put(`/notebook/${id}/mail`);
5136
+ return response.data;
5137
+ }
5138
+ async disable(id) {
5139
+ await this.client.delete(`/notebook/${id}/mail`);
5140
+ }
5141
+ async list(id, options = {}) {
5142
+ const response = await this.client.get(
5143
+ `/notebook/${id}/mails${formatQueryString(options)}`
5144
+ );
5145
+ return response.data;
5146
+ }
5147
+ async get(id, hash) {
5148
+ const response = await this.client.get(`/notebook/${id}/mails/${encodeURIComponent(hash)}`);
5149
+ return response.data;
5150
+ }
5151
+ async delete(id, hash) {
5152
+ await this.client.delete(`/notebook/${id}/mails/${encodeURIComponent(hash)}`);
5153
+ }
5154
+ };
5097
5155
  var _initPromise, _NotebookInstance_instances, init_fn;
5098
5156
  var NotebookInstance = class {
5099
5157
  constructor(data, client) {
@@ -5125,6 +5183,7 @@ var NotebookInstance = class {
5125
5183
  this.services = new Services(this);
5126
5184
  this.secrets = new NotebookSecrets(client, this.data.id);
5127
5185
  this.previewAuth = new NotebookPreviewAuth(client, this.data.id);
5186
+ this.mail = new NotebookMail(client, this.data.id);
5128
5187
  }
5129
5188
  async ready() {
5130
5189
  const terminalError = this.socket.getTerminalError();
@@ -5313,6 +5372,40 @@ var NotebookPreviewAuth = class {
5313
5372
  return this.client.notebook.previewAuth.delete(this.notebookId);
5314
5373
  }
5315
5374
  };
5375
+ var NotebookMail = class {
5376
+ constructor(client, notebookId) {
5377
+ this.client = client;
5378
+ this.notebookId = notebookId;
5379
+ }
5380
+ status() {
5381
+ return this.client.notebook.mail.status(this.notebookId);
5382
+ }
5383
+ enable() {
5384
+ return this.client.notebook.mail.enable(this.notebookId);
5385
+ }
5386
+ disable() {
5387
+ return this.client.notebook.mail.disable(this.notebookId);
5388
+ }
5389
+ list(options = {}) {
5390
+ return this.client.notebook.mail.list(this.notebookId, options);
5391
+ }
5392
+ get(hash) {
5393
+ return this.client.notebook.mail.get(this.notebookId, hash);
5394
+ }
5395
+ delete(hash) {
5396
+ return this.client.notebook.mail.delete(this.notebookId, hash);
5397
+ }
5398
+ };
5399
+ function formatQueryString(params) {
5400
+ const searchParams = new URLSearchParams();
5401
+ for (const [key, value] of Object.entries(params)) {
5402
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
5403
+ searchParams.set(key, String(value));
5404
+ }
5405
+ }
5406
+ const query = searchParams.toString();
5407
+ return query === "" ? "" : `?${query}`;
5408
+ }
5316
5409
  export {
5317
5410
  ApiError,
5318
5411
  Beacon,
@@ -5332,6 +5425,8 @@ export {
5332
5425
  NotebookApi,
5333
5426
  NotebookInitError,
5334
5427
  NotebookInstance,
5428
+ NotebookMail,
5429
+ NotebookMailApi,
5335
5430
  NotebookPreviewAuth,
5336
5431
  NotebookPreviewAuthApi,
5337
5432
  NotebookSecretApi,