@ethersphere/bee-js 13.1.0 → 13.1.1-upcoming.g157b172

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.
@@ -40,9 +40,7 @@ async function loadRecursively(node, bee, options, requestOptions) {
40
40
  };
41
41
  }
42
42
  const data = (await bee.data.download(fork.node.selfAddress, downloadOptions, requestOptions)).toUint8Array();
43
- const loaded = CoreMantarayNode.unmarshalFromData(data, fork.node.selfAddress);
44
- fork.node.targetAddress = loaded.targetAddress;
45
- fork.node.forks = loaded.forks;
43
+ fork.node.hydrate(data);
46
44
  fork.node.path = fork.prefix;
47
45
  fork.node.parent = node;
48
46
  await loadRecursively(fork.node, bee, options, requestOptions);
@@ -38,7 +38,7 @@ export class Chequebook {
38
38
  min: 1n,
39
39
  name: 'amount'
40
40
  });
41
- const gasPriceString = gasPrice ? asNumberString(amount, {
41
+ const gasPriceString = gasPrice ? asNumberString(gasPrice, {
42
42
  min: 0n,
43
43
  name: 'gasPrice'
44
44
  }) : undefined;
@@ -56,7 +56,7 @@ export class Chequebook {
56
56
  min: 1n,
57
57
  name: 'amount'
58
58
  });
59
- const gasPriceString = gasPrice ? asNumberString(amount, {
59
+ const gasPriceString = gasPrice ? asNumberString(gasPrice, {
60
60
  min: 0n,
61
61
  name: 'gasPrice'
62
62
  }) : undefined;
@@ -1,12 +1,14 @@
1
1
  export class BeeError extends Error {
2
2
  constructor(message) {
3
3
  super(message);
4
+ this.name = 'BeeError';
4
5
  }
5
6
  }
6
7
  export class BeeArgumentError extends BeeError {
7
8
  constructor(message, value) {
8
9
  super(message);
9
10
  this.value = value;
11
+ this.name = 'BeeArgumentError';
10
12
  }
11
13
  }
12
14
  export class BeeResponseError extends BeeError {
@@ -17,6 +19,7 @@ export class BeeResponseError extends BeeError {
17
19
  this.responseBody = responseBody;
18
20
  this.status = status;
19
21
  this.statusText = statusText;
22
+ this.name = 'BeeResponseError';
20
23
  this.response = {
21
24
  status,
22
25
  data: responseBody,
@@ -51,7 +51,7 @@ export async function http(options, config) {
51
51
  params: requestConfig.params
52
52
  });
53
53
  const res = await fetch(url, requestConfig);
54
- if (!res.ok) await throwHttpError(method, url, res, requestConfig.responseType);
54
+ if (!res.ok) await throwHttpError(method, url, res);
55
55
  return toBeeResponse(res, requestConfig.responseType);
56
56
  } catch (e) {
57
57
  if (e instanceof BeeResponseError) throw e;
@@ -86,13 +86,22 @@ function attachBody(config) {
86
86
  };
87
87
  }
88
88
  }
89
- async function throwHttpError(method, url, res, responseType) {
90
- const errBody = await toBeeResponse(res, responseType).catch(() => ({
91
- data: undefined
92
- }));
93
- const bodyMsg = typeof errBody.data === 'string' ? errBody.data : JSON.stringify(errBody.data);
94
- const message = bodyMsg && bodyMsg !== 'undefined' ? `${res.statusText}: ${bodyMsg}` : res.statusText;
95
- throw new BeeResponseError(method, url, message, errBody.data, res.status, res.statusText);
89
+ async function throwHttpError(method, url, res) {
90
+ const data = await readErrorBody(res);
91
+ const bodyMsg = typeof data === 'string' ? data : JSON.stringify(data);
92
+ const message = bodyMsg ? `${res.statusText}: ${bodyMsg}` : res.statusText;
93
+ throw new BeeResponseError(method, url, message, data, res.status, res.statusText);
94
+ }
95
+ async function readErrorBody(res) {
96
+ const raw = await res.text().catch(() => '');
97
+ if (!raw) {
98
+ return undefined;
99
+ }
100
+ try {
101
+ return JSON.parse(raw);
102
+ } catch {
103
+ return raw;
104
+ }
96
105
  }
97
106
  function toBeeError(err, method, url) {
98
107
  if (err.name === 'AbortError') {
@@ -1,7 +1,7 @@
1
1
  import { BatchId, Reference } from '@ethersphere/core-sdk';
2
- import type { BeeRequestOptions, DownloadOptions, EnvelopeWithBatchId, UploadOptions, UploadResult } from '../types';
2
+ import type { BeeRequestOptions, ChunkUploadOptions, DownloadOptions, EnvelopeWithBatchId, UploadResult } from '../types';
3
3
  /**
4
4
  * Raw HTTP calls for the `/chunks` endpoint.
5
5
  */
6
- export declare function upload(requestOptions: BeeRequestOptions, data: Uint8Array, stamp: EnvelopeWithBatchId | BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
6
+ export declare function upload(requestOptions: BeeRequestOptions, data: Uint8Array, stamp: EnvelopeWithBatchId | BatchId | Uint8Array | string, options?: ChunkUploadOptions): Promise<UploadResult>;
7
7
  export declare function download(requestOptions: BeeRequestOptions, reference: Reference | string | Uint8Array, options?: DownloadOptions): Promise<Uint8Array>;
@@ -1,6 +1,6 @@
1
1
  import { BatchId, EthAddress, Identifier, Signature } from '@ethersphere/core-sdk';
2
- import type { BeeRequestOptions, UploadOptions, UploadResult } from '../types';
2
+ import type { BeeRequestOptions, ChunkUploadOptions, UploadResult } from '../types';
3
3
  /**
4
4
  * Raw HTTP calls for the `/soc` endpoint.
5
5
  */
6
- export declare function upload(requestOptions: BeeRequestOptions, owner: EthAddress, identifier: Identifier, signature: Signature, data: Uint8Array, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
6
+ export declare function upload(requestOptions: BeeRequestOptions, owner: EthAddress, identifier: Identifier, signature: Signature, data: Uint8Array, stamp: BatchId | Uint8Array | string, options?: ChunkUploadOptions): Promise<UploadResult>;
@@ -1,5 +1,5 @@
1
1
  import { BatchId, Bytes, Chunk, EthAddress, Identifier, PrivateKey, Reference, SingleOwnerChunk, Span, makeSOCAddress } from '@ethersphere/core-sdk';
2
- import { BeeRequestOptions, UploadOptions, UploadResult } from '../types';
2
+ import { BeeRequestOptions, ChunkUploadOptions, UploadResult } from '../types';
3
3
  export { makeSOCAddress };
4
4
  export type { SingleOwnerChunk };
5
5
  /**
@@ -30,7 +30,7 @@ export declare function makeSingleOwnerChunk(address: Reference, span: Span, pay
30
30
  * @param stamp Postage BatchId that will be assigned to uploaded data
31
31
  * @param options Upload options
32
32
  */
33
- export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions, chunk: SingleOwnerChunk, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
33
+ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions, chunk: SingleOwnerChunk, stamp: BatchId | Uint8Array | string, options?: ChunkUploadOptions): Promise<UploadResult>;
34
34
  /**
35
35
  * Helper function to create and upload SOC.
36
36
  *
@@ -41,8 +41,8 @@ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions
41
41
  * @param data The chunk data
42
42
  * @param options
43
43
  */
44
- export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
45
- export declare function uploadSingleOwnerChunkWithWrappedChunk(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, wrappedChunk: Chunk, options?: UploadOptions): Promise<UploadResult>;
44
+ export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: Uint8Array, options?: ChunkUploadOptions): Promise<UploadResult>;
45
+ export declare function uploadSingleOwnerChunkWithWrappedChunk(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, wrappedChunk: Chunk, options?: ChunkUploadOptions): Promise<UploadResult>;
46
46
  /**
47
47
  * Helper function to download SOC.
48
48
  *
@@ -1,6 +1,6 @@
1
1
  import { BatchId, Chunk as ContentAddressedChunk, Reference } from '@ethersphere/core-sdk';
2
2
  import { SingleOwnerChunk } from '../chunk/soc';
3
- import type { BeeRequestOptions, DownloadOptions, EnvelopeWithBatchId, UploadOptions } from '../types';
3
+ import type { BeeRequestOptions, ChunkUploadOptions, DownloadOptions, EnvelopeWithBatchId } from '../types';
4
4
  import { UploadResult } from '../types';
5
5
  import type { BeeContext } from './context';
6
6
  /**
@@ -21,7 +21,7 @@ export declare class Chunk {
21
21
  * @param options Additional options like tag, encryption, pinning, content-type and request options
22
22
  * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
23
23
  */
24
- upload(stamp: EnvelopeWithBatchId | BatchId | Uint8Array | string, data: Uint8Array | ContentAddressedChunk | SingleOwnerChunk, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
24
+ upload(stamp: EnvelopeWithBatchId | BatchId | Uint8Array | string, data: Uint8Array | ContentAddressedChunk | SingleOwnerChunk, options?: ChunkUploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
25
25
  /**
26
26
  * Downloads a chunk as a `Uint8Array`.
27
27
  *
@@ -1,5 +1,5 @@
1
1
  import { BatchId, Bytes, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Topic } from '@ethersphere/core-sdk';
2
- import type { BeeRequestOptions, GsocMessageHandler, GsocSubscription, PssMessageHandler, PssSubscription, UploadOptions } from '../types';
2
+ import type { BeeRequestOptions, ChunkUploadOptions, GsocMessageHandler, GsocSubscription, PssMessageHandler, PssSubscription } from '../types';
3
3
  import type { BeeContext } from './context';
4
4
  /**
5
5
  * Messaging protocols — PSS (Postal Service for Swarm) and GSOC. Method names keep
@@ -61,7 +61,7 @@ export declare class Messaging {
61
61
  * @param options
62
62
  * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
63
63
  */
64
- gsocSend(postageBatchId: BatchId | Uint8Array | string, signer: PrivateKey | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: string | Uint8Array, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<import("../types").UploadResult>;
64
+ gsocSend(postageBatchId: BatchId | Uint8Array | string, signer: PrivateKey | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: string | Uint8Array, options?: ChunkUploadOptions, requestOptions?: BeeRequestOptions): Promise<import("../types").UploadResult>;
65
65
  /**
66
66
  * Subscribes to GSOC messages for the specified owner (of the signer) and identifier.
67
67
  *
@@ -137,6 +137,12 @@ export interface UploadOptions {
137
137
  */
138
138
  deferred?: boolean;
139
139
  }
140
+ export interface ChunkUploadOptions extends Omit<UploadOptions, 'act' | 'actHistoryAddress'> {
141
+ /** @deprecated Bee ignores ACT on `/chunks` and `/soc`; this option will be removed. */
142
+ act?: boolean;
143
+ /** @deprecated Bee ignores ACT on `/chunks` and `/soc`; this option will be removed. */
144
+ actHistoryAddress?: Reference | Uint8Array | string;
145
+ }
140
146
  /**
141
147
  * Add redundancy to the data being uploaded so that downloaders can download it with better UX.
142
148
  * 0 value is default and does not add any redundancy to the file.
@@ -396,7 +402,7 @@ export interface SOCWriter extends SOCReader {
396
402
  * @param data The chunk payload data
397
403
  * @param options Upload options
398
404
  */
399
- upload: (stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: Uint8Array, options?: UploadOptions) => Promise<UploadResult>;
405
+ upload: (stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: Uint8Array, options?: ChunkUploadOptions) => Promise<UploadResult>;
400
406
  }
401
407
  export interface GlobalPostageBatch {
402
408
  batchID: BatchId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "13.1.0",
3
+ "version": "13.1.1-upcoming.g157b172",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -75,7 +75,7 @@
75
75
  "debug": "^4.4.3",
76
76
  "isomorphic-ws": "^5.0.0",
77
77
  "semver": "^7.3.5",
78
- "@ethersphere/core-sdk": "^0.1.1",
78
+ "@ethersphere/core-sdk": "^0.2.2",
79
79
  "ws": "^8.21.0",
80
80
  "zod": "^4.4.3"
81
81
  },