@future-unknown/known 0.0.0-stage → 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/README.md +558 -2
- package/bin/known +156 -0
- package/lib/auth.js +206 -0
- package/lib/cmds/_audit.js +153 -0
- package/lib/cmds/_code.js +673 -0
- package/lib/cmds/_config.js +91 -0
- package/lib/cmds/_endpoints.js +58 -0
- package/lib/cmds/_feedback.js +44 -0
- package/lib/cmds/_help.js +70 -0
- package/lib/cmds/_login.js +50 -0
- package/lib/cmds/_logout.js +40 -0
- package/lib/cmds/_members.js +403 -0
- package/lib/cmds/_ping.js +49 -0
- package/lib/cmds/_post.js +103 -0
- package/lib/cmds/_rpc.js +86 -0
- package/lib/cmds/_sessions.js +68 -0
- package/lib/cmds/_sites.js +300 -0
- package/lib/cmds/_teams.js +270 -0
- package/lib/cmds/_whoami.js +76 -0
- package/lib/cmds/_wiki.js +1503 -0
- package/lib/cmds/org.js +85 -0
- package/lib/config.js +297 -0
- package/lib/helpers.js +371 -0
- package/lib/output.js +338 -0
- package/lib/project.js +100 -0
- package/package.json +50 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const config = require("../config")
|
|
2
|
+
const project = require("../project")
|
|
3
|
+
const output = require("../output")
|
|
4
|
+
const { getClient, sessionFor, accountLabel, run, unwrap } = require("../helpers")
|
|
5
|
+
|
|
6
|
+
// `known whoami` who you are here: the project's org when a KNOWN_ORG file
|
|
7
|
+
// or $KNOWN_ORG binds one, else every session on this machine
|
|
8
|
+
// `known acme whoami` just that one
|
|
9
|
+
//
|
|
10
|
+
// Unbound, this reports on every session rather than erroring: with one session
|
|
11
|
+
// per org — and possibly a different account per org — "who am I" is genuinely
|
|
12
|
+
// a list.
|
|
13
|
+
module.exports = function (argv, ref) {
|
|
14
|
+
return run(async () => {
|
|
15
|
+
const single = !!(ref || project.binding())
|
|
16
|
+
const targets = single ? [sessionFor(argv, ref)] : config.allSessions()
|
|
17
|
+
|
|
18
|
+
if (!targets.length) {
|
|
19
|
+
const e = new Error("not signed in — run `known login`")
|
|
20
|
+
e.friendly = true
|
|
21
|
+
throw e
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const results = []
|
|
25
|
+
for (const session of targets) {
|
|
26
|
+
try {
|
|
27
|
+
const client = getClient(argv, { session })
|
|
28
|
+
const who = unwrap(await client.auth.whoami())
|
|
29
|
+
results.push({ session, who: { ...who, handle: await handleOf(client) } })
|
|
30
|
+
} catch (e) {
|
|
31
|
+
results.push({ session, error: e.message })
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (output.isJson()) {
|
|
36
|
+
const shaped = results.map((r) =>
|
|
37
|
+
r.error
|
|
38
|
+
? { session: r.session.label, error: r.error }
|
|
39
|
+
: { session: r.session.label, from: r.session.source || null, endpoint: r.session.endpoint, ...r.who }
|
|
40
|
+
)
|
|
41
|
+
return output.data(single ? shaped[0] : shaped)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const result of results) {
|
|
45
|
+
if (result.error) {
|
|
46
|
+
output.record([["session", result.session.label], ["error", result.error]])
|
|
47
|
+
continue
|
|
48
|
+
}
|
|
49
|
+
const who = result.who
|
|
50
|
+
const org = who.org || {}
|
|
51
|
+
output.record([
|
|
52
|
+
["session", result.session.label],
|
|
53
|
+
...(result.session.source ? [["from", result.session.source]] : []),
|
|
54
|
+
["endpoint", result.session.endpoint],
|
|
55
|
+
["org", (org.name || result.session.key) + (org.slug ? " (" + org.slug + ")" : "")],
|
|
56
|
+
["account", accountLabel(who.user)],
|
|
57
|
+
["handle", who.handle ? "@" + who.handle : "none yet — choose one in Known"],
|
|
58
|
+
["role", who.role],
|
|
59
|
+
["permissions", Array.isArray(who.permissions) ? who.permissions.length + " actions" : null]
|
|
60
|
+
])
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A non-zero exit when nothing could be verified keeps scripts honest.
|
|
64
|
+
if (results.every((r) => r.error)) throw new Error(results[0].error)
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The person's handle, or null when they have
|
|
69
|
+
// none or the server is older than handles.
|
|
70
|
+
async function handleOf(client) {
|
|
71
|
+
try {
|
|
72
|
+
return unwrap(await client.handle.get()).handle || null
|
|
73
|
+
} catch {
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
}
|