amorphous-cli 0.1.0
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/index.mjs +14 -0
- package/lib/api.mjs +67 -0
- package/lib/commands.mjs +736 -0
- package/lib/config.mjs +92 -0
- package/lib/files.mjs +50 -0
- package/lib/help.mjs +150 -0
- package/lib/login.mjs +153 -0
- package/lib/mailpit.mjs +99 -0
- package/lib/session.mjs +36 -0
- package/lib/tls.mjs +25 -0
- package/mcp.mjs +132 -0
- package/package.json +30 -0
package/index.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { loadDotEnv } from './lib/config.mjs'
|
|
3
|
+
import { runCommand } from './lib/commands.mjs'
|
|
4
|
+
import { ensureLocalHttpsTrust } from './lib/tls.mjs'
|
|
5
|
+
|
|
6
|
+
ensureLocalHttpsTrust()
|
|
7
|
+
loadDotEnv()
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
await runCommand(process.argv.slice(2))
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.error(e instanceof Error ? e.message : e)
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
package/lib/api.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { cliAppFetchOrigin, cliAppHostHeader } from './config.mjs'
|
|
2
|
+
import { accessToken } from './session.mjs'
|
|
3
|
+
|
|
4
|
+
const FRIENDLY = {
|
|
5
|
+
'Abstract cap reached': 'You already have an abstract.',
|
|
6
|
+
'Membership cap reached': 'They already have as many shared abstracts as allowed.',
|
|
7
|
+
'User not found': 'No account with that email yet.',
|
|
8
|
+
'Grant failed': 'Could not invite.',
|
|
9
|
+
'Cannot revoke owner': "You can't remove the owner.",
|
|
10
|
+
'Cannot remove yourself': "You can't remove yourself.",
|
|
11
|
+
'Collection not found': 'Folder not found.',
|
|
12
|
+
Forbidden: "You don't have access.",
|
|
13
|
+
'Not Found': 'Not found.',
|
|
14
|
+
'Owner required': 'Only the owner can do that.',
|
|
15
|
+
'id required': 'Missing id.',
|
|
16
|
+
'userId required': 'Pass an email or id.',
|
|
17
|
+
'Invalid body': 'Invalid request.',
|
|
18
|
+
'Name required': 'Name required.',
|
|
19
|
+
'Create failed': 'Could not create the abstract.',
|
|
20
|
+
'Publish failed': 'Could not publish.',
|
|
21
|
+
'File too large': 'File too large.',
|
|
22
|
+
'Not logged in. Run: amorphous login <email>': 'Not signed in. Run: amorphous login <email>',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function friendlyMessage(raw) {
|
|
26
|
+
const text = String(raw || '').trim()
|
|
27
|
+
if (FRIENDLY[text]) return FRIENDLY[text]
|
|
28
|
+
const stripped = text.replace(/^\d{3}\s+/, '')
|
|
29
|
+
if (FRIENDLY[stripped]) return FRIENDLY[stripped]
|
|
30
|
+
return stripped || text || 'Request failed.'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function apiFetch(path, opts = {}) {
|
|
34
|
+
const url = `${cliAppFetchOrigin()}${path}`
|
|
35
|
+
const headers = { ...cliAppHostHeader(), ...(opts.headers || {}) }
|
|
36
|
+
if (opts.auth !== false) {
|
|
37
|
+
const token = accessToken()
|
|
38
|
+
if (!token) {
|
|
39
|
+
throw new Error('Not signed in. Run: amorphous login <email>')
|
|
40
|
+
}
|
|
41
|
+
headers.Authorization = `Bearer ${token}`
|
|
42
|
+
}
|
|
43
|
+
if (opts.body && !headers['Content-Type']) {
|
|
44
|
+
headers['Content-Type'] = 'application/json'
|
|
45
|
+
}
|
|
46
|
+
const res = await fetch(url, {
|
|
47
|
+
...opts,
|
|
48
|
+
headers,
|
|
49
|
+
})
|
|
50
|
+
const text = await res.text()
|
|
51
|
+
let data = null
|
|
52
|
+
try {
|
|
53
|
+
data = text ? JSON.parse(text) : null
|
|
54
|
+
} catch {
|
|
55
|
+
data = text
|
|
56
|
+
}
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
const msg =
|
|
59
|
+
typeof data === 'object' && data?.message
|
|
60
|
+
? data.message
|
|
61
|
+
: typeof data === 'string'
|
|
62
|
+
? data
|
|
63
|
+
: res.statusText
|
|
64
|
+
throw new Error(friendlyMessage(msg))
|
|
65
|
+
}
|
|
66
|
+
return data
|
|
67
|
+
}
|