@sendhoney/cli 0.1.4 → 0.1.5

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
@@ -43,14 +43,14 @@ async function browserLogin(args, config) {
43
43
  const state = base64Url(randomBytes(24)); const verifier = base64Url(randomBytes(48))
44
44
  const server = http.createServer()
45
45
  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`
46
+ const callback = `http://127.0.0.1:${server.address().port}`
47
47
  const authorization = new URL(`${authUrl}/realms/${encodeURIComponent(realm)}/protocol/openid-connect/auth`)
48
48
  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
49
  const result = await new Promise((resolve, reject) => {
50
50
  const timeout = setTimeout(() => { server.close(); reject(new Error('login timed out')) }, 300000)
51
51
  server.on('request', (req, res) => {
52
52
  const url = new URL(req.url || '/', callback)
53
- if (url.pathname !== '/callback') { res.end('SendHoney CLI login'); return }
53
+ if (url.pathname !== '/') { res.end('SendHoney CLI login'); return }
54
54
  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
55
  const code = url.searchParams.get('code'); const error = url.searchParams.get('error')
56
56
  res.end(error ? 'SendHoney login failed. You may close this window.' : 'SendHoney login complete. You may close this window.')
@@ -130,9 +130,32 @@ function widgetInstall(args) {
130
130
  if (!['chat', 'video', 'both'].includes(widgetType)) die('widget install --widget-type must be chat, video, or both')
131
131
 
132
132
  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 -->`
133
+ const nextApp = args['next-app'] ? path.resolve(String(args['next-app'])) : ''
134
+ if (nextApp) {
135
+ const layoutCandidates = [path.join(nextApp, 'app', 'layout.tsx'), path.join(nextApp, 'src', 'app', 'layout.tsx')]
136
+ const layout = layoutCandidates.find(file => fs.existsSync(file))
137
+ if (!layout) die(`widget install could not find app/layout.tsx or src/app/layout.tsx under ${nextApp}`)
138
+ const appDir = path.dirname(layout)
139
+ const component = path.join(appDir, 'sendhoney-widget.tsx')
140
+ const importLine = `import SendHoneyWidget from './sendhoney-widget'`
141
+ 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`
142
+ const source = fs.readFileSync(layout, 'utf8')
143
+ if (source.includes('sendhoney-widget') && fs.existsSync(component)) {
144
+ json({ ok: true, changed: false, framework: 'nextjs', layout, component, message: 'SendHoney widget is already installed in this Next.js app.' })
145
+ return
146
+ }
147
+ if (!source.includes(importLine)) fs.writeFileSync(layout, `${importLine}\n${source}`)
148
+ const updated = fs.readFileSync(layout, 'utf8')
149
+ const bodyClose = updated.search(/<\/body\s*>/i)
150
+ if (bodyClose < 0) die(`widget install could not find </body> in ${layout}`)
151
+ fs.writeFileSync(layout, `${updated.slice(0, bodyClose)} <SendHoneyWidget />\n${updated.slice(bodyClose)}`)
152
+ fs.writeFileSync(component, componentSource)
153
+ json({ ok: true, changed: true, framework: 'nextjs', layout, component, orgId, widgetType, scriptUrl })
154
+ return
155
+ }
133
156
  const target = args.file ? path.resolve(String(args.file)) : ''
134
157
  if (!target) {
135
- json({ ok: true, orgId, widgetType, scriptUrl, snippet, next: 'Pass --file path/to/index.html to insert it before </body>.' })
158
+ 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
159
  return
137
160
  }
138
161
  if (!fs.existsSync(target)) die(`widget install file does not exist: ${target}`)
@@ -347,7 +370,7 @@ async function main() {
347
370
  }
348
371
  if (!command && stdin.isTTY && stdout.isTTY) return interactiveMenu(args)
349
372
  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')
373
+ 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
374
  return
352
375
  }
353
376
  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.5",
4
4
  "description": "SendHoney platform CLI for authenticated API, CRUD, release, and ThunderCompute operations.",
5
5
  "private": false,
6
6
  "bin": { "sendhoney": "bin/sendhoney" },