@sequenzy/cli 0.0.1 → 0.0.2
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/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -299,4 +299,4 @@ Read about how to prevent this error on https://github.com/vadimdemedes/ink/#isr
|
|
|
299
299
|
`;if(this.options.debug){if(C)this.fullStaticOutput+=Q;this.options.stdout.write(this.fullStaticOutput+A);return}if(OH){if(C)this.options.stdout.write(Q);this.lastOutput=A;return}if(C)this.fullStaticOutput+=Q;if(B>=this.options.stdout.rows){this.options.stdout.write($H.clearTerminal+this.fullStaticOutput+A),this.lastOutput=A;return}if(C)this.log.clear(),this.options.stdout.write(Q),this.log(A);if(!C&&A!==this.lastOutput)this.throttledLog(A);this.lastOutput=A};render(A){let B=mq.default.createElement(K6,{stdin:this.options.stdin,stdout:this.options.stdout,stderr:this.options.stderr,writeToStdout:this.writeToStdout,writeToStderr:this.writeToStderr,exitOnCtrlC:this.options.exitOnCtrlC,onExit:this.unmount},A);t1.updateContainer(B,this.container,null,hq)}writeToStdout(A){if(this.isUnmounted)return;if(this.options.debug){this.options.stdout.write(A+this.fullStaticOutput+this.lastOutput);return}if(OH){this.options.stdout.write(A);return}this.log.clear(),this.options.stdout.write(A),this.log(this.lastOutput)}writeToStderr(A){if(this.isUnmounted)return;if(this.options.debug){this.options.stderr.write(A),this.options.stdout.write(this.fullStaticOutput+this.lastOutput);return}if(OH){this.options.stderr.write(A);return}this.log.clear(),this.options.stderr.write(A),this.log(this.lastOutput)}unmount(A){if(this.isUnmounted)return;if(this.calculateLayout(),this.onRender(),this.unsubscribeExit(),typeof this.restoreConsole==="function")this.restoreConsole();if(typeof this.unsubscribeResize==="function")this.unsubscribeResize();if(OH)this.options.stdout.write(this.lastOutput+`
|
|
300
300
|
`);else if(!this.options.debug)this.log.done();if(this.isUnmounted=!0,t1.updateContainer(null,this.container,null,hq),Q3.delete(this.options.stdout),A instanceof Error)this.rejectExitPromise(A);else this.resolveExitPromise()}async waitUntilExit(){return this.exitPromise||=new Promise((A,B)=>{this.resolveExitPromise=A,this.rejectExitPromise=B}),this.exitPromise}clear(){if(!OH&&!this.options.debug)this.log.clear()}patchConsole(){if(this.options.debug)return;this.restoreConsole=a5((A,B)=>{if(A==="stdout")this.writeToStdout(B);if(A==="stderr"){if(!B.startsWith("The above error occurred"))this.writeToStderr(B)}})}}var Ax=(A,B)=>{let Q={stdout:Y6.stdout,stdin:Y6.stdin,stderr:Y6.stderr,debug:!1,exitOnCtrlC:!0,patchConsole:!0,...Bx(B)},C=Ix(Q.stdout,()=>new M6(Q));return C.render(A),{rerender:C.render,unmount(){C.unmount()},waitUntilExit:C.waitUntilExit,cleanup:()=>Q3.delete(Q.stdout),clear:C.clear}},eg=Ax,Bx=(A={})=>{if(A instanceof ev)return{stdout:A,stdin:Y6.stdin};return A},Ix=(A,B)=>{let Q=Q3.get(A);if(!Q)Q=B(),Q3.set(A,Q);return Q};var N6=cB(kQ(),1);var Qx=cB(kQ(),1);var Ex=cB(kQ(),1);var Cx=cB(kQ(),1);var Gx=cB(kQ(),1);var Dx={OP:"f1",OQ:"f2",OR:"f3",OS:"f4","[11~":"f1","[12~":"f2","[13~":"f3","[14~":"f4","[[A":"f1","[[B":"f2","[[C":"f3","[[D":"f4","[[E":"f5","[15~":"f5","[17~":"f6","[18~":"f7","[19~":"f8","[20~":"f9","[21~":"f10","[23~":"f11","[24~":"f12","[A":"up","[B":"down","[C":"right","[D":"left","[E":"clear","[F":"end","[H":"home",OA:"up",OB:"down",OC:"right",OD:"left",OE:"clear",OF:"end",OH:"home","[1~":"home","[2~":"insert","[3~":"delete","[4~":"end","[5~":"pageup","[6~":"pagedown","[[5~":"pageup","[[6~":"pagedown","[7~":"home","[8~":"end","[a":"up","[b":"down","[c":"right","[d":"left","[e":"clear","[2$":"insert","[3$":"delete","[5$":"pageup","[6$":"pagedown","[7$":"home","[8$":"end",Oa:"up",Ob:"down",Oc:"right",Od:"left",Oe:"clear","[2^":"insert","[3^":"delete","[5^":"pageup","[6^":"pagedown","[7^":"home","[8^":"end","[Z":"tab"},gx=[...Object.values(Dx),"backspace"];var Fx=cB(kQ(),1);var Hx=cB(kQ(),1);var Jx=cB(kQ(),1);var Rx=cB(kQ(),1);var dN=cB(kQ(),1);var Ux=cB(kQ(),1);var E3=cB(kQ(),1);var rq=cB(nq(),1);function Kx({type:A="dots"}){let[B,Q]=E3.useState(0),C=rq.default[A];return E3.useEffect(()=>{let g=setInterval(()=>{Q((H)=>{return H===C.frames.length-1?0:H+1})},C.interval);return()=>{clearInterval(g)}},[C]),E3.default.createElement(XB,null,C.frames[B])}var AF=Kx;import It from"node:os";import I9 from"node:process";import{Buffer as DW}from"node:buffer";import gW from"node:path";import{fileURLToPath as hx}from"node:url";import{promisify as mx}from"node:util";import FW from"node:child_process";import lx,{constants as ix}from"node:fs/promises";import tq from"node:process";import eq,{constants as qx}from"node:fs/promises";import oq from"node:process";import Lx from"node:os";import Xx from"node:fs";import Nx from"node:fs";import aq from"node:fs";var pN;function Mx(){try{return aq.statSync("/.dockerenv"),!0}catch{return!1}}function Yx(){try{return aq.readFileSync("/proc/self/cgroup","utf8").includes("docker")}catch{return!1}}function nN(){if(pN===void 0)pN=Mx()||Yx();return pN}var rN,Zx=()=>{try{return Nx.statSync("/run/.containerenv"),!0}catch{return!1}};function C3(){if(rN===void 0)rN=Zx()||nN();return rN}var sq=()=>{if(oq.platform!=="linux")return!1;if(Lx.release().toLowerCase().includes("microsoft")){if(C3())return!1;return!0}try{return Xx.readFileSync("/proc/version","utf8").toLowerCase().includes("microsoft")?!C3():!1}catch{return!1}},G8=oq.env.__IS_WSL_TEST__?sq:sq();var Wx=(()=>{let B;return async function(){if(B)return B;let Q="/etc/wsl.conf",C=!1;try{await eq.access(Q,qx.F_OK),C=!0}catch{}if(!C)return"/mnt/";let g=await eq.readFile(Q,{encoding:"utf8"}),H=/(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(g);if(!H)return"/mnt/";return B=H.groups.mountPoint.trim(),B=B.endsWith("/")?B:`${B}/`,B}})(),zx=async()=>{return`${await Wx()}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`},aN=async()=>{if(G8)return zx();return`${tq.env.SYSTEMROOT||tq.env.windir||String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`};function H8(A,B,Q){let C=(g)=>Object.defineProperty(A,B,{value:g,enumerable:!0,writable:!0});return Object.defineProperty(A,B,{configurable:!0,enumerable:!0,get(){let g=Q();return C(g),g},set(g){C(g)}}),A}import{promisify as _x}from"node:util";import A9 from"node:process";import{execFile as vx}from"node:child_process";import{promisify as Sx}from"node:util";import $x from"node:process";import{execFile as Ox}from"node:child_process";var Vx=Sx(Ox);async function sN(){if($x.platform!=="darwin")throw Error("macOS only");let{stdout:A}=await Vx("defaults",["read","com.apple.LaunchServices/com.apple.launchservices.secure","LSHandlers"]),Q=/LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(A)?.groups.id??"com.apple.Safari";if(Q==="com.apple.safari")return"com.apple.Safari";return Q}import ux from"node:process";import{promisify as jx}from"node:util";import{execFile as Px,execFileSync as fCA}from"node:child_process";var Tx=jx(Px);async function AW(A,{humanReadableOutput:B=!0,signal:Q}={}){if(ux.platform!=="darwin")throw Error("macOS only");let C=B?[]:["-ss"],g={};if(Q)g.signal=Q;let{stdout:H}=await Tx("osascript",["-e",A,C],g);return H.trim()}async function oN(A){return AW(`tell application "Finder" to set app_path to application file id "${A}" as string
|
|
301
301
|
tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`)}import{promisify as kx}from"node:util";import{execFile as yx}from"node:child_process";var fx=kx(yx),BW={MSEdgeHTM:{name:"Edge",id:"com.microsoft.edge"},MSEdgeBHTML:{name:"Edge Beta",id:"com.microsoft.edge.beta"},MSEdgeDHTML:{name:"Edge Dev",id:"com.microsoft.edge.dev"},AppXq0fevzme2pys62n3e0fbqa7peapykr8v:{name:"Edge",id:"com.microsoft.edge.old"},ChromeHTML:{name:"Chrome",id:"com.google.chrome"},ChromeBHTML:{name:"Chrome Beta",id:"com.google.chrome.beta"},ChromeDHTML:{name:"Chrome Dev",id:"com.google.chrome.dev"},ChromiumHTM:{name:"Chromium",id:"org.chromium.Chromium"},BraveHTML:{name:"Brave",id:"com.brave.Browser"},BraveBHTML:{name:"Brave Beta",id:"com.brave.Browser.beta"},BraveDHTML:{name:"Brave Dev",id:"com.brave.Browser.dev"},BraveSSHTM:{name:"Brave Nightly",id:"com.brave.Browser.nightly"},FirefoxURL:{name:"Firefox",id:"org.mozilla.firefox"},OperaStable:{name:"Opera",id:"com.operasoftware.Opera"},VivaldiHTM:{name:"Vivaldi",id:"com.vivaldi.Vivaldi"},"IE.HTTP":{name:"Internet Explorer",id:"com.microsoft.ie"}},mCA=new Map(Object.entries(BW));class tN extends Error{}async function eN(A=fx){let{stdout:B}=await A("reg",["QUERY"," HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice","/v","ProgId"]),Q=/ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(B);if(!Q)throw new tN(`Cannot find Windows browser in stdout: ${JSON.stringify(B)}`);let{id:C}=Q.groups,g=BW[C];if(!g)throw new tN(`Unknown browser ID: ${C}`);return g}var xx=_x(vx),bx=(A)=>A.toLowerCase().replaceAll(/(?:^|\s|-)\S/g,(B)=>B.toUpperCase());async function B9(){if(A9.platform==="darwin"){let A=await sN();return{name:await oN(A),id:A}}if(A9.platform==="linux"){let{stdout:A}=await xx("xdg-mime",["query","default","x-scheme-handler/http"]),B=A.trim();return{name:bx(B.replace(/.desktop$/,"").replace("-"," ")),id:B}}if(A9.platform==="win32")return eN();throw Error("Only macOS, Linux, and Windows are supported")}var cx=mx(FW.execFile),Q9=gW.dirname(hx(import.meta.url)),IW=gW.join(Q9,"xdg-open"),{platform:D3,arch:QW}=I9;async function dx(){let A=await aN(),B=String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`,Q=DW.from(B,"utf16le").toString("base64"),{stdout:C}=await cx(A,["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-EncodedCommand",Q],{encoding:"utf8"}),g=C.trim(),H={ChromeHTML:"com.google.chrome",BraveHTML:"com.brave.Browser",MSEdgeHTM:"com.microsoft.edge",FirefoxURL:"org.mozilla.firefox"};return H[g]?{id:H[g]}:{}}var EW=async(A,B)=>{let Q;for(let C of A)try{return await B(C)}catch(g){Q=g}throw Q},L6=async(A)=>{if(A={wait:!1,background:!1,newInstance:!1,allowNonzeroExitCode:!1,...A},Array.isArray(A.app))return EW(A.app,(w)=>L6({...A,app:w}));let{name:B,arguments:Q=[]}=A.app??{};if(Q=[...Q],Array.isArray(B))return EW(B,(w)=>L6({...A,app:{name:w,arguments:Q}}));if(B==="browser"||B==="browserPrivate"){let w={"com.google.chrome":"chrome","google-chrome.desktop":"chrome","com.brave.Browser":"brave","org.mozilla.firefox":"firefox","firefox.desktop":"firefox","com.microsoft.msedge":"edge","com.microsoft.edge":"edge","com.microsoft.edgemac":"edge","microsoft-edge.desktop":"edge"},N={chrome:"--incognito",brave:"--incognito",firefox:"--private-window",edge:"--inPrivate"},L=G8?await dx():await B9();if(L.id in w){let u=w[L.id];if(B==="browserPrivate")Q.push(N[u]);return L6({...A,app:{name:vH[u],arguments:Q}})}throw Error(`${L.name} is not supported as a default browser`)}let C,g=[],H={};if(D3==="darwin"){if(C="open",A.wait)g.push("--wait-apps");if(A.background)g.push("--background");if(A.newInstance)g.push("--new");if(B)g.push("-a",B)}else if(D3==="win32"||G8&&!C3()&&!B){if(C=await aN(),g.push("-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-EncodedCommand"),!G8)H.windowsVerbatimArguments=!0;let w=["Start"];if(A.wait)w.push("-Wait");if(B){if(w.push(`"\`"${B}\`""`),A.target)Q.push(A.target)}else if(A.target)w.push(`"${A.target}"`);if(Q.length>0)Q=Q.map((N)=>`"\`"${N}\`""`),w.push("-ArgumentList",Q.join(","));A.target=DW.from(w.join(" "),"utf16le").toString("base64")}else{if(B)C=B;else{let w=!Q9||Q9==="/",N=!1;try{await lx.access(IW,ix.X_OK),N=!0}catch{}C=I9.versions.electron??(D3==="android"||w||!N)?"xdg-open":IW}if(Q.length>0)g.push(...Q);if(!A.wait)H.stdio="ignore",H.detached=!0}if(D3==="darwin"&&Q.length>0)g.push("--args",...Q);if(A.target)g.push(A.target);let M=FW.spawn(C,g,H);if(A.wait)return new Promise((w,N)=>{M.once("error",N),M.once("close",(L)=>{if(!A.allowNonzeroExitCode&&L>0){N(Error(`Exited with code ${L}`));return}w(M)})});return M.unref(),M},px=(A,B)=>{if(typeof A!=="string")throw TypeError("Expected a `target`");return L6({...B,target:A})};function CW(A){if(typeof A==="string"||Array.isArray(A))return A;let{[QW]:B}=A;if(!B)throw Error(`${QW} is not supported`);return B}function X6({[D3]:A},{wsl:B}){if(B&&G8)return CW(B);if(!A)throw Error(`${D3} is not supported`);return CW(A)}var vH={};H8(vH,"chrome",()=>X6({darwin:"google chrome",win32:"chrome",linux:["google-chrome","google-chrome-stable","chromium"]},{wsl:{ia32:"/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",x64:["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe","/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]}}));H8(vH,"brave",()=>X6({darwin:"brave browser",win32:"brave",linux:["brave-browser","brave"]},{wsl:{ia32:"/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",x64:["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe","/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]}}));H8(vH,"firefox",()=>X6({darwin:"firefox",win32:String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,linux:"firefox"},{wsl:"/mnt/c/Program Files/Mozilla Firefox/firefox.exe"}));H8(vH,"edge",()=>X6({darwin:"microsoft edge",win32:"msedge",linux:["microsoft-edge","microsoft-edge-dev"]},{wsl:"/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"}));H8(vH,"browser",()=>"browser");H8(vH,"browserPrivate",()=>"browserPrivate");var GW=px;var Xg=cB(kQ(),1);import{isDeepStrictEqual as so}from"node:util";import bj from"node:process";import rH from"node:fs";import hj from"node:path";import X4 from"node:crypto";import oo from"node:assert";var xH=(A)=>{let B=typeof A;return A!==null&&(B==="object"||B==="function")};var E9=new Set(["__proto__","prototype","constructor"]),nx=new Set("0123456789");function q6(A){let B=[],Q="",C="start",g=!1;for(let H of A)switch(H){case"\\":{if(C==="index")throw Error("Invalid character in an index");if(C==="indexEnd")throw Error("Invalid character after an index");if(g)Q+=H;C="property",g=!g;break}case".":{if(C==="index")throw Error("Invalid character in an index");if(C==="indexEnd"){C="property";break}if(g){g=!1,Q+=H;break}if(E9.has(Q))return[];B.push(Q),Q="",C="property";break}case"[":{if(C==="index")throw Error("Invalid character in an index");if(C==="indexEnd"){C="index";break}if(g){g=!1,Q+=H;break}if(C==="property"){if(E9.has(Q))return[];B.push(Q),Q=""}C="index";break}case"]":{if(C==="index"){B.push(Number.parseInt(Q,10)),Q="",C="indexEnd";break}if(C==="indexEnd")throw Error("Invalid character after an index")}default:{if(C==="index"&&!nx.has(H))throw Error("Invalid character in an index");if(C==="indexEnd")throw Error("Invalid character after an index");if(C==="start")C="property";if(g)g=!1,Q+="\\";Q+=H}}if(g)Q+="\\";switch(C){case"property":{if(E9.has(Q))return[];B.push(Q);break}case"index":throw Error("Index was not closed");case"start":{B.push("");break}}return B}function C9(A,B){if(typeof B!=="number"&&Array.isArray(A)){let Q=Number.parseInt(B,10);return Number.isInteger(Q)&&A[Q]===A[B]}return!1}function HW(A,B){if(C9(A,B))throw Error("Cannot use string index")}function JW(A,B,Q){if(!xH(A)||typeof B!=="string")return Q===void 0?A:Q;let C=q6(B);if(C.length===0)return Q;for(let g=0;g<C.length;g++){let H=C[g];if(C9(A,H))A=g===C.length-1?void 0:null;else A=A[H];if(A===void 0||A===null){if(g!==C.length-1)return Q;break}}return A===void 0?Q:A}function D9(A,B,Q){if(!xH(A)||typeof B!=="string")return A;let C=A,g=q6(B);for(let H=0;H<g.length;H++){let M=g[H];if(HW(A,M),H===g.length-1)A[M]=Q;else if(!xH(A[M]))A[M]=typeof g[H+1]==="number"?[]:{};A=A[M]}return C}function RW(A,B){if(!xH(A)||typeof B!=="string")return!1;let Q=q6(B);for(let C=0;C<Q.length;C++){let g=Q[C];if(HW(A,g),C===Q.length-1)return delete A[g],!0;if(A=A[g],!xH(A))return!1}}function UW(A,B){if(!xH(A)||typeof B!=="string")return!1;let Q=q6(B);if(Q.length===0)return!1;for(let C of Q){if(!xH(A)||!(C in A)||C9(A,C))return!1;A=A[C]}return!0}import qE from"node:path";import wW from"node:os";import g9 from"node:process";var J8=wW.homedir(),F9=wW.tmpdir(),{env:g3}=g9,rx=(A)=>{let B=qE.join(J8,"Library");return{data:qE.join(B,"Application Support",A),config:qE.join(B,"Preferences",A),cache:qE.join(B,"Caches",A),log:qE.join(B,"Logs",A),temp:qE.join(F9,A)}},ax=(A)=>{let B=g3.APPDATA||qE.join(J8,"AppData","Roaming"),Q=g3.LOCALAPPDATA||qE.join(J8,"AppData","Local");return{data:qE.join(Q,A,"Data"),config:qE.join(B,A,"Config"),cache:qE.join(Q,A,"Cache"),log:qE.join(Q,A,"Log"),temp:qE.join(F9,A)}},sx=(A)=>{let B=qE.basename(J8);return{data:qE.join(g3.XDG_DATA_HOME||qE.join(J8,".local","share"),A),config:qE.join(g3.XDG_CONFIG_HOME||qE.join(J8,".config"),A),cache:qE.join(g3.XDG_CACHE_HOME||qE.join(J8,".cache"),A),log:qE.join(g3.XDG_STATE_HOME||qE.join(J8,".local","state"),A),temp:qE.join(F9,B,A)}};function G9(A,{suffix:B="nodejs"}={}){if(typeof A!=="string")throw TypeError(`Expected a string, got ${typeof A}`);if(B)A+=`-${B}`;if(g9.platform==="darwin")return rx(A);if(g9.platform==="win32")return ax(A);return sx(A)}import Eb from"node:path";import GQ from"node:fs";import{promisify as BD}from"node:util";var ox=(A,B)=>{let{onError:Q}=B;return function(...g){return A.apply(void 0,g).catch(Q)}},BF=ox;var tx=(A,B)=>{let{onError:Q}=B;return function(...g){try{return A.apply(void 0,g)}catch(H){return Q(H)}}},Ug=tx;var KW=250;var ex=(A,B)=>{let{isRetriable:Q}=B;return function(g){let{timeout:H}=g,M=g.interval??KW,w=Date.now()+H;return function N(...L){return A.apply(void 0,L).catch((u)=>{if(!Q(u))throw u;if(Date.now()>=w)throw u;let j=Math.round(M*Math.random());if(j>0)return new Promise((O)=>setTimeout(O,j)).then(()=>N.apply(void 0,L));else return N.apply(void 0,L)})}}},IF=ex;var Ab=(A,B)=>{let{isRetriable:Q}=B;return function(g){let{timeout:H}=g,M=Date.now()+H;return function(...N){while(!0)try{return A.apply(void 0,N)}catch(L){if(!Q(L))throw L;if(Date.now()>=M)throw L;continue}}}},QF=Ab;import YW from"node:process";var hU={isChangeErrorOk:(A)=>{if(!hU.isNodeError(A))return!1;let{code:B}=A;if(B==="ENOSYS")return!0;if(!MW&&(B==="EINVAL"||B==="EPERM"))return!0;return!1},isNodeError:(A)=>{return A instanceof Error},isRetriableError:(A)=>{if(!hU.isNodeError(A))return!1;let{code:B}=A;if(B==="EMFILE"||B==="ENFILE"||B==="EAGAIN"||B==="EBUSY"||B==="EACCESS"||B==="EACCES"||B==="EACCS"||B==="EPERM")return!0;return!1},onChangeError:(A)=>{if(!hU.isNodeError(A))throw A;if(hU.isChangeErrorOk(A))return;throw A}},H9=hU;var mU={onError:H9.onChangeError},xD={onError:()=>{return}},MW=YW.getuid?!YW.getuid():!1,yC={isRetriable:H9.isRetriableError};var Bb={attempt:{chmod:BF(BD(GQ.chmod),mU),chown:BF(BD(GQ.chown),mU),close:BF(BD(GQ.close),xD),fsync:BF(BD(GQ.fsync),xD),mkdir:BF(BD(GQ.mkdir),xD),realpath:BF(BD(GQ.realpath),xD),stat:BF(BD(GQ.stat),xD),unlink:BF(BD(GQ.unlink),xD),chmodSync:Ug(GQ.chmodSync,mU),chownSync:Ug(GQ.chownSync,mU),closeSync:Ug(GQ.closeSync,xD),existsSync:Ug(GQ.existsSync,xD),fsyncSync:Ug(GQ.fsync,xD),mkdirSync:Ug(GQ.mkdirSync,xD),realpathSync:Ug(GQ.realpathSync,xD),statSync:Ug(GQ.statSync,xD),unlinkSync:Ug(GQ.unlinkSync,xD)},retry:{close:IF(BD(GQ.close),yC),fsync:IF(BD(GQ.fsync),yC),open:IF(BD(GQ.open),yC),readFile:IF(BD(GQ.readFile),yC),rename:IF(BD(GQ.rename),yC),stat:IF(BD(GQ.stat),yC),write:IF(BD(GQ.write),yC),writeFile:IF(BD(GQ.writeFile),yC),closeSync:QF(GQ.closeSync,yC),fsyncSync:QF(GQ.fsyncSync,yC),openSync:QF(GQ.openSync,yC),readFileSync:QF(GQ.readFileSync,yC),renameSync:QF(GQ.renameSync,yC),statSync:QF(GQ.statSync,yC),writeSync:QF(GQ.writeSync,yC),writeFileSync:QF(GQ.writeFileSync,yC)}},qC=Bb;import bH from"node:process";var NW="utf8",J9=438,ZW=511;var LW={},XW=bH.geteuid?bH.geteuid():-1,qW=bH.getegid?bH.getegid():-1;var WW=1000,zW=!!bH.getuid,_DA=bH.getuid?!bH.getuid():!1,R9=128;var SW=(A)=>{return A instanceof Error&&"code"in A};var U9=(A)=>{return typeof A==="string"},W6=(A)=>{return A===void 0};import Qb from"node:path";import F3 from"node:process";import $W from"node:process";var OW=$W.platform==="linux",z6=$W.platform==="win32";var w9=["SIGHUP","SIGINT","SIGTERM"];if(!z6)w9.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");if(OW)w9.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");var VW=w9;class uW{constructor(){this.callbacks=new Set,this.exited=!1,this.exit=(A)=>{if(this.exited)return;this.exited=!0;for(let B of this.callbacks)B();if(A)if(z6&&(A!=="SIGINT"&&A!=="SIGTERM"&&A!=="SIGKILL"))F3.kill(F3.pid,"SIGTERM");else F3.kill(F3.pid,A)},this.hook=()=>{F3.once("exit",()=>this.exit());for(let A of VW)try{F3.once(A,()=>this.exit(A))}catch{}},this.register=(A)=>{return this.callbacks.add(A),()=>{this.callbacks.delete(A)}},this.hook()}}var jW=new uW;var Ib=jW.register,PW=Ib;var J0={store:{},create:(A)=>{let B=`000000${Math.floor(Math.random()*16777215).toString(16)}`.slice(-6),Q=Date.now().toString().slice(-10),C="tmp-",g=`.tmp-${Q}${B}`;return`${A}${g}`},get:(A,B,Q=!0)=>{let C=J0.truncate(B(A));if(C in J0.store)return J0.get(A,B,Q);return J0.store[C]=Q,[C,()=>delete J0.store[C]]},purge:(A)=>{if(!J0.store[A])return;delete J0.store[A],qC.attempt.unlink(A)},purgeSync:(A)=>{if(!J0.store[A])return;delete J0.store[A],qC.attempt.unlinkSync(A)},purgeSyncAll:()=>{for(let A in J0.store)J0.purgeSync(A)},truncate:(A)=>{let B=Qb.basename(A);if(B.length<=R9)return A;let Q=/^(\.?)(.*?)((?:\.[^.]+)?(?:\.tmp-\d{10}[a-f0-9]{6})?)$/.exec(B);if(!Q)return A;let C=B.length-R9;return`${A.slice(0,-B.length)}${Q[1]}${Q[2].slice(0,-C)}${Q[3]}`}};PW(J0.purgeSyncAll);var lU=J0;function K9(A,B,Q=LW){if(U9(Q))return K9(A,B,{encoding:Q});let g={timeout:Q.timeout??WW},H=null,M=null,w=null;try{let N=qC.attempt.realpathSync(A),L=!!N;A=N||A,[M,H]=lU.get(A,Q.tmpCreate||lU.create,Q.tmpPurge!==!1);let u=zW&&W6(Q.chown),j=W6(Q.mode);if(L&&(u||j)){let W=qC.attempt.statSync(A);if(W){if(Q={...Q},u)Q.chown={uid:W.uid,gid:W.gid};if(j)Q.mode=W.mode}}if(!L){let W=Eb.dirname(A);qC.attempt.mkdirSync(W,{mode:ZW,recursive:!0})}if(w=qC.retry.openSync(g)(M,"w",Q.mode||J9),Q.tmpCreated)Q.tmpCreated(M);if(U9(B))qC.retry.writeSync(g)(w,B,0,Q.encoding||NW);else if(!W6(B))qC.retry.writeSync(g)(w,B,0,B.length,0);if(Q.fsync!==!1)if(Q.fsyncWait!==!1)qC.retry.fsyncSync(g)(w);else qC.attempt.fsync(w);if(qC.retry.closeSync(g)(w),w=null,Q.chown&&(Q.chown.uid!==XW||Q.chown.gid!==qW))qC.attempt.chownSync(M,Q.chown.uid,Q.chown.gid);if(Q.mode&&Q.mode!==J9)qC.attempt.chmodSync(M,Q.mode);try{qC.retry.renameSync(g)(M,A)}catch(W){if(!SW(W))throw W;if(W.code!=="ENAMETOOLONG")throw W;qC.retry.renameSync(g)(M,lU.truncate(A))}H(),M=null}finally{if(w)qC.attempt.closeSync(w);if(M)lU.purge(M)}}var lj=cB(WV(),1),ij=cB(dV(),1);var lr=(A,B,Q,C)=>{if(Q==="length"||Q==="prototype")return;if(Q==="arguments"||Q==="caller")return;let g=Object.getOwnPropertyDescriptor(A,Q),H=Object.getOwnPropertyDescriptor(B,Q);if(!ir(g,H)&&C)return;Object.defineProperty(A,Q,H)},ir=function(A,B){return A===void 0||A.configurable||A.writable===B.writable&&A.enumerable===B.enumerable&&A.configurable===B.configurable&&(A.writable||A.value===B.value)},cr=(A,B)=>{let Q=Object.getPrototypeOf(B);if(Q===Object.getPrototypeOf(A))return;Object.setPrototypeOf(A,Q)},dr=(A,B)=>`/* Wrapped ${A}*/
|
|
302
|
-
${B}`,pr=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),nr=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),rr=(A,B,Q)=>{let C=Q===""?"":`with ${Q.trim()}() `,g=dr.bind(null,C,B.toString());Object.defineProperty(g,"name",nr);let{writable:H,enumerable:M,configurable:w}=pr;Object.defineProperty(A,"toString",{value:g,writable:H,enumerable:M,configurable:w})};function jZ(A,B,{ignoreNonConfigurable:Q=!1}={}){let{name:C}=A;for(let g of Reflect.ownKeys(B))lr(A,B,g,Q);return cr(A,B),rr(A,B,C),A}var ar=(A,B={})=>{if(typeof A!=="function")throw TypeError(`Expected the first argument to be a function, got \`${typeof A}\``);let{wait:Q=0,maxWait:C=Number.POSITIVE_INFINITY,before:g=!1,after:H=!0}=B;if(Q<0||C<0)throw RangeError("`wait` and `maxWait` must not be negative.");if(!g&&!H)throw Error("Both `before` and `after` are false, function wouldn't be called.");let M,w,N,L=function(...u){let j=this,W=()=>{if(M=void 0,w)clearTimeout(w),w=void 0;if(H)N=A.apply(j,u)},O=()=>{if(w=void 0,M)clearTimeout(M),M=void 0;if(H)N=A.apply(j,u)},v=g&&!M;if(clearTimeout(M),M=setTimeout(W,Q),C>0&&C!==Number.POSITIVE_INFINITY&&!w)w=setTimeout(O,C);if(v)N=A.apply(j,u);return N};return jZ(L,A),L.cancel=()=>{if(M)clearTimeout(M),M=void 0;if(w)clearTimeout(w),w=void 0},L},PZ=ar;var aH=cB(fj(),1);var lo=Object.prototype.toString;function vj(A,B,Q){if(!A)return!1;if(A.constructor===B)return!0;return lo.call(A)===Q}function xj(A){return vj(A,Uint8Array,"[object Uint8Array]")}function io(A){return vj(A,ArrayBuffer,"[object ArrayBuffer]")}function co(A){return xj(A)||io(A)}function po(A){if(!xj(A))throw TypeError(`Expected \`Uint8Array\`, got \`${typeof A}\``)}function no(A){if(!co(A))throw TypeError(`Expected \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof A}\``)}function nZ(A,B){if(A.length===0)return new Uint8Array(0);B??=A.reduce((g,H)=>g+H.length,0);let Q=new Uint8Array(B),C=0;for(let g of A)po(g),Q.set(g,C),C+=g.length;return Q}var _j={utf8:new globalThis.TextDecoder("utf8")};function rZ(A,B="utf8"){return no(A),_j[B]??=new globalThis.TextDecoder(B),_j[B].decode(A)}function ro(A){if(typeof A!=="string")throw TypeError(`Expected \`string\`, got \`${typeof A}\``)}var ao=new globalThis.TextEncoder;function q2(A){return ro(A),ao.encode(A)}var WGA=Array.from({length:256},(A,B)=>B.toString(16).padStart(2,"0"));var to=ij.default.default,mj="aes-256-cbc",z3=()=>Object.create(null),eo=(A)=>A!==void 0&&A!==null,At=(A,B)=>{let Q=new Set(["undefined","symbol","function"]),C=typeof B;if(Q.has(C))throw TypeError(`Setting a value of type \`${C}\` for key \`${A}\` is not allowed as it's not supported by JSON`)},W2="__internal__",aZ=`${W2}.migrations.version`;class z2{path;events;#Q;#B;#A;#I={};constructor(A={}){let B={configName:"config",fileExtension:"json",projectSuffix:"nodejs",clearInvalidConfig:!1,accessPropertiesByDotNotation:!0,configFileMode:438,...A};if(!B.cwd){if(!B.projectName)throw Error("Please specify the `projectName` option.");B.cwd=G9(B.projectName,{suffix:B.projectSuffix}).config}if(this.#A=B,B.schema??B.ajvOptions??B.rootSchema){if(B.schema&&typeof B.schema!=="object")throw TypeError("The `schema` option must be an object.");let H=new lj.Ajv2020({allErrors:!0,useDefaults:!0,...B.ajvOptions});to(H);let M={...B.rootSchema,type:"object",properties:B.schema};this.#Q=H.compile(M);for(let[w,N]of Object.entries(B.schema??{}))if(N?.default)this.#I[w]=N.default}if(B.defaults)this.#I={...this.#I,...B.defaults};if(B.serialize)this._serialize=B.serialize;if(B.deserialize)this._deserialize=B.deserialize;this.events=new EventTarget,this.#B=B.encryptionKey;let Q=B.fileExtension?`.${B.fileExtension}`:"";this.path=hj.resolve(B.cwd,`${B.configName??"config"}${Q}`);let C=this.store,g=Object.assign(z3(),B.defaults,C);if(B.migrations){if(!B.projectVersion)throw Error("Please specify the `projectVersion` option.");this._migrate(B.migrations,B.projectVersion,B.beforeEachMigration)}this._validate(g);try{oo.deepEqual(C,g)}catch{this.store=g}if(B.watch)this._watch()}get(A,B){if(this.#A.accessPropertiesByDotNotation)return this._get(A,B);let{store:Q}=this;return A in Q?Q[A]:B}set(A,B){if(typeof A!=="string"&&typeof A!=="object")throw TypeError(`Expected \`key\` to be of type \`string\` or \`object\`, got ${typeof A}`);if(typeof A!=="object"&&B===void 0)throw TypeError("Use `delete()` to clear values");if(this._containsReservedKey(A))throw TypeError(`Please don't use the ${W2} key, as it's used to manage this module internal operations.`);let{store:Q}=this,C=(g,H)=>{if(At(g,H),this.#A.accessPropertiesByDotNotation)D9(Q,g,H);else Q[g]=H};if(typeof A==="object"){let g=A;for(let[H,M]of Object.entries(g))C(H,M)}else C(A,B);this.store=Q}has(A){if(this.#A.accessPropertiesByDotNotation)return UW(this.store,A);return A in this.store}reset(...A){for(let B of A)if(eo(this.#I[B]))this.set(B,this.#I[B])}delete(A){let{store:B}=this;if(this.#A.accessPropertiesByDotNotation)RW(B,A);else delete B[A];this.store=B}clear(){this.store=z3();for(let A of Object.keys(this.#I))this.reset(A)}onDidChange(A,B){if(typeof A!=="string")throw TypeError(`Expected \`key\` to be of type \`string\`, got ${typeof A}`);if(typeof B!=="function")throw TypeError(`Expected \`callback\` to be of type \`function\`, got ${typeof B}`);return this._handleChange(()=>this.get(A),B)}onDidAnyChange(A){if(typeof A!=="function")throw TypeError(`Expected \`callback\` to be of type \`function\`, got ${typeof A}`);return this._handleChange(()=>this.store,A)}get size(){return Object.keys(this.store).length}get store(){try{let A=rH.readFileSync(this.path,this.#B?null:"utf8"),B=this._encryptData(A),Q=this._deserialize(B);return this._validate(Q),Object.assign(z3(),Q)}catch(A){if(A?.code==="ENOENT")return this._ensureDirectory(),z3();if(this.#A.clearInvalidConfig&&A.name==="SyntaxError")return z3();throw A}}set store(A){this._ensureDirectory(),this._validate(A),this._write(A),this.events.dispatchEvent(new Event("change"))}*[Symbol.iterator](){for(let[A,B]of Object.entries(this.store))yield[A,B]}_encryptData(A){if(!this.#B)return typeof A==="string"?A:rZ(A);try{let B=A.slice(0,16),Q=X4.pbkdf2Sync(this.#B,B.toString(),1e4,32,"sha512"),C=X4.createDecipheriv(mj,Q,B),g=A.slice(17),H=typeof g==="string"?q2(g):g;return rZ(nZ([C.update(H),C.final()]))}catch{}return A.toString()}_handleChange(A,B){let Q=A(),C=()=>{let g=Q,H=A();if(so(H,g))return;Q=H,B.call(this,H,g)};return this.events.addEventListener("change",C),()=>{this.events.removeEventListener("change",C)}}_deserialize=(A)=>JSON.parse(A);_serialize=(A)=>JSON.stringify(A,void 0,"\t");_validate(A){if(!this.#Q)return;if(this.#Q(A)||!this.#Q.errors)return;let Q=this.#Q.errors.map(({instancePath:C,message:g=""})=>`\`${C.slice(1)}\` ${g}`);throw Error("Config schema violation: "+Q.join("; "))}_ensureDirectory(){rH.mkdirSync(hj.dirname(this.path),{recursive:!0})}_write(A){let B=this._serialize(A);if(this.#B){let Q=X4.randomBytes(16),C=X4.pbkdf2Sync(this.#B,Q.toString(),1e4,32,"sha512"),g=X4.createCipheriv(mj,C,Q);B=nZ([Q,q2(":"),g.update(q2(B)),g.final()])}if(bj.env.SNAP)rH.writeFileSync(this.path,B,{mode:this.#A.configFileMode});else try{K9(this.path,B,{mode:this.#A.configFileMode})}catch(Q){if(Q?.code==="EXDEV"){rH.writeFileSync(this.path,B,{mode:this.#A.configFileMode});return}throw Q}}_watch(){if(this._ensureDirectory(),!rH.existsSync(this.path))this._write(z3());if(bj.platform==="win32")rH.watch(this.path,{persistent:!1},PZ(()=>{this.events.dispatchEvent(new Event("change"))},{wait:100}));else rH.watchFile(this.path,{persistent:!1},PZ(()=>{this.events.dispatchEvent(new Event("change"))},{wait:5000}))}_migrate(A,B,Q){let C=this._get(aZ,"0.0.0"),g=Object.keys(A).filter((M)=>this._shouldPerformMigration(M,C,B)),H={...this.store};for(let M of g)try{if(Q)Q(this,{fromVersion:C,toVersion:M,finalVersion:B,versions:g});let w=A[M];w?.(this),this._set(aZ,M),C=M,H={...this.store}}catch(w){throw this.store=H,Error(`Something went wrong during the migration! Changes applied to the store until this failed migration will be restored. ${w}`)}if(this._isVersionInRangeFormat(C)||!aH.default.eq(C,B))this._set(aZ,B)}_containsReservedKey(A){if(typeof A==="object"){if(Object.keys(A)[0]===W2)return!0}if(typeof A!=="string")return!1;if(this.#A.accessPropertiesByDotNotation){if(A.startsWith(`${W2}.`))return!0;return!1}return!1}_isVersionInRangeFormat(A){return aH.default.clean(A)===null}_shouldPerformMigration(A,B,Q){if(this._isVersionInRangeFormat(A)){if(B!=="0.0.0"&&aH.default.satisfies(B,A))return!1;return aH.default.satisfies(Q,A)}if(aH.default.lte(A,B))return!1;if(aH.default.gt(A,Q))return!1;return!0}_get(A,B){return JW(this.store,A,B)}_set(A,B){let{store:Q}=this;D9(Q,A,B),this.store=Q}}var sZ="com.sequenzy.cli",oZ="api-key",q4=new z2({projectName:"sequenzy",schema:{userId:{type:"string"},userEmail:{type:"string"}}});async function tZ(){let A=process.env.SEQUENZY_API_KEY;if(A)return A;try{return await Bun.secrets.get({service:sZ,name:oZ})??void 0}catch{return}}async function cj(A){await Bun.secrets.set({service:sZ,name:oZ,value:A,allowUnrestrictedAccess:!1})}async function dj(){await Bun.secrets.delete({service:sZ,name:oZ})}async function l0(){return!!await tZ()}function pj(){return{userId:q4.get("userId"),userEmail:q4.get("userEmail")}}function nj(A){if(A.userId!==void 0)q4.set("userId",A.userId);if(A.userEmail!==void 0)q4.set("userEmail",A.userEmail)}function rj(){q4.clear()}var yQ=cB(DG(),1),aj=process.env.SEQUENZY_API_URL??"https://api.sequenzy.com",sj=process.env.SEQUENZY_APP_URL??"https://app.sequenzy.com";function Qt(){let[A,B]=Xg.useState("check"),[Q,C]=Xg.useState(""),[g,H]=Xg.useState(""),[M,w]=Xg.useState(5),[N,L]=Xg.useState(null),[u,j]=Xg.useState("");if(Xg.useEffect(()=>{if(A!=="check")return;l0().then((W)=>{if(W)j("Already logged in. Run `sequenzy logout` first to switch accounts."),B("error");else B("init")})},[A]),Xg.useEffect(()=>{if(A!=="init")return;let W=`${process.platform}-${It.hostname()}`;fetch(`${aj}/api/device-auth/initiate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceName:W,clientType:"cli"})}).then((O)=>O.json()).then((O)=>{if(!O.success||!O.data){j(O.error??"Failed to initiate auth"),B("error");return}C(O.data.userCode),H(O.data.deviceCode),w(O.data.pollInterval);let v=`${sj}/setup/auth?code=${O.data.userCode}`;GW(v),B("waiting")}).catch((O)=>{j(O.message),B("error")})},[A]),Xg.useEffect(()=>{if(A!=="waiting")return;let W=setInterval(()=>{fetch(`${aj}/api/device-auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:g})}).then((O)=>O.json()).then((O)=>{if(O.success&&O.data)clearInterval(W),L(O.data),cj(O.data.apiKey).then(()=>{nj({userId:O.data.userId,userEmail:O.data.userEmail}),B("success"),setTimeout(()=>process.exit(0),100)}).catch((v)=>{j(`Failed to save credentials: ${v.message}`),B("error"),setTimeout(()=>process.exit(1),100)});else if(O.error==="access_denied")clearInterval(W),j("Authorization denied"),B("error"),setTimeout(()=>process.exit(1),100);else if(O.error==="expired_token")clearInterval(W),j("Authorization expired. Please try again."),B("error"),setTimeout(()=>process.exit(1),100)}).catch(()=>{})},M*1000);return()=>clearInterval(W)},[A,g,M]),A==="check"||A==="init")return yQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:yQ.jsxDEV(XB,{children:[yQ.jsxDEV(XB,{color:"cyan",children:yQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this)," ","Initializing..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(A==="waiting")return yQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:[yQ.jsxDEV(DI,{marginBottom:1,children:yQ.jsxDEV(XB,{bold:!0,color:"green",children:"Sequenzy Login"},void 0,!1,void 0,this)},void 0,!1,void 0,this),yQ.jsxDEV(XB,{children:"Opening browser to authenticate..."},void 0,!1,void 0,this),yQ.jsxDEV(XB,{dimColor:!0,children:"If the browser doesn't open, visit:"},void 0,!1,void 0,this),yQ.jsxDEV(XB,{color:"cyan",children:[sj,"/setup/auth?code=",Q]},void 0,!0,void 0,this),yQ.jsxDEV(DI,{marginTop:1,children:yQ.jsxDEV(XB,{children:[yQ.jsxDEV(XB,{color:"yellow",children:yQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this)," ","Waiting for approval..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this),yQ.jsxDEV(DI,{marginTop:1,children:[yQ.jsxDEV(XB,{dimColor:!0,children:"Your code: "},void 0,!1,void 0,this),yQ.jsxDEV(XB,{bold:!0,color:"magenta",children:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(A==="success")return yQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:[yQ.jsxDEV(DI,{marginBottom:1,children:yQ.jsxDEV(XB,{color:"green",children:" Logged in successfully!"},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&yQ.jsxDEV(DI,{children:[yQ.jsxDEV(XB,{dimColor:!0,children:"User: "},void 0,!1,void 0,this),yQ.jsxDEV(XB,{children:N.userEmail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),yQ.jsxDEV(DI,{marginTop:1,children:yQ.jsxDEV(XB,{dimColor:!0,children:"Run `sequenzy --help` to see available commands."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(A==="error")return yQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:yQ.jsxDEV(XB,{color:"red",children:[" Error: ",u]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return null}function oj(){eg(yQ.jsxDEV(Qt,{},void 0,!1,void 0,this))}async function tj(){if(!await l0()){console.log("Not logged in.");return}await dj(),rj(),console.log("Logged out successfully.")}import{readFileSync as Ct}from"node:fs";var sH=cB(kQ(),1);var Et=process.env.SEQUENZY_API_URL??"https://api.sequenzy.com";class L8 extends Error{statusCode;constructor(A,B){super(A);this.statusCode=B;this.name="ApiError"}}async function qg(A,B,Q){let C=await tZ();if(!C)throw new L8("Not logged in. Run `sequenzy login` first.",401);let g=await fetch(`${Et}${B}`,{method:A,headers:{"Content-Type":"application/json",Authorization:`Bearer ${C}`},body:Q?JSON.stringify(Q):void 0});if(!g.ok){let H=await g.text();throw new L8(`API error: ${H}`,g.status)}return g.json()}var FF=cB(DG(),1);function Dt({email:A,options:B}){let[Q,C]=sH.useState(!0),[g,H]=sH.useState(""),[M,w]=sH.useState(!1);if(sH.useEffect(()=>{async function N(){try{let L={};for(let j of B.var??[]){let[W,O]=j.split("=");if(W&&O)L[W]=O}let u=B.html;if(B.htmlFile)u=Ct(B.htmlFile,"utf-8");if(!B.template&&!u)throw Error("Either --template or --html/--html-file is required");if(!B.template&&!B.subject)throw Error("--subject is required when using --html");await qg("POST","/api/v1/transactional/send",{to:A,templateId:B.template,subject:B.subject,html:u,variables:L}),w(!0)}catch(L){H(L instanceof Error?L.message:"Failed to send")}finally{C(!1)}}N()},[A,B]),sH.useEffect(()=>{if(!Q)setTimeout(()=>process.exit(g?1:0),100)},[Q,g]),Q)return FF.jsxDEV(DI,{padding:1,children:[FF.jsxDEV(XB,{color:"cyan",children:FF.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this),FF.jsxDEV(XB,{children:[" Sending email to ",A,"..."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(g)return FF.jsxDEV(DI,{padding:1,children:FF.jsxDEV(XB,{color:"red",children:[" ",g]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return FF.jsxDEV(DI,{padding:1,children:FF.jsxDEV(XB,{color:"green",children:[" Email sent to ",A]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}async function ej(A,B){if(!await l0())console.log("Not logged in. Run `sequenzy login` first."),process.exit(1);eg(FF.jsxDEV(Dt,{email:A,options:B},void 0,!1,void 0,this))}var oH=cB(kQ(),1);var CQ=cB(DG(),1);function gt({options:A}){let[B,Q]=oH.useState(!0),[C,g]=oH.useState(""),[H,M]=oH.useState(null);if(oH.useEffect(()=>{async function L(){try{let u;if(A.campaign)u=await qg("GET",`/api/v1/campaigns/${A.campaign}/stats`);else if(A.sequence)u=await qg("GET",`/api/v1/sequences/${A.sequence}/stats`);else u=await qg("GET",`/api/v1/stats?period=${A.period??"7d"}`);M(u)}catch(u){g(u instanceof L8?u.message:"Failed to fetch stats")}finally{Q(!1)}}L()},[A]),oH.useEffect(()=>{if(!B)setTimeout(()=>process.exit(C?1:0),100)},[B,C]),B)return CQ.jsxDEV(DI,{padding:1,children:[CQ.jsxDEV(XB,{color:"cyan",children:CQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:" Loading stats..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(C)return CQ.jsxDEV(DI,{padding:1,children:CQ.jsxDEV(XB,{color:"red",children:[" ",C]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(!H)return CQ.jsxDEV(DI,{padding:1,children:CQ.jsxDEV(XB,{dimColor:!0,children:"No stats available"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let w=A.period??"7d",N=A.campaign?"Campaign Stats":A.sequence?"Sequence Stats":`Stats (${w})`;return CQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:[CQ.jsxDEV(DI,{marginBottom:1,children:CQ.jsxDEV(XB,{bold:!0,color:"green",children:N},void 0,!1,void 0,this)},void 0,!1,void 0,this),CQ.jsxDEV(DI,{flexDirection:"column",children:[CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Sent: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.sent.toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Delivered: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.delivered.toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Opened: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.opened.toLocaleString()},void 0,!1,void 0,this),CQ.jsxDEV(XB,{dimColor:!0,children:[" (",(H.openRate*100).toFixed(1),"%)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Clicked: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.clicked.toLocaleString()},void 0,!1,void 0,this),CQ.jsxDEV(XB,{dimColor:!0,children:[" (",(H.clickRate*100).toFixed(1),"%)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Bounced: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{color:H.bounced>0?"yellow":void 0,children:H.bounced.toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Unsubscribed: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.unsubscribed.toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}async function AP(A){if(!await l0())console.log("Not logged in. Run `sequenzy login` first."),process.exit(1);eg(CQ.jsxDEV(gt,{options:A},void 0,!1,void 0,this))}var i0=cB(kQ(),1);var dQ=cB(DG(),1);function Ft({options:A}){let[B,Q]=i0.useState(!0),[C,g]=i0.useState(""),[H,M]=i0.useState([]);if(i0.useEffect(()=>{async function w(){try{let N=new URLSearchParams;if(A.segment)N.set("segmentId",A.segment);if(A.tag)N.set("tags",A.tag);if(A.limit)N.set("limit",A.limit);let L=await qg("GET",`/api/v1/subscribers?${N}`);M(L.subscribers??[])}catch(N){g(N instanceof L8?N.message:"Failed to fetch")}finally{Q(!1)}}w()},[A]),i0.useEffect(()=>{if(!B)setTimeout(()=>process.exit(C?1:0),100)},[B,C]),B)return dQ.jsxDEV(DI,{padding:1,children:[dQ.jsxDEV(XB,{color:"cyan",children:dQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this),dQ.jsxDEV(XB,{children:" Loading subscribers..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(C)return dQ.jsxDEV(DI,{padding:1,children:dQ.jsxDEV(XB,{color:"red",children:[" ",C]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(H.length===0)return dQ.jsxDEV(DI,{padding:1,children:dQ.jsxDEV(XB,{dimColor:!0,children:"No subscribers found"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return dQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:[dQ.jsxDEV(DI,{marginBottom:1,children:dQ.jsxDEV(XB,{bold:!0,children:["Subscribers (",H.length,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H.map((w)=>dQ.jsxDEV(DI,{children:[dQ.jsxDEV(XB,{children:w.email},void 0,!1,void 0,this),dQ.jsxDEV(XB,{dimColor:!0,children:[" [",w.status,"]"]},void 0,!0,void 0,this),w.tags.length>0&&dQ.jsxDEV(XB,{color:"cyan",children:[" ",w.tags.join(", ")]},void 0,!0,void 0,this)]},w.id,!0,void 0,this))]},void 0,!0,void 0,this)}function Gt({action:A,options:B}){let[Q,C]=i0.useState(!0),[g,H]=i0.useState(""),[M,w]=i0.useState("");if(i0.useEffect(()=>{async function N(){try{switch(A){case"add":{let L={};for(let u of B.attr??[]){let[j,W]=u.split("=");if(j&&W)L[j]=W}await qg("POST","/api/v1/subscribers",{email:B.email,tags:B.tag?[B.tag]:[],attributes:L}),w(`Added subscriber: ${B.email}`);break}case"get":{let L=await qg("GET",`/api/v1/subscribers/${B.email}`);w(JSON.stringify(L,null,2));break}case"remove":{await qg("DELETE",`/api/v1/subscribers/${B.email}`,{hardDelete:B.hard}),w(B.hard?`Deleted subscriber: ${B.email}`:`Unsubscribed: ${B.email}`);break}}}catch(L){H(L instanceof L8?L.message:"Failed")}finally{C(!1)}}N()},[A,B]),i0.useEffect(()=>{if(!Q)setTimeout(()=>process.exit(g?1:0),100)},[Q,g]),Q)return dQ.jsxDEV(DI,{padding:1,children:[dQ.jsxDEV(XB,{color:"cyan",children:dQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this),dQ.jsxDEV(XB,{children:" Processing..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(g)return dQ.jsxDEV(DI,{padding:1,children:dQ.jsxDEV(XB,{color:"red",children:[" ",g]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return dQ.jsxDEV(DI,{padding:1,children:dQ.jsxDEV(XB,{color:"green",children:[" ",M]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}async function W4(A,B){if(!await l0())console.log("Not logged in. Run `sequenzy login` first."),process.exit(1);if(A==="list")eg(dQ.jsxDEV(Ft,{options:B},void 0,!1,void 0,this));else eg(dQ.jsxDEV(Gt,{action:A,options:B},void 0,!1,void 0,this))}async function BP(){if(!await l0()){console.log("Not logged in. Run `sequenzy login` to authenticate.");return}let A=pj();console.log(`Email: ${A.userEmail??"Unknown"}`),console.log(`User ID: ${A.userId??"Unknown"}`),console.log(""),console.log("Your API key can access all companies you belong to."),console.log("Use `sequenzy account` to see available companies.")}var _C=new v5;_C.name("sequenzy").description("Sequenzy CLI - Email marketing from the terminal").version("0.0.1");_C.command("login").description("Log in to your Sequenzy account").action(oj);_C.command("logout").description("Log out of your Sequenzy account").action(tj);_C.command("whoami").description("Show current logged in user").action(BP);_C.command("stats").description("Show email statistics").option("-p, --period <period>","Time period (7d, 30d, 90d)","7d").option("--campaign <id>","Get stats for specific campaign").option("--sequence <id>","Get stats for specific sequence").action(AP);var S2=_C.command("subscribers").description("Manage subscribers");S2.command("list").description("List subscribers").option("-s, --segment <id>","Filter by segment").option("-t, --tag <tag>","Filter by tag").option("-l, --limit <number>","Limit results","50").action((A)=>W4("list",A));S2.command("add <email>").description("Add a subscriber").option("-t, --tag <tags...>","Tags to apply").option("-a, --attr <attrs...>","Attributes (key=value)").action((A,B)=>W4("add",{email:A,...B}));S2.command("get <email>").description("Get subscriber details").action((A)=>W4("get",{email:A}));S2.command("remove <email>").description("Remove a subscriber").option("--hard","Permanently delete (not just unsubscribe)").action((A,B)=>W4("remove",{email:A,...B}));_C.command("send <email>").description("Send a transactional email").option("-t, --template <id>","Template ID to use").option("-s, --subject <subject>","Email subject").option("--html <html>","Email HTML content").option("--html-file <file>","Read HTML from file").option("-v, --var <vars...>","Variables (key=value)").action(ej);var $2=_C.command("campaigns").description("Manage campaigns");$2.command("list").description("List campaigns").option("-s, --status <status>","Filter by status (draft, scheduled, sent)");$2.command("get <id>").description("Get campaign details");$2.command("create").description("Create a draft campaign").option("-n, --name <name>","Campaign name").option("-s, --subject <subject>","Email subject").option("-t, --template <id>","Use template");$2.command("test <id>").description("Send test email").option("--to <email>","Send test to this email");var O2=_C.command("sequences").description("Manage email sequences");O2.command("list").description("List all sequences");O2.command("get <id>").description("Get sequence details");O2.command("enable <id>").description("Enable a sequence");O2.command("disable <id>").description("Disable a sequence");var IP=_C.command("templates").description("Manage email templates");IP.command("list").description("List all templates");IP.command("get <id>").description("Get template details");_C.command("tags").description("List all tags");_C.command("lists").description("List all subscriber lists");_C.command("segments").description("List all segments");_C.command("account").description("Show account info");_C.command("websites").description("List sender websites");var AL=_C.command("generate").description("AI-powered content generation");AL.command("email <prompt>").description("Generate email from prompt").option("-s, --style <style>","Style: minimal, branded, promotional").option("-t, --tone <tone>","Tone: professional, casual, friendly");AL.command("sequence <goal>").description("Generate email sequence from goal").option("-c, --count <number>","Number of emails","5").option("-d, --days <number>","Duration in days","14");AL.command("subjects <topic>").description("Generate A/B subject line variants").option("-c, --count <number>","Number of variants","5");_C.parse();
|
|
302
|
+
${B}`,pr=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),nr=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),rr=(A,B,Q)=>{let C=Q===""?"":`with ${Q.trim()}() `,g=dr.bind(null,C,B.toString());Object.defineProperty(g,"name",nr);let{writable:H,enumerable:M,configurable:w}=pr;Object.defineProperty(A,"toString",{value:g,writable:H,enumerable:M,configurable:w})};function jZ(A,B,{ignoreNonConfigurable:Q=!1}={}){let{name:C}=A;for(let g of Reflect.ownKeys(B))lr(A,B,g,Q);return cr(A,B),rr(A,B,C),A}var ar=(A,B={})=>{if(typeof A!=="function")throw TypeError(`Expected the first argument to be a function, got \`${typeof A}\``);let{wait:Q=0,maxWait:C=Number.POSITIVE_INFINITY,before:g=!1,after:H=!0}=B;if(Q<0||C<0)throw RangeError("`wait` and `maxWait` must not be negative.");if(!g&&!H)throw Error("Both `before` and `after` are false, function wouldn't be called.");let M,w,N,L=function(...u){let j=this,W=()=>{if(M=void 0,w)clearTimeout(w),w=void 0;if(H)N=A.apply(j,u)},O=()=>{if(w=void 0,M)clearTimeout(M),M=void 0;if(H)N=A.apply(j,u)},v=g&&!M;if(clearTimeout(M),M=setTimeout(W,Q),C>0&&C!==Number.POSITIVE_INFINITY&&!w)w=setTimeout(O,C);if(v)N=A.apply(j,u);return N};return jZ(L,A),L.cancel=()=>{if(M)clearTimeout(M),M=void 0;if(w)clearTimeout(w),w=void 0},L},PZ=ar;var aH=cB(fj(),1);var lo=Object.prototype.toString;function vj(A,B,Q){if(!A)return!1;if(A.constructor===B)return!0;return lo.call(A)===Q}function xj(A){return vj(A,Uint8Array,"[object Uint8Array]")}function io(A){return vj(A,ArrayBuffer,"[object ArrayBuffer]")}function co(A){return xj(A)||io(A)}function po(A){if(!xj(A))throw TypeError(`Expected \`Uint8Array\`, got \`${typeof A}\``)}function no(A){if(!co(A))throw TypeError(`Expected \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof A}\``)}function nZ(A,B){if(A.length===0)return new Uint8Array(0);B??=A.reduce((g,H)=>g+H.length,0);let Q=new Uint8Array(B),C=0;for(let g of A)po(g),Q.set(g,C),C+=g.length;return Q}var _j={utf8:new globalThis.TextDecoder("utf8")};function rZ(A,B="utf8"){return no(A),_j[B]??=new globalThis.TextDecoder(B),_j[B].decode(A)}function ro(A){if(typeof A!=="string")throw TypeError(`Expected \`string\`, got \`${typeof A}\``)}var ao=new globalThis.TextEncoder;function q2(A){return ro(A),ao.encode(A)}var WGA=Array.from({length:256},(A,B)=>B.toString(16).padStart(2,"0"));var to=ij.default.default,mj="aes-256-cbc",z3=()=>Object.create(null),eo=(A)=>A!==void 0&&A!==null,At=(A,B)=>{let Q=new Set(["undefined","symbol","function"]),C=typeof B;if(Q.has(C))throw TypeError(`Setting a value of type \`${C}\` for key \`${A}\` is not allowed as it's not supported by JSON`)},W2="__internal__",aZ=`${W2}.migrations.version`;class z2{path;events;#Q;#B;#A;#I={};constructor(A={}){let B={configName:"config",fileExtension:"json",projectSuffix:"nodejs",clearInvalidConfig:!1,accessPropertiesByDotNotation:!0,configFileMode:438,...A};if(!B.cwd){if(!B.projectName)throw Error("Please specify the `projectName` option.");B.cwd=G9(B.projectName,{suffix:B.projectSuffix}).config}if(this.#A=B,B.schema??B.ajvOptions??B.rootSchema){if(B.schema&&typeof B.schema!=="object")throw TypeError("The `schema` option must be an object.");let H=new lj.Ajv2020({allErrors:!0,useDefaults:!0,...B.ajvOptions});to(H);let M={...B.rootSchema,type:"object",properties:B.schema};this.#Q=H.compile(M);for(let[w,N]of Object.entries(B.schema??{}))if(N?.default)this.#I[w]=N.default}if(B.defaults)this.#I={...this.#I,...B.defaults};if(B.serialize)this._serialize=B.serialize;if(B.deserialize)this._deserialize=B.deserialize;this.events=new EventTarget,this.#B=B.encryptionKey;let Q=B.fileExtension?`.${B.fileExtension}`:"";this.path=hj.resolve(B.cwd,`${B.configName??"config"}${Q}`);let C=this.store,g=Object.assign(z3(),B.defaults,C);if(B.migrations){if(!B.projectVersion)throw Error("Please specify the `projectVersion` option.");this._migrate(B.migrations,B.projectVersion,B.beforeEachMigration)}this._validate(g);try{oo.deepEqual(C,g)}catch{this.store=g}if(B.watch)this._watch()}get(A,B){if(this.#A.accessPropertiesByDotNotation)return this._get(A,B);let{store:Q}=this;return A in Q?Q[A]:B}set(A,B){if(typeof A!=="string"&&typeof A!=="object")throw TypeError(`Expected \`key\` to be of type \`string\` or \`object\`, got ${typeof A}`);if(typeof A!=="object"&&B===void 0)throw TypeError("Use `delete()` to clear values");if(this._containsReservedKey(A))throw TypeError(`Please don't use the ${W2} key, as it's used to manage this module internal operations.`);let{store:Q}=this,C=(g,H)=>{if(At(g,H),this.#A.accessPropertiesByDotNotation)D9(Q,g,H);else Q[g]=H};if(typeof A==="object"){let g=A;for(let[H,M]of Object.entries(g))C(H,M)}else C(A,B);this.store=Q}has(A){if(this.#A.accessPropertiesByDotNotation)return UW(this.store,A);return A in this.store}reset(...A){for(let B of A)if(eo(this.#I[B]))this.set(B,this.#I[B])}delete(A){let{store:B}=this;if(this.#A.accessPropertiesByDotNotation)RW(B,A);else delete B[A];this.store=B}clear(){this.store=z3();for(let A of Object.keys(this.#I))this.reset(A)}onDidChange(A,B){if(typeof A!=="string")throw TypeError(`Expected \`key\` to be of type \`string\`, got ${typeof A}`);if(typeof B!=="function")throw TypeError(`Expected \`callback\` to be of type \`function\`, got ${typeof B}`);return this._handleChange(()=>this.get(A),B)}onDidAnyChange(A){if(typeof A!=="function")throw TypeError(`Expected \`callback\` to be of type \`function\`, got ${typeof A}`);return this._handleChange(()=>this.store,A)}get size(){return Object.keys(this.store).length}get store(){try{let A=rH.readFileSync(this.path,this.#B?null:"utf8"),B=this._encryptData(A),Q=this._deserialize(B);return this._validate(Q),Object.assign(z3(),Q)}catch(A){if(A?.code==="ENOENT")return this._ensureDirectory(),z3();if(this.#A.clearInvalidConfig&&A.name==="SyntaxError")return z3();throw A}}set store(A){this._ensureDirectory(),this._validate(A),this._write(A),this.events.dispatchEvent(new Event("change"))}*[Symbol.iterator](){for(let[A,B]of Object.entries(this.store))yield[A,B]}_encryptData(A){if(!this.#B)return typeof A==="string"?A:rZ(A);try{let B=A.slice(0,16),Q=X4.pbkdf2Sync(this.#B,B.toString(),1e4,32,"sha512"),C=X4.createDecipheriv(mj,Q,B),g=A.slice(17),H=typeof g==="string"?q2(g):g;return rZ(nZ([C.update(H),C.final()]))}catch{}return A.toString()}_handleChange(A,B){let Q=A(),C=()=>{let g=Q,H=A();if(so(H,g))return;Q=H,B.call(this,H,g)};return this.events.addEventListener("change",C),()=>{this.events.removeEventListener("change",C)}}_deserialize=(A)=>JSON.parse(A);_serialize=(A)=>JSON.stringify(A,void 0,"\t");_validate(A){if(!this.#Q)return;if(this.#Q(A)||!this.#Q.errors)return;let Q=this.#Q.errors.map(({instancePath:C,message:g=""})=>`\`${C.slice(1)}\` ${g}`);throw Error("Config schema violation: "+Q.join("; "))}_ensureDirectory(){rH.mkdirSync(hj.dirname(this.path),{recursive:!0})}_write(A){let B=this._serialize(A);if(this.#B){let Q=X4.randomBytes(16),C=X4.pbkdf2Sync(this.#B,Q.toString(),1e4,32,"sha512"),g=X4.createCipheriv(mj,C,Q);B=nZ([Q,q2(":"),g.update(q2(B)),g.final()])}if(bj.env.SNAP)rH.writeFileSync(this.path,B,{mode:this.#A.configFileMode});else try{K9(this.path,B,{mode:this.#A.configFileMode})}catch(Q){if(Q?.code==="EXDEV"){rH.writeFileSync(this.path,B,{mode:this.#A.configFileMode});return}throw Q}}_watch(){if(this._ensureDirectory(),!rH.existsSync(this.path))this._write(z3());if(bj.platform==="win32")rH.watch(this.path,{persistent:!1},PZ(()=>{this.events.dispatchEvent(new Event("change"))},{wait:100}));else rH.watchFile(this.path,{persistent:!1},PZ(()=>{this.events.dispatchEvent(new Event("change"))},{wait:5000}))}_migrate(A,B,Q){let C=this._get(aZ,"0.0.0"),g=Object.keys(A).filter((M)=>this._shouldPerformMigration(M,C,B)),H={...this.store};for(let M of g)try{if(Q)Q(this,{fromVersion:C,toVersion:M,finalVersion:B,versions:g});let w=A[M];w?.(this),this._set(aZ,M),C=M,H={...this.store}}catch(w){throw this.store=H,Error(`Something went wrong during the migration! Changes applied to the store until this failed migration will be restored. ${w}`)}if(this._isVersionInRangeFormat(C)||!aH.default.eq(C,B))this._set(aZ,B)}_containsReservedKey(A){if(typeof A==="object"){if(Object.keys(A)[0]===W2)return!0}if(typeof A!=="string")return!1;if(this.#A.accessPropertiesByDotNotation){if(A.startsWith(`${W2}.`))return!0;return!1}return!1}_isVersionInRangeFormat(A){return aH.default.clean(A)===null}_shouldPerformMigration(A,B,Q){if(this._isVersionInRangeFormat(A)){if(B!=="0.0.0"&&aH.default.satisfies(B,A))return!1;return aH.default.satisfies(Q,A)}if(aH.default.lte(A,B))return!1;if(aH.default.gt(A,Q))return!1;return!0}_get(A,B){return JW(this.store,A,B)}_set(A,B){let{store:Q}=this;D9(Q,A,B),this.store=Q}}var sZ="com.sequenzy.cli",oZ="api-key",q4=new z2({projectName:"sequenzy",schema:{userId:{type:"string"},userEmail:{type:"string"}}});async function tZ(){let A=process.env.SEQUENZY_API_KEY;if(A)return A;try{return await Bun.secrets.get({service:sZ,name:oZ})??void 0}catch{return}}async function cj(A){await Bun.secrets.set({service:sZ,name:oZ,value:A,allowUnrestrictedAccess:!1})}async function dj(){await Bun.secrets.delete({service:sZ,name:oZ})}async function l0(){return!!await tZ()}function pj(){return{userId:q4.get("userId"),userEmail:q4.get("userEmail")}}function nj(A){if(A.userId!==void 0)q4.set("userId",A.userId);if(A.userEmail!==void 0)q4.set("userEmail",A.userEmail)}function rj(){q4.clear()}var yQ=cB(DG(),1),aj=process.env.SEQUENZY_API_URL??"https://api.sequenzy.com",sj=process.env.SEQUENZY_APP_URL??"https://sequenzy.com";function Qt(){let[A,B]=Xg.useState("check"),[Q,C]=Xg.useState(""),[g,H]=Xg.useState(""),[M,w]=Xg.useState(5),[N,L]=Xg.useState(null),[u,j]=Xg.useState("");if(Xg.useEffect(()=>{if(A!=="check")return;l0().then((W)=>{if(W)j("Already logged in. Run `sequenzy logout` first to switch accounts."),B("error");else B("init")})},[A]),Xg.useEffect(()=>{if(A!=="init")return;let W=`${process.platform}-${It.hostname()}`;fetch(`${aj}/api/device-auth/initiate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceName:W,clientType:"cli"})}).then((O)=>O.json()).then((O)=>{if(!O.success||!O.data){j(O.error??"Failed to initiate auth"),B("error");return}C(O.data.userCode),H(O.data.deviceCode),w(O.data.pollInterval);let v=`${sj}/setup/auth?code=${O.data.userCode}`;GW(v),B("waiting")}).catch((O)=>{j(O.message),B("error")})},[A]),Xg.useEffect(()=>{if(A!=="waiting")return;let W=setInterval(()=>{fetch(`${aj}/api/device-auth/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:g})}).then((O)=>O.json()).then((O)=>{if(O.success&&O.data)clearInterval(W),L(O.data),cj(O.data.apiKey).then(()=>{nj({userId:O.data.userId,userEmail:O.data.userEmail}),B("success"),setTimeout(()=>process.exit(0),100)}).catch((v)=>{j(`Failed to save credentials: ${v.message}`),B("error"),setTimeout(()=>process.exit(1),100)});else if(O.error==="access_denied")clearInterval(W),j("Authorization denied"),B("error"),setTimeout(()=>process.exit(1),100);else if(O.error==="expired_token")clearInterval(W),j("Authorization expired. Please try again."),B("error"),setTimeout(()=>process.exit(1),100)}).catch(()=>{})},M*1000);return()=>clearInterval(W)},[A,g,M]),A==="check"||A==="init")return yQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:yQ.jsxDEV(XB,{children:[yQ.jsxDEV(XB,{color:"cyan",children:yQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this)," ","Initializing..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(A==="waiting")return yQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:[yQ.jsxDEV(DI,{marginBottom:1,children:yQ.jsxDEV(XB,{bold:!0,color:"green",children:"Sequenzy Login"},void 0,!1,void 0,this)},void 0,!1,void 0,this),yQ.jsxDEV(XB,{children:"Opening browser to authenticate..."},void 0,!1,void 0,this),yQ.jsxDEV(XB,{dimColor:!0,children:"If the browser doesn't open, visit:"},void 0,!1,void 0,this),yQ.jsxDEV(XB,{color:"cyan",children:[sj,"/setup/auth?code=",Q]},void 0,!0,void 0,this),yQ.jsxDEV(DI,{marginTop:1,children:yQ.jsxDEV(XB,{children:[yQ.jsxDEV(XB,{color:"yellow",children:yQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this)," ","Waiting for approval..."]},void 0,!0,void 0,this)},void 0,!1,void 0,this),yQ.jsxDEV(DI,{marginTop:1,children:[yQ.jsxDEV(XB,{dimColor:!0,children:"Your code: "},void 0,!1,void 0,this),yQ.jsxDEV(XB,{bold:!0,color:"magenta",children:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(A==="success")return yQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:[yQ.jsxDEV(DI,{marginBottom:1,children:yQ.jsxDEV(XB,{color:"green",children:" Logged in successfully!"},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&yQ.jsxDEV(DI,{children:[yQ.jsxDEV(XB,{dimColor:!0,children:"User: "},void 0,!1,void 0,this),yQ.jsxDEV(XB,{children:N.userEmail},void 0,!1,void 0,this)]},void 0,!0,void 0,this),yQ.jsxDEV(DI,{marginTop:1,children:yQ.jsxDEV(XB,{dimColor:!0,children:"Run `sequenzy --help` to see available commands."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(A==="error")return yQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:yQ.jsxDEV(XB,{color:"red",children:[" Error: ",u]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return null}function oj(){eg(yQ.jsxDEV(Qt,{},void 0,!1,void 0,this))}async function tj(){if(!await l0()){console.log("Not logged in.");return}await dj(),rj(),console.log("Logged out successfully.")}import{readFileSync as Ct}from"node:fs";var sH=cB(kQ(),1);var Et=process.env.SEQUENZY_API_URL??"https://api.sequenzy.com";class L8 extends Error{statusCode;constructor(A,B){super(A);this.statusCode=B;this.name="ApiError"}}async function qg(A,B,Q){let C=await tZ();if(!C)throw new L8("Not logged in. Run `sequenzy login` first.",401);let g=await fetch(`${Et}${B}`,{method:A,headers:{"Content-Type":"application/json",Authorization:`Bearer ${C}`},body:Q?JSON.stringify(Q):void 0});if(!g.ok){let H=await g.text();throw new L8(`API error: ${H}`,g.status)}return g.json()}var FF=cB(DG(),1);function Dt({email:A,options:B}){let[Q,C]=sH.useState(!0),[g,H]=sH.useState(""),[M,w]=sH.useState(!1);if(sH.useEffect(()=>{async function N(){try{let L={};for(let j of B.var??[]){let[W,O]=j.split("=");if(W&&O)L[W]=O}let u=B.html;if(B.htmlFile)u=Ct(B.htmlFile,"utf-8");if(!B.template&&!u)throw Error("Either --template or --html/--html-file is required");if(!B.template&&!B.subject)throw Error("--subject is required when using --html");await qg("POST","/api/v1/transactional/send",{to:A,templateId:B.template,subject:B.subject,html:u,variables:L}),w(!0)}catch(L){H(L instanceof Error?L.message:"Failed to send")}finally{C(!1)}}N()},[A,B]),sH.useEffect(()=>{if(!Q)setTimeout(()=>process.exit(g?1:0),100)},[Q,g]),Q)return FF.jsxDEV(DI,{padding:1,children:[FF.jsxDEV(XB,{color:"cyan",children:FF.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this),FF.jsxDEV(XB,{children:[" Sending email to ",A,"..."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(g)return FF.jsxDEV(DI,{padding:1,children:FF.jsxDEV(XB,{color:"red",children:[" ",g]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return FF.jsxDEV(DI,{padding:1,children:FF.jsxDEV(XB,{color:"green",children:[" Email sent to ",A]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}async function ej(A,B){if(!await l0())console.log("Not logged in. Run `sequenzy login` first."),process.exit(1);eg(FF.jsxDEV(Dt,{email:A,options:B},void 0,!1,void 0,this))}var oH=cB(kQ(),1);var CQ=cB(DG(),1);function gt({options:A}){let[B,Q]=oH.useState(!0),[C,g]=oH.useState(""),[H,M]=oH.useState(null);if(oH.useEffect(()=>{async function L(){try{let u;if(A.campaign)u=await qg("GET",`/api/v1/campaigns/${A.campaign}/stats`);else if(A.sequence)u=await qg("GET",`/api/v1/sequences/${A.sequence}/stats`);else u=await qg("GET",`/api/v1/stats?period=${A.period??"7d"}`);M(u)}catch(u){g(u instanceof L8?u.message:"Failed to fetch stats")}finally{Q(!1)}}L()},[A]),oH.useEffect(()=>{if(!B)setTimeout(()=>process.exit(C?1:0),100)},[B,C]),B)return CQ.jsxDEV(DI,{padding:1,children:[CQ.jsxDEV(XB,{color:"cyan",children:CQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:" Loading stats..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(C)return CQ.jsxDEV(DI,{padding:1,children:CQ.jsxDEV(XB,{color:"red",children:[" ",C]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(!H)return CQ.jsxDEV(DI,{padding:1,children:CQ.jsxDEV(XB,{dimColor:!0,children:"No stats available"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let w=A.period??"7d",N=A.campaign?"Campaign Stats":A.sequence?"Sequence Stats":`Stats (${w})`;return CQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:[CQ.jsxDEV(DI,{marginBottom:1,children:CQ.jsxDEV(XB,{bold:!0,color:"green",children:N},void 0,!1,void 0,this)},void 0,!1,void 0,this),CQ.jsxDEV(DI,{flexDirection:"column",children:[CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Sent: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.sent.toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Delivered: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.delivered.toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Opened: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.opened.toLocaleString()},void 0,!1,void 0,this),CQ.jsxDEV(XB,{dimColor:!0,children:[" (",(H.openRate*100).toFixed(1),"%)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Clicked: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.clicked.toLocaleString()},void 0,!1,void 0,this),CQ.jsxDEV(XB,{dimColor:!0,children:[" (",(H.clickRate*100).toFixed(1),"%)"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Bounced: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{color:H.bounced>0?"yellow":void 0,children:H.bounced.toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this),CQ.jsxDEV(DI,{children:[CQ.jsxDEV(XB,{dimColor:!0,children:"Unsubscribed: "},void 0,!1,void 0,this),CQ.jsxDEV(XB,{children:H.unsubscribed.toLocaleString()},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}async function AP(A){if(!await l0())console.log("Not logged in. Run `sequenzy login` first."),process.exit(1);eg(CQ.jsxDEV(gt,{options:A},void 0,!1,void 0,this))}var i0=cB(kQ(),1);var dQ=cB(DG(),1);function Ft({options:A}){let[B,Q]=i0.useState(!0),[C,g]=i0.useState(""),[H,M]=i0.useState([]);if(i0.useEffect(()=>{async function w(){try{let N=new URLSearchParams;if(A.segment)N.set("segmentId",A.segment);if(A.tag)N.set("tags",A.tag);if(A.limit)N.set("limit",A.limit);let L=await qg("GET",`/api/v1/subscribers?${N}`);M(L.subscribers??[])}catch(N){g(N instanceof L8?N.message:"Failed to fetch")}finally{Q(!1)}}w()},[A]),i0.useEffect(()=>{if(!B)setTimeout(()=>process.exit(C?1:0),100)},[B,C]),B)return dQ.jsxDEV(DI,{padding:1,children:[dQ.jsxDEV(XB,{color:"cyan",children:dQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this),dQ.jsxDEV(XB,{children:" Loading subscribers..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(C)return dQ.jsxDEV(DI,{padding:1,children:dQ.jsxDEV(XB,{color:"red",children:[" ",C]},void 0,!0,void 0,this)},void 0,!1,void 0,this);if(H.length===0)return dQ.jsxDEV(DI,{padding:1,children:dQ.jsxDEV(XB,{dimColor:!0,children:"No subscribers found"},void 0,!1,void 0,this)},void 0,!1,void 0,this);return dQ.jsxDEV(DI,{flexDirection:"column",padding:1,children:[dQ.jsxDEV(DI,{marginBottom:1,children:dQ.jsxDEV(XB,{bold:!0,children:["Subscribers (",H.length,")"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H.map((w)=>dQ.jsxDEV(DI,{children:[dQ.jsxDEV(XB,{children:w.email},void 0,!1,void 0,this),dQ.jsxDEV(XB,{dimColor:!0,children:[" [",w.status,"]"]},void 0,!0,void 0,this),w.tags.length>0&&dQ.jsxDEV(XB,{color:"cyan",children:[" ",w.tags.join(", ")]},void 0,!0,void 0,this)]},w.id,!0,void 0,this))]},void 0,!0,void 0,this)}function Gt({action:A,options:B}){let[Q,C]=i0.useState(!0),[g,H]=i0.useState(""),[M,w]=i0.useState("");if(i0.useEffect(()=>{async function N(){try{switch(A){case"add":{let L={};for(let u of B.attr??[]){let[j,W]=u.split("=");if(j&&W)L[j]=W}await qg("POST","/api/v1/subscribers",{email:B.email,tags:B.tag?[B.tag]:[],attributes:L}),w(`Added subscriber: ${B.email}`);break}case"get":{let L=await qg("GET",`/api/v1/subscribers/${B.email}`);w(JSON.stringify(L,null,2));break}case"remove":{await qg("DELETE",`/api/v1/subscribers/${B.email}`,{hardDelete:B.hard}),w(B.hard?`Deleted subscriber: ${B.email}`:`Unsubscribed: ${B.email}`);break}}}catch(L){H(L instanceof L8?L.message:"Failed")}finally{C(!1)}}N()},[A,B]),i0.useEffect(()=>{if(!Q)setTimeout(()=>process.exit(g?1:0),100)},[Q,g]),Q)return dQ.jsxDEV(DI,{padding:1,children:[dQ.jsxDEV(XB,{color:"cyan",children:dQ.jsxDEV(AF,{type:"dots"},void 0,!1,void 0,this)},void 0,!1,void 0,this),dQ.jsxDEV(XB,{children:" Processing..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(g)return dQ.jsxDEV(DI,{padding:1,children:dQ.jsxDEV(XB,{color:"red",children:[" ",g]},void 0,!0,void 0,this)},void 0,!1,void 0,this);return dQ.jsxDEV(DI,{padding:1,children:dQ.jsxDEV(XB,{color:"green",children:[" ",M]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}async function W4(A,B){if(!await l0())console.log("Not logged in. Run `sequenzy login` first."),process.exit(1);if(A==="list")eg(dQ.jsxDEV(Ft,{options:B},void 0,!1,void 0,this));else eg(dQ.jsxDEV(Gt,{action:A,options:B},void 0,!1,void 0,this))}async function BP(){if(!await l0()){console.log("Not logged in. Run `sequenzy login` to authenticate.");return}let A=pj();console.log(`Email: ${A.userEmail??"Unknown"}`),console.log(`User ID: ${A.userId??"Unknown"}`),console.log(""),console.log("Your API key can access all companies you belong to."),console.log("Use `sequenzy account` to see available companies.")}var _C=new v5;_C.name("sequenzy").description("Sequenzy CLI - Email marketing from the terminal").version("0.0.1");_C.command("login").description("Log in to your Sequenzy account").action(oj);_C.command("logout").description("Log out of your Sequenzy account").action(tj);_C.command("whoami").description("Show current logged in user").action(BP);_C.command("stats").description("Show email statistics").option("-p, --period <period>","Time period (7d, 30d, 90d)","7d").option("--campaign <id>","Get stats for specific campaign").option("--sequence <id>","Get stats for specific sequence").action(AP);var S2=_C.command("subscribers").description("Manage subscribers");S2.command("list").description("List subscribers").option("-s, --segment <id>","Filter by segment").option("-t, --tag <tag>","Filter by tag").option("-l, --limit <number>","Limit results","50").action((A)=>W4("list",A));S2.command("add <email>").description("Add a subscriber").option("-t, --tag <tags...>","Tags to apply").option("-a, --attr <attrs...>","Attributes (key=value)").action((A,B)=>W4("add",{email:A,...B}));S2.command("get <email>").description("Get subscriber details").action((A)=>W4("get",{email:A}));S2.command("remove <email>").description("Remove a subscriber").option("--hard","Permanently delete (not just unsubscribe)").action((A,B)=>W4("remove",{email:A,...B}));_C.command("send <email>").description("Send a transactional email").option("-t, --template <id>","Template ID to use").option("-s, --subject <subject>","Email subject").option("--html <html>","Email HTML content").option("--html-file <file>","Read HTML from file").option("-v, --var <vars...>","Variables (key=value)").action(ej);var $2=_C.command("campaigns").description("Manage campaigns");$2.command("list").description("List campaigns").option("-s, --status <status>","Filter by status (draft, scheduled, sent)");$2.command("get <id>").description("Get campaign details");$2.command("create").description("Create a draft campaign").option("-n, --name <name>","Campaign name").option("-s, --subject <subject>","Email subject").option("-t, --template <id>","Use template");$2.command("test <id>").description("Send test email").option("--to <email>","Send test to this email");var O2=_C.command("sequences").description("Manage email sequences");O2.command("list").description("List all sequences");O2.command("get <id>").description("Get sequence details");O2.command("enable <id>").description("Enable a sequence");O2.command("disable <id>").description("Disable a sequence");var IP=_C.command("templates").description("Manage email templates");IP.command("list").description("List all templates");IP.command("get <id>").description("Get template details");_C.command("tags").description("List all tags");_C.command("lists").description("List all subscriber lists");_C.command("segments").description("List all segments");_C.command("account").description("Show account info");_C.command("websites").description("List sender websites");var AL=_C.command("generate").description("AI-powered content generation");AL.command("email <prompt>").description("Generate email from prompt").option("-s, --style <style>","Style: minimal, branded, promotional").option("-t, --tone <tone>","Tone: professional, casual, friendly");AL.command("sequence <goal>").description("Generate email sequence from goal").option("-c, --count <number>","Number of emails","5").option("-d, --days <number>","Duration in days","14");AL.command("subjects <topic>").description("Generate A/B subject line variants").option("-c, --count <number>","Number of variants","5");_C.parse();
|