@swirls/cli 0.0.3 → 0.0.5

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.
@@ -0,0 +1 @@
1
+ import{f as o}from"./chunk-LIZAQE7K.js";import{a as c,b as i}from"./chunk-WT3YKOQJ.js";import{withResult as n}from"@byteslice/result";import{render as s}from"ink";import{jsx as a}from"react/jsx-runtime";async function j(p,t){let m=await o(this),e=await n(()=>m.projects.createProject({name:t}),r=>new Error(`Failed to create project: ${r.message}`,{cause:r}));e.failure&&(s(a(c,{message:e.failure.message})),process.exit(1)),s(a(i,{message:`Success! Created "${t}" project: ${e.data.id}`}))}export{j as createProject};
@@ -0,0 +1,73 @@
1
+ import{a as w,b as F,d as A}from"./chunk-PL5KWBVQ.js";import{f as S}from"./chunk-LIZAQE7K.js";import{a as y,b as P}from"./chunk-WT3YKOQJ.js";import C from"process";import{withResult as j}from"@byteslice/result";var O=(e,r)=>e.anyOf.length?e.anyOf.length===1?a(e.anyOf[0],{...r,path:[...r.path,"anyOf",0]}):`z.union([${e.anyOf.map((t,o)=>a(t,{...r,path:[...r.path,"anyOf",o]})).join(", ")}])`:"z.any()";var N=e=>"z.boolean()";var E=e=>"z.any()";var T=(e,r)=>`z.union([${e.type.map(t=>a({...e,type:t},{...r,withoutDefaults:!0})).join(", ")}])`;var I=(e,r)=>`z.any().refine((value) => !${a(e.not,{...r,path:[...r.path,"not"]})}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;var J=e=>"z.null()";var L=e=>[e.slice(0,e.length/2),e.slice(e.length/2)];var c=Symbol("Original index"),ae=e=>{let r=[];for(let t=0;t<e.length;t++){let o=e[t];if(typeof o=="boolean")r.push(o?{[c]:t}:{[c]:t,not:{}});else{if(c in o)return e;r.push({...o,[c]:t})}}return r};function m(e,r){if(e.allOf.length===0)return"z.never()";if(e.allOf.length===1){let t=e.allOf[0];return a(t,{...r,path:[...r.path,"allOf",t[c]]})}else{let[t,o]=L(ae(e.allOf));return`z.intersection(${m({allOf:t},r)}, ${m({allOf:o},r)})`}}function u(e,r,t){let o=e[r],n="";if(o!==void 0){let s=t({value:o,json:JSON.stringify(o)});if(s){let i=s[0],p=s.length===3?s[1]:"",f=s.length===3?s[2]:s[1];n+=i,e.errorMessage?.[r]!==void 0&&(n+=p+JSON.stringify(e.errorMessage[r])),n+=f}}return n}var M=(e,r)=>{if(Array.isArray(e.items))return`z.tuple([${e.items.map((o,n)=>a(o,{...r,path:[...r.path,"items",n]}))}])`;let t=e.items?`z.array(${a(e.items,{...r,path:[...r.path,"items"]})})`:"z.array(z.any())";return t+=u(e,"minItems",({json:o})=>[`.min(${o}`,", ",")"]),t+=u(e,"maxItems",({json:o})=>[`.max(${o}`,", ",")"]),e.uniqueItems===!0&&(t+=u(e,"uniqueItems",()=>[".unique(","",")"])),t};var R=e=>`z.literal(${JSON.stringify(e.const)})`;var D=e=>e.enum.length===0?"z.never()":e.enum.length===1?`z.literal(${JSON.stringify(e.enum[0])})`:e.enum.every(r=>typeof r=="string")?`z.enum([${e.enum.map(r=>JSON.stringify(r))}])`:`z.union([${e.enum.map(r=>`z.literal(${JSON.stringify(r)})`).join(", ")}])`;var q=(e,r)=>{let t=a(e.if,{...r,path:[...r.path,"if"]}),o=a(e.then,{...r,path:[...r.path,"then"]}),n=a(e.else,{...r,path:[...r.path,"else"]});return`z.union([${o}, ${n}]).superRefine((value,ctx) => {
2
+ const result = ${t}.safeParse(value).success
3
+ ? ${o}.safeParse(value)
4
+ : ${n}.safeParse(value);
5
+ if (!result.success) {
6
+ result.error.errors.forEach((error) => ctx.addIssue(error))
7
+ }
8
+ })`};var _=e=>{let r="z.number()";return e.type==="integer"?r+=u(e,"type",()=>[".int(",")"]):r+=u(e,"format",({value:t})=>{if(t==="int64")return[".int(",")"]}),r+=u(e,"multipleOf",({value:t,json:o})=>t===1?r.startsWith("z.number().int(")?void 0:[".int(",")"]:[`.multipleOf(${o}`,", ",")"]),typeof e.minimum=="number"?e.exclusiveMinimum===!0?r+=u(e,"minimum",({json:t})=>[`.gt(${t}`,", ",")"]):r+=u(e,"minimum",({json:t})=>[`.gte(${t}`,", ",")"]):typeof e.exclusiveMinimum=="number"&&(r+=u(e,"exclusiveMinimum",({json:t})=>[`.gt(${t}`,", ",")"])),typeof e.maximum=="number"?e.exclusiveMaximum===!0?r+=u(e,"maximum",({json:t})=>[`.lt(${t}`,", ",")"]):r+=u(e,"maximum",({json:t})=>[`.lte(${t}`,", ",")"]):typeof e.exclusiveMaximum=="number"&&(r+=u(e,"exclusiveMaximum",({json:t})=>[`.lt(${t}`,", ",")"])),r};var $=(e,r)=>e.oneOf.length?e.oneOf.length===1?a(e.oneOf[0],{...r,path:[...r.path,"oneOf",0]}):`z.any().superRefine((x, ctx) => {
9
+ const schemas = [${e.oneOf.map((t,o)=>a(t,{...r,path:[...r.path,"oneOf",o]})).join(", ")}];
10
+ const errors = schemas.reduce<z.ZodError[]>(
11
+ (errors, schema) =>
12
+ ((result) =>
13
+ result.error ? [...errors, result.error] : errors)(
14
+ schema.safeParse(x),
15
+ ),
16
+ [],
17
+ );
18
+ if (schemas.length - errors.length !== 1) {
19
+ ctx.addIssue({
20
+ path: ctx.path,
21
+ code: "invalid_union",
22
+ unionErrors: errors,
23
+ message: "Invalid input: Should pass single schema",
24
+ });
25
+ }
26
+ })`:"z.any()";var v=e=>{let r=e.split(`
27
+ `);return`/**${r.length===1?r[0]:`
28
+ ${r.map(o=>`* ${o}`).join(`
29
+ `)}
30
+ `}*/
31
+ `},k=(e,r)=>{let t=e.description;return t?`
32
+ ${v(t)}${r}`:r};function U(e,r){let t;e.properties&&(Object.keys(e.properties).length?(t="z.object({ ",t+=Object.keys(e.properties).map(i=>{let p=e.properties[i],f=`${JSON.stringify(i)}: ${a(p,{...r,path:[...r.path,"properties",i]})}`;r.withJsdocs&&typeof p=="object"&&(f=k(p,f));let ie=typeof p=="object"&&p.default!==void 0,se=Array.isArray(e.required)?e.required.includes(i):typeof p=="object"&&p.required===!0;return!ie&&!se?`${f}.optional()`:f}).join(", "),t+=" })"):t="z.object({})");let o=e.additionalProperties!==void 0?a(e.additionalProperties,{...r,path:[...r.path,"additionalProperties"]}):void 0,n;if(e.patternProperties){let i=Object.fromEntries(Object.entries(e.patternProperties).map(([p,f])=>[p,a(f,{...r,path:[...r.path,"patternProperties",p]})],{}));n="",t?o?n+=`.catchall(z.union([${[...Object.values(i),o].join(", ")}]))`:Object.keys(i).length>1?n+=`.catchall(z.union([${Object.values(i).join(", ")}]))`:n+=`.catchall(${Object.values(i)})`:o?n+=`z.record(z.union([${[...Object.values(i),o].join(", ")}]))`:Object.keys(i).length>1?n+=`z.record(z.union([${Object.values(i).join(", ")}]))`:n+=`z.record(${Object.values(i)})`,n+=`.superRefine((value, ctx) => {
33
+ `,n+=`for (const key in value) {
34
+ `,o&&(e.properties?n+=`let evaluated = [${Object.keys(e.properties).map(p=>JSON.stringify(p)).join(", ")}].includes(key)
35
+ `:n+=`let evaluated = false
36
+ `);for(let p in e.patternProperties)n+="if (key.match(new RegExp("+JSON.stringify(p)+`))) {
37
+ `,o&&(n+=`evaluated = true
38
+ `),n+="const result = "+i[p]+`.safeParse(value[key])
39
+ `,n+=`if (!result.success) {
40
+ `,n+=`ctx.addIssue({
41
+ path: [...ctx.path, key],
42
+ code: 'custom',
43
+ message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
44
+ params: {
45
+ issues: result.error.issues
46
+ }
47
+ })
48
+ `,n+=`}
49
+ `,n+=`}
50
+ `;o&&(n+=`if (!evaluated) {
51
+ `,n+="const result = "+o+`.safeParse(value[key])
52
+ `,n+=`if (!result.success) {
53
+ `,n+=`ctx.addIssue({
54
+ path: [...ctx.path, key],
55
+ code: 'custom',
56
+ message: \`Invalid input: must match catchall schema\`,
57
+ params: {
58
+ issues: result.error.issues
59
+ }
60
+ })
61
+ `,n+=`}
62
+ `,n+=`}
63
+ `),n+=`}
64
+ `,n+="})"}let s=t?n?t+n:o?o==="z.never()"?t+".strict()":t+`.catchall(${o})`:t:n||(o?`z.record(${o})`:"z.record(z.any())");return l.an.anyOf(e)&&(s+=`.and(${O({...e,anyOf:e.anyOf.map(i=>typeof i=="object"&&!i.type&&(i.properties||i.additionalProperties||i.patternProperties)?{...i,type:"object"}:i)},r)})`),l.a.oneOf(e)&&(s+=`.and(${$({...e,oneOf:e.oneOf.map(i=>typeof i=="object"&&!i.type&&(i.properties||i.additionalProperties||i.patternProperties)?{...i,type:"object"}:i)},r)})`),l.an.allOf(e)&&(s+=`.and(${m({...e,allOf:e.allOf.map(i=>typeof i=="object"&&!i.type&&(i.properties||i.additionalProperties||i.patternProperties)?{...i,type:"object"}:i)},r)})`),s}var B=e=>{let r="z.string()";r+=u(e,"format",({value:o})=>{switch(o){case"email":return[".email(",")"];case"ip":return[".ip(",")"];case"ipv4":return['.ip({ version: "v4"',", message: "," })"];case"ipv6":return['.ip({ version: "v6"',", message: "," })"];case"uri":return[".url(",")"];case"uuid":return[".uuid(",")"];case"date-time":return[".datetime({ offset: true",", message: "," })"];case"time":return[".time(",")"];case"date":return[".date(",")"];case"binary":return[".base64(",")"];case"duration":return[".duration(",")"]}}),r+=u(e,"pattern",({json:o})=>[`.regex(new RegExp(${o})`,", ",")"]),r+=u(e,"minLength",({json:o})=>[`.min(${o}`,", ",")"]),r+=u(e,"maxLength",({json:o})=>[`.max(${o}`,", ",")"]),r+=u(e,"contentEncoding",({value:o})=>{if(o==="base64")return[".base64(",")"]});let t=u(e,"contentMediaType",({value:o})=>{if(o==="application/json")return['.transform((str, ctx) => { try { return JSON.parse(str); } catch (err) { ctx.addIssue({ code: "custom", message: "Invalid JSON" }); }}',", ",")"]});return t!=""&&(r+=t,r+=u(e,"contentSchema",({value:o})=>{if(o&&o instanceof Object)return[`.pipe(${a(o)}`,", ",")"]})),r};var G=(e,r)=>e.oneOf.length?e.oneOf.length===1?a(e.oneOf[0],{...r,path:[...r.path,"oneOf",0]}):`z.discriminatedUnion("${e.discriminator.propertyName}", [${e.oneOf.map((t,o)=>a(t,{...r,path:[...r.path,"oneOf",o]})).join(", ")}])`:"z.any()";var Z=(e,...r)=>Object.keys(e).reduce((t,o)=>(r.includes(o)||(t[o]=e[o]),t),{});var X=(e,r)=>`${a(Z(e,"nullable"),r,!0)}.nullable()`;var a=(e,r={seen:new Map,path:[]},t)=>{if(typeof e!="object")return e?"z.any()":"z.never()";if(r.parserOverride){let s=r.parserOverride(e,r);if(typeof s=="string")return s}let o=r.seen.get(e);if(o){if(o.r!==void 0)return o.r;if(r.depth===void 0||o.n>=r.depth)return"z.any()";o.n+=1}else o={r:void 0,n:0},r.seen.set(e,o);let n=fe(e,r);return t||(r.withoutDescribes||(n=pe(e,n)),r.withoutDefaults||(n=ue(e,n)),n=le(e,n)),o.r=n,n},pe=(e,r)=>(e.description&&(r+=`.describe(${JSON.stringify(e.description)})`),r),ue=(e,r)=>(e.default!==void 0&&(r+=`.default(${JSON.stringify(e.default)})`),r),le=(e,r)=>(e.readOnly&&(r+=".readonly()"),r),fe=(e,r)=>l.a.nullable(e)?X(e,r):l.an.object(e)?U(e,r):l.an.array(e)?M(e,r):l.an.anyOf(e)?O(e,r):l.an.allOf(e)?m(e,r):l.a.simpleDiscriminatedOneOf(e)?G(e,r):l.a.oneOf(e)?$(e,r):l.a.not(e)?I(e,r):l.an.enum(e)?D(e):l.a.const(e)?R(e):l.a.multipleType(e)?T(e,r):l.a.primitive(e,"string")?B(e):l.a.primitive(e,"number")||l.a.primitive(e,"integer")?_(e):l.a.primitive(e,"boolean")?N(e):l.a.primitive(e,"null")?J(e):l.a.conditional(e)?q(e,r):E(e),l={an:{object:e=>e.type==="object",array:e=>e.type==="array",anyOf:e=>e.anyOf!==void 0,allOf:e=>e.allOf!==void 0,enum:e=>e.enum!==void 0},a:{nullable:e=>e.nullable===!0,multipleType:e=>Array.isArray(e.type),not:e=>e.not!==void 0,const:e=>e.const!==void 0,primitive:(e,r)=>e.type===r,conditional:e=>!!("if"in e&&e.if&&"then"in e&&"else"in e&&e.then&&e.else),simpleDiscriminatedOneOf:e=>{if(!e.oneOf||!Array.isArray(e.oneOf)||e.oneOf.length===0||!e.discriminator||typeof e.discriminator!="object"||!("propertyName"in e.discriminator)||typeof e.discriminator.propertyName!="string")return!1;let r=e.discriminator.propertyName;return e.oneOf.every(t=>{if(!t||typeof t!="object"||t.type!=="object"||!t.properties||typeof t.properties!="object"||!(r in t.properties))return!1;let o=t.properties[r];return o&&typeof o=="object"&&o.type==="string"&&(o.const!==void 0||o.enum&&Array.isArray(o.enum)&&o.enum.length===1)&&Array.isArray(t.required)&&t.required.includes(r)})},oneOf:e=>e.oneOf!==void 0}};var h=(e,{module:r,name:t,type:o,noImport:n,...s}={})=>{if(o&&(!t||r!=="esm"))throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");let i=a(e,{module:r,name:t,path:[],seen:new Map,...s}),p=s.withJsdocs&&typeof e!="boolean"&&e.description?v(e.description):"";if(r==="cjs"?(i=`${p}module.exports = ${t?`{ ${JSON.stringify(t)}: ${i} }`:i}
65
+ `,n||(i=`${p}const { z } = require("zod")
66
+
67
+ ${i}`)):r==="esm"?(i=`${p}export ${t?`const ${t} =`:"default"} ${i}
68
+ `,n||(i=`import { z } from "zod"
69
+
70
+ ${i}`)):t&&(i=`${p}const ${t} = ${i}`),o&&t){let f=typeof o=="string"?o:`${t[0].toUpperCase()}${t.substring(1)}`;i+=`export type ${f} = z.infer<typeof ${t}>
71
+ `}return i};function K(e){return e?e.toLowerCase():""}var me=[/(\p{Ll}|\p{N})(\p{Lu})/gu,/(\p{Lu})(\p{Lu}\p{Ll})/gu],ce=/[^\p{L}\p{N}]+/gu;function H(e,r={}){if(!e)return"";let{splitRegexp:t=me,stripRegexp:o=ce,transform:n=K,delimiter:s=" "}=r,i=W(W(e,t,"$1\0$2"),o,"\0"),p=0,f=i.length;for(;i.charAt(p)==="\0";)p++;for(;i.charAt(f-1)==="\0";)f--;return i.slice(p,f).split("\0").map(n).join(s)}function W(e,r,t){return r instanceof RegExp?e.replace(r,t):r.reduce((o,n)=>o.replace(n,t),e)}function z(e,r){let t=e.charAt(0),o=e.slice(1).toLowerCase();return r>0&&t>="0"&&t<="9"?`_${t}${o}`:`${t.toUpperCase()}${o}`}function x(e,r={}){return e?H(e,{delimiter:"",transform:z,...r}):""}function de(e,r){return r===0?e.toLowerCase():z(e,r)}function Q(e,r={}){return e?x(e,{transform:de,...r}):""}function V(e,r){let t=["import { registerForm } from '@swirls/sdk/form'","import { z } from 'zod'",""],o=e.flatMap(({name:n,schema:s})=>ge(n,s));return[...r,...t,...o,...ye(e),...Oe(e),...$e(e)].join(`
72
+ `)}function ge(e,r){let t=h(r,{module:"esm",name:b(e).camel,noImport:!0,type:!0}),[o,n]=t.split(`
73
+ `);if(!o||!n)throw new Error("Failed to generate standard schema");return[`// Form schema: ${e}`,o,"",n,""]}function ye(e){return["// Form registry","export const registry = {",...e.flatMap(({name:r,id:t})=>[` '${r}': {`,` id: '${t}',`,` name: '${r}',`,` schema: ${b(r).camel},`," },"]),"} as const",""]}function Oe(e){return["// Form registration","export function registerForms() {",...e.map(({name:r})=>` registerForm('${r}', registry['${r}'])`),"}",""]}function $e(e){let r="@swirls/sdk/form";return[`// Module augmentation for ${r}`,`declare module '${r}' {`," interface FormRegistry {",...e.flatMap(({name:t,id:o})=>[` '${t}': {`,` id: '${o}'`,` name: '${t}'`,` schema: typeof ${b(t).camel}`," }"])," }","}",""]}function b(e){return{camel:`${Q(e)}Schema`,pascal:`${x(e)}Schema`}}import{render as d}from"ink";import{Box as xe,Text as Y}from"ink";import we from"ink-spinner";import{jsx as ee,jsxs as re}from"react/jsx-runtime";function te(e){return re(xe,{children:[ee(Y,{color:"cyan",children:ee(we,{type:"dots"})}),re(Y,{children:[" ",e.message]})]})}import{existsSync as ve}from"fs";import{resolve as he}from"path";import{createJiti as ze}from"jiti";async function oe(){let e=he(process.cwd(),w);if(!ve(e))throw new Error(`Config file not found in project root: ${w}`);let t=await ze(import.meta.url).import(e,{default:!0});return F.parse(t)}async function ne(e,r){let t=await S(e),{results:o}=await t.forms.listForms({projectId:r});function n(i){return i.schema!=null}return o.filter(n).map(i=>({id:i.id,name:i.name,schema:i.schema}))}import{jsx as g}from"react/jsx-runtime";async function Mt(){let e=await j(()=>oe(),s=>new Error("Failed to load configuration",{cause:s}));e.failure&&(d(g(y,{message:e.failure.message})),C.exit(1));let{projectId:r,genPath:t}=e.data;d(g(te,{message:"Generating form code..."}));let o=await j(async()=>{let s=['// This file was generated by "@swirls/cli dev generate"',"// Do not edit this file manually",""],i=await ne(this,r);return V(i,s)},s=>new Error(`Failed to generate form code: ${s.message}`,{cause:s}));o.failure&&(d(g(y,{message:o.failure.message})),C.exit(1));let n=await j(()=>A(t,o.data),s=>new Error("Failed to write code file",{cause:s}));n.failure&&(d(g(y,{message:n.failure.message})),C.exit(1)),d(g(P,{message:`Success! Generated code at ${t}`}))}export{Mt as generateCode};
@@ -0,0 +1,40 @@
1
+ import{a as k,b as v,c as C,d as w,e as b,f as m}from"./chunk-LIZAQE7K.js";import{a as p,b as g}from"./chunk-WT3YKOQJ.js";import{withResult as s}from"@byteslice/result";import{render as f}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 I(e){return new Promise((t,r)=>{let i=R.createServer(async(a,o)=>{let c=await P(()=>Y(a),d=>d);if(c.failure){S(o),r(c.failure);return}let u=await P(()=>e(c.data),d=>d);if(u.failure){S(o),r(u.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 L(e){let t=new D(e);return await t.load({standardBrowser:!1}),t}async function F(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 z(e){return J(M,{color:"yellow",children:e.message})}function W(e){return`${k(e)}/project`}async function E(e){let t=W(e);await e.fsPromise.stat(t).then(()=>!0).catch(()=>!1)&&await e.fsPromise.unlink(t)}import{jsx as h}from"react/jsx-runtime";async function $(e,t,r){let i=await s(async()=>await(await m(e)).cli.exchangeToken({code:r.code}),n=>new Error("Failed to exchange callback code for token",{cause:n.message}));if(i.failure)throw i.failure;await w(e,i.data.idToken,"","");let a=await s(async()=>await(await m(e)).cli.createSignInTicket(),n=>new Error("Failed to exchange ID token code for a sign-in ticket",{cause:n.message}));if(a.failure)throw a.failure;let o=await L(t.clerkPublishableKey),c=await s(()=>F(o,a.data.token),n=>new Error("Failed to create a new sign-in for this device",{cause:n.message}));if(c.failure)throw c.failure;let u=await s(async()=>await(await m(e)).cli.createJwt({sessionId:c.data.createdSessionId}),n=>new Error("Failed to create a session JWT",{cause:n.message}));if(u.failure)throw u.failure;let d=await s(()=>w(e,i.data.idToken,u.data,c.data.createdSessionId),n=>new Error("Failed to save your credentials to disk",{cause:n.message}));if(d.failure)throw d.failure}async function ye(){let e=await m(this),t=U(),r=await s(()=>e.cli.getConfig(),a=>a);if(r.failure)throw r.failure;T({authorizeUri:b.OAUTH_AUTHORIZE_URL,clientId:r.data.clientId,redirectUri:y,state:t});let i=await s(()=>I(async a=>{if(a.state!==t)throw new Error("Invalid state.");await $(this,r.data,a)}),a=>a);i.failure&&(f(h(p,{message:i.failure.message})),process.exit(1)),f(h(g,{message:"Success! You are now logged in."}))}async function xe(){let e=await s(()=>C(this),o=>o);e.failure&&(f(h(p,{message:"There was an issue reading your credentials. You are probably already logged out."})),process.exit(1));let t=await m(this),r=await s(()=>t.cli.getConfig(),o=>o);if(r.failure)throw r.failure;(await s(async()=>t.cli.revokeSession({sessionId:e.data.sessionId}),o=>o)).failure&&f(h(z,{message:"There was an issue revoking your session. You are probably already logged out. Purging credentials file..."}));let a=await s(async()=>{await v(this),await E(this)},o=>o);if(a.failure)throw a.failure;f(h(g,{message:"Success! You are now logged out."}))}export{ye as login,xe as logout};
@@ -0,0 +1 @@
1
+ import{a as p,c as d,d as g}from"./chunk-PL5KWBVQ.js";import{a as s,b as l}from"./chunk-WT3YKOQJ.js";import{existsSync as F}from"fs";import{resolve as D}from"path";import m from"process";import{withResult as T}from"@byteslice/result";import{render as c}from"ink";import{Box as x,render as C,Text as I}from"ink";import y from"ink-text-input";import{useState as P}from"react";import{z as S}from"zod";import{jsx as i,jsxs as h}from"react/jsx-runtime";function v(t){let[r,o]=P(""),[e,a]=P(null);return h(x,{flexDirection:"column",children:[h(x,{children:[i(I,{children:"Enter project ID (UUID): "}),i(y,{value:r,onChange:n=>{a(null),o(n)},onSubmit:n=>{if(a(null),n.trim()===""){setImmediate(()=>t.onInput());return}let f=S.uuid().safeParse(n);if(!f.success){a("Invalid UUID. Please try again."),o("");return}setImmediate(()=>t.onInput(f.data))}})]}),e&&i(I,{color:"red",children:e})]})}async function w(){return new Promise(t=>{let r=C(i(v,{onInput:o=>{r.unmount(),t(o)}}))})}import{jsx as u}from"react/jsx-runtime";async function M(){let t=D(m.cwd(),p);F(t)&&(c(u(s,{message:`Configuration already exists at ${t}.`})),m.exit(1));let r=await w(),o=await T(async()=>{let e=d(r);await g(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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swirls/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Swirls command line application",
5
5
  "author": {
6
6
  "name": "Swirls",
@@ -21,18 +21,13 @@
21
21
  "dev": "op run --no-masking --env-file=.env.development -- tsup --watch",
22
22
  "prepublishOnly": "bun run build"
23
23
  },
24
- "devDependencies": {
24
+ "dependencies": {
25
25
  "@byteslice/result": "0.3.0",
26
26
  "@clerk/clerk-js": "5.109.2",
27
27
  "@orpc/client": "1.12.2",
28
28
  "@orpc/contract": "1.12.2",
29
29
  "@stricli/auto-complete": "1.2.4",
30
30
  "@stricli/core": "1.2.4",
31
- "@swirls/core": "0.0.1",
32
- "@swirls/sdk": "0.0.1",
33
- "@types/node": "24.10.0",
34
- "@types/react": "19.2.6",
35
- "dotenv": "16.4.7",
36
31
  "ink": "6.4.0",
37
32
  "ink-select-input": "6.2.0",
38
33
  "ink-spinner": "5.0.0",
@@ -40,10 +35,17 @@
40
35
  "jiti": "2.6.1",
41
36
  "open": "10.2.0",
42
37
  "react": "19.2.1",
43
- "tsup": "8.5.1",
44
- "typescript": "5.9.3",
45
38
  "zod": "4.3.5"
46
39
  },
40
+ "devDependencies": {
41
+ "@swirls/core": "0.0.1",
42
+ "@swirls/sdk": "0.0.1",
43
+ "@types/node": "24.10.0",
44
+ "@types/react": "19.2.6",
45
+ "dotenv": "16.4.7",
46
+ "tsup": "8.5.1",
47
+ "typescript": "5.9.3"
48
+ },
47
49
  "engines": {
48
50
  "node": ">=22"
49
51
  },