@phpsandbox/sdk 0.0.59 → 0.0.61
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.
|
@@ -19862,7 +19862,7 @@ var NotebookApi = class {
|
|
|
19862
19862
|
}
|
|
19863
19863
|
async fork(id, input = {}) {
|
|
19864
19864
|
const response = await this.client.post(`/notebook/${id}/fork`, input);
|
|
19865
|
-
return
|
|
19865
|
+
return new NotebookInstance(response.data, this.client);
|
|
19866
19866
|
}
|
|
19867
19867
|
async gitCredentials(id) {
|
|
19868
19868
|
const response = await this.client.post(`/notebook/${id}/git/credentials`);
|
|
@@ -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=Am(a);s&&t.enqueue(s)}},flush(i){if(n+=e.decode(),n.trim()!==""){let t=Am(n);t&&i.enqueue(t)}}}))}function Am(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 el(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 Si=class{constructor(e){this.client=e}async list(){return(await this.client.get("/servers")).data}async create(e){let n=await this.client.post("/servers",e);return new Ii(n.data,this.client)}async get(e){let n=await this.client.get(`/servers/${e}`);return new Ii(n.data,this.client)}async delete(e){await this.client.delete(`/servers/${e}`)}},Ii=class{constructor(e,n){this.data=e;this.client=n}refresh(){return this.client.servers.get(this.data.id)}delete(){return this.client.servers.delete(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 Mv(r){return Array.isArray(r)?r:Object.entries(r).map(([e,n])=>({name:e,...typeof n=="string"?{value:n}:n}))}var nl=class extends Error{constructor(n,i={}){super(n);this.message=n;this.data=i;this.name="NotebookInitError"}},Fe=class extends Error{constructor(n,i){let t=Bv(i),o=Gv(t,i);super(`PHPSandbox API Error: ${n.status} ${n.statusText}${o===""?"":` - ${o}`}`);this.response=n;this.body=i;this.status=n.status,this.data=t,this.apiMessage=o===""?void 0:o}};function Bv(r){try{return JSON.parse(r)}catch{return null}}function Gv(r,e){if(r!==null&&typeof r=="object"){let n=r;if(typeof n.message=="string"&&n.message.trim()!=="")return n.message.trim();if(n.error!==void 0)return typeof n.error=="string"?n.error.trim():JSON.stringify(n.error)}return e.trim()}var il=class{constructor(e){this.client=e;this.secrets=new al(e),this.preview=new sl(e),this.mail=new cl(e),this.deployment=new _i(e)}async create(e,n={},i=!0){let t=await this.client.post("/notebook",{template:e,...n}),o=new we(t.data,this.client);return i?this.init(o):o}async get(e){let n=await this.client.get(`/notebook/${e}`);return new we(n.data,this.client)}async update(e,n={}){let i=await this.client.put(`/notebook/${e}`,n);return new we(i.data,this.client)}async delete(e){await this.client.delete(`/notebook/${e}`)}async fork(e,n={}){let i=await this.client.post(`/notebook/${e}/fork`,n);return this.init(new we(i.data,this.client))}async gitCredentials(e){return(await this.client.post(`/notebook/${e}/git/credentials`)).data}async open(e){let n=await this.client.get(`/notebook/${e}`);return new we(n.data,this.client)}openFromData(e){return this.init(new we(e,this.client))}async init(e){return await e.ready(),e}};function Jv(r){let e=new URL(r),n=e.pathname.replace(/\/+$/,"");return e.pathname=n===""||n==="/"?"/v1/":`${n}/`,e.search="",e.hash="",e.toString()}var ol=class{constructor(e,n="https://api.phpsandbox.io/v1",i={}){this.fetch=globalThis.fetch;this.deployments=new wi(this),this.notebook=new il(this),this.servers=new Si(this),this.options=Object.assign({startClosed:!0},i),this.baseUrl=Jv(n),i.fetch&&(this.fetch=i.fetch),this.headers={Accept:"application/json",Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}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)})}async stream(e){let n=await this.fetch(new Request(new URL(e.replace(/^\//,""),this.baseUrl),{method:"GET",headers:this.headers}));if(!n.ok)throw new Fe(n,await n.text());if(!n.body)throw new Error("PHPSandbox API Error: response body is not readable");return n.body}async sse(e){let n=await this.fetch(new Request(e,{method:"GET",headers:{...this.headers,Accept:"text/event-stream"}}));if(!n.ok)throw new Fe(n,await n.text());if(!n.body)throw new Error("PHPSandbox API Error: SSE response body is not readable");return n.body}async makeRequest(e,n,i){let t=await this.fetch(new Request(new URL(n.replace(/^\//,""),this.baseUrl),{method:e,...i,headers:this.headers}));if(!t.ok)throw new Fe(t,await t.text());if(t.status===204)return{data:void 0};let o=await t.text();return{data:o===""?void 0:JSON.parse(o)}}},Rm=class extends ol{},al=class{constructor(e){this.client=e}async list(e,n){let i=new URLSearchParams;n?.environment&&i.set("environment",n.environment);let t=i.toString();return(await this.client.get(`/notebook/${e}/secrets${t?`?${t}`:""}`)).data}async set(e,n,i){let t=typeof i=="string"?{name:n,value:i}:{name:n,...i};return(await this.client.put(`/notebook/${e}/secrets`,t)).data}async setMany(e,n){return(await this.client.put(`/notebook/${e}/secrets`,{secrets:Mv(n)})).data}async delete(e,n,i){let t=new URLSearchParams;i?.environment&&t.set("environment",i.environment);let o=t.toString();await this.client.delete(`/notebook/${e}/secrets/${encodeURIComponent(n)}${o?`?${o}`:""}`)}},sl=class{constructor(e){this.client=e}async get(e){return(await this.client.get(`/notebook/${e}/preview`)).data}async setPassword(e,n){return(await this.client.put(`/notebook/${e}/preview`,n)).data}async disable(e){await this.client.delete(`/notebook/${e}/preview`)}async createSession(e){return(await this.client.post(`/notebook/${e}/preview/session`)).data}async createHandoff(e,n){return(await this.client.post(`/notebook/${e}/preview/handoff`,n)).data}},cl=class{constructor(e){this.client=e}async status(e){return(await this.client.get(`/notebook/${e}/mail`)).data}async enable(e){return(await this.client.put(`/notebook/${e}/mail`)).data}async disable(e){await this.client.delete(`/notebook/${e}/mail`)}async list(e,n={}){return(await this.client.get(`/notebook/${e}/mails${Wv(n)}`)).data}async get(e,n){return(await this.client.get(`/notebook/${e}/mails/${encodeURIComponent(n)}`)).data}async delete(e,n){await this.client.delete(`/notebook/${e}/mails/${encodeURIComponent(n)}`)}},Se,wr,ul,we=class{constructor(e,n){this.data=e;this.client=n;kt(this,wr);this.initialized=!1;kt(this,Se);this.disposables=[];this.emitter=Te.createInstance(),this.socket=new Mt(e.okraUrl,this.emitter,{debug:n.options.debug,startClosed:n.options.startClosed,webSocket:n.options.webSocket}),this.watchConnection(),Pi(this,Se,ue(this,wr,ul).call(this)),this.file=new Ir(this),this.terminal=new St(this),this.auth=new Dt(this),this.lsp=new Pt(this),this.composer=new zt(this),this.log=new Et(this),this.repl=new Ut(this),this.container=new It(this),this.laravel=new Tt(this),this.shell=new Ot(this),this.git=new Bt(this,n),this.services=new Nt(this),this.config=new jt(this),this.secrets=new ll(n,this.data.id),this.preview=new dl(n,this.data.id),this.mail=new pl(n,this.data.id)}async ready(){let e=this.socket.getTerminalError();if(e)throw e;return(async()=>(this.client.options.startClosed&&!this.socket.isConnected&&await this.socket.connect(),Sr(this,Se)))()}fork(e={}){return this.client.notebook.fork(this.data.id,e)}deployment(){return this.client.notebook.deployment.current(this.data.id)}publish(e){return this.client.notebook.deployment.publish(this.data.id,e)}gitCredentials(){return this.client.notebook.gitCredentials(this.data.id)}delete(){return this.client.notebook.delete(this.data.id).then(()=>{this.socket.terminate(new le("Notebook has been deleted.",{id:this.data.id}))})}stop(){return this.container.stop()}restart(){return this.container.restart()}invoke(e,n={},i={}){return this.socket.invoke(e,n||{},i)}send(e,n={}){return this.socket.send(e,n||{})}ping(){return this.invoke("ping")}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.isClosed&&this.socket.disconnect()}connected(){return this.waitForSocketConnection({rejectOnClose:!0})}whenConnected(){return this.waitForSocketConnection({rejectOnClose:!1})}waitForSocketConnection(e){let n=this.socket.getTerminalError();return n?Promise.reject(n):this.socket.isConnected?Promise.resolve(this):new Promise((i,t)=>{let o=[],a=!1,s=()=>{for(let u of o)u.dispose();o.length=0},c=u=>{a||(a=!0,s(),u())};try{o.push(this.socket.onDidConnect(()=>c(()=>i(this)))),e.rejectOnClose&&o.push(this.socket.onDidClose(()=>c(()=>t(new Error("Connection closed"))))),o.push(this.socket.onDidBootError(u=>c(()=>t(u))))}catch(u){c(()=>t(u))}})}watchConnection(){this.socket.onDidConnect(()=>{this.socket.emit("okra.connected"),this.client.options.telemetry&&this.container.enableTelemetry(this.client.options.telemetry)}),this.socket.onDidClose(()=>{this.socket.emit("okra.disconnected"),this.initialized=!1}),this.socket.onDidBootError(e=>{this.socket.emit("okra.boot_error",e),this.socket.emit("okra.disconnected"),this.initialized=!1})}onDidConnect(e){this.socket.removeListener("okra.connected",e);let n=this.socket.listen("okra.connected",e);return this.disposables.push(n),n}onDidDisconnect(e){let n=this.socket.listen("okra.disconnected",e);return this.disposables.push(n),n}onDidBootError(e){let n=this.socket.listen("okra.boot_error",e);return this.disposables.push(n),n}update(){return this.invoke("notebook.update")}onDidInitialize(e){return this.listen("notebook.initialized",e)}async reconnect(){let e=this.whenConnected();return this.socket.reconnect(),this.initialized=!1,await e,ue(this,wr,ul).call(this),this.ready().then(()=>this)}async beacon(e,n){let i=await this.ready();return e.src=i.data.previewUrl,Ul(e,n)}};Se=new WeakMap,wr=new WeakSet,ul=function(){return Pi(this,Se,new Promise((e,n)=>{let i=this.onDidInitialize(o=>{if(t.dispose(),i.dispose(),this.initialized=o,o.type==="error"){n(new nl(o.message,o.data));return}e(o)}),t=this.onDidBootError(o=>{i.dispose(),t.dispose(),n(o)})})),Sr(this,Se).catch(()=>{}),Sr(this,Se)};var ll=class{constructor(e,n){this.client=e;this.notebookId=n}list(e){return this.client.notebook.secrets.list(this.notebookId,e)}set(e,n){return this.client.notebook.secrets.set(this.notebookId,e,n)}setMany(e){return this.client.notebook.secrets.setMany(this.notebookId,e)}delete(e,n){return this.client.notebook.secrets.delete(this.notebookId,e,n)}},dl=class{constructor(e,n){this.client=e;this.notebookId=n}get(){return this.client.notebook.preview.get(this.notebookId)}setPassword(e){return this.client.notebook.preview.setPassword(this.notebookId,e)}disable(){return this.client.notebook.preview.disable(this.notebookId)}createSession(){return this.client.notebook.preview.createSession(this.notebookId)}createHandoff(e){return this.client.notebook.preview.createHandoff(this.notebookId,e)}},pl=class{constructor(e,n){this.client=e;this.notebookId=n}status(){return this.client.notebook.mail.status(this.notebookId)}enable(){return this.client.notebook.mail.enable(this.notebookId)}disable(){return this.client.notebook.mail.disable(this.notebookId)}list(e={}){return this.client.notebook.mail.list(this.notebookId,e)}get(e){return this.client.notebook.mail.get(this.notebookId,e)}delete(e){return this.client.notebook.mail.delete(this.notebookId,e)}};function Wv(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{Fe as ApiError,Ki as Beacon,oe as BeaconConnectionError,Be as BeaconError,Cr as BeaconTimeoutError,ol as Client,Ui as CommandError,Ev as DeployStreamErrorSchema,zv as DeployStreamEventSchema,Dv as DeployStreamLogEventSchema,Om as DeployStreamLogSchema,Sv as DeployStreamLogStreamSchema,Iv as DeployStreamPhaseEventSchema,Um as DeployStreamPhaseSchema,Pv as DeployStreamResultEventSchema,Qu as DeployStreamResultSchema,Ov as DeployStreamSseDoneEventSchema,jv as DeployStreamSseErrorEventSchema,Nm as DeployStreamSseEventNameSchema,jm as DeployStreamSseEventSchema,Uv as DeployStreamSseLogEventSchema,Tv as DeployStreamSsePhaseEventSchema,Nv as DeployStreamSseResultEventSchema,wi as DeploymentApi,Dk as DeploymentBuildStatusSchema,Uk as DeploymentDomainDnsRecordTypeSchema,Tm as DeploymentEventDataSchema,_e as DeploymentInstance,Tk as DeploymentJurisdictionSchema,Yu as DeploymentLogChunkDataSchema,wv as DeploymentLogStreamSchema,Ok as DeploymentProtectionModeSchema,Ek as DeploymentRegionSchema,Pk as DeploymentReleaseStatusSchema,tl as DeploymentRun,zk as DeploymentSizeSchema,_v as DeploymentStatusSchema,Ik as DeploymentTargetProviderSchema,ee as ErrorEvent,Fm as FileChangeFilter,Mm as FileChangeType,Lm as FileType,Ir as Filesystem,zi as FilesystemError,Bm as FilesystemErrorType,Ti as LspConnection,Gt as Navigator,il as NotebookApi,_i as NotebookDeploymentApi,nl as NotebookInitError,we as NotebookInstance,pl as NotebookMail,cl as NotebookMailApi,dl as NotebookPreview,sl as NotebookPreviewApi,al as NotebookSecretApi,ll as NotebookSecrets,Wm as NotebookState,le as NotebookUnavailableError,Rm as PHPSandbox,hl as PHPSandboxError,Ie as PromiseTimeoutError,_t as RateLimitError,wt as SendTimeoutError,Si as ServerApi,Ii as ServerInstance,Mt as Transport,Ul as createBeacon,Iy as isBeaconSupported,Vm as notebookBuiltinServices,bb as notebookKnownServices,Pr as once,Dr as timeout};
|
|
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 Si=class{constructor(e){this.client=e}async list(){return(await this.client.get("/servers")).data}async create(e){let n=await this.client.post("/servers",e);return new Ii(n.data,this.client)}async get(e){let n=await this.client.get(`/servers/${e}`);return new Ii(n.data,this.client)}async delete(e){await this.client.delete(`/servers/${e}`)}},Ii=class{constructor(e,n){this.data=e;this.client=n}refresh(){return this.client.servers.get(this.data.id)}delete(){return this.client.servers.delete(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 Mv(r){return Array.isArray(r)?r:Object.entries(r).map(([e,n])=>({name:e,...typeof n=="string"?{value:n}:n}))}var nl=class extends Error{constructor(n,i={}){super(n);this.message=n;this.data=i;this.name="NotebookInitError"}},Fe=class extends Error{constructor(n,i){let t=Bv(i),o=Gv(t,i);super(`PHPSandbox API Error: ${n.status} ${n.statusText}${o===""?"":` - ${o}`}`);this.response=n;this.body=i;this.status=n.status,this.data=t,this.apiMessage=o===""?void 0:o}};function Bv(r){try{return JSON.parse(r)}catch{return null}}function Gv(r,e){if(r!==null&&typeof r=="object"){let n=r;if(typeof n.message=="string"&&n.message.trim()!=="")return n.message.trim();if(n.error!==void 0)return typeof n.error=="string"?n.error.trim():JSON.stringify(n.error)}return e.trim()}var il=class{constructor(e){this.client=e;this.secrets=new al(e),this.preview=new sl(e),this.mail=new cl(e),this.deployment=new _i(e)}async create(e,n={},i=!0){let t=await this.client.post("/notebook",{template:e,...n}),o=new we(t.data,this.client);return i?this.init(o):o}async get(e){let n=await this.client.get(`/notebook/${e}`);return new we(n.data,this.client)}async update(e,n={}){let i=await this.client.put(`/notebook/${e}`,n);return new we(i.data,this.client)}async delete(e){await this.client.delete(`/notebook/${e}`)}async fork(e,n={}){let i=await this.client.post(`/notebook/${e}/fork`,n);return new we(i.data,this.client)}async gitCredentials(e){return(await this.client.post(`/notebook/${e}/git/credentials`)).data}async open(e){let n=await this.client.get(`/notebook/${e}`);return new we(n.data,this.client)}openFromData(e){return this.init(new we(e,this.client))}async init(e){return await e.ready(),e}};function Jv(r){let e=new URL(r),n=e.pathname.replace(/\/+$/,"");return e.pathname=n===""||n==="/"?"/v1/":`${n}/`,e.search="",e.hash="",e.toString()}var ol=class{constructor(e,n="https://api.phpsandbox.io/v1",i={}){this.fetch=globalThis.fetch;this.deployments=new wi(this),this.notebook=new il(this),this.servers=new Si(this),this.options=Object.assign({startClosed:!0},i),this.baseUrl=Jv(n),i.fetch&&(this.fetch=i.fetch),this.headers={Accept:"application/json",Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}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)})}async stream(e){let n=await this.fetch(new Request(new URL(e.replace(/^\//,""),this.baseUrl),{method:"GET",headers:this.headers}));if(!n.ok)throw new Fe(n,await n.text());if(!n.body)throw new Error("PHPSandbox API Error: response body is not readable");return n.body}async sse(e){let n=await this.fetch(new Request(e,{method:"GET",headers:{...this.headers,Accept:"text/event-stream"}}));if(!n.ok)throw new Fe(n,await n.text());if(!n.body)throw new Error("PHPSandbox API Error: SSE response body is not readable");return n.body}async makeRequest(e,n,i){let t=await this.fetch(new Request(new URL(n.replace(/^\//,""),this.baseUrl),{method:e,...i,headers:this.headers}));if(!t.ok)throw new Fe(t,await t.text());if(t.status===204)return{data:void 0};let o=await t.text();return{data:o===""?void 0:JSON.parse(o)}}},Rm=class extends ol{},al=class{constructor(e){this.client=e}async list(e,n){let i=new URLSearchParams;n?.environment&&i.set("environment",n.environment);let t=i.toString();return(await this.client.get(`/notebook/${e}/secrets${t?`?${t}`:""}`)).data}async set(e,n,i){let t=typeof i=="string"?{name:n,value:i}:{name:n,...i};return(await this.client.put(`/notebook/${e}/secrets`,t)).data}async setMany(e,n){return(await this.client.put(`/notebook/${e}/secrets`,{secrets:Mv(n)})).data}async delete(e,n,i){let t=new URLSearchParams;i?.environment&&t.set("environment",i.environment);let o=t.toString();await this.client.delete(`/notebook/${e}/secrets/${encodeURIComponent(n)}${o?`?${o}`:""}`)}},sl=class{constructor(e){this.client=e}async get(e){return(await this.client.get(`/notebook/${e}/preview`)).data}async setPassword(e,n){return(await this.client.put(`/notebook/${e}/preview`,n)).data}async disable(e){await this.client.delete(`/notebook/${e}/preview`)}async createSession(e){return(await this.client.post(`/notebook/${e}/preview/session`)).data}async createHandoff(e,n){return(await this.client.post(`/notebook/${e}/preview/handoff`,n)).data}},cl=class{constructor(e){this.client=e}async status(e){return(await this.client.get(`/notebook/${e}/mail`)).data}async enable(e){return(await this.client.put(`/notebook/${e}/mail`)).data}async disable(e){await this.client.delete(`/notebook/${e}/mail`)}async list(e,n={}){return(await this.client.get(`/notebook/${e}/mails${Wv(n)}`)).data}async get(e,n){return(await this.client.get(`/notebook/${e}/mails/${encodeURIComponent(n)}`)).data}async delete(e,n){await this.client.delete(`/notebook/${e}/mails/${encodeURIComponent(n)}`)}},Se,wr,ul,we=class{constructor(e,n){this.data=e;this.client=n;kt(this,wr);this.initialized=!1;kt(this,Se);this.disposables=[];this.emitter=Te.createInstance(),this.socket=new Mt(e.okraUrl,this.emitter,{debug:n.options.debug,startClosed:n.options.startClosed,webSocket:n.options.webSocket}),this.watchConnection(),Pi(this,Se,ue(this,wr,ul).call(this)),this.file=new Ir(this),this.terminal=new St(this),this.auth=new Dt(this),this.lsp=new Pt(this),this.composer=new zt(this),this.log=new Et(this),this.repl=new Ut(this),this.container=new It(this),this.laravel=new Tt(this),this.shell=new Ot(this),this.git=new Bt(this,n),this.services=new Nt(this),this.config=new jt(this),this.secrets=new ll(n,this.data.id),this.preview=new dl(n,this.data.id),this.mail=new pl(n,this.data.id)}async ready(){let e=this.socket.getTerminalError();if(e)throw e;return(async()=>(this.client.options.startClosed&&!this.socket.isConnected&&await this.socket.connect(),Sr(this,Se)))()}fork(e={}){return this.client.notebook.fork(this.data.id,e)}deployment(){return this.client.notebook.deployment.current(this.data.id)}publish(e){return this.client.notebook.deployment.publish(this.data.id,e)}gitCredentials(){return this.client.notebook.gitCredentials(this.data.id)}delete(){return this.client.notebook.delete(this.data.id).then(()=>{this.socket.terminate(new le("Notebook has been deleted.",{id:this.data.id}))})}stop(){return this.container.stop()}restart(){return this.container.restart()}invoke(e,n={},i={}){return this.socket.invoke(e,n||{},i)}send(e,n={}){return this.socket.send(e,n||{})}ping(){return this.invoke("ping")}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.isClosed&&this.socket.disconnect()}connected(){return this.waitForSocketConnection({rejectOnClose:!0})}whenConnected(){return this.waitForSocketConnection({rejectOnClose:!1})}waitForSocketConnection(e){let n=this.socket.getTerminalError();return n?Promise.reject(n):this.socket.isConnected?Promise.resolve(this):new Promise((i,t)=>{let o=[],a=!1,s=()=>{for(let u of o)u.dispose();o.length=0},c=u=>{a||(a=!0,s(),u())};try{o.push(this.socket.onDidConnect(()=>c(()=>i(this)))),e.rejectOnClose&&o.push(this.socket.onDidClose(()=>c(()=>t(new Error("Connection closed"))))),o.push(this.socket.onDidBootError(u=>c(()=>t(u))))}catch(u){c(()=>t(u))}})}watchConnection(){this.socket.onDidConnect(()=>{this.socket.emit("okra.connected"),this.client.options.telemetry&&this.container.enableTelemetry(this.client.options.telemetry)}),this.socket.onDidClose(()=>{this.socket.emit("okra.disconnected"),this.initialized=!1}),this.socket.onDidBootError(e=>{this.socket.emit("okra.boot_error",e),this.socket.emit("okra.disconnected"),this.initialized=!1})}onDidConnect(e){this.socket.removeListener("okra.connected",e);let n=this.socket.listen("okra.connected",e);return this.disposables.push(n),n}onDidDisconnect(e){let n=this.socket.listen("okra.disconnected",e);return this.disposables.push(n),n}onDidBootError(e){let n=this.socket.listen("okra.boot_error",e);return this.disposables.push(n),n}update(){return this.invoke("notebook.update")}onDidInitialize(e){return this.listen("notebook.initialized",e)}async reconnect(){let e=this.whenConnected();return this.socket.reconnect(),this.initialized=!1,await e,ue(this,wr,ul).call(this),this.ready().then(()=>this)}async beacon(e,n){let i=await this.ready();return e.src=i.data.previewUrl,Ul(e,n)}};Se=new WeakMap,wr=new WeakSet,ul=function(){return Pi(this,Se,new Promise((e,n)=>{let i=this.onDidInitialize(o=>{if(t.dispose(),i.dispose(),this.initialized=o,o.type==="error"){n(new nl(o.message,o.data));return}e(o)}),t=this.onDidBootError(o=>{i.dispose(),t.dispose(),n(o)})})),Sr(this,Se).catch(()=>{}),Sr(this,Se)};var ll=class{constructor(e,n){this.client=e;this.notebookId=n}list(e){return this.client.notebook.secrets.list(this.notebookId,e)}set(e,n){return this.client.notebook.secrets.set(this.notebookId,e,n)}setMany(e){return this.client.notebook.secrets.setMany(this.notebookId,e)}delete(e,n){return this.client.notebook.secrets.delete(this.notebookId,e,n)}},dl=class{constructor(e,n){this.client=e;this.notebookId=n}get(){return this.client.notebook.preview.get(this.notebookId)}setPassword(e){return this.client.notebook.preview.setPassword(this.notebookId,e)}disable(){return this.client.notebook.preview.disable(this.notebookId)}createSession(){return this.client.notebook.preview.createSession(this.notebookId)}createHandoff(e){return this.client.notebook.preview.createHandoff(this.notebookId,e)}},pl=class{constructor(e,n){this.client=e;this.notebookId=n}status(){return this.client.notebook.mail.status(this.notebookId)}enable(){return this.client.notebook.mail.enable(this.notebookId)}disable(){return this.client.notebook.mail.disable(this.notebookId)}list(e={}){return this.client.notebook.mail.list(this.notebookId,e)}get(e){return this.client.notebook.mail.get(this.notebookId,e)}delete(e){return this.client.notebook.mail.delete(this.notebookId,e)}};function Wv(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{Fe as ApiError,Ki as Beacon,oe as BeaconConnectionError,Be as BeaconError,Cr as BeaconTimeoutError,ol as Client,Ui as CommandError,Ev as DeployStreamErrorSchema,zv as DeployStreamEventSchema,Dv as DeployStreamLogEventSchema,Om as DeployStreamLogSchema,Sv as DeployStreamLogStreamSchema,Iv as DeployStreamPhaseEventSchema,Um as DeployStreamPhaseSchema,Pv as DeployStreamResultEventSchema,Qu as DeployStreamResultSchema,Ov as DeployStreamSseDoneEventSchema,jv as DeployStreamSseErrorEventSchema,Nm as DeployStreamSseEventNameSchema,jm as DeployStreamSseEventSchema,Uv as DeployStreamSseLogEventSchema,Tv as DeployStreamSsePhaseEventSchema,Nv as DeployStreamSseResultEventSchema,wi as DeploymentApi,Dk as DeploymentBuildStatusSchema,Uk as DeploymentDomainDnsRecordTypeSchema,Tm as DeploymentEventDataSchema,_e as DeploymentInstance,Tk as DeploymentJurisdictionSchema,Yu as DeploymentLogChunkDataSchema,wv as DeploymentLogStreamSchema,Ok as DeploymentProtectionModeSchema,Ek as DeploymentRegionSchema,Pk as DeploymentReleaseStatusSchema,tl as DeploymentRun,zk as DeploymentSizeSchema,_v as DeploymentStatusSchema,Ik as DeploymentTargetProviderSchema,ee as ErrorEvent,Fm as FileChangeFilter,Mm as FileChangeType,Lm as FileType,Ir as Filesystem,zi as FilesystemError,Bm as FilesystemErrorType,Ti as LspConnection,Gt as Navigator,il as NotebookApi,_i as NotebookDeploymentApi,nl as NotebookInitError,we as NotebookInstance,pl as NotebookMail,cl as NotebookMailApi,dl as NotebookPreview,sl as NotebookPreviewApi,al as NotebookSecretApi,ll as NotebookSecrets,Wm as NotebookState,le as NotebookUnavailableError,Rm as PHPSandbox,hl as PHPSandboxError,Ie as PromiseTimeoutError,_t as RateLimitError,wt as SendTimeoutError,Si as ServerApi,Ii as ServerInstance,Mt as Transport,Ul as createBeacon,Iy as isBeaconSupported,Vm as notebookBuiltinServices,bb as notebookKnownServices,Pr as once,Dr as timeout};
|
|
71
71
|
/*! Bundled license information:
|
|
72
72
|
|
|
73
73
|
reconnecting-websocket/dist/reconnecting-websocket-mjs.js:
|
|
@@ -19953,7 +19953,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19953
19953
|
}
|
|
19954
19954
|
async fork(id, input = {}) {
|
|
19955
19955
|
const response = await this.client.post(`/notebook/${id}/fork`, input);
|
|
19956
|
-
return
|
|
19956
|
+
return new NotebookInstance(response.data, this.client);
|
|
19957
19957
|
}
|
|
19958
19958
|
async gitCredentials(id) {
|
|
19959
19959
|
const response = await this.client.post(`/notebook/${id}/git/credentials`);
|
|
@@ -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=nf(a);s&&t.enqueue(s)}},flush(i){if(n+=e.decode(),n.trim()!==""){let t=nf(n);t&&i.enqueue(t)}}}))}function nf(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 bl(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 Er=class{constructor(e){this.client=e}async list(){return(await this.client.get("/servers")).data}async create(e){let n=await this.client.post("/servers",e);return new Tr(n.data,this.client)}async get(e){let n=await this.client.get(`/servers/${e}`);return new Tr(n.data,this.client)}async delete(e){await this.client.delete(`/servers/${e}`)}},Tr=class{constructor(e,n){this.data=e;this.client=n}refresh(){return this.client.servers.get(this.data.id)}delete(){return this.client.servers.delete(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 nb(r){return Array.isArray(r)?r:Object.entries(r).map(([e,n])=>({name:e,...typeof n=="string"?{value:n}:n}))}var Ni=class extends Error{constructor(n,i={}){super(n);this.message=n;this.data=i;this.name="NotebookInitError"}},Ie=class extends Error{constructor(n,i){let t=ib(i),o=ob(t,i);super(`PHPSandbox API Error: ${n.status} ${n.statusText}${o===""?"":` - ${o}`}`);this.response=n;this.body=i;this.status=n.status,this.data=t,this.apiMessage=o===""?void 0:o}};function ib(r){try{return JSON.parse(r)}catch{return null}}function ob(r,e){if(r!==null&&typeof r=="object"){let n=r;if(typeof n.message=="string"&&n.message.trim()!=="")return n.message.trim();if(n.error!==void 0)return typeof n.error=="string"?n.error.trim():JSON.stringify(n.error)}return e.trim()}var ji=class{constructor(e){this.client=e;this.secrets=new Ri(e),this.preview=new Ci(e),this.mail=new Zi(e),this.deployment=new Pr(e)}async create(e,n={},i=!0){let t=await this.client.post("/notebook",{template:e,...n}),o=new de(t.data,this.client);return i?this.init(o):o}async get(e){let n=await this.client.get(`/notebook/${e}`);return new de(n.data,this.client)}async update(e,n={}){let i=await this.client.put(`/notebook/${e}`,n);return new de(i.data,this.client)}async delete(e){await this.client.delete(`/notebook/${e}`)}async fork(e,n={}){let i=await this.client.post(`/notebook/${e}/fork`,n);return this.init(new de(i.data,this.client))}async gitCredentials(e){return(await this.client.post(`/notebook/${e}/git/credentials`)).data}async open(e){let n=await this.client.get(`/notebook/${e}`);return new de(n.data,this.client)}openFromData(e){return this.init(new de(e,this.client))}async init(e){return await e.ready(),e}};function ab(r){let e=new URL(r),n=e.pathname.replace(/\/+$/,"");return e.pathname=n===""||n==="/"?"/v1/":`${n}/`,e.search="",e.hash="",e.toString()}var Ai=class{constructor(e,n="https://api.phpsandbox.io/v1",i={}){this.fetch=globalThis.fetch;this.deployments=new zr(this),this.notebook=new ji(this),this.servers=new Er(this),this.options=Object.assign({startClosed:!0},i),this.baseUrl=ab(n),i.fetch&&(this.fetch=i.fetch),this.headers={Accept:"application/json",Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}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)})}async stream(e){let n=await this.fetch(new Request(new URL(e.replace(/^\//,""),this.baseUrl),{method:"GET",headers:this.headers}));if(!n.ok)throw new Ie(n,await n.text());if(!n.body)throw new Error("PHPSandbox API Error: response body is not readable");return n.body}async sse(e){let n=await this.fetch(new Request(e,{method:"GET",headers:{...this.headers,Accept:"text/event-stream"}}));if(!n.ok)throw new Ie(n,await n.text());if(!n.body)throw new Error("PHPSandbox API Error: SSE response body is not readable");return n.body}async makeRequest(e,n,i){let t=await this.fetch(new Request(new URL(n.replace(/^\//,""),this.baseUrl),{method:e,...i,headers:this.headers}));if(!t.ok)throw new Ie(t,await t.text());if(t.status===204)return{data:void 0};let o=await t.text();return{data:o===""?void 0:JSON.parse(o)}}},xl=class extends Ai{},Ri=class{constructor(e){this.client=e}async list(e,n){let i=new URLSearchParams;n?.environment&&i.set("environment",n.environment);let t=i.toString();return(await this.client.get(`/notebook/${e}/secrets${t?`?${t}`:""}`)).data}async set(e,n,i){let t=typeof i=="string"?{name:n,value:i}:{name:n,...i};return(await this.client.put(`/notebook/${e}/secrets`,t)).data}async setMany(e,n){return(await this.client.put(`/notebook/${e}/secrets`,{secrets:nb(n)})).data}async delete(e,n,i){let t=new URLSearchParams;i?.environment&&t.set("environment",i.environment);let o=t.toString();await this.client.delete(`/notebook/${e}/secrets/${encodeURIComponent(n)}${o?`?${o}`:""}`)}},Ci=class{constructor(e){this.client=e}async get(e){return(await this.client.get(`/notebook/${e}/preview`)).data}async setPassword(e,n){return(await this.client.put(`/notebook/${e}/preview`,n)).data}async disable(e){await this.client.delete(`/notebook/${e}/preview`)}async createSession(e){return(await this.client.post(`/notebook/${e}/preview/session`)).data}async createHandoff(e,n){return(await this.client.post(`/notebook/${e}/preview/handoff`,n)).data}},Zi=class{constructor(e){this.client=e}async status(e){return(await this.client.get(`/notebook/${e}/mail`)).data}async enable(e){return(await this.client.put(`/notebook/${e}/mail`)).data}async disable(e){await this.client.delete(`/notebook/${e}/mail`)}async list(e,n={}){return(await this.client.get(`/notebook/${e}/mails${sb(n)}`)).data}async get(e,n){return(await this.client.get(`/notebook/${e}/mails/${encodeURIComponent(n)}`)).data}async delete(e,n){await this.client.delete(`/notebook/${e}/mails/${encodeURIComponent(n)}`)}},De,Ur,$l,de=class{constructor(e,n){this.data=e;this.client=n;It(this,Ur);this.initialized=!1;It(this,De);this.disposables=[];this.emitter=Ue.createInstance(),this.socket=new We(e.okraUrl,this.emitter,{debug:n.options.debug,startClosed:n.options.startClosed,webSocket:n.options.webSocket}),this.watchConnection(),Ji(this,De,pe(this,Ur,$l).call(this)),this.file=new Dt(this),this.terminal=new Et(this),this.auth=new Ut(this),this.lsp=new Ot(this),this.composer=new Nt(this),this.log=new jt(this),this.repl=new Rt(this),this.container=new Tt(this),this.laravel=new At(this),this.shell=new Ct(this),this.git=new Vt(this,n),this.services=new Zt(this),this.config=new Lt(this),this.secrets=new Li(n,this.data.id),this.preview=new Fi(n,this.data.id),this.mail=new Mi(n,this.data.id)}async ready(){let e=this.socket.getTerminalError();if(e)throw e;return(async()=>(this.client.options.startClosed&&!this.socket.isConnected&&await this.socket.connect(),Or(this,De)))()}fork(e={}){return this.client.notebook.fork(this.data.id,e)}deployment(){return this.client.notebook.deployment.current(this.data.id)}publish(e){return this.client.notebook.deployment.publish(this.data.id,e)}gitCredentials(){return this.client.notebook.gitCredentials(this.data.id)}delete(){return this.client.notebook.delete(this.data.id).then(()=>{this.socket.terminate(new ae("Notebook has been deleted.",{id:this.data.id}))})}stop(){return this.container.stop()}restart(){return this.container.restart()}invoke(e,n={},i={}){return this.socket.invoke(e,n||{},i)}send(e,n={}){return this.socket.send(e,n||{})}ping(){return this.invoke("ping")}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.isClosed&&this.socket.disconnect()}connected(){return this.waitForSocketConnection({rejectOnClose:!0})}whenConnected(){return this.waitForSocketConnection({rejectOnClose:!1})}waitForSocketConnection(e){let n=this.socket.getTerminalError();return n?Promise.reject(n):this.socket.isConnected?Promise.resolve(this):new Promise((i,t)=>{let o=[],a=!1,s=()=>{for(let u of o)u.dispose();o.length=0},c=u=>{a||(a=!0,s(),u())};try{o.push(this.socket.onDidConnect(()=>c(()=>i(this)))),e.rejectOnClose&&o.push(this.socket.onDidClose(()=>c(()=>t(new Error("Connection closed"))))),o.push(this.socket.onDidBootError(u=>c(()=>t(u))))}catch(u){c(()=>t(u))}})}watchConnection(){this.socket.onDidConnect(()=>{this.socket.emit("okra.connected"),this.client.options.telemetry&&this.container.enableTelemetry(this.client.options.telemetry)}),this.socket.onDidClose(()=>{this.socket.emit("okra.disconnected"),this.initialized=!1}),this.socket.onDidBootError(e=>{this.socket.emit("okra.boot_error",e),this.socket.emit("okra.disconnected"),this.initialized=!1})}onDidConnect(e){this.socket.removeListener("okra.connected",e);let n=this.socket.listen("okra.connected",e);return this.disposables.push(n),n}onDidDisconnect(e){let n=this.socket.listen("okra.disconnected",e);return this.disposables.push(n),n}onDidBootError(e){let n=this.socket.listen("okra.boot_error",e);return this.disposables.push(n),n}update(){return this.invoke("notebook.update")}onDidInitialize(e){return this.listen("notebook.initialized",e)}async reconnect(){let e=this.whenConnected();return this.socket.reconnect(),this.initialized=!1,await e,pe(this,Ur,$l).call(this),this.ready().then(()=>this)}async beacon(e,n){let i=await this.ready();return e.src=i.data.previewUrl,uo(e,n)}};De=new WeakMap,Ur=new WeakSet,$l=function(){return Ji(this,De,new Promise((e,n)=>{let i=this.onDidInitialize(o=>{if(t.dispose(),i.dispose(),this.initialized=o,o.type==="error"){n(new Ni(o.message,o.data));return}e(o)}),t=this.onDidBootError(o=>{i.dispose(),t.dispose(),n(o)})})),Or(this,De).catch(()=>{}),Or(this,De)};var Li=class{constructor(e,n){this.client=e;this.notebookId=n}list(e){return this.client.notebook.secrets.list(this.notebookId,e)}set(e,n){return this.client.notebook.secrets.set(this.notebookId,e,n)}setMany(e){return this.client.notebook.secrets.setMany(this.notebookId,e)}delete(e,n){return this.client.notebook.secrets.delete(this.notebookId,e,n)}},Fi=class{constructor(e,n){this.client=e;this.notebookId=n}get(){return this.client.notebook.preview.get(this.notebookId)}setPassword(e){return this.client.notebook.preview.setPassword(this.notebookId,e)}disable(){return this.client.notebook.preview.disable(this.notebookId)}createSession(){return this.client.notebook.preview.createSession(this.notebookId)}createHandoff(e){return this.client.notebook.preview.createHandoff(this.notebookId,e)}},Mi=class{constructor(e,n){this.client=e;this.notebookId=n}status(){return this.client.notebook.mail.status(this.notebookId)}enable(){return this.client.notebook.mail.enable(this.notebookId)}disable(){return this.client.notebook.mail.disable(this.notebookId)}list(e={}){return this.client.notebook.mail.list(this.notebookId,e)}get(e){return this.client.notebook.mail.get(this.notebookId,e)}delete(e){return this.client.notebook.mail.delete(this.notebookId,e)}};function sb(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(cb);})();
|
|
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 Er=class{constructor(e){this.client=e}async list(){return(await this.client.get("/servers")).data}async create(e){let n=await this.client.post("/servers",e);return new Tr(n.data,this.client)}async get(e){let n=await this.client.get(`/servers/${e}`);return new Tr(n.data,this.client)}async delete(e){await this.client.delete(`/servers/${e}`)}},Tr=class{constructor(e,n){this.data=e;this.client=n}refresh(){return this.client.servers.get(this.data.id)}delete(){return this.client.servers.delete(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 nb(r){return Array.isArray(r)?r:Object.entries(r).map(([e,n])=>({name:e,...typeof n=="string"?{value:n}:n}))}var Ni=class extends Error{constructor(n,i={}){super(n);this.message=n;this.data=i;this.name="NotebookInitError"}},Ie=class extends Error{constructor(n,i){let t=ib(i),o=ob(t,i);super(`PHPSandbox API Error: ${n.status} ${n.statusText}${o===""?"":` - ${o}`}`);this.response=n;this.body=i;this.status=n.status,this.data=t,this.apiMessage=o===""?void 0:o}};function ib(r){try{return JSON.parse(r)}catch{return null}}function ob(r,e){if(r!==null&&typeof r=="object"){let n=r;if(typeof n.message=="string"&&n.message.trim()!=="")return n.message.trim();if(n.error!==void 0)return typeof n.error=="string"?n.error.trim():JSON.stringify(n.error)}return e.trim()}var ji=class{constructor(e){this.client=e;this.secrets=new Ri(e),this.preview=new Ci(e),this.mail=new Zi(e),this.deployment=new Pr(e)}async create(e,n={},i=!0){let t=await this.client.post("/notebook",{template:e,...n}),o=new de(t.data,this.client);return i?this.init(o):o}async get(e){let n=await this.client.get(`/notebook/${e}`);return new de(n.data,this.client)}async update(e,n={}){let i=await this.client.put(`/notebook/${e}`,n);return new de(i.data,this.client)}async delete(e){await this.client.delete(`/notebook/${e}`)}async fork(e,n={}){let i=await this.client.post(`/notebook/${e}/fork`,n);return new de(i.data,this.client)}async gitCredentials(e){return(await this.client.post(`/notebook/${e}/git/credentials`)).data}async open(e){let n=await this.client.get(`/notebook/${e}`);return new de(n.data,this.client)}openFromData(e){return this.init(new de(e,this.client))}async init(e){return await e.ready(),e}};function ab(r){let e=new URL(r),n=e.pathname.replace(/\/+$/,"");return e.pathname=n===""||n==="/"?"/v1/":`${n}/`,e.search="",e.hash="",e.toString()}var Ai=class{constructor(e,n="https://api.phpsandbox.io/v1",i={}){this.fetch=globalThis.fetch;this.deployments=new zr(this),this.notebook=new ji(this),this.servers=new Er(this),this.options=Object.assign({startClosed:!0},i),this.baseUrl=ab(n),i.fetch&&(this.fetch=i.fetch),this.headers={Accept:"application/json",Authorization:`Bearer ${e}`,"Content-Type":"application/json"}}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)})}async stream(e){let n=await this.fetch(new Request(new URL(e.replace(/^\//,""),this.baseUrl),{method:"GET",headers:this.headers}));if(!n.ok)throw new Ie(n,await n.text());if(!n.body)throw new Error("PHPSandbox API Error: response body is not readable");return n.body}async sse(e){let n=await this.fetch(new Request(e,{method:"GET",headers:{...this.headers,Accept:"text/event-stream"}}));if(!n.ok)throw new Ie(n,await n.text());if(!n.body)throw new Error("PHPSandbox API Error: SSE response body is not readable");return n.body}async makeRequest(e,n,i){let t=await this.fetch(new Request(new URL(n.replace(/^\//,""),this.baseUrl),{method:e,...i,headers:this.headers}));if(!t.ok)throw new Ie(t,await t.text());if(t.status===204)return{data:void 0};let o=await t.text();return{data:o===""?void 0:JSON.parse(o)}}},xl=class extends Ai{},Ri=class{constructor(e){this.client=e}async list(e,n){let i=new URLSearchParams;n?.environment&&i.set("environment",n.environment);let t=i.toString();return(await this.client.get(`/notebook/${e}/secrets${t?`?${t}`:""}`)).data}async set(e,n,i){let t=typeof i=="string"?{name:n,value:i}:{name:n,...i};return(await this.client.put(`/notebook/${e}/secrets`,t)).data}async setMany(e,n){return(await this.client.put(`/notebook/${e}/secrets`,{secrets:nb(n)})).data}async delete(e,n,i){let t=new URLSearchParams;i?.environment&&t.set("environment",i.environment);let o=t.toString();await this.client.delete(`/notebook/${e}/secrets/${encodeURIComponent(n)}${o?`?${o}`:""}`)}},Ci=class{constructor(e){this.client=e}async get(e){return(await this.client.get(`/notebook/${e}/preview`)).data}async setPassword(e,n){return(await this.client.put(`/notebook/${e}/preview`,n)).data}async disable(e){await this.client.delete(`/notebook/${e}/preview`)}async createSession(e){return(await this.client.post(`/notebook/${e}/preview/session`)).data}async createHandoff(e,n){return(await this.client.post(`/notebook/${e}/preview/handoff`,n)).data}},Zi=class{constructor(e){this.client=e}async status(e){return(await this.client.get(`/notebook/${e}/mail`)).data}async enable(e){return(await this.client.put(`/notebook/${e}/mail`)).data}async disable(e){await this.client.delete(`/notebook/${e}/mail`)}async list(e,n={}){return(await this.client.get(`/notebook/${e}/mails${sb(n)}`)).data}async get(e,n){return(await this.client.get(`/notebook/${e}/mails/${encodeURIComponent(n)}`)).data}async delete(e,n){await this.client.delete(`/notebook/${e}/mails/${encodeURIComponent(n)}`)}},De,Ur,$l,de=class{constructor(e,n){this.data=e;this.client=n;It(this,Ur);this.initialized=!1;It(this,De);this.disposables=[];this.emitter=Ue.createInstance(),this.socket=new We(e.okraUrl,this.emitter,{debug:n.options.debug,startClosed:n.options.startClosed,webSocket:n.options.webSocket}),this.watchConnection(),Ji(this,De,pe(this,Ur,$l).call(this)),this.file=new Dt(this),this.terminal=new Et(this),this.auth=new Ut(this),this.lsp=new Ot(this),this.composer=new Nt(this),this.log=new jt(this),this.repl=new Rt(this),this.container=new Tt(this),this.laravel=new At(this),this.shell=new Ct(this),this.git=new Vt(this,n),this.services=new Zt(this),this.config=new Lt(this),this.secrets=new Li(n,this.data.id),this.preview=new Fi(n,this.data.id),this.mail=new Mi(n,this.data.id)}async ready(){let e=this.socket.getTerminalError();if(e)throw e;return(async()=>(this.client.options.startClosed&&!this.socket.isConnected&&await this.socket.connect(),Or(this,De)))()}fork(e={}){return this.client.notebook.fork(this.data.id,e)}deployment(){return this.client.notebook.deployment.current(this.data.id)}publish(e){return this.client.notebook.deployment.publish(this.data.id,e)}gitCredentials(){return this.client.notebook.gitCredentials(this.data.id)}delete(){return this.client.notebook.delete(this.data.id).then(()=>{this.socket.terminate(new ae("Notebook has been deleted.",{id:this.data.id}))})}stop(){return this.container.stop()}restart(){return this.container.restart()}invoke(e,n={},i={}){return this.socket.invoke(e,n||{},i)}send(e,n={}){return this.socket.send(e,n||{})}ping(){return this.invoke("ping")}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.isClosed&&this.socket.disconnect()}connected(){return this.waitForSocketConnection({rejectOnClose:!0})}whenConnected(){return this.waitForSocketConnection({rejectOnClose:!1})}waitForSocketConnection(e){let n=this.socket.getTerminalError();return n?Promise.reject(n):this.socket.isConnected?Promise.resolve(this):new Promise((i,t)=>{let o=[],a=!1,s=()=>{for(let u of o)u.dispose();o.length=0},c=u=>{a||(a=!0,s(),u())};try{o.push(this.socket.onDidConnect(()=>c(()=>i(this)))),e.rejectOnClose&&o.push(this.socket.onDidClose(()=>c(()=>t(new Error("Connection closed"))))),o.push(this.socket.onDidBootError(u=>c(()=>t(u))))}catch(u){c(()=>t(u))}})}watchConnection(){this.socket.onDidConnect(()=>{this.socket.emit("okra.connected"),this.client.options.telemetry&&this.container.enableTelemetry(this.client.options.telemetry)}),this.socket.onDidClose(()=>{this.socket.emit("okra.disconnected"),this.initialized=!1}),this.socket.onDidBootError(e=>{this.socket.emit("okra.boot_error",e),this.socket.emit("okra.disconnected"),this.initialized=!1})}onDidConnect(e){this.socket.removeListener("okra.connected",e);let n=this.socket.listen("okra.connected",e);return this.disposables.push(n),n}onDidDisconnect(e){let n=this.socket.listen("okra.disconnected",e);return this.disposables.push(n),n}onDidBootError(e){let n=this.socket.listen("okra.boot_error",e);return this.disposables.push(n),n}update(){return this.invoke("notebook.update")}onDidInitialize(e){return this.listen("notebook.initialized",e)}async reconnect(){let e=this.whenConnected();return this.socket.reconnect(),this.initialized=!1,await e,pe(this,Ur,$l).call(this),this.ready().then(()=>this)}async beacon(e,n){let i=await this.ready();return e.src=i.data.previewUrl,uo(e,n)}};De=new WeakMap,Ur=new WeakSet,$l=function(){return Ji(this,De,new Promise((e,n)=>{let i=this.onDidInitialize(o=>{if(t.dispose(),i.dispose(),this.initialized=o,o.type==="error"){n(new Ni(o.message,o.data));return}e(o)}),t=this.onDidBootError(o=>{i.dispose(),t.dispose(),n(o)})})),Or(this,De).catch(()=>{}),Or(this,De)};var Li=class{constructor(e,n){this.client=e;this.notebookId=n}list(e){return this.client.notebook.secrets.list(this.notebookId,e)}set(e,n){return this.client.notebook.secrets.set(this.notebookId,e,n)}setMany(e){return this.client.notebook.secrets.setMany(this.notebookId,e)}delete(e,n){return this.client.notebook.secrets.delete(this.notebookId,e,n)}},Fi=class{constructor(e,n){this.client=e;this.notebookId=n}get(){return this.client.notebook.preview.get(this.notebookId)}setPassword(e){return this.client.notebook.preview.setPassword(this.notebookId,e)}disable(){return this.client.notebook.preview.disable(this.notebookId)}createSession(){return this.client.notebook.preview.createSession(this.notebookId)}createHandoff(e){return this.client.notebook.preview.createHandoff(this.notebookId,e)}},Mi=class{constructor(e,n){this.client=e;this.notebookId=n}status(){return this.client.notebook.mail.status(this.notebookId)}enable(){return this.client.notebook.mail.enable(this.notebookId)}disable(){return this.client.notebook.mail.disable(this.notebookId)}list(e={}){return this.client.notebook.mail.list(this.notebookId,e)}get(e){return this.client.notebook.mail.get(this.notebookId,e)}delete(e){return this.client.notebook.mail.delete(this.notebookId,e)}};function sb(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(cb);})();
|
|
71
71
|
/*! Bundled license information:
|
|
72
72
|
|
|
73
73
|
reconnecting-websocket/dist/reconnecting-websocket-mjs.js:
|
package/dist/index.js
CHANGED
|
@@ -122,7 +122,7 @@ export class NotebookApi {
|
|
|
122
122
|
}
|
|
123
123
|
async fork(id, input = {}) {
|
|
124
124
|
const response = await this.client.post(`/notebook/${id}/fork`, input);
|
|
125
|
-
return
|
|
125
|
+
return new NotebookInstance(response.data, this.client);
|
|
126
126
|
}
|
|
127
127
|
async gitCredentials(id) {
|
|
128
128
|
const response = await this.client.post(`/notebook/${id}/git/credentials`);
|
package/package.json
CHANGED