UNPKG

@appzung/cli

Version:

AppZung CLI

7 lines (4 loc) 6.82 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f23333e5-5af6-5811-8745-be73342fdd95")}catch(e){}}(); var i=class extends Error{},f=class extends i{name="Cancelled";message="Operation cancellation"},y=class extends i{name="TokenNotFound";message='Please login using the "appzung auth login" command.'},l=class extends i{name="Expired";message='Your token has expired. Please run the "appzung auth login" command.'},h=class extends i{name="InvalidApiKey";message="Your API key is invalid."},x=class extends i{name="RecentAuthenticationRequired";message='For security reasons, a recent authentication is required for this action. Please run "appzung auth logout --web" then login again with "appzung auth login" and retry.'},_=class extends i{constructor(e){super(),this.message=`The file '${e}' doesn't exist or you don't have access to it`}name="NoAccessToFile"},v=class extends i{constructor(e){super(),this.message=e}name="BadInput"},P=class extends i{constructor(e){super(),this.message=e}name="DuplicateRelease"},z=class extends i{name="SubscriptionPlanNotFound";message="This plan is not available anymore, please update the CLI."};var u=class extends Error{constructor(t){super();this.errors=t}get message(){return this.errors.map(t=>t.extensions?.code==="INTERNAL_SERVER_ERROR"&&t.extensions?.errorId?`An internal server error occurred. Please contact support with this error ID: ${t.extensions.errorId}`:t.message).filter(Boolean).join(" | ")}};import U from"debug";function ce(r){throw r instanceof i||r instanceof u||U(r instanceof Error?JSON.stringify(r):"Unknown error"),r}import{randomUUID as F}from"node:crypto";var N={ENV:"production",WEB_URL:process.env.APPZUNG_WEB_URL||"https://console.appzung.com",API_BASE_URL:process.env.APPZUNG_API_URL||"https://api.appzung.com",SIMPLE_ANALYTICS_HOSTNAME:"cli.appzung.com",SENTRY_DSN:"https://d26cf42a4eccad4b024e8339ac29e16d@o4508570861240320.ingest.de.sentry.io/4508570864582736"};import{setUser as D}from"@sentry/node";import{jwtDecode as C}from"jwt-decode";import L from"node:fs";import K from"node:os";import B from"node:path";var G=3*60*1e3;function R(){let r=B.join(K.homedir(),".appzung","token");if(!L.existsSync(r))throw new y;let e=L.readFileSync(r,"utf8"),t=C(e);if(!t.exp)throw new l;let n=new Date(t.exp*1e3),s=new Date;if(n.getTime()-G<s.getTime())throw new l;return t.user_id&&D({id:t.user_id}),{token:e,decodedToken:t}}function Z(){try{return new Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return null}}function b(){return process.env.TZ??Z()??null}var O="1.13.2";var A=async({url:r,query:e,variables:t,options:n={headers:{}}})=>{let s=await fetch(r,{...n,method:"POST",headers:{...n.headers,"Content-Type":"application/json"},body:JSON.stringify({query:e,variables:t})}),o=await s.json();if(!s.ok){let a=typeof o=="string"?{error:o}:o;if(o.errors?.[0]?.extensions?.code==="UNAUTHENTICATED")switch(o.errors[0].extensions.reason){case"INVALID_API_KEY":throw new h;case"EXPIRED_TOKEN":throw new l}throw o.errors?.[0]?.extensions?.code==="BAD_USER_INPUT"?new v(o.errors?.[0].message):new Error(JSON.stringify(a))}if(o.errors?.length)throw o.errors[0]?.extensions?.code==="RECENT_AUTHENTICATION_REQUIRED"?new x:new u(o.errors);return o};var I=class{constructor(e){this.url=e}getHeaders(e={}){let t=e.apiKey?{token:e.apiKey,kind:"api_key"}:{token:R().token,kind:"firebase"},n=b();return{authorization:`Bearer ${t.token}`,...!!n&&{"az-device-timezone":n},"az-client-name":"cli","az-authentication-kind":t.kind,"az-client-version":O}}query(e,t,n={}){return A({url:this.url,query:e,variables:t,options:{headers:this.getHeaders(n)}})}mutate(e,t,n={}){return A({url:this.url,query:e,variables:t,options:{headers:{...this.getHeaders(n),"idempotency-key":F()}}})}},E=new I(`${N.API_BASE_URL}/graphql`);import{isCancel as $,outro as M}from"@clack/prompts";import{isCancel as H,log as Y,select as W,spinner as J}from"@clack/prompts";import k from"picocolors";var w=(r,...e)=>Array.isArray(r)?r.reduce((t,n,s)=>t+n+(e[s]||""),"").trim():r;var S=w`query ListMyOrganizations($limit: PositiveInt!, $offset: Int!) { me { id organizations(limit: $limit, offset: $offset) { count list { id name email slug } } } }`;async function j({offset:r=0,allOrganizations:e=[]}={}){let n=J();n.start("Loading organizations");let{data:s}=await E.query(S,{limit:10,offset:r}),{list:o,count:a}=s.me.organizations;if(n.stop(r?"":`Found ${a} organization(s)`),a===0)return;if(a===1&&o[0])return Y.message(k.dim(o[0].slug)),o[0];e.push(...o);let m=e.map(c=>({value:c.slug,label:`${c.name} ${k.dim(`(${c.slug})`)}`}));a>(r+1)*10&&m.push({value:"load-more",label:"Load more"});let d=m.at(r),p=await W({message:"Select an organization",options:m,initialValue:d?.value});if(typeof p!="string")return p;if(p==="load-more")return j({allOrganizations:e,offset:r+10});let g=e.find(c=>c.slug===p);if(!g)throw new Error("Missing organization");return g}async function q(r={}){let e=await j(r);return H(e)||!e?e:e.slug}import{log as X,select as ee,spinner as re}from"@clack/prompts";import V from"picocolors";var Q=w`query ListMyProjects($input: OrganizationIdentifierInput!, $limit: PositiveInt!, $offset: Int!) { organization(input: $input) { id projects(limit: $limit, offset: $offset) { count list { id name slug framework } } } }`;async function T(r,{offset:e=0,allProjects:t=[]}={}){let s=re();s.start("Loading projects");let{data:o}=await E.query(Q,{input:{bySlug:{organizationSlug:r}},limit:10,offset:e}),{list:a,count:m}=o.organization.projects;if(s.stop(e?"":`Found ${m} project(s)`),m===0)return;if(m===1&&a[0])return X.message(V.dim(a[0].slug)),a[0].slug;t.push(...a);let d=t.map(c=>({value:c.slug,label:`${c.name} ${V.dim(`(${c.slug})`)}`}));m>(e+1)*10&&d.push({value:"load-more",label:"Load more"});let p=d.at(e),g=await ee({message:"Select a project",options:d,initialValue:p?.value});return g==="load-more"?T(r,{allProjects:t,offset:e+10}):g}async function He(r={}){let e=r.org??await q();if($(e)||!e)throw M("No organization selected"),new f;let t=r.project??await T(e);if($(t)||!t)throw M("No project selected"),new f;return{organizationSlug:e,projectSlug:t}}var We={REACT_NATIVE:"React Native bundling",AUTO_DETECTION:"Automatic detection of target binary version and Hermes usage",REQUIRED_NON_INTERACTIVE:"Required in non-interactive terminals"};import te from"is-interactive";var er=te();export{N as a,O as b,i as c,f as d,y as e,l as f,_ as g,P as h,z as i,G as j,R as k,u as l,ce as m,b as n,E as o,w as p,S as q,j as r,q as s,Q as t,He as u,We as v,er as w}; //# sourceMappingURL=chunk-XJDCHVMB.js.map //# debugId=f23333e5-5af6-5811-8745-be73342fdd95