@ethersphere/bee-js 3.0.0 → 3.3.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 (196) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/bee-debug.js +615 -0
  3. package/dist/cjs/bee.js +922 -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 +137 -0
  8. package/dist/cjs/chunk/soc.js +172 -0
  9. package/dist/cjs/chunk/span.js +29 -0
  10. package/dist/cjs/feed/index.js +184 -0
  11. package/dist/cjs/feed/json.js +41 -0
  12. package/dist/cjs/feed/topic.js +25 -0
  13. package/dist/cjs/feed/type.js +15 -0
  14. package/dist/cjs/index.js +35 -0
  15. package/dist/cjs/modules/bytes.js +74 -0
  16. package/dist/cjs/modules/bzz.js +131 -0
  17. package/dist/cjs/modules/chunk.js +58 -0
  18. package/dist/cjs/modules/debug/balance.js +77 -0
  19. package/dist/cjs/modules/debug/chequebook.js +167 -0
  20. package/dist/cjs/modules/debug/chunk.js +51 -0
  21. package/dist/cjs/modules/debug/connectivity.js +75 -0
  22. package/dist/cjs/modules/debug/settlements.js +45 -0
  23. package/dist/cjs/modules/debug/stamps.js +89 -0
  24. package/dist/cjs/modules/debug/states.js +47 -0
  25. package/dist/cjs/modules/debug/status.js +153 -0
  26. package/dist/cjs/modules/debug/tag.js +30 -0
  27. package/dist/cjs/modules/debug/transactions.js +81 -0
  28. package/dist/cjs/modules/feed.js +76 -0
  29. package/dist/cjs/modules/pinning.js +84 -0
  30. package/dist/cjs/modules/pss.js +55 -0
  31. package/dist/cjs/modules/soc.js +40 -0
  32. package/dist/cjs/modules/status.js +26 -0
  33. package/dist/cjs/modules/stewardship.js +41 -0
  34. package/dist/cjs/modules/tag.js +96 -0
  35. package/dist/cjs/package.json +8 -0
  36. package/dist/cjs/types/debug.js +9 -0
  37. package/dist/cjs/types/index.js +46 -0
  38. package/dist/cjs/types/ky-options.js +8 -0
  39. package/dist/cjs/types/ky-universal/common.js +8 -0
  40. package/dist/cjs/types/ky-universal/hooks.js +8 -0
  41. package/dist/cjs/types/ky-universal/retry.js +8 -0
  42. package/dist/cjs/utils/bytes.js +107 -0
  43. package/dist/cjs/utils/collection.browser.js +36 -0
  44. package/dist/cjs/utils/collection.js +70 -0
  45. package/dist/cjs/utils/collection.node.js +115 -0
  46. package/dist/cjs/utils/data.browser.js +78 -0
  47. package/dist/cjs/utils/data.js +60 -0
  48. package/dist/cjs/utils/error.js +50 -0
  49. package/dist/cjs/utils/eth.js +211 -0
  50. package/dist/cjs/utils/expose.js +44 -0
  51. package/dist/cjs/utils/file.js +49 -0
  52. package/dist/cjs/utils/hash.js +21 -0
  53. package/dist/cjs/utils/headers.js +59 -0
  54. package/dist/cjs/utils/hex.js +150 -0
  55. package/dist/cjs/utils/http.js +166 -0
  56. package/dist/cjs/utils/merge.js +34 -0
  57. package/dist/cjs/utils/pss.js +18 -0
  58. package/dist/cjs/utils/stamps.js +17 -0
  59. package/dist/cjs/utils/stream.js +146 -0
  60. package/dist/cjs/utils/tar.js +25 -0
  61. package/dist/cjs/utils/type.js +327 -0
  62. package/dist/cjs/utils/uint64.js +29 -0
  63. package/dist/cjs/utils/url.js +56 -0
  64. package/dist/index.browser.min.js +1 -1
  65. package/dist/index.browser.min.js.LICENSE.txt +5 -12
  66. package/dist/index.browser.min.js.map +1 -1
  67. package/dist/mjs/bee-debug.js +609 -0
  68. package/dist/mjs/bee.js +944 -0
  69. package/dist/mjs/chunk/bmt.js +56 -0
  70. package/dist/mjs/chunk/cac.js +52 -0
  71. package/dist/mjs/chunk/serialize.js +15 -0
  72. package/dist/mjs/chunk/signer.js +131 -0
  73. package/dist/mjs/chunk/soc.js +139 -0
  74. package/dist/mjs/chunk/span.js +28 -0
  75. package/dist/mjs/feed/index.js +145 -0
  76. package/dist/mjs/feed/json.js +27 -0
  77. package/dist/mjs/feed/topic.js +21 -0
  78. package/dist/mjs/feed/type.js +10 -0
  79. package/dist/mjs/index.js +7 -0
  80. package/dist/mjs/modules/bytes.js +59 -0
  81. package/dist/mjs/modules/bzz.js +122 -0
  82. package/dist/mjs/modules/chunk.js +45 -0
  83. package/dist/mjs/modules/debug/balance.js +57 -0
  84. package/dist/mjs/modules/debug/chequebook.js +150 -0
  85. package/dist/mjs/modules/debug/chunk.js +35 -0
  86. package/dist/mjs/modules/debug/connectivity.js +45 -0
  87. package/dist/mjs/modules/debug/settlements.js +29 -0
  88. package/dist/mjs/modules/debug/stamps.js +64 -0
  89. package/dist/mjs/modules/debug/states.js +31 -0
  90. package/dist/mjs/modules/debug/status.js +134 -0
  91. package/dist/mjs/modules/debug/tag.js +16 -0
  92. package/dist/mjs/modules/debug/transactions.js +63 -0
  93. package/dist/mjs/modules/feed.js +67 -0
  94. package/dist/mjs/modules/pinning.js +66 -0
  95. package/dist/mjs/modules/pss.js +40 -0
  96. package/dist/mjs/modules/soc.js +31 -0
  97. package/dist/mjs/modules/status.js +12 -0
  98. package/dist/mjs/modules/stewardship.js +24 -0
  99. package/dist/mjs/modules/tag.js +77 -0
  100. package/dist/mjs/package.json +8 -0
  101. package/dist/mjs/types/debug.js +7 -0
  102. package/dist/mjs/types/index.js +37 -0
  103. package/dist/mjs/types/ky-options.js +7 -0
  104. package/dist/mjs/types/ky-universal/common.js +7 -0
  105. package/dist/mjs/types/ky-universal/hooks.js +7 -0
  106. package/dist/mjs/types/ky-universal/retry.js +7 -0
  107. package/dist/mjs/utils/bytes.js +101 -0
  108. package/dist/mjs/utils/collection.browser.js +19 -0
  109. package/dist/mjs/utils/collection.js +64 -0
  110. package/dist/mjs/utils/collection.node.js +74 -0
  111. package/dist/mjs/utils/data.browser.js +73 -0
  112. package/dist/mjs/utils/data.js +43 -0
  113. package/dist/mjs/utils/error.js +56 -0
  114. package/dist/mjs/utils/eth.js +199 -0
  115. package/dist/mjs/utils/expose.js +9 -0
  116. package/dist/mjs/utils/file.js +36 -0
  117. package/dist/mjs/utils/hash.js +17 -0
  118. package/dist/mjs/utils/headers.js +58 -0
  119. package/dist/mjs/utils/hex.js +154 -0
  120. package/dist/mjs/utils/http.js +155 -0
  121. package/dist/mjs/utils/merge.js +36 -0
  122. package/dist/mjs/utils/pss.js +16 -0
  123. package/dist/mjs/utils/stamps.js +17 -0
  124. package/dist/mjs/utils/stream.js +156 -0
  125. package/dist/mjs/utils/tar.js +21 -0
  126. package/dist/mjs/utils/type.js +336 -0
  127. package/dist/mjs/utils/uint64.js +23 -0
  128. package/dist/mjs/utils/url.js +57 -0
  129. package/dist/{src → types}/bee-debug.d.ts +51 -1
  130. package/dist/{src → types}/bee.d.ts +21 -0
  131. package/dist/{src → types}/chunk/bmt.d.ts +0 -0
  132. package/dist/{src → types}/chunk/cac.d.ts +0 -0
  133. package/dist/{src → types}/chunk/serialize.d.ts +0 -0
  134. package/dist/{src → types}/chunk/signer.d.ts +0 -0
  135. package/dist/{src → types}/chunk/soc.d.ts +0 -0
  136. package/dist/{src → types}/chunk/span.d.ts +0 -0
  137. package/dist/{src → types}/feed/index.d.ts +0 -0
  138. package/dist/{src → types}/feed/json.d.ts +0 -0
  139. package/dist/{src → types}/feed/topic.d.ts +0 -0
  140. package/dist/{src → types}/feed/type.d.ts +0 -0
  141. package/dist/{src → types}/index.d.ts +0 -0
  142. package/dist/{src → types}/modules/bytes.d.ts +0 -0
  143. package/dist/{src → types}/modules/bzz.d.ts +0 -0
  144. package/dist/{src → types}/modules/chunk.d.ts +2 -10
  145. package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
  146. package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
  147. package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
  148. package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
  149. package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
  150. package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
  151. package/dist/{src → types}/modules/debug/states.d.ts +0 -0
  152. package/dist/types/modules/debug/status.d.ts +72 -0
  153. package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
  154. package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
  155. package/dist/{src → types}/modules/feed.d.ts +0 -0
  156. package/dist/{src → types}/modules/pinning.d.ts +0 -0
  157. package/dist/{src → types}/modules/pss.d.ts +0 -0
  158. package/dist/{src → types}/modules/soc.d.ts +0 -0
  159. package/dist/{src → types}/modules/status.d.ts +0 -0
  160. package/dist/{src → types}/modules/stewardship.d.ts +0 -0
  161. package/dist/{src → types}/modules/tag.d.ts +0 -0
  162. package/dist/{src → types}/types/debug.d.ts +25 -0
  163. package/dist/{src → types}/types/index.d.ts +32 -2
  164. package/dist/types/types/ky-options.d.ts +221 -0
  165. package/dist/types/types/ky-universal/common.d.ts +13 -0
  166. package/dist/types/types/ky-universal/hooks.d.ts +92 -0
  167. package/dist/types/types/ky-universal/retry.d.ts +38 -0
  168. package/dist/{src → types}/utils/bytes.d.ts +0 -0
  169. package/dist/types/utils/collection.browser.d.ts +15 -0
  170. package/dist/{src → types}/utils/collection.d.ts +0 -14
  171. package/dist/types/utils/collection.node.d.ts +15 -0
  172. package/dist/{src → types}/utils/data.browser.d.ts +0 -0
  173. package/dist/{src → types}/utils/data.d.ts +0 -0
  174. package/dist/types/utils/error.d.ts +33 -0
  175. package/dist/{src → types}/utils/eth.d.ts +0 -0
  176. package/dist/{src → types}/utils/expose.d.ts +3 -1
  177. package/dist/{src → types}/utils/file.d.ts +0 -0
  178. package/dist/{src → types}/utils/hash.d.ts +0 -0
  179. package/dist/{src → types}/utils/headers.d.ts +0 -0
  180. package/dist/{src → types}/utils/hex.d.ts +0 -0
  181. package/dist/{src → types}/utils/http.d.ts +7 -9
  182. package/dist/{src → types}/utils/merge.d.ts +0 -0
  183. package/dist/{src → types}/utils/pss.d.ts +0 -0
  184. package/dist/types/utils/stamps.d.ts +12 -0
  185. package/dist/{src → types}/utils/stream.d.ts +11 -8
  186. package/dist/{src → types}/utils/tar.d.ts +0 -0
  187. package/dist/{src → types}/utils/type.d.ts +6 -0
  188. package/dist/{src → types}/utils/uint64.d.ts +0 -0
  189. package/dist/{src → types}/utils/url.d.ts +0 -0
  190. package/package.json +61 -43
  191. package/CHANGELOG.md +0 -546
  192. package/dist/index.min.js +0 -3
  193. package/dist/index.min.js.LICENSE.txt +0 -50
  194. package/dist/index.min.js.map +0 -1
  195. package/dist/src/modules/debug/status.d.ts +0 -18
  196. package/dist/src/utils/error.d.ts +0 -14
@@ -121,6 +121,31 @@ export interface Health {
121
121
  apiVersion: string;
122
122
  debugApiVersion: string;
123
123
  }
124
+ export interface BeeVersions {
125
+ supportedBeeVersion: string;
126
+ supportedBeeApiVersion: string;
127
+ supportedBeeDebugApiVersion: string;
128
+ beeVersion: string;
129
+ beeApiVersion: string;
130
+ beeDebugApiVersion: string;
131
+ }
132
+ export declare enum BeeModes {
133
+ FULL = "full",
134
+ LIGHT = "light",
135
+ DEV = "dev"
136
+ }
137
+ /**
138
+ * Information about Bee node and its configuration
139
+ */
140
+ export interface NodeInfo {
141
+ gatewayMode: boolean;
142
+ beeMode: BeeModes;
143
+ }
144
+ /**
145
+ * Information about Bee node and its configuration
146
+ * @deprecated Use NodeInfo instead
147
+ */
148
+ export declare type NodesInfo = NodeInfo;
124
149
  export interface RemovePeerResponse {
125
150
  message: string;
126
151
  code: 0;
@@ -11,11 +11,16 @@ import type ky from 'ky-universal';
11
11
  import type { Readable as NativeReadable } from 'stream';
12
12
  import type { Readable as CompatibilityReadable } from 'readable-stream';
13
13
  import type { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill/ponyfill';
14
+ import { Options as KyOptions } from './ky-options';
14
15
  export * from './debug';
15
16
  export declare type Ky = typeof ky;
16
17
  export interface Dictionary<T> {
17
18
  [Key: string]: T;
18
19
  }
20
+ export declare const SPAN_SIZE = 8;
21
+ export declare const SECTION_SIZE = 32;
22
+ export declare const BRANCHES = 128;
23
+ export declare const CHUNK_SIZE: number;
19
24
  export declare const ADDRESS_HEX_LENGTH = 64;
20
25
  export declare const PSS_TARGET_HEX_LENGTH_MAX = 6;
21
26
  export declare const PUBKEY_HEX_LENGTH = 66;
@@ -59,6 +64,17 @@ export declare type BatchId = HexString<typeof BATCH_ID_HEX_LENGTH>;
59
64
  * It represents PSS Address Prefix that is used to define address neighborhood that will receive the PSS message.
60
65
  */
61
66
  export declare type AddressPrefix = HexString;
67
+ /**
68
+ * Internal interface that represents configuration for creating a request with Ky
69
+ */
70
+ export interface KyRequestOptions extends Omit<KyOptions, 'searchParams'> {
71
+ path: string;
72
+ responseType?: 'json' | 'arraybuffer' | 'stream';
73
+ /**
74
+ * Overridden parameter that allows undefined as a value.
75
+ */
76
+ searchParams?: Record<string, string | number | boolean | undefined>;
77
+ }
62
78
  export interface RequestOptions {
63
79
  /**
64
80
  * Timeout of requests in milliseconds
@@ -138,6 +154,17 @@ export interface UploadOptions extends RequestOptions {
138
154
  * @link Tag
139
155
  */
140
156
  tag?: number;
157
+ /**
158
+ * Determines if the uploaded data should be sent to the network immediately (eq. deferred=false) or in a deferred fashion (eq. deferred=true).
159
+ *
160
+ * With deferred style client uploads all the data to Bee node first and only then Bee node starts push the data to network itself. The progress of this upload can be tracked with tags.
161
+ * With non-deferred style client uploads the data to Bee which immediately starts pushing the data to network. The request is only finished once all the data was pushed through the Bee node to the network.
162
+ *
163
+ * In future there will be move to the non-deferred style and even the support for deferred upload will be removed from Bee itself.
164
+ *
165
+ * @default true
166
+ */
167
+ deferred?: boolean;
141
168
  }
142
169
  export interface FileUploadOptions extends UploadOptions {
143
170
  /**
@@ -335,6 +362,7 @@ export interface FeedWriter extends FeedReader {
335
362
  * Interface for downloading single owner chunks
336
363
  */
337
364
  export interface SOCReader {
365
+ readonly owner: HexEthAddress;
338
366
  /**
339
367
  * Downloads a single owner chunk
340
368
  *
@@ -368,14 +396,16 @@ export interface PostageBatch {
368
396
  bucketDepth: number;
369
397
  blockNumber: number;
370
398
  immutableFlag: boolean;
371
- }
372
- export interface DebugPostageBatch extends PostageBatch {
373
399
  /**
374
400
  * The time (in seconds) remaining until the batch expires; -1 signals that the batch never expires; 0 signals that the batch has already expired.
375
401
  */
376
402
  batchTTL: number;
377
403
  exists: boolean;
378
404
  }
405
+ /**
406
+ * @deprecated Use PostageBatch instead.
407
+ */
408
+ export declare type DebugPostageBatch = PostageBatch;
379
409
  export interface BatchBucket {
380
410
  bucketID: number;
381
411
  collisions: number;
@@ -0,0 +1,221 @@
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
+ import type { LiteralUnion, Required } from './ky-universal/common';
8
+ import type { Hooks } from './ky-universal/hooks';
9
+ import type { RetryOptions } from './ky-universal/retry';
10
+ export declare type SearchParamsInit = string | string[][] | Record<string, string> | URLSearchParams | undefined;
11
+ export declare type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean> | Array<Array<string | number | boolean>>;
12
+ export declare type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'head' | 'delete';
13
+ export declare type Input = string | URL | Request;
14
+ export interface DownloadProgress {
15
+ percent: number;
16
+ transferredBytes: number;
17
+ /**
18
+ Note: If it's not possible to retrieve the body size, it will be `0`.
19
+ */
20
+ totalBytes: number;
21
+ }
22
+ export declare type KyHeadersInit = HeadersInit | Record<string, string | undefined>;
23
+ /**
24
+ Options are the same as `window.fetch`, with some exceptions.
25
+ */
26
+ export interface Options extends Omit<RequestInit, 'headers'> {
27
+ /**
28
+ HTTP method used to make the request.
29
+
30
+ Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.
31
+ */
32
+ method?: LiteralUnion<HTTPMethod, string>;
33
+ /**
34
+ HTTP headers used to make the request.
35
+
36
+ You can pass a `Headers` instance or a plain object.
37
+
38
+ You can remove a header with `.extend()` by passing the header with an `undefined` value.
39
+
40
+ @example
41
+ ```
42
+ import ky from 'ky';
43
+
44
+ const url = 'https://sindresorhus.com';
45
+
46
+ const original = ky.create({
47
+ headers: {
48
+ rainbow: 'rainbow',
49
+ unicorn: 'unicorn'
50
+ }
51
+ });
52
+
53
+ const extended = original.extend({
54
+ headers: {
55
+ rainbow: undefined
56
+ }
57
+ });
58
+
59
+ const response = await extended(url).json();
60
+
61
+ console.log('rainbow' in response);
62
+ //=> false
63
+
64
+ console.log('unicorn' in response);
65
+ //=> true
66
+ ```
67
+ */
68
+ headers?: KyHeadersInit;
69
+ /**
70
+ Shortcut for sending JSON. Use this instead of the `body` option.
71
+
72
+ Accepts any plain object or value, which will be `JSON.stringify()`'d and sent in the body with the correct header set.
73
+ */
74
+ json?: unknown;
75
+ /**
76
+ User-defined JSON-parsing function.
77
+
78
+ Use-cases:
79
+ 1. Parse JSON via the [`bourne` package](https://github.com/hapijs/bourne) to protect from prototype pollution.
80
+ 2. Parse JSON with [`reviver` option of `JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
81
+
82
+ @default JSON.parse()
83
+
84
+ @example
85
+ ```
86
+ import ky from 'ky';
87
+ import bourne from '@hapijs/bourne';
88
+
89
+ const json = await ky('https://example.com', {
90
+ parseJson: text => bourne(text)
91
+ }).json();
92
+ ```
93
+ */
94
+ parseJson?: (text: string) => unknown;
95
+ /**
96
+ Search parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.
97
+
98
+ Accepts any value supported by [`URLSearchParams()`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams).
99
+ */
100
+ searchParams?: SearchParamsOption;
101
+ /**
102
+ A prefix to prepend to the `input` URL when making the request. It can be any valid URL, either relative or absolute. A trailing slash `/` is optional and will be added automatically, if needed, when it is joined with `input`. Only takes effect when `input` is a string. The `input` argument cannot start with a slash `/` when using this option.
103
+
104
+ Useful when used with `ky.extend()` to create niche-specific Ky-instances.
105
+
106
+ Notes:
107
+ - After `prefixUrl` and `input` are joined, the result is resolved against the [base URL](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) of the page (if any).
108
+ - Leading slashes in `input` are disallowed when using this option to enforce consistency and avoid confusion about how the `input` URL is handled, given that `input` will not follow the normal URL resolution rules when `prefixUrl` is being used, which changes the meaning of a leading slash.
109
+
110
+ @example
111
+ ```
112
+ import ky from 'ky';
113
+
114
+ // On https://example.com
115
+
116
+ const response = await ky('unicorn', {prefixUrl: '/api'});
117
+ //=> 'https://example.com/api/unicorn'
118
+
119
+ const response = await ky('unicorn', {prefixUrl: 'https://cats.com'});
120
+ //=> 'https://cats.com/unicorn'
121
+ ```
122
+ */
123
+ prefixUrl?: URL | string;
124
+ /**
125
+ An object representing `limit`, `methods`, `statusCodes` and `maxRetryAfter` fields for maximum retry count, allowed methods, allowed status codes and maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time.
126
+
127
+ If `retry` is a number, it will be used as `limit` and other defaults will remain in place.
128
+
129
+ If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`. If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.
130
+
131
+ Delays between retries is calculated with the function `0.3 * (2 ** (retry - 1)) * 1000`, where `retry` is the attempt number (starts from 1).
132
+
133
+ @example
134
+ ```
135
+ import ky from 'ky';
136
+
137
+ const json = await ky('https://example.com', {
138
+ retry: {
139
+ limit: 10,
140
+ methods: ['get'],
141
+ statusCodes: [413]
142
+ }
143
+ }).json();
144
+ ```
145
+ */
146
+ retry?: RetryOptions | number;
147
+ /**
148
+ Timeout in milliseconds for getting a response. Can not be greater than 2147483647.
149
+ If set to `false`, there will be no timeout.
150
+
151
+ @default 10000
152
+ */
153
+ timeout?: number | false;
154
+ /**
155
+ Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.
156
+ */
157
+ hooks?: Hooks;
158
+ /**
159
+ Throw an `HTTPError` when, after following redirects, the response has a non-2xx status code. To also throw for redirects instead of following them, set the [`redirect`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters) option to `'manual'`.
160
+
161
+ Setting this to `false` may be useful if you are checking for resource availability and are expecting error responses.
162
+
163
+ @default true
164
+ */
165
+ throwHttpErrors?: boolean;
166
+ /**
167
+ Download progress event handler.
168
+
169
+ @param chunk - Note: It's empty for the first call.
170
+
171
+ @example
172
+ ```
173
+ import ky from 'ky';
174
+
175
+ const response = await ky('https://example.com', {
176
+ onDownloadProgress: (progress, chunk) => {
177
+ // Example output:
178
+ // `0% - 0 of 1271 bytes`
179
+ // `100% - 1271 of 1271 bytes`
180
+ console.log(`${progress.percent * 100}% - ${progress.transferredBytes} of ${progress.totalBytes} bytes`);
181
+ }
182
+ });
183
+ ```
184
+ */
185
+ onDownloadProgress?: (progress: DownloadProgress, chunk: Uint8Array) => void;
186
+ /**
187
+ User-defined `fetch` function.
188
+ Has to be fully compatible with the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) standard.
189
+
190
+ Use-cases:
191
+ 1. Use custom `fetch` implementations like [`isomorphic-unfetch`](https://www.npmjs.com/package/isomorphic-unfetch).
192
+ 2. Use the `fetch` wrapper function provided by some frameworks that use server-side rendering (SSR).
193
+
194
+ @default fetch
195
+
196
+ @example
197
+ ```
198
+ import ky from 'ky';
199
+ import fetch from 'isomorphic-unfetch';
200
+
201
+ const json = await ky('https://example.com', {fetch}).json();
202
+ ```
203
+ */
204
+ fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
205
+ }
206
+ export declare type InternalOptions = Required<Omit<Options, 'hooks' | 'retry'>, 'credentials' | 'fetch' | 'prefixUrl' | 'timeout'> & {
207
+ hooks: Required<Hooks>;
208
+ retry: Required<RetryOptions>;
209
+ prefixUrl: string;
210
+ };
211
+ /**
212
+ Normalized options passed to the `fetch` call and the `beforeRequest` hooks.
213
+ */
214
+ export interface NormalizedOptions extends RequestInit {
215
+ method: RequestInit['method'];
216
+ credentials: RequestInit['credentials'];
217
+ retry: RetryOptions;
218
+ prefixUrl: string;
219
+ onDownloadProgress: Options['onDownloadProgress'];
220
+ }
221
+ export { RetryOptions };
@@ -0,0 +1,13 @@
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
+ export declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
8
+ export declare type Required<T, K extends keyof T = keyof T> = T & {
9
+ [P in K]-?: T[P];
10
+ };
11
+ export declare type LiteralUnion<LiteralType extends BaseType, BaseType extends Primitive> = LiteralType | (BaseType & {
12
+ _?: never;
13
+ });
@@ -0,0 +1,92 @@
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
+ import type { NormalizedOptions } from '../ky-options';
8
+ export declare const stop: unique symbol;
9
+ export declare type BeforeRequestHook = (request: Request, options: NormalizedOptions) => Request | Response | void | Promise<Request | Response | void>;
10
+ export declare type BeforeRetryState = {
11
+ request: Request;
12
+ response: Response;
13
+ options: NormalizedOptions;
14
+ error: Error;
15
+ retryCount: number;
16
+ };
17
+ export declare type BeforeRetryHook = (options: BeforeRetryState) => typeof stop | void | Promise<typeof stop | void>;
18
+ export declare type AfterResponseHook = (request: Request, options: NormalizedOptions, response: Response) => Response | void | Promise<Response | void>;
19
+ export interface Hooks {
20
+ /**
21
+ 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.
22
+
23
+ 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**.
24
+
25
+ @default []
26
+ */
27
+ beforeRequest?: BeforeRequestHook[];
28
+ /**
29
+ 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.
30
+
31
+ 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`.
32
+
33
+ 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).
34
+
35
+ @example
36
+ ```
37
+ import ky from 'ky';
38
+
39
+ const response = await ky('https://example.com', {
40
+ hooks: {
41
+ beforeRetry: [
42
+ async ({request, options, error, retryCount}) => {
43
+ const token = await ky('https://example.com/refresh-token');
44
+ options.headers.set('Authorization', `token ${token}`);
45
+ }
46
+ ]
47
+ }
48
+ });
49
+ ```
50
+
51
+ @default []
52
+ */
53
+ beforeRetry?: BeforeRetryHook[];
54
+ /**
55
+ 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).
56
+
57
+ @default []
58
+
59
+ @example
60
+ ```
61
+ import ky from 'ky';
62
+
63
+ const response = await ky('https://example.com', {
64
+ hooks: {
65
+ afterResponse: [
66
+ (_input, _options, response) => {
67
+ // You could do something with the response, for example, logging.
68
+ log(response);
69
+
70
+ // Or return a `Response` instance to overwrite the response.
71
+ return new Response('A different response', {status: 200});
72
+ },
73
+
74
+ // Or retry with a fresh token on a 403 error
75
+ async (input, options, response) => {
76
+ if (response.status === 403) {
77
+ // Get a fresh token
78
+ const token = await ky('https://example.com/token').text();
79
+
80
+ // Retry with the token
81
+ options.headers.set('Authorization', `token ${token}`);
82
+
83
+ return ky(input, options);
84
+ }
85
+ }
86
+ ]
87
+ }
88
+ });
89
+ ```
90
+ */
91
+ afterResponse?: AfterResponseHook[];
92
+ }
@@ -0,0 +1,38 @@
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
+ export interface RetryOptions {
8
+ /**
9
+ The number of times to retry failed requests.
10
+
11
+ @default 2
12
+ */
13
+ limit?: number;
14
+ /**
15
+ The HTTP methods allowed to retry.
16
+
17
+ @default ['get', 'put', 'head', 'delete', 'options', 'trace']
18
+ */
19
+ methods?: string[];
20
+ /**
21
+ The HTTP status codes allowed to retry.
22
+
23
+ @default [408, 413, 429, 500, 502, 503, 504]
24
+ */
25
+ statusCodes?: number[];
26
+ /**
27
+ The HTTP status codes allowed to retry with a `Retry-After` header.
28
+
29
+ @default [413, 429, 503]
30
+ */
31
+ afterStatusCodes?: number[];
32
+ /**
33
+ If the `Retry-After` header is greater than `maxRetryAfter`, the request will be canceled.
34
+
35
+ @default Infinity
36
+ */
37
+ maxRetryAfter?: number;
38
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ import { Collection } from '../types';
2
+ /**
3
+ * Creates array in the format of Collection with data loaded from directory on filesystem.
4
+ * The function loads all the data into memory!
5
+ *
6
+ * @param dir path to the directory
7
+ */
8
+ export declare function makeCollectionFromFS(dir: string): Promise<Collection<Uint8Array>>;
9
+ /**
10
+ * Calculate folder size recursively
11
+ *
12
+ * @param dir the path to the folder to check
13
+ * @returns size in bytes
14
+ */
15
+ export declare function getFolderSize(dir: string): Promise<number>;
@@ -1,13 +1,6 @@
1
1
  import { Collection } from '../types';
2
2
  export declare function isCollection(data: unknown): data is Collection<Uint8Array>;
3
3
  export declare function assertCollection(data: unknown): asserts data is Collection<Uint8Array>;
4
- /**
5
- * Creates array in the format of Collection with data loaded from directory on filesystem.
6
- * The function loads all the data into memory!
7
- *
8
- * @param dir path to the directory
9
- */
10
- export declare function makeCollectionFromFS(dir: string): Promise<Collection<Uint8Array>>;
11
4
  export declare function makeCollectionFromFileList(fileList: FileList | File[]): Promise<Collection<Uint8Array>>;
12
5
  /**
13
6
  * Calculate cumulative size of files
@@ -16,10 +9,3 @@ export declare function makeCollectionFromFileList(fileList: FileList | File[]):
16
9
  * @returns size in bytes
17
10
  */
18
11
  export declare function getCollectionSize(fileList: FileList | File[]): number;
19
- /**
20
- * Calculate folder size recursively
21
- *
22
- * @param dir the path to the folder to check
23
- * @returns size in bytes
24
- */
25
- export declare function getFolderSize(dir: string): Promise<number>;
@@ -0,0 +1,15 @@
1
+ import { Collection } from '../types';
2
+ /**
3
+ * Creates array in the format of Collection with data loaded from directory on filesystem.
4
+ * The function loads all the data into memory!
5
+ *
6
+ * @param dir path to the directory
7
+ */
8
+ export declare function makeCollectionFromFS(dir: string): Promise<Collection<Uint8Array>>;
9
+ /**
10
+ * Calculate folder size recursively
11
+ *
12
+ * @param dir the path to the folder to check
13
+ * @returns size in bytes
14
+ */
15
+ export declare function getFolderSize(dir: string): Promise<number>;
File without changes
File without changes
@@ -0,0 +1,33 @@
1
+ import { KyRequestOptions } from '../types';
2
+ export declare class BeeError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export declare class BeeArgumentError extends BeeError {
6
+ readonly value: unknown;
7
+ constructor(message: string, value: unknown);
8
+ }
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
+ }
File without changes
@@ -1,7 +1,9 @@
1
- export { getCollectionSize, getFolderSize } from './collection';
1
+ export { getCollectionSize } from './collection';
2
+ export { getFolderSize } from './collection.node';
2
3
  export { Bytes, FlexBytes, isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual, } from './bytes';
3
4
  export { HexString, PrefixedHexString, makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString, } from './hex';
4
5
  export { EthAddress, makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner, } from './eth';
5
6
  export { readableWebToNode, readableNodeToWeb, isReadableStream, isNodeReadable, normalizeToReadableStream, isReadable, } from './stream';
6
7
  export { keccak256Hash } from './hash';
7
8
  export { makeMaxTarget } from './pss';
9
+ export { getStampUsage } from './stamps';
File without changes
File without changes
File without changes
File without changes
@@ -1,13 +1,6 @@
1
1
  import type { BeeRequest, BeeResponse, HookCallback, Ky } from '../types';
2
2
  import { Options as KyOptions } from 'ky-universal';
3
- interface HttpOptions extends Omit<KyOptions, 'searchParams'> {
4
- path: string;
5
- responseType?: 'json' | 'arraybuffer' | 'stream';
6
- /**
7
- * Overridden parameter that allows undefined as a value.
8
- */
9
- searchParams?: Record<string, string | number | boolean | undefined>;
10
- }
3
+ import { KyRequestOptions } from '../types';
11
4
  interface KyResponse<T> extends Response {
12
5
  data: T;
13
6
  }
@@ -20,6 +13,11 @@ export declare function wrapResponseClosure(cb: HookCallback<BeeResponse>): (req
20
13
  * @param obj
21
14
  */
22
15
  export declare function filterHeaders(obj?: object): Record<string, string> | undefined;
23
- export declare function http<T>(ky: Ky, config: HttpOptions): Promise<KyResponse<T>>;
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>>;
24
22
  export declare function makeDefaultKy(kyConfig: KyOptions): Ky;
25
23
  export {};
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ import { DebugPostageBatch } from '../types';
2
+ /**
3
+ * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
4
+ *
5
+ * Be aware for small depths (17, 18) this does not provide that much information as the provided set of distinct values
6
+ * is small.
7
+ *
8
+ * @param utilization
9
+ * @param depth
10
+ * @param bucketDepth
11
+ */
12
+ export declare function getStampUsage({ utilization, depth, bucketDepth }: DebugPostageBatch): number;