@ethersphere/bee-js 6.0.0-pre.0 → 6.0.0-pre.1

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 (193) hide show
  1. package/README.md +18 -17
  2. package/dist/cjs/bee-debug.js +569 -0
  3. package/dist/cjs/bee.js +873 -0
  4. package/dist/cjs/chunk/bmt.js +55 -0
  5. package/dist/cjs/chunk/cac.js +56 -0
  6. package/dist/cjs/chunk/serialize.js +19 -0
  7. package/dist/cjs/chunk/signer.js +126 -0
  8. package/dist/cjs/chunk/soc.js +159 -0
  9. package/dist/cjs/chunk/span.js +29 -0
  10. package/dist/cjs/feed/identifier.js +35 -0
  11. package/dist/cjs/feed/index.js +116 -0
  12. package/dist/cjs/feed/json.js +28 -0
  13. package/dist/cjs/feed/retrievable.js +58 -0
  14. package/dist/cjs/feed/topic.js +25 -0
  15. package/dist/cjs/feed/type.js +15 -0
  16. package/dist/cjs/index.js +39 -0
  17. package/dist/cjs/modules/bytes.js +62 -0
  18. package/dist/cjs/modules/bzz.js +125 -0
  19. package/dist/cjs/modules/chunk.js +48 -0
  20. package/dist/cjs/modules/debug/balance.js +60 -0
  21. package/dist/cjs/modules/debug/chequebook.js +142 -0
  22. package/dist/cjs/modules/debug/chunk.js +38 -0
  23. package/dist/cjs/modules/debug/connectivity.js +54 -0
  24. package/dist/cjs/modules/debug/settlements.js +32 -0
  25. package/dist/cjs/modules/debug/stake.js +57 -0
  26. package/dist/cjs/modules/debug/stamps.js +68 -0
  27. package/dist/cjs/modules/debug/states.js +64 -0
  28. package/dist/cjs/modules/debug/status.js +148 -0
  29. package/dist/cjs/modules/debug/tag.js +19 -0
  30. package/dist/cjs/modules/debug/transactions.js +64 -0
  31. package/dist/cjs/modules/feed.js +66 -0
  32. package/dist/cjs/modules/pinning.js +63 -0
  33. package/dist/cjs/modules/pss.js +44 -0
  34. package/dist/cjs/modules/soc.js +32 -0
  35. package/dist/cjs/modules/status.js +15 -0
  36. package/dist/cjs/modules/stewardship.js +28 -0
  37. package/dist/cjs/modules/tag.js +77 -0
  38. package/dist/cjs/package.json +8 -0
  39. package/dist/cjs/types/debug.js +10 -0
  40. package/dist/cjs/types/index.js +51 -0
  41. package/dist/cjs/utils/bytes.js +121 -0
  42. package/dist/cjs/utils/collection.browser.js +23 -0
  43. package/dist/cjs/utils/collection.js +59 -0
  44. package/dist/cjs/utils/collection.node.js +71 -0
  45. package/dist/cjs/utils/data.browser.js +61 -0
  46. package/dist/cjs/utils/data.js +45 -0
  47. package/dist/cjs/utils/error.js +16 -0
  48. package/dist/cjs/utils/eth.js +199 -0
  49. package/dist/cjs/utils/expose.js +44 -0
  50. package/dist/cjs/utils/file.js +38 -0
  51. package/dist/cjs/utils/hash.js +21 -0
  52. package/dist/cjs/utils/headers.js +59 -0
  53. package/dist/cjs/utils/hex.js +150 -0
  54. package/dist/cjs/utils/http.js +30 -0
  55. package/dist/cjs/utils/pss.js +18 -0
  56. package/dist/cjs/utils/reference.js +36 -0
  57. package/dist/cjs/utils/stamps.js +17 -0
  58. package/dist/cjs/utils/stream.js +146 -0
  59. package/dist/cjs/utils/tar.js +25 -0
  60. package/dist/cjs/utils/type.js +434 -0
  61. package/dist/cjs/utils/uint64.js +29 -0
  62. package/dist/cjs/utils/url.js +56 -0
  63. package/dist/index.browser.min.js +3 -0
  64. package/dist/index.browser.min.js.LICENSE.txt +50 -0
  65. package/dist/index.browser.min.js.map +1 -0
  66. package/dist/{src → mjs}/bee-debug.js +101 -185
  67. package/dist/{src → mjs}/bee.js +81 -234
  68. package/dist/{src → mjs}/chunk/bmt.js +4 -10
  69. package/dist/{src → mjs}/chunk/cac.js +0 -3
  70. package/dist/{src → mjs}/chunk/signer.js +1 -18
  71. package/dist/{src → mjs}/chunk/soc.js +17 -29
  72. package/dist/{src → mjs}/chunk/span.js +2 -5
  73. package/dist/{src → mjs}/feed/identifier.js +0 -6
  74. package/dist/{src → mjs}/feed/index.js +24 -27
  75. package/dist/{src → mjs}/feed/json.js +2 -5
  76. package/dist/{src → mjs}/feed/retrievable.js +7 -21
  77. package/dist/{src → mjs}/feed/topic.js +0 -2
  78. package/dist/{src → mjs}/index.js +2 -2
  79. package/dist/{src → mjs}/modules/bytes.js +16 -19
  80. package/dist/{src → mjs}/modules/bzz.js +33 -40
  81. package/dist/{src → mjs}/modules/chunk.js +11 -13
  82. package/dist/mjs/modules/debug/balance.js +53 -0
  83. package/dist/mjs/modules/debug/chequebook.js +135 -0
  84. package/dist/{src → mjs}/modules/debug/chunk.js +10 -12
  85. package/dist/mjs/modules/debug/connectivity.js +45 -0
  86. package/dist/mjs/modules/debug/settlements.js +27 -0
  87. package/dist/mjs/modules/debug/stake.js +51 -0
  88. package/dist/mjs/modules/debug/stamps.js +61 -0
  89. package/dist/mjs/modules/debug/states.js +58 -0
  90. package/dist/{src → mjs}/modules/debug/status.js +46 -37
  91. package/dist/mjs/modules/debug/tag.js +15 -0
  92. package/dist/mjs/modules/debug/transactions.js +59 -0
  93. package/dist/{src → mjs}/modules/feed.js +15 -21
  94. package/dist/mjs/modules/pinning.js +56 -0
  95. package/dist/{src → mjs}/modules/pss.js +7 -9
  96. package/dist/{src → mjs}/modules/soc.js +6 -7
  97. package/dist/mjs/modules/status.js +11 -0
  98. package/dist/mjs/modules/stewardship.js +23 -0
  99. package/dist/mjs/modules/tag.js +72 -0
  100. package/dist/mjs/package.json +8 -0
  101. package/dist/{src → mjs}/types/debug.js +0 -1
  102. package/dist/{src → mjs}/types/index.js +0 -4
  103. package/dist/{src → mjs}/utils/bytes.js +8 -17
  104. package/dist/{src/utils/collection-browser.js → mjs/utils/collection.browser.js} +0 -1
  105. package/dist/{src → mjs}/utils/collection.js +0 -12
  106. package/dist/{src/utils/collection-node.js → mjs/utils/collection.node.js} +0 -13
  107. package/dist/{src → mjs}/utils/data.browser.js +2 -11
  108. package/dist/{src → mjs}/utils/data.js +0 -7
  109. package/dist/mjs/utils/error.js +11 -0
  110. package/dist/{src → mjs}/utils/eth.js +6 -28
  111. package/dist/{src → mjs}/utils/expose.js +1 -1
  112. package/dist/{src → mjs}/utils/file.js +4 -9
  113. package/dist/{src → mjs}/utils/hash.js +0 -1
  114. package/dist/{src → mjs}/utils/headers.js +5 -13
  115. package/dist/{src → mjs}/utils/hex.js +6 -25
  116. package/dist/mjs/utils/http.js +22 -0
  117. package/dist/{src → mjs}/utils/pss.js +0 -2
  118. package/dist/{src → mjs}/utils/reference.js +2 -5
  119. package/dist/{src → mjs}/utils/stream.js +3 -26
  120. package/dist/{src → mjs}/utils/tar.js +2 -5
  121. package/dist/{src → mjs}/utils/type.js +23 -80
  122. package/dist/{src → mjs}/utils/uint64.js +0 -1
  123. package/dist/{src → mjs}/utils/url.js +2 -10
  124. package/dist/types/bee-debug.d.ts +71 -46
  125. package/dist/types/bee.d.ts +34 -58
  126. package/dist/types/chunk/bmt.d.ts +1 -1
  127. package/dist/types/chunk/cac.d.ts +1 -1
  128. package/dist/types/chunk/soc.d.ts +9 -9
  129. package/dist/types/chunk/span.d.ts +1 -1
  130. package/dist/types/feed/index.d.ts +10 -10
  131. package/dist/types/feed/json.d.ts +2 -2
  132. package/dist/types/feed/retrievable.d.ts +2 -2
  133. package/dist/types/feed/type.d.ts +1 -1
  134. package/dist/types/index.d.ts +13 -2
  135. package/dist/types/modules/bytes.d.ts +5 -5
  136. package/dist/types/modules/bzz.d.ts +8 -8
  137. package/dist/types/modules/chunk.d.ts +4 -4
  138. package/dist/types/modules/debug/balance.d.ts +9 -9
  139. package/dist/types/modules/debug/chequebook.d.ts +17 -17
  140. package/dist/types/modules/debug/chunk.d.ts +5 -5
  141. package/dist/types/modules/debug/connectivity.d.ts +7 -7
  142. package/dist/types/modules/debug/settlements.d.ts +5 -5
  143. package/dist/types/modules/debug/stake.d.ts +21 -0
  144. package/dist/types/modules/debug/stamps.d.ts +7 -7
  145. package/dist/types/modules/debug/states.d.ts +7 -7
  146. package/dist/types/modules/debug/status.d.ts +21 -15
  147. package/dist/types/modules/debug/tag.d.ts +3 -3
  148. package/dist/types/modules/debug/transactions.d.ts +5 -5
  149. package/dist/types/modules/feed.d.ts +3 -3
  150. package/dist/types/modules/pinning.d.ts +7 -7
  151. package/dist/types/modules/pss.d.ts +3 -3
  152. package/dist/types/modules/soc.d.ts +2 -2
  153. package/dist/types/modules/status.d.ts +3 -3
  154. package/dist/types/modules/stewardship.d.ts +3 -3
  155. package/dist/types/modules/tag.d.ts +6 -6
  156. package/dist/types/types/debug.d.ts +35 -2
  157. package/dist/types/types/index.d.ts +45 -88
  158. package/dist/types/utils/error.d.ts +0 -26
  159. package/dist/types/utils/eth.d.ts +6 -6
  160. package/dist/types/utils/expose.d.ts +4 -7
  161. package/dist/types/utils/hash.d.ts +1 -1
  162. package/dist/types/utils/headers.d.ts +1 -1
  163. package/dist/types/utils/hex.d.ts +4 -4
  164. package/dist/types/utils/http.d.ts +12 -21
  165. package/dist/types/utils/stream.d.ts +1 -1
  166. package/dist/types/utils/type.d.ts +3 -2
  167. package/dist/types/utils/uint64.d.ts +1 -1
  168. package/package.json +59 -49
  169. package/dist/index.browser.js +0 -33
  170. package/dist/index.browser.js.map +0 -7
  171. package/dist/src/modules/debug/balance.js +0 -57
  172. package/dist/src/modules/debug/chequebook.js +0 -150
  173. package/dist/src/modules/debug/connectivity.js +0 -45
  174. package/dist/src/modules/debug/settlements.js +0 -29
  175. package/dist/src/modules/debug/stamps.js +0 -64
  176. package/dist/src/modules/debug/states.js +0 -46
  177. package/dist/src/modules/debug/tag.js +0 -16
  178. package/dist/src/modules/debug/transactions.js +0 -69
  179. package/dist/src/modules/pinning.js +0 -60
  180. package/dist/src/modules/status.js +0 -12
  181. package/dist/src/modules/stewardship.js +0 -24
  182. package/dist/src/modules/tag.js +0 -77
  183. package/dist/src/utils/error.js +0 -47
  184. package/dist/src/utils/http.js +0 -162
  185. package/dist/src/utils/merge.js +0 -36
  186. package/dist/src/utils/sleep.js +0 -8
  187. package/dist/types/utils/merge.d.ts +0 -8
  188. package/dist/types/utils/sleep.d.ts +0 -6
  189. /package/dist/{src → mjs}/chunk/serialize.js +0 -0
  190. /package/dist/{src → mjs}/feed/type.js +0 -0
  191. /package/dist/{src → mjs}/utils/stamps.js +0 -0
  192. /package/dist/types/utils/{collection-browser.d.ts → collection.browser.d.ts} +0 -0
  193. /package/dist/types/utils/{collection-node.d.ts → collection.node.d.ts} +0 -0
@@ -7,13 +7,10 @@ import type { Bytes } from '../utils/bytes';
7
7
  import type { BeeError } from '../utils/error';
8
8
  import type { EthAddress, HexEthAddress } from '../utils/eth';
9
9
  import type { HexString } from '../utils/hex';
10
- import type ky from 'ky-universal';
11
- import type { Options as KyOptions } from 'ky';
12
- import type { Readable as NativeReadable } from 'stream';
13
10
  import type { Readable as CompatibilityReadable } from 'readable-stream';
11
+ import type { Readable as NativeReadable } from 'stream';
14
12
  import type { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill';
15
13
  export * from './debug';
16
- export declare type Ky = typeof ky;
17
14
  export interface Dictionary<T> {
18
15
  [Key: string]: T;
19
16
  }
@@ -48,80 +45,45 @@ export declare const FEED_INDEX_HEX_LENGTH = 16;
48
45
  *
49
46
  * @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/access-the-swarm/store-with-encryption)
50
47
  */
51
- export declare type Reference = HexString<typeof REFERENCE_HEX_LENGTH> | HexString<typeof ENCRYPTED_REFERENCE_HEX_LENGTH>;
48
+ export type Reference = HexString<typeof REFERENCE_HEX_LENGTH> | HexString<typeof ENCRYPTED_REFERENCE_HEX_LENGTH>;
52
49
  /**
53
50
  * Type that represents either Swarm's reference in hex string or ESN domain (something.eth).
54
51
  */
55
- export declare type ReferenceOrEns = Reference | string;
52
+ export type ReferenceOrEns = Reference | string;
56
53
  /**
57
54
  * Type that represents either Swarm's reference in hex string, ESN domain (something.eth) or CID using one of the Swarm's codecs.
58
55
  */
59
- export declare type ReferenceCidOrEns = ReferenceOrEns | string;
60
- export declare type PlainBytesReference = Bytes<typeof REFERENCE_BYTES_LENGTH>;
61
- export declare type EncryptedBytesReference = Bytes<typeof ENCRYPTED_REFERENCE_BYTES_LENGTH>;
62
- export declare type BytesReference = PlainBytesReference | EncryptedBytesReference;
63
- export declare type PublicKey = HexString<typeof PUBKEY_HEX_LENGTH>;
64
- export declare type Address = HexString<typeof ADDRESS_HEX_LENGTH>;
56
+ export type ReferenceCidOrEns = ReferenceOrEns | string;
57
+ export type PlainBytesReference = Bytes<typeof REFERENCE_BYTES_LENGTH>;
58
+ export type EncryptedBytesReference = Bytes<typeof ENCRYPTED_REFERENCE_BYTES_LENGTH>;
59
+ export type BytesReference = PlainBytesReference | EncryptedBytesReference;
60
+ export type PublicKey = HexString<typeof PUBKEY_HEX_LENGTH>;
61
+ export type Address = HexString<typeof ADDRESS_HEX_LENGTH>;
65
62
  /**
66
63
  * Type representing Readable stream that abstracts away implementation especially the difference between
67
64
  * browser and NodeJS versions as both are supported.
68
65
  */
69
- export declare type Readable = NativeReadable | CompatibilityReadable | ReadableStream | ReadableStreamPonyfill;
66
+ export type Readable = NativeReadable | CompatibilityReadable | ReadableStream | ReadableStreamPonyfill;
70
67
  /**
71
68
  * BatchId is result of keccak256 hash so 64 hex string without prefix.
72
69
  */
73
- export declare type BatchId = HexString<typeof BATCH_ID_HEX_LENGTH>;
70
+ export type BatchId = HexString<typeof BATCH_ID_HEX_LENGTH>;
74
71
  /**
75
72
  * AddressPrefix is an HexString of length equal or smaller then ADDRESS_HEX_LENGTH.
76
73
  * It represents PSS Address Prefix that is used to define address neighborhood that will receive the PSS message.
77
74
  */
78
- export declare type AddressPrefix = HexString;
79
- /**
80
- * Internal interface that represents configuration for creating a request with Ky
81
- */
82
- export interface KyRequestOptions extends Omit<KyOptions, 'searchParams'> {
83
- path: string;
84
- responseType?: 'json' | 'arraybuffer' | 'stream';
85
- /**
86
- * Overridden parameter that allows undefined as a value.
87
- */
88
- searchParams?: Record<string, string | number | boolean | undefined>;
89
- }
90
- export interface RequestOptions {
91
- /**
92
- * Timeout of requests in milliseconds
93
- */
94
- timeout?: number;
95
- /**
96
- * Configure backoff mechanism for requests retries.
97
- * Specifies how many retries will be performed before failing a request.
98
- * Retries are performed for GET, PUT, HEAD, DELETE, OPTIONS and TRACE requests.
99
- * Default is 2.
100
- */
101
- retry?: number;
102
- /**
103
- * User defined Fetch compatible function
104
- */
105
- fetch?: Fetch;
106
- }
107
- export interface BeeOptions extends RequestOptions {
75
+ export type AddressPrefix = HexString;
76
+ export type BeeRequestOptions = {
77
+ baseURL?: string;
78
+ timeout?: number | false;
79
+ retry?: number | false;
80
+ headers?: Record<string, string>;
81
+ };
82
+ export interface BeeOptions extends BeeRequestOptions {
108
83
  /**
109
84
  * Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance.
110
85
  */
111
86
  signer?: Signer | Uint8Array | string;
112
- /**
113
- * Object that contains default headers that will be present
114
- * in all outgoing bee-js requests for instance of Bee class.
115
- */
116
- defaultHeaders?: Record<string, string>;
117
- /**
118
- * Function that registers listener callback for all outgoing HTTP requests that Bee instance makes.
119
- */
120
- onRequest?: HookCallback<BeeRequest>;
121
- /**
122
- * Function that registers listener callback for all incoming HTTP responses that Bee instance made.
123
- */
124
- onResponse?: HookCallback<BeeResponse>;
125
87
  }
126
88
  export interface UploadResultWithCid extends UploadResult {
127
89
  /**
@@ -145,14 +107,12 @@ export interface UploadResult {
145
107
  */
146
108
  tagUid: number;
147
109
  }
148
- export interface UploadOptions extends RequestOptions {
110
+ export interface UploadOptions {
149
111
  /**
150
112
  * Will pin the data locally in the Bee node as well.
151
113
  *
152
114
  * Locally pinned data is possible to reupload to network if it disappear.
153
115
  *
154
- * **Warning! Not allowed when node is in Gateway mode!**
155
- *
156
116
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
157
117
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
158
118
  */
@@ -160,8 +120,6 @@ export interface UploadOptions extends RequestOptions {
160
120
  /**
161
121
  * Will encrypt the uploaded data and return longer hash which also includes the decryption key.
162
122
  *
163
- * **Warning! Not allowed when node is in Gateway mode!**
164
- *
165
123
  * @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/access-the-swarm/store-with-encryption)
166
124
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
167
125
  * @see Reference
@@ -250,7 +208,7 @@ export interface Tag {
250
208
  */
251
209
  startedAt: string;
252
210
  }
253
- export interface AllTagsOptions extends RequestOptions {
211
+ export interface AllTagsOptions {
254
212
  limit?: number;
255
213
  offset?: number;
256
214
  }
@@ -266,13 +224,13 @@ export interface Pin {
266
224
  reference: string;
267
225
  }
268
226
  /**
269
- * Interface that represents Data passed from Bee and that allows accessing it in different forms..
227
+ * Helper interface that adds utility functions
228
+ * to work more conveniently with bytes in normal
229
+ * user scenarios.
230
+ *
231
+ * Concretely: text(), hex(), json()
270
232
  */
271
- export interface Data {
272
- /**
273
- * The raw binary data in form of Uint8Array
274
- */
275
- bytes(): Uint8Array;
233
+ export interface Data extends Uint8Array {
276
234
  /**
277
235
  * Converts the binary data using UTF-8 decoding into string.
278
236
  */
@@ -299,7 +257,7 @@ export interface CollectionEntry<T> {
299
257
  /**
300
258
  * Represents Collections
301
259
  */
302
- export declare type Collection<T> = Array<CollectionEntry<T>>;
260
+ export type Collection<T> = Array<CollectionEntry<T>>;
303
261
  export interface PssSubscription {
304
262
  readonly topic: string;
305
263
  cancel: () => void;
@@ -315,8 +273,8 @@ export interface BeeGenericResponse {
315
273
  export interface ReferenceResponse {
316
274
  reference: Reference;
317
275
  }
318
- export declare type HttpMethod = 'GET' | 'DELETE' | 'POST' | 'PATCH' | 'PUT';
319
- export declare type HookCallback<V> = (value: V) => void | Promise<void>;
276
+ export type HttpMethod = 'GET' | 'DELETE' | 'POST' | 'PATCH' | 'PUT';
277
+ export type HookCallback<V> = (value: V) => void | Promise<void>;
320
278
  export interface BeeRequest {
321
279
  url: string;
322
280
  method: HttpMethod;
@@ -337,7 +295,7 @@ export declare const TOPIC_HEX_LENGTH = 64;
337
295
  /**
338
296
  * Hex string of length 64 chars without prefix that specifies topics for feed.
339
297
  */
340
- export declare type Topic = HexString<typeof TOPIC_HEX_LENGTH>;
298
+ export type Topic = HexString<typeof TOPIC_HEX_LENGTH>;
341
299
  /**
342
300
  * Result of upload calls.
343
301
  */
@@ -365,7 +323,7 @@ export interface FeedReader {
365
323
  */
366
324
  download(options?: FeedUpdateOptions): Promise<FetchFeedUpdateResponse>;
367
325
  }
368
- export interface JsonFeedOptions extends RequestOptions {
326
+ export interface JsonFeedOptions {
369
327
  /**
370
328
  * Valid only for `get` action, where either this `address` or `signer` has
371
329
  * to be specified.
@@ -448,7 +406,7 @@ export interface PostageBatchBuckets {
448
406
  bucketUpperBound: number;
449
407
  buckets?: BatchBucket[];
450
408
  }
451
- export declare type TransactionHash = BrandedString<'TransactionHash'>;
409
+ export type TransactionHash = BrandedString<'TransactionHash'>;
452
410
  export interface TransactionInfo {
453
411
  transactionHash: TransactionHash;
454
412
  to: HexEthAddress;
@@ -463,7 +421,7 @@ export interface TransactionInfo {
463
421
  /**
464
422
  * Options for creation of postage batch
465
423
  */
466
- export interface PostageBatchOptions extends RequestOptions {
424
+ export interface PostageBatchOptions {
467
425
  /**
468
426
  * Sets label for the postage batch
469
427
  */
@@ -493,14 +451,14 @@ export interface PostageBatchOptions extends RequestOptions {
493
451
  /**
494
452
  * With this type a number should be represented in a string
495
453
  */
496
- export declare type NumberString = FlavoredType<string, 'NumberString'>;
454
+ export type NumberString = FlavoredType<string, 'NumberString'>;
497
455
  /*********************************************************
498
456
  * Ethereum compatible signing interfaces and definitions
499
457
  */
500
458
  export declare const SIGNATURE_HEX_LENGTH = 130;
501
459
  export declare const SIGNATURE_BYTES_LENGTH = 65;
502
- export declare type Signature = Bytes<typeof SIGNATURE_BYTES_LENGTH>;
503
- export declare type PrivateKeyBytes = Bytes<32>;
460
+ export type Signature = Bytes<typeof SIGNATURE_BYTES_LENGTH>;
461
+ export type PrivateKeyBytes = Bytes<32>;
504
462
  /**
505
463
  * Signing function that takes digest in Uint8Array to be signed that has helpers to convert it
506
464
  * conveniently into other types like hex-string (non prefix).
@@ -508,8 +466,8 @@ export declare type PrivateKeyBytes = Bytes<32>;
508
466
  *
509
467
  * @see Data
510
468
  */
511
- declare type SyncSigner = (digest: Data) => Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string;
512
- declare type AsyncSigner = (digest: Data) => Promise<Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string>;
469
+ type SyncSigner = (digest: Data) => Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string;
470
+ type AsyncSigner = (digest: Data) => Promise<Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string>;
513
471
  /**
514
472
  * Interface for implementing Ethereum compatible signing.
515
473
  *
@@ -527,7 +485,7 @@ declare type AsyncSigner = (digest: Data) => Promise<Signature | HexString<typeo
527
485
  * @property address The ethereum address of the signer in bytes.
528
486
  * @see hashWithEthereumPrefix
529
487
  */
530
- export declare type Signer = {
488
+ export type Signer = {
531
489
  sign: SyncSigner | AsyncSigner;
532
490
  address: EthAddress;
533
491
  };
@@ -536,16 +494,15 @@ export declare type Signer = {
536
494
  *
537
495
  * See https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/
538
496
  */
539
- export declare type BrandedType<Type, Name> = Type & {
497
+ export type BrandedType<Type, Name> = Type & {
540
498
  __tag__: Name;
541
499
  };
542
- export declare type BrandedString<Name> = BrandedType<string, Name>;
543
- export declare type FlavoredType<Type, Name> = Type & {
500
+ export type BrandedString<Name> = BrandedType<string, Name>;
501
+ export type FlavoredType<Type, Name> = Type & {
544
502
  __tag__?: Name;
545
503
  };
546
- export declare type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
504
+ export type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
547
505
  interface JsonMap {
548
506
  [key: string]: AnyJson;
549
507
  }
550
- declare type JsonArray = Array<AnyJson>;
551
- export declare type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
508
+ type JsonArray = Array<AnyJson>;
@@ -1,4 +1,3 @@
1
- import type { KyRequestOptions } from '../types';
2
1
  export declare class BeeError extends Error {
3
2
  constructor(message: string);
4
3
  }
@@ -6,28 +5,3 @@ export declare class BeeArgumentError extends BeeError {
6
5
  readonly value: unknown;
7
6
  constructor(message: string, value: unknown);
8
7
  }
9
- export declare class BeeRequestError extends BeeError {
10
- readonly requestOptions: KyRequestOptions;
11
- /**
12
- * @param message
13
- * @param requestOptions KyOptions that were used to assemble the request. THIS MIGHT NOT BE COMPLETE! If custom Ky instance was used that has set defaults then these defaults are not visible in this object!
14
- */
15
- constructor(message: string, requestOptions: KyRequestOptions);
16
- }
17
- export declare class BeeResponseError extends BeeError {
18
- readonly status: number;
19
- readonly response: Response;
20
- readonly responseBody: string;
21
- readonly requestOptions: KyRequestOptions;
22
- /**
23
- * @param status HTTP status code number
24
- * @param response Response returned from the server
25
- * @param responseBody Response body as string which is returned from response.text() call
26
- * @param requestOptions KyOptions that were used to assemble the request. THIS MIGHT NOT BE COMPLETE! If custom Ky instance was used that has set defaults then these defaults are not visible in this object!
27
- * @param message
28
- */
29
- constructor(status: number, response: Response, responseBody: string, requestOptions: KyRequestOptions, message: string);
30
- }
31
- export declare class BeeNotAJsonError extends BeeError {
32
- constructor();
33
- }
@@ -1,9 +1,9 @@
1
- import type { HexString } from './hex';
2
- import type { Bytes } from '../utils/bytes';
3
- import type { BrandedString, Signer } from '../types';
4
- export declare type OverlayAddress = BrandedString<'OverlayAddress'>;
5
- export declare type EthAddress = Bytes<20>;
6
- export declare type HexEthAddress = HexString<40>;
1
+ import { BrandedString, Signer } from '../types';
2
+ import { HexString } from './hex';
3
+ import { Bytes } from './bytes';
4
+ export type OverlayAddress = BrandedString<'OverlayAddress'>;
5
+ export type EthAddress = Bytes<20>;
6
+ export type HexEthAddress = HexString<40>;
7
7
  export declare function makeEthAddress(address: EthAddress | Uint8Array | string | unknown): EthAddress;
8
8
  export declare function makeHexEthAddress(address: EthAddress | Uint8Array | string | unknown): HexEthAddress;
9
9
  /**
@@ -1,11 +1,8 @@
1
1
  export { getCollectionSize } from './collection';
2
- export { getFolderSize } from './collection-node';
3
- export type { Bytes, FlexBytes } from './bytes';
4
- export { isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual, } from './bytes';
5
- export type { HexString, PrefixedHexString } from './hex';
6
- export { makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString, } from './hex';
7
- export type { EthAddress } from './eth';
8
- export { makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner, } from './eth';
2
+ export { getFolderSize } from './collection.node';
3
+ export { Bytes, FlexBytes, isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual, } from './bytes';
4
+ export { HexString, PrefixedHexString, makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString, } from './hex';
5
+ export { EthAddress, makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner, } from './eth';
9
6
  export { readableWebToNode, readableNodeToWeb, isReadableStream, isNodeReadable, normalizeToReadableStream, isReadable, } from './stream';
10
7
  export { keccak256Hash } from './hash';
11
8
  export { makeMaxTarget } from './pss';
@@ -1,5 +1,5 @@
1
1
  import { Message } from 'js-sha3';
2
- import type { Bytes } from './bytes';
2
+ import { Bytes } from './bytes';
3
3
  /**
4
4
  * Helper function for calculating the keccak256 hash with
5
5
  * correct types.
@@ -1,3 +1,3 @@
1
1
  import { BatchId, FileHeaders, UploadOptions } from '../types';
2
- export declare function readFileHeaders(headers: Headers): FileHeaders;
2
+ export declare function readFileHeaders(headers: Record<string, string>): FileHeaders;
3
3
  export declare function extractUploadHeaders(postageBatchId: BatchId, options?: UploadOptions): Record<string, string>;
@@ -1,11 +1,11 @@
1
- import type { Bytes } from '../utils/bytes';
2
- import type { BrandedType, FlavoredType } from '../types';
1
+ import { Bytes } from './bytes';
2
+ import { BrandedType, FlavoredType } from '../types';
3
3
  /**
4
4
  * Nominal type to represent hex strings WITHOUT '0x' prefix.
5
5
  * For example for 32 bytes hex representation you have to use 64 length.
6
6
  * TODO: Make Length mandatory: https://github.com/ethersphere/bee-js/issues/208
7
7
  */
8
- export declare type HexString<Length extends number = number> = FlavoredType<string & {
8
+ export type HexString<Length extends number = number> = FlavoredType<string & {
9
9
  readonly length: Length;
10
10
  }, 'HexString'>;
11
11
  /**
@@ -15,7 +15,7 @@ export declare type HexString<Length extends number = number> = FlavoredType<str
15
15
  * Because of that it does not contain the Length property as the variables
16
16
  * should be validated and converted to HexString ASAP.
17
17
  */
18
- export declare type PrefixedHexString = BrandedType<string, 'PrefixedHexString'>;
18
+ export type PrefixedHexString = BrandedType<string, 'PrefixedHexString'>;
19
19
  /**
20
20
  * Creates unprefixed hex string from wide range of data.
21
21
  *
@@ -1,23 +1,14 @@
1
- import type { BeeRequest, BeeResponse, HookCallback, Ky } from '../types';
2
- import type { Options as KyOptions } from 'ky';
3
- import type { KyRequestOptions } from '../types';
4
- interface KyResponse<T> extends Response {
5
- parsedData: T;
6
- }
7
- export declare function wrapRequestClosure(cb: HookCallback<BeeRequest>): (request: Request) => Promise<void>;
8
- export declare function wrapResponseClosure(cb: HookCallback<BeeResponse>): (request: Request, options: unknown, response: Response) => Promise<void>;
1
+ import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ import { BeeRequestOptions } from '../index';
3
+ export declare const DEFAULT_HTTP_CONFIG: {
4
+ headers: {
5
+ accept: string;
6
+ 'user-agent': string;
7
+ };
8
+ };
9
9
  /**
10
- * Filters out entries that has undefined value from headers object.
11
- * Modifies the original object!
12
- *
13
- * @param obj
10
+ * Main function to make HTTP requests.
11
+ * @param options User defined settings
12
+ * @param config Internal settings and/or Bee settings
14
13
  */
15
- export declare function filterHeaders(obj?: object): Record<string, string> | undefined;
16
- /**
17
- * Main utility function to make HTTP requests.
18
- * @param ky
19
- * @param config
20
- */
21
- export declare function http<T>(ky: Ky, config: KyRequestOptions): Promise<KyResponse<T>>;
22
- export declare function makeDefaultKy(kyConfig: KyOptions): Ky;
23
- export {};
14
+ export declare function http<T>(options: BeeRequestOptions, config: AxiosRequestConfig): Promise<AxiosResponse<T>>;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
+ import { Readable as NodeReadableNative, ReadableOptions as NodeReadableOptions } from 'stream';
2
3
  import { ReadableStream } from 'web-streams-polyfill';
3
- import type { Readable as NodeReadableNative, ReadableOptions as NodeReadableOptions } from 'stream';
4
4
  import { Readable } from '../types';
5
5
  /**
6
6
  * Validates if passed object is either browser's ReadableStream
@@ -1,5 +1,5 @@
1
- import { Address, AddressPrefix, AllTagsOptions, BatchId, CollectionUploadOptions, FileUploadOptions, NumberString, PssMessageHandler, PublicKey, Readable, Reference, Tag, UploadOptions, TransactionHash, RequestOptions, PostageBatchOptions, CashoutOptions, ReferenceOrEns } from '../types';
2
1
  import { ReferenceType } from '@ethersphere/swarm-cid';
2
+ import { Address, AddressPrefix, AllTagsOptions, BatchId, BeeRequestOptions, CashoutOptions, CollectionUploadOptions, FileUploadOptions, NumberString, PostageBatchOptions, PssMessageHandler, PublicKey, Readable, Reference, ReferenceOrEns, Tag, TransactionHash, TransactionOptions, UploadOptions } from '../types';
3
3
  export declare function isUint8Array(obj: unknown): obj is Uint8Array;
4
4
  export declare function isInteger(value: unknown): value is number | NumberString;
5
5
  export declare function isObject(value: unknown): value is Record<string, unknown>;
@@ -45,7 +45,7 @@ export declare function addCidConversionFunction<T extends {
45
45
  };
46
46
  export declare function assertAddress(value: unknown): asserts value is Address;
47
47
  export declare function assertBatchId(value: unknown): asserts value is BatchId;
48
- export declare function assertRequestOptions(value: unknown, name?: string): asserts value is RequestOptions;
48
+ export declare function assertRequestOptions(value: unknown, name?: string): asserts value is BeeRequestOptions;
49
49
  export declare function assertUploadOptions(value: unknown, name?: string): asserts value is UploadOptions;
50
50
  export declare function assertFileUploadOptions(value: unknown): asserts value is FileUploadOptions;
51
51
  export declare function assertCollectionUploadOptions(value: unknown): asserts value is CollectionUploadOptions;
@@ -55,6 +55,7 @@ export declare function assertAddressPrefix(value: unknown): asserts value is Ad
55
55
  export declare function assertPssMessageHandler(value: unknown): asserts value is PssMessageHandler;
56
56
  export declare function assertPublicKey(value: unknown): asserts value is PublicKey;
57
57
  export declare function assertPostageBatchOptions(value: unknown): asserts value is PostageBatchOptions;
58
+ export declare function assertTransactionOptions(value: unknown, name?: string): asserts value is TransactionOptions;
58
59
  export declare function assertCashoutOptions(value: unknown): asserts value is CashoutOptions;
59
60
  /**
60
61
  * Check whether the given parameter is valid data to upload
@@ -1,4 +1,4 @@
1
- import type { Bytes } from '../utils/bytes';
1
+ import { Bytes } from './bytes';
2
2
  export declare function writeUint64LittleEndian(value: number, bytes?: Bytes<8>): Bytes<8>;
3
3
  export declare function writeUint64BigEndian(value: number, bytes?: Bytes<8>): Bytes<8>;
4
4
  export declare function readUint64BigEndian(bytes: Bytes<8>): number;
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "6.0.0-pre.0",
3
+ "version": "6.0.0-pre.1",
4
4
  "description": "Javascript client for Bee",
5
- "type": "module",
6
5
  "keywords": [
7
6
  "bee",
8
7
  "swarm",
@@ -23,17 +22,23 @@
23
22
  "type": "git",
24
23
  "url": "https://github.com/ethersphere/bee-js.git"
25
24
  },
26
- "main": "dist/src/index.js",
25
+ "main": "dist/cjs/index.js",
26
+ "module": "dist/mjs/index.js",
27
27
  "exports": {
28
- ".": "./dist/src/index.js"
28
+ ".": {
29
+ "import": "./dist/mjs/index.js",
30
+ "require": "./dist/cjs/index.js"
31
+ }
29
32
  },
30
33
  "types": "dist/types/index.d.ts",
31
34
  "browser": {
32
35
  "stream": false,
33
- "./dist/src/utils/data.js": "./dist/src/utils/data.browser.js",
34
- "./dist/src/utils/collection-node.js": "./dist/src/utils/collection-browser.js",
35
36
  "./src/utils/data.ts": "./src/utils/data.browser.ts",
36
- "./src/utils/collection-node.ts": "./src/utils/collection-browser.ts"
37
+ "./dist/cjs/utils/data.js": "./dist/cjs/utils/data.browser.js",
38
+ "./dist/mjs/utils/data.js": "./dist/mjs/utils/data.browser.js",
39
+ "./dist/cjs/utils/collection.node.js": "./dist/cjs/utils/collection.browser.js",
40
+ "./dist/mjs/utils/collection.node.js": "./dist/mjs/utils/collection.browser.js",
41
+ "./src/utils/collection.node.ts": "./src/utils/collection.browser.ts"
37
42
  },
38
43
  "files": [
39
44
  "dist"
@@ -41,18 +46,11 @@
41
46
  "scripts": {
42
47
  "prepublishOnly": "cross-env NODE_ENV=production npm run build",
43
48
  "build": "rimraf dist && npm run build:node && npm run build:types && npm run build:browser",
44
- "build:node": "tsc && babel --no-babelrc --plugins \"babel-plugin-add-import-extension\" --out-dir dist/src/ dist/src/",
49
+ "build:node": "tsc -p tsconfig.json && tsc -p tsconfig-mjs.json && ./build-fixup && babel --plugins \"babel-plugin-add-import-extension\" --out-dir dist/mjs/ dist/mjs/",
45
50
  "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
46
- "build:browser": "esbuild src/index.ts --minify --bundle --format=esm --sourcemap --platform=browser --outfile=dist/index.browser.js",
47
- "build:browser:nonminify": "esbuild src/index.ts --bundle --format=esm --sourcemap --platform=browser --outfile=dist/index.browser.js",
51
+ "build:browser": "webpack --progress",
48
52
  "mock-ci": "npm run lint:check && npm run check:types && npm run test",
49
- "test": "npm run build:browser:nonminify && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs 'NODE_OPTIONS=${NODE_OPTIONS:--experimental-vm-modules}' jest --no-cache --verbose --selectProjects=node:unit node:integration dom:integration",
50
- "test:integration:browser": "npm run build:browser:nonminify && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs 'NODE_OPTIONS=${NODE_OPTIONS:--experimental-vm-modules}' jest --no-cache --verbose --selectProjects=dom:integration",
51
- "test:integration:node": "cross-env 'NODE_OPTIONS=${NODE_OPTIONS:--experimental-vm-modules}' jest --no-cache --verbose --selectProjects=node:integration",
52
- "test:integration": "npm run build:browser:nonminify && cross-env JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs 'NODE_OPTIONS=${NODE_OPTIONS:--experimental-vm-modules}' jest --no-cache --verbose --selectProjects=node:integration dom:integration",
53
- "test:unit": "cross-env 'NODE_OPTIONS=${NODE_OPTIONS:--experimental-vm-modules}' jest --no-cache --verbose --selectProjects=node:unit",
54
- "test:node": "cross-env 'NODE_OPTIONS=${NODE_OPTIONS:--experimental-vm-modules}' jest --no-cache --verbose --selectProjects=node:unit node:integration",
55
- "test:browser": "npm run test:integration:browser",
53
+ "test": "mocha",
56
54
  "check:types": "tsc --project tsconfig.test.json",
57
55
  "lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" && prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
58
56
  "lint:check": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
@@ -62,66 +60,78 @@
62
60
  "dependencies": {
63
61
  "@ethersphere/swarm-cid": "^0.1.0",
64
62
  "@types/readable-stream": "^2.3.13",
63
+ "axios": "^1.3.4",
65
64
  "bufferutil": "^4.0.6",
65
+ "cafe-utility": "8.0.0",
66
66
  "elliptic": "^6.5.4",
67
67
  "fetch-blob": "2.1.2",
68
- "isomorphic-ws": "^5.0.0",
68
+ "isomorphic-ws": "^4.0.1",
69
69
  "js-sha3": "^0.8.0",
70
- "ky": "^0.31.4",
71
- "ky-universal": "^0.11.0",
72
- "semver": "^7.3.7",
70
+ "semver": "^7.3.5",
73
71
  "tar-js": "^0.3.0",
74
72
  "utf-8-validate": "^5.0.9",
75
- "web-streams-polyfill": "^4.0.0-beta.1",
73
+ "web-streams-polyfill": "^4.0.0-beta.3",
76
74
  "ws": "^8.7.0"
77
75
  },
78
76
  "devDependencies": {
79
- "@babel/cli": "^7.17.10",
80
- "@babel/core": "^7.18.2",
81
- "@commitlint/cli": "^17.1.2",
82
- "@commitlint/config-conventional": "^17.1.0",
83
- "@ethersphere/bee-factory": "^0.4.1",
77
+ "@babel/cli": "^7.19.3",
78
+ "@babel/core": "^7.20.5",
79
+ "@babel/plugin-proposal-class-properties": "^7.16.7",
80
+ "@babel/plugin-transform-runtime": "^7.17.0",
81
+ "@babel/preset-env": "^7.20.2",
82
+ "@babel/preset-typescript": "^7.18.6",
83
+ "@commitlint/cli": "^17.0.2",
84
+ "@commitlint/config-conventional": "^17.4.2",
85
+ "@ethersphere/bee-factory": "^0.5.2",
84
86
  "@fluffy-spoon/substitute": "^1.208.0",
85
- "@jest/globals": "^29.1.2",
86
- "@jest/test-sequencer": "^29.1.2",
87
87
  "@naholyr/cross-env": "^1.0.0",
88
+ "@types/chai": "^4.3.4",
89
+ "@types/chai-as-promised": "^7.1.5",
88
90
  "@types/content-disposition": "^0.5.4",
89
91
  "@types/debug": "^4.1.7",
90
92
  "@types/elliptic": "^6.4.14",
91
- "@types/expect-puppeteer": "^5.0.1",
92
- "@types/jest-environment-puppeteer": "^5.0.2",
93
- "@types/node": "^18.7.23",
94
- "@types/puppeteer": "^5.4.6",
95
- "@types/semver": "^7.3.12",
93
+ "@types/mocha": "^10.0.1",
94
+ "@types/node": "^18.11.11",
95
+ "@types/semver": "^7.3.9",
96
+ "@types/sinon": "^10.0.13",
97
+ "@types/sinon-chai": "^3.2.9",
96
98
  "@types/ws": "^8.5.3",
97
- "@typescript-eslint/eslint-plugin": "^5.38.1",
98
- "@typescript-eslint/parser": "^5.38.1",
99
+ "@typescript-eslint/eslint-plugin": "^5.46.0",
100
+ "@typescript-eslint/parser": "^5.46.0",
101
+ "babel-loader": "^9.1.0",
99
102
  "babel-plugin-add-import-extension": "^1.6.0",
103
+ "chai": "^4.3.7",
104
+ "chai-as-promised": "^7.1.1",
105
+ "chai-parentheses": "^0.0.2",
100
106
  "cross-blob": "^2.0.1",
107
+ "cross-env": "^7.0.3",
101
108
  "debug": "^4.3.4",
102
109
  "depcheck": "^1.4.3",
103
- "esbuild": "^0.15.8",
104
- "eslint": "^8.23.1",
110
+ "eslint": "^8.13.0",
105
111
  "eslint-config-prettier": "^8.5.0",
106
- "eslint-plugin-jest": "^27.0.4",
107
- "eslint-plugin-prettier": "^4.2.1",
112
+ "eslint-plugin-prettier": "^4.0.0",
108
113
  "eslint-plugin-unused-imports": "^2.0.0",
114
+ "expect": "^29.4.0",
109
115
  "husky": "^8.0.1",
110
- "jest": "^29.1.2",
111
- "jest-puppeteer": "^6.1.1",
112
- "nock": "^13.2.9",
113
- "node-fetch": "^3.2.10",
116
+ "mocha": "^10.2.0",
117
+ "nock": "^13.3.0",
118
+ "playwright-test": "^8.1.2",
114
119
  "prettier": "^2.6.2",
115
- "puppeteer": "^18.0.5",
116
120
  "rimraf": "^3.0.2",
121
+ "sinon": "^15.0.1",
122
+ "sinon-chai": "^3.7.0",
123
+ "terser-webpack-plugin": "^5.3.1",
117
124
  "ts-node": "^10.9.1",
118
- "typescript": "^4.8.4"
125
+ "typescript": "^4.9.5",
126
+ "webpack": "^5.75.0",
127
+ "webpack-bundle-analyzer": "^4.5.0",
128
+ "webpack-cli": "^5.0.1"
119
129
  },
120
130
  "engines": {
121
131
  "node": ">=14.0.0",
122
132
  "npm": ">=6.0.0",
123
- "beeApiVersion": "3.0.2",
124
- "beeDebugApiVersion": "3.0.2",
125
- "bee": "1.7.0-bbf13011"
133
+ "beeApiVersion": "4.0.0",
134
+ "beeDebugApiVersion": "4.0.0",
135
+ "bee": "1.12.0-88c1d236"
126
136
  }
127
137
  }