@sendhoney/cli 0.1.3 → 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 +27 -5
- package/bin/sendhoney +69 -5
- package/package.json +10 -21
package/README.md
CHANGED
|
@@ -58,6 +58,22 @@ sendhoney credentials list --tenant-id TENANT_ID
|
|
|
58
58
|
sendhoney credentials add --type postiz --json @postiz-credential.json
|
|
59
59
|
sendhoney credentials update --id CREDENTIAL_ID --json @rotated-credential.json
|
|
60
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
|
+
# Install into a Next.js root layout (recommended for decoded.africa)
|
|
70
|
+
sendhoney widget install --next-app ./apps/web --widget-type both
|
|
71
|
+
|
|
72
|
+
# An explicit organization still overrides the saved workspace
|
|
73
|
+
sendhoney widget install --org-id ORG_ID --widget-type both
|
|
74
|
+
|
|
75
|
+
# Insert it idempotently before </body> in a static website file
|
|
76
|
+
sendhoney widget install --org-id ORG_ID --widget-type both --file ./dist/index.html
|
|
61
77
|
```
|
|
62
78
|
|
|
63
79
|
---
|
|
@@ -82,6 +98,7 @@ sendhoney credentials validate --secret-refs @secret-refs.json
|
|
|
82
98
|
| `credentials add [--type TYPE] [--json JSON\|@FILE]` | Add a new credential |
|
|
83
99
|
| `credentials update --id ID [--json JSON\|@FILE]` | Rotate/update an existing credential |
|
|
84
100
|
| `credentials validate --secret-refs @FILE \| --secret-ref REF` | Validate secret references |
|
|
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 |
|
|
85
102
|
| `thundercompute catalog\|health\|models\|status\|pull\|ensure\|chat` | ThunderCompute / RunPod AI model operations |
|
|
86
103
|
| `release check [--platform android\|ios\|all]` | Check mobile release readiness |
|
|
87
104
|
|
|
@@ -110,17 +127,22 @@ The expert interface is the Go program in `apps/sendhoney-tui`. It shares this c
|
|
|
110
127
|
## Publishing
|
|
111
128
|
|
|
112
129
|
Maintained in the `sendhoney-api-monorepo-oatpp-v2` repo under `apps/sendhoney-cli`.
|
|
113
|
-
Publish to npmjs
|
|
130
|
+
Publish to npmjs using the `staging` dist-tag so `latest` remains unchanged:
|
|
114
131
|
|
|
115
132
|
1. Stage the package (uploaded to npm staging, not yet public):
|
|
116
133
|
```bash
|
|
117
134
|
pnpm --filter @sendhoney/cli generate-catalog
|
|
118
135
|
cd apps/sendhoney-cli
|
|
119
|
-
|
|
136
|
+
./scripts/publish-sendhoney-cli.sh
|
|
137
|
+
```
|
|
138
|
+
2. Verify the staged version:
|
|
139
|
+
```bash
|
|
140
|
+
npm view @sendhoney/cli dist-tags versions
|
|
141
|
+
```
|
|
142
|
+
3. Promote the verified version:
|
|
143
|
+
```bash
|
|
144
|
+
npm dist-tag add @sendhoney/cli@VERSION latest
|
|
120
145
|
```
|
|
121
|
-
2. Log in to https://www.npmjs.com
|
|
122
|
-
3. Go to https://www.npmjs.com/package/@sendhoney/cli
|
|
123
|
-
4. Promote the staged version from **Staging → Public**
|
|
124
146
|
|
|
125
147
|
Alternatively, run the publish script which stages and prints the promotion link:
|
|
126
148
|
|
package/bin/sendhoney
CHANGED
|
@@ -43,20 +43,22 @@ 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}
|
|
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 !== '/
|
|
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.')
|
|
57
57
|
clearTimeout(timeout); server.close(); error ? reject(new Error(error)) : resolve({ code, callback })
|
|
58
58
|
})
|
|
59
|
-
|
|
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,54 @@ 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 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
|
+
}
|
|
156
|
+
const target = args.file ? path.resolve(String(args.file)) : ''
|
|
157
|
+
if (!target) {
|
|
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.' })
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
if (!fs.existsSync(target)) die(`widget install file does not exist: ${target}`)
|
|
162
|
+
const source = fs.readFileSync(target, 'utf8')
|
|
163
|
+
if (source.includes('data-sendhoney-widget')) {
|
|
164
|
+
json({ ok: true, changed: false, file: target, message: 'SendHoney widget is already installed in this file.' })
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
const bodyClose = source.search(/<\/body\s*>/i)
|
|
168
|
+
if (bodyClose < 0) die(`widget install could not find </body> in ${target}`)
|
|
169
|
+
fs.writeFileSync(target, `${source.slice(0, bodyClose)}${snippet}\n${source.slice(bodyClose)}`)
|
|
170
|
+
json({ ok: true, changed: true, file: target, orgId, widgetType, scriptUrl })
|
|
171
|
+
}
|
|
172
|
+
|
|
119
173
|
function visibleCatalog(operator = false) {
|
|
120
174
|
return catalog().filter(entry => operator || entry.auth !== 'service')
|
|
121
175
|
}
|
|
@@ -229,6 +283,10 @@ async function request(method, endpoint, options = {}) {
|
|
|
229
283
|
let body
|
|
230
284
|
try { body = text ? JSON.parse(text) : null } catch { body = text }
|
|
231
285
|
if (!response.ok) { json({ status: response.status, url, error: body }); process.exitCode = 1; return }
|
|
286
|
+
if (endpoint === '/api/v1/org/me') {
|
|
287
|
+
const orgId = organizationIdFrom(body)
|
|
288
|
+
if (orgId) saveConfig({ ...loadConfig(), orgId })
|
|
289
|
+
}
|
|
232
290
|
json(options.redactCredentials ? redactCredential(body) : body)
|
|
233
291
|
}
|
|
234
292
|
|
|
@@ -295,7 +353,12 @@ async function login(args) {
|
|
|
295
353
|
})
|
|
296
354
|
const body = await response.json().catch(() => ({}))
|
|
297
355
|
if (!response.ok || !body.access_token) die(`login failed (${response.status}): ${body.error_description || body.error || 'no access token'}`)
|
|
298
|
-
|
|
356
|
+
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 }
|
|
357
|
+
saveConfig(nextConfig)
|
|
358
|
+
const orgResponse = await fetch(`${nextConfig.apiUrl.replace(/\/$/, '')}/api/v1/org/me`, { headers: { Accept: 'application/json', Authorization: `Bearer ${body.access_token}` } }).catch(() => null)
|
|
359
|
+
const orgBody = orgResponse ? await orgResponse.json().catch(() => ({})) : {}
|
|
360
|
+
const orgId = organizationIdFrom(orgBody)
|
|
361
|
+
if (orgId) saveConfig({ ...nextConfig, orgId })
|
|
299
362
|
json({ ok: true, username, apiUrl: args['api-url'] || config.apiUrl || 'https://api.sendhoney.app' })
|
|
300
363
|
}
|
|
301
364
|
|
|
@@ -307,7 +370,7 @@ async function main() {
|
|
|
307
370
|
}
|
|
308
371
|
if (!command && stdin.isTTY && stdout.isTTY) return interactiveMenu(args)
|
|
309
372
|
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')
|
|
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')
|
|
311
374
|
return
|
|
312
375
|
}
|
|
313
376
|
if (command === 'login') {
|
|
@@ -318,6 +381,7 @@ async function main() {
|
|
|
318
381
|
if (command === 'logout') { const c = loadConfig(); delete c.accessToken; delete c.refreshToken; delete c.expiresAt; saveConfig(c); return json({ ok: true }) }
|
|
319
382
|
if (command === 'menu') return interactiveMenu(args)
|
|
320
383
|
if (command === 'credentials') return credentials(args, subcommand)
|
|
384
|
+
if (command === 'widget' && subcommand === 'install') return widgetInstall(args)
|
|
321
385
|
if (command === 'resources') return curated(args, subcommand)
|
|
322
386
|
if (command === 'endpoints' && subcommand === 'list') return curated(args, 'endpoints')
|
|
323
387
|
if (command === 'billing') return curated(args, subcommand)
|
package/package.json
CHANGED
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendhoney/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "SendHoney platform CLI for authenticated API, CRUD, release, and ThunderCompute operations.",
|
|
5
5
|
"private": false,
|
|
6
|
-
"bin": {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"scripts/",
|
|
12
|
-
"README.md",
|
|
13
|
-
"endpoints.json"
|
|
14
|
-
],
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=22"
|
|
6
|
+
"bin": { "sendhoney": "bin/sendhoney" },
|
|
7
|
+
"files": ["bin/", "scripts/", "README.md", "endpoints.json"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"generate-catalog": "node scripts/generate-catalog.mjs",
|
|
10
|
+
"postinstall": "node scripts/postinstall.js"
|
|
17
11
|
},
|
|
12
|
+
"engines": { "node": ">=22" },
|
|
18
13
|
"license": "UNLICENSED",
|
|
19
|
-
"publishConfig": {
|
|
20
|
-
"access": "public"
|
|
21
|
-
},
|
|
14
|
+
"publishConfig": { "access": "public" },
|
|
22
15
|
"repository": {
|
|
23
16
|
"type": "git",
|
|
24
17
|
"url": "https://gitea.sendhoney.app/sendhoney/sendhoney-api-monorepo-oatpp-v2"
|
|
25
18
|
},
|
|
26
|
-
"homepage": "https://sendhoney.app/docs/cli"
|
|
27
|
-
|
|
28
|
-
"generate-catalog": "node scripts/generate-catalog.mjs",
|
|
29
|
-
"postinstall": "node scripts/postinstall.js"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
19
|
+
"homepage": "https://sendhoney.app/docs/cli"
|
|
20
|
+
}
|