@swirls/cli 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bash-complete.js +40 -1
- package/dist/cli.js +40 -1
- package/package.json +1 -1
- package/dist/chunk-7KXMHQNZ.js +0 -1
- package/dist/chunk-KCGRSAKR.js +0 -1
- package/dist/chunk-N2UFNXNM.js +0 -1
- package/dist/chunk-OEQFVEK4.js +0 -1
- package/dist/chunk-RJOLKCKW.js +0 -1
- package/dist/chunk-VHACPEPJ.js +0 -1
- package/dist/chunk-Y7H7V3KU.js +0 -1
- package/dist/create-project-4SZY6HDF.js +0 -1
- package/dist/delete-SDEN2DHA.js +0 -1
- package/dist/download-IX63ZPH7.js +0 -1
- package/dist/generate-code-L5H45YK4.js +0 -1
- package/dist/implementation-EXDODHPG.js +0 -40
- package/dist/initialize-config-DKTZP3W4.js +0 -1
- package/dist/list-5ZNZIBFA.js +0 -1
- package/dist/open-project-544S7TXQ.js +0 -1
- package/dist/upload-NMJWKERQ.js +0 -1
- package/dist/url-DQSBHBMV.js +0 -1
package/dist/bash-complete.js
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
var Vt=Object.defineProperty;var f=(e,t)=>()=>(e&&(t=e(e=0)),t);var b=(e,t)=>{for(var r in t)Vt(e,r,{get:t[r],enumerable:!0})};import Ho from"path";import{fileURLToPath as Yo}from"url";var i=f(()=>{"use strict"});import Wt from"http";import{withResult as je}from"@byteslice/result";import*as F from"zod";function Qt(e){if(!e.url)throw new Error("No URL found in callback response.");let t=new URL(e.url,G);return F.parse(Gt,Object.fromEntries(t.searchParams.entries()))}function Fe(e){e.writeHead(400,{"Content-Type":"text/html"}),e.end(Zt)}function Xt(e){e.writeHead(200,{"Content-Type":"text/html"}),e.end(Kt)}function Le(e){return new Promise((t,r)=>{let o=Wt.createServer(async(a,s)=>{let c=await je(()=>Qt(a),n=>n);if(c.failure){Fe(s),r(c.failure);return}let d=await je(()=>e(c.data),n=>n);if(d.failure){Fe(s),r(d.failure);return}Xt(s),o.close(()=>{t()})});o.listen(ve)})}var ve,G,Gt,Kt,Zt,Ie=f(()=>{"use strict";i();ve=8765,G=`http://localhost:${ve}`,Gt=F.object({code:F.string(),state:F.string()}),Kt=`
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="UTF-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<title>Authentication Successful</title>
|
|
9
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
|
12
|
+
<div class="bg-white p-8 rounded-2xl shadow-lg text-center max-w-md">
|
|
13
|
+
<svg class="w-16 h-16 text-green-500 mx-auto" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
14
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
|
|
15
|
+
</svg>
|
|
16
|
+
<h1 class="text-2xl font-semibold mt-4">Authentication Successful</h1>
|
|
17
|
+
<p class="text-gray-600 mt-2">You can now return to your terminal and close this browser.</p>
|
|
18
|
+
</div>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
21
|
+
`,Zt=`
|
|
22
|
+
<!DOCTYPE html>
|
|
23
|
+
<html lang="en">
|
|
24
|
+
<head>
|
|
25
|
+
<meta charset="UTF-8">
|
|
26
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
27
|
+
<title>Authentication Failed</title>
|
|
28
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
29
|
+
</head>
|
|
30
|
+
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
|
31
|
+
<div class="bg-white p-8 rounded-2xl shadow-lg text-center max-w-md">
|
|
32
|
+
<svg class="w-16 h-16 text-red-500 mx-auto" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
33
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
34
|
+
</svg>
|
|
35
|
+
<h1 class="text-2xl font-semibold mt-4">Authentication Failed</h1>
|
|
36
|
+
<p class="text-gray-600 mt-2">Something bad happened while trying to authenticate you. Please try again.</p>
|
|
37
|
+
<p class="text-gray-600 mt-2">If the problem persists, <a href="mailto:help@byteslice.co" target="_blank" class="text-amber-500 hover:text-amber-600">please let us know</a>.</p>
|
|
38
|
+
</div>
|
|
39
|
+
</body>
|
|
40
|
+
</html>
|
|
41
|
+
`});import qt from"@clerk/clerk-js/headless/index.js";async function Te(e){let t=new er(e);return await t.load({standardBrowser:!1}),t}async function Re(e,t){let r=await e.client?.signIn.create({ticket:t,strategy:"ticket"});if(!r||!r.createdSessionId)throw new Error("Failed to sign in.");return{createdSessionId:r.createdSessionId}}var er,Ue=f(()=>{"use strict";i();er=qt.Clerk});async function K(e,t){await e.fsPromise.stat(t).then(()=>!0).catch(()=>!1)||await e.fsPromise.mkdir(t,{recursive:!0})}function U(e){if(!e.path)throw new Error("No `path` found in context.");if(!e.os)throw new Error("No `os` found in context.");let t=e.os.homedir();return e.path.join(t,".swirls")}var Z=f(()=>{"use strict";i()});import*as j from"zod";function Q(e){return`${U(e)}/credentials`}async function Ee(e){let t=Q(e);await e.fsPromise.stat(t).then(()=>!0).catch(()=>!1)&&await e.fsPromise.unlink(t)}async function O(e){let t=Q(e),r=await e.fsPromise.readFile(t,"utf8");return j.parse(tr,JSON.parse(r))}async function X(e,t,r,o){let a=Q(e);await K(e,U(e)),await e.fsPromise.writeFile(a,JSON.stringify({idToken:t,jwt:r,sessionId:o}))}var tr,q=f(()=>{"use strict";i();Z();tr=j.object({idToken:j.string(),jwt:j.string(),sessionId:j.string()})});import rr from"open";function De(e=32){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=new Uint8Array(e);crypto.getRandomValues(r);let o="";for(let a of r)o+=t[a%t.length];return o}function Ae(e){let t=new URLSearchParams({client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",scope:"openid profile email",state:e.state});rr(`${e.authorizeUri}?${t}`)}var $e=f(()=>{"use strict";i()});import*as v from"zod";var or,ir,N,ee=f(()=>{"use strict";i();or=v.object({API_URL:v.string(),OAUTH_AUTHORIZE_URL:v.string()}),ir={API_URL:"https://swirls.ai/api",OAUTH_AUTHORIZE_URL:"https://clerk.swirls.ai/oauth/authorize"},N=v.parse(or,ir)});import{withResult as ar}from"@byteslice/result";import{createORPCClient as sr,onError as nr}from"@orpc/client";import{RPCLink as cr}from"@orpc/client/fetch";async function u(e){let t=new cr({url:`${N.API_URL}/rpc`,headers:async()=>{let o=await ar(()=>O(e),c=>new Error("Failed to read credentials file",{cause:c.message}));if(o.failure)return{};let{idToken:a,jwt:s}=o.data;return{Authorization:`Bearer ${s||a}`}},interceptors:[nr(o=>{o instanceof Error&&o.name==="AbortError"||console.error(o)})]});return sr(t)}var P=f(()=>{"use strict";i();q();ee()});import{Box as lr,Text as ze}from"ink";import{jsx as _e,jsxs as mr}from"react/jsx-runtime";function p(e){return mr(lr,{flexDirection:"column",children:[_e(ze,{color:"red",children:e.message}),_e(ze,{children:"If this issue persists, send us an email at help@byteslice.co, and we can help you out."})]})}var y=f(()=>{"use strict";i()});import{Text as pr}from"ink";import{jsx as fr}from"react/jsx-runtime";function g(e){return fr(pr,{color:"green",children:e.message})}var k=f(()=>{"use strict";i()});import{Text as dr}from"ink";import{jsx as ur}from"react/jsx-runtime";function Be(e){return ur(dr,{color:"yellow",children:e.message})}var Oe=f(()=>{"use strict";i()});function gr(e){return`${U(e)}/project`}async function Ne(e){let t=gr(e);await e.fsPromise.stat(t).then(()=>!0).catch(()=>!1)&&await e.fsPromise.unlink(t)}var Me=f(()=>{"use strict";i();Z()});var te={};b(te,{login:()=>hr,logout:()=>xr});import{withResult as C}from"@byteslice/result";import{render as L}from"ink";import{jsx as I}from"react/jsx-runtime";async function wr(e,t,r){let o=await C(async()=>await(await u(e)).cli.exchangeToken({code:r.code}),h=>new Error("Failed to exchange callback code for token",{cause:h.message}));if(o.failure)throw o.failure;await X(e,o.data.idToken,"","");let a=await C(async()=>await(await u(e)).cli.createSignInTicket(),h=>new Error("Failed to exchange ID token code for a sign-in ticket",{cause:h.message}));if(a.failure)throw a.failure;let s=await Te(t.clerkPublishableKey),c=await C(()=>Re(s,a.data.token),h=>new Error("Failed to create a new sign-in for this device",{cause:h.message}));if(c.failure)throw c.failure;let d=await C(async()=>await(await u(e)).cli.createJwt({sessionId:c.data.createdSessionId}),h=>new Error("Failed to create a session JWT",{cause:h.message}));if(d.failure)throw d.failure;let n=await C(()=>X(e,o.data.idToken,d.data,c.data.createdSessionId),h=>new Error("Failed to save your credentials to disk",{cause:h.message}));if(n.failure)throw n.failure}async function hr(){let e=await u(this),t=De(),r=await C(()=>e.cli.getConfig(),a=>new Error("Failed to retrieve authentication configuration",{cause:a.message}));r.failure&&(L(I(p,{message:r.failure.message})),process.exit(1)),Ae({authorizeUri:N.OAUTH_AUTHORIZE_URL,clientId:r.data.clientId,redirectUri:G,state:t});let o=await C(()=>Le(async a=>{if(a.state!==t)throw new Error("Invalid state.");await wr(this,r.data,a)}),a=>a);o.failure&&(L(I(p,{message:o.failure.message})),process.exit(1)),L(I(g,{message:"Success! You are now logged in."}))}async function xr(){let e=await C(()=>O(this),s=>s);e.failure&&(L(I(p,{message:"There was an issue reading your credentials. You are probably already logged out."})),process.exit(1));let t=await u(this),r=await C(()=>t.cli.getConfig(),s=>new Error("Failed to retrieve authentication configuration",{cause:s.message}));r.failure&&(L(I(p,{message:r.failure.message})),process.exit(1)),(await C(async()=>t.cli.revokeSession({sessionId:e.data.sessionId}),s=>s)).failure&&L(I(Be,{message:"There was an issue revoking your session. You are probably already logged out. Purging credentials file..."}));let a=await C(async()=>{await Ee(this),await Ne(this)},s=>s);if(a.failure)throw a.failure;L(I(g,{message:"Success! You are now logged out."}))}var re=f(()=>{"use strict";i();Ie();Ue();q();$e();P();y();k();Oe();ee();Me()});import{Box as Pr,Text as Ye}from"ink";import kr from"ink-spinner";import{jsx as Ve,jsxs as We}from"react/jsx-runtime";function Ge(e){return We(Pr,{children:[Ve(Ye,{color:"cyan",children:Ve(kr,{type:"dots"})}),We(Ye,{children:[" ",e.message]})]})}var Ke=f(()=>{"use strict";i()});import{existsSync as Sr}from"fs";import{resolve as jr}from"path";import{configFileName as Ze,configSchema as Fr}from"@swirls/sdk/config";import{createJiti as vr}from"jiti";async function Qe(){let e=jr(process.cwd(),Ze);if(!Sr(e))throw new Error(`Config file not found in project root: ${Ze}`);let r=await vr(import.meta.url).import(e,{default:!0});return Fr.parse(r)}var Xe=f(()=>{"use strict";i()});async function qe(e,t){let r=await u(e),{results:o}=await r.forms.listForms({projectId:t});function a(c){return c.schema!=null}return o.filter(a).map(c=>({id:c.id,name:c.name,schema:c.schema}))}var et=f(()=>{"use strict";i();P()});import tt from"fs/promises";import Lr from"path";async function M(e,t){let r=Lr.dirname(e);await tt.mkdir(r,{recursive:!0}),await tt.writeFile(e,t,"utf-8")}var oe=f(()=>{"use strict";i()});var rt={};b(rt,{generateCode:()=>Tr});import ie from"process";import{withResult as ae}from"@byteslice/result";import{generateFormsCode as Ir}from"@swirls/sdk/form/generate";import{render as E}from"ink";import{jsx as D}from"react/jsx-runtime";async function Tr(){let e=await ae(()=>Qe(),s=>new Error("Failed to load configuration",{cause:s}));e.failure&&(E(D(p,{message:e.failure.message})),ie.exit(1));let{projectId:t,genPath:r}=e.data;E(D(Ge,{message:"Generating form code..."}));let o=await ae(async()=>{let s=['// This file was generated by "@swirls/cli dev generate"',"// Do not edit this file manually",""],c=await qe(this,t);return Ir(c,s)},s=>new Error(`Failed to generate form code: ${s.message}`,{cause:s}));o.failure&&(E(D(p,{message:o.failure.message})),ie.exit(1));let a=await ae(()=>M(r,o.data),s=>new Error("Failed to write code file",{cause:s}));a.failure&&(E(D(p,{message:a.failure.message})),ie.exit(1)),E(D(g,{message:`Success! Generated code at ${r}`}))}var ot=f(()=>{"use strict";i();y();Ke();k();Xe();et();oe()});import{Box as it,render as Rr,Text as at}from"ink";import Ur from"ink-text-input";import{useState as st}from"react";import{z as Er}from"zod";import{jsx as H,jsxs as nt}from"react/jsx-runtime";function Dr(e){let[t,r]=st(""),[o,a]=st(null);return nt(it,{flexDirection:"column",children:[nt(it,{children:[H(at,{children:"Enter project ID (UUID): "}),H(Ur,{value:t,onChange:d=>{a(null),r(d)},onSubmit:d=>{if(a(null),d.trim()===""){setImmediate(()=>e.onInput());return}let n=Er.uuid().safeParse(d);if(!n.success){a("Invalid UUID. Please try again."),r("");return}setImmediate(()=>e.onInput(n.data))}})]}),o&&H(at,{color:"red",children:o})]})}async function ct(){return new Promise(e=>{let t=Rr(H(Dr,{onInput:r=>{t.unmount(),e(r)}}))})}var lt=f(()=>{"use strict";i()});var mt={};b(mt,{initializeConfig:()=>Or});import{existsSync as Ar}from"fs";import{resolve as $r}from"path";import se from"process";import{withResult as zr}from"@byteslice/result";import{configFileName as _r,generateConfig as Br}from"@swirls/sdk/config";import{render as ne}from"ink";import{jsx as ce}from"react/jsx-runtime";async function Or(){let e=$r(se.cwd(),_r);Ar(e)&&(ne(ce(p,{message:`Configuration already exists at ${e}.`})),se.exit(1));let t=await ct(),r=await zr(async()=>{let o=Br(t);await M(e,o)},o=>new Error("Failed to create configuration",{cause:o}));r.failure&&(ne(ce(p,{message:r.failure.message})),se.exit(1)),ne(ce(g,{message:`Success! Created configuration at ${e}`}))}var pt=f(()=>{"use strict";i();y();k();lt();oe()});import{render as Jr}from"ink";import Yr from"open";import{jsx as Wr}from"react/jsx-runtime";async function J(e){let t=`${Vr}/${e.id}`;await Yr(t),Jr(Wr(g,{message:`Opened project "${e.name}" in browser.`}))}var Vr,le=f(()=>{"use strict";i();k();Vr="https://swirls.ai/projects"});import{Box as me,render as Gr,Text as Kr}from"ink";import Zr from"ink-text-input";import{useState as Qr}from"react";import{jsx as fe,jsxs as pe}from"react/jsx-runtime";function Xr(e){let[t,r]=Qr(""),o=a=>{let s=a.trim().toLowerCase(),c=s===""||s==="y"||s==="yes";setImmediate(()=>e.onAnswer(c))};return fe(me,{flexDirection:"column",children:pe(me,{children:[pe(Kr,{children:[e.message," "]}),fe(Zr,{value:t,onChange:r,onSubmit:o})]})})}async function ut(e){let{above:t}=e??{};return new Promise(r=>{let o=Gr(pe(me,{flexDirection:"column",children:[t,fe(Xr,{message:"Open project in browser? (Y/n)",onAnswer:a=>{o.unmount(),r(a)}})]}))})}var gt=f(()=>{"use strict";i()});var ht={};b(ht,{createProject:()=>to});import{withResult as qr}from"@byteslice/result";import{render as eo}from"ink";import{jsx as wt}from"react/jsx-runtime";async function to(e,t){let r=await u(this),o=await qr(()=>r.projects.createProject({name:t}),s=>new Error(`Failed to create project: ${s.message}`,{cause:s}));o.failure&&(eo(wt(p,{message:o.failure.message})),process.exit(1)),await ut({above:wt(g,{message:`Success! Created "${t}" project: ${o.data.id}`})})&&await J(o.data)}var xt=f(()=>{"use strict";i();P();y();k();le();gt()});var bt={};b(bt,{openProject:()=>oo});import{withResult as ro}from"@byteslice/result";import{render as yt}from"ink";import{jsx as Ct}from"react/jsx-runtime";async function oo(e,t){let r=await u(this),o=await ro(()=>r.projects.getProject({projectId:t}),a=>new Error(`Failed to get project: ${a.message}`,{cause:a}));o.failure&&(yt(Ct(p,{message:o.failure.message})),process.exit(1)),o.data||(yt(Ct(p,{message:"Project not found."})),process.exit(1)),await J(o.data)}var Pt=f(()=>{"use strict";i();P();y();le()});import{Box as T,Text as Y}from"ink";import{Fragment as no}from"react";import{Fragment as po,jsx as x,jsxs as ue}from"react/jsx-runtime";function co(e){return typeof e=="boolean"?e?ue(po,{children:[x(Y,{color:"green",children:"\u2714"})," yes"]}):"no":String(e)}function lo(e,t){return t.map(r=>{let o=r.key in e?co(e[r.key]):null;return{column:r,value:o}})}function mo(e,t,r=1){return t.map(o=>{let a=String(o).length,s=e.map(d=>o in d&&(typeof d[o]=="string"||typeof d[o]=="number")?String(d[o]).length:0),c=Math.max(...s,a)+r*2;return{name:String(o),key:o,width:c}})}function de(e){return x(Y,{children:Array(e.width).fill("\u2500").join("")})}function jt(e){let t=mo(e.data,e.keys),r=t.reduce((o,a)=>o+a.width,0);return ue(T,{flexDirection:"column",width:r,children:[x(de,{width:r}),x(T,{flexDirection:"row",children:t.map(o=>x(T,{width:o.width,children:x(Y,{bold:!0,color:"blue",children:o.name})},o.name))}),x(de,{width:r}),x(T,{flexDirection:"column",children:e.data.map((o,a)=>{let s=lo(o,t);return ue(no,{children:[x(T,{flexDirection:"row",children:s.map(c=>x(T,{width:c.column.width,children:x(Y,{children:c.value})},c.column.name))}),x(de,{width:r})]},`row-${a}`)})})]})}var Ft=f(()=>{"use strict";i()});import{existsSync as fo}from"fs";import{resolve as uo}from"path";import{configFileName as vt,configSchema as go}from"@swirls/sdk/config";import{createJiti as wo}from"jiti";async function S(e){if(e)return e;let t=uo(process.cwd(),vt);if(!fo(t))throw new Error(`No project specified and no ${vt} found. Use --project flag or run from a project directory.`);let o=await wo(import.meta.url).import(t,{default:!0});return go.parse(o).projectId}var R=f(()=>{"use strict";i()});var It={};b(It,{list:()=>ho});import{withResult as Lt}from"@byteslice/result";import{render as ge}from"ink";import{jsx as we}from"react/jsx-runtime";async function ho(e,t){let r=await Lt(()=>S(e.project),n=>new Error(n.message));r.failure&&(ge(we(p,{message:r.failure.message})),process.exit(1));let o=await u(this),a=await Lt(()=>o.buckets.listFiles({projectId:r.data,path:t}),n=>new Error(`Failed to list files: ${n.message}`,{cause:n}));a.failure&&(ge(we(p,{message:a.failure.message})),process.exit(1));let{files:s,folders:c}=a.data;if(c.length===0&&s.length===0){console.log("No files or folders found.");return}let d=[...c.map(n=>({type:"folder",name:n.name,size:"-"})),...s.map(n=>({type:"file",name:n.name,size:n.size?xo(n.size):"-"}))];ge(we(jt,{keys:["type","name","size"],data:d}))}function xo(e){if(e===0)return"0 B";let t=1024,r=["B","KB","MB","GB","TB"],o=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**o).toFixed(2))} ${r[o]}`}var Tt=f(()=>{"use strict";i();P();y();Ft();R()});var Rt={};b(Rt,{upload:()=>bo});import{readFile as yo}from"fs/promises";import{basename as Co}from"path";import{withResult as V}from"@byteslice/result";import{render as A}from"ink";import{jsx as $}from"react/jsx-runtime";async function bo(e,t,r){let o=await V(()=>S(e.project),w=>new Error(w.message));o.failure&&(A($(p,{message:o.failure.message})),process.exit(1));let a=await V(()=>yo(t),w=>new Error(`Failed to read file: ${w.message}`,{cause:w}));a.failure&&(A($(p,{message:a.failure.message})),process.exit(1));let s=Co(t),c=r?`${r}/${s}`:s,d=await u(this),n=await V(()=>d.buckets.createSignedUploadUrl({projectId:o.data,path:c}),w=>new Error(`Failed to get upload URL: ${w.message}`,{cause:w}));n.failure&&(A($(p,{message:n.failure.message})),process.exit(1));let h=await V(async()=>{let w=await fetch(n.data.signedUrl,{method:"PUT",headers:{"Content-Type":"application/octet-stream","x-upsert":"true"},body:a.data});if(!w.ok)throw new Error(`Upload failed: ${w.statusText}`);return w},w=>new Error(`Failed to upload file: ${w.message}`,{cause:w}));h.failure&&(A($(p,{message:h.failure.message})),process.exit(1)),A($(g,{message:`Uploaded ${s} to ${c}`}))}var Ut=f(()=>{"use strict";i();P();y();k();R()});var Et={};b(Et,{download:()=>ko});import{writeFile as Po}from"fs/promises";import{withResult as W}from"@byteslice/result";import{render as z}from"ink";import{jsx as _}from"react/jsx-runtime";async function ko(e,t,r){let o=await W(()=>S(e.project),n=>new Error(n.message));o.failure&&(z(_(p,{message:o.failure.message})),process.exit(1));let a=await u(this),s=await W(()=>a.buckets.createSignedUrl({projectId:o.data,path:t}),n=>new Error(`Failed to get download URL: ${n.message}`,{cause:n}));s.failure&&(z(_(p,{message:s.failure.message})),process.exit(1));let c=await W(async()=>{let n=await fetch(s.data.signedUrl);if(!n.ok)throw new Error(`Download failed: ${n.statusText}`);return n.arrayBuffer()},n=>new Error(`Failed to download file: ${n.message}`,{cause:n}));c.failure&&(z(_(p,{message:c.failure.message})),process.exit(1));let d=await W(()=>Po(r,Buffer.from(c.data)),n=>new Error(`Failed to write file: ${n.message}`,{cause:n}));d.failure&&(z(_(p,{message:d.failure.message})),process.exit(1)),z(_(g,{message:`Downloaded ${t} to ${r}`}))}var Dt=f(()=>{"use strict";i();P();y();k();R()});var $t={};b($t,{deleteFile:()=>So});import{withResult as At}from"@byteslice/result";import{render as he}from"ink";import{jsx as xe}from"react/jsx-runtime";async function So(e,t){let r=await At(()=>S(e.project),s=>new Error(s.message));r.failure&&(he(xe(p,{message:r.failure.message})),process.exit(1));let o=await u(this),a=await At(()=>o.buckets.deleteFile({projectId:r.data,path:t}),s=>new Error(`Failed to delete file: ${s.message}`,{cause:s}));a.failure&&(he(xe(p,{message:a.failure.message})),process.exit(1)),he(xe(g,{message:`Deleted ${t}`}))}var zt=f(()=>{"use strict";i();P();y();k();R()});var Bt={};b(Bt,{url:()=>jo});import{withResult as _t}from"@byteslice/result";import{render as ye}from"ink";import{jsx as Ce}from"react/jsx-runtime";async function jo(e,t){let r=await _t(()=>S(e.project),s=>new Error(s.message));r.failure&&(ye(Ce(p,{message:r.failure.message})),process.exit(1));let o=await u(this),a=await _t(()=>o.buckets.createSignedUrl({projectId:r.data,path:t,expiresIn:e.expires}),s=>new Error(`Failed to create signed URL: ${s.message}`,{cause:s}));a.failure&&(ye(Ce(p,{message:a.failure.message})),process.exit(1)),console.log(a.data.signedUrl),ye(Ce(g,{message:`URL expires at ${a.data.expiresAt}`}))}var Ot=f(()=>{"use strict";i();P();y();k();R()});i();import{proposeCompletions as Yt}from"@stricli/core";i();import{buildInstallCommand as Uo,buildUninstallCommand as Eo}from"@stricli/auto-complete";import{buildApplication as Do,buildRouteMap as Ao}from"@stricli/core";i();import{buildCommand as He,buildRouteMap as yr}from"@stricli/core";var Cr=He({loader:async()=>{let{login:e}=await Promise.resolve().then(()=>(re(),te));return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log in with an existing account"}}),br=He({loader:async()=>{let{logout:e}=await Promise.resolve().then(()=>(re(),te));return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log out of an existing account"}}),Je=yr({routes:{login:Cr,logout:br},docs:{brief:"Auth commands"}});i();import{buildCommand as ft,buildRouteMap as Nr}from"@stricli/core";var Mr=ft({loader:async()=>{let{generateCode:e}=await Promise.resolve().then(()=>(ot(),rt));return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Generate application code and types"}}),Hr=ft({loader:async()=>{let{initializeConfig:e}=await Promise.resolve().then(()=>(pt(),mt));return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Initialize Swirls configuration file"}}),dt=Nr({routes:{gen:Mr,init:Hr},docs:{brief:"Developer commands"}});i();import{buildCommand as kt,buildRouteMap as io}from"@stricli/core";var ao=kt({loader:async()=>{let{createProject:e}=await Promise.resolve().then(()=>(xt(),ht));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Project name",parse:String,placeholder:"name"}]}},docs:{brief:"Create a new project"}}),so=kt({loader:async()=>{let{openProject:e}=await Promise.resolve().then(()=>(Pt(),bt));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Project ID",parse:String,placeholder:"project-id"}]}},docs:{brief:"Open project in browser"}}),St=io({routes:{create:ao,open:so},docs:{brief:"Project commands"}});i();import{buildCommand as B,buildRouteMap as Fo}from"@stricli/core";var vo=B({loader:async()=>{let{list:e}=await Promise.resolve().then(()=>(Tt(),It));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to list (optional)",parse:String,placeholder:"path",optional:!0}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"List files in storage"}}),Lo=B({loader:async()=>{let{upload:e}=await Promise.resolve().then(()=>(Ut(),Rt));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Local file path to upload",parse:String,placeholder:"file"},{brief:"Destination path in storage (optional)",parse:String,placeholder:"dest",optional:!0}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Upload a file to storage"}}),Io=B({loader:async()=>{let{download:e}=await Promise.resolve().then(()=>(Dt(),Et));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"},{brief:"Local destination path",parse:String,placeholder:"dest"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Download a file from storage"}}),To=B({loader:async()=>{let{deleteFile:e}=await Promise.resolve().then(()=>(zt(),$t));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Delete a file from storage"}}),Ro=B({loader:async()=>{let{url:e}=await Promise.resolve().then(()=>(Ot(),Bt));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0},expires:{kind:"parsed",brief:"Expiration time in seconds (default: 86400 = 24 hours)",parse:Number,optional:!0}}},docs:{brief:"Get a signed URL for a file"}}),Nt=Fo({routes:{list:vo,upload:Lo,download:Io,delete:To,url:Ro},docs:{brief:"Storage commands"}});var Mt="@swirls/cli",Ht="0.0.19",Jt="Swirls command line application";var $o=Ao({routes:{auth:Je,dev:dt,project:St,storage:Nt,install:Uo("cli",{bash:"__cli_bash_complete"}),uninstall:Eo("cli",{bash:!0})},docs:{brief:Jt,hideRoute:{install:!0,uninstall:!0}}}),Pe=Do($o,{name:Mt,versionInfo:{currentVersion:Ht}});i();import zo from"fs";import _o from"fs/promises";import Bo from"os";import Oo from"path";function ke(e){return{fs:zo,fsPromise:_o,os:Bo,path:Oo,process:e}}var Se=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&Se.push("");await Yt(Pe,Se,ke(process));try{for(let{completion:e}of await Yt(Pe,Se,ke(process)))process.stdout.write(`${e}
|
|
3
42
|
`)}catch{}
|
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,41 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
var Jt=Object.defineProperty;var f=(e,t)=>()=>(e&&(t=e(e=0)),t);var b=(e,t)=>{for(var r in t)Jt(e,r,{get:t[r],enumerable:!0})};import Mo from"path";import{fileURLToPath as Jo}from"url";var i=f(()=>{"use strict"});import Yt from"http";import{withResult as Pe}from"@byteslice/result";import*as F from"zod";function Kt(e){if(!e.url)throw new Error("No URL found in callback response.");let t=new URL(e.url,G);return F.parse(Vt,Object.fromEntries(t.searchParams.entries()))}function ke(e){e.writeHead(400,{"Content-Type":"text/html"}),e.end(Gt)}function Zt(e){e.writeHead(200,{"Content-Type":"text/html"}),e.end(Wt)}function je(e){return new Promise((t,r)=>{let o=Yt.createServer(async(a,s)=>{let c=await Pe(()=>Kt(a),n=>n);if(c.failure){ke(s),r(c.failure);return}let d=await Pe(()=>e(c.data),n=>n);if(d.failure){ke(s),r(d.failure);return}Zt(s),o.close(()=>{t()})});o.listen(Se)})}var Se,G,Vt,Wt,Gt,Fe=f(()=>{"use strict";i();Se=8765,G=`http://localhost:${Se}`,Vt=F.object({code:F.string(),state:F.string()}),Wt=`
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="UTF-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<title>Authentication Successful</title>
|
|
9
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
|
12
|
+
<div class="bg-white p-8 rounded-2xl shadow-lg text-center max-w-md">
|
|
13
|
+
<svg class="w-16 h-16 text-green-500 mx-auto" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
14
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
|
|
15
|
+
</svg>
|
|
16
|
+
<h1 class="text-2xl font-semibold mt-4">Authentication Successful</h1>
|
|
17
|
+
<p class="text-gray-600 mt-2">You can now return to your terminal and close this browser.</p>
|
|
18
|
+
</div>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
21
|
+
`,Gt=`
|
|
22
|
+
<!DOCTYPE html>
|
|
23
|
+
<html lang="en">
|
|
24
|
+
<head>
|
|
25
|
+
<meta charset="UTF-8">
|
|
26
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
27
|
+
<title>Authentication Failed</title>
|
|
28
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
29
|
+
</head>
|
|
30
|
+
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
|
31
|
+
<div class="bg-white p-8 rounded-2xl shadow-lg text-center max-w-md">
|
|
32
|
+
<svg class="w-16 h-16 text-red-500 mx-auto" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
33
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
34
|
+
</svg>
|
|
35
|
+
<h1 class="text-2xl font-semibold mt-4">Authentication Failed</h1>
|
|
36
|
+
<p class="text-gray-600 mt-2">Something bad happened while trying to authenticate you. Please try again.</p>
|
|
37
|
+
<p class="text-gray-600 mt-2">If the problem persists, <a href="mailto:help@byteslice.co" target="_blank" class="text-amber-500 hover:text-amber-600">please let us know</a>.</p>
|
|
38
|
+
</div>
|
|
39
|
+
</body>
|
|
40
|
+
</html>
|
|
41
|
+
`});import Qt from"@clerk/clerk-js/headless/index.js";async function ve(e){let t=new Xt(e);return await t.load({standardBrowser:!1}),t}async function Le(e,t){let r=await e.client?.signIn.create({ticket:t,strategy:"ticket"});if(!r||!r.createdSessionId)throw new Error("Failed to sign in.");return{createdSessionId:r.createdSessionId}}var Xt,Ie=f(()=>{"use strict";i();Xt=Qt.Clerk});async function K(e,t){await e.fsPromise.stat(t).then(()=>!0).catch(()=>!1)||await e.fsPromise.mkdir(t,{recursive:!0})}function U(e){if(!e.path)throw new Error("No `path` found in context.");if(!e.os)throw new Error("No `os` found in context.");let t=e.os.homedir();return e.path.join(t,".swirls")}var Z=f(()=>{"use strict";i()});import*as j from"zod";function Q(e){return`${U(e)}/credentials`}async function Te(e){let t=Q(e);await e.fsPromise.stat(t).then(()=>!0).catch(()=>!1)&&await e.fsPromise.unlink(t)}async function O(e){let t=Q(e),r=await e.fsPromise.readFile(t,"utf8");return j.parse(qt,JSON.parse(r))}async function X(e,t,r,o){let a=Q(e);await K(e,U(e)),await e.fsPromise.writeFile(a,JSON.stringify({idToken:t,jwt:r,sessionId:o}))}var qt,q=f(()=>{"use strict";i();Z();qt=j.object({idToken:j.string(),jwt:j.string(),sessionId:j.string()})});import er from"open";function Re(e=32){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=new Uint8Array(e);crypto.getRandomValues(r);let o="";for(let a of r)o+=t[a%t.length];return o}function Ue(e){let t=new URLSearchParams({client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",scope:"openid profile email",state:e.state});er(`${e.authorizeUri}?${t}`)}var Ee=f(()=>{"use strict";i()});import*as v from"zod";var tr,rr,N,ee=f(()=>{"use strict";i();tr=v.object({API_URL:v.string(),OAUTH_AUTHORIZE_URL:v.string()}),rr={API_URL:"https://swirls.ai/api",OAUTH_AUTHORIZE_URL:"https://clerk.swirls.ai/oauth/authorize"},N=v.parse(tr,rr)});import{withResult as or}from"@byteslice/result";import{createORPCClient as ir,onError as ar}from"@orpc/client";import{RPCLink as sr}from"@orpc/client/fetch";async function u(e){let t=new sr({url:`${N.API_URL}/rpc`,headers:async()=>{let o=await or(()=>O(e),c=>new Error("Failed to read credentials file",{cause:c.message}));if(o.failure)return{};let{idToken:a,jwt:s}=o.data;return{Authorization:`Bearer ${s||a}`}},interceptors:[ar(o=>{o instanceof Error&&o.name==="AbortError"||console.error(o)})]});return ir(t)}var P=f(()=>{"use strict";i();q();ee()});import{Box as nr,Text as De}from"ink";import{jsx as Ae,jsxs as cr}from"react/jsx-runtime";function p(e){return cr(nr,{flexDirection:"column",children:[Ae(De,{color:"red",children:e.message}),Ae(De,{children:"If this issue persists, send us an email at help@byteslice.co, and we can help you out."})]})}var y=f(()=>{"use strict";i()});import{Text as lr}from"ink";import{jsx as mr}from"react/jsx-runtime";function g(e){return mr(lr,{color:"green",children:e.message})}var k=f(()=>{"use strict";i()});import{Text as pr}from"ink";import{jsx as fr}from"react/jsx-runtime";function $e(e){return fr(pr,{color:"yellow",children:e.message})}var ze=f(()=>{"use strict";i()});function dr(e){return`${U(e)}/project`}async function _e(e){let t=dr(e);await e.fsPromise.stat(t).then(()=>!0).catch(()=>!1)&&await e.fsPromise.unlink(t)}var Be=f(()=>{"use strict";i();Z()});var te={};b(te,{login:()=>gr,logout:()=>wr});import{withResult as C}from"@byteslice/result";import{render as L}from"ink";import{jsx as I}from"react/jsx-runtime";async function ur(e,t,r){let o=await C(async()=>await(await u(e)).cli.exchangeToken({code:r.code}),h=>new Error("Failed to exchange callback code for token",{cause:h.message}));if(o.failure)throw o.failure;await X(e,o.data.idToken,"","");let a=await C(async()=>await(await u(e)).cli.createSignInTicket(),h=>new Error("Failed to exchange ID token code for a sign-in ticket",{cause:h.message}));if(a.failure)throw a.failure;let s=await ve(t.clerkPublishableKey),c=await C(()=>Le(s,a.data.token),h=>new Error("Failed to create a new sign-in for this device",{cause:h.message}));if(c.failure)throw c.failure;let d=await C(async()=>await(await u(e)).cli.createJwt({sessionId:c.data.createdSessionId}),h=>new Error("Failed to create a session JWT",{cause:h.message}));if(d.failure)throw d.failure;let n=await C(()=>X(e,o.data.idToken,d.data,c.data.createdSessionId),h=>new Error("Failed to save your credentials to disk",{cause:h.message}));if(n.failure)throw n.failure}async function gr(){let e=await u(this),t=Re(),r=await C(()=>e.cli.getConfig(),a=>new Error("Failed to retrieve authentication configuration",{cause:a.message}));r.failure&&(L(I(p,{message:r.failure.message})),process.exit(1)),Ue({authorizeUri:N.OAUTH_AUTHORIZE_URL,clientId:r.data.clientId,redirectUri:G,state:t});let o=await C(()=>je(async a=>{if(a.state!==t)throw new Error("Invalid state.");await ur(this,r.data,a)}),a=>a);o.failure&&(L(I(p,{message:o.failure.message})),process.exit(1)),L(I(g,{message:"Success! You are now logged in."}))}async function wr(){let e=await C(()=>O(this),s=>s);e.failure&&(L(I(p,{message:"There was an issue reading your credentials. You are probably already logged out."})),process.exit(1));let t=await u(this),r=await C(()=>t.cli.getConfig(),s=>new Error("Failed to retrieve authentication configuration",{cause:s.message}));r.failure&&(L(I(p,{message:r.failure.message})),process.exit(1)),(await C(async()=>t.cli.revokeSession({sessionId:e.data.sessionId}),s=>s)).failure&&L(I($e,{message:"There was an issue revoking your session. You are probably already logged out. Purging credentials file..."}));let a=await C(async()=>{await Te(this),await _e(this)},s=>s);if(a.failure)throw a.failure;L(I(g,{message:"Success! You are now logged out."}))}var re=f(()=>{"use strict";i();Fe();Ie();q();Ee();P();y();k();ze();ee();Be()});import{Box as Cr,Text as Me}from"ink";import br from"ink-spinner";import{jsx as He,jsxs as Je}from"react/jsx-runtime";function Ye(e){return Je(Cr,{children:[He(Me,{color:"cyan",children:He(br,{type:"dots"})}),Je(Me,{children:[" ",e.message]})]})}var Ve=f(()=>{"use strict";i()});import{existsSync as Pr}from"fs";import{resolve as kr}from"path";import{configFileName as We,configSchema as Sr}from"@swirls/sdk/config";import{createJiti as jr}from"jiti";async function Ge(){let e=kr(process.cwd(),We);if(!Pr(e))throw new Error(`Config file not found in project root: ${We}`);let r=await jr(import.meta.url).import(e,{default:!0});return Sr.parse(r)}var Ke=f(()=>{"use strict";i()});async function Ze(e,t){let r=await u(e),{results:o}=await r.forms.listForms({projectId:t});function a(c){return c.schema!=null}return o.filter(a).map(c=>({id:c.id,name:c.name,schema:c.schema}))}var Qe=f(()=>{"use strict";i();P()});import Xe from"fs/promises";import Fr from"path";async function M(e,t){let r=Fr.dirname(e);await Xe.mkdir(r,{recursive:!0}),await Xe.writeFile(e,t,"utf-8")}var oe=f(()=>{"use strict";i()});var qe={};b(qe,{generateCode:()=>Lr});import ie from"process";import{withResult as ae}from"@byteslice/result";import{generateFormsCode as vr}from"@swirls/sdk/form/generate";import{render as E}from"ink";import{jsx as D}from"react/jsx-runtime";async function Lr(){let e=await ae(()=>Ge(),s=>new Error("Failed to load configuration",{cause:s}));e.failure&&(E(D(p,{message:e.failure.message})),ie.exit(1));let{projectId:t,genPath:r}=e.data;E(D(Ye,{message:"Generating form code..."}));let o=await ae(async()=>{let s=['// This file was generated by "@swirls/cli dev generate"',"// Do not edit this file manually",""],c=await Ze(this,t);return vr(c,s)},s=>new Error(`Failed to generate form code: ${s.message}`,{cause:s}));o.failure&&(E(D(p,{message:o.failure.message})),ie.exit(1));let a=await ae(()=>M(r,o.data),s=>new Error("Failed to write code file",{cause:s}));a.failure&&(E(D(p,{message:a.failure.message})),ie.exit(1)),E(D(g,{message:`Success! Generated code at ${r}`}))}var et=f(()=>{"use strict";i();y();Ve();k();Ke();Qe();oe()});import{Box as tt,render as Ir,Text as rt}from"ink";import Tr from"ink-text-input";import{useState as ot}from"react";import{z as Rr}from"zod";import{jsx as H,jsxs as it}from"react/jsx-runtime";function Ur(e){let[t,r]=ot(""),[o,a]=ot(null);return it(tt,{flexDirection:"column",children:[it(tt,{children:[H(rt,{children:"Enter project ID (UUID): "}),H(Tr,{value:t,onChange:d=>{a(null),r(d)},onSubmit:d=>{if(a(null),d.trim()===""){setImmediate(()=>e.onInput());return}let n=Rr.uuid().safeParse(d);if(!n.success){a("Invalid UUID. Please try again."),r("");return}setImmediate(()=>e.onInput(n.data))}})]}),o&&H(rt,{color:"red",children:o})]})}async function at(){return new Promise(e=>{let t=Ir(H(Ur,{onInput:r=>{t.unmount(),e(r)}}))})}var st=f(()=>{"use strict";i()});var nt={};b(nt,{initializeConfig:()=>_r});import{existsSync as Er}from"fs";import{resolve as Dr}from"path";import se from"process";import{withResult as Ar}from"@byteslice/result";import{configFileName as $r,generateConfig as zr}from"@swirls/sdk/config";import{render as ne}from"ink";import{jsx as ce}from"react/jsx-runtime";async function _r(){let e=Dr(se.cwd(),$r);Er(e)&&(ne(ce(p,{message:`Configuration already exists at ${e}.`})),se.exit(1));let t=await at(),r=await Ar(async()=>{let o=zr(t);await M(e,o)},o=>new Error("Failed to create configuration",{cause:o}));r.failure&&(ne(ce(p,{message:r.failure.message})),se.exit(1)),ne(ce(g,{message:`Success! Created configuration at ${e}`}))}var ct=f(()=>{"use strict";i();y();k();st();oe()});import{render as Mr}from"ink";import Hr from"open";import{jsx as Yr}from"react/jsx-runtime";async function J(e){let t=`${Jr}/${e.id}`;await Hr(t),Mr(Yr(g,{message:`Opened project "${e.name}" in browser.`}))}var Jr,le=f(()=>{"use strict";i();k();Jr="https://swirls.ai/projects"});import{Box as me,render as Vr,Text as Wr}from"ink";import Gr from"ink-text-input";import{useState as Kr}from"react";import{jsx as fe,jsxs as pe}from"react/jsx-runtime";function Zr(e){let[t,r]=Kr(""),o=a=>{let s=a.trim().toLowerCase(),c=s===""||s==="y"||s==="yes";setImmediate(()=>e.onAnswer(c))};return fe(me,{flexDirection:"column",children:pe(me,{children:[pe(Wr,{children:[e.message," "]}),fe(Gr,{value:t,onChange:r,onSubmit:o})]})})}async function pt(e){let{above:t}=e??{};return new Promise(r=>{let o=Vr(pe(me,{flexDirection:"column",children:[t,fe(Zr,{message:"Open project in browser? (Y/n)",onAnswer:a=>{o.unmount(),r(a)}})]}))})}var ft=f(()=>{"use strict";i()});var ut={};b(ut,{createProject:()=>qr});import{withResult as Qr}from"@byteslice/result";import{render as Xr}from"ink";import{jsx as dt}from"react/jsx-runtime";async function qr(e,t){let r=await u(this),o=await Qr(()=>r.projects.createProject({name:t}),s=>new Error(`Failed to create project: ${s.message}`,{cause:s}));o.failure&&(Xr(dt(p,{message:o.failure.message})),process.exit(1)),await pt({above:dt(g,{message:`Success! Created "${t}" project: ${o.data.id}`})})&&await J(o.data)}var gt=f(()=>{"use strict";i();P();y();k();le();ft()});var xt={};b(xt,{openProject:()=>to});import{withResult as eo}from"@byteslice/result";import{render as wt}from"ink";import{jsx as ht}from"react/jsx-runtime";async function to(e,t){let r=await u(this),o=await eo(()=>r.projects.getProject({projectId:t}),a=>new Error(`Failed to get project: ${a.message}`,{cause:a}));o.failure&&(wt(ht(p,{message:o.failure.message})),process.exit(1)),o.data||(wt(ht(p,{message:"Project not found."})),process.exit(1)),await J(o.data)}var yt=f(()=>{"use strict";i();P();y();le()});import{Box as T,Text as Y}from"ink";import{Fragment as ao}from"react";import{Fragment as lo,jsx as x,jsxs as ue}from"react/jsx-runtime";function so(e){return typeof e=="boolean"?e?ue(lo,{children:[x(Y,{color:"green",children:"\u2714"})," yes"]}):"no":String(e)}function no(e,t){return t.map(r=>{let o=r.key in e?so(e[r.key]):null;return{column:r,value:o}})}function co(e,t,r=1){return t.map(o=>{let a=String(o).length,s=e.map(d=>o in d&&(typeof d[o]=="string"||typeof d[o]=="number")?String(d[o]).length:0),c=Math.max(...s,a)+r*2;return{name:String(o),key:o,width:c}})}function de(e){return x(Y,{children:Array(e.width).fill("\u2500").join("")})}function Pt(e){let t=co(e.data,e.keys),r=t.reduce((o,a)=>o+a.width,0);return ue(T,{flexDirection:"column",width:r,children:[x(de,{width:r}),x(T,{flexDirection:"row",children:t.map(o=>x(T,{width:o.width,children:x(Y,{bold:!0,color:"blue",children:o.name})},o.name))}),x(de,{width:r}),x(T,{flexDirection:"column",children:e.data.map((o,a)=>{let s=no(o,t);return ue(ao,{children:[x(T,{flexDirection:"row",children:s.map(c=>x(T,{width:c.column.width,children:x(Y,{children:c.value})},c.column.name))}),x(de,{width:r})]},`row-${a}`)})})]})}var kt=f(()=>{"use strict";i()});import{existsSync as mo}from"fs";import{resolve as po}from"path";import{configFileName as St,configSchema as fo}from"@swirls/sdk/config";import{createJiti as uo}from"jiti";async function S(e){if(e)return e;let t=po(process.cwd(),St);if(!mo(t))throw new Error(`No project specified and no ${St} found. Use --project flag or run from a project directory.`);let o=await uo(import.meta.url).import(t,{default:!0});return fo.parse(o).projectId}var R=f(()=>{"use strict";i()});var Ft={};b(Ft,{list:()=>go});import{withResult as jt}from"@byteslice/result";import{render as ge}from"ink";import{jsx as we}from"react/jsx-runtime";async function go(e,t){let r=await jt(()=>S(e.project),n=>new Error(n.message));r.failure&&(ge(we(p,{message:r.failure.message})),process.exit(1));let o=await u(this),a=await jt(()=>o.buckets.listFiles({projectId:r.data,path:t}),n=>new Error(`Failed to list files: ${n.message}`,{cause:n}));a.failure&&(ge(we(p,{message:a.failure.message})),process.exit(1));let{files:s,folders:c}=a.data;if(c.length===0&&s.length===0){console.log("No files or folders found.");return}let d=[...c.map(n=>({type:"folder",name:n.name,size:"-"})),...s.map(n=>({type:"file",name:n.name,size:n.size?wo(n.size):"-"}))];ge(we(Pt,{keys:["type","name","size"],data:d}))}function wo(e){if(e===0)return"0 B";let t=1024,r=["B","KB","MB","GB","TB"],o=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**o).toFixed(2))} ${r[o]}`}var vt=f(()=>{"use strict";i();P();y();kt();R()});var Lt={};b(Lt,{upload:()=>yo});import{readFile as ho}from"fs/promises";import{basename as xo}from"path";import{withResult as V}from"@byteslice/result";import{render as A}from"ink";import{jsx as $}from"react/jsx-runtime";async function yo(e,t,r){let o=await V(()=>S(e.project),w=>new Error(w.message));o.failure&&(A($(p,{message:o.failure.message})),process.exit(1));let a=await V(()=>ho(t),w=>new Error(`Failed to read file: ${w.message}`,{cause:w}));a.failure&&(A($(p,{message:a.failure.message})),process.exit(1));let s=xo(t),c=r?`${r}/${s}`:s,d=await u(this),n=await V(()=>d.buckets.createSignedUploadUrl({projectId:o.data,path:c}),w=>new Error(`Failed to get upload URL: ${w.message}`,{cause:w}));n.failure&&(A($(p,{message:n.failure.message})),process.exit(1));let h=await V(async()=>{let w=await fetch(n.data.signedUrl,{method:"PUT",headers:{"Content-Type":"application/octet-stream","x-upsert":"true"},body:a.data});if(!w.ok)throw new Error(`Upload failed: ${w.statusText}`);return w},w=>new Error(`Failed to upload file: ${w.message}`,{cause:w}));h.failure&&(A($(p,{message:h.failure.message})),process.exit(1)),A($(g,{message:`Uploaded ${s} to ${c}`}))}var It=f(()=>{"use strict";i();P();y();k();R()});var Tt={};b(Tt,{download:()=>bo});import{writeFile as Co}from"fs/promises";import{withResult as W}from"@byteslice/result";import{render as z}from"ink";import{jsx as _}from"react/jsx-runtime";async function bo(e,t,r){let o=await W(()=>S(e.project),n=>new Error(n.message));o.failure&&(z(_(p,{message:o.failure.message})),process.exit(1));let a=await u(this),s=await W(()=>a.buckets.createSignedUrl({projectId:o.data,path:t}),n=>new Error(`Failed to get download URL: ${n.message}`,{cause:n}));s.failure&&(z(_(p,{message:s.failure.message})),process.exit(1));let c=await W(async()=>{let n=await fetch(s.data.signedUrl);if(!n.ok)throw new Error(`Download failed: ${n.statusText}`);return n.arrayBuffer()},n=>new Error(`Failed to download file: ${n.message}`,{cause:n}));c.failure&&(z(_(p,{message:c.failure.message})),process.exit(1));let d=await W(()=>Co(r,Buffer.from(c.data)),n=>new Error(`Failed to write file: ${n.message}`,{cause:n}));d.failure&&(z(_(p,{message:d.failure.message})),process.exit(1)),z(_(g,{message:`Downloaded ${t} to ${r}`}))}var Rt=f(()=>{"use strict";i();P();y();k();R()});var Et={};b(Et,{deleteFile:()=>Po});import{withResult as Ut}from"@byteslice/result";import{render as he}from"ink";import{jsx as xe}from"react/jsx-runtime";async function Po(e,t){let r=await Ut(()=>S(e.project),s=>new Error(s.message));r.failure&&(he(xe(p,{message:r.failure.message})),process.exit(1));let o=await u(this),a=await Ut(()=>o.buckets.deleteFile({projectId:r.data,path:t}),s=>new Error(`Failed to delete file: ${s.message}`,{cause:s}));a.failure&&(he(xe(p,{message:a.failure.message})),process.exit(1)),he(xe(g,{message:`Deleted ${t}`}))}var Dt=f(()=>{"use strict";i();P();y();k();R()});var $t={};b($t,{url:()=>ko});import{withResult as At}from"@byteslice/result";import{render as ye}from"ink";import{jsx as Ce}from"react/jsx-runtime";async function ko(e,t){let r=await At(()=>S(e.project),s=>new Error(s.message));r.failure&&(ye(Ce(p,{message:r.failure.message})),process.exit(1));let o=await u(this),a=await At(()=>o.buckets.createSignedUrl({projectId:r.data,path:t,expiresIn:e.expires}),s=>new Error(`Failed to create signed URL: ${s.message}`,{cause:s}));a.failure&&(ye(Ce(p,{message:a.failure.message})),process.exit(1)),console.log(a.data.signedUrl),ye(Ce(g,{message:`URL expires at ${a.data.expiresAt}`}))}var zt=f(()=>{"use strict";i();P();y();k();R()});i();import{run as Bo}from"@stricli/core";i();import{buildInstallCommand as To,buildUninstallCommand as Ro}from"@stricli/auto-complete";import{buildApplication as Uo,buildRouteMap as Eo}from"@stricli/core";i();import{buildCommand as Oe,buildRouteMap as hr}from"@stricli/core";var xr=Oe({loader:async()=>{let{login:e}=await Promise.resolve().then(()=>(re(),te));return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log in with an existing account"}}),yr=Oe({loader:async()=>{let{logout:e}=await Promise.resolve().then(()=>(re(),te));return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log out of an existing account"}}),Ne=hr({routes:{login:xr,logout:yr},docs:{brief:"Auth commands"}});i();import{buildCommand as lt,buildRouteMap as Br}from"@stricli/core";var Or=lt({loader:async()=>{let{generateCode:e}=await Promise.resolve().then(()=>(et(),qe));return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Generate application code and types"}}),Nr=lt({loader:async()=>{let{initializeConfig:e}=await Promise.resolve().then(()=>(ct(),nt));return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Initialize Swirls configuration file"}}),mt=Br({routes:{gen:Or,init:Nr},docs:{brief:"Developer commands"}});i();import{buildCommand as Ct,buildRouteMap as ro}from"@stricli/core";var oo=Ct({loader:async()=>{let{createProject:e}=await Promise.resolve().then(()=>(gt(),ut));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Project name",parse:String,placeholder:"name"}]}},docs:{brief:"Create a new project"}}),io=Ct({loader:async()=>{let{openProject:e}=await Promise.resolve().then(()=>(yt(),xt));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Project ID",parse:String,placeholder:"project-id"}]}},docs:{brief:"Open project in browser"}}),bt=ro({routes:{create:oo,open:io},docs:{brief:"Project commands"}});i();import{buildCommand as B,buildRouteMap as So}from"@stricli/core";var jo=B({loader:async()=>{let{list:e}=await Promise.resolve().then(()=>(vt(),Ft));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to list (optional)",parse:String,placeholder:"path",optional:!0}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"List files in storage"}}),Fo=B({loader:async()=>{let{upload:e}=await Promise.resolve().then(()=>(It(),Lt));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Local file path to upload",parse:String,placeholder:"file"},{brief:"Destination path in storage (optional)",parse:String,placeholder:"dest",optional:!0}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Upload a file to storage"}}),vo=B({loader:async()=>{let{download:e}=await Promise.resolve().then(()=>(Rt(),Tt));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"},{brief:"Local destination path",parse:String,placeholder:"dest"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Download a file from storage"}}),Lo=B({loader:async()=>{let{deleteFile:e}=await Promise.resolve().then(()=>(Dt(),Et));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Delete a file from storage"}}),Io=B({loader:async()=>{let{url:e}=await Promise.resolve().then(()=>(zt(),$t));return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0},expires:{kind:"parsed",brief:"Expiration time in seconds (default: 86400 = 24 hours)",parse:Number,optional:!0}}},docs:{brief:"Get a signed URL for a file"}}),_t=So({routes:{list:jo,upload:Fo,download:vo,delete:Lo,url:Io},docs:{brief:"Storage commands"}});var Bt="@swirls/cli",Ot="0.0.19",Nt="Swirls command line application";var Do=Eo({routes:{auth:Ne,dev:mt,project:bt,storage:_t,install:To("cli",{bash:"__cli_bash_complete"}),uninstall:Ro("cli",{bash:!0})},docs:{brief:Nt,hideRoute:{install:!0,uninstall:!0}}}),Mt=Uo(Do,{name:Bt,versionInfo:{currentVersion:Ot}});i();import Ao from"fs";import $o from"fs/promises";import zo from"os";import _o from"path";function Ht(e){return{fs:Ao,fsPromise:$o,os:zo,path:_o,process:e}}await Bo(Mt,process.argv.slice(2),Ht(process));
|
package/package.json
CHANGED
package/dist/chunk-7KXMHQNZ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import*as o from"zod";async function l(t,r){await t.fsPromise.stat(r).then(()=>!0).catch(()=>!1)||await t.fsPromise.mkdir(r,{recursive:!0})}function a(t){if(!t.path)throw new Error("No `path` found in context.");if(!t.os)throw new Error("No `os` found in context.");let r=t.os.homedir();return t.path.join(r,".swirls")}var d=o.object({idToken:o.string(),jwt:o.string(),sessionId:o.string()});function c(t){return`${a(t)}/credentials`}async function R(t){let r=c(t);await t.fsPromise.stat(r).then(()=>!0).catch(()=>!1)&&await t.fsPromise.unlink(r)}async function f(t){let r=c(t),n=await t.fsPromise.readFile(r,"utf8");return o.parse(d,JSON.parse(n))}async function U(t,r,n,e){let s=c(t);await l(t,a(t)),await t.fsPromise.writeFile(s,JSON.stringify({idToken:r,jwt:n,sessionId:e}))}import*as i from"zod";var w=i.object({API_URL:i.string(),OAUTH_AUTHORIZE_URL:i.string()}),C={API_URL:"https://swirls.ai/api",OAUTH_AUTHORIZE_URL:"https://clerk.swirls.ai/oauth/authorize"},m=i.parse(w,C);import{withResult as h}from"@byteslice/result";import{createORPCClient as x,onError as y}from"@orpc/client";import{RPCLink as L}from"@orpc/client/fetch";async function I(t){let r=new L({url:`${m.API_URL}/rpc`,headers:async()=>{let e=await h(()=>f(t),u=>new Error("Failed to read credentials file",{cause:u.message}));if(e.failure)return{};let{idToken:s,jwt:p}=e.data;return{Authorization:`Bearer ${p||s}`}},interceptors:[y(e=>{e instanceof Error&&e.name==="AbortError"||console.error(e)})]});return x(r)}export{a,R as b,f as c,U as d,m as e,I as f};
|
package/dist/chunk-KCGRSAKR.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as o}from"./chunk-RJOLKCKW.js";import{render as t}from"ink";import n from"open";import{jsx as i}from"react/jsx-runtime";var s="https://swirls.ai/projects";async function a(e){let r=`${s}/${e.id}`;await n(r),t(i(o,{message:`Opened project "${e.name}" in browser.`}))}export{a};
|
package/dist/chunk-N2UFNXNM.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{existsSync as i}from"fs";import{resolve as c}from"path";import{configFileName as t,configSchema as n}from"@swirls/sdk/config";import{createJiti as s}from"jiti";async function g(r){if(r)return r;let o=c(process.cwd(),t);if(!i(o))throw new Error(`No project specified and no ${t} found. Use --project flag or run from a project directory.`);let e=await s(import.meta.url).import(o,{default:!0});return n.parse(e).projectId}export{g as a};
|
package/dist/chunk-OEQFVEK4.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Box as t,Text as e}from"ink";import{jsx as o,jsxs as i}from"react/jsx-runtime";function r(s){return i(t,{flexDirection:"column",children:[o(e,{color:"red",children:s.message}),o(e,{children:"If this issue persists, send us an email at help@byteslice.co, and we can help you out."})]})}export{r as a};
|
package/dist/chunk-RJOLKCKW.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Text as o}from"ink";import{jsx as r}from"react/jsx-runtime";function t(e){return r(o,{color:"green",children:e.message})}export{t as a};
|
package/dist/chunk-VHACPEPJ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{buildInstallCommand as D,buildUninstallCommand as L}from"@stricli/auto-complete";import{buildApplication as I,buildRouteMap as _}from"@stricli/core";import{buildCommand as r,buildRouteMap as m}from"@stricli/core";var f=r({loader:async()=>{let{login:e}=await import("./implementation-EXDODHPG.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log in with an existing account"}}),g=r({loader:async()=>{let{logout:e}=await import("./implementation-EXDODHPG.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Log out of an existing account"}}),i=m({routes:{login:f,logout:g},docs:{brief:"Auth commands"}});import{buildCommand as a,buildRouteMap as b}from"@stricli/core";var h=a({loader:async()=>{let{generateCode:e}=await import("./generate-code-L5H45YK4.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Generate application code and types"}}),k=a({loader:async()=>{let{initializeConfig:e}=await import("./initialize-config-DKTZP3W4.js");return e},parameters:{positional:{kind:"tuple",parameters:[]}},docs:{brief:"Initialize Swirls configuration file"}}),s=b({routes:{gen:h,init:k},docs:{brief:"Developer commands"}});import{buildCommand as n,buildRouteMap as j}from"@stricli/core";var w=n({loader:async()=>{let{createProject:e}=await import("./create-project-4SZY6HDF.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Project name",parse:String,placeholder:"name"}]}},docs:{brief:"Create a new project"}}),C=n({loader:async()=>{let{openProject:e}=await import("./open-project-544S7TXQ.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Project ID",parse:String,placeholder:"project-id"}]}},docs:{brief:"Open project in browser"}}),p=j({routes:{create:w,open:C},docs:{brief:"Project commands"}});import{buildCommand as t,buildRouteMap as S}from"@stricli/core";var y=t({loader:async()=>{let{list:e}=await import("./list-5ZNZIBFA.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to list (optional)",parse:String,placeholder:"path",optional:!0}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"List files in storage"}}),x=t({loader:async()=>{let{upload:e}=await import("./upload-NMJWKERQ.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Local file path to upload",parse:String,placeholder:"file"},{brief:"Destination path in storage (optional)",parse:String,placeholder:"dest",optional:!0}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Upload a file to storage"}}),P=t({loader:async()=>{let{download:e}=await import("./download-IX63ZPH7.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"},{brief:"Local destination path",parse:String,placeholder:"dest"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Download a file from storage"}}),v=t({loader:async()=>{let{deleteFile:e}=await import("./delete-SDEN2DHA.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0}}},docs:{brief:"Delete a file from storage"}}),R=t({loader:async()=>{let{url:e}=await import("./url-DQSBHBMV.js");return e},parameters:{positional:{kind:"tuple",parameters:[{brief:"Path to file in storage",parse:String,placeholder:"path"}]},flags:{project:{kind:"parsed",brief:"Project ID (uses config if not specified)",parse:String,optional:!0},expires:{kind:"parsed",brief:"Expiration time in seconds (default: 86400 = 24 hours)",parse:Number,optional:!0}}},docs:{brief:"Get a signed URL for a file"}}),l=S({routes:{list:y,upload:x,download:P,delete:v,url:R},docs:{brief:"Storage commands"}});var c="@swirls/cli",d="0.0.18",u="Swirls command line application";var z=_({routes:{auth:i,dev:s,project:p,storage:l,install:D("cli",{bash:"__cli_bash_complete"}),uninstall:L("cli",{bash:!0})},docs:{brief:u,hideRoute:{install:!0,uninstall:!0}}}),Z=I(z,{name:c,versionInfo:{currentVersion:d}});import M from"fs";import N from"fs/promises";import A from"os";import E from"path";function ae(e){return{fs:M,fsPromise:N,os:A,path:E,process:e}}export{Z as a,ae as b};
|
package/dist/chunk-Y7H7V3KU.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import r from"fs/promises";import o from"path";async function s(i,t){let e=o.dirname(i);await r.mkdir(e,{recursive:!0}),await r.writeFile(i,t,"utf-8")}export{s as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as u}from"./chunk-KCGRSAKR.js";import{a as f}from"./chunk-RJOLKCKW.js";import{f as c}from"./chunk-7KXMHQNZ.js";import{a as p}from"./chunk-OEQFVEK4.js";import{withResult as j}from"@byteslice/result";import{render as b}from"ink";import{Box as i,render as w,Text as x}from"ink";import P from"ink-text-input";import{useState as y}from"react";import{jsx as m,jsxs as a}from"react/jsx-runtime";function C(r){let[o,n]=y(""),e=s=>{let t=s.trim().toLowerCase(),g=t===""||t==="y"||t==="yes";setImmediate(()=>r.onAnswer(g))};return m(i,{flexDirection:"column",children:a(i,{children:[a(x,{children:[r.message," "]}),m(P,{value:o,onChange:n,onSubmit:e})]})})}async function l(r){let{above:o}=r??{};return new Promise(n=>{let e=w(a(i,{flexDirection:"column",children:[o,m(C,{message:"Open project in browser? (Y/n)",onAnswer:s=>{e.unmount(),n(s)}})]}))})}import{jsx as d}from"react/jsx-runtime";async function I(r,o){let n=await c(this),e=await j(()=>n.projects.createProject({name:o}),t=>new Error(`Failed to create project: ${t.message}`,{cause:t}));e.failure&&(b(d(p,{message:e.failure.message})),process.exit(1)),await l({above:d(f,{message:`Success! Created "${o}" project: ${e.data.id}`})})&&await u(e.data)}export{I as createProject};
|
package/dist/delete-SDEN2DHA.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as m}from"./chunk-RJOLKCKW.js";import{a as c}from"./chunk-N2UFNXNM.js";import{f as l}from"./chunk-7KXMHQNZ.js";import{a as r}from"./chunk-OEQFVEK4.js";import{withResult as f}from"@byteslice/result";import{render as o}from"ink";import{jsx as s}from"react/jsx-runtime";async function j(n,i){let t=await f(()=>c(n.project),e=>new Error(e.message));t.failure&&(o(s(r,{message:t.failure.message})),process.exit(1));let p=await l(this),a=await f(()=>p.buckets.deleteFile({projectId:t.data,path:i}),e=>new Error(`Failed to delete file: ${e.message}`,{cause:e}));a.failure&&(o(s(r,{message:a.failure.message})),process.exit(1)),o(s(m,{message:`Deleted ${i}`}))}export{j as deleteFile};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as c}from"./chunk-RJOLKCKW.js";import{a as w}from"./chunk-N2UFNXNM.js";import{f as d}from"./chunk-7KXMHQNZ.js";import{a as r}from"./chunk-OEQFVEK4.js";import{writeFile as u}from"fs/promises";import{withResult as a}from"@byteslice/result";import{render as o}from"ink";import{jsx as t}from"react/jsx-runtime";async function D(g,n,f){let s=await a(()=>w(g.project),e=>new Error(e.message));s.failure&&(o(t(r,{message:s.failure.message})),process.exit(1));let p=await d(this),i=await a(()=>p.buckets.createSignedUrl({projectId:s.data,path:n}),e=>new Error(`Failed to get download URL: ${e.message}`,{cause:e}));i.failure&&(o(t(r,{message:i.failure.message})),process.exit(1));let l=await a(async()=>{let e=await fetch(i.data.signedUrl);if(!e.ok)throw new Error(`Download failed: ${e.statusText}`);return e.arrayBuffer()},e=>new Error(`Failed to download file: ${e.message}`,{cause:e}));l.failure&&(o(t(r,{message:l.failure.message})),process.exit(1));let m=await a(()=>u(f,Buffer.from(l.data)),e=>new Error(`Failed to write file: ${e.message}`,{cause:e}));m.failure&&(o(t(r,{message:m.failure.message})),process.exit(1)),o(t(c,{message:`Downloaded ${n} to ${f}`}))}export{D as download};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as g}from"./chunk-Y7H7V3KU.js";import{a as d}from"./chunk-RJOLKCKW.js";import{f as p}from"./chunk-7KXMHQNZ.js";import{a as c}from"./chunk-OEQFVEK4.js";import f from"process";import{withResult as l}from"@byteslice/result";import{generateFormsCode as $}from"@swirls/sdk/form/generate";import{render as a}from"ink";import{Box as S,Text as u}from"ink";import L from"ink-spinner";import{jsx as w,jsxs as h}from"react/jsx-runtime";function x(e){return h(S,{children:[w(u,{color:"cyan",children:w(L,{type:"dots"})}),h(u,{children:[" ",e.message]})]})}import{existsSync as E}from"fs";import{resolve as R}from"path";import{configFileName as y,configSchema as T}from"@swirls/sdk/config";import{createJiti as J}from"jiti";async function F(){let e=R(process.cwd(),y);if(!E(e))throw new Error(`Config file not found in project root: ${y}`);let r=await J(import.meta.url).import(e,{default:!0});return T.parse(r)}async function C(e,n){let r=await p(e),{results:i}=await r.forms.listForms({projectId:n});function m(t){return t.schema!=null}return i.filter(m).map(t=>({id:t.id,name:t.name,schema:t.schema}))}import{jsx as s}from"react/jsx-runtime";async function X(){let e=await l(()=>F(),o=>new Error("Failed to load configuration",{cause:o}));e.failure&&(a(s(c,{message:e.failure.message})),f.exit(1));let{projectId:n,genPath:r}=e.data;a(s(x,{message:"Generating form code..."}));let i=await l(async()=>{let o=['// This file was generated by "@swirls/cli dev generate"',"// Do not edit this file manually",""],t=await C(this,n);return $(t,o)},o=>new Error(`Failed to generate form code: ${o.message}`,{cause:o}));i.failure&&(a(s(c,{message:i.failure.message})),f.exit(1));let m=await l(()=>g(r,i.data),o=>new Error("Failed to write code file",{cause:o}));m.failure&&(a(s(c,{message:m.failure.message})),f.exit(1)),a(s(d,{message:`Success! Generated code at ${r}`}))}export{X as generateCode};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import{a as p}from"./chunk-RJOLKCKW.js";import{a as k,b as v,c as C,d as w,e as b,f as g}from"./chunk-7KXMHQNZ.js";import{a as h}from"./chunk-OEQFVEK4.js";import{withResult as n}from"@byteslice/result";import{render as u}from"ink";import R from"http";import{withResult as P}from"@byteslice/result";import*as l from"zod";var A=8765,y=`http://localhost:${A}`,j=l.object({code:l.string(),state:l.string()}),O=`
|
|
2
|
-
<!DOCTYPE html>
|
|
3
|
-
<html lang="en">
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<title>Authentication Successful</title>
|
|
8
|
-
<script src="https://cdn.tailwindcss.com"></script>
|
|
9
|
-
</head>
|
|
10
|
-
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
|
11
|
-
<div class="bg-white p-8 rounded-2xl shadow-lg text-center max-w-md">
|
|
12
|
-
<svg class="w-16 h-16 text-green-500 mx-auto" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
13
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7" />
|
|
14
|
-
</svg>
|
|
15
|
-
<h1 class="text-2xl font-semibold mt-4">Authentication Successful</h1>
|
|
16
|
-
<p class="text-gray-600 mt-2">You can now return to your terminal and close this browser.</p>
|
|
17
|
-
</div>
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
20
|
-
`,_=`
|
|
21
|
-
<!DOCTYPE html>
|
|
22
|
-
<html lang="en">
|
|
23
|
-
<head>
|
|
24
|
-
<meta charset="UTF-8">
|
|
25
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
26
|
-
<title>Authentication Failed</title>
|
|
27
|
-
<script src="https://cdn.tailwindcss.com"></script>
|
|
28
|
-
</head>
|
|
29
|
-
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
|
|
30
|
-
<div class="bg-white p-8 rounded-2xl shadow-lg text-center max-w-md">
|
|
31
|
-
<svg class="w-16 h-16 text-red-500 mx-auto" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
|
|
32
|
-
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
|
|
33
|
-
</svg>
|
|
34
|
-
<h1 class="text-2xl font-semibold mt-4">Authentication Failed</h1>
|
|
35
|
-
<p class="text-gray-600 mt-2">Something bad happened while trying to authenticate you. Please try again.</p>
|
|
36
|
-
<p class="text-gray-600 mt-2">If the problem persists, <a href="mailto:help@byteslice.co" target="_blank" class="text-amber-500 hover:text-amber-600">please let us know</a>.</p>
|
|
37
|
-
</div>
|
|
38
|
-
</body>
|
|
39
|
-
</html>
|
|
40
|
-
`;function Y(e){if(!e.url)throw new Error("No URL found in callback response.");let t=new URL(e.url,y);return l.parse(j,Object.fromEntries(t.searchParams.entries()))}function S(e){e.writeHead(400,{"Content-Type":"text/html"}),e.end(_)}function B(e){e.writeHead(200,{"Content-Type":"text/html"}),e.end(O)}function F(e){return new Promise((t,r)=>{let i=R.createServer(async(a,o)=>{let c=await P(()=>Y(a),f=>f);if(c.failure){S(o),r(c.failure);return}let m=await P(()=>e(c.data),f=>f);if(m.failure){S(o),r(m.failure);return}B(o),i.close(()=>{t()})});i.listen(A)})}import H from"@clerk/clerk-js/headless/index.js";var D=H.Clerk;async function I(e){let t=new D(e);return await t.load({standardBrowser:!1}),t}async function L(e,t){let r=await e.client?.signIn.create({ticket:t,strategy:"ticket"});if(!r||!r.createdSessionId)throw new Error("Failed to sign in.");return{createdSessionId:r.createdSessionId}}import K from"open";function U(e=32){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r=new Uint8Array(e);crypto.getRandomValues(r);let i="";for(let a of r)i+=t[a%t.length];return i}function T(e){let t=new URLSearchParams({client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",scope:"openid profile email",state:e.state});K(`${e.authorizeUri}?${t}`)}import{Text as M}from"ink";import{jsx as J}from"react/jsx-runtime";function E(e){return J(M,{color:"yellow",children:e.message})}function W(e){return`${k(e)}/project`}async function z(e){let t=W(e);await e.fsPromise.stat(t).then(()=>!0).catch(()=>!1)&&await e.fsPromise.unlink(t)}import{jsx as d}from"react/jsx-runtime";async function $(e,t,r){let i=await n(async()=>await(await g(e)).cli.exchangeToken({code:r.code}),s=>new Error("Failed to exchange callback code for token",{cause:s.message}));if(i.failure)throw i.failure;await w(e,i.data.idToken,"","");let a=await n(async()=>await(await g(e)).cli.createSignInTicket(),s=>new Error("Failed to exchange ID token code for a sign-in ticket",{cause:s.message}));if(a.failure)throw a.failure;let o=await I(t.clerkPublishableKey),c=await n(()=>L(o,a.data.token),s=>new Error("Failed to create a new sign-in for this device",{cause:s.message}));if(c.failure)throw c.failure;let m=await n(async()=>await(await g(e)).cli.createJwt({sessionId:c.data.createdSessionId}),s=>new Error("Failed to create a session JWT",{cause:s.message}));if(m.failure)throw m.failure;let f=await n(()=>w(e,i.data.idToken,m.data,c.data.createdSessionId),s=>new Error("Failed to save your credentials to disk",{cause:s.message}));if(f.failure)throw f.failure}async function ye(){let e=await g(this),t=U(),r=await n(()=>e.cli.getConfig(),a=>new Error("Failed to retrieve authentication configuration",{cause:a.message}));r.failure&&(u(d(h,{message:r.failure.message})),process.exit(1)),T({authorizeUri:b.OAUTH_AUTHORIZE_URL,clientId:r.data.clientId,redirectUri:y,state:t});let i=await n(()=>F(async a=>{if(a.state!==t)throw new Error("Invalid state.");await $(this,r.data,a)}),a=>a);i.failure&&(u(d(h,{message:i.failure.message})),process.exit(1)),u(d(p,{message:"Success! You are now logged in."}))}async function xe(){let e=await n(()=>C(this),o=>o);e.failure&&(u(d(h,{message:"There was an issue reading your credentials. You are probably already logged out."})),process.exit(1));let t=await g(this),r=await n(()=>t.cli.getConfig(),o=>new Error("Failed to retrieve authentication configuration",{cause:o.message}));r.failure&&(u(d(h,{message:r.failure.message})),process.exit(1)),(await n(async()=>t.cli.revokeSession({sessionId:e.data.sessionId}),o=>o)).failure&&u(d(E,{message:"There was an issue revoking your session. You are probably already logged out. Purging credentials file..."}));let a=await n(async()=>{await v(this),await z(this)},o=>o);if(a.failure)throw a.failure;u(d(p,{message:"Success! You are now logged out."}))}export{ye as login,xe as logout};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as p}from"./chunk-Y7H7V3KU.js";import{a as l}from"./chunk-RJOLKCKW.js";import{a as s}from"./chunk-OEQFVEK4.js";import{existsSync as S}from"fs";import{resolve as v}from"path";import m from"process";import{withResult as F}from"@byteslice/result";import{configFileName as D,generateConfig as T}from"@swirls/sdk/config";import{render as c}from"ink";import{Box as d,render as h,Text as g}from"ink";import w from"ink-text-input";import{useState as x}from"react";import{z as C}from"zod";import{jsx as i,jsxs as I}from"react/jsx-runtime";function y(t){let[r,o]=x(""),[e,a]=x(null);return I(d,{flexDirection:"column",children:[I(d,{children:[i(g,{children:"Enter project ID (UUID): "}),i(w,{value:r,onChange:n=>{a(null),o(n)},onSubmit:n=>{if(a(null),n.trim()===""){setImmediate(()=>t.onInput());return}let f=C.uuid().safeParse(n);if(!f.success){a("Invalid UUID. Please try again."),o("");return}setImmediate(()=>t.onInput(f.data))}})]}),e&&i(g,{color:"red",children:e})]})}async function P(){return new Promise(t=>{let r=h(i(y,{onInput:o=>{r.unmount(),t(o)}}))})}import{jsx as u}from"react/jsx-runtime";async function M(){let t=v(m.cwd(),D);S(t)&&(c(u(s,{message:`Configuration already exists at ${t}.`})),m.exit(1));let r=await P(),o=await F(async()=>{let e=T(r);await p(t,e)},e=>new Error("Failed to create configuration",{cause:e}));o.failure&&(c(u(s,{message:o.failure.message})),m.exit(1)),c(u(l,{message:`Success! Created configuration at ${t}`}))}export{M as initializeConfig};
|
package/dist/list-5ZNZIBFA.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as T}from"./chunk-N2UFNXNM.js";import{f as x}from"./chunk-7KXMHQNZ.js";import{a as c}from"./chunk-OEQFVEK4.js";import{withResult as y}from"@byteslice/result";import{render as g}from"ink";import{Box as f,Text as u}from"ink";import{Fragment as B}from"react";import{Fragment as b,jsx as r,jsxs as p}from"react/jsx-runtime";function k(t){return typeof t=="boolean"?t?p(b,{children:[r(u,{color:"green",children:"\u2714"})," yes"]}):"no":String(t)}function C(t,o){return o.map(n=>{let e=n.key in t?k(t[n.key]):null;return{column:n,value:e}})}function D(t,o,n=1){return o.map(e=>{let a=String(e).length,l=t.map(m=>e in m&&(typeof m[e]=="string"||typeof m[e]=="number")?String(m[e]).length:0),s=Math.max(...l,a)+n*2;return{name:String(e),key:e,width:s}})}function d(t){return r(u,{children:Array(t.width).fill("\u2500").join("")})}function w(t){let o=D(t.data,t.keys),n=o.reduce((e,a)=>e+a.width,0);return p(f,{flexDirection:"column",width:n,children:[r(d,{width:n}),r(f,{flexDirection:"row",children:o.map(e=>r(f,{width:e.width,children:r(u,{bold:!0,color:"blue",children:e.name})},e.name))}),r(d,{width:n}),r(f,{flexDirection:"column",children:t.data.map((e,a)=>{let l=C(e,o);return p(B,{children:[r(f,{flexDirection:"row",children:l.map(s=>r(f,{width:s.column.width,children:r(u,{children:s.value})},s.column.name))}),r(d,{width:n})]},`row-${a}`)})})]})}import{jsx as h}from"react/jsx-runtime";async function v(t,o){let n=await y(()=>T(t.project),i=>new Error(i.message));n.failure&&(g(h(c,{message:n.failure.message})),process.exit(1));let e=await x(this),a=await y(()=>e.buckets.listFiles({projectId:n.data,path:o}),i=>new Error(`Failed to list files: ${i.message}`,{cause:i}));a.failure&&(g(h(c,{message:a.failure.message})),process.exit(1));let{files:l,folders:s}=a.data;if(s.length===0&&l.length===0){console.log("No files or folders found.");return}let m=[...s.map(i=>({type:"folder",name:i.name,size:"-"})),...l.map(i=>({type:"file",name:i.name,size:i.size?F(i.size):"-"}))];g(h(w,{keys:["type","name","size"],data:m}))}function F(t){if(t===0)return"0 B";let o=1024,n=["B","KB","MB","GB","TB"],e=Math.floor(Math.log(t)/Math.log(o));return`${parseFloat((t/o**e).toFixed(2))} ${n[e]}`}export{v as list};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as i}from"./chunk-KCGRSAKR.js";import"./chunk-RJOLKCKW.js";import{f as r}from"./chunk-7KXMHQNZ.js";import{a as e}from"./chunk-OEQFVEK4.js";import{withResult as m}from"@byteslice/result";import{render as a}from"ink";import{jsx as n}from"react/jsx-runtime";async function d(p,s){let c=await r(this),t=await m(()=>c.projects.getProject({projectId:s}),o=>new Error(`Failed to get project: ${o.message}`,{cause:o}));t.failure&&(a(n(e,{message:t.failure.message})),process.exit(1)),t.data||(a(n(e,{message:"Project not found."})),process.exit(1)),await i(t.data)}export{d as openProject};
|
package/dist/upload-NMJWKERQ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as g}from"./chunk-RJOLKCKW.js";import{a as u}from"./chunk-N2UFNXNM.js";import{f}from"./chunk-7KXMHQNZ.js";import{a as t}from"./chunk-OEQFVEK4.js";import{readFile as h}from"fs/promises";import{basename as x}from"path";import{withResult as r}from"@byteslice/result";import{render as a}from"ink";import{jsx as o}from"react/jsx-runtime";async function L(w,p,m){let s=await r(()=>u(w.project),e=>new Error(e.message));s.failure&&(a(o(t,{message:s.failure.message})),process.exit(1));let i=await r(()=>h(p),e=>new Error(`Failed to read file: ${e.message}`,{cause:e}));i.failure&&(a(o(t,{message:i.failure.message})),process.exit(1));let l=x(p),d=m?`${m}/${l}`:l,U=await f(this),n=await r(()=>U.buckets.createSignedUploadUrl({projectId:s.data,path:d}),e=>new Error(`Failed to get upload URL: ${e.message}`,{cause:e}));n.failure&&(a(o(t,{message:n.failure.message})),process.exit(1));let c=await r(async()=>{let e=await fetch(n.data.signedUrl,{method:"PUT",headers:{"Content-Type":"application/octet-stream","x-upsert":"true"},body:i.data});if(!e.ok)throw new Error(`Upload failed: ${e.statusText}`);return e},e=>new Error(`Failed to upload file: ${e.message}`,{cause:e}));c.failure&&(a(o(t,{message:c.failure.message})),process.exit(1)),a(o(g,{message:`Uploaded ${l} to ${d}`}))}export{L as upload};
|
package/dist/url-DQSBHBMV.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as m}from"./chunk-RJOLKCKW.js";import{a as n}from"./chunk-N2UFNXNM.js";import{f as c}from"./chunk-7KXMHQNZ.js";import{a as s}from"./chunk-OEQFVEK4.js";import{withResult as p}from"@byteslice/result";import{render as o}from"ink";import{jsx as i}from"react/jsx-runtime";async function j(a,l){let t=await p(()=>n(a.project),r=>new Error(r.message));t.failure&&(o(i(s,{message:t.failure.message})),process.exit(1));let g=await c(this),e=await p(()=>g.buckets.createSignedUrl({projectId:t.data,path:l,expiresIn:a.expires}),r=>new Error(`Failed to create signed URL: ${r.message}`,{cause:r}));e.failure&&(o(i(s,{message:e.failure.message})),process.exit(1)),console.log(e.data.signedUrl),o(i(m,{message:`URL expires at ${e.data.expiresAt}`}))}export{j as url};
|