@ethersphere/bee-js 8.0.2 → 8.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.
package/dist/mjs/bee.js CHANGED
@@ -78,7 +78,10 @@ export class Bee {
78
78
  async uploadData(postageBatchId, data, options, requestOptions) {
79
79
  assertBatchId(postageBatchId);
80
80
  assertData(data);
81
- if (options) assertUploadOptions(options);
81
+ assertRequestOptions(requestOptions);
82
+ if (options) {
83
+ assertUploadOptions(options);
84
+ }
82
85
  return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
83
86
  }
84
87
  /**
@@ -124,6 +127,7 @@ export class Bee {
124
127
  */
125
128
  async uploadChunk(postageBatchId, data, options, requestOptions) {
126
129
  assertBatchId(postageBatchId);
130
+ assertRequestOptions(requestOptions);
127
131
  if (!(data instanceof Uint8Array)) {
128
132
  throw new TypeError('Data has to be Uint8Array instance!');
129
133
  }
@@ -133,7 +137,9 @@ export class Bee {
133
137
  if (data.length > CHUNK_SIZE + SPAN_SIZE) {
134
138
  throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE}.`, data);
135
139
  }
136
- if (options) assertUploadOptions(options);
140
+ if (options) {
141
+ assertUploadOptions(options);
142
+ }
137
143
  return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
138
144
  }
139
145
  /**
@@ -162,6 +168,7 @@ export class Bee {
162
168
  * @returns A promise that resolves to a `GranteesResult` object.
163
169
  */
164
170
  async createGrantees(postageBatchId, grantees, requestOptions) {
171
+ assertRequestOptions(requestOptions);
165
172
  assertBatchId(postageBatchId);
166
173
  return grantee.createGrantees(this.getRequestOptionsForCall(requestOptions), postageBatchId, grantees);
167
174
  }
@@ -173,6 +180,7 @@ export class Bee {
173
180
  * @returns A promise that resolves to a `GetGranteesResult` object.
174
181
  */
175
182
  async getGrantees(reference, requestOptions) {
183
+ assertRequestOptions(requestOptions);
176
184
  return grantee.getGrantees(reference, this.getRequestOptionsForCall(requestOptions));
177
185
  }
178
186
  /**
@@ -186,6 +194,7 @@ export class Bee {
186
194
  * @returns A Promise that resolves to to a `GranteesResult` object.
187
195
  */
188
196
  async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
197
+ assertRequestOptions(requestOptions);
189
198
  assertBatchId(postageBatchId);
190
199
  return grantee.patchGrantees(postageBatchId, reference, history, {
191
200
  add: grantees.add || [],
@@ -209,9 +218,12 @@ export class Bee {
209
218
  * @returns reference is a content hash of the file
210
219
  */
211
220
  async uploadFile(postageBatchId, data, name, options, requestOptions) {
221
+ assertRequestOptions(requestOptions);
212
222
  assertBatchId(postageBatchId);
213
223
  assertFileData(data);
214
- if (options) assertFileUploadOptions(options);
224
+ if (options) {
225
+ assertFileUploadOptions(options);
226
+ }
215
227
  if (name && typeof name !== 'string') {
216
228
  throw new TypeError('name has to be string or undefined!');
217
229
  }
@@ -284,8 +296,11 @@ export class Bee {
284
296
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
285
297
  */
286
298
  async uploadFiles(postageBatchId, fileList, options, requestOptions) {
299
+ assertRequestOptions(requestOptions);
287
300
  assertBatchId(postageBatchId);
288
- if (options) assertCollectionUploadOptions(options);
301
+ if (options) {
302
+ assertCollectionUploadOptions(options);
303
+ }
289
304
  const data = await makeCollectionFromFileList(fileList);
290
305
  return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST);
291
306
  }
@@ -299,11 +314,12 @@ export class Bee {
299
314
  * @param collection
300
315
  * @param options Collections and request options
301
316
  */
302
- async uploadCollection(postageBatchId, collection, options) {
317
+ async uploadCollection(postageBatchId, collection, options, requestOptions) {
318
+ assertRequestOptions(requestOptions);
303
319
  assertBatchId(postageBatchId);
304
320
  assertCollection(collection);
305
321
  if (options) assertCollectionUploadOptions(options);
306
- return addCidConversionFunction(await bzz.uploadCollection(this.requestOptions, collection, postageBatchId, options), ReferenceType.MANIFEST);
322
+ return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(this.requestOptions), collection, postageBatchId, options), ReferenceType.MANIFEST);
307
323
  }
308
324
  /**
309
325
  * Upload collection of files.
@@ -323,6 +339,7 @@ export class Bee {
323
339
  */
324
340
  async uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions) {
325
341
  assertBatchId(postageBatchId);
342
+ assertRequestOptions(requestOptions);
326
343
  if (options) assertCollectionUploadOptions(options);
327
344
  const data = await makeCollectionFromFS(dir);
328
345
  return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST);
@@ -350,10 +367,10 @@ export class Bee {
350
367
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
351
368
  * @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
352
369
  */
353
- async getAllTags(options) {
354
- assertRequestOptions(options);
370
+ async getAllTags(options, requestOptions) {
371
+ assertRequestOptions(requestOptions);
355
372
  assertAllTagsOptions(options);
356
- return tag.getAllTags(this.getRequestOptionsForCall(options), options?.offset, options?.limit);
373
+ return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
357
374
  }
358
375
  /**
359
376
  * Retrieve tag information from Bee node
@@ -515,7 +532,7 @@ export class Bee {
515
532
  await this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
516
533
  return true;
517
534
  } catch (e) {
518
- if (e?.response?.status === 404) {
535
+ if (e?.status === 404 || e?.status === 500) {
519
536
  return false;
520
537
  }
521
538
  throw e;
@@ -745,7 +762,7 @@ export class Bee {
745
762
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
746
763
  */
747
764
  async setJsonFeed(postageBatchId, topic, data, options, requestOptions) {
748
- assertRequestOptions(options, 'JsonFeedOptions');
765
+ assertRequestOptions(requestOptions, 'JsonFeedOptions');
749
766
  assertBatchId(postageBatchId);
750
767
  const hashedTopic = this.makeFeedTopic(topic);
751
768
  const feedType = options?.type ?? DEFAULT_FEED_TYPE;
@@ -771,8 +788,8 @@ export class Bee {
771
788
  *
772
789
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
773
790
  */
774
- async getJsonFeed(topic, options) {
775
- assertRequestOptions(options, 'JsonFeedOptions');
791
+ async getJsonFeed(topic, options, requestOptions) {
792
+ assertRequestOptions(requestOptions);
776
793
  const hashedTopic = this.makeFeedTopic(topic);
777
794
  const feedType = options?.type ?? DEFAULT_FEED_TYPE;
778
795
  if (options?.signer && options?.address) {
@@ -792,7 +809,7 @@ export class Bee {
792
809
  }
793
810
  }
794
811
  }
795
- const reader = this.makeFeedReader(feedType, hashedTopic, address, options);
812
+ const reader = this.makeFeedReader(feedType, hashedTopic, address, requestOptions);
796
813
  return getJsonData(this, reader);
797
814
  }
798
815
  /**
@@ -1007,6 +1024,7 @@ export class Bee {
1007
1024
  async cashoutLastCheque(address, options, requestOptions) {
1008
1025
  assertCashoutOptions(options);
1009
1026
  assertAddress(address);
1027
+ assertRequestOptions(requestOptions);
1010
1028
  return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
1011
1029
  }
1012
1030
  /**
@@ -1189,6 +1207,7 @@ export class Bee {
1189
1207
  assertPostageBatchOptions(options);
1190
1208
  assertPositiveInteger(amount);
1191
1209
  assertNonNegativeInteger(depth);
1210
+ assertRequestOptions(requestOptions);
1192
1211
  if (depth < STAMPS_DEPTH_MIN) {
1193
1212
  throw new BeeArgumentError(`Depth has to be at least ${STAMPS_DEPTH_MIN}`, depth);
1194
1213
  }
@@ -1348,8 +1367,8 @@ export class Bee {
1348
1367
  * @param options
1349
1368
  */
1350
1369
  async depositStake(amount, options, requestOptions) {
1351
- assertRequestOptions(options);
1352
1370
  assertTransactionOptions(options);
1371
+ assertRequestOptions(requestOptions);
1353
1372
  await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
1354
1373
  }
1355
1374
  /**
@@ -1386,7 +1405,7 @@ export class Bee {
1386
1405
  if (this.signer) {
1387
1406
  return this.signer;
1388
1407
  }
1389
- throw new BeeError('You have to pass Signer as property to either the method call or constructor! Non found.');
1408
+ throw new TypeError('You have to pass Signer as property to either the method call or constructor! Non found.');
1390
1409
  }
1391
1410
  getRequestOptionsForCall(options) {
1392
1411
  return options ? Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
@@ -20,5 +20,7 @@ export async function setJsonData(bee, writer, postageBatchId, data, options, re
20
20
  const {
21
21
  reference
22
22
  } = await bee.uploadData(postageBatchId, serializedData, options, requestOptions);
23
- return writer.upload(postageBatchId, reference);
23
+ return writer.upload(postageBatchId, reference, {
24
+ pin: options?.pin
25
+ });
24
26
  }
@@ -26,7 +26,7 @@ async function isChunkRetrievable(bee, ref, requestOptions) {
26
26
  await bee.downloadChunk(ref, requestOptions);
27
27
  return true;
28
28
  } catch (e) {
29
- if (e?.response?.status === 404) {
29
+ if (e?.status === 404 || e?.status === 500) {
30
30
  return false;
31
31
  }
32
32
  throw e;
@@ -1,9 +1,8 @@
1
1
  import getMajorSemver from 'semver/functions/major.js';
2
2
  import { http } from "../../utils/http.js"; // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
3
3
  // so if you are changing anything about them change the `update_bee` action accordingly!
4
- export const SUPPORTED_BEE_VERSION_EXACT = '1.18.2-759f56f';
5
- export const SUPPORTED_API_VERSION = '4.0.0';
6
- export const SUPPORTED_DEBUG_API_VERSION = '4.0.0';
4
+ export const SUPPORTED_BEE_VERSION_EXACT = '2.2.0-06a0aca7';
5
+ export const SUPPORTED_API_VERSION = '7.1.0';
7
6
  export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.split('-')[0];
8
7
  const NODE_INFO_URL = 'node';
9
8
  const STATUS_URL = 'status';
@@ -52,5 +52,5 @@ export async function getAllPins(requestOptions) {
52
52
  responseType: 'json',
53
53
  url: `${PINNING_ENDPOINT}`
54
54
  });
55
- return response.data.references;
55
+ return response.data.references || [];
56
56
  }
@@ -10,8 +10,11 @@ export class BeeArgumentError extends BeeError {
10
10
  }
11
11
  }
12
12
  export class BeeResponseError extends BeeError {
13
- constructor(message, status, statusText) {
13
+ constructor(method, url, message, responseBody, status, statusText) {
14
14
  super(message);
15
+ this.method = method;
16
+ this.url = url;
17
+ this.responseBody = responseBody;
15
18
  this.status = status;
16
19
  this.statusText = statusText;
17
20
  }
@@ -5,8 +5,8 @@
5
5
  */
6
6
  export function isFile(file) {
7
7
  // browser
8
- if (typeof File === 'function') {
9
- return file instanceof File;
8
+ if (typeof File === 'function' && file instanceof File) {
9
+ return true;
10
10
  }
11
11
  // node.js
12
12
  const f = file;
@@ -32,7 +32,7 @@ export async function http(options, config) {
32
32
  return response;
33
33
  } catch (e) {
34
34
  if (e instanceof AxiosError) {
35
- throw new BeeResponseError(e.message, e.status, e.code);
35
+ throw new BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.code);
36
36
  }
37
37
  throw e;
38
38
  }
@@ -151,9 +151,6 @@ export function assertRequestOptions(value, name = 'RequestOptions') {
151
151
  throw new TypeError(`${name} has to be an object!`);
152
152
  }
153
153
  const options = value;
154
- if (options.retry) {
155
- assertNonNegativeInteger(options.retry, `${name}.retry`);
156
- }
157
154
  if (options.timeout) {
158
155
  assertNonNegativeInteger(options.timeout, `${name}.timeout`);
159
156
  }
@@ -190,7 +190,7 @@ export declare class Bee {
190
190
  * @param collection
191
191
  * @param options Collections and request options
192
192
  */
193
- uploadCollection(postageBatchId: string | BatchId, collection: Collection, options?: CollectionUploadOptions & UploadRedundancyOptions): Promise<UploadResultWithCid>;
193
+ uploadCollection(postageBatchId: string | BatchId, collection: Collection, options?: CollectionUploadOptions & UploadRedundancyOptions, requestOptions?: BeeRequestOptions): Promise<UploadResultWithCid>;
194
194
  /**
195
195
  * Upload collection of files.
196
196
  *
@@ -228,7 +228,7 @@ export declare class Bee {
228
228
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
229
229
  * @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
230
230
  */
231
- getAllTags(options?: AllTagsOptions): Promise<Tag[]>;
231
+ getAllTags(options?: AllTagsOptions, requestOptions?: BeeRequestOptions): Promise<Tag[]>;
232
232
  /**
233
233
  * Retrieve tag information from Bee node
234
234
  *
@@ -464,7 +464,7 @@ export declare class Bee {
464
464
  *
465
465
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
466
466
  */
467
- setJsonFeed<T extends AnyJson>(postageBatchId: string | BatchId, topic: string, data: T, options?: JsonFeedOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
467
+ setJsonFeed<T extends AnyJson>(postageBatchId: string | BatchId, topic: string, data: T, options?: JsonFeedOptions & UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
468
468
  /**
469
469
  * High-level function that allows you to easily get data from feed.
470
470
  * Returned data are parsed using JSON.parse().
@@ -484,7 +484,7 @@ export declare class Bee {
484
484
  *
485
485
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
486
486
  */
487
- getJsonFeed<T extends AnyJson>(topic: string, options?: JsonFeedOptions): Promise<T>;
487
+ getJsonFeed<T extends AnyJson>(topic: string, options?: JsonFeedOptions, requestOptions?: BeeRequestOptions): Promise<T>;
488
488
  /**
489
489
  * Make a new feed topic from a string
490
490
  *
@@ -1,9 +1,8 @@
1
1
  import { BeeRequestOptions } from '../../index';
2
2
  import type { DebugStatus, Health, NodeInfo } from '../../types/debug';
3
3
  import { BeeVersions } from '../../types/debug';
4
- export declare const SUPPORTED_BEE_VERSION_EXACT = "1.18.2-759f56f";
5
- export declare const SUPPORTED_API_VERSION = "4.0.0";
6
- export declare const SUPPORTED_DEBUG_API_VERSION = "4.0.0";
4
+ export declare const SUPPORTED_BEE_VERSION_EXACT = "2.2.0-06a0aca7";
5
+ export declare const SUPPORTED_API_VERSION = "7.1.0";
7
6
  export declare const SUPPORTED_BEE_VERSION: string;
8
7
  export declare function getDebugStatus(requestOptions: BeeRequestOptions): Promise<DebugStatus>;
9
8
  /**
@@ -71,7 +71,6 @@ export type AddressPrefix = HexString;
71
71
  export type BeeRequestOptions = {
72
72
  baseURL?: string;
73
73
  timeout?: number | false;
74
- retry?: number | false;
75
74
  headers?: Record<string, string>;
76
75
  onRequest?: (request: BeeRequest) => void;
77
76
  };
@@ -6,7 +6,10 @@ export declare class BeeArgumentError extends BeeError {
6
6
  constructor(message: string, value: unknown);
7
7
  }
8
8
  export declare class BeeResponseError extends BeeError {
9
+ method: string;
10
+ url: string;
11
+ responseBody?: any;
9
12
  status?: number | undefined;
10
13
  statusText?: string | undefined;
11
- constructor(message: string, status?: number | undefined, statusText?: string | undefined);
14
+ constructor(method: string, url: string, message: string, responseBody?: any, status?: number | undefined, statusText?: string | undefined);
12
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "8.0.2",
3
+ "version": "8.1.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -52,12 +52,13 @@
52
52
  "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
53
53
  "build:browser": "webpack --progress",
54
54
  "mock-ci": "npm run lint:check && npm run check:types && npm run test",
55
- "test": "mocha",
55
+ "test": "jest --config=jest.config.ts --runInBand --verbose",
56
+ "test:coverage": "jest --config=jest.config.ts --coverage",
56
57
  "check:types": "tsc --project tsconfig.test.json",
57
58
  "lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" && prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
58
59
  "lint:check": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
59
60
  "depcheck": "depcheck .",
60
- "bee": "npx fdp-play start --detach --fresh"
61
+ "bee": "npx @fairdatasociety/fdp-play@3.2.0 start --detach --fresh"
61
62
  },
62
63
  "dependencies": {
63
64
  "@ethersphere/swarm-cid": "^0.1.0",
@@ -79,42 +80,38 @@
79
80
  "@commitlint/cli": "^17.0.2",
80
81
  "@commitlint/config-conventional": "^17.4.2",
81
82
  "@fluffy-spoon/substitute": "^1.208.0",
83
+ "@jest/types": "^29.6.3",
82
84
  "@naholyr/cross-env": "^1.0.0",
83
- "@types/chai": "^4.3.4",
84
- "@types/chai-as-promised": "^7.1.5",
85
85
  "@types/elliptic": "^6.4.14",
86
- "@types/mocha": "^10.0.1",
86
+ "@types/jest": "^29.5.13",
87
87
  "@types/node": "^18.11.11",
88
88
  "@types/semver": "^7.3.9",
89
- "@types/sinon": "^10.0.13",
90
- "@types/sinon-chai": "^3.2.9",
91
89
  "@types/ws": "^8.5.3",
92
90
  "@typescript-eslint/eslint-plugin": "^5.46.0",
93
91
  "@typescript-eslint/parser": "^5.46.0",
94
92
  "babel-loader": "^9.1.0",
95
93
  "babel-plugin-add-import-extension": "^1.6.0",
96
- "chai": "^4.3.7",
97
- "chai-as-promised": "^7.1.1",
98
- "chai-parentheses": "^0.0.2",
99
94
  "cross-env": "^7.0.3",
100
95
  "depcheck": "^1.4.7",
101
96
  "eslint": "^8.13.0",
102
97
  "eslint-config-prettier": "^8.5.0",
103
98
  "eslint-plugin-prettier": "^4.0.0",
104
99
  "eslint-plugin-unused-imports": "^2.0.0",
105
- "expect": "^29.4.0",
106
100
  "husky": "^8.0.1",
107
- "mocha": "^10.2.0",
101
+ "jest": "^29.7.0",
108
102
  "nock": "^13.3.0",
109
103
  "playwright-test": "^8.1.2",
110
104
  "prettier": "^2.6.2",
111
105
  "rimraf": "^3.0.2",
112
- "sinon": "^15.0.1",
113
- "sinon-chai": "^3.7.0",
114
106
  "terser-webpack-plugin": "^5.3.1",
107
+ "ts-jest": "^29.2.5",
115
108
  "ts-node": "^10.9.1",
116
109
  "typescript": "^4.9.5",
117
110
  "webpack": "^5.75.0",
118
111
  "webpack-cli": "^5.0.1"
112
+ },
113
+ "engines": {
114
+ "bee": "2.2.0-06a0aca7",
115
+ "beeApiVersion": "7.1.0"
119
116
  }
120
117
  }