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