@getjusto/team-cli 0.0.2 → 0.0.4
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 +583 -70
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -1,41 +1,441 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
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!) {
|
|
2
|
+
var X={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"}},L="prod";function lo(o){L=o}function po(){return L}function B(o){return X[o][L]}function wo(o){let t=[],e={},i={};for(let r=0;r<o.length;r++)if(o[r].startsWith("--")&&o[r+1]&&!o[r+1].startsWith("--")){let s=o[r].slice(2);if(e[s]=o[r+1],!i[s])i[s]=[];i[s].push(o[r+1]),r++}else if(o[r].startsWith("--"))e[o[r].slice(2)]="true";else t.push(o[r]);return{positional:t,flags:e,arrayFlags:i}}function J(o,t){let e=o[t];if(!e)throw Error(`--${t} es requerido.`);return e}import{existsSync as to,mkdirSync as bt,readFileSync as qt,writeFileSync as Ct,unlinkSync as It}from"node:fs";import{join as fo}from"node:path";import{homedir as $t}from"node:os";var oo=fo($t(),".justo-team");function eo(){let o=po(),t=o==="prod"?"credentials.json":`credentials.${o}.json`;return fo(oo,t)}function yt(){if(!to(oo))bt(oo,{recursive:!0})}function Y(o){yt(),Ct(eo(),JSON.stringify(o,null,2))}function d(){let o=eo();if(!to(o))return null;try{let t=qt(o,"utf-8");return JSON.parse(t)}catch{return null}}function io(){let o=eo();if(to(o))It(o)}import{existsSync as bo,readFileSync as jt,writeFileSync as ht,mkdirSync as Rt}from"node:fs";import{join as qo}from"node:path";import{homedir as Et}from"node:os";function xt(){let o=qo(Et(),".justo-team"),t=qo(o,"device-id");if(bo(t))return jt(t,"utf-8").trim();let e=crypto.randomUUID();if(!bo(o))Rt(o,{recursive:!0});return ht(t,e),e}var Io={required:({label:o})=>`${o} no es opcional`,notAString:({label:o})=>`${o} no es un texto`,notANumber:({label:o})=>`${o} no es un número`,notAnInteger:({label:o})=>`${o} no es un número entero`,notABoolean:({label:o})=>`${o} no es un valor verdadero o falso`,notAnEmail:({label:o})=>`${o} no es un email`,notAnId:({label:o})=>`${o} no es un ID válido`,notADate:({label:o})=>`${o} no es una fecha válida`,notAnArray:({label:o})=>`${o} no es un arreglo`,notAnObject:({label:o})=>`${o} no es un objeto`,stringTooShort:({label:o})=>`${o} no tiene el largo suficiente`,stringTooLong:"El largo es mayor al permitido",numberTooSmall:({label:o})=>`${o} es un número muy pequeño`,numberTooBig:({label:o})=>`${o} es un número muy grande`,notInSchema:({label:o})=>`${o} no esta permitido`,notUnique:({label:o})=>`${o} no es único`,notFound:({label:o})=>`${o} 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 Ut(o,t){let e=Io[o];if(!e)return`${t}: ${o}`;if(typeof e==="function")return e({label:t});return e}function Co(o){return Object.entries(o).map(([t,e])=>Ut(e,t)).join(", ")}function Pt(o){if(o.error==="validationError"&&o.validationErrors)return Co(o.validationErrors);if(o.extensions?.code==="PermissionsError"){let r=o.extensions.info?.type;if(r?.includes("User doesn't have permissions for "))return`Tu usuario no tiene permisos para [${r.split("User doesn't have permissions for ")[1]}]`;return o.message}if(o.validationErrors)return`${o.message} (${Co(o.validationErrors)})`;let t=o.message||"Error desconocido",e=Io[t];if(e)return typeof e==="function"?e({label:""}).trim():e;let i=o.error||o.code||o.type;return i?`${t} [${i}]`:t}function Nt(o){try{return JSON.parse(Buffer.from(o.split(".")[1],"base64").toString()).exp*1000<Date.now()}catch{return!0}}async function Wt(){let o=d();if(!o?.refreshToken)return null;let t=`${B("auth")}/refresh-token`,i=await(await fetch(t,{method:"POST",headers:{"X-ORION-REFRESH":o.refreshToken}})).json();if(!i.token)return null;return Y({...o,token:i.token}),i.token}async function At(){let o=d();if(!o?.token)return;if(!Nt(o.token))return o.token;return await Wt()??void 0}async function c(o){let t=`${B(o.service)}/graphql`,e=await At(),i={"Content-Type":"application/json","X-ORION-DEVICEID":xt(),"X-ORION-PLATFORM":"web"};if(e)i["x-orion-jwt"]=e;let r;try{r=await fetch(t,{method:"POST",headers:i,body:JSON.stringify({query:o.query,variables:o.variables}),signal:AbortSignal.timeout(15000)})}catch{throw Error("La solicitud tardó demasiado. Intenta de nuevo.")}let s=await r.json();if(s.errors?.length)throw Error(Pt(s.errors[0]));if(!s.data)throw Error("No data returned from server");return s.data}import{createInterface as Ot}from"node:readline";function ro(o){let t=Ot({input:process.stdin,output:process.stderr});return new Promise((e)=>{t.question(o,(i)=>{t.close(),e(i.trim())})})}var St={comma:",",tab:"\t",pipe:"|"},F=St.comma;function yo(o){return o.replace(/\\/g,"\\\\").replace(/"/g,"\\\"").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function Qt(o){return o==="true"||o==="false"||o==="null"}function h(o){if(o===null)return null;if(typeof o==="object"&&o!==null&&"toJSON"in o&&typeof o.toJSON==="function"){let t=o.toJSON();if(t!==o)return h(t)}if(typeof o==="string"||typeof o==="boolean")return o;if(typeof o==="number"){if(Object.is(o,-0))return 0;if(!Number.isFinite(o))return null;return o}if(typeof o==="bigint"){if(o>=Number.MIN_SAFE_INTEGER&&o<=Number.MAX_SAFE_INTEGER)return Number(o);return o.toString()}if(o instanceof Date)return o.toISOString();if(Array.isArray(o))return o.map(h);if(o instanceof Set)return Array.from(o).map(h);if(o instanceof Map)return Object.fromEntries(Array.from(o,([t,e])=>[String(t),h(e)]));if(Gt(o)){let t={};for(let e in o)if(Object.prototype.hasOwnProperty.call(o,e))t[e]=h(o[e]);return t}return null}function N(o){return o===null||typeof o==="string"||typeof o==="number"||typeof o==="boolean"}function U(o){return Array.isArray(o)}function w(o){return o!==null&&typeof o==="object"&&!Array.isArray(o)}function v(o){return Object.keys(o).length===0}function Gt(o){if(o===null||typeof o!=="object")return!1;let t=Object.getPrototypeOf(o);return t===null||t===Object.prototype}function T(o){return o.length===0||o.every((t)=>N(t))}function Bt(o){return o.length===0||o.every((t)=>U(t))}function jo(o){return o.length===0||o.every((t)=>w(t))}function Jt(o){return/^[A-Z_][\w.]*$/i.test(o)}function vt(o){return/^[A-Z_]\w*$/i.test(o)}function Tt(o,t=F){if(!o)return!1;if(o!==o.trim())return!1;if(Qt(o)||_t(o))return!1;if(o.includes(":"))return!1;if(o.includes('"')||o.includes("\\"))return!1;if(/[[\]{}]/.test(o))return!1;if(/[\n\r\t]/.test(o))return!1;if(o.includes(t))return!1;if(o.startsWith("-"))return!1;return!0}function _t(o){return/^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i.test(o)||/^0\d+$/.test(o)}var Be=Symbol("quotedKey");function Ft(o,t,e,i,r,s,n){if(i.keyFolding!=="safe")return;if(!w(t))return;let{segments:a,tail:u,leafValue:y}=Mt(o,t,n??i.flattenDepth);if(a.length<2)return;if(!a.every((j)=>vt(j)))return;let b=Xt(a),q=s?`${s}.${b}`:b;if(e.includes(b))return;if(r&&r.has(q))return;return{foldedKey:b,remainder:u,leafValue:y,segmentCount:a.length}}function Mt(o,t,e){let i=[o],r=t;while(i.length<e){if(!w(r))break;let s=Object.keys(r);if(s.length!==1)break;let n=s[0],a=r[n];i.push(n),r=a}if(!w(r)||v(r))return{segments:i,tail:void 0,leafValue:r};return{segments:i,tail:r,leafValue:r}}function Xt(o){return o.join(".")}function A(o,t){if(o===null)return"null";if(typeof o==="boolean")return String(o);if(typeof o==="number")return String(o);return Yt(o,t)}function Yt(o,t=F){if(Tt(o,t))return o;return`"${yo(o)}"`}function _(o){if(Jt(o))return o;return`"${yo(o)}"`}function ho(o,t=F){return o.map((e)=>A(e,t)).join(t)}function R(o,t){let e=t?.key,i=t?.fields,r=t?.delimiter??",",s="";if(e)s+=_(e);if(s+=`[${o}${r!==F?r:""}]`,i){let n=i.map((a)=>_(a));s+=`{${n.join(r)}}`}return s+=":",s}function*Zt(o,t,e){if(N(o)){let i=A(o,t.delimiter);if(i!=="")yield i;return}if(U(o))yield*so(void 0,o,e,t);else if(w(o))yield*W(o,e,t)}function*W(o,t,e,i,r,s){let n=Object.keys(o);if(t===0&&!i)i=new Set(n.filter((u)=>u.includes(".")));let a=s??e.flattenDepth;for(let[u,y]of Object.entries(o))yield*zt(u,y,t,e,n,i,r,a)}function*zt(o,t,e,i,r,s,n,a){let u=n?`${n}.${o}`:o,y=a??i.flattenDepth;if(i.keyFolding==="safe"&&r){let q=Ft(o,t,r,i,s,n,y);if(q){let{foldedKey:j,remainder:G,leafValue:x,segmentCount:pt}=q,V=_(j);if(G===void 0){if(N(x)){yield p(e,`${V}: ${A(x,i.delimiter)}`,i.indent);return}else if(U(x)){yield*so(j,x,e,i);return}else if(w(x)&&v(x)){yield p(e,`${V}:`,i.indent);return}}if(w(G)){yield p(e,`${V}:`,i.indent);let wt=y-pt,ft=n?`${n}.${j}`:j;yield*W(G,e+1,i,s,ft,wt);return}}}let b=_(o);if(N(t))yield p(e,`${b}: ${A(t,i.delimiter)}`,i.indent);else if(U(t))yield*so(o,t,e,i);else if(w(t)){if(yield p(e,`${b}:`,i.indent),!v(t))yield*W(t,e+1,i,s,u,y)}}function*so(o,t,e,i){if(t.length===0){yield p(e,R(0,{key:o,delimiter:i.delimiter}),i.indent);return}if(T(t)){yield p(e,z(t,i.delimiter,o),i.indent);return}if(Bt(t)){if(t.every((r)=>T(r))){yield*Ht(o,t,e,i);return}}if(jo(t)){let r=Ro(t);if(r)yield*Dt(o,t,r,e,i);else yield*$o(o,t,e,i);return}yield*$o(o,t,e,i)}function*Ht(o,t,e,i){yield p(e,R(t.length,{key:o,delimiter:i.delimiter}),i.indent);for(let r of t)if(T(r)){let s=z(r,i.delimiter);yield C(e+1,s,i.indent)}}function z(o,t,e){let i=R(o.length,{key:e,delimiter:t}),r=ho(o,t);if(o.length===0)return i;return`${i} ${r}`}function*Dt(o,t,e,i,r){yield p(i,R(t.length,{key:o,fields:e,delimiter:r.delimiter}),r.indent),yield*Eo(t,e,i+1,r)}function Ro(o){if(o.length===0)return;let t=o[0],e=Object.keys(t);if(e.length===0)return;if(kt(o,e))return e}function kt(o,t){for(let e of o){if(Object.keys(e).length!==t.length)return!1;for(let i of t){if(!(i in e))return!1;if(!N(e[i]))return!1}}return!0}function*Eo(o,t,e,i){for(let r of o)yield p(e,ho(t.map((s)=>r[s]),i.delimiter),i.indent)}function*$o(o,t,e,i){yield p(e,R(t.length,{key:o,delimiter:i.delimiter}),i.indent);for(let r of t)yield*no(r,e+1,i)}function*Kt(o,t,e){if(v(o)){yield p(t,"-",e.indent);return}let i=Object.entries(o),[r,s]=i[0],n=i.slice(1);if(U(s)&&jo(s)){let u=Ro(s);if(u){if(yield C(t,R(s.length,{key:r,fields:u,delimiter:e.delimiter}),e.indent),yield*Eo(s,u,t+2,e),n.length>0)yield*W(Object.fromEntries(n),t+1,e);return}}let a=_(r);if(N(s))yield C(t,`${a}: ${A(s,e.delimiter)}`,e.indent);else if(U(s))if(s.length===0)yield C(t,`${a}${R(0,{delimiter:e.delimiter})}`,e.indent);else if(T(s))yield C(t,`${a}${z(s,e.delimiter)}`,e.indent);else{yield C(t,`${a}${R(s.length,{delimiter:e.delimiter})}`,e.indent);for(let u of s)yield*no(u,t+2,e)}else if(w(s)){if(yield C(t,`${a}:`,e.indent),!v(s))yield*W(s,t+2,e)}if(n.length>0)yield*W(Object.fromEntries(n),t+1,e)}function*no(o,t,e){if(N(o))yield C(t,A(o,e.delimiter),e.indent);else if(U(o))if(T(o))yield C(t,z(o,e.delimiter),e.indent);else{yield C(t,R(o.length,{delimiter:e.delimiter}),e.indent);for(let i of o)yield*no(i,t+1,e)}else if(w(o))yield*Kt(o,t,e)}function p(o,t,e){return" ".repeat(e*o)+t}function C(o,t,e){return p(o,"- "+t,e)}function Vt(o,t){let e=t("",o,[]);if(e===void 0)return Z(o,t,[]);return Z(h(e),t,[])}function Z(o,t,e){if(w(o))return Lt(o,t,e);if(U(o))return oe(o,t,e);return o}function Lt(o,t,e){let i={};for(let[r,s]of Object.entries(o)){let n=[...e,r],a=t(r,s,n);if(a===void 0)continue;i[r]=Z(h(a),t,n)}return i}function oe(o,t,e){let i=[];for(let r=0;r<o.length;r++){let s=o[r],n=[...e,r],a=t(String(r),s,n);if(a===void 0)continue;let u=h(a);i.push(Z(u,t,n))}return i}function ao(o,t){return Array.from(te(o,t)).join(`
|
|
3
|
+
`)}function te(o,t){let e=h(o),i=ee(t);return Zt(i.replacer?Vt(e,i.replacer):e,i,0)}function ee(o){return{indent:o?.indent??2,delimiter:o?.delimiter??F,keyFolding:o?.keyFolding??"off",flattenDepth:o?.flattenDepth??Number.POSITIVE_INFINITY,replacer:o?.replacer}}function ie(o){let t=o.format??"toon";if(t!=="toon"&&t!=="json")throw Error("--format debe ser toon o json.");return t}function xo(o,t){if(ie(t)==="json"){console.log(JSON.stringify(o,null,2));return}console.log(ao(o))}function g(o){process.stdout.write(`${o}
|
|
4
|
+
`)}function Uo(o,t){let i={ok:!1,error:o instanceof Error?o.message:String(o)};if((t.format==="json"?"json":"toon")==="json"){console.error(JSON.stringify(i,null,2));return}console.error(ao(i))}function I(o){process.stderr.write(o)}async function Po(o){return(await c({service:"auth",query:`mutation ($email: String!) {
|
|
3
5
|
requestLoginCode(email: $email)
|
|
4
|
-
}`,variables:{email:
|
|
6
|
+
}`,variables:{email:o}})).requestLoginCode}async function No(o,t,e){let i=await c({service:"auth",query:`mutation ($email: String!, $token: String!, $code: String!) {
|
|
5
7
|
loginWithCode(email: $email, token: $token, code: $code) {
|
|
6
8
|
token
|
|
7
9
|
refreshToken
|
|
8
10
|
}
|
|
9
|
-
}`,variables:{email:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
}`,variables:{email:o,token:t,code:e.toUpperCase()}});Y({email:o,token:i.loginWithCode.token,refreshToken:i.loginWithCode.refreshToken}),await re()}async function re(){if(!(await c({service:"main",query:"query { me { roles } }"})).me?.roles?.length)throw io(),Error("Solo miembros del equipo Justo pueden usar esta herramienta.")}async function Wo(){let o=await ro("Email: ");I(`Enviando codigo de verificacion...
|
|
12
|
+
`);let t=await Po(o);I(`Codigo enviado a tu email.
|
|
13
|
+
`);let e=await ro("Codigo: ");return await No(o,t,e),{ok:!0,authenticated:!0,email:o}}async function Ao(o){let t=J(o,"email"),e=J(o,"token"),i=J(o,"code");return await No(t,e,i),{ok:!0,authenticated:!0,email:t}}async function Oo(o){let t=J(o,"email");I(`Enviando codigo de verificacion...
|
|
14
|
+
`);let e=await Po(t);return{ok:!0,email:t,token:e,nextCommand:`npx @getjusto/team-cli auth login-with-token --email ${t} --token ${e} --code <CODIGO>`}}async function So(){return io(),{ok:!0,authenticated:!1}}async function Qo(){let o=d();if(!o)return{authenticated:!1,loginCommand:"npx @getjusto/team-cli@latest auth login"};return{authenticated:!0,email:o.email}}function co(){return`team-cli auth
|
|
15
|
+
|
|
16
|
+
Gestion de sesion.
|
|
17
|
+
|
|
18
|
+
Uso:
|
|
19
|
+
team-cli auth <subcomando> [opciones]
|
|
20
|
+
|
|
21
|
+
Subcomandos:
|
|
22
|
+
login
|
|
23
|
+
Iniciar sesion en modo interactivo.
|
|
24
|
+
Uso: team-cli auth login
|
|
25
|
+
|
|
26
|
+
logout
|
|
27
|
+
Cerrar sesion actual.
|
|
28
|
+
Uso: team-cli auth logout
|
|
29
|
+
|
|
30
|
+
status
|
|
31
|
+
Ver la sesion actual.
|
|
32
|
+
Uso: team-cli auth status
|
|
33
|
+
|
|
34
|
+
request-code
|
|
35
|
+
Solicitar codigo para login no interactivo.
|
|
36
|
+
Uso: team-cli auth request-code --email <email>
|
|
37
|
+
|
|
38
|
+
login-with-token
|
|
39
|
+
Iniciar sesion sin prompts.
|
|
40
|
+
Uso: team-cli auth login-with-token --email <email> --token <token> --code <codigo>`}var mo=["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"],Go=`
|
|
41
|
+
query ResolverInfo($name: ID!, $mutation: Boolean!) {
|
|
42
|
+
params(name: $name, mutation: $mutation) {
|
|
43
|
+
name
|
|
44
|
+
params
|
|
45
|
+
result
|
|
46
|
+
basicResultQuery
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
`;function se(o){if(!o)throw Error("Uso: team-cli graphql <servicio> '<query>' [--variables '<json>'] [--format toon|json]");if(!mo.includes(o))throw Error(`Servicio "${o}" no válido. Servicios disponibles: ${mo.join(", ")}`)}async function ne(o,t){let e;try{let i=await c({service:o,query:Go,variables:{name:t,mutation:!1}});return{service:o,operationName:t,operationType:"query",info:i.params}}catch(i){e=i}try{let i=await c({service:o,query:Go,variables:{name:t,mutation:!0}});return{service:o,operationName:t,operationType:"mutation",info:i.params}}catch(i){let r=e instanceof Error?e.message:"",s=i instanceof Error?i.message:"";if(r.includes('Cannot query field "params"')||s.includes('Cannot query field "params"'))throw Error(`El servicio "${o}" no expone metadata de resolvers por GraphQL.`);throw e instanceof Error?e:i}}async function Bo(o,t){let e=o[1],i=o[2],r=o[2];if(!d())throw Error("Debes iniciar sesión primero. Usa: team-cli auth login");if(se(e),i==="info"){let a=o[3];if(!a)throw Error("Uso: team-cli graphql <servicio> info <queryName|mutationName> [--format toon|json]");return await ne(e,a)}if(!r)throw Error("Uso: team-cli graphql <servicio> '<query>' [--variables '<json>'] [--format toon|json]");let s;if(t.variables)try{s=JSON.parse(t.variables)}catch{throw Error("Las variables deben ser un JSON válido.")}return await c({service:e,query:r,variables:s})}function Jo(){return`team-cli graphql
|
|
50
|
+
|
|
51
|
+
Ejecutar queries y mutations GraphQL.
|
|
52
|
+
|
|
53
|
+
Uso:
|
|
54
|
+
team-cli graphql <servicio> '<query>' [--variables '<json>'] [--format toon|json]
|
|
55
|
+
team-cli graphql <servicio> info <queryName|mutationName> [--format toon|json]
|
|
56
|
+
|
|
57
|
+
Ejemplos:
|
|
58
|
+
team-cli graphql main 'query { me { _id roles } }'
|
|
59
|
+
team-cli graphql main 'query($id: ID) { user(userId: $id) { _id } }' --variables '{"id": "abc123"}'
|
|
60
|
+
team-cli graphql main 'query { me { _id } }' --format json
|
|
61
|
+
team-cli graphql main info website
|
|
62
|
+
team-cli graphql webdata info setWebsiteTheme --format json
|
|
63
|
+
|
|
64
|
+
Servicios disponibles:
|
|
65
|
+
${mo.join(", ")}
|
|
66
|
+
|
|
67
|
+
Comando info:
|
|
68
|
+
Consulta la metadata publicada por OrionJS para un query o mutation.
|
|
69
|
+
Devuelve el tipo de operación, los params serializados, el resultado y un basicResultQuery.
|
|
70
|
+
Si no indicas si es query o mutation, la CLI prueba ambas automáticamente.
|
|
71
|
+
|
|
72
|
+
Formato:
|
|
73
|
+
Por defecto usa toon. Usa --format json para JSON estándar.`}function ae(o){return o.replace(/^https?:\/\//,"").replace(/^www\./,"").replace(/\/.*$/,"")}function ce(o){return o.includes(".")||o.startsWith("http://")||o.startsWith("https://")}async function O(o){if(ce(o)){let t=ae(o),e=await fetch(`${B("main")}/website-id/${t}`,{signal:AbortSignal.timeout(1e4)});if(!e.ok)throw Error(`No se encontro el sitio "${t}"`);let i=await e.json();if(!i.websiteId)throw Error(`No se pudo resolver el websiteId para "${t}"`);return{input:o,websiteId:i.websiteId,targetType:"domain"}}return{input:o,websiteId:o,targetType:"websiteId"}}async function vo(o){let t=await c({service:"main",query:`query ($websiteId: ID) {
|
|
74
|
+
website(websiteId: $websiteId) {
|
|
75
|
+
_id
|
|
76
|
+
name
|
|
77
|
+
active
|
|
78
|
+
baseURL
|
|
79
|
+
domain
|
|
80
|
+
domains
|
|
81
|
+
countryCode
|
|
82
|
+
timezone
|
|
83
|
+
defaultMenuId
|
|
84
|
+
}
|
|
85
|
+
}`,variables:{websiteId:o}});if(!t.website)throw Error(`No se encontro el website "${o}"`);return t.website}function me(){if(!d())throw Error("Debes iniciar sesión primero. Usa: team-cli auth login")}async function To(o){if(me(),!o)throw Error("Uso: team-cli admin <websiteId|domain> show");let t=await O(o),e=await vo(t.websiteId);return{context:t,website:e}}function H(){return`team-cli admin
|
|
86
|
+
|
|
87
|
+
Comandos administrativos con contexto de website.
|
|
88
|
+
|
|
89
|
+
Uso:
|
|
90
|
+
team-cli admin <websiteId|domain> <modulo> <accion> [opciones]
|
|
91
|
+
|
|
92
|
+
Modulos:
|
|
93
|
+
show
|
|
94
|
+
Mostrar informacion basica del website seleccionado.
|
|
95
|
+
Uso: team-cli admin <websiteId|domain> show
|
|
96
|
+
|
|
97
|
+
search
|
|
98
|
+
Buscar websites en admin.
|
|
99
|
+
Uso: team-cli admin search <texto> [--limit <n>] [--page <n>]
|
|
100
|
+
|
|
101
|
+
stores list
|
|
102
|
+
Listar las tiendas del website seleccionado.
|
|
103
|
+
Uso: team-cli admin <websiteId|domain> stores list
|
|
104
|
+
|
|
105
|
+
coupons
|
|
106
|
+
Administrar cupones y sus códigos.
|
|
107
|
+
Uso: team-cli admin <websiteId|domain> coupons <accion> [opciones]`}var _o=`
|
|
108
|
+
availableAtPeriods
|
|
109
|
+
closedDays
|
|
110
|
+
closedUntilDate
|
|
111
|
+
isAvailableNow
|
|
112
|
+
timezone
|
|
113
|
+
openPeriods {
|
|
114
|
+
daysOfWeek
|
|
115
|
+
fromMinute
|
|
116
|
+
toMinute
|
|
117
|
+
}
|
|
118
|
+
specialPeriods {
|
|
119
|
+
days
|
|
120
|
+
fromMinute
|
|
121
|
+
toMinute
|
|
122
|
+
}
|
|
123
|
+
`,D=`
|
|
124
|
+
_id
|
|
125
|
+
websiteId
|
|
126
|
+
name
|
|
127
|
+
code
|
|
128
|
+
active
|
|
129
|
+
type
|
|
130
|
+
description
|
|
131
|
+
isHidden
|
|
132
|
+
isBirthdayCoupon
|
|
133
|
+
totalRedemptions
|
|
134
|
+
fromDate
|
|
135
|
+
endDate
|
|
136
|
+
percentageOff
|
|
137
|
+
discountAmount
|
|
138
|
+
fixedAmount
|
|
139
|
+
maxRedemptions
|
|
140
|
+
maxRedemptionsPerUser
|
|
141
|
+
maxRedemptionsPerUserPerDay
|
|
142
|
+
minimumOrderPrice
|
|
143
|
+
maximumOrderPrice
|
|
144
|
+
applyDeliveryDiscount
|
|
145
|
+
deliveryDiscountType
|
|
146
|
+
deliveryDiscountValue
|
|
147
|
+
deliveryDiscountPercentage
|
|
148
|
+
allowedEmails
|
|
149
|
+
requireChannels
|
|
150
|
+
requiresPaymentTypes
|
|
151
|
+
requiresStoresIds
|
|
152
|
+
requiresMenusIds
|
|
153
|
+
requiresCategoriesIds
|
|
154
|
+
requiresProductsIds
|
|
155
|
+
requiredBINs
|
|
156
|
+
extraRequirementsForPaymentTypes
|
|
157
|
+
schedule {
|
|
158
|
+
${_o}
|
|
159
|
+
}
|
|
160
|
+
scheduleAtUse {
|
|
161
|
+
${_o}
|
|
162
|
+
}
|
|
163
|
+
codesCode
|
|
164
|
+
`,Fo=`
|
|
165
|
+
_id
|
|
166
|
+
code
|
|
167
|
+
couponId
|
|
168
|
+
websiteId
|
|
169
|
+
userEmail
|
|
170
|
+
sentToEmail
|
|
171
|
+
totalRedemptions
|
|
172
|
+
createdAt
|
|
173
|
+
`;function uo(){if(!d())throw Error("Debes iniciar sesión primero. Usa: team-cli auth login")}function S(o,t){let e=o[t];if(!e)throw Error(`--${t} es requerido.`);try{return JSON.parse(e)}catch{throw Error(`--${t} debe ser un JSON válido.`)}}function $(o,t){let e=o[t];if(!e)return;let i=Number.parseInt(e,10);if(Number.isNaN(i))throw Error(`--${t} debe ser un número entero.`);return i}function Mo(o,t){let e=o[t];if(!e)return;if(e==="true")return!0;if(e==="false")return!1;throw Error(`--${t} debe ser true o false.`)}async function f(o){if(uo(),!o)throw Error("Debes indicar <websiteId|domain>.");return O(o)}async function E(o,t){let e=await c({service:"main",query:`query ($couponId: ID) {
|
|
174
|
+
coupon(couponId: $couponId) {
|
|
175
|
+
_id
|
|
176
|
+
websiteId
|
|
177
|
+
}
|
|
178
|
+
}`,variables:{couponId:o}});if(!e.coupon)throw Error(`No se encontró el cupón "${o}"`);if(e.coupon.websiteId!==t)throw Error(`El cupón "${o}" no pertenece al website seleccionado.`);return e.coupon}async function Xo(o,t){uo();let e=o[2]??t.filter;if(!e)throw Error("Debes indicar un término de búsqueda. Uso: team-cli admin search <texto>");let i=$(t,"limit"),r=$(t,"page"),s=Mo(t,"only-active"),n=await c({service:"main",query:`query ($filter: String, $limit: BigInt, $page: BigInt, $onlyActiveWebsites: Boolean) {
|
|
179
|
+
websites(filter: $filter, limit: $limit, page: $page, onlyActiveWebsites: $onlyActiveWebsites) {
|
|
180
|
+
items {
|
|
181
|
+
_id
|
|
182
|
+
name
|
|
183
|
+
active
|
|
184
|
+
baseURL
|
|
185
|
+
domain
|
|
186
|
+
countryCode
|
|
187
|
+
timezone
|
|
188
|
+
}
|
|
189
|
+
totalCount
|
|
190
|
+
totalPages
|
|
191
|
+
hasNextPage
|
|
192
|
+
hasPreviousPage
|
|
193
|
+
}
|
|
194
|
+
}`,variables:{filter:e,limit:i,page:r,onlyActiveWebsites:s}});return{searchTerm:e,websites:n.websites.items??[],pagination:{totalCount:n.websites.totalCount??0,totalPages:n.websites.totalPages??0,hasNextPage:Boolean(n.websites.hasNextPage),hasPreviousPage:Boolean(n.websites.hasPreviousPage),page:r??1,limit:i??null}}}function Yo(){return`team-cli admin search
|
|
16
195
|
|
|
17
|
-
|
|
18
|
-
Primero solicita un código, luego úsalo para iniciar sesión:
|
|
196
|
+
Buscar websites en admin.
|
|
19
197
|
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
team-cli graphql - Ejecutar queries y mutations GraphQL
|
|
198
|
+
Uso:
|
|
199
|
+
team-cli admin search <texto> [--limit <n>] [--page <n>] [--only-active true|false]
|
|
25
200
|
|
|
26
|
-
|
|
27
|
-
|
|
201
|
+
Opciones:
|
|
202
|
+
--limit <n>
|
|
203
|
+
Límite de resultados.
|
|
28
204
|
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
205
|
+
--page <n>
|
|
206
|
+
Página a consultar.
|
|
33
207
|
|
|
34
|
-
|
|
208
|
+
--only-active true|false
|
|
209
|
+
Filtrar solo websites activos.
|
|
35
210
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
211
|
+
Ejemplos:
|
|
212
|
+
team-cli admin search milas
|
|
213
|
+
team-cli admin search buffalo --limit 5
|
|
214
|
+
team-cli admin search pizza --only-active true`}function ue(){if(!d())throw Error("Debes iniciar sesión primero. Usa: team-cli auth login")}function ge(o){let t=[o.address?.streetAddress,o.address?.extendedAddress,o.address?.locality].filter(Boolean);if(!t.length)return null;return t.join(", ")}async function Zo(o){if(ue(),!o)throw Error("Uso: team-cli admin <websiteId|domain> stores list");let t=await O(o),i=((await c({service:"main",query:`query ($websiteId: ID) {
|
|
215
|
+
stores(websiteId: $websiteId) {
|
|
216
|
+
items {
|
|
217
|
+
_id
|
|
218
|
+
name
|
|
219
|
+
address {
|
|
220
|
+
streetAddress
|
|
221
|
+
extendedAddress
|
|
222
|
+
locality
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}`,variables:{websiteId:t.websiteId}})).stores.items??[]).map((r)=>({_id:r._id,name:r.name,address:ge(r)})).sort((r,s)=>r.name.localeCompare(s.name,"es",{sensitivity:"base"}));return{context:t,stores:i,totalCount:i.length}}var zo={active:"Boolean",allowedEmails:"[String]",applyDeliveryDiscount:"Boolean",code:"ID",deliveryDiscountPercentage:"Float",deliveryDiscountType:"String",deliveryDiscountValue:"Float",description:"String",discountAmount:"Float",dontApplyToProductsIds:"[ID]",endDate:"Date",externalId:"String",extraRequirementsForPaymentTypes:"JSON",fixedAmount:"Float",fromDate:"Date",isBirthdayCoupon:"Boolean",isHidden:"Boolean",maxPercentageOffDiscount:"Float",maxProductsPerOrder:"Float",maxRedemptions:"Float",maxRedemptionsPerUser:"Float",maxRedemptionsPerUserPerDay:"Boolean",maximumOrderPrice:"Float",minimumOrderPrice:"Float",name:"String",onlyForNewUsers:"Boolean",onlyForProductsWithoutDiscount:"Boolean",onlyRedeemOnBirthday:"Boolean",percentageOff:"Float",requireChannels:"[ID]",requirePhoneVerification:"Boolean",requiredBINs:"[String]",requiresCategoriesIds:"[ID]",requiresMenusIds:"[ID]",requiresPaymentTypes:"[ID]",requiresProductsIds:"[ID]",requiresStoresIds:"[ID]",schedule:"ScheduleInput",scheduleAtUse:"ScheduleInput",type:"ID",websiteId:"ID"};function de(o){let t=Object.entries(o).filter(([,s])=>s!==void 0),e=t.map(([s])=>s).filter((s)=>!zo[s]);if(e.length)throw Error(`Campos no soportados para create: ${e.join(", ")}`);let i=t.map(([s])=>`$${s}: ${zo[s]}`).join(", "),r=t.map(([s])=>`${s}: $${s}`).join(", ");return`mutation (${i}) {
|
|
227
|
+
createCoupon(${r}) {
|
|
228
|
+
${D}
|
|
229
|
+
}
|
|
230
|
+
}`}async function Ho(o,t){let e=await f(o),i=$(t,"limit"),r=$(t,"page"),s=t.filter,n=await c({service:"main",query:`query ($websiteId: ID, $filter: String, $limit: BigInt, $page: BigInt) {
|
|
231
|
+
coupons(websiteId: $websiteId, filter: $filter, limit: $limit, page: $page) {
|
|
232
|
+
items {
|
|
233
|
+
_id
|
|
234
|
+
name
|
|
235
|
+
code
|
|
236
|
+
active
|
|
237
|
+
type
|
|
238
|
+
totalRedemptions
|
|
239
|
+
percentageOff
|
|
240
|
+
discountAmount
|
|
241
|
+
fixedAmount
|
|
242
|
+
fromDate
|
|
243
|
+
endDate
|
|
244
|
+
}
|
|
245
|
+
totalCount
|
|
246
|
+
totalPages
|
|
247
|
+
hasNextPage
|
|
248
|
+
hasPreviousPage
|
|
249
|
+
}
|
|
250
|
+
}`,variables:{websiteId:e.websiteId,filter:s,limit:i,page:r}});return{context:e,coupons:n.coupons.items??[],pagination:{totalCount:n.coupons.totalCount??0,totalPages:n.coupons.totalPages??0,hasNextPage:Boolean(n.coupons.hasNextPage),hasPreviousPage:Boolean(n.coupons.hasPreviousPage),page:r??1,limit:i??null}}}async function Do(o,t){let e=await f(o);await E(t,e.websiteId);let i=await c({service:"main",query:`query ($couponId: ID) {
|
|
251
|
+
coupon(couponId: $couponId) {
|
|
252
|
+
${D}
|
|
253
|
+
}
|
|
254
|
+
}`,variables:{couponId:t}});return{context:e,coupon:i.coupon}}async function ko(o,t){let e=await f(o),i=S(t,"input");if(i.websiteId&&i.websiteId!==e.websiteId)throw Error("El websiteId del input no coincide con el website seleccionado.");let r={...i,websiteId:e.websiteId},s=de(r),n=await c({service:"main",query:s,variables:r});return{context:e,coupon:n.createCoupon}}async function Ko(o,t,e){let i=await f(o);await E(t,i.websiteId);let r=S(e,"input"),s=await c({service:"main",query:`mutation ($couponId: ID, $coupon: UpdateCouponInput) {
|
|
255
|
+
updateCoupon(couponId: $couponId, coupon: $coupon) {
|
|
256
|
+
${D}
|
|
257
|
+
}
|
|
258
|
+
}`,variables:{couponId:t,coupon:r}});return{context:i,coupon:s.updateCoupon}}async function Vo(o,t){let e=await f(o);await E(t,e.websiteId);let i=await c({service:"main",query:`mutation ($couponsIds: [ID]) {
|
|
259
|
+
deleteCoupons(couponsIds: $couponsIds, globalCoupon: false)
|
|
260
|
+
}`,variables:{couponsIds:[t]}});return{context:e,couponId:t,deleted:i.deleteCoupons}}function M(){return`team-cli admin coupons
|
|
261
|
+
|
|
262
|
+
Administracion de cupones para el website seleccionado.
|
|
263
|
+
|
|
264
|
+
Uso:
|
|
265
|
+
team-cli admin <websiteId|domain> coupons <accion> [opciones]
|
|
266
|
+
|
|
267
|
+
Acciones:
|
|
268
|
+
list
|
|
269
|
+
Listar cupones.
|
|
270
|
+
Uso: team-cli admin <web> coupons list [--filter <text>] [--limit <n>] [--page <n>]
|
|
271
|
+
|
|
272
|
+
show
|
|
273
|
+
Ver detalle de un cupón.
|
|
274
|
+
Uso: team-cli admin <web> coupons show <couponId>
|
|
275
|
+
|
|
276
|
+
create
|
|
277
|
+
Crear un cupón usando --input con JSON.
|
|
278
|
+
Uso: team-cli admin <web> coupons create --input '<json>'
|
|
279
|
+
Ayuda detallada: team-cli admin <web> coupons create --help
|
|
280
|
+
|
|
281
|
+
update
|
|
282
|
+
Actualizar un cupón usando --input con JSON.
|
|
283
|
+
Uso: team-cli admin <web> coupons update <couponId> --input '<json>'
|
|
284
|
+
Ayuda detallada: team-cli admin <web> coupons update <couponId> --help
|
|
285
|
+
|
|
286
|
+
delete
|
|
287
|
+
Eliminar un cupón.
|
|
288
|
+
Uso: team-cli admin <web> coupons delete <couponId>
|
|
289
|
+
|
|
290
|
+
codes list
|
|
291
|
+
Listar códigos de un cupón.
|
|
292
|
+
Uso: team-cli admin <web> coupons codes list <couponId> [--filter <text>] [--limit <n>] [--page <n>]
|
|
293
|
+
|
|
294
|
+
codes create
|
|
295
|
+
Crear códigos explícitos para un cupón.
|
|
296
|
+
Uso: team-cli admin <web> coupons codes create <couponId> --input '<json>'
|
|
297
|
+
Ayuda detallada: team-cli admin <web> coupons codes create <couponId> --help
|
|
298
|
+
|
|
299
|
+
codes create-random
|
|
300
|
+
Crear códigos aleatorios para un cupón.
|
|
301
|
+
Uso: team-cli admin <web> coupons codes create-random <couponId> --quantity <n> [--prefix <text>]
|
|
302
|
+
|
|
303
|
+
codes delete
|
|
304
|
+
Eliminar códigos por id.
|
|
305
|
+
Uso: team-cli admin <web> coupons codes delete <couponId> --ids '["id1","id2"]'
|
|
306
|
+
|
|
307
|
+
Nota:
|
|
308
|
+
El schema actual no expone update para coupon codes.`}function Lo(){return`team-cli admin coupons create
|
|
309
|
+
|
|
310
|
+
Crea un cupón para el website seleccionado.
|
|
311
|
+
|
|
312
|
+
Uso:
|
|
313
|
+
team-cli admin <websiteId|domain> coupons create --input '<json>'
|
|
314
|
+
|
|
315
|
+
Como funciona:
|
|
316
|
+
--input recibe un objeto JSON con los campos de createCoupon.
|
|
317
|
+
team-cli agrega automaticamente websiteId usando el contexto seleccionado.
|
|
318
|
+
Si mandas websiteId dentro del JSON y no coincide con el website seleccionado, el comando falla.
|
|
319
|
+
|
|
320
|
+
Campos comunes:
|
|
321
|
+
name
|
|
322
|
+
code
|
|
323
|
+
type
|
|
324
|
+
active
|
|
325
|
+
description
|
|
326
|
+
percentageOff
|
|
327
|
+
discountAmount
|
|
328
|
+
fixedAmount
|
|
329
|
+
maxRedemptions
|
|
330
|
+
maxRedemptionsPerUser
|
|
331
|
+
minimumOrderPrice
|
|
332
|
+
maximumOrderPrice
|
|
333
|
+
fromDate
|
|
334
|
+
endDate
|
|
335
|
+
requiresStoresIds
|
|
336
|
+
requireChannels
|
|
337
|
+
requiresPaymentTypes
|
|
338
|
+
requiredBINs
|
|
339
|
+
schedule
|
|
340
|
+
scheduleAtUse
|
|
341
|
+
|
|
342
|
+
Ejemplo porcentaje:
|
|
343
|
+
team-cli admin <web> coupons create --input '{"name":"Promo 20","code":"PROMO20","type":"percentage","percentageOff":20,"active":true}'
|
|
344
|
+
|
|
345
|
+
Ejemplo monto fijo:
|
|
346
|
+
team-cli admin <web> coupons create --input '{"name":"Descuento 5000","code":"MENOS5K","type":"fixed","discountAmount":5000,"active":true}'
|
|
347
|
+
|
|
348
|
+
Ejemplo con restricciones:
|
|
349
|
+
team-cli admin <web> coupons create --input '{"name":"Solo retiro","code":"GOONLY","type":"fixed","discountAmount":3000,"active":true,"requiresStoresIds":["store1","store2"],"requireChannels":["web"]}'
|
|
350
|
+
|
|
351
|
+
Ejemplo con schedule:
|
|
352
|
+
team-cli admin <web> coupons create --input '{"name":"Happy Hour","code":"HAPPY","type":"percentage","percentageOff":15,"schedule":{"timezone":"America/Santiago","isAvailableNow":true,"openPeriods":[{"daysOfWeek":[1,2,3,4,5],"fromMinute":720,"toMinute":900}]}}'
|
|
353
|
+
|
|
354
|
+
Tips:
|
|
355
|
+
Usa comillas simples afuera del JSON en shell.
|
|
356
|
+
Usa arrays JSON reales para ids o listas.
|
|
357
|
+
Si necesitas el shape exacto de un cupón existente, parte con: team-cli admin <web> coupons show <couponId>`}function ot(){return`team-cli admin coupons update
|
|
358
|
+
|
|
359
|
+
Actualiza un cupón existente.
|
|
360
|
+
|
|
361
|
+
Uso:
|
|
362
|
+
team-cli admin <websiteId|domain> coupons update <couponId> --input '<json>'
|
|
363
|
+
|
|
364
|
+
Como funciona:
|
|
365
|
+
--input recibe un objeto JSON compatible con UpdateCouponInput.
|
|
366
|
+
Solo envía los campos que quieras cambiar.
|
|
367
|
+
couponId se valida contra el website seleccionado antes de ejecutar la mutation.
|
|
368
|
+
|
|
369
|
+
Campos comunes:
|
|
370
|
+
name
|
|
371
|
+
active
|
|
372
|
+
description
|
|
373
|
+
percentageOff
|
|
374
|
+
discountAmount
|
|
375
|
+
fixedAmount
|
|
376
|
+
maxRedemptions
|
|
377
|
+
maxRedemptionsPerUser
|
|
378
|
+
minimumOrderPrice
|
|
379
|
+
maximumOrderPrice
|
|
380
|
+
fromDate
|
|
381
|
+
endDate
|
|
382
|
+
requiresStoresIds
|
|
383
|
+
requireChannels
|
|
384
|
+
requiresPaymentTypes
|
|
385
|
+
requiredBINs
|
|
386
|
+
schedule
|
|
387
|
+
scheduleAtUse
|
|
388
|
+
|
|
389
|
+
Ejemplo simple:
|
|
390
|
+
team-cli admin <web> coupons update <couponId> --input '{"active":false}'
|
|
391
|
+
|
|
392
|
+
Ejemplo cambiando descuento:
|
|
393
|
+
team-cli admin <web> coupons update <couponId> --input '{"percentageOff":25,"maxRedemptions":100}'
|
|
394
|
+
|
|
395
|
+
Ejemplo reemplazando restricciones:
|
|
396
|
+
team-cli admin <web> coupons update <couponId> --input '{"requiresStoresIds":["store1"],"requiresPaymentTypes":["card"]}'
|
|
397
|
+
|
|
398
|
+
Tip:
|
|
399
|
+
Primero mira el cupón actual con: team-cli admin <web> coupons show <couponId>`}function le(o){if(!Array.isArray(o))throw Error("--input debe ser un arreglo JSON.");return o.map((t)=>{if(!t||typeof t!=="object"||typeof t.code!=="string")throw Error('Cada item de --input debe tener al menos { "code": "..." }.');if(t.userEmail!=null&&typeof t.userEmail!=="string")throw Error("userEmail debe ser string cuando viene informado.");return{code:t.code,userEmail:t.userEmail}})}function pe(o){if(!Array.isArray(o)||o.some((t)=>typeof t!=="string"))throw Error("--ids debe ser un arreglo JSON de strings.");return o}async function tt(o,t,e){let i=await f(o);await E(t,i.websiteId);let r=$(e,"limit"),s=$(e,"page"),n=e.filter,a=await c({service:"main",query:`query ($couponId: ID, $filter: String, $limit: BigInt, $page: BigInt) {
|
|
400
|
+
couponCodes(couponId: $couponId, filter: $filter, limit: $limit, page: $page) {
|
|
401
|
+
items {
|
|
402
|
+
${Fo}
|
|
403
|
+
}
|
|
404
|
+
totalCount
|
|
405
|
+
totalPages
|
|
406
|
+
hasNextPage
|
|
407
|
+
hasPreviousPage
|
|
408
|
+
}
|
|
409
|
+
}`,variables:{couponId:t,filter:n,limit:r,page:s}});return{context:i,couponId:t,codes:a.couponCodes.items??[],pagination:{totalCount:a.couponCodes.totalCount??0,totalPages:a.couponCodes.totalPages??0,hasNextPage:Boolean(a.couponCodes.hasNextPage),hasPreviousPage:Boolean(a.couponCodes.hasPreviousPage),page:s??1,limit:r??null}}}async function et(o,t,e){let i=await f(o);await E(t,i.websiteId);let r=le(S(e,"input")),s=r.some((a)=>a.userEmail),n=await c({service:"main",query:`mutation ($couponId: ID, $codesWithEmail: [CodeWithEmailInput], $useCodeWithEmail: Boolean) {
|
|
410
|
+
createCouponCodes(couponId: $couponId, codesWithEmail: $codesWithEmail, useCodeWithEmail: $useCodeWithEmail)
|
|
411
|
+
}`,variables:{couponId:t,codesWithEmail:r,useCodeWithEmail:s}});return{context:i,couponId:t,requestedCount:r.length,result:n.createCouponCodes}}async function it(o,t,e){let i=await f(o);await E(t,i.websiteId);let r=$(e,"quantity");if(!r)throw Error("--quantity es requerido.");let s=await c({service:"main",query:`mutation ($couponId: ID, $couponQuantity: Float, $couponCodePrefix: String) {
|
|
412
|
+
createRandomCouponCodes(couponId: $couponId, couponQuantity: $couponQuantity, couponCodePrefix: $couponCodePrefix)
|
|
413
|
+
}`,variables:{couponId:t,couponQuantity:r,couponCodePrefix:e.prefix}});return{context:i,couponId:t,quantity:r,prefix:e.prefix??null,result:s.createRandomCouponCodes}}async function rt(o,t,e){let i=await f(o);await E(t,i.websiteId);let r=pe(S(e,"ids")),s=await c({service:"main",query:`mutation ($couponId: ID, $couponCodesIds: [ID]) {
|
|
414
|
+
deleteCouponCodes(couponId: $couponId, couponCodesIds: $couponCodesIds, globalCoupon: false)
|
|
415
|
+
}`,variables:{couponId:t,couponCodesIds:r}});return{context:i,couponId:t,deleted:s.deleteCouponCodes,couponCodesIds:r}}function st(){return`team-cli admin coupons codes create
|
|
416
|
+
|
|
417
|
+
Crea códigos explícitos para un cupón.
|
|
418
|
+
|
|
419
|
+
Uso:
|
|
420
|
+
team-cli admin <websiteId|domain> coupons codes create <couponId> --input '<json>'
|
|
421
|
+
|
|
422
|
+
Como funciona:
|
|
423
|
+
--input recibe un arreglo JSON.
|
|
424
|
+
Cada item debe tener al menos el campo code.
|
|
425
|
+
Opcionalmente puede incluir userEmail.
|
|
426
|
+
|
|
427
|
+
Formato esperado:
|
|
428
|
+
[
|
|
429
|
+
{"code":"BIENVENIDA1"},
|
|
430
|
+
{"code":"BIENVENIDA2","userEmail":"persona@ejemplo.com"}
|
|
431
|
+
]
|
|
432
|
+
|
|
433
|
+
Ejemplo:
|
|
434
|
+
team-cli admin <web> coupons codes create <couponId> --input '[{"code":"PROMO001"},{"code":"PROMO002","userEmail":"ana@ejemplo.com"}]'
|
|
435
|
+
|
|
436
|
+
Notas:
|
|
437
|
+
Si algún item trae userEmail, team-cli activa useCodeWithEmail automáticamente.
|
|
438
|
+
couponId se valida contra el website seleccionado antes de ejecutar la mutation.`}import{writeFileSync as we}from"node:fs";function k(){if(!d())throw Error("Debes iniciar sesión primero. Usa: team-cli auth login")}function K(o,t){let e=o[3];if(!e)throw Error(`Uso: ${t}`);return e}function nt(o){if(!o.params)return{};try{return JSON.parse(o.params)}catch{throw Error("--params debe ser un JSON válido.")}}function fe(o){if(typeof o!=="string")return o;try{return JSON.parse(o)}catch{return{value:o}}}async function at(o){k();let t=K(o,"team-cli data queries view <queryId>");return(await c({service:"data",query:`query ($aggregationQueryId: String) {
|
|
39
439
|
aggregationQuery(aggregationQueryId: $aggregationQueryId) {
|
|
40
440
|
_id
|
|
41
441
|
name
|
|
@@ -48,15 +448,17 @@ var sg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",pr
|
|
|
48
448
|
fieldParams
|
|
49
449
|
}
|
|
50
450
|
}
|
|
51
|
-
}`,variables:{aggregationQueryId:
|
|
451
|
+
}`,variables:{aggregationQueryId:t}})).aggregationQuery}async function ct(o){k();let t=K(o,"team-cli data queries view-pipeline <queryId>"),e=await c({service:"data",query:`query ($aggregationQueryId: String) {
|
|
52
452
|
aggregationQuery(aggregationQueryId: $aggregationQueryId) {
|
|
53
453
|
pipeline
|
|
54
454
|
}
|
|
55
|
-
}`,variables:{aggregationQueryId:
|
|
455
|
+
}`,variables:{aggregationQueryId:t}});return{queryId:t,pipeline:e.aggregationQuery.pipeline}}async function mt(o,t){k();let e=K(o,"team-cli data queries preview <queryId> --params '<json>'"),i=nt(t),r=await c({service:"data",query:`mutation ($aggregationQueryId: String, $params: JSON) {
|
|
56
456
|
testAggregationQuery(aggregationQueryId: $aggregationQueryId, params: $params)
|
|
57
|
-
}`,variables:{aggregationQueryId:
|
|
457
|
+
}`,variables:{aggregationQueryId:e,params:i}});return fe(r.testAggregationQuery)}function be(o){return new Promise((t)=>setTimeout(t,o))}async function ut(o,t){k();let e=K(o,"team-cli data queries download <queryId> --params '<json>'"),i=nt(t);if(!t.path)throw Error("--path es requerido. Ejemplo: --path resultado.xlsx");let r=t.path;I(`Iniciando descarga...
|
|
458
|
+
`);let n=(await c({service:"data",query:`mutation ($aggregationQueryId: String, $params: JSON) {
|
|
58
459
|
downloadAggregationQueryData(aggregationQueryId: $aggregationQueryId, params: $params)
|
|
59
|
-
}`,variables:{aggregationQueryId:
|
|
460
|
+
}`,variables:{aggregationQueryId:e,params:i}})).downloadAggregationQueryData;I(`Reporte en proceso (${n})...
|
|
461
|
+
`);let a=null;while(!a){await be(1000);let b=await c({service:"data",query:`query ($id: String) {
|
|
60
462
|
getAsyncReport(id: $id) {
|
|
61
463
|
_id
|
|
62
464
|
status
|
|
@@ -64,30 +466,42 @@ var sg={main:{local:"http://localhost:3000",develop:"https://api.bejusto.com",pr
|
|
|
64
466
|
fileUrl
|
|
65
467
|
}
|
|
66
468
|
getAsyncReportRecordsCount(id: $id)
|
|
67
|
-
}`,variables:{id:
|
|
68
|
-
`),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
team-cli data queries download
|
|
90
|
-
|
|
469
|
+
}`,variables:{id:n}}),q=b.getAsyncReport,j=b.getAsyncReportRecordsCount;if(q.status==="error")throw Error("El reporte falló al generarse.");if(q.fileUrl)a=q.fileUrl;else{let G=q.estimatedRecordsCount?` (~${q.estimatedRecordsCount} registros)`:"",x=j!=null?` ${j} procesados`:"";I(`\rGenerando...${G}${x}`)}}I(`
|
|
470
|
+
`),I(`Descargando archivo...
|
|
471
|
+
`);let u=await fetch(a);if(!u.ok)throw Error(`Error descargando archivo: ${u.status}`);let y=Buffer.from(await u.arrayBuffer());return we(r,y),{ok:!0,queryId:e,asyncReportId:n,outputPath:r,fileUrl:a}}function go(){return`team-cli data
|
|
472
|
+
|
|
473
|
+
Comandos de datos y reportes.
|
|
474
|
+
|
|
475
|
+
Uso:
|
|
476
|
+
team-cli data queries <subcomando> [opciones]
|
|
477
|
+
|
|
478
|
+
Subcomandos:
|
|
479
|
+
view <queryId>
|
|
480
|
+
Ver informacion de un query.
|
|
481
|
+
|
|
482
|
+
view-pipeline <queryId>
|
|
483
|
+
Ver el pipeline de un query.
|
|
484
|
+
|
|
485
|
+
preview <queryId>
|
|
486
|
+
Ejecutar un query de prueba.
|
|
487
|
+
Uso: team-cli data queries preview <queryId> --params '<json>' [--format toon|json]
|
|
488
|
+
|
|
489
|
+
download <queryId>
|
|
490
|
+
Descargar resultado completo como Excel.
|
|
491
|
+
Uso: team-cli data queries download <queryId> --path <filepath> [--params '<json>'] [--format toon|json]
|
|
492
|
+
|
|
493
|
+
Opciones:
|
|
494
|
+
--params '<json>' Parametros del query. Default: {}
|
|
495
|
+
--format <toon|json>
|
|
496
|
+
--path <filepath> Requerido para download
|
|
497
|
+
|
|
498
|
+
Ejemplos:
|
|
499
|
+
team-cli data queries view abc123
|
|
500
|
+
team-cli data queries view-pipeline abc123
|
|
501
|
+
team-cli data queries preview abc123 --params '{"startDate": "2026-01-01"}'
|
|
502
|
+
team-cli data queries download abc123 --params '{"startDate": "2026-01-01"}' --path resultado.xlsx`}var qe=["local","develop","prod"];function gt(){return Object.keys(X)}function Ce(){return gt().map((o)=>{return[`- \`${o}\``,...qe.map((e)=>{let i=X[o][e];return` - ${e}: \`${i}/graphql\``})].join(`
|
|
503
|
+
`)}).join(`
|
|
504
|
+
`)}function Ie(){let t=gt().join(", "),e=Ce();return`# @getjusto/team-cli
|
|
91
505
|
|
|
92
506
|
CLI tool for Justo team members. Authenticated access to Justo's GraphQL services and data queries.
|
|
93
507
|
|
|
@@ -116,7 +530,7 @@ npx @getjusto/team-cli auth login
|
|
|
116
530
|
npx @getjusto/team-cli graphql <service> '<query>' [--variables '<json>'] [--format toon|json]
|
|
117
531
|
\`\`\`
|
|
118
532
|
|
|
119
|
-
Available services:
|
|
533
|
+
Available services: ${t}.
|
|
120
534
|
|
|
121
535
|
Examples:
|
|
122
536
|
\`\`\`bash
|
|
@@ -125,6 +539,94 @@ npx @getjusto/team-cli graphql main 'query($id: ID) { user(userId: $id) { _id }
|
|
|
125
539
|
npx @getjusto/team-cli graphql tabs 'query { tab(tabId: "t123") { _id status } }' --format json
|
|
126
540
|
\`\`\`
|
|
127
541
|
|
|
542
|
+
### graphql info — Inspect query/mutation params and result metadata
|
|
543
|
+
|
|
544
|
+
Use this before writing the final GraphQL call when you only know the operation name, or when someone shares a curl and you need to understand the params expected by the resolver.
|
|
545
|
+
|
|
546
|
+
\`\`\`bash
|
|
547
|
+
npx @getjusto/team-cli graphql <service> info <queryName|mutationName> [--format toon|json]
|
|
548
|
+
\`\`\`
|
|
549
|
+
|
|
550
|
+
What it returns:
|
|
551
|
+
- \`operationType\` — whether Orion exposed it as query or mutation
|
|
552
|
+
- \`info.params\` — serialized params schema, including optional fields and GraphQL scalar types
|
|
553
|
+
- \`info.result\` — top-level result model/type name when available
|
|
554
|
+
- \`info.basicResultQuery\` — a starter field selection you can reuse in the final GraphQL document
|
|
555
|
+
|
|
556
|
+
Examples:
|
|
557
|
+
\`\`\`bash
|
|
558
|
+
npx @getjusto/team-cli graphql main info website
|
|
559
|
+
npx @getjusto/team-cli graphql auth info requestLoginCode --format json
|
|
560
|
+
\`\`\`
|
|
561
|
+
|
|
562
|
+
Recommended workflow for converting a curl into team-cli:
|
|
563
|
+
1. Identify the service from the GraphQL URL.
|
|
564
|
+
2. If you know the operation name, inspect it first with \`graphql <service> info <name>\`.
|
|
565
|
+
3. Use \`info.params\` to build the variables object.
|
|
566
|
+
4. Use \`info.basicResultQuery\` as the starting selection set.
|
|
567
|
+
5. Run the final command with \`graphql <service> '<queryOrMutation>' --variables '<json>'\`.
|
|
568
|
+
|
|
569
|
+
### GraphQL Service Map
|
|
570
|
+
|
|
571
|
+
Use this when someone shares a GraphQL \`curl\` and you need to map the URL to the correct \`team-cli graphql <service>\` value.
|
|
572
|
+
|
|
573
|
+
Rule:
|
|
574
|
+
- If the curl points to \`https://something/.../graphql\`, match that URL against the list below and use the corresponding service name.
|
|
575
|
+
- In \`team-cli\`, you pass the service name only, not the full URL.
|
|
576
|
+
|
|
577
|
+
Service name to endpoint map:
|
|
578
|
+
${e}
|
|
579
|
+
|
|
580
|
+
Example conversion:
|
|
581
|
+
\`\`\`bash
|
|
582
|
+
# curl
|
|
583
|
+
curl 'https://tabs.service.getjusto.com/graphql' \\
|
|
584
|
+
-H 'content-type: application/json' \\
|
|
585
|
+
--data-raw '{"query":"query { tab(tabId: \\"t123\\") { _id status } }"}'
|
|
586
|
+
|
|
587
|
+
# inspect the resolver first
|
|
588
|
+
npx @getjusto/team-cli graphql tabs info tab
|
|
589
|
+
|
|
590
|
+
# team-cli
|
|
591
|
+
npx @getjusto/team-cli graphql tabs 'query { tab(tabId: "t123") { _id status } }'
|
|
592
|
+
\`\`\`
|
|
593
|
+
|
|
594
|
+
### admin search — Search websites/brands in admin
|
|
595
|
+
|
|
596
|
+
Use this when you need to find a website first before calling other admin commands.
|
|
597
|
+
|
|
598
|
+
\`\`\`bash
|
|
599
|
+
npx @getjusto/team-cli admin search <text> [--limit <n>] [--page <n>] [--only-active true|false]
|
|
600
|
+
\`\`\`
|
|
601
|
+
|
|
602
|
+
What it returns:
|
|
603
|
+
- \`_id\`
|
|
604
|
+
- \`name\`
|
|
605
|
+
- \`active\`
|
|
606
|
+
- \`baseURL\`
|
|
607
|
+
- \`domain\`
|
|
608
|
+
- \`countryCode\`
|
|
609
|
+
- \`timezone\`
|
|
610
|
+
|
|
611
|
+
Typical use:
|
|
612
|
+
1. Search the brand/site by name fragment.
|
|
613
|
+
2. Take either the returned \`_id\` or a known domain/baseURL.
|
|
614
|
+
3. Use that value in \`team-cli admin <websiteId|domain> ...\`.
|
|
615
|
+
|
|
616
|
+
Examples:
|
|
617
|
+
\`\`\`bash
|
|
618
|
+
# find the website
|
|
619
|
+
npx @getjusto/team-cli admin search milas --limit 5
|
|
620
|
+
|
|
621
|
+
# then use the returned website id
|
|
622
|
+
npx @getjusto/team-cli admin YRZjQ7L6whxfkezmF show
|
|
623
|
+
npx @getjusto/team-cli admin YRZjQ7L6whxfkezmF stores list
|
|
624
|
+
npx @getjusto/team-cli admin YRZjQ7L6whxfkezmF coupons list
|
|
625
|
+
|
|
626
|
+
# or use a domain directly
|
|
627
|
+
npx @getjusto/team-cli admin www.masmilas.com show
|
|
628
|
+
\`\`\`
|
|
629
|
+
|
|
128
630
|
### data queries view — View query metadata and required variables
|
|
129
631
|
|
|
130
632
|
\`\`\`bash
|
|
@@ -166,22 +668,33 @@ Default output is TOON (Token-Oriented Object Notation), a compact human-readabl
|
|
|
166
668
|
1. View a query to understand its variables: \`data queries view <id>\`
|
|
167
669
|
2. Preview with params: \`data queries preview <id> --params '{"startDate": "2026-01-01"}'\`
|
|
168
670
|
3. Download full data: \`data queries download <id> --params '{"startDate": "2026-01-01"}' --path output.xlsx\`
|
|
169
|
-
`)}var{positional:
|
|
170
|
-
|
|
671
|
+
`}function dt(){return{skill:Ie()}}var{positional:l,flags:m}=wo(process.argv.slice(2));if(m.env)lo(m.env);var Q=l[0],P=l[1];function lt(){let o=d();return`team-cli
|
|
672
|
+
|
|
673
|
+
Herramienta CLI para el equipo Justo.
|
|
674
|
+
|
|
675
|
+
${o?`Sesión: ${o.email}`:"Sesión: no iniciada"}
|
|
676
|
+
|
|
677
|
+
Uso:
|
|
678
|
+
team-cli <comando> [opciones]
|
|
679
|
+
|
|
680
|
+
Comandos:
|
|
681
|
+
auth
|
|
682
|
+
Gestión de sesión.
|
|
683
|
+
|
|
684
|
+
admin
|
|
685
|
+
Comandos administrativos con contexto de website.
|
|
171
686
|
|
|
172
|
-
|
|
687
|
+
graphql
|
|
688
|
+
Ejecutar queries y mutations GraphQL.
|
|
173
689
|
|
|
174
|
-
|
|
175
|
-
|
|
690
|
+
data
|
|
691
|
+
Datos y reportes.
|
|
176
692
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
graphql Ejecutar queries/mutations GraphQL
|
|
180
|
-
data Datos y reportes
|
|
181
|
-
get-skill Obtener skill para usar con Claude
|
|
693
|
+
get-skill
|
|
694
|
+
Obtener skill para usar con Claude.
|
|
182
695
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
696
|
+
Opciones globales:
|
|
697
|
+
--env <local|develop|prod>
|
|
698
|
+
--version
|
|
699
|
+
--help
|
|
700
|
+
--format <toon|json>`}async function $e(){try{let o;if(m.version)o={version:"0.0.4"};else if(m.help&&!Q){g(lt());return}else if(Q==="auth")if(P==="--help"||m.help){g(co());return}else if(P==="login")o=await Wo();else if(P==="login-with-token")o=await Ao(m);else if(P==="request-code")o=await Oo(m);else if(P==="logout")o=await So();else if(P==="status")o=await Qo();else{g(co());return}else if(Q==="admin"){let t=l[1],e=l[2],i=l[3],r=l[4];if(!t||t==="--help"){g(H());return}else if(t==="search"&&m.help){g(Yo());return}else if(t==="search")o=await Xo(l,m);else if(!e||e==="--help"){g(H());return}else if(e==="show")o=await To(t);else if(e==="stores"&&i==="list")o=await Zo(t);else if(e==="coupons"&&(!i||i==="--help")){g(M());return}else if(e==="coupons"&&i==="create"&&m.help){g(Lo());return}else if(e==="coupons"&&i==="update"&&m.help){g(ot());return}else if(e==="coupons"&&i==="codes"&&l[4]==="create"&&m.help){g(st());return}else if(e==="coupons"&&m.help){g(M());return}else if(e==="coupons"&&i==="list")o=await Ho(t,m);else if(e==="coupons"&&i==="show"){if(!r)throw Error("Uso: team-cli admin <web> coupons show <couponId>");o=await Do(t,r)}else if(e==="coupons"&&i==="create")o=await ko(t,m);else if(e==="coupons"&&i==="update"){if(!r)throw Error("Uso: team-cli admin <web> coupons update <couponId> --input '<json>'");o=await Ko(t,r,m)}else if(e==="coupons"&&i==="delete"){if(!r)throw Error("Uso: team-cli admin <web> coupons delete <couponId>");o=await Vo(t,r)}else if(e==="coupons"&&i==="codes"){let s=l[4],n=l[5];if(!s||s==="--help"){g(M());return}else if(s==="list"){if(!n)throw Error("Uso: team-cli admin <web> coupons codes list <couponId>");o=await tt(t,n,m)}else if(s==="create"){if(!n)throw Error("Uso: team-cli admin <web> coupons codes create <couponId> --input '<json>'");o=await et(t,n,m)}else if(s==="create-random"){if(!n)throw Error("Uso: team-cli admin <web> coupons codes create-random <couponId> --quantity <n>");o=await it(t,n,m)}else if(s==="delete"){if(!n)throw Error(`Uso: team-cli admin <web> coupons codes delete <couponId> --ids '["id1"]'`);o=await rt(t,n,m)}else{g(M());return}}else{g(H());return}}else if(Q==="graphql")if(P==="--help"||m.help){g(Jo());return}else o=await Bo(l,m);else if(Q==="get-skill")o=dt();else if(Q==="data"){let t=l[1],e=l[2];if(m.help||P==="--help"){g(go());return}else if(t==="queries"&&e==="view")o=await at(l);else if(t==="queries"&&e==="view-pipeline")o=await ct(l);else if(t==="queries"&&e==="preview")o=await mt(l,m);else if(t==="queries"&&e==="download")o=await ut(l,m);else{g(go());return}}else{g(lt());return}if(o!==void 0)xo(o,m)}catch(o){Uo(o,m),process.exit(1)}}$e();
|