@ethersphere/bee-js 2.1.0 → 3.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 (160) hide show
  1. package/README.md +3 -3
  2. package/dist/index.browser.min.js +1 -1
  3. package/dist/index.browser.min.js.map +1 -1
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/src/bee-debug.d.ts +5 -1
  7. package/dist/src/bee.d.ts +23 -46
  8. package/dist/src/modules/chunk.d.ts +2 -10
  9. package/dist/src/modules/debug/status.d.ts +10 -4
  10. package/dist/src/types/debug.d.ts +19 -0
  11. package/dist/src/types/index.d.ts +31 -2
  12. package/dist/src/utils/bytes.d.ts +1 -1
  13. package/dist/src/utils/error.d.ts +21 -2
  14. package/dist/src/utils/expose.d.ts +1 -0
  15. package/dist/src/utils/http.d.ts +7 -9
  16. package/dist/src/utils/stamps.d.ts +12 -0
  17. package/dist/src/utils/type.d.ts +6 -0
  18. package/package.json +28 -27
  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/CHANGELOG.md +0 -520
  35. package/CODEOWNERS +0 -1
  36. package/CODE_OF_CONDUCT.md +0 -76
  37. package/commitlint.config.js +0 -3
  38. package/dist/src/modules/stamps.d.ts +0 -4
  39. package/jest-puppeteer.config.js +0 -5
  40. package/jest.config.ts +0 -85
  41. package/src/bee-debug.ts +0 -601
  42. package/src/bee.ts +0 -1087
  43. package/src/chunk/bmt.ts +0 -55
  44. package/src/chunk/cac.ts +0 -79
  45. package/src/chunk/serialize.ts +0 -16
  46. package/src/chunk/signer.ts +0 -141
  47. package/src/chunk/soc.ts +0 -190
  48. package/src/chunk/span.ts +0 -33
  49. package/src/feed/index.ts +0 -217
  50. package/src/feed/json.ts +0 -33
  51. package/src/feed/topic.ts +0 -23
  52. package/src/feed/type.ts +0 -12
  53. package/src/index.ts +0 -24
  54. package/src/modules/bytes.ts +0 -70
  55. package/src/modules/bzz.ts +0 -179
  56. package/src/modules/chunk.ts +0 -69
  57. package/src/modules/debug/balance.ts +0 -63
  58. package/src/modules/debug/chequebook.ts +0 -175
  59. package/src/modules/debug/chunk.ts +0 -39
  60. package/src/modules/debug/connectivity.ts +0 -61
  61. package/src/modules/debug/settlements.ts +0 -33
  62. package/src/modules/debug/stamps.ts +0 -96
  63. package/src/modules/debug/states.ts +0 -35
  64. package/src/modules/debug/status.ts +0 -34
  65. package/src/modules/debug/tag.ts +0 -19
  66. package/src/modules/debug/transactions.ts +0 -79
  67. package/src/modules/feed.ts +0 -105
  68. package/src/modules/pinning.ts +0 -74
  69. package/src/modules/pss.ts +0 -49
  70. package/src/modules/soc.ts +0 -40
  71. package/src/modules/stamps.ts +0 -59
  72. package/src/modules/status.ts +0 -13
  73. package/src/modules/stewardship.ts +0 -32
  74. package/src/modules/tag.ts +0 -83
  75. package/src/types/debug.ts +0 -204
  76. package/src/types/index.ts +0 -561
  77. package/src/types/ky-universal/common.d.ts +0 -17
  78. package/src/types/ky-universal/hooks.d.ts +0 -103
  79. package/src/types/ky-universal/index.d.ts +0 -125
  80. package/src/types/ky-universal/options.d.ts +0 -235
  81. package/src/types/ky-universal/response.d.ts +0 -38
  82. package/src/types/ky-universal/retry.d.ts +0 -39
  83. package/src/types/tar-js.d.ts +0 -1
  84. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  85. package/src/utils/bytes.ts +0 -144
  86. package/src/utils/collection.ts +0 -151
  87. package/src/utils/data.browser.ts +0 -68
  88. package/src/utils/data.ts +0 -48
  89. package/src/utils/error.ts +0 -23
  90. package/src/utils/eth.ts +0 -229
  91. package/src/utils/expose.ts +0 -48
  92. package/src/utils/file.ts +0 -40
  93. package/src/utils/hash.ts +0 -16
  94. package/src/utils/headers.ts +0 -63
  95. package/src/utils/hex.ts +0 -186
  96. package/src/utils/http.ts +0 -141
  97. package/src/utils/merge.ts +0 -34
  98. package/src/utils/pss.ts +0 -16
  99. package/src/utils/stream.ts +0 -146
  100. package/src/utils/tar.ts +0 -30
  101. package/src/utils/type.ts +0 -394
  102. package/src/utils/uint64.ts +0 -31
  103. package/src/utils/url.ts +0 -52
  104. package/test/bee.sh +0 -187
  105. package/test/data/1.txt +0 -1
  106. package/test/data/2.txt +0 -0
  107. package/test/data/empty +0 -0
  108. package/test/data/sub/3.txt +0 -1
  109. package/test/data/sub//303/251 +0 -0
  110. package/test/data/sub//360/237/230/216 +0 -0
  111. package/test/integration/bee-class.browser.spec.ts +0 -272
  112. package/test/integration/bee-class.spec.ts +0 -648
  113. package/test/integration/bee-debug-class.spec.ts +0 -114
  114. package/test/integration/chunk/bmt.spec.ts +0 -33
  115. package/test/integration/chunk/cac.spec.ts +0 -27
  116. package/test/integration/chunk/soc.spec.ts +0 -38
  117. package/test/integration/feed/index.spec.ts +0 -84
  118. package/test/integration/modules/bytes.spec.ts +0 -23
  119. package/test/integration/modules/bzz.spec.ts +0 -265
  120. package/test/integration/modules/chunk.spec.ts +0 -29
  121. package/test/integration/modules/debug/balance.spec.ts +0 -70
  122. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  123. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  124. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  125. package/test/integration/modules/debug/states.spec.ts +0 -34
  126. package/test/integration/modules/debug/status.spec.ts +0 -65
  127. package/test/integration/modules/debug/tag.spec.ts +0 -27
  128. package/test/integration/modules/debug/transactions.spec.ts +0 -10
  129. package/test/integration/modules/feed.spec.ts +0 -61
  130. package/test/integration/modules/pinning.spec.ts +0 -155
  131. package/test/integration/modules/pss.spec.ts +0 -105
  132. package/test/integration/modules/status.spec.ts +0 -10
  133. package/test/integration/modules/stewardship.spec.ts +0 -32
  134. package/test/integration/modules/tag.spec.ts +0 -51
  135. package/test/test-type-sequencer.js +0 -36
  136. package/test/testpage/testpage.html +0 -20
  137. package/test/tests-setup.ts +0 -94
  138. package/test/unit/assertions.ts +0 -460
  139. package/test/unit/bee-class.spec.ts +0 -976
  140. package/test/unit/bee-debug-class.spec.ts +0 -435
  141. package/test/unit/chunk/bmt.spec.ts +0 -16
  142. package/test/unit/chunk/cac.spec.ts +0 -29
  143. package/test/unit/chunk/serialize.spec.ts +0 -24
  144. package/test/unit/chunk/signer.spec.ts +0 -140
  145. package/test/unit/chunk/soc.spec.ts +0 -25
  146. package/test/unit/chunk/span.spec.ts +0 -38
  147. package/test/unit/feed/json.spec.ts +0 -73
  148. package/test/unit/nock.ts +0 -151
  149. package/test/unit/utils/bytes.spec.ts +0 -32
  150. package/test/unit/utils/collection.spec.ts +0 -22
  151. package/test/unit/utils/eth.spec.ts +0 -224
  152. package/test/unit/utils/hex.spec.ts +0 -115
  153. package/test/unit/utils/stream.spec.ts +0 -30
  154. package/test/unit/utils/type.spec.ts +0 -32
  155. package/test/unit/utils/uint64.spec.ts +0 -102
  156. package/test/utils.ts +0 -426
  157. package/tsconfig.json +0 -18
  158. package/tsconfig.test.json +0 -11
  159. package/typedoc.json +0 -7
  160. package/webpack.config.ts +0 -141
@@ -1,561 +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 = 6
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
- tagUid: number
131
- }
132
-
133
- export interface UploadOptions extends RequestOptions {
134
- /**
135
- * Will pin the data locally in the Bee node as well.
136
- *
137
- * Locally pinned data is possible to reupload to network if it disappear.
138
- *
139
- * **Warning! Not allowed when node is in Gateway mode!**
140
- *
141
- * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
142
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
143
- */
144
- pin?: boolean
145
-
146
- /**
147
- * Will encrypt the uploaded data and return longer hash which also includes the decryption key.
148
- *
149
- * **Warning! Not allowed when node is in Gateway mode!**
150
- *
151
- * @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/access-the-swarm/store-with-encryption)
152
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
153
- * @see Reference
154
- */
155
- encrypt?: boolean
156
-
157
- /**
158
- * Tags keep track of syncing the data with network. This option allows attach existing Tag UUID to the uploaded data.
159
- *
160
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
161
- * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
162
- * @link Tag
163
- */
164
- tag?: number
165
- }
166
-
167
- export interface FileUploadOptions extends UploadOptions {
168
- /**
169
- * Specifies Content-Length for the given data. It is required when uploading with Readable.
170
- *
171
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
172
- */
173
- size?: number
174
-
175
- /**
176
- * Specifies given Content-Type so when loaded in browser the file is correctly represented.
177
- *
178
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
179
- */
180
- contentType?: string
181
- }
182
-
183
- export interface CollectionUploadOptions extends UploadOptions {
184
- /**
185
- * Default file to be returned when the root hash of collection is accessed.
186
- *
187
- * @see [Bee docs - Upload a directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory)
188
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
189
- */
190
- indexDocument?: string
191
-
192
- /**
193
- * Configure custom error document to be returned when a specified path can not be found in collection.
194
- *
195
- * @see [Bee docs - Upload a directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory)
196
- * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File)
197
- */
198
- errorDocument?: string
199
- }
200
-
201
- export interface UploadHeaders {
202
- 'swarm-pin'?: string
203
- 'swarm-encrypt'?: string
204
- 'swarm-tag'?: string
205
- 'swarm-postage-batch-id'?: string
206
- }
207
-
208
- /**
209
- * Object that contains infromation about progress of upload of data to network.
210
- *
211
- * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
212
- */
213
- export interface Tag {
214
- /**
215
- * Number of all chunks that the data will be split into.
216
- */
217
- total: number
218
-
219
- /**
220
- * Number of chunks that is locally stored in the Bee node.
221
- */
222
- processed: number
223
-
224
- /**
225
- * Number of chunks that arrived to their designated destination in the network
226
- */
227
- synced: number
228
-
229
- /**
230
- * Unique identifier
231
- */
232
- uid: number
233
-
234
- /**
235
- * When the upload process started
236
- */
237
- startedAt: string
238
- }
239
-
240
- export interface AllTagsOptions extends RequestOptions {
241
- limit?: number
242
- offset?: number
243
- }
244
-
245
- export interface FileHeaders {
246
- name?: string
247
- tagUid?: number
248
- contentType?: string
249
- }
250
-
251
- export interface FileData<T> extends FileHeaders {
252
- data: T
253
- }
254
-
255
- export interface Pin {
256
- reference: string
257
- }
258
-
259
- /**
260
- * Helper interface that adds utility functions
261
- * to work more conveniently with bytes in normal
262
- * user scenarios.
263
- *
264
- * Concretely: text(), hex(), json()
265
- */
266
- export interface Data extends Uint8Array {
267
- /**
268
- * Converts the binary data using UTF-8 decoding into string.
269
- */
270
- text(): string
271
-
272
- /**
273
- * Converts the binary data into hex-string.
274
- */
275
- hex(): HexString
276
-
277
- /**
278
- * Converts the binary data into string which is then parsed into JSON.
279
- */
280
- json(): Record<string, unknown>
281
- }
282
-
283
- /**
284
- * Object represents a file and some of its metadata in [[Directory]] object.
285
- */
286
- export interface CollectionEntry<T> {
287
- data: T
288
-
289
- /**
290
- *
291
- */
292
- path: string
293
- }
294
-
295
- /**
296
- * Represents Collections
297
- */
298
- export type Collection<T> = Array<CollectionEntry<T>>
299
-
300
- export interface PssSubscription {
301
- readonly topic: string
302
- cancel: () => void
303
- }
304
-
305
- export interface PssMessageHandler {
306
- onMessage: (message: Data, subscription: PssSubscription) => void
307
- onError: (error: BeeError, subscription: PssSubscription) => void
308
- }
309
-
310
- export interface BeeGenericResponse {
311
- message: string
312
- code: number
313
- }
314
-
315
- export interface ReferenceResponse {
316
- reference: Reference
317
- }
318
-
319
- export type HttpMethod = 'GET' | 'DELETE' | 'POST' | 'PATCH' | 'PUT'
320
-
321
- export type HookCallback<V> = (value: V) => void | Promise<void>
322
-
323
- export interface BeeRequest {
324
- url: string
325
- method: HttpMethod
326
- headers?: Record<string, string>
327
- params?: Record<string, unknown>
328
- }
329
-
330
- export interface BeeResponse {
331
- headers: Record<string, string>
332
- status: number
333
- statusText?: string
334
- request: BeeRequest
335
- }
336
-
337
- /*********************************************************
338
- * Writers and Readers interfaces
339
- */
340
-
341
- export const TOPIC_BYTES_LENGTH = 32
342
- export const TOPIC_HEX_LENGTH = 64
343
-
344
- /**
345
- * Hex string of length 64 chars without prefix that specifies topics for feed.
346
- */
347
- export type Topic = HexString<typeof TOPIC_HEX_LENGTH>
348
-
349
- /**
350
- * FeedReader is an interface for downloading feed updates
351
- */
352
- export interface FeedReader {
353
- readonly type: FeedType
354
- readonly owner: HexEthAddress
355
- readonly topic: Topic
356
- /**
357
- * Download the latest feed update
358
- */
359
- download(options?: FeedUpdateOptions): Promise<FetchFeedUpdateResponse>
360
- }
361
-
362
- export interface JsonFeedOptions extends RequestOptions {
363
- /**
364
- * Valid only for `get` action, where either this `address` or `signer` has
365
- * to be specified.
366
- */
367
- address?: EthAddress | Uint8Array | string
368
-
369
- /**
370
- * Custom Signer object or private key in either binary or hex form.
371
- * This required for `set` action, and optional for `get` although
372
- * if not specified for `get` then `address` option has to be specified.
373
- */
374
- signer?: Signer | Uint8Array | string
375
- type?: FeedType
376
- }
377
-
378
- /**
379
- * FeedWriter is an interface for updating feeds
380
- */
381
- export interface FeedWriter extends FeedReader {
382
- /**
383
- * Upload a new feed update
384
- *
385
- * @param postageBatchId Postage BatchId to be used to upload the data with
386
- * @param reference The reference to be stored in the new update
387
- * @param options Additional options like `at`
388
- *
389
- * @returns Reference that points at Single Owner Chunk that contains the new update and pointer to the updated chunk reference.
390
- */
391
- upload(
392
- postageBatchId: string | BatchId,
393
- reference: ChunkReference | Reference,
394
- options?: FeedUploadOptions,
395
- ): Promise<Reference>
396
- }
397
-
398
- /**
399
- * Interface for downloading single owner chunks
400
- */
401
- export interface SOCReader {
402
- /**
403
- * Downloads a single owner chunk
404
- *
405
- * @param identifier The identifier of the chunk
406
- */
407
- download: (identifier: Identifier) => Promise<SingleOwnerChunk>
408
- }
409
-
410
- /**
411
- * Interface for downloading and uploading single owner chunks
412
- */
413
- export interface SOCWriter extends SOCReader {
414
- /**
415
- * Uploads a single owner chunk
416
- *
417
- * @param identifier The identifier of the chunk
418
- * @param data The chunk payload data
419
- * @param options Upload options
420
- */
421
- upload: (
422
- postageBatchId: string | BatchId,
423
- identifier: Identifier,
424
- data: Uint8Array,
425
- options?: UploadOptions,
426
- ) => Promise<Reference>
427
- }
428
-
429
- /**
430
- * Interface representing Postage stamp batch.
431
- */
432
- export interface PostageBatch {
433
- batchID: BatchId
434
- utilization: number
435
- usable: boolean
436
- label: '' | string
437
- depth: number
438
- amount: string
439
- bucketDepth: number
440
- blockNumber: number
441
- immutableFlag: boolean
442
- }
443
-
444
- export interface DebugPostageBatch extends PostageBatch {
445
- /**
446
- * The time (in seconds) remaining until the batch expires; -1 signals that the batch never expires; 0 signals that the batch has already expired.
447
- */
448
- batchTTL: number
449
-
450
- exists: boolean
451
- }
452
-
453
- export interface BatchBucket {
454
- bucketID: number
455
- collisions: number
456
- }
457
-
458
- export interface PostageBatchBuckets {
459
- depth: number
460
- bucketDepth: number
461
- bucketUpperBound: number
462
- buckets?: BatchBucket[]
463
- }
464
-
465
- export type TransactionHash = BrandedString<'TransactionHash'>
466
-
467
- export interface TransactionInfo {
468
- transactionHash: TransactionHash
469
- to: HexEthAddress
470
- nonce: number
471
- gasPrice: NumberString
472
- gasLimit: number
473
- data: string
474
- created: string
475
- description: string
476
- value: string
477
- }
478
-
479
- /**
480
- * Options for creation of postage batch
481
- */
482
- export interface PostageBatchOptions extends RequestOptions {
483
- /**
484
- * Sets label for the postage batch
485
- */
486
- label?: string
487
-
488
- /**
489
- * Sets gas price in Wei for the transaction that creates the postage batch
490
- */
491
- gasPrice?: NumberString
492
- immutableFlag?: boolean
493
- }
494
-
495
- /**
496
- * With this type a number should be represented in a string
497
- */
498
- export type NumberString = FlavoredType<string, 'NumberString'>
499
-
500
- /*********************************************************
501
- * Ethereum compatible signing interfaces and definitions
502
- */
503
-
504
- export const SIGNATURE_HEX_LENGTH = 130
505
- export const SIGNATURE_BYTES_LENGTH = 65
506
-
507
- export type Signature = Bytes<typeof SIGNATURE_BYTES_LENGTH>
508
- export type PrivateKeyBytes = Bytes<32>
509
-
510
- /**
511
- * Signing function that takes digest in Uint8Array to be signed that has helpers to convert it
512
- * conveniently into other types like hex-string (non prefix).
513
- * Result of the signing can be returned either in Uint8Array or hex string form.
514
- *
515
- * @see Data
516
- */
517
- type SyncSigner = (digest: Data) => Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string
518
- type AsyncSigner = (digest: Data) => Promise<Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string>
519
-
520
- /**
521
- * Interface for implementing Ethereum compatible signing.
522
- *
523
- * In order to be compatible with Ethereum and its signing method `personal_sign`, the data
524
- * that are passed to sign() function should be prefixed with: `\x19Ethereum Signed Message:\n${data.length}`, hashed
525
- * and only then signed.
526
- * If you are wrapping another signer tool/library (like Metamask or some other Ethereum wallet), you might not have
527
- * to do this prefixing manually if you use the `personal_sign` method. Check documentation of the tool!
528
- * If you are writing your own storage for keys, then you have to prefix the data manually otherwise the Bee node
529
- * will reject the chunks signed by you!
530
- *
531
- * For example see the hashWithEthereumPrefix() function.
532
- *
533
- * @property sign The sign function that can be sync or async. This function takes non-prefixed data. See above.
534
- * @property address The ethereum address of the signer in bytes.
535
- * @see hashWithEthereumPrefix
536
- */
537
- export type Signer = {
538
- sign: SyncSigner | AsyncSigner
539
- address: EthAddress
540
- }
541
-
542
- /**
543
- * These type are used to create new nominal types
544
- *
545
- * See https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/
546
- */
547
- export type BrandedType<Type, Name> = Type & { __tag__: Name }
548
-
549
- export type BrandedString<Name> = BrandedType<string, Name>
550
-
551
- export type FlavoredType<Type, Name> = Type & { __tag__?: Name }
552
-
553
- // JSON typings
554
- // by @indiescripter at https://github.com/microsoft/TypeScript/issues/1897#issuecomment-338650717
555
- export type AnyJson = boolean | number | string | null | JsonArray | JsonMap
556
- interface JsonMap {
557
- [key: string]: AnyJson
558
- }
559
- type JsonArray = Array<AnyJson>
560
-
561
- 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
- }