@phpsandbox/sdk 0.3.2 → 0.3.4

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 (43) hide show
  1. package/README.md +38 -0
  2. package/dist/beacon/index.js +4 -2
  3. package/dist/beacon/navigator.js +0 -1
  4. package/dist/beacon/types.d.ts +1 -1
  5. package/dist/browser/phpsandbox-sdk.esm.js +405 -308
  6. package/dist/browser/phpsandbox-sdk.esm.min.js +23 -25
  7. package/dist/browser/phpsandbox-sdk.iife.js +405 -308
  8. package/dist/browser/phpsandbox-sdk.iife.min.js +8 -10
  9. package/dist/composer.js +8 -4
  10. package/dist/errors/index.d.ts +1 -1
  11. package/dist/errors/index.js +1 -3
  12. package/dist/feedback.js +2 -1
  13. package/dist/filesystem.js +32 -15
  14. package/dist/identity.d.ts +13 -0
  15. package/dist/identity.js +6 -0
  16. package/dist/index.d.ts +5 -4
  17. package/dist/index.js +14 -5
  18. package/dist/integrations/sandbox.js +1 -1
  19. package/dist/lsp.d.ts +2 -2
  20. package/dist/lsp.js +2 -2
  21. package/dist/publication/index.d.ts +1 -0
  22. package/dist/publication/index.js +1 -0
  23. package/dist/publication/instance.d.ts +2 -0
  24. package/dist/publication/instance.js +8 -0
  25. package/dist/publication/notebook.js +7 -5
  26. package/dist/publication/resources.js +2 -1
  27. package/dist/publication/run.js +2 -76
  28. package/dist/publication/stream.d.ts +18 -0
  29. package/dist/publication/stream.js +185 -0
  30. package/dist/runtime/rest.js +2 -1
  31. package/dist/runtime.js +1 -1
  32. package/dist/schemas/publications.js +53 -59
  33. package/dist/servers.d.ts +2 -0
  34. package/dist/servers.js +5 -1
  35. package/dist/shell.js +5 -2
  36. package/dist/socket/index.js +25 -13
  37. package/dist/telemetry.js +8 -3
  38. package/dist/terminal.js +3 -4
  39. package/dist/utils/promise.js +1 -1
  40. package/dist/utils/websocket.js +2 -2
  41. package/package.json +49 -33
  42. package/dist/auth.d.ts +0 -11
  43. package/dist/auth.js +0 -12
@@ -12,137 +12,6 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
12
12
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
13
13
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
14
14
 
15
- // src/errors/index.ts
16
- var remoteErrorCodes = [
17
- "ActionNotFound",
18
- "AuthenticationRequired",
19
- "BadGateway",
20
- "BadRequest",
21
- "Conflict",
22
- "FileAlreadyExists",
23
- "FileIsDirectory",
24
- "FileNotDirectory",
25
- "FileNotFound",
26
- "FilesystemUnavailable",
27
- "InternalError",
28
- "InvalidArgument",
29
- "InvalidConfiguration",
30
- "InvalidRequest",
31
- "InvalidResponse",
32
- "InvalidServiceCommand",
33
- "MethodNotAllowed",
34
- "NotebookInitializationFailed",
35
- "NotebookUnavailable",
36
- "NotFound",
37
- "PayloadTooLarge",
38
- "PermissionDenied",
39
- "RateLimited",
40
- "RequestFailed",
41
- "RuntimeOperationFailed",
42
- "ServiceNotFound",
43
- "ServiceUnavailable",
44
- "UnprocessableEntity",
45
- "ValidationFailed",
46
- "WorkspaceUnavailable"
47
- ];
48
- var PHPSandboxError = class extends Error {
49
- constructor(message, cause) {
50
- super(message);
51
- this.name = new.target.name;
52
- this.cause = cause;
53
- }
54
- };
55
- var RemoteError = class _RemoteError extends PHPSandboxError {
56
- constructor(message, options) {
57
- super(message, options.cause);
58
- this.source = options.source;
59
- this.status = options.status;
60
- this.code = options.code;
61
- this.details = options.details;
62
- }
63
- static is(error51, code) {
64
- return error51 instanceof _RemoteError && (code === void 0 || error51.code === code);
65
- }
66
- static isValidation(error51) {
67
- return _RemoteError.is(error51, "ValidationFailed") && validationDetails(error51.details) !== void 0;
68
- }
69
- is(code) {
70
- return this.code === code;
71
- }
72
- };
73
- var TransportError = class _TransportError extends PHPSandboxError {
74
- constructor(message, code, cause, response) {
75
- super(message, cause);
76
- this.code = code;
77
- this.response = response;
78
- }
79
- static is(error51, code) {
80
- return error51 instanceof _TransportError && (code === void 0 || error51.code === code);
81
- }
82
- is(code) {
83
- return this.code === code;
84
- }
85
- };
86
- function remoteError(source, payload, cause) {
87
- const error51 = record(payload);
88
- const status = positiveInteger(error51?.status);
89
- const code = nonEmptyString(error51?.code);
90
- const message = nonEmptyString(error51?.message);
91
- if (status === void 0 || !isRemoteErrorCode(code) || message === void 0) {
92
- throw new TransportError("PHPSandbox returned an invalid error response.", "InvalidResponse", cause ?? payload);
93
- }
94
- return new RemoteError(message, {
95
- source,
96
- status,
97
- code,
98
- details: error51?.details,
99
- cause
100
- });
101
- }
102
- function isRemoteErrorCode(value) {
103
- return typeof value === "string" && remoteErrorCodes.includes(value);
104
- }
105
- function positiveInteger(value) {
106
- return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
107
- }
108
- function nonEmptyString(value) {
109
- return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
110
- }
111
- function record(value) {
112
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
113
- }
114
- function stringArrayRecord(value) {
115
- const candidate = record(value);
116
- if (candidate === void 0) {
117
- return void 0;
118
- }
119
- const entries = Object.entries(candidate);
120
- if (!entries.every(([, messages]) => Array.isArray(messages) && messages.every((message) => typeof message === "string"))) {
121
- return void 0;
122
- }
123
- return Object.fromEntries(entries);
124
- }
125
- function validationDetails(value) {
126
- const details = record(value);
127
- const errors = stringArrayRecord(details?.errors);
128
- return errors === void 0 ? void 0 : { errors };
129
- }
130
- var PromiseTimeoutError = class extends Error {
131
- constructor(message, time3) {
132
- super(message);
133
- this.time = time3;
134
- }
135
- };
136
- var SendTimeoutError = class _SendTimeoutError extends TransportError {
137
- constructor(message, time3, cause) {
138
- super(message, "SendTimeout", cause);
139
- this.time = time3;
140
- }
141
- static fromPromiseTimeoutError(error51) {
142
- return new _SendTimeoutError(error51.message, error51.time, error51);
143
- }
144
- };
145
-
146
15
  // node_modules/zod/v4/classic/external.js
147
16
  var external_exports = {};
148
17
  __export(external_exports, {
@@ -337,7 +206,7 @@ __export(external_exports, {
337
206
  promise: () => promise,
338
207
  property: () => _property,
339
208
  readonly: () => readonly,
340
- record: () => record2,
209
+ record: () => record,
341
210
  refine: () => refine,
342
211
  regex: () => _regex,
343
212
  regexes: () => regexes_exports,
@@ -12675,7 +12544,7 @@ __export(schemas_exports2, {
12675
12544
  preprocess: () => preprocess,
12676
12545
  promise: () => promise,
12677
12546
  readonly: () => readonly,
12678
- record: () => record2,
12547
+ record: () => record,
12679
12548
  refine: () => refine,
12680
12549
  set: () => set,
12681
12550
  strictObject: () => strictObject,
@@ -13644,7 +13513,7 @@ var ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
13644
13513
  inst.keyType = def.keyType;
13645
13514
  inst.valueType = def.valueType;
13646
13515
  });
13647
- function record2(keyType, valueType, params) {
13516
+ function record(keyType, valueType, params) {
13648
13517
  if (!valueType || !valueType._zod) {
13649
13518
  return new ZodRecord({
13650
13519
  type: "record",
@@ -14111,7 +13980,7 @@ var stringbool = (...args) => _stringbool({
14111
13980
  }, ...args);
14112
13981
  function json(params) {
14113
13982
  const jsonSchema = lazy(() => {
14114
- return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record2(string2(), jsonSchema)]);
13983
+ return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record(string2(), jsonSchema)]);
14115
13984
  });
14116
13985
  return jsonSchema;
14117
13986
  }
@@ -14657,12 +14526,146 @@ function date4(params) {
14657
14526
  // node_modules/zod/v4/classic/external.js
14658
14527
  config(en_default());
14659
14528
 
14529
+ // src/identity.ts
14530
+ var identitySchema = external_exports.object({
14531
+ user: external_exports.object({ id: external_exports.string(), name: external_exports.string() }).nullable(),
14532
+ organization: external_exports.object({ id: external_exports.string(), name: external_exports.string() }),
14533
+ permissions: external_exports.array(external_exports.string())
14534
+ });
14535
+
14536
+ // src/errors/index.ts
14537
+ var remoteErrorCodes = [
14538
+ "ActionNotFound",
14539
+ "AuthenticationRequired",
14540
+ "BadGateway",
14541
+ "BadRequest",
14542
+ "Conflict",
14543
+ "FileAlreadyExists",
14544
+ "FileIsDirectory",
14545
+ "FileNotDirectory",
14546
+ "FileNotFound",
14547
+ "FilesystemUnavailable",
14548
+ "InternalError",
14549
+ "InvalidArgument",
14550
+ "InvalidConfiguration",
14551
+ "InvalidRequest",
14552
+ "InvalidResponse",
14553
+ "InvalidServiceCommand",
14554
+ "MethodNotAllowed",
14555
+ "NotebookInitializationFailed",
14556
+ "NotebookUnavailable",
14557
+ "NotFound",
14558
+ "PayloadTooLarge",
14559
+ "PermissionDenied",
14560
+ "RateLimited",
14561
+ "RequestFailed",
14562
+ "RuntimeOperationFailed",
14563
+ "ServiceNotFound",
14564
+ "ServiceUnavailable",
14565
+ "UnprocessableEntity",
14566
+ "ValidationFailed",
14567
+ "WorkspaceUnavailable"
14568
+ ];
14569
+ var PHPSandboxError = class extends Error {
14570
+ constructor(message, cause) {
14571
+ super(message);
14572
+ this.name = new.target.name;
14573
+ this.cause = cause;
14574
+ }
14575
+ };
14576
+ var RemoteError = class _RemoteError extends PHPSandboxError {
14577
+ constructor(message, options) {
14578
+ super(message, options.cause);
14579
+ this.source = options.source;
14580
+ this.status = options.status;
14581
+ this.code = options.code;
14582
+ this.details = options.details;
14583
+ }
14584
+ static is(error51, code) {
14585
+ return error51 instanceof _RemoteError && (code === void 0 || error51.code === code);
14586
+ }
14587
+ static isValidation(error51) {
14588
+ return _RemoteError.is(error51, "ValidationFailed") && validationDetails(error51.details) !== void 0;
14589
+ }
14590
+ is(code) {
14591
+ return this.code === code;
14592
+ }
14593
+ };
14594
+ var TransportError = class _TransportError extends PHPSandboxError {
14595
+ constructor(message, code, cause, response) {
14596
+ super(message, cause);
14597
+ this.code = code;
14598
+ this.response = response;
14599
+ }
14600
+ static is(error51, code) {
14601
+ return error51 instanceof _TransportError && (code === void 0 || error51.code === code);
14602
+ }
14603
+ is(code) {
14604
+ return this.code === code;
14605
+ }
14606
+ };
14607
+ function remoteError(source, payload, cause) {
14608
+ const error51 = record2(payload);
14609
+ const status = positiveInteger(error51?.status);
14610
+ const code = nonEmptyString(error51?.code);
14611
+ const message = nonEmptyString(error51?.message);
14612
+ if (status === void 0 || !isRemoteErrorCode(code) || message === void 0) {
14613
+ throw new TransportError("PHPSandbox returned an invalid error response.", "InvalidResponse", cause ?? payload);
14614
+ }
14615
+ return new RemoteError(message, {
14616
+ source,
14617
+ status,
14618
+ code,
14619
+ details: error51?.details,
14620
+ cause
14621
+ });
14622
+ }
14623
+ function isRemoteErrorCode(value) {
14624
+ return typeof value === "string" && remoteErrorCodes.includes(value);
14625
+ }
14626
+ function positiveInteger(value) {
14627
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
14628
+ }
14629
+ function nonEmptyString(value) {
14630
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
14631
+ }
14632
+ function record2(value) {
14633
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
14634
+ }
14635
+ function stringArrayRecord(value) {
14636
+ const candidate = record2(value);
14637
+ if (candidate === void 0) {
14638
+ return void 0;
14639
+ }
14640
+ const entries = Object.entries(candidate);
14641
+ if (!entries.every(([, messages]) => Array.isArray(messages) && messages.every((message) => typeof message === "string"))) {
14642
+ return void 0;
14643
+ }
14644
+ return Object.fromEntries(entries);
14645
+ }
14646
+ function validationDetails(value) {
14647
+ const details = record2(value);
14648
+ const errors = stringArrayRecord(details?.errors);
14649
+ return errors === void 0 ? void 0 : { errors };
14650
+ }
14651
+ var PromiseTimeoutError = class extends Error {
14652
+ constructor(message, time3) {
14653
+ super(message);
14654
+ this.time = time3;
14655
+ }
14656
+ };
14657
+ var SendTimeoutError = class _SendTimeoutError extends TransportError {
14658
+ constructor(message, time3, cause) {
14659
+ super(message, "SendTimeout", cause);
14660
+ this.time = time3;
14661
+ }
14662
+ static fromPromiseTimeoutError(error51) {
14663
+ return new _SendTimeoutError(error51.message, error51.time, error51);
14664
+ }
14665
+ };
14666
+
14660
14667
  // src/schemas/publications.ts
14661
- var PublicationProviderNameSchema = external_exports.enum([
14662
- "cloudflare-containers",
14663
- "ssh-server",
14664
- "laravel-cloud"
14665
- ]);
14668
+ var PublicationProviderNameSchema = external_exports.enum(["cloudflare-containers", "ssh-server", "laravel-cloud"]);
14666
14669
  var PublicationStatusSchema = external_exports.enum([
14667
14670
  "pending",
14668
14671
  "queued",
@@ -14675,36 +14678,10 @@ var PublicationStatusSchema = external_exports.enum([
14675
14678
  "deleted",
14676
14679
  "delete_failed"
14677
14680
  ]);
14678
- var PublicationBuildStatusSchema = external_exports.enum([
14679
- "pending",
14680
- "queued",
14681
- "running",
14682
- "succeeded",
14683
- "failed",
14684
- "cancelled"
14685
- ]);
14681
+ var PublicationBuildStatusSchema = external_exports.enum(["pending", "queued", "running", "succeeded", "failed", "cancelled"]);
14686
14682
  var PublicationReleaseStatusSchema = external_exports.enum(["created", "ready", "deleted"]);
14687
- var PublicationSizeSchema = external_exports.enum([
14688
- "nano",
14689
- "small",
14690
- "medium",
14691
- "large",
14692
- "lite",
14693
- "basic",
14694
- "standard-1",
14695
- "standard-2"
14696
- ]);
14697
- var PublicationRegionSchema = external_exports.enum([
14698
- "ENAM",
14699
- "WNAM",
14700
- "EEUR",
14701
- "WEUR",
14702
- "APAC",
14703
- "SAM",
14704
- "ME",
14705
- "OC",
14706
- "AFR"
14707
- ]);
14683
+ var PublicationSizeSchema = external_exports.enum(["nano", "small", "medium", "large", "lite", "basic", "standard-1", "standard-2"]);
14684
+ var PublicationRegionSchema = external_exports.enum(["ENAM", "WNAM", "EEUR", "WEUR", "APAC", "SAM", "ME", "OC", "AFR"]);
14708
14685
  var PublicationJurisdictionSchema = external_exports.enum(["eu", "fedramp"]);
14709
14686
  var PublicationProtectionModeSchema = external_exports.enum(["none", "password"]);
14710
14687
  var PublicationLogStreamSchema = external_exports.enum(["build", "runtime"]);
@@ -14795,6 +14772,179 @@ var PublishStreamSseEventSchema = external_exports.discriminatedUnion("event", [
14795
14772
  return PublishStreamEventSchema.parse({ type, ...event.data });
14796
14773
  });
14797
14774
 
14775
+ // src/publication/stream.ts
14776
+ async function* readPublicationStream(input, options = {}) {
14777
+ if (input instanceof Response && (!input.ok || !input.body)) {
14778
+ await input.body?.cancel().catch(() => void 0);
14779
+ throw new PHPSandboxError(`Publishing stream is unavailable (HTTP ${input.status}).`);
14780
+ }
14781
+ const stream = input instanceof Response ? input.body : input;
14782
+ const reader = stream.getReader();
14783
+ const decoder = new TextDecoder();
14784
+ let buffer = "";
14785
+ let eventName = "message";
14786
+ let data = [];
14787
+ let ended = false;
14788
+ let receivedResult = false;
14789
+ function dispatch() {
14790
+ const name = eventName;
14791
+ const lines = data;
14792
+ eventName = "message";
14793
+ data = [];
14794
+ if (!lines.length || !PublishStreamSseEventNameSchema.safeParse(name).success) {
14795
+ return null;
14796
+ }
14797
+ const raw = lines.join("\n");
14798
+ let payload;
14799
+ try {
14800
+ payload = JSON.parse(raw);
14801
+ } catch {
14802
+ payload = raw;
14803
+ }
14804
+ const event = PublishStreamSseEventSchema.parse({ event: name, data: payload });
14805
+ if (event.type === "result") {
14806
+ receivedResult = true;
14807
+ }
14808
+ return event;
14809
+ }
14810
+ function line(value) {
14811
+ if (value === "") {
14812
+ return dispatch();
14813
+ }
14814
+ if (value.startsWith(":")) {
14815
+ return null;
14816
+ }
14817
+ const colon = value.indexOf(":");
14818
+ const field = colon < 0 ? value : value.slice(0, colon);
14819
+ let content = colon < 0 ? "" : value.slice(colon + 1);
14820
+ if (content.startsWith(" ")) {
14821
+ content = content.slice(1);
14822
+ }
14823
+ if (field === "event") {
14824
+ eventName = content;
14825
+ }
14826
+ if (field === "data") {
14827
+ data.push(content);
14828
+ }
14829
+ return null;
14830
+ }
14831
+ try {
14832
+ while (true) {
14833
+ const { done, value } = await reader.read();
14834
+ buffer += done ? decoder.decode() : decoder.decode(value, { stream: true });
14835
+ let match;
14836
+ while (match = /\r\n|\r|\n/.exec(buffer)) {
14837
+ if (!done && match[0] === "\r" && match.index === buffer.length - 1) {
14838
+ break;
14839
+ }
14840
+ const event = line(buffer.slice(0, match.index));
14841
+ buffer = buffer.slice(match.index + match[0].length);
14842
+ if (event) {
14843
+ yield event;
14844
+ }
14845
+ }
14846
+ if (done) {
14847
+ ended = true;
14848
+ if (buffer) {
14849
+ const event2 = line(buffer);
14850
+ if (event2) {
14851
+ yield event2;
14852
+ }
14853
+ }
14854
+ const event = dispatch();
14855
+ if (event) {
14856
+ yield event;
14857
+ }
14858
+ if (options.requireResult !== false && !receivedResult) {
14859
+ throw new PHPSandboxError("Publish stream ended without result");
14860
+ }
14861
+ return;
14862
+ }
14863
+ }
14864
+ } finally {
14865
+ if (!ended) {
14866
+ await reader.cancel().catch(() => void 0);
14867
+ }
14868
+ reader.releaseLock();
14869
+ }
14870
+ }
14871
+ function createPublicationStreamResponse(stream, options = {}) {
14872
+ const reader = stream.getReader();
14873
+ let disposed = false;
14874
+ let finished = false;
14875
+ let cancellation;
14876
+ let abort;
14877
+ async function dispose() {
14878
+ if (disposed) {
14879
+ return;
14880
+ }
14881
+ disposed = true;
14882
+ options.signal?.removeEventListener("abort", abort);
14883
+ reader.releaseLock();
14884
+ await options.onDispose?.();
14885
+ }
14886
+ function cancel(reason) {
14887
+ return cancellation ?? (cancellation = (async () => {
14888
+ finished = true;
14889
+ try {
14890
+ await reader.cancel(reason);
14891
+ } finally {
14892
+ await dispose();
14893
+ }
14894
+ })());
14895
+ }
14896
+ return new Response(
14897
+ new ReadableStream(
14898
+ {
14899
+ start(controller) {
14900
+ abort = () => {
14901
+ controller.error(options.signal.reason);
14902
+ void cancel(options.signal.reason).catch(() => void 0);
14903
+ };
14904
+ if (options.signal?.aborted) {
14905
+ abort();
14906
+ } else {
14907
+ options.signal?.addEventListener("abort", abort, { once: true });
14908
+ }
14909
+ },
14910
+ async pull(controller) {
14911
+ try {
14912
+ const { done, value } = await reader.read();
14913
+ if (finished) {
14914
+ return;
14915
+ }
14916
+ if (done) {
14917
+ finished = true;
14918
+ await dispose();
14919
+ controller.close();
14920
+ } else {
14921
+ controller.enqueue(value);
14922
+ }
14923
+ } catch (error51) {
14924
+ if (finished && cancellation) {
14925
+ return;
14926
+ }
14927
+ try {
14928
+ await cancel(error51);
14929
+ } finally {
14930
+ controller.error(error51);
14931
+ }
14932
+ }
14933
+ },
14934
+ cancel
14935
+ },
14936
+ { highWaterMark: 0 }
14937
+ ),
14938
+ {
14939
+ headers: {
14940
+ "Content-Type": "text/event-stream",
14941
+ "Cache-Control": "no-cache, no-transform",
14942
+ "X-Accel-Buffering": "no"
14943
+ }
14944
+ }
14945
+ );
14946
+ }
14947
+
14798
14948
  // src/publication/run.ts
14799
14949
  var PublicationRun = class {
14800
14950
  constructor(initial, client) {
@@ -14882,7 +15032,7 @@ var PublicationRun = class {
14882
15032
  async consumeStream(eventStreamUrl) {
14883
15033
  try {
14884
15034
  const stream = await this.client.sse(eventStreamUrl, this.streamAbort.signal);
14885
- for await (const event of readPublishStreamEvents(stream)) {
15035
+ for await (const event of readPublicationStream(stream)) {
14886
15036
  this.publish(event);
14887
15037
  if (event.type === "result") {
14888
15038
  const { type: _, ...result } = event;
@@ -14983,78 +15133,6 @@ var AsyncPublishEventQueue = class {
14983
15133
  });
14984
15134
  }
14985
15135
  };
14986
- async function* readPublishStreamEvents(stream) {
14987
- const reader = parseSSEStream(stream).getReader();
14988
- try {
14989
- while (true) {
14990
- const { done, value } = await reader.read();
14991
- if (done) {
14992
- return;
14993
- }
14994
- const event = parsePublishStreamEvent(value);
14995
- if (event) {
14996
- yield event;
14997
- }
14998
- }
14999
- } finally {
15000
- reader.releaseLock();
15001
- }
15002
- }
15003
- function parsePublishStreamEvent(event) {
15004
- if (!PublishStreamSseEventNameSchema.safeParse(event.event).success) {
15005
- return null;
15006
- }
15007
- return PublishStreamSseEventSchema.parse(event);
15008
- }
15009
- function parseSSEStream(input) {
15010
- const decoder = new TextDecoder();
15011
- let buffer = "";
15012
- return input.pipeThrough(
15013
- new TransformStream({
15014
- transform(chunk, controller) {
15015
- buffer += decoder.decode(chunk, { stream: true });
15016
- const blocks = buffer.split("\n\n");
15017
- buffer = blocks.pop() ?? "";
15018
- for (const block of blocks) {
15019
- const event = parseSSEBlock(block);
15020
- if (event) {
15021
- controller.enqueue(event);
15022
- }
15023
- }
15024
- },
15025
- flush(controller) {
15026
- buffer += decoder.decode();
15027
- if (buffer.trim() !== "") {
15028
- const event = parseSSEBlock(buffer);
15029
- if (event) {
15030
- controller.enqueue(event);
15031
- }
15032
- }
15033
- }
15034
- })
15035
- );
15036
- }
15037
- function parseSSEBlock(block) {
15038
- let eventType = "message";
15039
- let data = "";
15040
- for (const line of block.split("\n")) {
15041
- if (line.startsWith("event: ")) {
15042
- eventType = line.slice(7).trim();
15043
- } else if (line.startsWith("data: ")) {
15044
- data += line.slice(6);
15045
- } else if (line.startsWith("data:")) {
15046
- data += line.slice(5);
15047
- }
15048
- }
15049
- if (data === "") {
15050
- return null;
15051
- }
15052
- try {
15053
- return { event: eventType, data: JSON.parse(data) };
15054
- } catch {
15055
- return { event: eventType, data };
15056
- }
15057
- }
15058
15136
 
15059
15137
  // src/publication/resources.ts
15060
15138
  var PublicationResources = class {
@@ -15146,6 +15224,13 @@ var PublicationInstance = class _PublicationInstance {
15146
15224
  follow() {
15147
15225
  return new PublicationRun(this, this.client).start();
15148
15226
  }
15227
+ /** Open the original publishing SSE bytes for an authenticated, transparent proxy. */
15228
+ async stream(signal) {
15229
+ if (!this.data.eventStreamUrl) {
15230
+ throw new PHPSandboxError(`Publication ${this.data.id} has no eventStreamUrl for SSE streaming`);
15231
+ }
15232
+ return this.client.sse(this.data.eventStreamUrl, signal);
15233
+ }
15149
15234
  async destroy(options = {}) {
15150
15235
  const query = options.deleteResources ? "?deleteResources=1" : "";
15151
15236
  await this.client.delete(`/publications/${encodeURIComponent(this.data.id)}${query}`);
@@ -15178,7 +15263,9 @@ var PublicationInstance = class _PublicationInstance {
15178
15263
  }
15179
15264
  async logSnapshot(stream, limit = 50) {
15180
15265
  const query = new URLSearchParams({ stream, limit: String(limit) });
15181
- return (await this.client.get(`/publications/${encodeURIComponent(this.data.id)}/logs?${query}`)).data;
15266
+ return (await this.client.get(
15267
+ `/publications/${encodeURIComponent(this.data.id)}/logs?${query}`
15268
+ )).data;
15182
15269
  }
15183
15270
  async logs() {
15184
15271
  return parseNdjsonStream(
@@ -15287,11 +15374,15 @@ var NotebookPublication = class {
15287
15374
  /** Publish the exact app selection in a server-owned review. */
15288
15375
  async publish(input) {
15289
15376
  const application = (await this.client.post(`${this.path}/publication`, input)).data;
15290
- if (!("confirmationRequired" in application)) this.startApplicationRuns(application);
15377
+ if (!("confirmationRequired" in application)) {
15378
+ this.startApplicationRuns(application);
15379
+ }
15291
15380
  return application;
15292
15381
  }
15293
15382
  async application(applicationId) {
15294
- return (await this.client.get(`${this.path}/publication/application/${encodeURIComponent(applicationId)}`)).data;
15383
+ return (await this.client.get(
15384
+ `${this.path}/publication/application/${encodeURIComponent(applicationId)}`
15385
+ )).data;
15295
15386
  }
15296
15387
  /** Retry failed apps and pending route attachments while preserving running releases. */
15297
15388
  async retryApplication(applicationId) {
@@ -15308,12 +15399,13 @@ var NotebookPublication = class {
15308
15399
  }
15309
15400
  startApplicationRuns(application) {
15310
15401
  for (const app of application.apps) {
15311
- if (!(application.selectedAppIds ?? []).includes(app.appId)) continue;
15312
- if (!["pending", "queued", "building", "deploying"].includes(app.publication.status)) continue;
15313
- new PublicationRun(
15314
- new PublicationInstance(app.publication, this.client, this.notebookId),
15315
- this.client
15316
- ).start();
15402
+ if (!(application.selectedAppIds ?? []).includes(app.appId)) {
15403
+ continue;
15404
+ }
15405
+ if (!["pending", "queued", "building", "deploying"].includes(app.publication.status)) {
15406
+ continue;
15407
+ }
15408
+ new PublicationRun(new PublicationInstance(app.publication, this.client, this.notebookId), this.client).start();
15317
15409
  }
15318
15410
  }
15319
15411
  async catalog(provider, serverId) {
@@ -15928,7 +16020,7 @@ var Terminals = class {
15928
16020
  return this.okra.invoke("terminal.close", { id });
15929
16021
  });
15930
16022
  const resize = (dimensions) => {
15931
- this.okra.invoke("terminal.resize", { id, width: dimensions.cols, height: dimensions.rows });
16023
+ return this.okra.invoke("terminal.resize", { id, width: dimensions.cols, height: dimensions.rows });
15932
16024
  };
15933
16025
  if (abortSignal && !abortSignal.aborted) {
15934
16026
  abortHandler = () => {
@@ -15949,20 +16041,6 @@ var Terminals = class {
15949
16041
  }
15950
16042
  };
15951
16043
 
15952
- // src/auth.ts
15953
- var Auth = class {
15954
- constructor(okra) {
15955
- this.okra = okra;
15956
- }
15957
- login(runtimeUrl) {
15958
- const runtimeTicket = new URL(runtimeUrl).searchParams.get("ticket");
15959
- if (runtimeTicket === null || runtimeTicket === "") {
15960
- throw new TypeError("The notebook connection does not contain a runtime ticket.");
15961
- }
15962
- return this.okra.invoke("auth.login", { runtimeTicket });
15963
- }
15964
- };
15965
-
15966
16044
  // src/lsp.ts
15967
16045
  var Lsp = class {
15968
16046
  constructor(okra) {
@@ -16017,10 +16095,10 @@ var LspConnection = class _LspConnection {
16017
16095
  return this.lsp.onClose(this.id, cb);
16018
16096
  }
16019
16097
  dispose() {
16020
- this.lsp.close(this.id);
16098
+ return this.lsp.close(this.id);
16021
16099
  }
16022
16100
  start() {
16023
- this.lsp.start(this.id);
16101
+ return this.lsp.start(this.id);
16024
16102
  }
16025
16103
  onClientDisconnect(cb) {
16026
16104
  return this.lsp.onClientDisconnect(cb);
@@ -16123,11 +16201,7 @@ var ShellProcess = class {
16123
16201
  stderr.fail(error51);
16124
16202
  };
16125
16203
  const { abortSignal, ...payloadOpts } = opts;
16126
- this.completion = this.okra.invoke(
16127
- "shell.exec",
16128
- { command, opts: { ...payloadOpts, id: this.id } },
16129
- { abortSignal }
16130
- ).then((result) => {
16204
+ this.completion = this.okra.invoke("shell.exec", { command, opts: { ...payloadOpts, id: this.id } }, { abortSignal }).then((result) => {
16131
16205
  finish();
16132
16206
  return result;
16133
16207
  }).catch((error51) => {
@@ -16160,15 +16234,14 @@ var ComposerCredentials = class {
16160
16234
  this.notebookId = notebookId;
16161
16235
  }
16162
16236
  async set(input) {
16163
- const response = await this.client.put(
16164
- `/notebook/${this.notebookId}/composer/credentials`,
16165
- input
16166
- );
16237
+ const response = await this.client.put(`/notebook/${this.notebookId}/composer/credentials`, input);
16167
16238
  return response.data;
16168
16239
  }
16169
16240
  async remove(type, url2) {
16170
16241
  const params = new URLSearchParams({ type });
16171
- if (url2) params.set("url", url2);
16242
+ if (url2) {
16243
+ params.set("url", url2);
16244
+ }
16172
16245
  await this.client.delete(`/notebook/${this.notebookId}/composer/credentials?${params.toString()}`);
16173
16246
  }
16174
16247
  };
@@ -16353,11 +16426,18 @@ var Logs = class {
16353
16426
  this.telemetry = telemetry;
16354
16427
  }
16355
16428
  follow(options = {}) {
16356
- return watchRuntimeTelemetry(this.okra, this.telemetry, "logs", "notebook.log", (message) => ({
16357
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
16358
- source: "runtime",
16359
- message
16360
- }), options);
16429
+ return watchRuntimeTelemetry(
16430
+ this.okra,
16431
+ this.telemetry,
16432
+ "logs",
16433
+ "notebook.log",
16434
+ (message) => ({
16435
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
16436
+ source: "runtime",
16437
+ message
16438
+ }),
16439
+ options
16440
+ );
16361
16441
  }
16362
16442
  };
16363
16443
 
@@ -18817,7 +18897,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
18817
18897
  id() {
18818
18898
  return this.clientId;
18819
18899
  }
18820
- async registerWatchers() {
18900
+ registerWatchers() {
18821
18901
  const onMessage = (ev) => {
18822
18902
  this.incomingMessageChain = this.incomingMessageChain.catch(() => void 0).then(() => this.processIncomingMessage(ev)).catch((error51) => {
18823
18903
  this.log("error", "Failed to process queued WebSocket frame", {
@@ -18983,7 +19063,9 @@ ${JSON.stringify(metadata, null, 2)}` : "";
18983
19063
  this.eventEmitter.emit(event, this.clientId);
18984
19064
  return;
18985
19065
  }
18986
- event && this.eventEmitter.emit(as || event, data);
19066
+ if (event) {
19067
+ this.eventEmitter.emit(as || event, data);
19068
+ }
18987
19069
  }
18988
19070
  listen(event, listener, _context) {
18989
19071
  return this.eventEmitter.listen(event, listener);
@@ -19079,12 +19161,14 @@ ${JSON.stringify(metadata, null, 2)}` : "";
19079
19161
  });
19080
19162
  closeHandler = (_ev) => {
19081
19163
  if (_ev.code === 1008 && (_ev.reason || "").includes("rate limit")) {
19082
- reject(new RemoteError(_ev.reason || "Rate limit exceeded", {
19083
- source: "runtime",
19084
- status: 429,
19085
- code: "RateLimited",
19086
- cause: _ev
19087
- }));
19164
+ reject(
19165
+ new RemoteError(_ev.reason || "Rate limit exceeded", {
19166
+ source: "runtime",
19167
+ status: 429,
19168
+ code: "RateLimited",
19169
+ cause: _ev
19170
+ })
19171
+ );
19088
19172
  return;
19089
19173
  }
19090
19174
  const detail = describeWebSocketEvent(_ev);
@@ -19620,8 +19704,13 @@ var ServerInstance = class {
19620
19704
  async share(email3) {
19621
19705
  return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, { email: email3 })).data;
19622
19706
  }
19707
+ async shareWithOrganization(organizationId) {
19708
+ return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, { organizationId })).data;
19709
+ }
19623
19710
  async revokeAccess(memberId) {
19624
- await this.client.delete(`/servers/${encodeURIComponent(this.data.id)}/members/${encodeURIComponent(String(memberId))}`);
19711
+ await this.client.delete(
19712
+ `/servers/${encodeURIComponent(this.data.id)}/members/${encodeURIComponent(String(memberId))}`
19713
+ );
19625
19714
  }
19626
19715
  refresh() {
19627
19716
  return this.client.servers.get(this.data.id);
@@ -19845,9 +19934,7 @@ function runtimeActionRequestBody(action, data, url2, headers) {
19845
19934
  throw new TypeError("Runtime file contents must be binary data.");
19846
19935
  }
19847
19936
  headers["Content-Type"] = "application/octet-stream";
19848
- return Uint8Array.from(
19849
- new Uint8Array(payload.contents.buffer, payload.contents.byteOffset, payload.contents.byteLength)
19850
- ).buffer;
19937
+ return Uint8Array.from(new Uint8Array(payload.contents.buffer, payload.contents.byteOffset, payload.contents.byteLength)).buffer;
19851
19938
  }
19852
19939
  headers["Content-Type"] = "application/json";
19853
19940
  return JSON.stringify(data);
@@ -19909,11 +19996,11 @@ var Feedback = class {
19909
19996
  async list(options = {}) {
19910
19997
  const query = new URLSearchParams();
19911
19998
  for (const [name, value] of Object.entries(options)) {
19912
- if (value !== void 0) query.set(name, String(value));
19999
+ if (value !== void 0) {
20000
+ query.set(name, String(value));
20001
+ }
19913
20002
  }
19914
- return this.client.get(
19915
- `${this.path()}${query.size === 0 ? "" : `?${query.toString()}`}`
19916
- );
20003
+ return this.client.get(`${this.path()}${query.size === 0 ? "" : `?${query.toString()}`}`);
19917
20004
  }
19918
20005
  async get(id) {
19919
20006
  const response = await this.client.get(this.path(`/${encodeURIComponent(id)}`));
@@ -19961,10 +20048,7 @@ var Integration = class _Integration {
19961
20048
  return this.data.label;
19962
20049
  }
19963
20050
  async update(input) {
19964
- const response = await this.client.patch(
19965
- `/integrations/${encodeURIComponent(this.id)}`,
19966
- input
19967
- );
20051
+ const response = await this.client.patch(`/integrations/${encodeURIComponent(this.id)}`, input);
19968
20052
  return new _Integration(response.data, this.client);
19969
20053
  }
19970
20054
  async unlink() {
@@ -20227,6 +20311,14 @@ var PHPSandbox = class _PHPSandbox {
20227
20311
  this.servers = client.servers;
20228
20312
  this.integrations = client.integrations;
20229
20313
  }
20314
+ async whoami() {
20315
+ const { data } = await this.client.get("/auth/whoami");
20316
+ const result = identitySchema.safeParse(data);
20317
+ if (!result.success) {
20318
+ throw new PHPSandboxError("Invalid identity response.");
20319
+ }
20320
+ return result.data;
20321
+ }
20230
20322
  get runtimeTransport() {
20231
20323
  return this.client.runtimeTransport;
20232
20324
  }
@@ -20274,7 +20366,6 @@ var _NotebookInstance = class _NotebookInstance {
20274
20366
  }
20275
20367
  this.files = new Filesystem(this, this.socket === null ? null : (handler) => this.onDidConnect(handler));
20276
20368
  this.terminals = new Terminals(this);
20277
- this.auth = new Auth(this);
20278
20369
  this.lsp = new Lsp(this);
20279
20370
  this.composer = new Composer(this, client);
20280
20371
  this.runtime = new Runtime(this);
@@ -20475,7 +20566,7 @@ var _NotebookInstance = class _NotebookInstance {
20475
20566
  socket.reconnect();
20476
20567
  this.initialized = false;
20477
20568
  await whenConnected;
20478
- __privateMethod(this, _NotebookInstance_instances, init_fn).call(this);
20569
+ __privateSet(this, _initPromise, __privateMethod(this, _NotebookInstance_instances, init_fn).call(this));
20479
20570
  return this.ready().then(() => this);
20480
20571
  }
20481
20572
  realtimeSocket() {
@@ -20524,7 +20615,9 @@ var NotebookSecrets = class {
20524
20615
  }
20525
20616
  async list(options) {
20526
20617
  const params = new URLSearchParams();
20527
- if (options?.environment) params.set("environment", options.environment);
20618
+ if (options?.environment) {
20619
+ params.set("environment", options.environment);
20620
+ }
20528
20621
  const query = params.toString();
20529
20622
  const response = await this.client.get(
20530
20623
  `/notebook/${this.notebookId}/secrets${query ? `?${query}` : ""}`
@@ -20544,7 +20637,9 @@ var NotebookSecrets = class {
20544
20637
  }
20545
20638
  async delete(name, options) {
20546
20639
  const params = new URLSearchParams();
20547
- if (options?.environment) params.set("environment", options.environment);
20640
+ if (options?.environment) {
20641
+ params.set("environment", options.environment);
20642
+ }
20548
20643
  const query = params.toString();
20549
20644
  await this.client.delete(`/notebook/${this.notebookId}/secrets/${encodeURIComponent(name)}${query ? `?${query}` : ""}`);
20550
20645
  }
@@ -20628,9 +20723,11 @@ export {
20628
20723
  PublicationRun,
20629
20724
  RemoteError,
20630
20725
  TransportError,
20726
+ createPublicationStreamResponse,
20631
20727
  laravelCloudSetupForRepublish,
20632
20728
  notebookBuiltinServices,
20633
- notebookKnownServices
20729
+ notebookKnownServices,
20730
+ readPublicationStream
20634
20731
  };
20635
20732
  /*! Bundled license information:
20636
20733