run402 4.93.2 → 4.95.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 +61 -59
- package/cli.mjs +40 -47
- package/core-dist/config.js +52 -18
- package/core-dist/control-plane-session.js +31 -6
- package/core-dist/keystore.js +7 -7
- package/core-dist/profiles.js +9 -7
- package/core-dist/{allowance-auth.js → wallet-auth.js} +15 -15
- package/{sdk/core-dist/allowance.js → core-dist/wallet.js} +20 -20
- package/{sdk/core-dist/write-auth-session.js → core-dist/write-approvals.js} +19 -19
- package/gitvault-surface.json +2 -2
- package/lib/admin.mjs +6 -6
- package/lib/agent.mjs +20 -18
- package/lib/ai.mjs +5 -5
- package/lib/approve.mjs +81 -0
- package/lib/apps.mjs +12 -12
- package/lib/archives.mjs +371 -8
- package/lib/argparse.mjs +5 -5
- package/lib/assets.mjs +14 -14
- package/lib/auth.mjs +34 -34
- package/lib/billing.mjs +6 -6
- package/lib/branches.mjs +7 -7
- package/lib/buzz-doctor.mjs +2 -2
- package/lib/buzz-notifications.mjs +5 -5
- package/lib/buzz.mjs +3 -3
- package/lib/buzz.test.mjs +1 -1
- package/lib/cache.mjs +1 -1
- package/lib/cdn.mjs +2 -2
- package/lib/ci.mjs +12 -12
- package/lib/claims.mjs +2 -2
- package/lib/cold-start.mjs +21 -21
- package/lib/command-manifest.mjs +55 -70
- package/lib/config.mjs +28 -28
- package/lib/contacts.mjs +16 -16
- package/lib/contracts.mjs +12 -12
- package/lib/credentials.mjs +33 -33
- package/lib/daemon-path.mjs +1 -1
- package/lib/delegates.mjs +14 -14
- package/lib/deliveries.mjs +6 -6
- package/lib/deploy-rehearse-discovery.test.mjs +7 -7
- package/lib/deploy-v2.mjs +241 -193
- package/lib/deploy.mjs +21 -53
- package/lib/dev.mjs +3 -3
- package/lib/doctor-source-scan.mjs +1 -1
- package/lib/doctor.mjs +63 -63
- package/lib/domains.mjs +27 -27
- package/lib/email.mjs +38 -38
- package/lib/errors.mjs +40 -24
- package/lib/escalations.mjs +5 -5
- package/lib/events.mjs +32 -25
- package/lib/feedback.mjs +12 -12
- package/lib/functions.mjs +34 -34
- package/lib/gitvault-daemon.mjs +1 -1
- package/lib/gitvault-scaffold.mjs +2 -2
- package/lib/gitvault.mjs +2 -2
- package/lib/grants.mjs +7 -7
- package/lib/image.mjs +10 -10
- package/lib/init.mjs +69 -69
- package/lib/jobs.mjs +15 -15
- package/lib/lightning-wallet.mjs +28 -28
- package/lib/live.mjs +1 -1
- package/lib/login.mjs +207 -0
- package/lib/logout.mjs +53 -0
- package/lib/logs.mjs +8 -8
- package/lib/messages.mjs +5 -5
- package/lib/next-actions.mjs +16 -16
- package/lib/org-context.mjs +13 -13
- package/lib/{org.mjs → orgs.mjs} +215 -167
- package/lib/pay.mjs +1 -1
- package/lib/projects.mjs +70 -84
- package/lib/redeem.mjs +7 -8
- package/lib/remote-helper-session.mjs +12 -12
- package/lib/repos.mjs +83 -83
- package/lib/rooms.mjs +105 -69
- package/lib/sdk-errors.mjs +10 -5
- package/lib/sdk.mjs +3 -3
- package/lib/secrets.mjs +13 -13
- package/lib/service.mjs +5 -5
- package/lib/session-proofs.mjs +21 -0
- package/lib/sign-in.mjs +296 -0
- package/lib/sites.mjs +22 -22
- package/lib/snapshots.mjs +10 -10
- package/lib/stats.mjs +2 -2
- package/lib/status.mjs +25 -25
- package/lib/subdomains.mjs +30 -30
- package/lib/subscriptions.mjs +10 -10
- package/lib/tier.mjs +29 -22
- package/lib/transfer.mjs +59 -86
- package/lib/up.mjs +14 -14
- package/lib/wallet-context.mjs +4 -4
- package/lib/wallet-context.test.mjs +3 -3
- package/lib/wallets.mjs +197 -32
- package/lib/webhook-secret.mjs +6 -6
- package/lib/webhooks.mjs +8 -8
- package/lib/whoami.mjs +102 -0
- package/package.json +1 -1
- package/sdk/core-dist/config.js +52 -18
- package/sdk/core-dist/control-plane-session.js +31 -6
- package/sdk/core-dist/keystore.js +7 -7
- package/sdk/core-dist/profiles.js +9 -7
- package/sdk/core-dist/{allowance-auth.js → wallet-auth.js} +15 -15
- package/{core-dist/allowance.js → sdk/core-dist/wallet.js} +20 -20
- package/{core-dist/write-auth-session.js → sdk/core-dist/write-approvals.js} +19 -19
- package/sdk/dist/actions.d.ts +4 -4
- package/sdk/dist/actions.d.ts.map +1 -1
- package/sdk/dist/app-up.d.ts +2 -2
- package/sdk/dist/app-up.d.ts.map +1 -1
- package/sdk/dist/config.d.ts +1 -2
- package/sdk/dist/config.d.ts.map +1 -1
- package/sdk/dist/config.js.map +1 -1
- package/sdk/dist/control-plane-credentials.d.ts +8 -8
- package/sdk/dist/control-plane-credentials.js +7 -7
- package/sdk/dist/credentials.d.ts +20 -20
- package/sdk/dist/credentials.d.ts.map +1 -1
- package/sdk/dist/credentials.js +1 -1
- package/sdk/dist/errors.d.ts +26 -28
- package/sdk/dist/errors.d.ts.map +1 -1
- package/sdk/dist/errors.js +35 -38
- package/sdk/dist/errors.js.map +1 -1
- package/sdk/dist/index.d.ts +29 -16
- package/sdk/dist/index.d.ts.map +1 -1
- package/sdk/dist/index.js +30 -17
- package/sdk/dist/index.js.map +1 -1
- package/sdk/dist/kernel.d.ts +1 -1
- package/sdk/dist/kernel.d.ts.map +1 -1
- package/sdk/dist/kernel.js +10 -9
- package/sdk/dist/kernel.js.map +1 -1
- package/sdk/dist/namespaces/admin.d.ts +52 -121
- package/sdk/dist/namespaces/admin.d.ts.map +1 -1
- package/sdk/dist/namespaces/admin.js +41 -45
- 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 +2 -2
- package/sdk/dist/namespaces/agent.js.map +1 -1
- package/sdk/dist/namespaces/ai.d.ts +2 -2
- package/sdk/dist/namespaces/ai.js +3 -3
- package/sdk/dist/namespaces/ai.js.map +1 -1
- package/sdk/dist/namespaces/assets.js +1 -1
- package/sdk/dist/namespaces/assets.js.map +1 -1
- package/sdk/dist/namespaces/billing.d.ts +6 -3
- package/sdk/dist/namespaces/billing.d.ts.map +1 -1
- package/sdk/dist/namespaces/billing.js.map +1 -1
- package/sdk/dist/namespaces/buzz-notifications.types.d.ts +1 -1
- package/sdk/dist/namespaces/buzz.d.ts +2 -2
- package/sdk/dist/namespaces/buzz.d.ts.map +1 -1
- package/sdk/dist/namespaces/buzz.js +2 -2
- package/sdk/dist/namespaces/buzz.js.map +1 -1
- package/sdk/dist/namespaces/buzz.types.d.ts +2 -2
- package/sdk/dist/namespaces/buzz.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/ci.js +3 -3
- package/sdk/dist/namespaces/ci.js.map +1 -1
- package/sdk/dist/namespaces/credentials.types.d.ts +1 -1
- package/sdk/dist/namespaces/deploy.d.ts +1 -1
- package/sdk/dist/namespaces/deploy.d.ts.map +1 -1
- package/sdk/dist/namespaces/deploy.js +31 -32
- package/sdk/dist/namespaces/deploy.js.map +1 -1
- package/sdk/dist/namespaces/deploy.types.d.ts +6 -6
- package/sdk/dist/namespaces/deploy.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/domains.d.ts +10 -2
- package/sdk/dist/namespaces/domains.d.ts.map +1 -1
- package/sdk/dist/namespaces/domains.js +10 -5
- package/sdk/dist/namespaces/domains.js.map +1 -1
- package/sdk/dist/namespaces/errors.js +1 -1
- package/sdk/dist/namespaces/escalations.d.ts +1 -1
- package/sdk/dist/namespaces/escalations.js +1 -1
- package/sdk/dist/namespaces/escalations.types.d.ts +2 -2
- package/sdk/dist/namespaces/escalations.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/events.types.d.ts +1 -1
- package/sdk/dist/namespaces/functions.d.ts +1 -1
- package/sdk/dist/namespaces/functions.js +2 -2
- package/sdk/dist/namespaces/functions.js.map +1 -1
- package/sdk/dist/namespaces/gitvault.crypto.d.ts +1 -1
- package/sdk/dist/namespaces/gitvault.d.ts +26 -26
- package/sdk/dist/namespaces/gitvault.d.ts.map +1 -1
- package/sdk/dist/namespaces/gitvault.js +113 -113
- package/sdk/dist/namespaces/gitvault.js.map +1 -1
- package/sdk/dist/namespaces/me.d.ts +120 -0
- package/sdk/dist/namespaces/me.d.ts.map +1 -0
- package/sdk/dist/namespaces/me.js +34 -0
- package/sdk/dist/namespaces/me.js.map +1 -0
- package/sdk/dist/namespaces/org.d.ts +108 -6
- package/sdk/dist/namespaces/org.d.ts.map +1 -1
- package/sdk/dist/namespaces/org.js +63 -7
- package/sdk/dist/namespaces/org.js.map +1 -1
- package/sdk/dist/namespaces/org.types.d.ts +29 -9
- package/sdk/dist/namespaces/org.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/pay.js +3 -3
- package/sdk/dist/namespaces/pay.js.map +1 -1
- package/sdk/dist/namespaces/projects.d.ts +9 -9
- package/sdk/dist/namespaces/projects.js +15 -15
- package/sdk/dist/namespaces/projects.js.map +1 -1
- package/sdk/dist/namespaces/projects.types.d.ts +28 -12
- package/sdk/dist/namespaces/projects.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/rooms.d.ts +7 -7
- package/sdk/dist/namespaces/rooms.js +17 -17
- package/sdk/dist/namespaces/rooms.js.map +1 -1
- package/sdk/dist/namespaces/rooms.types.d.ts +9 -9
- package/sdk/dist/namespaces/rooms.types.d.ts.map +1 -1
- package/sdk/dist/namespaces/service.d.ts +1 -1
- package/sdk/dist/namespaces/service.js +1 -1
- package/sdk/dist/namespaces/{operator-session.d.ts → session.d.ts} +135 -51
- package/sdk/dist/namespaces/session.d.ts.map +1 -0
- package/sdk/dist/namespaces/{operator-session.js → session.js} +118 -30
- package/sdk/dist/namespaces/session.js.map +1 -0
- package/sdk/dist/namespaces/subdomains.d.ts +5 -5
- package/sdk/dist/namespaces/subdomains.d.ts.map +1 -1
- package/sdk/dist/namespaces/subdomains.js +6 -6
- package/sdk/dist/namespaces/subdomains.js.map +1 -1
- package/sdk/dist/namespaces/tier.d.ts +44 -21
- package/sdk/dist/namespaces/tier.d.ts.map +1 -1
- package/sdk/dist/namespaces/tier.js +7 -7
- package/sdk/dist/namespaces/tier.js.map +1 -1
- package/sdk/dist/namespaces/transfers.d.ts +119 -85
- package/sdk/dist/namespaces/transfers.d.ts.map +1 -1
- package/sdk/dist/namespaces/transfers.js +31 -38
- package/sdk/dist/namespaces/transfers.js.map +1 -1
- package/sdk/dist/namespaces/vouchers.d.ts +9 -10
- package/sdk/dist/namespaces/vouchers.d.ts.map +1 -1
- package/sdk/dist/namespaces/vouchers.js +4 -5
- package/sdk/dist/namespaces/vouchers.js.map +1 -1
- package/sdk/dist/namespaces/wallets.d.ts +72 -3
- package/sdk/dist/namespaces/wallets.d.ts.map +1 -1
- package/sdk/dist/namespaces/wallets.js +141 -3
- package/sdk/dist/namespaces/wallets.js.map +1 -1
- package/sdk/dist/namespaces/write-approval.d.ts +101 -0
- package/sdk/dist/namespaces/write-approval.d.ts.map +1 -0
- package/sdk/dist/namespaces/write-approval.js +62 -0
- package/sdk/dist/namespaces/write-approval.js.map +1 -0
- package/sdk/dist/node/actions-node.d.ts +3 -3
- package/sdk/dist/node/actions-node.d.ts.map +1 -1
- package/sdk/dist/node/actions-node.js +44 -44
- package/sdk/dist/node/actions-node.js.map +1 -1
- package/sdk/dist/node/assets-node.js +6 -6
- package/sdk/dist/node/assets-node.js.map +1 -1
- package/sdk/dist/node/{bearer-claim-key.d.ts → bearer-redeem-key.d.ts} +12 -12
- package/sdk/dist/node/bearer-redeem-key.d.ts.map +1 -0
- package/sdk/dist/node/{bearer-claim-key.js → bearer-redeem-key.js} +21 -21
- package/sdk/dist/node/bearer-redeem-key.js.map +1 -0
- package/sdk/dist/node/ci.d.ts +1 -1
- package/sdk/dist/node/ci.d.ts.map +1 -1
- package/sdk/dist/node/ci.js +6 -6
- package/sdk/dist/node/ci.js.map +1 -1
- package/sdk/dist/node/credentials.d.ts +18 -17
- package/sdk/dist/node/credentials.d.ts.map +1 -1
- package/sdk/dist/node/credentials.js +29 -28
- package/sdk/dist/node/credentials.js.map +1 -1
- package/sdk/dist/node/deploy-manifest.d.ts +3 -5
- package/sdk/dist/node/deploy-manifest.d.ts.map +1 -1
- package/sdk/dist/node/deploy-manifest.js +3 -12
- package/sdk/dist/node/deploy-manifest.js.map +1 -1
- package/sdk/dist/node/funding-recovery.d.ts +1 -1
- package/sdk/dist/node/funding-recovery.d.ts.map +1 -1
- package/sdk/dist/node/funding-recovery.js +1 -1
- package/sdk/dist/node/funding-recovery.js.map +1 -1
- package/sdk/dist/node/gitvault-apply.d.ts +1 -1
- package/sdk/dist/node/gitvault-apply.d.ts.map +1 -1
- package/sdk/dist/node/gitvault-apply.js +1 -1
- package/sdk/dist/node/gitvault-apply.js.map +1 -1
- package/sdk/dist/node/gitvault-handoff.d.ts +22 -22
- package/sdk/dist/node/gitvault-handoff.d.ts.map +1 -1
- package/sdk/dist/node/gitvault-handoff.js +45 -45
- package/sdk/dist/node/gitvault-handoff.js.map +1 -1
- package/sdk/dist/node/gitvault-prewarm.js +7 -7
- package/sdk/dist/node/gitvault-prewarm.js.map +1 -1
- package/sdk/dist/node/gitvault-restore.d.ts +1 -1
- package/sdk/dist/node/gitvault-restore.js +1 -1
- package/sdk/dist/node/index.d.ts +16 -16
- package/sdk/dist/node/index.d.ts.map +1 -1
- package/sdk/dist/node/index.js +15 -15
- package/sdk/dist/node/index.js.map +1 -1
- package/sdk/dist/node/manifest-export.js +2 -2
- package/sdk/dist/node/manifest-export.js.map +1 -1
- package/sdk/dist/node/org-adopt.d.ts +49 -0
- package/sdk/dist/node/org-adopt.d.ts.map +1 -0
- package/sdk/dist/node/org-adopt.js +77 -0
- package/sdk/dist/node/org-adopt.js.map +1 -0
- package/sdk/dist/node/paid-fetch.d.ts +7 -7
- package/sdk/dist/node/paid-fetch.d.ts.map +1 -1
- package/sdk/dist/node/paid-fetch.js +54 -54
- package/sdk/dist/node/paid-fetch.js.map +1 -1
- package/sdk/dist/node/preflight.d.ts +1 -1
- package/sdk/dist/node/preflight.d.ts.map +1 -1
- package/sdk/dist/node/preflight.js +1 -1
- package/sdk/dist/node/preflight.js.map +1 -1
- package/sdk/dist/node/sites-node.js +1 -1
- package/sdk/dist/node/sites-node.js.map +1 -1
- package/sdk/dist/node/source-scan.d.ts +1 -1
- package/sdk/dist/node/source-scan.js +2 -2
- package/sdk/dist/node/source-scan.js.map +1 -1
- package/sdk/dist/scoped.d.ts +11 -11
- package/sdk/dist/scoped.d.ts.map +1 -1
- package/sdk/dist/scoped.js +5 -5
- package/sdk/dist/scoped.js.map +1 -1
- package/core-dist/operator-session.js +0 -154
- package/lib/allowance.mjs +0 -355
- package/lib/cloud.mjs +0 -256
- package/lib/core.mjs +0 -123
- package/lib/operator-proofs.mjs +0 -22
- package/lib/operator.mjs +0 -771
- package/sdk/core-dist/operator-session.js +0 -154
- package/sdk/dist/namespaces/allowance.d.ts +0 -79
- package/sdk/dist/namespaces/allowance.d.ts.map +0 -1
- package/sdk/dist/namespaces/allowance.js +0 -149
- package/sdk/dist/namespaces/allowance.js.map +0 -1
- package/sdk/dist/namespaces/operator-session.d.ts.map +0 -1
- package/sdk/dist/namespaces/operator-session.js.map +0 -1
- package/sdk/dist/namespaces/operator.d.ts +0 -359
- package/sdk/dist/namespaces/operator.d.ts.map +0 -1
- package/sdk/dist/namespaces/operator.js +0 -272
- package/sdk/dist/namespaces/operator.js.map +0 -1
- package/sdk/dist/node/bearer-claim-key.d.ts.map +0 -1
- package/sdk/dist/node/bearer-claim-key.js.map +0 -1
- package/sdk/dist/node/operator-claim.d.ts +0 -49
- package/sdk/dist/node/operator-claim.d.ts.map +0 -1
- package/sdk/dist/node/operator-claim.js +0 -77
- package/sdk/dist/node/operator-claim.js.map +0 -1
package/lib/allowance.mjs
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import { readAllowance, saveAllowance, allowanceFile } from "./config.mjs";
|
|
2
|
-
import { getSdk } from "./sdk.mjs";
|
|
3
|
-
import { reportSdkError, fail } from "./sdk-errors.mjs";
|
|
4
|
-
import { assertKnownFlags, flagValue, normalizeArgv, parseIntegerFlag, positionalArgs, failUnknownSubcommand } from "./argparse.mjs";
|
|
5
|
-
|
|
6
|
-
const HELP = `run402 allowance — Manage your agent allowance
|
|
7
|
-
|
|
8
|
-
Usage:
|
|
9
|
-
run402 allowance <subcommand>
|
|
10
|
-
|
|
11
|
-
Subcommands:
|
|
12
|
-
status Show allowance address, network, rail, and funding status
|
|
13
|
-
create Generate a new allowance and save it locally
|
|
14
|
-
fund Request test funds from the faucet (Base Sepolia or Tempo)
|
|
15
|
-
balance Show on-chain balances and Run402 billing balance
|
|
16
|
-
export Print the allowance address as JSON (useful for scripting)
|
|
17
|
-
checkout Create an org balance checkout session (--amount <usd_micros>)
|
|
18
|
-
history View billing transaction history (--limit <n>)
|
|
19
|
-
|
|
20
|
-
Notes:
|
|
21
|
-
- Agent allowance is stored locally at ~/.config/run402/allowance.json
|
|
22
|
-
- The allowance works on any EVM chain (Base for x402, Tempo for MPP)
|
|
23
|
-
- Use 'run402 init' for x402 or 'run402 init mpp' for MPP rail
|
|
24
|
-
|
|
25
|
-
Examples:
|
|
26
|
-
run402 allowance create
|
|
27
|
-
run402 allowance status
|
|
28
|
-
run402 allowance fund
|
|
29
|
-
run402 allowance export
|
|
30
|
-
run402 allowance balance
|
|
31
|
-
run402 allowance checkout --amount 5000000
|
|
32
|
-
run402 allowance history --limit 10
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
const SUB_HELP = {
|
|
36
|
-
checkout: `run402 allowance checkout — Create an org balance checkout session
|
|
37
|
-
|
|
38
|
-
Usage:
|
|
39
|
-
run402 allowance checkout --amount <usd_micros>
|
|
40
|
-
|
|
41
|
-
Options:
|
|
42
|
-
--amount <n> Amount in USD micros (required; e.g. 5000000 for $5)
|
|
43
|
-
|
|
44
|
-
Examples:
|
|
45
|
-
run402 allowance checkout --amount 5000000
|
|
46
|
-
run402 allowance checkout --amount 10000000
|
|
47
|
-
`,
|
|
48
|
-
history: `run402 allowance history — View billing transaction history
|
|
49
|
-
|
|
50
|
-
Usage:
|
|
51
|
-
run402 allowance history [--limit <n>]
|
|
52
|
-
|
|
53
|
-
Options:
|
|
54
|
-
--limit <n> Max entries to return (default: 20)
|
|
55
|
-
|
|
56
|
-
Examples:
|
|
57
|
-
run402 allowance history
|
|
58
|
-
run402 allowance history --limit 10
|
|
59
|
-
`,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const USDC_ABI = [{ name: "balanceOf", type: "function", stateMutability: "view", inputs: [{ name: "account", type: "address" }], outputs: [{ name: "", type: "uint256" }] }];
|
|
63
|
-
const USDC_MAINNET = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
64
|
-
const USDC_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
|
|
65
|
-
const PATH_USD = "0x20c0000000000000000000000000000000000000";
|
|
66
|
-
const TEMPO_RPC = "https://rpc.moderato.tempo.xyz/";
|
|
67
|
-
|
|
68
|
-
async function loadDeps() {
|
|
69
|
-
const { generatePrivateKey, privateKeyToAccount } = await import("viem/accounts");
|
|
70
|
-
const { createPublicClient, http, defineChain } = await import("viem");
|
|
71
|
-
const { base, baseSepolia } = await import("viem/chains");
|
|
72
|
-
const tempoModerato = defineChain({
|
|
73
|
-
id: 42431,
|
|
74
|
-
name: "Tempo Moderato",
|
|
75
|
-
nativeCurrency: { name: "pathUSD", symbol: "pathUSD", decimals: 6 },
|
|
76
|
-
rpcUrls: { default: { http: [TEMPO_RPC] } },
|
|
77
|
-
});
|
|
78
|
-
return { generatePrivateKey, privateKeyToAccount, createPublicClient, http, base, baseSepolia, tempoModerato };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function status() {
|
|
82
|
-
try {
|
|
83
|
-
const data = await getSdk().allowance.status();
|
|
84
|
-
if (!data.configured) {
|
|
85
|
-
console.log(JSON.stringify({ wallet: null, hint: "Run: run402 allowance create" }));
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const w = readAllowance();
|
|
89
|
-
// The Lightning allowance (mpp-lightning-over-nwc): public facts plus a
|
|
90
|
-
// best-effort balance read over NWC; the pairing secret never prints.
|
|
91
|
-
const { describeLightning, readLightningBalance } = await import("./lightning-wallet.mjs");
|
|
92
|
-
const lightning = w?.lightning ? describeLightning(w, null, await readLightningBalance(w)) : null;
|
|
93
|
-
console.log(JSON.stringify({
|
|
94
|
-
wallet: {
|
|
95
|
-
address: data.address,
|
|
96
|
-
created: data.created,
|
|
97
|
-
configured: data.configured,
|
|
98
|
-
// `faucet_used` is named for what it is: an on-disk marker that
|
|
99
|
-
// tracks faucet invocation, not pay-readiness. For a true "can this
|
|
100
|
-
// account pay right now" check, use `run402 allowance balance`.
|
|
101
|
-
faucet_used: !!data.faucet_used,
|
|
102
|
-
rail: data.rail ?? w?.rail ?? "x402",
|
|
103
|
-
path: data.path ?? allowanceFile(),
|
|
104
|
-
},
|
|
105
|
-
...(lightning ? { lightning } : {}),
|
|
106
|
-
}));
|
|
107
|
-
} catch (err) {
|
|
108
|
-
reportSdkError(err);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async function create() {
|
|
113
|
-
try {
|
|
114
|
-
const result = await getSdk().allowance.create();
|
|
115
|
-
console.log(JSON.stringify({
|
|
116
|
-
address: result.address,
|
|
117
|
-
path: result.path ?? allowanceFile(),
|
|
118
|
-
created: true,
|
|
119
|
-
}));
|
|
120
|
-
} catch (err) {
|
|
121
|
-
const msg = (err instanceof Error) ? err.message : String(err);
|
|
122
|
-
if (/already exists/i.test(msg)) {
|
|
123
|
-
fail({
|
|
124
|
-
code: "ALLOWANCE_EXISTS",
|
|
125
|
-
message: "Agent allowance already exists.",
|
|
126
|
-
hint: "Use 'status' to check it.",
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
reportSdkError(err);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async function fund() {
|
|
134
|
-
const w = readAllowance();
|
|
135
|
-
if (!w) {
|
|
136
|
-
fail({
|
|
137
|
-
code: "NO_ALLOWANCE",
|
|
138
|
-
message: "No agent allowance.",
|
|
139
|
-
hint: "Run: run402 allowance create",
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (w.rail === "mpp") {
|
|
144
|
-
// Tempo Moderato faucet — instant, no polling needed
|
|
145
|
-
const { createPublicClient, http, tempoModerato } = await loadDeps();
|
|
146
|
-
const client = createPublicClient({ chain: tempoModerato, transport: http() });
|
|
147
|
-
const before = await readUsdcBalance(client, PATH_USD, w.address).catch(() => 0);
|
|
148
|
-
|
|
149
|
-
const res = await fetch(TEMPO_RPC, {
|
|
150
|
-
method: "POST",
|
|
151
|
-
headers: { "Content-Type": "application/json" },
|
|
152
|
-
body: JSON.stringify({ jsonrpc: "2.0", method: "tempo_fundAddress", params: [w.address], id: 1 }),
|
|
153
|
-
});
|
|
154
|
-
const data = await res.json();
|
|
155
|
-
if (data.error) {
|
|
156
|
-
fail({
|
|
157
|
-
code: "FAUCET_FAILED",
|
|
158
|
-
message: data.error.message || "Tempo faucet failed",
|
|
159
|
-
details: { rail: "mpp" },
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Re-read balance once (instant confirmation)
|
|
164
|
-
const now = await readUsdcBalance(client, PATH_USD, w.address).catch(() => before);
|
|
165
|
-
saveAllowance({ ...w, funded: true, lastFaucet: new Date().toISOString() });
|
|
166
|
-
console.log(JSON.stringify({
|
|
167
|
-
address: w.address,
|
|
168
|
-
rail: "mpp",
|
|
169
|
-
onchain: {
|
|
170
|
-
"tempo-moderato_pathusd_micros": now,
|
|
171
|
-
},
|
|
172
|
-
}, null, 2));
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Default: Base Sepolia faucet (existing behavior)
|
|
177
|
-
const { createPublicClient, http, baseSepolia } = await loadDeps();
|
|
178
|
-
const client = createPublicClient({ chain: baseSepolia, transport: http() });
|
|
179
|
-
const before = await readUsdcBalance(client, USDC_SEPOLIA, w.address).catch(() => 0);
|
|
180
|
-
|
|
181
|
-
let data;
|
|
182
|
-
try {
|
|
183
|
-
data = await getSdk().allowance.faucet(w.address);
|
|
184
|
-
} catch (err) {
|
|
185
|
-
reportSdkError(err);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const MAX_WAIT = 30;
|
|
189
|
-
for (let i = 0; i < MAX_WAIT; i++) {
|
|
190
|
-
await new Promise(r => setTimeout(r, 1000));
|
|
191
|
-
const now = await readUsdcBalance(client, USDC_SEPOLIA, w.address).catch(() => before);
|
|
192
|
-
if (now > before) {
|
|
193
|
-
saveAllowance({ ...w, funded: true, lastFaucet: new Date().toISOString() });
|
|
194
|
-
console.log(JSON.stringify({
|
|
195
|
-
address: w.address,
|
|
196
|
-
rail: w.rail || "x402",
|
|
197
|
-
onchain: {
|
|
198
|
-
"base-sepolia_usd_micros": now,
|
|
199
|
-
},
|
|
200
|
-
}, null, 2));
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
saveAllowance({ ...w, funded: true, lastFaucet: new Date().toISOString() });
|
|
206
|
-
console.log(JSON.stringify({ ...data, balance_confirmed: false, hint: "Faucet request sent but on-chain balance not yet confirmed" }));
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
async function readUsdcBalance(client, usdc, address) {
|
|
210
|
-
const raw = await client.readContract({ address: usdc, abi: USDC_ABI, functionName: "balanceOf", args: [address] });
|
|
211
|
-
return Number(raw);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
async function balance() {
|
|
215
|
-
const w = readAllowance();
|
|
216
|
-
if (!w) {
|
|
217
|
-
fail({
|
|
218
|
-
code: "NO_ALLOWANCE",
|
|
219
|
-
message: "No agent allowance.",
|
|
220
|
-
hint: "Run: run402 allowance create",
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const { createPublicClient, http, base, baseSepolia, tempoModerato } = await loadDeps();
|
|
225
|
-
const mainnetClient = createPublicClient({ chain: base, transport: http() });
|
|
226
|
-
const sepoliaClient = createPublicClient({ chain: baseSepolia, transport: http() });
|
|
227
|
-
const tempoClient = createPublicClient({ chain: tempoModerato, transport: http() });
|
|
228
|
-
|
|
229
|
-
const [mainnetUsdc, sepoliaUsdc, tempoPathUsd, billingRes] = await Promise.all([
|
|
230
|
-
readUsdcBalance(mainnetClient, USDC_MAINNET, w.address).catch(() => null),
|
|
231
|
-
readUsdcBalance(sepoliaClient, USDC_SEPOLIA, w.address).catch(() => null),
|
|
232
|
-
readUsdcBalance(tempoClient, PATH_USD, w.address).catch(() => null),
|
|
233
|
-
getSdk().billing.checkBalance(w.address).catch(() => null),
|
|
234
|
-
]);
|
|
235
|
-
|
|
236
|
-
console.log(JSON.stringify({
|
|
237
|
-
address: w.address,
|
|
238
|
-
rail: w.rail || "x402",
|
|
239
|
-
onchain: {
|
|
240
|
-
"base-mainnet_usd_micros": mainnetUsdc,
|
|
241
|
-
"base-sepolia_usd_micros": sepoliaUsdc,
|
|
242
|
-
"tempo-moderato_pathusd_micros": tempoPathUsd,
|
|
243
|
-
},
|
|
244
|
-
run402: billingRes ? { balance_usd_micros: billingRes.available_usd_micros } : "no organization",
|
|
245
|
-
}, null, 2));
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
async function exportAddr(args = []) {
|
|
249
|
-
const parsedArgs = normalizeArgv(args);
|
|
250
|
-
assertKnownFlags(parsedArgs, [], []);
|
|
251
|
-
const bare = positionalArgs(parsedArgs, []);
|
|
252
|
-
if (bare.length > 0) {
|
|
253
|
-
fail({
|
|
254
|
-
code: "BAD_USAGE",
|
|
255
|
-
message: `Unexpected argument for allowance export: ${bare[0]}`,
|
|
256
|
-
details: { argument: bare[0] },
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
try {
|
|
260
|
-
const address = await getSdk().allowance.export();
|
|
261
|
-
console.log(JSON.stringify({ address }));
|
|
262
|
-
} catch {
|
|
263
|
-
fail({ code: "NO_ALLOWANCE", message: "No agent allowance." });
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
async function checkout(args) {
|
|
268
|
-
const w = readAllowance();
|
|
269
|
-
if (!w) {
|
|
270
|
-
fail({
|
|
271
|
-
code: "NO_ALLOWANCE",
|
|
272
|
-
message: "No agent allowance.",
|
|
273
|
-
hint: "Run: run402 allowance create",
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
const parsedArgs = normalizeArgv(args);
|
|
277
|
-
assertKnownFlags(parsedArgs, ["--amount", "--help", "-h"], ["--amount"]);
|
|
278
|
-
const bare = positionalArgs(parsedArgs, ["--amount"]);
|
|
279
|
-
if (bare.length > 0) {
|
|
280
|
-
fail({
|
|
281
|
-
code: "BAD_USAGE",
|
|
282
|
-
message: `Unexpected argument for allowance checkout: ${bare[0]}`,
|
|
283
|
-
details: { argument: bare[0] },
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
const amountRaw = flagValue(parsedArgs, "--amount");
|
|
287
|
-
if (amountRaw === null) {
|
|
288
|
-
fail({
|
|
289
|
-
code: "BAD_USAGE",
|
|
290
|
-
message: "Missing --amount <usd_micros>",
|
|
291
|
-
hint: "e.g. --amount 5000000 for $5",
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
const amount = parseIntegerFlag("--amount", amountRaw, { min: 1 });
|
|
295
|
-
try {
|
|
296
|
-
const org = await getSdk().billing.lookupOrganization(w.address);
|
|
297
|
-
const data = await getSdk().billing.createCheckout(org.org_id, {
|
|
298
|
-
product: "balance_topup",
|
|
299
|
-
amountUsdMicros: amount,
|
|
300
|
-
});
|
|
301
|
-
console.log(JSON.stringify(data, null, 2));
|
|
302
|
-
} catch (err) {
|
|
303
|
-
reportSdkError(err);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
async function history(args) {
|
|
308
|
-
const w = readAllowance();
|
|
309
|
-
if (!w) {
|
|
310
|
-
fail({
|
|
311
|
-
code: "NO_ALLOWANCE",
|
|
312
|
-
message: "No agent allowance.",
|
|
313
|
-
hint: "Run: run402 allowance create",
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
const parsedArgs = normalizeArgv(args);
|
|
317
|
-
assertKnownFlags(parsedArgs, ["--limit", "--help", "-h"], ["--limit"]);
|
|
318
|
-
const bare = positionalArgs(parsedArgs, ["--limit"]);
|
|
319
|
-
if (bare.length > 0) {
|
|
320
|
-
fail({
|
|
321
|
-
code: "BAD_USAGE",
|
|
322
|
-
message: `Unexpected argument for allowance history: ${bare[0]}`,
|
|
323
|
-
details: { argument: bare[0] },
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
const limit = parseIntegerFlag("--limit", flagValue(parsedArgs, "--limit"), { min: 1, def: 20 });
|
|
327
|
-
try {
|
|
328
|
-
const data = await getSdk().billing.history(w.address, limit);
|
|
329
|
-
console.log(JSON.stringify(data, null, 2));
|
|
330
|
-
} catch (err) {
|
|
331
|
-
reportSdkError(err);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export async function run(sub, args) {
|
|
336
|
-
if (!sub || sub === '--help' || sub === '-h') {
|
|
337
|
-
console.log(HELP);
|
|
338
|
-
process.exit(0);
|
|
339
|
-
}
|
|
340
|
-
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) {
|
|
341
|
-
console.log(SUB_HELP[sub] || HELP);
|
|
342
|
-
process.exit(0);
|
|
343
|
-
}
|
|
344
|
-
switch (sub) {
|
|
345
|
-
case "status": await status(); break;
|
|
346
|
-
case "create": await create(); break;
|
|
347
|
-
case "fund": await fund(); break;
|
|
348
|
-
case "balance": await balance(); break;
|
|
349
|
-
case "export": await exportAddr(args); break;
|
|
350
|
-
case "checkout": await checkout(args); break;
|
|
351
|
-
case "history": await history(args); break;
|
|
352
|
-
default:
|
|
353
|
-
failUnknownSubcommand("allowance", sub);
|
|
354
|
-
}
|
|
355
|
-
}
|
package/lib/cloud.mjs
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
3
|
-
|
|
4
|
-
import { getSdk } from "./sdk.mjs";
|
|
5
|
-
import { fail, reportSdkError } from "./sdk-errors.mjs";
|
|
6
|
-
import { assertAllowedValue, assertKnownFlags, flagValue, hasHelp, normalizeArgv, parseIntegerFlag, positionalArgs, resolveProjectSelector, failUnknownSubcommand } from "./argparse.mjs";
|
|
7
|
-
|
|
8
|
-
const HELP = `run402 cloud — Run402 Cloud portability commands
|
|
9
|
-
|
|
10
|
-
Usage:
|
|
11
|
-
run402 cloud archives create [--project <id>] [options]
|
|
12
|
-
run402 cloud archives download <archive-id> --output <file> [--project <id>] [--json]
|
|
13
|
-
run402 cloud archives status <archive-id> [--project <id>] [--json]
|
|
14
|
-
|
|
15
|
-
Legacy (still supported): a leading prj_... positional selects the project,
|
|
16
|
-
e.g. run402 cloud archives download <project-id> <archive-id> --output <file>.
|
|
17
|
-
--project defaults to the active project.
|
|
18
|
-
|
|
19
|
-
Canonical agent path:
|
|
20
|
-
run402 cloud archives create prj_... \\
|
|
21
|
-
--scope portable-runtime-v1 --auth stubs --consistency pause-writes \\
|
|
22
|
-
--wait --output ./project.r402ar --json
|
|
23
|
-
|
|
24
|
-
Options for create:
|
|
25
|
-
--scope <scope> Archive scope. v1 supports portable-runtime-v1.
|
|
26
|
-
--auth <mode> Auth export mode: stubs (default) or none.
|
|
27
|
-
--consistency <mode> pause-writes (default) or cloud_write_pause_v1.
|
|
28
|
-
--idempotency-key <key> Retry-safe creation key.
|
|
29
|
-
--wait Poll until the archive is ready.
|
|
30
|
-
--output <file> Save archive bytes. Implies --wait.
|
|
31
|
-
--poll-interval <ms> Poll interval while waiting (default 1000).
|
|
32
|
-
--timeout <ms> Wait timeout (default 600000).
|
|
33
|
-
--json Emit final JSON on stdout.
|
|
34
|
-
--json-stream Emit NDJSON progress events on stdout.
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
const FLAG_VALUES = [
|
|
38
|
-
"--project",
|
|
39
|
-
"--scope",
|
|
40
|
-
"--auth",
|
|
41
|
-
"--consistency",
|
|
42
|
-
"--idempotency-key",
|
|
43
|
-
"--output",
|
|
44
|
-
"--poll-interval",
|
|
45
|
-
"--timeout",
|
|
46
|
-
];
|
|
47
|
-
const FLAGS = new Set([
|
|
48
|
-
...FLAG_VALUES,
|
|
49
|
-
"--wait",
|
|
50
|
-
"--json",
|
|
51
|
-
"--json-stream",
|
|
52
|
-
"--help",
|
|
53
|
-
"-h",
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
export async function run(sub, args = []) {
|
|
57
|
-
const all = [sub, ...args].filter(Boolean);
|
|
58
|
-
if (hasHelp(all)) {
|
|
59
|
-
console.log(HELP);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (sub !== "archives") {
|
|
63
|
-
failUnknownSubcommand("cloud", sub, {
|
|
64
|
-
next_actions: [{ type: "run_command", command: "run402 cloud archives --help" }],
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
const action = args[0];
|
|
68
|
-
const rest = args.slice(1);
|
|
69
|
-
if (action === "create") return create(rest);
|
|
70
|
-
if (action === "download") return download(rest);
|
|
71
|
-
if (action === "status") return status(rest);
|
|
72
|
-
failUnknownSubcommand("cloud archives", action, {
|
|
73
|
-
next_actions: [{ type: "run_command", command: "run402 cloud archives --help" }],
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function create(rawArgs) {
|
|
78
|
-
const args = normalizeArgv(rawArgs);
|
|
79
|
-
assertKnownFlags(args, [...FLAGS], FLAG_VALUES);
|
|
80
|
-
const { projectId, rest } = resolveProjectSelector(args, { valueFlags: FLAG_VALUES });
|
|
81
|
-
const extraPos = positionalArgs(rest, FLAG_VALUES);
|
|
82
|
-
if (extraPos.length > 0) {
|
|
83
|
-
fail({ code: "BAD_USAGE", message: `Unexpected argument for cloud archives create: ${extraPos[0]}` });
|
|
84
|
-
}
|
|
85
|
-
const scope = flagValue(args, "--scope") ?? "portable-runtime-v1";
|
|
86
|
-
const auth = flagValue(args, "--auth") ?? "stubs";
|
|
87
|
-
const consistency = flagValue(args, "--consistency") ?? "pause-writes";
|
|
88
|
-
assertAllowedValue(scope, ["portable-runtime-v1"], "--scope");
|
|
89
|
-
assertAllowedValue(auth, ["stubs", "none"], "--auth");
|
|
90
|
-
assertAllowedValue(consistency, ["pause-writes", "cloud_write_pause_v1"], "--consistency");
|
|
91
|
-
|
|
92
|
-
const output = flagValue(args, "--output");
|
|
93
|
-
const wait = args.includes("--wait") || Boolean(output);
|
|
94
|
-
const jsonStream = args.includes("--json-stream");
|
|
95
|
-
const idempotencyKey = flagValue(args, "--idempotency-key") ?? undefined;
|
|
96
|
-
const pollIntervalMs = parseIntegerFlag("--poll-interval", flagValue(args, "--poll-interval"), { min: 100, def: 1000 });
|
|
97
|
-
const timeoutMs = parseIntegerFlag("--timeout", flagValue(args, "--timeout"), { min: 1000, def: 600000 });
|
|
98
|
-
const emit = (event) => {
|
|
99
|
-
if (jsonStream) console.log(JSON.stringify(event));
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const sdk = getSdk();
|
|
104
|
-
const created = await sdk.archives.create(projectId, {
|
|
105
|
-
scope,
|
|
106
|
-
auth,
|
|
107
|
-
consistency,
|
|
108
|
-
idempotencyKey,
|
|
109
|
-
});
|
|
110
|
-
emit(progressEvent("archive_export_created", "create", projectId, created));
|
|
111
|
-
|
|
112
|
-
let archive = created;
|
|
113
|
-
let outputPath = null;
|
|
114
|
-
let bytesWritten = 0;
|
|
115
|
-
if (wait) {
|
|
116
|
-
archive = created.status === "ready"
|
|
117
|
-
? created
|
|
118
|
-
: await sdk.archives.wait(projectId, created.archive_id, {
|
|
119
|
-
pollIntervalMs,
|
|
120
|
-
timeoutMs,
|
|
121
|
-
onProgress: emit,
|
|
122
|
-
});
|
|
123
|
-
if (archive.status !== "ready") {
|
|
124
|
-
const result = finalCreateResult({ projectId, created, archive, outputPath, bytesWritten });
|
|
125
|
-
printJson(result, jsonStream);
|
|
126
|
-
process.exit(1);
|
|
127
|
-
}
|
|
128
|
-
if (output) {
|
|
129
|
-
const download = await sdk.archives.download(projectId, archive.archive_id);
|
|
130
|
-
outputPath = resolve(output);
|
|
131
|
-
mkdirSync(dirname(outputPath), { recursive: true });
|
|
132
|
-
writeFileSync(outputPath, download.bytes);
|
|
133
|
-
bytesWritten = download.bytes.byteLength;
|
|
134
|
-
emit({
|
|
135
|
-
...progressEvent("archive_export_downloaded", "download", projectId, archive),
|
|
136
|
-
context: { output_path: outputPath, bytes_written: bytesWritten },
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const result = finalCreateResult({ projectId, created, archive, outputPath, bytesWritten });
|
|
142
|
-
if (jsonStream) {
|
|
143
|
-
console.log(JSON.stringify({
|
|
144
|
-
event: "archive_export_complete",
|
|
145
|
-
stage: "complete",
|
|
146
|
-
resource_type: "project_archive",
|
|
147
|
-
resource_id: archive.archive_id,
|
|
148
|
-
project_id: projectId,
|
|
149
|
-
status: archive.status === "ready" ? "complete" : archive.status,
|
|
150
|
-
completed_units: archive.status === "ready" ? 1 : 0,
|
|
151
|
-
total_units: 1,
|
|
152
|
-
code: null,
|
|
153
|
-
message: archive.status === "ready" ? "Archive export complete." : "Archive export did not complete.",
|
|
154
|
-
next_action: archive.next_action,
|
|
155
|
-
retryable: false,
|
|
156
|
-
result,
|
|
157
|
-
}));
|
|
158
|
-
} else {
|
|
159
|
-
console.log(JSON.stringify(result, null, 2));
|
|
160
|
-
}
|
|
161
|
-
if (archive.status !== "ready") process.exit(1);
|
|
162
|
-
} catch (err) {
|
|
163
|
-
reportSdkError(err);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function download(rawArgs) {
|
|
168
|
-
const args = normalizeArgv(rawArgs);
|
|
169
|
-
assertKnownFlags(args, ["--project", "--output", "--json", "--help", "-h"], ["--project", "--output"]);
|
|
170
|
-
const { projectId, rest } = resolveProjectSelector(args, { valueFlags: ["--project", "--output"] });
|
|
171
|
-
const pos = positionalArgs(rest, ["--project", "--output"]);
|
|
172
|
-
const [archiveId] = pos;
|
|
173
|
-
const output = flagValue(args, "--output");
|
|
174
|
-
if (!archiveId || pos.length > 1 || !output) {
|
|
175
|
-
fail({ code: "BAD_USAGE", message: "Usage: run402 cloud archives download <archive-id> --output <file> [--project <id>] [--json]" });
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
const download = await getSdk().archives.download(projectId, archiveId);
|
|
179
|
-
const outputPath = resolve(output);
|
|
180
|
-
mkdirSync(dirname(outputPath), { recursive: true });
|
|
181
|
-
writeFileSync(outputPath, download.bytes);
|
|
182
|
-
console.log(JSON.stringify({
|
|
183
|
-
ok: true,
|
|
184
|
-
project_id: projectId,
|
|
185
|
-
archive_id: archiveId,
|
|
186
|
-
output_path: outputPath,
|
|
187
|
-
bytes_written: download.bytes.byteLength,
|
|
188
|
-
sha256: download.archive.sha256,
|
|
189
|
-
verify_command: `run402 archives verify ${JSON.stringify(outputPath)} --json`,
|
|
190
|
-
import_command: `run402 core projects import ${JSON.stringify(outputPath)} --name imported-project --env-file ./required.env --json`,
|
|
191
|
-
archive: download.archive,
|
|
192
|
-
}, null, 2));
|
|
193
|
-
} catch (err) {
|
|
194
|
-
reportSdkError(err);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async function status(rawArgs) {
|
|
199
|
-
const args = normalizeArgv(rawArgs);
|
|
200
|
-
assertKnownFlags(args, ["--project", "--json", "--help", "-h"], ["--project"]);
|
|
201
|
-
const { projectId, rest } = resolveProjectSelector(args, { valueFlags: ["--project"] });
|
|
202
|
-
const pos = positionalArgs(rest, ["--project"]);
|
|
203
|
-
const [archiveId] = pos;
|
|
204
|
-
if (!archiveId || pos.length > 1) {
|
|
205
|
-
fail({ code: "BAD_USAGE", message: "Usage: run402 cloud archives status <archive-id> [--project <id>] [--json]" });
|
|
206
|
-
}
|
|
207
|
-
try {
|
|
208
|
-
const archive = await getSdk().archives.get(projectId, archiveId);
|
|
209
|
-
console.log(JSON.stringify({ archive }, null, 2));
|
|
210
|
-
} catch (err) {
|
|
211
|
-
reportSdkError(err);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function finalCreateResult({ projectId, created, archive, outputPath, bytesWritten }) {
|
|
216
|
-
return {
|
|
217
|
-
ok: archive.status === "ready",
|
|
218
|
-
project_id: projectId,
|
|
219
|
-
archive_id: archive.archive_id,
|
|
220
|
-
operation_id: archive.operation_id,
|
|
221
|
-
created_archive_id: created.archive_id,
|
|
222
|
-
archive_status: archive.status,
|
|
223
|
-
output_path: outputPath,
|
|
224
|
-
bytes_written: bytesWritten,
|
|
225
|
-
sha256: archive.sha256,
|
|
226
|
-
byte_count: archive.byte_count,
|
|
227
|
-
expires_at: archive.expires_at,
|
|
228
|
-
verify_command: outputPath ? `run402 archives verify ${JSON.stringify(outputPath)} --json` : null,
|
|
229
|
-
import_command: outputPath ? `run402 core projects import ${JSON.stringify(outputPath)} --name imported-project --env-file ./required.env --json` : null,
|
|
230
|
-
next_action: archive.next_action,
|
|
231
|
-
portability_report: archive.portability_report,
|
|
232
|
-
export_report: archive.export_report,
|
|
233
|
-
archive,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function progressEvent(event, stage, projectId, archive) {
|
|
238
|
-
return {
|
|
239
|
-
event,
|
|
240
|
-
stage,
|
|
241
|
-
resource_type: "project_archive",
|
|
242
|
-
resource_id: archive.archive_id,
|
|
243
|
-
project_id: projectId,
|
|
244
|
-
status: archive.status,
|
|
245
|
-
completed_units: archive.status === "ready" || archive.status === "failed" || archive.status === "expired" ? 1 : 0,
|
|
246
|
-
total_units: 1,
|
|
247
|
-
code: archive.status === "failed" ? archive.error?.code ?? "ARCHIVE_EXPORT_FAILED" : null,
|
|
248
|
-
message: `Archive export status: ${archive.status}`,
|
|
249
|
-
next_action: archive.next_action,
|
|
250
|
-
retryable: archive.status === "running",
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
function printJson(result, alreadyStreamed) {
|
|
255
|
-
if (!alreadyStreamed) console.log(JSON.stringify(result, null, 2));
|
|
256
|
-
}
|