liveblocks 1.6.0 → 1.6.1
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.
|
@@ -433,9 +433,9 @@ that the user can disable this by setting it to "false".`}import{execSync as Ho}
|
|
|
433
433
|
</main>
|
|
434
434
|
</body>
|
|
435
435
|
</html>
|
|
436
|
-
`;var re=new sr({authorize:()=>!0});re.route("GET /v7",()=>Ut(426));re.route("GET /v8",()=>Ut(426));re.route("GET /health",()=>rr({status:"ok"}));re.route("GET /",()=>or(Mt.replace("__VERSION__","1.6.0")));import{ServerMsgCode as cr}from"@liveblocks/core";import{QueryParser as ur}from"@liveblocks/query-parser";import{ConsoleTarget as zt,jsonObjectYolo as lr,Logger as $t,ROOT_YDOC_ID as Ye,snapshotToLossyJson_eager as mr,snapshotToNodeStream as pr,snapshotToPlainLson_eager as Yt,transientClientMsgDecoder as fr}from"@liveblocks/server";import{json as Re,ndjsonStream as gr,ZenRouter as hr}from"@liveblocks/zenrouter";import{array as V,constant as Er,either as vr,enum_ as _r,nullable as Gt,object as Se,optional as z,record as pe,string as k}from"decoders";function*nr(t){for(let e of t)for(let o of e)yield o}function Bt(...t){return nr(t)}import{Base64 as Ir}from"js-base64";import*as Oe from"yjs";import*as b from"yjs";function ir(t){return t.content instanceof b.ContentFormat||t.content instanceof b.ContentEmbed?"text":"arr"in t.content?"array":"str"in t.content?"text":"type"in t.content?"xml":"unknown"}function ar(t){let e=[],o=t;for(;o!==null;){if(!o.deleted)if(o.content instanceof b.ContentType)e.push(o.content.type.toJSON());else if(o.content instanceof b.ContentString)e.push(o.content.str);else if(o.content instanceof b.ContentFormat){let{key:r,value:n}=o.content;e.push({key:r,value:n})}else o.content instanceof b.ContentEmbed&&e.push(o.content.embed);o=o.right}return e}function Ft(t,e,o,r=!1){if(!e._first&&e._map instanceof Map&&e._map.size>0)return t.getMap(o).toJSON();if(e._first!==null){let n=ir(e._first);if(n==="text")return r?ar(e._first):t.getText(o).toJSON();if(n==="array")return t.getArray(o).toJSON();if(n==="xml")return t.getXmlFragment(o).toJSON()}return e.toJSON()}var dr={ytext:b.Text,yxmlfragment:b.XmlFragment,yxmltext:b.XmlText,ymap:b.Map,yarray:b.Array};function Jt(t,e="",o=!1,r=""){let n={};if(e.length){if(t.share.has(e)){if(r.length){let a=dr[r];if(a)return t.get(e,a).toJSON()}return{[e]:Ft(t,t.share.get(e),e,o)}}return{[e]:""}}for(let[a,d]of t.share)n[a]=Ft(t,d,a,o);return n}var Vt=(o=>(o.PlainLson="plain-lson",o.LossyJson="json",o))(Vt||{}),Tr=_r(Vt),Ht=pe(k,vr(k,V(k))),i=new hr({authorize:({req:t})=>be(t)});function R(t){return Re({error:"ROOM_NOT_FOUND",message:`Room with id "${t}" not found.`},404)}var yr=new ur({fields:{roomId:"string"},indexableFields:{metadata:"token"}});function br(t){let e=yr.parse(t),o={};for(let r of e.query.allOf)switch(r.type){case"PrefixCondition":{r.field.type==="DirectField"&&r.field.ref.name==="roomId"&&(o.roomId={value:r.prefix.value,operator:"^"});break}case"ExactCondition":{r.field.type==="KeyedField"&&r.field.base.name==="metadata"&&r.value.type==="LiteralString"&&(o.metadata??={},o.metadata[r.field.key]=r.value.value);break}}return o}function Le(t){return{type:"room",id:t.id,organizationId:t.organizationId,createdAt:t.createdAt,metadata:t.metadata,defaultAccesses:t.defaultAccesses,groupsAccesses:t.groupsAccesses,usersAccesses:t.usersAccesses}}i.route("GET /v2/rooms/<roomId>",({p:t})=>{let e=I(t.roomId);if(!e)throw R(t.roomId);return Le(e)});i.route("GET /v2/rooms",({url:t})=>{let e,o=t.searchParams.get("query");if(o)try{e=br(o)}catch(d){return Re({error:"INVALID_QUERY",message:d instanceof Error?d.message:String(d)},422)}else{let d={};for(let[c,l]of t.searchParams.entries())c.startsWith("metadata.")&&(d[c.slice(9)]=l);Object.keys(d).length>0&&(e={metadata:d})}let r=t.searchParams.get("organizationId")??void 0;return r&&(e={...e,organizationId:r}),{data:pt(e).map(Le),nextPage:null,nextCursor:null}});i.route("POST /v2/rooms",Se({id:k,organizationId:z(k),defaultAccesses:z(V(k)),metadata:z(Ht),usersAccesses:z(pe(k,V(k))),groupsAccesses:z(pe(k,V(k)))}),({body:t,url:e})=>{if(!e.searchParams.has("idempotent")&&I(t.id))return Re({error:"ROOM_ALREADY_EXISTS",message:`Room with id "${t.id}" already exists.`},409);let r=Te(t.id,{organizationId:t.organizationId,defaultAccesses:t.defaultAccesses,metadata:t.metadata,usersAccesses:t.usersAccesses,groupsAccesses:t.groupsAccesses});return Le(r)});i.route("POST /v2/rooms/<roomId>",Se({defaultAccesses:z(V(k)),metadata:z(Ht),usersAccesses:z(pe(k,Gt(V(k)))),groupsAccesses:z(pe(k,Gt(V(k))))}),({p:t,body:e})=>{let o=ft(t.roomId,{defaultAccesses:e.defaultAccesses,metadata:e.metadata,usersAccesses:e.usersAccesses,groupsAccesses:e.groupsAccesses});if(!o)throw R(t.roomId);return Le(o)});i.route("DELETE /v2/rooms/<roomId>",async({p:t})=>(await gt(t.roomId),new Response(null,{status:204})));i.route("GET /v2/rooms/<roomId>/storage",({url:t,p:e})=>{if(!I(e.roomId))throw R(e.roomId);let o=Tr.value(t.searchParams.get("format"))??"plain-lson",n=U(e.roomId).storage.driver.get_snapshot(!1),a=o==="json"?mr(n):Yt(n);return new Response(JSON.stringify(a),{status:200,headers:{"Content-Type":"application/json"}})});i.route("POST /v2/rooms/<roomId>/storage",Se({liveblocksType:Er("LiveObject"),data:lr}).refineType(),({p:t,body:e})=>{if(!I(t.roomId))throw R(t.roomId);let o=U(t.roomId),r=o.storage.driver.get_snapshot(!1),n=Yt(r);return Object.keys(n.data).length>0?new Response(JSON.stringify({error:"CANNOT_UPDATE_EXISTING_STORAGE",message:"The room already has storage data. It's only possible to initialize the storage for an empty room.",suggestion:"Create another room or clear this room storage first."}),{status:409,headers:{"Content-Type":"application/json"}}):(o.driver.DANGEROUSLY_reset_nodes(e),o.unload(),new Response(JSON.stringify(e),{status:200,headers:{"Content-Type":"application/json"}}))});i.route("DELETE /v2/rooms/<roomId>/storage",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let e=U(t.roomId),o={liveblocksType:"LiveObject",data:{}};return e.driver.DANGEROUSLY_reset_nodes(o),e.unload(),new Response(null,{status:204})});i.route("GET /v2/rooms/<roomId>/ydoc",({url:t,p:e})=>{if(!I(e.roomId))throw R(e.roomId);let o=U(e.roomId),r=t.searchParams.get("key")??"",n=t.searchParams.get("type")??"",a=t.searchParams.get("guid")??Ye,d=t.searchParams.get("formatting")!==null,c=new $t(new zt("warning")),l=o.yjsStorage.getYDoc(c,a),S=Jt(l,r,d,n);return new Response(JSON.stringify(S),{status:200,headers:{"Content-Type":"application/json"}})});i.route("PUT /v2/rooms/<roomId>/ydoc",async({req:t,url:e,p:o})=>{if(t.headers.get("content-type")!=="application/octet-stream")return new Response(JSON.stringify({error:"BAD_REQUEST",message:'Expected "Content-Type" header to be "application/octet-stream", and the HTTP body to be a valid binary Yjs update.'}),{status:400,headers:{"Content-Type":"application/json"}});if(!I(o.roomId))throw R(o.roomId);let r=U(o.roomId),n=await t.arrayBuffer(),a=Ir.fromUint8Array(new Uint8Array(n)),d=e.searchParams.get("guid"),l=e.searchParams.get("encoder")==="v2",S=d&&d!==Ye?d:void 0;try{let J=await r.mutex.runExclusive(()=>r.yjsStorage.addYDocUpdate({},a,S,l)),g=N=>{};return r.sendToAll({type:cr.UPDATE_YDOC,update:a,isSync:!1,stateVector:null,guid:S,v2:l,remoteSnapshotHash:J.snapshotHash},void 0,g),new Response(JSON.stringify({success:!0}),{status:200,headers:{"Content-Type":"application/json"}})}catch(J){return new Response(JSON.stringify({error:"UNPROCESSABLE_ENTITY",message:J instanceof Error?J.message:"Could not apply update",suggestion:"Please ensure the update is correct, and you selected the correct encoder to use (v1 or v2)."}),{status:422,headers:{"Content-Type":"application/json"}})}});i.route("GET /v2/rooms/<roomId>/ydoc-binary",({url:t,p:e})=>{if(!I(e.roomId))throw R(e.roomId);let o=U(e.roomId),r=t.searchParams.get("guid")??Ye,n=t.searchParams.get("encoder"),a=new $t(new zt("warning")),d=o.yjsStorage.getYDoc(a,r),c=n==="v2"?Oe.encodeStateAsUpdateV2(d):Oe.encodeStateAsUpdate(d);return new Response(c,{status:200,headers:{"Content-Type":"application/octet-stream"}})});i.route("GET /v2/rooms/<roomId>/active_users",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let o=U(t.roomId).listSessions().map(r=>({type:"user",connectionId:r.actor,id:r.user.id,info:r.user.info}));return Re({data:o})});i.route("DELETE /v2/rooms/<roomId>/feeds/<feedId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({ok:!0})});i.route("DELETE /v2/rooms/<roomId>/feeds/<feedId>/messages/<messageId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({ok:!0})});i.route("GET /v2/rooms/<roomId>/feeds",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({feeds:[{feedId:"123",metadata:{title:"Test Feed",description:"This is a test feed"},timestamp:new Date().getTime()}],nextCursor:null})});i.route("GET /v2/rooms/<roomId>/feeds/<feedId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({feedId:"123",timestamp:new Date().getTime(),metadata:{title:"Test Feed",description:"This is a test feed"}})});i.route("GET /v2/rooms/<roomId>/feeds/<feedId>/messages",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({messages:[{messageId:"123",data:{content:"This is a test message"}}],nextCursor:null})});i.route("PATCH /v2/rooms/<roomId>/feeds/<feedId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let e=Date.now();return C({feedId:t.feedId,createdAt:e,updatedAt:e,metadata:{title:"Test Feed",description:"This is a test feed"}})});i.route("PATCH /v2/rooms/<roomId>/feeds/<feedId>/messages/<messageId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let e=Date.now();return C({id:t.messageId,createdAt:e,updatedAt:e,data:{content:"This is a test message"}})});i.route("POST /v2/rooms/<roomId>/feeds",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({feedId:"123",timestamp:new Date().getTime(),metadata:{title:"Test Feed",description:"This is a test feed"}})});i.route("POST /v2/rooms/<roomId>/feeds/<feedId>/messages",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({id:"123",timestamp:new Date().getTime(),data:{content:"This is a test message"}})});i.route("POST /v2/rooms/<roomId>/request-storage-mutation",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let e=U(t.roomId),o=e.getNextActor(),r=e.storage.driver.get_snapshot(!1);return gr(Bt([{actor:o}],pr(r)))});i.route("POST /v2/rooms/<roomId>/send-message",Se({messages:V(fr)}),async({p:t,body:e})=>{if(!I(t.roomId))throw R(t.roomId);let o=U(t.roomId),[r,n]=o.createBackendSession_experimental();return await o.processClientMsgFromBackendSession(r,e.messages),new Response(`{"messages":[${n.join(",")}]}`,{status:200,headers:{"Content-Type":"application/json; charset=utf-8"}})});i.route("PATCH /v2/rooms/<roomId>/storage/json-patch",()=>s()),i.route("POST /v2/rooms/<roomId>/presence",()=>s()),i.route("GET /v2/rooms/<roomId>/threads",()=>s()),i.route("POST /v2/rooms/<roomId>/upsert",()=>s()),i.route("POST /v2/rooms/<roomId>/update-room-id",()=>s()),i.route("POST /v2/rooms/<roomId>/update-organization-id",()=>s()),i.route("GET /v2/rooms/<roomId>/prewarm",()=>s()),i.route("POST /v2/rooms/<roomId>/broadcast_event",()=>s()),i.route("GET /v2/rooms/<roomId>/versions",()=>s()),i.route("GET /v2/rooms/<roomId>/version/<version>",()=>s()),i.route("POST /v2/rooms/<roomId>/version",()=>s()),i.route("POST /v2/rooms/<roomId>/threads",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/mark-as-resolved",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/mark-as-unresolved",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/subscribe",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/unsubscribe",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>/subscriptions",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/metadata",()=>s()),i.route("DELETE /v2/rooms/<roomId>/threads/<threadId>",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>/participants",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>/inbox-notifications",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>/metadata",()=>s()),i.route("DELETE /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>/add-reaction",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>/remove-reaction",()=>s()),i.route("GET /v2/rooms/<roomId>/attachments/<attachmentId>",()=>s()),i.route("GET /v2/rooms/<roomId>/users/<userId>/notification-settings",()=>s()),i.route("GET /v2/rooms/<roomId>/users/<userId>/subscription-settings",()=>s()),i.route("POST /v2/rooms/<roomId>/users/<userId>/notification-settings",()=>s()),i.route("POST /v2/rooms/<roomId>/users/<userId>/subscription-settings",()=>s()),i.route("DELETE /v2/rooms/<roomId>/users/<userId>/notification-settings",()=>s()),i.route("DELETE /v2/rooms/<roomId>/users/<userId>/subscription-settings",()=>s()),i.route("GET /v2/users/<userId>/inbox-notifications/<inboxNotificationId>",()=>s()),i.route("DELETE /v2/users/<userId>/inbox-notifications/<inboxNotificationId>",()=>s()),i.route("GET /v2/users/<userId>/inbox-notifications",()=>s()),i.route("DELETE /v2/users/<userId>/inbox-notifications",()=>s()),i.route("GET /v2/users/<userId>/notification-settings",()=>s()),i.route("POST /v2/users/<userId>/notification-settings",()=>s()),i.route("DELETE /v2/users/<userId>/notification-settings",()=>s()),i.route("GET /v2/users/<userId>/room-subscription-settings",()=>s()),i.route("POST /v2/inbox-notifications/trigger",()=>s()),i.route("POST /v2/inbox-notifications/<inboxNotificationId>/read",()=>s()),i.route("POST /v2/groups",()=>s()),i.route("GET /v2/groups/<groupId>",()=>s()),i.route("POST /v2/groups/<groupId>/add-members",()=>s()),i.route("POST /v2/groups/<groupId>/remove-members",()=>s()),i.route("DELETE /v2/groups/<groupId>",()=>s()),i.route("GET /v2/groups",()=>s()),i.route("GET /v2/users/<userId>/groups",()=>s()),i.route("GET /v2/ai/copilots",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>/knowledge",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>/knowledge/<knowledgeSourceId>",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>/knowledge/file/<knowledgeSourceId>",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>/knowledge/web/<knowledgeSourceId>/links",()=>s()),i.route("POST /v2/ai/copilots",()=>s()),i.route("POST /v2/ai/copilots/<copilotId>",()=>s()),i.route("POST /v2/ai/copilots/<copilotId>/knowledge/web",()=>s()),i.route("DELETE /v2/ai/copilots/<copilotId>",()=>s()),i.route("DELETE /v2/ai/copilots/<copilotId>/knowledge/file/<knowledgeSourceId>",()=>s()),i.route("DELETE /v2/ai/copilots/<copilotId>/knowledge/web/<knowledgeSourceId>",()=>s()),i.route("PUT /v2/ai/copilots/<copilotId>/knowledge/file/<fileName>",()=>s()),i.route("GET /v2/management/projects",()=>s()),i.route("GET /v2/management/projects/<projectId>",()=>s()),i.route("POST /v2/management/projects",()=>s()),i.route("POST /v2/management/projects/<projectId>",()=>s()),i.route("DELETE /v2/management/projects/<projectId>",()=>s()),i.route("GET /v2/management/projects/<projectId>/webhooks",()=>s()),i.route("GET /v2/management/projects/<projectId>/webhooks/<webhookId>",()=>s()),i.route("GET /v2/management/projects/<projectId>/webhooks/<webhookId>/additional-headers",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/additional-headers",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/delete-additional-headers",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/recover-failed-messages",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/secret/roll",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/test",()=>s()),i.route("DELETE /v2/management/projects/<projectId>/webhooks/<webhookId>",()=>s()),i.route("POST /v2/management/projects/<projectId>/api-keys/public/activate",()=>s()),i.route("POST /v2/management/projects/<projectId>/api-keys/public/deactivate",()=>s()),i.route("POST /v2/management/projects/<projectId>/api-keys/public/roll",()=>s()),i.route("POST /v2/management/projects/<projectId>/api-keys/secret/roll",()=>s());function Xt(t,e,o,r){if(!t.upgrade(e,{data:{refuseConnection:{code:o,message:r}}}))return new Response("Could not upgrade to WebSocket",{status:426})}var se=new Sr;se.relay("/v2/authorize-user/*",me);se.relay("/v2/identify-user/*",me);se.relay("/v2/c/*",u);se.relay("/v2/*",i);se.relay("/*",re);var He=1153;function qt(t){if(t===void 0)return;let e=Number(t);return Number.isInteger(e)&&e>0&&e<=65535?e:void 0}function Lr(t){return process.platform==="win32"?[process.env.COMSPEC||"cmd.exe","/c",t]:["sh","-c",t]}function Cr(t){return"'"+t.replace(/'/g,"'\\''")+"'"}var Nr={description:"Start the local Liveblocks dev server",async run(t){let{options:e,args:o}=Xe(t,{port:{type:"string",short:"p",default:He.toString()},"random-port":{type:"boolean",short:"P",default:!1},host:{type:"string"},cmd:{type:"string",short:"c"},help:{type:"boolean",short:"h",default:!1},"no-check":{type:"boolean",default:!1},ci:{type:"boolean",default:!1},verbose:{type:"boolean",short:"v",default:!1}},{allowPositionals:!0});if(o.length>0&&!e.cmd&&(console.error(ae("Extra arguments are only supported with --cmd (-c)")),process.exit(1)),o.length>0&&e.cmd){let y=o.map(Cr).join(" ");e.cmd.includes("{}")?e.cmd=e.cmd.replaceAll("{}",y):e.cmd+=" "+y}if(e.help){console.log("Usage: liveblocks dev [options]"),console.log(),console.log("Start the local Liveblocks dev server"),console.log(),console.log("Options:"),console.log(` --port, -p Port to listen on (default: ${He})`),console.log(" --random-port, -P Bind a random free port instead of --port (no collisions,"),console.log(" ever). With --cmd, the chosen port is exposed to the command"),console.log(" via LIVEBLOCKS_DEV_SERVER_PORT. Ideal for CI."),console.log(" --host Host to bind to (default: localhost)"),console.log(" --cmd, -c Run a one-off command against a fresh server instance, then"),console.log(" shut down. Does not affect your local data in .liveblocks/."),console.log(" Extra args are appended to the command, or replace {} if"),console.log(" present. Use -- before args starting with -."),console.log(" --ci Start a fresh server instance on every boot, ideal for CI"),console.log(" --no-check Skip project setup check on start"),console.log(" --verbose, -v Show verbose output"),console.log(" --help, -h Show help");return}let r=!1;e.ci&&(r=!0,e["no-check"]=!0),e.cmd&&(r=!0,e["no-check"]=!0);let n=e["random-port"]?0:qt(e.port)??qt(process.env.LIVEBLOCKS_DEVSERVER_PORT)??He,a=e.host||process.env.LIVEBLOCKS_DEVSERVER_HOST||"localhost",d=r?mt():null;n!==0&&await kt(n,a)&&(console.error(`Port ${n} is already in use.
|
|
436
|
+
`;var re=new sr({authorize:()=>!0});re.route("GET /v7",()=>Ut(426));re.route("GET /v8",()=>Ut(426));re.route("GET /health",()=>rr({status:"ok"}));re.route("GET /",()=>or(Mt.replace("__VERSION__","1.6.1")));import{ServerMsgCode as cr}from"@liveblocks/core";import{QueryParser as ur}from"@liveblocks/query-parser";import{ConsoleTarget as zt,jsonObjectYolo as lr,Logger as $t,ROOT_YDOC_ID as Ye,snapshotToLossyJson_eager as mr,snapshotToNodeStream as pr,snapshotToPlainLson_eager as Yt,transientClientMsgDecoder as fr}from"@liveblocks/server";import{json as Re,ndjsonStream as gr,ZenRouter as hr}from"@liveblocks/zenrouter";import{array as V,constant as Er,either as vr,enum_ as _r,nullable as Gt,object as Se,optional as z,record as pe,string as k}from"decoders";function*nr(t){for(let e of t)for(let o of e)yield o}function Bt(...t){return nr(t)}import{Base64 as Ir}from"js-base64";import*as Oe from"yjs";import*as b from"yjs";function ir(t){return t.content instanceof b.ContentFormat||t.content instanceof b.ContentEmbed?"text":"arr"in t.content?"array":"str"in t.content?"text":"type"in t.content?"xml":"unknown"}function ar(t){let e=[],o=t;for(;o!==null;){if(!o.deleted)if(o.content instanceof b.ContentType)e.push(o.content.type.toJSON());else if(o.content instanceof b.ContentString)e.push(o.content.str);else if(o.content instanceof b.ContentFormat){let{key:r,value:n}=o.content;e.push({key:r,value:n})}else o.content instanceof b.ContentEmbed&&e.push(o.content.embed);o=o.right}return e}function Ft(t,e,o,r=!1){if(!e._first&&e._map instanceof Map&&e._map.size>0)return t.getMap(o).toJSON();if(e._first!==null){let n=ir(e._first);if(n==="text")return r?ar(e._first):t.getText(o).toJSON();if(n==="array")return t.getArray(o).toJSON();if(n==="xml")return t.getXmlFragment(o).toJSON()}return e.toJSON()}var dr={ytext:b.Text,yxmlfragment:b.XmlFragment,yxmltext:b.XmlText,ymap:b.Map,yarray:b.Array};function Jt(t,e="",o=!1,r=""){let n={};if(e.length){if(t.share.has(e)){if(r.length){let a=dr[r];if(a)return t.get(e,a).toJSON()}return{[e]:Ft(t,t.share.get(e),e,o)}}return{[e]:""}}for(let[a,d]of t.share)n[a]=Ft(t,d,a,o);return n}var Vt=(o=>(o.PlainLson="plain-lson",o.LossyJson="json",o))(Vt||{}),Tr=_r(Vt),Ht=pe(k,vr(k,V(k))),i=new hr({authorize:({req:t})=>be(t)});function R(t){return Re({error:"ROOM_NOT_FOUND",message:`Room with id "${t}" not found.`},404)}var yr=new ur({fields:{roomId:"string"},indexableFields:{metadata:"token"}});function br(t){let e=yr.parse(t),o={};for(let r of e.query.allOf)switch(r.type){case"PrefixCondition":{r.field.type==="DirectField"&&r.field.ref.name==="roomId"&&(o.roomId={value:r.prefix.value,operator:"^"});break}case"ExactCondition":{r.field.type==="KeyedField"&&r.field.base.name==="metadata"&&r.value.type==="LiteralString"&&(o.metadata??={},o.metadata[r.field.key]=r.value.value);break}}return o}function Le(t){return{type:"room",id:t.id,organizationId:t.organizationId,createdAt:t.createdAt,metadata:t.metadata,defaultAccesses:t.defaultAccesses,groupsAccesses:t.groupsAccesses,usersAccesses:t.usersAccesses}}i.route("GET /v2/rooms/<roomId>",({p:t})=>{let e=I(t.roomId);if(!e)throw R(t.roomId);return Le(e)});i.route("GET /v2/rooms",({url:t})=>{let e,o=t.searchParams.get("query");if(o)try{e=br(o)}catch(d){return Re({error:"INVALID_QUERY",message:d instanceof Error?d.message:String(d)},422)}else{let d={};for(let[c,l]of t.searchParams.entries())c.startsWith("metadata.")&&(d[c.slice(9)]=l);Object.keys(d).length>0&&(e={metadata:d})}let r=t.searchParams.get("organizationId")??void 0;return r&&(e={...e,organizationId:r}),{data:pt(e).map(Le),nextPage:null,nextCursor:null}});i.route("POST /v2/rooms",Se({id:k,organizationId:z(k),defaultAccesses:z(V(k)),metadata:z(Ht),usersAccesses:z(pe(k,V(k))),groupsAccesses:z(pe(k,V(k)))}),({body:t,url:e})=>{if(!e.searchParams.has("idempotent")&&I(t.id))return Re({error:"ROOM_ALREADY_EXISTS",message:`Room with id "${t.id}" already exists.`},409);let r=Te(t.id,{organizationId:t.organizationId,defaultAccesses:t.defaultAccesses,metadata:t.metadata,usersAccesses:t.usersAccesses,groupsAccesses:t.groupsAccesses});return Le(r)});i.route("POST /v2/rooms/<roomId>",Se({defaultAccesses:z(V(k)),metadata:z(Ht),usersAccesses:z(pe(k,Gt(V(k)))),groupsAccesses:z(pe(k,Gt(V(k))))}),({p:t,body:e})=>{let o=ft(t.roomId,{defaultAccesses:e.defaultAccesses,metadata:e.metadata,usersAccesses:e.usersAccesses,groupsAccesses:e.groupsAccesses});if(!o)throw R(t.roomId);return Le(o)});i.route("DELETE /v2/rooms/<roomId>",async({p:t})=>(await gt(t.roomId),new Response(null,{status:204})));i.route("GET /v2/rooms/<roomId>/storage",({url:t,p:e})=>{if(!I(e.roomId))throw R(e.roomId);let o=Tr.value(t.searchParams.get("format"))??"plain-lson",n=U(e.roomId).storage.driver.get_snapshot(!1),a=o==="json"?mr(n):Yt(n);return new Response(JSON.stringify(a),{status:200,headers:{"Content-Type":"application/json"}})});i.route("POST /v2/rooms/<roomId>/storage",Se({liveblocksType:Er("LiveObject"),data:lr}).refineType(),({p:t,body:e})=>{if(!I(t.roomId))throw R(t.roomId);let o=U(t.roomId),r=o.storage.driver.get_snapshot(!1),n=Yt(r);return Object.keys(n.data).length>0?new Response(JSON.stringify({error:"CANNOT_UPDATE_EXISTING_STORAGE",message:"The room already has storage data. It's only possible to initialize the storage for an empty room.",suggestion:"Create another room or clear this room storage first."}),{status:409,headers:{"Content-Type":"application/json"}}):(o.driver.DANGEROUSLY_reset_nodes(e),o.unload(),new Response(JSON.stringify(e),{status:200,headers:{"Content-Type":"application/json"}}))});i.route("DELETE /v2/rooms/<roomId>/storage",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let e=U(t.roomId),o={liveblocksType:"LiveObject",data:{}};return e.driver.DANGEROUSLY_reset_nodes(o),e.unload(),new Response(null,{status:204})});i.route("GET /v2/rooms/<roomId>/ydoc",({url:t,p:e})=>{if(!I(e.roomId))throw R(e.roomId);let o=U(e.roomId),r=t.searchParams.get("key")??"",n=t.searchParams.get("type")??"",a=t.searchParams.get("guid")??Ye,d=t.searchParams.get("formatting")!==null,c=new $t(new zt("warning")),l=o.yjsStorage.getYDoc(c,a),S=Jt(l,r,d,n);return new Response(JSON.stringify(S),{status:200,headers:{"Content-Type":"application/json"}})});i.route("PUT /v2/rooms/<roomId>/ydoc",async({req:t,url:e,p:o})=>{if(t.headers.get("content-type")!=="application/octet-stream")return new Response(JSON.stringify({error:"BAD_REQUEST",message:'Expected "Content-Type" header to be "application/octet-stream", and the HTTP body to be a valid binary Yjs update.'}),{status:400,headers:{"Content-Type":"application/json"}});if(!I(o.roomId))throw R(o.roomId);let r=U(o.roomId),n=await t.arrayBuffer(),a=Ir.fromUint8Array(new Uint8Array(n)),d=e.searchParams.get("guid"),l=e.searchParams.get("encoder")==="v2",S=d&&d!==Ye?d:void 0;try{let J=await r.mutex.runExclusive(()=>r.yjsStorage.addYDocUpdate({},a,S,l)),g=N=>{};return r.sendToAll({type:cr.UPDATE_YDOC,update:a,isSync:!1,stateVector:null,guid:S,v2:l,remoteSnapshotHash:J.snapshotHash},void 0,g),new Response(JSON.stringify({success:!0}),{status:200,headers:{"Content-Type":"application/json"}})}catch(J){return new Response(JSON.stringify({error:"UNPROCESSABLE_ENTITY",message:J instanceof Error?J.message:"Could not apply update",suggestion:"Please ensure the update is correct, and you selected the correct encoder to use (v1 or v2)."}),{status:422,headers:{"Content-Type":"application/json"}})}});i.route("GET /v2/rooms/<roomId>/ydoc-binary",({url:t,p:e})=>{if(!I(e.roomId))throw R(e.roomId);let o=U(e.roomId),r=t.searchParams.get("guid")??Ye,n=t.searchParams.get("encoder"),a=new $t(new zt("warning")),d=o.yjsStorage.getYDoc(a,r),c=n==="v2"?Oe.encodeStateAsUpdateV2(d):Oe.encodeStateAsUpdate(d);return new Response(c,{status:200,headers:{"Content-Type":"application/octet-stream"}})});i.route("GET /v2/rooms/<roomId>/active_users",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let o=U(t.roomId).listSessions().map(r=>({type:"user",connectionId:r.actor,id:r.user.id,info:r.user.info}));return Re({data:o})});i.route("DELETE /v2/rooms/<roomId>/feeds/<feedId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({ok:!0})});i.route("DELETE /v2/rooms/<roomId>/feeds/<feedId>/messages/<messageId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({ok:!0})});i.route("GET /v2/rooms/<roomId>/feeds",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({feeds:[{feedId:"123",metadata:{title:"Test Feed",description:"This is a test feed"},timestamp:new Date().getTime()}],nextCursor:null})});i.route("GET /v2/rooms/<roomId>/feeds/<feedId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({feedId:"123",timestamp:new Date().getTime(),metadata:{title:"Test Feed",description:"This is a test feed"}})});i.route("GET /v2/rooms/<roomId>/feeds/<feedId>/messages",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({messages:[{messageId:"123",data:{content:"This is a test message"}}],nextCursor:null})});i.route("PATCH /v2/rooms/<roomId>/feeds/<feedId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let e=Date.now();return C({feedId:t.feedId,createdAt:e,updatedAt:e,metadata:{title:"Test Feed",description:"This is a test feed"}})});i.route("PATCH /v2/rooms/<roomId>/feeds/<feedId>/messages/<messageId>",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let e=Date.now();return C({id:t.messageId,createdAt:e,updatedAt:e,data:{content:"This is a test message"}})});i.route("POST /v2/rooms/<roomId>/feeds",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({feedId:"123",timestamp:new Date().getTime(),metadata:{title:"Test Feed",description:"This is a test feed"}})});i.route("POST /v2/rooms/<roomId>/feeds/<feedId>/messages",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);return C({id:"123",timestamp:new Date().getTime(),data:{content:"This is a test message"}})});i.route("POST /v2/rooms/<roomId>/request-storage-mutation",({p:t})=>{if(!I(t.roomId))throw R(t.roomId);let e=U(t.roomId),o=e.getNextActor(),r=e.storage.driver.get_snapshot(!1);return gr(Bt([{actor:o}],pr(r)))});i.route("POST /v2/rooms/<roomId>/send-message",Se({messages:V(fr)}),async({p:t,body:e})=>{if(!I(t.roomId))throw R(t.roomId);let o=U(t.roomId),[r,n]=o.createBackendSession_experimental();return await o.processClientMsgFromBackendSession(r,e.messages),new Response(`{"messages":[${n.join(",")}]}`,{status:200,headers:{"Content-Type":"application/json; charset=utf-8"}})});i.route("PATCH /v2/rooms/<roomId>/storage/json-patch",()=>s()),i.route("POST /v2/rooms/<roomId>/presence",()=>s()),i.route("GET /v2/rooms/<roomId>/threads",()=>s()),i.route("POST /v2/rooms/<roomId>/upsert",()=>s()),i.route("POST /v2/rooms/<roomId>/update-room-id",()=>s()),i.route("POST /v2/rooms/<roomId>/update-organization-id",()=>s()),i.route("GET /v2/rooms/<roomId>/prewarm",()=>s()),i.route("POST /v2/rooms/<roomId>/broadcast_event",()=>s()),i.route("GET /v2/rooms/<roomId>/versions",()=>s()),i.route("GET /v2/rooms/<roomId>/version/<version>",()=>s()),i.route("POST /v2/rooms/<roomId>/version",()=>s()),i.route("POST /v2/rooms/<roomId>/threads",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/mark-as-resolved",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/mark-as-unresolved",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/subscribe",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/unsubscribe",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>/subscriptions",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/metadata",()=>s()),i.route("DELETE /v2/rooms/<roomId>/threads/<threadId>",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>/participants",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>/inbox-notifications",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments",()=>s()),i.route("GET /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>/metadata",()=>s()),i.route("DELETE /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>/add-reaction",()=>s()),i.route("POST /v2/rooms/<roomId>/threads/<threadId>/comments/<commentId>/remove-reaction",()=>s()),i.route("GET /v2/rooms/<roomId>/attachments/<attachmentId>",()=>s()),i.route("GET /v2/rooms/<roomId>/users/<userId>/notification-settings",()=>s()),i.route("GET /v2/rooms/<roomId>/users/<userId>/subscription-settings",()=>s()),i.route("POST /v2/rooms/<roomId>/users/<userId>/notification-settings",()=>s()),i.route("POST /v2/rooms/<roomId>/users/<userId>/subscription-settings",()=>s()),i.route("DELETE /v2/rooms/<roomId>/users/<userId>/notification-settings",()=>s()),i.route("DELETE /v2/rooms/<roomId>/users/<userId>/subscription-settings",()=>s()),i.route("GET /v2/users/<userId>/inbox-notifications/<inboxNotificationId>",()=>s()),i.route("DELETE /v2/users/<userId>/inbox-notifications/<inboxNotificationId>",()=>s()),i.route("GET /v2/users/<userId>/inbox-notifications",()=>s()),i.route("DELETE /v2/users/<userId>/inbox-notifications",()=>s()),i.route("GET /v2/users/<userId>/notification-settings",()=>s()),i.route("POST /v2/users/<userId>/notification-settings",()=>s()),i.route("DELETE /v2/users/<userId>/notification-settings",()=>s()),i.route("GET /v2/users/<userId>/room-subscription-settings",()=>s()),i.route("POST /v2/inbox-notifications/trigger",()=>s()),i.route("POST /v2/inbox-notifications/<inboxNotificationId>/read",()=>s()),i.route("POST /v2/groups",()=>s()),i.route("GET /v2/groups/<groupId>",()=>s()),i.route("POST /v2/groups/<groupId>/add-members",()=>s()),i.route("POST /v2/groups/<groupId>/remove-members",()=>s()),i.route("DELETE /v2/groups/<groupId>",()=>s()),i.route("GET /v2/groups",()=>s()),i.route("GET /v2/users/<userId>/groups",()=>s()),i.route("GET /v2/ai/copilots",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>/knowledge",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>/knowledge/<knowledgeSourceId>",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>/knowledge/file/<knowledgeSourceId>",()=>s()),i.route("GET /v2/ai/copilots/<copilotId>/knowledge/web/<knowledgeSourceId>/links",()=>s()),i.route("POST /v2/ai/copilots",()=>s()),i.route("POST /v2/ai/copilots/<copilotId>",()=>s()),i.route("POST /v2/ai/copilots/<copilotId>/knowledge/web",()=>s()),i.route("DELETE /v2/ai/copilots/<copilotId>",()=>s()),i.route("DELETE /v2/ai/copilots/<copilotId>/knowledge/file/<knowledgeSourceId>",()=>s()),i.route("DELETE /v2/ai/copilots/<copilotId>/knowledge/web/<knowledgeSourceId>",()=>s()),i.route("PUT /v2/ai/copilots/<copilotId>/knowledge/file/<fileName>",()=>s()),i.route("GET /v2/management/projects",()=>s()),i.route("GET /v2/management/projects/<projectId>",()=>s()),i.route("POST /v2/management/projects",()=>s()),i.route("POST /v2/management/projects/<projectId>",()=>s()),i.route("DELETE /v2/management/projects/<projectId>",()=>s()),i.route("GET /v2/management/projects/<projectId>/webhooks",()=>s()),i.route("GET /v2/management/projects/<projectId>/webhooks/<webhookId>",()=>s()),i.route("GET /v2/management/projects/<projectId>/webhooks/<webhookId>/additional-headers",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/additional-headers",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/delete-additional-headers",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/recover-failed-messages",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/secret/roll",()=>s()),i.route("POST /v2/management/projects/<projectId>/webhooks/<webhookId>/test",()=>s()),i.route("DELETE /v2/management/projects/<projectId>/webhooks/<webhookId>",()=>s()),i.route("POST /v2/management/projects/<projectId>/api-keys/public/activate",()=>s()),i.route("POST /v2/management/projects/<projectId>/api-keys/public/deactivate",()=>s()),i.route("POST /v2/management/projects/<projectId>/api-keys/public/roll",()=>s()),i.route("POST /v2/management/projects/<projectId>/api-keys/secret/roll",()=>s());function Xt(t,e,o,r){if(!t.upgrade(e,{data:{refuseConnection:{code:o,message:r}}}))return new Response("Could not upgrade to WebSocket",{status:426})}var se=new Sr;se.relay("/v2/authorize-user/*",me);se.relay("/v2/identify-user/*",me);se.relay("/v2/c/*",u);se.relay("/v2/*",i);se.relay("/*",re);var He=1153;function qt(t){if(t===void 0)return;let e=Number(t);return Number.isInteger(e)&&e>0&&e<=65535?e:void 0}function Lr(t){return process.platform==="win32"?[process.env.COMSPEC||"cmd.exe","/c",t]:["sh","-c",t]}function Cr(t){return"'"+t.replace(/'/g,"'\\''")+"'"}var Nr={description:"Start the local Liveblocks dev server",async run(t){let{options:e,args:o}=Xe(t,{port:{type:"string",short:"p",default:He.toString()},"random-port":{type:"boolean",short:"P",default:!1},host:{type:"string"},cmd:{type:"string",short:"c"},help:{type:"boolean",short:"h",default:!1},"no-check":{type:"boolean",default:!1},ci:{type:"boolean",default:!1},verbose:{type:"boolean",short:"v",default:!1}},{allowPositionals:!0});if(o.length>0&&!e.cmd&&(console.error(ae("Extra arguments are only supported with --cmd (-c)")),process.exit(1)),o.length>0&&e.cmd){let y=o.map(Cr).join(" ");e.cmd.includes("{}")?e.cmd=e.cmd.replaceAll("{}",y):e.cmd+=" "+y}if(e.help){console.log("Usage: liveblocks dev [options]"),console.log(),console.log("Start the local Liveblocks dev server"),console.log(),console.log("Options:"),console.log(` --port, -p Port to listen on (default: ${He})`),console.log(" --random-port, -P Bind a random free port instead of --port (no collisions,"),console.log(" ever). With --cmd, the chosen port is exposed to the command"),console.log(" via LIVEBLOCKS_DEV_SERVER_PORT. Ideal for CI."),console.log(" --host Host to bind to (default: localhost)"),console.log(" --cmd, -c Run a one-off command against a fresh server instance, then"),console.log(" shut down. Does not affect your local data in .liveblocks/."),console.log(" Extra args are appended to the command, or replace {} if"),console.log(" present. Use -- before args starting with -."),console.log(" --ci Start a fresh server instance on every boot, ideal for CI"),console.log(" --no-check Skip project setup check on start"),console.log(" --verbose, -v Show verbose output"),console.log(" --help, -h Show help");return}let r=!1;e.ci&&(r=!0,e["no-check"]=!0),e.cmd&&(r=!0,e["no-check"]=!0);let n=e["random-port"]?0:qt(e.port)??qt(process.env.LIVEBLOCKS_DEVSERVER_PORT)??He,a=e.host||process.env.LIVEBLOCKS_DEVSERVER_HOST||"localhost",d=r?mt():null;n!==0&&await kt(n,a)&&(console.error(`Port ${n} is already in use.
|
|
437
437
|
Is another dev server already running?`),process.exit(1));let c,l=!1,S=n;function J(){let y=Ve.serve({hostname:a,port:S,async fetch(h,v){if(h.headers.get("Upgrade")==="websocket"){let F=Ct(h);if(!F.ok)return Je(F.xwarn,!0),Xt(v,h,Wt.NOT_ALLOWED,"You have no access to this room");let{roomId:$,ticketData:L}=F;if(Et($))return Xt(v,h,Wt.TRY_AGAIN_LATER,"Server is undergoing maintenance, try again later");let w=U($),G=w.createTicket(L),fe=G.sessionKey;if(v.upgrade(h,{data:{room:w,ticket:G,sessionKey:fe}})){console.log(`${B("101")} WS ${new URL(h.url).pathname}${m(` - ${$}`)}`);return}return new Response("Could not upgrade to WebSocket",{status:426})}let O=new URL(h.url);if(h.method==="POST"&&O.pathname==="/crash")return console.log(`${B("204")} POST /crash`),setTimeout(()=>{g()},0),new Response(null,{status:204});let T=`${h.method} ${O.pathname}`,P;if(l)try{P=await h.clone().text()}catch{}let H=await se.fetch(h),j=H.status,ne=j>=500?ae(j):j>=400?q(j):B(j);console.log(`${ne} ${T}`);let _=H.headers.get("X-LB-Warn")??void 0;if(Je(_,!H.ok),l){if(P){let L=Kt(P);L!==void 0&&console.log(m(` \u2192 ${JSON.stringify(L)}`))}let F=await H.clone().text(),$=Kt(F);$!==void 0&&console.log(m(` \u2190 ${JSON.stringify($)}`))}return H},error(h){return console.error(h),new Response("An unknown error occurred",{status:500})},websocket:{open(h){let{refuseConnection:v,room:O,ticket:T}=h.data;if(v){h.close(v.code,v.message);return}O&&T&&O.startBrowserSession(T,h)},async message(h,v){let{room:O,sessionKey:T}=h.data;O&&T&&await O.handleData(T,v)},close(h,v,O){let{room:T,sessionKey:P}=h.data;T&&P&&T.endBrowserSession(P,v,O)}}});return S=y.port,y}c=J();async function g(){_t(),await c.stop(!0),c=J(),console.log("Crash \u{1F4A5}")}let N=y=>process.stderr.write(y+`
|
|
438
|
-
`);if(e.cmd){N(`Liveblocks dev server ${m("v1.6.
|
|
438
|
+
`);if(e.cmd){N(`Liveblocks dev server ${m("v1.6.1")} running at http://${c.hostname}:${c.port}`),d&&e.verbose&&N(m(`Ephemeral mode, using ${d}`));let y=Or(d,"server.log");N(m(`Server logs: ${y}`));let h=Ve.file(y).writer(),v=(...T)=>{h.write(T.map(String).join(" ")+`
|
|
439
439
|
`),h.flush()};console.log=v,console.error=v;let O=1;try{let T=Ve.spawn(Lr(e.cmd),{stdin:"inherit",stdout:"inherit",stderr:"inherit",env:{...process.env,LIVEBLOCKS_DEV_SERVER_HOST:a,LIVEBLOCKS_DEV_SERVER_PORT:String(c.port)}}),P=()=>{T.kill()};process.on("SIGTERM",P),process.on("SIGINT",P),O=await T.exited}finally{h.end(),await c.stop(),Pe(),N(m("Liveblocks dev server shut down"))}process.exit(O)}else{let y=`http://${a}:${c.port}`,h=e["no-check"]?[]:await wt(y),v="logs",O=null,T=null,P=null,H=`http://${c.hostname}:${c.port}`,j=()=>{let E=v==="logs"?A(" Logs "):m(" Logs "),f=v==="sockets"?A(" Sockets "):m(" Sockets "),p=E+m("|")+f,ie=(T?Y("\u23F8 maintenance")+" ":"")+m(`Liveblocks running at ${H}`),Ce=process.stdout.columns??80,Ne=Math.max(1,Ce-we(p).length-we(ie).length);return p+" ".repeat(Ne)+ie},ne=[],_=console.log.bind(console);console.log=(...E)=>{let f=E.map(String).join(" ");ne.push(f),v==="logs"&&_(f)};let F=()=>m(" ")+A("q")+m(" quit, ")+A("!")+m(" crash, ")+A("c")+m(" clear, ")+A("v")+m(l?" verbose (on)":" verbose"),$=()=>{P&&(clearInterval(P),P=null),v="logs",process.stdout.write("\x1B[2J\x1B[H"),_(j()),_(F()),_();for(let E of ne)_(E)},L=0,w=[],G=E=>`${E.roomId}:${E.actor}`,fe=()=>{w=ue().map(E=>({...E,alive:!0}))},Ke=()=>{let E=new Set(ue().map(G));for(let p of w)p.alive=E.has(G(p));let f=new Set(w.map(G));for(let p of ue())f.has(G(p))||w.push({...p,alive:!0})},Zt=E=>{let f=Date.now()-E,p=Math.floor(f/1e3);if(p<60)return`${p}s`;let D=Math.floor(p/60);return D<60?`${D}m`:`${Math.floor(D/60)}h`},Qt=E=>{if(!E)return"";let f=Date.now()-E;return f<1e3?" "+B("\u25CF"):f<3e3?" "+m(B("\u25CF")):f<5e3?" "+m("\u25CF"):""},ge=(E,f)=>{let p=E+f;for(;p>=0&&p<w.length;){if(w[p].alive)return p;p+=f}return E},K=()=>{Ke();let E=w.filter(p=>p.alive).length;if(process.stdout.write("\x1B[2J\x1B[H"),_(j()),_(m(" ")+A("\u2191\u2193")+m(" navigate, ")+A("k")+m(" kill, ")+A("m")+m(T?" maintenance off, ":" maintenance on, ")+A("r")+m(" refresh")),_(),_(" "+A("Connections")+m(` (${E} alive)`)),_(),w.length===0){_(m(" No active connections"));return}if(L>=w.length&&(L=w.length-1),!w[L]?.alive){let p=ge(L,-1);L=w[p]?.alive?p:ge(L,1)}let f=new Map;for(let p of ue())f.set(G(p),p.lastActiveAt);for(let p=0;p<w.length;p++){let D=w[p];if(!D.alive){_(m(` ${D.roomId} \xB7 actor=${D.actor} \xB7 disconnected`));continue}let ie=p===L?B("\u25B6 "):" ",Ce=D.userId??m("anonymous"),Ne=Zt(D.connectedAt),oo=f.get(G(D)),ro=Qt(oo);_(`${ie}${A(D.roomId)} ${m("\xB7")} actor=${D.actor} ${m("\xB7")} ${Ce} ${m("\xB7")} ${m(Ne)}${ro}`)}},eo=()=>{v="sockets",L=0,fe(),K(),P=setInterval(()=>K(),1e3)},to=()=>{if(T)T(),T=null;else{let{promise:E,resolve:f}=Rr();ht(E),T=f}};process.stdout.write("\x1B[2J\x1B[H"),_(j()),_(F()),_(),d&&e.verbose&&console.log(m(`Ephemeral mode, using ${d}`)),process.stdin.setRawMode?.(!0),process.stdin.resume(),process.stdin.on("data",E=>{let f=E.toString();if(f===""||f==="q"){c.stop(!0).then(()=>{Pe(),process.exit(0)});return}if(f==="m"){to(),v==="sockets"?K():(process.stdout.write("\x1B[s\x1B[H\x1B[2K"),_(j()),process.stdout.write("\x1B[u"));return}if((f==="s"||f==="\x1B[C")&&v!=="sockets"){eo();return}if((f==="l"||f==="\x1B[D")&&v!=="logs"){$();return}if(v==="sockets"){if(f==="\x1B[A")L=ge(L,-1),K();else if(f==="\x1B[B")L=ge(L,1),K();else if(f==="k"){let p=w[L];p?.alive&&(vt(p.roomId,p.actor),K())}else f==="r"&&(fe(),L=0,K());return}if(f==="!")O!==null?(clearTimeout(O),O=null,g()):(console.log("Simulating crash in 2.5s... (press ! again to crash now)"),O=setTimeout(()=>{O=null,g()},2500));else if(f==="c")ne.length=0,process.stdout.write("\x1B[2J\x1B[H"),_(j()),_(F()),_();else if(f==="v")l=!l,process.stdout.write("\x1B[s\x1B[H\x1B[2K"),_(j()),process.stdout.write("\x1B[2K"),_(F()),process.stdout.write("\x1B[u"),console.log(m(l?"Verbose mode on":"Verbose mode off"));else if(f==="p")if(h.length>0){let p=xt(h,y);At(p),console.log(m("Copied AI fix prompt to clipboard"))}else console.log(m("No setup issues detected"))})}}},on=Nr;export{on as default};
|
|
440
440
|
/*! Bundled license information:
|
|
441
441
|
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{i as r}from"./chunk-ZFPKG3IB.js";import{execFileSync as l,spawnSync as c}from"child_process";function a(){try{return l("bun",["--version"],{stdio:"ignore"}),!0}catch{return!1}}function d(){if(a()){let e=c("bun",process.argv.slice(1),{stdio:"inherit"});process.exit(e.status??1)}else console.error("The Liveblocks local dev server requires Bun."),console.error("See https://liveblocks.io/docs/get-started/dev-server for more information."),process.exit(1)}var s=process.argv.slice(2),o=s.findIndex(e=>!e.startsWith("-")),{options:t}=r(o>=0?s.slice(0,o):s,{help:{type:"boolean",short:"h",default:!1},version:{type:"boolean",default:!1}}),n=o>=0?s[o]:void 0,u=o>=0?s.slice(o+1):[];async function p(e){switch(e){case"dev":return typeof Bun>"u"&&d(),(await import("./dev-server-
|
|
2
|
+
import{i as r}from"./chunk-ZFPKG3IB.js";import{execFileSync as l,spawnSync as c}from"child_process";function a(){try{return l("bun",["--version"],{stdio:"ignore"}),!0}catch{return!1}}function d(){if(a()){let e=c("bun",process.argv.slice(1),{stdio:"inherit"});process.exit(e.status??1)}else console.error("The Liveblocks local dev server requires Bun."),console.error("See https://liveblocks.io/docs/get-started/dev-server for more information."),process.exit(1)}var s=process.argv.slice(2),o=s.findIndex(e=>!e.startsWith("-")),{options:t}=r(o>=0?s.slice(0,o):s,{help:{type:"boolean",short:"h",default:!1},version:{type:"boolean",default:!1}}),n=o>=0?s[o]:void 0,u=o>=0?s.slice(o+1):[];async function p(e){switch(e){case"dev":return typeof Bun>"u"&&d(),(await import("./dev-server-7C7774LJ.js")).default;case"upgrade":return(await import("./upgrade-QCUVOTDV.js")).default;default:return}}var m={dev:"Start the local Liveblocks dev server",upgrade:"Upgrade all Liveblocks packages"};function f(){console.log("liveblocks v1.6.1"),console.log(),console.log("Usage: liveblocks <command> [options]"),console.log(),console.log("Commands:");for(let[e,i]of Object.entries(m))console.log(` ${e.padEnd(12)} ${i}`);console.log(),console.log("Options:"),console.log(" --help, -h Show this help message"),console.log(" --version Show version number")}async function v(){t.version&&(console.log("1.6.1"),process.exit(0)),(t.help||!n)&&(f(),process.exit(n?0:1));let e=await p(n);e?await e.run(u):(console.error(`Unknown command: ${n}`),console.error('Run "liveblocks --help" for usage.'),process.exit(1))}v();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "liveblocks",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Liveblocks command line interface",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"decoders": "^2.9.0",
|
|
42
42
|
"js-base64": "^3.7.5",
|
|
43
43
|
"yjs": "^13.6.10",
|
|
44
|
-
"@liveblocks/
|
|
45
|
-
"@liveblocks/
|
|
44
|
+
"@liveblocks/query-parser": "^0.1.1",
|
|
45
|
+
"@liveblocks/server": "^1.6.1"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsup",
|