@artblocks/abx-storage 0.1.0-alpha.8 → 0.1.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/dist/arweave.d.ts +34 -47
  3. package/dist/arweave.d.ts.map +1 -1
  4. package/dist/arweave.js +64 -160
  5. package/dist/arweave.js.map +1 -1
  6. package/dist/backend.d.ts +1 -4
  7. package/dist/backend.d.ts.map +1 -1
  8. package/dist/backend.js +4 -33
  9. package/dist/backend.js.map +1 -1
  10. package/dist/content-index.d.ts.map +1 -1
  11. package/dist/content-index.js +3 -1
  12. package/dist/content-index.js.map +1 -1
  13. package/dist/content-plan.d.ts +78 -0
  14. package/dist/content-plan.d.ts.map +1 -0
  15. package/dist/content-plan.js +68 -0
  16. package/dist/content-plan.js.map +1 -0
  17. package/dist/fs.d.ts.map +1 -1
  18. package/dist/fs.js +3 -1
  19. package/dist/fs.js.map +1 -1
  20. package/dist/index.d.ts +7 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +7 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/ipfs.d.ts +17 -1
  25. package/dist/ipfs.d.ts.map +1 -1
  26. package/dist/ipfs.js +60 -2
  27. package/dist/ipfs.js.map +1 -1
  28. package/dist/migrate.d.ts +37 -0
  29. package/dist/migrate.d.ts.map +1 -0
  30. package/dist/migrate.js +55 -0
  31. package/dist/migrate.js.map +1 -0
  32. package/dist/probe.d.ts +66 -0
  33. package/dist/probe.d.ts.map +1 -0
  34. package/dist/probe.js +155 -0
  35. package/dist/probe.js.map +1 -0
  36. package/dist/readiness.d.ts +158 -0
  37. package/dist/readiness.d.ts.map +1 -0
  38. package/dist/readiness.js +183 -0
  39. package/dist/readiness.js.map +1 -0
  40. package/dist/upload-readiness.d.ts +89 -0
  41. package/dist/upload-readiness.d.ts.map +1 -0
  42. package/dist/upload-readiness.js +85 -0
  43. package/dist/upload-readiness.js.map +1 -0
  44. package/dist/upload.d.ts +28 -0
  45. package/dist/upload.d.ts.map +1 -0
  46. package/dist/upload.js +41 -0
  47. package/dist/upload.js.map +1 -0
  48. package/package.json +17 -9
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The storage half of a resolver migration: re-pinning node-custody images to a durable backend.
3
+ *
4
+ * The rest of the migration — reconciling a destination resolver's off-chain state against a
5
+ * source resolver's served JSON (`buildMigrationPlan`/`verifyParity`) — is pure fetch-based
6
+ * reconciliation with no storage dependency, so it lives in `@artblocks/abx-sdk`'s `migrate.ts`.
7
+ * This module is the one piece that needs an actual byte-custody backend: turning a
8
+ * {@link NodeCustodyImage} (bytes that live only on the soon-to-be-decommissioned source host)
9
+ * into a portable, durable locator.
10
+ */
11
+ import { type StorageBackend } from './backend.js';
12
+ import type { NodeCustodyImage } from '@artblocks/abx-sdk';
13
+ /**
14
+ * Re-pin node-custody images to a DURABLE backend so the destination never depends on the
15
+ * (soon-to-be-decommissioned) source host. For each image: fetch the bytes from the source,
16
+ * **verify** them against the on-chain hash (trustless — we trust the chain, not the old node),
17
+ * then `put` them to the destination operator's own backend and read back a portable locator.
18
+ *
19
+ * If the configured backend isn't durable (no `locator` — fs/cloud serve only through their own
20
+ * node, so re-pinning there just moves the single-host dependency), we re-pin NOTHING and report
21
+ * every image as `needsDurableBackend`: the right move is to configure IPFS/Arweave and re-run,
22
+ * never to bridge a URL that points back at the dying host.
23
+ */
24
+ export interface RepinResult {
25
+ /** hash → new durable locator, ready to bridge to the destination. */
26
+ repinned: Record<string, string>;
27
+ /** Re-pinned token ids (for reporting). */
28
+ repinnedTokens: string[];
29
+ /** Bytes fetched but their hash didn't match the on-chain commitment — NOT trusted, NOT pinned. */
30
+ mismatched: NodeCustodyImage[];
31
+ /** Couldn't fetch the bytes from the source (host down, 404). */
32
+ unreachable: NodeCustodyImage[];
33
+ /** Skipped because no durable backend is configured — these need IPFS/Arweave + a re-run. */
34
+ needsDurableBackend: NodeCustodyImage[];
35
+ }
36
+ export declare function repinNodeCustody(images: NodeCustodyImage[], backend: StorageBackend): Promise<RepinResult>;
37
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAc,KAAK,cAAc,EAAC,MAAM,cAAc,CAAC;AAC9D,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAGzD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,2CAA2C;IAC3C,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,mGAAmG;IACnG,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC/B,iEAAiE;IACjE,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,6FAA6F;IAC7F,mBAAmB,EAAE,gBAAgB,EAAE,CAAC;CACzC;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAyChH"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The storage half of a resolver migration: re-pinning node-custody images to a durable backend.
3
+ *
4
+ * The rest of the migration — reconciling a destination resolver's off-chain state against a
5
+ * source resolver's served JSON (`buildMigrationPlan`/`verifyParity`) — is pure fetch-based
6
+ * reconciliation with no storage dependency, so it lives in `@artblocks/abx-sdk`'s `migrate.ts`.
7
+ * This module is the one piece that needs an actual byte-custody backend: turning a
8
+ * {@link NodeCustodyImage} (bytes that live only on the soon-to-be-decommissioned source host)
9
+ * into a portable, durable locator.
10
+ */
11
+ import { hashContent } from './backend.js';
12
+ export async function repinNodeCustody(images, backend) {
13
+ const result = { repinned: {}, repinnedTokens: [], mismatched: [], unreachable: [], needsDurableBackend: [] };
14
+ if (!images.length)
15
+ return result;
16
+ // A backend is "durable" for migration iff it can hand back a node-independent locator.
17
+ if (!backend.locator) {
18
+ result.needsDurableBackend = [...images];
19
+ return result;
20
+ }
21
+ for (const img of images) {
22
+ let bytes;
23
+ let contentType;
24
+ try {
25
+ const resp = await fetch(img.imageUrl);
26
+ if (!resp.ok) {
27
+ result.unreachable.push(img);
28
+ continue;
29
+ }
30
+ bytes = new Uint8Array(await resp.arrayBuffer());
31
+ contentType = resp.headers.get('content-type') ?? 'application/octet-stream';
32
+ }
33
+ catch {
34
+ result.unreachable.push(img);
35
+ continue;
36
+ }
37
+ // Trustless: re-hash the fetched bytes and compare to the ON-CHAIN commitment.
38
+ if (hashContent(bytes).toLowerCase() !== img.hash.toLowerCase()) {
39
+ result.mismatched.push(img);
40
+ continue;
41
+ }
42
+ await backend.put(img.hash, { bytes, contentType });
43
+ const loc = await backend.locator(img.hash);
44
+ if (loc) {
45
+ result.repinned[img.hash.toLowerCase()] = loc;
46
+ result.repinnedTokens.push(img.tokenId);
47
+ }
48
+ else {
49
+ // Stored, but the backend still can't produce a portable locator — treat as not durable.
50
+ result.needsDurableBackend.push(img);
51
+ }
52
+ }
53
+ return result;
54
+ }
55
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAC,WAAW,EAAsB,MAAM,cAAc,CAAC;AA4B9D,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAA0B,EAAE,OAAuB;IACxF,MAAM,MAAM,GAAgB,EAAC,QAAQ,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,mBAAmB,EAAE,EAAE,EAAC,CAAC;IACzH,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;IAElC,wF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W,EAAE,CAAC,GAAG,GAAG,CAAC;YAC9C,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,yFAAyF;YACzF,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,66 @@
1
+ import type { StorageBackend } from './backend.js';
2
+ import type { CloudStorageConfig } from './cloud.js';
3
+ import { type ArweaveConfig } from './arweave.js';
4
+ import { type ResolveStorageOptions } from './resolve.js';
5
+ /**
6
+ * `abx storage show --check` / `abx doctor`'s storage section — go beyond "is this backend
7
+ * CONFIGURED" (what {@link resolveBackend} plus each backend's own `health()` already answer) to
8
+ * "does a write actually reach the URL a token would bake on-chain."
9
+ *
10
+ * The gap this closes is the R2/S3 endpoint-vs-public-base confusion: a backend's `health()` signs
11
+ * a request against the API `endpoint` — proving credentials work — but never touches the SEPARATE
12
+ * `publicBase` a marketplace would actually fetch from. Those can point at different buckets (or one
13
+ * can simply be wrong) with `health()` reporting green the whole time. A PUT through the API,
14
+ * fetched back over the PUBLIC base with a plain unsigned GET, is the only check that proves the two
15
+ * agree.
16
+ *
17
+ * `fs` and `ipfs` are NOT reimplemented here — their existing `health()` already does exactly what's
18
+ * asked (fs: writability; ipfs: gateway/API reachability, no upload) and duplicating that logic is
19
+ * how the two copies drift. `arweave` layers a balance READ (never a paid upload) on top of its
20
+ * existing identity check. `cloud` gets the new round trip.
21
+ */
22
+ export interface StorageCheckResult {
23
+ backend: string;
24
+ ok: boolean;
25
+ detail: string;
26
+ /** Set on a `cloud` check — the API write target and the public read URL, so a mismatch between
27
+ * them (the R2/S3 endpoint-vs-public-base trap) is visible on failure rather than a bare
28
+ * "fetch failed". Equal in shape, not necessarily in host — that's exactly what's being checked. */
29
+ putUrl?: string;
30
+ publicUrl?: string;
31
+ }
32
+ export interface StorageCheckOptions {
33
+ /** Bound on each network step. A backend method with no abort hook (cloud's `putObject`/
34
+ * `getObject`, arweave's balance read) is raced against this rather than truly cancelled — good
35
+ * enough to keep a caller (doctor) from hanging, not a guarantee the underlying request stopped. */
36
+ timeoutMs?: number;
37
+ /** Injectable for tests — used for the public-base GET only (the PUT/API side goes through the
38
+ * resolved backend, which owns its own signing). */
39
+ fetchFn?: typeof fetch;
40
+ }
41
+ /** fs + ipfs (and any future backend with nothing more to add): delegate straight to the existing
42
+ * `health()` — see the module doc for why this is reuse, not a stand-in pending real logic. */
43
+ export declare function checkViaHealth(backend: StorageBackend, opts?: StorageCheckOptions): Promise<StorageCheckResult>;
44
+ /**
45
+ * `cloud`: PUT a tiny probe object through the signed API, then GET it back with a plain,
46
+ * UNSIGNED fetch against `publicBase` — the same request a marketplace/browser would make. Reuses
47
+ * one well-known key (`abx-probe/check.txt`) rather than minting a new one per run, so repeated
48
+ * checks don't litter the bucket. `cfg` (when given) names the API write target too — the R2/S3
49
+ * endpoint-vs-public-base trap is only diagnosable if BOTH URLs are on screen, not just the one
50
+ * that failed.
51
+ */
52
+ export declare function checkCloudBackend(backend: StorageBackend, cfg?: CloudStorageConfig, opts?: StorageCheckOptions): Promise<StorageCheckResult>;
53
+ /**
54
+ * `arweave`: the existing `health()` (gateway reachability + identity presence) plus a Turbo
55
+ * BALANCE read when an identity already exists — never a paid upload (no identity yet is reported
56
+ * as-is: it's created free on first real upload, so there's nothing to check).
57
+ */
58
+ export declare function checkArweaveBackend(backend: StorageBackend, cfg: ArweaveConfig | undefined, opts?: StorageCheckOptions): Promise<StorageCheckResult>;
59
+ /**
60
+ * The one storage-config probe both `abx storage show --check` and `abx doctor` call — dispatches to
61
+ * the right per-backend check above. Resolving the backend can throw (missing required config, e.g.
62
+ * cloud with no endpoint/bucket) — same as every other `resolveBackend` call site, and the caller's
63
+ * existing try/catch around it is the right place to handle that, not this function.
64
+ */
65
+ export declare function probeStorageBackend(opts: ResolveStorageOptions, checkOpts?: StorageCheckOptions): Promise<StorageCheckResult>;
66
+ //# sourceMappingURL=probe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.d.ts","sourceRoot":"","sources":["../src/probe.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,EAAqE,KAAK,aAAa,EAAC,MAAM,cAAc,CAAC;AACpH,OAAO,EAAiB,KAAK,qBAAqB,EAAC,MAAM,cAAc,CAAC;AAExE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf;;yGAEqG;IACrG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC;;yGAEqG;IACrG,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;yDACqD;IACrD,OAAO,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB;AAqBD;gGACgG;AAChG,wBAAsB,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAYzH;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,CAAC,EAAE,kBAAkB,EAAE,IAAI,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA+DtJ;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,aAAa,GAAG,SAAS,EAAE,IAAI,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA0B9J;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,EAAE,SAAS,GAAE,mBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAKvI"}
package/dist/probe.js ADDED
@@ -0,0 +1,155 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { arweaveFunding, turboIdentity, turboIdentityAddress, isEthIdentity } from './arweave.js';
3
+ import { resolveBackend } from './resolve.js';
4
+ /** Matches readiness.ts's gateway-probe default — this module's other real-network default. */
5
+ const DEFAULT_CHECK_TIMEOUT_MS = 6000;
6
+ /** Race a call against a `ms` deadline, rejecting with `message` if it wins. Most methods probed
7
+ * here have no abort hook of their own, so this stops WAITING for a hung request rather than
8
+ * cancelling it — good enough to keep a caller (doctor) from hanging. Always clears its timer, so
9
+ * a fast call doesn't leave one pending. */
10
+ async function race(p, ms, message) {
11
+ let timer;
12
+ const timeout = new Promise((_, reject) => {
13
+ timer = setTimeout(() => reject(new Error(message)), ms);
14
+ });
15
+ try {
16
+ return await Promise.race([p, timeout]);
17
+ }
18
+ finally {
19
+ clearTimeout(timer);
20
+ }
21
+ }
22
+ /** fs + ipfs (and any future backend with nothing more to add): delegate straight to the existing
23
+ * `health()` — see the module doc for why this is reuse, not a stand-in pending real logic. */
24
+ export async function checkViaHealth(backend, opts = {}) {
25
+ const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
26
+ try {
27
+ const h = await race(backend.health?.() ?? Promise.resolve({ ok: true, detail: 'no check defined for this backend' }), timeoutMs, `timed out after ${timeoutMs}ms`);
28
+ return { backend: backend.id, ok: h.ok, detail: h.detail ?? '' };
29
+ }
30
+ catch (e) {
31
+ return { backend: backend.id, ok: false, detail: e.message };
32
+ }
33
+ }
34
+ /**
35
+ * `cloud`: PUT a tiny probe object through the signed API, then GET it back with a plain,
36
+ * UNSIGNED fetch against `publicBase` — the same request a marketplace/browser would make. Reuses
37
+ * one well-known key (`abx-probe/check.txt`) rather than minting a new one per run, so repeated
38
+ * checks don't litter the bucket. `cfg` (when given) names the API write target too — the R2/S3
39
+ * endpoint-vs-public-base trap is only diagnosable if BOTH URLs are on screen, not just the one
40
+ * that failed.
41
+ */
42
+ export async function checkCloudBackend(backend, cfg, opts = {}) {
43
+ const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
44
+ const key = 'abx-probe/check.txt';
45
+ const putUrl = cfg ? `${cfg.endpoint.replace(/\/+$/, '')}/${cfg.bucket}/${key}` : undefined;
46
+ if (!backend.publicBase) {
47
+ return {
48
+ backend: 'cloud',
49
+ ok: false,
50
+ detail: "no public read base configured — set ABX_S3_PUBLIC_BASE (or --public-base) to the bucket's public URL.",
51
+ putUrl,
52
+ };
53
+ }
54
+ if (!backend.putObject || !backend.getObject) {
55
+ return { backend: 'cloud', ok: false, detail: 'this cloud backend has no putObject/getObject — cannot round-trip check it.', putUrl };
56
+ }
57
+ const publicUrl = `${backend.publicBase.replace(/\/+$/, '')}/${key}`;
58
+ const token = randomBytes(8).toString('hex');
59
+ const body = `abx storage check ${token}`;
60
+ const bytes = new TextEncoder().encode(body);
61
+ try {
62
+ await race(backend.putObject(key, { bytes, contentType: 'text/plain' }), timeoutMs, `PUT timed out after ${timeoutMs}ms`);
63
+ }
64
+ catch (e) {
65
+ return { backend: 'cloud', ok: false, detail: `PUT via the API failed: ${e.message}`, putUrl, publicUrl };
66
+ }
67
+ const fetchFn = opts.fetchFn ?? fetch;
68
+ const ctrl = new AbortController();
69
+ const timer = setTimeout(() => ctrl.abort(), timeoutMs);
70
+ try {
71
+ const res = await fetchFn(publicUrl, { signal: ctrl.signal });
72
+ if (!res.ok) {
73
+ return {
74
+ backend: 'cloud',
75
+ ok: false,
76
+ detail: `GET via the public base failed (${res.status}) — the public base may point at a different bucket/endpoint than the write API.`,
77
+ putUrl,
78
+ publicUrl,
79
+ };
80
+ }
81
+ const got = new TextDecoder().decode(new Uint8Array(await res.arrayBuffer()));
82
+ if (got !== body) {
83
+ return {
84
+ backend: 'cloud',
85
+ ok: false,
86
+ detail: 'GET via the public base returned different bytes than were PUT — check for a caching layer or a public base pointed at a different bucket.',
87
+ putUrl,
88
+ publicUrl,
89
+ };
90
+ }
91
+ return { backend: 'cloud', ok: true, detail: `round-trip ok via ${publicUrl}`, putUrl, publicUrl };
92
+ }
93
+ catch (e) {
94
+ const aborted = e.name === 'AbortError';
95
+ return {
96
+ backend: 'cloud',
97
+ ok: false,
98
+ detail: aborted ? `GET via the public base timed out after ${timeoutMs}ms` : `GET via the public base failed: ${e.message}`,
99
+ putUrl,
100
+ publicUrl,
101
+ };
102
+ }
103
+ finally {
104
+ clearTimeout(timer);
105
+ }
106
+ }
107
+ /**
108
+ * `arweave`: the existing `health()` (gateway reachability + identity presence) plus a Turbo
109
+ * BALANCE read when an identity already exists — never a paid upload (no identity yet is reported
110
+ * as-is: it's created free on first real upload, so there's nothing to check).
111
+ */
112
+ export async function checkArweaveBackend(backend, cfg, opts = {}) {
113
+ const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
114
+ let base;
115
+ try {
116
+ base = await race(backend.health?.() ?? Promise.resolve({ ok: true, detail: '' }), timeoutMs, `timed out after ${timeoutMs}ms`);
117
+ }
118
+ catch (e) {
119
+ base = { ok: false, detail: e.message };
120
+ }
121
+ if (!cfg)
122
+ return { backend: 'arweave', ok: base.ok, detail: base.detail ?? '' };
123
+ const id = turboIdentity(cfg);
124
+ if (!id) {
125
+ return { backend: 'arweave', ok: base.ok, detail: [base.detail, 'no identity yet — created free on first upload (nothing to check)'].filter(Boolean).join(' · ') };
126
+ }
127
+ try {
128
+ const funding = await arweaveFunding(cfg);
129
+ const { credits } = await race(funding.balance(), timeoutMs, `balance check timed out after ${timeoutMs}ms`);
130
+ const address = turboIdentityAddress(id);
131
+ return {
132
+ backend: 'arweave',
133
+ ok: base.ok,
134
+ detail: [base.detail, `${credits} credits (identity ${address}${isEthIdentity(id) ? ', eth' : ''})`].filter(Boolean).join(' · '),
135
+ };
136
+ }
137
+ catch (e) {
138
+ return { backend: 'arweave', ok: base.ok, detail: [base.detail, `balance check failed: ${e.message}`].filter(Boolean).join(' · ') };
139
+ }
140
+ }
141
+ /**
142
+ * The one storage-config probe both `abx storage show --check` and `abx doctor` call — dispatches to
143
+ * the right per-backend check above. Resolving the backend can throw (missing required config, e.g.
144
+ * cloud with no endpoint/bucket) — same as every other `resolveBackend` call site, and the caller's
145
+ * existing try/catch around it is the right place to handle that, not this function.
146
+ */
147
+ export async function probeStorageBackend(opts, checkOpts = {}) {
148
+ const backend = resolveBackend(opts);
149
+ if (backend.id === 'cloud' || backend.id === 's3')
150
+ return checkCloudBackend(backend, opts.cloud, checkOpts);
151
+ if (backend.id === 'arweave')
152
+ return checkArweaveBackend(backend, opts.arweave, checkOpts);
153
+ return checkViaHealth(backend, checkOpts);
154
+ }
155
+ //# sourceMappingURL=probe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe.js","sourceRoot":"","sources":["../src/probe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAC,cAAc,EAAE,aAAa,EAAE,oBAAoB,EAAE,aAAa,EAAqB,MAAM,cAAc,CAAC;AACpH,OAAO,EAAC,cAAc,EAA6B,MAAM,cAAc,CAAC;AAwCxE,+FAA+F;AAC/F,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAEtC;;;6CAG6C;AAC7C,KAAK,UAAU,IAAI,CAAI,CAAa,EAAE,EAAU,EAAE,OAAe;IAC/D,IAAI,KAAoC,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;QAC/C,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IACH,IAAI,CAAC;QACH,OAAO,MAAM,O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abx-sdk';
3
+ export type { LocatorNetwork } from '@artblocks/abx-sdk';
4
+ /**
5
+ * Is a locator **retrievable** yet — not just accepted?
6
+ *
7
+ * An upload service answers "accepted" the moment it has your bytes; a gateway answers "serving"
8
+ * only once they have propagated to it, and on Arweave that gap runs to minutes. Nothing in the
9
+ * upload result distinguishes the two, so the natural implementation — upload during a mint, write
10
+ * the locator into the token — mints a token that renders broken for the first minutes of its life.
11
+ *
12
+ * Two independent integrators hit this eight days apart. The first rebuilt this layer themselves
13
+ * (ranged GETs, a propagating/ready model, retry ladders lengthened after measuring real times) and
14
+ * concluded "every serious integrator will rebuild some version of this." The second published 32
15
+ * renders and found **32/32 404ing on `arweave.net` while 22/32 already served from `permagate.io`
16
+ * and `vilenarios.com`**, with the uploader reporting `CONFIRMED` throughout. That second
17
+ * observation is why this probes several gateways rather than one: propagation is per-gateway, so
18
+ * "your gateway doesn't have it" and "the network doesn't have it" are different answers, and only
19
+ * one of them means something is wrong.
20
+ */
21
+ export type Readiness =
22
+ /** The gateway this toolkit would actually use serves the bytes. Safe to reference. */
23
+ 'ready'
24
+ /** Another gateway serves it, so the data provably exists on the network — yours hasn't caught
25
+ * up. Waiting is the fix. */
26
+ | 'propagating'
27
+ /** No probed gateway serves it. Deliberately NOT called "propagating": from outside, a locator
28
+ * that is still settling and one that is simply wrong look identical, and claiming the friendlier
29
+ * of the two is how a tool teaches someone to ignore it. */
30
+ | 'unreachable';
31
+ export interface GatewayProbe {
32
+ /** The exact URL asked. */
33
+ url: string;
34
+ /** Host only — what a human recognises. */
35
+ gateway: string;
36
+ /** Whether this gateway served the bytes. */
37
+ serving: boolean;
38
+ /** HTTP status, or null when the request never completed (timeout, DNS, refused). */
39
+ status: number | null;
40
+ contentType: string | null;
41
+ /** Total size when the gateway reported one, else null. A ranged request is used, so this comes
42
+ * from `content-range`'s total rather than `content-length` (which is 1 byte on a 206). */
43
+ bytes: number | null;
44
+ ms: number;
45
+ /** Why the request didn't complete. Absent when it did, whatever the status. */
46
+ error?: string;
47
+ }
48
+ export interface LocatorStatus {
49
+ /** The locator as given. */
50
+ locator: string;
51
+ network: LocatorNetwork;
52
+ /** The txid / CID / absolute URL the locator resolves to. */
53
+ id: string;
54
+ readiness: Readiness;
55
+ /** The gateway a baked locator would actually resolve through — the one that decides whether a
56
+ * marketplace can render this today. */
57
+ primary: GatewayProbe;
58
+ /** Well-known others for the same network. Their whole job is to tell propagation from a bad id. */
59
+ alternates: GatewayProbe[];
60
+ }
61
+ export interface LocatorStatusOptions {
62
+ /** The gateway to treat as primary — normally the one the active backend is configured with, so
63
+ * the verdict is about the gateway that will really be used. Defaults per network. */
64
+ gateway?: string;
65
+ /** Skip the alternates (one request instead of three). The cost is the `propagating` verdict:
66
+ * without them, a locator that hasn't reached your gateway is indistinguishable from a bad one. */
67
+ primaryOnly?: boolean;
68
+ timeoutMs?: number;
69
+ fetchFn?: typeof fetch;
70
+ }
71
+ /** Parse any accepted locator form into its network + id. */
72
+ export declare function parseLocator(locator: string): {
73
+ network: LocatorNetwork;
74
+ id: string;
75
+ };
76
+ /**
77
+ * The gateway BASE for a locator network — **override → env → generic public default**
78
+ * (`ABX_IPFS_GATEWAY`/`ABX_ARWEAVE_GATEWAY`, then `ipfs.io`/`arweave.net`). This is the READ-TIME
79
+ * default for resolving an arbitrary on-chain locator whose upload backend is unknown to the
80
+ * resolver — distinct from {@link ipfsConfigFromEnv}/{@link arweaveConfigFromEnv}'s MODE-aware
81
+ * defaults for a backend this toolkit itself configured to write through (e.g. a `kubo` IPFS
82
+ * gateway defaults to `127.0.0.1:8080`, a locator resolver has no such context and must default
83
+ * to something that resolves for anyone). `http` locators carry their own base (they are already
84
+ * an absolute URL) and never reach here — callers return them verbatim before consulting a gateway.
85
+ *
86
+ * A thin compose over the SDK's split: {@link resolveGatewayBase} used to own the
87
+ * `override ?? env ?? default` line itself (`process.env` read inline); now the pure decision
88
+ * lives in `@artblocks/abx-sdk`'s `resolveGatewayBase` (src/gateways.ts) and the env read in its
89
+ * `gatewayConfigFromEnv`, so this function's whole body is just wiring override → (env or
90
+ * nothing) → the SDK's pure default. Kept here, under this same name and signature, because
91
+ * every existing caller (this package's own `locatorStatus`, token-api's `resolveLocatorUrl`)
92
+ * still wants exactly this three-rung precedence with one call.
93
+ */
94
+ export declare function resolveGatewayBase(network: LocatorNetwork, override?: string): string;
95
+ /**
96
+ * Ask one gateway whether it serves these bytes, reading **headers only**.
97
+ *
98
+ * A ranged request (`Range: bytes=0-0`) is what keeps this cheap: the content in question can be tens of
99
+ * megabytes and the question is only whether it is there. Gateways that ignore `Range` answer 200
100
+ * with the whole body, so the body is cancelled rather than read — without that, checking a large
101
+ * locator would download it.
102
+ */
103
+ export declare function probeGateway(url: string, opts?: {
104
+ timeoutMs?: number;
105
+ fetchFn?: typeof fetch;
106
+ }): Promise<GatewayProbe>;
107
+ /** Accepted-vs-retrievable for one locator, across the gateway that matters and a couple of others. */
108
+ export declare function locatorStatus(locator: string, opts?: LocatorStatusOptions): Promise<LocatorStatus>;
109
+ /** One poll attempt from {@link awaitLocatorReady} — lets a caller narrate progress (a CLI spinner,
110
+ * a log line) without this module printing anything itself (the SDK/storage layers never print). */
111
+ export interface AwaitLocatorReadyEvent {
112
+ /** 1-indexed poll attempt. */
113
+ attempt: number;
114
+ /** Milliseconds since {@link awaitLocatorReady} was called. */
115
+ elapsedMs: number;
116
+ status: LocatorStatus;
117
+ }
118
+ export interface AwaitLocatorReadyOptions {
119
+ /** Forwarded to every {@link locatorStatus} probe. */
120
+ gateway?: string;
121
+ primaryOnly?: boolean;
122
+ /** Per-probe network timeout, forwarded as {@link LocatorStatusOptions.timeoutMs} (NOT the
123
+ * poll's overall deadline — see `timeoutMs` below). Default 6000ms, same as `locatorStatus`. */
124
+ probeTimeoutMs?: number;
125
+ fetchFn?: typeof fetch;
126
+ /** Give up polling once this much total time has elapsed, returning the last status with
127
+ * `ready: false` rather than throwing — a caller decides what "still not ready" means for its
128
+ * own flow. Default 5 minutes: long enough for typical Arweave propagation (this module's whole
129
+ * reason to exist — see the module doc, "the gap runs to minutes"). */
130
+ timeoutMs?: number;
131
+ /** Base delay for the linear backoff between polls (`attempt * pollBaseMs`, via the SDK's
132
+ * {@link linearBackoffDelay} — the same primitive `service.ts`'s retry ladder uses). Default
133
+ * 3000ms, so the very first re-poll is quick and later ones back off. */
134
+ pollBaseMs?: number;
135
+ onEvent?: (e: AwaitLocatorReadyEvent) => void;
136
+ }
137
+ export interface AwaitLocatorReadyResult {
138
+ /** The last status observed — `'ready'` iff {@link ready} is true. */
139
+ status: LocatorStatus;
140
+ attempts: number;
141
+ elapsedMs: number;
142
+ /** False when the deadline was hit before `status.readiness` reached `'ready'`. */
143
+ ready: boolean;
144
+ }
145
+ /**
146
+ * Poll {@link locatorStatus} until it reports `'ready'` or the deadline passes.
147
+ *
148
+ * `locatorStatus` alone answers "right now" — the natural next question, for a caller that would
149
+ * otherwise upload during a mint and write the locator into a token that renders broken for its
150
+ * first minutes of life (see the module doc), is "wait until it's actually there." This is that,
151
+ * factored out once so a caller doesn't hand-roll its own poll/backoff loop around a one-shot check.
152
+ *
153
+ * `'propagating'` is treated the same as `'unreachable'` here — both mean "not yet what THIS caller
154
+ * can rely on" — but every intermediate status still reaches `onEvent`, so a caller that wants to
155
+ * distinguish "provably on the network, just behind" from "no evidence yet" can from the events.
156
+ */
157
+ export declare function awaitLocatorReady(locator: string, opts?: AwaitLocatorReadyOptions): Promise<AwaitLocatorReadyResult>;
158
+ //# sourceMappingURL=readiness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readiness.d.ts","sourceRoot":"","sources":["../src/readiness.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAEvD;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,SAAS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