@phpsandbox/sdk 0.6.0-canary.2 → 0.6.0-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -0
- package/dist/browser/phpsandbox-sdk.esm.js +174 -18
- package/dist/browser/phpsandbox-sdk.esm.min.js +9 -9
- package/dist/browser/phpsandbox-sdk.iife.js +174 -18
- package/dist/browser/phpsandbox-sdk.iife.min.js +9 -9
- package/dist/feedback.d.ts +19 -4
- package/dist/feedback.js +17 -5
- package/dist/filesystem.d.ts +2 -2
- package/dist/filesystem.js +4 -13
- package/dist/index.d.ts +14 -3
- package/dist/index.js +23 -4
- package/dist/runtime/rest.d.ts +7 -0
- package/dist/runtime/rest.js +122 -1
- package/package.json +1 -1
|
@@ -33,6 +33,8 @@ var PHPSandbox = (() => {
|
|
|
33
33
|
CustomerRuntime: () => CustomerRuntime,
|
|
34
34
|
CustomersApi: () => CustomersApi,
|
|
35
35
|
DEFAULT_PAYMENT_CALLBACK_PATH: () => DEFAULT_PAYMENT_CALLBACK_PATH,
|
|
36
|
+
Feedback: () => Feedback,
|
|
37
|
+
FeedbackApi: () => FeedbackApi,
|
|
36
38
|
FileChangeFilter: () => FileChangeFilter,
|
|
37
39
|
FileChangeType: () => FileChangeType,
|
|
38
40
|
FileType: () => FileType,
|
|
@@ -16423,17 +16425,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
16423
16425
|
exists(path) {
|
|
16424
16426
|
return this.stat(path).then(() => true).catch(() => false);
|
|
16425
16427
|
}
|
|
16426
|
-
|
|
16427
|
-
|
|
16428
|
-
|
|
16429
|
-
|
|
16430
|
-
|
|
16431
|
-
|
|
16432
|
-
stream ? options.onChunk : (data) => {
|
|
16433
|
-
chunks.push(data);
|
|
16428
|
+
download(options = {}) {
|
|
16429
|
+
return this.okra.stream(
|
|
16430
|
+
"fs.download",
|
|
16431
|
+
{ include: options.include, exclude: options.exclude },
|
|
16432
|
+
{
|
|
16433
|
+
abortSignal: options.signal
|
|
16434
16434
|
}
|
|
16435
16435
|
);
|
|
16436
|
-
return this.okra.invoke("fs.download", { id, exclude: options.exclude, include: options.include }).then(() => new Blob(chunks, { type: "application/octet-stream" })).finally(() => disposable.dispose());
|
|
16437
16436
|
}
|
|
16438
16437
|
tree(path = "/") {
|
|
16439
16438
|
return this.okra.invoke("fs.tree", { path });
|
|
@@ -20394,6 +20393,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20394
20393
|
"shell.exec": { method: "POST", path: "/runtime/executions" },
|
|
20395
20394
|
"fs.readFile": { method: "GET", path: "/runtime/files/content" },
|
|
20396
20395
|
"fs.writeFile": { method: "PUT", path: "/runtime/files/content" },
|
|
20396
|
+
"fs.download": { method: "POST", path: "/runtime/files/download" },
|
|
20397
20397
|
"fs.createDirectory": { method: "PUT", path: "/runtime/directories" },
|
|
20398
20398
|
"fs.readDirectory": { method: "POST", path: "/runtime/directories/read" },
|
|
20399
20399
|
"fs.stat": { method: "POST", path: "/runtime/files/stat" },
|
|
@@ -20430,6 +20430,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20430
20430
|
this.fetch = fetch;
|
|
20431
20431
|
this.refresh = refresh;
|
|
20432
20432
|
this.refreshPromise = null;
|
|
20433
|
+
this.streams = /* @__PURE__ */ new Set();
|
|
20433
20434
|
this.notebookId = data.id;
|
|
20434
20435
|
this.configure(data.runtimeUrl);
|
|
20435
20436
|
}
|
|
@@ -20462,6 +20463,127 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20462
20463
|
send() {
|
|
20463
20464
|
throw new PHPSandboxError("Fire-and-forget actions require the realtime transport.");
|
|
20464
20465
|
}
|
|
20466
|
+
dispose() {
|
|
20467
|
+
for (const stream of this.streams) {
|
|
20468
|
+
stream.abort(new DOMException("Notebook disposed", "AbortError"));
|
|
20469
|
+
}
|
|
20470
|
+
}
|
|
20471
|
+
stream(action, data, options = {}) {
|
|
20472
|
+
const cancellation = new AbortController();
|
|
20473
|
+
this.streams.add(cancellation);
|
|
20474
|
+
const abort = runtimeAbort({ ...options, abortSignal: cancellation.signal });
|
|
20475
|
+
const abortFromCaller = () => cancellation.abort(options.abortSignal?.reason);
|
|
20476
|
+
let reader;
|
|
20477
|
+
let closed = false;
|
|
20478
|
+
let onAbort = () => {
|
|
20479
|
+
};
|
|
20480
|
+
const dispose = () => {
|
|
20481
|
+
this.streams.delete(cancellation);
|
|
20482
|
+
options.abortSignal?.removeEventListener("abort", abortFromCaller);
|
|
20483
|
+
abort.signal.removeEventListener("abort", onAbort);
|
|
20484
|
+
abort.dispose();
|
|
20485
|
+
};
|
|
20486
|
+
const cancelReader = async (reason) => {
|
|
20487
|
+
const activeReader = reader;
|
|
20488
|
+
reader = void 0;
|
|
20489
|
+
if (activeReader !== void 0) {
|
|
20490
|
+
await activeReader.cancel(reason).catch(() => void 0);
|
|
20491
|
+
activeReader.releaseLock();
|
|
20492
|
+
}
|
|
20493
|
+
};
|
|
20494
|
+
return new ReadableStream(
|
|
20495
|
+
{
|
|
20496
|
+
start: (controller) => {
|
|
20497
|
+
onAbort = () => {
|
|
20498
|
+
if (closed) {
|
|
20499
|
+
return;
|
|
20500
|
+
}
|
|
20501
|
+
closed = true;
|
|
20502
|
+
dispose();
|
|
20503
|
+
controller.error(abort.signal.reason);
|
|
20504
|
+
void cancelReader(abort.signal.reason);
|
|
20505
|
+
};
|
|
20506
|
+
abort.signal.addEventListener("abort", onAbort, { once: true });
|
|
20507
|
+
options.abortSignal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
20508
|
+
if (options.abortSignal?.aborted) {
|
|
20509
|
+
abortFromCaller();
|
|
20510
|
+
}
|
|
20511
|
+
},
|
|
20512
|
+
pull: async (controller) => {
|
|
20513
|
+
try {
|
|
20514
|
+
if (reader === void 0) {
|
|
20515
|
+
const response = await this.streamResponse(action, data, abort.signal);
|
|
20516
|
+
if (closed) {
|
|
20517
|
+
await response.body?.cancel();
|
|
20518
|
+
return;
|
|
20519
|
+
}
|
|
20520
|
+
if (response.body === null) {
|
|
20521
|
+
throw new TransportError("PHPSandbox runtime returned an empty download.", "InvalidResponse", response);
|
|
20522
|
+
}
|
|
20523
|
+
reader = response.body.getReader();
|
|
20524
|
+
}
|
|
20525
|
+
const result = await reader.read();
|
|
20526
|
+
if (closed) {
|
|
20527
|
+
return;
|
|
20528
|
+
}
|
|
20529
|
+
if (result.done) {
|
|
20530
|
+
closed = true;
|
|
20531
|
+
dispose();
|
|
20532
|
+
reader.releaseLock();
|
|
20533
|
+
reader = void 0;
|
|
20534
|
+
controller.close();
|
|
20535
|
+
} else {
|
|
20536
|
+
controller.enqueue(result.value);
|
|
20537
|
+
}
|
|
20538
|
+
} catch (error51) {
|
|
20539
|
+
if (!closed) {
|
|
20540
|
+
closed = true;
|
|
20541
|
+
cancellation.abort(error51);
|
|
20542
|
+
dispose();
|
|
20543
|
+
await cancelReader(error51);
|
|
20544
|
+
controller.error(error51);
|
|
20545
|
+
}
|
|
20546
|
+
}
|
|
20547
|
+
},
|
|
20548
|
+
cancel: async (reason) => {
|
|
20549
|
+
closed = true;
|
|
20550
|
+
cancellation.abort(reason);
|
|
20551
|
+
dispose();
|
|
20552
|
+
await cancelReader(reason);
|
|
20553
|
+
}
|
|
20554
|
+
},
|
|
20555
|
+
{ highWaterMark: 0 }
|
|
20556
|
+
);
|
|
20557
|
+
}
|
|
20558
|
+
async streamResponse(action, data, signal) {
|
|
20559
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
20560
|
+
signal.throwIfAborted();
|
|
20561
|
+
const response = await runtimeFetch(this.fetch, this.request(action, data, signal));
|
|
20562
|
+
if (signal.aborted) {
|
|
20563
|
+
await response.body?.cancel();
|
|
20564
|
+
signal.throwIfAborted();
|
|
20565
|
+
}
|
|
20566
|
+
if (response.status === 401 && attempt === 0 && this.refresh !== void 0) {
|
|
20567
|
+
await response.body?.cancel();
|
|
20568
|
+
await this.refreshAuthorization();
|
|
20569
|
+
continue;
|
|
20570
|
+
}
|
|
20571
|
+
if (!response.ok) {
|
|
20572
|
+
const payload = await runtimeActionResponse(response);
|
|
20573
|
+
throw remoteError("runtime", payload.error, response);
|
|
20574
|
+
}
|
|
20575
|
+
if (!response.headers.get("content-type")?.toLowerCase().startsWith("application/zip")) {
|
|
20576
|
+
await response.body?.cancel();
|
|
20577
|
+
throw new TransportError("PHPSandbox runtime returned an invalid download.", "InvalidResponse", response);
|
|
20578
|
+
}
|
|
20579
|
+
return response;
|
|
20580
|
+
}
|
|
20581
|
+
throw new RemoteError("Notebook download could not be authorized.", {
|
|
20582
|
+
source: "runtime",
|
|
20583
|
+
status: 401,
|
|
20584
|
+
code: "AuthenticationRequired"
|
|
20585
|
+
});
|
|
20586
|
+
}
|
|
20465
20587
|
async invokeRaw(action, data, options) {
|
|
20466
20588
|
const abort = runtimeAbort(options);
|
|
20467
20589
|
try {
|
|
@@ -20494,7 +20616,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20494
20616
|
const url2 = new URL(this.actionUrl);
|
|
20495
20617
|
url2.pathname += route.path;
|
|
20496
20618
|
const headers = {
|
|
20497
|
-
Accept: "application/json, application/octet-stream",
|
|
20619
|
+
Accept: action === "fs.download" ? "application/zip" : "application/json, application/octet-stream",
|
|
20498
20620
|
Authorization: `Bearer ${this.ticket}`
|
|
20499
20621
|
};
|
|
20500
20622
|
const body = runtimeActionRequestBody(action, data, url2, headers);
|
|
@@ -20611,9 +20733,9 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20611
20733
|
|
|
20612
20734
|
// src/feedback.ts
|
|
20613
20735
|
var Feedback = class {
|
|
20614
|
-
constructor(client,
|
|
20736
|
+
constructor(client, identifier) {
|
|
20615
20737
|
this.client = client;
|
|
20616
|
-
this.
|
|
20738
|
+
this.identifier = identifier;
|
|
20617
20739
|
}
|
|
20618
20740
|
async configure(input) {
|
|
20619
20741
|
const response = await this.client.put(this.path("/configuration"), input);
|
|
@@ -20623,8 +20745,8 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20623
20745
|
const response = await this.client.get(this.path("/configuration"));
|
|
20624
20746
|
return response.data;
|
|
20625
20747
|
}
|
|
20626
|
-
async submit(input) {
|
|
20627
|
-
const response = await this.client.post(this.path(), input);
|
|
20748
|
+
async submit(input, options = {}) {
|
|
20749
|
+
const response = await this.client.post(this.path(), input, options);
|
|
20628
20750
|
return response.data;
|
|
20629
20751
|
}
|
|
20630
20752
|
async list(options = {}) {
|
|
@@ -20645,7 +20767,18 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20645
20767
|
return response.data;
|
|
20646
20768
|
}
|
|
20647
20769
|
path(suffix = "") {
|
|
20648
|
-
return `/
|
|
20770
|
+
return `/platform/projects/${encodeURIComponent(this.identifier)}/feedback${suffix}`;
|
|
20771
|
+
}
|
|
20772
|
+
};
|
|
20773
|
+
var FeedbackApi = class {
|
|
20774
|
+
constructor(client) {
|
|
20775
|
+
this.client = client;
|
|
20776
|
+
}
|
|
20777
|
+
forProject(projectId) {
|
|
20778
|
+
return new Feedback(this.client, projectId);
|
|
20779
|
+
}
|
|
20780
|
+
forNotebook(notebookId) {
|
|
20781
|
+
return new Feedback(this.client, notebookId);
|
|
20649
20782
|
}
|
|
20650
20783
|
};
|
|
20651
20784
|
|
|
@@ -20806,6 +20939,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20806
20939
|
this.integrations = new IntegrationApi(this);
|
|
20807
20940
|
this.payments = new PaymentsApi(this);
|
|
20808
20941
|
this.customers = new CustomersApi(this);
|
|
20942
|
+
this.feedback = new FeedbackApi(this);
|
|
20809
20943
|
this.options = { ...options };
|
|
20810
20944
|
this.runtimeTransportValue = runtimeTransport;
|
|
20811
20945
|
this.baseUrl = normalizeApiBaseUrl(url2);
|
|
@@ -20824,8 +20958,13 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20824
20958
|
get(path) {
|
|
20825
20959
|
return this.requireData(this.makeRequest("GET", path));
|
|
20826
20960
|
}
|
|
20827
|
-
post(path, body) {
|
|
20828
|
-
return this.requireData(
|
|
20961
|
+
post(path, body, options = {}) {
|
|
20962
|
+
return this.requireData(
|
|
20963
|
+
this.makeRequest("POST", path, {
|
|
20964
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
20965
|
+
headers: options.idempotencyKey === void 0 ? void 0 : { "Idempotency-Key": options.idempotencyKey }
|
|
20966
|
+
})
|
|
20967
|
+
);
|
|
20829
20968
|
}
|
|
20830
20969
|
delete(path) {
|
|
20831
20970
|
return this.makeRequest("DELETE", path);
|
|
@@ -20878,11 +21017,15 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20878
21017
|
return { ...response, data: response.data };
|
|
20879
21018
|
}
|
|
20880
21019
|
async makeRequest(method, path, init) {
|
|
21020
|
+
const headers = new Headers(init?.headers);
|
|
21021
|
+
for (const [name, value] of Object.entries(this.headers)) {
|
|
21022
|
+
headers.set(name, value);
|
|
21023
|
+
}
|
|
20881
21024
|
const response = await this.fetchResponse(
|
|
20882
21025
|
authenticatedRequest(new URL(path.replace(/^\//, ""), this.baseUrl), {
|
|
20883
21026
|
method,
|
|
20884
21027
|
...init,
|
|
20885
|
-
headers
|
|
21028
|
+
headers
|
|
20886
21029
|
})
|
|
20887
21030
|
);
|
|
20888
21031
|
if (!response.ok) {
|
|
@@ -20948,6 +21091,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20948
21091
|
this.integrations = client.integrations;
|
|
20949
21092
|
this.payments = client.payments;
|
|
20950
21093
|
this.customers = client.customers;
|
|
21094
|
+
this.feedback = client.feedback;
|
|
20951
21095
|
}
|
|
20952
21096
|
async whoami() {
|
|
20953
21097
|
const { data } = await this.client.get("/auth/whoami");
|
|
@@ -20977,6 +21121,7 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
20977
21121
|
this.data = data;
|
|
20978
21122
|
this.client = client;
|
|
20979
21123
|
__privateAdd(this, _NotebookInstance_instances);
|
|
21124
|
+
this.downloadInvoker = null;
|
|
20980
21125
|
this.initialized = false;
|
|
20981
21126
|
__privateAdd(this, _initPromise, null);
|
|
20982
21127
|
this.disposables = [];
|
|
@@ -21098,12 +21243,23 @@ ${JSON.stringify(metadata, null, 2)}` : "";
|
|
|
21098
21243
|
}
|
|
21099
21244
|
return this.realtimeSocket().send(action, data || {});
|
|
21100
21245
|
}
|
|
21246
|
+
/** Binary downloads use HTTP independently of the selected runtime transport. */
|
|
21247
|
+
stream(action, data = {}, options = {}) {
|
|
21248
|
+
const runtimeUrlProvider = this.client.options.runtimeUrlProvider;
|
|
21249
|
+
this.downloadInvoker ?? (this.downloadInvoker = this.restInvoker ?? new RestRuntimeInvoker(
|
|
21250
|
+
this.data,
|
|
21251
|
+
this.client.options.fetch ?? globalThis.fetch,
|
|
21252
|
+
runtimeUrlProvider === void 0 ? void 0 : () => runtimeUrlProvider(this.data.id)
|
|
21253
|
+
));
|
|
21254
|
+
return this.downloadInvoker.stream(action, data, options);
|
|
21255
|
+
}
|
|
21101
21256
|
listen(event, handler) {
|
|
21102
21257
|
const disposable = this.emitter.listen(event, handler);
|
|
21103
21258
|
this.disposables.push(disposable);
|
|
21104
21259
|
return disposable;
|
|
21105
21260
|
}
|
|
21106
21261
|
dispose() {
|
|
21262
|
+
this.downloadInvoker?.dispose();
|
|
21107
21263
|
this.disposables.forEach((d) => d.dispose());
|
|
21108
21264
|
if (this.socket !== null && !this.socket.isClosed) {
|
|
21109
21265
|
this.socket.disconnect();
|