run402 4.96.0 → 4.98.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 +3 -3
- package/cli.mjs +1 -7
- package/core-dist/binding-file.js +28 -1
- package/core-dist/wallet.js +3 -3
- package/lib/auth.mjs +1 -2
- package/lib/buzz-doctor.mjs +21 -806
- package/lib/buzz-doctor.test.mjs +7 -6
- package/lib/buzz.mjs +1 -1
- package/lib/buzz.test.mjs +13 -2
- package/lib/command-manifest.mjs +3 -6
- package/lib/credentials.mjs +4 -4
- package/lib/deploy-v2.mjs +27 -27
- package/lib/doctor.mjs +72 -811
- package/lib/errors.mjs +1 -1
- package/lib/events.mjs +1 -1
- package/lib/grants.mjs +148 -46
- package/lib/init.mjs +35 -576
- package/lib/logs.mjs +1 -1
- package/lib/org-context.mjs +39 -376
- package/lib/orgs.mjs +22 -106
- package/lib/projects.mjs +2 -3
- package/lib/repos.mjs +6 -6
- package/lib/rooms.mjs +1 -2
- package/lib/sdk-errors.mjs +26 -0
- package/lib/sites.mjs +5 -5
- package/lib/status.mjs +14 -154
- package/lib/up.mjs +1 -2
- package/lib/vault-scaffold.mjs +2 -3
- package/lib/vault-target.mjs +14 -141
- package/lib/wallet-context.mjs +61 -227
- package/lib/wallets.mjs +47 -310
- package/package.json +1 -2
- package/sdk/core-dist/binding-file.js +28 -1
- package/sdk/core-dist/wallet.js +3 -3
- package/sdk/dist/errors.d.ts +25 -3
- package/sdk/dist/errors.d.ts.map +1 -1
- package/sdk/dist/errors.js +46 -4
- package/sdk/dist/errors.js.map +1 -1
- package/sdk/dist/grant-key-credentials.d.ts +38 -0
- package/sdk/dist/grant-key-credentials.d.ts.map +1 -0
- package/sdk/dist/grant-key-credentials.js +42 -0
- package/sdk/dist/grant-key-credentials.js.map +1 -0
- package/sdk/dist/index.d.ts +25 -17
- package/sdk/dist/index.d.ts.map +1 -1
- package/sdk/dist/index.js +18 -14
- package/sdk/dist/index.js.map +1 -1
- package/sdk/dist/kernel.d.ts +34 -0
- package/sdk/dist/kernel.d.ts.map +1 -1
- package/sdk/dist/kernel.js +15 -1
- package/sdk/dist/kernel.js.map +1 -1
- package/sdk/dist/namespaces/admin.d.ts.map +1 -1
- package/sdk/dist/namespaces/admin.js +8 -0
- package/sdk/dist/namespaces/admin.js.map +1 -1
- package/sdk/dist/namespaces/agent.d.ts +2 -2
- package/sdk/dist/namespaces/agent.d.ts.map +1 -1
- package/sdk/dist/namespaces/agent.js +4 -0
- package/sdk/dist/namespaces/agent.js.map +1 -1
- package/sdk/dist/namespaces/agent.types.d.ts +5 -0
- package/sdk/dist/namespaces/agent.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/apps.d.ts.map +1 -1
- package/sdk/dist/namespaces/apps.js +2 -0
- package/sdk/dist/namespaces/apps.js.map +1 -1
- package/sdk/dist/namespaces/auth.d.ts.map +1 -1
- package/sdk/dist/namespaces/auth.js +9 -0
- package/sdk/dist/namespaces/auth.js.map +1 -1
- package/sdk/dist/namespaces/billing.d.ts +1 -1
- package/sdk/dist/namespaces/billing.js +1 -1
- package/sdk/dist/namespaces/branches.d.ts.map +1 -1
- package/sdk/dist/namespaces/branches.js +2 -0
- package/sdk/dist/namespaces/branches.js.map +1 -1
- package/sdk/dist/namespaces/buzz.js +1 -1
- package/sdk/dist/namespaces/buzz.js.map +1 -1
- package/sdk/dist/namespaces/ci.d.ts.map +1 -1
- package/sdk/dist/namespaces/ci.js +2 -0
- package/sdk/dist/namespaces/ci.js.map +1 -1
- package/sdk/dist/namespaces/credentials.d.ts +4 -27
- package/sdk/dist/namespaces/credentials.d.ts.map +1 -1
- package/sdk/dist/namespaces/credentials.js +33 -4
- package/sdk/dist/namespaces/credentials.js.map +1 -1
- package/sdk/dist/namespaces/deploy.js +5 -5
- package/sdk/dist/namespaces/deploy.js.map +1 -1
- package/sdk/dist/namespaces/domains.d.ts +1 -1
- package/sdk/dist/namespaces/domains.js +1 -1
- package/sdk/dist/namespaces/errors.d.ts +1 -1
- package/sdk/dist/namespaces/errors.js +2 -2
- package/sdk/dist/namespaces/escalations.d.ts +2 -2
- package/sdk/dist/namespaces/escalations.d.ts.map +1 -1
- package/sdk/dist/namespaces/escalations.js +4 -2
- package/sdk/dist/namespaces/escalations.js.map +1 -1
- package/sdk/dist/namespaces/escalations.types.d.ts +3 -3
- package/sdk/dist/namespaces/escalations.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/events.d.ts +1 -1
- package/sdk/dist/namespaces/events.js +1 -1
- package/sdk/dist/namespaces/functions.js +1 -1
- package/sdk/dist/namespaces/functions.js.map +1 -1
- package/sdk/dist/namespaces/grants.d.ts +43 -9
- package/sdk/dist/namespaces/grants.d.ts.map +1 -1
- package/sdk/dist/namespaces/grants.js +103 -10
- package/sdk/dist/namespaces/grants.js.map +1 -1
- package/sdk/dist/namespaces/grants.types.d.ts +120 -15
- package/sdk/dist/namespaces/grants.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/grants.types.js +12 -3
- package/sdk/dist/namespaces/grants.types.js.map +1 -1
- package/sdk/dist/namespaces/identity-links.types.d.ts +2 -2
- package/sdk/dist/namespaces/identity-links.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/live.d.ts +0 -16
- package/sdk/dist/namespaces/live.d.ts.map +1 -1
- package/sdk/dist/namespaces/live.js +19 -0
- package/sdk/dist/namespaces/live.js.map +1 -1
- package/sdk/dist/namespaces/me.d.ts.map +1 -1
- package/sdk/dist/namespaces/me.js +3 -0
- package/sdk/dist/namespaces/me.js.map +1 -1
- package/sdk/dist/namespaces/org.d.ts +1 -1
- package/sdk/dist/namespaces/org.d.ts.map +1 -1
- package/sdk/dist/namespaces/org.js +4 -1
- package/sdk/dist/namespaces/org.js.map +1 -1
- package/sdk/dist/namespaces/projects.d.ts +1 -1
- package/sdk/dist/namespaces/projects.d.ts.map +1 -1
- package/sdk/dist/namespaces/projects.js +6 -1
- package/sdk/dist/namespaces/projects.js.map +1 -1
- package/sdk/dist/namespaces/repos.d.ts.map +1 -1
- package/sdk/dist/namespaces/repos.js +7 -2
- package/sdk/dist/namespaces/repos.js.map +1 -1
- package/sdk/dist/namespaces/rooms.d.ts +3 -3
- package/sdk/dist/namespaces/rooms.d.ts.map +1 -1
- package/sdk/dist/namespaces/rooms.js +6 -3
- package/sdk/dist/namespaces/rooms.js.map +1 -1
- package/sdk/dist/namespaces/session.d.ts.map +1 -1
- package/sdk/dist/namespaces/session.js +18 -0
- package/sdk/dist/namespaces/session.js.map +1 -1
- package/sdk/dist/namespaces/transfers.d.ts.map +1 -1
- package/sdk/dist/namespaces/transfers.js +3 -0
- package/sdk/dist/namespaces/transfers.js.map +1 -1
- package/sdk/dist/namespaces/wallets.d.ts.map +1 -1
- package/sdk/dist/namespaces/wallets.js +2 -0
- package/sdk/dist/namespaces/wallets.js.map +1 -1
- package/sdk/dist/namespaces/write-approval.d.ts.map +1 -1
- package/sdk/dist/namespaces/write-approval.js +3 -0
- package/sdk/dist/namespaces/write-approval.js.map +1 -1
- package/sdk/dist/node/actions-node.d.ts.map +1 -1
- package/sdk/dist/node/actions-node.js +3 -0
- package/sdk/dist/node/actions-node.js.map +1 -1
- package/sdk/dist/node/buzz-doctor-contract.d.ts +155 -0
- package/sdk/dist/node/buzz-doctor-contract.d.ts.map +1 -0
- package/sdk/dist/node/buzz-doctor-contract.js +385 -0
- package/sdk/dist/node/buzz-doctor-contract.js.map +1 -0
- package/sdk/dist/node/buzz-doctor.d.ts +155 -0
- package/sdk/dist/node/buzz-doctor.d.ts.map +1 -0
- package/sdk/dist/node/buzz-doctor.js +810 -0
- package/sdk/dist/node/buzz-doctor.js.map +1 -0
- package/sdk/dist/node/credentials.d.ts +18 -13
- package/sdk/dist/node/credentials.d.ts.map +1 -1
- package/sdk/dist/node/credentials.js +13 -13
- package/sdk/dist/node/credentials.js.map +1 -1
- package/sdk/dist/node/diagnostics.d.ts +45 -0
- package/sdk/dist/node/diagnostics.d.ts.map +1 -0
- package/sdk/dist/node/diagnostics.js +67 -0
- package/sdk/dist/node/diagnostics.js.map +1 -0
- package/sdk/dist/node/doctor.d.ts +101 -0
- package/sdk/dist/node/doctor.d.ts.map +1 -0
- package/sdk/dist/node/doctor.js +618 -0
- package/sdk/dist/node/doctor.js.map +1 -0
- package/sdk/dist/node/index.d.ts +61 -9
- package/sdk/dist/node/index.d.ts.map +1 -1
- package/sdk/dist/node/index.js +37 -2
- package/sdk/dist/node/index.js.map +1 -1
- package/sdk/dist/node/init.d.ts +137 -0
- package/sdk/dist/node/init.d.ts.map +1 -0
- package/sdk/dist/node/init.js +507 -0
- package/sdk/dist/node/init.js.map +1 -0
- package/sdk/dist/node/lightning-wallet.d.ts +61 -0
- package/sdk/dist/node/lightning-wallet.d.ts.map +1 -0
- package/sdk/dist/node/lightning-wallet.js +126 -0
- package/sdk/dist/node/lightning-wallet.js.map +1 -0
- package/sdk/dist/node/local-actions.d.ts +23 -0
- package/sdk/dist/node/local-actions.d.ts.map +1 -0
- package/sdk/dist/node/local-actions.js +38 -0
- package/sdk/dist/node/local-actions.js.map +1 -0
- package/sdk/dist/node/org-context.d.ts +169 -0
- package/sdk/dist/node/org-context.d.ts.map +1 -0
- package/sdk/dist/node/org-context.js +403 -0
- package/sdk/dist/node/org-context.js.map +1 -0
- package/sdk/dist/node/status.d.ts +62 -0
- package/sdk/dist/node/status.d.ts.map +1 -0
- package/sdk/dist/node/status.js +132 -0
- package/sdk/dist/node/status.js.map +1 -0
- package/sdk/dist/node/vault-target.d.ts +49 -0
- package/sdk/dist/node/vault-target.d.ts.map +1 -0
- package/sdk/dist/node/vault-target.js +109 -0
- package/sdk/dist/node/vault-target.js.map +1 -0
- package/sdk/dist/node/wallets.d.ts +242 -0
- package/sdk/dist/node/wallets.d.ts.map +1 -0
- package/sdk/dist/node/wallets.js +484 -0
- package/sdk/dist/node/wallets.js.map +1 -0
- package/sdk/dist/project-auth-classification.d.ts +8 -8
- package/sdk/dist/project-auth-classification.d.ts.map +1 -1
- package/sdk/dist/project-auth-classification.js +7 -7
- package/sdk/dist/project-auth-classification.js.map +1 -1
- package/sdk/dist/scoped.d.ts +6 -14
- package/sdk/dist/scoped.d.ts.map +1 -1
- package/sdk/dist/scoped.js +10 -21
- package/sdk/dist/scoped.js.map +1 -1
- package/sdk/dist/secret-gate.d.ts +377 -0
- package/sdk/dist/secret-gate.d.ts.map +1 -0
- package/sdk/dist/secret-gate.js +273 -0
- package/sdk/dist/secret-gate.js.map +1 -0
- package/vault-surface.json +1 -1
- package/fixtures/buzz-v0.5.2-cli-capabilities.json +0 -92
- package/fixtures/run402-buzz-doctor-v1-contract.json +0 -140
- package/lib/buzz-doctor-contract.mjs +0 -97
- package/lib/buzz-doctor-contract.test.mjs +0 -134
- package/lib/delegates.mjs +0 -189
- package/lib/lightning-wallet.mjs +0 -115
- package/sdk/dist/delegate-credentials.d.ts +0 -37
- package/sdk/dist/delegate-credentials.d.ts.map +0 -1
- package/sdk/dist/delegate-credentials.js +0 -41
- package/sdk/dist/delegate-credentials.js.map +0 -1
- package/sdk/dist/namespaces/delegates.d.ts +0 -50
- package/sdk/dist/namespaces/delegates.d.ts.map +0 -1
- package/sdk/dist/namespaces/delegates.js +0 -99
- package/sdk/dist/namespaces/delegates.js.map +0 -1
- package/sdk/dist/namespaces/delegates.types.d.ts +0 -88
- package/sdk/dist/namespaces/delegates.types.d.ts.map +0 -1
- package/sdk/dist/namespaces/delegates.types.js +0 -10
- package/sdk/dist/namespaces/delegates.types.js.map +0 -1
package/lib/delegates.mjs
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { getSdk } from "./sdk.mjs";
|
|
2
|
-
import { reportSdkError, parseFlagJson } from "./sdk-errors.mjs";
|
|
3
|
-
import {
|
|
4
|
-
normalizeArgv,
|
|
5
|
-
assertKnownFlags,
|
|
6
|
-
flagValue,
|
|
7
|
-
requirePositionalCount,
|
|
8
|
-
resolveProjectSelector,
|
|
9
|
-
failUnknownSubcommand,
|
|
10
|
-
} from "./argparse.mjs";
|
|
11
|
-
|
|
12
|
-
const HELP = `run402 delegates — scoped deploy credentials an owner mints for an agent
|
|
13
|
-
|
|
14
|
-
Usage:
|
|
15
|
-
run402 delegates <subcommand> [args...]
|
|
16
|
-
|
|
17
|
-
Subcommands:
|
|
18
|
-
create --grant <grant_id> [--project <project_id>] [--capability <cap>] [--kind <kind>]
|
|
19
|
-
[--scope <json>] [--expires <iso8601>]
|
|
20
|
-
Mint a delegate. The bearer is printed ONCE.
|
|
21
|
-
list [--project <project_id>] List delegates (never shows tokens)
|
|
22
|
-
revoke <delegate_id> [--project <project_id>]
|
|
23
|
-
Revoke immediately
|
|
24
|
-
rotate <delegate_id> [--project <project_id>]
|
|
25
|
-
Revoke + reissue; new bearer printed ONCE
|
|
26
|
-
|
|
27
|
-
Notes:
|
|
28
|
-
- A delegate NARROWS an existing grant, so mint the grant first:
|
|
29
|
-
run402 grants create <agent-wallet> --capability deploy --project <project_id>
|
|
30
|
-
then pass the returned grant_id to 'delegates create'.
|
|
31
|
-
- Mutations require you to be an owner of the project's org (wallet SIWX).
|
|
32
|
-
- A delegate can never be an owner, and is revocable and expiring.
|
|
33
|
-
- The token is shown ONCE and is not recoverable. Store it immediately;
|
|
34
|
-
if you lose it, 'rotate' issues a new one.
|
|
35
|
-
- Use it with: RUN402_DELEGATE_TOKEN=<token> run402 deploy ...
|
|
36
|
-
- JSON in, JSON out.
|
|
37
|
-
|
|
38
|
-
Why this exists:
|
|
39
|
-
Project API keys are issued once at project-create and are never re-issued.
|
|
40
|
-
An agent that loses local state therefore cannot deploy to its own project.
|
|
41
|
-
You still hold the wallet, so SIWX is enough to mint a fresh credential.
|
|
42
|
-
|
|
43
|
-
Examples:
|
|
44
|
-
run402 grants create 0x90F3eB...F80a --capability deploy --project prj_abc
|
|
45
|
-
run402 delegates create --grant 1d86452e-... --project prj_abc
|
|
46
|
-
run402 delegates list --project prj_abc
|
|
47
|
-
run402 delegates revoke 5845f17b-... --project prj_abc
|
|
48
|
-
`;
|
|
49
|
-
|
|
50
|
-
const SUB_HELP = {
|
|
51
|
-
create: `run402 delegates create — mint a scoped deploy credential
|
|
52
|
-
|
|
53
|
-
Usage:
|
|
54
|
-
run402 delegates create --grant <grant_id> [--project <project_id>] [--capability <cap>]
|
|
55
|
-
[--kind <kind>] [--scope <json>] [--expires <iso8601>]
|
|
56
|
-
|
|
57
|
-
--capability defaults to "deploy". --kind defaults to "run402_agent_key" (the
|
|
58
|
-
only kind that returns a bearer). --scope, if given, overrides --capability and
|
|
59
|
-
must be a JSON object like {"v":1,"capabilities":["deploy"]}.
|
|
60
|
-
|
|
61
|
-
The bearer is printed ONCE and cannot be read back. Store it immediately.
|
|
62
|
-
Requires owner of the project's org.
|
|
63
|
-
`,
|
|
64
|
-
list: `run402 delegates list — list a project's delegates
|
|
65
|
-
|
|
66
|
-
Usage:
|
|
67
|
-
run402 delegates list [--project <project_id>]
|
|
68
|
-
|
|
69
|
-
Never returns tokens or secret material — id, kind, scope, expiry, revocation.
|
|
70
|
-
`,
|
|
71
|
-
revoke: `run402 delegates revoke — revoke a delegate immediately
|
|
72
|
-
|
|
73
|
-
Usage:
|
|
74
|
-
run402 delegates revoke <delegate_id> [--project <project_id>]
|
|
75
|
-
|
|
76
|
-
Takes effect for every subsequent request. Requires owner of the project's org.
|
|
77
|
-
`,
|
|
78
|
-
rotate: `run402 delegates rotate — revoke and reissue in one step
|
|
79
|
-
|
|
80
|
-
Usage:
|
|
81
|
-
run402 delegates rotate <delegate_id> [--project <project_id>]
|
|
82
|
-
|
|
83
|
-
Keeps the same principal, grant, kind, scope, cap and expiry. The NEW bearer is
|
|
84
|
-
printed once. Use this when a token is lost or possibly exposed.
|
|
85
|
-
`,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const CREATE_VALUE_FLAGS = ["--project", "--grant", "--capability", "--kind", "--scope", "--expires"];
|
|
89
|
-
|
|
90
|
-
async function create(args) {
|
|
91
|
-
const a = normalizeArgv(args);
|
|
92
|
-
assertKnownFlags(a, [...CREATE_VALUE_FLAGS, "--help", "-h"], CREATE_VALUE_FLAGS);
|
|
93
|
-
const grantId = flagValue(a, "--grant");
|
|
94
|
-
const capability = flagValue(a, "--capability") || "deploy";
|
|
95
|
-
const kind = flagValue(a, "--kind") || undefined;
|
|
96
|
-
const scopeRaw = flagValue(a, "--scope");
|
|
97
|
-
const expiresAt = flagValue(a, "--expires");
|
|
98
|
-
const { projectId, rest } = resolveProjectSelector(a, { valueFlags: CREATE_VALUE_FLAGS });
|
|
99
|
-
requirePositionalCount(rest, CREATE_VALUE_FLAGS, {
|
|
100
|
-
min: 0,
|
|
101
|
-
max: 0,
|
|
102
|
-
command: "run402 delegates create --grant <grant_id> [--project <project_id>]",
|
|
103
|
-
missing: "",
|
|
104
|
-
});
|
|
105
|
-
if (!grantId) {
|
|
106
|
-
console.error("Missing --grant <grant_id>. Mint one first:");
|
|
107
|
-
console.error(" run402 grants create <agent-wallet> --capability deploy --project <project_id>");
|
|
108
|
-
process.exit(1);
|
|
109
|
-
}
|
|
110
|
-
const scope = scopeRaw != null
|
|
111
|
-
? parseFlagJson("--scope", scopeRaw)
|
|
112
|
-
: { v: 1, capabilities: [capability], projects: [projectId] };
|
|
113
|
-
try {
|
|
114
|
-
const res = await getSdk().delegates.create(projectId, {
|
|
115
|
-
grantId,
|
|
116
|
-
kind,
|
|
117
|
-
scope,
|
|
118
|
-
expiresAt: expiresAt || undefined,
|
|
119
|
-
});
|
|
120
|
-
console.log(JSON.stringify(res, null, 2));
|
|
121
|
-
if (res?.token) {
|
|
122
|
-
console.error("");
|
|
123
|
-
console.error("The token above is shown ONCE and cannot be read back.");
|
|
124
|
-
console.error("Store it now, then use it as: RUN402_DELEGATE_TOKEN=<token>");
|
|
125
|
-
}
|
|
126
|
-
} catch (err) {
|
|
127
|
-
reportSdkError(err);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async function list(args) {
|
|
132
|
-
const a = normalizeArgv(args);
|
|
133
|
-
assertKnownFlags(a, ["--project", "--help", "-h"], ["--project"]);
|
|
134
|
-
const { projectId, rest } = resolveProjectSelector(a, { valueFlags: ["--project"] });
|
|
135
|
-
requirePositionalCount(rest, ["--project"], {
|
|
136
|
-
min: 0,
|
|
137
|
-
max: 0,
|
|
138
|
-
command: "run402 delegates list [--project <project_id>]",
|
|
139
|
-
missing: "",
|
|
140
|
-
});
|
|
141
|
-
try {
|
|
142
|
-
console.log(JSON.stringify(await getSdk().delegates.list(projectId), null, 2));
|
|
143
|
-
} catch (err) {
|
|
144
|
-
reportSdkError(err);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function oneIdCommand(name) {
|
|
149
|
-
return async (args) => {
|
|
150
|
-
const a = normalizeArgv(args);
|
|
151
|
-
assertKnownFlags(a, ["--project", "--help", "-h"], ["--project"]);
|
|
152
|
-
const { projectId, rest } = resolveProjectSelector(a, { valueFlags: ["--project"] });
|
|
153
|
-
const [delegateId] = requirePositionalCount(rest, ["--project"], {
|
|
154
|
-
min: 1,
|
|
155
|
-
max: 1,
|
|
156
|
-
command: `run402 delegates ${name} <delegate_id> [--project <project_id>]`,
|
|
157
|
-
missing: "Missing <delegate_id>.",
|
|
158
|
-
});
|
|
159
|
-
try {
|
|
160
|
-
const res = await getSdk().delegates[name](projectId, delegateId);
|
|
161
|
-
console.log(JSON.stringify(res, null, 2));
|
|
162
|
-
if (res?.token) {
|
|
163
|
-
console.error("");
|
|
164
|
-
console.error("The token above is shown ONCE and cannot be read back.");
|
|
165
|
-
}
|
|
166
|
-
} catch (err) {
|
|
167
|
-
reportSdkError(err);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export async function run(sub, args) {
|
|
173
|
-
if (!sub || sub === "--help" || sub === "-h") {
|
|
174
|
-
console.log(HELP);
|
|
175
|
-
process.exit(0);
|
|
176
|
-
}
|
|
177
|
-
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) {
|
|
178
|
-
console.log(SUB_HELP[sub] || HELP);
|
|
179
|
-
process.exit(0);
|
|
180
|
-
}
|
|
181
|
-
switch (sub) {
|
|
182
|
-
case "create": await create(args); break;
|
|
183
|
-
case "list": await list(args); break;
|
|
184
|
-
case "revoke": await oneIdCommand("revoke")(args); break;
|
|
185
|
-
case "rotate": await oneIdCommand("rotate")(args); break;
|
|
186
|
-
default:
|
|
187
|
-
failUnknownSubcommand("delegates", sub);
|
|
188
|
-
}
|
|
189
|
-
}
|
package/lib/lightning-wallet.mjs
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Lightning wallet on the CLI: mint the agent's budgeted wallet on
|
|
3
|
-
* Run402's Hub, keep its pairing in the active profile's wallet.json
|
|
4
|
-
* beside the Base key, report its balance, revoke it. Shared by
|
|
5
|
-
* `run402 init lightning`, `run402 wallets lightning …`, and
|
|
6
|
-
* `run402 wallets current`. The pairing secret is never printed.
|
|
7
|
-
*/
|
|
8
|
-
import { readWallet, saveWallet } from "../core-dist/wallet.js";
|
|
9
|
-
import { getSdk } from "./sdk.mjs";
|
|
10
|
-
|
|
11
|
-
export const LIGHTNING_MINT_TIMEOUT_MS = 45_000;
|
|
12
|
-
|
|
13
|
-
/** Public facts only: never the pairing. */
|
|
14
|
-
export function describeLightning(localWallet, wallet = null, balance = null) {
|
|
15
|
-
const local = localWallet?.lightning ?? null;
|
|
16
|
-
if (!local && !wallet) return null;
|
|
17
|
-
return {
|
|
18
|
-
wallet_id: wallet?.wallet_id ?? local?.wallet_id ?? null,
|
|
19
|
-
status: wallet?.status ?? (local ? "active" : null),
|
|
20
|
-
custody: "run402_hub",
|
|
21
|
-
custody_note: "The sats sit on Run402's Lightning Hub; this wallet is a budgeted connection to them, not self-custody.",
|
|
22
|
-
lightning_address: wallet?.lightning_address ?? local?.lightning_address ?? null,
|
|
23
|
-
budget_sats: wallet?.budget_sats ?? local?.budget_sats ?? null,
|
|
24
|
-
starter_sats: wallet?.starter_sats ?? local?.starter_sats ?? null,
|
|
25
|
-
has_pairing: Boolean(local?.nwc),
|
|
26
|
-
minted_at: local?.minted_at ?? wallet?.activated_at ?? null,
|
|
27
|
-
...(balance ? balance : {}),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Balance and remaining budget over NWC, best-effort (null on any failure). */
|
|
32
|
-
export async function readLightningBalance(localWallet) {
|
|
33
|
-
const nwc = localWallet?.lightning?.nwc;
|
|
34
|
-
if (!nwc) return null;
|
|
35
|
-
try {
|
|
36
|
-
const { NwcWallet, closeNwcConnections } = await import("#sdk/node");
|
|
37
|
-
const wallet = new NwcWallet(nwc, { timeoutMs: 15_000 });
|
|
38
|
-
const [balance_sats, budget] = await Promise.all([wallet.getBalanceSats(), wallet.getBudgetSats().catch(() => null)]);
|
|
39
|
-
closeNwcConnections();
|
|
40
|
-
return {
|
|
41
|
-
balance_sats,
|
|
42
|
-
budget_remaining_sats: budget && budget.totalSats !== null ? budget.totalSats - budget.usedSats : null,
|
|
43
|
-
};
|
|
44
|
-
} catch {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function storePairing(localWallet, wallet) {
|
|
50
|
-
const next = {
|
|
51
|
-
...localWallet,
|
|
52
|
-
rail: "lightning",
|
|
53
|
-
lightning: {
|
|
54
|
-
wallet_id: wallet.wallet_id,
|
|
55
|
-
nwc: wallet.pairing,
|
|
56
|
-
lightning_address: wallet.lightning_address ?? null,
|
|
57
|
-
budget_sats: wallet.budget_sats,
|
|
58
|
-
starter_sats: wallet.starter_sats,
|
|
59
|
-
custody: "run402_hub",
|
|
60
|
-
minted_at: wallet.activated_at ?? new Date().toISOString(),
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
saveWallet(next);
|
|
64
|
-
return next;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Ensure the active profile holds an active Lightning wallet. Returns
|
|
69
|
-
* `{ localWallet, wallet, outcome }` where outcome is `stored` (pairing just
|
|
70
|
-
* saved), `present` (already held locally), `minting` (the platform is still
|
|
71
|
-
* minting; rerun later), `unavailable` (no Hub on this gateway), or
|
|
72
|
-
* `pairing_lost` (the wallet is active but its one-time pairing was handed to
|
|
73
|
-
* another machine; revoke and mint again).
|
|
74
|
-
*/
|
|
75
|
-
export async function ensureLightningWallet(options = {}) {
|
|
76
|
-
let localWallet = readWallet();
|
|
77
|
-
if (!localWallet) throw new Error("no local wallet configured; run `run402 init` first");
|
|
78
|
-
if (localWallet.lightning?.nwc) {
|
|
79
|
-
let wallet = null;
|
|
80
|
-
try { wallet = await getSdk().agent.lightningWallet.get(); } catch { /* offline read is fine */ }
|
|
81
|
-
if (wallet && wallet.status !== "active") return { localWallet, wallet, outcome: wallet.status };
|
|
82
|
-
return { localWallet, wallet, outcome: "present" };
|
|
83
|
-
}
|
|
84
|
-
let wallet;
|
|
85
|
-
try {
|
|
86
|
-
wallet = await getSdk().agent.lightningWallet.mint({ timeoutMs: options.timeoutMs ?? LIGHTNING_MINT_TIMEOUT_MS });
|
|
87
|
-
} catch (err) {
|
|
88
|
-
const code = err?.body?.code ?? err?.code;
|
|
89
|
-
if (code === "LIGHTNING_WALLET_NOT_AVAILABLE") return { localWallet, wallet: null, outcome: "unavailable", error: err };
|
|
90
|
-
if (code === "LIGHTNING_WALLET_STILL_MINTING") return { localWallet, wallet: null, outcome: "minting", error: err };
|
|
91
|
-
throw err;
|
|
92
|
-
}
|
|
93
|
-
if (wallet.status === "minting") return { localWallet, wallet, outcome: "minting" };
|
|
94
|
-
if (wallet.status !== "active") return { localWallet, wallet, outcome: wallet.status };
|
|
95
|
-
if (typeof wallet.pairing !== "string") return { localWallet, wallet, outcome: "pairing_lost" };
|
|
96
|
-
localWallet = storePairing(localWallet, wallet);
|
|
97
|
-
return { localWallet, wallet, outcome: "stored" };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** Revoke on the platform and forget the pairing locally; the rail returns to x402. */
|
|
101
|
-
export async function revokeLightningWallet() {
|
|
102
|
-
const localWallet = readWallet();
|
|
103
|
-
let wallet = null;
|
|
104
|
-
try {
|
|
105
|
-
wallet = await getSdk().agent.lightningWallet.revoke();
|
|
106
|
-
} catch (err) {
|
|
107
|
-
const code = err?.body?.code ?? err?.code;
|
|
108
|
-
if (code !== "LIGHTNING_WALLET_NOT_FOUND") throw err;
|
|
109
|
-
}
|
|
110
|
-
if (localWallet) {
|
|
111
|
-
const { lightning: _dropped, ...rest } = localWallet;
|
|
112
|
-
saveWallet({ ...rest, rail: rest.rail === "lightning" ? "x402" : rest.rail });
|
|
113
|
-
}
|
|
114
|
-
return wallet;
|
|
115
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Delegate-credential helpers.
|
|
3
|
-
*
|
|
4
|
-
* A delegate is a scoped, revocable, expiring bearer an OWNER mints for an
|
|
5
|
-
* agent (gateway `cryptographic-delegates`, v1.79). It authenticates the same
|
|
6
|
-
* routes a CI session does — including the apikey-gated `/content/v1/*` CAS
|
|
7
|
-
* routes — so from the client's perspective it behaves exactly like the CI
|
|
8
|
-
* session path: the bearer rides `Authorization`, and helpers that would
|
|
9
|
-
* otherwise attach a project `apikey` must stand down so the two credential
|
|
10
|
-
* families never mix on one request.
|
|
11
|
-
*
|
|
12
|
-
* Why this exists at all: project API keys are stateless JWTs issued once at
|
|
13
|
-
* project-create and never re-issued. An agent that loses local state (fresh
|
|
14
|
-
* container, new sandbox) therefore has no cached apikey and no way to deploy
|
|
15
|
-
* to a project it owns. The owner still holds the wallet, so they can mint a
|
|
16
|
-
* delegate with SIWX and hand it to the agent.
|
|
17
|
-
*/
|
|
18
|
-
import type { CredentialsProvider } from "./credentials.js";
|
|
19
|
-
export declare const DELEGATE_CREDENTIALS: unique symbol;
|
|
20
|
-
export interface DelegateMarkedCredentialsProvider extends CredentialsProvider {
|
|
21
|
-
readonly [DELEGATE_CREDENTIALS]: true;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* True when this provider is presenting a delegate bearer for the current
|
|
25
|
-
* request family. Consumers use it the same way they use
|
|
26
|
-
* `isCiSessionCredentials` — to suppress apikey attachment.
|
|
27
|
-
*/
|
|
28
|
-
export declare function isDelegateCredentials(credentials: CredentialsProvider): boolean;
|
|
29
|
-
/** Environment variable carrying a delegate bearer for non-interactive runs. */
|
|
30
|
-
export declare const DELEGATE_TOKEN_ENV = "RUN402_DELEGATE_TOKEN";
|
|
31
|
-
/**
|
|
32
|
-
* Read a delegate bearer from the environment. Whitespace-trimmed; an empty or
|
|
33
|
-
* whitespace-only value is treated as absent so `RUN402_DELEGATE_TOKEN=` in a
|
|
34
|
-
* shell profile does not silently disable every other credential class.
|
|
35
|
-
*/
|
|
36
|
-
export declare function delegateTokenFromEnv(env?: NodeJS.ProcessEnv): string | undefined;
|
|
37
|
-
//# sourceMappingURL=delegate-credentials.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-credentials.d.ts","sourceRoot":"","sources":["../src/delegate-credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,eAAiD,CAAC;AAEnF,MAAM,WAAW,iCAAkC,SAAQ,mBAAmB;IAC5E,QAAQ,CAAC,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,mBAAmB,GAAG,OAAO,CAE/E;AAED,gFAAgF;AAChF,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,GAAG,SAAS,CAKpB"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Delegate-credential helpers.
|
|
3
|
-
*
|
|
4
|
-
* A delegate is a scoped, revocable, expiring bearer an OWNER mints for an
|
|
5
|
-
* agent (gateway `cryptographic-delegates`, v1.79). It authenticates the same
|
|
6
|
-
* routes a CI session does — including the apikey-gated `/content/v1/*` CAS
|
|
7
|
-
* routes — so from the client's perspective it behaves exactly like the CI
|
|
8
|
-
* session path: the bearer rides `Authorization`, and helpers that would
|
|
9
|
-
* otherwise attach a project `apikey` must stand down so the two credential
|
|
10
|
-
* families never mix on one request.
|
|
11
|
-
*
|
|
12
|
-
* Why this exists at all: project API keys are stateless JWTs issued once at
|
|
13
|
-
* project-create and never re-issued. An agent that loses local state (fresh
|
|
14
|
-
* container, new sandbox) therefore has no cached apikey and no way to deploy
|
|
15
|
-
* to a project it owns. The owner still holds the wallet, so they can mint a
|
|
16
|
-
* delegate with SIWX and hand it to the agent.
|
|
17
|
-
*/
|
|
18
|
-
export const DELEGATE_CREDENTIALS = Symbol.for("@run402/sdk/delegate-credentials");
|
|
19
|
-
/**
|
|
20
|
-
* True when this provider is presenting a delegate bearer for the current
|
|
21
|
-
* request family. Consumers use it the same way they use
|
|
22
|
-
* `isCiSessionCredentials` — to suppress apikey attachment.
|
|
23
|
-
*/
|
|
24
|
-
export function isDelegateCredentials(credentials) {
|
|
25
|
-
return Boolean(credentials[DELEGATE_CREDENTIALS]);
|
|
26
|
-
}
|
|
27
|
-
/** Environment variable carrying a delegate bearer for non-interactive runs. */
|
|
28
|
-
export const DELEGATE_TOKEN_ENV = "RUN402_DELEGATE_TOKEN";
|
|
29
|
-
/**
|
|
30
|
-
* Read a delegate bearer from the environment. Whitespace-trimmed; an empty or
|
|
31
|
-
* whitespace-only value is treated as absent so `RUN402_DELEGATE_TOKEN=` in a
|
|
32
|
-
* shell profile does not silently disable every other credential class.
|
|
33
|
-
*/
|
|
34
|
-
export function delegateTokenFromEnv(env = process.env) {
|
|
35
|
-
const raw = env[DELEGATE_TOKEN_ENV];
|
|
36
|
-
if (typeof raw !== "string")
|
|
37
|
-
return undefined;
|
|
38
|
-
const trimmed = raw.trim();
|
|
39
|
-
return trimmed.length > 0 ? trimmed : undefined;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=delegate-credentials.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegate-credentials.js","sourceRoot":"","sources":["../src/delegate-credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAMnF;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,WAAgC;IACpE,OAAO,OAAO,CAAE,WAA0D,CAAC,oBAAoB,CAAC,CAAC,CAAC;AACpG,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAyB,OAAO,CAAC,GAAG;IAEpC,MAAM,GAAG,GAAG,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACpC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC9C,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AAClD,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `delegates` namespace — scoped, revocable, expiring credentials an OWNER
|
|
3
|
-
* mints for an agent (gateway `cryptographic-delegates`, v1.79). Maps to
|
|
4
|
-
* `/projects/v1/:project_id/delegates`. Every mutation requires the caller to
|
|
5
|
-
* be an active owner of the project's owning org.
|
|
6
|
-
*
|
|
7
|
-
* A delegate always NARROWS an existing `project_grant` — mint the grant first
|
|
8
|
-
* (`r.grants.create(...)`), then hang a delegate off its `grant_id`. A delegate
|
|
9
|
-
* can never be an owner; that is enforced structurally by the gateway.
|
|
10
|
-
*
|
|
11
|
-
* The practical reason this exists on the client: project API keys are
|
|
12
|
-
* stateless JWTs handed out once at create and never re-issued, so an agent
|
|
13
|
-
* that loses local state has no way back into its own project. A delegate is
|
|
14
|
-
* the supported recovery path — the owner still holds a wallet, and SIWX is
|
|
15
|
-
* enough to mint a fresh deploy credential.
|
|
16
|
-
*
|
|
17
|
-
* Exposed both unscoped (`r.delegates.create(projectId, …)`) and
|
|
18
|
-
* project-scoped (`r.project(id).delegates.create(…)`), mirroring `r.grants`.
|
|
19
|
-
*/
|
|
20
|
-
import type { Client } from "../kernel.js";
|
|
21
|
-
import type { CreateDelegateInput, DelegateCreateResult, DelegateListResult, DelegateRevokeResult } from "./delegates.types.js";
|
|
22
|
-
export declare class Delegates {
|
|
23
|
-
private readonly client;
|
|
24
|
-
constructor(client: Client);
|
|
25
|
-
/**
|
|
26
|
-
* Issue a delegate against an existing grant
|
|
27
|
-
* (`POST /projects/v1/:project_id/delegates`). Requires owner of the project's org.
|
|
28
|
-
*
|
|
29
|
-
* The returned `token` is shown **once**. Persist it immediately; there is no
|
|
30
|
-
* way to read it back, only to rotate for a new one.
|
|
31
|
-
*/
|
|
32
|
-
create(projectId: string, input: CreateDelegateInput): Promise<DelegateCreateResult>;
|
|
33
|
-
/**
|
|
34
|
-
* List a project's delegates (`GET /projects/v1/:project_id/delegates`).
|
|
35
|
-
* Never returns a token or any secret material — names, scope and caps only.
|
|
36
|
-
*/
|
|
37
|
-
list(projectId: string): Promise<DelegateListResult>;
|
|
38
|
-
/**
|
|
39
|
-
* Revoke a delegate (`DELETE /projects/v1/:project_id/delegates/:delegate_id`).
|
|
40
|
-
* Effective immediately for subsequent requests.
|
|
41
|
-
*/
|
|
42
|
-
revoke(projectId: string, delegateId: string): Promise<DelegateRevokeResult>;
|
|
43
|
-
/**
|
|
44
|
-
* Rotate a delegate (`POST /projects/v1/:project_id/delegates/:delegate_id/rotate`)
|
|
45
|
-
* — revokes the old credential and reissues the same principal/grant/scope/cap.
|
|
46
|
-
* The new `token` is again shown once.
|
|
47
|
-
*/
|
|
48
|
-
rotate(projectId: string, delegateId: string): Promise<DelegateCreateResult>;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=delegates.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegates.d.ts","sourceRoot":"","sources":["../../src/namespaces/delegates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EAErB,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,SAAS;IACR,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE3C;;;;;;OAMG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgC1F;;;OAGG;IACG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAU1D;;;OAGG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAalF;;;;OAIG;IACG,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAYnF"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `delegates` namespace — scoped, revocable, expiring credentials an OWNER
|
|
3
|
-
* mints for an agent (gateway `cryptographic-delegates`, v1.79). Maps to
|
|
4
|
-
* `/projects/v1/:project_id/delegates`. Every mutation requires the caller to
|
|
5
|
-
* be an active owner of the project's owning org.
|
|
6
|
-
*
|
|
7
|
-
* A delegate always NARROWS an existing `project_grant` — mint the grant first
|
|
8
|
-
* (`r.grants.create(...)`), then hang a delegate off its `grant_id`. A delegate
|
|
9
|
-
* can never be an owner; that is enforced structurally by the gateway.
|
|
10
|
-
*
|
|
11
|
-
* The practical reason this exists on the client: project API keys are
|
|
12
|
-
* stateless JWTs handed out once at create and never re-issued, so an agent
|
|
13
|
-
* that loses local state has no way back into its own project. A delegate is
|
|
14
|
-
* the supported recovery path — the owner still holds a wallet, and SIWX is
|
|
15
|
-
* enough to mint a fresh deploy credential.
|
|
16
|
-
*
|
|
17
|
-
* Exposed both unscoped (`r.delegates.create(projectId, …)`) and
|
|
18
|
-
* project-scoped (`r.project(id).delegates.create(…)`), mirroring `r.grants`.
|
|
19
|
-
*/
|
|
20
|
-
import { LocalError } from "../errors.js";
|
|
21
|
-
export class Delegates {
|
|
22
|
-
client;
|
|
23
|
-
constructor(client) {
|
|
24
|
-
this.client = client;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Issue a delegate against an existing grant
|
|
28
|
-
* (`POST /projects/v1/:project_id/delegates`). Requires owner of the project's org.
|
|
29
|
-
*
|
|
30
|
-
* The returned `token` is shown **once**. Persist it immediately; there is no
|
|
31
|
-
* way to read it back, only to rotate for a new one.
|
|
32
|
-
*/
|
|
33
|
-
async create(projectId, input) {
|
|
34
|
-
if (!projectId) {
|
|
35
|
-
throw new LocalError("delegates.create requires a projectId", "issuing project delegate");
|
|
36
|
-
}
|
|
37
|
-
if (!input?.grantId) {
|
|
38
|
-
throw new LocalError("delegates.create requires { grantId } — mint a grant first with grants.create()", "issuing project delegate");
|
|
39
|
-
}
|
|
40
|
-
// The gateway REQUIRES a scope object and 400s without one. Default to the
|
|
41
|
-
// common case (this grant's capability on this project) so the caller does
|
|
42
|
-
// not have to know the wire schema to do the obvious thing.
|
|
43
|
-
const scope = input.scope ?? {
|
|
44
|
-
v: 1,
|
|
45
|
-
capabilities: ["deploy"],
|
|
46
|
-
projects: [projectId],
|
|
47
|
-
};
|
|
48
|
-
const body = {
|
|
49
|
-
grant_id: input.grantId,
|
|
50
|
-
kind: input.kind ?? "run402_agent_key",
|
|
51
|
-
scope,
|
|
52
|
-
};
|
|
53
|
-
if (input.spendCap !== undefined)
|
|
54
|
-
body.spend_cap = input.spendCap;
|
|
55
|
-
if (input.expiresAt !== undefined)
|
|
56
|
-
body.expires_at = input.expiresAt;
|
|
57
|
-
if (input.publicSubject !== undefined)
|
|
58
|
-
body.public_subject = input.publicSubject;
|
|
59
|
-
return this.client.request(`/projects/v1/${encodeURIComponent(projectId)}/delegates`, { method: "POST", body, context: "issuing project delegate" });
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* List a project's delegates (`GET /projects/v1/:project_id/delegates`).
|
|
63
|
-
* Never returns a token or any secret material — names, scope and caps only.
|
|
64
|
-
*/
|
|
65
|
-
async list(projectId) {
|
|
66
|
-
if (!projectId) {
|
|
67
|
-
throw new LocalError("delegates.list requires a projectId", "listing project delegates");
|
|
68
|
-
}
|
|
69
|
-
return this.client.request(`/projects/v1/${encodeURIComponent(projectId)}/delegates`, { method: "GET", context: "listing project delegates" });
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Revoke a delegate (`DELETE /projects/v1/:project_id/delegates/:delegate_id`).
|
|
73
|
-
* Effective immediately for subsequent requests.
|
|
74
|
-
*/
|
|
75
|
-
async revoke(projectId, delegateId) {
|
|
76
|
-
if (!projectId) {
|
|
77
|
-
throw new LocalError("delegates.revoke requires a projectId", "revoking project delegate");
|
|
78
|
-
}
|
|
79
|
-
if (!delegateId) {
|
|
80
|
-
throw new LocalError("delegates.revoke requires a delegateId", "revoking project delegate");
|
|
81
|
-
}
|
|
82
|
-
return this.client.request(`/projects/v1/${encodeURIComponent(projectId)}/delegates/${encodeURIComponent(delegateId)}`, { method: "DELETE", context: "revoking project delegate" });
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Rotate a delegate (`POST /projects/v1/:project_id/delegates/:delegate_id/rotate`)
|
|
86
|
-
* — revokes the old credential and reissues the same principal/grant/scope/cap.
|
|
87
|
-
* The new `token` is again shown once.
|
|
88
|
-
*/
|
|
89
|
-
async rotate(projectId, delegateId) {
|
|
90
|
-
if (!projectId) {
|
|
91
|
-
throw new LocalError("delegates.rotate requires a projectId", "rotating project delegate");
|
|
92
|
-
}
|
|
93
|
-
if (!delegateId) {
|
|
94
|
-
throw new LocalError("delegates.rotate requires a delegateId", "rotating project delegate");
|
|
95
|
-
}
|
|
96
|
-
return this.client.request(`/projects/v1/${encodeURIComponent(projectId)}/delegates/${encodeURIComponent(delegateId)}/rotate`, { method: "POST", context: "rotating project delegate" });
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=delegates.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegates.js","sourceRoot":"","sources":["../../src/namespaces/delegates.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request/response types for the `delegates` namespace — scoped, revocable,
|
|
3
|
-
* expiring credentials an OWNER mints for an agent (gateway
|
|
4
|
-
* `cryptographic-delegates`). Maps to `/projects/v1/:project_id/delegates`.
|
|
5
|
-
*
|
|
6
|
-
* A delegate always NARROWS an existing `project_grant`; it is never broader
|
|
7
|
-
* than the grant it hangs off, and it can never be an owner.
|
|
8
|
-
*/
|
|
9
|
-
/** Delegate kinds the gateway accepts. Only `run402_agent_key` returns a bearer. */
|
|
10
|
-
export type DelegateKind = "run402_agent_key" | "ci_oidc" | "tempo_access_key" | "base_disposable_eoa" | "erc7710";
|
|
11
|
-
/**
|
|
12
|
-
* Delegate scope (`scope` JSONB, compiled server-side to `DelegateScopeV1`).
|
|
13
|
-
* REQUIRED by the gateway — omitting it returns `400 INVALID_DELEGATE_SCOPE`.
|
|
14
|
-
*/
|
|
15
|
-
export interface DelegateScope {
|
|
16
|
-
/** Schema version. Must be `1`. */
|
|
17
|
-
v: 1;
|
|
18
|
-
/** Non-empty capability list, e.g. `["deploy"]`. */
|
|
19
|
-
capabilities: string[];
|
|
20
|
-
/** Optional project allowlist. Defaults to the issuing project. */
|
|
21
|
-
projects?: string[];
|
|
22
|
-
[key: string]: unknown;
|
|
23
|
-
}
|
|
24
|
-
/** Spend cap (`spend_cap` JSONB). Enforced at SEND time, not control-plane authz. */
|
|
25
|
-
export interface DelegateSpendCap {
|
|
26
|
-
v: 1;
|
|
27
|
-
currency: "usd_micros";
|
|
28
|
-
per_tx?: number;
|
|
29
|
-
per_period?: number;
|
|
30
|
-
[key: string]: unknown;
|
|
31
|
-
}
|
|
32
|
-
/** Input to {@link Delegates.create}. */
|
|
33
|
-
export interface CreateDelegateInput {
|
|
34
|
-
/** The `project_grant` this delegate narrows. Required by the gateway. */
|
|
35
|
-
grantId: string;
|
|
36
|
-
/** Delegate kind. Defaults to `"run402_agent_key"` (the bearer-returning kind). */
|
|
37
|
-
kind?: DelegateKind;
|
|
38
|
-
/**
|
|
39
|
-
* Scope. If omitted the SDK sends `{ v:1, capabilities:["deploy"], projects:[projectId] }`
|
|
40
|
-
* so the common "let this agent deploy this one project" case is one call.
|
|
41
|
-
*/
|
|
42
|
-
scope?: DelegateScope;
|
|
43
|
-
/** Optional spend cap (payment rails only). */
|
|
44
|
-
spendCap?: DelegateSpendCap;
|
|
45
|
-
/** Optional ISO-8601 expiry. Omit for a non-expiring delegate. */
|
|
46
|
-
expiresAt?: string | null;
|
|
47
|
-
/** Optional rail-specific public subject. */
|
|
48
|
-
publicSubject?: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Result of {@link Delegates.create} / {@link Delegates.rotate}.
|
|
52
|
-
*
|
|
53
|
-
* `token` is returned **once** and never again — persist it immediately
|
|
54
|
-
* (Secrets Manager, CI secret) or you must rotate to get a new one.
|
|
55
|
-
*/
|
|
56
|
-
export interface DelegateCreateResult {
|
|
57
|
-
status: string;
|
|
58
|
-
delegate_id: string;
|
|
59
|
-
/** The bearer. Present for `run402_agent_key`. Shown once. */
|
|
60
|
-
token?: string;
|
|
61
|
-
expires_at: string | null;
|
|
62
|
-
[key: string]: unknown;
|
|
63
|
-
}
|
|
64
|
-
/** A delegate as returned by {@link Delegates.list} — never includes a token. */
|
|
65
|
-
export interface DelegateSummary {
|
|
66
|
-
id: string;
|
|
67
|
-
project_id: string;
|
|
68
|
-
principal_id: string;
|
|
69
|
-
kind: DelegateKind;
|
|
70
|
-
scope: Record<string, unknown>;
|
|
71
|
-
spend_cap: Record<string, unknown> | null;
|
|
72
|
-
expires_at: string | null;
|
|
73
|
-
revoked_at: string | null;
|
|
74
|
-
created_at: string;
|
|
75
|
-
[key: string]: unknown;
|
|
76
|
-
}
|
|
77
|
-
/** Result of {@link Delegates.list}. */
|
|
78
|
-
export interface DelegateListResult {
|
|
79
|
-
delegates: DelegateSummary[];
|
|
80
|
-
[key: string]: unknown;
|
|
81
|
-
}
|
|
82
|
-
/** Result of {@link Delegates.revoke}. */
|
|
83
|
-
export interface DelegateRevokeResult {
|
|
84
|
-
status: string;
|
|
85
|
-
delegate_id: string;
|
|
86
|
-
[key: string]: unknown;
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=delegates.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegates.types.d.ts","sourceRoot":"","sources":["../../src/namespaces/delegates.types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oFAAoF;AACpF,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,SAAS,GACT,kBAAkB,GAClB,qBAAqB,GACrB,SAAS,CAAC;AAEd;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,mCAAmC;IACnC,CAAC,EAAE,CAAC,CAAC;IACL,oDAAoD;IACpD,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,qFAAqF;AACrF,MAAM,WAAW,gBAAgB;IAC/B,CAAC,EAAE,CAAC,CAAC;IACL,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,yCAAyC;AACzC,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,6CAA6C;IAC7C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,iFAAiF;AACjF,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1C,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,wCAAwC;AACxC,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,0CAA0C;AAC1C,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request/response types for the `delegates` namespace — scoped, revocable,
|
|
3
|
-
* expiring credentials an OWNER mints for an agent (gateway
|
|
4
|
-
* `cryptographic-delegates`). Maps to `/projects/v1/:project_id/delegates`.
|
|
5
|
-
*
|
|
6
|
-
* A delegate always NARROWS an existing `project_grant`; it is never broader
|
|
7
|
-
* than the grant it hangs off, and it can never be an owner.
|
|
8
|
-
*/
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=delegates.types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegates.types.js","sourceRoot":"","sources":["../../src/namespaces/delegates.types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|