@ethersphere/bee-js 7.1.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bee.js +40 -1
- package/dist/cjs/modules/bytes.js +1 -0
- package/dist/cjs/modules/bzz.js +2 -0
- package/dist/cjs/modules/chunk.js +6 -1
- package/dist/cjs/modules/grantee.js +56 -0
- package/dist/cjs/modules/soc.js +6 -1
- package/dist/cjs/utils/headers.js +3 -0
- package/dist/cjs/utils/http.js +5 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +43 -1
- package/dist/mjs/modules/bytes.js +2 -1
- package/dist/mjs/modules/bzz.js +4 -2
- package/dist/mjs/modules/chunk.js +6 -1
- package/dist/mjs/modules/grantee.js +52 -0
- package/dist/mjs/modules/soc.js +6 -1
- package/dist/mjs/utils/headers.js +3 -0
- package/dist/mjs/utils/http.js +7 -0
- package/dist/types/bee.d.ts +37 -4
- package/dist/types/chunk/soc.d.ts +3 -3
- package/dist/types/feed/index.d.ts +2 -2
- package/dist/types/feed/json.d.ts +2 -2
- package/dist/types/modules/chunk.d.ts +2 -2
- package/dist/types/modules/grantee.d.ts +7 -0
- package/dist/types/modules/soc.d.ts +2 -2
- package/dist/types/types/index.d.ts +24 -3
- package/package.json +1 -1
package/dist/cjs/bee.js
CHANGED
|
@@ -47,6 +47,7 @@ const debugStatus = __importStar(require("./modules/debug/status"));
|
|
|
47
47
|
const debugTag = __importStar(require("./modules/debug/tag"));
|
|
48
48
|
const transactions = __importStar(require("./modules/debug/transactions"));
|
|
49
49
|
const feed_2 = require("./modules/feed");
|
|
50
|
+
const grantee = __importStar(require("./modules/grantee"));
|
|
50
51
|
const pinning = __importStar(require("./modules/pinning"));
|
|
51
52
|
const pss = __importStar(require("./modules/pss"));
|
|
52
53
|
const status = __importStar(require("./modules/status"));
|
|
@@ -178,10 +179,48 @@ class Bee {
|
|
|
178
179
|
(0, type_2.assertReferenceOrEns)(reference);
|
|
179
180
|
return chunk.download(this.getRequestOptionsForCall(options), reference);
|
|
180
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Create a grantees list from the given array of public keys.
|
|
184
|
+
*
|
|
185
|
+
* The grantees list can be obtained with the `getGrantees` method.
|
|
186
|
+
*
|
|
187
|
+
* @param postageBatchId - The ID of the postage batch.
|
|
188
|
+
* @param grantees - An array of public keys representing the grantees.
|
|
189
|
+
* @param requestOptions - Optional request options.
|
|
190
|
+
* @returns A promise that resolves to a `GranteesResult` object.
|
|
191
|
+
*/
|
|
192
|
+
async createGrantees(postageBatchId, grantees, requestOptions) {
|
|
193
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
194
|
+
return grantee.createGrantees(this.getRequestOptionsForCall(requestOptions), postageBatchId, grantees);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Retrieves the grantees for a given reference.
|
|
198
|
+
*
|
|
199
|
+
* @param reference - The reference.
|
|
200
|
+
* @param requestOptions - Optional request options.
|
|
201
|
+
* @returns A promise that resolves to a `GetGranteesResult` object.
|
|
202
|
+
*/
|
|
203
|
+
async getGrantees(reference, requestOptions) {
|
|
204
|
+
return grantee.getGrantees(reference, this.getRequestOptionsForCall(requestOptions));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Updates the grantees of a specific reference and history.
|
|
208
|
+
*
|
|
209
|
+
* @param reference - The reference.
|
|
210
|
+
* @param history - The history.
|
|
211
|
+
* @param postageBatchId - The ID of the postage batch.
|
|
212
|
+
* @param grantees - The grantees.
|
|
213
|
+
* @param requestOptions - Optional request options.
|
|
214
|
+
* @returns A Promise that resolves to to a `GranteesResult` object.
|
|
215
|
+
*/
|
|
216
|
+
async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
|
|
217
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
218
|
+
return grantee.patchGrantees(postageBatchId, reference, history, { add: grantees.add || [], revoke: grantees.revoke || [] }, this.getRequestOptionsForCall(requestOptions));
|
|
219
|
+
}
|
|
181
220
|
/**
|
|
182
221
|
* Upload single file to a Bee node.
|
|
183
222
|
*
|
|
184
|
-
* **To make sure that you won't
|
|
223
|
+
* **To make sure that you won't lose critical data it is highly recommended to also
|
|
185
224
|
* locally pin the data with `options.pin = true`**
|
|
186
225
|
*
|
|
187
226
|
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
@@ -28,6 +28,7 @@ async function upload(requestOptions, data, postageBatchId, options) {
|
|
|
28
28
|
return {
|
|
29
29
|
reference: response.data.reference,
|
|
30
30
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
31
|
+
historyAddress: response.headers['swarm-act-history-address'] || '',
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
exports.upload = upload;
|
package/dist/cjs/modules/bzz.js
CHANGED
|
@@ -45,6 +45,7 @@ async function uploadFile(requestOptions, data, postageBatchId, name, options) {
|
|
|
45
45
|
return {
|
|
46
46
|
reference: response.data.reference,
|
|
47
47
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
48
|
+
historyAddress: response.headers['swarm-act-history-address'] || '',
|
|
48
49
|
};
|
|
49
50
|
}
|
|
50
51
|
exports.uploadFile = uploadFile;
|
|
@@ -114,6 +115,7 @@ async function uploadCollection(requestOptions, collection, postageBatchId, opti
|
|
|
114
115
|
return {
|
|
115
116
|
reference: response.data.reference,
|
|
116
117
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
118
|
+
historyAddress: response.headers['swarm-act-history-address'] || '',
|
|
117
119
|
};
|
|
118
120
|
}
|
|
119
121
|
exports.uploadCollection = uploadCollection;
|
|
@@ -4,6 +4,7 @@ exports.download = exports.upload = void 0;
|
|
|
4
4
|
const bytes_1 = require("../utils/bytes");
|
|
5
5
|
const headers_1 = require("../utils/headers");
|
|
6
6
|
const http_1 = require("../utils/http");
|
|
7
|
+
const type_1 = require("../utils/type");
|
|
7
8
|
const endpoint = 'chunks';
|
|
8
9
|
/**
|
|
9
10
|
* Upload chunk to a Bee node
|
|
@@ -28,7 +29,11 @@ async function upload(requestOptions, data, postageBatchId, options) {
|
|
|
28
29
|
},
|
|
29
30
|
responseType: 'json',
|
|
30
31
|
});
|
|
31
|
-
return
|
|
32
|
+
return {
|
|
33
|
+
reference: response.data.reference,
|
|
34
|
+
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
35
|
+
historyAddress: response.headers['swarm-act-history-address'] || '',
|
|
36
|
+
};
|
|
32
37
|
}
|
|
33
38
|
exports.upload = upload;
|
|
34
39
|
/**
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchGrantees = exports.createGrantees = exports.getGrantees = void 0;
|
|
4
|
+
const headers_1 = require("../utils/headers");
|
|
5
|
+
const http_1 = require("../utils/http");
|
|
6
|
+
const granteeEndpoint = 'grantee';
|
|
7
|
+
async function getGrantees(reference, requestOptions) {
|
|
8
|
+
const response = await (0, http_1.http)(requestOptions, {
|
|
9
|
+
method: 'get',
|
|
10
|
+
url: `${granteeEndpoint}/${reference}`,
|
|
11
|
+
responseType: 'json',
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
status: response.status,
|
|
15
|
+
statusText: response.statusText,
|
|
16
|
+
data: response.data.data,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.getGrantees = getGrantees;
|
|
20
|
+
async function createGrantees(requestOptions, postageBatchId, grantees) {
|
|
21
|
+
const response = await (0, http_1.http)(requestOptions, {
|
|
22
|
+
method: 'post',
|
|
23
|
+
url: granteeEndpoint,
|
|
24
|
+
data: { grantees: grantees },
|
|
25
|
+
headers: {
|
|
26
|
+
...(0, headers_1.extractRedundantUploadHeaders)(postageBatchId),
|
|
27
|
+
},
|
|
28
|
+
responseType: 'json',
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
status: response.status,
|
|
32
|
+
statusText: response.statusText,
|
|
33
|
+
ref: response.data.ref,
|
|
34
|
+
historyref: response.data.historyref,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.createGrantees = createGrantees;
|
|
38
|
+
async function patchGrantees(postageBatchId, reference, historyRef, grantees, requestOptions) {
|
|
39
|
+
const response = await (0, http_1.http)(requestOptions, {
|
|
40
|
+
method: 'patch',
|
|
41
|
+
url: `${granteeEndpoint}/${reference}`,
|
|
42
|
+
data: grantees,
|
|
43
|
+
headers: {
|
|
44
|
+
...(0, headers_1.extractRedundantUploadHeaders)(postageBatchId),
|
|
45
|
+
'swarm-act-history-address': historyRef,
|
|
46
|
+
},
|
|
47
|
+
responseType: 'json',
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
status: response.status,
|
|
51
|
+
statusText: response.statusText,
|
|
52
|
+
ref: response.data.ref,
|
|
53
|
+
historyref: response.data.historyref,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
exports.patchGrantees = patchGrantees;
|
package/dist/cjs/modules/soc.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.upload = void 0;
|
|
4
4
|
const headers_1 = require("../utils/headers");
|
|
5
5
|
const http_1 = require("../utils/http");
|
|
6
|
+
const type_1 = require("../utils/type");
|
|
6
7
|
const socEndpoint = 'soc';
|
|
7
8
|
/**
|
|
8
9
|
* Upload single owner chunk (SOC) to a Bee node
|
|
@@ -27,6 +28,10 @@ async function upload(requestOptions, owner, identifier, signature, data, postag
|
|
|
27
28
|
responseType: 'json',
|
|
28
29
|
params: { sig: signature },
|
|
29
30
|
});
|
|
30
|
-
return
|
|
31
|
+
return {
|
|
32
|
+
reference: response.data.reference,
|
|
33
|
+
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
34
|
+
historyAddress: response.headers['swarm-act-history-address'] || '',
|
|
35
|
+
};
|
|
31
36
|
}
|
|
32
37
|
exports.upload = upload;
|
|
@@ -46,6 +46,9 @@ function extractUploadHeaders(postageBatchId, options) {
|
|
|
46
46
|
const headers = {
|
|
47
47
|
'swarm-postage-batch-id': postageBatchId,
|
|
48
48
|
};
|
|
49
|
+
if (options?.act) {
|
|
50
|
+
headers['swarm-act'] = String(options.act);
|
|
51
|
+
}
|
|
49
52
|
if (options?.pin) {
|
|
50
53
|
headers['swarm-pin'] = String(options.pin);
|
|
51
54
|
}
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -25,6 +25,11 @@ async function http(options, config) {
|
|
|
25
25
|
const requestConfig = cafe_utility_1.Objects.deepMerge3(exports.DEFAULT_HTTP_CONFIG, config, options);
|
|
26
26
|
maybeRunOnRequestHook(options, requestConfig);
|
|
27
27
|
const response = await (0, axios_1.default)(requestConfig);
|
|
28
|
+
// Axios does not parse array of strings as JSON
|
|
29
|
+
if (Array.isArray(response.data) && response.data.every(element => typeof element === 'string')) {
|
|
30
|
+
const array = response.data;
|
|
31
|
+
response.data = { data: array };
|
|
32
|
+
}
|
|
28
33
|
// TODO: https://github.com/axios/axios/pull/6253
|
|
29
34
|
return response;
|
|
30
35
|
}
|