@atomicmail/agent-skill 0.1.0 → 0.2.1
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 +91 -0
- package/SKILL.md +53 -193
- package/esm/_dnt.polyfills.d.ts +101 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +127 -0
- package/esm/{skill/scripts/lib/auth.d.ts → lib/agent/auth/agent-auth-http.d.ts} +1 -17
- package/esm/lib/agent/auth/agent-auth-http.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-auth-http.js +76 -0
- package/esm/lib/agent/auth/agent-jwt.d.ts +14 -0
- package/esm/lib/agent/auth/agent-jwt.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-jwt.js +29 -0
- package/esm/lib/agent/auth/agent-pow.d.ts +5 -0
- package/esm/lib/agent/auth/agent-pow.d.ts.map +1 -0
- package/esm/lib/agent/auth/agent-pow.js +49 -0
- package/esm/lib/agent/jmap/agent-help-content.d.ts +4 -0
- package/esm/lib/agent/jmap/agent-help-content.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-help-content.js +244 -0
- package/esm/lib/agent/jmap/agent-jmap.d.ts +49 -0
- package/esm/lib/agent/jmap/agent-jmap.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-jmap.js +174 -0
- package/esm/lib/agent/jmap/agent-vars.d.ts +23 -0
- package/esm/lib/agent/jmap/agent-vars.d.ts.map +1 -0
- package/esm/lib/agent/jmap/agent-vars.js +65 -0
- package/esm/{skill/scripts/lib/credentials.d.ts → lib/agent/session/agent-credentials-store.d.ts} +4 -1
- package/esm/lib/agent/session/agent-credentials-store.d.ts.map +1 -0
- package/esm/{skill/scripts/lib/credentials.js → lib/agent/session/agent-credentials-store.js} +28 -8
- package/esm/lib/agent/session/agent-resolve-config.d.ts +24 -0
- package/esm/lib/agent/session/agent-resolve-config.d.ts.map +1 -0
- package/esm/lib/agent/session/agent-resolve-config.js +70 -0
- package/esm/lib/agent/session/agent-session.d.ts +62 -0
- package/esm/lib/agent/session/agent-session.d.ts.map +1 -0
- package/esm/lib/agent/session/agent-session.js +206 -0
- package/esm/lib/core/consts.d.ts.map +1 -0
- package/esm/lib/core/types.d.ts +2 -0
- package/esm/lib/core/types.d.ts.map +1 -0
- package/esm/lib/core/types.js +1 -0
- package/esm/lib/core/utils.d.ts +10 -0
- package/esm/lib/core/utils.d.ts.map +1 -0
- package/esm/lib/core/utils.js +28 -0
- package/esm/lib/mod.d.ts +14 -0
- package/esm/lib/mod.d.ts.map +1 -0
- package/esm/lib/mod.js +13 -0
- package/esm/lib/network/auth-client.d.ts +57 -0
- package/esm/lib/network/auth-client.d.ts.map +1 -0
- package/esm/lib/network/auth-client.js +188 -0
- package/esm/skill/cli.d.ts +3 -0
- package/esm/skill/cli.d.ts.map +1 -0
- package/esm/skill/cli.js +306 -0
- package/package.json +5 -6
- package/presets/list_inbox.json +39 -0
- package/presets/reply.json +75 -0
- package/presets/send_mail.json +42 -0
- package/esm/lib/src/consts.d.ts.map +0 -1
- package/esm/skill/scripts/jmap_request.d.ts +0 -3
- package/esm/skill/scripts/jmap_request.d.ts.map +0 -1
- package/esm/skill/scripts/jmap_request.js +0 -265
- package/esm/skill/scripts/lib/auth.d.ts.map +0 -1
- package/esm/skill/scripts/lib/auth.js +0 -163
- package/esm/skill/scripts/lib/credentials.d.ts.map +0 -1
- package/esm/skill/scripts/signup.d.ts +0 -3
- package/esm/skill/scripts/signup.d.ts.map +0 -1
- package/esm/skill/scripts/signup.js +0 -170
- /package/esm/lib/{src → core}/consts.d.ts +0 -0
- /package/esm/lib/{src → core}/consts.js +0 -0
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Atomic Mail skill: signup / login.
|
|
3
|
-
//
|
|
4
|
-
// Performs the full PoW handshake against auth-service:
|
|
5
|
-
// POST /api/v1/challenge -> { challengeJWT }
|
|
6
|
-
// solve scrypt PoW
|
|
7
|
-
// POST /api/v1/session -> { sessionJWT, apiKey? }
|
|
8
|
-
// POST /api/v1/capability -> { capabilityJWT }
|
|
9
|
-
//
|
|
10
|
-
// Writes three files into --out-dir:
|
|
11
|
-
// credentials.json stable account info + server config
|
|
12
|
-
// session.jwt 4h TTL, rotated by jmap_request when expired
|
|
13
|
-
// capability.jwt 2m TTL, rotated by jmap_request before each request
|
|
14
|
-
import process from "node:process";
|
|
15
|
-
import { parseArgs } from "node:util";
|
|
16
|
-
import { DEFAULT_POW_SCRYPT_SALT_HEX } from "../../lib/src/consts.js";
|
|
17
|
-
import { decodeJwtPayload, fetchCapability, performPoWAndSession, } from "./lib/auth.js";
|
|
18
|
-
import { defaultFilesFromOutDir, writeCredentials, writeJwtFile, } from "./lib/credentials.js";
|
|
19
|
-
const HELP = `Usage: atomic-mail-signup [OPTIONS]
|
|
20
|
-
|
|
21
|
-
Register a new Atomic Mail account, or log in with an existing API key.
|
|
22
|
-
Persists credentials to disk so subsequent atomic-mail-jmap invocations
|
|
23
|
-
work without re-authentication.
|
|
24
|
-
|
|
25
|
-
Options:
|
|
26
|
-
--auth-url URL Auth-service base URL.
|
|
27
|
-
[env: ATOMIC_MAIL_AUTH_URL]
|
|
28
|
-
--api-url URL API-service base URL (stored for jmap_request).
|
|
29
|
-
[env: ATOMIC_MAIL_API_URL]
|
|
30
|
-
--scrypt-salt SALT Override PoW scrypt salt (defaults to the deployment
|
|
31
|
-
constant). [env: ATOMIC_MAIL_SCRYPT_SALT]
|
|
32
|
-
--username NAME Register a NEW account with this username. The server
|
|
33
|
-
returns a freshly minted API key. Mutually exclusive
|
|
34
|
-
with --api-key.
|
|
35
|
-
--api-key KEY Log in with an existing API key. Mutually exclusive
|
|
36
|
-
with --username.
|
|
37
|
-
--out-dir DIR Directory to write credential files into.
|
|
38
|
-
Default: current working directory.
|
|
39
|
-
--quiet Suppress progress messages on stderr.
|
|
40
|
-
--help, -h Show this help.
|
|
41
|
-
|
|
42
|
-
Output files (in --out-dir):
|
|
43
|
-
credentials.json { apiKey, inboxId, authUrl, apiUrl, scryptSalt }
|
|
44
|
-
session.jwt Session JWT (4h TTL).
|
|
45
|
-
capability.jwt Capability JWT (2m TTL).
|
|
46
|
-
|
|
47
|
-
Exit codes:
|
|
48
|
-
0 success
|
|
49
|
-
1 network error, server rejection, or unexpected response shape
|
|
50
|
-
2 invalid CLI usage (missing/conflicting flags)
|
|
51
|
-
|
|
52
|
-
Examples:
|
|
53
|
-
atomic-mail-signup --auth-url https://auth.example.com \\
|
|
54
|
-
--api-url https://api.example.com \\
|
|
55
|
-
--username alice
|
|
56
|
-
atomic-mail-signup --api-key 11111111-2222-3333-4444-555555555555
|
|
57
|
-
`;
|
|
58
|
-
function fail(message, code = 1) {
|
|
59
|
-
process.stderr.write(`Error: ${message}\n`);
|
|
60
|
-
if (code === 2)
|
|
61
|
-
process.stderr.write("\nRun with --help for usage.\n");
|
|
62
|
-
process.exit(code);
|
|
63
|
-
}
|
|
64
|
-
function readArgs() {
|
|
65
|
-
let parsed;
|
|
66
|
-
try {
|
|
67
|
-
parsed = parseArgs({
|
|
68
|
-
args: process.argv.slice(2),
|
|
69
|
-
options: {
|
|
70
|
-
"auth-url": { type: "string" },
|
|
71
|
-
"api-url": { type: "string" },
|
|
72
|
-
"scrypt-salt": { type: "string" },
|
|
73
|
-
username: { type: "string" },
|
|
74
|
-
"api-key": { type: "string" },
|
|
75
|
-
"out-dir": { type: "string" },
|
|
76
|
-
quiet: { type: "boolean" },
|
|
77
|
-
help: { type: "boolean", short: "h" },
|
|
78
|
-
},
|
|
79
|
-
strict: true,
|
|
80
|
-
allowPositionals: false,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
catch (err) {
|
|
84
|
-
fail(err.message, 2);
|
|
85
|
-
}
|
|
86
|
-
if (parsed.values.help) {
|
|
87
|
-
process.stdout.write(HELP);
|
|
88
|
-
process.exit(0);
|
|
89
|
-
}
|
|
90
|
-
const env = process.env;
|
|
91
|
-
const authUrl = parsed.values["auth-url"] ??
|
|
92
|
-
env.ATOMIC_MAIL_AUTH_URL ?? "";
|
|
93
|
-
const apiUrl = parsed.values["api-url"] ??
|
|
94
|
-
env.ATOMIC_MAIL_API_URL ?? "";
|
|
95
|
-
const scryptSalt = parsed.values["scrypt-salt"] ??
|
|
96
|
-
env.ATOMIC_MAIL_SCRYPT_SALT ?? DEFAULT_POW_SCRYPT_SALT_HEX;
|
|
97
|
-
const outDir = parsed.values["out-dir"] ?? ".";
|
|
98
|
-
if (!authUrl) {
|
|
99
|
-
fail("--auth-url is required (or set ATOMIC_MAIL_AUTH_URL).", 2);
|
|
100
|
-
}
|
|
101
|
-
if (!apiUrl) {
|
|
102
|
-
fail("--api-url is required (or set ATOMIC_MAIL_API_URL).", 2);
|
|
103
|
-
}
|
|
104
|
-
const username = parsed.values.username;
|
|
105
|
-
const apiKey = parsed.values["api-key"];
|
|
106
|
-
if (!!username === !!apiKey) {
|
|
107
|
-
fail("Provide exactly one of --username (new account) or --api-key (login).", 2);
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
authUrl: authUrl.replace(/\/+$/, ""),
|
|
111
|
-
apiUrl: apiUrl.replace(/\/+$/, ""),
|
|
112
|
-
scryptSalt,
|
|
113
|
-
username,
|
|
114
|
-
apiKey,
|
|
115
|
-
outDir,
|
|
116
|
-
quiet: parsed.values.quiet === true,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async function main() {
|
|
120
|
-
const args = readArgs();
|
|
121
|
-
const files = defaultFilesFromOutDir(args.outDir);
|
|
122
|
-
const log = (msg) => {
|
|
123
|
-
if (!args.quiet)
|
|
124
|
-
process.stderr.write(msg + "\n");
|
|
125
|
-
};
|
|
126
|
-
log(args.username
|
|
127
|
-
? `Registering new account "${args.username}"...`
|
|
128
|
-
: `Logging in with existing API key...`);
|
|
129
|
-
log(`Solving PoW + exchanging session against ${args.authUrl}...`);
|
|
130
|
-
const session = await performPoWAndSession({
|
|
131
|
-
authUrl: args.authUrl,
|
|
132
|
-
scryptSalt: args.scryptSalt,
|
|
133
|
-
username: args.username,
|
|
134
|
-
apiKey: args.apiKey,
|
|
135
|
-
});
|
|
136
|
-
const apiKey = session.apiKey ?? args.apiKey;
|
|
137
|
-
if (!apiKey) {
|
|
138
|
-
fail("Session response did not include an apiKey and none was provided. " +
|
|
139
|
-
"This indicates a server bug.");
|
|
140
|
-
}
|
|
141
|
-
log(`Fetching initial capability JWT...`);
|
|
142
|
-
const capabilityJWT = await fetchCapability(args.authUrl, session.sessionJWT);
|
|
143
|
-
const claims = decodeJwtPayload(capabilityJWT);
|
|
144
|
-
const inboxId = claims.inboxId;
|
|
145
|
-
if (typeof inboxId !== "string" || inboxId.length === 0) {
|
|
146
|
-
fail("Capability JWT did not contain an inboxId claim.");
|
|
147
|
-
}
|
|
148
|
-
await writeCredentials(files.credentialsFile, {
|
|
149
|
-
apiKey,
|
|
150
|
-
inboxId,
|
|
151
|
-
authUrl: args.authUrl,
|
|
152
|
-
apiUrl: args.apiUrl,
|
|
153
|
-
scryptSalt: args.scryptSalt,
|
|
154
|
-
});
|
|
155
|
-
await writeJwtFile(files.sessionFile, session.sessionJWT);
|
|
156
|
-
await writeJwtFile(files.capabilityFile, capabilityJWT);
|
|
157
|
-
log(`Wrote ${files.credentialsFile}`);
|
|
158
|
-
log(`Wrote ${files.sessionFile}`);
|
|
159
|
-
log(`Wrote ${files.capabilityFile}`);
|
|
160
|
-
process.stdout.write(JSON.stringify({
|
|
161
|
-
inboxId,
|
|
162
|
-
apiKey,
|
|
163
|
-
credentialsFile: files.credentialsFile,
|
|
164
|
-
sessionFile: files.sessionFile,
|
|
165
|
-
capabilityFile: files.capabilityFile,
|
|
166
|
-
}, null, 2) + "\n");
|
|
167
|
-
}
|
|
168
|
-
main().catch((err) => {
|
|
169
|
-
fail(err instanceof Error ? err.message : String(err));
|
|
170
|
-
});
|
|
File without changes
|
|
File without changes
|