@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
|
@@ -525,6 +525,9 @@ var Container = class {
|
|
|
525
525
|
start() {
|
|
526
526
|
return this.okra.invoke("container.start");
|
|
527
527
|
}
|
|
528
|
+
restart() {
|
|
529
|
+
return this.okra.invoke("container.restart");
|
|
530
|
+
}
|
|
528
531
|
stop() {
|
|
529
532
|
return this.okra.invoke("container.stop");
|
|
530
533
|
}
|
|
@@ -2848,15 +2851,15 @@ var ReconnectingWebSocket = (
|
|
|
2848
2851
|
};
|
|
2849
2852
|
ReconnectingWebSocket3.prototype._getNextDelay = function() {
|
|
2850
2853
|
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;
|
|
2851
|
-
var
|
|
2854
|
+
var delay2 = 0;
|
|
2852
2855
|
if (this._retryCount > 0) {
|
|
2853
|
-
|
|
2854
|
-
if (
|
|
2855
|
-
|
|
2856
|
+
delay2 = minReconnectionDelay * Math.pow(reconnectionDelayGrowFactor, this._retryCount - 1);
|
|
2857
|
+
if (delay2 > maxReconnectionDelay) {
|
|
2858
|
+
delay2 = maxReconnectionDelay;
|
|
2856
2859
|
}
|
|
2857
2860
|
}
|
|
2858
|
-
this._debug("next delay",
|
|
2859
|
-
return
|
|
2861
|
+
this._debug("next delay", delay2);
|
|
2862
|
+
return delay2;
|
|
2860
2863
|
};
|
|
2861
2864
|
ReconnectingWebSocket3.prototype._wait = function() {
|
|
2862
2865
|
var _this = this;
|
|
@@ -4617,6 +4620,198 @@ function isBeaconSupported() {
|
|
|
4617
4620
|
}
|
|
4618
4621
|
}
|
|
4619
4622
|
|
|
4623
|
+
// src/deployments.ts
|
|
4624
|
+
var NotebookDeploymentApi = class {
|
|
4625
|
+
constructor(client) {
|
|
4626
|
+
this.client = client;
|
|
4627
|
+
}
|
|
4628
|
+
async create(id, input = {}) {
|
|
4629
|
+
const response = await this.client.post(`/notebook/${id}/deployments`, input);
|
|
4630
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4631
|
+
}
|
|
4632
|
+
async list(id) {
|
|
4633
|
+
const response = await this.client.get(`/notebook/${id}/deployments`);
|
|
4634
|
+
return response.data;
|
|
4635
|
+
}
|
|
4636
|
+
async slugAvailability(id, slug) {
|
|
4637
|
+
const query = new URLSearchParams({ slug }).toString();
|
|
4638
|
+
const response = await this.client.get(
|
|
4639
|
+
`/notebook/${id}/deployments/slug-availability?${query}`
|
|
4640
|
+
);
|
|
4641
|
+
return response.data;
|
|
4642
|
+
}
|
|
4643
|
+
};
|
|
4644
|
+
var DeploymentApi = class {
|
|
4645
|
+
constructor(client) {
|
|
4646
|
+
this.client = client;
|
|
4647
|
+
}
|
|
4648
|
+
async get(id) {
|
|
4649
|
+
const response = await this.client.get(`/deployments/${id}`);
|
|
4650
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4651
|
+
}
|
|
4652
|
+
async redeploy(id, input = {}) {
|
|
4653
|
+
const response = await this.client.post(`/deployments/${id}/redeploy`, input);
|
|
4654
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4655
|
+
}
|
|
4656
|
+
async delete(id) {
|
|
4657
|
+
await this.client.delete(`/deployments/${id}`);
|
|
4658
|
+
}
|
|
4659
|
+
async setProtection(id, input) {
|
|
4660
|
+
const response = await this.client.put(`/deployments/${id}/protection`, input);
|
|
4661
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4662
|
+
}
|
|
4663
|
+
async protection(id) {
|
|
4664
|
+
const response = await this.client.get(`/deployments/${id}/protection`);
|
|
4665
|
+
return response.data;
|
|
4666
|
+
}
|
|
4667
|
+
async createProtectionSession(id) {
|
|
4668
|
+
const response = await this.client.post(`/deployments/${id}/protection/session`);
|
|
4669
|
+
return response.data;
|
|
4670
|
+
}
|
|
4671
|
+
async disableProtection(id) {
|
|
4672
|
+
const response = await this.client.delete(`/deployments/${id}/protection`);
|
|
4673
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4674
|
+
}
|
|
4675
|
+
async setFeedback(id, input) {
|
|
4676
|
+
const response = await this.client.put(`/deployments/${id}/feedback`, input);
|
|
4677
|
+
return new DeploymentInstance(response.data, this.client);
|
|
4678
|
+
}
|
|
4679
|
+
async listDomains(id) {
|
|
4680
|
+
const response = await this.client.get(
|
|
4681
|
+
`/deployments/${id}/domains`
|
|
4682
|
+
);
|
|
4683
|
+
return unwrapDeploymentDomainCollection(response.data);
|
|
4684
|
+
}
|
|
4685
|
+
async createDomain(id, input) {
|
|
4686
|
+
const response = await this.client.post(`/deployments/${id}/domains`, input);
|
|
4687
|
+
return response.data;
|
|
4688
|
+
}
|
|
4689
|
+
async refreshDomain(id, domainId) {
|
|
4690
|
+
const response = await this.client.post(`/deployments/${id}/domains/${domainId}/refresh`);
|
|
4691
|
+
return response.data;
|
|
4692
|
+
}
|
|
4693
|
+
async deleteDomain(id, domainId) {
|
|
4694
|
+
await this.client.delete(`/deployments/${id}/domains/${domainId}`);
|
|
4695
|
+
}
|
|
4696
|
+
async events(id) {
|
|
4697
|
+
return parseNdjsonStream(await this.client.stream(`/deployments/${id}/events/stream`));
|
|
4698
|
+
}
|
|
4699
|
+
async buildLogs(id, buildId) {
|
|
4700
|
+
return parseNdjsonStream(
|
|
4701
|
+
await this.client.stream(`/deployments/${id}/builds/${buildId}/logs/stream`)
|
|
4702
|
+
);
|
|
4703
|
+
}
|
|
4704
|
+
async logs(id) {
|
|
4705
|
+
return parseNdjsonStream(await this.client.stream(`/deployments/${id}/logs/stream`));
|
|
4706
|
+
}
|
|
4707
|
+
};
|
|
4708
|
+
var DeploymentInstance = class {
|
|
4709
|
+
constructor(data, client) {
|
|
4710
|
+
this.data = data;
|
|
4711
|
+
this.client = client;
|
|
4712
|
+
}
|
|
4713
|
+
refresh() {
|
|
4714
|
+
return this.client.deployments.get(this.data.id);
|
|
4715
|
+
}
|
|
4716
|
+
redeploy(input = {}) {
|
|
4717
|
+
return this.client.deployments.redeploy(this.data.id, input);
|
|
4718
|
+
}
|
|
4719
|
+
delete() {
|
|
4720
|
+
return this.client.deployments.delete(this.data.id);
|
|
4721
|
+
}
|
|
4722
|
+
async wait(options = {}) {
|
|
4723
|
+
const intervalMs = options.intervalMs ?? 1e3;
|
|
4724
|
+
const timeoutMs = options.timeoutMs ?? 3e5;
|
|
4725
|
+
const startedAt = Date.now();
|
|
4726
|
+
let current = this;
|
|
4727
|
+
while (!deploymentStatusIsTerminal(current.data.status)) {
|
|
4728
|
+
if (Date.now() - startedAt > timeoutMs) {
|
|
4729
|
+
throw new Error(`Timed out waiting for deployment ${this.data.id}`);
|
|
4730
|
+
}
|
|
4731
|
+
await delay(intervalMs);
|
|
4732
|
+
current = await current.refresh();
|
|
4733
|
+
}
|
|
4734
|
+
return current;
|
|
4735
|
+
}
|
|
4736
|
+
events() {
|
|
4737
|
+
return this.client.deployments.events(this.data.id);
|
|
4738
|
+
}
|
|
4739
|
+
buildLogs(buildId = this.data.latest_build?.id ?? "") {
|
|
4740
|
+
if (buildId === "") {
|
|
4741
|
+
return Promise.reject(new Error("Deployment has no latest build id"));
|
|
4742
|
+
}
|
|
4743
|
+
return this.client.deployments.buildLogs(this.data.id, buildId);
|
|
4744
|
+
}
|
|
4745
|
+
logs() {
|
|
4746
|
+
return this.client.deployments.logs(this.data.id);
|
|
4747
|
+
}
|
|
4748
|
+
setProtection(input) {
|
|
4749
|
+
return this.client.deployments.setProtection(this.data.id, input);
|
|
4750
|
+
}
|
|
4751
|
+
protection() {
|
|
4752
|
+
return this.client.deployments.protection(this.data.id);
|
|
4753
|
+
}
|
|
4754
|
+
createProtectionSession() {
|
|
4755
|
+
return this.client.deployments.createProtectionSession(this.data.id);
|
|
4756
|
+
}
|
|
4757
|
+
disableProtection() {
|
|
4758
|
+
return this.client.deployments.disableProtection(this.data.id);
|
|
4759
|
+
}
|
|
4760
|
+
setFeedback(input) {
|
|
4761
|
+
return this.client.deployments.setFeedback(this.data.id, input);
|
|
4762
|
+
}
|
|
4763
|
+
domains() {
|
|
4764
|
+
return this.client.deployments.listDomains(this.data.id);
|
|
4765
|
+
}
|
|
4766
|
+
addDomain(input) {
|
|
4767
|
+
return this.client.deployments.createDomain(this.data.id, input);
|
|
4768
|
+
}
|
|
4769
|
+
refreshDomain(domainId) {
|
|
4770
|
+
return this.client.deployments.refreshDomain(this.data.id, domainId);
|
|
4771
|
+
}
|
|
4772
|
+
deleteDomain(domainId) {
|
|
4773
|
+
return this.client.deployments.deleteDomain(this.data.id, domainId);
|
|
4774
|
+
}
|
|
4775
|
+
};
|
|
4776
|
+
function deploymentStatusIsTerminal(status) {
|
|
4777
|
+
return ["healthy", "failed", "stopped", "deleted", "delete_failed"].includes(status);
|
|
4778
|
+
}
|
|
4779
|
+
function delay(ms) {
|
|
4780
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4781
|
+
}
|
|
4782
|
+
function unwrapDeploymentDomainCollection(input) {
|
|
4783
|
+
if (Array.isArray(input)) {
|
|
4784
|
+
return input;
|
|
4785
|
+
}
|
|
4786
|
+
return Array.isArray(input.data) ? input.data : [];
|
|
4787
|
+
}
|
|
4788
|
+
function parseNdjsonStream(input) {
|
|
4789
|
+
const decoder = new TextDecoder();
|
|
4790
|
+
let buffer = "";
|
|
4791
|
+
return input.pipeThrough(
|
|
4792
|
+
new TransformStream({
|
|
4793
|
+
transform(chunk, controller) {
|
|
4794
|
+
buffer += decoder.decode(chunk, { stream: true });
|
|
4795
|
+
const lines = buffer.split("\n");
|
|
4796
|
+
buffer = lines.pop() ?? "";
|
|
4797
|
+
for (const line of lines) {
|
|
4798
|
+
const trimmed = line.trim();
|
|
4799
|
+
if (trimmed !== "") {
|
|
4800
|
+
controller.enqueue(JSON.parse(trimmed));
|
|
4801
|
+
}
|
|
4802
|
+
}
|
|
4803
|
+
},
|
|
4804
|
+
flush(controller) {
|
|
4805
|
+
buffer += decoder.decode();
|
|
4806
|
+
const trimmed = buffer.trim();
|
|
4807
|
+
if (trimmed !== "") {
|
|
4808
|
+
controller.enqueue(JSON.parse(trimmed));
|
|
4809
|
+
}
|
|
4810
|
+
}
|
|
4811
|
+
})
|
|
4812
|
+
);
|
|
4813
|
+
}
|
|
4814
|
+
|
|
4620
4815
|
// src/index.ts
|
|
4621
4816
|
function normalizeNotebookSecretInputs(input) {
|
|
4622
4817
|
if (Array.isArray(input)) {
|
|
@@ -4637,18 +4832,42 @@ var NotebookInitError = class extends Error {
|
|
|
4637
4832
|
};
|
|
4638
4833
|
var ApiError = class extends Error {
|
|
4639
4834
|
constructor(response, body) {
|
|
4640
|
-
|
|
4835
|
+
const data = parseApiErrorBody(body);
|
|
4836
|
+
const apiMessage = apiErrorMessage(data, body);
|
|
4837
|
+
super(`PHPSandbox API Error: ${response.status} ${response.statusText}${apiMessage === "" ? "" : ` - ${apiMessage}`}`);
|
|
4641
4838
|
this.response = response;
|
|
4642
4839
|
this.body = body;
|
|
4643
4840
|
this.status = response.status;
|
|
4841
|
+
this.data = data;
|
|
4842
|
+
this.apiMessage = apiMessage === "" ? void 0 : apiMessage;
|
|
4644
4843
|
}
|
|
4645
4844
|
};
|
|
4845
|
+
function parseApiErrorBody(body) {
|
|
4846
|
+
try {
|
|
4847
|
+
return JSON.parse(body);
|
|
4848
|
+
} catch {
|
|
4849
|
+
return null;
|
|
4850
|
+
}
|
|
4851
|
+
}
|
|
4852
|
+
function apiErrorMessage(data, fallback) {
|
|
4853
|
+
if (data !== null && typeof data === "object") {
|
|
4854
|
+
const record = data;
|
|
4855
|
+
if (typeof record.message === "string" && record.message.trim() !== "") {
|
|
4856
|
+
return record.message.trim();
|
|
4857
|
+
}
|
|
4858
|
+
if (record.error !== void 0) {
|
|
4859
|
+
return typeof record.error === "string" ? record.error.trim() : JSON.stringify(record.error);
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
return fallback.trim();
|
|
4863
|
+
}
|
|
4646
4864
|
var NotebookApi = class {
|
|
4647
4865
|
constructor(client) {
|
|
4648
4866
|
this.client = client;
|
|
4649
4867
|
this.secrets = new NotebookSecretApi(client);
|
|
4650
4868
|
this.preview = new NotebookPreviewApi(client);
|
|
4651
4869
|
this.mail = new NotebookMailApi(client);
|
|
4870
|
+
this.deployments = new NotebookDeploymentApi(client);
|
|
4652
4871
|
}
|
|
4653
4872
|
async create(template, input = {}, init = true) {
|
|
4654
4873
|
const response = await this.client.post("/notebook", { template, ...input });
|
|
@@ -4700,6 +4919,7 @@ function normalizeApiBaseUrl(url) {
|
|
|
4700
4919
|
var Client = class {
|
|
4701
4920
|
constructor(token, url = "https://api.phpsandbox.io/v1", options = {}) {
|
|
4702
4921
|
this.fetch = globalThis.fetch;
|
|
4922
|
+
this.deployments = new DeploymentApi(this);
|
|
4703
4923
|
this.notebook = new NotebookApi(this);
|
|
4704
4924
|
this.options = Object.assign({ startClosed: true }, options);
|
|
4705
4925
|
this.baseUrl = normalizeApiBaseUrl(url);
|
|
@@ -4724,6 +4944,21 @@ var Client = class {
|
|
|
4724
4944
|
put(path, body) {
|
|
4725
4945
|
return this.makeRequest("PUT", path, { body: body === void 0 ? void 0 : JSON.stringify(body) });
|
|
4726
4946
|
}
|
|
4947
|
+
async stream(path) {
|
|
4948
|
+
const response = await this.fetch(
|
|
4949
|
+
new Request(new URL(path.replace(/^\//, ""), this.baseUrl), {
|
|
4950
|
+
method: "GET",
|
|
4951
|
+
headers: this.headers
|
|
4952
|
+
})
|
|
4953
|
+
);
|
|
4954
|
+
if (!response.ok) {
|
|
4955
|
+
throw new ApiError(response, await response.text());
|
|
4956
|
+
}
|
|
4957
|
+
if (!response.body) {
|
|
4958
|
+
throw new Error("PHPSandbox API Error: response body is not readable");
|
|
4959
|
+
}
|
|
4960
|
+
return response.body;
|
|
4961
|
+
}
|
|
4727
4962
|
async makeRequest(method, path, init) {
|
|
4728
4963
|
const response = await this.fetch(
|
|
4729
4964
|
new Request(new URL(path.replace(/^\//, ""), this.baseUrl), {
|
|
@@ -4870,6 +5105,9 @@ var NotebookInstance = class {
|
|
|
4870
5105
|
fork(input = {}) {
|
|
4871
5106
|
return this.client.notebook.fork(this.data.id, input);
|
|
4872
5107
|
}
|
|
5108
|
+
deploy(input = {}) {
|
|
5109
|
+
return this.client.notebook.deployments.create(this.data.id, input);
|
|
5110
|
+
}
|
|
4873
5111
|
gitCredentials() {
|
|
4874
5112
|
return this.client.notebook.gitCredentials(this.data.id);
|
|
4875
5113
|
}
|
|
@@ -5102,6 +5340,8 @@ export {
|
|
|
5102
5340
|
BeaconTimeoutError,
|
|
5103
5341
|
Client,
|
|
5104
5342
|
CommandError,
|
|
5343
|
+
DeploymentApi,
|
|
5344
|
+
DeploymentInstance,
|
|
5105
5345
|
ErrorEvent,
|
|
5106
5346
|
FileChangeFilter,
|
|
5107
5347
|
FileChangeType,
|
|
@@ -5112,6 +5352,7 @@ export {
|
|
|
5112
5352
|
LspConnection,
|
|
5113
5353
|
Navigator,
|
|
5114
5354
|
NotebookApi,
|
|
5355
|
+
NotebookDeploymentApi,
|
|
5115
5356
|
NotebookInitError,
|
|
5116
5357
|
NotebookInstance,
|
|
5117
5358
|
NotebookMail,
|