@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
@@ -44,142 +44,13 @@ var PHPSandbox = (() => {
44
44
  PublicationRun: () => PublicationRun,
45
45
  RemoteError: () => RemoteError,
46
46
  TransportError: () => TransportError,
47
+ createPublicationStreamResponse: () => createPublicationStreamResponse,
47
48
  laravelCloudSetupForRepublish: () => laravelCloudSetupForRepublish,
48
49
  notebookBuiltinServices: () => notebookBuiltinServices,
49
- notebookKnownServices: () => notebookKnownServices
50
+ notebookKnownServices: () => notebookKnownServices,
51
+ readPublicationStream: () => readPublicationStream
50
52
  });
51
53
 
52
- // src/errors/index.ts
53
- var remoteErrorCodes = [
54
- "ActionNotFound",
55
- "AuthenticationRequired",
56
- "BadGateway",
57
- "BadRequest",
58
- "Conflict",
59
- "FileAlreadyExists",
60
- "FileIsDirectory",
61
- "FileNotDirectory",
62
- "FileNotFound",
63
- "FilesystemUnavailable",
64
- "InternalError",
65
- "InvalidArgument",
66
- "InvalidConfiguration",
67
- "InvalidRequest",
68
- "InvalidResponse",
69
- "InvalidServiceCommand",
70
- "MethodNotAllowed",
71
- "NotebookInitializationFailed",
72
- "NotebookUnavailable",
73
- "NotFound",
74
- "PayloadTooLarge",
75
- "PermissionDenied",
76
- "RateLimited",
77
- "RequestFailed",
78
- "RuntimeOperationFailed",
79
- "ServiceNotFound",
80
- "ServiceUnavailable",
81
- "UnprocessableEntity",
82
- "ValidationFailed",
83
- "WorkspaceUnavailable"
84
- ];
85
- var PHPSandboxError = class extends Error {
86
- constructor(message, cause) {
87
- super(message);
88
- this.name = new.target.name;
89
- this.cause = cause;
90
- }
91
- };
92
- var RemoteError = class _RemoteError extends PHPSandboxError {
93
- constructor(message, options) {
94
- super(message, options.cause);
95
- this.source = options.source;
96
- this.status = options.status;
97
- this.code = options.code;
98
- this.details = options.details;
99
- }
100
- static is(error51, code) {
101
- return error51 instanceof _RemoteError && (code === void 0 || error51.code === code);
102
- }
103
- static isValidation(error51) {
104
- return _RemoteError.is(error51, "ValidationFailed") && validationDetails(error51.details) !== void 0;
105
- }
106
- is(code) {
107
- return this.code === code;
108
- }
109
- };
110
- var TransportError = class _TransportError extends PHPSandboxError {
111
- constructor(message, code, cause, response) {
112
- super(message, cause);
113
- this.code = code;
114
- this.response = response;
115
- }
116
- static is(error51, code) {
117
- return error51 instanceof _TransportError && (code === void 0 || error51.code === code);
118
- }
119
- is(code) {
120
- return this.code === code;
121
- }
122
- };
123
- function remoteError(source, payload, cause) {
124
- const error51 = record(payload);
125
- const status = positiveInteger(error51?.status);
126
- const code = nonEmptyString(error51?.code);
127
- const message = nonEmptyString(error51?.message);
128
- if (status === void 0 || !isRemoteErrorCode(code) || message === void 0) {
129
- throw new TransportError("PHPSandbox returned an invalid error response.", "InvalidResponse", cause ?? payload);
130
- }
131
- return new RemoteError(message, {
132
- source,
133
- status,
134
- code,
135
- details: error51?.details,
136
- cause
137
- });
138
- }
139
- function isRemoteErrorCode(value) {
140
- return typeof value === "string" && remoteErrorCodes.includes(value);
141
- }
142
- function positiveInteger(value) {
143
- return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
144
- }
145
- function nonEmptyString(value) {
146
- return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
147
- }
148
- function record(value) {
149
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
150
- }
151
- function stringArrayRecord(value) {
152
- const candidate = record(value);
153
- if (candidate === void 0) {
154
- return void 0;
155
- }
156
- const entries = Object.entries(candidate);
157
- if (!entries.every(([, messages]) => Array.isArray(messages) && messages.every((message) => typeof message === "string"))) {
158
- return void 0;
159
- }
160
- return Object.fromEntries(entries);
161
- }
162
- function validationDetails(value) {
163
- const details = record(value);
164
- const errors = stringArrayRecord(details?.errors);
165
- return errors === void 0 ? void 0 : { errors };
166
- }
167
- var PromiseTimeoutError = class extends Error {
168
- constructor(message, time3) {
169
- super(message);
170
- this.time = time3;
171
- }
172
- };
173
- var SendTimeoutError = class _SendTimeoutError extends TransportError {
174
- constructor(message, time3, cause) {
175
- super(message, "SendTimeout", cause);
176
- this.time = time3;
177
- }
178
- static fromPromiseTimeoutError(error51) {
179
- return new _SendTimeoutError(error51.message, error51.time, error51);
180
- }
181
- };
182
-
183
54
  // node_modules/zod/v4/classic/external.js
184
55
  var external_exports = {};
185
56
  __export(external_exports, {
@@ -374,7 +245,7 @@ var PHPSandbox = (() => {
374
245
  promise: () => promise,
375
246
  property: () => _property,
376
247
  readonly: () => readonly,
377
- record: () => record2,
248
+ record: () => record,
378
249
  refine: () => refine,
379
250
  regex: () => _regex,
380
251
  regexes: () => regexes_exports,
@@ -12712,7 +12583,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
12712
12583
  preprocess: () => preprocess,
12713
12584
  promise: () => promise,
12714
12585
  readonly: () => readonly,
12715
- record: () => record2,
12586
+ record: () => record,
12716
12587
  refine: () => refine,
12717
12588
  set: () => set,
12718
12589
  strictObject: () => strictObject,
@@ -13681,7 +13552,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
13681
13552
  inst.keyType = def.keyType;
13682
13553
  inst.valueType = def.valueType;
13683
13554
  });
13684
- function record2(keyType, valueType, params) {
13555
+ function record(keyType, valueType, params) {
13685
13556
  if (!valueType || !valueType._zod) {
13686
13557
  return new ZodRecord({
13687
13558
  type: "record",
@@ -14148,7 +14019,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14148
14019
  }, ...args);
14149
14020
  function json(params) {
14150
14021
  const jsonSchema = lazy(() => {
14151
- return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record2(string2(), jsonSchema)]);
14022
+ return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record(string2(), jsonSchema)]);
14152
14023
  });
14153
14024
  return jsonSchema;
14154
14025
  }
@@ -14694,12 +14565,146 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14694
14565
  // node_modules/zod/v4/classic/external.js
14695
14566
  config(en_default());
14696
14567
 
14568
+ // src/identity.ts
14569
+ var identitySchema = external_exports.object({
14570
+ user: external_exports.object({ id: external_exports.string(), name: external_exports.string() }).nullable(),
14571
+ organization: external_exports.object({ id: external_exports.string(), name: external_exports.string() }),
14572
+ permissions: external_exports.array(external_exports.string())
14573
+ });
14574
+
14575
+ // src/errors/index.ts
14576
+ var remoteErrorCodes = [
14577
+ "ActionNotFound",
14578
+ "AuthenticationRequired",
14579
+ "BadGateway",
14580
+ "BadRequest",
14581
+ "Conflict",
14582
+ "FileAlreadyExists",
14583
+ "FileIsDirectory",
14584
+ "FileNotDirectory",
14585
+ "FileNotFound",
14586
+ "FilesystemUnavailable",
14587
+ "InternalError",
14588
+ "InvalidArgument",
14589
+ "InvalidConfiguration",
14590
+ "InvalidRequest",
14591
+ "InvalidResponse",
14592
+ "InvalidServiceCommand",
14593
+ "MethodNotAllowed",
14594
+ "NotebookInitializationFailed",
14595
+ "NotebookUnavailable",
14596
+ "NotFound",
14597
+ "PayloadTooLarge",
14598
+ "PermissionDenied",
14599
+ "RateLimited",
14600
+ "RequestFailed",
14601
+ "RuntimeOperationFailed",
14602
+ "ServiceNotFound",
14603
+ "ServiceUnavailable",
14604
+ "UnprocessableEntity",
14605
+ "ValidationFailed",
14606
+ "WorkspaceUnavailable"
14607
+ ];
14608
+ var PHPSandboxError = class extends Error {
14609
+ constructor(message, cause) {
14610
+ super(message);
14611
+ this.name = new.target.name;
14612
+ this.cause = cause;
14613
+ }
14614
+ };
14615
+ var RemoteError = class _RemoteError extends PHPSandboxError {
14616
+ constructor(message, options) {
14617
+ super(message, options.cause);
14618
+ this.source = options.source;
14619
+ this.status = options.status;
14620
+ this.code = options.code;
14621
+ this.details = options.details;
14622
+ }
14623
+ static is(error51, code) {
14624
+ return error51 instanceof _RemoteError && (code === void 0 || error51.code === code);
14625
+ }
14626
+ static isValidation(error51) {
14627
+ return _RemoteError.is(error51, "ValidationFailed") && validationDetails(error51.details) !== void 0;
14628
+ }
14629
+ is(code) {
14630
+ return this.code === code;
14631
+ }
14632
+ };
14633
+ var TransportError = class _TransportError extends PHPSandboxError {
14634
+ constructor(message, code, cause, response) {
14635
+ super(message, cause);
14636
+ this.code = code;
14637
+ this.response = response;
14638
+ }
14639
+ static is(error51, code) {
14640
+ return error51 instanceof _TransportError && (code === void 0 || error51.code === code);
14641
+ }
14642
+ is(code) {
14643
+ return this.code === code;
14644
+ }
14645
+ };
14646
+ function remoteError(source, payload, cause) {
14647
+ const error51 = record2(payload);
14648
+ const status = positiveInteger(error51?.status);
14649
+ const code = nonEmptyString(error51?.code);
14650
+ const message = nonEmptyString(error51?.message);
14651
+ if (status === void 0 || !isRemoteErrorCode(code) || message === void 0) {
14652
+ throw new TransportError("PHPSandbox returned an invalid error response.", "InvalidResponse", cause ?? payload);
14653
+ }
14654
+ return new RemoteError(message, {
14655
+ source,
14656
+ status,
14657
+ code,
14658
+ details: error51?.details,
14659
+ cause
14660
+ });
14661
+ }
14662
+ function isRemoteErrorCode(value) {
14663
+ return typeof value === "string" && remoteErrorCodes.includes(value);
14664
+ }
14665
+ function positiveInteger(value) {
14666
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
14667
+ }
14668
+ function nonEmptyString(value) {
14669
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
14670
+ }
14671
+ function record2(value) {
14672
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
14673
+ }
14674
+ function stringArrayRecord(value) {
14675
+ const candidate = record2(value);
14676
+ if (candidate === void 0) {
14677
+ return void 0;
14678
+ }
14679
+ const entries = Object.entries(candidate);
14680
+ if (!entries.every(([, messages]) => Array.isArray(messages) && messages.every((message) => typeof message === "string"))) {
14681
+ return void 0;
14682
+ }
14683
+ return Object.fromEntries(entries);
14684
+ }
14685
+ function validationDetails(value) {
14686
+ const details = record2(value);
14687
+ const errors = stringArrayRecord(details?.errors);
14688
+ return errors === void 0 ? void 0 : { errors };
14689
+ }
14690
+ var PromiseTimeoutError = class extends Error {
14691
+ constructor(message, time3) {
14692
+ super(message);
14693
+ this.time = time3;
14694
+ }
14695
+ };
14696
+ var SendTimeoutError = class _SendTimeoutError extends TransportError {
14697
+ constructor(message, time3, cause) {
14698
+ super(message, "SendTimeout", cause);
14699
+ this.time = time3;
14700
+ }
14701
+ static fromPromiseTimeoutError(error51) {
14702
+ return new _SendTimeoutError(error51.message, error51.time, error51);
14703
+ }
14704
+ };
14705
+
14697
14706
  // src/schemas/publications.ts
14698
- var PublicationProviderNameSchema = external_exports.enum([
14699
- "cloudflare-containers",
14700
- "ssh-server",
14701
- "laravel-cloud"
14702
- ]);
14707
+ var PublicationProviderNameSchema = external_exports.enum(["cloudflare-containers", "ssh-server", "laravel-cloud"]);
14703
14708
  var PublicationStatusSchema = external_exports.enum([
14704
14709
  "pending",
14705
14710
  "queued",
@@ -14712,36 +14717,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14712
14717
  "deleted",
14713
14718
  "delete_failed"
14714
14719
  ]);
14715
- var PublicationBuildStatusSchema = external_exports.enum([
14716
- "pending",
14717
- "queued",
14718
- "running",
14719
- "succeeded",
14720
- "failed",
14721
- "cancelled"
14722
- ]);
14720
+ var PublicationBuildStatusSchema = external_exports.enum(["pending", "queued", "running", "succeeded", "failed", "cancelled"]);
14723
14721
  var PublicationReleaseStatusSchema = external_exports.enum(["created", "ready", "deleted"]);
14724
- var PublicationSizeSchema = external_exports.enum([
14725
- "nano",
14726
- "small",
14727
- "medium",
14728
- "large",
14729
- "lite",
14730
- "basic",
14731
- "standard-1",
14732
- "standard-2"
14733
- ]);
14734
- var PublicationRegionSchema = external_exports.enum([
14735
- "ENAM",
14736
- "WNAM",
14737
- "EEUR",
14738
- "WEUR",
14739
- "APAC",
14740
- "SAM",
14741
- "ME",
14742
- "OC",
14743
- "AFR"
14744
- ]);
14722
+ var PublicationSizeSchema = external_exports.enum(["nano", "small", "medium", "large", "lite", "basic", "standard-1", "standard-2"]);
14723
+ var PublicationRegionSchema = external_exports.enum(["ENAM", "WNAM", "EEUR", "WEUR", "APAC", "SAM", "ME", "OC", "AFR"]);
14745
14724
  var PublicationJurisdictionSchema = external_exports.enum(["eu", "fedramp"]);
14746
14725
  var PublicationProtectionModeSchema = external_exports.enum(["none", "password"]);
14747
14726
  var PublicationLogStreamSchema = external_exports.enum(["build", "runtime"]);
@@ -14832,6 +14811,179 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14832
14811
  return PublishStreamEventSchema.parse({ type, ...event.data });
14833
14812
  });
14834
14813
 
14814
+ // src/publication/stream.ts
14815
+ async function* readPublicationStream(input, options = {}) {
14816
+ if (input instanceof Response && (!input.ok || !input.body)) {
14817
+ await input.body?.cancel().catch(() => void 0);
14818
+ throw new PHPSandboxError(`Publishing stream is unavailable (HTTP ${input.status}).`);
14819
+ }
14820
+ const stream = input instanceof Response ? input.body : input;
14821
+ const reader = stream.getReader();
14822
+ const decoder = new TextDecoder();
14823
+ let buffer = "";
14824
+ let eventName = "message";
14825
+ let data = [];
14826
+ let ended = false;
14827
+ let receivedResult = false;
14828
+ function dispatch() {
14829
+ const name = eventName;
14830
+ const lines = data;
14831
+ eventName = "message";
14832
+ data = [];
14833
+ if (!lines.length || !PublishStreamSseEventNameSchema.safeParse(name).success) {
14834
+ return null;
14835
+ }
14836
+ const raw = lines.join("\n");
14837
+ let payload;
14838
+ try {
14839
+ payload = JSON.parse(raw);
14840
+ } catch {
14841
+ payload = raw;
14842
+ }
14843
+ const event = PublishStreamSseEventSchema.parse({ event: name, data: payload });
14844
+ if (event.type === "result") {
14845
+ receivedResult = true;
14846
+ }
14847
+ return event;
14848
+ }
14849
+ function line(value) {
14850
+ if (value === "") {
14851
+ return dispatch();
14852
+ }
14853
+ if (value.startsWith(":")) {
14854
+ return null;
14855
+ }
14856
+ const colon = value.indexOf(":");
14857
+ const field = colon < 0 ? value : value.slice(0, colon);
14858
+ let content = colon < 0 ? "" : value.slice(colon + 1);
14859
+ if (content.startsWith(" ")) {
14860
+ content = content.slice(1);
14861
+ }
14862
+ if (field === "event") {
14863
+ eventName = content;
14864
+ }
14865
+ if (field === "data") {
14866
+ data.push(content);
14867
+ }
14868
+ return null;
14869
+ }
14870
+ try {
14871
+ while (true) {
14872
+ const { done, value } = await reader.read();
14873
+ buffer += done ? decoder.decode() : decoder.decode(value, { stream: true });
14874
+ let match;
14875
+ while (match = /\r\n|\r|\n/.exec(buffer)) {
14876
+ if (!done && match[0] === "\r" && match.index === buffer.length - 1) {
14877
+ break;
14878
+ }
14879
+ const event = line(buffer.slice(0, match.index));
14880
+ buffer = buffer.slice(match.index + match[0].length);
14881
+ if (event) {
14882
+ yield event;
14883
+ }
14884
+ }
14885
+ if (done) {
14886
+ ended = true;
14887
+ if (buffer) {
14888
+ const event2 = line(buffer);
14889
+ if (event2) {
14890
+ yield event2;
14891
+ }
14892
+ }
14893
+ const event = dispatch();
14894
+ if (event) {
14895
+ yield event;
14896
+ }
14897
+ if (options.requireResult !== false && !receivedResult) {
14898
+ throw new PHPSandboxError("Publish stream ended without result");
14899
+ }
14900
+ return;
14901
+ }
14902
+ }
14903
+ } finally {
14904
+ if (!ended) {
14905
+ await reader.cancel().catch(() => void 0);
14906
+ }
14907
+ reader.releaseLock();
14908
+ }
14909
+ }
14910
+ function createPublicationStreamResponse(stream, options = {}) {
14911
+ const reader = stream.getReader();
14912
+ let disposed = false;
14913
+ let finished = false;
14914
+ let cancellation;
14915
+ let abort;
14916
+ async function dispose() {
14917
+ if (disposed) {
14918
+ return;
14919
+ }
14920
+ disposed = true;
14921
+ options.signal?.removeEventListener("abort", abort);
14922
+ reader.releaseLock();
14923
+ await options.onDispose?.();
14924
+ }
14925
+ function cancel(reason) {
14926
+ return cancellation ?? (cancellation = (async () => {
14927
+ finished = true;
14928
+ try {
14929
+ await reader.cancel(reason);
14930
+ } finally {
14931
+ await dispose();
14932
+ }
14933
+ })());
14934
+ }
14935
+ return new Response(
14936
+ new ReadableStream(
14937
+ {
14938
+ start(controller) {
14939
+ abort = () => {
14940
+ controller.error(options.signal.reason);
14941
+ void cancel(options.signal.reason).catch(() => void 0);
14942
+ };
14943
+ if (options.signal?.aborted) {
14944
+ abort();
14945
+ } else {
14946
+ options.signal?.addEventListener("abort", abort, { once: true });
14947
+ }
14948
+ },
14949
+ async pull(controller) {
14950
+ try {
14951
+ const { done, value } = await reader.read();
14952
+ if (finished) {
14953
+ return;
14954
+ }
14955
+ if (done) {
14956
+ finished = true;
14957
+ await dispose();
14958
+ controller.close();
14959
+ } else {
14960
+ controller.enqueue(value);
14961
+ }
14962
+ } catch (error51) {
14963
+ if (finished && cancellation) {
14964
+ return;
14965
+ }
14966
+ try {
14967
+ await cancel(error51);
14968
+ } finally {
14969
+ controller.error(error51);
14970
+ }
14971
+ }
14972
+ },
14973
+ cancel
14974
+ },
14975
+ { highWaterMark: 0 }
14976
+ ),
14977
+ {
14978
+ headers: {
14979
+ "Content-Type": "text/event-stream",
14980
+ "Cache-Control": "no-cache, no-transform",
14981
+ "X-Accel-Buffering": "no"
14982
+ }
14983
+ }
14984
+ );
14985
+ }
14986
+
14835
14987
  // src/publication/run.ts
14836
14988
  var PublicationRun = class {
14837
14989
  constructor(initial, client) {
@@ -14919,7 +15071,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
14919
15071
  async consumeStream(eventStreamUrl) {
14920
15072
  try {
14921
15073
  const stream = await this.client.sse(eventStreamUrl, this.streamAbort.signal);
14922
- for await (const event of readPublishStreamEvents(stream)) {
15074
+ for await (const event of readPublicationStream(stream)) {
14923
15075
  this.publish(event);
14924
15076
  if (event.type === "result") {
14925
15077
  const { type: _, ...result } = event;
@@ -15020,78 +15172,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15020
15172
  });
15021
15173
  }
15022
15174
  };
15023
- async function* readPublishStreamEvents(stream) {
15024
- const reader = parseSSEStream(stream).getReader();
15025
- try {
15026
- while (true) {
15027
- const { done, value } = await reader.read();
15028
- if (done) {
15029
- return;
15030
- }
15031
- const event = parsePublishStreamEvent(value);
15032
- if (event) {
15033
- yield event;
15034
- }
15035
- }
15036
- } finally {
15037
- reader.releaseLock();
15038
- }
15039
- }
15040
- function parsePublishStreamEvent(event) {
15041
- if (!PublishStreamSseEventNameSchema.safeParse(event.event).success) {
15042
- return null;
15043
- }
15044
- return PublishStreamSseEventSchema.parse(event);
15045
- }
15046
- function parseSSEStream(input) {
15047
- const decoder = new TextDecoder();
15048
- let buffer = "";
15049
- return input.pipeThrough(
15050
- new TransformStream({
15051
- transform(chunk, controller) {
15052
- buffer += decoder.decode(chunk, { stream: true });
15053
- const blocks = buffer.split("\n\n");
15054
- buffer = blocks.pop() ?? "";
15055
- for (const block of blocks) {
15056
- const event = parseSSEBlock(block);
15057
- if (event) {
15058
- controller.enqueue(event);
15059
- }
15060
- }
15061
- },
15062
- flush(controller) {
15063
- buffer += decoder.decode();
15064
- if (buffer.trim() !== "") {
15065
- const event = parseSSEBlock(buffer);
15066
- if (event) {
15067
- controller.enqueue(event);
15068
- }
15069
- }
15070
- }
15071
- })
15072
- );
15073
- }
15074
- function parseSSEBlock(block) {
15075
- let eventType = "message";
15076
- let data = "";
15077
- for (const line of block.split("\n")) {
15078
- if (line.startsWith("event: ")) {
15079
- eventType = line.slice(7).trim();
15080
- } else if (line.startsWith("data: ")) {
15081
- data += line.slice(6);
15082
- } else if (line.startsWith("data:")) {
15083
- data += line.slice(5);
15084
- }
15085
- }
15086
- if (data === "") {
15087
- return null;
15088
- }
15089
- try {
15090
- return { event: eventType, data: JSON.parse(data) };
15091
- } catch {
15092
- return { event: eventType, data };
15093
- }
15094
- }
15095
15175
 
15096
15176
  // src/publication/resources.ts
15097
15177
  var PublicationResources = class {
@@ -15183,6 +15263,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15183
15263
  follow() {
15184
15264
  return new PublicationRun(this, this.client).start();
15185
15265
  }
15266
+ /** Open the original publishing SSE bytes for an authenticated, transparent proxy. */
15267
+ async stream(signal) {
15268
+ if (!this.data.eventStreamUrl) {
15269
+ throw new PHPSandboxError(`Publication ${this.data.id} has no eventStreamUrl for SSE streaming`);
15270
+ }
15271
+ return this.client.sse(this.data.eventStreamUrl, signal);
15272
+ }
15186
15273
  async destroy(options = {}) {
15187
15274
  const query = options.deleteResources ? "?deleteResources=1" : "";
15188
15275
  await this.client.delete(`/publications/${encodeURIComponent(this.data.id)}${query}`);
@@ -15215,7 +15302,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15215
15302
  }
15216
15303
  async logSnapshot(stream, limit = 50) {
15217
15304
  const query = new URLSearchParams({ stream, limit: String(limit) });
15218
- return (await this.client.get(`/publications/${encodeURIComponent(this.data.id)}/logs?${query}`)).data;
15305
+ return (await this.client.get(
15306
+ `/publications/${encodeURIComponent(this.data.id)}/logs?${query}`
15307
+ )).data;
15219
15308
  }
15220
15309
  async logs() {
15221
15310
  return parseNdjsonStream(
@@ -15324,11 +15413,15 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15324
15413
  /** Publish the exact app selection in a server-owned review. */
15325
15414
  async publish(input) {
15326
15415
  const application = (await this.client.post(`${this.path}/publication`, input)).data;
15327
- if (!("confirmationRequired" in application)) this.startApplicationRuns(application);
15416
+ if (!("confirmationRequired" in application)) {
15417
+ this.startApplicationRuns(application);
15418
+ }
15328
15419
  return application;
15329
15420
  }
15330
15421
  async application(applicationId) {
15331
- return (await this.client.get(`${this.path}/publication/application/${encodeURIComponent(applicationId)}`)).data;
15422
+ return (await this.client.get(
15423
+ `${this.path}/publication/application/${encodeURIComponent(applicationId)}`
15424
+ )).data;
15332
15425
  }
15333
15426
  /** Retry failed apps and pending route attachments while preserving running releases. */
15334
15427
  async retryApplication(applicationId) {
@@ -15345,12 +15438,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15345
15438
  }
15346
15439
  startApplicationRuns(application) {
15347
15440
  for (const app of application.apps) {
15348
- if (!(application.selectedAppIds ?? []).includes(app.appId)) continue;
15349
- if (!["pending", "queued", "building", "deploying"].includes(app.publication.status)) continue;
15350
- new PublicationRun(
15351
- new PublicationInstance(app.publication, this.client, this.notebookId),
15352
- this.client
15353
- ).start();
15441
+ if (!(application.selectedAppIds ?? []).includes(app.appId)) {
15442
+ continue;
15443
+ }
15444
+ if (!["pending", "queued", "building", "deploying"].includes(app.publication.status)) {
15445
+ continue;
15446
+ }
15447
+ new PublicationRun(new PublicationInstance(app.publication, this.client, this.notebookId), this.client).start();
15354
15448
  }
15355
15449
  }
15356
15450
  async catalog(provider, serverId) {
@@ -15965,7 +16059,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15965
16059
  return this.okra.invoke("terminal.close", { id });
15966
16060
  });
15967
16061
  const resize = (dimensions) => {
15968
- this.okra.invoke("terminal.resize", { id, width: dimensions.cols, height: dimensions.rows });
16062
+ return this.okra.invoke("terminal.resize", { id, width: dimensions.cols, height: dimensions.rows });
15969
16063
  };
15970
16064
  if (abortSignal && !abortSignal.aborted) {
15971
16065
  abortHandler = () => {
@@ -15986,20 +16080,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
15986
16080
  }
15987
16081
  };
15988
16082
 
15989
- // src/auth.ts
15990
- var Auth = class {
15991
- constructor(okra) {
15992
- this.okra = okra;
15993
- }
15994
- login(runtimeUrl) {
15995
- const runtimeTicket = new URL(runtimeUrl).searchParams.get("ticket");
15996
- if (runtimeTicket === null || runtimeTicket === "") {
15997
- throw new TypeError("The notebook connection does not contain a runtime ticket.");
15998
- }
15999
- return this.okra.invoke("auth.login", { runtimeTicket });
16000
- }
16001
- };
16002
-
16003
16083
  // src/lsp.ts
16004
16084
  var Lsp = class {
16005
16085
  constructor(okra) {
@@ -16054,10 +16134,10 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16054
16134
  return this.lsp.onClose(this.id, cb);
16055
16135
  }
16056
16136
  dispose() {
16057
- this.lsp.close(this.id);
16137
+ return this.lsp.close(this.id);
16058
16138
  }
16059
16139
  start() {
16060
- this.lsp.start(this.id);
16140
+ return this.lsp.start(this.id);
16061
16141
  }
16062
16142
  onClientDisconnect(cb) {
16063
16143
  return this.lsp.onClientDisconnect(cb);
@@ -16160,11 +16240,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16160
16240
  stderr.fail(error51);
16161
16241
  };
16162
16242
  const { abortSignal, ...payloadOpts } = opts;
16163
- this.completion = this.okra.invoke(
16164
- "shell.exec",
16165
- { command, opts: { ...payloadOpts, id: this.id } },
16166
- { abortSignal }
16167
- ).then((result) => {
16243
+ this.completion = this.okra.invoke("shell.exec", { command, opts: { ...payloadOpts, id: this.id } }, { abortSignal }).then((result) => {
16168
16244
  finish();
16169
16245
  return result;
16170
16246
  }).catch((error51) => {
@@ -16197,15 +16273,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16197
16273
  this.notebookId = notebookId;
16198
16274
  }
16199
16275
  async set(input) {
16200
- const response = await this.client.put(
16201
- `/notebook/${this.notebookId}/composer/credentials`,
16202
- input
16203
- );
16276
+ const response = await this.client.put(`/notebook/${this.notebookId}/composer/credentials`, input);
16204
16277
  return response.data;
16205
16278
  }
16206
16279
  async remove(type, url2) {
16207
16280
  const params = new URLSearchParams({ type });
16208
- if (url2) params.set("url", url2);
16281
+ if (url2) {
16282
+ params.set("url", url2);
16283
+ }
16209
16284
  await this.client.delete(`/notebook/${this.notebookId}/composer/credentials?${params.toString()}`);
16210
16285
  }
16211
16286
  };
@@ -16390,11 +16465,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
16390
16465
  this.telemetry = telemetry;
16391
16466
  }
16392
16467
  follow(options = {}) {
16393
- return watchRuntimeTelemetry(this.okra, this.telemetry, "logs", "notebook.log", (message) => ({
16394
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
16395
- source: "runtime",
16396
- message
16397
- }), options);
16468
+ return watchRuntimeTelemetry(
16469
+ this.okra,
16470
+ this.telemetry,
16471
+ "logs",
16472
+ "notebook.log",
16473
+ (message) => ({
16474
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
16475
+ source: "runtime",
16476
+ message
16477
+ }),
16478
+ options
16479
+ );
16398
16480
  }
16399
16481
  };
16400
16482
 
@@ -18854,7 +18936,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
18854
18936
  id() {
18855
18937
  return this.clientId;
18856
18938
  }
18857
- async registerWatchers() {
18939
+ registerWatchers() {
18858
18940
  const onMessage = (ev) => {
18859
18941
  this.incomingMessageChain = this.incomingMessageChain.catch(() => void 0).then(() => this.processIncomingMessage(ev)).catch((error51) => {
18860
18942
  this.log("error", "Failed to process queued WebSocket frame", {
@@ -19020,7 +19102,9 @@ ${JSON.stringify(metadata, null, 2)}` : "";
19020
19102
  this.eventEmitter.emit(event, this.clientId);
19021
19103
  return;
19022
19104
  }
19023
- event && this.eventEmitter.emit(as || event, data);
19105
+ if (event) {
19106
+ this.eventEmitter.emit(as || event, data);
19107
+ }
19024
19108
  }
19025
19109
  listen(event, listener, _context) {
19026
19110
  return this.eventEmitter.listen(event, listener);
@@ -19116,12 +19200,14 @@ ${JSON.stringify(metadata, null, 2)}` : "";
19116
19200
  });
19117
19201
  closeHandler = (_ev) => {
19118
19202
  if (_ev.code === 1008 && (_ev.reason || "").includes("rate limit")) {
19119
- reject(new RemoteError(_ev.reason || "Rate limit exceeded", {
19120
- source: "runtime",
19121
- status: 429,
19122
- code: "RateLimited",
19123
- cause: _ev
19124
- }));
19203
+ reject(
19204
+ new RemoteError(_ev.reason || "Rate limit exceeded", {
19205
+ source: "runtime",
19206
+ status: 429,
19207
+ code: "RateLimited",
19208
+ cause: _ev
19209
+ })
19210
+ );
19125
19211
  return;
19126
19212
  }
19127
19213
  const detail = describeWebSocketEvent(_ev);
@@ -19657,8 +19743,13 @@ ${JSON.stringify(metadata, null, 2)}` : "";
19657
19743
  async share(email3) {
19658
19744
  return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, { email: email3 })).data;
19659
19745
  }
19746
+ async shareWithOrganization(organizationId) {
19747
+ return (await this.client.post(`/servers/${encodeURIComponent(this.data.id)}/members`, { organizationId })).data;
19748
+ }
19660
19749
  async revokeAccess(memberId) {
19661
- await this.client.delete(`/servers/${encodeURIComponent(this.data.id)}/members/${encodeURIComponent(String(memberId))}`);
19750
+ await this.client.delete(
19751
+ `/servers/${encodeURIComponent(this.data.id)}/members/${encodeURIComponent(String(memberId))}`
19752
+ );
19662
19753
  }
19663
19754
  refresh() {
19664
19755
  return this.client.servers.get(this.data.id);
@@ -19882,9 +19973,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
19882
19973
  throw new TypeError("Runtime file contents must be binary data.");
19883
19974
  }
19884
19975
  headers["Content-Type"] = "application/octet-stream";
19885
- return Uint8Array.from(
19886
- new Uint8Array(payload.contents.buffer, payload.contents.byteOffset, payload.contents.byteLength)
19887
- ).buffer;
19976
+ return Uint8Array.from(new Uint8Array(payload.contents.buffer, payload.contents.byteOffset, payload.contents.byteLength)).buffer;
19888
19977
  }
19889
19978
  headers["Content-Type"] = "application/json";
19890
19979
  return JSON.stringify(data);
@@ -19946,11 +20035,11 @@ ${JSON.stringify(metadata, null, 2)}` : "";
19946
20035
  async list(options = {}) {
19947
20036
  const query = new URLSearchParams();
19948
20037
  for (const [name, value] of Object.entries(options)) {
19949
- if (value !== void 0) query.set(name, String(value));
20038
+ if (value !== void 0) {
20039
+ query.set(name, String(value));
20040
+ }
19950
20041
  }
19951
- return this.client.get(
19952
- `${this.path()}${query.size === 0 ? "" : `?${query.toString()}`}`
19953
- );
20042
+ return this.client.get(`${this.path()}${query.size === 0 ? "" : `?${query.toString()}`}`);
19954
20043
  }
19955
20044
  async get(id) {
19956
20045
  const response = await this.client.get(this.path(`/${encodeURIComponent(id)}`));
@@ -19998,10 +20087,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
19998
20087
  return this.data.label;
19999
20088
  }
20000
20089
  async update(input) {
20001
- const response = await this.client.patch(
20002
- `/integrations/${encodeURIComponent(this.id)}`,
20003
- input
20004
- );
20090
+ const response = await this.client.patch(`/integrations/${encodeURIComponent(this.id)}`, input);
20005
20091
  return new _Integration(response.data, this.client);
20006
20092
  }
20007
20093
  async unlink() {
@@ -20264,6 +20350,14 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20264
20350
  this.servers = client.servers;
20265
20351
  this.integrations = client.integrations;
20266
20352
  }
20353
+ async whoami() {
20354
+ const { data } = await this.client.get("/auth/whoami");
20355
+ const result = identitySchema.safeParse(data);
20356
+ if (!result.success) {
20357
+ throw new PHPSandboxError("Invalid identity response.");
20358
+ }
20359
+ return result.data;
20360
+ }
20267
20361
  get runtimeTransport() {
20268
20362
  return this.client.runtimeTransport;
20269
20363
  }
@@ -20311,7 +20405,6 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20311
20405
  }
20312
20406
  this.files = new Filesystem(this, this.socket === null ? null : (handler) => this.onDidConnect(handler));
20313
20407
  this.terminals = new Terminals(this);
20314
- this.auth = new Auth(this);
20315
20408
  this.lsp = new Lsp(this);
20316
20409
  this.composer = new Composer(this, client);
20317
20410
  this.runtime = new Runtime(this);
@@ -20512,7 +20605,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20512
20605
  socket.reconnect();
20513
20606
  this.initialized = false;
20514
20607
  await whenConnected;
20515
- __privateMethod(this, _NotebookInstance_instances, init_fn).call(this);
20608
+ __privateSet(this, _initPromise, __privateMethod(this, _NotebookInstance_instances, init_fn).call(this));
20516
20609
  return this.ready().then(() => this);
20517
20610
  }
20518
20611
  realtimeSocket() {
@@ -20561,7 +20654,9 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20561
20654
  }
20562
20655
  async list(options) {
20563
20656
  const params = new URLSearchParams();
20564
- if (options?.environment) params.set("environment", options.environment);
20657
+ if (options?.environment) {
20658
+ params.set("environment", options.environment);
20659
+ }
20565
20660
  const query = params.toString();
20566
20661
  const response = await this.client.get(
20567
20662
  `/notebook/${this.notebookId}/secrets${query ? `?${query}` : ""}`
@@ -20581,7 +20676,9 @@ ${JSON.stringify(metadata, null, 2)}` : "";
20581
20676
  }
20582
20677
  async delete(name, options) {
20583
20678
  const params = new URLSearchParams();
20584
- if (options?.environment) params.set("environment", options.environment);
20679
+ if (options?.environment) {
20680
+ params.set("environment", options.environment);
20681
+ }
20585
20682
  const query = params.toString();
20586
20683
  await this.client.delete(`/notebook/${this.notebookId}/secrets/${encodeURIComponent(name)}${query ? `?${query}` : ""}`);
20587
20684
  }