@phpsandbox/sdk 0.0.53 → 0.0.55
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/dist/browser/phpsandbox-sdk.esm.js +248 -7
- package/dist/browser/phpsandbox-sdk.esm.min.js +3 -2
- package/dist/browser/phpsandbox-sdk.iife.js +248 -7
- package/dist/browser/phpsandbox-sdk.iife.min.js +3 -2
- package/dist/container.d.ts +2 -0
- package/dist/container.js +3 -0
- package/dist/deployments.d.ts +191 -0
- package/dist/deployments.js +182 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +45 -1
- package/package.json +1 -1
|
@@ -35,6 +35,8 @@ var PHPSandbox = (() => {
|
|
|
35
35
|
BeaconTimeoutError: () => BeaconTimeoutError,
|
|
36
36
|
Client: () => Client,
|
|
37
37
|
CommandError: () => CommandError,
|
|
38
|
+
DeploymentApi: () => DeploymentApi,
|
|
39
|
+
DeploymentInstance: () => DeploymentInstance,
|
|
38
40
|
ErrorEvent: () => ErrorEvent,
|
|
39
41
|
FileChangeFilter: () => FileChangeFilter,
|
|
40
42
|
FileChangeType: () => FileChangeType,
|
|
@@ -45,6 +47,7 @@ var PHPSandbox = (() => {
|
|
|
45
47
|
LspConnection: () => LspConnection,
|
|
46
48
|
Navigator: () => Navigator,
|
|
47
49
|
NotebookApi: () => NotebookApi,
|
|
50
|
+
NotebookDeploymentApi: () => NotebookDeploymentApi,
|
|
48
51
|
NotebookInitError: () => NotebookInitError,
|
|
49
52
|
NotebookInstance: () => NotebookInstance,
|
|
50
53
|
NotebookMail: () => NotebookMail,
|
|
@@ -582,6 +585,9 @@ var PHPSandbox = (() => {
|
|
|
582
585
|
start() {
|
|
583
586
|
return this.okra.invoke("container.start");
|
|
584
587
|
}
|
|
588
|
+
restart() {
|
|
589
|
+
return this.okra.invoke("container.restart");
|
|
590
|
+
}
|
|
585
591
|
stop() {
|
|
586
592
|
return this.okra.invoke("container.stop");
|
|
587
593
|
}
|
|
@@ -2905,15 +2911,15 @@ var PHPSandbox = (() => {
|
|
|
2905
2911
|
};
|
|
2906
2912
|
ReconnectingWebSocket3.prototype._getNextDelay = function() {
|
|
2907
2913
|
var _a = this._options, _b = _a.reconnectionDelayGrowFactor, reconnectionDelayGrowFactor = _b === void 0 ? DEFAULT.reconnectionDelayGrowFactor : _b, _c = _a.minReconnectionDelay, minReconnectionDelay = _c === void 0 ? DEFAULT.minReconnectionDelay : _c, _d = _a.maxReconnectionDelay, maxReconnectionDelay = _d === void 0 ? DEFAULT.maxReconnectionDelay : _d;
|
|
2908
|
-
var
|
|
2914
|
+
var delay2 = 0;
|
|
2909
2915
|
if (this._retryCount > 0) {
|
|
2910
|
-
|
|
2911
|
-
if (
|
|
2912
|
-
|
|
2916
|
+
delay2 = minReconnectionDelay * Math.pow(reconnectionDelayGrowFactor, this._retryCount - 1);
|
|
2917
|
+
if (delay2 > maxReconnectionDelay) {
|
|
2918
|
+
delay2 = maxReconnectionDelay;
|
|
2913
2919
|
}
|
|
2914
2920
|
}
|
|
2915
|
-
this._debug("next delay",
|
|
2916
|
-
return
|
|
2921
|
+
this._debug("next delay", delay2);
|
|
2922
|
+
return delay2;
|
|
2917
2923
|
};
|
|
2918
2924
|
ReconnectingWebSocket3.prototype._wait = function() {
|
|
2919
2925
|
var _this = this;
|
|
@@ -4674,6 +4680,198 @@ var PHPSandbox = (() => {
|
|
|
4674
4680
|
}
|
|
4675
4681
|
}
|
|
4676
4682
|
|
|
4683
|
+
// src/deployments.ts
|
|
4684
|
+
var NotebookDeploymentApi = class {
|
|
4685
|
+
constructor(client) {
|
|
4686
|
+
this.client = client;
|
|
4687
|
+
}
|
|
4688
|
+
async create(id, input = {}) {
|
|
4689
|
+
const response = await this.client.post(`/notebook/${id}/deployments`, input);
|
|
4690
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4691
|
+
}
|
|
4692
|
+
async list(id) {
|
|
4693
|
+
const response = await this.client.get(`/notebook/${id}/deployments`);
|
|
4694
|
+
return response.data;
|
|
4695
|
+
}
|
|
4696
|
+
async slugAvailability(id, slug) {
|
|
4697
|
+
const query = new URLSearchParams({ slug }).toString();
|
|
4698
|
+
const response = await this.client.get(
|
|
4699
|
+
`/notebook/${id}/deployments/slug-availability?${query}`
|
|
4700
|
+
);
|
|
4701
|
+
return response.data;
|
|
4702
|
+
}
|
|
4703
|
+
};
|
|
4704
|
+
var DeploymentApi = class {
|
|
4705
|
+
constructor(client) {
|
|
4706
|
+
this.client = client;
|
|
4707
|
+
}
|
|
4708
|
+
async get(id) {
|
|
4709
|
+
const response = await this.client.get(`/deployments/${id}`);
|
|
4710
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4711
|
+
}
|
|
4712
|
+
async redeploy(id, input = {}) {
|
|
4713
|
+
const response = await this.client.post(`/deployments/${id}/redeploy`, input);
|
|
4714
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4715
|
+
}
|
|
4716
|
+
async delete(id) {
|
|
4717
|
+
await this.client.delete(`/deployments/${id}`);
|
|
4718
|
+
}
|
|
4719
|
+
async setProtection(id, input) {
|
|
4720
|
+
const response = await this.client.put(`/deployments/${id}/protection`, input);
|
|
4721
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4722
|
+
}
|
|
4723
|
+
async protection(id) {
|
|
4724
|
+
const response = await this.client.get(`/deployments/${id}/protection`);
|
|
4725
|
+
return response.data;
|
|
4726
|
+
}
|
|
4727
|
+
async createProtectionSession(id) {
|
|
4728
|
+
const response = await this.client.post(`/deployments/${id}/protection/session`);
|
|
4729
|
+
return response.data;
|
|
4730
|
+
}
|
|
4731
|
+
async disableProtection(id) {
|
|
4732
|
+
const response = await this.client.delete(`/deployments/${id}/protection`);
|
|
4733
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4734
|
+
}
|
|
4735
|
+
async setFeedback(id, input) {
|
|
4736
|
+
const response = await this.client.put(`/deployments/${id}/feedback`, input);
|
|
4737
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4738
|
+
}
|
|
4739
|
+
async listDomains(id) {
|
|
4740
|
+
const response = await this.client.get(
|
|
4741
|
+
`/deployments/${id}/domains`
|
|
4742
|
+
);
|
|
4743
|
+
return unwrapDeploymentDomainCollection(response.data);
|
|
4744
|
+
}
|
|
4745
|
+
async createDomain(id, input) {
|
|
4746
|
+
const response = await this.client.post(`/deployments/${id}/domains`, input);
|
|
4747
|
+
return response.data;
|
|
4748
|
+
}
|
|
4749
|
+
async refreshDomain(id, domainId) {
|
|
4750
|
+
const response = await this.client.post(`/deployments/${id}/domains/${domainId}/refresh`);
|
|
4751
|
+
return response.data;
|
|
4752
|
+
}
|
|
4753
|
+
async deleteDomain(id, domainId) {
|
|
4754
|
+
await this.client.delete(`/deployments/${id}/domains/${domainId}`);
|
|
4755
|
+
}
|
|
4756
|
+
async events(id) {
|
|
4757
|
+
return parseNdjsonStream(await this.client.stream(`/deployments/${id}/events/stream`));
|
|
4758
|
+
}
|
|
4759
|
+
async buildLogs(id, buildId) {
|
|
4760
|
+
return parseNdjsonStream(
|
|
4761
|
+
await this.client.stream(`/deployments/${id}/builds/${buildId}/logs/stream`)
|
|
4762
|
+
);
|
|
4763
|
+
}
|
|
4764
|
+
async logs(id) {
|
|
4765
|
+
return parseNdjsonStream(await this.client.stream(`/deployments/${id}/logs/stream`));
|
|
4766
|
+
}
|
|
4767
|
+
};
|
|
4768
|
+
var DeploymentInstance = class {
|
|
4769
|
+
constructor(data, client) {
|
|
4770
|
+
this.data = data;
|
|
4771
|
+
this.client = client;
|
|
4772
|
+
}
|
|
4773
|
+
refresh() {
|
|
4774
|
+
return this.client.deployments.get(this.data.id);
|
|
4775
|
+
}
|
|
4776
|
+
redeploy(input = {}) {
|
|
4777
|
+
return this.client.deployments.redeploy(this.data.id, input);
|
|
4778
|
+
}
|
|
4779
|
+
delete() {
|
|
4780
|
+
return this.client.deployments.delete(this.data.id);
|
|
4781
|
+
}
|
|
4782
|
+
async wait(options = {}) {
|
|
4783
|
+
const intervalMs = options.intervalMs ?? 1e3;
|
|
4784
|
+
const timeoutMs = options.timeoutMs ?? 3e5;
|
|
4785
|
+
const startedAt = Date.now();
|
|
4786
|
+
let current = this;
|
|
4787
|
+
while (!deploymentStatusIsTerminal(current.data.status)) {
|
|
4788
|
+
if (Date.now() - startedAt > timeoutMs) {
|
|
4789
|
+
throw new Error(`Timed out waiting for deployment ${this.data.id}`);
|
|
4790
|
+
}
|
|
4791
|
+
await delay(intervalMs);
|
|
4792
|
+
current = await current.refresh();
|
|
4793
|
+
}
|
|
4794
|
+
return current;
|
|
4795
|
+
}
|
|
4796
|
+
events() {
|
|
4797
|
+
return this.client.deployments.events(this.data.id);
|
|
4798
|
+
}
|
|
4799
|
+
buildLogs(buildId = this.data.latest_build?.id ?? "") {
|
|
4800
|
+
if (buildId === "") {
|
|
4801
|
+
return Promise.reject(new Error("Deployment has no latest build id"));
|
|
4802
|
+
}
|
|
4803
|
+
return this.client.deployments.buildLogs(this.data.id, buildId);
|
|
4804
|
+
}
|
|
4805
|
+
logs() {
|
|
4806
|
+
return this.client.deployments.logs(this.data.id);
|
|
4807
|
+
}
|
|
4808
|
+
setProtection(input) {
|
|
4809
|
+
return this.client.deployments.setProtection(this.data.id, input);
|
|
4810
|
+
}
|
|
4811
|
+
protection() {
|
|
4812
|
+
return this.client.deployments.protection(this.data.id);
|
|
4813
|
+
}
|
|
4814
|
+
createProtectionSession() {
|
|
4815
|
+
return this.client.deployments.createProtectionSession(this.data.id);
|
|
4816
|
+
}
|
|
4817
|
+
disableProtection() {
|
|
4818
|
+
return this.client.deployments.disableProtection(this.data.id);
|
|
4819
|
+
}
|
|
4820
|
+
setFeedback(input) {
|
|
4821
|
+
return this.client.deployments.setFeedback(this.data.id, input);
|
|
4822
|
+
}
|
|
4823
|
+
domains() {
|
|
4824
|
+
return this.client.deployments.listDomains(this.data.id);
|
|
4825
|
+
}
|
|
4826
|
+
addDomain(input) {
|
|
4827
|
+
return this.client.deployments.createDomain(this.data.id, input);
|
|
4828
|
+
}
|
|
4829
|
+
refreshDomain(domainId) {
|
|
4830
|
+
return this.client.deployments.refreshDomain(this.data.id, domainId);
|
|
4831
|
+
}
|
|
4832
|
+
deleteDomain(domainId) {
|
|
4833
|
+
return this.client.deployments.deleteDomain(this.data.id, domainId);
|
|
4834
|
+
}
|
|
4835
|
+
};
|
|
4836
|
+
function deploymentStatusIsTerminal(status) {
|
|
4837
|
+
return ["healthy", "failed", "stopped", "deleted", "delete_failed"].includes(status);
|
|
4838
|
+
}
|
|
4839
|
+
function delay(ms) {
|
|
4840
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4841
|
+
}
|
|
4842
|
+
function unwrapDeploymentDomainCollection(input) {
|
|
4843
|
+
if (Array.isArray(input)) {
|
|
4844
|
+
return input;
|
|
4845
|
+
}
|
|
4846
|
+
return Array.isArray(input.data) ? input.data : [];
|
|
4847
|
+
}
|
|
4848
|
+
function parseNdjsonStream(input) {
|
|
4849
|
+
const decoder = new TextDecoder();
|
|
4850
|
+
let buffer = "";
|
|
4851
|
+
return input.pipeThrough(
|
|
4852
|
+
new TransformStream({
|
|
4853
|
+
transform(chunk, controller) {
|
|
4854
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
4855
|
+
const lines = buffer.split("\n");
|
|
4856
|
+
buffer = lines.pop() ?? "";
|
|
4857
|
+
for (const line of lines) {
|
|
4858
|
+
const trimmed = line.trim();
|
|
4859
|
+
if (trimmed !== "") {
|
|
4860
|
+
controller.enqueue(JSON.parse(trimmed));
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
},
|
|
4864
|
+
flush(controller) {
|
|
4865
|
+
buffer += decoder.decode();
|
|
4866
|
+
const trimmed = buffer.trim();
|
|
4867
|
+
if (trimmed !== "") {
|
|
4868
|
+
controller.enqueue(JSON.parse(trimmed));
|
|
4869
|
+
}
|
|
4870
|
+
}
|
|
4871
|
+
})
|
|
4872
|
+
);
|
|
4873
|
+
}
|
|
4874
|
+
|
|
4677
4875
|
// src/index.ts
|
|
4678
4876
|
function normalizeNotebookSecretInputs(input) {
|
|
4679
4877
|
if (Array.isArray(input)) {
|
|
@@ -4694,18 +4892,42 @@ var PHPSandbox = (() => {
|
|
|
4694
4892
|
};
|
|
4695
4893
|
var ApiError = class extends Error {
|
|
4696
4894
|
constructor(response, body) {
|
|
4697
|
-
|
|
4895
|
+
const data = parseApiErrorBody(body);
|
|
4896
|
+
const apiMessage = apiErrorMessage(data, body);
|
|
4897
|
+
super(`PHPSandbox API Error: ${response.status} ${response.statusText}${apiMessage === "" ? "" : ` - ${apiMessage}`}`);
|
|
4698
4898
|
this.response = response;
|
|
4699
4899
|
this.body = body;
|
|
4700
4900
|
this.status = response.status;
|
|
4901
|
+
this.data = data;
|
|
4902
|
+
this.apiMessage = apiMessage === "" ? void 0 : apiMessage;
|
|
4701
4903
|
}
|
|
4702
4904
|
};
|
|
4905
|
+
function parseApiErrorBody(body) {
|
|
4906
|
+
try {
|
|
4907
|
+
return JSON.parse(body);
|
|
4908
|
+
} catch {
|
|
4909
|
+
return null;
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
function apiErrorMessage(data, fallback) {
|
|
4913
|
+
if (data !== null && typeof data === "object") {
|
|
4914
|
+
const record = data;
|
|
4915
|
+
if (typeof record.message === "string" && record.message.trim() !== "") {
|
|
4916
|
+
return record.message.trim();
|
|
4917
|
+
}
|
|
4918
|
+
if (record.error !== void 0) {
|
|
4919
|
+
return typeof record.error === "string" ? record.error.trim() : JSON.stringify(record.error);
|
|
4920
|
+
}
|
|
4921
|
+
}
|
|
4922
|
+
return fallback.trim();
|
|
4923
|
+
}
|
|
4703
4924
|
var NotebookApi = class {
|
|
4704
4925
|
constructor(client) {
|
|
4705
4926
|
this.client = client;
|
|
4706
4927
|
this.secrets = new NotebookSecretApi(client);
|
|
4707
4928
|
this.preview = new NotebookPreviewApi(client);
|
|
4708
4929
|
this.mail = new NotebookMailApi(client);
|
|
4930
|
+
this.deployments = new NotebookDeploymentApi(client);
|
|
4709
4931
|
}
|
|
4710
4932
|
async create(template, input = {}, init = true) {
|
|
4711
4933
|
const response = await this.client.post("/notebook", { template, ...input });
|
|
@@ -4757,6 +4979,7 @@ var PHPSandbox = (() => {
|
|
|
4757
4979
|
var Client = class {
|
|
4758
4980
|
constructor(token, url = "https://api.phpsandbox.io/v1", options = {}) {
|
|
4759
4981
|
this.fetch = globalThis.fetch;
|
|
4982
|
+
this.deployments = new DeploymentApi(this);
|
|
4760
4983
|
this.notebook = new NotebookApi(this);
|
|
4761
4984
|
this.options = Object.assign({ startClosed: true }, options);
|
|
4762
4985
|
this.baseUrl = normalizeApiBaseUrl(url);
|
|
@@ -4781,6 +5004,21 @@ var PHPSandbox = (() => {
|
|
|
4781
5004
|
put(path, body) {
|
|
4782
5005
|
return this.makeRequest("PUT", path, { body: body === void 0 ? void 0 : JSON.stringify(body) });
|
|
4783
5006
|
}
|
|
5007
|
+
async stream(path) {
|
|
5008
|
+
const response = await this.fetch(
|
|
5009
|
+
new Request(new URL(path.replace(/^\//, ""), this.baseUrl), {
|
|
5010
|
+
method: "GET",
|
|
5011
|
+
headers: this.headers
|
|
5012
|
+
})
|
|
5013
|
+
);
|
|
5014
|
+
if (!response.ok) {
|
|
5015
|
+
throw new ApiError(response, await response.text());
|
|
5016
|
+
}
|
|
5017
|
+
if (!response.body) {
|
|
5018
|
+
throw new Error("PHPSandbox API Error: response body is not readable");
|
|
5019
|
+
}
|
|
5020
|
+
return response.body;
|
|
5021
|
+
}
|
|
4784
5022
|
async makeRequest(method, path, init) {
|
|
4785
5023
|
const response = await this.fetch(
|
|
4786
5024
|
new Request(new URL(path.replace(/^\//, ""), this.baseUrl), {
|
|
@@ -4927,6 +5165,9 @@ var PHPSandbox = (() => {
|
|
|
4927
5165
|
fork(input = {}) {
|
|
4928
5166
|
return this.client.notebook.fork(this.data.id, input);
|
|
4929
5167
|
}
|
|
5168
|
+
deploy(input = {}) {
|
|
5169
|
+
return this.client.notebook.deployments.create(this.data.id, input);
|
|
5170
|
+
}
|
|
4930
5171
|
gitCredentials() {
|
|
4931
5172
|
return this.client.notebook.gitCredentials(this.data.id);
|
|
4932
5173
|
}
|