@artblocks/abx-sdk 0.1.0-alpha.2 → 0.1.0-alpha.20
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 +131 -0
- package/dist/abi/generated.d.ts +8502 -129
- package/dist/abi/generated.d.ts.map +1 -1
- package/dist/abi/generated.js +40 -22
- package/dist/abi/generated.js.map +1 -1
- package/dist/abi/index.d.ts +2645 -168
- package/dist/abi/index.d.ts.map +1 -1
- package/dist/abi/index.js +34 -7
- package/dist/abi/index.js.map +1 -1
- package/dist/anchors.d.ts +266 -0
- package/dist/anchors.d.ts.map +1 -0
- package/dist/anchors.js +653 -0
- package/dist/anchors.js.map +1 -0
- package/dist/chains.d.ts +15 -9
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +19 -15
- package/dist/chains.js.map +1 -1
- package/dist/chunks.d.ts +53 -23
- package/dist/chunks.d.ts.map +1 -1
- package/dist/chunks.js +68 -6
- package/dist/chunks.js.map +1 -1
- package/dist/clients.d.ts +23 -11
- package/dist/clients.d.ts.map +1 -1
- package/dist/clients.js +17 -18
- package/dist/clients.js.map +1 -1
- package/dist/create2.d.ts +85 -1
- package/dist/create2.d.ts.map +1 -1
- package/dist/create2.js +159 -2
- package/dist/create2.js.map +1 -1
- package/dist/creator-token.d.ts +132 -0
- package/dist/creator-token.d.ts.map +1 -0
- package/dist/creator-token.js +183 -0
- package/dist/creator-token.js.map +1 -0
- package/dist/deploy.d.ts +234 -14
- package/dist/deploy.d.ts.map +1 -1
- package/dist/deploy.js +289 -111
- package/dist/deploy.js.map +1 -1
- package/dist/deployments.d.ts +12 -0
- package/dist/deployments.d.ts.map +1 -1
- package/dist/deployments.js +155 -28
- package/dist/deployments.js.map +1 -1
- package/dist/deps.d.ts +122 -5
- package/dist/deps.d.ts.map +1 -1
- package/dist/deps.js +248 -6
- package/dist/deps.js.map +1 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +8 -0
- package/dist/env.js.map +1 -1
- package/dist/errors.d.ts +94 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +126 -0
- package/dist/errors.js.map +1 -0
- package/dist/execute.d.ts +115 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +142 -0
- package/dist/execute.js.map +1 -0
- package/dist/gateways.d.ts +79 -0
- package/dist/gateways.d.ts.map +1 -0
- package/dist/gateways.js +156 -0
- package/dist/gateways.js.map +1 -0
- package/dist/generator-document.d.ts +58 -0
- package/dist/generator-document.d.ts.map +1 -0
- package/dist/generator-document.js +124 -0
- package/dist/generator-document.js.map +1 -0
- package/dist/generator.d.ts +43 -1
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +29 -0
- package/dist/generator.js.map +1 -1
- package/dist/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/dist/inspect.d.ts +48 -0
- package/dist/inspect.d.ts.map +1 -0
- package/dist/inspect.js +295 -0
- package/dist/inspect.js.map +1 -0
- package/dist/migrate.d.ts +41 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +140 -0
- package/dist/migrate.js.map +1 -0
- package/dist/mime.d.ts +11 -0
- package/dist/mime.d.ts.map +1 -0
- package/dist/mime.js +40 -0
- package/dist/mime.js.map +1 -0
- package/dist/node.d.ts +10 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +24 -0
- package/dist/node.js.map +1 -0
- package/dist/onchain-uri.d.ts +110 -0
- package/dist/onchain-uri.d.ts.map +1 -0
- package/dist/onchain-uri.js +273 -0
- package/dist/onchain-uri.js.map +1 -0
- package/dist/ops.d.ts +507 -14
- package/dist/ops.d.ts.map +1 -1
- package/dist/ops.js +848 -32
- package/dist/ops.js.map +1 -1
- package/dist/probe.d.ts +29 -0
- package/dist/probe.d.ts.map +1 -1
- package/dist/probe.js +104 -9
- package/dist/probe.js.map +1 -1
- package/dist/reconstruct.d.ts +92 -2
- package/dist/reconstruct.d.ts.map +1 -1
- package/dist/reconstruct.js +378 -93
- package/dist/reconstruct.js.map +1 -1
- package/dist/resume.d.ts +96 -0
- package/dist/resume.d.ts.map +1 -0
- package/dist/resume.js +95 -0
- package/dist/resume.js.map +1 -0
- package/dist/script-chunks.d.ts +24 -0
- package/dist/script-chunks.d.ts.map +1 -0
- package/dist/script-chunks.js +63 -0
- package/dist/script-chunks.js.map +1 -0
- package/dist/service.d.ts +188 -9
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +228 -18
- package/dist/service.js.map +1 -1
- package/dist/spine.d.ts +31 -4
- package/dist/spine.d.ts.map +1 -1
- package/dist/spine.js +0 -0
- package/dist/spine.js.map +1 -1
- package/dist/staging.d.ts +124 -0
- package/dist/staging.d.ts.map +1 -0
- package/dist/staging.js +134 -0
- package/dist/staging.js.map +1 -0
- package/dist/tokendata.d.ts +62 -2
- package/dist/tokendata.d.ts.map +1 -1
- package/dist/tokendata.js +79 -17
- package/dist/tokendata.js.map +1 -1
- package/dist/tokens.d.ts +94 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +296 -0
- package/dist/tokens.js.map +1 -0
- package/dist/types.d.ts +60 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/util.d.ts +74 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +106 -0
- package/dist/util.js.map +1 -0
- package/package.json +10 -2
package/dist/service.d.ts
CHANGED
|
@@ -11,13 +11,87 @@
|
|
|
11
11
|
import type { Hex } from 'viem';
|
|
12
12
|
import type { OpenSeaAttribute } from './traits.js';
|
|
13
13
|
export declare const WELL_KNOWN_SERVICE_PATH = "/.well-known/abx-service";
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
14
|
+
/**
|
|
15
|
+
* Versioned interface ids a service declares in its descriptor. Versions ride these ids
|
|
16
|
+
* (they track the `/v1` path prefix); the descriptor has no separate format version.
|
|
17
|
+
*
|
|
18
|
+
* There are exactly two, and they are **all-or-nothing**: declaring one asserts every route it names
|
|
19
|
+
* answers per the spec. The artifact-registry routes ride {@link CONTROL_PLANE_INTERFACE} rather
|
|
20
|
+
* than an id of their own — once referenced output is locator-only, accepting a registration is a
|
|
21
|
+
* database insert, so a separate capability flag would describe a distinction that doesn't exist.
|
|
22
|
+
* A service that won't take a given caller's artifacts refuses on the credential (`403`), which is
|
|
23
|
+
* the honest axis: interfaces describe wire grammar, tokens describe permission.
|
|
24
|
+
*/
|
|
16
25
|
export declare const TOKEN_API_INTERFACE = "abx-token-api/v1";
|
|
17
26
|
export declare const CONTROL_PLANE_INTERFACE = "abx-control-plane/v1";
|
|
18
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Why this locator can't be accepted for a referenced artifact, or `null` if it passes.
|
|
29
|
+
*
|
|
30
|
+
* A locator is a **reachability** claim, not a durability one: it must resolve for a third party
|
|
31
|
+
* with no producer credentials and no private-network assumption. The protocol deliberately has
|
|
32
|
+
* **no preference among schemes** — `https://` (S3/R2, a producer's own public base, a chosen
|
|
33
|
+
* IPFS/Arweave gateway), `ipfs://` and `ar://` are peers, because derived output is re-creatable and
|
|
34
|
+
* a producer with an opinion about which gateway serves its content is making an operational call the
|
|
35
|
+
* protocol has no standing to override.
|
|
36
|
+
*
|
|
37
|
+
* Reachability can't be *proved* without fetching, and fetching a third-party URL while handling an
|
|
38
|
+
* authed write is byte custody through the back door plus an SSRF surface. So this checks the two
|
|
39
|
+
* things that are decidable from the string alone and are always wrong:
|
|
40
|
+
* - a private / loopback host — resolvable only from the producer's own network;
|
|
41
|
+
* - a presigned, expiring URL — resolvable now, dead later, which is the worst failure shape
|
|
42
|
+
* (it passes every check at publish time and rots silently).
|
|
43
|
+
*/
|
|
44
|
+
export declare function locatorRejectionReason(locator: string): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* The indexing lifecycle a registration moves through, closed and provider-neutral
|
|
47
|
+
* (specs/self-host-toolkit/remote-services.md → The indexing lifecycle). One vocabulary for a
|
|
48
|
+
* managed provider and for your own node — the reference resolver stamps these too.
|
|
49
|
+
*
|
|
50
|
+
* queued registered + accepted; catch-up hasn't started
|
|
51
|
+
* backfilling actively catching up (initial sync or a forced replay); may already serve partial state
|
|
52
|
+
* live caught up to head; tracking head incrementally
|
|
53
|
+
* stale was live, now lagging (watcher behind, or transient RPC trouble) — still serving
|
|
54
|
+
* failed catch-up errored; carries `error`; will be retried
|
|
55
|
+
*
|
|
56
|
+
* Observability, never a source of truth: token resolution never consults it, and a project
|
|
57
|
+
* reconstructs from chain regardless.
|
|
58
|
+
*/
|
|
59
|
+
export type IndexStatus = 'queued' | 'backfilling' | 'live' | 'stale' | 'failed';
|
|
60
|
+
/** Statuses a caller can stop waiting on — see {@link AbxServiceClient.awaitIndexed}. */
|
|
61
|
+
export declare const TERMINAL_INDEX_STATUSES: readonly IndexStatus[];
|
|
62
|
+
/**
|
|
63
|
+
* Why catch-up failed, as a closed machine class — never free-form prose the client must parse.
|
|
64
|
+
* Deliberately NOT extended with a reorg class: the protocol defines no reorg detection (the repair
|
|
65
|
+
* is the deterministic full replay), so no implementation could emit one honestly.
|
|
66
|
+
*/
|
|
67
|
+
export type IndexErrorClass =
|
|
68
|
+
/** The RPC didn't answer (down, timing out, network). Retryable — nothing is wrong with the add. */
|
|
69
|
+
'rpc_unavailable'
|
|
70
|
+
/** The RPC answered "too many requests". Retryable, slower — the usual cause of a long backfill. */
|
|
71
|
+
| 'rpc_rate_limited'
|
|
72
|
+
/** The address doesn't look like an ABX contract on this chain. NOT emitted by the reference
|
|
73
|
+
* (it indexes what its operator tells it); a provider that validates clone-ness SHOULD refuse
|
|
74
|
+
* synchronously at register instead of accepting and failing here. */
|
|
75
|
+
| 'not_abx_contract'
|
|
76
|
+
/** Anything else. Carries no detail — the service logs the cause. */
|
|
77
|
+
| 'internal';
|
|
78
|
+
/** A catch-up failure as it crosses the wire: a machine class plus a short, CREDENTIAL-FREE hint.
|
|
79
|
+
* Messages come from a closed set (see {@link classifyIndexError}) rather than from a scrubber, so
|
|
80
|
+
* "no RPC URL can leak through here" is checkable by reading the code. */
|
|
81
|
+
export interface IndexError {
|
|
82
|
+
class: IndexErrorClass;
|
|
83
|
+
message?: string;
|
|
84
|
+
}
|
|
85
|
+
/** Map a catch-up failure to its wire form. Sniffs the underlying error's shape only to CHOOSE a
|
|
86
|
+
* class — nothing from it reaches the returned message. */
|
|
87
|
+
export declare function classifyIndexError(err: unknown): IndexError;
|
|
19
88
|
/** Machine error codes every conforming service uses — clients key off these, never off prose. */
|
|
20
89
|
export type ServiceErrorCode = 'invalid_request' | 'unsupported_chain' | 'unauthorized' | 'forbidden' | 'not_registered' | 'disabled'
|
|
90
|
+
/** 404 — this node serves no route at that path AT ALL (as opposed to a known route whose shape
|
|
91
|
+
* was wrong, which is a 400 `invalid_request` carrying the correct template). The pair exists so
|
|
92
|
+
* a client can tell "I built the wrong URL" from "this project isn't indexed here" from "this
|
|
93
|
+
* node is older than the route I want" — a bare 404 conflates all three and reads as an outage. */
|
|
94
|
+
| 'unknown_route'
|
|
21
95
|
/** 500 — an unexpected server-side failure. Never carries internal detail (it could embed the
|
|
22
96
|
* operator's own credentials); the node logs the cause. Retryable. */
|
|
23
97
|
| 'internal_error';
|
|
@@ -75,8 +149,11 @@ export interface RegisterProjectBody {
|
|
|
75
149
|
/** Force a full replay even on a re-POST. */
|
|
76
150
|
full?: boolean;
|
|
77
151
|
}
|
|
78
|
-
|
|
152
|
+
/** `200` — catch-up finished inside the request; the counts are facts. */
|
|
153
|
+
export interface RegisterProjectSummary {
|
|
79
154
|
ok: boolean;
|
|
155
|
+
/** Discriminator. Normalized from the HTTP status by {@link AbxServiceClient.registerProject}. */
|
|
156
|
+
accepted: false;
|
|
80
157
|
mode: 'full' | 'incremental';
|
|
81
158
|
elapsedMs: number;
|
|
82
159
|
project: {
|
|
@@ -85,8 +162,30 @@ export interface RegisterProjectResult {
|
|
|
85
162
|
eventCount: number;
|
|
86
163
|
tokenCount: number;
|
|
87
164
|
mintedCount: number;
|
|
165
|
+
/** Sum of every token's current supply — ERC-1155 editions only; absent for a 721 project. */
|
|
166
|
+
copies?: string;
|
|
167
|
+
status?: IndexStatus;
|
|
88
168
|
};
|
|
89
169
|
}
|
|
170
|
+
/** `202` — the registration is durable and catch-up is deferred; there are no counts yet. Poll
|
|
171
|
+
* {@link AbxServiceClient.projectStatus} (or {@link AbxServiceClient.awaitIndexed}) for progress. */
|
|
172
|
+
export interface RegisterProjectAccepted {
|
|
173
|
+
ok: boolean;
|
|
174
|
+
accepted: true;
|
|
175
|
+
project: {
|
|
176
|
+
address: string;
|
|
177
|
+
name?: string | null;
|
|
178
|
+
status: IndexStatus;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* `POST /v1/projects` answers in one of two shapes and **the HTTP status code is the discriminator**
|
|
183
|
+
* (200 = done, 202 = accepted). Both are conformant; a client MUST handle both, which is why this is
|
|
184
|
+
* a union rather than a shape with everything optional. Narrow with {@link isAccepted}.
|
|
185
|
+
*/
|
|
186
|
+
export type RegisterProjectResult = RegisterProjectSummary | RegisterProjectAccepted;
|
|
187
|
+
/** Narrow a register response to the deferred-catch-up branch. */
|
|
188
|
+
export declare function isAccepted(r: RegisterProjectResult): r is RegisterProjectAccepted;
|
|
90
189
|
/** One row of `GET /v1/projects` — the projects visible to this token. */
|
|
91
190
|
export interface RemoteProjectSummary {
|
|
92
191
|
chainId: number;
|
|
@@ -96,18 +195,38 @@ export interface RemoteProjectSummary {
|
|
|
96
195
|
eventCount?: number;
|
|
97
196
|
tokenCount?: number;
|
|
98
197
|
mintedCount?: number;
|
|
198
|
+
/** Sum of every token's current supply — ERC-1155 editions only; absent for a 721 project. */
|
|
199
|
+
copies?: string;
|
|
99
200
|
reconstructedAt?: string | null;
|
|
201
|
+
/** Where this project is in the indexing lifecycle — so a list renders "3 live, 1 backfilling,
|
|
202
|
+
* 1 failed" with no per-project round trip. */
|
|
203
|
+
status?: IndexStatus;
|
|
204
|
+
/** Present on `stale`/`failed` — the class only; the full hint lives on the status route. */
|
|
205
|
+
error?: {
|
|
206
|
+
class: IndexErrorClass;
|
|
207
|
+
};
|
|
100
208
|
}
|
|
101
|
-
/** `GET /v1/projects/{chainId}/{address}/status` — indexing freshness. */
|
|
209
|
+
/** `GET /v1/projects/{chainId}/{address}/status` — indexing freshness + lifecycle. */
|
|
102
210
|
export interface RemoteProjectStatus {
|
|
103
211
|
chainId: number;
|
|
104
212
|
address: string;
|
|
213
|
+
/** Where this project is in the lifecycle. */
|
|
214
|
+
status: IndexStatus;
|
|
105
215
|
fromBlock: string;
|
|
106
216
|
toBlock: string | null;
|
|
217
|
+
/** Chain head as the service last saw it — so a client computes lag / % complete without knowing
|
|
218
|
+
* anything about the service's watcher. `null` when the service can't say. */
|
|
219
|
+
headBlock?: string | null;
|
|
107
220
|
eventCount: number;
|
|
108
221
|
tokenCount: number;
|
|
109
222
|
mintedCount: number;
|
|
223
|
+
/** Sum of every token's current supply — ERC-1155 editions only; absent for a 721 project. */
|
|
224
|
+
copies?: string;
|
|
110
225
|
reconstructedAt: string | null;
|
|
226
|
+
/** Present on `stale`/`failed`. Credential-free by contract. */
|
|
227
|
+
error?: IndexError;
|
|
228
|
+
/** Catch-up attempts since the last success. */
|
|
229
|
+
attempts?: number;
|
|
111
230
|
watcher?: {
|
|
112
231
|
watching: boolean;
|
|
113
232
|
pollAt: string | null;
|
|
@@ -115,6 +234,21 @@ export interface RemoteProjectStatus {
|
|
|
115
234
|
intervalMs?: number;
|
|
116
235
|
};
|
|
117
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* How far along a BACKFILL is, from a status read — `null` when there is no meaningful ratio.
|
|
239
|
+
*
|
|
240
|
+
* Deliberately `null` for anything but `backfilling`, because `toBlock` measures two different things
|
|
241
|
+
* depending on the state. During an initial sync it advances monotonically, so `toBlock` vs head IS
|
|
242
|
+
* progress. Once a project is `live` it only moves when that project has *events* — so a perfectly
|
|
243
|
+
* current project on a busy chain sits at a tiny fraction of head, and rendering that as "3%" reads
|
|
244
|
+
* as broken when nothing is wrong. Same reason the reference measures staleness against its watcher's
|
|
245
|
+
* watermark rather than a project's `toBlock`.
|
|
246
|
+
*/
|
|
247
|
+
export declare function indexProgress(s: RemoteProjectStatus): {
|
|
248
|
+
done: bigint;
|
|
249
|
+
total: bigint;
|
|
250
|
+
percent: number;
|
|
251
|
+
} | null;
|
|
118
252
|
/** `POST /v1/effect-artifacts` — a render producer publishes one output (locator or bytes). */
|
|
119
253
|
export interface PublishEffectArtifactBody {
|
|
120
254
|
chainId: number;
|
|
@@ -125,9 +259,19 @@ export interface PublishEffectArtifactBody {
|
|
|
125
259
|
output?: string;
|
|
126
260
|
effectKey?: string;
|
|
127
261
|
contentType?: string;
|
|
128
|
-
/**
|
|
262
|
+
/**
|
|
263
|
+
* REFERENCED outputs (`render/image`, a video, a model — anything the service doesn't stitch):
|
|
264
|
+
* an `https://` / `ipfs://` / `ar://` pointer, reachable without the producer's credentials. The
|
|
265
|
+
* service records it and 302-redirects; it never fetches or proxies the bytes. Required for this
|
|
266
|
+
* class — sending {@link bytes_base64} instead is a `400`.
|
|
267
|
+
*/
|
|
129
268
|
locator?: string;
|
|
130
|
-
/**
|
|
269
|
+
/**
|
|
270
|
+
* BOUND outputs only (`render/traits` — content that stitches into the metadata JSON): the raw
|
|
271
|
+
* output, ≤{@link BOUND_ARTIFACT_MAX_BYTES}, held by the service beside the artifact row. Sending
|
|
272
|
+
* a {@link locator} for a bound output is a `400` — the content is assembled into `tokenURI`, so a
|
|
273
|
+
* pointer there would be recorded and then never stitch.
|
|
274
|
+
*/
|
|
131
275
|
bytes_base64?: string;
|
|
132
276
|
}
|
|
133
277
|
/** `POST /v1/effect-status` — a producer reports one run's transient state. */
|
|
@@ -147,12 +291,30 @@ export declare class AbxServiceError extends Error {
|
|
|
147
291
|
readonly status: number;
|
|
148
292
|
readonly code?: ServiceErrorCode;
|
|
149
293
|
readonly url: string;
|
|
294
|
+
/** The failure CLASS when the service volunteered one (a credential-free hint about *why* — an
|
|
295
|
+
* exhausted RPC reads very differently from a broken service). Optional on the wire. */
|
|
296
|
+
readonly class?: IndexErrorClass;
|
|
150
297
|
constructor(message: string, opts: {
|
|
151
298
|
status: number;
|
|
152
299
|
code?: ServiceErrorCode;
|
|
153
300
|
url: string;
|
|
301
|
+
class?: IndexErrorClass;
|
|
154
302
|
});
|
|
155
303
|
}
|
|
304
|
+
/** Waiting for a project to reach a terminal status ran out of time. The registration is durable —
|
|
305
|
+
* this is "still working", never "the add failed". */
|
|
306
|
+
export declare class AbxIndexTimeoutError extends Error {
|
|
307
|
+
readonly last?: RemoteProjectStatus;
|
|
308
|
+
constructor(message: string, last?: RemoteProjectStatus);
|
|
309
|
+
}
|
|
310
|
+
export interface AwaitIndexedOptions {
|
|
311
|
+
/** Give up after this long (default 5 min). The registration stays durable regardless. */
|
|
312
|
+
timeoutMs?: number;
|
|
313
|
+
/** Poll cadence (default 3s). */
|
|
314
|
+
intervalMs?: number;
|
|
315
|
+
/** Called on every poll — drive a progress line from it. */
|
|
316
|
+
onProgress?: (status: RemoteProjectStatus) => void;
|
|
317
|
+
}
|
|
156
318
|
export interface ServiceClientOptions {
|
|
157
319
|
baseUrl: string;
|
|
158
320
|
/** Bearer token for the control plane. Omit for descriptor-only use. */
|
|
@@ -170,8 +332,23 @@ export declare class AbxServiceClient {
|
|
|
170
332
|
constructor(opts: ServiceClientOptions);
|
|
171
333
|
/** The public service descriptor — no auth, safe to fetch before trusting a provider. */
|
|
172
334
|
descriptor(): Promise<ServiceDescriptor>;
|
|
173
|
-
/**
|
|
335
|
+
/**
|
|
336
|
+
* Register + index a project (the HTTP form of `abx add`; a re-POST is the nudge). Returns the
|
|
337
|
+
* completed summary (HTTP 200) or the accepted-and-still-working shape (HTTP 202) — narrow with
|
|
338
|
+
* {@link isAccepted}, and follow a 202 with {@link awaitIndexed}.
|
|
339
|
+
*
|
|
340
|
+
* A timed-out register is NOT retried blind. A conforming service persists the registration before
|
|
341
|
+
* it starts catching up, so a timeout usually means "it's in there, still working" — and re-POSTing
|
|
342
|
+
* would kick off a *second* full reconstruct against the RPC that was already too slow to answer.
|
|
343
|
+
* So we ask the status route whether it landed, and if it did we return the async shape instead.
|
|
344
|
+
*/
|
|
174
345
|
registerProject(body: RegisterProjectBody): Promise<RegisterProjectResult>;
|
|
346
|
+
/**
|
|
347
|
+
* Poll a project's status until it reaches a terminal lifecycle state (`live` or `failed`) — the
|
|
348
|
+
* one implementation of the wait loop, so the CLI, the effects runner, and any hosted agent all
|
|
349
|
+
* behave identically against any provider. `stale` keeps polling: it means lagging, not caught up.
|
|
350
|
+
*/
|
|
351
|
+
awaitIndexed(chainId: number, address: string, opts?: AwaitIndexedOptions): Promise<RemoteProjectStatus>;
|
|
175
352
|
/** The projects this token may see. */
|
|
176
353
|
listProjects(): Promise<RemoteProjectSummary[]>;
|
|
177
354
|
/** Deregister (remote `abx forget`). `not_registered` means "already gone" — reported, not
|
|
@@ -179,7 +356,8 @@ export declare class AbxServiceClient {
|
|
|
179
356
|
removeProject(chainId: number, address: string): Promise<{
|
|
180
357
|
removed: boolean;
|
|
181
358
|
}>;
|
|
182
|
-
/** Nudge a re-index.
|
|
359
|
+
/** Nudge a re-index. Answers in the same two shapes as {@link registerProject} — a full replay is
|
|
360
|
+
* the *most* likely call to outlive one HTTP request. */
|
|
183
361
|
reindexProject(chainId: number, address: string): Promise<RegisterProjectResult>;
|
|
184
362
|
/** Indexing freshness for one project. */
|
|
185
363
|
projectStatus(chainId: number, address: string): Promise<RemoteProjectStatus>;
|
|
@@ -192,5 +370,6 @@ export declare class AbxServiceClient {
|
|
|
192
370
|
/** Report a run's transient state for the artifact key it is producing. */
|
|
193
371
|
reportEffectStatus(body: ReportEffectStatusBody): Promise<void>;
|
|
194
372
|
private request;
|
|
373
|
+
private requestWithStatus;
|
|
195
374
|
}
|
|
196
375
|
//# sourceMappingURL=service.d.ts.map
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAGlD,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAElE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,qBAAqB,CAAC;AACtD,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AAE9D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiCrE;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEjF,yFAAyF;AACzF,eAAO,MAAM,uBAAuB,EAAE,SAAS,WAAW,EAAuB,CAAC;AAElF;;;;GAIG;AACH,MAAM,MAAM,eAAe;AACzB,oGAAoG;AAClG,iBAAiB;AACnB,oGAAoG;GAClG,kBAAkB;AACpB;;uEAEuE;GACrE,kBAAkB;AACpB,qEAAqE;GACnE,UAAU,CAAC;AAEf;;2EAE2E;AAC3E,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD;4DAC4D;AAC5D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAc3D;AAED,kGAAkG;AAClG,MAAM,MAAM,gBAAgB,GACxB,iB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,CAAC,oBAAoB,EAAE,CAAC;IAKrD;qGACiG;IAC3F,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAC,CAAC;IAUlF;8DAC0D;IACpD,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAUtF,0CAA0C;IACpC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAInF,iGAAiG;IAC3F,qBAAqB,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC;QAAC,EAAE,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC;QAAC,GAAG,EAAE,GAAG,CAAA;KAAC,CAAC;IAIzH,2EAA2E;IACrE,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;YAIvD,OAAO;YAIP,iBAAiB;CAsEhC"}
|
package/dist/service.js
CHANGED
|
@@ -8,24 +8,155 @@
|
|
|
8
8
|
* credential resolution is the caller's concern (the CLI's named-remote convention lives in
|
|
9
9
|
* packages/cli/src/remote.ts).
|
|
10
10
|
*/
|
|
11
|
+
import { linearBackoffDelay, sleep } from './util.js';
|
|
11
12
|
export const WELL_KNOWN_SERVICE_PATH = '/.well-known/abx-service';
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
13
|
+
/**
|
|
14
|
+
* Versioned interface ids a service declares in its descriptor. Versions ride these ids
|
|
15
|
+
* (they track the `/v1` path prefix); the descriptor has no separate format version.
|
|
16
|
+
*
|
|
17
|
+
* There are exactly two, and they are **all-or-nothing**: declaring one asserts every route it names
|
|
18
|
+
* answers per the spec. The artifact-registry routes ride {@link CONTROL_PLANE_INTERFACE} rather
|
|
19
|
+
* than an id of their own — once referenced output is locator-only, accepting a registration is a
|
|
20
|
+
* database insert, so a separate capability flag would describe a distinction that doesn't exist.
|
|
21
|
+
* A service that won't take a given caller's artifacts refuses on the credential (`403`), which is
|
|
22
|
+
* the honest axis: interfaces describe wire grammar, tokens describe permission.
|
|
23
|
+
*/
|
|
14
24
|
export const TOKEN_API_INTERFACE = 'abx-token-api/v1';
|
|
15
25
|
export const CONTROL_PLANE_INTERFACE = 'abx-control-plane/v1';
|
|
16
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Why this locator can't be accepted for a referenced artifact, or `null` if it passes.
|
|
28
|
+
*
|
|
29
|
+
* A locator is a **reachability** claim, not a durability one: it must resolve for a third party
|
|
30
|
+
* with no producer credentials and no private-network assumption. The protocol deliberately has
|
|
31
|
+
* **no preference among schemes** — `https://` (S3/R2, a producer's own public base, a chosen
|
|
32
|
+
* IPFS/Arweave gateway), `ipfs://` and `ar://` are peers, because derived output is re-creatable and
|
|
33
|
+
* a producer with an opinion about which gateway serves its content is making an operational call the
|
|
34
|
+
* protocol has no standing to override.
|
|
35
|
+
*
|
|
36
|
+
* Reachability can't be *proved* without fetching, and fetching a third-party URL while handling an
|
|
37
|
+
* authed write is byte custody through the back door plus an SSRF surface. So this checks the two
|
|
38
|
+
* things that are decidable from the string alone and are always wrong:
|
|
39
|
+
* - a private / loopback host — resolvable only from the producer's own network;
|
|
40
|
+
* - a presigned, expiring URL — resolvable now, dead later, which is the worst failure shape
|
|
41
|
+
* (it passes every check at publish time and rots silently).
|
|
42
|
+
*/
|
|
43
|
+
export function locatorRejectionReason(locator) {
|
|
44
|
+
const trimmed = locator.trim();
|
|
45
|
+
if (!/^(https?|ipfs|ar):/i.test(trimmed)) {
|
|
46
|
+
return `unsupported scheme — use https://, ipfs:// or ar://`;
|
|
47
|
+
}
|
|
48
|
+
if (/^https?:/i.test(trimmed)) {
|
|
49
|
+
let url;
|
|
50
|
+
try {
|
|
51
|
+
url = new URL(trimmed);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return 'not a parseable URL';
|
|
55
|
+
}
|
|
56
|
+
const host = url.hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
57
|
+
const privateHost = host === 'localhost' ||
|
|
58
|
+
host.endsWith('.localhost') ||
|
|
59
|
+
host === '::1' ||
|
|
60
|
+
host === '0.0.0.0' ||
|
|
61
|
+
/^127\./.test(host) ||
|
|
62
|
+
/^10\./.test(host) ||
|
|
63
|
+
/^192\.168\./.test(host) ||
|
|
64
|
+
/^172\.(1[6-9]|2\d|3[01])\./.test(host) ||
|
|
65
|
+
/^169\.254\./.test(host) ||
|
|
66
|
+
/^f[cd][0-9a-f]{2}:/.test(host);
|
|
67
|
+
if (privateHost) {
|
|
68
|
+
return `'${url.hostname}' is a loopback/private host — a locator must resolve for anyone, not just from the producer's network`;
|
|
69
|
+
}
|
|
70
|
+
const q = url.searchParams;
|
|
71
|
+
if (q.has('X-Amz-Signature') || q.has('Signature') || q.has('X-Goog-Signature') || q.has('sig') || q.has('Expires') || q.has('X-Amz-Expires')) {
|
|
72
|
+
return 'looks like a presigned/expiring URL — it would resolve now and rot later; publish a durable public URL instead';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
/** Statuses a caller can stop waiting on — see {@link AbxServiceClient.awaitIndexed}. */
|
|
78
|
+
export const TERMINAL_INDEX_STATUSES = ['live', 'failed'];
|
|
79
|
+
/** The one message per class. Fixed strings — an upstream error is never interpolated, because a
|
|
80
|
+
* keyed RPC URL *is* a credential and upstream messages routinely embed one. */
|
|
81
|
+
const INDEX_ERROR_MESSAGES = {
|
|
82
|
+
rpc_unavailable: 'upstream RPC unavailable; will retry',
|
|
83
|
+
rpc_rate_limited: 'upstream RPC rate-limited; will retry',
|
|
84
|
+
not_abx_contract: 'address emits no ABX event spine on this chain',
|
|
85
|
+
internal: 'indexing failed; see the service operator’s logs',
|
|
86
|
+
};
|
|
87
|
+
/** Map a catch-up failure to its wire form. Sniffs the underlying error's shape only to CHOOSE a
|
|
88
|
+
* class — nothing from it reaches the returned message. */
|
|
89
|
+
export function classifyIndexError(err) {
|
|
90
|
+
const raw = err instanceof Error ? `${err.name} ${err.message}` : String(err);
|
|
91
|
+
const text = raw.toLowerCase();
|
|
92
|
+
let cls = 'internal';
|
|
93
|
+
if (/rate.?limit|too many requests|\b429\b|quota|exceeded .*(?:compute|cu)|throttl/.test(text)) {
|
|
94
|
+
cls = 'rpc_rate_limited';
|
|
95
|
+
}
|
|
96
|
+
else if (/timeout|timed out|econnrefused|econnreset|enotfound|eai_again|socket hang up|fetch failed|network|502|503|504|http request failed/.test(text)) {
|
|
97
|
+
cls = 'rpc_unavailable';
|
|
98
|
+
}
|
|
99
|
+
return { class: cls, message: INDEX_ERROR_MESSAGES[cls] };
|
|
100
|
+
}
|
|
101
|
+
/** Narrow a register response to the deferred-catch-up branch. */
|
|
102
|
+
export function isAccepted(r) {
|
|
103
|
+
return r.accepted === true;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* How far along a BACKFILL is, from a status read — `null` when there is no meaningful ratio.
|
|
107
|
+
*
|
|
108
|
+
* Deliberately `null` for anything but `backfilling`, because `toBlock` measures two different things
|
|
109
|
+
* depending on the state. During an initial sync it advances monotonically, so `toBlock` vs head IS
|
|
110
|
+
* progress. Once a project is `live` it only moves when that project has *events* — so a perfectly
|
|
111
|
+
* current project on a busy chain sits at a tiny fraction of head, and rendering that as "3%" reads
|
|
112
|
+
* as broken when nothing is wrong. Same reason the reference measures staleness against its watcher's
|
|
113
|
+
* watermark rather than a project's `toBlock`.
|
|
114
|
+
*/
|
|
115
|
+
export function indexProgress(s) {
|
|
116
|
+
if (s.status !== 'backfilling')
|
|
117
|
+
return null;
|
|
118
|
+
if (!s.headBlock || !s.toBlock)
|
|
119
|
+
return null;
|
|
120
|
+
try {
|
|
121
|
+
const from = BigInt(s.fromBlock);
|
|
122
|
+
const to = BigInt(s.toBlock);
|
|
123
|
+
const head = BigInt(s.headBlock);
|
|
124
|
+
if (head <= from || to < from)
|
|
125
|
+
return null;
|
|
126
|
+
const total = head - from;
|
|
127
|
+
const done = (to > head ? head : to) - from;
|
|
128
|
+
return { done, total, percent: Number((done * 100n) / total) };
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
17
134
|
/** A non-2xx control-plane response (or an unreachable service, after retries). `code` is the
|
|
18
135
|
* spec's machine code when the service sent one — key behavior off it, never off `message`. */
|
|
19
136
|
export class AbxServiceError extends Error {
|
|
20
137
|
status;
|
|
21
138
|
code;
|
|
22
139
|
url;
|
|
140
|
+
/** The failure CLASS when the service volunteered one (a credential-free hint about *why* — an
|
|
141
|
+
* exhausted RPC reads very differently from a broken service). Optional on the wire. */
|
|
142
|
+
class;
|
|
23
143
|
constructor(message, opts) {
|
|
24
144
|
super(message);
|
|
25
145
|
this.name = 'AbxServiceError';
|
|
26
146
|
this.status = opts.status;
|
|
27
147
|
this.code = opts.code;
|
|
28
148
|
this.url = opts.url;
|
|
149
|
+
this.class = opts.class;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Waiting for a project to reach a terminal status ran out of time. The registration is durable —
|
|
153
|
+
* this is "still working", never "the add failed". */
|
|
154
|
+
export class AbxIndexTimeoutError extends Error {
|
|
155
|
+
last;
|
|
156
|
+
constructor(message, last) {
|
|
157
|
+
super(message);
|
|
158
|
+
this.name = 'AbxIndexTimeoutError';
|
|
159
|
+
this.last = last;
|
|
29
160
|
}
|
|
30
161
|
}
|
|
31
162
|
/**
|
|
@@ -51,11 +182,48 @@ export class AbxServiceClient {
|
|
|
51
182
|
}
|
|
52
183
|
/** The public service descriptor — no auth, safe to fetch before trusting a provider. */
|
|
53
184
|
async descriptor() {
|
|
54
|
-
return (await this.request('GET', WELL_KNOWN_SERVICE_PATH, undefined, DESCRIPTOR_ATTEMPTS));
|
|
185
|
+
return (await this.request('GET', WELL_KNOWN_SERVICE_PATH, undefined, { attempts: DESCRIPTOR_ATTEMPTS }));
|
|
55
186
|
}
|
|
56
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Register + index a project (the HTTP form of `abx add`; a re-POST is the nudge). Returns the
|
|
189
|
+
* completed summary (HTTP 200) or the accepted-and-still-working shape (HTTP 202) — narrow with
|
|
190
|
+
* {@link isAccepted}, and follow a 202 with {@link awaitIndexed}.
|
|
191
|
+
*
|
|
192
|
+
* A timed-out register is NOT retried blind. A conforming service persists the registration before
|
|
193
|
+
* it starts catching up, so a timeout usually means "it's in there, still working" — and re-POSTing
|
|
194
|
+
* would kick off a *second* full reconstruct against the RPC that was already too slow to answer.
|
|
195
|
+
* So we ask the status route whether it landed, and if it did we return the async shape instead.
|
|
196
|
+
*/
|
|
57
197
|
async registerProject(body) {
|
|
58
|
-
|
|
198
|
+
const landed = async () => {
|
|
199
|
+
const st = await this.projectStatus(body.chainId, body.address).catch(() => null);
|
|
200
|
+
if (!st)
|
|
201
|
+
return undefined; // not there (or the service is truly unreachable) — keep retrying
|
|
202
|
+
return { ok: true, accepted: true, project: { address: body.address, status: st.status } };
|
|
203
|
+
};
|
|
204
|
+
const { status, body: out } = await this.requestWithStatus('POST', '/v1/projects', body, { onTimeout: landed });
|
|
205
|
+
return normalizeRegisterResult(status, out, body.address);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Poll a project's status until it reaches a terminal lifecycle state (`live` or `failed`) — the
|
|
209
|
+
* one implementation of the wait loop, so the CLI, the effects runner, and any hosted agent all
|
|
210
|
+
* behave identically against any provider. `stale` keeps polling: it means lagging, not caught up.
|
|
211
|
+
*/
|
|
212
|
+
async awaitIndexed(chainId, address, opts = {}) {
|
|
213
|
+
const timeoutMs = opts.timeoutMs ?? 300_000;
|
|
214
|
+
const intervalMs = opts.intervalMs ?? 3_000;
|
|
215
|
+
const deadline = Date.now() + timeoutMs;
|
|
216
|
+
let last;
|
|
217
|
+
for (;;) {
|
|
218
|
+
last = await this.projectStatus(chainId, address);
|
|
219
|
+
opts.onProgress?.(last);
|
|
220
|
+
if (TERMINAL_INDEX_STATUSES.includes(last.status))
|
|
221
|
+
return last;
|
|
222
|
+
if (Date.now() + intervalMs > deadline) {
|
|
223
|
+
throw new AbxIndexTimeoutError(`${address} was still '${last.status}' after ${Math.round(timeoutMs / 1000)}s — the registration is durable and the service keeps working; check back with \`abx status ${address} --remote\``, last);
|
|
224
|
+
}
|
|
225
|
+
await sleep(intervalMs);
|
|
226
|
+
}
|
|
59
227
|
}
|
|
60
228
|
/** The projects this token may see. */
|
|
61
229
|
async listProjects() {
|
|
@@ -75,9 +243,16 @@ export class AbxServiceClient {
|
|
|
75
243
|
throw err;
|
|
76
244
|
}
|
|
77
245
|
}
|
|
78
|
-
/** Nudge a re-index.
|
|
246
|
+
/** Nudge a re-index. Answers in the same two shapes as {@link registerProject} — a full replay is
|
|
247
|
+
* the *most* likely call to outlive one HTTP request. */
|
|
79
248
|
async reindexProject(chainId, address) {
|
|
80
|
-
|
|
249
|
+
const { status, body } = await this.requestWithStatus('POST', `/v1/projects/${chainId}/${address}/reindex`, undefined, {
|
|
250
|
+
onTimeout: async () => {
|
|
251
|
+
const st = await this.projectStatus(chainId, address).catch(() => null);
|
|
252
|
+
return st ? { ok: true, accepted: true, project: { address, status: st.status } } : undefined;
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
return normalizeRegisterResult(status, body, address);
|
|
81
256
|
}
|
|
82
257
|
/** Indexing freshness for one project. */
|
|
83
258
|
async projectStatus(chainId, address) {
|
|
@@ -91,7 +266,11 @@ export class AbxServiceClient {
|
|
|
91
266
|
async reportEffectStatus(body) {
|
|
92
267
|
await this.request('POST', '/v1/effect-status', body);
|
|
93
268
|
}
|
|
94
|
-
async request(method, path, body,
|
|
269
|
+
async request(method, path, body, opts) {
|
|
270
|
+
return (await this.requestWithStatus(method, path, body, opts)).body;
|
|
271
|
+
}
|
|
272
|
+
async requestWithStatus(method, path, body, opts) {
|
|
273
|
+
const attempts = opts?.attempts ?? ATTEMPTS;
|
|
95
274
|
const url = this.baseUrl + path;
|
|
96
275
|
const headers = {};
|
|
97
276
|
if (this.token)
|
|
@@ -101,6 +280,7 @@ export class AbxServiceClient {
|
|
|
101
280
|
let lastFailure = '';
|
|
102
281
|
let lastStatus = 0;
|
|
103
282
|
let lastCode;
|
|
283
|
+
let lastClass;
|
|
104
284
|
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
105
285
|
let resp;
|
|
106
286
|
try {
|
|
@@ -114,13 +294,21 @@ export class AbxServiceClient {
|
|
|
114
294
|
catch (err) {
|
|
115
295
|
lastFailure = err.message;
|
|
116
296
|
lastStatus = 0;
|
|
297
|
+
// "We waited the full timeout" and "nothing is listening" are different failures, and for a
|
|
298
|
+
// mutating POST the difference decides whether retrying is safe: the request may still be
|
|
299
|
+
// running on the service. Let the caller check before we hammer it again.
|
|
300
|
+
if (opts?.onTimeout && err.name === 'TimeoutError') {
|
|
301
|
+
const resolved = await opts.onTimeout();
|
|
302
|
+
if (resolved !== undefined)
|
|
303
|
+
return { status: 202, body: resolved };
|
|
304
|
+
}
|
|
117
305
|
if (attempt < attempts)
|
|
118
|
-
await sleep(this.retryDelayMs
|
|
306
|
+
await sleep(linearBackoffDelay(attempt, this.retryDelayMs));
|
|
119
307
|
continue;
|
|
120
308
|
}
|
|
121
309
|
if (resp.ok) {
|
|
122
310
|
const text = await resp.text();
|
|
123
|
-
return text ? JSON.parse(text) : {};
|
|
311
|
+
return { status: resp.status, body: text ? JSON.parse(text) : {} };
|
|
124
312
|
}
|
|
125
313
|
if (resp.status >= 500 || resp.status === 429) {
|
|
126
314
|
// Retryable — but KEEP the service's own words. A 5xx body carries the actual cause (an
|
|
@@ -129,9 +317,10 @@ export class AbxServiceClient {
|
|
|
129
317
|
const said = await bodyMessage(resp);
|
|
130
318
|
lastStatus = resp.status;
|
|
131
319
|
lastCode = said.code;
|
|
320
|
+
lastClass = said.class;
|
|
132
321
|
lastFailure = said.error ? `${resp.status} ${said.error}` : `${resp.status} ${resp.statusText}`;
|
|
133
322
|
if (attempt < attempts)
|
|
134
|
-
await sleep(this.retryDelayMs
|
|
323
|
+
await sleep(linearBackoffDelay(attempt, this.retryDelayMs));
|
|
135
324
|
continue;
|
|
136
325
|
}
|
|
137
326
|
// A genuine 4xx is an answer, not weather — surface the service's own words + code.
|
|
@@ -139,6 +328,7 @@ export class AbxServiceClient {
|
|
|
139
328
|
throw new AbxServiceError(`${method} ${url}: ${resp.status} ${detail.error ?? resp.statusText}`, {
|
|
140
329
|
status: resp.status,
|
|
141
330
|
code: detail.code,
|
|
331
|
+
class: detail.class,
|
|
142
332
|
url,
|
|
143
333
|
});
|
|
144
334
|
}
|
|
@@ -147,20 +337,40 @@ export class AbxServiceClient {
|
|
|
147
337
|
const summary = lastStatus
|
|
148
338
|
? `service failed after ${attempts} attempt(s) — last response ${lastFailure}`
|
|
149
339
|
: `nothing responded after ${attempts} attempt(s) (${lastFailure})`;
|
|
150
|
-
throw new AbxServiceError(`${method} ${url}: ${summary}`, { status: lastStatus, code: lastCode, url });
|
|
340
|
+
throw new AbxServiceError(`${method} ${url}: ${summary}`, { status: lastStatus, code: lastCode, class: lastClass, url });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/** Normalize a register/reindex response: the HTTP status is the authoritative discriminator, and
|
|
344
|
+
* the `accepted` flag is derived from it so callers switch on one field even against a service that
|
|
345
|
+
* doesn't send it. */
|
|
346
|
+
function normalizeRegisterResult(status, out, fallbackAddress) {
|
|
347
|
+
if (status === 202) {
|
|
348
|
+
const r = out;
|
|
349
|
+
return {
|
|
350
|
+
ok: r.ok ?? true,
|
|
351
|
+
accepted: true,
|
|
352
|
+
project: {
|
|
353
|
+
address: r.project?.address ?? fallbackAddress,
|
|
354
|
+
name: r.project?.name ?? null,
|
|
355
|
+
status: r.project?.status ?? 'backfilling',
|
|
356
|
+
},
|
|
357
|
+
};
|
|
151
358
|
}
|
|
359
|
+
return { ...out, accepted: false };
|
|
152
360
|
}
|
|
153
|
-
/** The service's own `{error, code}` from a non-2xx body (never throws — a body may be
|
|
361
|
+
/** The service's own `{error, code, class?}` from a non-2xx body (never throws — a body may be
|
|
362
|
+
* empty/HTML). `class` is the optional credential-free failure hint. */
|
|
154
363
|
async function bodyMessage(resp) {
|
|
155
364
|
try {
|
|
156
365
|
const parsed = (await resp.json());
|
|
157
|
-
return {
|
|
366
|
+
return {
|
|
367
|
+
error: parsed.error,
|
|
368
|
+
code: parsed.code,
|
|
369
|
+
class: parsed.class,
|
|
370
|
+
};
|
|
158
371
|
}
|
|
159
372
|
catch {
|
|
160
373
|
return {};
|
|
161
374
|
}
|
|
162
375
|
}
|
|
163
|
-
function sleep(ms) {
|
|
164
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
165
|
-
}
|
|
166
376
|
//# sourceMappingURL=service.js.map
|