@ethersphere/bee-js 8.0.2 → 8.2.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 (53) hide show
  1. package/dist/cjs/bee.js +50 -22
  2. package/dist/cjs/chunk/soc.js +4 -6
  3. package/dist/cjs/feed/json.js +1 -1
  4. package/dist/cjs/feed/retrievable.js +1 -1
  5. package/dist/cjs/modules/bytes.js +18 -1
  6. package/dist/cjs/modules/chunk.js +4 -4
  7. package/dist/cjs/modules/debug/status.js +3 -4
  8. package/dist/cjs/modules/envelope.js +23 -0
  9. package/dist/cjs/modules/feed.js +2 -2
  10. package/dist/cjs/modules/pinning.js +1 -1
  11. package/dist/cjs/modules/soc.js +2 -2
  12. package/dist/cjs/utils/error.js +4 -1
  13. package/dist/cjs/utils/expose.js +3 -1
  14. package/dist/cjs/utils/file.js +2 -2
  15. package/dist/cjs/utils/headers.js +11 -6
  16. package/dist/cjs/utils/http.js +1 -1
  17. package/dist/cjs/utils/stamps.js +22 -1
  18. package/dist/cjs/utils/type.js +1 -8
  19. package/dist/index.browser.min.js +1 -1
  20. package/dist/index.browser.min.js.map +1 -1
  21. package/dist/mjs/bee.js +54 -22
  22. package/dist/mjs/chunk/soc.js +4 -6
  23. package/dist/mjs/feed/json.js +3 -1
  24. package/dist/mjs/feed/retrievable.js +1 -1
  25. package/dist/mjs/modules/bytes.js +16 -0
  26. package/dist/mjs/modules/chunk.js +4 -4
  27. package/dist/mjs/modules/debug/status.js +2 -3
  28. package/dist/mjs/modules/envelope.js +33 -0
  29. package/dist/mjs/modules/feed.js +2 -2
  30. package/dist/mjs/modules/pinning.js +1 -1
  31. package/dist/mjs/modules/soc.js +2 -2
  32. package/dist/mjs/utils/error.js +4 -1
  33. package/dist/mjs/utils/expose.js +3 -1
  34. package/dist/mjs/utils/file.js +2 -2
  35. package/dist/mjs/utils/headers.js +10 -6
  36. package/dist/mjs/utils/http.js +1 -1
  37. package/dist/mjs/utils/stamps.js +19 -0
  38. package/dist/mjs/utils/type.js +0 -6
  39. package/dist/types/bee.d.ts +14 -7
  40. package/dist/types/chunk/soc.d.ts +2 -2
  41. package/dist/types/modules/bytes.d.ts +8 -1
  42. package/dist/types/modules/chunk.d.ts +3 -3
  43. package/dist/types/modules/debug/status.d.ts +2 -3
  44. package/dist/types/modules/envelope.d.ts +2 -0
  45. package/dist/types/modules/feed.d.ts +1 -1
  46. package/dist/types/modules/soc.d.ts +1 -1
  47. package/dist/types/types/index.d.ts +10 -2
  48. package/dist/types/utils/error.d.ts +4 -1
  49. package/dist/types/utils/expose.d.ts +6 -3
  50. package/dist/types/utils/headers.d.ts +1 -1
  51. package/dist/types/utils/stamps.d.ts +3 -1
  52. package/dist/types/utils/type.d.ts +0 -1
  53. package/package.json +13 -16
@@ -44,7 +44,7 @@ export declare function makeSingleOwnerChunk(chunk: Chunk, identifier: Identifie
44
44
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
45
45
  * @param options Upload options
46
46
  */
47
- export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions, chunk: SingleOwnerChunk, postageBatchId: BatchId, options?: UploadOptions): Promise<UploadResult>;
47
+ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions, chunk: SingleOwnerChunk, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
48
48
  /**
49
49
  * Helper function to create and upload SOC.
50
50
  *
@@ -55,7 +55,7 @@ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions
55
55
  * @param data The chunk data
56
56
  * @param options
57
57
  */
58
- export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: Signer, postageBatchId: BatchId | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
58
+ export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: Signer, stamp: BatchId | Uint8Array | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
59
59
  /**
60
60
  * Helper function to download SOC.
61
61
  *
@@ -1,4 +1,4 @@
1
- import type { BatchId, BeeRequestOptions, Data, DownloadRedundancyOptions, ReferenceOrEns, UploadOptions, UploadRedundancyOptions } from '../types';
1
+ import type { BatchId, BeeRequestOptions, Data, DownloadRedundancyOptions, ReferenceInformation, ReferenceOrEns, UploadOptions, UploadRedundancyOptions } from '../types';
2
2
  import { UploadResult } from '../types';
3
3
  /**
4
4
  * Upload data to a Bee node
@@ -9,6 +9,13 @@ import { UploadResult } from '../types';
9
9
  * @param options Additional options like tag, encryption, pinning
10
10
  */
11
11
  export declare function upload(requestOptions: BeeRequestOptions, data: string | Uint8Array, postageBatchId: BatchId, options?: UploadOptions & UploadRedundancyOptions): Promise<UploadResult>;
12
+ /**
13
+ * Requests content length for a reference
14
+ *
15
+ * @param requestOptions Options for making requests
16
+ * @param hash Bee content reference
17
+ */
18
+ export declare function head(requestOptions: BeeRequestOptions, hash: ReferenceOrEns): Promise<ReferenceInformation>;
12
19
  /**
13
20
  * Download data as a byte array
14
21
  *
@@ -7,11 +7,11 @@ import type { BatchId, BeeRequestOptions, Data, ReferenceOrEns, UploadOptions, U
7
7
  * Upload expects the chuck data to be set accordingly.
8
8
  *
9
9
  * @param requestOptions Options for making requests
10
- * @param data Chunk data to be uploaded
11
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
10
+ * @param data Chunk data to be uploaded
11
+ * @param stamp BatchId or marshaled stamp to be used for the upload
12
12
  * @param options Additional options like tag, encryption, pinning
13
13
  */
14
- export declare function upload(requestOptions: BeeRequestOptions, data: Uint8Array, postageBatchId: BatchId, options?: UploadOptions): Promise<UploadResult>;
14
+ export declare function upload(requestOptions: BeeRequestOptions, data: Uint8Array, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
15
15
  /**
16
16
  * Download chunk data as a byte array
17
17
  *
@@ -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
  /**
@@ -0,0 +1,2 @@
1
+ import type { BatchId, BeeRequestOptions, Envelope, Reference } from '../types';
2
+ export declare function postEnvelope(requestOptions: BeeRequestOptions, postageBatchId: BatchId, reference: Reference): Promise<Envelope>;
@@ -38,7 +38,7 @@ export interface FetchFeedUpdateResponse extends ReferenceResponse, FeedUpdateHe
38
38
  * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
39
39
  * @param options Additional options, like type (default: 'sequence')
40
40
  */
41
- export declare function createFeedManifest(requestOptions: BeeRequestOptions, owner: HexEthAddress, topic: Topic, postageBatchId: BatchId): Promise<Reference>;
41
+ export declare function createFeedManifest(requestOptions: BeeRequestOptions, owner: HexEthAddress, topic: Topic, stamp: BatchId | Uint8Array | string): Promise<Reference>;
42
42
  /**
43
43
  * Find and retrieve feed update
44
44
  *
@@ -10,4 +10,4 @@ import { BatchId, BeeRequestOptions, UploadOptions, UploadResult } from '../type
10
10
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
11
11
  * @param options Additional options like tag, encryption, pinning
12
12
  */
13
- export declare function upload(requestOptions: BeeRequestOptions, owner: string, identifier: string, signature: string, data: Uint8Array, postageBatchId: BatchId, options?: UploadOptions): Promise<UploadResult>;
13
+ export declare function upload(requestOptions: BeeRequestOptions, owner: string, identifier: string, signature: string, data: Uint8Array, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
@@ -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
  };
@@ -296,6 +295,9 @@ export interface FileData<T> extends FileHeaders {
296
295
  export interface Pin {
297
296
  reference: string;
298
297
  }
298
+ export interface ReferenceInformation {
299
+ contentLength: number;
300
+ }
299
301
  /**
300
302
  * Helper interface that adds utility functions
301
303
  * to work more conveniently with bytes in normal
@@ -447,7 +449,7 @@ export interface SOCWriter extends SOCReader {
447
449
  * @param data The chunk payload data
448
450
  * @param options Upload options
449
451
  */
450
- upload: (postageBatchId: string | BatchId, identifier: Identifier, data: Uint8Array, options?: UploadOptions) => Promise<UploadResult>;
452
+ upload: (stamp: BatchId | Uint8Array | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions) => Promise<UploadResult>;
451
453
  }
452
454
  /**
453
455
  * Interface representing Postage stamp batch.
@@ -520,6 +522,12 @@ export interface PostageBatchOptions {
520
522
  */
521
523
  waitForUsableTimeout?: number;
522
524
  }
525
+ export interface Envelope {
526
+ issuer: Uint8Array;
527
+ index: Uint8Array;
528
+ timestamp: Uint8Array;
529
+ signature: Uint8Array;
530
+ }
523
531
  /**
524
532
  * With this type a number should be represented in a string
525
533
  */
@@ -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
  }
@@ -1,9 +1,12 @@
1
+ import { BatchId, Topic } from '..';
1
2
  export { getCollectionSize } from './collection';
2
3
  export { getFolderSize } from './collection.node';
3
- export { Bytes, FlexBytes, assertBytes, assertFlexBytes, bytesAtOffset, bytesEqual, flexBytesAtOffset, isBytes, isFlexBytes, } from './bytes';
4
- export { HexString, PrefixedHexString, assertHexString, assertPrefixedHexString, bytesToHex, hexToBytes, intToHex, isHexString, makeHexString, } from './hex';
5
- export { EthAddress, capitalizeAddressERC55, ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, makeEthereumWalletSigner, makeHexEthAddress, toLittleEndian, } from './eth';
4
+ export { assertBytes, assertFlexBytes, Bytes, bytesAtOffset, bytesEqual, FlexBytes, flexBytesAtOffset, isBytes, isFlexBytes, } from './bytes';
5
+ export { assertHexString, assertPrefixedHexString, bytesToHex, HexString, hexToBytes, intToHex, isHexString, makeHexString, PrefixedHexString, } from './hex';
6
+ export { capitalizeAddressERC55, EthAddress, ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, makeEthereumWalletSigner, makeHexEthAddress, toLittleEndian, } from './eth';
6
7
  export { keccak256Hash } from './hash';
7
8
  export { makeMaxTarget } from './pss';
8
9
  export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampEffectiveBytes, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage, } from './stamps';
9
10
  export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from './redundancy';
11
+ export declare const NULL_STAMP: BatchId;
12
+ export declare const NULL_TOPIC: Topic;
@@ -1,5 +1,5 @@
1
1
  import { BatchId, DownloadRedundancyOptions, FileHeaders, UploadOptions, UploadRedundancyOptions } from '../types';
2
2
  export declare function readFileHeaders(headers: Record<string, string>): FileHeaders;
3
- export declare function extractUploadHeaders(postageBatchId: BatchId, options?: UploadOptions): Record<string, string>;
3
+ export declare function extractUploadHeaders(stamp: BatchId | Uint8Array | string, options?: UploadOptions): Record<string, string>;
4
4
  export declare function extractRedundantUploadHeaders(postageBatchId: BatchId, options?: UploadOptions & UploadRedundancyOptions): Record<string, string>;
5
5
  export declare function extractDownloadHeaders(options?: DownloadRedundancyOptions): Record<string, string>;
@@ -1,4 +1,4 @@
1
- import { NumberString } from '../types';
1
+ import { BatchId, Envelope, NumberString } from '../types';
2
2
  /**
3
3
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
4
4
  *
@@ -62,3 +62,5 @@ export declare function getAmountForTtl(days: number): NumberString;
62
62
  * @returns {number} The calculated depth necessary to achieve the specified capacity.
63
63
  */
64
64
  export declare function getDepthForCapacity(gigabytes: number): number;
65
+ export declare function convertEnvelopeToMarshaledStamp(batchID: BatchId, envelope: Envelope): Uint8Array;
66
+ export declare function marshalStamp(signature: Uint8Array, batchID: Uint8Array, timestamp: Uint8Array, index: Uint8Array): Uint8Array;
@@ -3,7 +3,6 @@ import { ReferenceType } from '@ethersphere/swarm-cid';
3
3
  import { Readable } from 'stream';
4
4
  import { Address, AddressPrefix, AllTagsOptions, BatchId, BeeRequestOptions, CashoutOptions, CollectionUploadOptions, FileUploadOptions, NumberString, PostageBatchOptions, PssMessageHandler, PublicKey, Reference, ReferenceOrEns, Tag, TransactionHash, TransactionOptions, UploadOptions } from '../types';
5
5
  export declare function isReadable(obj: unknown): obj is Readable;
6
- export declare function isUint8Array(obj: unknown): obj is Uint8Array;
7
6
  export declare function isInteger(value: unknown): value is number | NumberString;
8
7
  export declare function isObject(value: unknown): value is Record<string, unknown>;
9
8
  export declare function isStrictlyObject(value: unknown): value is Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "8.0.2",
3
+ "version": "8.2.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -52,17 +52,18 @@
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",
64
65
  "axios": "^0.28.1",
65
- "cafe-utility": "^21.3.1",
66
+ "cafe-utility": "^23.7.0",
66
67
  "elliptic": "^6.5.4",
67
68
  "isomorphic-ws": "^4.0.1",
68
69
  "js-sha3": "^0.8.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
  }