@phpsandbox/sdk 0.1.19 → 0.1.20

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.
@@ -20146,6 +20146,12 @@ var _NotebookInstance = class _NotebookInstance {
20146
20146
  };
20147
20147
  return ready();
20148
20148
  }
20149
+ /** Update sandbox metadata and Git defaults without restarting it. */
20150
+ async update(input) {
20151
+ const response = await this.client.put(`/notebook/${this.data.id}`, input);
20152
+ Object.assign(this.data, response.data);
20153
+ return this.data;
20154
+ }
20149
20155
  async fork(input = {}) {
20150
20156
  const response = await this.client.post(`/notebook/${this.data.id}/fork`, input);
20151
20157
  return new _NotebookInstance(response.data, this.client);
@@ -67,7 +67,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
67
67
 
68
68
  `);n=o.pop()??"";for(let a of o){let s=Ym(a);s&&t.enqueue(s)}},flush(i){if(n+=e.decode(),n.trim()!==""){let t=Ym(n);t&&i.enqueue(t)}}}))}function Ym(r){let e="message",n="";for(let i of r.split(`
69
69
  `))i.startsWith("event: ")?e=i.slice(7).trim():i.startsWith("data: ")?n+=i.slice(6):i.startsWith("data:")&&(n+=i.slice(5));if(n==="")return null;try{return{event:e,data:JSON.parse(n)}}catch{return{event:e,data:n}}}function fl(r,e){let n=new TextDecoder,i="";return r.pipeThrough(new TransformStream({transform(t,o){i+=n.decode(t,{stream:!0});let a=i.split(`
70
- `);i=a.pop()??"";for(let s of a){let c=s.trim();c!==""&&o.enqueue(e.parse(JSON.parse(c)))}},flush(t){i+=n.decode();let o=i.trim();o!==""&&t.enqueue(e.parse(JSON.parse(o)))}}))}var Ei=class{constructor(e){this.client=e}async list(e={}){let n=e.page===void 0?"":`?${new URLSearchParams({page:String(e.page)}).toString()}`;return this.client.get(`/servers${n}`)}async create(e){let n=await this.client.post("/servers",e);return new Ti(n.data,this.client)}async get(e){let n=await this.client.get(`/servers/${e}`);return new Ti(n.data,this.client)}},Ti=class{constructor(e,n){this.data=e;this.client=n}refresh(){return this.client.servers.get(this.data.id)}async delete(){await this.client.delete(`/servers/${this.data.id}`)}async waitReady(e){let n=e?.timeout??3e5,i=e?.interval??3e3,t=Date.now()+n;for(;Date.now()<t;){let o=await this.refresh();if(o.data.status==="connected")return o;if(o.data.status==="failed")throw new Error(`Server provisioning failed: ${o.data.id}`);await new Promise(a=>setTimeout(a,i))}throw new Error(`Server did not become ready within ${n}ms`)}};function _t(r,e){return new Request(r,{...e,redirect:"manual"})}var Qm={"runtime.ready":{method:"GET",path:"/runtime"},"config.get":{method:"GET",path:"/runtime/config"},"config.update":{method:"PATCH",path:"/runtime/config"},"config.set-ports":{method:"PUT",path:"/runtime/config/ports"},"container.restart":{method:"POST",path:"/runtime/container/restart"},"container.stop":{method:"POST",path:"/runtime/container/stop"},"container.set-php":{method:"PUT",path:"/runtime/container/php"},"container.opened-ports":{method:"GET",path:"/runtime/container/ports"},"container.resolve-port":{method:"POST",path:"/runtime/container/ports/resolve"},"container.stats":{method:"GET",path:"/runtime/container/stats"},"terminal.list":{method:"GET",path:"/runtime/terminals"},"shell.exec":{method:"POST",path:"/runtime/executions"},"fs.readFile":{method:"GET",path:"/runtime/files/content"},"fs.writeFile":{method:"PUT",path:"/runtime/files/content"},"fs.createDirectory":{method:"PUT",path:"/runtime/directories"},"fs.readDirectory":{method:"POST",path:"/runtime/directories/read"},"fs.stat":{method:"POST",path:"/runtime/files/stat"},"fs.rename":{method:"POST",path:"/runtime/files/rename"},"fs.copy":{method:"POST",path:"/runtime/files/copy"},"fs.delete":{method:"DELETE",path:"/runtime/files"},"fs.tail":{method:"POST",path:"/runtime/files/tail"},"fs.find":{method:"POST",path:"/runtime/files/find"},"fs.textSearch":{method:"POST",path:"/runtime/files/search"},"fs.tree":{method:"POST",path:"/runtime/files/tree"},"service.list":{method:"GET",path:"/runtime/services"},"service.run":{method:"POST",path:"/runtime/services/run"},"service.stop":{method:"POST",path:"/runtime/services/stop"},"service.logs":{method:"POST",path:"/runtime/services/logs"},"composer.invoke":{method:"POST",path:"/runtime/composer/executions"},"composer.packages":{method:"GET",path:"/runtime/composer/packages"},"git.checkpoint":{method:"POST",path:"/runtime/git/checkpoints"},"git.checkout":{method:"POST",path:"/runtime/git/checkouts"},"git.log":{method:"POST",path:"/runtime/git/log"},"git.sync":{method:"POST",path:"/runtime/git/sync"},"git.diff":{method:"POST",path:"/runtime/git/diff"},"git.merge":{method:"POST",path:"/runtime/git/merge"},"git.conflicts":{method:"GET",path:"/runtime/git/conflicts"},"git.resolve":{method:"POST",path:"/runtime/git/conflicts/resolve"},"git.restore":{method:"POST",path:"/runtime/git/restore"},"git.status":{method:"GET",path:"/runtime/git/status"},"git.review":{method:"GET",path:"/runtime/git/review"},"git.stage":{method:"POST",path:"/runtime/git/stage"},"git.unstage":{method:"POST",path:"/runtime/git/unstage"},"git.revert":{method:"POST",path:"/runtime/git/revert"}},Oi=class{constructor(e,n,i){this.fetch=n;this.refresh=i;this.refreshPromise=null;this.notebookId=e.id,this.configure(e.runtimeUrl)}configure(e){let n=new URL(e),i=n.searchParams.get("ticket")??"";if(i==="")throw new J("The notebook connection does not contain a runtime ticket.");this.ticket=i,n.protocol==="wss:"?n.protocol="https:":n.protocol==="ws:"&&(n.protocol="http:"),n.pathname=`/api/v1/notebooks/${encodeURIComponent(this.notebookId)}`,n.searchParams.delete("ticket"),n.hash="",this.actionUrl=n}ready(){return this.invokeRaw("runtime.ready",{},{})}supports(e){return e in Qm}invoke(e,n={},i={}){return this.invokeRaw(e,n??{},i)}send(){throw new J("Fire-and-forget actions require the realtime transport.")}async invokeRaw(e,n,i){let t=hb(i);try{for(let o=0;o<2;o+=1){let a=await mb(this.fetch,this.request(e,n,t.signal));if(a.status===401&&o===0&&this.refresh!==void 0){await this.refreshAuthorization();continue}let s=await fb(a);if(!a.ok||s.error!==void 0)throw Fe("runtime",s.error,a);return s.data}throw new F(`Runtime action ${e} could not be authorized.`,{source:"runtime",status:401,code:"AuthenticationRequired"})}finally{t.dispose()}}request(e,n,i){let t=Qm[e];if(t===void 0)throw new J(`Runtime action ${e} requires the realtime transport.`);let o=new URL(this.actionUrl);o.pathname+=t.path;let a={Accept:"application/json, application/octet-stream",Authorization:`Bearer ${this.ticket}`},s=gb(e,n,o,a);return _t(o,{method:t.method,headers:a,body:t.method==="GET"?void 0:s,signal:i})}async refreshAuthorization(){this.refreshPromise===null&&(this.refreshPromise=this.refresh().then(e=>this.configure(e)));try{await this.refreshPromise}finally{this.refreshPromise=null}}};async function mb(r,e){try{return await r(e)}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?n:new O("Unable to reach the PHPSandbox runtime.","ConnectionFailed",n)}}async function fb(r){if(r.ok&&r.headers.get("content-type")?.toLowerCase().startsWith("application/octet-stream"))return{data:new Uint8Array(await r.arrayBuffer())};let e=await r.text();if(e===""){if(r.ok)throw new O("PHPSandbox runtime returned an empty response.","InvalidResponse",r);return{}}try{return JSON.parse(e)}catch(n){throw new O("PHPSandbox runtime returned an invalid JSON response.","InvalidResponse",n)}}function gb(r,e,n,i){let t=Di(e);if(r==="fs.readFile"){Ui(n,"path",t.path);let o=Di(t.lineRange);(o.lineStart!==void 0||o.lineEnd!==void 0)&&(Ui(n,"lineStart",o.lineStart),Ui(n,"lineEnd",o.lineEnd));return}if(r==="fs.writeFile"){Ui(n,"path",t.path);let o=Di(t.options);vl(n,"overwrite",o.overwrite),vl(n,"create",o.create),vl(n,"unlock",o.unlock);let a=Di(o.atomic);if(typeof a.postfix=="string"&&a.postfix!==""&&n.searchParams.set("atomicPostfix",a.postfix),!ArrayBuffer.isView(t.contents))throw new TypeError("Runtime file contents must be binary data.");return i["Content-Type"]="application/octet-stream",Uint8Array.from(new Uint8Array(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength)).buffer}return i["Content-Type"]="application/json",JSON.stringify(e)}function Di(r){return r!==null&&typeof r=="object"?r:{}}function Ui(r,e,n){if(typeof n!="string"&&typeof n!="number"||String(n)==="")throw new TypeError(`Runtime file ${e} is required.`);r.searchParams.set(e,String(n))}function vl(r,e,n){r.searchParams.set(e,n===!0?"true":"false")}function hb(r){if(r.timeout===void 0&&r.abortSignal===void 0)return{signal:new AbortController().signal,dispose:()=>{}};let e=new AbortController,n=()=>e.abort(r.abortSignal?.reason);r.abortSignal?.addEventListener("abort",n,{once:!0}),r.abortSignal?.aborted&&n();let i=r.timeout===void 0?void 0:setTimeout(()=>e.abort(),r.timeout);return{signal:e.signal,dispose:()=>{r.abortSignal?.removeEventListener("abort",n),i!==void 0&&clearTimeout(i)}}}var Ni=class{constructor(e,n){this.client=e;this.notebookId=n}async configure(e){return(await this.client.put(this.path("/configuration"),e)).data}async configuration(){return(await this.client.get(this.path("/configuration"))).data}async submit(e){return(await this.client.post(this.path(),e)).data}async list(e={}){let n=new URLSearchParams;for(let[i,t]of Object.entries(e))t!==void 0&&n.set(i,String(t));return this.client.get(`${this.path()}${n.size===0?"":`?${n.toString()}`}`)}async get(e){return(await this.client.get(this.path(`/${encodeURIComponent(e)}`))).data}async update(e,n){return(await this.client.patch(this.path(`/${encodeURIComponent(e)}`),n)).data}path(e=""){return`/notebook/${this.notebookId}/feedback${e}`}};var Ri=class{constructor(e){this.client=e}async link(e){let n=await this.client.post("/integrations",e);return new Ze(n.data,this.client)}async list(){return(await this.client.get("/integrations")).data.map(n=>new Ze(n,this.client))}async get(e){let n=await this.client.get(`/integrations/${encodeURIComponent(ji(e))}`);return new Ze(n.data,this.client)}},Ze=class r{constructor(e,n){this.data=e;this.client=n}get id(){return this.data.id}get provider(){return this.data.provider}get label(){return this.data.label}async update(e){let n=await this.client.patch(`/integrations/${encodeURIComponent(this.id)}`,e);return new r(n.data,this.client)}async unlink(){await this.client.delete(`/integrations/${encodeURIComponent(this.id)}`)}};function ji(r){return typeof r=="string"?r:r.id}var Ai=class{constructor(e,n){this.notebookId=e;this.client=n}async attach(e){let n=await this.client.post(this.path(),{...e,integration:ji(e.integration)});return new Ir(n.data,this.notebookId,this.client)}async list(){return(await this.client.get(this.path())).data.map(n=>new Ir(n,this.notebookId,this.client))}async get(e){let n=await this.client.get(this.bindingPath(e));return new Ir(n.data,this.notebookId,this.client)}path(){return`/notebook/${this.notebookId}/integrations`}bindingPath(e){return`${this.path()}/${encodeURIComponent(vb(e))}`}},Ir=class r{constructor(e,n,i){this.data=e;this.notebookId=n;this.client=i}get id(){return this.data.id}get integration(){return new Ze(this.data.integration,this.client)}get effects(){return this.data.effects}async update(e){let n=await this.client.patch(this.path(),{...e,integration:e.integration===void 0?void 0:ji(e.integration)});return new r(n.data,this.notebookId,this.client)}async detach(){await this.client.delete(this.path())}path(){return`/notebook/${this.notebookId}/integrations/${encodeURIComponent(this.id)}`}};function vb(r){return typeof r=="string"?r:r.id}function bb(r){return Array.isArray(r)?r:Object.entries(r).map(([e,n])=>({name:e,...typeof n=="string"?{value:n}:n}))}var yl=class{constructor(e){this.client=e}async list(e={}){return this.client.get(`/notebook${tf({page:e.page,per_page:e.perPage})}`)}async inspectImport(e){return(await this.client.post("/notebook/imports/inspect",e)).data}async create(e,n={}){let i=await this.client.post("/notebook",{template:e,...n});return new Pr(i.data,this.client)}async get(e){let n=await this.client.get(`/notebook/${e}`);return new Pr(n.data,this.client)}open(e){return new Pr(e,this.client)}};function yb(r){let e=new URL(r),n=e.pathname.replace(/\/+$/,"");return e.pathname=n===""||n==="/"?"/v1/":`${n}/`,e.search="",e.hash="",e.toString()}var Ci=class{constructor(e,n="https://api.phpsandbox.io/v1",i={},t="realtime"){this.fetch=globalThis.fetch;this.publications=new zi(this),this.notebook=new yl(this),this.servers=new Ei(this),this.integrations=new Ri(this),this.options={...i},this.runtimeTransportValue=t,this.baseUrl=yb(n),i.fetch&&(this.fetch=i.fetch),this.headers={Accept:"application/json",Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}get runtimeTransport(){return this.runtimeTransportValue}get(e){return this.makeRequest("GET",e)}post(e,n){return this.makeRequest("POST",e,{body:n===void 0?void 0:JSON.stringify(n)})}delete(e){return this.makeRequest("DELETE",e)}put(e,n){return this.makeRequest("PUT",e,{body:n===void 0?void 0:JSON.stringify(n)})}patch(e,n){return this.makeRequest("PATCH",e,{body:n===void 0?void 0:JSON.stringify(n)})}async stream(e){let n=await this.fetchResponse(_t(new URL(e.replace(/^\//,""),this.baseUrl),{method:"GET",headers:this.headers}));if(!n.ok)throw await bl(n);if(!n.body)throw new O("PHPSandbox API response body is not readable.","InvalidResponse",n);return n.body}async sse(e,n){let i=await this.fetchResponse(_t(e,{method:"GET",headers:{...this.headers,Accept:"text/event-stream"},...n===void 0?{}:{signal:n}}));if(!i.ok)throw await bl(i);if(!i.body)throw new O("PHPSandbox API SSE response body is not readable.","InvalidResponse",i);return i.body}async makeRequest(e,n,i){let t=await this.fetchResponse(_t(new URL(n.replace(/^\//,""),this.baseUrl),{method:e,...i,headers:this.headers}));if(!t.ok)throw await bl(t);if(t.status===204)return{data:void 0};let o=await t.text();if(o==="")throw new O("PHPSandbox API returned an empty response.","InvalidResponse",t);try{let a=JSON.parse(o);if(a===null||typeof a!="object"||Array.isArray(a)||!Object.prototype.hasOwnProperty.call(a,"data"))throw new O("PHPSandbox API returned an invalid success response.","InvalidResponse",t);return a}catch(a){throw O.is(a)?a:new O("PHPSandbox API returned an invalid JSON response.","InvalidResponse",a)}}async fetchResponse(e){try{return await this.fetch(e)}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?n:new O("Unable to reach the PHPSandbox API.","ConnectionFailed",n)}}};async function bl(r){let e=await r.text();try{return Fe("core",xb(e===""?void 0:JSON.parse(e)),r)}catch{return new O(`PHPSandbox API returned an invalid error response (HTTP ${r.status}).`,"InvalidResponse",r,{status:r.status,statusText:r.statusText,body:e})}}function xb(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)?r.error:void 0}var ef=class r{constructor(e){this.client=e;this.notebook=e.notebook,this.publications=e.publications,this.servers=e.servers,this.integrations=e.integrations}get runtimeTransport(){return this.client.runtimeTransport}static realtime(e,n="https://api.phpsandbox.io/v1",i={}){return new r(new Ci(e,n,i))}static rest(e,n="https://api.phpsandbox.io/v1",i={}){return new r(new Ci(e,n,i,"rest"))}},ee,zr,xl,wl=class wl{constructor(e,n){this.data=e;this.client=n;St(this,zr);this.initialized=!1;St(this,ee,null);this.disposables=[];let i=n.options.runtimeUrlProvider;if(this.emitter=Bt.createInstance(),n.runtimeTransport==="rest")this.socket=null,this.restInvoker=new Oi(e,n.options.fetch??globalThis.fetch,i===void 0?void 0:()=>i(e.id));else{this.restInvoker=null;let t=!0,o=i===void 0?e.runtimeUrl:async()=>t?(t=!1,e.runtimeUrl):i(e.id);this.socket=new Br(o,this.emitter,{debug:n.options.debug,webSocket:n.options.webSocket}),this.watchConnection(),Er(this,ee,pe(this,zr,xl).call(this))}this.files=new Tr(this,this.socket===null?null:t=>this.onDidConnect(t)),this.terminals=new Pt(this),this.auth=new zt(this),this.lsp=new Et(this),this.composer=new Dt(this,n),this.runtime=new Rt(this),this.repl=new jt(this),this.shell=new Tt(this),this.git=new Wt(this,n),this.services=new At(this),this.config=new Ct(this),this.secrets=new kl(n,this.data.id),this.integrations=new Ai(this.data.id,n),this.preview=new $l(n,this.data.id),this.mail=new _l(n,this.data.id),this.feedback=new Ni(n,this.data.id)}get runtimeTransport(){return this.client.runtimeTransport}async ready(){if(this.restInvoker!==null)return this.restInitialization();let e=this.realtimeSocket(),n=e.getTerminalError();if(n)throw n;return(async()=>(e.isConnected||await e.connect(),Se(this,ee)))()}async fork(e={}){let n=await this.client.post(`/notebook/${this.data.id}/fork`,e);return new wl(n.data,this.client)}async publication(){try{let e=await this.client.get(`/notebook/${this.data.id}/publication`);return new $t(e.data,this.client,this.data.id)}catch(e){if(F.is(e)&&e.status===404)return null;throw e}}async publish(e){let n=await this.client.post(`/notebook/${this.data.id}/publication`,e),i=new Sr(new $t(n.data,this.client,this.data.id),this.client);return i.start(),i}run(e,n=[],i){return Array.isArray(n)?this.shell.run(e,n,i):this.shell.run(e,n)}exec(e,n=[],i){return Array.isArray(n)?this.run(e,n,i).wait():this.run(e,n).wait()}async destroy(){await this.client.delete(`/notebook/${this.data.id}`),this.socket?.terminate(new F("Notebook has been deleted.",{source:"runtime",status:503,code:"NotebookUnavailable",details:{id:this.data.id}}))}restart(){return this.invoke("container.restart")}stop(){return this.invoke("container.stop")}invoke(e,n={},i={}){return this.restInvoker!==null?(this.restInvoker.supports(String(e))&&this.restInitialization(),this.restInvoker.invoke(e,n||{},i)):this.realtimeSocket().invoke(e,n||{},i)}send(e,n={}){return this.restInvoker!==null?this.restInvoker.send():this.realtimeSocket().send(e,n||{})}listen(e,n){let i=this.emitter.listen(e,n);return this.disposables.push(i),i}dispose(){this.disposables.forEach(e=>e.dispose()),this.socket!==null&&!this.socket.isClosed&&this.socket.disconnect()}connected(){return this.waitForSocketConnection({rejectOnClose:!0})}waitForSocketConnection(e){let n=this.realtimeSocket(),i=n.getTerminalError();return i?Promise.reject(i):n.isConnected?Promise.resolve(this):new Promise((t,o)=>{let a=[],s=!1,c=()=>{for(let l of a)l.dispose();a.length=0},u=l=>{s||(s=!0,c(),l())};try{a.push(n.onDidConnect(()=>u(()=>t(this)))),e.rejectOnClose&&a.push(n.onDidClose(()=>u(()=>o(new Error("Connection closed"))))),a.push(n.onDidBootError(l=>u(()=>o(l))))}catch(l){u(()=>o(l))}})}watchConnection(){let e=this.realtimeSocket();e.onDidConnect(()=>{e.emit("okra.connected")}),e.onDidClose(()=>{e.emit("okra.disconnected"),this.initialized=!1}),e.onDidBootError(n=>{e.emit("okra.boot_error",n),e.emit("okra.disconnected"),this.initialized=!1})}onDidConnect(e){let n=this.realtimeSocket();n.removeListener("okra.connected",e);let i=n.listen("okra.connected",e);return this.disposables.push(i),i}onDidDisconnect(e){let n=this.realtimeSocket().listen("okra.disconnected",e);return this.disposables.push(n),n}onDidBootError(e){let n=this.realtimeSocket().listen("okra.boot_error",e);return this.disposables.push(n),n}restInitialization(){if(this.restInvoker===null)throw new J("This operation requires the REST transport.");return Se(this,ee)===null&&(Er(this,ee,this.restInvoker.ready().then(e=>(this.initialized=e,this.emitter.emit("notebook.initialized",e),e))),Se(this,ee).catch(()=>{})),Se(this,ee)}onDidInitialize(e){return this.listen("notebook.initialized",e)}async reconnect(){let e=this.realtimeSocket(),n=this.waitForSocketConnection({rejectOnClose:!1});return e.reconnect(),this.initialized=!1,await n,pe(this,zr,xl).call(this),this.ready().then(()=>this)}realtimeSocket(){if(this.socket===null)throw new J("This operation requires the realtime transport.");return this.socket}};ee=new WeakMap,zr=new WeakSet,xl=function(){return Er(this,ee,new Promise((e,n)=>{let i=this.onDidInitialize(o=>{if(t.dispose(),i.dispose(),this.initialized=o,o.type==="error"){n(new F(o.message,{source:"runtime",status:503,code:"NotebookInitializationFailed",details:o.data}));return}e(o)}),t=this.onDidBootError(o=>{i.dispose(),t.dispose(),n(o)})})),Se(this,ee).catch(()=>{}),Se(this,ee)};var Pr=wl,kl=class{constructor(e,n){this.client=e;this.notebookId=n}async list(e){let n=new URLSearchParams;e?.environment&&n.set("environment",e.environment);let i=n.toString();return(await this.client.get(`/notebook/${this.notebookId}/secrets${i?`?${i}`:""}`)).data}async set(e,n){let i=typeof n=="string"?{name:e,value:n}:{name:e,...n};return(await this.client.put(`/notebook/${this.notebookId}/secrets`,i)).data}async setMany(e){return(await this.client.put(`/notebook/${this.notebookId}/secrets`,{secrets:bb(e)})).data}async delete(e,n){let i=new URLSearchParams;n?.environment&&i.set("environment",n.environment);let t=i.toString();await this.client.delete(`/notebook/${this.notebookId}/secrets/${encodeURIComponent(e)}${t?`?${t}`:""}`)}},$l=class{constructor(e,n){this.client=e;this.notebookId=n}async get(e){let n=e===void 0?"":`?${new URLSearchParams({url:e}).toString()}`;return(await this.client.get(`/notebook/${this.notebookId}/preview${n}`)).data}async setPassword(e){return(await this.client.put(`/notebook/${this.notebookId}/preview`,e)).data}async disable(){await this.client.delete(`/notebook/${this.notebookId}/preview`)}async createSession(e){return(await this.client.post(`/notebook/${this.notebookId}/preview/session`,e)).data}async createHandoff(e){return(await this.client.post(`/notebook/${this.notebookId}/preview/handoff`,e)).data}},_l=class{constructor(e,n){this.client=e;this.notebookId=n}async status(){return(await this.client.get(`/notebook/${this.notebookId}/mail`)).data}async enable(){return(await this.client.put(`/notebook/${this.notebookId}/mail`)).data}async disable(){await this.client.delete(`/notebook/${this.notebookId}/mail`)}async list(e={}){return this.client.get(`/notebook/${this.notebookId}/mails${tf(e)}`)}async get(e){return(await this.client.get(`/notebook/${this.notebookId}/mails/${encodeURIComponent(e)}`)).data}async delete(e){await this.client.delete(`/notebook/${this.notebookId}/mails/${encodeURIComponent(e)}`)}};function tf(r){let e=new URLSearchParams;for(let[i,t]of Object.entries(r))(typeof t=="string"||typeof t=="number"||typeof t=="boolean")&&e.set(i,String(t));let n=e.toString();return n===""?"":`?${n}`}export{Dl as FileChangeFilter,Ul as FileChangeType,Tl as FileType,Ur as LspConnection,Pr as NotebookInstance,ef as PHPSandbox,J as PHPSandboxError,F as RemoteError,O as TransportError,Nl as notebookBuiltinServices,gf as notebookKnownServices};
70
+ `);i=a.pop()??"";for(let s of a){let c=s.trim();c!==""&&o.enqueue(e.parse(JSON.parse(c)))}},flush(t){i+=n.decode();let o=i.trim();o!==""&&t.enqueue(e.parse(JSON.parse(o)))}}))}var Ei=class{constructor(e){this.client=e}async list(e={}){let n=e.page===void 0?"":`?${new URLSearchParams({page:String(e.page)}).toString()}`;return this.client.get(`/servers${n}`)}async create(e){let n=await this.client.post("/servers",e);return new Ti(n.data,this.client)}async get(e){let n=await this.client.get(`/servers/${e}`);return new Ti(n.data,this.client)}},Ti=class{constructor(e,n){this.data=e;this.client=n}refresh(){return this.client.servers.get(this.data.id)}async delete(){await this.client.delete(`/servers/${this.data.id}`)}async waitReady(e){let n=e?.timeout??3e5,i=e?.interval??3e3,t=Date.now()+n;for(;Date.now()<t;){let o=await this.refresh();if(o.data.status==="connected")return o;if(o.data.status==="failed")throw new Error(`Server provisioning failed: ${o.data.id}`);await new Promise(a=>setTimeout(a,i))}throw new Error(`Server did not become ready within ${n}ms`)}};function _t(r,e){return new Request(r,{...e,redirect:"manual"})}var Qm={"runtime.ready":{method:"GET",path:"/runtime"},"config.get":{method:"GET",path:"/runtime/config"},"config.update":{method:"PATCH",path:"/runtime/config"},"config.set-ports":{method:"PUT",path:"/runtime/config/ports"},"container.restart":{method:"POST",path:"/runtime/container/restart"},"container.stop":{method:"POST",path:"/runtime/container/stop"},"container.set-php":{method:"PUT",path:"/runtime/container/php"},"container.opened-ports":{method:"GET",path:"/runtime/container/ports"},"container.resolve-port":{method:"POST",path:"/runtime/container/ports/resolve"},"container.stats":{method:"GET",path:"/runtime/container/stats"},"terminal.list":{method:"GET",path:"/runtime/terminals"},"shell.exec":{method:"POST",path:"/runtime/executions"},"fs.readFile":{method:"GET",path:"/runtime/files/content"},"fs.writeFile":{method:"PUT",path:"/runtime/files/content"},"fs.createDirectory":{method:"PUT",path:"/runtime/directories"},"fs.readDirectory":{method:"POST",path:"/runtime/directories/read"},"fs.stat":{method:"POST",path:"/runtime/files/stat"},"fs.rename":{method:"POST",path:"/runtime/files/rename"},"fs.copy":{method:"POST",path:"/runtime/files/copy"},"fs.delete":{method:"DELETE",path:"/runtime/files"},"fs.tail":{method:"POST",path:"/runtime/files/tail"},"fs.find":{method:"POST",path:"/runtime/files/find"},"fs.textSearch":{method:"POST",path:"/runtime/files/search"},"fs.tree":{method:"POST",path:"/runtime/files/tree"},"service.list":{method:"GET",path:"/runtime/services"},"service.run":{method:"POST",path:"/runtime/services/run"},"service.stop":{method:"POST",path:"/runtime/services/stop"},"service.logs":{method:"POST",path:"/runtime/services/logs"},"composer.invoke":{method:"POST",path:"/runtime/composer/executions"},"composer.packages":{method:"GET",path:"/runtime/composer/packages"},"git.checkpoint":{method:"POST",path:"/runtime/git/checkpoints"},"git.checkout":{method:"POST",path:"/runtime/git/checkouts"},"git.log":{method:"POST",path:"/runtime/git/log"},"git.sync":{method:"POST",path:"/runtime/git/sync"},"git.diff":{method:"POST",path:"/runtime/git/diff"},"git.merge":{method:"POST",path:"/runtime/git/merge"},"git.conflicts":{method:"GET",path:"/runtime/git/conflicts"},"git.resolve":{method:"POST",path:"/runtime/git/conflicts/resolve"},"git.restore":{method:"POST",path:"/runtime/git/restore"},"git.status":{method:"GET",path:"/runtime/git/status"},"git.review":{method:"GET",path:"/runtime/git/review"},"git.stage":{method:"POST",path:"/runtime/git/stage"},"git.unstage":{method:"POST",path:"/runtime/git/unstage"},"git.revert":{method:"POST",path:"/runtime/git/revert"}},Oi=class{constructor(e,n,i){this.fetch=n;this.refresh=i;this.refreshPromise=null;this.notebookId=e.id,this.configure(e.runtimeUrl)}configure(e){let n=new URL(e),i=n.searchParams.get("ticket")??"";if(i==="")throw new J("The notebook connection does not contain a runtime ticket.");this.ticket=i,n.protocol==="wss:"?n.protocol="https:":n.protocol==="ws:"&&(n.protocol="http:"),n.pathname=`/api/v1/notebooks/${encodeURIComponent(this.notebookId)}`,n.searchParams.delete("ticket"),n.hash="",this.actionUrl=n}ready(){return this.invokeRaw("runtime.ready",{},{})}supports(e){return e in Qm}invoke(e,n={},i={}){return this.invokeRaw(e,n??{},i)}send(){throw new J("Fire-and-forget actions require the realtime transport.")}async invokeRaw(e,n,i){let t=hb(i);try{for(let o=0;o<2;o+=1){let a=await mb(this.fetch,this.request(e,n,t.signal));if(a.status===401&&o===0&&this.refresh!==void 0){await this.refreshAuthorization();continue}let s=await fb(a);if(!a.ok||s.error!==void 0)throw Fe("runtime",s.error,a);return s.data}throw new F(`Runtime action ${e} could not be authorized.`,{source:"runtime",status:401,code:"AuthenticationRequired"})}finally{t.dispose()}}request(e,n,i){let t=Qm[e];if(t===void 0)throw new J(`Runtime action ${e} requires the realtime transport.`);let o=new URL(this.actionUrl);o.pathname+=t.path;let a={Accept:"application/json, application/octet-stream",Authorization:`Bearer ${this.ticket}`},s=gb(e,n,o,a);return _t(o,{method:t.method,headers:a,body:t.method==="GET"?void 0:s,signal:i})}async refreshAuthorization(){this.refreshPromise===null&&(this.refreshPromise=this.refresh().then(e=>this.configure(e)));try{await this.refreshPromise}finally{this.refreshPromise=null}}};async function mb(r,e){try{return await r(e)}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?n:new O("Unable to reach the PHPSandbox runtime.","ConnectionFailed",n)}}async function fb(r){if(r.ok&&r.headers.get("content-type")?.toLowerCase().startsWith("application/octet-stream"))return{data:new Uint8Array(await r.arrayBuffer())};let e=await r.text();if(e===""){if(r.ok)throw new O("PHPSandbox runtime returned an empty response.","InvalidResponse",r);return{}}try{return JSON.parse(e)}catch(n){throw new O("PHPSandbox runtime returned an invalid JSON response.","InvalidResponse",n)}}function gb(r,e,n,i){let t=Di(e);if(r==="fs.readFile"){Ui(n,"path",t.path);let o=Di(t.lineRange);(o.lineStart!==void 0||o.lineEnd!==void 0)&&(Ui(n,"lineStart",o.lineStart),Ui(n,"lineEnd",o.lineEnd));return}if(r==="fs.writeFile"){Ui(n,"path",t.path);let o=Di(t.options);vl(n,"overwrite",o.overwrite),vl(n,"create",o.create),vl(n,"unlock",o.unlock);let a=Di(o.atomic);if(typeof a.postfix=="string"&&a.postfix!==""&&n.searchParams.set("atomicPostfix",a.postfix),!ArrayBuffer.isView(t.contents))throw new TypeError("Runtime file contents must be binary data.");return i["Content-Type"]="application/octet-stream",Uint8Array.from(new Uint8Array(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength)).buffer}return i["Content-Type"]="application/json",JSON.stringify(e)}function Di(r){return r!==null&&typeof r=="object"?r:{}}function Ui(r,e,n){if(typeof n!="string"&&typeof n!="number"||String(n)==="")throw new TypeError(`Runtime file ${e} is required.`);r.searchParams.set(e,String(n))}function vl(r,e,n){r.searchParams.set(e,n===!0?"true":"false")}function hb(r){if(r.timeout===void 0&&r.abortSignal===void 0)return{signal:new AbortController().signal,dispose:()=>{}};let e=new AbortController,n=()=>e.abort(r.abortSignal?.reason);r.abortSignal?.addEventListener("abort",n,{once:!0}),r.abortSignal?.aborted&&n();let i=r.timeout===void 0?void 0:setTimeout(()=>e.abort(),r.timeout);return{signal:e.signal,dispose:()=>{r.abortSignal?.removeEventListener("abort",n),i!==void 0&&clearTimeout(i)}}}var Ni=class{constructor(e,n){this.client=e;this.notebookId=n}async configure(e){return(await this.client.put(this.path("/configuration"),e)).data}async configuration(){return(await this.client.get(this.path("/configuration"))).data}async submit(e){return(await this.client.post(this.path(),e)).data}async list(e={}){let n=new URLSearchParams;for(let[i,t]of Object.entries(e))t!==void 0&&n.set(i,String(t));return this.client.get(`${this.path()}${n.size===0?"":`?${n.toString()}`}`)}async get(e){return(await this.client.get(this.path(`/${encodeURIComponent(e)}`))).data}async update(e,n){return(await this.client.patch(this.path(`/${encodeURIComponent(e)}`),n)).data}path(e=""){return`/notebook/${this.notebookId}/feedback${e}`}};var Ri=class{constructor(e){this.client=e}async link(e){let n=await this.client.post("/integrations",e);return new Ze(n.data,this.client)}async list(){return(await this.client.get("/integrations")).data.map(n=>new Ze(n,this.client))}async get(e){let n=await this.client.get(`/integrations/${encodeURIComponent(ji(e))}`);return new Ze(n.data,this.client)}},Ze=class r{constructor(e,n){this.data=e;this.client=n}get id(){return this.data.id}get provider(){return this.data.provider}get label(){return this.data.label}async update(e){let n=await this.client.patch(`/integrations/${encodeURIComponent(this.id)}`,e);return new r(n.data,this.client)}async unlink(){await this.client.delete(`/integrations/${encodeURIComponent(this.id)}`)}};function ji(r){return typeof r=="string"?r:r.id}var Ai=class{constructor(e,n){this.notebookId=e;this.client=n}async attach(e){let n=await this.client.post(this.path(),{...e,integration:ji(e.integration)});return new Ir(n.data,this.notebookId,this.client)}async list(){return(await this.client.get(this.path())).data.map(n=>new Ir(n,this.notebookId,this.client))}async get(e){let n=await this.client.get(this.bindingPath(e));return new Ir(n.data,this.notebookId,this.client)}path(){return`/notebook/${this.notebookId}/integrations`}bindingPath(e){return`${this.path()}/${encodeURIComponent(vb(e))}`}},Ir=class r{constructor(e,n,i){this.data=e;this.notebookId=n;this.client=i}get id(){return this.data.id}get integration(){return new Ze(this.data.integration,this.client)}get effects(){return this.data.effects}async update(e){let n=await this.client.patch(this.path(),{...e,integration:e.integration===void 0?void 0:ji(e.integration)});return new r(n.data,this.notebookId,this.client)}async detach(){await this.client.delete(this.path())}path(){return`/notebook/${this.notebookId}/integrations/${encodeURIComponent(this.id)}`}};function vb(r){return typeof r=="string"?r:r.id}function bb(r){return Array.isArray(r)?r:Object.entries(r).map(([e,n])=>({name:e,...typeof n=="string"?{value:n}:n}))}var yl=class{constructor(e){this.client=e}async list(e={}){return this.client.get(`/notebook${tf({page:e.page,per_page:e.perPage})}`)}async inspectImport(e){return(await this.client.post("/notebook/imports/inspect",e)).data}async create(e,n={}){let i=await this.client.post("/notebook",{template:e,...n});return new Pr(i.data,this.client)}async get(e){let n=await this.client.get(`/notebook/${e}`);return new Pr(n.data,this.client)}open(e){return new Pr(e,this.client)}};function yb(r){let e=new URL(r),n=e.pathname.replace(/\/+$/,"");return e.pathname=n===""||n==="/"?"/v1/":`${n}/`,e.search="",e.hash="",e.toString()}var Ci=class{constructor(e,n="https://api.phpsandbox.io/v1",i={},t="realtime"){this.fetch=globalThis.fetch;this.publications=new zi(this),this.notebook=new yl(this),this.servers=new Ei(this),this.integrations=new Ri(this),this.options={...i},this.runtimeTransportValue=t,this.baseUrl=yb(n),i.fetch&&(this.fetch=i.fetch),this.headers={Accept:"application/json",Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}get runtimeTransport(){return this.runtimeTransportValue}get(e){return this.makeRequest("GET",e)}post(e,n){return this.makeRequest("POST",e,{body:n===void 0?void 0:JSON.stringify(n)})}delete(e){return this.makeRequest("DELETE",e)}put(e,n){return this.makeRequest("PUT",e,{body:n===void 0?void 0:JSON.stringify(n)})}patch(e,n){return this.makeRequest("PATCH",e,{body:n===void 0?void 0:JSON.stringify(n)})}async stream(e){let n=await this.fetchResponse(_t(new URL(e.replace(/^\//,""),this.baseUrl),{method:"GET",headers:this.headers}));if(!n.ok)throw await bl(n);if(!n.body)throw new O("PHPSandbox API response body is not readable.","InvalidResponse",n);return n.body}async sse(e,n){let i=await this.fetchResponse(_t(e,{method:"GET",headers:{...this.headers,Accept:"text/event-stream"},...n===void 0?{}:{signal:n}}));if(!i.ok)throw await bl(i);if(!i.body)throw new O("PHPSandbox API SSE response body is not readable.","InvalidResponse",i);return i.body}async makeRequest(e,n,i){let t=await this.fetchResponse(_t(new URL(n.replace(/^\//,""),this.baseUrl),{method:e,...i,headers:this.headers}));if(!t.ok)throw await bl(t);if(t.status===204)return{data:void 0};let o=await t.text();if(o==="")throw new O("PHPSandbox API returned an empty response.","InvalidResponse",t);try{let a=JSON.parse(o);if(a===null||typeof a!="object"||Array.isArray(a)||!Object.prototype.hasOwnProperty.call(a,"data"))throw new O("PHPSandbox API returned an invalid success response.","InvalidResponse",t);return a}catch(a){throw O.is(a)?a:new O("PHPSandbox API returned an invalid JSON response.","InvalidResponse",a)}}async fetchResponse(e){try{return await this.fetch(e)}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?n:new O("Unable to reach the PHPSandbox API.","ConnectionFailed",n)}}};async function bl(r){let e=await r.text();try{return Fe("core",xb(e===""?void 0:JSON.parse(e)),r)}catch{return new O(`PHPSandbox API returned an invalid error response (HTTP ${r.status}).`,"InvalidResponse",r,{status:r.status,statusText:r.statusText,body:e})}}function xb(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)?r.error:void 0}var ef=class r{constructor(e){this.client=e;this.notebook=e.notebook,this.publications=e.publications,this.servers=e.servers,this.integrations=e.integrations}get runtimeTransport(){return this.client.runtimeTransport}static realtime(e,n="https://api.phpsandbox.io/v1",i={}){return new r(new Ci(e,n,i))}static rest(e,n="https://api.phpsandbox.io/v1",i={}){return new r(new Ci(e,n,i,"rest"))}},ee,zr,xl,wl=class wl{constructor(e,n){this.data=e;this.client=n;St(this,zr);this.initialized=!1;St(this,ee,null);this.disposables=[];let i=n.options.runtimeUrlProvider;if(this.emitter=Bt.createInstance(),n.runtimeTransport==="rest")this.socket=null,this.restInvoker=new Oi(e,n.options.fetch??globalThis.fetch,i===void 0?void 0:()=>i(e.id));else{this.restInvoker=null;let t=!0,o=i===void 0?e.runtimeUrl:async()=>t?(t=!1,e.runtimeUrl):i(e.id);this.socket=new Br(o,this.emitter,{debug:n.options.debug,webSocket:n.options.webSocket}),this.watchConnection(),Er(this,ee,pe(this,zr,xl).call(this))}this.files=new Tr(this,this.socket===null?null:t=>this.onDidConnect(t)),this.terminals=new Pt(this),this.auth=new zt(this),this.lsp=new Et(this),this.composer=new Dt(this,n),this.runtime=new Rt(this),this.repl=new jt(this),this.shell=new Tt(this),this.git=new Wt(this,n),this.services=new At(this),this.config=new Ct(this),this.secrets=new kl(n,this.data.id),this.integrations=new Ai(this.data.id,n),this.preview=new $l(n,this.data.id),this.mail=new _l(n,this.data.id),this.feedback=new Ni(n,this.data.id)}get runtimeTransport(){return this.client.runtimeTransport}async ready(){if(this.restInvoker!==null)return this.restInitialization();let e=this.realtimeSocket(),n=e.getTerminalError();if(n)throw n;return(async()=>(e.isConnected||await e.connect(),Se(this,ee)))()}async update(e){let n=await this.client.put(`/notebook/${this.data.id}`,e);return Object.assign(this.data,n.data),this.data}async fork(e={}){let n=await this.client.post(`/notebook/${this.data.id}/fork`,e);return new wl(n.data,this.client)}async publication(){try{let e=await this.client.get(`/notebook/${this.data.id}/publication`);return new $t(e.data,this.client,this.data.id)}catch(e){if(F.is(e)&&e.status===404)return null;throw e}}async publish(e){let n=await this.client.post(`/notebook/${this.data.id}/publication`,e),i=new Sr(new $t(n.data,this.client,this.data.id),this.client);return i.start(),i}run(e,n=[],i){return Array.isArray(n)?this.shell.run(e,n,i):this.shell.run(e,n)}exec(e,n=[],i){return Array.isArray(n)?this.run(e,n,i).wait():this.run(e,n).wait()}async destroy(){await this.client.delete(`/notebook/${this.data.id}`),this.socket?.terminate(new F("Notebook has been deleted.",{source:"runtime",status:503,code:"NotebookUnavailable",details:{id:this.data.id}}))}restart(){return this.invoke("container.restart")}stop(){return this.invoke("container.stop")}invoke(e,n={},i={}){return this.restInvoker!==null?(this.restInvoker.supports(String(e))&&this.restInitialization(),this.restInvoker.invoke(e,n||{},i)):this.realtimeSocket().invoke(e,n||{},i)}send(e,n={}){return this.restInvoker!==null?this.restInvoker.send():this.realtimeSocket().send(e,n||{})}listen(e,n){let i=this.emitter.listen(e,n);return this.disposables.push(i),i}dispose(){this.disposables.forEach(e=>e.dispose()),this.socket!==null&&!this.socket.isClosed&&this.socket.disconnect()}connected(){return this.waitForSocketConnection({rejectOnClose:!0})}waitForSocketConnection(e){let n=this.realtimeSocket(),i=n.getTerminalError();return i?Promise.reject(i):n.isConnected?Promise.resolve(this):new Promise((t,o)=>{let a=[],s=!1,c=()=>{for(let l of a)l.dispose();a.length=0},u=l=>{s||(s=!0,c(),l())};try{a.push(n.onDidConnect(()=>u(()=>t(this)))),e.rejectOnClose&&a.push(n.onDidClose(()=>u(()=>o(new Error("Connection closed"))))),a.push(n.onDidBootError(l=>u(()=>o(l))))}catch(l){u(()=>o(l))}})}watchConnection(){let e=this.realtimeSocket();e.onDidConnect(()=>{e.emit("okra.connected")}),e.onDidClose(()=>{e.emit("okra.disconnected"),this.initialized=!1}),e.onDidBootError(n=>{e.emit("okra.boot_error",n),e.emit("okra.disconnected"),this.initialized=!1})}onDidConnect(e){let n=this.realtimeSocket();n.removeListener("okra.connected",e);let i=n.listen("okra.connected",e);return this.disposables.push(i),i}onDidDisconnect(e){let n=this.realtimeSocket().listen("okra.disconnected",e);return this.disposables.push(n),n}onDidBootError(e){let n=this.realtimeSocket().listen("okra.boot_error",e);return this.disposables.push(n),n}restInitialization(){if(this.restInvoker===null)throw new J("This operation requires the REST transport.");return Se(this,ee)===null&&(Er(this,ee,this.restInvoker.ready().then(e=>(this.initialized=e,this.emitter.emit("notebook.initialized",e),e))),Se(this,ee).catch(()=>{})),Se(this,ee)}onDidInitialize(e){return this.listen("notebook.initialized",e)}async reconnect(){let e=this.realtimeSocket(),n=this.waitForSocketConnection({rejectOnClose:!1});return e.reconnect(),this.initialized=!1,await n,pe(this,zr,xl).call(this),this.ready().then(()=>this)}realtimeSocket(){if(this.socket===null)throw new J("This operation requires the realtime transport.");return this.socket}};ee=new WeakMap,zr=new WeakSet,xl=function(){return Er(this,ee,new Promise((e,n)=>{let i=this.onDidInitialize(o=>{if(t.dispose(),i.dispose(),this.initialized=o,o.type==="error"){n(new F(o.message,{source:"runtime",status:503,code:"NotebookInitializationFailed",details:o.data}));return}e(o)}),t=this.onDidBootError(o=>{i.dispose(),t.dispose(),n(o)})})),Se(this,ee).catch(()=>{}),Se(this,ee)};var Pr=wl,kl=class{constructor(e,n){this.client=e;this.notebookId=n}async list(e){let n=new URLSearchParams;e?.environment&&n.set("environment",e.environment);let i=n.toString();return(await this.client.get(`/notebook/${this.notebookId}/secrets${i?`?${i}`:""}`)).data}async set(e,n){let i=typeof n=="string"?{name:e,value:n}:{name:e,...n};return(await this.client.put(`/notebook/${this.notebookId}/secrets`,i)).data}async setMany(e){return(await this.client.put(`/notebook/${this.notebookId}/secrets`,{secrets:bb(e)})).data}async delete(e,n){let i=new URLSearchParams;n?.environment&&i.set("environment",n.environment);let t=i.toString();await this.client.delete(`/notebook/${this.notebookId}/secrets/${encodeURIComponent(e)}${t?`?${t}`:""}`)}},$l=class{constructor(e,n){this.client=e;this.notebookId=n}async get(e){let n=e===void 0?"":`?${new URLSearchParams({url:e}).toString()}`;return(await this.client.get(`/notebook/${this.notebookId}/preview${n}`)).data}async setPassword(e){return(await this.client.put(`/notebook/${this.notebookId}/preview`,e)).data}async disable(){await this.client.delete(`/notebook/${this.notebookId}/preview`)}async createSession(e){return(await this.client.post(`/notebook/${this.notebookId}/preview/session`,e)).data}async createHandoff(e){return(await this.client.post(`/notebook/${this.notebookId}/preview/handoff`,e)).data}},_l=class{constructor(e,n){this.client=e;this.notebookId=n}async status(){return(await this.client.get(`/notebook/${this.notebookId}/mail`)).data}async enable(){return(await this.client.put(`/notebook/${this.notebookId}/mail`)).data}async disable(){await this.client.delete(`/notebook/${this.notebookId}/mail`)}async list(e={}){return this.client.get(`/notebook/${this.notebookId}/mails${tf(e)}`)}async get(e){return(await this.client.get(`/notebook/${this.notebookId}/mails/${encodeURIComponent(e)}`)).data}async delete(e){await this.client.delete(`/notebook/${this.notebookId}/mails/${encodeURIComponent(e)}`)}};function tf(r){let e=new URLSearchParams;for(let[i,t]of Object.entries(r))(typeof t=="string"||typeof t=="number"||typeof t=="boolean")&&e.set(i,String(t));let n=e.toString();return n===""?"":`?${n}`}export{Dl as FileChangeFilter,Ul as FileChangeType,Tl as FileType,Ur as LspConnection,Pr as NotebookInstance,ef as PHPSandbox,J as PHPSandboxError,F as RemoteError,O as TransportError,Nl as notebookBuiltinServices,gf as notebookKnownServices};
71
71
  /*! Bundled license information:
72
72
 
73
73
  reconnecting-websocket/dist/reconnecting-websocket-mjs.js:
@@ -20175,6 +20175,12 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
20175
20175
  };
20176
20176
  return ready();
20177
20177
  }
20178
+ /** Update sandbox metadata and Git defaults without restarting it. */
20179
+ async update(input) {
20180
+ const response = await this.client.put(`/notebook/${this.data.id}`, input);
20181
+ Object.assign(this.data, response.data);
20182
+ return this.data;
20183
+ }
20178
20184
  async fork(input = {}) {
20179
20185
  const response = await this.client.post(`/notebook/${this.data.id}/fork`, input);
20180
20186
  return new _NotebookInstance(response.data, this.client);
@@ -67,7 +67,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
67
67
 
68
68
  `);n=o.pop()??"";for(let a of o){let s=tf(a);s&&t.enqueue(s)}},flush(i){if(n+=e.decode(),n.trim()!==""){let t=tf(n);t&&i.enqueue(t)}}}))}function tf(r){let e="message",n="";for(let i of r.split(`
69
69
  `))i.startsWith("event: ")?e=i.slice(7).trim():i.startsWith("data: ")?n+=i.slice(6):i.startsWith("data:")&&(n+=i.slice(5));if(n==="")return null;try{return{event:e,data:JSON.parse(n)}}catch{return{event:e,data:n}}}function yl(r,e){let n=new TextDecoder,i="";return r.pipeThrough(new TransformStream({transform(t,o){i+=n.decode(t,{stream:!0});let a=i.split(`
70
- `);i=a.pop()??"";for(let s of a){let c=s.trim();c!==""&&o.enqueue(e.parse(JSON.parse(c)))}},flush(t){i+=n.decode();let o=i.trim();o!==""&&t.enqueue(e.parse(JSON.parse(o)))}}))}var Ei=class{constructor(e){this.client=e}async list(e={}){let n=e.page===void 0?"":`?${new URLSearchParams({page:String(e.page)}).toString()}`;return this.client.get(`/servers${n}`)}async create(e){let n=await this.client.post("/servers",e);return new Ti(n.data,this.client)}async get(e){let n=await this.client.get(`/servers/${e}`);return new Ti(n.data,this.client)}},Ti=class{constructor(e,n){this.data=e;this.client=n}refresh(){return this.client.servers.get(this.data.id)}async delete(){await this.client.delete(`/servers/${this.data.id}`)}async waitReady(e){let n=e?.timeout??3e5,i=e?.interval??3e3,t=Date.now()+n;for(;Date.now()<t;){let o=await this.refresh();if(o.data.status==="connected")return o;if(o.data.status==="failed")throw new Error(`Server provisioning failed: ${o.data.id}`);await new Promise(a=>setTimeout(a,i))}throw new Error(`Server did not become ready within ${n}ms`)}};function _t(r,e){return new Request(r,{...e,redirect:"manual"})}var rf={"runtime.ready":{method:"GET",path:"/runtime"},"config.get":{method:"GET",path:"/runtime/config"},"config.update":{method:"PATCH",path:"/runtime/config"},"config.set-ports":{method:"PUT",path:"/runtime/config/ports"},"container.restart":{method:"POST",path:"/runtime/container/restart"},"container.stop":{method:"POST",path:"/runtime/container/stop"},"container.set-php":{method:"PUT",path:"/runtime/container/php"},"container.opened-ports":{method:"GET",path:"/runtime/container/ports"},"container.resolve-port":{method:"POST",path:"/runtime/container/ports/resolve"},"container.stats":{method:"GET",path:"/runtime/container/stats"},"terminal.list":{method:"GET",path:"/runtime/terminals"},"shell.exec":{method:"POST",path:"/runtime/executions"},"fs.readFile":{method:"GET",path:"/runtime/files/content"},"fs.writeFile":{method:"PUT",path:"/runtime/files/content"},"fs.createDirectory":{method:"PUT",path:"/runtime/directories"},"fs.readDirectory":{method:"POST",path:"/runtime/directories/read"},"fs.stat":{method:"POST",path:"/runtime/files/stat"},"fs.rename":{method:"POST",path:"/runtime/files/rename"},"fs.copy":{method:"POST",path:"/runtime/files/copy"},"fs.delete":{method:"DELETE",path:"/runtime/files"},"fs.tail":{method:"POST",path:"/runtime/files/tail"},"fs.find":{method:"POST",path:"/runtime/files/find"},"fs.textSearch":{method:"POST",path:"/runtime/files/search"},"fs.tree":{method:"POST",path:"/runtime/files/tree"},"service.list":{method:"GET",path:"/runtime/services"},"service.run":{method:"POST",path:"/runtime/services/run"},"service.stop":{method:"POST",path:"/runtime/services/stop"},"service.logs":{method:"POST",path:"/runtime/services/logs"},"composer.invoke":{method:"POST",path:"/runtime/composer/executions"},"composer.packages":{method:"GET",path:"/runtime/composer/packages"},"git.checkpoint":{method:"POST",path:"/runtime/git/checkpoints"},"git.checkout":{method:"POST",path:"/runtime/git/checkouts"},"git.log":{method:"POST",path:"/runtime/git/log"},"git.sync":{method:"POST",path:"/runtime/git/sync"},"git.diff":{method:"POST",path:"/runtime/git/diff"},"git.merge":{method:"POST",path:"/runtime/git/merge"},"git.conflicts":{method:"GET",path:"/runtime/git/conflicts"},"git.resolve":{method:"POST",path:"/runtime/git/conflicts/resolve"},"git.restore":{method:"POST",path:"/runtime/git/restore"},"git.status":{method:"GET",path:"/runtime/git/status"},"git.review":{method:"GET",path:"/runtime/git/review"},"git.stage":{method:"POST",path:"/runtime/git/stage"},"git.unstage":{method:"POST",path:"/runtime/git/unstage"},"git.revert":{method:"POST",path:"/runtime/git/revert"}},Oi=class{constructor(e,n,i){this.fetch=n;this.refresh=i;this.refreshPromise=null;this.notebookId=e.id,this.configure(e.runtimeUrl)}configure(e){let n=new URL(e),i=n.searchParams.get("ticket")??"";if(i==="")throw new M("The notebook connection does not contain a runtime ticket.");this.ticket=i,n.protocol==="wss:"?n.protocol="https:":n.protocol==="ws:"&&(n.protocol="http:"),n.pathname=`/api/v1/notebooks/${encodeURIComponent(this.notebookId)}`,n.searchParams.delete("ticket"),n.hash="",this.actionUrl=n}ready(){return this.invokeRaw("runtime.ready",{},{})}supports(e){return e in rf}invoke(e,n={},i={}){return this.invokeRaw(e,n??{},i)}send(){throw new M("Fire-and-forget actions require the realtime transport.")}async invokeRaw(e,n,i){let t=kb(i);try{for(let o=0;o<2;o+=1){let a=await bb(this.fetch,this.request(e,n,t.signal));if(a.status===401&&o===0&&this.refresh!==void 0){await this.refreshAuthorization();continue}let s=await yb(a);if(!a.ok||s.error!==void 0)throw Fe("runtime",s.error,a);return s.data}throw new L(`Runtime action ${e} could not be authorized.`,{source:"runtime",status:401,code:"AuthenticationRequired"})}finally{t.dispose()}}request(e,n,i){let t=rf[e];if(t===void 0)throw new M(`Runtime action ${e} requires the realtime transport.`);let o=new URL(this.actionUrl);o.pathname+=t.path;let a={Accept:"application/json, application/octet-stream",Authorization:`Bearer ${this.ticket}`},s=xb(e,n,o,a);return _t(o,{method:t.method,headers:a,body:t.method==="GET"?void 0:s,signal:i})}async refreshAuthorization(){this.refreshPromise===null&&(this.refreshPromise=this.refresh().then(e=>this.configure(e)));try{await this.refreshPromise}finally{this.refreshPromise=null}}};async function bb(r,e){try{return await r(e)}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?n:new U("Unable to reach the PHPSandbox runtime.","ConnectionFailed",n)}}async function yb(r){if(r.ok&&r.headers.get("content-type")?.toLowerCase().startsWith("application/octet-stream"))return{data:new Uint8Array(await r.arrayBuffer())};let e=await r.text();if(e===""){if(r.ok)throw new U("PHPSandbox runtime returned an empty response.","InvalidResponse",r);return{}}try{return JSON.parse(e)}catch(n){throw new U("PHPSandbox runtime returned an invalid JSON response.","InvalidResponse",n)}}function xb(r,e,n,i){let t=Di(e);if(r==="fs.readFile"){Ui(n,"path",t.path);let o=Di(t.lineRange);(o.lineStart!==void 0||o.lineEnd!==void 0)&&(Ui(n,"lineStart",o.lineStart),Ui(n,"lineEnd",o.lineEnd));return}if(r==="fs.writeFile"){Ui(n,"path",t.path);let o=Di(t.options);$l(n,"overwrite",o.overwrite),$l(n,"create",o.create),$l(n,"unlock",o.unlock);let a=Di(o.atomic);if(typeof a.postfix=="string"&&a.postfix!==""&&n.searchParams.set("atomicPostfix",a.postfix),!ArrayBuffer.isView(t.contents))throw new TypeError("Runtime file contents must be binary data.");return i["Content-Type"]="application/octet-stream",Uint8Array.from(new Uint8Array(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength)).buffer}return i["Content-Type"]="application/json",JSON.stringify(e)}function Di(r){return r!==null&&typeof r=="object"?r:{}}function Ui(r,e,n){if(typeof n!="string"&&typeof n!="number"||String(n)==="")throw new TypeError(`Runtime file ${e} is required.`);r.searchParams.set(e,String(n))}function $l(r,e,n){r.searchParams.set(e,n===!0?"true":"false")}function kb(r){if(r.timeout===void 0&&r.abortSignal===void 0)return{signal:new AbortController().signal,dispose:()=>{}};let e=new AbortController,n=()=>e.abort(r.abortSignal?.reason);r.abortSignal?.addEventListener("abort",n,{once:!0}),r.abortSignal?.aborted&&n();let i=r.timeout===void 0?void 0:setTimeout(()=>e.abort(),r.timeout);return{signal:e.signal,dispose:()=>{r.abortSignal?.removeEventListener("abort",n),i!==void 0&&clearTimeout(i)}}}var Ni=class{constructor(e,n){this.client=e;this.notebookId=n}async configure(e){return(await this.client.put(this.path("/configuration"),e)).data}async configuration(){return(await this.client.get(this.path("/configuration"))).data}async submit(e){return(await this.client.post(this.path(),e)).data}async list(e={}){let n=new URLSearchParams;for(let[i,t]of Object.entries(e))t!==void 0&&n.set(i,String(t));return this.client.get(`${this.path()}${n.size===0?"":`?${n.toString()}`}`)}async get(e){return(await this.client.get(this.path(`/${encodeURIComponent(e)}`))).data}async update(e,n){return(await this.client.patch(this.path(`/${encodeURIComponent(e)}`),n)).data}path(e=""){return`/notebook/${this.notebookId}/feedback${e}`}};var Ri=class{constructor(e){this.client=e}async link(e){let n=await this.client.post("/integrations",e);return new Ze(n.data,this.client)}async list(){return(await this.client.get("/integrations")).data.map(n=>new Ze(n,this.client))}async get(e){let n=await this.client.get(`/integrations/${encodeURIComponent(ji(e))}`);return new Ze(n.data,this.client)}},Ze=class r{constructor(e,n){this.data=e;this.client=n}get id(){return this.data.id}get provider(){return this.data.provider}get label(){return this.data.label}async update(e){let n=await this.client.patch(`/integrations/${encodeURIComponent(this.id)}`,e);return new r(n.data,this.client)}async unlink(){await this.client.delete(`/integrations/${encodeURIComponent(this.id)}`)}};function ji(r){return typeof r=="string"?r:r.id}var Ai=class{constructor(e,n){this.notebookId=e;this.client=n}async attach(e){let n=await this.client.post(this.path(),{...e,integration:ji(e.integration)});return new zr(n.data,this.notebookId,this.client)}async list(){return(await this.client.get(this.path())).data.map(n=>new zr(n,this.notebookId,this.client))}async get(e){let n=await this.client.get(this.bindingPath(e));return new zr(n.data,this.notebookId,this.client)}path(){return`/notebook/${this.notebookId}/integrations`}bindingPath(e){return`${this.path()}/${encodeURIComponent($b(e))}`}},zr=class r{constructor(e,n,i){this.data=e;this.notebookId=n;this.client=i}get id(){return this.data.id}get integration(){return new Ze(this.data.integration,this.client)}get effects(){return this.data.effects}async update(e){let n=await this.client.patch(this.path(),{...e,integration:e.integration===void 0?void 0:ji(e.integration)});return new r(n.data,this.notebookId,this.client)}async detach(){await this.client.delete(this.path())}path(){return`/notebook/${this.notebookId}/integrations/${encodeURIComponent(this.id)}`}};function $b(r){return typeof r=="string"?r:r.id}function _b(r){return Array.isArray(r)?r:Object.entries(r).map(([e,n])=>({name:e,...typeof n=="string"?{value:n}:n}))}var wl=class{constructor(e){this.client=e}async list(e={}){return this.client.get(`/notebook${nf({page:e.page,per_page:e.perPage})}`)}async inspectImport(e){return(await this.client.post("/notebook/imports/inspect",e)).data}async create(e,n={}){let i=await this.client.post("/notebook",{template:e,...n});return new wt(i.data,this.client)}async get(e){let n=await this.client.get(`/notebook/${e}`);return new wt(n.data,this.client)}open(e){return new wt(e,this.client)}};function wb(r){let e=new URL(r),n=e.pathname.replace(/\/+$/,"");return e.pathname=n===""||n==="/"?"/v1/":`${n}/`,e.search="",e.hash="",e.toString()}var Ci=class{constructor(e,n="https://api.phpsandbox.io/v1",i={},t="realtime"){this.fetch=globalThis.fetch;this.publications=new zi(this),this.notebook=new wl(this),this.servers=new Ei(this),this.integrations=new Ri(this),this.options={...i},this.runtimeTransportValue=t,this.baseUrl=wb(n),i.fetch&&(this.fetch=i.fetch),this.headers={Accept:"application/json",Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}get runtimeTransport(){return this.runtimeTransportValue}get(e){return this.makeRequest("GET",e)}post(e,n){return this.makeRequest("POST",e,{body:n===void 0?void 0:JSON.stringify(n)})}delete(e){return this.makeRequest("DELETE",e)}put(e,n){return this.makeRequest("PUT",e,{body:n===void 0?void 0:JSON.stringify(n)})}patch(e,n){return this.makeRequest("PATCH",e,{body:n===void 0?void 0:JSON.stringify(n)})}async stream(e){let n=await this.fetchResponse(_t(new URL(e.replace(/^\//,""),this.baseUrl),{method:"GET",headers:this.headers}));if(!n.ok)throw await _l(n);if(!n.body)throw new U("PHPSandbox API response body is not readable.","InvalidResponse",n);return n.body}async sse(e,n){let i=await this.fetchResponse(_t(e,{method:"GET",headers:{...this.headers,Accept:"text/event-stream"},...n===void 0?{}:{signal:n}}));if(!i.ok)throw await _l(i);if(!i.body)throw new U("PHPSandbox API SSE response body is not readable.","InvalidResponse",i);return i.body}async makeRequest(e,n,i){let t=await this.fetchResponse(_t(new URL(n.replace(/^\//,""),this.baseUrl),{method:e,...i,headers:this.headers}));if(!t.ok)throw await _l(t);if(t.status===204)return{data:void 0};let o=await t.text();if(o==="")throw new U("PHPSandbox API returned an empty response.","InvalidResponse",t);try{let a=JSON.parse(o);if(a===null||typeof a!="object"||Array.isArray(a)||!Object.prototype.hasOwnProperty.call(a,"data"))throw new U("PHPSandbox API returned an invalid success response.","InvalidResponse",t);return a}catch(a){throw U.is(a)?a:new U("PHPSandbox API returned an invalid JSON response.","InvalidResponse",a)}}async fetchResponse(e){try{return await this.fetch(e)}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?n:new U("Unable to reach the PHPSandbox API.","ConnectionFailed",n)}}};async function _l(r){let e=await r.text();try{return Fe("core",Sb(e===""?void 0:JSON.parse(e)),r)}catch{return new U(`PHPSandbox API returned an invalid error response (HTTP ${r.status}).`,"InvalidResponse",r,{status:r.status,statusText:r.statusText,body:e})}}function Sb(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)?r.error:void 0}var Sl=class r{constructor(e){this.client=e;this.notebook=e.notebook,this.publications=e.publications,this.servers=e.servers,this.integrations=e.integrations}get runtimeTransport(){return this.client.runtimeTransport}static realtime(e,n="https://api.phpsandbox.io/v1",i={}){return new r(new Ci(e,n,i))}static rest(e,n="https://api.phpsandbox.io/v1",i={}){return new r(new Ci(e,n,i,"rest"))}},te,Er,Il,Tl=class Tl{constructor(e,n){this.data=e;this.client=n;It(this,Er);this.initialized=!1;It(this,te,null);this.disposables=[];let i=n.options.runtimeUrlProvider;if(this.emitter=Wt.createInstance(),n.runtimeTransport==="rest")this.socket=null,this.restInvoker=new Oi(e,n.options.fetch??globalThis.fetch,i===void 0?void 0:()=>i(e.id));else{this.restInvoker=null;let t=!0,o=i===void 0?e.runtimeUrl:async()=>t?(t=!1,e.runtimeUrl):i(e.id);this.socket=new Br(o,this.emitter,{debug:n.options.debug,webSocket:n.options.webSocket}),this.watchConnection(),Tr(this,te,pe(this,Er,Il).call(this))}this.files=new Dr(this,this.socket===null?null:t=>this.onDidConnect(t)),this.terminals=new zt(this),this.auth=new Et(this),this.lsp=new Tt(this),this.composer=new Ot(this,n),this.runtime=new At(this),this.repl=new Ct(this),this.shell=new Ut(this),this.git=new Vt(this,n),this.services=new Zt(this),this.config=new Lt(this),this.secrets=new Pl(n,this.data.id),this.integrations=new Ai(this.data.id,n),this.preview=new zl(n,this.data.id),this.mail=new El(n,this.data.id),this.feedback=new Ni(n,this.data.id)}get runtimeTransport(){return this.client.runtimeTransport}async ready(){if(this.restInvoker!==null)return this.restInitialization();let e=this.realtimeSocket(),n=e.getTerminalError();if(n)throw n;return(async()=>(e.isConnected||await e.connect(),Se(this,te)))()}async fork(e={}){let n=await this.client.post(`/notebook/${this.data.id}/fork`,e);return new Tl(n.data,this.client)}async publication(){try{let e=await this.client.get(`/notebook/${this.data.id}/publication`);return new $t(e.data,this.client,this.data.id)}catch(e){if(L.is(e)&&e.status===404)return null;throw e}}async publish(e){let n=await this.client.post(`/notebook/${this.data.id}/publication`,e),i=new Pr(new $t(n.data,this.client,this.data.id),this.client);return i.start(),i}run(e,n=[],i){return Array.isArray(n)?this.shell.run(e,n,i):this.shell.run(e,n)}exec(e,n=[],i){return Array.isArray(n)?this.run(e,n,i).wait():this.run(e,n).wait()}async destroy(){await this.client.delete(`/notebook/${this.data.id}`),this.socket?.terminate(new L("Notebook has been deleted.",{source:"runtime",status:503,code:"NotebookUnavailable",details:{id:this.data.id}}))}restart(){return this.invoke("container.restart")}stop(){return this.invoke("container.stop")}invoke(e,n={},i={}){return this.restInvoker!==null?(this.restInvoker.supports(String(e))&&this.restInitialization(),this.restInvoker.invoke(e,n||{},i)):this.realtimeSocket().invoke(e,n||{},i)}send(e,n={}){return this.restInvoker!==null?this.restInvoker.send():this.realtimeSocket().send(e,n||{})}listen(e,n){let i=this.emitter.listen(e,n);return this.disposables.push(i),i}dispose(){this.disposables.forEach(e=>e.dispose()),this.socket!==null&&!this.socket.isClosed&&this.socket.disconnect()}connected(){return this.waitForSocketConnection({rejectOnClose:!0})}waitForSocketConnection(e){let n=this.realtimeSocket(),i=n.getTerminalError();return i?Promise.reject(i):n.isConnected?Promise.resolve(this):new Promise((t,o)=>{let a=[],s=!1,c=()=>{for(let l of a)l.dispose();a.length=0},u=l=>{s||(s=!0,c(),l())};try{a.push(n.onDidConnect(()=>u(()=>t(this)))),e.rejectOnClose&&a.push(n.onDidClose(()=>u(()=>o(new Error("Connection closed"))))),a.push(n.onDidBootError(l=>u(()=>o(l))))}catch(l){u(()=>o(l))}})}watchConnection(){let e=this.realtimeSocket();e.onDidConnect(()=>{e.emit("okra.connected")}),e.onDidClose(()=>{e.emit("okra.disconnected"),this.initialized=!1}),e.onDidBootError(n=>{e.emit("okra.boot_error",n),e.emit("okra.disconnected"),this.initialized=!1})}onDidConnect(e){let n=this.realtimeSocket();n.removeListener("okra.connected",e);let i=n.listen("okra.connected",e);return this.disposables.push(i),i}onDidDisconnect(e){let n=this.realtimeSocket().listen("okra.disconnected",e);return this.disposables.push(n),n}onDidBootError(e){let n=this.realtimeSocket().listen("okra.boot_error",e);return this.disposables.push(n),n}restInitialization(){if(this.restInvoker===null)throw new M("This operation requires the REST transport.");return Se(this,te)===null&&(Tr(this,te,this.restInvoker.ready().then(e=>(this.initialized=e,this.emitter.emit("notebook.initialized",e),e))),Se(this,te).catch(()=>{})),Se(this,te)}onDidInitialize(e){return this.listen("notebook.initialized",e)}async reconnect(){let e=this.realtimeSocket(),n=this.waitForSocketConnection({rejectOnClose:!1});return e.reconnect(),this.initialized=!1,await n,pe(this,Er,Il).call(this),this.ready().then(()=>this)}realtimeSocket(){if(this.socket===null)throw new M("This operation requires the realtime transport.");return this.socket}};te=new WeakMap,Er=new WeakSet,Il=function(){return Tr(this,te,new Promise((e,n)=>{let i=this.onDidInitialize(o=>{if(t.dispose(),i.dispose(),this.initialized=o,o.type==="error"){n(new L(o.message,{source:"runtime",status:503,code:"NotebookInitializationFailed",details:o.data}));return}e(o)}),t=this.onDidBootError(o=>{i.dispose(),t.dispose(),n(o)})})),Se(this,te).catch(()=>{}),Se(this,te)};var wt=Tl,Pl=class{constructor(e,n){this.client=e;this.notebookId=n}async list(e){let n=new URLSearchParams;e?.environment&&n.set("environment",e.environment);let i=n.toString();return(await this.client.get(`/notebook/${this.notebookId}/secrets${i?`?${i}`:""}`)).data}async set(e,n){let i=typeof n=="string"?{name:e,value:n}:{name:e,...n};return(await this.client.put(`/notebook/${this.notebookId}/secrets`,i)).data}async setMany(e){return(await this.client.put(`/notebook/${this.notebookId}/secrets`,{secrets:_b(e)})).data}async delete(e,n){let i=new URLSearchParams;n?.environment&&i.set("environment",n.environment);let t=i.toString();await this.client.delete(`/notebook/${this.notebookId}/secrets/${encodeURIComponent(e)}${t?`?${t}`:""}`)}},zl=class{constructor(e,n){this.client=e;this.notebookId=n}async get(e){let n=e===void 0?"":`?${new URLSearchParams({url:e}).toString()}`;return(await this.client.get(`/notebook/${this.notebookId}/preview${n}`)).data}async setPassword(e){return(await this.client.put(`/notebook/${this.notebookId}/preview`,e)).data}async disable(){await this.client.delete(`/notebook/${this.notebookId}/preview`)}async createSession(e){return(await this.client.post(`/notebook/${this.notebookId}/preview/session`,e)).data}async createHandoff(e){return(await this.client.post(`/notebook/${this.notebookId}/preview/handoff`,e)).data}},El=class{constructor(e,n){this.client=e;this.notebookId=n}async status(){return(await this.client.get(`/notebook/${this.notebookId}/mail`)).data}async enable(){return(await this.client.put(`/notebook/${this.notebookId}/mail`)).data}async disable(){await this.client.delete(`/notebook/${this.notebookId}/mail`)}async list(e={}){return this.client.get(`/notebook/${this.notebookId}/mails${nf(e)}`)}async get(e){return(await this.client.get(`/notebook/${this.notebookId}/mails/${encodeURIComponent(e)}`)).data}async delete(e){await this.client.delete(`/notebook/${this.notebookId}/mails/${encodeURIComponent(e)}`)}};function nf(r){let e=new URLSearchParams;for(let[i,t]of Object.entries(r))(typeof t=="string"||typeof t=="number"||typeof t=="boolean")&&e.set(i,String(t));let n=e.toString();return n===""?"":`?${n}`}return lf(Ib);})();
70
+ `);i=a.pop()??"";for(let s of a){let c=s.trim();c!==""&&o.enqueue(e.parse(JSON.parse(c)))}},flush(t){i+=n.decode();let o=i.trim();o!==""&&t.enqueue(e.parse(JSON.parse(o)))}}))}var Ei=class{constructor(e){this.client=e}async list(e={}){let n=e.page===void 0?"":`?${new URLSearchParams({page:String(e.page)}).toString()}`;return this.client.get(`/servers${n}`)}async create(e){let n=await this.client.post("/servers",e);return new Ti(n.data,this.client)}async get(e){let n=await this.client.get(`/servers/${e}`);return new Ti(n.data,this.client)}},Ti=class{constructor(e,n){this.data=e;this.client=n}refresh(){return this.client.servers.get(this.data.id)}async delete(){await this.client.delete(`/servers/${this.data.id}`)}async waitReady(e){let n=e?.timeout??3e5,i=e?.interval??3e3,t=Date.now()+n;for(;Date.now()<t;){let o=await this.refresh();if(o.data.status==="connected")return o;if(o.data.status==="failed")throw new Error(`Server provisioning failed: ${o.data.id}`);await new Promise(a=>setTimeout(a,i))}throw new Error(`Server did not become ready within ${n}ms`)}};function _t(r,e){return new Request(r,{...e,redirect:"manual"})}var rf={"runtime.ready":{method:"GET",path:"/runtime"},"config.get":{method:"GET",path:"/runtime/config"},"config.update":{method:"PATCH",path:"/runtime/config"},"config.set-ports":{method:"PUT",path:"/runtime/config/ports"},"container.restart":{method:"POST",path:"/runtime/container/restart"},"container.stop":{method:"POST",path:"/runtime/container/stop"},"container.set-php":{method:"PUT",path:"/runtime/container/php"},"container.opened-ports":{method:"GET",path:"/runtime/container/ports"},"container.resolve-port":{method:"POST",path:"/runtime/container/ports/resolve"},"container.stats":{method:"GET",path:"/runtime/container/stats"},"terminal.list":{method:"GET",path:"/runtime/terminals"},"shell.exec":{method:"POST",path:"/runtime/executions"},"fs.readFile":{method:"GET",path:"/runtime/files/content"},"fs.writeFile":{method:"PUT",path:"/runtime/files/content"},"fs.createDirectory":{method:"PUT",path:"/runtime/directories"},"fs.readDirectory":{method:"POST",path:"/runtime/directories/read"},"fs.stat":{method:"POST",path:"/runtime/files/stat"},"fs.rename":{method:"POST",path:"/runtime/files/rename"},"fs.copy":{method:"POST",path:"/runtime/files/copy"},"fs.delete":{method:"DELETE",path:"/runtime/files"},"fs.tail":{method:"POST",path:"/runtime/files/tail"},"fs.find":{method:"POST",path:"/runtime/files/find"},"fs.textSearch":{method:"POST",path:"/runtime/files/search"},"fs.tree":{method:"POST",path:"/runtime/files/tree"},"service.list":{method:"GET",path:"/runtime/services"},"service.run":{method:"POST",path:"/runtime/services/run"},"service.stop":{method:"POST",path:"/runtime/services/stop"},"service.logs":{method:"POST",path:"/runtime/services/logs"},"composer.invoke":{method:"POST",path:"/runtime/composer/executions"},"composer.packages":{method:"GET",path:"/runtime/composer/packages"},"git.checkpoint":{method:"POST",path:"/runtime/git/checkpoints"},"git.checkout":{method:"POST",path:"/runtime/git/checkouts"},"git.log":{method:"POST",path:"/runtime/git/log"},"git.sync":{method:"POST",path:"/runtime/git/sync"},"git.diff":{method:"POST",path:"/runtime/git/diff"},"git.merge":{method:"POST",path:"/runtime/git/merge"},"git.conflicts":{method:"GET",path:"/runtime/git/conflicts"},"git.resolve":{method:"POST",path:"/runtime/git/conflicts/resolve"},"git.restore":{method:"POST",path:"/runtime/git/restore"},"git.status":{method:"GET",path:"/runtime/git/status"},"git.review":{method:"GET",path:"/runtime/git/review"},"git.stage":{method:"POST",path:"/runtime/git/stage"},"git.unstage":{method:"POST",path:"/runtime/git/unstage"},"git.revert":{method:"POST",path:"/runtime/git/revert"}},Oi=class{constructor(e,n,i){this.fetch=n;this.refresh=i;this.refreshPromise=null;this.notebookId=e.id,this.configure(e.runtimeUrl)}configure(e){let n=new URL(e),i=n.searchParams.get("ticket")??"";if(i==="")throw new M("The notebook connection does not contain a runtime ticket.");this.ticket=i,n.protocol==="wss:"?n.protocol="https:":n.protocol==="ws:"&&(n.protocol="http:"),n.pathname=`/api/v1/notebooks/${encodeURIComponent(this.notebookId)}`,n.searchParams.delete("ticket"),n.hash="",this.actionUrl=n}ready(){return this.invokeRaw("runtime.ready",{},{})}supports(e){return e in rf}invoke(e,n={},i={}){return this.invokeRaw(e,n??{},i)}send(){throw new M("Fire-and-forget actions require the realtime transport.")}async invokeRaw(e,n,i){let t=kb(i);try{for(let o=0;o<2;o+=1){let a=await bb(this.fetch,this.request(e,n,t.signal));if(a.status===401&&o===0&&this.refresh!==void 0){await this.refreshAuthorization();continue}let s=await yb(a);if(!a.ok||s.error!==void 0)throw Fe("runtime",s.error,a);return s.data}throw new L(`Runtime action ${e} could not be authorized.`,{source:"runtime",status:401,code:"AuthenticationRequired"})}finally{t.dispose()}}request(e,n,i){let t=rf[e];if(t===void 0)throw new M(`Runtime action ${e} requires the realtime transport.`);let o=new URL(this.actionUrl);o.pathname+=t.path;let a={Accept:"application/json, application/octet-stream",Authorization:`Bearer ${this.ticket}`},s=xb(e,n,o,a);return _t(o,{method:t.method,headers:a,body:t.method==="GET"?void 0:s,signal:i})}async refreshAuthorization(){this.refreshPromise===null&&(this.refreshPromise=this.refresh().then(e=>this.configure(e)));try{await this.refreshPromise}finally{this.refreshPromise=null}}};async function bb(r,e){try{return await r(e)}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?n:new U("Unable to reach the PHPSandbox runtime.","ConnectionFailed",n)}}async function yb(r){if(r.ok&&r.headers.get("content-type")?.toLowerCase().startsWith("application/octet-stream"))return{data:new Uint8Array(await r.arrayBuffer())};let e=await r.text();if(e===""){if(r.ok)throw new U("PHPSandbox runtime returned an empty response.","InvalidResponse",r);return{}}try{return JSON.parse(e)}catch(n){throw new U("PHPSandbox runtime returned an invalid JSON response.","InvalidResponse",n)}}function xb(r,e,n,i){let t=Di(e);if(r==="fs.readFile"){Ui(n,"path",t.path);let o=Di(t.lineRange);(o.lineStart!==void 0||o.lineEnd!==void 0)&&(Ui(n,"lineStart",o.lineStart),Ui(n,"lineEnd",o.lineEnd));return}if(r==="fs.writeFile"){Ui(n,"path",t.path);let o=Di(t.options);$l(n,"overwrite",o.overwrite),$l(n,"create",o.create),$l(n,"unlock",o.unlock);let a=Di(o.atomic);if(typeof a.postfix=="string"&&a.postfix!==""&&n.searchParams.set("atomicPostfix",a.postfix),!ArrayBuffer.isView(t.contents))throw new TypeError("Runtime file contents must be binary data.");return i["Content-Type"]="application/octet-stream",Uint8Array.from(new Uint8Array(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength)).buffer}return i["Content-Type"]="application/json",JSON.stringify(e)}function Di(r){return r!==null&&typeof r=="object"?r:{}}function Ui(r,e,n){if(typeof n!="string"&&typeof n!="number"||String(n)==="")throw new TypeError(`Runtime file ${e} is required.`);r.searchParams.set(e,String(n))}function $l(r,e,n){r.searchParams.set(e,n===!0?"true":"false")}function kb(r){if(r.timeout===void 0&&r.abortSignal===void 0)return{signal:new AbortController().signal,dispose:()=>{}};let e=new AbortController,n=()=>e.abort(r.abortSignal?.reason);r.abortSignal?.addEventListener("abort",n,{once:!0}),r.abortSignal?.aborted&&n();let i=r.timeout===void 0?void 0:setTimeout(()=>e.abort(),r.timeout);return{signal:e.signal,dispose:()=>{r.abortSignal?.removeEventListener("abort",n),i!==void 0&&clearTimeout(i)}}}var Ni=class{constructor(e,n){this.client=e;this.notebookId=n}async configure(e){return(await this.client.put(this.path("/configuration"),e)).data}async configuration(){return(await this.client.get(this.path("/configuration"))).data}async submit(e){return(await this.client.post(this.path(),e)).data}async list(e={}){let n=new URLSearchParams;for(let[i,t]of Object.entries(e))t!==void 0&&n.set(i,String(t));return this.client.get(`${this.path()}${n.size===0?"":`?${n.toString()}`}`)}async get(e){return(await this.client.get(this.path(`/${encodeURIComponent(e)}`))).data}async update(e,n){return(await this.client.patch(this.path(`/${encodeURIComponent(e)}`),n)).data}path(e=""){return`/notebook/${this.notebookId}/feedback${e}`}};var Ri=class{constructor(e){this.client=e}async link(e){let n=await this.client.post("/integrations",e);return new Ze(n.data,this.client)}async list(){return(await this.client.get("/integrations")).data.map(n=>new Ze(n,this.client))}async get(e){let n=await this.client.get(`/integrations/${encodeURIComponent(ji(e))}`);return new Ze(n.data,this.client)}},Ze=class r{constructor(e,n){this.data=e;this.client=n}get id(){return this.data.id}get provider(){return this.data.provider}get label(){return this.data.label}async update(e){let n=await this.client.patch(`/integrations/${encodeURIComponent(this.id)}`,e);return new r(n.data,this.client)}async unlink(){await this.client.delete(`/integrations/${encodeURIComponent(this.id)}`)}};function ji(r){return typeof r=="string"?r:r.id}var Ai=class{constructor(e,n){this.notebookId=e;this.client=n}async attach(e){let n=await this.client.post(this.path(),{...e,integration:ji(e.integration)});return new zr(n.data,this.notebookId,this.client)}async list(){return(await this.client.get(this.path())).data.map(n=>new zr(n,this.notebookId,this.client))}async get(e){let n=await this.client.get(this.bindingPath(e));return new zr(n.data,this.notebookId,this.client)}path(){return`/notebook/${this.notebookId}/integrations`}bindingPath(e){return`${this.path()}/${encodeURIComponent($b(e))}`}},zr=class r{constructor(e,n,i){this.data=e;this.notebookId=n;this.client=i}get id(){return this.data.id}get integration(){return new Ze(this.data.integration,this.client)}get effects(){return this.data.effects}async update(e){let n=await this.client.patch(this.path(),{...e,integration:e.integration===void 0?void 0:ji(e.integration)});return new r(n.data,this.notebookId,this.client)}async detach(){await this.client.delete(this.path())}path(){return`/notebook/${this.notebookId}/integrations/${encodeURIComponent(this.id)}`}};function $b(r){return typeof r=="string"?r:r.id}function _b(r){return Array.isArray(r)?r:Object.entries(r).map(([e,n])=>({name:e,...typeof n=="string"?{value:n}:n}))}var wl=class{constructor(e){this.client=e}async list(e={}){return this.client.get(`/notebook${nf({page:e.page,per_page:e.perPage})}`)}async inspectImport(e){return(await this.client.post("/notebook/imports/inspect",e)).data}async create(e,n={}){let i=await this.client.post("/notebook",{template:e,...n});return new wt(i.data,this.client)}async get(e){let n=await this.client.get(`/notebook/${e}`);return new wt(n.data,this.client)}open(e){return new wt(e,this.client)}};function wb(r){let e=new URL(r),n=e.pathname.replace(/\/+$/,"");return e.pathname=n===""||n==="/"?"/v1/":`${n}/`,e.search="",e.hash="",e.toString()}var Ci=class{constructor(e,n="https://api.phpsandbox.io/v1",i={},t="realtime"){this.fetch=globalThis.fetch;this.publications=new zi(this),this.notebook=new wl(this),this.servers=new Ei(this),this.integrations=new Ri(this),this.options={...i},this.runtimeTransportValue=t,this.baseUrl=wb(n),i.fetch&&(this.fetch=i.fetch),this.headers={Accept:"application/json",Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}get runtimeTransport(){return this.runtimeTransportValue}get(e){return this.makeRequest("GET",e)}post(e,n){return this.makeRequest("POST",e,{body:n===void 0?void 0:JSON.stringify(n)})}delete(e){return this.makeRequest("DELETE",e)}put(e,n){return this.makeRequest("PUT",e,{body:n===void 0?void 0:JSON.stringify(n)})}patch(e,n){return this.makeRequest("PATCH",e,{body:n===void 0?void 0:JSON.stringify(n)})}async stream(e){let n=await this.fetchResponse(_t(new URL(e.replace(/^\//,""),this.baseUrl),{method:"GET",headers:this.headers}));if(!n.ok)throw await _l(n);if(!n.body)throw new U("PHPSandbox API response body is not readable.","InvalidResponse",n);return n.body}async sse(e,n){let i=await this.fetchResponse(_t(e,{method:"GET",headers:{...this.headers,Accept:"text/event-stream"},...n===void 0?{}:{signal:n}}));if(!i.ok)throw await _l(i);if(!i.body)throw new U("PHPSandbox API SSE response body is not readable.","InvalidResponse",i);return i.body}async makeRequest(e,n,i){let t=await this.fetchResponse(_t(new URL(n.replace(/^\//,""),this.baseUrl),{method:e,...i,headers:this.headers}));if(!t.ok)throw await _l(t);if(t.status===204)return{data:void 0};let o=await t.text();if(o==="")throw new U("PHPSandbox API returned an empty response.","InvalidResponse",t);try{let a=JSON.parse(o);if(a===null||typeof a!="object"||Array.isArray(a)||!Object.prototype.hasOwnProperty.call(a,"data"))throw new U("PHPSandbox API returned an invalid success response.","InvalidResponse",t);return a}catch(a){throw U.is(a)?a:new U("PHPSandbox API returned an invalid JSON response.","InvalidResponse",a)}}async fetchResponse(e){try{return await this.fetch(e)}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?n:new U("Unable to reach the PHPSandbox API.","ConnectionFailed",n)}}};async function _l(r){let e=await r.text();try{return Fe("core",Sb(e===""?void 0:JSON.parse(e)),r)}catch{return new U(`PHPSandbox API returned an invalid error response (HTTP ${r.status}).`,"InvalidResponse",r,{status:r.status,statusText:r.statusText,body:e})}}function Sb(r){return r!==null&&typeof r=="object"&&!Array.isArray(r)?r.error:void 0}var Sl=class r{constructor(e){this.client=e;this.notebook=e.notebook,this.publications=e.publications,this.servers=e.servers,this.integrations=e.integrations}get runtimeTransport(){return this.client.runtimeTransport}static realtime(e,n="https://api.phpsandbox.io/v1",i={}){return new r(new Ci(e,n,i))}static rest(e,n="https://api.phpsandbox.io/v1",i={}){return new r(new Ci(e,n,i,"rest"))}},te,Er,Il,Tl=class Tl{constructor(e,n){this.data=e;this.client=n;It(this,Er);this.initialized=!1;It(this,te,null);this.disposables=[];let i=n.options.runtimeUrlProvider;if(this.emitter=Wt.createInstance(),n.runtimeTransport==="rest")this.socket=null,this.restInvoker=new Oi(e,n.options.fetch??globalThis.fetch,i===void 0?void 0:()=>i(e.id));else{this.restInvoker=null;let t=!0,o=i===void 0?e.runtimeUrl:async()=>t?(t=!1,e.runtimeUrl):i(e.id);this.socket=new Br(o,this.emitter,{debug:n.options.debug,webSocket:n.options.webSocket}),this.watchConnection(),Tr(this,te,pe(this,Er,Il).call(this))}this.files=new Dr(this,this.socket===null?null:t=>this.onDidConnect(t)),this.terminals=new zt(this),this.auth=new Et(this),this.lsp=new Tt(this),this.composer=new Ot(this,n),this.runtime=new At(this),this.repl=new Ct(this),this.shell=new Ut(this),this.git=new Vt(this,n),this.services=new Zt(this),this.config=new Lt(this),this.secrets=new Pl(n,this.data.id),this.integrations=new Ai(this.data.id,n),this.preview=new zl(n,this.data.id),this.mail=new El(n,this.data.id),this.feedback=new Ni(n,this.data.id)}get runtimeTransport(){return this.client.runtimeTransport}async ready(){if(this.restInvoker!==null)return this.restInitialization();let e=this.realtimeSocket(),n=e.getTerminalError();if(n)throw n;return(async()=>(e.isConnected||await e.connect(),Se(this,te)))()}async update(e){let n=await this.client.put(`/notebook/${this.data.id}`,e);return Object.assign(this.data,n.data),this.data}async fork(e={}){let n=await this.client.post(`/notebook/${this.data.id}/fork`,e);return new Tl(n.data,this.client)}async publication(){try{let e=await this.client.get(`/notebook/${this.data.id}/publication`);return new $t(e.data,this.client,this.data.id)}catch(e){if(L.is(e)&&e.status===404)return null;throw e}}async publish(e){let n=await this.client.post(`/notebook/${this.data.id}/publication`,e),i=new Pr(new $t(n.data,this.client,this.data.id),this.client);return i.start(),i}run(e,n=[],i){return Array.isArray(n)?this.shell.run(e,n,i):this.shell.run(e,n)}exec(e,n=[],i){return Array.isArray(n)?this.run(e,n,i).wait():this.run(e,n).wait()}async destroy(){await this.client.delete(`/notebook/${this.data.id}`),this.socket?.terminate(new L("Notebook has been deleted.",{source:"runtime",status:503,code:"NotebookUnavailable",details:{id:this.data.id}}))}restart(){return this.invoke("container.restart")}stop(){return this.invoke("container.stop")}invoke(e,n={},i={}){return this.restInvoker!==null?(this.restInvoker.supports(String(e))&&this.restInitialization(),this.restInvoker.invoke(e,n||{},i)):this.realtimeSocket().invoke(e,n||{},i)}send(e,n={}){return this.restInvoker!==null?this.restInvoker.send():this.realtimeSocket().send(e,n||{})}listen(e,n){let i=this.emitter.listen(e,n);return this.disposables.push(i),i}dispose(){this.disposables.forEach(e=>e.dispose()),this.socket!==null&&!this.socket.isClosed&&this.socket.disconnect()}connected(){return this.waitForSocketConnection({rejectOnClose:!0})}waitForSocketConnection(e){let n=this.realtimeSocket(),i=n.getTerminalError();return i?Promise.reject(i):n.isConnected?Promise.resolve(this):new Promise((t,o)=>{let a=[],s=!1,c=()=>{for(let l of a)l.dispose();a.length=0},u=l=>{s||(s=!0,c(),l())};try{a.push(n.onDidConnect(()=>u(()=>t(this)))),e.rejectOnClose&&a.push(n.onDidClose(()=>u(()=>o(new Error("Connection closed"))))),a.push(n.onDidBootError(l=>u(()=>o(l))))}catch(l){u(()=>o(l))}})}watchConnection(){let e=this.realtimeSocket();e.onDidConnect(()=>{e.emit("okra.connected")}),e.onDidClose(()=>{e.emit("okra.disconnected"),this.initialized=!1}),e.onDidBootError(n=>{e.emit("okra.boot_error",n),e.emit("okra.disconnected"),this.initialized=!1})}onDidConnect(e){let n=this.realtimeSocket();n.removeListener("okra.connected",e);let i=n.listen("okra.connected",e);return this.disposables.push(i),i}onDidDisconnect(e){let n=this.realtimeSocket().listen("okra.disconnected",e);return this.disposables.push(n),n}onDidBootError(e){let n=this.realtimeSocket().listen("okra.boot_error",e);return this.disposables.push(n),n}restInitialization(){if(this.restInvoker===null)throw new M("This operation requires the REST transport.");return Se(this,te)===null&&(Tr(this,te,this.restInvoker.ready().then(e=>(this.initialized=e,this.emitter.emit("notebook.initialized",e),e))),Se(this,te).catch(()=>{})),Se(this,te)}onDidInitialize(e){return this.listen("notebook.initialized",e)}async reconnect(){let e=this.realtimeSocket(),n=this.waitForSocketConnection({rejectOnClose:!1});return e.reconnect(),this.initialized=!1,await n,pe(this,Er,Il).call(this),this.ready().then(()=>this)}realtimeSocket(){if(this.socket===null)throw new M("This operation requires the realtime transport.");return this.socket}};te=new WeakMap,Er=new WeakSet,Il=function(){return Tr(this,te,new Promise((e,n)=>{let i=this.onDidInitialize(o=>{if(t.dispose(),i.dispose(),this.initialized=o,o.type==="error"){n(new L(o.message,{source:"runtime",status:503,code:"NotebookInitializationFailed",details:o.data}));return}e(o)}),t=this.onDidBootError(o=>{i.dispose(),t.dispose(),n(o)})})),Se(this,te).catch(()=>{}),Se(this,te)};var wt=Tl,Pl=class{constructor(e,n){this.client=e;this.notebookId=n}async list(e){let n=new URLSearchParams;e?.environment&&n.set("environment",e.environment);let i=n.toString();return(await this.client.get(`/notebook/${this.notebookId}/secrets${i?`?${i}`:""}`)).data}async set(e,n){let i=typeof n=="string"?{name:e,value:n}:{name:e,...n};return(await this.client.put(`/notebook/${this.notebookId}/secrets`,i)).data}async setMany(e){return(await this.client.put(`/notebook/${this.notebookId}/secrets`,{secrets:_b(e)})).data}async delete(e,n){let i=new URLSearchParams;n?.environment&&i.set("environment",n.environment);let t=i.toString();await this.client.delete(`/notebook/${this.notebookId}/secrets/${encodeURIComponent(e)}${t?`?${t}`:""}`)}},zl=class{constructor(e,n){this.client=e;this.notebookId=n}async get(e){let n=e===void 0?"":`?${new URLSearchParams({url:e}).toString()}`;return(await this.client.get(`/notebook/${this.notebookId}/preview${n}`)).data}async setPassword(e){return(await this.client.put(`/notebook/${this.notebookId}/preview`,e)).data}async disable(){await this.client.delete(`/notebook/${this.notebookId}/preview`)}async createSession(e){return(await this.client.post(`/notebook/${this.notebookId}/preview/session`,e)).data}async createHandoff(e){return(await this.client.post(`/notebook/${this.notebookId}/preview/handoff`,e)).data}},El=class{constructor(e,n){this.client=e;this.notebookId=n}async status(){return(await this.client.get(`/notebook/${this.notebookId}/mail`)).data}async enable(){return(await this.client.put(`/notebook/${this.notebookId}/mail`)).data}async disable(){await this.client.delete(`/notebook/${this.notebookId}/mail`)}async list(e={}){return this.client.get(`/notebook/${this.notebookId}/mails${nf(e)}`)}async get(e){return(await this.client.get(`/notebook/${this.notebookId}/mails/${encodeURIComponent(e)}`)).data}async delete(e){await this.client.delete(`/notebook/${this.notebookId}/mails/${encodeURIComponent(e)}`)}};function nf(r){let e=new URLSearchParams;for(let[i,t]of Object.entries(r))(typeof t=="string"||typeof t=="number"||typeof t=="boolean")&&e.set(i,String(t));let n=e.toString();return n===""?"":`?${n}`}return lf(Ib);})();
71
71
  /*! Bundled license information:
72
72
 
73
73
  reconnecting-websocket/dist/reconnecting-websocket-mjs.js:
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ import Repl, { ReplActions, ReplEvents } from './repl.js';
9
9
  import { ShellEvents, ShellActions, type ProcessResult, type ShellProcess } from './shell.js';
10
10
  import Services, { ServiceActions, ServiceEvents } from './services.js';
11
11
  import Config, { ConfigActions } from './config.js';
12
- import Git, { GitActions } from './git.js';
12
+ import Git, { GitActions, type GitSyncAuthor } from './git.js';
13
13
  import { Disposable } from './types.js';
14
14
  import { RemoteError } from './errors/index.js';
15
15
  import { PublicationApi, PublicationInstance, PublicationRun, type PublishInput } from './publications.js';
@@ -133,7 +133,12 @@ export interface NotebookImportInspectionData {
133
133
  reason: string | null;
134
134
  requiredSecrets: NotebookImportRequiredSecret[];
135
135
  }
136
+ export interface NotebookGitConfiguration {
137
+ /** Set a sandbox default identity, or use null to reset it to the Helfer bot. */
138
+ author: GitSyncAuthor | null;
139
+ }
136
140
  export interface NotebookLifecycleInput {
141
+ git?: NotebookGitConfiguration;
137
142
  persistent?: true;
138
143
  }
139
144
  export interface CreateNotebookInput extends NotebookLifecycleInput {
@@ -144,6 +149,11 @@ export interface CreateNotebookInput extends NotebookLifecycleInput {
144
149
  secrets?: UpsertNotebookSecretItemInput[];
145
150
  }
146
151
  export type ForkNotebookInput = NotebookLifecycleInput;
152
+ export interface UpdateNotebookInput {
153
+ title?: string;
154
+ visibility?: 'public' | 'private' | 'unlisted';
155
+ git?: NotebookGitConfiguration;
156
+ }
147
157
  export interface NotebookPolicyData {
148
158
  autoDeleteWhenStale: boolean;
149
159
  staleAfterMinutes: number | null;
@@ -365,6 +375,9 @@ export interface NotebookData {
365
375
  slug?: string;
366
376
  description?: string | null;
367
377
  policy?: NotebookPolicyData;
378
+ git?: {
379
+ author: GitSyncAuthor;
380
+ };
368
381
  }
369
382
  export declare class NotebookInstance {
370
383
  #private;
@@ -394,6 +407,8 @@ export declare class NotebookInstance {
394
407
  private readonly disposables;
395
408
  constructor(data: NotebookData, client: Client);
396
409
  ready(): Promise<NotebookInitSuccessResult>;
410
+ /** Update sandbox metadata and Git defaults without restarting it. */
411
+ update(input: UpdateNotebookInput): Promise<NotebookData>;
397
412
  fork(input?: Partial<ForkNotebookInput>): Promise<NotebookInstance>;
398
413
  publication(): Promise<PublicationInstance | null>;
399
414
  publish(input?: PublishInput): Promise<PublicationRun>;
package/dist/index.js CHANGED
@@ -297,6 +297,12 @@ export class NotebookInstance {
297
297
  // Just apply a reasonable timeout for the entire initialization process
298
298
  return ready();
299
299
  }
300
+ /** Update sandbox metadata and Git defaults without restarting it. */
301
+ async update(input) {
302
+ const response = await this.client.put(`/notebook/${this.data.id}`, input);
303
+ Object.assign(this.data, response.data);
304
+ return this.data;
305
+ }
300
306
  async fork(input = {}) {
301
307
  const response = await this.client.post(`/notebook/${this.data.id}/fork`, input);
302
308
  return new NotebookInstance(response.data, this.client);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phpsandbox/sdk",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "The TypeScript SDK for PHPSandbox cloud development environments",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",