@sendhoney/cli 0.1.2 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +118 -32
  2. package/bin/sendhoney +44 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,20 +1,43 @@
1
- # SendHoney CLI
1
+ # @sendhoney/cli
2
2
 
3
- Authenticated API and operations CLI for SendHoney tech teams. It follows the
4
- small launcher pattern used by the GameDay and Decoded CLIs, while keeping API
5
- behavior server-side.
3
+ SendHoney platform CLI for authenticated API, CRUD, release, and ThunderCompute operations. Follows the small launcher pattern used by the GameDay and Decoded CLIs, while keeping API behavior server-side.
6
4
 
7
- Run `sendhoney` with no arguments for the interactive resource menu. It groups
8
- the generated endpoint contract by domain and resource, hides service-only
9
- routes by default, prompts for route parameters and JSON, and confirms deletes.
10
- Use `sendhoney menu --operator` for service routes.
5
+ ---
6
+
7
+ ## Install
11
8
 
12
9
  ```bash
10
+ # npm (latest)
11
+ npm install -g @sendhoney/cli
12
+
13
+ # npm (pinned)
14
+ npm install -g @sendhoney/cli@0.1.3
15
+
16
+ # Homebrew
17
+ brew tap sendhoney/tap && brew install sendhoney
18
+
19
+ # curl installer
20
+ curl -fsSL https://sendhoney.app/cli/install.sh | bash
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Quick start
26
+
27
+ ```bash
28
+ # 1. Generate the endpoint contract catalog
13
29
  pnpm --filter @sendhoney/cli generate-catalog
14
- # Opens Keycloak in the browser and completes a PKCE login through localhost.
15
- node apps/sendhoney-cli/bin/sendhoney login
16
- # CI/service account alternative:
30
+
31
+ # 2. Log in (opens Keycloak PKCE in the browser via localhost)
32
+ sendhoney login
33
+
34
+ # 3. CI / service account alternative (token never printed)
17
35
  sendhoney login --token "$SENDHONEY_TOKEN"
36
+
37
+ # 4. Browse and call API resources interactively
38
+ sendhoney menu
39
+
40
+ # 5. Non-interactive examples
18
41
  sendhoney resources list
19
42
  sendhoney resources current
20
43
  sendhoney endpoints list
@@ -35,30 +58,93 @@ sendhoney credentials list --tenant-id TENANT_ID
35
58
  sendhoney credentials add --type postiz --json @postiz-credential.json
36
59
  sendhoney credentials update --id CREDENTIAL_ID --json @rotated-credential.json
37
60
  sendhoney credentials validate --secret-refs @secret-refs.json
61
+
62
+ # Log in and resolve the current workspace organization automatically
63
+ sendhoney login
64
+ sendhoney resources current
65
+
66
+ # Generate the decoded.africa widget snippet using the saved organization
67
+ sendhoney widget install --widget-type both
68
+
69
+ # An explicit organization still overrides the saved workspace
70
+ sendhoney widget install --org-id ORG_ID --widget-type both
71
+
72
+ # Insert it idempotently before </body> in a local website file
73
+ sendhoney widget install --org-id ORG_ID --widget-type both --file ./dist/index.html
38
74
  ```
39
75
 
40
- Installation:
76
+ ---
77
+
78
+ ## Commands
79
+
80
+ | Command | Description |
81
+ |---------|-------------|
82
+ | `login [--token TOKEN] \| [--username USER --password PASS]` | Keycloak PKCE browser login or direct token/password auth |
83
+ | `logout` | Clear stored credentials |
84
+ | `whoami` | Return the authenticated user profile |
85
+ | `menu [--operator]` | Interactive resource menu grouped by domain |
86
+ | `resources list \| current` | List organization modules / current org |
87
+ | `endpoints list` | List published API endpoints |
88
+ | `billing balance [--org-id ID]` | Organization billing balance |
89
+ | `billing ledger [--org-id ID]` | Organization billing ledger |
90
+ | `billing rates` | Billing rate card |
91
+ | `api catalog [--search TEXT] [--method GET]` | Search/filter endpoint catalog |
92
+ | `api get\|post\|put\|patch\|delete PATH [--json JSON]` | Direct API request |
93
+ | `crud PATH list\|create\|update\|delete [--id ID] [--json JSON] [--yes]` | Generic CRUD against any API path |
94
+ | `credentials list [--tenant-id ID]` | List tenant-scoped channel credentials (metadata only) |
95
+ | `credentials add [--type TYPE] [--json JSON\|@FILE]` | Add a new credential |
96
+ | `credentials update --id ID [--json JSON\|@FILE]` | Rotate/update an existing credential |
97
+ | `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 |
99
+ | `thundercompute catalog\|health\|models\|status\|pull\|ensure\|chat` | ThunderCompute / RunPod AI model operations |
100
+ | `release check [--platform android\|ios\|all]` | Check mobile release readiness |
101
+
102
+ ---
103
+
104
+ ## Authentication
105
+
106
+ `sendhoney login` uses Keycloak Authorization Code + PKCE and refreshes expired access tokens automatically. Use `SENDHONEY_TOKEN` for CI / service accounts.
107
+
108
+ Credentials are stored in `$XDG_CONFIG_HOME/sendhoney/config.json` (or `~/.config/sendhoney/config.json`) with mode `0600`; tokens are never printed by the CLI.
109
+
110
+ ---
111
+
112
+ ## Credentials
113
+
114
+ Credential operations are tenant-scoped through the SendHoney API. `list` returns metadata only; secret references and payload fields are redacted from CLI output. `add` and `update` send `secretPayload` to the server, where it is stored through the configured secret manager. Use `@file` for payloads so credentials do not enter shell history. `update` rotates the secret reference on the existing credential record without retrieving the secret value.
115
+
116
+ ---
117
+
118
+ ## Expert interface
119
+
120
+ The expert interface is the Go program in `apps/sendhoney-tui`. It shares this config file and speaks to the module-agent routes. See `docs/SENDHONEY_TUI.md`. npm, Homebrew, and the curl installer do not install that binary.
121
+
122
+ ---
123
+
124
+ ## Publishing
125
+
126
+ Maintained in the `sendhoney-api-monorepo-oatpp-v2` repo under `apps/sendhoney-cli`.
127
+ Publish to npmjs using the `staging` dist-tag so `latest` remains unchanged:
128
+
129
+ 1. Stage the package (uploaded to npm staging, not yet public):
130
+ ```bash
131
+ pnpm --filter @sendhoney/cli generate-catalog
132
+ cd apps/sendhoney-cli
133
+ ./scripts/publish-sendhoney-cli.sh
134
+ ```
135
+ 2. Verify the staged version:
136
+ ```bash
137
+ npm view @sendhoney/cli dist-tags versions
138
+ ```
139
+ 3. Promote the verified version:
140
+ ```bash
141
+ npm dist-tag add @sendhoney/cli@VERSION latest
142
+ ```
143
+
144
+ Alternatively, run the publish script which stages and prints the promotion link:
41
145
 
42
146
  ```bash
43
- npm install -g @sendhoney/cli
44
- brew tap sendhoney/tap && brew install sendhoney
45
- curl -fsSL https://sendhoney.app/cli/install.sh | bash
147
+ ./scripts/publish-sendhoney-cli.sh
46
148
  ```
47
149
 
48
- `sendhoney login` uses Keycloak Authorization Code + PKCE and refreshes expired
49
- access tokens automatically. Use `SENDHONEY_TOKEN` for CI/service accounts.
50
- Credentials are stored in
51
- `$XDG_CONFIG_HOME/sendhoney/config.json` (or `~/.config/sendhoney/config.json`)
52
- with mode `0600`; tokens are never printed by the CLI.
53
-
54
- Credential operations are tenant-scoped through the SendHoney API. `list`
55
- returns metadata only; secret references and payload fields are redacted from
56
- CLI output. `add` and `update` send `secretPayload` to the server, where it is
57
- stored through the configured secret manager. Use `@file` for payloads so
58
- credentials do not enter shell history. `update` rotates the secret reference
59
- on the existing credential record without retrieving the secret value.
60
-
61
- The expert interface is the Go program in `apps/sendhoney-tui`. It shares
62
- this config file and speaks to the module-agent routes. See
63
- `docs/SENDHONEY_TUI.md`. npm, Homebrew, and the curl installer do not
64
- install that binary.
150
+ npm disallows republishing an already-published version, so always bump `version` in `package.json` before staging.
package/bin/sendhoney CHANGED
@@ -56,7 +56,9 @@ async function browserLogin(args, config) {
56
56
  res.end(error ? 'SendHoney login failed. You may close this window.' : 'SendHoney login complete. You may close this window.')
57
57
  clearTimeout(timeout); server.close(); error ? reject(new Error(error)) : resolve({ code, callback })
58
58
  })
59
- openBrowser(authorization.toString())
59
+ const loginUrl = authorization.toString()
60
+ stdout.write(`Keycloak login URL:\n${loginUrl}\n\n`)
61
+ openBrowser(loginUrl)
60
62
  stdout.write(`Opening Keycloak login in your browser (${callback})\n`)
61
63
  })
62
64
  const tokenResponse = await fetch(`${authUrl}/realms/${encodeURIComponent(realm)}/protocol/openid-connect/token`, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ grant_type: 'authorization_code', client_id: clientId, code: result.code, redirect_uri: result.callback, code_verifier: verifier }).toString() })
@@ -87,6 +89,10 @@ function catalog() {
87
89
 
88
90
  function json(value) { process.stdout.write(`${JSON.stringify(value, null, 2)}\n`) }
89
91
  function die(message, code = 1) { process.stderr.write(`sendhoney: ${message}\n`); process.exit(code) }
92
+ function organizationIdFrom(value) {
93
+ if (!value || typeof value !== 'object') return ''
94
+ return String(value.orgId || value.organizationId || value.tenantId || value.organization?.id || value.organization?.orgId || value.workspace?.organizationId || value.organizations?.[0]?.id || '').trim()
95
+ }
90
96
  function redactCredential(value) {
91
97
  if (Array.isArray(value)) return value.map(redactCredential)
92
98
  if (!value || typeof value !== 'object') return value
@@ -116,6 +122,31 @@ function readJson(value) {
116
122
  try { return JSON.parse(source) } catch { die(`invalid JSON: ${value.startsWith('@') ? value : 'inline value'}`) }
117
123
  }
118
124
 
125
+ function widgetInstall(args) {
126
+ const orgId = String(args['org-id'] || loadConfig().orgId || '').trim()
127
+ if (!orgId) die('widget install requires --org-id')
128
+ const scriptUrl = String(args['script-url'] || 'https://sendhoney.app/widget/v1.js').trim()
129
+ const widgetType = String(args['widget-type'] || 'both').trim()
130
+ if (!['chat', 'video', 'both'].includes(widgetType)) die('widget install --widget-type must be chat, video, or both')
131
+
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 target = args.file ? path.resolve(String(args.file)) : ''
134
+ if (!target) {
135
+ json({ ok: true, orgId, widgetType, scriptUrl, snippet, next: 'Pass --file path/to/index.html to insert it before </body>.' })
136
+ return
137
+ }
138
+ if (!fs.existsSync(target)) die(`widget install file does not exist: ${target}`)
139
+ const source = fs.readFileSync(target, 'utf8')
140
+ if (source.includes('data-sendhoney-widget')) {
141
+ json({ ok: true, changed: false, file: target, message: 'SendHoney widget is already installed in this file.' })
142
+ return
143
+ }
144
+ const bodyClose = source.search(/<\/body\s*>/i)
145
+ if (bodyClose < 0) die(`widget install could not find </body> in ${target}`)
146
+ fs.writeFileSync(target, `${source.slice(0, bodyClose)}${snippet}\n${source.slice(bodyClose)}`)
147
+ json({ ok: true, changed: true, file: target, orgId, widgetType, scriptUrl })
148
+ }
149
+
119
150
  function visibleCatalog(operator = false) {
120
151
  return catalog().filter(entry => operator || entry.auth !== 'service')
121
152
  }
@@ -229,6 +260,10 @@ async function request(method, endpoint, options = {}) {
229
260
  let body
230
261
  try { body = text ? JSON.parse(text) : null } catch { body = text }
231
262
  if (!response.ok) { json({ status: response.status, url, error: body }); process.exitCode = 1; return }
263
+ if (endpoint === '/api/v1/org/me') {
264
+ const orgId = organizationIdFrom(body)
265
+ if (orgId) saveConfig({ ...loadConfig(), orgId })
266
+ }
232
267
  json(options.redactCredentials ? redactCredential(body) : body)
233
268
  }
234
269
 
@@ -295,7 +330,12 @@ async function login(args) {
295
330
  })
296
331
  const body = await response.json().catch(() => ({}))
297
332
  if (!response.ok || !body.access_token) die(`login failed (${response.status}): ${body.error_description || body.error || 'no access token'}`)
298
- saveConfig({ ...config, apiUrl: args['api-url'] || config.apiUrl || 'https://api.sendhoney.app', authUrl, realm, clientId, accessToken: body.access_token, refreshToken: body.refresh_token, expiresAt: Date.now() + (body.expires_in || 300) * 1000 })
333
+ const nextConfig = { ...config, apiUrl: args['api-url'] || config.apiUrl || 'https://api.sendhoney.app', authUrl, realm, clientId, accessToken: body.access_token, refreshToken: body.refresh_token, expiresAt: Date.now() + (body.expires_in || 300) * 1000 }
334
+ saveConfig(nextConfig)
335
+ const orgResponse = await fetch(`${nextConfig.apiUrl.replace(/\/$/, '')}/api/v1/org/me`, { headers: { Accept: 'application/json', Authorization: `Bearer ${body.access_token}` } }).catch(() => null)
336
+ const orgBody = orgResponse ? await orgResponse.json().catch(() => ({})) : {}
337
+ const orgId = organizationIdFrom(orgBody)
338
+ if (orgId) saveConfig({ ...nextConfig, orgId })
299
339
  json({ ok: true, username, apiUrl: args['api-url'] || config.apiUrl || 'https://api.sendhoney.app' })
300
340
  }
301
341
 
@@ -307,7 +347,7 @@ async function main() {
307
347
  }
308
348
  if (!command && stdin.isTTY && stdout.isTTY) return interactiveMenu(args)
309
349
  if (!command || command === 'help' || args.help) {
310
- process.stdout.write('SendHoney CLI\n\nCommands: login, logout, whoami, menu, resources, endpoints, billing, api, crud, credentials, 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\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')
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')
311
351
  return
312
352
  }
313
353
  if (command === 'login') {
@@ -318,6 +358,7 @@ async function main() {
318
358
  if (command === 'logout') { const c = loadConfig(); delete c.accessToken; delete c.refreshToken; delete c.expiresAt; saveConfig(c); return json({ ok: true }) }
319
359
  if (command === 'menu') return interactiveMenu(args)
320
360
  if (command === 'credentials') return credentials(args, subcommand)
361
+ if (command === 'widget' && subcommand === 'install') return widgetInstall(args)
321
362
  if (command === 'resources') return curated(args, subcommand)
322
363
  if (command === 'endpoints' && subcommand === 'list') return curated(args, 'endpoints')
323
364
  if (command === 'billing') return curated(args, subcommand)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sendhoney/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "SendHoney platform CLI for authenticated API, CRUD, release, and ThunderCompute operations.",
5
5
  "private": false,
6
6
  "bin": { "sendhoney": "bin/sendhoney" },