1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 | "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.addFile = exports.usage = exports.detachDomain = exports.updateDomainPins = exports.listAllDomainPins = exports.listDomainPins = exports.getDomain = exports.attachDomain = exports.listDomains = exports.publishTarget = exports.deleteName = exports.getName = exports.createName = exports.listNames = exports.getUpload = exports.startUpload = exports.unpin = exports.getPin = exports.pin = exports.listAllPins = exports.listPins = void 0;
const errors_js_1 = require("./errors.js");
const gate_js_1 = require("./gate.js");
const http = __importStar(require("./http.js"));
/** GET /ipfs/pins — List your pins (offset-paginated). */
const listPins = (client, query) => http.get(client, '/ipfs/pins', { query });
exports.listPins = listPins;
/** Every pin, following offset pagination (page `limit` defaults to 100). */
const listAllPins = (client, query) => http.paginateOffset(client, '/ipfs/pins', 'pins', { query });
exports.listAllPins = listAllPins;
/** POST /ipfs/pins — Pin by CID (202; billing starts once pinned). */
const pin = (client, body) => http.post(client, '/ipfs/pins', { body });
exports.pin = pin;
/** GET /ipfs/pins/{id} — Pin detail. */
const getPin = (client, id) => http.get(client, '/ipfs/pins/{id}', { params: { id } });
exports.getPin = getPin;
/** DELETE /ipfs/pins/{id} — Unpin (202; free). */
const unpin = (client, id) => http.del(client, '/ipfs/pins/{id}', { params: { id } });
exports.unpin = unpin;
/**
* POST /ipfs/uploads — Start a direct upload. Issues a short-lived
* single-use grant `{ upload: { url, token, ... } }`; POST the raw bytes to
* that URL (see `http.uploadBytes`) then poll `getUpload`.
*/
const startUpload = (client, body) => http.post(client, '/ipfs/uploads', { body });
exports.startUpload = startUpload;
/** GET /ipfs/uploads/{id} — Upload status (issued/completed/failed/expired). */
const getUpload = (client, id) => http.get(client, '/ipfs/uploads/{id}', { params: { id } });
exports.getUpload = getUpload;
/** GET /ipfs/names — List your IPNS names. */
const listNames = (client) => http.get(client, '/ipfs/names');
exports.listNames = listNames;
/** POST /ipfs/names — Create an IPNS name. */
const createName = (client, body) => http.post(client, '/ipfs/names', { body });
exports.createName = createName;
/** GET /ipfs/names/{id} — IPNS name detail. */
const getName = (client, id) => http.get(client, '/ipfs/names/{id}', { params: { id } });
exports.getName = getName;
/** DELETE /ipfs/names/{id} — Delete an IPNS name (202). */
const deleteName = (client, id) => http.del(client, '/ipfs/names/{id}', { params: { id } });
exports.deleteName = deleteName;
/** PUT /ipfs/names/{id}/target — Publish a new target for an IPNS name. */
const publishTarget = (client, id, body) => http.put(client, '/ipfs/names/{id}/target', { params: { id }, body });
exports.publishTarget = publishTarget;
/** GET /ipfs/domains — List your gateway domains. */
const listDomains = (client) => http.get(client, '/ipfs/domains');
exports.listDomains = listDomains;
/**
* POST /ipfs/domains — Attach your own domain as an IPFS gateway. Gated on
* `domain`. The response's `dns_target` is the gateway IPv4 the domain's A
* record must point at on manually mapped rows.
*/
const attachDomain = async (client, body) => {
await (0, gate_js_1.checkGate)(client, 'POST /ipfs/domains', { domain: body.domain });
return http.post(client, '/ipfs/domains', { body });
};
exports.attachDomain = attachDomain;
/** GET /ipfs/domains/{id} — Gateway domain detail. */
const getDomain = (client, id) => http.get(client, '/ipfs/domains/{id}', { params: { id } });
exports.getDomain = getDomain;
/** GET /ipfs/domains/{id}/pins — The pins a gateway domain serves, oldest attachment first. */
const listDomainPins = (client, id, query) => http.get(client, '/ipfs/domains/{id}/pins', { params: { id }, query });
exports.listDomainPins = listDomainPins;
/** Every pin a gateway domain serves, following offset pagination. */
const listAllDomainPins = (client, id, query) => http.paginateOffset(client, '/ipfs/domains/{id}/pins', 'pins', { params: { id }, query });
exports.listAllDomainPins = listAllDomainPins;
/** Resolve the gateway's domain name (only when gated) and run the gate. */
const checkGatewayGate = async (client, op, id) => {
if (!client.gate)
return;
const { domain } = await (0, exports.getDomain)(client, id);
await (0, gate_js_1.checkGate)(client, op, { domain: domain?.domain });
};
/**
* POST /ipfs/domains/{id}/pins — Attach or detach the pins a gateway
* domain serves (`add` / `remove` pin ids; idempotent delta). Gated on the
* gateway's domain (resolved via `getDomain` when a gate is set).
*/
const updateDomainPins = async (client, id, body) => {
await checkGatewayGate(client, 'POST /ipfs/domains/{id}/pins', id);
return http.post(client, '/ipfs/domains/{id}/pins', { params: { id }, body });
};
exports.updateDomainPins = updateDomainPins;
/** DELETE /ipfs/domains/{id} — Detach a gateway domain (202). Gated on the gateway's domain. */
const detachDomain = async (client, id) => {
await checkGatewayGate(client, 'DELETE /ipfs/domains/{id}', id);
return http.del(client, '/ipfs/domains/{id}', { params: { id } });
};
exports.detachDomain = detachDomain;
/** GET /ipfs/usage — Storage usage and cost. */
const usage = (client) => http.get(client, '/ipfs/usage');
exports.usage = usage;
const UPLOAD_TERMINAL = new Set(['completed', 'failed', 'expired']);
const toUploadSource = async (source) => {
if (typeof source !== 'string')
return source;
const { readFile } = await Promise.resolve().then(() => __importStar(require('node:fs/promises')));
return new Uint8Array(await readFile(source));
};
/**
* Upload local content to IPFS end to end: start an upload grant, POST the
* bytes to the grant URL, poll until the upload completes, and return the
* final upload (with `cid` and `pin_id`). SOURCE is a file path, bytes, a
* Blob, or a ReadableStream. Throws an uploadFailed error when the upload
* fails or expires, or a timeout error when the deadline passes first.
*/
const addFile = async (client, source, options = {}) => {
const { name, format, meta } = options;
const startBody = {
...(name === undefined ? {} : { name }),
...(format === undefined ? {} : { format }),
...(meta === undefined ? {} : { meta: { ...meta } }),
};
const { upload } = await (0, exports.startUpload)(client, Object.keys(startBody).length === 0 ? undefined : startBody);
await http.uploadBytes(upload.url, upload.token, await toUploadSource(source), { format, fetch: client.fetch });
const { upload: final } = await http.pollUntil(() => (0, exports.getUpload)(client, upload.id), (r) => UPLOAD_TERMINAL.has(r.upload.status), {
intervalMs: options.intervalMs,
timeoutMs: options.timeoutMs ?? 300000,
message: `Timed out waiting for IPFS upload ${upload.id}`,
sleep: client.sleep,
});
if (final.status === 'completed')
return final;
throw (0, errors_js_1.uploadFailed)(`IPFS upload ${final.id} ${final.status}`, final);
};
exports.addFile = addFile;
|