@phpsandbox/sdk 0.1.2 → 0.1.6

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.
@@ -33,12 +33,17 @@ var PHPSandbox = (() => {
33
33
  CommandError: () => CommandError,
34
34
  ComposerCredentials: () => ComposerCredentials,
35
35
  ErrorEvent: () => ErrorEvent,
36
+ Feedback: () => Feedback,
36
37
  FileChangeFilter: () => FileChangeFilter,
37
38
  FileChangeType: () => FileChangeType,
38
39
  FileType: () => FileType,
39
40
  Filesystem: () => Filesystem,
40
41
  FilesystemError: () => FilesystemError,
41
42
  FilesystemErrorType: () => FilesystemErrorType,
43
+ GitTarget: () => GitTarget,
44
+ GitTargetApi: () => GitTargetApi,
45
+ Integration: () => Integration,
46
+ IntegrationApi: () => IntegrationApi,
42
47
  LspConnection: () => LspConnection,
43
48
  NotebookApi: () => NotebookApi,
44
49
  NotebookComposerCredentialApi: () => NotebookComposerCredentialApi,
@@ -91,18 +96,48 @@ var PHPSandbox = (() => {
91
96
  PublishStreamSseResultEventSchema: () => PublishStreamSseResultEventSchema,
92
97
  RateLimitError: () => RateLimitError,
93
98
  RuntimeTelemetry: () => RuntimeTelemetry,
99
+ SandboxIntegration: () => SandboxIntegration,
100
+ SandboxIntegrationApi: () => SandboxIntegrationApi,
94
101
  SendTimeoutError: () => SendTimeoutError,
95
102
  ServerApi: () => ServerApi,
96
103
  ServerInstance: () => ServerInstance,
97
104
  ShellProcess: () => ShellProcess,
98
105
  UnsupportedRuntimeTransportError: () => UnsupportedRuntimeTransportError,
106
+ integrationId: () => integrationId,
99
107
  notebookBuiltinServices: () => notebookBuiltinServices,
100
108
  notebookKnownServices: () => notebookKnownServices,
101
109
  once: () => once,
110
+ sandboxIntegrationId: () => sandboxIntegrationId,
102
111
  timeout: () => timeout,
103
112
  watchRuntimeTelemetry: () => watchRuntimeTelemetry
104
113
  });
105
114
 
115
+ // src/errors/index.ts
116
+ var PromiseTimeoutError = class extends Error {
117
+ constructor(message, time3) {
118
+ super(message);
119
+ this.time = time3;
120
+ }
121
+ };
122
+ var SendTimeoutError = class _SendTimeoutError extends PromiseTimeoutError {
123
+ static fromPromiseTimeoutError(error51) {
124
+ return new _SendTimeoutError(error51.message, error51.time);
125
+ }
126
+ };
127
+ var NotebookUnavailableError = class extends Error {
128
+ constructor(message = "Notebook is no longer available", raw = {}) {
129
+ super(message);
130
+ this.raw = raw;
131
+ this.name = "NotebookUnavailableError";
132
+ }
133
+ };
134
+ var UnsupportedRuntimeTransportError = class extends Error {
135
+ constructor(message) {
136
+ super(message);
137
+ this.name = "UnsupportedRuntimeTransportError";
138
+ }
139
+ };
140
+
106
141
  // src/types.ts
107
142
  var ErrorEvent = class extends Error {
108
143
  constructor(code, message, raw = {}) {
@@ -317,6 +352,77 @@ var PHPSandbox = (() => {
317
352
  }
318
353
  });
319
354
  }
355
+ follow(path, options = {}) {
356
+ if (this.okra.runtimeTransport === "rest") {
357
+ return new ReadableStream({
358
+ start(controller) {
359
+ controller.error(new UnsupportedRuntimeTransportError("Following files requires the realtime transport."));
360
+ }
361
+ });
362
+ }
363
+ const id = nanoid();
364
+ let disposable = null;
365
+ let abort = null;
366
+ let started = false;
367
+ let closed = false;
368
+ const stop = async () => {
369
+ if (closed) {
370
+ return;
371
+ }
372
+ closed = true;
373
+ disposable?.dispose();
374
+ disposable = null;
375
+ if (abort && options.signal) {
376
+ options.signal.removeEventListener("abort", abort);
377
+ }
378
+ abort = null;
379
+ if (started) {
380
+ await this.okra.invoke("fs.cancelFollow", { id }).catch(() => false);
381
+ }
382
+ };
383
+ return new ReadableStream({
384
+ start: (controller) => {
385
+ disposable = this.okra.listen(`fs.follow.${id}`, (event) => {
386
+ if (!closed) {
387
+ controller.enqueue(event.data);
388
+ }
389
+ });
390
+ if (options.signal) {
391
+ abort = () => {
392
+ void stop().finally(() => controller.error(options.signal?.reason ?? new Error("Aborted")));
393
+ };
394
+ if (options.signal.aborted) {
395
+ abort();
396
+ return;
397
+ }
398
+ options.signal.addEventListener("abort", abort, { once: true });
399
+ }
400
+ started = true;
401
+ void this.okra.invoke("fs.follow", { id, path, lines: options.lines ?? 10 }).then(() => {
402
+ if (!closed) {
403
+ closed = true;
404
+ disposable?.dispose();
405
+ if (abort && options.signal) {
406
+ options.signal.removeEventListener("abort", abort);
407
+ }
408
+ abort = null;
409
+ controller.close();
410
+ }
411
+ }).catch((error51) => {
412
+ if (!closed) {
413
+ closed = true;
414
+ disposable?.dispose();
415
+ if (abort && options.signal) {
416
+ options.signal.removeEventListener("abort", abort);
417
+ }
418
+ abort = null;
419
+ controller.error(error51);
420
+ }
421
+ });
422
+ },
423
+ cancel: stop
424
+ });
425
+ }
320
426
  find(query, options = {
321
427
  useIgnoreFiles: false,
322
428
  followSymlinks: false,
@@ -395,7 +501,7 @@ var PHPSandbox = (() => {
395
501
  return this.okra.invoke("fs.textSearch", { query, options: { ...defaultOptions, ...options } }).finally(() => disposable.dispose());
396
502
  }
397
503
  tail(path, options = {}) {
398
- return this.okra.invoke("fs.tail", { path, lines: options.lines ?? 10 }).catch((e) => this.handleError(e));
504
+ return this.okra.invoke("fs.tail", { path, lines: options.lines ?? 10 }).then(({ content }) => content).catch((e) => this.handleError(e));
399
505
  }
400
506
  stat(path) {
401
507
  return this.okra.invoke("fs.stat", { path }).catch((e) => this.handleError(e));
@@ -499,32 +605,6 @@ var PHPSandbox = (() => {
499
605
  return output;
500
606
  }
501
607
 
502
- // src/errors/index.ts
503
- var PromiseTimeoutError = class extends Error {
504
- constructor(message, time3) {
505
- super(message);
506
- this.time = time3;
507
- }
508
- };
509
- var SendTimeoutError = class _SendTimeoutError extends PromiseTimeoutError {
510
- static fromPromiseTimeoutError(error51) {
511
- return new _SendTimeoutError(error51.message, error51.time);
512
- }
513
- };
514
- var NotebookUnavailableError = class extends Error {
515
- constructor(message = "Notebook is no longer available", raw = {}) {
516
- super(message);
517
- this.raw = raw;
518
- this.name = "NotebookUnavailableError";
519
- }
520
- };
521
- var UnsupportedRuntimeTransportError = class extends Error {
522
- constructor(message) {
523
- super(message);
524
- this.name = "UnsupportedRuntimeTransportError";
525
- }
526
- };
527
-
528
608
  // src/utils/promise.ts
529
609
  var timeout = (prom, time3) => {
530
610
  let timer;
@@ -4186,6 +4266,7 @@ var PHPSandbox = (() => {
4186
4266
  constructor(okra, client) {
4187
4267
  this.okra = okra;
4188
4268
  this.client = client;
4269
+ this.targets = new GitTargetApi(okra.data.id, client);
4189
4270
  }
4190
4271
  checkpoint(author, message, branch = "main", allowEmpty = false) {
4191
4272
  return this.okra.invoke("git.checkpoint", { author, message, branch, allowEmpty });
@@ -4193,17 +4274,6 @@ var PHPSandbox = (() => {
4193
4274
  checkout(branch, create = true) {
4194
4275
  return this.okra.invoke("git.checkout", { branch, create });
4195
4276
  }
4196
- async sync(input) {
4197
- const response = await this.client.post(
4198
- `/notebook/${this.okra.data.id}/git/sync-targets`,
4199
- this.omitUndefined({ ...input })
4200
- );
4201
- return response.data;
4202
- }
4203
- async syncTargets() {
4204
- const response = await this.client.get(`/notebook/${this.okra.data.id}/git/sync-targets`);
4205
- return response.data;
4206
- }
4207
4277
  log(ref = "main") {
4208
4278
  return this.okra.invoke("git.log", { ref });
4209
4279
  }
@@ -4272,10 +4342,56 @@ var PHPSandbox = (() => {
4272
4342
  url2.hash = "";
4273
4343
  return url2.toString();
4274
4344
  }
4275
- omitUndefined(input) {
4276
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
4345
+ };
4346
+ var GitTargetApi = class {
4347
+ constructor(notebookId, client) {
4348
+ this.notebookId = notebookId;
4349
+ this.client = client;
4350
+ }
4351
+ async create(input) {
4352
+ const response = await this.client.post(
4353
+ `/notebook/${this.notebookId}/git/targets`,
4354
+ omitUndefined({ ...input })
4355
+ );
4356
+ return new GitTarget(response.data, this.notebookId, this.client);
4357
+ }
4358
+ async list() {
4359
+ const response = await this.client.get(`/notebook/${this.notebookId}/git/targets`);
4360
+ return response.data.map((target) => new GitTarget(target, this.notebookId, this.client));
4361
+ }
4362
+ async get(target) {
4363
+ const response = await this.client.get(
4364
+ `/notebook/${this.notebookId}/git/targets/${encodeURIComponent(gitTargetId(target))}`
4365
+ );
4366
+ return new GitTarget(response.data, this.notebookId, this.client);
4367
+ }
4368
+ async sync(target, input = {}) {
4369
+ const response = await this.client.post(
4370
+ `/notebook/${this.notebookId}/git/targets/${encodeURIComponent(gitTargetId(target))}/sync`,
4371
+ omitUndefined({ ...input })
4372
+ );
4373
+ return new GitTarget(response.data, this.notebookId, this.client);
4374
+ }
4375
+ };
4376
+ var GitTarget = class {
4377
+ constructor(data, notebookId, client) {
4378
+ this.data = data;
4379
+ this.notebookId = notebookId;
4380
+ this.client = client;
4381
+ }
4382
+ get id() {
4383
+ return this.data.id;
4384
+ }
4385
+ sync(input = {}) {
4386
+ return new GitTargetApi(this.notebookId, this.client).sync(this, input);
4277
4387
  }
4278
4388
  };
4389
+ function gitTargetId(target) {
4390
+ return typeof target === "string" ? target : target.id;
4391
+ }
4392
+ function omitUndefined(input) {
4393
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
4394
+ }
4279
4395
 
4280
4396
  // node_modules/zod/v4/classic/external.js
4281
4397
  var external_exports = {};
@@ -18844,11 +18960,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18844
18960
  var PublicationProtectionModeSchema = external_exports.enum(["none", "password"]);
18845
18961
  var PublicationLogStreamSchema = external_exports.enum(["build", "runtime"]);
18846
18962
  var PublishStreamLogStreamSchema = external_exports.enum(["build", "publish", "runtime"]);
18963
+ var PublicationEventPayloadSchema = external_exports.preprocess(
18964
+ (payload) => Array.isArray(payload) && payload.length === 0 ? {} : payload,
18965
+ external_exports.record(external_exports.string(), external_exports.unknown())
18966
+ );
18847
18967
  var PublicationEventDataSchema = external_exports.object({
18848
18968
  id: external_exports.union([external_exports.number(), external_exports.string()]).optional(),
18849
18969
  sequence: external_exports.number(),
18850
18970
  type: external_exports.string(),
18851
- payload: external_exports.record(external_exports.string(), external_exports.unknown()),
18971
+ payload: PublicationEventPayloadSchema,
18852
18972
  createdAt: external_exports.string().nullable()
18853
18973
  }).passthrough();
18854
18974
  var PublicationLogChunkDataSchema = external_exports.object({
@@ -18869,6 +18989,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18869
18989
  var PublishStreamResultSchema = external_exports.object({
18870
18990
  success: external_exports.boolean(),
18871
18991
  publicationId: external_exports.string(),
18992
+ url: external_exports.string().url(),
18872
18993
  buildId: external_exports.string(),
18873
18994
  releaseId: external_exports.string(),
18874
18995
  status: PublicationStatusSchema
@@ -18980,10 +19101,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
18980
19101
  const response = await this.client.delete(`/publications/${id}/protection`);
18981
19102
  return new PublicationInstance(response.data, this.client);
18982
19103
  }
18983
- async setFeedback(id, input) {
18984
- const response = await this.client.put(`/publications/${id}/feedback`, input);
18985
- return new PublicationInstance(response.data, this.client);
18986
- }
18987
19104
  async listDomains(id) {
18988
19105
  const response = await this.client.get(
18989
19106
  `/publications/${id}/domains`
@@ -19093,7 +19210,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19093
19210
  if (event.type === "result") {
19094
19211
  const { type: _, ...result } = event;
19095
19212
  this.finalResult = result;
19096
- this.resolveResult?.(result);
19213
+ this.resolveResult?.(this.finalResult);
19097
19214
  }
19098
19215
  }
19099
19216
  if (!this.finalResult) {
@@ -19184,9 +19301,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19184
19301
  disableProtection() {
19185
19302
  return this.client.publications.disableProtection(this.data.id);
19186
19303
  }
19187
- setFeedback(input) {
19188
- return this.client.publications.setFeedback(this.data.id, input);
19189
- }
19190
19304
  domains() {
19191
19305
  return this.client.publications.listDomains(this.data.id);
19192
19306
  }
@@ -19439,18 +19553,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19439
19553
  "container.stats": { method: "GET", path: "/runtime/container/stats" },
19440
19554
  "terminal.list": { method: "GET", path: "/runtime/terminals" },
19441
19555
  "shell.exec": { method: "POST", path: "/runtime/executions" },
19442
- "fs.info": { method: "POST", path: "/runtime/files/info" },
19443
19556
  "fs.readFile": { method: "GET", path: "/runtime/files/content" },
19444
19557
  "fs.writeFile": { method: "PUT", path: "/runtime/files/content" },
19445
- "fs.write": { method: "PUT", path: "/runtime/files/text" },
19446
- "fs.mkdir": { method: "POST", path: "/runtime/directories" },
19447
19558
  "fs.createDirectory": { method: "PUT", path: "/runtime/directories" },
19448
19559
  "fs.readDirectory": { method: "POST", path: "/runtime/directories/read" },
19449
19560
  "fs.stat": { method: "POST", path: "/runtime/files/stat" },
19450
- "fs.move": { method: "POST", path: "/runtime/files/move" },
19451
19561
  "fs.rename": { method: "POST", path: "/runtime/files/rename" },
19452
19562
  "fs.copy": { method: "POST", path: "/runtime/files/copy" },
19453
- "fs.remove": { method: "POST", path: "/runtime/files/remove" },
19454
19563
  "fs.delete": { method: "DELETE", path: "/runtime/files" },
19455
19564
  "fs.tail": { method: "POST", path: "/runtime/files/tail" },
19456
19565
  "fs.find": { method: "POST", path: "/runtime/files/find" },
@@ -19645,6 +19754,164 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19645
19754
  };
19646
19755
  }
19647
19756
 
19757
+ // src/feedback.ts
19758
+ var Feedback = class {
19759
+ constructor(client, notebookId) {
19760
+ this.client = client;
19761
+ this.notebookId = notebookId;
19762
+ }
19763
+ async configure(input) {
19764
+ const response = await this.client.put(this.path("/configuration"), input);
19765
+ return response.data;
19766
+ }
19767
+ async configuration() {
19768
+ const response = await this.client.get(this.path("/configuration"));
19769
+ return response.data;
19770
+ }
19771
+ async submit(input) {
19772
+ const response = await this.client.post(this.path(), input);
19773
+ return response.data;
19774
+ }
19775
+ async list(options = {}) {
19776
+ const query = new URLSearchParams();
19777
+ for (const [name, value] of Object.entries(options)) {
19778
+ if (value !== void 0) query.set(name, String(value));
19779
+ }
19780
+ const response = await this.client.get(
19781
+ `${this.path()}${query.size === 0 ? "" : `?${query.toString()}`}`
19782
+ );
19783
+ return response.data;
19784
+ }
19785
+ async get(id) {
19786
+ const response = await this.client.get(this.path(`/${encodeURIComponent(id)}`));
19787
+ return response.data;
19788
+ }
19789
+ async update(id, input) {
19790
+ const response = await this.client.patch(this.path(`/${encodeURIComponent(id)}`), input);
19791
+ return response.data;
19792
+ }
19793
+ path(suffix = "") {
19794
+ return `/notebook/${this.notebookId}/feedback${suffix}`;
19795
+ }
19796
+ };
19797
+
19798
+ // src/integrations.ts
19799
+ var IntegrationApi = class {
19800
+ constructor(client) {
19801
+ this.client = client;
19802
+ }
19803
+ async link(input) {
19804
+ const response = await this.client.post("/integrations", input);
19805
+ return new Integration(response.data, this.client);
19806
+ }
19807
+ async list() {
19808
+ const response = await this.client.get("/integrations");
19809
+ return response.data.map((integration) => new Integration(integration, this.client));
19810
+ }
19811
+ async get(integration) {
19812
+ const response = await this.client.get(`/integrations/${encodeURIComponent(integrationId(integration))}`);
19813
+ return new Integration(response.data, this.client);
19814
+ }
19815
+ async update(integration, input) {
19816
+ const response = await this.client.patch(
19817
+ `/integrations/${encodeURIComponent(integrationId(integration))}`,
19818
+ input
19819
+ );
19820
+ return new Integration(response.data, this.client);
19821
+ }
19822
+ async unlink(integration) {
19823
+ await this.client.delete(`/integrations/${encodeURIComponent(integrationId(integration))}`);
19824
+ }
19825
+ };
19826
+ var Integration = class {
19827
+ constructor(data, client) {
19828
+ this.data = data;
19829
+ this.client = client;
19830
+ }
19831
+ get id() {
19832
+ return this.data.id;
19833
+ }
19834
+ get provider() {
19835
+ return this.data.provider;
19836
+ }
19837
+ get label() {
19838
+ return this.data.label;
19839
+ }
19840
+ update(input) {
19841
+ return new IntegrationApi(this.client).update(this, input);
19842
+ }
19843
+ unlink() {
19844
+ return new IntegrationApi(this.client).unlink(this);
19845
+ }
19846
+ };
19847
+ function integrationId(integration) {
19848
+ return typeof integration === "string" ? integration : integration.id;
19849
+ }
19850
+
19851
+ // src/sandbox-integrations.ts
19852
+ var SandboxIntegrationApi = class {
19853
+ constructor(notebookId, client) {
19854
+ this.notebookId = notebookId;
19855
+ this.client = client;
19856
+ }
19857
+ async attach(input) {
19858
+ const response = await this.client.post(this.path(), {
19859
+ ...input,
19860
+ integration: integrationId(input.integration)
19861
+ });
19862
+ return new SandboxIntegration(response.data, this.notebookId, this.client);
19863
+ }
19864
+ async list() {
19865
+ const response = await this.client.get(this.path());
19866
+ return response.data.map((integration) => new SandboxIntegration(integration, this.notebookId, this.client));
19867
+ }
19868
+ async get(integration) {
19869
+ const response = await this.client.get(this.bindingPath(integration));
19870
+ return new SandboxIntegration(response.data, this.notebookId, this.client);
19871
+ }
19872
+ async update(integration, input) {
19873
+ const response = await this.client.patch(this.bindingPath(integration), {
19874
+ ...input,
19875
+ integration: input.integration === void 0 ? void 0 : integrationId(input.integration)
19876
+ });
19877
+ return new SandboxIntegration(response.data, this.notebookId, this.client);
19878
+ }
19879
+ async detach(integration) {
19880
+ await this.client.delete(this.bindingPath(integration));
19881
+ }
19882
+ path() {
19883
+ return `/notebook/${this.notebookId}/integrations`;
19884
+ }
19885
+ bindingPath(integration) {
19886
+ return `${this.path()}/${encodeURIComponent(sandboxIntegrationId(integration))}`;
19887
+ }
19888
+ };
19889
+ var SandboxIntegration = class {
19890
+ constructor(data, notebookId, client) {
19891
+ this.data = data;
19892
+ this.notebookId = notebookId;
19893
+ this.client = client;
19894
+ }
19895
+ get id() {
19896
+ return this.data.id;
19897
+ }
19898
+ get integration() {
19899
+ return new Integration(this.data.integration, this.client);
19900
+ }
19901
+ get effects() {
19902
+ return this.data.effects;
19903
+ }
19904
+ update(input) {
19905
+ return new SandboxIntegrationApi(this.notebookId, this.client).update(this, input);
19906
+ }
19907
+ detach() {
19908
+ return new SandboxIntegrationApi(this.notebookId, this.client).detach(this);
19909
+ }
19910
+ };
19911
+ function sandboxIntegrationId(integration) {
19912
+ return typeof integration === "string" ? integration : integration.id;
19913
+ }
19914
+
19648
19915
  // src/index.ts
19649
19916
  function normalizeNotebookSecretInputs(input) {
19650
19917
  if (Array.isArray(input)) {
@@ -19753,6 +20020,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19753
20020
  this.publications = new PublicationApi(this);
19754
20021
  this.notebook = new NotebookApi(this);
19755
20022
  this.servers = new ServerApi(this);
20023
+ this.integrations = new IntegrationApi(this);
19756
20024
  this.options = Object.assign({ startClosed: true }, options);
19757
20025
  this.baseUrl = normalizeApiBaseUrl(url2);
19758
20026
  if (options.fetch) {
@@ -19779,6 +20047,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19779
20047
  put(path, body) {
19780
20048
  return this.makeRequest("PUT", path, { body: body === void 0 ? void 0 : JSON.stringify(body) });
19781
20049
  }
20050
+ patch(path, body) {
20051
+ return this.makeRequest("PATCH", path, { body: body === void 0 ? void 0 : JSON.stringify(body) });
20052
+ }
19782
20053
  async stream(path) {
19783
20054
  const response = await this.fetch(
19784
20055
  new Request(new URL(path.replace(/^\//, ""), this.baseUrl), {
@@ -19992,8 +20263,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
19992
20263
  this.services = new Services(this);
19993
20264
  this.config = new Config(this);
19994
20265
  this.secrets = new NotebookSecrets(client, this.data.id);
20266
+ this.integrations = new SandboxIntegrationApi(this.data.id, client);
19995
20267
  this.preview = new NotebookPreview(client, this.data.id);
19996
20268
  this.mail = new NotebookMail(client, this.data.id);
20269
+ this.feedback = new Feedback(client, this.data.id);
19997
20270
  }
19998
20271
  get runtimeTransport() {
19999
20272
  return this.client.runtimeTransport;