@sendhoney/cli 0.1.4 → 0.1.6

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/README.md CHANGED
@@ -66,10 +66,13 @@ sendhoney resources current
66
66
  # Generate the decoded.africa widget snippet using the saved organization
67
67
  sendhoney widget install --widget-type both
68
68
 
69
+ # Install into a Next.js root layout (recommended for decoded.africa)
70
+ sendhoney widget install --next-app ./apps/web --widget-type both
71
+
69
72
  # An explicit organization still overrides the saved workspace
70
73
  sendhoney widget install --org-id ORG_ID --widget-type both
71
74
 
72
- # Insert it idempotently before </body> in a local website file
75
+ # Insert it idempotently before </body> in a static website file
73
76
  sendhoney widget install --org-id ORG_ID --widget-type both --file ./dist/index.html
74
77
  ```
75
78
 
@@ -95,7 +98,7 @@ sendhoney widget install --org-id ORG_ID --widget-type both --file ./dist/index.
95
98
  | `credentials add [--type TYPE] [--json JSON\|@FILE]` | Add a new credential |
96
99
  | `credentials update --id ID [--json JSON\|@FILE]` | Rotate/update an existing credential |
97
100
  | `credentials validate --secret-refs @FILE \| --secret-ref REF` | Validate secret references |
98
- | `widget install [--org-id ID] [--file FILE] [--widget-type chat\|video\|both]` | Generate the tenant-scoped widget snippet or insert it into a local HTML file; uses the organization resolved at login/current-workspace time when omitted |
101
+ | `widget install [--org-id ID] [--next-app APP] [--file FILE] [--widget-type chat\|video\|both]` | Install into a Next.js root layout or insert into static HTML; uses the organization resolved at login/current-workspace time when omitted |
99
102
  | `thundercompute catalog\|health\|models\|status\|pull\|ensure\|chat` | ThunderCompute / RunPod AI model operations |
100
103
  | `release check [--platform android\|ios\|all]` | Check mobile release readiness |
101
104
 
package/bin/sendhoney CHANGED
@@ -36,6 +36,16 @@ function openBrowser(url) {
36
36
  function base64Url(value) { return value.toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_') }
37
37
  function pkceChallenge(verifier) { return base64Url(createHash('sha256').update(verifier).digest()) }
38
38
 
39
+ function loginCallbackPage(success) {
40
+ const title = success ? 'You’re signed in' : 'Sign-in could not be completed'
41
+ const message = success
42
+ ? 'SendHoney CLI is connected. You can close this window and return to your terminal.'
43
+ : 'The SendHoney CLI could not complete sign-in. Close this window and try again from your terminal.'
44
+ const icon = success ? '✓' : '!'
45
+ const accent = success ? '#0f766e' : '#b42318'
46
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${title} · SendHoney</title><style>*,*:before,*:after{box-sizing:border-box}body{margin:0;min-height:100vh;display:grid;place-items:center;padding:24px;background:#f7fbfb;color:#102a2a;font-family:Inter,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}.card{width:min(100%,480px);padding:40px;border:1px solid #d9e9e7;border-radius:24px;background:#fff;box-shadow:0 20px 60px #0f766e18;text-align:center}.brand{display:inline-flex;align-items:center;gap:10px;margin-bottom:32px;color:#0f766e;font-size:18px;font-weight:800;letter-spacing:-.02em}.mark{display:grid;place-items:center;width:32px;height:32px;border-radius:10px;background:#0f766e;color:#fff;font-size:20px}.status{display:grid;place-items:center;width:64px;height:64px;margin:0 auto 22px;border-radius:20px;background:${accent}18;color:${accent};font-size:32px;font-weight:800}.title{margin:0;font-size:30px;letter-spacing:-.04em}.message{margin:14px auto 0;max-width:30rem;color:#587070;font-size:16px;line-height:1.6}.hint{margin-top:28px;color:#789090;font-size:13px}</style></head><body><main class="card"><div class="brand"><span class="mark">S</span><span>SendHoney</span></div><div class="status">${icon}</div><h1 class="title">${title}</h1><p class="message">${message}</p><p class="hint">You may safely close this tab.</p></main></body></html>`
47
+ }
48
+
39
49
  async function browserLogin(args, config) {
40
50
  const authUrl = (args['auth-url'] || process.env.SENDHONEY_AUTH_URL || config.authUrl || 'https://auth.sendhoney.app').replace(/\/$/, '')
41
51
  const realm = args.realm || process.env.SENDHONEY_KEYCLOAK_REALM || config.realm || 'users'
@@ -43,17 +53,18 @@ async function browserLogin(args, config) {
43
53
  const state = base64Url(randomBytes(24)); const verifier = base64Url(randomBytes(48))
44
54
  const server = http.createServer()
45
55
  await new Promise((resolve) => server.listen(Number(args.port || 0), '127.0.0.1', resolve))
46
- const callback = `http://127.0.0.1:${server.address().port}/callback`
56
+ const callback = `http://127.0.0.1:${server.address().port}`
47
57
  const authorization = new URL(`${authUrl}/realms/${encodeURIComponent(realm)}/protocol/openid-connect/auth`)
48
58
  authorization.search = new URLSearchParams({ client_id: clientId, redirect_uri: callback, response_type: 'code', scope: 'openid profile email offline_access', state, code_challenge: pkceChallenge(verifier), code_challenge_method: 'S256' }).toString()
49
59
  const result = await new Promise((resolve, reject) => {
50
60
  const timeout = setTimeout(() => { server.close(); reject(new Error('login timed out')) }, 300000)
51
61
  server.on('request', (req, res) => {
52
62
  const url = new URL(req.url || '/', callback)
53
- if (url.pathname !== '/callback') { res.end('SendHoney CLI login'); return }
63
+ if (url.pathname !== '/') { res.end('SendHoney CLI login'); return }
54
64
  if (url.searchParams.get('state') !== state) { res.statusCode = 400; res.end('Invalid login state'); clearTimeout(timeout); server.close(); reject(new Error('invalid login state')); return }
55
65
  const code = url.searchParams.get('code'); const error = url.searchParams.get('error')
56
- res.end(error ? 'SendHoney login failed. You may close this window.' : 'SendHoney login complete. You may close this window.')
66
+ res.setHeader('Content-Type', 'text/html; charset=utf-8')
67
+ res.end(loginCallbackPage(!error))
57
68
  clearTimeout(timeout); server.close(); error ? reject(new Error(error)) : resolve({ code, callback })
58
69
  })
59
70
  const loginUrl = authorization.toString()
@@ -130,9 +141,32 @@ function widgetInstall(args) {
130
141
  if (!['chat', 'video', 'both'].includes(widgetType)) die('widget install --widget-type must be chat, video, or both')
131
142
 
132
143
  const snippet = `<!-- SendHoney chat/call widget -->\n<script async src="${scriptUrl}" data-sendhoney-widget data-org-id="${orgId}" data-widget-type="${widgetType}"></script>\n<!-- End SendHoney widget -->`
144
+ const nextApp = args['next-app'] ? path.resolve(String(args['next-app'])) : ''
145
+ if (nextApp) {
146
+ const layoutCandidates = [path.join(nextApp, 'app', 'layout.tsx'), path.join(nextApp, 'src', 'app', 'layout.tsx')]
147
+ const layout = layoutCandidates.find(file => fs.existsSync(file))
148
+ if (!layout) die(`widget install could not find app/layout.tsx or src/app/layout.tsx under ${nextApp}`)
149
+ const appDir = path.dirname(layout)
150
+ const component = path.join(appDir, 'sendhoney-widget.tsx')
151
+ const importLine = `import SendHoneyWidget from './sendhoney-widget'`
152
+ const componentSource = `import Script from 'next/script'\n\nexport default function SendHoneyWidget() {\n return (\n <Script\n id="sendhoney-widget"\n src="${scriptUrl}"\n strategy="afterInteractive"\n data-sendhoney-widget\n data-org-id="${orgId}"\n data-widget-type="${widgetType}"\n />\n )\n}\n`
153
+ const source = fs.readFileSync(layout, 'utf8')
154
+ if (source.includes('sendhoney-widget') && fs.existsSync(component)) {
155
+ json({ ok: true, changed: false, framework: 'nextjs', layout, component, message: 'SendHoney widget is already installed in this Next.js app.' })
156
+ return
157
+ }
158
+ if (!source.includes(importLine)) fs.writeFileSync(layout, `${importLine}\n${source}`)
159
+ const updated = fs.readFileSync(layout, 'utf8')
160
+ const bodyClose = updated.search(/<\/body\s*>/i)
161
+ if (bodyClose < 0) die(`widget install could not find </body> in ${layout}`)
162
+ fs.writeFileSync(layout, `${updated.slice(0, bodyClose)} <SendHoneyWidget />\n${updated.slice(bodyClose)}`)
163
+ fs.writeFileSync(component, componentSource)
164
+ json({ ok: true, changed: true, framework: 'nextjs', layout, component, orgId, widgetType, scriptUrl })
165
+ return
166
+ }
133
167
  const target = args.file ? path.resolve(String(args.file)) : ''
134
168
  if (!target) {
135
- json({ ok: true, orgId, widgetType, scriptUrl, snippet, next: 'Pass --file path/to/index.html to insert it before </body>.' })
169
+ json({ ok: true, orgId, widgetType, scriptUrl, snippet, next: 'Pass --next-app ./apps/web for Next.js or --file path/to/index.html for static HTML.' })
136
170
  return
137
171
  }
138
172
  if (!fs.existsSync(target)) die(`widget install file does not exist: ${target}`)
@@ -347,7 +381,7 @@ async function main() {
347
381
  }
348
382
  if (!command && stdin.isTTY && stdout.isTTY) return interactiveMenu(args)
349
383
  if (!command || command === 'help' || args.help) {
350
- process.stdout.write('SendHoney CLI\n\nCommands: login, logout, whoami, menu, resources, endpoints, billing, api, crud, credentials, widget, thundercompute, release\n\n`login` opens a Keycloak PKCE browser login when no token/password is supplied.\nresources list\nresources current\nendpoints list\nbilling balance [--org-id ID]\nbilling ledger [--org-id ID]\nbilling rates\napi request METHOD PATH [--json JSON] | api get|post|put|patch|delete PATH\napi catalog [--search TEXT] [--method GET]\ncrud PATH list|create|update|delete [--id ID] [--json JSON] [--yes]\ncredentials list [--tenant-id ID]\ncredentials add [--type TYPE] [--json JSON|@FILE]\ncredentials update --id ID [--json JSON|@FILE]\ncredentials validate --secret-refs @FILE | --secret-ref REF\nwidget install --org-id ID [--file path/to/index.html] [--widget-type chat|video|both]\nSecret payloads are sent to the API and are never printed by these commands.\nthundercompute catalog|health|models|status|pull|ensure|chat\nrelease check [--platform android|ios|all]\n')
384
+ process.stdout.write('SendHoney CLI\n\nCommands: login, logout, whoami, menu, resources, endpoints, billing, api, crud, credentials, widget, thundercompute, release\n\n`login` opens a Keycloak PKCE browser login when no token/password is supplied.\nresources list\nresources current\nendpoints list\nbilling balance [--org-id ID]\nbilling ledger [--org-id ID]\nbilling rates\napi request METHOD PATH [--json JSON] | api get|post|put|patch|delete PATH\napi catalog [--search TEXT] [--method GET]\ncrud PATH list|create|update|delete [--id ID] [--json JSON] [--yes]\ncredentials list [--tenant-id ID]\ncredentials add [--type TYPE] [--json JSON|@FILE]\ncredentials update --id ID [--json JSON|@FILE]\ncredentials validate --secret-refs @FILE | --secret-ref REF\nwidget install [--org-id ID] [--next-app path/to/app] [--file path/to/index.html] [--widget-type chat|video|both]\nSecret payloads are sent to the API and are never printed by these commands.\nthundercompute catalog|health|models|status|pull|ensure|chat\nrelease check [--platform android|ios|all]\n')
351
385
  return
352
386
  }
353
387
  if (command === 'login') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendhoney/cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "SendHoney platform CLI for authenticated API, CRUD, release, and ThunderCompute operations.",
5
5
  "private": false,
6
6
  "bin": { "sendhoney": "bin/sendhoney" },