@sendhoney/cli 0.1.3 → 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.
- package/README.md +24 -5
- package/bin/sendhoney +44 -3
- package/package.json +10 -21
package/README.md
CHANGED
|
@@ -58,6 +58,19 @@ 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
|
+
# 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
|
|
61
74
|
```
|
|
62
75
|
|
|
63
76
|
---
|
|
@@ -82,6 +95,7 @@ sendhoney credentials validate --secret-refs @secret-refs.json
|
|
|
82
95
|
| `credentials add [--type TYPE] [--json JSON\|@FILE]` | Add a new credential |
|
|
83
96
|
| `credentials update --id ID [--json JSON\|@FILE]` | Rotate/update an existing credential |
|
|
84
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 |
|
|
85
99
|
| `thundercompute catalog\|health\|models\|status\|pull\|ensure\|chat` | ThunderCompute / RunPod AI model operations |
|
|
86
100
|
| `release check [--platform android\|ios\|all]` | Check mobile release readiness |
|
|
87
101
|
|
|
@@ -110,17 +124,22 @@ The expert interface is the Go program in `apps/sendhoney-tui`. It shares this c
|
|
|
110
124
|
## Publishing
|
|
111
125
|
|
|
112
126
|
Maintained in the `sendhoney-api-monorepo-oatpp-v2` repo under `apps/sendhoney-cli`.
|
|
113
|
-
Publish to npmjs
|
|
127
|
+
Publish to npmjs using the `staging` dist-tag so `latest` remains unchanged:
|
|
114
128
|
|
|
115
129
|
1. Stage the package (uploaded to npm staging, not yet public):
|
|
116
130
|
```bash
|
|
117
131
|
pnpm --filter @sendhoney/cli generate-catalog
|
|
118
132
|
cd apps/sendhoney-cli
|
|
119
|
-
|
|
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
|
|
120
142
|
```
|
|
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
143
|
|
|
125
144
|
Alternatively, run the publish script which stages and prints the promotion link:
|
|
126
145
|
|
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
|
-
|
|
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
|
-
|
|
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,31 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sendhoney/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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
|
+
}
|