@run402/sdk 1.52.0 → 1.53.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 +149 -41
- package/dist/errors.d.ts +73 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +128 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +38 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -1
- package/dist/index.js.map +1 -1
- package/dist/namespaces/admin.d.ts +4 -1
- package/dist/namespaces/admin.d.ts.map +1 -1
- package/dist/namespaces/admin.js +1 -1
- package/dist/namespaces/admin.js.map +1 -1
- package/dist/namespaces/apps.d.ts +27 -30
- package/dist/namespaces/apps.d.ts.map +1 -1
- package/dist/namespaces/apps.js.map +1 -1
- package/dist/namespaces/billing.d.ts +15 -6
- package/dist/namespaces/billing.d.ts.map +1 -1
- package/dist/namespaces/billing.js.map +1 -1
- package/dist/namespaces/contracts.d.ts +67 -15
- package/dist/namespaces/contracts.d.ts.map +1 -1
- package/dist/namespaces/contracts.js +32 -8
- package/dist/namespaces/contracts.js.map +1 -1
- package/dist/namespaces/domains.d.ts +5 -1
- package/dist/namespaces/domains.d.ts.map +1 -1
- package/dist/namespaces/domains.js +1 -1
- package/dist/namespaces/domains.js.map +1 -1
- package/dist/namespaces/email.d.ts +21 -13
- package/dist/namespaces/email.d.ts.map +1 -1
- package/dist/namespaces/email.js +5 -4
- package/dist/namespaces/email.js.map +1 -1
- package/dist/namespaces/functions.d.ts +2 -2
- package/dist/namespaces/functions.d.ts.map +1 -1
- package/dist/namespaces/functions.js +1 -1
- package/dist/namespaces/functions.js.map +1 -1
- package/dist/namespaces/functions.types.d.ts +4 -0
- package/dist/namespaces/functions.types.d.ts.map +1 -1
- package/dist/namespaces/projects.d.ts +12 -0
- package/dist/namespaces/projects.d.ts.map +1 -1
- package/dist/namespaces/projects.js +15 -5
- package/dist/namespaces/projects.js.map +1 -1
- package/dist/namespaces/projects.types.d.ts +9 -1
- package/dist/namespaces/projects.types.d.ts.map +1 -1
- package/dist/namespaces/secrets.d.ts +5 -1
- package/dist/namespaces/secrets.d.ts.map +1 -1
- package/dist/namespaces/secrets.js +1 -1
- package/dist/namespaces/secrets.js.map +1 -1
- package/dist/namespaces/sender-domain.d.ts +4 -1
- package/dist/namespaces/sender-domain.d.ts.map +1 -1
- package/dist/namespaces/sender-domain.js +1 -1
- package/dist/namespaces/sender-domain.js.map +1 -1
- package/dist/namespaces/service.d.ts +11 -31
- package/dist/namespaces/service.d.ts.map +1 -1
- package/dist/namespaces/service.js.map +1 -1
- package/dist/namespaces/subdomains.d.ts +10 -1
- package/dist/namespaces/subdomains.d.ts.map +1 -1
- package/dist/namespaces/subdomains.js +1 -1
- package/dist/namespaces/subdomains.js.map +1 -1
- package/dist/namespaces/tier.d.ts +9 -1
- package/dist/namespaces/tier.d.ts.map +1 -1
- package/dist/namespaces/tier.js.map +1 -1
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/retry.d.ts +50 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +61 -0
- package/dist/retry.js.map +1 -0
- package/dist/scoped.d.ts +248 -0
- package/dist/scoped.d.ts.map +1 -0
- package/dist/scoped.js +443 -0
- package/dist/scoped.js.map +1 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -25,6 +25,19 @@ await r.blobs.put(project.project_id, "hello.txt", { content: "hi" });
|
|
|
25
25
|
|
|
26
26
|
That's it — credentials are read, x402 payments are signed, results are typed.
|
|
27
27
|
|
|
28
|
+
### Project-scoped sub-client
|
|
29
|
+
|
|
30
|
+
If you're working on a single project for the duration of a script, bind it once and skip the id arg on every call:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
const p = await r.useProject(projectId); // persists active project + returns scoped handle
|
|
34
|
+
await p.blobs.put("hello.txt", { content: "hi" }); // no projectId arg
|
|
35
|
+
await p.functions.list();
|
|
36
|
+
await p.deploy.apply({ site: { replace: files({ "index.html": "<h1>hi</h1>" }) } });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`r.useProject(id)` writes the active project to the keystore (shared with concurrent CLI runs). For transient in-script scoping that does NOT mutate that state, use `r.project(id)` (or `r.project()` with no arg to resolve from whatever the keystore currently considers active).
|
|
40
|
+
|
|
28
41
|
## Quick start (isomorphic)
|
|
29
42
|
|
|
30
43
|
```ts
|
|
@@ -45,38 +58,66 @@ The `CredentialsProvider` interface has two required methods (`getAuth`, `getPro
|
|
|
45
58
|
|
|
46
59
|
| Namespace | Highlights |
|
|
47
60
|
|---|---|
|
|
48
|
-
| `projects` | `provision`, `delete`, `list`, `getUsage`, `getSchema`, `info`, `keys`, `use`, `pin` |
|
|
49
|
-
| `deploy` | **The unified deploy primitive (v1.34+).** `apply` / `start` / `resume` / `status` / `getRelease` / `diff` / `plan` / `upload` / `commit` |
|
|
50
|
-
| `sites` | `deployDir`
|
|
51
|
-
| `blobs` | `put` (returns `AssetRef` with `
|
|
52
|
-
| `functions` | `deploy`, `invoke`, `
|
|
61
|
+
| `projects` | `provision`, `delete`, `list`, `getUsage`, `getSchema`, `info`, `keys`, `use`, `active`, `pin`, `getQuote` |
|
|
62
|
+
| `deploy` | **The unified deploy primitive (v1.34+).** `apply` / `start` / `resume` / `status` / `list` / `events` / `getRelease` / `diff` / `plan` / `upload` / `commit` |
|
|
63
|
+
| `sites` | `deployDir` — Node entry only (`@run402/sdk/node`); thin wrapper over `r.deploy.apply` |
|
|
64
|
+
| `blobs` | `put` (returns `AssetRef` with `cdnUrl` / `sri` / `etag` / `cacheKind` and `scriptTag()`/`linkTag()`/`imgTag()` emitters), `get`, `ls`, `rm`, `sign`, `diagnoseUrl`, `waitFresh` |
|
|
65
|
+
| `functions` | `deploy`, `invoke`, `logs`, `update`, `list`, `delete` |
|
|
53
66
|
| `secrets` | `set`, `list`, `delete` |
|
|
54
|
-
| `subdomains` | `claim`, `list`, `delete` |
|
|
67
|
+
| `subdomains` | `claim`, `list`, `delete` (most agents declare subdomains in `r.deploy.apply({ subdomains: { set: [...] } })` instead) |
|
|
55
68
|
| `domains` | `add`, `list`, `status`, `remove` |
|
|
56
|
-
| `email` | `createMailbox`, `
|
|
69
|
+
| `email` | `createMailbox`, `getMailbox`, `deleteMailbox`, `send`, `list`, `get`, `getRaw`, `webhooks.*` |
|
|
57
70
|
| `senderDomain` | `register`, `status`, `remove`, `enableInbound`, `disableInbound` |
|
|
58
|
-
| `auth` | `
|
|
59
|
-
| `apps` | `browse`, `
|
|
60
|
-
| `tier` | `set`, `status
|
|
71
|
+
| `auth` | `requestMagicLink`, `verifyMagicLink`, `setUserPassword`, `settings`, `promote`, `demote` |
|
|
72
|
+
| `apps` | `browse`, `getApp`, `fork`, `publish`, `listVersions`, `updateVersion`, `deleteVersion`, `bundleDeploy` (legacy shim → routes through `deploy`) |
|
|
73
|
+
| `tier` | `set`, `status` (tier pricing lives on `r.projects.getQuote()`) |
|
|
61
74
|
| `billing` | `createEmailAccount`, `linkWallet`, `tierCheckout`, `buyEmailPack`, `setAutoRecharge`, `balance`, `history`, `createCheckout` |
|
|
62
|
-
| `contracts` | `provisionWallet`, `getWallet`, `listWallets`, `
|
|
63
|
-
| `ai` | `translate`, `moderate`, `usage` |
|
|
64
|
-
| `allowance` | `status`, `create`, `export`, `
|
|
75
|
+
| `contracts` | `provisionWallet`, `getWallet`, `listWallets`, `setRecovery`, `setLowBalanceAlert`, `call`, `read`, `callStatus`, `drain`, `deleteWallet` |
|
|
76
|
+
| `ai` | `translate`, `moderate`, `usage`, `generateImage` |
|
|
77
|
+
| `allowance` | `status`, `create`, `export`, `faucet` |
|
|
65
78
|
| `service` | `status`, `health` (no auth, no setup — works on a fresh install) |
|
|
66
79
|
| `admin` | Admin-only endpoints (pinning, lifecycle reactivation, dispute resolution) |
|
|
67
80
|
|
|
81
|
+
### Casing in returned shapes
|
|
82
|
+
|
|
83
|
+
Two casings coexist by design — agents reading the type surface should
|
|
84
|
+
classify a field by the SHAPE it belongs to:
|
|
85
|
+
|
|
86
|
+
- **Raw API result shapes preserve the gateway's snake_case fields.** Examples:
|
|
87
|
+
`ProvisionResult.project_id`, `ProvisionResult.anon_key`,
|
|
88
|
+
`ProvisionResult.service_key`, `ProvisionResult.schema_slot`,
|
|
89
|
+
`ProjectInfo.project_id`, `ProjectSummary.lease_expires_at`,
|
|
90
|
+
`UsageReport.api_calls`, `SchemaReport.schema`. These mirror the HTTP
|
|
91
|
+
response bodies one-to-one.
|
|
92
|
+
- **SDK-specific helper shapes use camelCase.** Examples:
|
|
93
|
+
`AssetRef.cdnUrl` / `AssetRef.cacheKind` / `AssetRef.contentSha256`,
|
|
94
|
+
`Run402DeployError.safeToRetry` / `operationId` / `mutationState`,
|
|
95
|
+
every `DeployEvent` variant's discriminator (`type`, plus per-variant
|
|
96
|
+
fields like `releaseId`, `urls`).
|
|
97
|
+
|
|
98
|
+
This split is intentional and stays through `1.x`. Doc examples in this
|
|
99
|
+
README and in `llms-sdk.txt` use the exact field names the types export —
|
|
100
|
+
copy them verbatim. CI fails any TypeScript-fenced example that accesses a
|
|
101
|
+
field that does not exist on the actual type.
|
|
102
|
+
|
|
103
|
+
> **Reference tables (in `llms-sdk.txt`) use plain code fences, not `ts`
|
|
104
|
+
> fences.** They document the type surface in compact form for visual
|
|
105
|
+
> scanning — they are not runnable programs and are exempt from CI
|
|
106
|
+
> type-checking. Runnable example snippets still use ```` ```ts ```` and are
|
|
107
|
+
> CI-gated against the published types.
|
|
108
|
+
|
|
68
109
|
## Patterns
|
|
69
110
|
|
|
70
111
|
### Paste-and-go assets — content-addressed URLs with SRI
|
|
71
112
|
|
|
72
|
-
`r.blobs.put` returns an `AssetRef`. The `
|
|
113
|
+
`r.blobs.put` returns an `AssetRef`. The `cdnUrl` is content-addressed (`pr-<public_id>.run402.com/_blob/<key>-<8hex>.<ext>`), served through CloudFront, and never needs cache invalidation. The browser refuses execution on byte mismatch via SRI:
|
|
73
114
|
|
|
74
115
|
```ts
|
|
75
116
|
const logo = await r.blobs.put(projectId, "logo.png", { bytes });
|
|
76
|
-
// logo.
|
|
77
|
-
// logo.sri
|
|
78
|
-
// logo.etag
|
|
79
|
-
// logo.
|
|
117
|
+
// logo.cdnUrl → drop into <img src="…">
|
|
118
|
+
// logo.sri → "sha256-…" for <script integrity="…">
|
|
119
|
+
// logo.etag → strong "sha256-<hex>"
|
|
120
|
+
// logo.cacheKind → "immutable" | "mutable" | "private"
|
|
80
121
|
```
|
|
81
122
|
|
|
82
123
|
`immutable: true` is the default since v1.45 — pass `false` only when you specifically want to skip the SHA-256 pass on a very large upload.
|
|
@@ -89,9 +130,9 @@ The canonical primitive for any deploy (database + migrations + manifest + secre
|
|
|
89
130
|
// One-shot — most agents use this.
|
|
90
131
|
const result = await r.deploy.apply(spec);
|
|
91
132
|
|
|
92
|
-
// Long-running with progress events.
|
|
133
|
+
// Long-running with progress events. Events are a discriminated union on `type`.
|
|
93
134
|
const op = await r.deploy.start(spec);
|
|
94
|
-
for await (const
|
|
135
|
+
for await (const ev of op.events()) console.log(ev.type);
|
|
95
136
|
const final = await op.result();
|
|
96
137
|
|
|
97
138
|
// Resume a previously-started deploy by id.
|
|
@@ -99,7 +140,7 @@ const resumed = await r.deploy.resume(operationId);
|
|
|
99
140
|
```
|
|
100
141
|
|
|
101
142
|
- **All bytes ride through CAS.** The plan request body never carries inline bytes — only `ContentRef` objects. When the spec exceeds 5 MB JSON, the SDK uploads the manifest itself as a CAS object (`manifest_ref` escape hatch).
|
|
102
|
-
- **
|
|
143
|
+
- **Per-resource semantics on the spec.** `site.replace` = "this is the whole site" (files absent are removed). `site.patch.put` / `patch.delete` are surgical updates. `functions.replace` / `functions.patch.set` / `functions.patch.delete` mirror that. `secrets.set` / `secrets.delete` / `secrets.replace_all` and `subdomains.set` / `subdomains.add` / `subdomains.remove` use their own shapes (see `ReleaseSpec` types). Top-level absence = leave untouched.
|
|
103
144
|
- **Server-authoritative manifest digest** — no byte-for-byte canonicalize requirement on the client.
|
|
104
145
|
- The Node entry adds `fileSetFromDir(path)` for filesystem byte sources:
|
|
105
146
|
|
|
@@ -107,42 +148,109 @@ const resumed = await r.deploy.resume(operationId);
|
|
|
107
148
|
import { run402, fileSetFromDir } from "@run402/sdk/node";
|
|
108
149
|
const r = run402();
|
|
109
150
|
await r.deploy.apply({
|
|
110
|
-
|
|
111
|
-
site: { replace:
|
|
112
|
-
subdomains: {
|
|
151
|
+
project: projectId,
|
|
152
|
+
site: { replace: await fileSetFromDir("./dist") },
|
|
153
|
+
subdomains: { set: ["my-app"] },
|
|
113
154
|
});
|
|
114
155
|
```
|
|
115
156
|
|
|
116
157
|
### Errors
|
|
117
158
|
|
|
118
|
-
All failures throw subclasses of `Run402Error
|
|
159
|
+
All failures throw subclasses of `Run402Error`. Every subclass carries a stable
|
|
160
|
+
`kind` discriminator string and an `isRun402Error` brand:
|
|
161
|
+
|
|
162
|
+
| Class | `kind` | When | Notable fields |
|
|
163
|
+
|---|---|---|---|
|
|
164
|
+
| `PaymentRequired` | `"payment_required"` | HTTP 402 | x402 payment requirements in `body` |
|
|
165
|
+
| `ProjectNotFound` | `"project_not_found"` | Project ID not in the credential provider | `projectId` |
|
|
166
|
+
| `Unauthorized` | `"unauthorized"` | HTTP 401 / 403 | — |
|
|
167
|
+
| `ApiError` | `"api_error"` | Other non-2xx responses | `status`, `body` |
|
|
168
|
+
| `NetworkError` | `"network_error"` | Fetch rejected with no HTTP response | `cause` |
|
|
169
|
+
| `LocalError` | `"local_error"` | Local-host issues (filesystem, signing) | `cause` |
|
|
170
|
+
| `Run402DeployError` | `"deploy_error"` | Structured envelope from the deploy state machine (v1.34+) | `code`, `phase`, `operationId`, `safeToRetry`, `mutationState`, `nextActions` |
|
|
171
|
+
|
|
172
|
+
**Branch with type guards, not `instanceof`.** `instanceof X` is an identity
|
|
173
|
+
check on the class object — it fails silently when the consumer's runtime
|
|
174
|
+
holds a different copy of the SDK (duplicate npm installs, bundler chunk
|
|
175
|
+
splits, ESM/CJS interop, V8-isolate realms). The exported guards
|
|
176
|
+
(`isPaymentRequired`, `isDeployError`, …) check `isRun402Error` + `kind`,
|
|
177
|
+
which is identity-free and survives all of those scenarios. `instanceof`
|
|
178
|
+
continues to work for back-compat in the simple single-copy case.
|
|
119
179
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
180
|
+
```ts
|
|
181
|
+
import {
|
|
182
|
+
run402,
|
|
183
|
+
isPaymentRequired,
|
|
184
|
+
isDeployError,
|
|
185
|
+
type ReleaseSpec,
|
|
186
|
+
} from "@run402/sdk/node";
|
|
187
|
+
|
|
188
|
+
declare const spec: ReleaseSpec;
|
|
189
|
+
const r = run402();
|
|
129
190
|
|
|
130
|
-
|
|
191
|
+
try {
|
|
192
|
+
await r.deploy.apply(spec);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
if (isPaymentRequired(e)) {
|
|
195
|
+
// e is narrowed to PaymentRequired
|
|
196
|
+
// present payment requirements to the user — read e.body, e.context, etc.
|
|
197
|
+
} else if (isDeployError(e) && e.safeToRetry) {
|
|
198
|
+
// e is narrowed to Run402DeployError; it's safe to retry with the same idempotency key
|
|
199
|
+
} else throw e;
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`Run402Error.toJSON()` returns a canonical envelope, so `JSON.stringify(e)`
|
|
204
|
+
produces a populated structured object instead of the empty `"{}"` plain
|
|
205
|
+
`Error` produces. Use this for telemetry, MCP tool results, CLI JSON output,
|
|
206
|
+
and any inter-process boundary where the error needs to survive serialization.
|
|
207
|
+
|
|
208
|
+
#### Retry idempotent operations with `withRetry`
|
|
209
|
+
|
|
210
|
+
`withRetry(fn, opts?)` wraps any async call with exponential backoff. It uses
|
|
211
|
+
`isRetryableRun402Error` (the canonical "should I retry this?" policy: 408 /
|
|
212
|
+
425 / 429 / 5xx / `NetworkError` / gateway-flagged `retryable` or
|
|
213
|
+
`safeToRetry`) by default. Pair it with the SDK method's own
|
|
214
|
+
`idempotencyKey` so retried mutations dedup server-side:
|
|
131
215
|
|
|
132
216
|
```ts
|
|
133
|
-
import {
|
|
217
|
+
import {
|
|
218
|
+
run402,
|
|
219
|
+
withRetry,
|
|
220
|
+
isPaymentRequired,
|
|
221
|
+
isDeployError,
|
|
222
|
+
type ReleaseSpec,
|
|
223
|
+
} from "@run402/sdk/node";
|
|
224
|
+
|
|
225
|
+
declare const spec: ReleaseSpec;
|
|
226
|
+
const r = run402();
|
|
134
227
|
|
|
135
228
|
try {
|
|
136
|
-
await
|
|
229
|
+
const release = await withRetry(
|
|
230
|
+
() => r.deploy.apply(spec, { idempotencyKey: "deploy-2026-05-01" }),
|
|
231
|
+
{
|
|
232
|
+
attempts: 3,
|
|
233
|
+
onRetry: (e, attempt, delayMs) =>
|
|
234
|
+
process.stderr.write(`retry ${attempt} in ${delayMs}ms\n`),
|
|
235
|
+
},
|
|
236
|
+
);
|
|
237
|
+
console.log(release.urls);
|
|
137
238
|
} catch (e) {
|
|
138
|
-
if (e
|
|
139
|
-
// present payment
|
|
140
|
-
} else if (e
|
|
141
|
-
//
|
|
239
|
+
if (isPaymentRequired(e)) {
|
|
240
|
+
// ... present payment
|
|
241
|
+
} else if (isDeployError(e)) {
|
|
242
|
+
// log structured envelope for triage
|
|
243
|
+
process.stderr.write(JSON.stringify(e) + "\n");
|
|
142
244
|
} else throw e;
|
|
143
245
|
}
|
|
144
246
|
```
|
|
145
247
|
|
|
248
|
+
Defaults: 3 attempts (1 initial + 2 retries), 250 ms base delay, 5 s cap. Pass
|
|
249
|
+
a custom `retryIf` to override the default policy (e.g., retry on
|
|
250
|
+
`PaymentRequired` if your sandbox auto-funds). After exhausting attempts
|
|
251
|
+
`withRetry` throws the LAST error — your catch handler sees the original
|
|
252
|
+
structured envelope, not a wrapper.
|
|
253
|
+
|
|
146
254
|
The SDK never calls `process.exit`. Each interface (MCP tools, CLI, your code) wraps with its own error behavior.
|
|
147
255
|
|
|
148
256
|
## Stability
|
package/dist/errors.d.ts
CHANGED
|
@@ -2,8 +2,34 @@
|
|
|
2
2
|
* Error hierarchy for the Run402 SDK. Every failure throws a subclass of
|
|
3
3
|
* {@link Run402Error}. Consumers (MCP handlers, CLI commands, user functions)
|
|
4
4
|
* translate these into their native error shapes at the edge.
|
|
5
|
+
*
|
|
6
|
+
* Branch on {@link Run402Error.kind} (or the exported `is*` type guards) rather
|
|
7
|
+
* than `instanceof`. Discriminator-based checks survive duplicate SDK installs,
|
|
8
|
+
* bundler chunk splits, ESM/CJS interop, and V8-isolate realm boundaries —
|
|
9
|
+
* any setting where a class object's identity might differ from the consumer's
|
|
10
|
+
* own class object reference. `instanceof X` continues to work for callers
|
|
11
|
+
* holding a single SDK copy (back-compat); the guards are the recommended path.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Stable string discriminator on every {@link Run402Error} subclass. Use this
|
|
15
|
+
* (or the exported `is*` guards) to branch on errors safely across SDK copies
|
|
16
|
+
* and realms — value comparison, no class-identity dependency.
|
|
5
17
|
*/
|
|
18
|
+
export type Run402ErrorKind = "payment_required" | "project_not_found" | "unauthorized" | "api_error" | "network_error" | "local_error" | "deploy_error";
|
|
6
19
|
export declare abstract class Run402Error extends Error {
|
|
20
|
+
/**
|
|
21
|
+
* Structural brand. Always `true` on any {@link Run402Error} subclass
|
|
22
|
+
* instance, regardless of which SDK copy created it. The exported
|
|
23
|
+
* {@link isRun402Error} guard checks this field instead of `instanceof`,
|
|
24
|
+
* so cross-realm and cross-bundle errors still match.
|
|
25
|
+
*/
|
|
26
|
+
readonly isRun402Error: true;
|
|
27
|
+
/**
|
|
28
|
+
* Stable string discriminator. Branch on `e.kind === "..."` (or the
|
|
29
|
+
* exported subclass guards) rather than `e instanceof X`. Equality on
|
|
30
|
+
* `kind` survives duplicate SDK copies and cross-realm errors.
|
|
31
|
+
*/
|
|
32
|
+
abstract readonly kind: Run402ErrorKind;
|
|
7
33
|
/** HTTP status, or null for local/network failures that produced no response. */
|
|
8
34
|
readonly status: number | null;
|
|
9
35
|
/** Parsed response body, or null when no body was received. */
|
|
@@ -27,28 +53,42 @@ export declare abstract class Run402Error extends Error {
|
|
|
27
53
|
/** Advisory next actions from the gateway. Rendering them must not execute them. */
|
|
28
54
|
readonly nextActions?: unknown[];
|
|
29
55
|
constructor(message: string, status: number | null, body: unknown, context: string);
|
|
56
|
+
/**
|
|
57
|
+
* Canonical structured envelope for `JSON.stringify`. Without this, an
|
|
58
|
+
* `Error` instance serializes as `"{}"` (its built-in fields are
|
|
59
|
+
* non-enumerable), losing every structured detail an agent needs for
|
|
60
|
+
* triage. Subclasses with extra fields (e.g. {@link Run402DeployError})
|
|
61
|
+
* override and spread `super.toJSON()`.
|
|
62
|
+
*/
|
|
63
|
+
toJSON(): Record<string, unknown>;
|
|
30
64
|
}
|
|
31
65
|
/** HTTP 402 — the gateway requires payment (lease expired, insufficient balance, or x402 quote). */
|
|
32
66
|
export declare class PaymentRequired extends Run402Error {
|
|
67
|
+
readonly kind: "payment_required";
|
|
33
68
|
}
|
|
34
69
|
/** Project ID is not present in the credential provider (local miss) or the gateway returned 404. */
|
|
35
70
|
export declare class ProjectNotFound extends Run402Error {
|
|
71
|
+
readonly kind: "project_not_found";
|
|
36
72
|
readonly projectId: string;
|
|
37
73
|
constructor(projectId: string, context: string, status?: number | null, body?: unknown);
|
|
38
74
|
}
|
|
39
75
|
/** HTTP 401 or 403 — authentication missing, invalid, or insufficient for the operation. */
|
|
40
76
|
export declare class Unauthorized extends Run402Error {
|
|
77
|
+
readonly kind: "unauthorized";
|
|
41
78
|
}
|
|
42
79
|
/** Any other non-2xx HTTP response from the gateway. */
|
|
43
80
|
export declare class ApiError extends Run402Error {
|
|
81
|
+
readonly kind: "api_error";
|
|
44
82
|
}
|
|
45
83
|
/** The underlying `fetch` threw before producing a response (DNS, connection reset, offline). */
|
|
46
84
|
export declare class NetworkError extends Run402Error {
|
|
85
|
+
readonly kind: "network_error";
|
|
47
86
|
readonly cause: unknown;
|
|
48
87
|
constructor(message: string, cause: unknown, context: string);
|
|
49
88
|
}
|
|
50
89
|
/** Local/filesystem error — input validation, missing path, unreadable dir. No HTTP involved. */
|
|
51
90
|
export declare class LocalError extends Run402Error {
|
|
91
|
+
readonly kind: "local_error";
|
|
52
92
|
readonly cause?: unknown;
|
|
53
93
|
constructor(message: string, context: string, cause?: unknown);
|
|
54
94
|
}
|
|
@@ -69,6 +109,7 @@ export interface Run402DeployErrorFix {
|
|
|
69
109
|
[key: string]: unknown;
|
|
70
110
|
}
|
|
71
111
|
export declare class Run402DeployError extends Run402Error {
|
|
112
|
+
readonly kind: "deploy_error";
|
|
72
113
|
readonly code: Run402DeployErrorCode;
|
|
73
114
|
readonly phase: string | null;
|
|
74
115
|
readonly resource: string | null;
|
|
@@ -92,5 +133,37 @@ export declare class Run402DeployError extends Run402Error {
|
|
|
92
133
|
body?: unknown;
|
|
93
134
|
context: string;
|
|
94
135
|
});
|
|
136
|
+
toJSON(): Record<string, unknown>;
|
|
95
137
|
}
|
|
138
|
+
/** True if `e` is any {@link Run402Error} subclass instance, regardless of which SDK copy created it. */
|
|
139
|
+
export declare function isRun402Error(e: unknown): e is Run402Error;
|
|
140
|
+
/** True if `e` is a {@link PaymentRequired}. Survives duplicate SDK copies and realms. */
|
|
141
|
+
export declare function isPaymentRequired(e: unknown): e is PaymentRequired;
|
|
142
|
+
/** True if `e` is a {@link ProjectNotFound}. */
|
|
143
|
+
export declare function isProjectNotFound(e: unknown): e is ProjectNotFound;
|
|
144
|
+
/** True if `e` is an {@link Unauthorized}. */
|
|
145
|
+
export declare function isUnauthorized(e: unknown): e is Unauthorized;
|
|
146
|
+
/** True if `e` is an {@link ApiError}. */
|
|
147
|
+
export declare function isApiError(e: unknown): e is ApiError;
|
|
148
|
+
/** True if `e` is a {@link NetworkError}. */
|
|
149
|
+
export declare function isNetworkError(e: unknown): e is NetworkError;
|
|
150
|
+
/** True if `e` is a {@link LocalError}. */
|
|
151
|
+
export declare function isLocalError(e: unknown): e is LocalError;
|
|
152
|
+
/** True if `e` is a {@link Run402DeployError}. */
|
|
153
|
+
export declare function isDeployError(e: unknown): e is Run402DeployError;
|
|
154
|
+
/**
|
|
155
|
+
* Canonical "should I retry this?" policy. Returns true when `e` is a
|
|
156
|
+
* {@link Run402Error} AND any of:
|
|
157
|
+
* - `e.retryable === true` (gateway flagged it)
|
|
158
|
+
* - `e.safeToRetry === true` (gateway flagged it)
|
|
159
|
+
* - `e.kind === "network_error"` (fetch never produced a response)
|
|
160
|
+
* - `e.status` is 408 (Request Timeout), 425 (Too Early), or 429 (Too Many
|
|
161
|
+
* Requests)
|
|
162
|
+
* - `e.status` is a 5xx server error
|
|
163
|
+
*
|
|
164
|
+
* Returns false for non-Run402 errors so it can be safely called with
|
|
165
|
+
* `unknown` from a catch block. Used as the default `retryIf` in
|
|
166
|
+
* {@link withRetry}.
|
|
167
|
+
*/
|
|
168
|
+
export declare function isRetryableRun402Error(e: unknown): boolean;
|
|
96
169
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACvB,kBAAkB,GAClB,mBAAmB,GACnB,cAAc,GACd,WAAW,GACX,eAAe,GACf,aAAa,GACb,cAAc,CAAC;AAEnB,8BAAsB,WAAY,SAAQ,KAAK;IAC7C;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAG,IAAI,CAAU;IACvC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,C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AO,GAAG,CAAC,IAAI,WAAW,CAM1D;AAED,0FAA0F;AAC1F,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,eAAe,CAElE;AAED,gDAAgD;AAChD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,eAAe,CAElE;AAED,8CAA8C;AAC9C,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,YAAY,CAE5D;AAED,0CAA0C;AAC1C,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,QAAQ,CAEpD;AAED,6CAA6C;AAC7C,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,YAAY,CAE5D;AAED,2CAA2C;AAC3C,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,UAAU,CAExD;AAED,kDAAkD;AAClD,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,iBAAiB,CAEhE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAQ1D"}
|
package/dist/errors.js
CHANGED
|
@@ -2,8 +2,22 @@
|
|
|
2
2
|
* Error hierarchy for the Run402 SDK. Every failure throws a subclass of
|
|
3
3
|
* {@link Run402Error}. Consumers (MCP handlers, CLI commands, user functions)
|
|
4
4
|
* translate these into their native error shapes at the edge.
|
|
5
|
+
*
|
|
6
|
+
* Branch on {@link Run402Error.kind} (or the exported `is*` type guards) rather
|
|
7
|
+
* than `instanceof`. Discriminator-based checks survive duplicate SDK installs,
|
|
8
|
+
* bundler chunk splits, ESM/CJS interop, and V8-isolate realm boundaries —
|
|
9
|
+
* any setting where a class object's identity might differ from the consumer's
|
|
10
|
+
* own class object reference. `instanceof X` continues to work for callers
|
|
11
|
+
* holding a single SDK copy (back-compat); the guards are the recommended path.
|
|
5
12
|
*/
|
|
6
13
|
export class Run402Error extends Error {
|
|
14
|
+
/**
|
|
15
|
+
* Structural brand. Always `true` on any {@link Run402Error} subclass
|
|
16
|
+
* instance, regardless of which SDK copy created it. The exported
|
|
17
|
+
* {@link isRun402Error} guard checks this field instead of `instanceof`,
|
|
18
|
+
* so cross-realm and cross-bundle errors still match.
|
|
19
|
+
*/
|
|
20
|
+
isRun402Error = true;
|
|
7
21
|
/** HTTP status, or null for local/network failures that produced no response. */
|
|
8
22
|
status;
|
|
9
23
|
/** Parsed response body, or null when no body was received. */
|
|
@@ -51,6 +65,31 @@ export class Run402Error extends Error {
|
|
|
51
65
|
if (Array.isArray(envelope?.next_actions))
|
|
52
66
|
this.nextActions = envelope.next_actions;
|
|
53
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Canonical structured envelope for `JSON.stringify`. Without this, an
|
|
70
|
+
* `Error` instance serializes as `"{}"` (its built-in fields are
|
|
71
|
+
* non-enumerable), losing every structured detail an agent needs for
|
|
72
|
+
* triage. Subclasses with extra fields (e.g. {@link Run402DeployError})
|
|
73
|
+
* override and spread `super.toJSON()`.
|
|
74
|
+
*/
|
|
75
|
+
toJSON() {
|
|
76
|
+
return {
|
|
77
|
+
name: this.name,
|
|
78
|
+
kind: this.kind,
|
|
79
|
+
message: this.message,
|
|
80
|
+
status: this.status,
|
|
81
|
+
code: this.code,
|
|
82
|
+
category: this.category,
|
|
83
|
+
retryable: this.retryable,
|
|
84
|
+
safeToRetry: this.safeToRetry,
|
|
85
|
+
mutationState: this.mutationState,
|
|
86
|
+
traceId: this.traceId,
|
|
87
|
+
context: this.context,
|
|
88
|
+
details: this.details,
|
|
89
|
+
nextActions: this.nextActions,
|
|
90
|
+
body: this.body,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
54
93
|
}
|
|
55
94
|
function canonicalEnvelope(body) {
|
|
56
95
|
return body && typeof body === "object" && !Array.isArray(body)
|
|
@@ -59,9 +98,11 @@ function canonicalEnvelope(body) {
|
|
|
59
98
|
}
|
|
60
99
|
/** HTTP 402 — the gateway requires payment (lease expired, insufficient balance, or x402 quote). */
|
|
61
100
|
export class PaymentRequired extends Run402Error {
|
|
101
|
+
kind = "payment_required";
|
|
62
102
|
}
|
|
63
103
|
/** Project ID is not present in the credential provider (local miss) or the gateway returned 404. */
|
|
64
104
|
export class ProjectNotFound extends Run402Error {
|
|
105
|
+
kind = "project_not_found";
|
|
65
106
|
projectId;
|
|
66
107
|
constructor(projectId, context, status = null, body = null) {
|
|
67
108
|
super(`Project ${projectId} not found`, status, body, context);
|
|
@@ -70,12 +111,15 @@ export class ProjectNotFound extends Run402Error {
|
|
|
70
111
|
}
|
|
71
112
|
/** HTTP 401 or 403 — authentication missing, invalid, or insufficient for the operation. */
|
|
72
113
|
export class Unauthorized extends Run402Error {
|
|
114
|
+
kind = "unauthorized";
|
|
73
115
|
}
|
|
74
116
|
/** Any other non-2xx HTTP response from the gateway. */
|
|
75
117
|
export class ApiError extends Run402Error {
|
|
118
|
+
kind = "api_error";
|
|
76
119
|
}
|
|
77
120
|
/** The underlying `fetch` threw before producing a response (DNS, connection reset, offline). */
|
|
78
121
|
export class NetworkError extends Run402Error {
|
|
122
|
+
kind = "network_error";
|
|
79
123
|
cause;
|
|
80
124
|
constructor(message, cause, context) {
|
|
81
125
|
super(message, null, null, context);
|
|
@@ -84,6 +128,7 @@ export class NetworkError extends Run402Error {
|
|
|
84
128
|
}
|
|
85
129
|
/** Local/filesystem error — input validation, missing path, unreadable dir. No HTTP involved. */
|
|
86
130
|
export class LocalError extends Run402Error {
|
|
131
|
+
kind = "local_error";
|
|
87
132
|
cause;
|
|
88
133
|
constructor(message, context, cause) {
|
|
89
134
|
super(message, null, null, context);
|
|
@@ -92,6 +137,7 @@ export class LocalError extends Run402Error {
|
|
|
92
137
|
}
|
|
93
138
|
}
|
|
94
139
|
export class Run402DeployError extends Run402Error {
|
|
140
|
+
kind = "deploy_error";
|
|
95
141
|
code;
|
|
96
142
|
phase;
|
|
97
143
|
resource;
|
|
@@ -113,5 +159,87 @@ export class Run402DeployError extends Run402Error {
|
|
|
113
159
|
this.logs = init.logs ?? null;
|
|
114
160
|
this.rolledBack = init.rolledBack ?? false;
|
|
115
161
|
}
|
|
162
|
+
toJSON() {
|
|
163
|
+
return {
|
|
164
|
+
...super.toJSON(),
|
|
165
|
+
phase: this.phase,
|
|
166
|
+
resource: this.resource,
|
|
167
|
+
operationId: this.operationId,
|
|
168
|
+
planId: this.planId,
|
|
169
|
+
fix: this.fix,
|
|
170
|
+
logs: this.logs,
|
|
171
|
+
rolledBack: this.rolledBack,
|
|
172
|
+
retryable: this.retryable,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// ─── Type guards ─────────────────────────────────────────────────────────────
|
|
177
|
+
//
|
|
178
|
+
// Identity-free guards. Each one checks the structural brand and (for subclass
|
|
179
|
+
// guards) the `kind` discriminator. Use these instead of `instanceof X` so the
|
|
180
|
+
// check survives duplicate SDK installs, bundler chunk splits, ESM/CJS interop,
|
|
181
|
+
// and V8-isolate realm boundaries — anywhere the consumer's class object
|
|
182
|
+
// reference might differ from the throw site's.
|
|
183
|
+
/** True if `e` is any {@link Run402Error} subclass instance, regardless of which SDK copy created it. */
|
|
184
|
+
export function isRun402Error(e) {
|
|
185
|
+
return Boolean(e &&
|
|
186
|
+
typeof e === "object" &&
|
|
187
|
+
e.isRun402Error === true);
|
|
188
|
+
}
|
|
189
|
+
/** True if `e` is a {@link PaymentRequired}. Survives duplicate SDK copies and realms. */
|
|
190
|
+
export function isPaymentRequired(e) {
|
|
191
|
+
return isRun402Error(e) && e.kind === "payment_required";
|
|
192
|
+
}
|
|
193
|
+
/** True if `e` is a {@link ProjectNotFound}. */
|
|
194
|
+
export function isProjectNotFound(e) {
|
|
195
|
+
return isRun402Error(e) && e.kind === "project_not_found";
|
|
196
|
+
}
|
|
197
|
+
/** True if `e` is an {@link Unauthorized}. */
|
|
198
|
+
export function isUnauthorized(e) {
|
|
199
|
+
return isRun402Error(e) && e.kind === "unauthorized";
|
|
200
|
+
}
|
|
201
|
+
/** True if `e` is an {@link ApiError}. */
|
|
202
|
+
export function isApiError(e) {
|
|
203
|
+
return isRun402Error(e) && e.kind === "api_error";
|
|
204
|
+
}
|
|
205
|
+
/** True if `e` is a {@link NetworkError}. */
|
|
206
|
+
export function isNetworkError(e) {
|
|
207
|
+
return isRun402Error(e) && e.kind === "network_error";
|
|
208
|
+
}
|
|
209
|
+
/** True if `e` is a {@link LocalError}. */
|
|
210
|
+
export function isLocalError(e) {
|
|
211
|
+
return isRun402Error(e) && e.kind === "local_error";
|
|
212
|
+
}
|
|
213
|
+
/** True if `e` is a {@link Run402DeployError}. */
|
|
214
|
+
export function isDeployError(e) {
|
|
215
|
+
return isRun402Error(e) && e.kind === "deploy_error";
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Canonical "should I retry this?" policy. Returns true when `e` is a
|
|
219
|
+
* {@link Run402Error} AND any of:
|
|
220
|
+
* - `e.retryable === true` (gateway flagged it)
|
|
221
|
+
* - `e.safeToRetry === true` (gateway flagged it)
|
|
222
|
+
* - `e.kind === "network_error"` (fetch never produced a response)
|
|
223
|
+
* - `e.status` is 408 (Request Timeout), 425 (Too Early), or 429 (Too Many
|
|
224
|
+
* Requests)
|
|
225
|
+
* - `e.status` is a 5xx server error
|
|
226
|
+
*
|
|
227
|
+
* Returns false for non-Run402 errors so it can be safely called with
|
|
228
|
+
* `unknown` from a catch block. Used as the default `retryIf` in
|
|
229
|
+
* {@link withRetry}.
|
|
230
|
+
*/
|
|
231
|
+
export function isRetryableRun402Error(e) {
|
|
232
|
+
if (!isRun402Error(e))
|
|
233
|
+
return false;
|
|
234
|
+
if (e.retryable === true || e.safeToRetry === true)
|
|
235
|
+
return true;
|
|
236
|
+
if (e.kind === "network_error")
|
|
237
|
+
return true;
|
|
238
|
+
const s = e.status;
|
|
239
|
+
if (s === 408 || s === 425 || s === 429)
|
|
240
|
+
return true;
|
|
241
|
+
if (typeof s === "number" && s >= 500)
|
|
242
|
+
return true;
|
|
243
|
+
return false;
|
|
116
244
|
}
|
|
117
245
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAgBH,MAAM,OAAgB,WAAY,SAAQ,KAAK;IAC7C;;;;;OAKG;IACM,aAAa,GAAG,IAAa,CAAC;IAOvC,iFAAiF;IACxE,MAAM,CAAgB;IAC/B,+DAA+D;IACtD,IAAI,CAAU;IACvB,2FAA2F;IAClF,OAAO,CAAS;IACzB,mFAAmF;IAC1E,IAAI,CAAU;IACvB,+DAA+D;IACtD,QAAQ,CAAU;IAC3B,kDAAkD;IACzC,SAAS,CAAW;IAC7B,yFAAyF;IAChF,WAAW,CAAW;IAC/B,sEAAsE;IAC7D,aAAa,CAAU;IAChC,+CAA+C;IACtC,OAAO,CAAU;IAC1B,mFAAmF;IAC1E,OAAO,CAAW;IAC3B,oFAAoF;IAC3E,WAAW,CAAa;IAEjC,YAAY,OAAe,EAAE,MAAqB,EAAE,IAAa,EAAE,OAAe;QAChF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,OAAO,QAAQ,EAAE,IAAI,KAAK,QAAQ;YAAE,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAA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