@getjusto/team-cli 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +107 -0
- package/package.json +23 -0
package/bin/cli.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var yg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",prod:"https://api.getjusto.com"},auth:{local:"http://localhost:4112",develop:"https://auth.service.bejusto.com",prod:"https://auth.service.getjusto.com"},webdata:{local:"http://localhost:4125",develop:"https://webdata.service.bejusto.com",prod:"https://webdatacdn.getjusto.com"},preferences:{local:"http://localhost:4120",develop:"https://preferences.service.bejusto.com",prod:"https://preferences.service.getjusto.com"},buckets:{local:"http://localhost:4106",develop:"https://buckets.service.bejusto.com",prod:"https://buckets.service.getjusto.com"},reservations:{local:"http://localhost:4113",develop:"https://reservations.service.bejusto.com",prod:"https://reservations.service.getjusto.com"},data:{local:"http://localhost:4107",develop:"https://data.service.bejusto.com",prod:"https://data.service.getjusto.com"},finances:{local:"http://localhost:4105",develop:"https://finances.service.bejusto.com",prod:"https://finances.service.getjusto.com"},"url-shortener":{local:"http://localhost:4102",develop:"https://url-shortener.service.bejusto.com",prod:"https://url-shortener.service.getjusto.com"},files:{local:"http://localhost:4108",develop:"https://files.service.bejusto.com",prod:"https://files.service.getjusto.com"},tabs:{local:"http://localhost:4115",develop:"https://tabs.service.bejusto.com",prod:"https://tabs.service.getjusto.com"},commander:{local:"http://localhost:4109",develop:"https://commander.service.bejusto.com",prod:"https://commander.service.getjusto.com"},experiments:{local:"http://localhost:4114",develop:"https://experiments.service.bejusto.com",prod:"https://experiments.service.getjusto.com"},sales:{local:"http://localhost:4117",develop:"https://sales.service.bejusto.com",prod:"https://sales.service.getjusto.com"},delivery:{local:"http://localhost:3410",develop:"https://api-delivery.bejusto.com",prod:"https://api-delivery-2.getjusto.com"},payments:{local:"http://localhost:4118",develop:"https://payments.service.bejusto.com",prod:"https://payments.service.getjusto.com"},addresses:{local:"http://localhost:4051",develop:"https://addresses.service.bejusto.com",prod:"https://addresses.service.getjusto.com"},royalty:{local:"http://localhost:4121",develop:"https://royalty.service.bejusto.com",prod:"https://royalty.service.getjusto.com"},marketing:{local:"http://localhost:4005",develop:"https://marketing.service.bejusto.com",prod:"https://marketing.service.getjusto.com"},api:{local:"http://localhost:4119",develop:"https://api.service.bejusto.com",prod:"https://api.service.getjusto.com"},messenger:{local:"http://localhost:4122",develop:"https://messenger.service.bejusto.com",prod:"https://messenger.service.getjusto.com"},invoice:{local:"http://localhost:4123",develop:"https://invoice.service.bejusto.com",prod:"https://invoice.service.getjusto.com"},"drivers-server":{local:"http://localhost:3410",develop:"https://api-delivery.bejusto.com",prod:"https://api-delivery-2.getjusto.com"}},h="prod";function mg(g){h=g}function qg(){return h}function s(g){return yg[g][h]}function $g(g){let m=[],q={},$={};for(let j=0;j<g.length;j++)if(g[j].startsWith("--")&&g[j+1]&&!g[j+1].startsWith("--")){let C=g[j].slice(2);if(q[C]=g[j+1],!$[C])$[C]=[];$[C].push(g[j+1]),j++}else if(g[j].startsWith("--"))q[g[j].slice(2)]="true";else m.push(g[j]);return{positional:m,flags:q,arrayFlags:$}}function H(g,m){let q=g[m];if(!q)console.error(`Error: --${m} es requerido.`),process.exit(1);return q}import{existsSync as i,mkdirSync as Kg,readFileSync as xg,writeFileSync as kg,unlinkSync as Vg}from"node:fs";import{join as jg}from"node:path";import{homedir as rg}from"node:os";var o=jg(rg(),".justo-team");function l(){let g=qg(),m=g==="prod"?"credentials.json":`credentials.${g}.json`;return jg(o,m)}function Dg(){if(!i(o))Kg(o,{recursive:!0})}function K(g){Dg(),kg(l(),JSON.stringify(g,null,2))}function f(){let g=l();if(!i(g))return null;try{let m=xg(g,"utf-8");return JSON.parse(m)}catch{return null}}function d(){let g=l();if(i(g))Vg(g)}import{existsSync as Cg,readFileSync as vg,writeFileSync as Lg,mkdirSync as hg}from"node:fs";import{join as Gg}from"node:path";import{homedir as sg}from"node:os";function og(){let g=Gg(sg(),".justo-team"),m=Gg(g,"device-id");if(Cg(m))return vg(m,"utf-8").trim();let q=crypto.randomUUID();if(!Cg(g))hg(g,{recursive:!0});return Lg(m,q),q}var Qg={required:({label:g})=>`${g} no es opcional`,notAString:({label:g})=>`${g} no es un texto`,notANumber:({label:g})=>`${g} no es un número`,notAnInteger:({label:g})=>`${g} no es un número entero`,notABoolean:({label:g})=>`${g} no es un valor verdadero o falso`,notAnEmail:({label:g})=>`${g} no es un email`,notAnId:({label:g})=>`${g} no es un ID válido`,notADate:({label:g})=>`${g} no es una fecha válida`,notAnArray:({label:g})=>`${g} no es un arreglo`,notAnObject:({label:g})=>`${g} no es un objeto`,stringTooShort:({label:g})=>`${g} no tiene el largo suficiente`,stringTooLong:"El largo es mayor al permitido",numberTooSmall:({label:g})=>`${g} es un número muy pequeño`,numberTooBig:({label:g})=>`${g} es un número muy grande`,notInSchema:({label:g})=>`${g} no esta permitido`,notUnique:({label:g})=>`${g} no es único`,notFound:({label:g})=>`${g} no se encontró`,invalid:"No es válido",rateLimitExceeded:"Has excedido el límite de intentos. Intenta de nuevo más tarde.",incorrectLoginCode:"El código es incorrecto",loginCodeExpired:"El código expiró. Solicita un nuevo",loginCodeLocked:"El código se bloqueó. Genera un nuevo código para continuar",userNotFound:"No existe una cuenta con este email"};function ig(g,m){let q=Qg[g];if(!q)return`${m}: ${g}`;if(typeof q==="function")return q({label:m});return q}function Rg(g){return Object.entries(g).map(([m,q])=>ig(q,m)).join(", ")}function lg(g){if(g.error==="validationError"&&g.validationErrors)return Rg(g.validationErrors);if(g.extensions?.code==="PermissionsError"){let j=g.extensions.info?.type;if(j?.includes("User doesn't have permissions for "))return`Tu usuario no tiene permisos para [${j.split("User doesn't have permissions for ")[1]}]`;return g.message}if(g.validationErrors)return`${g.message} (${Rg(g.validationErrors)})`;let m=g.message||"Error desconocido",q=Qg[m];if(q)return typeof q==="function"?q({label:""}).trim():q;let $=g.error||g.code||g.type;return $?`${m} [${$}]`:m}function dg(g){try{return JSON.parse(Buffer.from(g.split(".")[1],"base64").toString()).exp*1000<Date.now()}catch{return!0}}async function pg(){let g=f();if(!g?.refreshToken)return null;let m=`${s("auth")}/refresh-token`,$=await(await fetch(m,{method:"POST",headers:{"X-ORION-REFRESH":g.refreshToken}})).json();if(!$.token)return null;return K({...g,token:$.token}),$.token}async function ug(){let g=f();if(!g?.token)return;if(!dg(g.token))return g.token;return await pg()??void 0}async function N(g){let m=`${s(g.service)}/graphql`,q=await ug(),$={"Content-Type":"application/json","X-ORION-DEVICEID":og(),"X-ORION-PLATFORM":"web"};if(q)$["x-orion-jwt"]=q;let j;try{j=await fetch(m,{method:"POST",headers:$,body:JSON.stringify({query:g.query,variables:g.variables}),signal:AbortSignal.timeout(15000)})}catch{throw Error("La solicitud tardó demasiado. Intenta de nuevo.")}let C=await j.json();if(C.errors?.length)throw Error(lg(C.errors[0]));if(!C.data)throw Error("No data returned from server");return C.data}import{createInterface as ag}from"node:readline";function p(g){let m=ag({input:process.stdin,output:process.stdout});return new Promise((q)=>{m.question(g,($)=>{m.close(),q($.trim())})})}async function wg(g){return(await N({service:"auth",query:`mutation ($email: String!) {
|
|
3
|
+
requestLoginCode(email: $email)
|
|
4
|
+
}`,variables:{email:g}})).requestLoginCode}async function Wg(g,m,q){let $=await N({service:"auth",query:`mutation ($email: String!, $token: String!, $code: String!) {
|
|
5
|
+
loginWithCode(email: $email, token: $token, code: $code) {
|
|
6
|
+
token
|
|
7
|
+
refreshToken
|
|
8
|
+
}
|
|
9
|
+
}`,variables:{email:g,token:m,code:q.toUpperCase()}});K({email:g,token:$.loginWithCode.token,refreshToken:$.loginWithCode.refreshToken}),await ng(),console.log(`Sesión iniciada como ${g}`)}async function ng(){if(!(await N({service:"main",query:"query { me { roles } }"})).me?.roles?.length)throw d(),Error("Solo miembros del equipo Justo pueden usar esta herramienta.")}async function Ng(){let g=await p("Email: ");console.log("Enviando código de verificación...");let m=await wg(g);console.log("Código enviado a tu email.");let q=await p("Código: ");await Wg(g,m,q)}async function fg(g){let m=H(g,"email"),q=H(g,"token"),$=H(g,"code");await Wg(m,q,$)}async function Ug(g){let m=H(g,"email");console.log("Enviando código de verificación...");let q=await wg(m);console.log(`Código enviado a ${m}`),console.log(`Token: ${q}`),console.log(""),console.log("Ahora ejecuta:"),console.log(` npx @getjusto/team-cli auth login-with-token --email ${m} --token ${q} --code <CÓDIGO>`)}async function Xg(){d(),console.log("Sesión cerrada.")}async function Zg(){let g=f();if(!g){console.log("No hay sesión activa."),console.log("Usa: npx @getjusto/team-cli@latest auth login");return}console.log(`Sesión activa: ${g.email}`)}function u(){console.log(`
|
|
10
|
+
team-cli auth - Gestión de sesión
|
|
11
|
+
|
|
12
|
+
Comandos:
|
|
13
|
+
login Iniciar sesión (interactivo, pide email y código)
|
|
14
|
+
logout Cerrar sesión
|
|
15
|
+
status Ver sesión actual
|
|
16
|
+
|
|
17
|
+
Modo no interactivo:
|
|
18
|
+
Primero solicita un código, luego úsalo para iniciar sesión:
|
|
19
|
+
|
|
20
|
+
1. request-code --email <email>
|
|
21
|
+
2. login-with-token --email <email> --token <token> --code <código>
|
|
22
|
+
`)}var tg={comma:",",tab:"\t",pipe:"|"},y=tg.comma;function Jg(g){return g.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function eg(g){return g==="true"||g==="false"||g==="null"}function E(g){if(g===null)return null;if(typeof g==="object"&&g!==null&&"toJSON"in g&&typeof g.toJSON==="function"){let m=g.toJSON();if(m!==g)return E(m)}if(typeof g==="string"||typeof g==="boolean")return g;if(typeof g==="number"){if(Object.is(g,-0))return 0;if(!Number.isFinite(g))return null;return g}if(typeof g==="bigint"){if(g>=Number.MIN_SAFE_INTEGER&&g<=Number.MAX_SAFE_INTEGER)return Number(g);return g.toString()}if(g instanceof Date)return g.toISOString();if(Array.isArray(g))return g.map(E);if(g instanceof Set)return Array.from(g).map(E);if(g instanceof Map)return Object.fromEntries(Array.from(g,([m,q])=>[String(m),E(q)]));if(gm(g)){let m={};for(let q in g)if(Object.prototype.hasOwnProperty.call(g,q))m[q]=E(g[q]);return m}return null}function T(g){return g===null||typeof g==="string"||typeof g==="number"||typeof g==="boolean"}function S(g){return Array.isArray(g)}function U(g){return g!==null&&typeof g==="object"&&!Array.isArray(g)}function I(g){return Object.keys(g).length===0}function gm(g){if(g===null||typeof g!=="object")return!1;let m=Object.getPrototypeOf(g);return m===null||m===Object.prototype}function c(g){return g.length===0||g.every((m)=>T(m))}function mm(g){return g.length===0||g.every((m)=>S(m))}function _g(g){return g.length===0||g.every((m)=>U(m))}function qm(g){return/^[A-Z_][\w.]*$/i.test(g)}function $m(g){return/^[A-Z_]\w*$/i.test(g)}function jm(g,m=y){if(!g)return!1;if(g!==g.trim())return!1;if(eg(g)||Cm(g))return!1;if(g.includes(":"))return!1;if(g.includes('"')||g.includes("\\"))return!1;if(/[[\]{}]/.test(g))return!1;if(/[\n\r\t]/.test(g))return!1;if(g.includes(m))return!1;if(g.startsWith("-"))return!1;return!0}function Cm(g){return/^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i.test(g)||/^0\d+$/.test(g)}var om=Symbol("quotedKey");function Gm(g,m,q,$,j,C,G){if($.keyFolding!=="safe")return;if(!U(m))return;let{segments:R,tail:Q,leafValue:J}=Rm(g,m,G??$.flattenDepth);if(R.length<2)return;if(!R.every((_)=>$m(_)))return;let X=Qm(R),Z=C?`${C}.${X}`:X;if(q.includes(X))return;if(j&&j.has(Z))return;return{foldedKey:X,remainder:Q,leafValue:J,segmentCount:R.length}}function Rm(g,m,q){let $=[g],j=m;while($.length<q){if(!U(j))break;let C=Object.keys(j);if(C.length!==1)break;let G=C[0],R=j[G];$.push(G),j=R}if(!U(j)||I(j))return{segments:$,tail:void 0,leafValue:j};return{segments:$,tail:j,leafValue:j}}function Qm(g){return g.join(".")}function O(g,m){if(g===null)return"null";if(typeof g==="boolean")return String(g);if(typeof g==="number")return String(g);return wm(g,m)}function wm(g,m=y){if(jm(g,m))return g;return`"${Jg(g)}"`}function b(g){if(qm(g))return g;return`"${Jg(g)}"`}function Eg(g,m=y){return g.map((q)=>O(q,m)).join(m)}function M(g,m){let q=m?.key,$=m?.fields,j=m?.delimiter??",",C="";if(q)C+=b(q);if(C+=`[${g}${j!==y?j:""}]`,$){let G=$.map((R)=>b(R));C+=`{${G.join(j)}}`}return C+=":",C}function*Wm(g,m,q){if(T(g)){let $=O(g,m.delimiter);if($!=="")yield $;return}if(S(g))yield*a(void 0,g,q,m);else if(U(g))yield*z(g,q,m)}function*z(g,m,q,$,j,C){let G=Object.keys(g);if(m===0&&!$)$=new Set(G.filter((Q)=>Q.includes(".")));let R=C??q.flattenDepth;for(let[Q,J]of Object.entries(g))yield*Nm(Q,J,m,q,G,$,j,R)}function*Nm(g,m,q,$,j,C,G,R){let Q=G?`${G}.${g}`:g,J=R??$.flattenDepth;if($.keyFolding==="safe"&&j){let Z=Gm(g,m,j,$,C,G,J);if(Z){let{foldedKey:_,remainder:P,leafValue:A,segmentCount:Ig}=Z,L=b(_);if(P===void 0){if(T(A)){yield W(q,`${L}: ${O(A,$.delimiter)}`,$.indent);return}else if(S(A)){yield*a(_,A,q,$);return}else if(U(A)&&I(A)){yield W(q,`${L}:`,$.indent);return}}if(U(P)){yield W(q,`${L}:`,$.indent);let cg=J-Ig,bg=G?`${G}.${_}`:_;yield*z(P,q+1,$,C,bg,cg);return}}}let X=b(g);if(T(m))yield W(q,`${X}: ${O(m,$.delimiter)}`,$.indent);else if(S(m))yield*a(g,m,q,$);else if(U(m)){if(yield W(q,`${X}:`,$.indent),!I(m))yield*z(m,q+1,$,C,Q,J)}}function*a(g,m,q,$){if(m.length===0){yield W(q,M(0,{key:g,delimiter:$.delimiter}),$.indent);return}if(c(m)){yield W(q,k(m,$.delimiter,g),$.indent);return}if(mm(m)){if(m.every((j)=>c(j))){yield*fm(g,m,q,$);return}}if(_g(m)){let j=Mg(m);if(j)yield*Um(g,m,j,q,$);else yield*Yg(g,m,q,$);return}yield*Yg(g,m,q,$)}function*fm(g,m,q,$){yield W(q,M(m.length,{key:g,delimiter:$.delimiter}),$.indent);for(let j of m)if(c(j)){let C=k(j,$.delimiter);yield Y(q+1,C,$.indent)}}function k(g,m,q){let $=M(g.length,{key:q,delimiter:m}),j=Eg(g,m);if(g.length===0)return $;return`${$} ${j}`}function*Um(g,m,q,$,j){yield W($,M(m.length,{key:g,fields:q,delimiter:j.delimiter}),j.indent),yield*Bg(m,q,$+1,j)}function Mg(g){if(g.length===0)return;let m=g[0],q=Object.keys(m);if(q.length===0)return;if(Xm(g,q))return q}function Xm(g,m){for(let q of g){if(Object.keys(q).length!==m.length)return!1;for(let $ of m){if(!($ in q))return!1;if(!T(q[$]))return!1}}return!0}function*Bg(g,m,q,$){for(let j of g)yield W(q,Eg(m.map((C)=>j[C]),$.delimiter),$.indent)}function*Yg(g,m,q,$){yield W(q,M(m.length,{key:g,delimiter:$.delimiter}),$.indent);for(let j of m)yield*n(j,q+1,$)}function*Zm(g,m,q){if(I(g)){yield W(m,"-",q.indent);return}let $=Object.entries(g),[j,C]=$[0],G=$.slice(1);if(S(C)&&_g(C)){let Q=Mg(C);if(Q){if(yield Y(m,M(C.length,{key:j,fields:Q,delimiter:q.delimiter}),q.indent),yield*Bg(C,Q,m+2,q),G.length>0)yield*z(Object.fromEntries(G),m+1,q);return}}let R=b(j);if(T(C))yield Y(m,`${R}: ${O(C,q.delimiter)}`,q.indent);else if(S(C))if(C.length===0)yield Y(m,`${R}${M(0,{delimiter:q.delimiter})}`,q.indent);else if(c(C))yield Y(m,`${R}${k(C,q.delimiter)}`,q.indent);else{yield Y(m,`${R}${M(C.length,{delimiter:q.delimiter})}`,q.indent);for(let Q of C)yield*n(Q,m+2,q)}else if(U(C)){if(yield Y(m,`${R}:`,q.indent),!I(C))yield*z(C,m+2,q)}if(G.length>0)yield*z(Object.fromEntries(G),m+1,q)}function*n(g,m,q){if(T(g))yield Y(m,O(g,q.delimiter),q.indent);else if(S(g))if(c(g))yield Y(m,k(g,q.delimiter),q.indent);else{yield Y(m,M(g.length,{delimiter:q.delimiter}),q.indent);for(let $ of g)yield*n($,m+1,q)}else if(U(g))yield*Zm(g,m,q)}function W(g,m,q){return" ".repeat(q*g)+m}function Y(g,m,q){return W(g,"- "+m,q)}function Ym(g,m){let q=m("",g,[]);if(q===void 0)return x(g,m,[]);return x(E(q),m,[])}function x(g,m,q){if(U(g))return Jm(g,m,q);if(S(g))return _m(g,m,q);return g}function Jm(g,m,q){let $={};for(let[j,C]of Object.entries(g)){let G=[...q,j],R=m(j,C,G);if(R===void 0)continue;$[j]=x(E(R),m,G)}return $}function _m(g,m,q){let $=[];for(let j=0;j<g.length;j++){let C=g[j],G=[...q,j],R=m(String(j),C,G);if(R===void 0)continue;let Q=E(R);$.push(x(Q,m,G))}return $}function V(g,m){return Array.from(Em(g,m)).join(`
|
|
23
|
+
`)}function Em(g,m){let q=E(g),$=Mm(m);return Wm($.replacer?Ym(q,$.replacer):q,$,0)}function Mm(g){return{indent:g?.indent??2,delimiter:g?.delimiter??y,keyFolding:g?.keyFolding??"off",flattenDepth:g?.flattenDepth??Number.POSITIVE_INFINITY,replacer:g?.replacer}}var t=["main","auth","webdata","preferences","buckets","reservations","data","finances","url-shortener","files","tabs","commander","experiments","sales","delivery","payments","addresses","royalty","marketing","api","messenger","invoice","drivers-server"];async function Ag(g,m){let q=g[1],$=g[2],j=m.format||"toon";if(!f())throw Error("Debes iniciar sesión primero. Usa: team-cli auth login");if(!q||!$)e(),process.exit(1);if(!t.includes(q))console.error(`Error: servicio "${q}" no válido.`),console.error(`Servicios disponibles: ${t.join(", ")}`),process.exit(1);let C;if(m.variables)try{C=JSON.parse(m.variables)}catch{throw Error("Las variables deben ser un JSON válido.")}let G=await N({service:q,query:$,variables:C});if(j==="json")console.log(JSON.stringify(G,null,2));else console.log(V(G))}function e(){console.log(`
|
|
24
|
+
team-cli graphql - Ejecutar queries y mutations GraphQL
|
|
25
|
+
|
|
26
|
+
Uso:
|
|
27
|
+
team-cli graphql <servicio> '<query>' [--variables '<json>'] [--format toon|json]
|
|
28
|
+
|
|
29
|
+
Ejemplos:
|
|
30
|
+
team-cli graphql main 'query { me { _id roles } }'
|
|
31
|
+
team-cli graphql main 'query($id: ID) { user(userId: $id) { _id } }' --variables '{"id": "abc123"}'
|
|
32
|
+
team-cli graphql main 'query { me { _id } }' --format json
|
|
33
|
+
|
|
34
|
+
El formato por defecto es TOON. Usa --format json para obtener JSON.
|
|
35
|
+
|
|
36
|
+
Servicios disponibles:
|
|
37
|
+
${t.join(", ")}
|
|
38
|
+
`)}import{writeFileSync as Bm}from"node:fs";function r(){if(!f())throw Error("Debes iniciar sesión primero. Usa: team-cli auth login")}function D(g,m){let q=g[3];if(!q)console.error(`Uso: ${m}`),process.exit(1);return q}function Sg(g){if(!g.params)return{};try{return JSON.parse(g.params)}catch{throw Error("--params debe ser un JSON válido.")}}function Fg(g,m){if((m.format||"toon")==="json")console.log(typeof g==="string"?g:JSON.stringify(g,null,2));else{let $=typeof g==="string"?JSON.parse(g):g;console.log(V($))}}async function Tg(g,m){r();let q=D(g,"team-cli data queries view <queryId>"),$=await N({service:"data",query:`query ($aggregationQueryId: String) {
|
|
39
|
+
aggregationQuery(aggregationQueryId: $aggregationQueryId) {
|
|
40
|
+
_id
|
|
41
|
+
name
|
|
42
|
+
description
|
|
43
|
+
collection
|
|
44
|
+
currentVersionIndex
|
|
45
|
+
variables {
|
|
46
|
+
key
|
|
47
|
+
fieldType
|
|
48
|
+
fieldParams
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}`,variables:{aggregationQueryId:q}});Fg($.aggregationQuery,m)}async function zg(g,m){r();let q=D(g,"team-cli data queries view-pipeline <queryId>"),$=await N({service:"data",query:`query ($aggregationQueryId: String) {
|
|
52
|
+
aggregationQuery(aggregationQueryId: $aggregationQueryId) {
|
|
53
|
+
pipeline
|
|
54
|
+
}
|
|
55
|
+
}`,variables:{aggregationQueryId:q}});console.log($.aggregationQuery.pipeline)}async function Og(g,m){r();let q=D(g,"team-cli data queries preview <queryId> --params '<json>'"),$=Sg(m),j=await N({service:"data",query:`mutation ($aggregationQueryId: String, $params: JSON) {
|
|
56
|
+
testAggregationQuery(aggregationQueryId: $aggregationQueryId, params: $params)
|
|
57
|
+
}`,variables:{aggregationQueryId:q,params:$}});Fg(j.testAggregationQuery,m)}function Am(g){return new Promise((m)=>setTimeout(m,g))}async function Pg(g,m){r();let q=D(g,"team-cli data queries download <queryId> --params '<json>'"),$=Sg(m);if(!m.path)throw Error("--path es requerido. Ejemplo: --path resultado.xlsx");let j=m.path;console.log("Iniciando descarga...");let G=(await N({service:"data",query:`mutation ($aggregationQueryId: String, $params: JSON) {
|
|
58
|
+
downloadAggregationQueryData(aggregationQueryId: $aggregationQueryId, params: $params)
|
|
59
|
+
}`,variables:{aggregationQueryId:q,params:$}})).downloadAggregationQueryData;console.log(`Reporte en proceso (${G})...`);let R=null;while(!R){await Am(1000);let X=await N({service:"data",query:`query ($id: String) {
|
|
60
|
+
getAsyncReport(id: $id) {
|
|
61
|
+
_id
|
|
62
|
+
status
|
|
63
|
+
estimatedRecordsCount
|
|
64
|
+
fileUrl
|
|
65
|
+
}
|
|
66
|
+
getAsyncReportRecordsCount(id: $id)
|
|
67
|
+
}`,variables:{id:G}}),Z=X.getAsyncReport,_=X.getAsyncReportRecordsCount;if(Z.status==="error")throw Error("El reporte falló al generarse.");if(Z.fileUrl)R=Z.fileUrl;else{let P=Z.estimatedRecordsCount?` (~${Z.estimatedRecordsCount} registros)`:"",A=_!=null?` ${_} procesados`:"";process.stdout.write(`\rGenerando...${P}${A}`)}}process.stdout.write(`
|
|
68
|
+
`),console.log("Descargando archivo...");let Q=await fetch(R);if(!Q.ok)throw Error(`Error descargando archivo: ${Q.status}`);let J=Buffer.from(await Q.arrayBuffer());Bm(j,J),console.log(`Archivo guardado en ${j}`)}function gg(){console.log(`
|
|
69
|
+
team-cli data - Comandos de datos y reportes
|
|
70
|
+
|
|
71
|
+
Uso:
|
|
72
|
+
team-cli data queries <subcomando> [opciones]
|
|
73
|
+
|
|
74
|
+
Subcomandos:
|
|
75
|
+
view <queryId> Ver información de un query
|
|
76
|
+
view-pipeline <queryId> Ver el pipeline de un query
|
|
77
|
+
preview <queryId> Ejecutar un query de prueba (max 100 filas)
|
|
78
|
+
download <queryId> Descargar resultado completo como Excel
|
|
79
|
+
|
|
80
|
+
Opciones:
|
|
81
|
+
--params '<json>' Parámetros del query (default: {})
|
|
82
|
+
--format toon|json Formato de salida para view/preview (default: toon)
|
|
83
|
+
--path <filepath> Ruta del archivo de descarga (requerido para download)
|
|
84
|
+
|
|
85
|
+
Ejemplos:
|
|
86
|
+
team-cli data queries view abc123
|
|
87
|
+
team-cli data queries view-pipeline abc123
|
|
88
|
+
team-cli data queries preview abc123 --params '{"startDate": "2026-01-01"}'
|
|
89
|
+
team-cli data queries download abc123 --params '{"startDate": "2026-01-01"}' --path resultado.xlsx
|
|
90
|
+
`)}var{positional:B,flags:w}=$g(process.argv.slice(2));if(w.env)mg(w.env);var v=B[0],F=B[1];function Hg(){let g=f(),m=g?`Sesión: ${g.email}`:"Sesión: no iniciada";console.log(`
|
|
91
|
+
team-cli - Herramienta CLI para el equipo Justo
|
|
92
|
+
|
|
93
|
+
${m}
|
|
94
|
+
|
|
95
|
+
Uso:
|
|
96
|
+
team-cli <comando> [opciones]
|
|
97
|
+
|
|
98
|
+
Comandos:
|
|
99
|
+
auth Gestión de sesión
|
|
100
|
+
graphql Ejecutar queries/mutations GraphQL
|
|
101
|
+
data Datos y reportes
|
|
102
|
+
|
|
103
|
+
Opciones globales:
|
|
104
|
+
--env <local|develop|prod> Seleccionar ambiente (default: prod)
|
|
105
|
+
--version Muestra la versión
|
|
106
|
+
--help Muestra la ayuda
|
|
107
|
+
`)}async function Sm(){try{if(w.version)console.log("0.0.1");else if(w.help&&!v)Hg();else if(v==="auth")if(F==="--help"||w.help)u();else if(F==="login")await Ng();else if(F==="login-with-token")await fg(w);else if(F==="request-code")await Ug(w);else if(F==="logout")await Xg();else if(F==="status")await Zg();else u();else if(v==="graphql")if(F==="--help"||w.help)e();else await Ag(B,w);else if(v==="data"){let g=B[1],m=B[2];if(w.help||F==="--help")gg();else if(g==="queries"&&m==="view")await Tg(B,w);else if(g==="queries"&&m==="view-pipeline")await zg(B,w);else if(g==="queries"&&m==="preview")await Og(B,w);else if(g==="queries"&&m==="download")await Pg(B,w);else gg()}else Hg()}catch(g){console.error(`Error: ${g instanceof Error?g.message:g}`),process.exit(1)}}Sm();
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getjusto/team-cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "CLI tool for Justo team members",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"team-cli": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"dev": "bun run src/index.ts",
|
|
14
|
+
"build": "bun build src/index.ts --outfile bin/cli.js --target node --minify",
|
|
15
|
+
"compile": "bun build src/index.ts --compile --outfile dist/team-cli"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/bun": "latest"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@toon-format/toon": "^2.1.0"
|
|
22
|
+
}
|
|
23
|
+
}
|