@ethersphere/bee-js 2.0.0 → 3.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +2 -2
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/dist/src/bee-debug.d.ts +38 -6
  8. package/dist/src/bee.d.ts +34 -46
  9. package/dist/src/modules/chunk.d.ts +2 -10
  10. package/dist/src/modules/debug/stamps.d.ts +2 -0
  11. package/dist/src/modules/debug/status.d.ts +10 -4
  12. package/dist/src/modules/stewardship.d.ts +1 -0
  13. package/dist/src/types/debug.d.ts +11 -0
  14. package/dist/src/types/index.d.ts +6 -7
  15. package/dist/src/utils/bytes.d.ts +1 -1
  16. package/dist/src/utils/expose.d.ts +1 -0
  17. package/dist/src/utils/stamps.d.ts +12 -0
  18. package/package.json +10 -8
  19. package/.babelrc.js +0 -33
  20. package/.depcheckrc.json +0 -27
  21. package/.editorconfig +0 -6
  22. package/.eslintignore +0 -1
  23. package/.eslintrc.js +0 -109
  24. package/.gitattributes +0 -1
  25. package/.github/config.yaml +0 -23
  26. package/.github/workflows/check.yaml +0 -57
  27. package/.github/workflows/publish_npmjs.yaml +0 -20
  28. package/.github/workflows/release_github.yaml +0 -20
  29. package/.github/workflows/tests.yaml +0 -128
  30. package/.huskyrc +0 -5
  31. package/.prettierrc +0 -13
  32. package/.vscode/launch.json +0 -49
  33. package/.vscode/settings.json +0 -39
  34. package/CODEOWNERS +0 -1
  35. package/CODE_OF_CONDUCT.md +0 -76
  36. package/commitlint.config.js +0 -3
  37. package/dist/src/modules/stamps.d.ts +0 -4
  38. package/jest-puppeteer.config.js +0 -5
  39. package/jest.config.ts +0 -85
  40. package/src/bee-debug.ts +0 -559
  41. package/src/bee.ts +0 -1070
  42. package/src/chunk/bmt.ts +0 -55
  43. package/src/chunk/cac.ts +0 -79
  44. package/src/chunk/serialize.ts +0 -16
  45. package/src/chunk/signer.ts +0 -141
  46. package/src/chunk/soc.ts +0 -190
  47. package/src/chunk/span.ts +0 -33
  48. package/src/feed/index.ts +0 -217
  49. package/src/feed/json.ts +0 -33
  50. package/src/feed/topic.ts +0 -23
  51. package/src/feed/type.ts +0 -12
  52. package/src/index.ts +0 -24
  53. package/src/modules/bytes.ts +0 -70
  54. package/src/modules/bzz.ts +0 -179
  55. package/src/modules/chunk.ts +0 -69
  56. package/src/modules/debug/balance.ts +0 -63
  57. package/src/modules/debug/chequebook.ts +0 -175
  58. package/src/modules/debug/chunk.ts +0 -39
  59. package/src/modules/debug/connectivity.ts +0 -61
  60. package/src/modules/debug/settlements.ts +0 -33
  61. package/src/modules/debug/stamps.ts +0 -76
  62. package/src/modules/debug/states.ts +0 -35
  63. package/src/modules/debug/status.ts +0 -35
  64. package/src/modules/debug/tag.ts +0 -19
  65. package/src/modules/debug/transactions.ts +0 -79
  66. package/src/modules/feed.ts +0 -105
  67. package/src/modules/pinning.ts +0 -74
  68. package/src/modules/pss.ts +0 -49
  69. package/src/modules/soc.ts +0 -40
  70. package/src/modules/stamps.ts +0 -59
  71. package/src/modules/status.ts +0 -13
  72. package/src/modules/stewardship.ts +0 -18
  73. package/src/modules/tag.ts +0 -83
  74. package/src/types/debug.ts +0 -204
  75. package/src/types/index.ts +0 -566
  76. package/src/types/ky-universal/common.d.ts +0 -17
  77. package/src/types/ky-universal/hooks.d.ts +0 -103
  78. package/src/types/ky-universal/index.d.ts +0 -125
  79. package/src/types/ky-universal/options.d.ts +0 -235
  80. package/src/types/ky-universal/response.d.ts +0 -38
  81. package/src/types/ky-universal/retry.d.ts +0 -39
  82. package/src/types/tar-js.d.ts +0 -1
  83. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  84. package/src/utils/bytes.ts +0 -144
  85. package/src/utils/collection.ts +0 -151
  86. package/src/utils/data.browser.ts +0 -68
  87. package/src/utils/data.ts +0 -48
  88. package/src/utils/error.ts +0 -23
  89. package/src/utils/eth.ts +0 -229
  90. package/src/utils/expose.ts +0 -48
  91. package/src/utils/file.ts +0 -40
  92. package/src/utils/hash.ts +0 -16
  93. package/src/utils/headers.ts +0 -63
  94. package/src/utils/hex.ts +0 -186
  95. package/src/utils/http.ts +0 -141
  96. package/src/utils/merge.ts +0 -34
  97. package/src/utils/pss.ts +0 -16
  98. package/src/utils/stream.ts +0 -146
  99. package/src/utils/tar.ts +0 -30
  100. package/src/utils/type.ts +0 -394
  101. package/src/utils/uint64.ts +0 -31
  102. package/src/utils/url.ts +0 -52
  103. package/test/bee.sh +0 -187
  104. package/test/data/1.txt +0 -1
  105. package/test/data/2.txt +0 -0
  106. package/test/data/empty +0 -0
  107. package/test/data/sub/3.txt +0 -1
  108. package/test/data/sub//303/251 +0 -0
  109. package/test/data/sub//360/237/230/216 +0 -0
  110. package/test/integration/bee-class.browser.spec.ts +0 -272
  111. package/test/integration/bee-class.spec.ts +0 -631
  112. package/test/integration/bee-debug-class.spec.ts +0 -85
  113. package/test/integration/chunk/bmt.spec.ts +0 -33
  114. package/test/integration/chunk/cac.spec.ts +0 -27
  115. package/test/integration/chunk/soc.spec.ts +0 -38
  116. package/test/integration/feed/index.spec.ts +0 -84
  117. package/test/integration/modules/bytes.spec.ts +0 -23
  118. package/test/integration/modules/bzz.spec.ts +0 -265
  119. package/test/integration/modules/chunk.spec.ts +0 -29
  120. package/test/integration/modules/debug/balance.spec.ts +0 -70
  121. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  122. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  123. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  124. package/test/integration/modules/debug/states.spec.ts +0 -34
  125. package/test/integration/modules/debug/status.spec.ts +0 -65
  126. package/test/integration/modules/debug/tag.spec.ts +0 -27
  127. package/test/integration/modules/debug/transactions.spec.ts +0 -10
  128. package/test/integration/modules/feed.spec.ts +0 -61
  129. package/test/integration/modules/pinning.spec.ts +0 -155
  130. package/test/integration/modules/pss.spec.ts +0 -97
  131. package/test/integration/modules/status.spec.ts +0 -10
  132. package/test/integration/modules/stewardship.spec.ts +0 -32
  133. package/test/integration/modules/tag.spec.ts +0 -51
  134. package/test/test-type-sequencer.js +0 -36
  135. package/test/testpage/testpage.html +0 -20
  136. package/test/tests-setup.ts +0 -94
  137. package/test/unit/assertions.ts +0 -460
  138. package/test/unit/bee-class.spec.ts +0 -976
  139. package/test/unit/bee-debug-class.spec.ts +0 -435
  140. package/test/unit/chunk/bmt.spec.ts +0 -16
  141. package/test/unit/chunk/cac.spec.ts +0 -29
  142. package/test/unit/chunk/serialize.spec.ts +0 -24
  143. package/test/unit/chunk/signer.spec.ts +0 -140
  144. package/test/unit/chunk/soc.spec.ts +0 -25
  145. package/test/unit/chunk/span.spec.ts +0 -38
  146. package/test/unit/feed/json.spec.ts +0 -73
  147. package/test/unit/nock.ts +0 -151
  148. package/test/unit/utils/bytes.spec.ts +0 -32
  149. package/test/unit/utils/collection.spec.ts +0 -22
  150. package/test/unit/utils/eth.spec.ts +0 -224
  151. package/test/unit/utils/hex.spec.ts +0 -115
  152. package/test/unit/utils/stream.spec.ts +0 -30
  153. package/test/unit/utils/type.spec.ts +0 -32
  154. package/test/unit/utils/uint64.spec.ts +0 -102
  155. package/test/utils.ts +0 -328
  156. package/tsconfig.json +0 -18
  157. package/tsconfig.test.json +0 -11
  158. package/typedoc.json +0 -7
  159. package/webpack.config.ts +0 -141
@@ -1,566 +0,0 @@
1
- import type { Identifier, SingleOwnerChunk } from '../chunk/soc'
2
- import type { ChunkReference, FeedUploadOptions } from '../feed'
3
- import type { FeedType } from '../feed/type'
4
- import type { FeedUpdateOptions, FetchFeedUpdateResponse } from '../modules/feed'
5
- import type { Bytes } from '../utils/bytes'
6
- import type { BeeError } from '../utils/error'
7
- import type { EthAddress, HexEthAddress } from '../utils/eth'
8
- import type { HexString } from '../utils/hex'
9
- import type ky from 'ky-universal'
10
-
11
- import type { Readable as NativeReadable } from 'stream'
12
- import type { Readable as CompatibilityReadable } from 'readable-stream'
13
- import type { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill/ponyfill'
14
-
15
- export * from './debug'
16
-
17
- export type Ky = typeof ky
18
-
19
- export interface Dictionary<T> {
20
- [Key: string]: T
21
- }
22
-
23
- export const ADDRESS_HEX_LENGTH = 64
24
- export const PSS_TARGET_HEX_LENGTH_MAX = 4
25
- export const PUBKEY_HEX_LENGTH = 66
26
- export const BATCH_ID_HEX_LENGTH = 64
27
- export const REFERENCE_HEX_LENGTH = 64
28
- export const ENCRYPTED_REFERENCE_HEX_LENGTH = 128
29
- export const REFERENCE_BYTES_LENGTH = 32
30
- export const ENCRYPTED_REFERENCE_BYTES_LENGTH = 64
31
-
32
- /**
33
- * Minimal depth that can be used for creation of postage batch
34
- */
35
- export const STAMPS_DEPTH_MIN = 17
36
-
37
- /**
38
- * Maximal depth that can be used for creation of postage batch
39
- */
40
- export const STAMPS_DEPTH_MAX = 255
41
-
42
- export const TAGS_LIMIT_MIN = 1
43
- export const TAGS_LIMIT_MAX = 1000
44
-
45
- /**
46
- * Generic reference that can be either non-encrypted reference which is a hex string of length 64 or encrypted
47
- * reference which is a hex string of length 128.
48
- *
49
- * Encrypted reference consists of two parts. The reference address itself (like non-encrypted reference) and decryption key.
50
- *
51
- * @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/access-the-swarm/store-with-encryption)
52
- */
53
- export type Reference = HexString<typeof REFERENCE_HEX_LENGTH> | HexString<typeof ENCRYPTED_REFERENCE_HEX_LENGTH>
54
- export type PublicKey = HexString<typeof PUBKEY_HEX_LENGTH>
55
-
56
- export type Address = HexString<typeof ADDRESS_HEX_LENGTH>
57
-
58
- /**
59
- * Type representing Readable stream that abstracts away implementation especially the difference between
60
- * browser and NodeJS versions as both are supported.
61
- */
62
- export type Readable = NativeReadable | CompatibilityReadable | ReadableStream | ReadableStreamPonyfill
63
-
64
- /**
65
- * BatchId is result of keccak256 hash so 64 hex string without prefix.
66
- */
67
- export type BatchId = HexString<typeof BATCH_ID_HEX_LENGTH>
68
-
69
- /**
70
- * AddressPrefix is an HexString of length equal or smaller then ADDRESS_HEX_LENGTH.
71
- * It represents PSS Address Prefix that is used to define address neighborhood that will receive the PSS message.
72
- */
73
- export type AddressPrefix = HexString
74
-
75
- export interface RequestOptions {
76
- /**
77
- * Timeout of requests in milliseconds
78
- */
79
- timeout?: number
80
-
81
- /**
82
- * Configure backoff mechanism for requests retries.
83
- * Specifies how many retries will be performed before failing a request.
84
- * Retries are performed for GET, PUT, HEAD, DELETE, OPTIONS and TRACE requests.
85
- * Default is 2.
86
- */
87
- retry?: number
88
-
89
- /**
90
- * User defined Fetch compatible function
91
- */
92
- fetch?: Fetch
93
- }
94
-
95
- export interface BeeOptions extends RequestOptions {
96
- /**
97
- * Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance.
98
- */
99
- signer?: Signer | Uint8Array | string
100
-
101
- /**
102
- * Object that contains default headers that will be present
103
- * in all outgoing bee-js requests for instance of Bee class.
104
- */
105
- defaultHeaders?: Record<string, string>
106
-
107
- /**
108
- * Function that registers listener callback for all outgoing HTTP requests that Bee instance makes.
109
- */
110
- onRequest?: HookCallback<BeeRequest>
111
-
112
- /**
113
- * Function that registers listener callback for all incoming HTTP responses that Bee instance made.
114
- */
115
- onResponse?: HookCallback<BeeResponse>
116
- }
117
-
118
- /**
119
- * Result of upload calls.
120
- */
121
- export interface UploadResult {
122
- /**
123
- * Reference of the uploaded data
124
- */
125
- reference: Reference
126
-
127
- /**
128
- * Automatically created tag's UID.
129
- *
130
- * There is bug in Bee, that does not return correct CORS header (Access-Control-Expose-Headers) for the `Swarm-Tag` to be exposed
131
- * in browser when uploading collection. The `tagUid` is marked as optional even though in 99% of results
132
- * it is present. The Optional mark will be removed with next Bee release.
133
- * TODO: Remove Optional with next Bee release: https://github.com/ethersphere/bee-js/issues/406
134
- */
135
- tagUid?: number
136
- }
137
-
138
- export interface UploadOptions extends RequestOptions {
139
- /**
140
- * Will pin the data locally in the Bee node as well.
141
- *
142
- * Locally pinned data is possible to reupload to network if it disappear.
143
- *
144
- * **Warning! Not allowed when node is in Gateway mode!**
145
- *
146
- * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
147
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
148
- */
149
- pin?: boolean
150
-
151
- /**
152
- * Will encrypt the uploaded data and return longer hash which also includes the decryption key.
153
- *
154
- * **Warning! Not allowed when node is in Gateway mode!**
155
- *
156
- * @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/access-the-swarm/store-with-encryption)
157
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
158
- * @see Reference
159
- */
160
- encrypt?: boolean
161
-
162
- /**
163
- * Tags keep track of syncing the data with network. This option allows attach existing Tag UUID to the uploaded data.
164
- *
165
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
166
- * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
167
- * @link Tag
168
- */
169
- tag?: number
170
- }
171
-
172
- export interface FileUploadOptions extends UploadOptions {
173
- /**
174
- * Specifies Content-Length for the given data. It is required when uploading with Readable.
175
- *
176
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
177
- */
178
- size?: number
179
-
180
- /**
181
- * Specifies given Content-Type so when loaded in browser the file is correctly represented.
182
- *
183
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
184
- */
185
- contentType?: string
186
- }
187
-
188
- export interface CollectionUploadOptions extends UploadOptions {
189
- /**
190
- * Default file to be returned when the root hash of collection is accessed.
191
- *
192
- * @see [Bee docs - Upload a directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory)
193
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
194
- */
195
- indexDocument?: string
196
-
197
- /**
198
- * Configure custom error document to be returned when a specified path can not be found in collection.
199
- *
200
- * @see [Bee docs - Upload a directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory)
201
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
202
- */
203
- errorDocument?: string
204
- }
205
-
206
- export interface UploadHeaders {
207
- 'swarm-pin'?: string
208
- 'swarm-encrypt'?: string
209
- 'swarm-tag'?: string
210
- 'swarm-postage-batch-id'?: string
211
- }
212
-
213
- /**
214
- * Object that contains infromation about progress of upload of data to network.
215
- *
216
- * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
217
- */
218
- export interface Tag {
219
- /**
220
- * Number of all chunks that the data will be split into.
221
- */
222
- total: number
223
-
224
- /**
225
- * Number of chunks that is locally stored in the Bee node.
226
- */
227
- processed: number
228
-
229
- /**
230
- * Number of chunks that arrived to their designated destination in the network
231
- */
232
- synced: number
233
-
234
- /**
235
- * Unique identifier
236
- */
237
- uid: number
238
-
239
- /**
240
- * When the upload process started
241
- */
242
- startedAt: string
243
- }
244
-
245
- export interface AllTagsOptions extends RequestOptions {
246
- limit?: number
247
- offset?: number
248
- }
249
-
250
- export interface FileHeaders {
251
- name?: string
252
- tagUid?: number
253
- contentType?: string
254
- }
255
-
256
- export interface FileData<T> extends FileHeaders {
257
- data: T
258
- }
259
-
260
- export interface Pin {
261
- reference: string
262
- }
263
-
264
- /**
265
- * Helper interface that adds utility functions
266
- * to work more conveniently with bytes in normal
267
- * user scenarios.
268
- *
269
- * Concretely: text(), hex(), json()
270
- */
271
- export interface Data extends Uint8Array {
272
- /**
273
- * Converts the binary data using UTF-8 decoding into string.
274
- */
275
- text(): string
276
-
277
- /**
278
- * Converts the binary data into hex-string.
279
- */
280
- hex(): HexString
281
-
282
- /**
283
- * Converts the binary data into string which is then parsed into JSON.
284
- */
285
- json(): Record<string, unknown>
286
- }
287
-
288
- /**
289
- * Object represents a file and some of its metadata in [[Directory]] object.
290
- */
291
- export interface CollectionEntry<T> {
292
- data: T
293
-
294
- /**
295
- *
296
- */
297
- path: string
298
- }
299
-
300
- /**
301
- * Represents Collections
302
- */
303
- export type Collection<T> = Array<CollectionEntry<T>>
304
-
305
- export interface PssSubscription {
306
- readonly topic: string
307
- cancel: () => void
308
- }
309
-
310
- export interface PssMessageHandler {
311
- onMessage: (message: Data, subscription: PssSubscription) => void
312
- onError: (error: BeeError, subscription: PssSubscription) => void
313
- }
314
-
315
- export interface BeeGenericResponse {
316
- message: string
317
- code: number
318
- }
319
-
320
- export interface ReferenceResponse {
321
- reference: Reference
322
- }
323
-
324
- export type HttpMethod = 'GET' | 'DELETE' | 'POST' | 'PATCH' | 'PUT'
325
-
326
- export type HookCallback<V> = (value: V) => void | Promise<void>
327
-
328
- export interface BeeRequest {
329
- url: string
330
- method: HttpMethod
331
- headers?: Record<string, string>
332
- params?: Record<string, unknown>
333
- }
334
-
335
- export interface BeeResponse {
336
- headers: Record<string, string>
337
- status: number
338
- statusText?: string
339
- request: BeeRequest
340
- }
341
-
342
- /*********************************************************
343
- * Writers and Readers interfaces
344
- */
345
-
346
- export const TOPIC_BYTES_LENGTH = 32
347
- export const TOPIC_HEX_LENGTH = 64
348
-
349
- /**
350
- * Hex string of length 64 chars without prefix that specifies topics for feed.
351
- */
352
- export type Topic = HexString<typeof TOPIC_HEX_LENGTH>
353
-
354
- /**
355
- * FeedReader is an interface for downloading feed updates
356
- */
357
- export interface FeedReader {
358
- readonly type: FeedType
359
- readonly owner: HexEthAddress
360
- readonly topic: Topic
361
- /**
362
- * Download the latest feed update
363
- */
364
- download(options?: FeedUpdateOptions): Promise<FetchFeedUpdateResponse>
365
- }
366
-
367
- export interface JsonFeedOptions extends RequestOptions {
368
- /**
369
- * Valid only for `get` action, where either this `address` or `signer` has
370
- * to be specified.
371
- */
372
- address?: EthAddress | Uint8Array | string
373
-
374
- /**
375
- * Custom Signer object or private key in either binary or hex form.
376
- * This required for `set` action, and optional for `get` although
377
- * if not specified for `get` then `address` option has to be specified.
378
- */
379
- signer?: Signer | Uint8Array | string
380
- type?: FeedType
381
- }
382
-
383
- /**
384
- * FeedWriter is an interface for updating feeds
385
- */
386
- export interface FeedWriter extends FeedReader {
387
- /**
388
- * Upload a new feed update
389
- *
390
- * @param postageBatchId Postage BatchId to be used to upload the data with
391
- * @param reference The reference to be stored in the new update
392
- * @param options Additional options like `at`
393
- *
394
- * @returns Reference that points at Single Owner Chunk that contains the new update and pointer to the updated chunk reference.
395
- */
396
- upload(
397
- postageBatchId: string | BatchId,
398
- reference: ChunkReference | Reference,
399
- options?: FeedUploadOptions,
400
- ): Promise<Reference>
401
- }
402
-
403
- /**
404
- * Interface for downloading single owner chunks
405
- */
406
- export interface SOCReader {
407
- /**
408
- * Downloads a single owner chunk
409
- *
410
- * @param identifier The identifier of the chunk
411
- */
412
- download: (identifier: Identifier) => Promise<SingleOwnerChunk>
413
- }
414
-
415
- /**
416
- * Interface for downloading and uploading single owner chunks
417
- */
418
- export interface SOCWriter extends SOCReader {
419
- /**
420
- * Uploads a single owner chunk
421
- *
422
- * @param identifier The identifier of the chunk
423
- * @param data The chunk payload data
424
- * @param options Upload options
425
- */
426
- upload: (
427
- postageBatchId: string | BatchId,
428
- identifier: Identifier,
429
- data: Uint8Array,
430
- options?: UploadOptions,
431
- ) => Promise<Reference>
432
- }
433
-
434
- /**
435
- * Interface representing Postage stamp batch.
436
- */
437
- export interface PostageBatch {
438
- batchID: BatchId
439
- utilization: number
440
- usable: boolean
441
- label: '' | string
442
- depth: number
443
- amount: string
444
- bucketDepth: number
445
- blockNumber: number
446
- immutableFlag: boolean
447
- }
448
-
449
- export interface DebugPostageBatch extends PostageBatch {
450
- /**
451
- * The time (in seconds) remaining until the batch expires; -1 signals that the batch never expires; 0 signals that the batch has already expired.
452
- */
453
- batchTTL: number
454
-
455
- exists: boolean
456
- }
457
-
458
- export interface BatchBucket {
459
- bucketID: number
460
- collisions: number
461
- }
462
-
463
- export interface PostageBatchBuckets {
464
- depth: number
465
- bucketDepth: number
466
- bucketUpperBound: number
467
- buckets?: BatchBucket[]
468
- }
469
-
470
- export type TransactionHash = BrandedString<'TransactionHash'>
471
-
472
- export interface TransactionInfo {
473
- transactionHash: TransactionHash
474
- to: HexEthAddress
475
- nonce: number
476
- gasPrice: NumberString
477
- gasLimit: number
478
- data: string
479
- created: string
480
- description: string
481
- value: string
482
- }
483
-
484
- /**
485
- * Options for creation of postage batch
486
- */
487
- export interface PostageBatchOptions extends RequestOptions {
488
- /**
489
- * Sets label for the postage batch
490
- */
491
- label?: string
492
-
493
- /**
494
- * Sets gas price in Wei for the transaction that creates the postage batch
495
- */
496
- gasPrice?: NumberString
497
- immutableFlag?: boolean
498
- }
499
-
500
- /**
501
- * With this type a number should be represented in a string
502
- */
503
- export type NumberString = FlavoredType<string, 'NumberString'>
504
-
505
- /*********************************************************
506
- * Ethereum compatible signing interfaces and definitions
507
- */
508
-
509
- export const SIGNATURE_HEX_LENGTH = 130
510
- export const SIGNATURE_BYTES_LENGTH = 65
511
-
512
- export type Signature = Bytes<typeof SIGNATURE_BYTES_LENGTH>
513
- export type PrivateKeyBytes = Bytes<32>
514
-
515
- /**
516
- * Signing function that takes digest in Uint8Array to be signed that has helpers to convert it
517
- * conveniently into other types like hex-string (non prefix).
518
- * Result of the signing can be returned either in Uint8Array or hex string form.
519
- *
520
- * @see Data
521
- */
522
- type SyncSigner = (digest: Data) => Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string
523
- type AsyncSigner = (digest: Data) => Promise<Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string>
524
-
525
- /**
526
- * Interface for implementing Ethereum compatible signing.
527
- *
528
- * In order to be compatible with Ethereum and its signing method `personal_sign`, the data
529
- * that are passed to sign() function should be prefixed with: `\x19Ethereum Signed Message:\n${data.length}`, hashed
530
- * and only then signed.
531
- * If you are wrapping another signer tool/library (like Metamask or some other Ethereum wallet), you might not have
532
- * to do this prefixing manually if you use the `personal_sign` method. Check documentation of the tool!
533
- * If you are writing your own storage for keys, then you have to prefix the data manually otherwise the Bee node
534
- * will reject the chunks signed by you!
535
- *
536
- * For example see the hashWithEthereumPrefix() function.
537
- *
538
- * @property sign The sign function that can be sync or async. This function takes non-prefixed data. See above.
539
- * @property address The ethereum address of the signer in bytes.
540
- * @see hashWithEthereumPrefix
541
- */
542
- export type Signer = {
543
- sign: SyncSigner | AsyncSigner
544
- address: EthAddress
545
- }
546
-
547
- /**
548
- * These type are used to create new nominal types
549
- *
550
- * See https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/
551
- */
552
- export type BrandedType<Type, Name> = Type & { __tag__: Name }
553
-
554
- export type BrandedString<Name> = BrandedType<string, Name>
555
-
556
- export type FlavoredType<Type, Name> = Type & { __tag__?: Name }
557
-
558
- // JSON typings
559
- // by @indiescripter at https://github.com/microsoft/TypeScript/issues/1897#issuecomment-338650717
560
- export type AnyJson = boolean | number | string | null | JsonArray | JsonMap
561
- interface JsonMap {
562
- [key: string]: AnyJson
563
- }
564
- type JsonArray = Array<AnyJson>
565
-
566
- type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
@@ -1,17 +0,0 @@
1
- /**
2
- * Types extracted from Ky as a backport for older Ky non-ESM version
3
- *
4
- * @author https://github.com/sindresorhus
5
- * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
- */
7
-
8
- export declare type Primitive = null | undefined | string | number | boolean | symbol | bigint
9
- export declare type Required<T, K extends keyof T = keyof T> = T &
10
- {
11
- [P in K]-?: T[P]
12
- }
13
- export declare type LiteralUnion<LiteralType extends BaseType, BaseType extends Primitive> =
14
- | LiteralType
15
- | (BaseType & {
16
- _?: never
17
- })
@@ -1,103 +0,0 @@
1
- /**
2
- * Types extracted from Ky as a backport for older Ky non-ESM version
3
- *
4
- * @author https://github.com/sindresorhus
5
- * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
- */
7
-
8
- import type { NormalizedOptions } from './options.js'
9
-
10
- export declare const stop: unique symbol
11
-
12
- export declare type BeforeRequestHook = (
13
- request: Request,
14
- options: NormalizedOptions,
15
- ) => Request | Response | void | Promise<Request | Response | void>
16
- export declare type BeforeRetryState = {
17
- request: Request
18
- response: Response
19
- options: NormalizedOptions
20
- error: Error
21
- retryCount: number
22
- }
23
- export declare type BeforeRetryHook = (options: BeforeRetryState) => typeof stop | void | Promise<typeof stop | void>
24
- export declare type AfterResponseHook = (
25
- request: Request,
26
- options: NormalizedOptions,
27
- response: Response,
28
- ) => Response | void | Promise<Response | void>
29
-
30
- export interface Hooks {
31
- /**
32
- This hook enables you to modify the request right before it is sent. Ky will make no further changes to the request after this. The hook function receives normalized input and options as arguments. You could, forf example, modiy `options.headers` here.
33
-
34
- A [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) can be returned from this hook to completely avoid making a HTTP request. This can be used to mock a request, check an internal cache, etc. An **important** consideration when returning a `Response` from this hook is that all the following hooks will be skipped, so **ensure you only return a `Response` from the last hook**.
35
-
36
- @default []
37
- */
38
- beforeRequest?: BeforeRequestHook[]
39
- /**
40
- This hook enables you to modify the request right before retry. Ky will make no further changes to the request after this. The hook function receives an object with the normalized request and options, an error instance, and the retry count. You could, for example, modify `request.headers` here.
41
-
42
- If the request received a response, the error will be of type `HTTPError` and the `Response` object will be available at `error.response`. Be aware that some types of errors, such as network errors, inherently mean that a response was not received. In that case, the error will not be an instance of `HTTPError`.
43
-
44
- You can prevent Ky from retrying the request by throwing an error. Ky will not handle it in any way and the error will be propagated to the request initiator. The rest of the `beforeRetry` hooks will not be called in this case. Alternatively, you can return the [`ky.stop`](#ky.stop) symbol to do the same thing but without propagating an error (this has some limitations, see `ky.stop` docs for details).
45
-
46
- @example
47
- ```
48
- import ky from 'ky';
49
-
50
- const response = await ky('https://example.com', {
51
- hooks: {
52
- beforeRetry: [
53
- async ({request, options, error, retryCount}) => {
54
- const token = await ky('https://example.com/refresh-token');
55
- options.headers.set('Authorization', `token ${token}`);
56
- }
57
- ]
58
- }
59
- });
60
- ```
61
-
62
- @default []
63
- */
64
- beforeRetry?: BeforeRetryHook[]
65
- /**
66
- This hook enables you to read and optionally modify the response. The hook function receives normalized input, options, and a clone of the response as arguments. The return value of the hook function will be used by Ky as the response object if it's an instance of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
67
-
68
- @default []
69
-
70
- @example
71
- ```
72
- import ky from 'ky';
73
-
74
- const response = await ky('https://example.com', {
75
- hooks: {
76
- afterResponse: [
77
- (_input, _options, response) => {
78
- // You could do something with the response, for example, logging.
79
- log(response);
80
-
81
- // Or return a `Response` instance to overwrite the response.
82
- return new Response('A different response', {status: 200});
83
- },
84
-
85
- // Or retry with a fresh token on a 403 error
86
- async (input, options, response) => {
87
- if (response.status === 403) {
88
- // Get a fresh token
89
- const token = await ky('https://example.com/token').text();
90
-
91
- // Retry with the token
92
- options.headers.set('Authorization', `token ${token}`);
93
-
94
- return ky(input, options);
95
- }
96
- }
97
- ]
98
- }
99
- });
100
- ```
101
- */
102
- afterResponse?: AfterResponseHook[]
103
- }