@getjusto/team-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/bin/cli.js +94 -14
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
2
|
+
var sg={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"}},v="prod";function mg(g){v=g}function qg(){return v}function D(g){return sg[g][v]}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 w=g[j].slice(2);if(q[w]=g[j+1],!$[w])$[w]=[];$[w].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 b(g,m){let q=g[m];if(!q)console.error(`Error: --${m} es requerido.`),process.exit(1);return q}import{existsSync as l,mkdirSync as yg,readFileSync as xg,writeFileSync as Kg,unlinkSync as og}from"node:fs";import{join as jg}from"node:path";import{homedir as ig}from"node:os";var h=jg(ig(),".justo-team");function L(){let g=qg(),m=g==="prod"?"credentials.json":`credentials.${g}.json`;return jg(h,m)}function kg(){if(!l(h))yg(h,{recursive:!0})}function y(g){kg(),Kg(L(),JSON.stringify(g,null,2))}function W(){let g=L();if(!l(g))return null;try{let m=xg(g,"utf-8");return JSON.parse(m)}catch{return null}}function d(){let g=L();if(l(g))og(g)}import{existsSync as wg,readFileSync as Vg,writeFileSync as vg,mkdirSync as Dg}from"node:fs";import{join as fg}from"node:path";import{homedir as hg}from"node:os";function lg(){let g=fg(hg(),".justo-team"),m=fg(g,"device-id");if(wg(m))return Vg(m,"utf-8").trim();let q=crypto.randomUUID();if(!wg(g))Dg(g,{recursive:!0});return vg(m,q),q}var Gg={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 Lg(g,m){let q=Gg[g];if(!q)return`${m}: ${g}`;if(typeof q==="function")return q({label:m});return q}function Cg(g){return Object.entries(g).map(([m,q])=>Lg(q,m)).join(", ")}function dg(g){if(g.error==="validationError"&&g.validationErrors)return Cg(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} (${Cg(g.validationErrors)})`;let m=g.message||"Error desconocido",q=Gg[m];if(q)return typeof q==="function"?q({label:""}).trim():q;let $=g.error||g.code||g.type;return $?`${m} [${$}]`:m}function ag(g){try{return JSON.parse(Buffer.from(g.split(".")[1],"base64").toString()).exp*1000<Date.now()}catch{return!0}}async function pg(){let g=W();if(!g?.refreshToken)return null;let m=`${D("auth")}/refresh-token`,$=await(await fetch(m,{method:"POST",headers:{"X-ORION-REFRESH":g.refreshToken}})).json();if(!$.token)return null;return y({...g,token:$.token}),$.token}async function ug(){let g=W();if(!g?.token)return;if(!ag(g.token))return g.token;return await pg()??void 0}async function N(g){let m=`${D(g.service)}/graphql`,q=await ug(),$={"Content-Type":"application/json","X-ORION-DEVICEID":lg(),"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 w=await j.json();if(w.errors?.length)throw Error(dg(w.errors[0]));if(!w.data)throw Error("No data returned from server");return w.data}import{createInterface as ng}from"node:readline";function a(g){let m=ng({input:process.stdin,output:process.stdout});return new Promise((q)=>{m.question(g,($)=>{m.close(),q($.trim())})})}async function Rg(g){return(await N({service:"auth",query:`mutation ($email: String!) {
|
|
3
3
|
requestLoginCode(email: $email)
|
|
4
|
-
}`,variables:{email:g}})).requestLoginCode}async function
|
|
4
|
+
}`,variables:{email:g}})).requestLoginCode}async function Qg(g,m,q){let $=await N({service:"auth",query:`mutation ($email: String!, $token: String!, $code: String!) {
|
|
5
5
|
loginWithCode(email: $email, token: $token, code: $code) {
|
|
6
6
|
token
|
|
7
7
|
refreshToken
|
|
8
8
|
}
|
|
9
|
-
}`,variables:{email:g,token:m,code:q.toUpperCase()}});
|
|
9
|
+
}`,variables:{email:g,token:m,code:q.toUpperCase()}});y({email:g,token:$.loginWithCode.token,refreshToken:$.loginWithCode.refreshToken}),await tg(),console.log(`Sesión iniciada como ${g}`)}async function tg(){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 a("Email: ");console.log("Enviando código de verificación...");let m=await Rg(g);console.log("Código enviado a tu email.");let q=await a("Código: ");await Qg(g,m,q)}async function Wg(g){let m=b(g,"email"),q=b(g,"token"),$=b(g,"code");await Qg(m,q,$)}async function Ug(g){let m=b(g,"email");console.log("Enviando código de verificación...");let q=await Rg(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 rg(){d(),console.log("Sesión cerrada.")}async function Xg(){let g=W();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 p(){console.log(`
|
|
10
10
|
team-cli auth - Gestión de sesión
|
|
11
11
|
|
|
12
12
|
Comandos:
|
|
@@ -19,8 +19,8 @@ var yg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",pr
|
|
|
19
19
|
|
|
20
20
|
1. request-code --email <email>
|
|
21
21
|
2. login-with-token --email <email> --token <token> --code <código>
|
|
22
|
-
`)}var
|
|
23
|
-
`)}function Em(g,m){let q=
|
|
22
|
+
`)}var eg={comma:",",tab:"\t",pipe:"|"},H=eg.comma;function Yg(g){return g.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function gm(g){return g==="true"||g==="false"||g==="null"}function _(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 _(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(_);if(g instanceof Set)return Array.from(g).map(_);if(g instanceof Map)return Object.fromEntries(Array.from(g,([m,q])=>[String(m),_(q)]));if(mm(g)){let m={};for(let q in g)if(Object.prototype.hasOwnProperty.call(g,q))m[q]=_(g[q]);return m}return null}function S(g){return g===null||typeof g==="string"||typeof g==="number"||typeof g==="boolean"}function A(g){return Array.isArray(g)}function U(g){return g!==null&&typeof g==="object"&&!Array.isArray(g)}function z(g){return Object.keys(g).length===0}function mm(g){if(g===null||typeof g!=="object")return!1;let m=Object.getPrototypeOf(g);return m===null||m===Object.prototype}function I(g){return g.length===0||g.every((m)=>S(m))}function qm(g){return g.length===0||g.every((m)=>A(m))}function Jg(g){return g.length===0||g.every((m)=>U(m))}function $m(g){return/^[A-Z_][\w.]*$/i.test(g)}function jm(g){return/^[A-Z_]\w*$/i.test(g)}function wm(g,m=H){if(!g)return!1;if(g!==g.trim())return!1;if(gm(g)||fm(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 fm(g){return/^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i.test(g)||/^0\d+$/.test(g)}var lm=Symbol("quotedKey");function Cm(g,m,q,$,j,w,f){if($.keyFolding!=="safe")return;if(!U(m))return;let{segments:C,tail:G,leafValue:Y}=Gm(g,m,f??$.flattenDepth);if(C.length<2)return;if(!C.every((J)=>jm(J)))return;let r=Rm(C),X=w?`${w}.${r}`:r;if(q.includes(r))return;if(j&&j.has(X))return;return{foldedKey:r,remainder:G,leafValue:Y,segmentCount:C.length}}function Gm(g,m,q){let $=[g],j=m;while($.length<q){if(!U(j))break;let w=Object.keys(j);if(w.length!==1)break;let f=w[0],C=j[f];$.push(f),j=C}if(!U(j)||z(j))return{segments:$,tail:void 0,leafValue:j};return{segments:$,tail:j,leafValue:j}}function Rm(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 Qm(g,m)}function Qm(g,m=H){if(wm(g,m))return g;return`"${Yg(g)}"`}function P(g){if($m(g))return g;return`"${Yg(g)}"`}function _g(g,m=H){return g.map((q)=>O(q,m)).join(m)}function E(g,m){let q=m?.key,$=m?.fields,j=m?.delimiter??",",w="";if(q)w+=P(q);if(w+=`[${g}${j!==H?j:""}]`,$){let f=$.map((C)=>P(C));w+=`{${f.join(j)}}`}return w+=":",w}function*Nm(g,m,q){if(S(g)){let $=O(g,m.delimiter);if($!=="")yield $;return}if(A(g))yield*u(void 0,g,q,m);else if(U(g))yield*T(g,q,m)}function*T(g,m,q,$,j,w){let f=Object.keys(g);if(m===0&&!$)$=new Set(f.filter((G)=>G.includes(".")));let C=w??q.flattenDepth;for(let[G,Y]of Object.entries(g))yield*Wm(G,Y,m,q,f,$,j,C)}function*Wm(g,m,q,$,j,w,f,C){let G=f?`${f}.${g}`:g,Y=C??$.flattenDepth;if($.keyFolding==="safe"&&j){let X=Cm(g,m,j,$,w,f,Y);if(X){let{foldedKey:J,remainder:F,leafValue:M,segmentCount:Ig}=X,V=P(J);if(F===void 0){if(S(M)){yield Q(q,`${V}: ${O(M,$.delimiter)}`,$.indent);return}else if(A(M)){yield*u(J,M,q,$);return}else if(U(M)&&z(M)){yield Q(q,`${V}:`,$.indent);return}}if(U(F)){yield Q(q,`${V}:`,$.indent);let Pg=Y-Ig,Hg=f?`${f}.${J}`:J;yield*T(F,q+1,$,w,Hg,Pg);return}}}let r=P(g);if(S(m))yield Q(q,`${r}: ${O(m,$.delimiter)}`,$.indent);else if(A(m))yield*u(g,m,q,$);else if(U(m)){if(yield Q(q,`${r}:`,$.indent),!z(m))yield*T(m,q+1,$,w,G,Y)}}function*u(g,m,q,$){if(m.length===0){yield Q(q,E(0,{key:g,delimiter:$.delimiter}),$.indent);return}if(I(m)){yield Q(q,K(m,$.delimiter,g),$.indent);return}if(qm(m)){if(m.every((j)=>I(j))){yield*Um(g,m,q,$);return}}if(Jg(m)){let j=Eg(m);if(j)yield*rm(g,m,j,q,$);else yield*Zg(g,m,q,$);return}yield*Zg(g,m,q,$)}function*Um(g,m,q,$){yield Q(q,E(m.length,{key:g,delimiter:$.delimiter}),$.indent);for(let j of m)if(I(j)){let w=K(j,$.delimiter);yield Z(q+1,w,$.indent)}}function K(g,m,q){let $=E(g.length,{key:q,delimiter:m}),j=_g(g,m);if(g.length===0)return $;return`${$} ${j}`}function*rm(g,m,q,$,j){yield Q($,E(m.length,{key:g,fields:q,delimiter:j.delimiter}),j.indent),yield*cg(m,q,$+1,j)}function Eg(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(!S(q[$]))return!1}}return!0}function*cg(g,m,q,$){for(let j of g)yield Q(q,_g(m.map((w)=>j[w]),$.delimiter),$.indent)}function*Zg(g,m,q,$){yield Q(q,E(m.length,{key:g,delimiter:$.delimiter}),$.indent);for(let j of m)yield*n(j,q+1,$)}function*Zm(g,m,q){if(z(g)){yield Q(m,"-",q.indent);return}let $=Object.entries(g),[j,w]=$[0],f=$.slice(1);if(A(w)&&Jg(w)){let G=Eg(w);if(G){if(yield Z(m,E(w.length,{key:j,fields:G,delimiter:q.delimiter}),q.indent),yield*cg(w,G,m+2,q),f.length>0)yield*T(Object.fromEntries(f),m+1,q);return}}let C=P(j);if(S(w))yield Z(m,`${C}: ${O(w,q.delimiter)}`,q.indent);else if(A(w))if(w.length===0)yield Z(m,`${C}${E(0,{delimiter:q.delimiter})}`,q.indent);else if(I(w))yield Z(m,`${C}${K(w,q.delimiter)}`,q.indent);else{yield Z(m,`${C}${E(w.length,{delimiter:q.delimiter})}`,q.indent);for(let G of w)yield*n(G,m+2,q)}else if(U(w)){if(yield Z(m,`${C}:`,q.indent),!z(w))yield*T(w,m+2,q)}if(f.length>0)yield*T(Object.fromEntries(f),m+1,q)}function*n(g,m,q){if(S(g))yield Z(m,O(g,q.delimiter),q.indent);else if(A(g))if(I(g))yield Z(m,K(g,q.delimiter),q.indent);else{yield Z(m,E(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 Q(g,m,q){return" ".repeat(q*g)+m}function Z(g,m,q){return Q(g,"- "+m,q)}function Ym(g,m){let q=m("",g,[]);if(q===void 0)return x(g,m,[]);return x(_(q),m,[])}function x(g,m,q){if(U(g))return Jm(g,m,q);if(A(g))return _m(g,m,q);return g}function Jm(g,m,q){let $={};for(let[j,w]of Object.entries(g)){let f=[...q,j],C=m(j,w,f);if(C===void 0)continue;$[j]=x(_(C),m,f)}return $}function _m(g,m,q){let $=[];for(let j=0;j<g.length;j++){let w=g[j],f=[...q,j],C=m(String(j),w,f);if(C===void 0)continue;let G=_(C);$.push(x(G,m,f))}return $}function o(g,m){return Array.from(Em(g,m)).join(`
|
|
23
|
+
`)}function Em(g,m){let q=_(g),$=cm(m);return Nm($.replacer?Ym(q,$.replacer):q,$,0)}function cm(g){return{indent:g?.indent??2,delimiter:g?.delimiter??H,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 Mg(g,m){let q=g[1],$=g[2],j=m.format||"toon";if(!W())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 w;if(m.variables)try{w=JSON.parse(m.variables)}catch{throw Error("Las variables deben ser un JSON válido.")}let f=await N({service:q,query:$,variables:w});if(j==="json")console.log(JSON.stringify(f,null,2));else console.log(o(f))}function e(){console.log(`
|
|
24
24
|
team-cli graphql - Ejecutar queries y mutations GraphQL
|
|
25
25
|
|
|
26
26
|
Uso:
|
|
@@ -35,7 +35,7 @@ var yg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",pr
|
|
|
35
35
|
|
|
36
36
|
Servicios disponibles:
|
|
37
37
|
${t.join(", ")}
|
|
38
|
-
`)}import{writeFileSync as
|
|
38
|
+
`)}import{writeFileSync as Mm}from"node:fs";function i(){if(!W())throw Error("Debes iniciar sesión primero. Usa: team-cli auth login")}function k(g,m){let q=g[3];if(!q)console.error(`Uso: ${m}`),process.exit(1);return q}function Ag(g){if(!g.params)return{};try{return JSON.parse(g.params)}catch{throw Error("--params debe ser un JSON válido.")}}function Bg(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(o($))}}async function Sg(g,m){i();let q=k(g,"team-cli data queries view <queryId>"),$=await N({service:"data",query:`query ($aggregationQueryId: String) {
|
|
39
39
|
aggregationQuery(aggregationQueryId: $aggregationQueryId) {
|
|
40
40
|
_id
|
|
41
41
|
name
|
|
@@ -48,15 +48,15 @@ var yg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",pr
|
|
|
48
48
|
fieldParams
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
}`,variables:{aggregationQueryId:q}});
|
|
51
|
+
}`,variables:{aggregationQueryId:q}});Bg($.aggregationQuery,m)}async function Tg(g,m){i();let q=k(g,"team-cli data queries view-pipeline <queryId>"),$=await N({service:"data",query:`query ($aggregationQueryId: String) {
|
|
52
52
|
aggregationQuery(aggregationQueryId: $aggregationQueryId) {
|
|
53
53
|
pipeline
|
|
54
54
|
}
|
|
55
|
-
}`,variables:{aggregationQueryId:q}});console.log($.aggregationQuery.pipeline)}async function Og(g,m){
|
|
55
|
+
}`,variables:{aggregationQueryId:q}});console.log($.aggregationQuery.pipeline)}async function Og(g,m){i();let q=k(g,"team-cli data queries preview <queryId> --params '<json>'"),$=Ag(m),j=await N({service:"data",query:`mutation ($aggregationQueryId: String, $params: JSON) {
|
|
56
56
|
testAggregationQuery(aggregationQueryId: $aggregationQueryId, params: $params)
|
|
57
|
-
}`,variables:{aggregationQueryId:q,params:$}});
|
|
57
|
+
}`,variables:{aggregationQueryId:q,params:$}});Bg(j.testAggregationQuery,m)}function Am(g){return new Promise((m)=>setTimeout(m,g))}async function Fg(g,m){i();let q=k(g,"team-cli data queries download <queryId> --params '<json>'"),$=Ag(m);if(!m.path)throw Error("--path es requerido. Ejemplo: --path resultado.xlsx");let j=m.path;console.log("Iniciando descarga...");let f=(await N({service:"data",query:`mutation ($aggregationQueryId: String, $params: JSON) {
|
|
58
58
|
downloadAggregationQueryData(aggregationQueryId: $aggregationQueryId, params: $params)
|
|
59
|
-
}`,variables:{aggregationQueryId:q,params:$}})).downloadAggregationQueryData;console.log(`Reporte en proceso (${
|
|
59
|
+
}`,variables:{aggregationQueryId:q,params:$}})).downloadAggregationQueryData;console.log(`Reporte en proceso (${f})...`);let C=null;while(!C){await Am(1000);let r=await N({service:"data",query:`query ($id: String) {
|
|
60
60
|
getAsyncReport(id: $id) {
|
|
61
61
|
_id
|
|
62
62
|
status
|
|
@@ -64,8 +64,8 @@ var yg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",pr
|
|
|
64
64
|
fileUrl
|
|
65
65
|
}
|
|
66
66
|
getAsyncReportRecordsCount(id: $id)
|
|
67
|
-
}`,variables:{id:
|
|
68
|
-
`),console.log("Descargando archivo...");let
|
|
67
|
+
}`,variables:{id:f}}),X=r.getAsyncReport,J=r.getAsyncReportRecordsCount;if(X.status==="error")throw Error("El reporte falló al generarse.");if(X.fileUrl)C=X.fileUrl;else{let F=X.estimatedRecordsCount?` (~${X.estimatedRecordsCount} registros)`:"",M=J!=null?` ${J} procesados`:"";process.stdout.write(`\rGenerando...${F}${M}`)}}process.stdout.write(`
|
|
68
|
+
`),console.log("Descargando archivo...");let G=await fetch(C);if(!G.ok)throw Error(`Error descargando archivo: ${G.status}`);let Y=Buffer.from(await G.arrayBuffer());Mm(j,Y),console.log(`Archivo guardado en ${j}`)}function gg(){console.log(`
|
|
69
69
|
team-cli data - Comandos de datos y reportes
|
|
70
70
|
|
|
71
71
|
Uso:
|
|
@@ -87,7 +87,86 @@ var yg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",pr
|
|
|
87
87
|
team-cli data queries view-pipeline abc123
|
|
88
88
|
team-cli data queries preview abc123 --params '{"startDate": "2026-01-01"}'
|
|
89
89
|
team-cli data queries download abc123 --params '{"startDate": "2026-01-01"}' --path resultado.xlsx
|
|
90
|
-
`)}
|
|
90
|
+
`)}function bg(){console.log(`# @getjusto/team-cli
|
|
91
|
+
|
|
92
|
+
CLI tool for Justo team members. Authenticated access to Justo's GraphQL services and data queries.
|
|
93
|
+
|
|
94
|
+
## Prerequisites
|
|
95
|
+
|
|
96
|
+
The CLI must be authenticated. Check with:
|
|
97
|
+
\`\`\`bash
|
|
98
|
+
npx @getjusto/team-cli auth status
|
|
99
|
+
\`\`\`
|
|
100
|
+
|
|
101
|
+
If not logged in, the user must log in interactively (you cannot do this):
|
|
102
|
+
\`\`\`bash
|
|
103
|
+
npx @getjusto/team-cli auth login
|
|
104
|
+
\`\`\`
|
|
105
|
+
|
|
106
|
+
## Global Options
|
|
107
|
+
|
|
108
|
+
- \`--env <local|develop|prod>\` — Environment (default: prod)
|
|
109
|
+
- \`--format toon|json\` — Output format (default: toon)
|
|
110
|
+
|
|
111
|
+
## Commands
|
|
112
|
+
|
|
113
|
+
### graphql — Run arbitrary GraphQL queries/mutations
|
|
114
|
+
|
|
115
|
+
\`\`\`bash
|
|
116
|
+
npx @getjusto/team-cli graphql <service> '<query>' [--variables '<json>'] [--format toon|json]
|
|
117
|
+
\`\`\`
|
|
118
|
+
|
|
119
|
+
Available services: 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.
|
|
120
|
+
|
|
121
|
+
Examples:
|
|
122
|
+
\`\`\`bash
|
|
123
|
+
npx @getjusto/team-cli graphql main 'query { me { _id roles } }'
|
|
124
|
+
npx @getjusto/team-cli graphql main 'query($id: ID) { user(userId: $id) { _id } }' --variables '{"id": "abc123"}'
|
|
125
|
+
npx @getjusto/team-cli graphql tabs 'query { tab(tabId: "t123") { _id status } }' --format json
|
|
126
|
+
\`\`\`
|
|
127
|
+
|
|
128
|
+
### data queries view — View query metadata and required variables
|
|
129
|
+
|
|
130
|
+
\`\`\`bash
|
|
131
|
+
npx @getjusto/team-cli data queries view <queryId>
|
|
132
|
+
\`\`\`
|
|
133
|
+
|
|
134
|
+
Returns: _id, name, description, collection, currentVersionIndex, and variables (key, fieldType, fieldParams). Use this to understand what params a query expects before running preview or download.
|
|
135
|
+
|
|
136
|
+
### data queries view-pipeline — View query pipeline code
|
|
137
|
+
|
|
138
|
+
\`\`\`bash
|
|
139
|
+
npx @getjusto/team-cli data queries view-pipeline <queryId>
|
|
140
|
+
\`\`\`
|
|
141
|
+
|
|
142
|
+
Returns the raw JavaScript pipeline code.
|
|
143
|
+
|
|
144
|
+
### data queries preview — Test-run a query (max 100 rows)
|
|
145
|
+
|
|
146
|
+
\`\`\`bash
|
|
147
|
+
npx @getjusto/team-cli data queries preview <queryId> [--params '<json>'] [--format toon|json]
|
|
148
|
+
\`\`\`
|
|
149
|
+
|
|
150
|
+
Executes the query with a 100-row limit. Use this to verify results before downloading.
|
|
151
|
+
|
|
152
|
+
### data queries download — Download full query results as Excel
|
|
153
|
+
|
|
154
|
+
\`\`\`bash
|
|
155
|
+
npx @getjusto/team-cli data queries download <queryId> --path <filepath> [--params '<json>']
|
|
156
|
+
\`\`\`
|
|
157
|
+
|
|
158
|
+
\`--path\` is required. Triggers an async report, polls until complete, then downloads the Excel file.
|
|
159
|
+
|
|
160
|
+
## Output Format
|
|
161
|
+
|
|
162
|
+
Default output is TOON (Token-Oriented Object Notation), a compact human-readable format. Use \`--format json\` for standard JSON output.
|
|
163
|
+
|
|
164
|
+
## Typical Workflow
|
|
165
|
+
|
|
166
|
+
1. View a query to understand its variables: \`data queries view <id>\`
|
|
167
|
+
2. Preview with params: \`data queries preview <id> --params '{"startDate": "2026-01-01"}'\`
|
|
168
|
+
3. Download full data: \`data queries download <id> --params '{"startDate": "2026-01-01"}' --path output.xlsx\`
|
|
169
|
+
`)}var{positional:c,flags:R}=$g(process.argv.slice(2));if(R.env)mg(R.env);var s=c[0],B=c[1];function zg(){let g=W(),m=g?`Sesión: ${g.email}`:"Sesión: no iniciada";console.log(`
|
|
91
170
|
team-cli - Herramienta CLI para el equipo Justo
|
|
92
171
|
|
|
93
172
|
${m}
|
|
@@ -99,9 +178,10 @@ var yg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",pr
|
|
|
99
178
|
auth Gestión de sesión
|
|
100
179
|
graphql Ejecutar queries/mutations GraphQL
|
|
101
180
|
data Datos y reportes
|
|
181
|
+
get-skill Obtener skill para usar con Claude
|
|
102
182
|
|
|
103
183
|
Opciones globales:
|
|
104
184
|
--env <local|develop|prod> Seleccionar ambiente (default: prod)
|
|
105
185
|
--version Muestra la versión
|
|
106
186
|
--help Muestra la ayuda
|
|
107
|
-
`)}async function
|
|
187
|
+
`)}async function Bm(){try{if(R.version)console.log("0.0.2");else if(R.help&&!s)zg();else if(s==="auth")if(B==="--help"||R.help)p();else if(B==="login")await Ng();else if(B==="login-with-token")await Wg(R);else if(B==="request-code")await Ug(R);else if(B==="logout")await rg();else if(B==="status")await Xg();else p();else if(s==="graphql")if(B==="--help"||R.help)e();else await Mg(c,R);else if(s==="get-skill")bg();else if(s==="data"){let g=c[1],m=c[2];if(R.help||B==="--help")gg();else if(g==="queries"&&m==="view")await Sg(c,R);else if(g==="queries"&&m==="view-pipeline")await Tg(c,R);else if(g==="queries"&&m==="preview")await Og(c,R);else if(g==="queries"&&m==="download")await Fg(c,R);else gg()}else zg()}catch(g){console.error(`Error: ${g instanceof Error?g.message:g}`),process.exit(1)}}Bm();
|