@phpsandbox/sdk 0.0.68 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -13
- package/dist/auth.d.ts +0 -1
- package/dist/auth.js +0 -3
- package/dist/beacon/index.d.ts +2 -0
- package/dist/beacon/index.js +5 -0
- package/dist/browser/phpsandbox-sdk.esm.js +306 -1010
- package/dist/browser/phpsandbox-sdk.esm.min.js +24 -24
- package/dist/browser/phpsandbox-sdk.iife.js +306 -1010
- package/dist/browser/phpsandbox-sdk.iife.min.js +24 -24
- package/dist/filesystem.d.ts +2 -1
- package/dist/filesystem.js +35 -2
- package/dist/index.d.ts +14 -19
- package/dist/index.js +16 -24
- package/dist/publications.d.ts +222 -0
- package/dist/{deployments.js → publications.js} +64 -69
- package/dist/repl.d.ts +0 -2
- package/dist/repl.js +0 -3
- package/dist/schemas/{deployments.d.ts → publications.d.ts} +68 -68
- package/dist/schemas/publications.js +133 -0
- package/dist/shell.d.ts +43 -22
- package/dist/shell.js +103 -75
- package/dist/terminal.d.ts +1 -3
- package/dist/terminal.js +2 -5
- package/docs/api-summary.md +13 -10
- package/docs/cdn-usage.md +4 -4
- package/docs/getting-started.md +6 -6
- package/examples/README.md +8 -9
- package/examples/basic.ts +1 -1
- package/examples/git-merge-smoke.ts +2 -2
- package/examples/laravel-load-test.ts +13 -18
- package/examples/notebook-readonly-smoke.ts +8 -8
- package/examples/publication-provider-label.ts +11 -0
- package/examples/{deploy-cloudflare-container.ts → publish-cloudflare-container.ts} +11 -11
- package/examples/{deploy-laravel-cloud.ts → publish-laravel-cloud.ts} +11 -11
- package/examples/{deploy-ssh-agent.ts → publish-ssh-agent.ts} +15 -16
- package/package.json +7 -2
- package/dist/deployments.d.ts +0 -251
- package/dist/laravel.d.ts +0 -22
- package/dist/laravel.js +0 -11
- package/dist/schemas/deployments.js +0 -133
- package/examples/deployment-provider-label.ts +0 -11
|
@@ -112,8 +112,25 @@ var Filesystem = class {
|
|
|
112
112
|
info(path) {
|
|
113
113
|
return this.okra.invoke("fs.info", { path });
|
|
114
114
|
}
|
|
115
|
-
write(path, contents) {
|
|
116
|
-
|
|
115
|
+
async write(path, contents, options = { overwrite: true, create: true, unlock: false, atomic: false }) {
|
|
116
|
+
if (typeof contents === "string") {
|
|
117
|
+
return this.okra.invoke("fs.write", { path, contents });
|
|
118
|
+
}
|
|
119
|
+
const bytes = contents instanceof Uint8Array ? contents : await collectBytes(contents);
|
|
120
|
+
await this.writeFile(path, bytes, options);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
read(path) {
|
|
124
|
+
return new ReadableStream({
|
|
125
|
+
start: async (controller) => {
|
|
126
|
+
try {
|
|
127
|
+
controller.enqueue(await this.readFile(path));
|
|
128
|
+
controller.close();
|
|
129
|
+
} catch (error51) {
|
|
130
|
+
controller.error(error51);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
117
134
|
}
|
|
118
135
|
find(query, options = {
|
|
119
136
|
useIgnoreFiles: false,
|
|
@@ -289,6 +306,21 @@ var Filesystem = class {
|
|
|
289
306
|
throw e;
|
|
290
307
|
}
|
|
291
308
|
};
|
|
309
|
+
async function collectBytes(stream) {
|
|
310
|
+
const chunks = [];
|
|
311
|
+
let length = 0;
|
|
312
|
+
for await (const chunk of stream) {
|
|
313
|
+
chunks.push(chunk);
|
|
314
|
+
length += chunk.byteLength;
|
|
315
|
+
}
|
|
316
|
+
const output = new Uint8Array(length);
|
|
317
|
+
let offset = 0;
|
|
318
|
+
for (const chunk of chunks) {
|
|
319
|
+
output.set(chunk, offset);
|
|
320
|
+
offset += chunk.byteLength;
|
|
321
|
+
}
|
|
322
|
+
return output;
|
|
323
|
+
}
|
|
292
324
|
|
|
293
325
|
// src/errors/index.ts
|
|
294
326
|
var PromiseTimeoutError = class extends Error {
|
|
@@ -341,9 +373,6 @@ var Terminal = class {
|
|
|
341
373
|
list() {
|
|
342
374
|
return this.okra.invoke("terminal.list");
|
|
343
375
|
}
|
|
344
|
-
start() {
|
|
345
|
-
return this.okra.invoke("terminal.start");
|
|
346
|
-
}
|
|
347
376
|
create(input) {
|
|
348
377
|
return this.okra.invoke("terminal.create", input);
|
|
349
378
|
}
|
|
@@ -476,7 +505,7 @@ var Terminal = class {
|
|
|
476
505
|
disposeInput();
|
|
477
506
|
}
|
|
478
507
|
});
|
|
479
|
-
const
|
|
508
|
+
const completion = new Promise((resolve) => {
|
|
480
509
|
disposables.add(
|
|
481
510
|
this.listen(`terminal.close.${id}`, (data) => {
|
|
482
511
|
if (controller) {
|
|
@@ -505,7 +534,7 @@ var Terminal = class {
|
|
|
505
534
|
}
|
|
506
535
|
return {
|
|
507
536
|
process: {
|
|
508
|
-
|
|
537
|
+
wait: () => completion,
|
|
509
538
|
input,
|
|
510
539
|
output,
|
|
511
540
|
kill,
|
|
@@ -581,9 +610,6 @@ var Auth = class {
|
|
|
581
610
|
constructor(okra) {
|
|
582
611
|
this.okra = okra;
|
|
583
612
|
}
|
|
584
|
-
logout() {
|
|
585
|
-
this.okra.dispose();
|
|
586
|
-
}
|
|
587
613
|
login(runtimeUrl) {
|
|
588
614
|
const runtimeTicket = new URL(runtimeUrl).searchParams.get("ticket");
|
|
589
615
|
if (runtimeTicket === null || runtimeTicket === "") {
|
|
@@ -708,19 +734,6 @@ var Log = class {
|
|
|
708
734
|
}
|
|
709
735
|
};
|
|
710
736
|
|
|
711
|
-
// src/laravel.ts
|
|
712
|
-
var Laravel = class {
|
|
713
|
-
constructor(okra) {
|
|
714
|
-
this.okra = okra;
|
|
715
|
-
}
|
|
716
|
-
maintenanceInfo() {
|
|
717
|
-
return this.okra.invoke("laravel.maintenance.info", {});
|
|
718
|
-
}
|
|
719
|
-
toggleMaintenance(down) {
|
|
720
|
-
return this.okra.invoke("laravel.maintenance.toggle", down);
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
|
|
724
737
|
// src/repl.ts
|
|
725
738
|
var Repl = class {
|
|
726
739
|
constructor(okra) {
|
|
@@ -735,9 +748,6 @@ var Repl = class {
|
|
|
735
748
|
stop() {
|
|
736
749
|
return this.okra.invoke("repl.stop");
|
|
737
750
|
}
|
|
738
|
-
start() {
|
|
739
|
-
return this.okra.invoke("repl.start");
|
|
740
|
-
}
|
|
741
751
|
resize(cols, rows) {
|
|
742
752
|
return this.okra.invoke("repl.resize", { cols, rows });
|
|
743
753
|
}
|
|
@@ -750,113 +760,142 @@ var Repl = class {
|
|
|
750
760
|
};
|
|
751
761
|
|
|
752
762
|
// src/shell.ts
|
|
753
|
-
function
|
|
763
|
+
function resolveRunInput(command, argsOrOpts = [], opts) {
|
|
754
764
|
const args = Array.isArray(argsOrOpts) ? argsOrOpts : [];
|
|
755
765
|
const resolvedOpts = Array.isArray(argsOrOpts) ? opts : argsOrOpts;
|
|
756
766
|
return {
|
|
757
767
|
command: Array.isArray(command) ? command : args.length > 0 ? [command, ...args] : command,
|
|
758
|
-
opts: resolvedOpts
|
|
768
|
+
opts: { tty: false, ...resolvedOpts }
|
|
759
769
|
};
|
|
760
770
|
}
|
|
761
771
|
var CommandError = class extends Error {
|
|
762
|
-
constructor(
|
|
763
|
-
super(output);
|
|
764
|
-
this.
|
|
765
|
-
this.exitCode = exitCode;
|
|
772
|
+
constructor(result) {
|
|
773
|
+
super(result.output);
|
|
774
|
+
this.result = result;
|
|
766
775
|
}
|
|
767
776
|
};
|
|
768
|
-
var
|
|
769
|
-
constructor(output, exitCode) {
|
|
777
|
+
var ProcessResult = class {
|
|
778
|
+
constructor(output, stdout, stderr, exitCode) {
|
|
770
779
|
this.output = output;
|
|
780
|
+
this.stdout = stdout;
|
|
781
|
+
this.stderr = stderr;
|
|
771
782
|
this.exitCode = exitCode;
|
|
772
783
|
}
|
|
773
784
|
throw() {
|
|
774
785
|
if (this.exitCode !== 0) {
|
|
775
|
-
throw new CommandError(this
|
|
786
|
+
throw new CommandError(this);
|
|
776
787
|
}
|
|
777
788
|
return this;
|
|
778
789
|
}
|
|
779
790
|
};
|
|
780
|
-
var
|
|
781
|
-
constructor(
|
|
782
|
-
this.
|
|
791
|
+
var OutputStream = class {
|
|
792
|
+
constructor() {
|
|
793
|
+
this.controller = null;
|
|
794
|
+
this.closed = false;
|
|
795
|
+
this.stream = new ReadableStream({
|
|
796
|
+
start: (controller) => {
|
|
797
|
+
this.controller = controller;
|
|
798
|
+
},
|
|
799
|
+
cancel: () => {
|
|
800
|
+
this.closed = true;
|
|
801
|
+
this.controller = null;
|
|
802
|
+
}
|
|
803
|
+
});
|
|
783
804
|
}
|
|
784
|
-
|
|
785
|
-
|
|
805
|
+
enqueue(value) {
|
|
806
|
+
if (!this.closed) {
|
|
807
|
+
this.controller?.enqueue(value);
|
|
808
|
+
}
|
|
786
809
|
}
|
|
787
|
-
|
|
788
|
-
|
|
810
|
+
close() {
|
|
811
|
+
if (this.closed) {
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
this.closed = true;
|
|
815
|
+
this.controller?.close();
|
|
816
|
+
this.controller = null;
|
|
789
817
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
opts: Object.keys(payloadOpts).length > 0 ? payloadOpts : void 0
|
|
798
|
-
},
|
|
799
|
-
{ abortSignal }
|
|
800
|
-
);
|
|
801
|
-
return new Result(result.output, result.exitCode);
|
|
818
|
+
fail(error51) {
|
|
819
|
+
if (this.closed) {
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
this.closed = true;
|
|
823
|
+
this.controller?.error(error51);
|
|
824
|
+
this.controller = null;
|
|
802
825
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
const
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
dispose();
|
|
821
|
-
if (controller) {
|
|
822
|
-
try {
|
|
823
|
-
controller.close();
|
|
824
|
-
} catch {
|
|
826
|
+
};
|
|
827
|
+
var ShellProcess = class {
|
|
828
|
+
constructor(id, okra, command, opts) {
|
|
829
|
+
this.id = id;
|
|
830
|
+
this.okra = okra;
|
|
831
|
+
const output = new OutputStream();
|
|
832
|
+
const stdout = new OutputStream();
|
|
833
|
+
const stderr = new OutputStream();
|
|
834
|
+
this.output = output.stream;
|
|
835
|
+
this.stdout = stdout.stream;
|
|
836
|
+
this.stderr = stderr.stream;
|
|
837
|
+
this.stdin = new WritableStream({
|
|
838
|
+
write: async (chunk) => {
|
|
839
|
+
const input = typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk);
|
|
840
|
+
const written = await this.okra.invoke("shell.input", { id: this.id, input });
|
|
841
|
+
if (!written) {
|
|
842
|
+
throw new Error(`Process ${this.id} is not accepting input`);
|
|
825
843
|
}
|
|
826
844
|
}
|
|
845
|
+
});
|
|
846
|
+
const encoder = new TextEncoder();
|
|
847
|
+
let subscription = this.okra.listen(`shell.output.${this.id}`, (event) => {
|
|
848
|
+
const data = encoder.encode(event.output);
|
|
849
|
+
const source = event.source ?? "output";
|
|
850
|
+
output.enqueue({ source, data });
|
|
851
|
+
if (source === "stderr") {
|
|
852
|
+
stderr.enqueue(data);
|
|
853
|
+
} else {
|
|
854
|
+
stdout.enqueue(data);
|
|
855
|
+
}
|
|
856
|
+
});
|
|
857
|
+
const finish = () => {
|
|
858
|
+
subscription?.dispose();
|
|
859
|
+
subscription = null;
|
|
860
|
+
output.close();
|
|
861
|
+
stdout.close();
|
|
862
|
+
stderr.close();
|
|
827
863
|
};
|
|
828
864
|
const fail = (error51) => {
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
if (controller) {
|
|
835
|
-
controller.error(error51);
|
|
836
|
-
}
|
|
865
|
+
subscription?.dispose();
|
|
866
|
+
subscription = null;
|
|
867
|
+
output.fail(error51);
|
|
868
|
+
stdout.fail(error51);
|
|
869
|
+
stderr.fail(error51);
|
|
837
870
|
};
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
},
|
|
847
|
-
cancel: () => {
|
|
848
|
-
closed = true;
|
|
849
|
-
dispose();
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
const result = this.exec(input.command, { ...input.opts, id }).then((response) => {
|
|
853
|
-
close();
|
|
854
|
-
return response;
|
|
871
|
+
const { abortSignal, ...payloadOpts } = opts;
|
|
872
|
+
this.completion = this.okra.invoke(
|
|
873
|
+
"shell.exec",
|
|
874
|
+
{ command, opts: { ...payloadOpts, id: this.id } },
|
|
875
|
+
{ abortSignal }
|
|
876
|
+
).then((result) => {
|
|
877
|
+
finish();
|
|
878
|
+
return new ProcessResult(result.output, result.stdout, result.stderr, result.exitCode);
|
|
855
879
|
}).catch((error51) => {
|
|
856
880
|
fail(error51);
|
|
857
881
|
throw error51;
|
|
858
882
|
});
|
|
859
|
-
|
|
883
|
+
}
|
|
884
|
+
wait() {
|
|
885
|
+
return this.completion;
|
|
886
|
+
}
|
|
887
|
+
async kill() {
|
|
888
|
+
await this.okra.invoke("shell.kill", { id: this.id });
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
var Shell = class {
|
|
892
|
+
constructor(okra) {
|
|
893
|
+
this.okra = okra;
|
|
894
|
+
}
|
|
895
|
+
run(command, argsOrOpts = [], opts) {
|
|
896
|
+
const input = resolveRunInput(command, argsOrOpts, opts);
|
|
897
|
+
const id = input.opts?.id ?? nanoid();
|
|
898
|
+
return new ShellProcess(id, this.okra, input.command, { ...input.opts, id });
|
|
860
899
|
}
|
|
861
900
|
};
|
|
862
901
|
|
|
@@ -3927,732 +3966,6 @@ var Git = class {
|
|
|
3927
3966
|
}
|
|
3928
3967
|
};
|
|
3929
3968
|
|
|
3930
|
-
// src/beacon/navigator.ts
|
|
3931
|
-
var Navigator = class {
|
|
3932
|
-
constructor(onEvent, onceEvent, beacon) {
|
|
3933
|
-
this.onEvent = onEvent;
|
|
3934
|
-
this.onceEvent = onceEvent;
|
|
3935
|
-
this.beacon = beacon;
|
|
3936
|
-
this.urlHistory = [];
|
|
3937
|
-
this.currentIndex = 0;
|
|
3938
|
-
this._canGoBack = false;
|
|
3939
|
-
this._canGoForward = false;
|
|
3940
|
-
this.beacon = beacon;
|
|
3941
|
-
this.setupUrlChangeListener();
|
|
3942
|
-
this.urlHistory.push(beacon.iframe.src);
|
|
3943
|
-
this.updateNavigationState();
|
|
3944
|
-
}
|
|
3945
|
-
/**
|
|
3946
|
-
* Navigate to a URL using internal history management
|
|
3947
|
-
*/
|
|
3948
|
-
visit(url2) {
|
|
3949
|
-
if (!this.beacon) {
|
|
3950
|
-
throw new Error("Beacon reference not set");
|
|
3951
|
-
}
|
|
3952
|
-
this.beacon.navigate(url2);
|
|
3953
|
-
if (this.currentIndex < this.urlHistory.length - 1) {
|
|
3954
|
-
this.urlHistory = this.urlHistory.slice(0, this.currentIndex + 1);
|
|
3955
|
-
}
|
|
3956
|
-
this.urlHistory.push(url2);
|
|
3957
|
-
this.currentIndex = this.urlHistory.length - 1;
|
|
3958
|
-
this.updateNavigationState();
|
|
3959
|
-
this.emitHistoryChange(url2, "push");
|
|
3960
|
-
}
|
|
3961
|
-
/**
|
|
3962
|
-
* Set up listener for URL change events from the beacon
|
|
3963
|
-
*/
|
|
3964
|
-
setupUrlChangeListener() {
|
|
3965
|
-
this.beacon.on("urlChange", (payload) => {
|
|
3966
|
-
this.addToHistory(payload.newUrl);
|
|
3967
|
-
});
|
|
3968
|
-
}
|
|
3969
|
-
/**
|
|
3970
|
-
* Add URL to internal history
|
|
3971
|
-
*/
|
|
3972
|
-
addToHistory(url2) {
|
|
3973
|
-
if (this.currentIndex < this.urlHistory.length - 1) {
|
|
3974
|
-
this.urlHistory = this.urlHistory.slice(0, this.currentIndex + 1);
|
|
3975
|
-
}
|
|
3976
|
-
this.urlHistory.push(url2);
|
|
3977
|
-
this.currentIndex = this.urlHistory.length - 1;
|
|
3978
|
-
this.updateNavigationState();
|
|
3979
|
-
}
|
|
3980
|
-
/**
|
|
3981
|
-
* Update internal navigation state and emit changes
|
|
3982
|
-
*/
|
|
3983
|
-
updateNavigationState() {
|
|
3984
|
-
const previousCanGoBack = this._canGoBack;
|
|
3985
|
-
const previousCanGoForward = this._canGoForward;
|
|
3986
|
-
this._canGoBack = this.currentIndex > 0;
|
|
3987
|
-
this._canGoForward = this.currentIndex < this.urlHistory.length - 1;
|
|
3988
|
-
if (previousCanGoBack !== this._canGoBack || previousCanGoForward !== this._canGoForward) {
|
|
3989
|
-
this.emitNavigationStateChange();
|
|
3990
|
-
}
|
|
3991
|
-
}
|
|
3992
|
-
/**
|
|
3993
|
-
* Emit navigation state change event
|
|
3994
|
-
*/
|
|
3995
|
-
emitNavigationStateChange() {
|
|
3996
|
-
if (this.beacon && this.beacon.emit) {
|
|
3997
|
-
this.beacon.emit("navigationStateChange", {
|
|
3998
|
-
canGoBack: this._canGoBack,
|
|
3999
|
-
canGoForward: this._canGoForward,
|
|
4000
|
-
currentIndex: this.currentIndex,
|
|
4001
|
-
historyLength: this.urlHistory.length,
|
|
4002
|
-
timestamp: Date.now()
|
|
4003
|
-
});
|
|
4004
|
-
}
|
|
4005
|
-
}
|
|
4006
|
-
get canGoBack() {
|
|
4007
|
-
return this._canGoBack;
|
|
4008
|
-
}
|
|
4009
|
-
get canGoForward() {
|
|
4010
|
-
return this._canGoForward;
|
|
4011
|
-
}
|
|
4012
|
-
async goBack() {
|
|
4013
|
-
if (!this.canGoBack) {
|
|
4014
|
-
return { success: false, error: "Cannot go back - no previous history" };
|
|
4015
|
-
}
|
|
4016
|
-
this.currentIndex--;
|
|
4017
|
-
this.updateNavigationState();
|
|
4018
|
-
const url2 = this.urlHistory[this.currentIndex];
|
|
4019
|
-
if (!this.beacon) {
|
|
4020
|
-
return { success: false, error: "Beacon reference not set" };
|
|
4021
|
-
}
|
|
4022
|
-
this.beacon.navigate(url2);
|
|
4023
|
-
this.emitHistoryChange(url2, "back");
|
|
4024
|
-
return { success: true, url: url2 };
|
|
4025
|
-
}
|
|
4026
|
-
/**
|
|
4027
|
-
* Navigate forward in internal history
|
|
4028
|
-
*/
|
|
4029
|
-
async goForward() {
|
|
4030
|
-
if (!this.canGoForward) {
|
|
4031
|
-
return { success: false, error: "Cannot go forward - no forward history" };
|
|
4032
|
-
}
|
|
4033
|
-
this.currentIndex++;
|
|
4034
|
-
this.updateNavigationState();
|
|
4035
|
-
const url2 = this.urlHistory[this.currentIndex];
|
|
4036
|
-
if (!this.beacon) {
|
|
4037
|
-
return { success: false, error: "Beacon reference not set" };
|
|
4038
|
-
}
|
|
4039
|
-
this.beacon.navigate(url2);
|
|
4040
|
-
this.emitHistoryChange(url2, "forward");
|
|
4041
|
-
return { success: true, url: url2 };
|
|
4042
|
-
}
|
|
4043
|
-
/**
|
|
4044
|
-
* Reload the current page
|
|
4045
|
-
*/
|
|
4046
|
-
async reload() {
|
|
4047
|
-
if (this.currentIndex >= 0 && this.currentIndex < this.urlHistory.length) {
|
|
4048
|
-
const currentUrl = this.urlHistory[this.currentIndex];
|
|
4049
|
-
if (!this.beacon) {
|
|
4050
|
-
throw new Error("Beacon reference not set");
|
|
4051
|
-
}
|
|
4052
|
-
this.beacon.navigate(currentUrl);
|
|
4053
|
-
this.emitHistoryChange(currentUrl, "reload");
|
|
4054
|
-
}
|
|
4055
|
-
}
|
|
4056
|
-
/**
|
|
4057
|
-
* Get current URL from internal history
|
|
4058
|
-
*/
|
|
4059
|
-
getCurrentUrl() {
|
|
4060
|
-
if (this.currentIndex >= 0 && this.currentIndex < this.urlHistory.length) {
|
|
4061
|
-
return new URL(this.urlHistory[this.currentIndex]);
|
|
4062
|
-
}
|
|
4063
|
-
return new URL("about:blank");
|
|
4064
|
-
}
|
|
4065
|
-
/**
|
|
4066
|
-
* Get the complete history array
|
|
4067
|
-
*/
|
|
4068
|
-
getHistory() {
|
|
4069
|
-
return [...this.urlHistory];
|
|
4070
|
-
}
|
|
4071
|
-
/**
|
|
4072
|
-
* Get current history index
|
|
4073
|
-
*/
|
|
4074
|
-
getCurrentIndex() {
|
|
4075
|
-
return this.currentIndex;
|
|
4076
|
-
}
|
|
4077
|
-
/**
|
|
4078
|
-
* Check if can go back synchronously
|
|
4079
|
-
*/
|
|
4080
|
-
canGoBackSync() {
|
|
4081
|
-
return this.currentIndex > 0;
|
|
4082
|
-
}
|
|
4083
|
-
/**
|
|
4084
|
-
* Check if can go forward synchronously
|
|
4085
|
-
*/
|
|
4086
|
-
canGoForwardSync() {
|
|
4087
|
-
return this.currentIndex < this.urlHistory.length - 1;
|
|
4088
|
-
}
|
|
4089
|
-
/**
|
|
4090
|
-
* Emit history change event
|
|
4091
|
-
*/
|
|
4092
|
-
emitHistoryChange(url2, direction) {
|
|
4093
|
-
if (this.beacon && this.beacon.emit) {
|
|
4094
|
-
this.beacon.emit("historyChange", {
|
|
4095
|
-
url: url2,
|
|
4096
|
-
state: null,
|
|
4097
|
-
direction,
|
|
4098
|
-
timestamp: Date.now()
|
|
4099
|
-
});
|
|
4100
|
-
}
|
|
4101
|
-
}
|
|
4102
|
-
/**
|
|
4103
|
-
* Push a new state to internal history (legacy method for compatibility)
|
|
4104
|
-
*/
|
|
4105
|
-
async pushState(url2) {
|
|
4106
|
-
this.visit(url2);
|
|
4107
|
-
}
|
|
4108
|
-
/**
|
|
4109
|
-
* Replace current state in internal history (legacy method for compatibility)
|
|
4110
|
-
*/
|
|
4111
|
-
async replaceState(url2) {
|
|
4112
|
-
if (this.currentIndex >= 0 && this.currentIndex < this.urlHistory.length) {
|
|
4113
|
-
this.urlHistory[this.currentIndex] = url2;
|
|
4114
|
-
if (!this.beacon) {
|
|
4115
|
-
throw new Error("Beacon reference not set");
|
|
4116
|
-
}
|
|
4117
|
-
this.beacon.navigate(url2);
|
|
4118
|
-
this.emitHistoryChange(url2, "replace");
|
|
4119
|
-
} else {
|
|
4120
|
-
this.visit(url2);
|
|
4121
|
-
}
|
|
4122
|
-
}
|
|
4123
|
-
/**
|
|
4124
|
-
* Get the current history length
|
|
4125
|
-
*/
|
|
4126
|
-
async getHistoryLength() {
|
|
4127
|
-
return this.urlHistory.length;
|
|
4128
|
-
}
|
|
4129
|
-
/**
|
|
4130
|
-
* Get the current history state (always null since we don't store state)
|
|
4131
|
-
*/
|
|
4132
|
-
async getHistoryState() {
|
|
4133
|
-
return null;
|
|
4134
|
-
}
|
|
4135
|
-
/**
|
|
4136
|
-
* Get comprehensive history information
|
|
4137
|
-
*/
|
|
4138
|
-
async getHistoryInfo() {
|
|
4139
|
-
return {
|
|
4140
|
-
length: this.urlHistory.length,
|
|
4141
|
-
state: null,
|
|
4142
|
-
url: this.urlHistory[this.currentIndex] || "",
|
|
4143
|
-
canGoBack: this.canGoBack,
|
|
4144
|
-
canGoForward: this.canGoForward
|
|
4145
|
-
};
|
|
4146
|
-
}
|
|
4147
|
-
/**
|
|
4148
|
-
* Listen for navigator events
|
|
4149
|
-
*/
|
|
4150
|
-
on(event, handler) {
|
|
4151
|
-
return this.onEvent(event, handler);
|
|
4152
|
-
}
|
|
4153
|
-
/**
|
|
4154
|
-
* Listen for navigator events (once)
|
|
4155
|
-
*/
|
|
4156
|
-
once(event, handler) {
|
|
4157
|
-
this.onceEvent(event, handler);
|
|
4158
|
-
}
|
|
4159
|
-
};
|
|
4160
|
-
|
|
4161
|
-
// src/beacon/index.ts
|
|
4162
|
-
function ensureBrowserEnvironment() {
|
|
4163
|
-
if (typeof window === "undefined") {
|
|
4164
|
-
throw new Error("Beacon SDK can only be used in a browser environment");
|
|
4165
|
-
}
|
|
4166
|
-
}
|
|
4167
|
-
var BeaconError = class extends Error {
|
|
4168
|
-
constructor(message, code) {
|
|
4169
|
-
super(message);
|
|
4170
|
-
this.code = code;
|
|
4171
|
-
this.name = "BeaconError";
|
|
4172
|
-
}
|
|
4173
|
-
};
|
|
4174
|
-
var BeaconTimeoutError = class extends BeaconError {
|
|
4175
|
-
constructor(operation, timeoutMs) {
|
|
4176
|
-
super(`Beacon operation '${operation}' timed out after ${timeoutMs}ms`);
|
|
4177
|
-
this.code = "TIMEOUT";
|
|
4178
|
-
}
|
|
4179
|
-
};
|
|
4180
|
-
var BeaconConnectionError = class extends BeaconError {
|
|
4181
|
-
constructor(message) {
|
|
4182
|
-
super(`Beacon connection error: ${message}`);
|
|
4183
|
-
this.code = "CONNECTION_ERROR";
|
|
4184
|
-
}
|
|
4185
|
-
};
|
|
4186
|
-
var Beacon = class {
|
|
4187
|
-
constructor(iframe, options = {}) {
|
|
4188
|
-
this.messageHandlers = /* @__PURE__ */ new Map();
|
|
4189
|
-
this.isBeaconReady = false;
|
|
4190
|
-
this.readyPromise = null;
|
|
4191
|
-
this.isStarted = false;
|
|
4192
|
-
this.disposables = [];
|
|
4193
|
-
// MessagePort communication
|
|
4194
|
-
this.messageChannel = null;
|
|
4195
|
-
this.port = null;
|
|
4196
|
-
this.channelEstablished = false;
|
|
4197
|
-
ensureBrowserEnvironment();
|
|
4198
|
-
this.iframe = iframe;
|
|
4199
|
-
const defaultRetryOptions = {
|
|
4200
|
-
retries: 3,
|
|
4201
|
-
minTimeout: 1e3,
|
|
4202
|
-
maxTimeout: 5e3,
|
|
4203
|
-
factor: 2,
|
|
4204
|
-
randomize: true
|
|
4205
|
-
};
|
|
4206
|
-
this.options = {
|
|
4207
|
-
timeout: 1e4,
|
|
4208
|
-
targetOrigin: "*",
|
|
4209
|
-
debug: false,
|
|
4210
|
-
retry: {
|
|
4211
|
-
...defaultRetryOptions,
|
|
4212
|
-
...options.retry
|
|
4213
|
-
},
|
|
4214
|
-
...options
|
|
4215
|
-
};
|
|
4216
|
-
this.eventEmitter = EventManager.make();
|
|
4217
|
-
this.setupMessageChannel();
|
|
4218
|
-
this.navigator = new Navigator(
|
|
4219
|
-
this.eventEmitter.listen.bind(this.eventEmitter),
|
|
4220
|
-
this.eventEmitter.once.bind(this.eventEmitter),
|
|
4221
|
-
this
|
|
4222
|
-
);
|
|
4223
|
-
}
|
|
4224
|
-
/**
|
|
4225
|
-
* Setup communication channel using MessagePort
|
|
4226
|
-
*/
|
|
4227
|
-
setupMessageChannel() {
|
|
4228
|
-
const readyHandler = (event) => {
|
|
4229
|
-
try {
|
|
4230
|
-
if (event.source !== this.iframe.contentWindow) {
|
|
4231
|
-
return;
|
|
4232
|
-
}
|
|
4233
|
-
const message = event.data;
|
|
4234
|
-
if (!message || typeof message !== "object" || !message.type) {
|
|
4235
|
-
return;
|
|
4236
|
-
}
|
|
4237
|
-
if (message.type === "beacon:ready-for-channel") {
|
|
4238
|
-
this.establishChannel().catch((error51) => {
|
|
4239
|
-
if (this.options.debug) {
|
|
4240
|
-
console.error("[Beacon SDK] Channel establishment failed:", error51);
|
|
4241
|
-
}
|
|
4242
|
-
});
|
|
4243
|
-
}
|
|
4244
|
-
if (message.type === "beacon:channel-established") {
|
|
4245
|
-
this.channelEstablished = true;
|
|
4246
|
-
this.isBeaconReady = true;
|
|
4247
|
-
this.emit("ready", message.payload);
|
|
4248
|
-
if (this.options.debug) {
|
|
4249
|
-
console.log("[Beacon SDK] Channel established and beacon ready");
|
|
4250
|
-
}
|
|
4251
|
-
}
|
|
4252
|
-
} catch (error51) {
|
|
4253
|
-
if (this.options.debug) {
|
|
4254
|
-
console.error("[Beacon SDK] Message parsing error:", error51);
|
|
4255
|
-
}
|
|
4256
|
-
}
|
|
4257
|
-
};
|
|
4258
|
-
window.addEventListener("message", readyHandler);
|
|
4259
|
-
this.disposables.push({
|
|
4260
|
-
dispose: () => window.removeEventListener("message", readyHandler)
|
|
4261
|
-
});
|
|
4262
|
-
}
|
|
4263
|
-
/**
|
|
4264
|
-
* Establish MessagePort communication channel
|
|
4265
|
-
*/
|
|
4266
|
-
async establishChannel() {
|
|
4267
|
-
if (!this.iframe.contentWindow) {
|
|
4268
|
-
throw new BeaconConnectionError("Iframe contentWindow not available");
|
|
4269
|
-
}
|
|
4270
|
-
this.messageChannel = new MessageChannel();
|
|
4271
|
-
this.port = this.messageChannel.port1;
|
|
4272
|
-
this.port.onmessage = (event) => {
|
|
4273
|
-
this.handleBeaconMessage(event.data);
|
|
4274
|
-
};
|
|
4275
|
-
this.port.onmessageerror = (event) => {
|
|
4276
|
-
if (this.options.debug) {
|
|
4277
|
-
console.error("[Beacon SDK] Port message error:", event);
|
|
4278
|
-
}
|
|
4279
|
-
};
|
|
4280
|
-
this.port.start();
|
|
4281
|
-
const establishMessage = {
|
|
4282
|
-
type: "beacon:establish-channel",
|
|
4283
|
-
timestamp: Date.now(),
|
|
4284
|
-
id: this.generateId()
|
|
4285
|
-
};
|
|
4286
|
-
this.iframe.contentWindow.postMessage(
|
|
4287
|
-
establishMessage,
|
|
4288
|
-
"*",
|
|
4289
|
-
// Safe for channel establishment
|
|
4290
|
-
[this.messageChannel.port2]
|
|
4291
|
-
// Transfer the port
|
|
4292
|
-
);
|
|
4293
|
-
if (this.options.debug) {
|
|
4294
|
-
console.log("[Beacon SDK] Channel establishment message sent");
|
|
4295
|
-
}
|
|
4296
|
-
return new Promise((resolve, reject) => {
|
|
4297
|
-
const timeoutId = setTimeout(() => {
|
|
4298
|
-
reject(new BeaconConnectionError("Channel establishment timeout"));
|
|
4299
|
-
}, this.options.timeout);
|
|
4300
|
-
const checkReady = () => {
|
|
4301
|
-
if (this.channelEstablished && this.isBeaconReady) {
|
|
4302
|
-
clearTimeout(timeoutId);
|
|
4303
|
-
resolve();
|
|
4304
|
-
} else {
|
|
4305
|
-
setTimeout(checkReady, 100);
|
|
4306
|
-
}
|
|
4307
|
-
};
|
|
4308
|
-
checkReady();
|
|
4309
|
-
});
|
|
4310
|
-
}
|
|
4311
|
-
/**
|
|
4312
|
-
* Handle incoming beacon messages
|
|
4313
|
-
*/
|
|
4314
|
-
handleBeaconMessage(message) {
|
|
4315
|
-
if (this.options.debug) {
|
|
4316
|
-
console.log("[Beacon SDK] Received message:", message.type, message.payload);
|
|
4317
|
-
}
|
|
4318
|
-
const eventType = message.type.replace("beacon:", "");
|
|
4319
|
-
this.emit(eventType, message.payload);
|
|
4320
|
-
const handlers = this.messageHandlers.get(message.type);
|
|
4321
|
-
if (handlers) {
|
|
4322
|
-
handlers.forEach((handler) => {
|
|
4323
|
-
try {
|
|
4324
|
-
handler(message.payload);
|
|
4325
|
-
} catch (error51) {
|
|
4326
|
-
if (this.options.debug) {
|
|
4327
|
-
console.error("[Beacon SDK] Message handler error:", error51);
|
|
4328
|
-
}
|
|
4329
|
-
}
|
|
4330
|
-
});
|
|
4331
|
-
}
|
|
4332
|
-
}
|
|
4333
|
-
/**
|
|
4334
|
-
* Wait for beacon to be ready - simplified approach
|
|
4335
|
-
*/
|
|
4336
|
-
waitForBeaconReady() {
|
|
4337
|
-
return retry(
|
|
4338
|
-
async () => {
|
|
4339
|
-
return new Promise((resolve, reject) => {
|
|
4340
|
-
if (this.isBeaconReady && this.channelEstablished) {
|
|
4341
|
-
resolve();
|
|
4342
|
-
return;
|
|
4343
|
-
}
|
|
4344
|
-
const timeoutMs = this.options.timeout;
|
|
4345
|
-
const timeoutId = setTimeout(() => {
|
|
4346
|
-
reject(new BeaconTimeoutError("beacon ready", timeoutMs));
|
|
4347
|
-
}, timeoutMs);
|
|
4348
|
-
const unsubscribe = this.on("ready", () => {
|
|
4349
|
-
clearTimeout(timeoutId);
|
|
4350
|
-
unsubscribe.dispose();
|
|
4351
|
-
resolve();
|
|
4352
|
-
});
|
|
4353
|
-
});
|
|
4354
|
-
},
|
|
4355
|
-
{
|
|
4356
|
-
retries: this.options.retry?.retries ?? 3,
|
|
4357
|
-
minTimeout: this.options.retry?.minTimeout ?? 1e3,
|
|
4358
|
-
maxTimeout: this.options.retry?.maxTimeout ?? 5e3,
|
|
4359
|
-
factor: this.options.retry?.factor ?? 2,
|
|
4360
|
-
randomize: this.options.retry?.randomize ?? true,
|
|
4361
|
-
onRetry: (error51, attempt) => {
|
|
4362
|
-
if (this.options.debug) {
|
|
4363
|
-
const errorMessage = error51 instanceof Error ? error51.message : String(error51);
|
|
4364
|
-
console.warn(`[Beacon SDK] Beacon ready retry attempt ${attempt}:`, errorMessage);
|
|
4365
|
-
}
|
|
4366
|
-
this.isBeaconReady = false;
|
|
4367
|
-
this.channelEstablished = false;
|
|
4368
|
-
}
|
|
4369
|
-
}
|
|
4370
|
-
);
|
|
4371
|
-
}
|
|
4372
|
-
/**
|
|
4373
|
-
* Send a message to the beacon via MessagePort
|
|
4374
|
-
*/
|
|
4375
|
-
sendMessage(type, payload = {}) {
|
|
4376
|
-
if (!this.port) {
|
|
4377
|
-
throw new BeaconConnectionError("MessagePort not available - channel not established");
|
|
4378
|
-
}
|
|
4379
|
-
const message = {
|
|
4380
|
-
type: `beacon:${type}`,
|
|
4381
|
-
payload,
|
|
4382
|
-
timestamp: Date.now(),
|
|
4383
|
-
source: "parent",
|
|
4384
|
-
id: this.generateId()
|
|
4385
|
-
};
|
|
4386
|
-
try {
|
|
4387
|
-
this.port.postMessage(message);
|
|
4388
|
-
if (this.options.debug) {
|
|
4389
|
-
console.log("[Beacon SDK] Sent message via port:", message.type, message.payload);
|
|
4390
|
-
}
|
|
4391
|
-
} catch (error51) {
|
|
4392
|
-
throw new BeaconConnectionError(
|
|
4393
|
-
`Failed to send message via port: ${error51 instanceof Error ? error51.message : String(error51)}`
|
|
4394
|
-
);
|
|
4395
|
-
}
|
|
4396
|
-
}
|
|
4397
|
-
/**
|
|
4398
|
-
* Send a message and wait for a specific response with retry logic
|
|
4399
|
-
*/
|
|
4400
|
-
async sendAndWaitFor(sendType, responseType, payload = {}, timeoutMs) {
|
|
4401
|
-
await this.ready();
|
|
4402
|
-
return retry(
|
|
4403
|
-
async (bail) => {
|
|
4404
|
-
return new Promise((resolve, reject) => {
|
|
4405
|
-
const actualTimeout = timeoutMs || this.options.timeout;
|
|
4406
|
-
const timeoutId = setTimeout(() => {
|
|
4407
|
-
unsubscribe.dispose();
|
|
4408
|
-
const error51 = new BeaconTimeoutError(sendType, actualTimeout);
|
|
4409
|
-
reject(error51);
|
|
4410
|
-
}, actualTimeout);
|
|
4411
|
-
const unsubscribe = this.eventEmitter.listen(responseType, (data) => {
|
|
4412
|
-
clearTimeout(timeoutId);
|
|
4413
|
-
unsubscribe.dispose();
|
|
4414
|
-
resolve(data);
|
|
4415
|
-
});
|
|
4416
|
-
try {
|
|
4417
|
-
this.sendMessage(sendType, payload);
|
|
4418
|
-
} catch (error51) {
|
|
4419
|
-
clearTimeout(timeoutId);
|
|
4420
|
-
unsubscribe.dispose();
|
|
4421
|
-
if (error51 instanceof BeaconConnectionError) {
|
|
4422
|
-
reject(error51);
|
|
4423
|
-
} else {
|
|
4424
|
-
bail(error51);
|
|
4425
|
-
}
|
|
4426
|
-
}
|
|
4427
|
-
});
|
|
4428
|
-
},
|
|
4429
|
-
{
|
|
4430
|
-
retries: this.options.retry?.retries ?? 3,
|
|
4431
|
-
minTimeout: this.options.retry?.minTimeout ?? 1e3,
|
|
4432
|
-
maxTimeout: this.options.retry?.maxTimeout ?? 5e3,
|
|
4433
|
-
factor: this.options.retry?.factor ?? 2,
|
|
4434
|
-
randomize: this.options.retry?.randomize ?? true,
|
|
4435
|
-
onRetry: (error51, attempt) => {
|
|
4436
|
-
if (this.options.debug) {
|
|
4437
|
-
const errorMessage = error51 instanceof Error ? error51.message : String(error51);
|
|
4438
|
-
console.warn(`[Beacon SDK] Retry attempt ${attempt} for ${sendType}:`, errorMessage);
|
|
4439
|
-
}
|
|
4440
|
-
}
|
|
4441
|
-
}
|
|
4442
|
-
);
|
|
4443
|
-
}
|
|
4444
|
-
/**
|
|
4445
|
-
* Generate a unique ID for messages
|
|
4446
|
-
*/
|
|
4447
|
-
generateId() {
|
|
4448
|
-
return `sdk_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
4449
|
-
}
|
|
4450
|
-
/**
|
|
4451
|
-
* Event emitter methods (both private and public for navigator access)
|
|
4452
|
-
*/
|
|
4453
|
-
emit(event, payload) {
|
|
4454
|
-
this.eventEmitter.emit(event, payload);
|
|
4455
|
-
}
|
|
4456
|
-
/**
|
|
4457
|
-
* Start the beacon initialization process
|
|
4458
|
-
*/
|
|
4459
|
-
start() {
|
|
4460
|
-
if (this.isStarted) {
|
|
4461
|
-
return this.readyPromise || Promise.resolve();
|
|
4462
|
-
}
|
|
4463
|
-
this.isStarted = true;
|
|
4464
|
-
this.readyPromise = this.waitForBeaconReady();
|
|
4465
|
-
return this.readyPromise;
|
|
4466
|
-
}
|
|
4467
|
-
/**
|
|
4468
|
-
* Wait for the beacon to be ready
|
|
4469
|
-
*/
|
|
4470
|
-
async ready() {
|
|
4471
|
-
if (!this.isStarted) {
|
|
4472
|
-
throw new BeaconError("Beacon has not been started. Call start() first.");
|
|
4473
|
-
}
|
|
4474
|
-
if (!this.readyPromise) {
|
|
4475
|
-
throw new BeaconError("Beacon ready promise is not available");
|
|
4476
|
-
}
|
|
4477
|
-
return timeout(this.readyPromise, this.options.timeout);
|
|
4478
|
-
}
|
|
4479
|
-
/**
|
|
4480
|
-
* Check if beacon is ready
|
|
4481
|
-
*/
|
|
4482
|
-
get isReady() {
|
|
4483
|
-
return this.isBeaconReady;
|
|
4484
|
-
}
|
|
4485
|
-
/**
|
|
4486
|
-
* Listen for beacon events
|
|
4487
|
-
*/
|
|
4488
|
-
on(event, handler) {
|
|
4489
|
-
return this.eventEmitter.listen(event, handler);
|
|
4490
|
-
}
|
|
4491
|
-
/**
|
|
4492
|
-
* Listen for beacon events (one-time)
|
|
4493
|
-
*/
|
|
4494
|
-
once(event, handler) {
|
|
4495
|
-
return this.eventEmitter.once(event, handler);
|
|
4496
|
-
}
|
|
4497
|
-
/**
|
|
4498
|
-
* Ping the beacon to check if it's responsive
|
|
4499
|
-
*/
|
|
4500
|
-
async ping() {
|
|
4501
|
-
try {
|
|
4502
|
-
await this.sendAndWaitFor("ping", "pong", { timestamp: Date.now() });
|
|
4503
|
-
return true;
|
|
4504
|
-
} catch (error51) {
|
|
4505
|
-
if (this.options.debug) {
|
|
4506
|
-
console.warn("[Beacon SDK] Ping failed:", error51);
|
|
4507
|
-
}
|
|
4508
|
-
return false;
|
|
4509
|
-
}
|
|
4510
|
-
}
|
|
4511
|
-
/**
|
|
4512
|
-
* Get debug information from the beacon
|
|
4513
|
-
*/
|
|
4514
|
-
async getDebugInfo() {
|
|
4515
|
-
return this.sendAndWaitFor("getDebugInfo", "debugInfo");
|
|
4516
|
-
}
|
|
4517
|
-
/**
|
|
4518
|
-
* Get console events from the beacon
|
|
4519
|
-
*/
|
|
4520
|
-
async getConsoleEvents() {
|
|
4521
|
-
return this.sendAndWaitFor("getConsoleEvents", "consoleEvents");
|
|
4522
|
-
}
|
|
4523
|
-
/**
|
|
4524
|
-
* Get error events from the beacon
|
|
4525
|
-
*/
|
|
4526
|
-
async getErrorEvents() {
|
|
4527
|
-
return this.sendAndWaitFor("getErrorEvents", "errorEvents");
|
|
4528
|
-
}
|
|
4529
|
-
/**
|
|
4530
|
-
* Clear console events in the beacon
|
|
4531
|
-
*/
|
|
4532
|
-
async clearConsole() {
|
|
4533
|
-
await this.ready();
|
|
4534
|
-
this.sendMessage("clearConsole");
|
|
4535
|
-
}
|
|
4536
|
-
/**
|
|
4537
|
-
* Clear error events in the beacon
|
|
4538
|
-
*/
|
|
4539
|
-
async clearErrors() {
|
|
4540
|
-
await this.ready();
|
|
4541
|
-
this.sendMessage("clearErrors");
|
|
4542
|
-
}
|
|
4543
|
-
/**
|
|
4544
|
-
* Execute code in the beacon context
|
|
4545
|
-
*/
|
|
4546
|
-
async executeCode(code) {
|
|
4547
|
-
return this.sendAndWaitFor("executeCode", "codeExecutionResult", { code });
|
|
4548
|
-
}
|
|
4549
|
-
/**
|
|
4550
|
-
* Inspect an element in the beacon context
|
|
4551
|
-
*/
|
|
4552
|
-
async inspectElement(selector) {
|
|
4553
|
-
return this.sendAndWaitFor("inspectElement", "elementInspectionResult", { selector });
|
|
4554
|
-
}
|
|
4555
|
-
/**
|
|
4556
|
-
* Fetch a URL in the beacon context
|
|
4557
|
-
*/
|
|
4558
|
-
async fetch(request) {
|
|
4559
|
-
return this.sendAndWaitFor("fetch", "fetchResult", request);
|
|
4560
|
-
}
|
|
4561
|
-
/**
|
|
4562
|
-
* Capture the current beacon document, optionally clipped to a viewport or document rectangle.
|
|
4563
|
-
*/
|
|
4564
|
-
async captureScreenshot(request = {}) {
|
|
4565
|
-
const mediaTimeoutMs = request.mediaTimeoutMs ?? request.timeout ?? 3e4;
|
|
4566
|
-
const timeoutMs = request.transportTimeoutMs ?? mediaTimeoutMs + 5e3;
|
|
4567
|
-
return this.sendAndWaitFor("captureScreenshot", "screenshotResult", request, timeoutMs);
|
|
4568
|
-
}
|
|
4569
|
-
/**
|
|
4570
|
-
* Debug a page (navigate and capture debug information). It loads
|
|
4571
|
-
* the page fresh in the IFRAME so that we can capture the latest state.
|
|
4572
|
-
*/
|
|
4573
|
-
async debug(request, waitSeconds) {
|
|
4574
|
-
const targetUrl = new URL(request.path, this.iframe.src || window.location.origin).href;
|
|
4575
|
-
if (this.iframe.src !== targetUrl) {
|
|
4576
|
-
this.navigator.visit(targetUrl);
|
|
4577
|
-
await this.ready();
|
|
4578
|
-
}
|
|
4579
|
-
waitSeconds && await this.wait(waitSeconds);
|
|
4580
|
-
const timeoutMs = (request.options?.timeout || 3e4) + 5e3;
|
|
4581
|
-
return this.sendAndWaitFor("debug", "debugResult", request, timeoutMs);
|
|
4582
|
-
}
|
|
4583
|
-
async wait(forSeconds) {
|
|
4584
|
-
return new Promise((resolve) => setTimeout(resolve, forSeconds * 1e3));
|
|
4585
|
-
}
|
|
4586
|
-
/**
|
|
4587
|
-
* Navigate the iframe to a new URL
|
|
4588
|
-
*/
|
|
4589
|
-
navigate(url2) {
|
|
4590
|
-
if (!this.iframe) {
|
|
4591
|
-
throw new BeaconConnectionError("Iframe not available");
|
|
4592
|
-
}
|
|
4593
|
-
try {
|
|
4594
|
-
const targetUrl = new URL(url2, this.iframe.src || window.location.origin);
|
|
4595
|
-
this.iframe.src = targetUrl.href;
|
|
4596
|
-
this.isBeaconReady = false;
|
|
4597
|
-
this.channelEstablished = false;
|
|
4598
|
-
if (this.port) {
|
|
4599
|
-
this.port.close();
|
|
4600
|
-
this.port = null;
|
|
4601
|
-
}
|
|
4602
|
-
if (this.messageChannel) {
|
|
4603
|
-
this.messageChannel = null;
|
|
4604
|
-
}
|
|
4605
|
-
if (this.isStarted) {
|
|
4606
|
-
this.readyPromise = this.waitForBeaconReady();
|
|
4607
|
-
}
|
|
4608
|
-
} catch (error51) {
|
|
4609
|
-
throw new BeaconConnectionError(`Invalid URL: ${url2}`);
|
|
4610
|
-
}
|
|
4611
|
-
}
|
|
4612
|
-
/**
|
|
4613
|
-
* Get current iframe URL
|
|
4614
|
-
*/
|
|
4615
|
-
get url() {
|
|
4616
|
-
return this.iframe.src;
|
|
4617
|
-
}
|
|
4618
|
-
/**
|
|
4619
|
-
* Get the iframe element
|
|
4620
|
-
*/
|
|
4621
|
-
get element() {
|
|
4622
|
-
return this.iframe;
|
|
4623
|
-
}
|
|
4624
|
-
/**
|
|
4625
|
-
* Dispose of all resources
|
|
4626
|
-
*/
|
|
4627
|
-
dispose() {
|
|
4628
|
-
if (this.port) {
|
|
4629
|
-
this.port.close();
|
|
4630
|
-
this.port = null;
|
|
4631
|
-
}
|
|
4632
|
-
if (this.messageChannel) {
|
|
4633
|
-
this.messageChannel = null;
|
|
4634
|
-
}
|
|
4635
|
-
this.disposables.forEach((disposable) => disposable.dispose());
|
|
4636
|
-
this.disposables = [];
|
|
4637
|
-
this.messageHandlers.clear();
|
|
4638
|
-
this.isBeaconReady = false;
|
|
4639
|
-
this.channelEstablished = false;
|
|
4640
|
-
this.isStarted = false;
|
|
4641
|
-
this.readyPromise = null;
|
|
4642
|
-
}
|
|
4643
|
-
};
|
|
4644
|
-
function createBeacon(iframe, options) {
|
|
4645
|
-
return new Beacon(iframe, options);
|
|
4646
|
-
}
|
|
4647
|
-
function isBeaconSupported() {
|
|
4648
|
-
try {
|
|
4649
|
-
ensureBrowserEnvironment();
|
|
4650
|
-
return true;
|
|
4651
|
-
} catch {
|
|
4652
|
-
return false;
|
|
4653
|
-
}
|
|
4654
|
-
}
|
|
4655
|
-
|
|
4656
3969
|
// node_modules/zod/v4/classic/external.js
|
|
4657
3970
|
var external_exports = {};
|
|
4658
3971
|
__export(external_exports, {
|
|
@@ -19167,13 +18480,13 @@ function date4(params) {
|
|
|
19167
18480
|
// node_modules/zod/v4/classic/external.js
|
|
19168
18481
|
config(en_default());
|
|
19169
18482
|
|
|
19170
|
-
// src/schemas/
|
|
19171
|
-
var
|
|
19172
|
-
"
|
|
19173
|
-
"
|
|
19174
|
-
"
|
|
18483
|
+
// src/schemas/publications.ts
|
|
18484
|
+
var PublicationProviderNameSchema = external_exports.enum([
|
|
18485
|
+
"cloudflare-containers",
|
|
18486
|
+
"ssh-server",
|
|
18487
|
+
"laravel-cloud"
|
|
19175
18488
|
]);
|
|
19176
|
-
var
|
|
18489
|
+
var PublicationStatusSchema = external_exports.enum([
|
|
19177
18490
|
"pending",
|
|
19178
18491
|
"queued",
|
|
19179
18492
|
"building",
|
|
@@ -19185,7 +18498,7 @@ var DeploymentStatusSchema = external_exports.enum([
|
|
|
19185
18498
|
"deleted",
|
|
19186
18499
|
"delete_failed"
|
|
19187
18500
|
]);
|
|
19188
|
-
var
|
|
18501
|
+
var PublicationBuildStatusSchema = external_exports.enum([
|
|
19189
18502
|
"pending",
|
|
19190
18503
|
"queued",
|
|
19191
18504
|
"running",
|
|
@@ -19193,8 +18506,8 @@ var DeploymentBuildStatusSchema = external_exports.enum([
|
|
|
19193
18506
|
"failed",
|
|
19194
18507
|
"cancelled"
|
|
19195
18508
|
]);
|
|
19196
|
-
var
|
|
19197
|
-
var
|
|
18509
|
+
var PublicationReleaseStatusSchema = external_exports.enum(["created", "ready", "deleted"]);
|
|
18510
|
+
var PublicationSizeSchema = external_exports.enum([
|
|
19198
18511
|
"nano",
|
|
19199
18512
|
"small",
|
|
19200
18513
|
"medium",
|
|
@@ -19204,7 +18517,7 @@ var DeploymentSizeSchema = external_exports.enum([
|
|
|
19204
18517
|
"standard-1",
|
|
19205
18518
|
"standard-2"
|
|
19206
18519
|
]);
|
|
19207
|
-
var
|
|
18520
|
+
var PublicationRegionSchema = external_exports.enum([
|
|
19208
18521
|
"ENAM",
|
|
19209
18522
|
"WNAM",
|
|
19210
18523
|
"EEUR",
|
|
@@ -19215,103 +18528,103 @@ var DeploymentRegionSchema = external_exports.enum([
|
|
|
19215
18528
|
"OC",
|
|
19216
18529
|
"AFR"
|
|
19217
18530
|
]);
|
|
19218
|
-
var
|
|
19219
|
-
var
|
|
19220
|
-
var
|
|
19221
|
-
var
|
|
19222
|
-
var
|
|
19223
|
-
var
|
|
18531
|
+
var PublicationJurisdictionSchema = external_exports.enum(["eu", "fedramp"]);
|
|
18532
|
+
var PublicationDomainDnsRecordTypeSchema = external_exports.enum(["CNAME", "ALIAS", "ANAME"]);
|
|
18533
|
+
var PublicationProtectionModeSchema = external_exports.enum(["none", "password"]);
|
|
18534
|
+
var PublicationLogStreamSchema = external_exports.enum(["build", "runtime"]);
|
|
18535
|
+
var PublishStreamLogStreamSchema = external_exports.enum(["build", "publish", "runtime"]);
|
|
18536
|
+
var PublicationEventDataSchema = external_exports.object({
|
|
19224
18537
|
id: external_exports.union([external_exports.number(), external_exports.string()]).optional(),
|
|
19225
18538
|
sequence: external_exports.number(),
|
|
19226
18539
|
type: external_exports.string(),
|
|
19227
18540
|
payload: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
19228
18541
|
createdAt: external_exports.string().nullable()
|
|
19229
18542
|
}).passthrough();
|
|
19230
|
-
var
|
|
18543
|
+
var PublicationLogChunkDataSchema = external_exports.object({
|
|
19231
18544
|
sequence: external_exports.number(),
|
|
19232
|
-
stream:
|
|
18545
|
+
stream: PublicationLogStreamSchema,
|
|
19233
18546
|
content: external_exports.string(),
|
|
19234
18547
|
createdAt: external_exports.string().nullable()
|
|
19235
18548
|
}).passthrough();
|
|
19236
|
-
var
|
|
18549
|
+
var PublishStreamPhaseSchema = external_exports.object({
|
|
19237
18550
|
name: external_exports.string(),
|
|
19238
18551
|
status: external_exports.enum(["running", "completed", "failed"]).optional(),
|
|
19239
18552
|
data: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
19240
18553
|
}).strict();
|
|
19241
|
-
var
|
|
19242
|
-
stream:
|
|
18554
|
+
var PublishStreamLogSchema = external_exports.object({
|
|
18555
|
+
stream: PublishStreamLogStreamSchema,
|
|
19243
18556
|
content: external_exports.string()
|
|
19244
18557
|
}).strict();
|
|
19245
|
-
var
|
|
18558
|
+
var PublishStreamResultSchema = external_exports.object({
|
|
19246
18559
|
success: external_exports.boolean(),
|
|
19247
|
-
|
|
18560
|
+
publicationId: external_exports.string(),
|
|
19248
18561
|
buildId: external_exports.string(),
|
|
19249
18562
|
releaseId: external_exports.string(),
|
|
19250
|
-
status:
|
|
18563
|
+
status: PublicationStatusSchema
|
|
19251
18564
|
}).strict();
|
|
19252
|
-
var
|
|
18565
|
+
var PublishStreamPhaseEventSchema = PublishStreamPhaseSchema.extend({
|
|
19253
18566
|
type: external_exports.literal("phase")
|
|
19254
18567
|
}).strict();
|
|
19255
|
-
var
|
|
18568
|
+
var PublishStreamLogEventSchema = PublishStreamLogSchema.extend({
|
|
19256
18569
|
type: external_exports.literal("log")
|
|
19257
18570
|
}).strict();
|
|
19258
|
-
var
|
|
18571
|
+
var PublishStreamResultEventSchema = PublishStreamResultSchema.extend({
|
|
19259
18572
|
type: external_exports.literal("result")
|
|
19260
18573
|
}).strict();
|
|
19261
|
-
var
|
|
19262
|
-
|
|
19263
|
-
|
|
19264
|
-
|
|
18574
|
+
var PublishStreamEventSchema = external_exports.discriminatedUnion("type", [
|
|
18575
|
+
PublishStreamPhaseEventSchema,
|
|
18576
|
+
PublishStreamLogEventSchema,
|
|
18577
|
+
PublishStreamResultEventSchema
|
|
19265
18578
|
]);
|
|
19266
|
-
var
|
|
18579
|
+
var PublishStreamErrorSchema = external_exports.object({
|
|
19267
18580
|
message: external_exports.string().optional()
|
|
19268
18581
|
}).passthrough();
|
|
19269
|
-
var
|
|
19270
|
-
var
|
|
18582
|
+
var PublishStreamSseEventNameSchema = external_exports.enum(["phase", "log", "done", "result", "error"]);
|
|
18583
|
+
var PublishStreamSsePhaseEventSchema = external_exports.object({
|
|
19271
18584
|
event: external_exports.literal("phase"),
|
|
19272
|
-
data:
|
|
18585
|
+
data: PublishStreamPhaseSchema
|
|
19273
18586
|
}).strict();
|
|
19274
|
-
var
|
|
18587
|
+
var PublishStreamSseLogEventSchema = external_exports.object({
|
|
19275
18588
|
event: external_exports.literal("log"),
|
|
19276
|
-
data:
|
|
18589
|
+
data: PublishStreamLogSchema
|
|
19277
18590
|
}).strict();
|
|
19278
|
-
var
|
|
18591
|
+
var PublishStreamSseDoneEventSchema = external_exports.object({
|
|
19279
18592
|
event: external_exports.literal("done"),
|
|
19280
|
-
data:
|
|
18593
|
+
data: PublishStreamResultSchema
|
|
19281
18594
|
}).strict();
|
|
19282
|
-
var
|
|
18595
|
+
var PublishStreamSseResultEventSchema = external_exports.object({
|
|
19283
18596
|
event: external_exports.literal("result"),
|
|
19284
|
-
data:
|
|
18597
|
+
data: PublishStreamResultSchema
|
|
19285
18598
|
}).strict();
|
|
19286
|
-
var
|
|
18599
|
+
var PublishStreamSseErrorEventSchema = external_exports.object({
|
|
19287
18600
|
event: external_exports.literal("error"),
|
|
19288
|
-
data:
|
|
18601
|
+
data: PublishStreamErrorSchema
|
|
19289
18602
|
}).strict();
|
|
19290
|
-
var
|
|
19291
|
-
|
|
19292
|
-
|
|
19293
|
-
|
|
19294
|
-
|
|
19295
|
-
|
|
18603
|
+
var PublishStreamSseEventSchema = external_exports.discriminatedUnion("event", [
|
|
18604
|
+
PublishStreamSsePhaseEventSchema,
|
|
18605
|
+
PublishStreamSseLogEventSchema,
|
|
18606
|
+
PublishStreamSseDoneEventSchema,
|
|
18607
|
+
PublishStreamSseResultEventSchema,
|
|
18608
|
+
PublishStreamSseErrorEventSchema
|
|
19296
18609
|
]).transform((event) => {
|
|
19297
18610
|
if (event.event === "error") {
|
|
19298
|
-
throw new Error(event.data.message ?? "
|
|
18611
|
+
throw new Error(event.data.message ?? "Publish failed");
|
|
19299
18612
|
}
|
|
19300
18613
|
const type = event.event === "done" ? "result" : event.event;
|
|
19301
|
-
return
|
|
18614
|
+
return PublishStreamEventSchema.parse({ type, ...event.data });
|
|
19302
18615
|
});
|
|
19303
18616
|
|
|
19304
|
-
// src/
|
|
19305
|
-
var
|
|
18617
|
+
// src/publications.ts
|
|
18618
|
+
var NotebookPublicationApi = class {
|
|
19306
18619
|
constructor(client) {
|
|
19307
18620
|
this.client = client;
|
|
19308
18621
|
}
|
|
19309
18622
|
async current(notebookId) {
|
|
19310
18623
|
try {
|
|
19311
18624
|
const response = await this.client.get(
|
|
19312
|
-
`/notebook/${notebookId}/
|
|
18625
|
+
`/notebook/${notebookId}/publication`
|
|
19313
18626
|
);
|
|
19314
|
-
return new
|
|
18627
|
+
return new PublicationInstance(response.data, this.client, notebookId);
|
|
19315
18628
|
} catch (error51) {
|
|
19316
18629
|
if (error51 instanceof ApiError && error51.status === 404) {
|
|
19317
18630
|
return null;
|
|
@@ -19321,89 +18634,82 @@ var NotebookDeploymentApi = class {
|
|
|
19321
18634
|
}
|
|
19322
18635
|
async publish(notebookId, input) {
|
|
19323
18636
|
const response = await this.client.post(
|
|
19324
|
-
`/notebook/${notebookId}/
|
|
18637
|
+
`/notebook/${notebookId}/publication`,
|
|
19325
18638
|
input
|
|
19326
18639
|
);
|
|
19327
|
-
const run = new
|
|
18640
|
+
const run = new PublicationRun(new PublicationInstance(response.data, this.client, notebookId), this.client);
|
|
19328
18641
|
run.start();
|
|
19329
18642
|
return run;
|
|
19330
18643
|
}
|
|
19331
|
-
async slugAvailability(id, slug) {
|
|
19332
|
-
const query = new URLSearchParams({ slug }).toString();
|
|
19333
|
-
const response = await this.client.get(
|
|
19334
|
-
`/notebook/${id}/deployment/slug-availability?${query}`
|
|
19335
|
-
);
|
|
19336
|
-
return response.data;
|
|
19337
|
-
}
|
|
19338
18644
|
};
|
|
19339
|
-
var
|
|
18645
|
+
var PublicationApi = class {
|
|
19340
18646
|
constructor(client) {
|
|
19341
18647
|
this.client = client;
|
|
19342
18648
|
}
|
|
19343
18649
|
async get(id) {
|
|
19344
|
-
const response = await this.client.get(`/
|
|
19345
|
-
return new
|
|
18650
|
+
const response = await this.client.get(`/publications/${id}`);
|
|
18651
|
+
return new PublicationInstance(response.data, this.client);
|
|
19346
18652
|
}
|
|
19347
|
-
async
|
|
19348
|
-
await this.client.delete(`/
|
|
18653
|
+
async destroy(id) {
|
|
18654
|
+
await this.client.delete(`/publications/${id}`);
|
|
19349
18655
|
}
|
|
19350
18656
|
async setProtection(id, input) {
|
|
19351
|
-
const response = await this.client.put(`/
|
|
19352
|
-
return new
|
|
18657
|
+
const response = await this.client.put(`/publications/${id}/protection`, input);
|
|
18658
|
+
return new PublicationInstance(response.data, this.client);
|
|
19353
18659
|
}
|
|
19354
18660
|
async protection(id) {
|
|
19355
|
-
const response = await this.client.get(`/
|
|
18661
|
+
const response = await this.client.get(`/publications/${id}/protection`);
|
|
19356
18662
|
return response.data;
|
|
19357
18663
|
}
|
|
19358
18664
|
async createProtectionSession(id) {
|
|
19359
|
-
const response = await this.client.post(`/
|
|
18665
|
+
const response = await this.client.post(`/publications/${id}/protection/session`);
|
|
19360
18666
|
return response.data;
|
|
19361
18667
|
}
|
|
19362
18668
|
async disableProtection(id) {
|
|
19363
|
-
const response = await this.client.delete(`/
|
|
19364
|
-
return new
|
|
18669
|
+
const response = await this.client.delete(`/publications/${id}/protection`);
|
|
18670
|
+
return new PublicationInstance(response.data, this.client);
|
|
19365
18671
|
}
|
|
19366
18672
|
async setFeedback(id, input) {
|
|
19367
|
-
const response = await this.client.put(`/
|
|
19368
|
-
return new
|
|
18673
|
+
const response = await this.client.put(`/publications/${id}/feedback`, input);
|
|
18674
|
+
return new PublicationInstance(response.data, this.client);
|
|
19369
18675
|
}
|
|
19370
18676
|
async listDomains(id) {
|
|
19371
18677
|
const response = await this.client.get(
|
|
19372
|
-
`/
|
|
18678
|
+
`/publications/${id}/domains`
|
|
19373
18679
|
);
|
|
19374
|
-
return
|
|
18680
|
+
return unwrapPublicationDomainCollection(response.data);
|
|
19375
18681
|
}
|
|
19376
18682
|
async createDomain(id, input) {
|
|
19377
|
-
const response = await this.client.post(`/
|
|
18683
|
+
const response = await this.client.post(`/publications/${id}/domains`, input);
|
|
19378
18684
|
return response.data;
|
|
19379
18685
|
}
|
|
19380
18686
|
async refreshDomain(id, domainId) {
|
|
19381
|
-
const response = await this.client.post(`/
|
|
18687
|
+
const response = await this.client.post(`/publications/${id}/domains/${domainId}/refresh`);
|
|
19382
18688
|
return response.data;
|
|
19383
18689
|
}
|
|
19384
18690
|
async deleteDomain(id, domainId) {
|
|
19385
|
-
await this.client.delete(`/
|
|
18691
|
+
await this.client.delete(`/publications/${id}/domains/${domainId}`);
|
|
19386
18692
|
}
|
|
19387
18693
|
async events(id) {
|
|
19388
18694
|
return parseNdjsonStream(
|
|
19389
|
-
await this.client.stream(`/
|
|
19390
|
-
|
|
18695
|
+
await this.client.stream(`/publications/${id}/events/stream`),
|
|
18696
|
+
PublicationEventDataSchema
|
|
19391
18697
|
);
|
|
19392
18698
|
}
|
|
19393
18699
|
async buildLogs(id, buildId) {
|
|
19394
18700
|
return parseNdjsonStream(
|
|
19395
|
-
await this.client.stream(`/
|
|
19396
|
-
|
|
18701
|
+
await this.client.stream(`/publications/${id}/builds/${buildId}/logs/stream`),
|
|
18702
|
+
PublicationLogChunkDataSchema
|
|
19397
18703
|
);
|
|
19398
18704
|
}
|
|
19399
18705
|
async logs(id) {
|
|
19400
18706
|
return parseNdjsonStream(
|
|
19401
|
-
await this.client.stream(`/
|
|
19402
|
-
|
|
18707
|
+
await this.client.stream(`/publications/${id}/logs/stream`),
|
|
18708
|
+
PublicationLogChunkDataSchema
|
|
19403
18709
|
);
|
|
19404
18710
|
}
|
|
19405
18711
|
};
|
|
19406
|
-
var
|
|
18712
|
+
var PublicationRun = class {
|
|
19407
18713
|
constructor(initial, client) {
|
|
19408
18714
|
this.initial = initial;
|
|
19409
18715
|
this.client = client;
|
|
@@ -19433,7 +18739,7 @@ var DeploymentRun = class {
|
|
|
19433
18739
|
this.start();
|
|
19434
18740
|
return this.resultPromise;
|
|
19435
18741
|
}
|
|
19436
|
-
async
|
|
18742
|
+
async publication() {
|
|
19437
18743
|
await this.result();
|
|
19438
18744
|
return this.initial.refresh();
|
|
19439
18745
|
}
|
|
@@ -19443,7 +18749,7 @@ var DeploymentRun = class {
|
|
|
19443
18749
|
}
|
|
19444
18750
|
const eventStreamUrl = this.initial.data.eventStreamUrl;
|
|
19445
18751
|
if (!eventStreamUrl) {
|
|
19446
|
-
throw new Error(`
|
|
18752
|
+
throw new Error(`Publication ${this.initial.data.id} has no eventStreamUrl for SSE streaming`);
|
|
19447
18753
|
}
|
|
19448
18754
|
this.started = true;
|
|
19449
18755
|
this.resultPromise = new Promise((resolve, reject) => {
|
|
@@ -19455,7 +18761,7 @@ var DeploymentRun = class {
|
|
|
19455
18761
|
return this;
|
|
19456
18762
|
}
|
|
19457
18763
|
subscribe() {
|
|
19458
|
-
const queue = new
|
|
18764
|
+
const queue = new AsyncPublishEventQueue();
|
|
19459
18765
|
for (const event of this.bufferedEvents) {
|
|
19460
18766
|
queue.push(event);
|
|
19461
18767
|
}
|
|
@@ -19471,7 +18777,7 @@ var DeploymentRun = class {
|
|
|
19471
18777
|
async consumeStream(eventStreamUrl) {
|
|
19472
18778
|
try {
|
|
19473
18779
|
const stream = await this.client.sse(eventStreamUrl);
|
|
19474
|
-
for await (const event of
|
|
18780
|
+
for await (const event of readPublishStreamEvents(stream)) {
|
|
19475
18781
|
this.publish(event);
|
|
19476
18782
|
if (event.type === "result") {
|
|
19477
18783
|
const { type: _, ...result } = event;
|
|
@@ -19480,7 +18786,7 @@ var DeploymentRun = class {
|
|
|
19480
18786
|
}
|
|
19481
18787
|
}
|
|
19482
18788
|
if (!this.finalResult) {
|
|
19483
|
-
throw new Error("
|
|
18789
|
+
throw new Error("Publish stream ended without result");
|
|
19484
18790
|
}
|
|
19485
18791
|
this.closeSubscribers();
|
|
19486
18792
|
} catch (err) {
|
|
@@ -19510,33 +18816,33 @@ var DeploymentRun = class {
|
|
|
19510
18816
|
this.subscribers.clear();
|
|
19511
18817
|
}
|
|
19512
18818
|
};
|
|
19513
|
-
var
|
|
18819
|
+
var PublicationInstance = class _PublicationInstance {
|
|
19514
18820
|
constructor(data, client, notebookId) {
|
|
19515
18821
|
this.data = data;
|
|
19516
18822
|
this.client = client;
|
|
19517
18823
|
this.notebookId = notebookId;
|
|
19518
18824
|
}
|
|
19519
18825
|
async refresh() {
|
|
19520
|
-
const response = await this.client.get(`/
|
|
19521
|
-
return new
|
|
18826
|
+
const response = await this.client.get(`/publications/${this.data.id}`);
|
|
18827
|
+
return new _PublicationInstance(response.data, this.client, this.notebookId);
|
|
19522
18828
|
}
|
|
19523
18829
|
publish() {
|
|
19524
18830
|
if (!this.notebookId) {
|
|
19525
|
-
return Promise.reject(new Error("
|
|
18831
|
+
return Promise.reject(new Error("Publishing requires a notebook-scoped publication instance."));
|
|
19526
18832
|
}
|
|
19527
|
-
return this.client.notebook.
|
|
18833
|
+
return this.client.notebook.publication.publish(this.notebookId);
|
|
19528
18834
|
}
|
|
19529
|
-
|
|
19530
|
-
return this.client.
|
|
18835
|
+
destroy() {
|
|
18836
|
+
return this.client.publications.destroy(this.data.id);
|
|
19531
18837
|
}
|
|
19532
18838
|
async wait(options = {}) {
|
|
19533
18839
|
const intervalMs = options.intervalMs ?? 1e3;
|
|
19534
18840
|
const timeoutMs = options.timeoutMs ?? 3e5;
|
|
19535
18841
|
const startedAt = Date.now();
|
|
19536
18842
|
let current = this;
|
|
19537
|
-
while (!
|
|
18843
|
+
while (!publicationStatusIsTerminal(current.data.status)) {
|
|
19538
18844
|
if (Date.now() - startedAt > timeoutMs) {
|
|
19539
|
-
throw new Error(`Timed out waiting for
|
|
18845
|
+
throw new Error(`Timed out waiting for publication ${this.data.id}`);
|
|
19540
18846
|
}
|
|
19541
18847
|
await delay(intervalMs);
|
|
19542
18848
|
current = await current.refresh();
|
|
@@ -19544,58 +18850,58 @@ var DeploymentInstance = class _DeploymentInstance {
|
|
|
19544
18850
|
return current;
|
|
19545
18851
|
}
|
|
19546
18852
|
events() {
|
|
19547
|
-
return this.client.
|
|
18853
|
+
return this.client.publications.events(this.data.id);
|
|
19548
18854
|
}
|
|
19549
18855
|
buildLogs(buildId = this.data.latestBuild?.id ?? "") {
|
|
19550
18856
|
if (buildId === "") {
|
|
19551
|
-
return Promise.reject(new Error("
|
|
18857
|
+
return Promise.reject(new Error("Publication has no latest build id"));
|
|
19552
18858
|
}
|
|
19553
|
-
return this.client.
|
|
18859
|
+
return this.client.publications.buildLogs(this.data.id, buildId);
|
|
19554
18860
|
}
|
|
19555
18861
|
logs() {
|
|
19556
|
-
return this.client.
|
|
18862
|
+
return this.client.publications.logs(this.data.id);
|
|
19557
18863
|
}
|
|
19558
18864
|
setProtection(input) {
|
|
19559
|
-
return this.client.
|
|
18865
|
+
return this.client.publications.setProtection(this.data.id, input);
|
|
19560
18866
|
}
|
|
19561
18867
|
protection() {
|
|
19562
|
-
return this.client.
|
|
18868
|
+
return this.client.publications.protection(this.data.id);
|
|
19563
18869
|
}
|
|
19564
18870
|
createProtectionSession() {
|
|
19565
|
-
return this.client.
|
|
18871
|
+
return this.client.publications.createProtectionSession(this.data.id);
|
|
19566
18872
|
}
|
|
19567
18873
|
disableProtection() {
|
|
19568
|
-
return this.client.
|
|
18874
|
+
return this.client.publications.disableProtection(this.data.id);
|
|
19569
18875
|
}
|
|
19570
18876
|
setFeedback(input) {
|
|
19571
|
-
return this.client.
|
|
18877
|
+
return this.client.publications.setFeedback(this.data.id, input);
|
|
19572
18878
|
}
|
|
19573
18879
|
domains() {
|
|
19574
|
-
return this.client.
|
|
18880
|
+
return this.client.publications.listDomains(this.data.id);
|
|
19575
18881
|
}
|
|
19576
18882
|
addDomain(input) {
|
|
19577
|
-
return this.client.
|
|
18883
|
+
return this.client.publications.createDomain(this.data.id, input);
|
|
19578
18884
|
}
|
|
19579
18885
|
refreshDomain(domainId) {
|
|
19580
|
-
return this.client.
|
|
18886
|
+
return this.client.publications.refreshDomain(this.data.id, domainId);
|
|
19581
18887
|
}
|
|
19582
18888
|
deleteDomain(domainId) {
|
|
19583
|
-
return this.client.
|
|
18889
|
+
return this.client.publications.deleteDomain(this.data.id, domainId);
|
|
19584
18890
|
}
|
|
19585
18891
|
};
|
|
19586
|
-
function
|
|
18892
|
+
function publicationStatusIsTerminal(status) {
|
|
19587
18893
|
return ["healthy", "failed", "stopped", "deleted", "delete_failed"].includes(status);
|
|
19588
18894
|
}
|
|
19589
18895
|
function delay(ms) {
|
|
19590
18896
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19591
18897
|
}
|
|
19592
|
-
function
|
|
18898
|
+
function unwrapPublicationDomainCollection(input) {
|
|
19593
18899
|
if (Array.isArray(input)) {
|
|
19594
18900
|
return input;
|
|
19595
18901
|
}
|
|
19596
18902
|
return Array.isArray(input.data) ? input.data : [];
|
|
19597
18903
|
}
|
|
19598
|
-
var
|
|
18904
|
+
var AsyncPublishEventQueue = class {
|
|
19599
18905
|
constructor() {
|
|
19600
18906
|
this.values = [];
|
|
19601
18907
|
this.pending = [];
|
|
@@ -19657,7 +18963,7 @@ var AsyncDeployEventQueue = class {
|
|
|
19657
18963
|
});
|
|
19658
18964
|
}
|
|
19659
18965
|
};
|
|
19660
|
-
async function*
|
|
18966
|
+
async function* readPublishStreamEvents(stream) {
|
|
19661
18967
|
const reader = parseSSEStream(stream).getReader();
|
|
19662
18968
|
try {
|
|
19663
18969
|
while (true) {
|
|
@@ -19665,7 +18971,7 @@ async function* readDeployStreamEvents(stream) {
|
|
|
19665
18971
|
if (done) {
|
|
19666
18972
|
return;
|
|
19667
18973
|
}
|
|
19668
|
-
const event =
|
|
18974
|
+
const event = parsePublishStreamEvent(value);
|
|
19669
18975
|
if (event) {
|
|
19670
18976
|
yield event;
|
|
19671
18977
|
}
|
|
@@ -19674,11 +18980,11 @@ async function* readDeployStreamEvents(stream) {
|
|
|
19674
18980
|
reader.releaseLock();
|
|
19675
18981
|
}
|
|
19676
18982
|
}
|
|
19677
|
-
function
|
|
19678
|
-
if (!
|
|
18983
|
+
function parsePublishStreamEvent(event) {
|
|
18984
|
+
if (!PublishStreamSseEventNameSchema.safeParse(event.event).success) {
|
|
19679
18985
|
return null;
|
|
19680
18986
|
}
|
|
19681
|
-
return
|
|
18987
|
+
return PublishStreamSseEventSchema.parse(event);
|
|
19682
18988
|
}
|
|
19683
18989
|
function parseSSEStream(input) {
|
|
19684
18990
|
const decoder = new TextDecoder();
|
|
@@ -20087,7 +19393,7 @@ var NotebookApi = class {
|
|
|
20087
19393
|
this.composerCredentials = new NotebookComposerCredentialApi(client);
|
|
20088
19394
|
this.preview = new NotebookPreviewApi(client);
|
|
20089
19395
|
this.mail = new NotebookMailApi(client);
|
|
20090
|
-
this.
|
|
19396
|
+
this.publication = new NotebookPublicationApi(client);
|
|
20091
19397
|
}
|
|
20092
19398
|
async create(template, input = {}, init = true) {
|
|
20093
19399
|
const response = await this.client.post("/notebook", { template, ...input });
|
|
@@ -20105,7 +19411,7 @@ var NotebookApi = class {
|
|
|
20105
19411
|
const response = await this.client.put(`/notebook/${id}`, input);
|
|
20106
19412
|
return new NotebookInstance2(response.data, this.client);
|
|
20107
19413
|
}
|
|
20108
|
-
async
|
|
19414
|
+
async destroy(id) {
|
|
20109
19415
|
await this.client.delete(`/notebook/${id}`);
|
|
20110
19416
|
}
|
|
20111
19417
|
async fork(id, input = {}) {
|
|
@@ -20116,10 +19422,6 @@ var NotebookApi = class {
|
|
|
20116
19422
|
const response = await this.client.post(`/notebook/${id}/git/credentials`);
|
|
20117
19423
|
return response.data;
|
|
20118
19424
|
}
|
|
20119
|
-
async open(id) {
|
|
20120
|
-
const response = await this.client.get(`/notebook/${id}`);
|
|
20121
|
-
return new NotebookInstance2(response.data, this.client);
|
|
20122
|
-
}
|
|
20123
19425
|
openFromData(data) {
|
|
20124
19426
|
return this.init(new NotebookInstance2(data, this.client));
|
|
20125
19427
|
}
|
|
@@ -20140,7 +19442,7 @@ var Client2 = class {
|
|
|
20140
19442
|
constructor(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
|
|
20141
19443
|
this.runtimeTransportValue = "realtime";
|
|
20142
19444
|
this.fetch = globalThis.fetch;
|
|
20143
|
-
this.
|
|
19445
|
+
this.publications = new PublicationApi(this);
|
|
20144
19446
|
this.notebook = new NotebookApi(this);
|
|
20145
19447
|
this.servers = new ServerApi(this);
|
|
20146
19448
|
this.options = Object.assign({ startClosed: true }, options);
|
|
@@ -20374,7 +19676,6 @@ var NotebookInstance2 = class {
|
|
|
20374
19676
|
this.log = new Log(this);
|
|
20375
19677
|
this.repl = new Repl(this);
|
|
20376
19678
|
this.container = new Container(this);
|
|
20377
|
-
this.laravel = new Laravel(this);
|
|
20378
19679
|
this.shell = new Shell(this);
|
|
20379
19680
|
this.git = new Git(this, client);
|
|
20380
19681
|
this.services = new Services(this);
|
|
@@ -20406,17 +19707,23 @@ var NotebookInstance2 = class {
|
|
|
20406
19707
|
fork(input = {}) {
|
|
20407
19708
|
return this.client.notebook.fork(this.data.id, input);
|
|
20408
19709
|
}
|
|
20409
|
-
|
|
20410
|
-
return this.client.notebook.
|
|
19710
|
+
publication() {
|
|
19711
|
+
return this.client.notebook.publication.current(this.data.id);
|
|
20411
19712
|
}
|
|
20412
19713
|
publish(input) {
|
|
20413
|
-
return this.client.notebook.
|
|
19714
|
+
return this.client.notebook.publication.publish(this.data.id, input);
|
|
19715
|
+
}
|
|
19716
|
+
run(command, argsOrOpts = [], opts) {
|
|
19717
|
+
if (Array.isArray(argsOrOpts)) {
|
|
19718
|
+
return this.shell.run(command, argsOrOpts, opts);
|
|
19719
|
+
}
|
|
19720
|
+
return this.shell.run(command, argsOrOpts);
|
|
20414
19721
|
}
|
|
20415
19722
|
gitCredentials() {
|
|
20416
19723
|
return this.client.notebook.gitCredentials(this.data.id);
|
|
20417
19724
|
}
|
|
20418
|
-
|
|
20419
|
-
return this.client.notebook.
|
|
19725
|
+
destroy() {
|
|
19726
|
+
return this.client.notebook.destroy(this.data.id).then(() => {
|
|
20420
19727
|
this.socket?.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
|
|
20421
19728
|
});
|
|
20422
19729
|
}
|
|
@@ -20563,11 +19870,6 @@ var NotebookInstance2 = class {
|
|
|
20563
19870
|
__privateMethod(this, _NotebookInstance_instances, init_fn).call(this);
|
|
20564
19871
|
return this.ready().then(() => this);
|
|
20565
19872
|
}
|
|
20566
|
-
async beacon(iframe, options) {
|
|
20567
|
-
const result = await this.ready();
|
|
20568
|
-
iframe.src = result.data.previewUrl;
|
|
20569
|
-
return createBeacon(iframe, options);
|
|
20570
|
-
}
|
|
20571
19873
|
realtimeSocket() {
|
|
20572
19874
|
if (this.socket === null) {
|
|
20573
19875
|
throw new UnsupportedRuntimeTransportError("This operation requires the realtime transport.");
|
|
@@ -20686,44 +19988,9 @@ function formatQueryString(params) {
|
|
|
20686
19988
|
}
|
|
20687
19989
|
export {
|
|
20688
19990
|
ApiError,
|
|
20689
|
-
Beacon,
|
|
20690
|
-
BeaconConnectionError,
|
|
20691
|
-
BeaconError,
|
|
20692
|
-
BeaconTimeoutError,
|
|
20693
19991
|
Client2 as Client,
|
|
20694
19992
|
CommandError,
|
|
20695
19993
|
ComposerCredentials,
|
|
20696
|
-
DeployStreamErrorSchema,
|
|
20697
|
-
DeployStreamEventSchema,
|
|
20698
|
-
DeployStreamLogEventSchema,
|
|
20699
|
-
DeployStreamLogSchema,
|
|
20700
|
-
DeployStreamLogStreamSchema,
|
|
20701
|
-
DeployStreamPhaseEventSchema,
|
|
20702
|
-
DeployStreamPhaseSchema,
|
|
20703
|
-
DeployStreamResultEventSchema,
|
|
20704
|
-
DeployStreamResultSchema,
|
|
20705
|
-
DeployStreamSseDoneEventSchema,
|
|
20706
|
-
DeployStreamSseErrorEventSchema,
|
|
20707
|
-
DeployStreamSseEventNameSchema,
|
|
20708
|
-
DeployStreamSseEventSchema,
|
|
20709
|
-
DeployStreamSseLogEventSchema,
|
|
20710
|
-
DeployStreamSsePhaseEventSchema,
|
|
20711
|
-
DeployStreamSseResultEventSchema,
|
|
20712
|
-
DeploymentApi,
|
|
20713
|
-
DeploymentBuildStatusSchema,
|
|
20714
|
-
DeploymentDomainDnsRecordTypeSchema,
|
|
20715
|
-
DeploymentEventDataSchema,
|
|
20716
|
-
DeploymentInstance,
|
|
20717
|
-
DeploymentJurisdictionSchema,
|
|
20718
|
-
DeploymentLogChunkDataSchema,
|
|
20719
|
-
DeploymentLogStreamSchema,
|
|
20720
|
-
DeploymentProtectionModeSchema,
|
|
20721
|
-
DeploymentRegionSchema,
|
|
20722
|
-
DeploymentReleaseStatusSchema,
|
|
20723
|
-
DeploymentRun,
|
|
20724
|
-
DeploymentSizeSchema,
|
|
20725
|
-
DeploymentStatusSchema,
|
|
20726
|
-
DeploymentTargetProviderSchema,
|
|
20727
19994
|
ErrorEvent,
|
|
20728
19995
|
FileChangeFilter,
|
|
20729
19996
|
FileChangeType,
|
|
@@ -20732,31 +19999,60 @@ export {
|
|
|
20732
19999
|
FilesystemError,
|
|
20733
20000
|
FilesystemErrorType,
|
|
20734
20001
|
LspConnection,
|
|
20735
|
-
Navigator,
|
|
20736
20002
|
NotebookApi,
|
|
20737
20003
|
NotebookComposerCredentialApi,
|
|
20738
|
-
NotebookDeploymentApi,
|
|
20739
20004
|
NotebookInitError,
|
|
20740
20005
|
NotebookInstance2 as NotebookInstance,
|
|
20741
20006
|
NotebookMail,
|
|
20742
20007
|
NotebookMailApi,
|
|
20743
20008
|
NotebookPreview,
|
|
20744
20009
|
NotebookPreviewApi,
|
|
20010
|
+
NotebookPublicationApi,
|
|
20745
20011
|
NotebookSecretApi,
|
|
20746
20012
|
NotebookSecrets,
|
|
20747
20013
|
NotebookState,
|
|
20748
20014
|
NotebookUnavailableError,
|
|
20749
20015
|
PHPSandbox,
|
|
20750
20016
|
PHPSandboxError,
|
|
20017
|
+
ProcessResult,
|
|
20751
20018
|
PromiseTimeoutError,
|
|
20019
|
+
PublicationApi,
|
|
20020
|
+
PublicationBuildStatusSchema,
|
|
20021
|
+
PublicationDomainDnsRecordTypeSchema,
|
|
20022
|
+
PublicationEventDataSchema,
|
|
20023
|
+
PublicationInstance,
|
|
20024
|
+
PublicationJurisdictionSchema,
|
|
20025
|
+
PublicationLogChunkDataSchema,
|
|
20026
|
+
PublicationLogStreamSchema,
|
|
20027
|
+
PublicationProtectionModeSchema,
|
|
20028
|
+
PublicationProviderNameSchema,
|
|
20029
|
+
PublicationRegionSchema,
|
|
20030
|
+
PublicationReleaseStatusSchema,
|
|
20031
|
+
PublicationRun,
|
|
20032
|
+
PublicationSizeSchema,
|
|
20033
|
+
PublicationStatusSchema,
|
|
20034
|
+
PublishStreamErrorSchema,
|
|
20035
|
+
PublishStreamEventSchema,
|
|
20036
|
+
PublishStreamLogEventSchema,
|
|
20037
|
+
PublishStreamLogSchema,
|
|
20038
|
+
PublishStreamLogStreamSchema,
|
|
20039
|
+
PublishStreamPhaseEventSchema,
|
|
20040
|
+
PublishStreamPhaseSchema,
|
|
20041
|
+
PublishStreamResultEventSchema,
|
|
20042
|
+
PublishStreamResultSchema,
|
|
20043
|
+
PublishStreamSseDoneEventSchema,
|
|
20044
|
+
PublishStreamSseErrorEventSchema,
|
|
20045
|
+
PublishStreamSseEventNameSchema,
|
|
20046
|
+
PublishStreamSseEventSchema,
|
|
20047
|
+
PublishStreamSseLogEventSchema,
|
|
20048
|
+
PublishStreamSsePhaseEventSchema,
|
|
20049
|
+
PublishStreamSseResultEventSchema,
|
|
20752
20050
|
RateLimitError,
|
|
20753
20051
|
SendTimeoutError,
|
|
20754
20052
|
ServerApi,
|
|
20755
20053
|
ServerInstance,
|
|
20756
|
-
|
|
20054
|
+
ShellProcess,
|
|
20757
20055
|
UnsupportedRuntimeTransportError,
|
|
20758
|
-
createBeacon,
|
|
20759
|
-
isBeaconSupported,
|
|
20760
20056
|
notebookBuiltinServices,
|
|
20761
20057
|
notebookKnownServices,
|
|
20762
20058
|
once,
|