@winning-sales/nexo 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,51 @@
1
+ const HTML_ESCAPES = {
2
+ '&': '&',
3
+ '<': '&lt;',
4
+ '>': '&gt;',
5
+ '"': '&quot;',
6
+ "'": '&#39;'
7
+ };
8
+ export function escapeHtml(value) {
9
+ return value.replace(/[&<>"']/g, (character) => HTML_ESCAPES[character] ?? character);
10
+ }
11
+ /** Tokens from the Nexo web app (nexu-fe src/index.css) and the site (nexo-site global.css). */
12
+ const STYLE = `
13
+ :root{color-scheme:light dark;--bg:#f6f2ed;--surface:#fffdfa;--line:#eae2d8;--ink:#1e1915;--ink-2:#57504a;--ink-3:#736a61;--brand:#e0294b;--violet:#6e56cf;--good:#178046;--good-soft:#e3f4ea;--crit:#c42841;--crit-soft:#fce8eb;--code:#f8f3ee;--shadow:0 2px 4px rgba(20,18,40,.04),0 16px 40px -12px rgba(60,30,90,.18)}
14
+ @media (prefers-color-scheme:dark){:root{--bg:#13110f;--surface:#1c1916;--line:#302a25;--ink:#f6f1eb;--ink-2:#c7beb3;--ink-3:#9e958a;--brand:#ff4f6d;--violet:#9d8cf0;--good:#4acb86;--good-soft:#13281c;--crit:#ff6b82;--crit-soft:#33161e;--code:#231f1b;--shadow:0 2px 4px rgba(0,0,0,.3),0 20px 44px -12px rgba(0,0,0,.6)}}
15
+ *{box-sizing:border-box}
16
+ html{background:var(--bg)}
17
+ body{margin:0;min-height:100vh;display:grid;place-items:center;padding:24px 16px;background:radial-gradient(60rem 30rem at 50% -10%,var(--surface),transparent);color:var(--ink);font-family:Nunito,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;line-height:1.55;-webkit-font-smoothing:antialiased}
18
+ main{width:100%;max-width:26rem;text-align:center;background:var(--surface);border:1px solid var(--line);border-radius:20px;padding:40px 32px 36px;box-shadow:var(--shadow)}
19
+ .brand{color:var(--ink);display:inline-flex;align-items:center;gap:10px;margin:0 0 32px;font-size:1.5rem;font-weight:800;letter-spacing:-.02em}
20
+ .brand svg{width:32px;height:32px}
21
+ .mark-ring{fill:none;stroke:var(--brand);stroke-width:5}
22
+ .mark-handle{fill:none;stroke:var(--violet);stroke-width:5.5;stroke-linecap:round}
23
+ .badge{display:grid;place-items:center;width:72px;height:72px;margin:0 auto 20px;border-radius:50%}
24
+ .badge svg{width:36px;height:36px;fill:none;stroke:currentColor;stroke-width:3;stroke-linecap:round;stroke-linejoin:round}
25
+ .success .badge{background:var(--good-soft);color:var(--good)}
26
+ .error .badge{background:var(--crit-soft);color:var(--crit)}
27
+ h1{margin:0 0 8px;font-size:1.75rem;line-height:1.2;font-weight:800;letter-spacing:-.02em;text-wrap:balance}
28
+ p{margin:0;color:var(--ink-2);font-size:1.0625rem;text-wrap:pretty}
29
+ .hint{margin-top:20px;padding-top:20px;border-top:1px solid var(--line);font-size:.9375rem;color:var(--ink-3)}
30
+ code{padding:2px 8px;border-radius:6px;background:var(--code);border:1px solid var(--line);color:var(--ink);font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.9em}
31
+ @media (prefers-reduced-motion:no-preference){.badge{animation:pop .45s cubic-bezier(.2,.9,.3,1.2) both}@keyframes pop{from{transform:scale(.6);opacity:0}to{transform:scale(1);opacity:1}}}
32
+ @media (max-width:420px){main{padding:32px 20px 28px;border-radius:16px}}
33
+ `
34
+ .trim()
35
+ .replace(/\n/g, '');
36
+ const MARK = '<svg viewBox="0 0 32 32" aria-hidden="true" focusable="false"><circle class="mark-ring" cx="13.5" cy="13.5" r="9"/><path class="mark-handle" d="M20.6 20.6L27 27"/></svg>';
37
+ const ICONS = {
38
+ success: '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>',
39
+ error: '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M6.5 6.5l11 11M17.5 6.5l-11 11"/></svg>'
40
+ };
41
+ const RETRY_HINT = 'Volte ao terminal e rode <code>nexo login</code> de novo.';
42
+ /** Escapes title and text, so a caller can pass text that came from the callback URL. No other caller text reaches the page. */
43
+ export function renderCallbackPage(content) {
44
+ const title = escapeHtml(content.title);
45
+ const hint = content.retry === true ? `<p class="hint">${RETRY_HINT}</p>` : '';
46
+ return (`<!doctype html><html lang="pt-BR"><head><meta charset="utf-8">` +
47
+ `<meta name="viewport" content="width=device-width,initial-scale=1">` +
48
+ `<meta name="color-scheme" content="light dark"><title>${title} - Nexo</title><style>${STYLE}</style></head>` +
49
+ `<body><main class="${content.state}"><div class="brand">${MARK}<span>Nexo</span></div>` +
50
+ `<div class="badge">${ICONS[content.state]}</div><h1>${title}</h1><p>${escapeHtml(content.text)}</p>${hint}</main></body></html>`);
51
+ }
@@ -1,14 +1,24 @@
1
1
  import { createServer } from 'node:http';
2
+ import { renderCallbackPage } from './callback-page.js';
2
3
  import { CliError } from '../errors.js';
3
4
  import { EXIT_CODES } from '../exit-codes.types.js';
4
- const PAGE_STYLE = 'font-family:system-ui,sans-serif;max-width:32rem;margin:4rem auto;padding:0 1rem;line-height:1.5';
5
- function page(title, text) {
6
- return `<!doctype html><html lang="pt-BR"><meta charset="utf-8"><title>${title}</title><body style="${PAGE_STYLE}"><h1>${title}</h1><p>${text}</p></body></html>`;
7
- }
8
5
  function answer(response, status, html) {
9
6
  response.writeHead(status, { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' });
10
7
  response.end(html);
11
8
  }
9
+ function answerNotFound(response) {
10
+ answer(response, 404, renderCallbackPage({ state: 'error', title: 'Nada aqui', text: 'Este endereço só recebe a volta do login do Nexo.' }));
11
+ }
12
+ function answerFailure(response, error) {
13
+ answer(response, 400, renderCallbackPage({ state: 'error', title: 'Não deu certo', text: error.message, retry: true }));
14
+ }
15
+ function answerSuccess(response) {
16
+ answer(response, 200, renderCallbackPage({
17
+ state: 'success',
18
+ title: 'Pronto',
19
+ text: 'A CLI do Nexo recebeu o acesso. Pode fechar esta aba e voltar ao terminal.'
20
+ }));
21
+ }
12
22
  function failure(message) {
13
23
  return new CliError(message, EXIT_CODES.unauthenticated, 'Rode `nexo login` de novo.');
14
24
  }
@@ -34,17 +44,17 @@ function waitForCode(server, redirectUri, expectation) {
34
44
  server.on('request', (request, response) => {
35
45
  const url = new URL(request.url ?? '/', redirectUri);
36
46
  if (url.pathname !== '/callback') {
37
- answer(response, 404, page('Nada aqui', 'Este endereço só recebe a volta do login do Nexo.'));
47
+ answerNotFound(response);
38
48
  return;
39
49
  }
40
50
  const outcome = outcomeOf(url, expectation);
41
51
  clearTimeout(timer);
42
52
  if (outcome instanceof CliError) {
43
- answer(response, 400, page('Não deu certo', `${outcome.message} Volte ao terminal.`));
53
+ answerFailure(response, outcome);
44
54
  reject(outcome);
45
55
  return;
46
56
  }
47
- answer(response, 200, page('Pronto', 'A CLI do Nexo recebeu o acesso. Pode fechar esta aba e voltar ao terminal.'));
57
+ answerSuccess(response);
48
58
  resolve(outcome);
49
59
  });
50
60
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winning-sales/nexo",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "CLI do Nexo: a API, o Connect, os dashboards, os fluxos, os documentos e as análises no terminal, com a documentação e as skills do produto para a sua IA",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/reference.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.0",
2
+ "version": "0.7.1",
3
3
  "program": {
4
4
  "name": "nexo",
5
5
  "path": "nexo",